[gjs/wip/package: 82/83] Package: add gdb integration



commit 14990146b165796f51866d4e342e460ce0c26ef8
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue May 7 23:51:32 2013 +0200

    Package: add gdb integration
    
    Allow running the program with --debug to replace the running instance
    with a GDB.
    Hopefully, by the time package is initialized, the program hasn't
    crashed yet.

 modules/package.js |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/modules/package.js b/modules/package.js
index f1f7823..ea5fbe9 100644
--- a/modules/package.js
+++ b/modules/package.js
@@ -137,6 +137,8 @@ function init(params) {
     imports.searchPath.unshift(moduledir);
     GIRepository.Repository.prepend_search_path(girpath);
     GIRepository.Repository.prepend_library_path(libpath);
+
+    _parseArgs();
 }
 
 /**
@@ -220,3 +222,21 @@ function loadResource(name) {
 
     Gio.Resource.load(GLib.build_filenamev([pkg.pkgdatadir, name]))._register();
 }
+
+function _spawnGDB(debugIndex) {
+    ARGV.splice(debugIndex, 1);
+
+    try {
+        System.exec(['gdb', '--args', 'gjs', System.programInvocationName].concat(ARGV));
+    } catch(e) {
+        print('Failed to launch debugger: ' + e.message);
+        System.exit(1);
+    }
+}
+
+function _parseArgs() {
+    for (let i = 0; i < ARGV.length; i++) {
+        if (ARGV[i] == '--debug')
+            _spawnGDB(i);
+    }
+}


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