Mention g_trap_object_ref
[platform/upstream/glib.git] / docs / reference / glib / running.sgml
1 <refentry id="glib-running" revision="17 Jan 2002">
2 <refmeta>
3 <refentrytitle>Running GLib Applications</refentrytitle>
4 <manvolnum>3</manvolnum>
5 <refmiscinfo>GLib Library</refmiscinfo>
6 </refmeta>
7
8 <refnamediv>
9 <refname>Running GLib Applications</refname>
10 <refpurpose>
11 How to run and debug your GLib application
12 </refpurpose>
13 </refnamediv>
14
15 <refsect1>
16 <title>Running and debugging GLib Applications</title>
17
18 <refsect2>
19 <title>Environment variables</title>
20
21 <para> 
22 GLib inspects a few of environment variables in addition to standard
23 variables like <envar>LANG</envar>, <envar>PATH</envar> or <envar>HOME</envar>. 
24 </para>
25
26 <formalpara id="G_FILENAME_ENCODING">
27   <title><envar>G_FILENAME_ENCODING</envar></title>
28
29   <para>
30     This environment variable can be set to a comma-separated list of character
31     set names. GLib assumes that filenames are encoded in the first character 
32     set from that list rather than in UTF-8. The special token "@locale" can be
33     used to specify the character set for the current locale.
34   </para>
35 </formalpara>
36
37 <formalpara id="G_BROKEN_FILENAMES">
38   <title><envar>G_BROKEN_FILENAMES</envar></title>
39
40   <para>
41     If this environment variable is set, GLib assumes that filenames are in 
42     the locale encoding rather than in UTF-8. G_FILENAME_ENCODING takes
43     priority over G_BROKEN_FILENAMES. 
44   </para>
45 </formalpara>
46
47 <formalpara id="G_MESSAGES_PREFIXED">
48   <title><envar>G_MESSAGES_PREFIXED</envar></title>
49
50   <para>
51     A list of log levels for which messages should be prefixed by the 
52     program name and PID of the application. The default is to prefix
53     everything except <literal>G_LOG_LEVEL_MESSAGE</literal> and <literal>G_LOG_LEVEL_INFO</literal>. 
54   </para>
55 </formalpara>
56
57 <formalpara id="G_DEBUG">
58   <title><envar>G_DEBUG</envar></title>
59   <para>
60     If GLib has been configured with <option>--enable-debug=yes</option>,
61     this variable can be set to a list of debug options, which cause GLib
62     to print out different types of debugging information.
63     <variablelist>
64       <varlistentry>
65         <term>fatal_warnings</term>
66         <listitem><para>Causes GLib to abort the program at the first call
67            to <link linkend="g-warning">g_warning</link>() or
68            <link linkend="g-critical">g_critical</link>(). This option is 
69            special in that it doesn't require GLib to be configured with 
70            debugging support.</para>
71         </listitem>
72       </varlistentry>
73       <varlistentry>
74         <term>fatal_criticals</term>
75         <listitem><para>Causes GLib to abort the program at the first call
76            to <link linkend="g-critical">g_critical</link>(). This option is 
77            special in that it doesn't require GLib to be configured with 
78            debugging support.</para>
79         </listitem>
80       </varlistentry>
81       <varlistentry>
82         <term>gc-friendly</term>
83         <listitem>
84                 <para>
85                   Newly allocated memory that isn't directly initialized, as well
86                   as memory being freed will be reset to 0. The point here is to
87                   allow memory checkers and similar programs that use bohem GC alike
88                   algorithms to produce more accurate results.
89                   This option is special in that it doesn't require GLib to be
90                   configured with debugging support.
91                 </para>
92         </listitem>
93       </varlistentry>
94     </variablelist>
95   </para>
96 </formalpara>
97
98 <formalpara id="G_SLICE">
99         <title><envar>G_SLICE</envar></title>
100         <para>
101           This environment variable allows reconfiguration of the #GSlice
102           memory allocator.
103           <variablelist>
104             <varlistentry>
105               <term>always-malloc</term>
106               <listitem>
107                 <para>
108                   This will cause all slices allocated through g_slice_alloc() and
109                   released by g_slice_free1() to be actually allocated via direct
110                   calls to g_malloc() and g_free().
111                   This is most useful for memory checkers and similar programs that
112                   use bohem GC alike algorithms to produce more accurate results.
113                   It can also be in conjunction with debugging features of the system's
114                   malloc implementation such as glibc's MALLOC_CHECK_=2 to debug
115                   erroneous slice allocation code.
116                 </para>
117               </listitem>
118             </varlistentry>
119           </variablelist>
120         </para>
121 </formalpara>
122
123 <formalpara id="G_RANDOM_VERSION">
124   <title><envar>G_RANDOM_VERSION</envar></title>
125
126   <para>
127     If this environment variable is set to '2.0', the outdated
128     pseudo-random number seeding and generation algorithms from
129     GLib-2.0 are used instead of the new better ones. Use the GLib-2.0
130     algorithms only if you have sequences of numbers generated with
131     Glib-2.0 that you need to reproduce exactly.  
132   </para>
133 </formalpara> 
134
135 <formalpara id="LIBCHARSET_ALIAS_DIR">
136   <title><envar>LIBCHARSET_ALIAS_DIR</envar></title>
137
138   <para>
139     Allows to specify a nonstandard location for the 
140     <filename>charset.aliases</filename> file that is used by the
141     character set conversion routines. The default location is the 
142     <replaceable>libdir</replaceable> specified at compilation time.
143   </para>
144 </formalpara> 
145
146 <formalpara id="G_WIN32_PRETEND_WIN9X">
147   <title><envar>G_WIN32_PRETEND_WIN9X</envar></title>
148
149   <para>
150     Setting this variable to any value forces g_win32_get_windows_version()
151     to return a version code for Windows 9x. This is mainly an internal 
152     debugging aid for GTK+ and GLib developers, to be able to check the 
153     code paths for Windows 9x.
154   </para>
155 </formalpara> 
156
157 </refsect2>
158
159 <refsect2>
160 <title>Traps and traces</title>
161
162 <para>
163 <indexterm><primary>g_trap_free_size</primary></indexterm>
164 <indexterm><primary>g_trap_realloc_size</primary></indexterm>
165 <indexterm><primary>g_trap_malloc_size</primary></indexterm>
166 Some code portions contain trap variables that can be set during debugging 
167 time if GLib has been configured with <option>--enable-debug=yes</option>. 
168 Such traps lead to immediate code halts to examine the current program state 
169 and backtrace.
170 </para>
171
172 <para>
173 Currently, the following trap variables exist:
174 <programlisting>
175 static volatile gulong g_trap_free_size;
176 static volatile gulong g_trap_realloc_size;
177 static volatile gulong g_trap_malloc_size;
178 </programlisting>
179 If set to a size > 0, <link linkend="g-free">g_free</link>(), 
180 <link linkend="g-realloc">g_realloc</link>() and 
181 <link linkend="g-malloc">g_malloc</link>() will be intercepted if the size 
182 matches the size of the corresponding memory block. This will only work with 
183 <literal>g_mem_set_vtable (glib_mem_profiler_table)</literal> upon startup 
184 though, because memory profiling is required to match on the memory block sizes.
185 </para>
186 <para>
187 Note that many modern debuggers support conditional breakpoints, which achieve
188 pretty much the same. E.g. in gdb, you can do
189 <programlisting>
190 break g_malloc
191 condition 1 n_bytes == 20
192 </programlisting>
193 to break only on g_malloc() calls where the size of the allocated memory block
194 is 20. 
195 </para>
196 </refsect2>
197
198 </refsect1>
199
200 </refentry>