Skip to content

Commit

Permalink
gjs - jsrdbg integration
Browse files Browse the repository at this point in the history
  • Loading branch information
swojtasiak committed Apr 13, 2015
1 parent 31a1e86 commit 391de09
Show file tree
Hide file tree
Showing 11 changed files with 419 additions and 13 deletions.
6 changes: 5 additions & 1 deletion Makefile.am
Expand Up @@ -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 = \
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion gjs-1.0.pc.in
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gjs-internals-1.0.pc.in
Expand Up @@ -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
Expand Down
53 changes: 51 additions & 2 deletions gjs/console.cpp
Expand Up @@ -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;
Expand All @@ -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 }
};

Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions gjs/context.cpp
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions gjs/context.h
Expand Up @@ -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);
Expand Down

0 comments on commit 391de09

Please sign in to comment.