Skip to content
Newer
Older
100644 243 lines (191 sloc) 9.11 KB
5390a50 @chromatic Merged the headercleanup branch to trunk as of r38254.
chromatic authored Apr 22, 2009
1 # Copyright (C) 2001-2009, Parrot Foundation.
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
2
9d8cce4 a bit more tidying up
Michael Scott authored Feb 28, 2004
3 =head1 NAME
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
4
9d8cce4 a bit more tidying up
Michael Scott authored Feb 28, 2004
5 docs/debug.pod - Debugging Parrot
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
6
7 =head1 ABSTRACT
8
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
9 This document describes how to debug various parts of Parrot.
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
10
0ba1e92 @coke Fix file reference in debug.pod -> running.pod, while we're in here, …
coke authored Nov 1, 2005
11 =head1 VERSION
12
13 $Revision $
14
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
15 =head1 THE PARROT BINARY
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
16
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
17 =head2 Using a debugger
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
18
05a7e7b @bschmalhofer This patch is huge because of all the whitespace reformatting. This was
bschmalhofer authored Sep 7, 2005
19 Per default the C<parrot> binary is being built with debugging symbols. This
20 means that you can run C<parrot> under an debugger like C<gdb>.
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
21
5d7f0f0 update debug docs WRT jit debugging
Leopold Toetsch authored Jun 2, 2005
22 Debugging support can be explicitly enabled with:
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
23
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
24 shell> perl Configure.pl --debugging
25 shell> make
ea3ecac @hotsphink Fun valgrind toy
hotsphink authored May 14, 2003
26
1772034 @jhoblitt reformat all Pod files under docs with podtidy except for docs/pdds
jhoblitt authored Oct 5, 2005
27 For testing it might be a good idea to make test runs without debug support. So
28 debugging can also be turned off with:
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
29
30 shell> perl Configure.pl --debugging=0
31 shell> make
32
33 =head2 Using a memory checker
34
05a7e7b @bschmalhofer This patch is huge because of all the whitespace reformatting. This was
bschmalhofer authored Sep 7, 2005
35 You could, and should, also run the tests with a memory checker such as
36 C<valgrind>. You can enable C<valgrind>, by running:
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
37
473f9e2 @chromatic [docs] Valgrind accepts "--log-file", not "--logfile" (Steven Dee, RT…
chromatic authored Jan 6, 2008
38 shell> make test VALGRIND="valgrind --log-file=/tmp/grind"
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
39
40 Another possibility is to use Electric Fence, or ...
ea3ecac @hotsphink Fun valgrind toy
hotsphink authored May 14, 2003
41
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
42 =head2 MEMORY MANAGEMENT
43
05a7e7b @bschmalhofer This patch is huge because of all the whitespace reformatting. This was
bschmalhofer authored Sep 7, 2005
44 Some of the more frequent and exasperating C<parrot> bugs are related to memory
45 management in general, and garbage collection in particular.
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
46
c4d3aee Remove =head3 for backward compatibility with Perl 5.6 perldoc
Michael Scott authored Mar 16, 2004
47 Infant mortality
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
48
955f01e @paultcochrane [docs] References to developer files have now been updated to point to
paultcochrane authored Jun 3, 2007
49 See F<docs/dev/infant.pod> for details of one frequent problem: infant
05a7e7b @bschmalhofer This patch is huge because of all the whitespace reformatting. This was
bschmalhofer authored Sep 7, 2005
50 mortality. Infant mortality is when you create a Parrot object, but the garbage
51 collector runs before you put it into a Parrot register or in something else
52 that is itself within a Parrot register.
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
53
05a7e7b @bschmalhofer This patch is huge because of all the whitespace reformatting. This was
bschmalhofer authored Sep 7, 2005
54 To help in resolving these issues, the parrot binary accepts a C<--gc-debug>
55 flag. This flag makes garbage collection occur as frequently as possible, which
56 maximizes the probability that any newborn objects will run afoul of the
57 garbage collector.
32bf14e - small format update (fit in 80 columns)
Jens Rieks authored Apr 3, 2005
58
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
59 =head1 PIR AND PASM CODE
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
60
f9a3ab7 @particle #37520: [TODO] rename library files from .imc to .pir
particle authored Dec 29, 2005
61 Let's say you have written (or generated) a huge .pasm or .pir file. It's not
05a7e7b @bschmalhofer This patch is huge because of all the whitespace reformatting. This was
bschmalhofer authored Sep 7, 2005
62 working. You'd like some help in figuring out why.
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
63
213a519 @NotFound Rename pdb to parrot_debugger after Reini Urban suggestions and later…
NotFound authored Jul 15, 2008
64 =head2 parrot_debugger
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
65
213a519 @NotFound Rename pdb to parrot_debugger after Reini Urban suggestions and later…
NotFound authored Jul 15, 2008
66 One possible tool is C<parrot_debugger>, the Parrot Debugger.
67 See F<docs/debugger.pod> for details on it.
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
68
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
69 =head1 PIR CODE GENERATION
fd2cbfd @hotsphink Improve debugging support and documentation:
hotsphink authored Feb 24, 2003
70
05a7e7b @bschmalhofer This patch is huge because of all the whitespace reformatting. This was
bschmalhofer authored Sep 7, 2005
71 The C<parrot> binary has a bunch of debugging flags for spewing out information
0ba1e92 @coke Fix file reference in debug.pod -> running.pod, while we're in here, …
coke authored Nov 1, 2005
72 about various aspects of its processing. See L<running.pod> for a
05a7e7b @bschmalhofer This patch is huge because of all the whitespace reformatting. This was
bschmalhofer authored Sep 7, 2005
73 list of flags. Or have a look at the information provided by:
d53ad02 @coke #26043 ([PATCH] Update of debug.pod)
coke authored Dec 14, 2004
74
75 shell> parrot --help
76
77 or
78
79 shell> parrot --help-debug
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
80
81
82 =head1 BACKTRACING
83
84 =head2 auto-magical
85
86 If Parrot is built on a system with GNU libc it is capable of automatically
87 generating a backtrace on C<stderr> for debugging purposes. Currently these
88 automatically backtraces are only generated by assertion failures but in the
89 future they also be produced by other bad events (for example, C<SEGV>).
90
91 Here is an example of a what a backtrace might look like:
92
93 Backtrace - Obtained 15 stack frames (max trace depth is 32).
94 (unknown)
95 Parrot_confess
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored Feb 3, 2009
96 Parrot_str_new_COW
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
97 Parrot_String_get_string
98 Parrot_set_s_p
99 (unknown)
100 (unknown)
101 (unknown)
102 (unknown)
103 Parrot_runops_fromc_args
104 Parrot_runcode
105 (unknown)
106 imcc_run
107 (unknown)
108 __libc_start_main
109 (unknown)
110
111 It must be noted that glibc's backtraces are not without limitation. It's
112 method depends completely on information that is available at run time.
113
114 =over
115
6468971 @jhoblitt formatting and a typo
jhoblitt authored Jul 30, 2007
116 =item * Functions marked as C<static> can only be identified by address as they
117 have no "symbol name" for dynamic linking in the executable's symbol table.
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
118 Static functions will appears as C<(unknown)>.
119
6468971 @jhoblitt formatting and a typo
jhoblitt authored Jul 30, 2007
120 =item * There must be some means available for walking the stack at runtime.
121 On x86(-64)? the "stack pointer" must be in C<[re]sp> register. For example,
6c3f959 @Util [docs] Typos in docs/*.pod
Util authored Mar 5, 2009
122 this C<gcc> compilation flag would break backtracing (except for functions
6468971 @jhoblitt formatting and a typo
jhoblitt authored Jul 30, 2007
123 that do dynamic allocation on the stack as this optimization can no be allied
124 to them). C<perl Configure.pl --ccflags=-fomit-frame-pointer>
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
125
126 =item * Some platforms may require extra linker flags in order to get all of
127 the required symbols exported in the symbol table. C<Configure.pl
128 --ccflags=-rdynamic>
129
130 =item * Any debugging information embedded in the object is not accessible. So
131 file and line number can not be included as part of the backtrace information.
132
133 =item * Be warned that signals may cause incorrect backtraces!
134
135 =back
136
137 =head2 gdb
138
139 On systems not equipped with libc, one will need to use an external debugger to
140 get backtrace information. This method is actually more capable then the
141 L<auto-magical> approach as most debuggers will use debugging information if
6468971 @jhoblitt formatting and a typo
jhoblitt authored Jul 30, 2007
142 it's available in the object code (for example, if parrot was built with
143 C<-g>).
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
144
6468971 @jhoblitt formatting and a typo
jhoblitt authored Jul 30, 2007
145 Since the C<Parrot_confess> symbol is I<always> compiled into parrot it can be
146 used as a break point to obtain a backtrace. Here is an example of doing this
806fb69 @paultcochrane [docs]
paultcochrane authored Oct 20, 2007
147 with gdb and a version of parrot compiled with C<gcc> and the C<-g> flag.
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
148
149 $ gdb parrot
150 GNU gdb 6.6
151 Copyright (C) 2006 Free Software Foundation, Inc.
152 GDB is free software, covered by the GNU General Public License, and you are
153 welcome to change it and/or distribute copies of it under certain conditions.
154 Type "show copying" to see the conditions.
155 There is absolutely no warranty for GDB. Type "show warranty" for details.
156 This GDB was configured as "i686-pc-linux-gnu"...
157 Using host libthread_db library "/lib/libthread_db.so.1".
158 (gdb) b main
159 Breakpoint 1 at 0x80488a0: file src/main.c, line 38.
160 (gdb) r foo.pir
161 Starting program: /home/moanui/jhoblitt/parrot/parrot foo.pir
162 Failed to read a valid object file image from memory.
163 [Thread debugging using libthread_db enabled]
164 [New Thread -1213900128 (LWP 23148)]
165 [Switching to Thread -1213900128 (LWP 23148)]
166
167 Breakpoint 1, main (argc=-400292727, argv=0x159a0) at src/main.c:38
168 38 {
169 (gdb) b Parrot_confess
170 Breakpoint 2 at 0xb7c542a0: file src/exceptions.c, line 767.
171 (gdb) c
172 Continuing.
173 [New Thread -1214039152 (LWP 23151)]
174 [New Thread -1222431856 (LWP 23152)]
175 1..1
176
177 Breakpoint 2, Parrot_confess (cond=0xb7eeda65 "s",
178 file=0xb7eeda58 "src/string.c", line=129) at src/exceptions.c:767
179 warning: Source file is more recent than executable.
180 767 {
181 (gdb) bt full
182 #0 Parrot_confess (cond=0xb7eeda65 "s", file=0xb7eeda58 "src/string.c",
183 line=129) at src/exceptions.c:767
184 No locals.
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored Feb 3, 2009
185 #1 0xb7c433b1 in Parrot_str_new_COW (interp=0x804e008, s=0x0)
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
186 at src/string.c:129
187 d = (STRING *) 0x81c21b8
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored Feb 3, 2009
188 __PRETTY_FUNCTION__ = "Parrot_str_new_COW"
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
189 #2 0xb7e40db3 in Parrot_String_get_string (interp=0x804e008, pmc=0x81c8578)
190 at src/pmc/string.c:310
191 No locals.
192 #3 0xb7cc7d41 in Parrot_set_s_p (cur_opcode=0x825d470, interp=0x804e008)
193 at src/ops/set.ops:159
194 No locals.
195 #4 0xb7c9da32 in runops_slow_core (interp=0x804e008, pc=0x825d470)
5390a50 @chromatic Merged the headercleanup branch to trunk as of r38254.
chromatic authored Apr 22, 2009
196 at src/runcore/cores.c:184
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
197 No locals.
198 #5 0xb7c67acf in runops_int (interp=0x804e008, offset=0)
5390a50 @chromatic Merged the headercleanup branch to trunk as of r38254.
chromatic authored Apr 22, 2009
199 at src/interp/interpreter.c:816
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
200 pc = (opcode_t * const) 0x8239730
201 lo_var_ptr = 134537224
202 core = (opcode_t *(*)(Parrot_Interp,
5390a50 @chromatic Merged the headercleanup branch to trunk as of r38254.
chromatic authored Apr 22, 2009
203 opcode_t *)) 0xb7c9d940 <runops_slow_core at src/runcore/cores.c:169>
dd0ad58 @Whiteknight [Core] Remove old references to inter_run.c, which has since been ren…
Whiteknight authored Feb 17, 2009
204 #6 0xb7c6854e in runops (interp=0x804e008, offs=0) at src/call/ops.c:100
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
205 offset = 0
206 old_runloop_id = 0
207 our_runloop_level = 1
208 our_runloop_id = 1
209 #7 0xb7c687da in runops_args (interp=0x804e008, sub=0x8204d58, obj=0x80912d8,
210 meth_unused=0x0, sig=0xb7eefca6 "vP",
806fb69 @paultcochrane [docs]
paultcochrane authored Oct 20, 2007
211 ap=0xbfec614c "@M \b�b��P�\222K\230�\004\b@\236\"\b@M \bXM
dd0ad58 @Whiteknight [Core] Remove old references to inter_run.c, which has since been ren…
Whiteknight authored Feb 17, 2009
212 \b\004����t��\b�\004\b\001") at src/call/ops.c:216
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
213 offset = 0
214 dest = (opcode_t *) 0x8239730
da779a3 @NotFound typedef struct Parrot_Context Parrot_Context, replace parrot_context_…
NotFound authored Oct 21, 2008
215 ctx = (Parrot_Context *) 0x822a3b0
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
216 new_sig = ""
217 sig_p = 0xb7eefca7 "P"
da779a3 @NotFound typedef struct Parrot_Context Parrot_Context, replace parrot_context_…
NotFound authored Oct 21, 2008
218 old_ctx = (Parrot_Context * const) 0x804e298
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
219 #8 0xb7c688fb in Parrot_runops_fromc_args (interp=0x804e008, sub=0x8204d58,
dd0ad58 @Whiteknight [Core] Remove old references to inter_run.c, which has since been ren…
Whiteknight authored Feb 17, 2009
220 sig=0xb7eefca6 "vP") at src/call/ops.c:293
806fb69 @paultcochrane [docs]
paultcochrane authored Oct 20, 2007
221 args = 0xbfec614c "@M \b�b��P�\222K\230�\004\b@\236\"\b@M
222 \bXM \b\004����t��\b�\004\b\001"
da779a3 @NotFound typedef struct Parrot_Context Parrot_Context, replace parrot_context_…
NotFound authored Oct 21, 2008
223 ctx = (Parrot_Context *) 0xb7fa1548
a423810 @jhoblitt add a few words about how to generate a backtrace
jhoblitt authored Jul 30, 2007
224 #9 0xb7c50c51 in Parrot_runcode (interp=0x804e008, argc=1, argv=0xbfec62e8)
225 at src/embed.c:783
226 userargv = (PMC *) 0x8204d40
227 main_sub = (PMC *) 0x8204d58
228 #10 0xb7ed74a1 in imcc_run_pbc (interp=0x804e008, obj_file=0, output_file=0x0,
229 argc=1, argv=0xbfec62e8) at compilers/imcc/main.c:614
230 No locals.
231 #11 0xb7ed7d90 in imcc_run (interp=0x804e008, sourcefile=0xbfec6e0a "foo.pir",
232 argc=1, argv=0xbfec62e8) at compilers/imcc/main.c:815
233 obj_file = 0
234 yyscanner = (yyscan_t) 0x822a090
235 output_file = 0x0
236 #12 0x080489b7 in main (argc=136704448, argv=0x825f220) at src/main.c:62
237 sourcefile = 0xbfec6e0a "foo.pir"
238 interp = (Interp *) 0x804e008
239 executable_name = (STRING *) 0x821b8e4
240 executable_name_pmc = (PMC *) 0x8204d70
241 status = 1267896320
242 (gdb)
Something went wrong with that request. Please try again.