238 lines
7.4 KiB
Diff
238 lines
7.4 KiB
Diff
From: =?utf-8?b?Ik1hcmNvIFRyZXZpc2FuIChUcmV2acOxbyki?= <mail@3v1n0.net>
|
|
Date: Tue, 24 Oct 2017 02:15:13 +0200
|
|
Subject: global: make possible to set debug-flags dynamically
|
|
|
|
Adding {set,get}_debug_flags functions to the shell global object to
|
|
make possible to set this easily from looking class, making it easier
|
|
for developers and users to debug without having to restart the shell
|
|
with environment variables.
|
|
|
|
Debug flags in main are updated when the "debug-flags" property is
|
|
changed. I'm keeping this as a string-list so that it's easier to update.
|
|
|
|
https://bugzilla.gnome.org/show_bug.cgi?id=789377
|
|
|
|
Bug-GNOME: https://bugzilla.gnome.org/show_bug.cgi?id=789377
|
|
Forwarded: https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/6
|
|
---
|
|
src/main.c | 60 ++++++++++++++++++++++++++++++++++++++++++------------
|
|
src/shell-global.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++
|
|
src/shell-global.h | 3 +++
|
|
3 files changed, 101 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/src/main.c b/src/main.c
|
|
index ac20be2..726afe9 100644
|
|
--- a/src/main.c
|
|
+++ b/src/main.c
|
|
@@ -276,14 +276,14 @@ shell_a11y_init (void)
|
|
}
|
|
|
|
static void
|
|
-shell_init_debug (const char *debug_env)
|
|
+shell_update_debug (const char *debug_string)
|
|
{
|
|
static const GDebugKey keys[] = {
|
|
{ "backtrace-warnings", SHELL_DEBUG_BACKTRACE_WARNINGS },
|
|
{ "backtrace-segfaults", SHELL_DEBUG_BACKTRACE_SEGFAULTS },
|
|
};
|
|
|
|
- _shell_debug = g_parse_debug_string (debug_env, keys,
|
|
+ _shell_debug = g_parse_debug_string (debug_string, keys,
|
|
G_N_ELEMENTS (keys));
|
|
}
|
|
|
|
@@ -385,6 +385,42 @@ dump_gjs_stack_on_signal (int signo)
|
|
_tracked_signals[signo] = TRUE;
|
|
}
|
|
|
|
+static void
|
|
+reset_signal_handler_to_default (int signo)
|
|
+{
|
|
+ signal (signo, SIG_DFL);
|
|
+ _tracked_signals[signo] = FALSE;
|
|
+}
|
|
+
|
|
+static void
|
|
+setup_debug_signal_listners (void)
|
|
+{
|
|
+ dump_gjs_stack_on_signal (SIGABRT);
|
|
+ dump_gjs_stack_on_signal (SIGFPE);
|
|
+ dump_gjs_stack_on_signal (SIGIOT);
|
|
+ dump_gjs_stack_on_signal (SIGTRAP);
|
|
+
|
|
+ if ((_shell_debug & SHELL_DEBUG_BACKTRACE_SEGFAULTS))
|
|
+ {
|
|
+ dump_gjs_stack_on_signal (SIGBUS);
|
|
+ dump_gjs_stack_on_signal (SIGSEGV);
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ reset_signal_handler_to_default (SIGBUS);
|
|
+ reset_signal_handler_to_default (SIGSEGV);
|
|
+ }
|
|
+}
|
|
+
|
|
+static void
|
|
+global_notify_debug_flags (GObject *gobject,
|
|
+ GParamSpec *pspec,
|
|
+ gpointer data)
|
|
+{
|
|
+ shell_update_debug (shell_global_get_debug_flags (shell_global_get ()));
|
|
+ setup_debug_signal_listners ();
|
|
+}
|
|
+
|
|
static gboolean
|
|
list_modes (const char *option_name,
|
|
const char *value,
|
|
@@ -506,6 +542,7 @@ main (int argc, char **argv)
|
|
{
|
|
g_autoptr (MetaContext) context = NULL;
|
|
GError *error = NULL;
|
|
+ const char *debug_flags;
|
|
int ecode = EXIT_SUCCESS;
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
|
@@ -543,7 +580,8 @@ main (int argc, char **argv)
|
|
g_setenv ("GJS_DEBUG_OUTPUT", "stderr", TRUE);
|
|
g_setenv ("GJS_DEBUG_TOPICS", "JS ERROR;JS LOG", TRUE);
|
|
|
|
- shell_init_debug (g_getenv ("SHELL_DEBUG"));
|
|
+ debug_flags = g_getenv ("SHELL_DEBUG");
|
|
+ shell_update_debug (debug_flags);
|
|
|
|
shell_dbus_init (meta_context_is_replacing (context));
|
|
shell_a11y_init ();
|
|
@@ -557,18 +595,14 @@ main (int argc, char **argv)
|
|
if (session_mode == NULL)
|
|
session_mode = is_gdm_mode ? (char *)"gdm" : (char *)"user";
|
|
|
|
- _shell_global_init ("session-mode", session_mode, NULL);
|
|
+ _shell_global_init ("session-mode", session_mode,
|
|
+ "debug-flags", debug_flags,
|
|
+ NULL);
|
|
|
|
- dump_gjs_stack_on_signal (SIGABRT);
|
|
- dump_gjs_stack_on_signal (SIGFPE);
|
|
- dump_gjs_stack_on_signal (SIGIOT);
|
|
- dump_gjs_stack_on_signal (SIGTRAP);
|
|
+ g_signal_connect (shell_global_get (), "notify::debug-flags",
|
|
+ G_CALLBACK (global_notify_debug_flags), NULL);
|
|
|
|
- if ((_shell_debug & SHELL_DEBUG_BACKTRACE_SEGFAULTS))
|
|
- {
|
|
- dump_gjs_stack_on_signal (SIGBUS);
|
|
- dump_gjs_stack_on_signal (SIGSEGV);
|
|
- }
|
|
+ setup_debug_signal_listners ();
|
|
|
|
shell_profiler_init ();
|
|
|
|
diff --git a/src/shell-global.c b/src/shell-global.c
|
|
index 0ccdb10..1676208 100644
|
|
--- a/src/shell-global.c
|
|
+++ b/src/shell-global.c
|
|
@@ -59,6 +59,7 @@ struct _ShellGlobal {
|
|
Display *xdisplay;
|
|
|
|
char *session_mode;
|
|
+ char *debug_flags;
|
|
|
|
XserverRegion input_region;
|
|
|
|
@@ -109,6 +110,7 @@ enum {
|
|
PROP_FRAME_TIMESTAMPS,
|
|
PROP_FRAME_FINISH_TIMESTAMP,
|
|
PROP_SWITCHEROO_CONTROL,
|
|
+ PROP_DEBUG_FLAGS,
|
|
|
|
N_PROPS
|
|
};
|
|
@@ -234,6 +236,9 @@ shell_global_set_property(GObject *object,
|
|
}
|
|
}
|
|
break;
|
|
+ case PROP_DEBUG_FLAGS:
|
|
+ shell_global_set_debug_flags (global, g_value_get_string (value));
|
|
+ break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
break;
|
|
@@ -316,6 +321,8 @@ shell_global_get_property(GObject *object,
|
|
break;
|
|
case PROP_SWITCHEROO_CONTROL:
|
|
g_value_set_object (value, global->switcheroo_control);
|
|
+ case PROP_DEBUG_FLAGS:
|
|
+ g_value_set_string (value, global->debug_flags);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
@@ -641,6 +648,13 @@ shell_global_class_init (ShellGlobalClass *klass)
|
|
G_TYPE_DBUS_PROXY,
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
+ props[PROP_DEBUG_FLAGS] =
|
|
+ g_param_spec_string ("debug-flags",
|
|
+ "Debug Flags",
|
|
+ "The debugging flags",
|
|
+ NULL,
|
|
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
|
+
|
|
g_object_class_install_properties (gobject_class, N_PROPS, props);
|
|
}
|
|
|
|
@@ -1858,3 +1872,40 @@ _shell_global_locate_pointer (ShellGlobal *global)
|
|
{
|
|
g_signal_emit (global, shell_global_signals[LOCATE_POINTER], 0);
|
|
}
|
|
+
|
|
+/**
|
|
+ * shell_global_get_debug_flags:
|
|
+ * @global: a #ShellGlobal
|
|
+ *
|
|
+ * Returns: (transfer none): The current debug flags
|
|
+ */
|
|
+const gchar *
|
|
+shell_global_get_debug_flags (ShellGlobal *global)
|
|
+{
|
|
+ g_return_val_if_fail (SHELL_IS_GLOBAL (global), NULL);
|
|
+
|
|
+ return global->debug_flags;
|
|
+}
|
|
+
|
|
+/**
|
|
+ * shell_global_set_debug_flags:
|
|
+ * @global: a #ShellGlobal
|
|
+ * @debug_flags: (nullable): A string for debugging flags
|
|
+ *
|
|
+ * Updates the debugging flags at runtime as the one set using the SHELL_DEBUG
|
|
+ * environment variables. Currently we support 'backtrace-warnings' and
|
|
+ * 'backtrace-segfaults' keys.
|
|
+ */
|
|
+void
|
|
+shell_global_set_debug_flags (ShellGlobal *global,
|
|
+ const char *debug_flags)
|
|
+{
|
|
+ g_return_if_fail (SHELL_IS_GLOBAL (global));
|
|
+
|
|
+ if (g_strcmp0 (global->debug_flags, debug_flags) != 0)
|
|
+ {
|
|
+ g_free (global->debug_flags);
|
|
+ global->debug_flags = g_strdup (debug_flags);
|
|
+ g_object_notify (G_OBJECT (global), "debug-flags");
|
|
+ }
|
|
+}
|
|
diff --git a/src/shell-global.h b/src/shell-global.h
|
|
index 8d8238c..04c59d1 100644
|
|
--- a/src/shell-global.h
|
|
+++ b/src/shell-global.h
|
|
@@ -88,6 +88,9 @@ void shell_global_set_persistent_state (ShellGlobal *global,
|
|
GVariant * shell_global_get_persistent_state (ShellGlobal *global,
|
|
const char *property_type,
|
|
const char *property_name);
|
|
+const char * shell_global_get_debug_flags (ShellGlobal *global);
|
|
+void shell_global_set_debug_flags (ShellGlobal *global,
|
|
+ const char *debug_flags);
|
|
|
|
G_END_DECLS
|
|
|