Skip to content

Commit 6e2f11e

Browse files
committed
cinnamon-global.c: Add the capability to print the js stack when a
C critical or warning occurs. This is useful for some difficult-to-trace library warnings that are triggered by JS code. ref: 0aae4bc
1 parent 0aae4bc commit 6e2f11e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/cinnamon-global.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
#define GNOME_DESKTOP_USE_UNSTABLE_API
2020
#include <libcinnamon-desktop/gnome-systemd.h>
2121

22+
// Warnings generated by C libraries (clutter, muffin, glib, etc...) can be
23+
// difficult to trace when they originate at the javascript level.
24+
//
25+
// Enabling (1) will print the current js call stack after the warning is logged.
26+
// Note, this may result in the stack being printed twice in some instances, as we
27+
// already do this for specific warnings elsewhere. It may be nicer to get rid of
28+
// those others (in cjs and st-widget I think) and permanently enable the logging
29+
// here.
30+
#define PRINT_JS_STACK_FOR_C_WARNINGS 0
31+
2232
static CinnamonGlobal *the_object = NULL;
2333

2434
enum {
@@ -60,6 +70,8 @@ G_DEFINE_TYPE(CinnamonGlobal, cinnamon_global, G_TYPE_OBJECT);
6070

6171
static guint cinnamon_global_signals [LAST_SIGNAL] = { 0 };
6272

73+
static void setup_log_handler (CinnamonGlobal *global);
74+
6375
static void
6476
cinnamon_global_set_property(GObject *object,
6577
guint prop_id,
@@ -234,6 +246,8 @@ cinnamon_global_init (CinnamonGlobal *global)
234246

235247
global->settings = g_settings_new ("org.cinnamon");
236248

249+
setup_log_handler (global);
250+
237251
setup_notifications_service (global);
238252

239253
global->ui_scale = 1;
@@ -908,6 +922,28 @@ _cinnamon_global_get_gjs_context (CinnamonGlobal *global)
908922
return global->js_context;
909923
}
910924

925+
static void
926+
log_handler (const char *domain,
927+
GLogLevelFlags level,
928+
const char *message,
929+
gpointer data)
930+
{
931+
g_log_default_handler (domain, level, message, data);
932+
933+
if ((level & (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)) != 0) {
934+
gjs_dumpstack ();
935+
}
936+
}
937+
938+
static void
939+
setup_log_handler (CinnamonGlobal *global)
940+
{
941+
if (!PRINT_JS_STACK_FOR_C_WARNINGS)
942+
return;
943+
944+
g_log_set_default_handler (log_handler, NULL);
945+
}
946+
911947
static guint32
912948
get_current_time_maybe_roundtrip (CinnamonGlobal *global)
913949
{

0 commit comments

Comments
 (0)