Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

Commit

Permalink
Debugger fixes for memory breakpoints, "if" processing, register pars…
Browse files Browse the repository at this point in the history
…ing, and more
  • Loading branch information
jeffpar committed Aug 13, 2015
1 parent 919f7cd commit d260c20
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 96 deletions.
43 changes: 25 additions & 18 deletions modules/filedump/lib/filedump.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ var DumpAPI = require("../../shared/lib/dumpapi");
* FileDump()
*
* TODO: Consider adding a "map" option that allows the user to supply a MAP filename (via a "map" API parameter
* or a "--map" command-line option), which in turn triggers a call to loadMap(). Note that loadMap() will need
* to be a bit more general and use a worker function that calls either net.getFile() or fs.readFile(), similar
* to what our loadFile() function already does.
* or a "--map" command-line option), which in turn triggers a call to loadMap(). Note that loadMap() will need to
* be a bit more general and use a worker function that calls either net.getFile() or fs.readFile(), similar to
* what the loadFile() function already does.
*
* @constructor
* @param {string|undefined} sFormat should be one of "json"|"data"|"hex"|"bytes"|"rom" (see the FORMAT constants)
* @param {boolean|string|undefined} fComments enables comments and other readability enhancements in the JSON output
* @param {boolean|string|undefined} fDecimal forces decimal output if not undefined
* @param {number|string|undefined} offDump
* @param {number|string|undefined} nWidthDump
* @param {string} [sServerRoot]
* @param {string} [sServerRoot] (if omitted, we assume local operation)
*/
function FileDump(sFormat, fComments, fDecimal, offDump, nWidthDump, sServerRoot)
{
Expand All @@ -67,6 +67,7 @@ function FileDump(sFormat, fComments, fDecimal, offDump, nWidthDump, sServerRoot
this.fDecimal = fDecimal;
this.offDump = +offDump || 0;
this.nWidthDump = +nWidthDump || 16;
this.fLocal = !sServerRoot;
this.sServerRoot = sServerRoot || process.cwd();
this.buf = null;
/*
Expand Down Expand Up @@ -135,7 +136,7 @@ FileDump.CLI = function()
var args = proc.getArgs();

if (!args.argc) {
console.log("usage: filedump --file=({path}|{URL}) [--merge=({path}|{url})] [--format=(json|data|hex|bytes|rom)] [--comments] [--decimal] [--output={path}] [--overwrite]");
console.log("usage: filedump --file=({path}|{URL}) [--merge=({path}|{url})] [--format=(json|data|hex|bytes|rom)] [--comments] [--decimal] [--offset={number}] [--width={number}] [--output={path}] [--overwrite]");
return;
}

Expand All @@ -147,7 +148,6 @@ FileDump.CLI = function()
}

var sOutputFile = argv['output'];
if (sOutputFile && sOutputFile.charAt(0) != '/') sOutputFile = path.join(process.cwd(), sOutputFile);
var fOverwrite = argv['overwrite'];

var sFormat = FileDump.validateFormat(argv['format']);
Expand Down Expand Up @@ -229,8 +229,8 @@ FileDump.validateFormat = function(sFormat)
* loadFile(sFile, iStart, nSkip, done)
*
* This used to be part of the FileDump constructor, but I felt it would be safer to separate
* object creation from any I/O that the object may perform, to ensure that a callback can never
* be called before the caller has actually received the newly created object.
* object creation from any I/O, ensuring that the callback will not be invoked until the caller
* has received the FileDump object.
*
* @this {FileDump}
* @param {string} sFile
Expand All @@ -245,7 +245,7 @@ FileDump.prototype.loadFile = function(sFile, iStart, nSkip, done)
var sExt = str.getExtension(sFile);
var options = {encoding: sExt == DumpAPI.FORMAT.JSON || sExt == DumpAPI.FORMAT.HEX? "utf8" : null};

var sFilePath = net.isRemote(sFile)? sFile : path.join(this.sServerRoot, sFile);
var sFilePath = (this.fLocal || net.isRemote(sFile))? sFile : path.join(this.sServerRoot, sFile);

if (!this.sFilePath) this.sFilePath = sFilePath;
if (this.fDebug) console.log("loadFile(" + sFilePath + "," + iStart + "," + nSkip + ")");
Expand Down Expand Up @@ -464,15 +464,15 @@ FileDump.prototype.dumpBuffer = function(sKey, buf, len, cbItem, offDump, nWidth
};

/**
* loadMap(sFilePath, done)
* loadMap(sMapFile, done)
*
* NOTE: Since ".map" files are an internal construct, I support only local map files (for now)
*
* @this {FileDump}
* @param {string} sFilePath
* @param {string} sMapFile
* @param {function(Error,string)} done
*/
FileDump.prototype.loadMap = function(sFilePath, done)
FileDump.prototype.loadMap = function(sMapFile, done)
{
/*
* The HEX format doesn't support MAP files, because old HEX clients expect an Array of bytes,
Expand All @@ -484,10 +484,14 @@ FileDump.prototype.loadMap = function(sFilePath, done)
this.json = '"bytes":' + this.json;
}
var obj = this;
var sMapPath = sFilePath.replace(/\.(rom|json)$/, ".map");
if (str.endsWith(sMapPath, ".map")) {
var sMapFile = path.basename(sMapPath);
fs.readFile(sMapPath, {encoding: "utf8"}, function(err, str) {

sMapFile = sMapFile.replace(/\.(rom|json)$/, ".map");

if (str.endsWith(sMapFile, ".map")) {

var sMapName = path.basename(sMapFile);

fs.readFile(sMapFile, {encoding: "utf8"}, function(err, str) {
var sMapData = null;
if (err) {
/*
Expand Down Expand Up @@ -612,7 +616,7 @@ FileDump.prototype.loadMap = function(sFilePath, done)
nBias = parseInt(sValue, 16);
continue;
default:
done(new Error("unrecognized symbol type (" + sType + ") in MAP file: " + sMapFile), null);
done(new Error("unrecognized symbol type (" + sType + ") in MAP file: " + sMapName), null);
return;
}
if (sID != sSymbol) {
Expand All @@ -624,7 +628,7 @@ FileDump.prototype.loadMap = function(sFilePath, done)
aSymbols[sID] = aValue;
continue;
}
done(new Error("unrecognized line (" + s + ") in MAP file: " + sMapFile), null);
done(new Error("unrecognized line (" + s + ") in MAP file: " + sMapName), null);
return;
}
sMapData = JSON.stringify(aSymbols);
Expand Down Expand Up @@ -692,6 +696,9 @@ FileDump.prototype.convertToJSON = function(done)
*/
FileDump.prototype.convertToFile = function(sOutputFile, fOverwrite)
{
if (sOutputFile && !this.fLocal) {
sOutputFile = path.join(this.sServerRoot, sOutputFile);
}
if (this.sFormat != DumpAPI.FORMAT.ROM) {
var obj = this;
this.buildJSON();
Expand Down
2 changes: 1 addition & 1 deletion modules/htmlout/lib/httpapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ HTTPAPI.processDumpAPI = function(req, res)
if (req.query[DumpAPI.QUERY.DECIMAL]) {
fDecimal = (req.query[DumpAPI.QUERY.DECIMAL] == "true");
}
var file = new FileDump(sFormat, fComments, fDecimal, sServerRoot);
var file = new FileDump(sFormat, fComments, fDecimal, 0, 0, sServerRoot);
file.loadFile(sFile, 0, 0, function(err) {
HTTPAPI.dumpFile(err, file, res);
});
Expand Down
Loading

0 comments on commit d260c20

Please sign in to comment.