2 Copyright (C) 2001-2010, Parrot Foundation.
7 parrot_debugger - The Parrot Debugger
15 parrot_debugger programfile
16 parrot_debugger --script scriptfile programfile
24 Disassemble the bytecode.
26 Use this if you have a PBC file but not the PASM.
30 Load a source code file.
34 List the source code file.
40 =item C<break> or C<b>
42 Add a breakpoint at the line number given or the current line if none is given.
48 Breakpoint 1 at pos 10
50 =item C<watch> or C<w>
54 =item C<delete> or C<d>
56 Given a number n, deletes the n-th breakpoint. To delete the first breakpoint:
67 Reenable a disabled breakpoint.
69 =item C<continue> or C<c>
71 Continue the program execution.
75 Run the next instruction
81 =item C<trace> or C<t>
83 Trace the next instruction. This is equivalent to printing the source of the
84 next instruction and then executing it.
86 =item C<print> or C<p>
88 Print an interpreter register. If a register I0 has been used, this
94 If no register number is given then all registers of that type will be printed.
95 If the two registers I0 and I1 have been used, then this would look like:
101 It would be nice if "p" with no arguments printed all registers, but this is
102 currently not the case.
104 =item C<stack> or C<s>
110 Print interpreter information relating to memory allocation and garbage
115 Toggle garbage collection debugging mode. In gcdebug mode a garbage collection
116 cycle is run before each opcocde, which is the same as using the gcdebug core.
118 =item C<quit> or C<q>
122 =item C<help> or C<h>
130 You can also debug Parrot code by using the C<debug_init>, C<debug_load>
131 and C<debug_break> ops in F<ops/debug.ops>.
143 #include "parrot/parrot.h"
144 #include "parrot/embed.h"
145 #include "parrot/debugger.h"
146 #include "parrot/runcore_api.h"
148 static void PDB_printwelcome(void);
149 static void PDB_run_code(PARROT_INTERP
, int argc
, const char *argv
[]);
153 =item C<int main(int argc, const char *argv[])>
155 Reads the PIR, PASM or PBC file from argv[1], loads it, and then calls
163 main(int argc
, const char *argv
[])
166 Parrot_Interp interp
;
168 const char *scriptname
= NULL
;
170 Parrot_set_config_hash();
172 interp
= Parrot_new(NULL
);
174 Parrot_set_executable_name(interp
, Parrot_str_new(interp
, argv
[0], 0));
176 Parrot_debugger_init(interp
);
180 /*Parrot_set_config_hash(); TODO link with cfg */
182 pdb
->state
= PDB_ENTER
;
184 Parrot_block_GC_mark(interp
);
185 Parrot_block_GC_sweep(interp
);
188 if (argv
[nextarg
] && strcmp(argv
[nextarg
], "--script") == 0)
190 scriptname
= argv
[++nextarg
];
195 const char *filename
= argv
[nextarg
];
196 const char *ext
= strrchr(filename
, '.');
198 if (ext
&& STREQ(ext
, ".pbc")) {
199 Parrot_PackFile pf
= Parrot_pbc_read(interp
, filename
, 0);
204 Parrot_pbc_load(interp
, pf
);
205 PackFile_fixup_subs(interp
, PBC_MAIN
, NULL
);
208 STRING
*errmsg
= NULL
;
209 Parrot_PackFile pf
= PackFile_new(interp
, 0);
211 Parrot_pbc_load(interp
, pf
);
212 Parrot_compile_file(interp
, filename
, &errmsg
);
214 Parrot_ex_throw_from_c_args(interp
, NULL
, 1, "%S", errmsg
);
215 PackFile_fixup_subs(interp
, PBC_POSTCOMP
, NULL
);
217 /* load the source for debugger list */
218 PDB_load_source(interp
, filename
);
220 PackFile_fixup_subs(interp
, PBC_MAIN
, NULL
);
225 /* Generate some code to be able to enter into runloop */
227 STRING
*compiler
= Parrot_str_new_constant(interp
, "PIR");
228 STRING
*errstr
= NULL
;
229 const char source
[]= ".sub aux :main\nexit 0\n.end\n";
230 Parrot_compile_string(interp
, compiler
, source
, &errstr
);
232 if (!Parrot_str_is_null(interp
, errstr
))
233 Parrot_io_eprintf(interp
, "%Ss\n", errstr
);
236 Parrot_unblock_GC_mark(interp
);
237 Parrot_unblock_GC_sweep(interp
);
240 PDB_script_file(interp
, scriptname
);
244 Parrot_runcore_switch(interp
, Parrot_str_new_constant(interp
, "debugger"));
245 PDB_run_code(interp
, argc
- nextarg
, argv
+ nextarg
);
247 Parrot_exit(interp
, 0);
252 =item C<static void PDB_run_code(PARROT_INTERP, int argc, const char *argv[])>
254 Run the code, catching exceptions if they are left unhandled.
261 PDB_run_code(PARROT_INTERP
, int argc
, const char *argv
[])
263 new_runloop_jump_point(interp
);
264 if (setjmp(interp
->current_runloop
->resume
)) {
265 free_runloop_jump_point(interp
);
266 fprintf(stderr
, "Caught exception\n");
270 /* Loop to avoid exiting at program end */
272 Parrot_runcode(interp
, argc
, argv
);
273 interp
->pdb
->state
|= PDB_STOPPED
;
274 } while (! (interp
->pdb
->state
& PDB_EXIT
));
275 free_runloop_jump_point(interp
);
280 =item C<static void PDB_printwelcome(void)>
282 Prints out the welcome string.
289 PDB_printwelcome(void)
292 "Parrot " PARROT_VERSION
" Debugger\n"
293 "\nPlease note: the debugger is currently under reconstruction\n");
302 F<src/debug.c>, F<include/parrot/debug.h>.
308 =item * Initial version by Daniel Grunblatt on 2002.5.19.
310 =item * Start of rewrite - leo 2005.02.16
312 The debugger now uses its own interpreter. User code is run in
313 Interp* debugee. We have:
315 debug_interp->pdb->debugee->debugger
318 +------------- := -----------+
320 Debug commands are mostly run inside the C<debugger>. User code
321 runs of course in the C<debugee>.
329 =item * Check the user input for bad commands, it's quite easy to make
330 it bang now, try listing the source before loading or disassembling it.
332 =item * Print the interpreter info.
334 =item * Make the user interface better (add comands
337 =item * Some other things I don't remember now because it's late.
344 Renamed from F<pdb.c> on 2008.7.15
353 * c-file-style: "parrot"
355 * vim: expandtab shiftwidth=4: