| OLD | NEW |
| 1 /* Manages interpreters for GDB, the GNU debugger. | 1 /* Manages interpreters for GDB, the GNU debugger. |
| 2 | 2 |
| 3 Copyright (C) 2000, 2002-2003, 2007-2012 Free Software Foundation, | 3 Copyright (C) 2000, 2002-2003, 2007-2012 Free Software Foundation, |
| 4 Inc. | 4 Inc. |
| 5 | 5 |
| 6 Written by Jim Ingham <jingham@apple.com> of Apple Computer, Inc. | 6 Written by Jim Ingham <jingham@apple.com> of Apple Computer, Inc. |
| 7 | 7 |
| 8 This file is part of GDB. | 8 This file is part of GDB. |
| 9 | 9 |
| 10 This program is free software; you can redistribute it and/or modify | 10 This program is free software; you can redistribute it and/or modify |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 /* Has the init_proc been run? */ | 67 /* Has the init_proc been run? */ |
| 68 int inited; | 68 int inited; |
| 69 | 69 |
| 70 const struct interp_procs *procs; | 70 const struct interp_procs *procs; |
| 71 int quiet_p; | 71 int quiet_p; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 /* Functions local to this file. */ | 74 /* Functions local to this file. */ |
| 75 static void initialize_interps (void); | 75 static void initialize_interps (void); |
| 76 static char **interpreter_completer (struct cmd_list_element *cmd, | |
| 77 char *text, char *word); | |
| 78 | 76 |
| 79 /* The magic initialization routine for this module. */ | 77 /* The magic initialization routine for this module. */ |
| 80 | 78 |
| 81 void _initialize_interpreter (void); | 79 void _initialize_interpreter (void); |
| 82 | 80 |
| 83 /* Variables local to this file: */ | 81 /* Variables local to this file: */ |
| 84 | 82 |
| 85 static struct interp *interp_list = NULL; | 83 static struct interp *interp_list = NULL; |
| 86 static struct interp *current_interpreter = NULL; | 84 static struct interp *current_interpreter = NULL; |
| 87 static struct interp *top_level_interpreter_ptr = NULL; | 85 static struct interp *top_level_interpreter_ptr = NULL; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 244 |
| 247 struct ui_out * | 245 struct ui_out * |
| 248 interp_ui_out (struct interp *interp) | 246 interp_ui_out (struct interp *interp) |
| 249 { | 247 { |
| 250 if (interp != NULL) | 248 if (interp != NULL) |
| 251 return interp->procs->ui_out_proc (interp); | 249 return interp->procs->ui_out_proc (interp); |
| 252 | 250 |
| 253 return current_interpreter->procs->ui_out_proc (current_interpreter); | 251 return current_interpreter->procs->ui_out_proc (current_interpreter); |
| 254 } | 252 } |
| 255 | 253 |
| 254 int |
| 255 current_interp_set_logging (int start_log, struct ui_file *out, |
| 256 struct ui_file *logfile) |
| 257 { |
| 258 if (current_interpreter == NULL |
| 259 || current_interpreter->procs->set_logging_proc == NULL) |
| 260 return 0; |
| 261 |
| 262 return current_interpreter->procs->set_logging_proc (current_interpreter, |
| 263 start_log, out, |
| 264 logfile); |
| 265 } |
| 266 |
| 267 /* Temporarily overrides the current interpreter. */ |
| 268 struct interp * |
| 269 interp_set_temp (const char *name) |
| 270 { |
| 271 struct interp *interp = interp_lookup (name); |
| 272 struct interp *old_interp = current_interpreter; |
| 273 |
| 274 if (interp) |
| 275 current_interpreter = interp; |
| 276 return old_interp; |
| 277 } |
| 278 |
| 256 /* Returns the interpreter's cookie. */ | 279 /* Returns the interpreter's cookie. */ |
| 257 | 280 |
| 258 void * | 281 void * |
| 259 interp_data (struct interp *interp) | 282 interp_data (struct interp *interp) |
| 260 { | 283 { |
| 261 return interp->data; | 284 return interp->data; |
| 262 } | 285 } |
| 263 | 286 |
| 264 /* Returns the interpreter's name. */ | 287 /* Returns the interpreter's name. */ |
| 265 | 288 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 error (_("error in command: \"%s\"."), prules[i]); | 449 error (_("error in command: \"%s\"."), prules[i]); |
| 427 } | 450 } |
| 428 } | 451 } |
| 429 | 452 |
| 430 interp_set (old_interp, 0); | 453 interp_set (old_interp, 0); |
| 431 interp_set_quiet (interp_to_use, use_quiet); | 454 interp_set_quiet (interp_to_use, use_quiet); |
| 432 interp_set_quiet (old_interp, old_quiet); | 455 interp_set_quiet (old_interp, old_quiet); |
| 433 } | 456 } |
| 434 | 457 |
| 435 /* List the possible interpreters which could complete the given text. */ | 458 /* List the possible interpreters which could complete the given text. */ |
| 436 static char ** | 459 static VEC (char_ptr) * |
| 437 interpreter_completer (struct cmd_list_element *ignore, char *text, char *word) | 460 interpreter_completer (struct cmd_list_element *ignore, char *text, char *word) |
| 438 { | 461 { |
| 439 int alloced = 0; | |
| 440 int textlen; | 462 int textlen; |
| 441 int num_matches; | 463 VEC (char_ptr) *matches = NULL; |
| 442 char **matches; | |
| 443 struct interp *interp; | 464 struct interp *interp; |
| 444 | 465 |
| 445 /* We expect only a very limited number of interpreters, so just | |
| 446 allocate room for all of them plus one for the last that must be NULL | |
| 447 to correctly end the list. */ | |
| 448 for (interp = interp_list; interp != NULL; interp = interp->next) | |
| 449 ++alloced; | |
| 450 matches = (char **) xcalloc (alloced + 1, sizeof (char *)); | |
| 451 | |
| 452 num_matches = 0; | |
| 453 textlen = strlen (text); | 466 textlen = strlen (text); |
| 454 for (interp = interp_list; interp != NULL; interp = interp->next) | 467 for (interp = interp_list; interp != NULL; interp = interp->next) |
| 455 { | 468 { |
| 456 if (strncmp (interp->name, text, textlen) == 0) | 469 if (strncmp (interp->name, text, textlen) == 0) |
| 457 { | 470 { |
| 458 » matches[num_matches] = | 471 » char *match; |
| 459 » (char *) xmalloc (strlen (word) + strlen (interp->name) + 1); | 472 |
| 473 » match = (char *) xmalloc (strlen (word) + strlen (interp->name) + 1); |
| 460 if (word == text) | 474 if (word == text) |
| 461 » strcpy (matches[num_matches], interp->name); | 475 » strcpy (match, interp->name); |
| 462 else if (word > text) | 476 else if (word > text) |
| 463 { | 477 { |
| 464 /* Return some portion of interp->name. */ | 478 /* Return some portion of interp->name. */ |
| 465 » strcpy (matches[num_matches], interp->name + (word - text)); | 479 » strcpy (match, interp->name + (word - text)); |
| 466 } | 480 } |
| 467 else | 481 else |
| 468 { | 482 { |
| 469 /* Return some of text plus interp->name. */ | 483 /* Return some of text plus interp->name. */ |
| 470 » strncpy (matches[num_matches], word, text - word); | 484 » strncpy (match, word, text - word); |
| 471 » matches[num_matches][text - word] = '\0'; | 485 » match[text - word] = '\0'; |
| 472 » strcat (matches[num_matches], interp->name); | 486 » strcat (match, interp->name); |
| 473 } | 487 } |
| 474 » ++num_matches; | 488 » VEC_safe_push (char_ptr, matches, match); |
| 475 } | 489 } |
| 476 } | 490 } |
| 477 | 491 |
| 478 if (num_matches == 0) | |
| 479 { | |
| 480 xfree (matches); | |
| 481 matches = NULL; | |
| 482 } | |
| 483 | |
| 484 return matches; | 492 return matches; |
| 485 } | 493 } |
| 486 | 494 |
| 487 struct interp * | 495 struct interp * |
| 488 top_level_interpreter (void) | 496 top_level_interpreter (void) |
| 489 { | 497 { |
| 490 return top_level_interpreter_ptr; | 498 return top_level_interpreter_ptr; |
| 491 } | 499 } |
| 492 | 500 |
| 493 void * | 501 void * |
| 494 top_level_interpreter_data (void) | 502 top_level_interpreter_data (void) |
| 495 { | 503 { |
| 496 gdb_assert (top_level_interpreter_ptr); | 504 gdb_assert (top_level_interpreter_ptr); |
| 497 return top_level_interpreter_ptr->data; | 505 return top_level_interpreter_ptr->data; |
| 498 } | 506 } |
| 499 | 507 |
| 500 /* This just adds the "interpreter-exec" command. */ | 508 /* This just adds the "interpreter-exec" command. */ |
| 501 void | 509 void |
| 502 _initialize_interpreter (void) | 510 _initialize_interpreter (void) |
| 503 { | 511 { |
| 504 struct cmd_list_element *c; | 512 struct cmd_list_element *c; |
| 505 | 513 |
| 506 c = add_cmd ("interpreter-exec", class_support, | 514 c = add_cmd ("interpreter-exec", class_support, |
| 507 interpreter_exec_cmd, _("\ | 515 interpreter_exec_cmd, _("\ |
| 508 Execute a command in an interpreter. It takes two arguments:\n\ | 516 Execute a command in an interpreter. It takes two arguments:\n\ |
| 509 The first argument is the name of the interpreter to use.\n\ | 517 The first argument is the name of the interpreter to use.\n\ |
| 510 The second argument is the command to execute.\n"), &cmdlist); | 518 The second argument is the command to execute.\n"), &cmdlist); |
| 511 set_cmd_completer (c, interpreter_completer); | 519 set_cmd_completer (c, interpreter_completer); |
| 512 } | 520 } |
| OLD | NEW |