[gjs: 3/5] debugger: Break on first frame



commit 71bba979be028792b86bf1ab74053a8df957599d
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri Jul 13 18:12:12 2018 +0100

    debugger: Break on first frame
    
    ...instead of inserting a 'debugger;' statement at the start of every
    program. This is cleaner because it doesn't mess up the client program.

 gjs/console.cpp                                     | 14 +++-----------
 installed-tests/debugger/backtrace.debugger.output  |  5 ++---
 installed-tests/debugger/breakpoint.debugger.output |  1 -
 installed-tests/debugger/continue.debugger.output   |  3 +--
 installed-tests/debugger/delete.debugger.output     |  1 -
 installed-tests/debugger/detach.debugger.output     |  1 -
 installed-tests/debugger/down-up.debugger.output    |  1 -
 installed-tests/debugger/finish.debugger.output     |  1 -
 installed-tests/debugger/frame.debugger.output      |  1 -
 installed-tests/debugger/keys.debugger.output       |  1 -
 installed-tests/debugger/next.debugger.output       |  1 -
 installed-tests/debugger/print.debugger.output      |  1 -
 installed-tests/debugger/quit.debugger.output       |  1 -
 installed-tests/debugger/return.debugger.output     |  1 -
 installed-tests/debugger/set.debugger.output        |  1 -
 installed-tests/debugger/step.debugger              |  1 -
 installed-tests/debugger/step.debugger.output       |  3 ---
 installed-tests/debugger/throw.debugger.output      |  1 -
 installed-tests/debugger/until.debugger.output      |  1 -
 modules/_bootstrap/debugger.js                      | 12 +++++++++---
 20 files changed, 15 insertions(+), 37 deletions(-)
---
diff --git a/gjs/console.cpp b/gjs/console.cpp
index 1739d882..c2c9d524 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -346,18 +346,10 @@ main(int argc, char **argv)
         goto out;
     }
 
-    /* If we're debugging, set up the debugger and prepend a debugger statement
-     * to the script we're going to evaluate. The debugger statement will break
-     * and cause a debugger prompt to appear.
-     * TODO: This is not great, as it messes up column offsets on the first
-     * line of all scripts. It would be better to hook into a debugger event
-     * and interrupt on the first frame. */
-    if (debugging) {
+    /* If we're debugging, set up the debugger. It will break on the first
+     * frame. */
+    if (debugging)
         gjs_context_setup_debugger_console(js_context);
-        char* old_script = script;
-        script = g_strconcat("debugger;", old_script, nullptr);
-        g_free(old_script);
-    }
 
     /* evaluate the script */
     if (!gjs_context_eval(js_context, script, len,
diff --git a/installed-tests/debugger/backtrace.debugger.output 
b/installed-tests/debugger/backtrace.debugger.output
index 753d4fe4..7f8e0fe3 100644
--- a/installed-tests/debugger/backtrace.debugger.output
+++ b/installed-tests/debugger/backtrace.debugger.output
@@ -1,11 +1,10 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at backtrace.debugger.js:1:0
 db> backtrace
 #0    toplevel at backtrace.debugger.js:1:0
 db> c
-Debugger statement, toplevel at backtrace.debugger.js:1:9
+Debugger statement, toplevel at backtrace.debugger.js:1:0
 db> bt
-#0    toplevel at backtrace.debugger.js:1:9
+#0    toplevel at backtrace.debugger.js:1:0
 db> c
 Debugger statement, <anonymous>([object Array], 0, [object Array]) at backtrace.debugger.js:3:4
 db> where
diff --git a/installed-tests/debugger/breakpoint.debugger.output 
b/installed-tests/debugger/breakpoint.debugger.output
index ffd8710a..1d9bc498 100644
--- a/installed-tests/debugger/breakpoint.debugger.output
+++ b/installed-tests/debugger/breakpoint.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at breakpoint.debugger.js:1:0
 db> breakpoint 2
 Breakpoint 1 at breakpoint.debugger.js:2:0
 db> break 4
diff --git a/installed-tests/debugger/continue.debugger.output 
b/installed-tests/debugger/continue.debugger.output
index 38447a45..66d5c115 100644
--- a/installed-tests/debugger/continue.debugger.output
+++ b/installed-tests/debugger/continue.debugger.output
@@ -1,7 +1,6 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at continue.debugger.js:1:0
 db> continue
-Debugger statement, toplevel at continue.debugger.js:1:9
+Debugger statement, toplevel at continue.debugger.js:1:0
 db> cont
 Debugger statement, toplevel at continue.debugger.js:2:0
 db> c
diff --git a/installed-tests/debugger/delete.debugger.output b/installed-tests/debugger/delete.debugger.output
index 7047d3d7..af6ee6d0 100644
--- a/installed-tests/debugger/delete.debugger.output
+++ b/installed-tests/debugger/delete.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at delete.debugger.js:1:0
 db> b 2
 Breakpoint 1 at delete.debugger.js:2:0
 db> b 3
diff --git a/installed-tests/debugger/detach.debugger.output b/installed-tests/debugger/detach.debugger.output
index 5417796b..94199c3b 100644
--- a/installed-tests/debugger/detach.debugger.output
+++ b/installed-tests/debugger/detach.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at detach.debugger.js:1:0
 db> detach
 hi
 Program exited with code 0
diff --git a/installed-tests/debugger/down-up.debugger.output 
b/installed-tests/debugger/down-up.debugger.output
index 3ae26908..3f2fe430 100644
--- a/installed-tests/debugger/down-up.debugger.output
+++ b/installed-tests/debugger/down-up.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at down-up.debugger.js:1:0
 db> c
 Debugger statement, d() at down-up.debugger.js:14:4
 db> down
diff --git a/installed-tests/debugger/finish.debugger.output b/installed-tests/debugger/finish.debugger.output
index ae967996..2253b973 100644
--- a/installed-tests/debugger/finish.debugger.output
+++ b/installed-tests/debugger/finish.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at finish.debugger.js:1:0
 db> c
 Print me
 Debugger statement, foo() at finish.debugger.js:3:4
diff --git a/installed-tests/debugger/frame.debugger.output b/installed-tests/debugger/frame.debugger.output
index 83a8ff5d..e0853ae2 100644
--- a/installed-tests/debugger/frame.debugger.output
+++ b/installed-tests/debugger/frame.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at frame.debugger.js:1:0
 db> c
 Debugger statement, b() at frame.debugger.js:6:4
 db> frame 2
diff --git a/installed-tests/debugger/keys.debugger.output b/installed-tests/debugger/keys.debugger.output
index 7eb99138..42df6ae0 100644
--- a/installed-tests/debugger/keys.debugger.output
+++ b/installed-tests/debugger/keys.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at keys.debugger.js:1:0
 db> c
 Debugger statement, toplevel at keys.debugger.js:6:0
 db> keys a
diff --git a/installed-tests/debugger/next.debugger.output b/installed-tests/debugger/next.debugger.output
index e9a39427..9174da2e 100644
--- a/installed-tests/debugger/next.debugger.output
+++ b/installed-tests/debugger/next.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at next.debugger.js:1:0
 db> c
 Debugger statement, a() at next.debugger.js:2:4
 db> next
diff --git a/installed-tests/debugger/print.debugger.output b/installed-tests/debugger/print.debugger.output
index f9e4c063..2c128fbe 100644
--- a/installed-tests/debugger/print.debugger.output
+++ b/installed-tests/debugger/print.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at print.debugger.js:1:0
 db> c
 Debugger statement, toplevel at print.debugger.js:15:0
 db> # Simple types
diff --git a/installed-tests/debugger/quit.debugger.output b/installed-tests/debugger/quit.debugger.output
index 3ed984b7..7d691b2f 100644
--- a/installed-tests/debugger/quit.debugger.output
+++ b/installed-tests/debugger/quit.debugger.output
@@ -1,4 +1,3 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at quit.debugger.js:1:0
 db> q
 Program exited with code 0
diff --git a/installed-tests/debugger/return.debugger.output b/installed-tests/debugger/return.debugger.output
index f063d669..7d7ee44e 100644
--- a/installed-tests/debugger/return.debugger.output
+++ b/installed-tests/debugger/return.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at return.debugger.js:1:0
 db> b 2
 Breakpoint 1 at return.debugger.js:2:4
 db> b 6
diff --git a/installed-tests/debugger/set.debugger.output b/installed-tests/debugger/set.debugger.output
index 5b89910d..93d95fea 100644
--- a/installed-tests/debugger/set.debugger.output
+++ b/installed-tests/debugger/set.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at set.debugger.js:1:0
 db> # Currently the only option is "pretty" for pretty-printing. Set doesn't yet
 db> # allow setting variables in the program.
 db> c
diff --git a/installed-tests/debugger/step.debugger b/installed-tests/debugger/step.debugger
index df197150..69d43e96 100644
--- a/installed-tests/debugger/step.debugger
+++ b/installed-tests/debugger/step.debugger
@@ -9,4 +9,3 @@ s
 s
 s
 s
-s
diff --git a/installed-tests/debugger/step.debugger.output b/installed-tests/debugger/step.debugger.output
index 02092f2d..3a0ce627 100644
--- a/installed-tests/debugger/step.debugger.output
+++ b/installed-tests/debugger/step.debugger.output
@@ -1,7 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at step.debugger.js:1:0
-db> s
-toplevel at step.debugger.js:1:0
 db> s
 toplevel at step.debugger.js:10:0
 entered frame: a() at step.debugger.js:2:4
diff --git a/installed-tests/debugger/throw.debugger.output b/installed-tests/debugger/throw.debugger.output
index cabf14ba..248827d6 100644
--- a/installed-tests/debugger/throw.debugger.output
+++ b/installed-tests/debugger/throw.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at throw.debugger.js:1:18
 db> c
 Debugger statement, a() at throw.debugger.js:2:4
 db> throw 'foobar' + 3.14;
diff --git a/installed-tests/debugger/until.debugger.output b/installed-tests/debugger/until.debugger.output
index 856b85dc..b2a7c4ce 100644
--- a/installed-tests/debugger/until.debugger.output
+++ b/installed-tests/debugger/until.debugger.output
@@ -1,5 +1,4 @@
 GJS debugger. Type "help" for help
-Debugger statement, toplevel at until.debugger.js:1:0
 db> until 3
 toplevel at until.debugger.js:1:0
 1
diff --git a/modules/_bootstrap/debugger.js b/modules/_bootstrap/debugger.js
index 6c0f2265..357cb126 100644
--- a/modules/_bootstrap/debugger.js
+++ b/modules/_bootstrap/debugger.js
@@ -12,8 +12,8 @@
  * SpiderMonkey source.
  *
  * To run it: gjs -d path/to/file.js
- * Execution will stop at debugger statements (one will be inserted at the start
- * of the program), and you'll get a prompt.
+ * Execution will stop at debugger statements, and you'll get a prompt before
+ * the first frame is executed.
  */
 
 // Debugger state.
@@ -703,6 +703,12 @@ function repl() {
     }
 }
 
+function onInitialEnterFrame(frame) {
+    print('GJS debugger. Type "help" for help');
+    topFrame = focusedFrame = frame;
+    return repl();
+}
+
 var dbg = new Debugger();
 dbg.onNewPromise = function({promiseID, promiseAllocationSite}) {
     const site = promiseAllocationSite.toString().split('\n')[0];
@@ -746,4 +752,4 @@ dbg.onExceptionUnwind = function(frame, value) {
 
 var debuggeeGlobalWrapper = dbg.addDebuggee(debuggee);
 
-print('GJS debugger. Type "help" for help');
+setUntilRepl(dbg, 'onEnterFrame', onInitialEnterFrame);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]