2 Copyright (C) 2001-2008, The Perl Foundation.
7 pdb - The Parrot debugger
21 Disassemble the bytecode.
23 Use this if you have a PBC file but not the PASM.
27 Load a source code file.
31 List the source code file.
37 =item C<break> or C<b>
41 =item C<watch> or C<w>
45 =item C<delete> or C<d>
55 Reenable a disabled breakpoint.
57 =item C<continue> or C<c>
59 Continue the program execution.
63 Run the next instruction
69 =item C<trace> or C<t>
71 Trace the next instruction.
73 =item C<print> or C<p>
75 Print the interpreter registers.
77 =item C<stack> or C<s>
83 Print interpreter information.
97 You can also debug Parrot code by using the C<debug_init>, C<debug_load>
98 and C<debug_break> ops in F<ops/debug.ops>.
109 #include "../compilers/imcc/imc.h"
110 #include "../compilers/imcc/parser.h"
111 #include "parrot/embed.h"
113 static void PDB_printwelcome(void);
114 static void PDB_run_code(Parrot_Interp interp
, int argc
, char *argv
[]);
118 =item C<int main(int argc, char *argv[])>
120 Reads the PASM or PBC file from argv[1], loads it, and then calls
127 extern void imcc_init(Parrot_Interp interp
);
130 main(int argc
, char *argv
[])
132 Parrot_Interp debugger
= Parrot_new(NULL
);
133 Parrot_Interp interp
= Parrot_new(debugger
);
134 PDB_t
*pdb
= mem_allocate_zeroed_typed(PDB_t
);
139 /*Parrot_set_config_hash(); TODO link with cfg */
141 /* attach pdb structure */
143 interp
->debugger
= debugger
;
144 pdb
->debugee
= interp
;
146 Parrot_block_DOD(interp
);
147 Parrot_block_GC(interp
);
150 do_yylex_init(interp
, &yyscanner
);
153 fprintf(stderr
, "Usage: pdb programfile [program-options]\n");
154 Parrot_exit(interp
, 1);
158 ext
= strrchr(filename
, '.');
160 if (ext
&& STREQ(ext
, ".pbc")) {
161 Parrot_PackFile pf
= Parrot_readbc(interp
, filename
);
166 Parrot_loadbc(interp
, pf
);
169 Parrot_PackFile pf
= PackFile_new(interp
, 0);
172 Parrot_loadbc(interp
, pf
);
174 IMCC_push_parser_state(interp
);
175 IMCC_INFO(interp
)->state
->file
= filename
;
177 if (!(imc_yyin_set(fopen(filename
, "r"), yyscanner
))) {
178 IMCC_fatal_standalone(interp
, E_IOError
,
179 "Error reading source file %s.\n",
183 if (ext
&& STREQ(ext
, ".pasm"))
186 emit_open(interp
, 1, NULL
);
187 IMCC_INFO(interp
)->state
->pasm_file
= pasm_file
;
188 yyparse(yyscanner
, interp
);
189 imc_compile_all_units(interp
);
191 imc_cleanup(interp
, yyscanner
);
193 fclose(imc_yyin_get(yyscanner
));
194 PackFile_fixup_subs(interp
, PBC_POSTCOMP
, NULL
);
197 Parrot_unblock_DOD(interp
);
198 Parrot_unblock_GC(interp
);
202 PDB_run_code(interp
, argc
- 1, argv
+ 1);
205 Parrot_exit(interp
, 0);
210 =item C<static void PDB_add_exception_handler(Parrot_Interp)>
212 Adds a default exception handler to PDB.
217 PDB_run_code(Parrot_Interp interp
, int argc
, char *argv
[])
219 Parrot_exception exp
;
221 if (setjmp(exp
.destination
)) {
222 fprintf(stderr
, "Caught exception: %s\n",
223 string_to_cstring(interp
, interp
->exceptions
->msg
));
227 push_new_c_exception_handler(interp
, &exp
);
229 Parrot_runcode(interp
, argc
- 1, argv
+ 1);
234 =item C<static void PDB_printwelcome(void)>
236 Prints out the welcome string.
243 PDB_printwelcome(void)
245 fprintf(stderr
, "Parrot Debugger 0.4.x\n");
246 fprintf(stderr
, "\nPlease note: ");
247 fprintf(stderr
, "the debugger is currently under reconstruction\n");
256 F<src/debug.c>, F<include/parrot/debug.h>.
262 =item * Initial version by Daniel Grunblatt on 2002.5.19.
264 =item * Start of rewrite - leo 2005.02.16
266 The debugger now uses it's own interpreter. User code is run in
267 Interp* debugee. We have:
269 debug_interp->pdb->debugee->debugger
272 +------------- := -----------+
274 Debug commands are mostly run inside the C<debugger>. User code
275 runs of course in the C<debugee>.
283 =item * Check the user input for bad commands, it's quite easy to make
284 it bang now, try listing the source before loading or disassembling it.
286 =item * Print the interpreter info.
288 =item * Make the user interface better (add comands
291 =item * Some other things I don't remember now because it's late.
303 * c-file-style: "parrot"
305 * vim: expandtab shiftwidth=4: