250 lines
7.8 KiB
Diff
250 lines
7.8 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 | 61 +++++++++++++++++++++++++++++++++++++++++-------------
|
||
|
src/shell-global.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++
|
||
|
src/shell-global.h | 4 ++++
|
||
|
3 files changed, 103 insertions(+), 14 deletions(-)
|
||
|
|
||
|
diff --git a/src/main.c b/src/main.c
|
||
|
index dca5f64..aa2f4dc 100644
|
||
|
--- a/src/main.c
|
||
|
+++ b/src/main.c
|
||
|
@@ -374,14 +374,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));
|
||
|
}
|
||
|
|
||
|
@@ -483,6 +483,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,
|
||
|
@@ -614,6 +650,7 @@ main (int argc, char **argv)
|
||
|
g_autoptr (GFile) automation_script = NULL;
|
||
|
g_autofree char *cwd = NULL;
|
||
|
GError *error = NULL;
|
||
|
+ const char *debug_flags;
|
||
|
int ecode = EXIT_SUCCESS;
|
||
|
|
||
|
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
||
|
@@ -649,17 +686,6 @@ main (int argc, char **argv)
|
||
|
g_setenv ("GJS_DEBUG_OUTPUT", "stderr", TRUE);
|
||
|
g_setenv ("GJS_DEBUG_TOPICS", "JS ERROR;JS LOG", TRUE);
|
||
|
|
||
|
- 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);
|
||
|
- }
|
||
|
-
|
||
|
if (script_path)
|
||
|
automation_script = g_file_new_for_commandline_arg_and_cwd (script_path, cwd);
|
||
|
|
||
|
@@ -668,10 +694,16 @@ main (int argc, char **argv)
|
||
|
* resolve internal modules.
|
||
|
*/
|
||
|
_shell_global_init ("session-mode", session_mode,
|
||
|
+ "debug-flags", debug_flags,
|
||
|
"force-animations", force_animations,
|
||
|
"automation-script", automation_script,
|
||
|
NULL);
|
||
|
|
||
|
+ g_signal_connect (shell_global_get (), "notify::debug-flags",
|
||
|
+ G_CALLBACK (global_notify_debug_flags), NULL);
|
||
|
+
|
||
|
+ setup_debug_signal_listners ();
|
||
|
+
|
||
|
/* Setup Meta _after_ the Shell global to avoid GjsContext
|
||
|
* iterating on the main loop once Meta starts adding events
|
||
|
*/
|
||
|
@@ -681,7 +713,8 @@ main (int argc, char **argv)
|
||
|
return EXIT_FAILURE;
|
||
|
}
|
||
|
|
||
|
- 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 ();
|
||
|
diff --git a/src/shell-global.c b/src/shell-global.c
|
||
|
index 66b2f57..2a6e7fd 100644
|
||
|
--- a/src/shell-global.c
|
||
|
+++ b/src/shell-global.c
|
||
|
@@ -62,6 +62,7 @@ struct _ShellGlobal {
|
||
|
Display *xdisplay;
|
||
|
|
||
|
char *session_mode;
|
||
|
+ char *debug_flags;
|
||
|
|
||
|
XserverRegion input_region;
|
||
|
|
||
|
@@ -123,6 +124,7 @@ enum {
|
||
|
PROP_SWITCHEROO_CONTROL,
|
||
|
PROP_FORCE_ANIMATIONS,
|
||
|
PROP_AUTOMATION_SCRIPT,
|
||
|
+ PROP_DEBUG_FLAGS,
|
||
|
|
||
|
N_PROPS
|
||
|
};
|
||
|
@@ -255,6 +257,9 @@ shell_global_set_property(GObject *object,
|
||
|
case PROP_AUTOMATION_SCRIPT:
|
||
|
g_set_object (&global->automation_script, g_value_get_object (value));
|
||
|
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;
|
||
|
@@ -347,6 +352,9 @@ shell_global_get_property(GObject *object,
|
||
|
case PROP_AUTOMATION_SCRIPT:
|
||
|
g_value_set_object (value, global->automation_script);
|
||
|
break;
|
||
|
+ case PROP_DEBUG_FLAGS:
|
||
|
+ g_value_set_string (value, global->debug_flags);
|
||
|
+ break;
|
||
|
default:
|
||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||
|
break;
|
||
|
@@ -704,6 +712,13 @@ shell_global_class_init (ShellGlobalClass *klass)
|
||
|
G_TYPE_FILE,
|
||
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | 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);
|
||
|
}
|
||
|
|
||
|
@@ -2004,3 +2019,40 @@ shell_global_get_app_usage (ShellGlobal *global)
|
||
|
global->app_usage = g_object_new (SHELL_TYPE_APP_USAGE, NULL);
|
||
|
return global->app_usage;
|
||
|
}
|
||
|
+
|
||
|
+/**
|
||
|
+ * 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 8399330..683f75a 100644
|
||
|
--- a/src/shell-global.h
|
||
|
+++ b/src/shell-global.h
|
||
|
@@ -99,6 +99,10 @@ ShellAppSystem * shell_global_get_app_system (ShellGlobal *global);
|
||
|
|
||
|
ShellAppUsage * shell_global_get_app_usage (ShellGlobal *global);
|
||
|
|
||
|
+const char * shell_global_get_debug_flags (ShellGlobal *global);
|
||
|
+void shell_global_set_debug_flags (ShellGlobal *global,
|
||
|
+ const char *debug_flags);
|
||
|
+
|
||
|
G_END_DECLS
|
||
|
|
||
|
#endif /* __SHELL_GLOBAL_H__ */
|