Permalink
Browse files

Implementing commands: debug and undebug

  • Loading branch information...
1 parent 176516a commit 7fb03e8ea2700ad4b3b4430b6deb3f3e35c5f2c1 @janodvarko janodvarko committed Mar 26, 2013
@@ -12,8 +12,12 @@ define([
"firebug/lib/dom",
"firebug/lib/url",
"firebug/lib/locale",
+ "firebug/debugger/debuggerLib",
+ "firebug/debugger/breakpoints/breakpointStore",
],
-function(FBTrace, Obj, Domplate, Reps, StackFrame, SourceFile, Events, Css, Dom, Url, Locale) {
+function(FBTrace, Obj, Domplate, Reps, StackFrame, SourceFile, Events, Css, Dom,
+ Url, Locale, DebuggerLib, BreakpointStore) {
+
with (Domplate) {
// ********************************************************************************************* //
@@ -113,12 +117,24 @@ var FunctionMonitor = Obj.extend(Firebug.Module,
var script = SourceFile.findScriptForFunctionInContext(context, fn);
if (script)
{
- Trace.sysout("functionMonitor.monitorScript; " + script.url + ", " + script.startLine);
+ Trace.sysout("functionMonitor.monitorScript; " + script.url + ", " +
+ script.startLine, fn);
if (mode == "debug")
{
- // xxxHonza: how to easily set a breakpoint here and do not worry about
- // server side correction?
+ var location = {line: script.startLine, url: script.url};
+
+ // If the first line of the script contains no code, slide down to
+ // the nextline the has runnable code.
+ location = DebuggerLib.getNextExecutableLine(context, location);
+
+ // Create a new breakpoint.
+ tool.setBreakpoint(context, location.url, location.line - 1,
+ function(response, bpClient)
+ {
+ BreakpointStore.addBreakpoint(bpClient.location.url,
+ bpClient.location.line - 1);
+ });
}
else if (mode == "monitor")
{
@@ -133,12 +149,19 @@ var FunctionMonitor = Obj.extend(Firebug.Module,
var script = SourceFile.findScriptForFunctionInContext(context, fn);
if (script)
{
- Trace.sysout("functionMonitor.unmonitorScript; " + fn, scriptInfo);
+ Trace.sysout("functionMonitor.unmonitorScript; " + script.url + ", " +
+ script.startLine, fn);
if (mode == "debug")
- tool.removeBreakpoint(context, script.url, script.startLine);
+ {
+ var location = {line: script.startLine, url: script.url};
+ location = DebuggerLib.getNextExecutableLine(context, location);
+ BreakpointStore.removeBreakpoint(location.url, location.line - 1);
+ }
else if (mode == "monitor")
+ {
this.unmonitor(context, scriptInfo.sourceFile.href, scriptInfo.lineNo);
+ }
}
},
@@ -27,6 +27,7 @@ const BP_ERROR = 16;
const BP_TRACE = 32; // BP used to initiate traceCalls
var Trace = FBTrace.to("DBG_BREAKPOINTSTORE");
+var TraceError = FBTrace.to("DBG_ERRORS");
// ********************************************************************************************* //
// Breakpoint Store
@@ -203,10 +204,16 @@ var BreakpointStore = Obj.extend(Firebug.Module,
addBreakpoint: function(url, lineNo)
{
+ if (!url || !lineNo)
+ {
+ TraceError.sysout("breakpointStore.addBreakpoint; ERROR invalid arguments " +
+ "url: " + url + ", lineNo: " + lineNo);
+ return;
+ }
+
if (this.findBreakpoint(url, lineNo))
{
- if (FBTrace.DBG_ERRORS)
- FBTrace.sysout("breakpointStore.addBreakpoint; ERROR There is alread a bp");
+ TraceError.sysout("breakpointStore.addBreakpoint; ERROR There is already a bp");
return;
}
@@ -13,6 +13,8 @@ var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
+Cu["import"]("resource://gre/modules/devtools/dbg-server.jsm");
+
// Debugees
var dglobalWeakMap = new WeakMap();
@@ -78,6 +80,120 @@ DebuggerLib.getDebuggeeGlobal = function(context, global)
};
// ********************************************************************************************* //
+// Local Access (hack for easier transition to JSD2/RDP)
+
+// xxxHonza: for now duplicated in debuggerClientModule, will be only here soon.
+
+/**
+ * The next step is to make this method asynchronous to be closer to the
+ * remote debugging requirements. Of course, it should use Promise
+ * as the return value.
+ *
+ * @param {Object} context
+ * @param {Object} actorId
+ */
+DebuggerLib.getObject = function(context, actorId)
+{
+ try
+ {
+ // xxxHonza: access server side objects, of course even hacks needs
+ // good architecure, refactor.
+ // First option: implement a provider used by UI widgets (e.g. DomTree)
+ // See: https://bugzilla.mozilla.org/show_bug.cgi?id=837723
+ var threadActor = this.getThreadActor(context);
+ var actor = threadActor.threadLifetimePool.get(actorId);
+
+ if (!actor && threadActor._pausePool)
+ actor = threadActor._pausePool.get(actorId);
+
+ if (!actor)
+ return null;
+
+ return this.unwrapObject(actor.obj);
+ }
+ catch (e)
+ {
+ TraceError.sysout("debuggerClientModule.getObject; EXCEPTION " + e, e);
+ }
+}
+
+DebuggerLib.getThreadActor = function(context)
+{
+ try
+ {
+ var conn = DebuggerServer._connections["conn0."];
+ var tabActor = conn.rootActor._tabActors.get(context.browser);
+ return tabActor.threadActor;
+ }
+ catch (e)
+ {
+ TraceError.sysout("debuggerClientModule.getObject; EXCEPTION " + e, e);
+ }
+}
+
+DebuggerLib.unwrapObject = function(obj)
+{
+ if (!obj)
+ return null;
+
+ // xxxHonza: use DebuggerLib.unwrapDebuggeeValue();
+ if (typeof(obj.unsafeDereference) != "undefined")
+ {
+ return obj.unsafeDereference();
+ }
+ else
+ {
+ TraceError.sysout("debuggerClientModule.getObject; You need patch from " +
+ "bug 837723");
+ }
+
+ return null;
+}
+
+// ********************************************************************************************* //
+// Executable Lines
+
+DebuggerLib.getNextExecutableLine = function(context, aLocation)
+{
+ var threadClient = this.getThreadActor(context);
+
+ var scripts = threadClient.dbg.findScripts(aLocation);
+ if (scripts.length == 0)
+ return;
+
+ for (var i=0; i<scripts.length; i++)
+ {
+ var script = scripts[i];
+ var offsets = script.getLineOffsets(aLocation.line);
+ if (offsets.length > 0)
+ return aLocation;
+ }
+
+ var scripts = threadClient.dbg.findScripts({
+ url: aLocation.url,
+ line: aLocation.line,
+ innermost: true
+ });
+
+ for (var i=0; i<scripts.length; i++)
+ {
+ var script = scripts[i];
+ var offsets = script.getAllOffsets();
+ for (var line = aLocation.line; line < offsets.length; ++line)
+ {
+ if (offsets[line])
+ {
+ return {
+ url: aLocation.url,
+ line: line,
+ column: aLocation.column
+ };
+ }
+ }
+ }
+}
+
+// ********************************************************************************************* //
// Local helpers
/**
@@ -421,12 +421,21 @@ var DebuggerTool = Obj.extend(Firebug.Module,
FBTrace.sysout("debuggerTool.setBreakpoint; Can't set a breakpoint.");
return;
}
+
var self = this;
var doSetBreakpoint = function _doSetBreakpoint(response, bpClient)
{
+ var actualLocation = response.actualLocation;
+
Trace.sysout("debuggerTool.onSetBreakpoint; " + bpClient.location.url + " (" +
bpClient.location.line + ")", bpClient);
+ if (actualLocation && actualLocation.line != bpClient.location.line)
+ {
+ // To be found when it needs removing.
+ bpClient.location.line = actualLocation.line;
+ }
+
// TODO: error logging?
// Store breakpoint clients so, we can use the actors to remove the
@@ -439,11 +448,9 @@ var DebuggerTool = Obj.extend(Firebug.Module,
// FF 19: uses same breakpoint client object for a executable line and
// all non-executable lines above that, so doesn't store breakpoint client
// objects if there is already one with same actor.
- if (!self.breakpointAcotrExists(context, bpClient))
+ if (!self.breakpointActorExists(context, bpClient))
context.breakpointClients.push(bpClient);
- // TODO: update the UI?
-
if (callback)
callback(response, bpClient);
};
@@ -550,39 +557,7 @@ var DebuggerTool = Obj.extend(Firebug.Module,
}
},
- removeDuplicatedBpInstances: function(context, bpClient)
- {
- var clients = context.breakpointClients;
- var client, location;
- if (!clients)
- return;
-
- var url = bpClient.location.url;
- var lineNumber = bpClient.location.line;
- var bpIndex;
- for (var i=0; i < clients.length; i++)
- {
- client = clients[i];
- location = client.location;
- if (location.url == url && location.line == lineNumber)
- {
- if(bpIndex || bpIndex == 0)
- {
- clients[bpIndex].remove(function()
- {
- });
- clients.splice(bpIndex, 1);
- bpIndex = --i;
- }
- else
- {
- bpIndex = i;
- }
- }
- }
- },
-
- breakpointAcotrExists: function(context, bpClient)
+ breakpointActorExists: function(context, bpClient)
{
var clients = context.breakpointClients;
if (!clients)
Oops, something went wrong.

0 comments on commit 7fb03e8

Please sign in to comment.