mutter/debian/patches/global-make-possible-to-set-debug-flags-dynamically.patch
Ward Nakchbandi (Cosmic Fusion) ebb234de19 initial push
2023-06-27 00:18:37 +03:00

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 | 57 ++++++++++++++++++++++++++++++++++++++++++------------
src/shell-global.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
src/shell-global.h | 4 ++++
3 files changed, 101 insertions(+), 12 deletions(-)
diff --git a/src/main.c b/src/main.c
index d4988e9..a9ea4e9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -353,14 +353,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));
}
@@ -462,6 +462,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,
@@ -585,6 +621,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);
@@ -622,7 +659,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 ();
@@ -638,18 +676,13 @@ main (int argc, char **argv)
_shell_global_init ("session-mode", session_mode,
"force-animations", force_animations,
+ "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 aae9469..e4565b3 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -61,6 +61,7 @@ struct _ShellGlobal {
Display *xdisplay;
char *session_mode;
+ char *debug_flags;
XserverRegion input_region;
@@ -120,6 +121,7 @@ enum {
PROP_FRAME_FINISH_TIMESTAMP,
PROP_SWITCHEROO_CONTROL,
PROP_FORCE_ANIMATIONS,
+ PROP_DEBUG_FLAGS,
N_PROPS
};
@@ -249,6 +251,9 @@ shell_global_set_property(GObject *object,
case PROP_FORCE_ANIMATIONS:
global->force_animations = g_value_get_boolean (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;
@@ -338,6 +343,9 @@ shell_global_get_property(GObject *object,
case PROP_FORCE_ANIMATIONS:
g_value_set_boolean (value, global->force_animations);
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;
@@ -688,6 +696,13 @@ shell_global_class_init (ShellGlobalClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT| 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);
}
@@ -1988,3 +2003,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__ */