Ticket #491: parrot_debugger_cmdline_options_rewrite.patch
| File parrot_debugger_cmdline_options_rewrite.patch, 3.3 KB (added by tuxdna, 4 years ago) |
|---|
-
src/parrot_debugger.c
117 117 static void PDB_printwelcome(void); 118 118 static void PDB_run_code(PARROT_INTERP, int argc, char *argv[]); 119 119 120 static struct longopt_opt_decl options[] = { 121 { 's', 's', OPTION_optional_FLAG, { "--script" } }, 122 { 'h', 'h', OPTION_optional_FLAG, { "--help" } }, 123 }; 124 125 120 126 /* 121 127 128 =item C<static void help(void)> 129 130 Print out the user help info. 131 132 =cut 133 134 */ 135 136 static void help(Parrot_Interp interp) 137 { 138 fprintf(stderr, "Usage: parrot_debugger programfile [program-options]\n"); 139 fprintf(stderr, "parrot_debugger - debugger for parrot\n"); 140 fprintf(stderr, "usage:\n"); 141 fprintf(stderr, "parrot_debugger [-s | --script FILE]\n"); 142 fprintf(stderr, "parrot_debugger [-h | --help ]\n"); 143 Parrot_exit(interp, 1); 144 } 145 146 /* 147 122 148 =item C<int main(int argc, char *argv[])> 123 149 124 150 Reads the PASM or PBC file from argv[1], loads it, and then calls … … 131 157 int 132 158 main(int argc, char *argv[]) 133 159 { 134 int nextarg;135 160 Parrot_Interp interp; 136 161 PDB_t *pdb; 137 162 const char *scriptname = NULL; 138 163 164 int status; 165 struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; 166 139 167 Parrot_set_config_hash(); 140 168 141 169 interp = Parrot_new(NULL); … … 153 181 Parrot_block_GC_mark(interp); 154 182 Parrot_block_GC_sweep(interp); 155 183 156 nextarg = 1; 157 if (argv[nextarg] && strcmp(argv[nextarg], "--script") == 0) 158 { 159 scriptname = argv [++nextarg]; 160 ++nextarg; 184 while ((status = longopt_get(interp, 185 argc, argv, options, &opt)) > 0) { 186 switch (opt.opt_id) { 187 case 's': 188 scriptname = opt.opt_arg; 189 break; 190 case 'h': 191 default: 192 help(interp); 193 break; 194 } 161 195 } 196 if (status == -1) { 197 help(interp); 198 } 199 argc -= opt.opt_index; 200 argv += opt.opt_index; 162 201 163 if (argv[nextarg]) { 164 const char *filename = argv[nextarg]; 202 203 if(argc > 0) { 204 const char *filename = *argv; 165 205 const char *ext = strrchr(filename, '.'); 206 argc --; 207 argv ++; 166 208 167 209 if (ext && STREQ(ext, ".pbc")) { 168 210 Parrot_PackFile pf = Parrot_pbc_read(interp, filename, 0); … … 232 274 PDB_printwelcome(); 233 275 234 276 interp->run_core = PARROT_DEBUGGER_CORE; 235 PDB_run_code(interp, argc - nextarg, argv + nextarg);277 PDB_run_code(interp, argc, argv); 236 278 237 279 238 280 Parrot_exit(interp, 0); … … 303 345 The debugger now uses it's own interpreter. User code is run in 304 346 Interp* debugee. We have: 305 347 306 debug_interp->pdb->debugee->debugger307 ^ |308 | v309 +--------- ---- := -----------+348 interp->pdb->debugee->debugger 349 ^ | 350 | v 351 +--------- := ---------+ 310 352 311 353 Debug commands are mostly run inside the C<debugger>. User code 312 354 runs of course in the C<debugee>. -
CREDITS
795 795 N: Saleem Ansari 796 796 E: tuxdna@gmail.com 797 797 D: Fixed typos in documentation 798 D: use longopts in parrot debugger 798 799 799 800 N: Sam Ruby 800 801 E: rubys@intertwingly.net
