Permalink
Browse files

gjs - jsrdbg integration

  • Loading branch information...
swojtasiak committed Apr 12, 2015
1 parent 31a1e86 commit 391de095ec5345af0b95c8f7586b09a15037da66
Showing with 419 additions and 13 deletions.
  1. +5 −1 Makefile.am
  2. +1 −0 configure.ac
  3. +1 −1 gjs-1.0.pc.in
  4. +1 −1 gjs-internals-1.0.pc.in
  5. +51 −2 gjs/console.cpp
  6. +7 −0 gjs/context.cpp
  7. +2 −0 gjs/context.h
  8. +275 −0 gjs/debugger.cpp
  9. +72 −0 gjs/debugger.h
  10. +1 −0 gjs/gjs.h
  11. +3 −8 gjs/jsapi-util.cpp
View
@@ -27,6 +27,7 @@ gjs_module_includedir = $(includedir)/gjs-1.0
########################################################################
nobase_gjs_public_include_HEADERS = \
gjs/context.h \
+ gjs/debugger.h \
gjs/gjs.h
nobase_gjs_module_include_HEADERS = \
@@ -89,6 +90,7 @@ lib_LTLIBRARIES += libgjs.la
libgjs_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(GJS_CFLAGS) \
+ $(JSRDBG_CFLAGS) \
$(gjs_directory_defines)\
-I$(top_srcdir)/gi \
-DGJS_COMPILATION
@@ -100,7 +102,8 @@ libgjs_la_LDFLAGS = \
-no-undefined \
-rdynamic
libgjs_la_LIBADD = \
- $(GJS_LIBS)
+ $(GJS_LIBS) \
+ $(JSRDBG_LIBS)
if ENABLE_GTK
libgjs_la_CPPFLAGS += $(GJS_GTK_CFLAGS)
@@ -110,6 +113,7 @@ endif
libgjs_la_SOURCES = \
gjs/byteArray.cpp \
gjs/context.cpp \
+ gjs/debugger.cpp \
gjs/importer.cpp \
gjs/gi.h \
gjs/gi.cpp \
View
@@ -87,6 +87,7 @@ PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= glib_required_version])
PKG_CHECK_MODULES([GJS], [$gjs_packages])
PKG_CHECK_MODULES([GJS_GDBUS], [$gjs_gdbus_packages])
PKG_CHECK_MODULES([GJSTESTS], [$gjstests_packages])
+PKG_CHECK_MODULES([JSRDBG], [libjsrdbg >= 0.0.2])
# Optional cairo dep (enabled by default)
AC_ARG_WITH(cairo,
View
@@ -10,7 +10,7 @@ gjs_console=${bindir}/gjs-console
Cflags: -I${includedir}/gjs-1.0
Requires: gobject-2.0
-Requires.private: gobject-introspection-1.0 mozjs-24
+Requires.private: gobject-introspection-1.0 mozjs-24 libjsrdbg
Libs: -L${libdir} -lgjs
Name: gjs-1.0
View
@@ -9,7 +9,7 @@ datadir=@datadir@
jsdir=@gjsjsdir@
Cflags: -I${includedir}/gjs-1.0
-Requires: gjs-1.0 gobject-introspection-1.0 mozjs-24
+Requires: gjs-1.0 gobject-introspection-1.0 mozjs-24 libjsrdbg
Name: gjs-internals-1.0
Description: Internal API for gjs (for modules and embedders); uses mozjs
View
@@ -28,7 +28,13 @@
#include <gjs/gjs.h>
#include <gjs/coverage.h>
+#include <gjs/debugger.h>
+static gboolean debugger_enabled = FALSE;
+static gboolean debugger_suspended = FALSE;
+static gboolean debugger_continuation = FALSE;
+static char *debugger_host = NULL;
+static gint debugger_port = 8089;
static char **include_path = NULL;
static char **coverage_paths = NULL;
static char *coverage_output_path = NULL;
@@ -39,6 +45,11 @@ static GOptionEntry entries[] = {
{ "coverage-path", 'C', 0, G_OPTION_ARG_STRING_ARRAY, &coverage_paths, "Add the filename FILE to the list of files to generate coverage info for", "FILE" },
{ "coverage-output", 0, 0, G_OPTION_ARG_STRING, &coverage_output_path, "Write coverage output to a directory DIR. This option is mandatory when using --coverage-path", "DIR", },
{ "include-path", 'I', 0, G_OPTION_ARG_STRING_ARRAY, &include_path, "Add the directory DIR to the list of directories to search for js files.", "DIR" },
+ { "debugger", 'D', 0, G_OPTION_ARG_NONE, &debugger_enabled, "Enables the JS remote debugger.", NULL },
+ { "debugger-suspended", 'S', 0, G_OPTION_ARG_NONE, &debugger_suspended, "Starts debugger in suspended state.", NULL },
+ { "debugger-continuation", 'R', 0, G_OPTION_ARG_NONE, &debugger_continuation, "Continues execution when all clients have disconnected.", NULL },
+ { "debugger-host", 'H', 0, G_OPTION_ARG_STRING, &debugger_host, "A host the debugger should be bound to.", NULL },
+ { "debugger-port", 'P', 0, G_OPTION_ARG_INT, &debugger_port, "A post the debugger should be bound to.", NULL },
{ NULL }
};
@@ -62,6 +73,7 @@ main(int argc, char **argv)
GOptionContext *context;
GError *error = NULL;
GjsContext *js_context;
+ GjsDebugger *js_debugger = NULL;
GjsCoverage *coverage = NULL;
char *script;
const char *filename;
@@ -117,6 +129,37 @@ main(int argc, char **argv)
"program-name", program_name,
NULL);
+ if( debugger_enabled ) {
+
+ js_debugger = (GjsDebugger*) g_object_new(GJS_TYPE_DEBUGGER,
+ "host", debugger_host,
+ "port", debugger_port,
+ NULL);
+
+ GjsDebuggerEngineOptions options;
+ options.continuation = debugger_continuation;
+ options.suspend = debugger_suspended;
+ options.source_displacement = -1;
+
+ if( !gjs_debugger_install( js_debugger, js_context, "gjs-console", &options, &error ) ) {
+ g_printerr("Failed to install debugger for JSContext: %s\n", error->message);
+ g_clear_error(&error);
+ goto out;
+ }
+
+ if( !gjs_debugger_start( js_debugger, &error ) ) {
+ g_printerr("Failed to start JS debugger: %s\n", error->message);
+ g_clear_error(&error);
+ goto out;
+ }
+
+ g_print("Debugger is listening on port: %d\n", debugger_port);
+ if( debugger_suspended ) {
+ g_print("Application is suspended.\n");
+ }
+
+ }
+
if (coverage_paths) {
if (!coverage_output_path)
g_error("--coverage-output is required when taking coverage statistics");
@@ -148,8 +191,14 @@ main(int argc, char **argv)
/* Probably doesn't make sense to write statistics on failure */
if (coverage && code == 0)
- gjs_coverage_write_statistics(coverage,
- coverage_output_path);
+ gjs_coverage_write_statistics(coverage,
+ coverage_output_path);
+
+ if( debugger_enabled ) {
+ gjs_debugger_stop( js_debugger, &error );
+ gjs_debugger_uninstall( js_debugger, js_context, &error );
+ g_object_unref(js_debugger);
+ }
g_object_unref(js_context);
g_free(script);
View
@@ -626,6 +626,13 @@ gjs_context_get_native_context (GjsContext *js_context)
return js_context->context;
}
+void*
+gjs_context_get_native_global (GjsContext *js_context)
+{
+ g_return_val_if_fail(GJS_IS_CONTEXT(js_context), NULL);
+ return js_context->global;
+}
+
gboolean
gjs_context_eval(GjsContext *js_context,
const char *script,
View
@@ -69,6 +69,8 @@ void gjs_context_make_current (GjsContext *js_context);
void* gjs_context_get_native_context (GjsContext *js_context);
+void* gjs_context_get_native_global (GjsContext *js_context);
+
void gjs_context_print_stack_stderr (GjsContext *js_context);
void gjs_context_maybe_gc (GjsContext *context);
Oops, something went wrong.

0 comments on commit 391de09

Please sign in to comment.