Skip to content

[GTK] Report the Java caller of a GTK message in debug mode - #3606

Merged
akurtakov merged 1 commit into
eclipse-platform:masterfrom
akurtakov:gtk-debug-log-writer
Sep 21, 2026
Merged

akurtakov merged 1 commit into
eclipse-platform:masterfrom
akurtakov:gtk-debug-log-writer

Conversation

@akurtakov

Copy link
Copy Markdown
Member

GTK is built with G_LOG_USE_STRUCTURED, so its messages never reach the g_log_set_handler() handler in Device.logProc, leaving no way to tell which SWT call provoked a GTK warning. Install a GLib writer function, the only hook that sees them, and append the Java stack to each message.

A writer is process-wide, fatal to set twice and impossible to unset, so it is installed only for a device in debug mode. Nothing changes without SWT_DEBUG=1 or DeviceData.debug.

Assisted-by: Anthropic Claude Code (claude-opus-5[1m])

GTK is built with G_LOG_USE_STRUCTURED, so its messages never reach the
g_log_set_handler() handler in Device.logProc, leaving no way to tell
which SWT call provoked a GTK warning. Install a GLib writer function,
the only hook that sees them, and append the Java stack to each message.

A writer is process-wide, fatal to set twice and impossible to unset, so
it is installed only for a device in debug mode. Nothing changes without
SWT_DEBUG=1 or DeviceData.debug.

Assisted-by: Anthropic Claude Code (claude-opus-5[1m])
@akurtakov

Copy link
Copy Markdown
Member Author

With this change Gtk/Gdk logging is converted to reports like:

(Eclipse:583760): Gtk-WARNING **: 17:39:46.322: Trying to measure GtkLabel 0x7f6ffd782a10 for height of 18, but it needs at least 19
java.lang.Error
	at org.eclipse.swt.graphics.Device.logWriterProc(Device.java:939)
	at org.eclipse.swt.internal.gtk4.GTK4.gtk_widget_size_allocate(Native Method)
	at org.eclipse.swt.widgets.Widget.gtk_widget_size_allocate(Widget.java:2762)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:1181)
	at org.eclipse.swt.widgets.Label.setBounds(Label.java:561)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:1002)
	at org.eclipse.swt.layout.FormLayout.layout(FormLayout.java:363)
	at org.eclipse.swt.layout.FormLayout.layout(FormLayout.java:292)
	at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1951)
	at org.eclipse.swt.widgets.Composite.setBounds(Composite.java:1743)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:1042)
	at org.eclipse.swt.layout.GridLayout.layout(GridLayout.java:697)
	at org.eclipse.swt.layout.GridLayout.layout(GridLayout.java:201)
	at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1951)
	at org.eclipse.swt.widgets.Composite.layout(Composite.java:1234)
	at org.eclipse.swt.widgets.Composite.layout(Composite.java:1186)
	at org.eclipse.swt.widgets.Composite.layout(Composite.java:1142)
	at org.eclipse.jface.dialogs.TitleAreaDialog.layoutForNewMessage(TitleAreaDialog.java:502)
	at org.eclipse.jface.dialogs.TitleAreaDialog.lambda$0(TitleAreaDialog.java:175)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5902)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1659)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1685)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1664)
	at org.eclipse.swt.widgets.Shell.resizeBounds(Shell.java:2402)
	at org.eclipse.swt.widgets.Shell.gtk_size_allocate(Shell.java:1956)
	at org.eclipse.swt.widgets.Widget.notifyProc(Widget.java:2590)
	at org.eclipse.swt.widgets.Display.notifyProc(Display.java:6223)
	at org.eclipse.swt.internal.gtk.GTK.gtk_window_set_default_size(Native Method)
	at org.eclipse.swt.widgets.Shell.setBounds(Shell.java:2501)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:1002)
	at org.eclipse.jface.window.Window.initializeBounds(Window.java:759)
	at org.eclipse.jface.dialogs.Dialog.initializeBounds(Dialog.java:719)
	at org.eclipse.jface.window.Window.create(Window.java:430)
	at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1090)
	at org.eclipse.jface.window.Window.open(Window.java:783)
	at org.eclipse.ui.internal.ide.ChooseWorkspaceDialog.prompt(ChooseWorkspaceDialog.java:137)
	at org.eclipse.ui.internal.ide.application.IDEApplication.showChooseWorkspaceDialog(IDEApplication.java:643)
	at org.eclipse.ui.internal.ide.application.IDEApplication.promptForWorkspace(IDEApplication.java:566)
	at org.eclipse.ui.internal.ide.application.IDEApplication.promptAndSetWorkspace(IDEApplication.java:356)
	at org.eclipse.ui.internal.ide.application.IDEApplication.checkInstanceLocation(IDEApplication.java:286)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:179)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:219)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:149)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:115)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:467)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:298)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:615)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:563)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1415)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1387)

that make it easier to spot how to actually come to a problem.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The process-global writer conflicts with GLib’s application-only contract, and the hard-linked APIs exceed SWT’s minimum supported GLib version.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 High severity

Open (2)
What changed in this PR

Adds Java stack traces to GTK structured log messages when SWT debugging is enabled.

Changes:

  • Installs a process-wide GLib log writer in debug mode.
  • Adds GLib JNI bindings and generated native wrappers.
File Description
Device.java Installs and handles the debug log writer.
OS.java Declares GLib writer APIs.
os.c Adds generated JNI implementations.
os_stats.h Registers generated native function identifiers.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results (linux)

  109 files  ±0    109 suites  ±0   15m 4s ⏱️ -23s
4 633 tests ±0  4 399 ✅ ±0  234 💤 ±0  0 ❌ ±0 
3 473 runs  ±0  3 384 ✅ ±0   89 💤 ±0  0 ❌ ±0 

Results for commit bd989c2. ± Comparison against base commit 2fb03ab.

@akurtakov
akurtakov merged commit 0b562bf into eclipse-platform:master Sep 21, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants