Always parse GTK/GDK/GSK_DEBUG env vars and make some entries available in non-debug mode

Currently GTK can be built with G_ENABLE_DEBUG which enables various debug code and parsing
of those env vars, or without, which instead of parsing them prints a warning if they are set.
While building with G_ENABLE_DEBUG isn't strictly needed it's the only way to make GTK_DEBUG=interactive work,
which is a nice thing to have always.

This enables parsing of those env vars in any case and allows specific values being marked as also
available when not built with G_ENABLE_DEBUG (interactive for example). If not built with G_ENABLE_DEBUG
then all unavailable values will be marked as such in the help output and a note is added that
GTK needs to be built with G_ENABLE_DEBUG to use them, which should help discoverability.
This commit is contained in:
Christoph Reiter 2020-11-14 08:49:17 +01:00
parent f4e1c271ea
commit afc73c38ce
5 changed files with 39 additions and 37 deletions

View File

@ -11,9 +11,9 @@ environment variables.
### GTK_DEBUG {#GTK_Debug-Options}
Unless GTK has been configured with `-Ddebug=false`, this variable
can be set to a list of debug options, which cause GTK to print out
different types of debugging information.
This variable can be set to a list of debug options, which cause GTK to
print out different types of debugging information. Some of these options
are only available when GTK has been configured with `-Ddebug=true`.
actions
: Actions and menu models
@ -141,9 +141,9 @@ The `loaders.cache` file is generated by the
### GDK_DEBUG
Unless GTK has been configured with `-Ddebug=false`, this variable
can be set to a list of debug options, which cause GDK to print out
different types of debugging information.
This variable can be set to a list of debug options, which cause GDK to
print out different types of debugging information. Some of these options
are only available when GTK has been configured with `-Ddebug=true`.
cursor
: Information about cursor objects (only win32)
@ -191,10 +191,9 @@ to obtain a list of all supported debug options.
### GSK_DEBUG {#GSK-Debug-Options}
Unless GTK has been configured with `-Ddebug=false`,
this variable can be set to a list of debug options,
which cause GSK to print out different types of debugging
information.
This variable can be set to a list of debug options, which cause GSK to
print out different types of debugging information. Some of these options
are only available when GTK has been configured with `-Ddebug=true`.
renderer
: General renderer information

View File

@ -45,6 +45,7 @@ typedef struct
const char *key;
guint value;
const char *help;
gboolean always_enabled;
} GdkDebugKey;
guint gdk_parse_debug_var (const char *variable,

View File

@ -128,7 +128,6 @@ static int gdk_initialized = 0; /* 1 if the library is initi
* 0 otherwise.
*/
#ifdef G_ENABLE_DEBUG
static const GdkDebugKey gdk_debug_keys[] = {
{ "misc", GDK_DEBUG_MISC, "Miscellaneous information" },
{ "events", GDK_DEBUG_EVENTS, "Information about events" },
@ -152,7 +151,6 @@ static const GdkDebugKey gdk_debug_keys[] = {
{ "vulkan-validate", GDK_DEBUG_VULKAN_VALIDATE, "Load the Vulkan validation layer" },
{ "default-settings",GDK_DEBUG_DEFAULT_SETTINGS, "Force default values for xsettings" },
};
#endif
#ifdef G_HAS_CONSTRUCTORS
@ -212,6 +210,13 @@ gdk_parse_debug_var (const char *variable,
const char *q;
gboolean invert;
gboolean help;
gboolean debug_enabled;
#ifdef G_ENABLE_DEBUG
debug_enabled = TRUE;
#else
debug_enabled = FALSE;
#endif
string = g_getenv (variable);
if (string == NULL)
@ -237,21 +242,25 @@ gdk_parse_debug_var (const char *variable,
}
else
{
char *val = g_strndup (p, q - p);
for (i = 0; i < nkeys; i++)
{
if (strlen (keys[i].key) == q - p &&
g_ascii_strncasecmp (keys[i].key, p, q - p) == 0)
{
if (!debug_enabled && !keys[i].always_enabled)
{
fprintf (stderr, "\"%s\" is only available when building GTK with G_ENABLE_DEBUG. See %s=help\n",
val, variable);
break;
}
result |= keys[i].value;
break;
}
}
if (i == nkeys)
{
char *val = g_strndup (p, q - p);
fprintf (stderr, "Unrecognized value \"%s\". Try %s=help\n", val, variable);
g_free (val);
}
fprintf (stderr, "Unrecognized value \"%s\". Try %s=help\n", val, variable);
g_free (val);
}
p = q;
@ -267,11 +276,17 @@ gdk_parse_debug_var (const char *variable,
max_width += 4;
fprintf (stderr, "Supported %s values:\n", variable);
for (i = 0; i < nkeys; i++)
fprintf (stderr, " %s%*s%s\n", keys[i].key, (int)(max_width - strlen (keys[i].key)), " ", keys[i].help);
for (i = 0; i < nkeys; i++) {
fprintf (stderr, " %s%*s%s", keys[i].key, (int)(max_width - strlen (keys[i].key)), " ", keys[i].help);
if (!debug_enabled && !keys[i].always_enabled)
fprintf (stderr, " [unavailable]");
fprintf (stderr, "\n");
}
fprintf (stderr, " %s%*s%s\n", "all", max_width - 3, " ", "Enable all values");
fprintf (stderr, " %s%*s%s\n", "help", max_width - 4, " ", "Print this help");
fprintf (stderr, "\nMultiple values can be given, separated by : or space.\n");
if (!debug_enabled)
fprintf (stderr, "Values marked as [unavailable] are only accessible if GTK is built with G_ENABLE_DEBUG.\n");
}
if (invert)
@ -279,7 +294,10 @@ gdk_parse_debug_var (const char *variable,
guint all_flags = 0;
for (i = 0; i < nkeys; i++)
all_flags |= keys[i].value;
{
if (debug_enabled || keys[i].always_enabled)
all_flags |= keys[i].value;
}
result = all_flags & (~result);
}
@ -294,14 +312,9 @@ gdk_pre_parse (void)
gdk_ensure_resources ();
#ifdef G_ENABLE_DEBUG
_gdk_debug_flags = gdk_parse_debug_var ("GDK_DEBUG",
gdk_debug_keys,
G_N_ELEMENTS (gdk_debug_keys));
#else
if (g_getenv ("GDK_DEBUG"))
g_warning ("GDK_DEBUG set but ignored because GTK isn't built with G_ENABLE_DEBUG");
#endif /* G_ENABLE_DEBUG */
#ifndef G_HAS_CONSTRUCTORS
stash_desktop_startup_notification_id ();

View File

@ -1,7 +1,6 @@
#include "gskdebugprivate.h"
#include "gdk/gdk-private.h"
#ifdef G_ENABLE_DEBUG
static const GdkDebugKey gsk_debug_keys[] = {
{ "renderer", GSK_DEBUG_RENDERER, "General renderer information" },
{ "cairo", GSK_DEBUG_CAIRO, "Cairo renderer information" },
@ -17,14 +16,12 @@ static const GdkDebugKey gsk_debug_keys[] = {
{ "vulkan-staging-image", GSK_DEBUG_VULKAN_STAGING_IMAGE, "Use a staging image for Vulkan texture upload" },
{ "vulkan-staging-buffer", GSK_DEBUG_VULKAN_STAGING_BUFFER, "Use a staging buffer for Vulkan texture upload" }
};
#endif
static guint gsk_debug_flags;
static void
init_debug_flags (void)
{
#ifdef G_ENABLE_DEBUG
static volatile gsize gsk_debug_flags__set;
if (g_once_init_enter (&gsk_debug_flags__set))
@ -35,7 +32,6 @@ init_debug_flags (void)
g_once_init_leave (&gsk_debug_flags__set, TRUE);
}
#endif
}
gboolean

View File

@ -244,7 +244,6 @@ gtk_simulate_touchscreen (void)
return (gtk_get_debug_flags () & GTK_DEBUG_TOUCHSCREEN) != 0;
}
#ifdef G_ENABLE_DEBUG
static const GdkDebugKey gtk_debug_keys[] = {
{ "keybindings", GTK_DEBUG_KEYBINDINGS, "Information about keyboard shortcuts" },
{ "modules", GTK_DEBUG_MODULES, "Information about modules and extensions" },
@ -260,12 +259,11 @@ static const GdkDebugKey gtk_debug_keys[] = {
{ "builder", GTK_DEBUG_BUILDER, "Trace GtkBuilder operation" },
{ "builder-objects", GTK_DEBUG_BUILDER_OBJECTS, "Log unused GtkBuilder objects" },
{ "no-css-cache", GTK_DEBUG_NO_CSS_CACHE, "Disable style property cache" },
{ "interactive", GTK_DEBUG_INTERACTIVE, "Enable the GTK inspector" },
{ "interactive", GTK_DEBUG_INTERACTIVE, "Enable the GTK inspector", TRUE },
{ "touchscreen", GTK_DEBUG_TOUCHSCREEN, "Pretend the pointer is a touchscreen" },
{ "snapshot", GTK_DEBUG_SNAPSHOT, "Generate debug render nodes" },
{ "accessibility", GTK_DEBUG_A11Y, "Information about accessibility state changes" },
};
#endif /* G_ENABLE_DEBUG */
/* This checks to see if the process is running suid or sgid
* at the current time. If so, we dont allow GTK to be initialized.
@ -546,15 +544,10 @@ do_pre_parse_initialization (void)
gdk_pre_parse ();
#ifdef G_ENABLE_DEBUG
debug_flags[0].flags = gdk_parse_debug_var ("GTK_DEBUG",
gtk_debug_keys,
G_N_ELEMENTS (gtk_debug_keys));
any_display_debug_flags_set = debug_flags[0].flags > 0;
#else
if (g_getenv ("GTK_DEBUG"))
g_warning ("GTK_DEBUG set but ignored because GTK isn't built with G_ENABLE_DEBUG");
#endif /* G_ENABLE_DEBUG */
env_string = g_getenv ("GTK_SLOWDOWN");
if (env_string)