OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libstdc++-v3/] [doc/] [xml/] [manual/] [debug.xml] - Blame information for rev 862

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
2
3
 
4
5
  
6
    
7
      C++
8
    
9
    
10
      debug
11
    
12
  
13
14
 
15
Debugging Support
16
 
17
18
  There are numerous things that can be done to improve the ease with
19
  which C++ binaries are debugged when using the GNU tool chain. Here
20
  are some of them.
21
22
 
23
24
Using <command>g++</command>
25
  
26
    Compiler flags determine how debug information is transmitted
27
    between compilation and debug or analysis tools.
28
  
29
 
30
  
31
    The default optimizations and debug flags for a libstdc++ build
32
    are -g -O2. However, both debug and optimization
33
    flags can be varied to change debugging characteristics. For
34
    instance, turning off all optimization via the -g -O0
35
    -fno-inline flags will disable inlining and optimizations,
36
    and add debugging information, so that stepping through all functions,
37
    (including inlined constructors and destructors) is possible. In
38
    addition, -fno-eliminate-unused-debug-types can be
39
    used when additional debug information, such as nested class info,
40
    is desired.
41
42
 
43
44
  Or, the debug format that the compiler and debugger use to
45
  communicate information about source constructs can be changed via
46
  -gdwarf-2 or -gstabs flags: some debugging
47
  formats permit more expressive type and scope information to be
48
  shown in gdb. Expressiveness can be enhanced by flags like
49
  -g3. The default debug information for a particular
50
  platform can be identified via the value set by the
51
  PREFERRED_DEBUGGING_TYPE macro in the gcc sources.
52
53
 
54
55
  Many other options are available: please see 
56
  url="http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#Debugging%20Options">"Options
57
  for Debugging Your Program" in Using the GNU Compiler
58
  Collection (GCC) for a complete list.
59
60
61
 
62
63
Debug Versions of Library Binary Files
64
 
65
66
  If you would like debug symbols in libstdc++, there are two ways to
67
  build libstdc++ with debug flags. The first is to run make from the
68
  toplevel in a freshly-configured tree with
69
70
71
     --enable-libstdcxx-debug
72
73
and perhaps
74
75
     --enable-libstdcxx-debug-flags='...'
76
77
78
  to create a separate debug build. Both the normal build and the
79
  debug build will persist, without having to specify
80
  CXXFLAGS, and the debug library will be installed in a
81
  separate directory tree, in (prefix)/lib/debug. For
82
  more information, look at the 
83
  linkend="manual.intro.setup.configure">configuration section.
84
85
 
86
87
  A second approach is to use the configuration flags
88
89
90
     make CXXFLAGS='-g3 -fno-inline -O0' all
91
92
 
93
94
  This quick and dirty approach is often sufficient for quick
95
  debugging tasks, when you cannot or don't want to recompile your
96
  application to use the debug mode.
97
98
 
99
100
Memory Leak Hunting
101
 
102
103
  There are various third party memory tracing and debug utilities
104
  that can be used to provide detailed memory allocation information
105
  about C++ code. An exhaustive list of tools is not going to be
106
  attempted, but includes mtrace, valgrind,
107
  mudflap, and the non-free commercial product
108
  purify. In addition, libcwd has a
109
  replacement for the global new and delete operators that can track
110
  memory allocation and deallocation and provide useful memory
111
  statistics.
112
113
 
114
115
  Regardless of the memory debugging tool being used, there is one
116
  thing of great importance to keep in mind when debugging C++ code
117
  that uses new and delete: there are
118
  different kinds of allocation schemes that can be used by 
119
  std::allocator . For implementation details, see the 
120
  linkend="manual.ext.allocator.mt">mt allocator documentation and
121
  look specifically for GLIBCXX_FORCE_NEW.
122
123
 
124
125
  In a nutshell, the default allocator used by 
126
  std::allocator is a high-performance pool allocator, and can
127
  give the mistaken impression that in a suspect executable, memory is
128
  being leaked, when in reality the memory "leak" is a pool being used
129
  by the library's allocator and is reclaimed after program
130
  termination.
131
132
 
133
134
  For valgrind, there are some specific items to keep in mind. First
135
  of all, use a version of valgrind that will work with current GNU
136
  C++ tools: the first that can do this is valgrind 1.0.4, but later
137
  versions should work at least as well. Second of all, use a
138
  completely unoptimized build to avoid confusing valgrind. Third, use
139
  GLIBCXX_FORCE_NEW to keep extraneous pool allocation noise from
140
  cluttering debug information.
141
142
 
143
144
  Fourth, it may be necessary to force deallocation in other libraries
145
  as well, namely the "C" library. On linux, this can be accomplished
146
  with the appropriate use of the __cxa_atexit or
147
  atexit functions.
148
149
 
150
151
   #include <cstdlib>
152
 
153
   extern "C" void __libc_freeres(void);
154
 
155
   void do_something() { }
156
 
157
   int main()
158
   {
159
     atexit(__libc_freeres);
160
     do_something();
161
     return 0;
162
   }
163
164
 
165
 
166
or, using __cxa_atexit:
167
 
168
169
   extern "C" void __libc_freeres(void);
170
   extern "C" int __cxa_atexit(void (*func) (void *), void *arg, void *d);
171
 
172
   void do_something() { }
173
 
174
   int main()
175
   {
176
      extern void* __dso_handle __attribute__ ((__weak__));
177
      __cxa_atexit((void (*) (void *)) __libc_freeres, NULL,
178
                   &__dso_handle ? __dso_handle : NULL);
179
      do_test();
180
      return 0;
181
   }
182
183
 
184
185
  Suggested valgrind flags, given the suggestions above about setting
186
  up the runtime environment, library, and test file, might be:
187
188
189
   valgrind -v --num-callers=20 --leak-check=yes --leak-resolution=high --show-reachable=yes a.out
190
191
 
192
193
 
194
195
Using <command>gdb</command>
196
  
197
  
198
 
199
200
  Many options are available for gdb itself: please see 
201
  url="http://sources.redhat.com/gdb/current/onlinedocs/gdb_13.html#SEC125">
202
  "GDB features for C++"  in the gdb documentation. Also
203
  recommended: the other parts of this manual.
204
205
 
206
207
  These settings can either be switched on in at the gdb command line,
208
  or put into a .gdbint file to establish default debugging
209
  characteristics, like so:
210
211
 
212
213
   set print pretty on
214
   set print object on
215
   set print static-members on
216
   set print vtbl on
217
   set print demangle on
218
   set demangle-style gnu-v3
219
220
 
221
222
  Starting with version 7.0, GDB includes support for writing
223
  pretty-printers in Python.  Pretty printers for STL classes are
224
  distributed with GCC from version 4.5.0.  The most recent version of
225
  these printers are always found in libstdc++ svn repository.
226
  To enable these printers, check-out the latest printers to a local
227
  directory:
228
229
 
230
231
  svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
232
233
 
234
235
  Next, add the following section to your ~/.gdbinit  The path must
236
  match the location where the Python module above was checked-out.
237
  So if checked out to: /home/maude/gdb_printers/, the path would be as
238
  written in the example below.
239
240
 
241
242
  python
243
  import sys
244
  sys.path.insert(0, '/home/maude/gdb_printers/python')
245
  from libstdcxx.v6.printers import register_libstdcxx_printers
246
  register_libstdcxx_printers (None)
247
  end
248
249
 
250
251
  The path should be the only element that needs to be adjusted in the
252
  example.  Once loaded, STL classes that the printers support
253
  should print in a more human-readable format.  To print the classes
254
  in the old style, use the /r (raw) switch in the print command
255
  (i.e., print /r foo).  This will print the classes as if the Python
256
  pretty-printers were not loaded.
257
258
 
259
260
  For additional information on STL support and GDB please visit:
261
   "GDB Support
262
  for STL"  in the GDB wiki.  Additionally, in-depth
263
  documentation and discussion of the pretty printing feature can be
264
  found in "Pretty Printing" node in the GDB manual.  You can find
265
  on-line versions of the GDB user manual in GDB's homepage, at
266
   "GDB: The GNU Project
267
  Debugger" .
268
269
 
270
271
 
272
273
Tracking uncaught exceptions
274
275
  The verbose
276
  termination handler gives information about uncaught
277
  exceptions which are killing the program.  It is described in the
278
  linked-to page.
279
280
281
 
282
283
Debug Mode
284
   The Debug Mode
285
  has compile and run-time checks for many containers.
286
  
287
288
 
289
290
Compile Time Checking
291
   The Compile-Time
292
  Checks Extension has compile-time checks for many algorithms.
293
  
294
295
 
296
297
Profile-based Performance Analysis
298
   The Profile-based
299
  Performance Analysis Extension has performance checks for many
300
  algorithms.
301
  
302
303
 
304

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.