function processDatabase(argv, outputBaseFile, db, done) {
  var templates = {
    header: fs.readFileSync(path.join(templatePath, 'webgl-header.cc'), 'utf8')
  };

  var zones = db.getZones();
  if (!zones.length) {
    console.log('No zones');
    done(1);
    return;
  }

  // TODO(benvanik): find the right zone.
  var zone = zones[0];

  // Build a step list.
  console.log("Building step list...");
  var eventList = zone.getEventList();
  var frameList = zone.getFrameList();
  var steps = wtf.replay.graphics.Step.constructStepsList(eventList, frameList);

  // Open bin file.
  var binFile = new BinFile(outputBaseFile + '.bin');

  console.log("Generating code...");
  var tempDir;
  if (argv['src_output']) {
    tempDir = argv['src_output'];
  } else {
    var tempDirObj = new tmp.Dir();
    tempDir = tempDirObj.path;
    process.on('exit', function() {
      tempDirObj.rmdir();
    });
  }
  if (!fs.existsSync(tempDir)) {
    fs.mkdirSync(tempDir);
  }

  // Add all steps.
  var ccFiles = [];
  for (var n = 0; n < steps.length; n++) {
    var step = steps[n];

    // Prep file.
    var output = [];
    output.push(templates.header);

    // Add step function.
    output.push('void step_' + n + '(Replay* replay) {');
    addStep(eventList, n, step, output, binFile);
    output.push('}');

    // Flush.
    var finalOutput = output.join(os.EOL);
    var ccFile = path.basename(outputBaseFile) + '_step_' + n + '.cc';
    ccFile = path.join(tempDir, ccFile);
    fs.writeFileSync(ccFile, finalOutput);
    ccFiles.push(ccFile);
  }

  // Build statics file.
  var output = [];
  output.push(templates.header);

  // Add step list variable.
  var stepFnList = [];
  for (var n = 0; n < steps.length; n++) {
    stepFnList.push('step_' + n + ',');
    output.push('extern void step_' + n + '(Replay* replay);');
  }
  output.push(
      'StepFunction __steps[] = { ' + stepFnList.join(' ') + ' };');
  output.push(
      'int __step_count = ' + stepFnList.length + ';');
  output.push('StepFunction* __get_steps() { return __steps; }');

  // Static info.
  output.push(
      'const char* __trace_name = "' +
          path.basename(outputBaseFile) + '";');
  output.push(
      'const char* __bin_name = "' +
          path.basename(outputBaseFile) + '.bin";');

  // Write output cc file.
  console.log("Writing .cc file...");
  var finalOutput = output.join(os.EOL);
  var ccFile = path.join(tempDir, path.basename(outputBaseFile) + '.cc');
  fs.writeFileSync(ccFile, finalOutput);
  ccFiles.push(ccFile);

  // Finish bin file.
  binFile.dispose();

  // Build!
  console.log("Building executable...");
  build(argv, tempDir, outputBaseFile, ccFiles, done);
}
Processes a loaded database.
@param {!Object} argv Parsed optimist arguments.
@param {string} outputBaseFile Base filename for output (without extension).
@param {!wtf.db.Database} db Database.
@param {function(number)} done Done callback. 0 for success.