Is installing a GTK debug binary the only way to effectively debug a GTK/X11 crash?
An otherwise normal activate function
static void activate (GtkApplication* app, gpointer user_data) {
GtkWidget *lwindow;
GtkWidget *rwindow;
lwindow = gtk_application_window_new(app);
rwindow = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (lwindow), "Left Panel");
gtk_window_set_title (GTK_WINDOW (rwindow), "Right Panel");
GdkDisplay * display; GListModel* monitors;
display = gdk_display_get_default();
monitors = gdk_display_get_monitors(display);
GdkMonitor * monitor = (GdkMonitor *) g_list_model_get_item(monitors, 0);
GdkMonitor * monitor2 = (GdkMonitor *) g_list_model_get_item(monitors, 1); //1 2 for 3 displays, 0 1 for 2
GtkCssProvider * cssProvider = gtk_css_provider_new();
gtk_css_provider_load_from_path(cssProvider, "styling.css");
gtk_style_context_add_provider_for_display(gtk_widget_get_display(lwindow), GTK_STYLE_PROVIDER(cssProvider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_style_context_add_provider_for_display(gtk_widget_get_display(rwindow), GTK_STYLE_PROVIDER(cssProvider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
make_toggles(lwindow, (unsigned char) 0);
make_toggles(rwindow, (unsigned char) 1);
update_toggles();
if (pthread_create(&thread_id, NULL, updateThread, NULL)) {
log_perror("GTK could not create thread");
exit(-1);
}
gtk_window_fullscreen_on_monitor(GTK_WINDOW(rwindow), monitor);
gtk_window_fullscreen_on_monitor(GTK_WINDOW(lwindow), monitor2);
gtk_window_present(GTK_WINDOW(lwindow));
gtk_window_present(GTK_WINDOW(rwindow));
}
crashes on gtk_window_present(GTK_WINDOW(lwindow))
, if the following is uncommented in make_toggles for the lwindow:
if (!type) {
gtk_widget_set_vexpand(box_row, FALSE);
GtkWidget * vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
utility = gtk_toggle_button_new();
label = gtk_label_new("Soufflerie"); gtk_label_set_wrap(GTK_LABEL(label), TRUE);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
gtk_button_set_child(GTK_BUTTON(utility), label);
gtk_widget_add_css_class(utility, "ctrl_btn");
gtk_widget_set_margin_start(utility, 65); gtk_widget_set_margin_top(utility, 30);
g_signal_connect(utility, "toggled", G_CALLBACK(utility_toggle), NULL);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(utility), TRUE);
gtk_box_append(GTK_BOX(vbox), utility);
GtkWidget * shutdown_ = gtk_button_new();
label = gtk_label_new(SHUTDOWN_NAME); gtk_label_set_wrap(GTK_LABEL(label), TRUE); gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
gtk_widget_add_css_class(shutdown_, "ctrl_btn");
gtk_button_set_child(GTK_BUTTON(shutdown_), label);
gtk_widget_set_margin_start(shutdown_, 65); gtk_widget_set_margin_top(shutdown_, 40); gtk_widget_set_margin_bottom(shutdown_, 40);
g_signal_connect(shutdown_, "clicked", G_CALLBACK(utility_toggle), NULL);
gtk_box_append(GTK_BOX(vbox), shutdown_);
gtk_box_append(GTK_BOX(box_row), vbox);
}
Essentially I am adding two buttons to the final row of buttons boxrow
in lwindow. The code worked fine on a different linux system with a slightly different monitor setup (3 monitors instead of 2), but crashes on this system. There is no way to get a backtrace by typing bt full
on gdb. This is GTK 4.10.
The X11 error that shows up is:
test:42726): Gdk-WARNING **: 19:29:30.795: The program 'test' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadIDChoice (invalid resource ID chosen for this connection)'.
(Details: serial 441 error_code 14 request_code 1 (core protocol) minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the GDK_SYNCHRONIZE environment
variable to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
My second question is: I set GDK_SYNCRHONIZE to 1 globally and in gdb as well, and didn’t notice a difference in my debugging experience. Is there a proper way to do this?