[gjs] bring back debugger module, with a nativeTrap() which calls G_BREAKPOINT()



commit 665f2835e77e60078a7a87a93b041aa62995ecea
Author: Joe Shaw <joeshaw litl com>
Date:   Thu Feb 3 11:39:06 2011 -0500

    bring back debugger module, with a nativeTrap() which calls G_BREAKPOINT()
    
    Makes it easier to debug code which crosses between JS and C by
    firing traps (to be caught in gdb) from JS code.

 Makefile-modules.am |   14 ++++++++++++-
 modules/debugger.c  |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 modules/debugger.h  |   39 ++++++++++++++++++++++++++++++++++++
 3 files changed, 107 insertions(+), 1 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index 30b19c6..c43b2d8 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -12,7 +12,7 @@ dist_gjsjs_DATA +=		\
 	modules/dbus.js		\
 	modules/promise.js
 
-gjsnative_LTLIBRARIES += console.la gi.la langNative.la mainloop.la gettextNative.la dbusNative.la cairoNative.la
+gjsnative_LTLIBRARIES += console.la debugger.la gi.la langNative.la mainloop.la gettextNative.la dbusNative.la cairoNative.la
 
 JS_NATIVE_MODULE_CFLAGS =	\
         $(AM_CFLAGS)		\
@@ -116,6 +116,18 @@ console_la_SOURCES =		\
 	modules/console.h	\
 	modules/console.c
 
+debugger_la_CFLAGS = 				\
+	$(JS_NATIVE_MODULE_CFLAGS)
+debugger_la_LIBADD = \
+	libgjs-gi.la				\
+	$(JS_NATIVE_MODULE_LIBADD)
+debugger_la_LDFLAGS = 				\
+	$(JS_NATIVE_MODULE_LDFLAGS)
+
+debugger_la_SOURCES =		\
+	modules/debugger.h	\
+	modules/debugger.c
+
 dbusNative_la_SOURCES =	\
 	modules/dbus-exports.h	\
 	modules/dbus-values.h	\
diff --git a/modules/debugger.c b/modules/debugger.c
new file mode 100644
index 0000000..f168ba5
--- /dev/null
+++ b/modules/debugger.c
@@ -0,0 +1,55 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (c) 2011  litl, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <string.h>
+
+#include <jsapi.h>
+
+#include <glib.h>
+#include <gjs/gjs.h>
+
+#include "debugger.h"
+
+static JSBool
+gjs_debugger_native_trap(JSContext *cx, JSObject *obj, uintN argc,
+                         jsval *argv, jsval *retval)
+{
+    G_BREAKPOINT();
+
+    return JS_TRUE;
+}
+
+JSBool
+gjs_define_debugger_stuff(JSContext *context,
+                          JSObject  *module_obj)
+{
+    if (!JS_DefineFunction(context, module_obj,
+                           "nativeTrap",
+                           gjs_debugger_native_trap,
+                           1, GJS_MODULE_PROP_FLAGS))
+        return JS_FALSE;
+
+    return JS_TRUE;
+}
+
+GJS_REGISTER_NATIVE_MODULE("debugger", gjs_define_debugger_stuff);
diff --git a/modules/debugger.h b/modules/debugger.h
new file mode 100644
index 0000000..2c61edc
--- /dev/null
+++ b/modules/debugger.h
@@ -0,0 +1,39 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (c) 2008  litl, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __GJS_DEBUGGER_H__
+#define __GJS_DEBUGGER_H__
+
+#include <config.h>
+#include <glib.h>
+
+#include <jsapi.h>
+
+G_BEGIN_DECLS
+
+JSBool        gjs_define_debugger_stuff    (JSContext      *context,
+                                            JSObject       *in_object);
+
+G_END_DECLS
+
+#endif  /* __GJS_DEBUGGER_H__ */



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