Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

GDB netproxy restructured as a shim #40

Merged
merged 20 commits into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 38 additions & 39 deletions debuggers/gdb/gdbdebugger.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/**
* GDB Debugger plugin for Cloud9
*
* @author Dan Armendariz <danallan AT cs DOT harvard DOT edu>
* @author Dan Armendariz <danallan AT cs DOT berkeley DOT edu>
*/
define(function(require, exports, module) {
main.consumes = [
"Plugin", "debugger", "c9", "panels", "settings", "dialog.error"
"Plugin", "c9", "debugger", "dialog.error", "fs", "panels", "settings"
];
main.provides = ["gdbdebugger"];
return main;

function main(options, imports, register) {
var Plugin = imports.Plugin;
var debug = imports["debugger"];
var c9 = imports.c9;
var debug = imports["debugger"];
var fs = imports["fs"];
var panels = imports.panels;
var settings = imports.settings;
var showError = imports["dialog.error"].show;
Expand All @@ -35,9 +36,6 @@ define(function(require, exports, module) {

var TYPE = "gdb";

// proxy location
var PROXY = require("text!./netproxy.js");

var attached = false;

var state, // debugger state
Expand All @@ -60,8 +58,20 @@ define(function(require, exports, module) {
["autoshow", "true"]
]);
});


// must register ASAP, or debugger won't be ready for reconnects
debug.registerDebugger(TYPE, plugin);

// writeFile root is workspace directory, unless given ~
var shimPath = "~/bin/c9gdbshim.js";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am looking for a way to make writefile call on demand, and only when missing
would it be ok to write this to ~/.c9/bin/c9gdbshim-<md5>.js instead, or is this supposed to be used from other places too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MD5 or other versioning would be fine, so long as we have a symlink or some other mechanism that always points to the latest revision from a known path, e.g., ~/.c9/bin/c9gdbshim.js is a link for ~/.c9/bin/c9gdbhim-<md5>.js?

var shim = require("text!./shim.js");
fs.writeFile(shimPath, shim, "utf8", function(err) {
if (err) {
// unregister the debugger on error
debug.unregisterDebugger(TYPE, plugin);
return console.log("Error writing gdb shim: " + err);
}
});
}

/***** Helper Functions *****/
Expand Down Expand Up @@ -164,21 +174,20 @@ define(function(require, exports, module) {
setState("stopped");
emit("frameActivate", { frame: topFrame });

if (content.err === "segfault") {
showError("GDB has detected a segmentation fault and execution has stopped!");
emit("exception", { frame: topFrame }, new Error("Segfault!"));
btnResume.$ext.style.display = "none";
btnSuspend.$ext.style.display = "inline-block";
btnSuspend.setAttribute("disabled", true);
btnStepOut.setAttribute("disabled", true);
btnStepInto.setAttribute("disabled", true);
btnStepOver.setAttribute("disabled", true);
var frameObj = { frame: topFrame, frames: stack };

if (content.err === "signal" && content.signal.name !== "SIGINT") {
var e = "Process received " + content.signal.name + ": "
+ content.signal.text;
showError(e);
emit("exception", frameObj, new Error(content.signal.name));
}
else {
emit("break", { frame: topFrame, frames: stack });
if (stack.length == 1)
btnStepOut.setAttribute("disabled", true);
emit("break", frameObj);
}

if (stack.length == 1)
btnStepOut.setAttribute("disabled", true);
}

/*
Expand Down Expand Up @@ -206,24 +215,13 @@ define(function(require, exports, module) {
/***** Methods *****/

function getProxySource(process){
var max_depth = (process.runner[0].maxdepth) ?
process.runner[0].maxdepth : 50;

var bin;
try {
bin = process.insertVariables(process.runner[0].executable);
}
catch(e) {
bin = "!";
}

return PROXY
.replace(/\/\/.*/g, "")
.replace(/[\n\r]/g, "")
.replace(/\{PATH\}/, c9.workspaceDir)
.replace(/\{MAX_DEPTH\}/, max_depth)
.replace(/\{BIN\}/, bin)
.replace(/\{PORT\}/, process.runner[0].debugport);
var socketpath = Path.join(c9.home, "/.c9/gdbdebugger.socket");
return {
source: null,
socketpath: process.runner[0].socketpath || socketpath,
retryInverval: process.runner[0].retryInterval || 300,
retries: process.runner[0].retryCount || 1000
};
}

function attach(s, reconnect, callback) {
Expand Down Expand Up @@ -439,8 +437,8 @@ define(function(require, exports, module) {
function evaluate(expression, frame, global, disableBreak, callback) {
var args = {
"exp": expression,
"f": (frame.index == null) ? 0 : frame.index,
"t": (frame.thread == null) ? 1 : frame.thread,
"f": (!frame || frame.index == null) ? 0 : frame.index,
"t": (!frame || frame.thread == null) ? 1 : frame.thread,
};
proxy.sendCommand("eval", args, function(err, reply) {
if (err)
Expand Down Expand Up @@ -471,6 +469,7 @@ define(function(require, exports, module) {
}

function setBreakpoint(bp, callback) {
bp.data.fullpath = Path.join(c9.workspaceDir, bp.data.path);
proxy.sendCommand("bp-set", bp.data, function(err, reply) {
if (err)
return callback && callback(err);
Expand Down
2 changes: 1 addition & 1 deletion debuggers/gdb/lib/GDBProxyService.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var GDBProxyService = module.exports = function(socket, haltHandler) {
this.$send = function(args) {
args = JSON.stringify(args);
var msg = ["Content-Length:", args.length, "\r\n\r\n", args].join("");
this.$socket.send(msg);
this.$socket && this.$socket.send(msg);
};

/*
Expand Down
Loading