|
Packit |
ae235b |
|
|
Packit |
ae235b |
<html>
|
|
Packit |
ae235b |
<head>
|
|
Packit |
ae235b |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
Packit |
ae235b |
<title>Running GLib Applications: GLib Reference Manual</title>
|
|
Packit |
ae235b |
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
|
|
Packit |
ae235b |
<link rel="home" href="index.html" title="GLib Reference Manual">
|
|
Packit |
ae235b |
<link rel="up" href="glib.html" title="GLib Overview">
|
|
Packit |
ae235b |
<link rel="prev" href="glib-compiling.html" title="Compiling GLib Applications">
|
|
Packit |
ae235b |
<link rel="next" href="glib-changes.html" title="Changes to GLib">
|
|
Packit |
ae235b |
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
|
|
Packit |
ae235b |
<link rel="stylesheet" href="style.css" type="text/css">
|
|
Packit |
ae235b |
</head>
|
|
Packit |
ae235b |
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Running GLib Applications
|
|
Packit |
ae235b |
Running GLib Applications —
|
|
Packit |
ae235b |
How to run and debug your GLib application
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Running and debugging GLib Applications
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Environment variables
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
The runtime behaviour of GLib applications can be influenced by a
|
|
Packit |
ae235b |
number of environment variables.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Standard variables.
|
|
Packit |
ae235b |
GLib reads standard environment variables like LANG ,
|
|
Packit |
ae235b |
PATH , HOME , TMPDIR ,
|
|
Packit |
ae235b |
TZ and LOGNAME .
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
XDG directories.
|
|
Packit |
ae235b |
GLib consults the environment variables XDG_DATA_HOME ,
|
|
Packit |
ae235b |
XDG_DATA_DIRS , XDG_CONFIG_HOME ,
|
|
Packit |
ae235b |
XDG_CONFIG_DIRS , XDG_CACHE_HOME and
|
|
Packit |
ae235b |
XDG_RUNTIME_DIR for the various XDG directories.
|
|
Packit |
ae235b |
For more information, see the XDG basedir spec.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
G_FILENAME_ENCODING .
|
|
Packit |
ae235b |
This environment variable can be set to a comma-separated list of character
|
|
Packit |
ae235b |
set names. GLib assumes that filenames are encoded in the first character
|
|
Packit |
ae235b |
set from that list rather than in UTF-8. The special token "@locale" can be
|
|
Packit |
ae235b |
used to specify the character set for the current locale.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
G_BROKEN_FILENAMES .
|
|
Packit |
ae235b |
If this environment variable is set, GLib assumes that filenames are in
|
|
Packit |
ae235b |
the locale encoding rather than in UTF-8. G_FILENAME_ENCODING takes
|
|
Packit |
ae235b |
priority over G_BROKEN_FILENAMES.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
G_MESSAGES_PREFIXED .
|
|
Packit |
ae235b |
A list of log levels for which messages should be prefixed by the
|
|
Packit |
ae235b |
program name and PID of the application. The default is to prefix
|
|
Packit |
ae235b |
everything except G_LOG_LEVEL_MESSAGE and
|
|
Packit |
ae235b |
G_LOG_LEVEL_INFO .
|
|
Packit |
ae235b |
The possible values are
|
|
Packit |
ae235b |
error ,
|
|
Packit |
ae235b |
warning ,
|
|
Packit |
ae235b |
critical ,
|
|
Packit |
ae235b |
message ,
|
|
Packit |
ae235b |
info and
|
|
Packit |
ae235b |
debug .
|
|
Packit |
ae235b |
You can also use the special values
|
|
Packit |
ae235b |
all and
|
|
Packit |
ae235b |
help .
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
This environment variable only affects the default log handler,
|
|
Packit |
ae235b |
g_log_default_handler().
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
G_MESSAGES_DEBUG .
|
|
Packit |
ae235b |
A space-separated list of log domains for which informational
|
|
Packit |
ae235b |
and debug messages should be printed. By default, these
|
|
Packit |
ae235b |
messages are not printed.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
You can also use the special value all .
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
This environment variable only affects the default log handler,
|
|
Packit |
ae235b |
g_log_default_handler().
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
G_DEBUG .
|
|
Packit |
ae235b |
This environment variable can be set to a list of debug options,
|
|
Packit |
ae235b |
which cause GLib to print out different types of debugging information.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
fatal-warnings
|
|
Packit |
ae235b |
Causes GLib to abort the program at the first call
|
|
Packit |
ae235b |
to g_warning() or g_critical().
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
fatal-criticals
|
|
Packit |
ae235b |
Causes GLib to abort the program at the first call
|
|
Packit |
ae235b |
to g_critical().
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
gc-friendly
|
|
Packit |
ae235b |
Newly allocated memory that isn't directly initialized,
|
|
Packit |
ae235b |
as well as memory being freed will be reset to 0. The point here is
|
|
Packit |
ae235b |
to allow memory checkers and similar programs that use Boehm GC alike
|
|
Packit |
ae235b |
algorithms to produce more accurate results.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
resident-modules
|
|
Packit |
ae235b |
All modules loaded by GModule will be made resident.
|
|
Packit |
ae235b |
This can be useful for tracking memory leaks in modules which are
|
|
Packit |
ae235b |
later unloaded; but it can also hide bugs where code is accessed
|
|
Packit |
ae235b |
after the module would have normally been unloaded.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
bind-now-modules
|
|
Packit |
ae235b |
All modules loaded by GModule will bind their symbols
|
|
Packit |
ae235b |
at load time, even when the code uses %G_MODULE_BIND_LAZY.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
The special value all can be used to turn on all debug options.
|
|
Packit |
ae235b |
The special value help can be used to print all available options.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
G_SLICE .
|
|
Packit |
ae235b |
This environment variable allows reconfiguration of the GSlice
|
|
Packit |
ae235b |
memory allocator.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
always-malloc
|
|
Packit |
ae235b |
This will cause all slices allocated through
|
|
Packit |
ae235b |
g_slice_alloc() and released by g_slice_free1() to be actually
|
|
Packit |
ae235b |
allocated via direct calls to g_malloc() and g_free().
|
|
Packit |
ae235b |
This is most useful for memory checkers and similar programs that
|
|
Packit |
ae235b |
use Boehm GC alike algorithms to produce more accurate results.
|
|
Packit |
ae235b |
It can also be in conjunction with debugging features of the system's
|
|
Packit |
ae235b |
malloc() implementation such as glibc's MALLOC_CHECK_=2 to debug
|
|
Packit |
ae235b |
erroneous slice allocation code, although
|
|
Packit |
ae235b |
debug-blocks is usually a better suited debugging
|
|
Packit |
ae235b |
tool.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
debug-blocks
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Using this option (present since GLib 2.13) engages
|
|
Packit |
ae235b |
extra code which performs sanity checks on the released memory
|
|
Packit |
ae235b |
slices. Invalid slice addresses or slice sizes will be reported and
|
|
Packit |
ae235b |
lead to a program halt. This option is for debugging scenarios.
|
|
Packit |
ae235b |
In particular, client packages sporting their own test suite should
|
|
Packit |
ae235b |
always enable this option when running tests.
|
|
Packit |
ae235b |
Global slice validation is ensured by storing size and address
|
|
Packit |
ae235b |
information for each allocated chunk, and maintaining a global
|
|
Packit |
ae235b |
hash table of that data. That way, multi-thread scalability is
|
|
Packit |
ae235b |
given up, and memory consumption is increased. However, the
|
|
Packit |
ae235b |
resulting code usually performs acceptably well, possibly better
|
|
Packit |
ae235b |
than with comparable memory checking carried out using external
|
|
Packit |
ae235b |
tools.
|
|
Packit |
ae235b |
An example of a memory corruption scenario that cannot be
|
|
Packit |
ae235b |
reproduced with G_SLICE=always-malloc , but will
|
|
Packit |
ae235b |
be caught by G_SLICE=debug-blocks is as follows:
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
void *slist = g_slist_alloc (); /* void* gives up type-safety */
|
|
Packit |
ae235b |
g_list_free (slist); /* corruption: sizeof (GSList) != sizeof (GList) */
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
The special value all can be used to turn on all options.
|
|
Packit |
ae235b |
The special value help can be used to print all available options.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
G_RANDOM_VERSION .
|
|
Packit |
ae235b |
If this environment variable is set to '2.0', the outdated
|
|
Packit |
ae235b |
pseudo-random number seeding and generation algorithms from
|
|
Packit |
ae235b |
GLib 2.0 are used instead of the newer, better ones. You should
|
|
Packit |
ae235b |
only set this variable if you have sequences of numbers that were
|
|
Packit |
ae235b |
generated with Glib 2.0 that you need to reproduce exactly.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
LIBCHARSET_ALIAS_DIR .
|
|
Packit |
ae235b |
Allows to specify a nonstandard location for the
|
|
Packit |
ae235b |
charset.aliases file that is used by the
|
|
Packit |
ae235b |
character set conversion routines. The default location is the
|
|
Packit |
ae235b |
libdir specified at compilation time.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
TZDIR .
|
|
Packit |
ae235b |
Allows to specify a nonstandard location for the timezone data files
|
|
Packit |
ae235b |
that are used by the #GDateTime API. The default location is under
|
|
Packit |
ae235b |
/usr/share/zoneinfo . For more information,
|
|
Packit |
ae235b |
also look at the tzset manual page.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
G_ENABLE_DIAGNOSTIC .
|
|
Packit |
ae235b |
If set to a non-zero value, this environment variable enables
|
|
Packit |
ae235b |
diagnostic messages, like deprecation messages for GObject properties
|
|
Packit |
ae235b |
and signals.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Locale
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
A number of interfaces in GLib depend on the current locale in which
|
|
Packit |
ae235b |
an application is running. Therefore, most GLib-using applications should
|
|
Packit |
ae235b |
call setlocale (LC_ALL, "") to set up the current
|
|
Packit |
ae235b |
locale.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
On Windows, in a C program there are several locale concepts
|
|
Packit |
ae235b |
that not necessarily are synchronized. On one hand, there is the
|
|
Packit |
ae235b |
system default ANSI code-page, which determines what encoding is used
|
|
Packit |
ae235b |
for file names handled by the C library's functions and the Win32
|
|
Packit |
ae235b |
API. (We are talking about the "narrow" functions here that take
|
|
Packit |
ae235b |
character pointers, not the "wide" ones.)
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
On the other hand, there is the C library's current locale. The
|
|
Packit |
ae235b |
character set (code-page) used by that is not necessarily the same as
|
|
Packit |
ae235b |
the system default ANSI code-page. Strings in this character set are
|
|
Packit |
ae235b |
returned by functions like strftime() .
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
GLib ships with a set of Python macros for the GDB debugger. These includes pretty
|
|
Packit |
ae235b |
printers for lists, hashtables and GObject types. It also has a backtrace filter
|
|
Packit |
ae235b |
that makes backtraces with signal emissions easier to read.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
To use this you need a version of GDB that supports Python scripting; anything
|
|
Packit |
ae235b |
from 7.0 should be fine. You then need to install GLib in the same prefix as
|
|
Packit |
ae235b |
GDB so that the Python GDB autoloaded files get installed in the right place
|
|
Packit |
ae235b |
for GDB to pick up.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
General pretty printing should just happen without having to do anything special.
|
|
Packit |
ae235b |
To get the signal emission filtered backtrace you must use the "new-backtrace" command
|
|
Packit |
ae235b |
instead of the standard one.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
There is also a new command called gforeach that can be used to apply a command
|
|
Packit |
ae235b |
on each item in a list. E.g. you can do
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
gforeach i in some_list_variable: print *(GtkWidget *)l
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Which would print the contents of each widget in a list of widgets.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
SystemTap
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
SystemTap is a dynamic whole-system
|
|
Packit |
ae235b |
analysis toolkit. GLib ships with a file libglib-2.0.so.*.stp which defines a
|
|
Packit |
ae235b |
set of probe points, which you can hook into with custom SystemTap scripts.
|
|
Packit |
ae235b |
See the files libglib-2.0.so.*.stp , libgobject-2.0.so.*.stp
|
|
Packit |
ae235b |
and libgio-2.0.so.*.stp which
|
|
Packit |
ae235b |
are in your shared SystemTap scripts directory.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Memory statistics
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_mem_profile() will output a summary g_malloc() memory usage, if memory
|
|
Packit |
ae235b |
profiling has been enabled by calling
|
|
Packit |
ae235b |
g_mem_set_vtable (glib_mem_profiler_table) upon startup.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
If GLib has been configured with --enable-debug=yes ,
|
|
Packit |
ae235b |
then g_slice_debug_tree_statistics() can be called in a debugger to
|
|
Packit |
ae235b |
output details about the memory usage of the slice allocator.
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
Generated by GTK-Doc V1.27
|
|
Packit |
ae235b |
</body>
|
|
Packit |
ae235b |
</html>
|