Remove mention of G_WIN32_PRETEND_WIN9X
[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       <varlistentry>
95         <term>resident-modules</term>
96         <listitem>
97           <para>
98             All modules loaded by GModule will be made resident. This can be useful
99             for tracking memory leaks in modules which are later unloaded; but it can
100             also hide bugs where code is accessed after the module would have normally
101             been unloaded.
102             This option is special in that it doesn't require GLib to be
103             configured with debugging support.
104           </para>
105         </listitem>
106       </varlistentry>
107       <varlistentry>
108         <term>bind-now-modules</term>
109         <listitem>
110           <para>
111             All modules loaded by GModule will bind their symbols at load time, even
112             when the code uses %G_MODULE_BIND_LAZY.
113             This option is special in that it doesn't require GLib to be
114             configured with debugging support.
115           </para>
116         </listitem>
117       </varlistentry>
118     </variablelist>
119   </para>
120 </formalpara>
121
122 <formalpara id="G_SLICE">
123         <title><envar>G_SLICE</envar></title>
124         <para>
125           This environment variable allows reconfiguration of the GSlice
126           memory allocator.
127           <variablelist>
128             <varlistentry>
129               <term>always-malloc</term>
130               <listitem>
131                 <para>
132                   This will cause all slices allocated through g_slice_alloc() and
133                   released by g_slice_free1() to be actually allocated via direct
134                   calls to g_malloc() and g_free().
135                   This is most useful for memory checkers and similar programs that
136                   use Bohem GC alike algorithms to produce more accurate results.
137                   It can also be in conjunction with debugging features of the system's
138                   malloc implementation such as glibc's MALLOC_CHECK_=2 to debug
139                   erroneous slice allocation code, allthough <literal>debug-blocks</literal>
140                   usually is a better suited debugging tool.
141                 </para>
142               </listitem>
143             </varlistentry>
144             <varlistentry>
145               <term>debug-blocks</term>
146               <listitem>
147                 <para>
148                   Using this option (present since GLib-2.13) engages extra code
149                   which performs sanity checks on the released memory slices.
150                   Invalid slice adresses or slice sizes will be reported and lead to
151                   a program halt.
152                   This option should only be used in debugging scenarios, because it
153                   significantly degrades GSlice performance. Extra per slice memory
154                   is requied to do the necessary bookeeping, and multi-thread scalability
155                   is given up to perform global slice validation.
156                   This option is mostly useful in scenarios where program crashes are encountered
157                   while GSlice is in use, but crashes cannot be reproduced with G_SLICE=always-malloc.
158                   A potential cause for such a situation that will be caught by G_SLICE=debug-blocks
159                   is e.g.:
160                   <programlisting>
161                     void *slist = g_slist_alloc(); /* void* gives up type-safety */
162                     g_list_free (slist);           /* corruption: sizeof (GSList) != sizeof (GList) */
163                   </programlisting>
164                 </para>
165               </listitem>
166             </varlistentry>
167           </variablelist>
168         </para>
169 </formalpara>
170
171 <formalpara id="G_RANDOM_VERSION">
172   <title><envar>G_RANDOM_VERSION</envar></title>
173
174   <para>
175     If this environment variable is set to '2.0', the outdated
176     pseudo-random number seeding and generation algorithms from
177     GLib-2.0 are used instead of the new better ones. Use the GLib-2.0
178     algorithms only if you have sequences of numbers generated with
179     Glib-2.0 that you need to reproduce exactly.  
180   </para>
181 </formalpara> 
182
183 <formalpara id="LIBCHARSET_ALIAS_DIR">
184   <title><envar>LIBCHARSET_ALIAS_DIR</envar></title>
185
186   <para>
187     Allows to specify a nonstandard location for the 
188     <filename>charset.aliases</filename> file that is used by the
189     character set conversion routines. The default location is the 
190     <replaceable>libdir</replaceable> specified at compilation time.
191   </para>
192 </formalpara> 
193
194 </refsect2>
195
196 <refsect2 id="setlocale">
197 <title>Locale</title>
198
199 <para>
200 A number of interfaces in GLib depend on the current locale in which
201 an application is running. Therefore, most GLib-using applications should
202 call <function>setlocale (LC_ALL, "")</function> to set up the current 
203 locale.
204 </para>
205
206 <para>
207 On Windows, in a C program there are several locale concepts
208 that not necessarily are synchronized. On one hand, there is the
209 system default ANSI code-page, which determines what encoding is used
210 for file names handled by the C library's functions and the Win32
211 API. (We are talking about the "narrow" functions here that take
212 character pointers, not the "wide" ones.)
213 </para>
214
215 <para>
216 On the other hand, there is the C library's current locale. The
217 character set (code-page) used by that is not necessarily the same as
218 the system default ANSI code-page. Strings in this character set are
219 returned by functions like <function>strftime()</function>.
220 </para>
221
222 </refsect2>
223
224 <refsect2>
225 <title>Traps and traces</title>
226
227 <para>
228 <indexterm><primary>g_trap_free_size</primary></indexterm>
229 <indexterm><primary>g_trap_realloc_size</primary></indexterm>
230 <indexterm><primary>g_trap_malloc_size</primary></indexterm>
231 Some code portions contain trap variables that can be set during debugging 
232 time if GLib has been configured with <option>--enable-debug=yes</option>. 
233 Such traps lead to immediate code halts to examine the current program state 
234 and backtrace.
235 </para>
236
237 <para>
238 Currently, the following trap variables exist:
239 <programlisting>
240 static volatile gulong g_trap_free_size;
241 static volatile gulong g_trap_realloc_size;
242 static volatile gulong g_trap_malloc_size;
243 </programlisting>
244 If set to a size > 0, <link linkend="g-free">g_free</link>(), 
245 <link linkend="g-realloc">g_realloc</link>() and 
246 <link linkend="g-malloc">g_malloc</link>() will be intercepted if the size 
247 matches the size of the corresponding memory block. This will only work with 
248 <literal>g_mem_set_vtable (glib_mem_profiler_table)</literal> upon startup 
249 though, because memory profiling is required to match on the memory block sizes.
250 </para>
251 <para>
252 Note that many modern debuggers support conditional breakpoints, which achieve
253 pretty much the same. E.g. in gdb, you can do
254 <programlisting>
255 break g_malloc
256 condition 1 n_bytes == 20
257 </programlisting>
258 to break only on g_malloc() calls where the size of the allocated memory block
259 is 20. 
260 </para>
261 </refsect2>
262
263 <refsect2>
264 <title>Memory statistics</title>
265
266 <para>
267 g_mem_profile() will output a summary g_malloc() memory usage, if memory
268 profiling has been enabled by calling 
269 <literal>g_mem_set_vtable (glib_mem_profiler_table)</literal> upon startup.
270 </para>
271
272 <para>
273 If GLib has been configured with <option>--enable-debug=yes</option>,
274 then g_slice_debug_tree_statistics() can be called in a debugger to 
275 output details about the memory usage of the slice allocator.
276 </para>
277
278 </refsect2>
279 </refsect1>
280 </refentry>