Commit | Line | Data |
---|---|---|
172559ec | 1 | /* Top level stuff for GDB, the GNU debugger. |
bf9084c0 | 2 | Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998 |
172559ec JK |
3 | Free Software Foundation, Inc. |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
6c9638b4 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
172559ec JK |
20 | |
21 | #include "defs.h" | |
22 | #include "gdbcmd.h" | |
23 | #include "call-cmds.h" | |
24 | #include "symtab.h" | |
25 | #include "inferior.h" | |
26 | #include "signals.h" | |
27 | #include "target.h" | |
28 | #include "breakpoint.h" | |
29 | #include "gdbtypes.h" | |
30 | #include "expression.h" | |
e52bfe0c | 31 | #include "value.h" |
172559ec JK |
32 | #include "language.h" |
33 | #include "terminal.h" /* For job_control. */ | |
34 | #include "annotate.h" | |
35 | #include <setjmp.h> | |
36 | #include "top.h" | |
37 | ||
38 | /* readline include files */ | |
0bf2ba41 PB |
39 | #include <readline/readline.h> |
40 | #include <readline/history.h> | |
172559ec JK |
41 | |
42 | /* readline defines this. */ | |
43 | #undef savestring | |
44 | ||
45 | #include <sys/types.h> | |
1a494973 | 46 | #ifdef HAVE_UNISTD_H |
172559ec JK |
47 | #include <unistd.h> |
48 | #endif | |
49 | ||
2b576293 | 50 | #include "gdb_string.h" |
2b576293 | 51 | #include "gdb_stat.h" |
172559ec JK |
52 | #include <ctype.h> |
53 | ||
e3be225e SS |
54 | extern void initialize_utils PARAMS ((void)); |
55 | ||
172559ec JK |
56 | /* Prototypes for local functions */ |
57 | ||
b607efe7 FF |
58 | static void dont_repeat_command PARAMS ((char *, int)); |
59 | ||
60 | static void source_cleanup_lines PARAMS ((PTR)); | |
61 | ||
62 | static void user_defined_command PARAMS ((char *, int)); | |
63 | ||
64 | static void init_signals PARAMS ((void)); | |
65 | ||
66 | #ifdef STOP_SIGNAL | |
67 | static void stop_sig PARAMS ((int)); | |
68 | #endif | |
69 | ||
9ed8604f PS |
70 | static char * line_completion_function PARAMS ((char *, int, char *, int)); |
71 | ||
72 | static char * readline_line_completion_function PARAMS ((char *, int)); | |
172559ec | 73 | |
e52bfe0c | 74 | static void command_loop_marker PARAMS ((int)); |
172559ec | 75 | |
e52bfe0c | 76 | static void while_command PARAMS ((char *, int)); |
172559ec | 77 | |
e52bfe0c | 78 | static void if_command PARAMS ((char *, int)); |
172559ec | 79 | |
e52bfe0c JL |
80 | static struct command_line * |
81 | build_command_line PARAMS ((enum command_control_type, char *)); | |
172559ec | 82 | |
e52bfe0c JL |
83 | static struct command_line * |
84 | get_command_line PARAMS ((enum command_control_type, char *)); | |
172559ec | 85 | |
e52bfe0c | 86 | static void realloc_body_list PARAMS ((struct command_line *, int)); |
172559ec | 87 | |
e52bfe0c | 88 | static enum misc_command_type read_next_line PARAMS ((struct command_line **)); |
172559ec | 89 | |
e52bfe0c JL |
90 | static enum command_control_type |
91 | recurse_read_control_structure PARAMS ((struct command_line *)); | |
172559ec | 92 | |
0f8cdd9b JL |
93 | static struct cleanup * setup_user_args PARAMS ((char *)); |
94 | ||
95 | static char * locate_arg PARAMS ((char *)); | |
96 | ||
97 | static char * insert_args PARAMS ((char *)); | |
98 | ||
99 | static void arg_cleanup PARAMS ((void)); | |
100 | ||
e52bfe0c | 101 | static void init_main PARAMS ((void)); |
172559ec | 102 | |
e52bfe0c | 103 | static void init_cmd_lists PARAMS ((void)); |
172559ec | 104 | |
e52bfe0c | 105 | static void float_handler PARAMS ((int)); |
172559ec | 106 | |
e52bfe0c | 107 | static void init_signals PARAMS ((void)); |
172559ec | 108 | |
e52bfe0c | 109 | static void set_verbose PARAMS ((char *, int, struct cmd_list_element *)); |
172559ec | 110 | |
e52bfe0c | 111 | static void show_history PARAMS ((char *, int)); |
172559ec | 112 | |
e52bfe0c | 113 | static void set_history PARAMS ((char *, int)); |
172559ec | 114 | |
e52bfe0c JL |
115 | static void set_history_size_command PARAMS ((char *, int, |
116 | struct cmd_list_element *)); | |
172559ec | 117 | |
e52bfe0c | 118 | static void show_commands PARAMS ((char *, int)); |
172559ec | 119 | |
e52bfe0c | 120 | static void echo_command PARAMS ((char *, int)); |
172559ec | 121 | |
e52bfe0c | 122 | static void pwd_command PARAMS ((char *, int)); |
172559ec | 123 | |
e52bfe0c | 124 | static void show_version PARAMS ((char *, int)); |
172559ec | 125 | |
e52bfe0c | 126 | static void document_command PARAMS ((char *, int)); |
172559ec | 127 | |
e52bfe0c | 128 | static void define_command PARAMS ((char *, int)); |
172559ec | 129 | |
e52bfe0c JL |
130 | static void validate_comname PARAMS ((char *)); |
131 | ||
132 | static void help_command PARAMS ((char *, int)); | |
133 | ||
134 | static void show_command PARAMS ((char *, int)); | |
135 | ||
136 | static void info_command PARAMS ((char *, int)); | |
137 | ||
138 | static void complete_command PARAMS ((char *, int)); | |
139 | ||
140 | static void do_nothing PARAMS ((int)); | |
141 | ||
4ce7ba51 | 142 | #ifdef SIGHUP |
e52bfe0c JL |
143 | static int quit_cover PARAMS ((char *)); |
144 | ||
145 | static void disconnect PARAMS ((int)); | |
4ce7ba51 | 146 | #endif |
e52bfe0c JL |
147 | |
148 | static void source_cleanup PARAMS ((FILE *)); | |
172559ec JK |
149 | |
150 | /* If this definition isn't overridden by the header files, assume | |
151 | that isatty and fileno exist on this system. */ | |
152 | #ifndef ISATTY | |
153 | #define ISATTY(FP) (isatty (fileno (FP))) | |
154 | #endif | |
155 | ||
156 | /* Initialization file name for gdb. This is overridden in some configs. */ | |
157 | ||
158 | #ifndef GDBINIT_FILENAME | |
159 | #define GDBINIT_FILENAME ".gdbinit" | |
160 | #endif | |
161 | char gdbinit[] = GDBINIT_FILENAME; | |
f22661ee | 162 | |
172559ec JK |
163 | int inhibit_gdbinit = 0; |
164 | ||
f22661ee SS |
165 | /* If nonzero, and GDB has been configured to be able to use windows, |
166 | attempt to open them upon startup. */ | |
754e5da2 | 167 | |
f22661ee | 168 | int use_windows = 1; |
754e5da2 | 169 | |
172559ec JK |
170 | /* Version number of GDB, as a string. */ |
171 | ||
172 | extern char *version; | |
173 | ||
174 | /* Canonical host name as a string. */ | |
175 | ||
176 | extern char *host_name; | |
177 | ||
178 | /* Canonical target name as a string. */ | |
179 | ||
180 | extern char *target_name; | |
181 | ||
182 | extern char lang_frame_mismatch_warn[]; /* language.c */ | |
183 | ||
184 | /* Flag for whether we want all the "from_tty" gubbish printed. */ | |
185 | ||
186 | int caution = 1; /* Default is yes, sigh. */ | |
187 | ||
f22661ee | 188 | /* Define all cmd_list_elements. */ |
172559ec JK |
189 | |
190 | /* Chain containing all defined commands. */ | |
191 | ||
192 | struct cmd_list_element *cmdlist; | |
193 | ||
194 | /* Chain containing all defined info subcommands. */ | |
195 | ||
196 | struct cmd_list_element *infolist; | |
197 | ||
198 | /* Chain containing all defined enable subcommands. */ | |
199 | ||
200 | struct cmd_list_element *enablelist; | |
201 | ||
202 | /* Chain containing all defined disable subcommands. */ | |
203 | ||
204 | struct cmd_list_element *disablelist; | |
205 | ||
65b07ddc DT |
206 | /* Chain containing all defined toggle subcommands. */ |
207 | ||
208 | struct cmd_list_element *togglelist; | |
209 | ||
210 | /* Chain containing all defined stop subcommands. */ | |
211 | ||
212 | struct cmd_list_element *stoplist; | |
213 | ||
172559ec JK |
214 | /* Chain containing all defined delete subcommands. */ |
215 | ||
216 | struct cmd_list_element *deletelist; | |
217 | ||
218 | /* Chain containing all defined "enable breakpoint" subcommands. */ | |
219 | ||
220 | struct cmd_list_element *enablebreaklist; | |
221 | ||
222 | /* Chain containing all defined set subcommands */ | |
223 | ||
224 | struct cmd_list_element *setlist; | |
225 | ||
226 | /* Chain containing all defined unset subcommands */ | |
227 | ||
228 | struct cmd_list_element *unsetlist; | |
229 | ||
230 | /* Chain containing all defined show subcommands. */ | |
231 | ||
232 | struct cmd_list_element *showlist; | |
233 | ||
234 | /* Chain containing all defined \"set history\". */ | |
235 | ||
236 | struct cmd_list_element *sethistlist; | |
237 | ||
238 | /* Chain containing all defined \"show history\". */ | |
239 | ||
240 | struct cmd_list_element *showhistlist; | |
241 | ||
242 | /* Chain containing all defined \"unset history\". */ | |
243 | ||
244 | struct cmd_list_element *unsethistlist; | |
245 | ||
246 | /* Chain containing all defined maintenance subcommands. */ | |
247 | ||
248 | #if MAINTENANCE_CMDS | |
249 | struct cmd_list_element *maintenancelist; | |
250 | #endif | |
251 | ||
252 | /* Chain containing all defined "maintenance info" subcommands. */ | |
253 | ||
254 | #if MAINTENANCE_CMDS | |
255 | struct cmd_list_element *maintenanceinfolist; | |
256 | #endif | |
257 | ||
258 | /* Chain containing all defined "maintenance print" subcommands. */ | |
259 | ||
260 | #if MAINTENANCE_CMDS | |
261 | struct cmd_list_element *maintenanceprintlist; | |
262 | #endif | |
263 | ||
264 | struct cmd_list_element *setprintlist; | |
265 | ||
266 | struct cmd_list_element *showprintlist; | |
267 | ||
268 | struct cmd_list_element *setchecklist; | |
269 | ||
270 | struct cmd_list_element *showchecklist; | |
271 | ||
272 | /* stdio stream that command input is being read from. Set to stdin normally. | |
273 | Set by source_command to the file we are sourcing. Set to NULL if we are | |
41756e56 | 274 | executing a user-defined command or interacting via a GUI. */ |
172559ec JK |
275 | |
276 | FILE *instream; | |
277 | ||
278 | /* Current working directory. */ | |
279 | ||
280 | char *current_directory; | |
281 | ||
282 | /* The directory name is actually stored here (usually). */ | |
b7ec5b8d | 283 | char gdb_dirbuf[1024]; |
172559ec JK |
284 | |
285 | /* Function to call before reading a command, if nonzero. | |
286 | The function receives two args: an input stream, | |
287 | and a prompt string. */ | |
288 | ||
289 | void (*window_hook) PARAMS ((FILE *, char *)); | |
290 | ||
291 | int epoch_interface; | |
292 | int xgdb_verbose; | |
293 | ||
294 | /* gdb prints this when reading a command interactively */ | |
295 | static char *prompt; | |
296 | ||
297 | /* Buffer used for reading command lines, and the size | |
298 | allocated for it so far. */ | |
299 | ||
300 | char *line; | |
301 | int linesize = 100; | |
302 | ||
303 | /* Nonzero if the current command is modified by "server ". This | |
304 | affects things like recording into the command history, comamnds | |
305 | repeating on RETURN, etc. This is so a user interface (emacs, GUI, | |
306 | whatever) can issue its own commands and also send along commands | |
307 | from the user, and have the user not notice that the user interface | |
308 | is issuing commands too. */ | |
309 | int server_command; | |
310 | ||
311 | /* Baud rate specified for talking to serial target systems. Default | |
312 | is left as -1, so targets can choose their own defaults. */ | |
313 | /* FIXME: This means that "show remotebaud" and gr_files_info can print -1 | |
314 | or (unsigned int)-1. This is a Bad User Interface. */ | |
315 | ||
316 | int baud_rate = -1; | |
317 | ||
cb1709ae DP |
318 | /* Timeout limit for response from target. */ |
319 | ||
320 | int remote_timeout = 20; /* Set default to 20 */ | |
321 | ||
172559ec JK |
322 | /* Non-zero tells remote* modules to output debugging info. */ |
323 | ||
324 | int remote_debug = 0; | |
325 | ||
e52bfe0c JL |
326 | /* Level of control structure. */ |
327 | static int control_level; | |
328 | ||
0f8cdd9b JL |
329 | /* Structure for arguments to user defined functions. */ |
330 | #define MAXUSERARGS 10 | |
331 | struct user_args | |
332 | { | |
333 | struct user_args *next; | |
334 | struct | |
335 | { | |
336 | char *arg; | |
337 | int len; | |
338 | } a[MAXUSERARGS]; | |
339 | int count; | |
340 | } *user_args; | |
341 | ||
172559ec JK |
342 | /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */ |
343 | ||
344 | #ifndef STOP_SIGNAL | |
345 | #ifdef SIGTSTP | |
346 | #define STOP_SIGNAL SIGTSTP | |
347 | static void stop_sig PARAMS ((int)); | |
348 | #endif | |
349 | #endif | |
350 | ||
351 | /* Some System V have job control but not sigsetmask(). */ | |
352 | #if !defined (HAVE_SIGSETMASK) | |
353 | #if !defined (USG) | |
354 | #define HAVE_SIGSETMASK 1 | |
355 | #else | |
356 | #define HAVE_SIGSETMASK 0 | |
357 | #endif | |
358 | #endif | |
359 | ||
360 | #if 0 == (HAVE_SIGSETMASK) | |
361 | #define sigsetmask(n) | |
362 | #endif | |
8164ec2e SG |
363 | |
364 | /* Hooks for alternate command interfaces. */ | |
365 | ||
366 | /* Called after most modules have been initialized, but before taking users | |
367 | command file. */ | |
368 | ||
2476848a | 369 | void (*init_ui_hook) PARAMS ((char *argv0)); |
d836385e | 370 | #ifdef __CYGWIN__ |
21b3bc77 KS |
371 | void (*ui_loop_hook) PARAMS ((int)); |
372 | #endif | |
8164ec2e SG |
373 | |
374 | /* Called instead of command_loop at top level. Can be invoked via | |
375 | return_to_top_level. */ | |
376 | ||
377 | void (*command_loop_hook) PARAMS ((void)); | |
378 | ||
764efb58 | 379 | |
8164ec2e SG |
380 | /* Called instead of fputs for all output. */ |
381 | ||
65b07ddc | 382 | void (*fputs_unfiltered_hook) PARAMS ((const char *linebuffer, GDB_FILE *stream)); |
8164ec2e | 383 | |
764efb58 SC |
384 | /* Called when the target says something to the host, which may |
385 | want to appear in a different window. */ | |
386 | ||
327332d8 | 387 | void (*target_output_hook) PARAMS ((char *)); |
764efb58 | 388 | |
8164ec2e SG |
389 | /* Called from print_frame_info to list the line we stopped in. */ |
390 | ||
391 | void (*print_frame_info_listing_hook) PARAMS ((struct symtab *s, int line, | |
392 | int stopline, int noerror)); | |
393 | /* Replaces most of query. */ | |
394 | ||
b607efe7 | 395 | int (*query_hook) PARAMS ((const char *, va_list)); |
8164ec2e | 396 | |
e6e9507d EZ |
397 | /* Replaces most of warning. */ |
398 | ||
399 | void (*warning_hook) PARAMS ((const char *, va_list)); | |
400 | ||
8164ec2e SG |
401 | /* Called from gdb_flush to flush output. */ |
402 | ||
65b07ddc | 403 | void (*flush_hook) PARAMS ((GDB_FILE *stream)); |
8164ec2e | 404 | |
41756e56 FF |
405 | /* These three functions support getting lines of text from the user. They |
406 | are used in sequence. First readline_begin_hook is called with a text | |
407 | string that might be (for example) a message for the user to type in a | |
408 | sequence of commands to be executed at a breakpoint. If this function | |
409 | calls back to a GUI, it might take this opportunity to pop up a text | |
410 | interaction window with this message. Next, readline_hook is called | |
411 | with a prompt that is emitted prior to collecting the user input. | |
412 | It can be called multiple times. Finally, readline_end_hook is called | |
413 | to notify the GUI that we are done with the interaction window and it | |
414 | can close it. */ | |
415 | ||
416 | void (*readline_begin_hook) PARAMS ((char *, ...)); | |
417 | char * (*readline_hook) PARAMS ((char *)); | |
418 | void (*readline_end_hook) PARAMS ((void)); | |
419 | ||
8164ec2e SG |
420 | /* Called as appropriate to notify the interface of the specified breakpoint |
421 | conditions. */ | |
422 | ||
637b1661 | 423 | void (*create_breakpoint_hook) PARAMS ((struct breakpoint *bpt)); |
8164ec2e | 424 | void (*delete_breakpoint_hook) PARAMS ((struct breakpoint *bpt)); |
6131622e | 425 | void (*modify_breakpoint_hook) PARAMS ((struct breakpoint *bpt)); |
637b1661 SG |
426 | |
427 | /* Called during long calculations to allow GUI to repair window damage, and to | |
428 | check for stop buttons, etc... */ | |
429 | ||
430 | void (*interactive_hook) PARAMS ((void)); | |
431 | ||
16041d53 SC |
432 | /* Called when the registers have changed, as a hint to a GUI |
433 | to minimize window update. */ | |
434 | ||
435 | void (*registers_changed_hook) PARAMS ((void)); | |
436 | ||
929db6e5 EZ |
437 | /* tell the GUI someone changed the PC */ |
438 | void (*pc_changed_hook) PARAMS ((void)); | |
439 | ||
479f0f18 SG |
440 | /* Called when going to wait for the target. Usually allows the GUI to run |
441 | while waiting for target events. */ | |
442 | ||
443 | int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus *status)); | |
444 | ||
445 | /* Used by UI as a wrapper around command execution. May do various things | |
446 | like enabling/disabling buttons, etc... */ | |
447 | ||
448 | void (*call_command_hook) PARAMS ((struct cmd_list_element *c, char *cmd, | |
449 | int from_tty)); | |
45993f61 | 450 | |
d5adad6a TT |
451 | /* Called when the current thread changes. Argument is thread id. */ |
452 | ||
453 | void (*context_hook) PARAMS ((int id)); | |
45993f61 SC |
454 | |
455 | /* Takes control from error (). Typically used to prevent longjmps out of the | |
456 | middle of the GUI. Usually used in conjunction with a catch routine. */ | |
457 | ||
b607efe7 | 458 | NORETURN void (*error_hook) PARAMS ((void)) ATTR_NORETURN; |
45993f61 | 459 | |
172559ec JK |
460 | \f |
461 | /* Where to go for return_to_top_level (RETURN_ERROR). */ | |
4b65fd38 | 462 | SIGJMP_BUF error_return; |
172559ec | 463 | /* Where to go for return_to_top_level (RETURN_QUIT). */ |
4b65fd38 | 464 | SIGJMP_BUF quit_return; |
172559ec JK |
465 | |
466 | /* Return for reason REASON. This generally gets back to the command | |
467 | loop, but can be caught via catch_errors. */ | |
468 | ||
469 | NORETURN void | |
470 | return_to_top_level (reason) | |
471 | enum return_reason reason; | |
472 | { | |
473 | quit_flag = 0; | |
474 | immediate_quit = 0; | |
475 | ||
476 | /* Perhaps it would be cleaner to do this via the cleanup chain (not sure | |
477 | I can think of a reason why that is vital, though). */ | |
478 | bpstat_clear_actions(stop_bpstat); /* Clear queued breakpoint commands */ | |
479 | ||
480 | disable_current_display (); | |
481 | do_cleanups (ALL_CLEANUPS); | |
482 | ||
483 | if (annotation_level > 1) | |
484 | switch (reason) | |
485 | { | |
486 | case RETURN_QUIT: | |
487 | annotate_quit (); | |
488 | break; | |
489 | case RETURN_ERROR: | |
490 | annotate_error (); | |
491 | break; | |
492 | } | |
493 | ||
4b65fd38 | 494 | (NORETURN void) SIGLONGJMP |
172559ec JK |
495 | (reason == RETURN_ERROR ? error_return : quit_return, 1); |
496 | } | |
497 | ||
498 | /* Call FUNC with arg ARGS, catching any errors. If there is no | |
499 | error, return the value returned by FUNC. If there is an error, | |
500 | print ERRSTRING, print the specific error message, then return | |
501 | zero. | |
502 | ||
503 | Must not be called with immediate_quit in effect (bad things might | |
504 | happen, say we got a signal in the middle of a memcpy to quit_return). | |
505 | This is an OK restriction; with very few exceptions immediate_quit can | |
506 | be replaced by judicious use of QUIT. | |
507 | ||
508 | MASK specifies what to catch; it is normally set to | |
509 | RETURN_MASK_ALL, if for no other reason than that the code which | |
510 | calls catch_errors might not be set up to deal with a quit which | |
511 | isn't caught. But if the code can deal with it, it generally | |
512 | should be RETURN_MASK_ERROR, unless for some reason it is more | |
513 | useful to abort only the portion of the operation inside the | |
514 | catch_errors. Note that quit should return to the command line | |
515 | fairly quickly, even if some further processing is being done. */ | |
516 | ||
517 | int | |
518 | catch_errors (func, args, errstring, mask) | |
6e45c399 | 519 | catch_errors_ftype *func; |
172559ec JK |
520 | PTR args; |
521 | char *errstring; | |
522 | return_mask mask; | |
523 | { | |
4b65fd38 DT |
524 | SIGJMP_BUF saved_error; |
525 | SIGJMP_BUF saved_quit; | |
526 | SIGJMP_BUF tmp_jmp; | |
172559ec JK |
527 | int val; |
528 | struct cleanup *saved_cleanup_chain; | |
529 | char *saved_error_pre_print; | |
dee80384 | 530 | char *saved_quit_pre_print; |
172559ec JK |
531 | |
532 | saved_cleanup_chain = save_cleanups (); | |
533 | saved_error_pre_print = error_pre_print; | |
dee80384 | 534 | saved_quit_pre_print = quit_pre_print; |
172559ec JK |
535 | |
536 | if (mask & RETURN_MASK_ERROR) | |
dee80384 | 537 | { |
4b65fd38 | 538 | memcpy ((char *)saved_error, (char *)error_return, sizeof (SIGJMP_BUF)); |
dee80384 JK |
539 | error_pre_print = errstring; |
540 | } | |
172559ec | 541 | if (mask & RETURN_MASK_QUIT) |
dee80384 | 542 | { |
4b65fd38 | 543 | memcpy (saved_quit, quit_return, sizeof (SIGJMP_BUF)); |
dee80384 JK |
544 | quit_pre_print = errstring; |
545 | } | |
172559ec | 546 | |
4b65fd38 | 547 | if (SIGSETJMP (tmp_jmp) == 0) |
172559ec JK |
548 | { |
549 | if (mask & RETURN_MASK_ERROR) | |
4b65fd38 | 550 | memcpy (error_return, tmp_jmp, sizeof (SIGJMP_BUF)); |
172559ec | 551 | if (mask & RETURN_MASK_QUIT) |
4b65fd38 | 552 | memcpy (quit_return, tmp_jmp, sizeof (SIGJMP_BUF)); |
172559ec JK |
553 | val = (*func) (args); |
554 | } | |
555 | else | |
556 | val = 0; | |
557 | ||
558 | restore_cleanups (saved_cleanup_chain); | |
559 | ||
172559ec | 560 | if (mask & RETURN_MASK_ERROR) |
dee80384 | 561 | { |
4b65fd38 | 562 | memcpy (error_return, saved_error, sizeof (SIGJMP_BUF)); |
dee80384 JK |
563 | error_pre_print = saved_error_pre_print; |
564 | } | |
172559ec | 565 | if (mask & RETURN_MASK_QUIT) |
dee80384 | 566 | { |
4b65fd38 | 567 | memcpy (quit_return, saved_quit, sizeof (SIGJMP_BUF)); |
dee80384 JK |
568 | quit_pre_print = saved_quit_pre_print; |
569 | } | |
172559ec JK |
570 | return val; |
571 | } | |
572 | ||
573 | /* Handler for SIGHUP. */ | |
574 | ||
4ce7ba51 | 575 | #ifdef SIGHUP |
172559ec JK |
576 | static void |
577 | disconnect (signo) | |
578 | int signo; | |
579 | { | |
580 | catch_errors (quit_cover, NULL, | |
581 | "Could not kill the program being debugged", RETURN_MASK_ALL); | |
582 | signal (SIGHUP, SIG_DFL); | |
583 | kill (getpid (), SIGHUP); | |
584 | } | |
585 | ||
586 | /* Just a little helper function for disconnect(). */ | |
587 | ||
588 | static int | |
589 | quit_cover (s) | |
590 | char *s; | |
591 | { | |
592 | caution = 0; /* Throw caution to the wind -- we're exiting. | |
593 | This prevents asking the user dumb questions. */ | |
594 | quit_command((char *)0, 0); | |
595 | return 0; | |
596 | } | |
4ce7ba51 | 597 | #endif /* defined SIGHUP */ |
172559ec JK |
598 | \f |
599 | /* Line number we are currently in in a file which is being sourced. */ | |
600 | static int source_line_number; | |
601 | ||
602 | /* Name of the file we are sourcing. */ | |
603 | static char *source_file_name; | |
604 | ||
605 | /* Buffer containing the error_pre_print used by the source stuff. | |
606 | Malloc'd. */ | |
607 | static char *source_error; | |
608 | static int source_error_allocated; | |
609 | ||
610 | /* Something to glom on to the start of error_pre_print if source_file_name | |
611 | is set. */ | |
612 | static char *source_pre_error; | |
613 | ||
614 | /* Clean up on error during a "source" command (or execution of a | |
615 | user-defined command). */ | |
616 | ||
617 | static void | |
618 | source_cleanup (stream) | |
619 | FILE *stream; | |
620 | { | |
621 | /* Restore the previous input stream. */ | |
622 | instream = stream; | |
623 | } | |
624 | ||
625 | /* Read commands from STREAM. */ | |
626 | void | |
627 | read_command_file (stream) | |
628 | FILE *stream; | |
629 | { | |
630 | struct cleanup *cleanups; | |
631 | ||
ad3b8c4a | 632 | cleanups = make_cleanup ((make_cleanup_func) source_cleanup, instream); |
172559ec JK |
633 | instream = stream; |
634 | command_loop (); | |
635 | do_cleanups (cleanups); | |
636 | } | |
637 | \f | |
b607efe7 | 638 | extern void init_proc PARAMS ((void)); |
172559ec | 639 | |
43ab4ba5 SS |
640 | void (*pre_init_ui_hook) PARAMS ((void)); |
641 | ||
172559ec | 642 | void |
2476848a MH |
643 | gdb_init (argv0) |
644 | char *argv0; | |
172559ec | 645 | { |
43ab4ba5 SS |
646 | if (pre_init_ui_hook) |
647 | pre_init_ui_hook (); | |
648 | ||
172559ec JK |
649 | /* Run the init function of each source file */ |
650 | ||
b7ec5b8d FF |
651 | getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); |
652 | current_directory = gdb_dirbuf; | |
f36b58b1 | 653 | |
172559ec | 654 | init_cmd_lists (); /* This needs to be done first */ |
754e5da2 SG |
655 | initialize_targets (); /* Setup target_terminal macros for utils.c */ |
656 | initialize_utils (); /* Make errors and warnings possible */ | |
172559ec JK |
657 | initialize_all_files (); |
658 | init_main (); /* But that omits this file! Do it now */ | |
659 | init_signals (); | |
660 | ||
661 | init_proc (); | |
662 | ||
663 | /* We need a default language for parsing expressions, so simple things like | |
664 | "set width 0" won't fail if no language is explicitly set in a config file | |
665 | or implicitly set by reading an executable during startup. */ | |
666 | set_language (language_c); | |
667 | expected_language = current_language; /* don't warn about the change. */ | |
754e5da2 SG |
668 | |
669 | if (init_ui_hook) | |
2476848a | 670 | init_ui_hook (argv0); |
172559ec JK |
671 | } |
672 | ||
e52bfe0c JL |
673 | /* Allocate, initialize a new command line structure for one of the |
674 | control commands (if/while). */ | |
675 | ||
676 | static struct command_line * | |
677 | build_command_line (type, args) | |
678 | enum command_control_type type; | |
679 | char *args; | |
680 | { | |
681 | struct command_line *cmd; | |
682 | ||
a25ffb08 JL |
683 | if (args == NULL) |
684 | error ("if/while commands require arguments.\n"); | |
685 | ||
e52bfe0c JL |
686 | cmd = (struct command_line *)xmalloc (sizeof (struct command_line)); |
687 | cmd->next = NULL; | |
688 | cmd->control_type = type; | |
689 | ||
690 | cmd->body_count = 1; | |
691 | cmd->body_list | |
692 | = (struct command_line **)xmalloc (sizeof (struct command_line *) | |
693 | * cmd->body_count); | |
694 | memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count); | |
695 | cmd->line = savestring (args, strlen (args)); | |
696 | return cmd; | |
697 | } | |
698 | ||
699 | /* Build and return a new command structure for the control commands | |
700 | such as "if" and "while". */ | |
701 | ||
702 | static struct command_line * | |
703 | get_command_line (type, arg) | |
704 | enum command_control_type type; | |
705 | char *arg; | |
706 | { | |
707 | struct command_line *cmd; | |
708 | struct cleanup *old_chain = NULL; | |
709 | ||
710 | /* Allocate and build a new command line structure. */ | |
711 | cmd = build_command_line (type, arg); | |
712 | ||
ad3b8c4a | 713 | old_chain = make_cleanup ((make_cleanup_func) free_command_lines, &cmd); |
e52bfe0c JL |
714 | |
715 | /* Read in the body of this command. */ | |
716 | if (recurse_read_control_structure (cmd) == invalid_control) | |
717 | { | |
718 | warning ("error reading in control structure\n"); | |
719 | do_cleanups (old_chain); | |
720 | return NULL; | |
721 | } | |
722 | ||
723 | discard_cleanups (old_chain); | |
724 | return cmd; | |
725 | } | |
726 | ||
0f8cdd9b JL |
727 | /* Recursively print a command (including full control structures). */ |
728 | void | |
729 | print_command_line (cmd, depth) | |
730 | struct command_line *cmd; | |
731 | unsigned int depth; | |
732 | { | |
733 | unsigned int i; | |
734 | ||
735 | if (depth) | |
736 | { | |
737 | for (i = 0; i < depth; i++) | |
738 | fputs_filtered (" ", gdb_stdout); | |
739 | } | |
740 | ||
741 | /* A simple command, print it and return. */ | |
742 | if (cmd->control_type == simple_control) | |
743 | { | |
744 | fputs_filtered (cmd->line, gdb_stdout); | |
745 | fputs_filtered ("\n", gdb_stdout); | |
746 | return; | |
747 | } | |
748 | ||
749 | /* loop_continue to jump to the start of a while loop, print it | |
750 | and return. */ | |
751 | if (cmd->control_type == continue_control) | |
752 | { | |
753 | fputs_filtered ("loop_continue\n", gdb_stdout); | |
754 | return; | |
755 | } | |
756 | ||
757 | /* loop_break to break out of a while loop, print it and return. */ | |
758 | if (cmd->control_type == break_control) | |
759 | { | |
760 | fputs_filtered ("loop_break\n", gdb_stdout); | |
761 | return; | |
762 | } | |
763 | ||
764 | /* A while command. Recursively print its subcommands before returning. */ | |
765 | if (cmd->control_type == while_control) | |
766 | { | |
767 | struct command_line *list; | |
768 | fputs_filtered ("while ", gdb_stdout); | |
769 | fputs_filtered (cmd->line, gdb_stdout); | |
770 | fputs_filtered ("\n", gdb_stdout); | |
771 | list = *cmd->body_list; | |
772 | while (list) | |
773 | { | |
774 | print_command_line (list, depth + 1); | |
775 | list = list->next; | |
776 | } | |
777 | } | |
778 | ||
779 | /* An if command. Recursively print both arms before returning. */ | |
780 | if (cmd->control_type == if_control) | |
781 | { | |
782 | fputs_filtered ("if ", gdb_stdout); | |
783 | fputs_filtered (cmd->line, gdb_stdout); | |
784 | fputs_filtered ("\n", gdb_stdout); | |
785 | /* The true arm. */ | |
786 | print_command_line (cmd->body_list[0], depth + 1); | |
787 | ||
788 | /* Show the false arm if it exists. */ | |
789 | if (cmd->body_count == 2) | |
790 | { | |
791 | if (depth) | |
792 | { | |
793 | for (i = 0; i < depth; i++) | |
794 | fputs_filtered (" ", gdb_stdout); | |
795 | } | |
796 | fputs_filtered ("else\n", gdb_stdout); | |
797 | print_command_line (cmd->body_list[1], depth + 1); | |
798 | } | |
799 | if (depth) | |
800 | { | |
801 | for (i = 0; i < depth; i++) | |
802 | fputs_filtered (" ", gdb_stdout); | |
803 | } | |
804 | fputs_filtered ("end\n", gdb_stdout); | |
805 | } | |
806 | } | |
807 | ||
e52bfe0c JL |
808 | /* Execute the command in CMD. */ |
809 | ||
0f8cdd9b | 810 | enum command_control_type |
e52bfe0c JL |
811 | execute_control_command (cmd) |
812 | struct command_line *cmd; | |
813 | { | |
814 | struct expression *expr; | |
815 | struct command_line *current; | |
816 | struct cleanup *old_chain = 0; | |
e52bfe0c | 817 | value_ptr val; |
e20c36ba | 818 | value_ptr val_mark; |
e52bfe0c JL |
819 | int loop; |
820 | enum command_control_type ret; | |
0f8cdd9b | 821 | char *new_line; |
e52bfe0c JL |
822 | |
823 | switch (cmd->control_type) | |
824 | { | |
825 | case simple_control: | |
826 | /* A simple command, execute it and return. */ | |
0f8cdd9b JL |
827 | new_line = insert_args (cmd->line); |
828 | if (!new_line) | |
829 | return invalid_control; | |
ad3b8c4a JM |
830 | old_chain = make_cleanup ((make_cleanup_func) free_current_contents, |
831 | &new_line); | |
0f8cdd9b JL |
832 | execute_command (new_line, 0); |
833 | ret = cmd->control_type; | |
834 | break; | |
e52bfe0c JL |
835 | |
836 | case continue_control: | |
837 | case break_control: | |
838 | /* Return for "continue", and "break" so we can either | |
839 | continue the loop at the top, or break out. */ | |
0f8cdd9b JL |
840 | ret = cmd->control_type; |
841 | break; | |
e52bfe0c JL |
842 | |
843 | case while_control: | |
844 | { | |
845 | /* Parse the loop control expression for the while statement. */ | |
0f8cdd9b JL |
846 | new_line = insert_args (cmd->line); |
847 | if (!new_line) | |
848 | return invalid_control; | |
ad3b8c4a JM |
849 | old_chain = make_cleanup ((make_cleanup_func) free_current_contents, |
850 | &new_line); | |
0f8cdd9b | 851 | expr = parse_expression (new_line); |
ad3b8c4a | 852 | make_cleanup ((make_cleanup_func) free_current_contents, &expr); |
0f8cdd9b | 853 | |
e52bfe0c | 854 | ret = simple_control; |
b5776522 | 855 | loop = 1; |
e52bfe0c JL |
856 | |
857 | /* Keep iterating so long as the expression is true. */ | |
b5776522 | 858 | while (loop == 1) |
e52bfe0c | 859 | { |
e20c36ba JL |
860 | int cond_result; |
861 | ||
24ecc17a JL |
862 | QUIT; |
863 | ||
e52bfe0c | 864 | /* Evaluate the expression. */ |
e20c36ba | 865 | val_mark = value_mark (); |
e52bfe0c | 866 | val = evaluate_expression (expr); |
e20c36ba JL |
867 | cond_result = value_true (val); |
868 | value_free_to_mark (val_mark); | |
e52bfe0c JL |
869 | |
870 | /* If the value is false, then break out of the loop. */ | |
e20c36ba | 871 | if (!cond_result) |
e52bfe0c JL |
872 | break; |
873 | ||
874 | /* Execute the body of the while statement. */ | |
875 | current = *cmd->body_list; | |
876 | while (current) | |
877 | { | |
878 | ret = execute_control_command (current); | |
879 | ||
880 | /* If we got an error, or a "break" command, then stop | |
881 | looping. */ | |
882 | if (ret == invalid_control || ret == break_control) | |
883 | { | |
b5776522 | 884 | loop = 0; |
e52bfe0c JL |
885 | break; |
886 | } | |
887 | ||
888 | /* If we got a "continue" command, then restart the loop | |
889 | at this point. */ | |
890 | if (ret == continue_control) | |
891 | break; | |
892 | ||
893 | /* Get the next statement. */ | |
894 | current = current->next; | |
895 | } | |
896 | } | |
897 | ||
898 | /* Reset RET so that we don't recurse the break all the way down. */ | |
899 | if (ret == break_control) | |
900 | ret = simple_control; | |
901 | ||
902 | break; | |
903 | } | |
904 | ||
905 | case if_control: | |
906 | { | |
0f8cdd9b JL |
907 | new_line = insert_args (cmd->line); |
908 | if (!new_line) | |
909 | return invalid_control; | |
ad3b8c4a JM |
910 | old_chain = make_cleanup ((make_cleanup_func) free_current_contents, |
911 | &new_line); | |
e52bfe0c | 912 | /* Parse the conditional for the if statement. */ |
0f8cdd9b | 913 | expr = parse_expression (new_line); |
ad3b8c4a | 914 | make_cleanup ((make_cleanup_func) free_current_contents, &expr); |
e52bfe0c JL |
915 | |
916 | current = NULL; | |
917 | ret = simple_control; | |
918 | ||
919 | /* Evaluate the conditional. */ | |
e20c36ba | 920 | val_mark = value_mark (); |
e52bfe0c JL |
921 | val = evaluate_expression (expr); |
922 | ||
923 | /* Choose which arm to take commands from based on the value of the | |
924 | conditional expression. */ | |
925 | if (value_true (val)) | |
926 | current = *cmd->body_list; | |
927 | else if (cmd->body_count == 2) | |
928 | current = *(cmd->body_list + 1); | |
e20c36ba | 929 | value_free_to_mark (val_mark); |
e52bfe0c JL |
930 | |
931 | /* Execute commands in the given arm. */ | |
932 | while (current) | |
933 | { | |
934 | ret = execute_control_command (current); | |
935 | ||
936 | /* If we got an error, get out. */ | |
937 | if (ret != simple_control) | |
938 | break; | |
939 | ||
940 | /* Get the next statement in the body. */ | |
941 | current = current->next; | |
942 | } | |
0f8cdd9b | 943 | |
e52bfe0c JL |
944 | break; |
945 | } | |
946 | ||
947 | default: | |
948 | warning ("Invalid control type in command structure."); | |
949 | return invalid_control; | |
950 | } | |
951 | ||
952 | if (old_chain) | |
953 | do_cleanups (old_chain); | |
954 | ||
955 | return ret; | |
956 | } | |
957 | ||
958 | /* "while" command support. Executes a body of statements while the | |
959 | loop condition is nonzero. */ | |
960 | ||
961 | static void | |
962 | while_command (arg, from_tty) | |
963 | char *arg; | |
964 | int from_tty; | |
965 | { | |
966 | struct command_line *command = NULL; | |
967 | ||
968 | control_level = 1; | |
969 | command = get_command_line (while_control, arg); | |
970 | ||
971 | if (command == NULL) | |
972 | return; | |
973 | ||
974 | execute_control_command (command); | |
975 | free_command_lines (&command); | |
976 | } | |
977 | ||
978 | /* "if" command support. Execute either the true or false arm depending | |
979 | on the value of the if conditional. */ | |
980 | ||
981 | static void | |
982 | if_command (arg, from_tty) | |
983 | char *arg; | |
984 | int from_tty; | |
985 | { | |
986 | struct command_line *command = NULL; | |
987 | ||
988 | control_level = 1; | |
989 | command = get_command_line (if_control, arg); | |
990 | ||
991 | if (command == NULL) | |
992 | return; | |
993 | ||
994 | execute_control_command (command); | |
995 | free_command_lines (&command); | |
996 | } | |
997 | ||
0f8cdd9b JL |
998 | /* Cleanup */ |
999 | static void | |
1000 | arg_cleanup () | |
1001 | { | |
1002 | struct user_args *oargs = user_args; | |
1003 | if (!user_args) | |
1004 | fatal ("Internal error, arg_cleanup called with no user args.\n"); | |
1005 | ||
1006 | user_args = user_args->next; | |
1007 | free (oargs); | |
1008 | } | |
1009 | ||
1010 | /* Bind the incomming arguments for a user defined command to | |
1011 | $arg0, $arg1 ... $argMAXUSERARGS. */ | |
1012 | ||
1013 | static struct cleanup * | |
1014 | setup_user_args (p) | |
1015 | char *p; | |
1016 | { | |
1017 | struct user_args *args; | |
1018 | struct cleanup *old_chain; | |
1019 | unsigned int arg_count = 0; | |
1020 | ||
1021 | args = (struct user_args *)xmalloc (sizeof (struct user_args)); | |
1022 | memset (args, 0, sizeof (struct user_args)); | |
1023 | ||
1024 | args->next = user_args; | |
1025 | user_args = args; | |
1026 | ||
ad3b8c4a | 1027 | old_chain = make_cleanup ((make_cleanup_func) arg_cleanup, 0); |
0f8cdd9b JL |
1028 | |
1029 | if (p == NULL) | |
1030 | return old_chain; | |
1031 | ||
1032 | while (*p) | |
1033 | { | |
1034 | char *start_arg; | |
ac7a8760 PS |
1035 | int squote = 0; |
1036 | int dquote = 0; | |
1037 | int bsquote = 0; | |
0f8cdd9b JL |
1038 | |
1039 | if (arg_count >= MAXUSERARGS) | |
1040 | { | |
1041 | error ("user defined function may only have %d arguments.\n", | |
1042 | MAXUSERARGS); | |
1043 | return old_chain; | |
1044 | } | |
1045 | ||
1046 | /* Strip whitespace. */ | |
1047 | while (*p == ' ' || *p == '\t') | |
1048 | p++; | |
1049 | ||
1050 | /* P now points to an argument. */ | |
1051 | start_arg = p; | |
1052 | user_args->a[arg_count].arg = p; | |
1053 | ||
1054 | /* Get to the end of this argument. */ | |
ac7a8760 PS |
1055 | while (*p) |
1056 | { | |
1057 | if (((*p == ' ' || *p == '\t')) && !squote && !dquote && !bsquote) | |
1058 | break; | |
1059 | else | |
1060 | { | |
1061 | if (bsquote) | |
1062 | bsquote = 0; | |
1063 | else if (*p == '\\') | |
1064 | bsquote = 1; | |
1065 | else if (squote) | |
1066 | { | |
1067 | if (*p == '\'') | |
1068 | squote = 0; | |
1069 | } | |
1070 | else if (dquote) | |
1071 | { | |
1072 | if (*p == '"') | |
1073 | dquote = 0; | |
1074 | } | |
1075 | else | |
1076 | { | |
1077 | if (*p == '\'') | |
1078 | squote = 1; | |
1079 | else if (*p == '"') | |
1080 | dquote = 1; | |
1081 | } | |
1082 | p++; | |
1083 | } | |
1084 | } | |
0f8cdd9b JL |
1085 | |
1086 | user_args->a[arg_count].len = p - start_arg; | |
1087 | arg_count++; | |
1088 | user_args->count++; | |
1089 | } | |
1090 | return old_chain; | |
1091 | } | |
1092 | ||
1093 | /* Given character string P, return a point to the first argument ($arg), | |
1094 | or NULL if P contains no arguments. */ | |
1095 | ||
1096 | static char * | |
1097 | locate_arg (p) | |
1098 | char *p; | |
1099 | { | |
e3be225e | 1100 | while ((p = strchr (p, '$'))) |
0f8cdd9b JL |
1101 | { |
1102 | if (strncmp (p, "$arg", 4) == 0 && isdigit (p[4])) | |
1103 | return p; | |
1104 | p++; | |
1105 | } | |
1106 | return NULL; | |
1107 | } | |
1108 | ||
1109 | /* Insert the user defined arguments stored in user_arg into the $arg | |
1110 | arguments found in line, with the updated copy being placed into nline. */ | |
1111 | ||
1112 | static char * | |
1113 | insert_args (line) | |
1114 | char *line; | |
1115 | { | |
1116 | char *p, *save_line, *new_line; | |
1117 | unsigned len, i; | |
1118 | ||
1119 | /* First we need to know how much memory to allocate for the new line. */ | |
1120 | save_line = line; | |
1121 | len = 0; | |
e3be225e | 1122 | while ((p = locate_arg (line))) |
0f8cdd9b JL |
1123 | { |
1124 | len += p - line; | |
1125 | i = p[4] - '0'; | |
1126 | ||
1127 | if (i >= user_args->count) | |
1128 | { | |
1129 | error ("Missing argument %d in user function.\n", i); | |
1130 | return NULL; | |
1131 | } | |
1132 | len += user_args->a[i].len; | |
1133 | line = p + 5; | |
1134 | } | |
1135 | ||
1136 | /* Don't forget the tail. */ | |
1137 | len += strlen (line); | |
1138 | ||
1139 | /* Allocate space for the new line and fill it in. */ | |
1140 | new_line = (char *)xmalloc (len + 1); | |
1141 | if (new_line == NULL) | |
1142 | return NULL; | |
1143 | ||
1144 | /* Restore pointer to beginning of old line. */ | |
1145 | line = save_line; | |
1146 | ||
1147 | /* Save pointer to beginning of new line. */ | |
1148 | save_line = new_line; | |
1149 | ||
e3be225e | 1150 | while ((p = locate_arg (line))) |
0f8cdd9b JL |
1151 | { |
1152 | int i, len; | |
1153 | ||
1154 | memcpy (new_line, line, p - line); | |
1155 | new_line += p - line; | |
1156 | i = p[4] - '0'; | |
1157 | ||
e3be225e SS |
1158 | len = user_args->a[i].len; |
1159 | if (len) | |
0f8cdd9b JL |
1160 | { |
1161 | memcpy (new_line, user_args->a[i].arg, len); | |
1162 | new_line += len; | |
1163 | } | |
1164 | line = p + 5; | |
1165 | } | |
1166 | /* Don't forget the tail. */ | |
1167 | strcpy (new_line, line); | |
1168 | ||
1169 | /* Return a pointer to the beginning of the new line. */ | |
1170 | return save_line; | |
1171 | } | |
1172 | ||
172559ec JK |
1173 | void |
1174 | execute_user_command (c, args) | |
1175 | struct cmd_list_element *c; | |
1176 | char *args; | |
1177 | { | |
1178 | register struct command_line *cmdlines; | |
1179 | struct cleanup *old_chain; | |
e52bfe0c JL |
1180 | enum command_control_type ret; |
1181 | ||
0f8cdd9b | 1182 | old_chain = setup_user_args (args); |
172559ec JK |
1183 | |
1184 | cmdlines = c->user_commands; | |
1185 | if (cmdlines == 0) | |
1186 | /* Null command */ | |
1187 | return; | |
1188 | ||
1189 | /* Set the instream to 0, indicating execution of a | |
1190 | user-defined function. */ | |
ad3b8c4a | 1191 | old_chain = make_cleanup ((make_cleanup_func) source_cleanup, instream); |
172559ec JK |
1192 | instream = (FILE *) 0; |
1193 | while (cmdlines) | |
1194 | { | |
e52bfe0c JL |
1195 | ret = execute_control_command (cmdlines); |
1196 | if (ret != simple_control && ret != break_control) | |
1197 | { | |
1198 | warning ("Error in control structure.\n"); | |
1199 | break; | |
1200 | } | |
172559ec JK |
1201 | cmdlines = cmdlines->next; |
1202 | } | |
1203 | do_cleanups (old_chain); | |
1204 | } | |
1205 | ||
1206 | /* Execute the line P as a command. | |
1207 | Pass FROM_TTY as second argument to the defining function. */ | |
1208 | ||
1209 | void | |
1210 | execute_command (p, from_tty) | |
1211 | char *p; | |
1212 | int from_tty; | |
1213 | { | |
1214 | register struct cmd_list_element *c; | |
1215 | register enum language flang; | |
1216 | static int warned = 0; | |
b607efe7 | 1217 | /* FIXME: These should really be in an appropriate header file */ |
b607efe7 | 1218 | extern void serial_log_command PARAMS ((const char *)); |
172559ec JK |
1219 | |
1220 | free_all_values (); | |
1221 | ||
5959df8e JL |
1222 | /* Force cleanup of any alloca areas if using C alloca instead of |
1223 | a builtin alloca. */ | |
1224 | alloca (0); | |
1225 | ||
172559ec JK |
1226 | /* This can happen when command_line_input hits end of file. */ |
1227 | if (p == NULL) | |
1228 | return; | |
e52bfe0c | 1229 | |
d9951af4 | 1230 | serial_log_command (p); |
e8f1ad9a | 1231 | |
172559ec JK |
1232 | while (*p == ' ' || *p == '\t') p++; |
1233 | if (*p) | |
1234 | { | |
1235 | char *arg; | |
e52bfe0c | 1236 | |
172559ec JK |
1237 | c = lookup_cmd (&p, cmdlist, "", 0, 1); |
1238 | /* Pass null arg rather than an empty one. */ | |
1239 | arg = *p ? p : 0; | |
1240 | ||
080868b4 PS |
1241 | /* Clear off trailing whitespace, except for set and complete command. */ |
1242 | if (arg && c->type != set_cmd && c->function.cfunc != complete_command) | |
1243 | { | |
1244 | p = arg + strlen (arg) - 1; | |
1245 | while (p >= arg && (*p == ' ' || *p == '\t')) | |
1246 | p--; | |
1247 | *(p + 1) = '\0'; | |
1248 | } | |
1249 | ||
172559ec JK |
1250 | /* If this command has been hooked, run the hook first. */ |
1251 | if (c->hook) | |
1252 | execute_user_command (c->hook, (char *)0); | |
1253 | ||
1254 | if (c->class == class_user) | |
1255 | execute_user_command (c, arg); | |
1256 | else if (c->type == set_cmd || c->type == show_cmd) | |
1257 | do_setshow_command (arg, from_tty & caution, c); | |
1258 | else if (c->function.cfunc == NO_FUNCTION) | |
1259 | error ("That is not a command, just a help topic."); | |
479f0f18 SG |
1260 | else if (call_command_hook) |
1261 | call_command_hook (c, arg, from_tty & caution); | |
172559ec JK |
1262 | else |
1263 | (*c->function.cfunc) (arg, from_tty & caution); | |
1264 | } | |
1265 | ||
1266 | /* Tell the user if the language has changed (except first time). */ | |
1267 | if (current_language != expected_language) | |
1268 | { | |
1269 | if (language_mode == language_mode_auto) { | |
1270 | language_info (1); /* Print what changed. */ | |
1271 | } | |
1272 | warned = 0; | |
1273 | } | |
1274 | ||
1275 | /* Warn the user if the working language does not match the | |
1276 | language of the current frame. Only warn the user if we are | |
1277 | actually running the program, i.e. there is a stack. */ | |
1278 | /* FIXME: This should be cacheing the frame and only running when | |
1279 | the frame changes. */ | |
43ab4ba5 | 1280 | |
172559ec | 1281 | if (target_has_stack) |
172559ec | 1282 | { |
43ab4ba5 SS |
1283 | flang = get_frame_language (); |
1284 | if (!warned | |
1285 | && flang != language_unknown | |
1286 | && flang != current_language->la_language) | |
1287 | { | |
1288 | printf_filtered ("%s\n", lang_frame_mismatch_warn); | |
1289 | warned = 1; | |
1290 | } | |
172559ec | 1291 | } |
172559ec JK |
1292 | } |
1293 | ||
1294 | /* ARGSUSED */ | |
1295 | static void | |
1296 | command_loop_marker (foo) | |
1297 | int foo; | |
1298 | { | |
1299 | } | |
1300 | ||
1301 | /* Read commands from `instream' and execute them | |
1302 | until end of file or error reading instream. */ | |
43ab4ba5 | 1303 | |
172559ec JK |
1304 | void |
1305 | command_loop () | |
1306 | { | |
1307 | struct cleanup *old_chain; | |
1308 | char *command; | |
1309 | int stdin_is_tty = ISATTY (stdin); | |
43ab4ba5 | 1310 | long time_at_cmd_start; |
38d715a4 | 1311 | #ifdef HAVE_SBRK |
65b07ddc | 1312 | long space_at_cmd_start = 0; |
38d715a4 | 1313 | #endif |
43ab4ba5 SS |
1314 | extern int display_time; |
1315 | extern int display_space; | |
172559ec | 1316 | |
41756e56 | 1317 | while (instream && !feof (instream)) |
172559ec | 1318 | { |
65b07ddc DT |
1319 | #if defined(TUI) |
1320 | extern int insert_mode; | |
1321 | #endif | |
172559ec JK |
1322 | if (window_hook && instream == stdin) |
1323 | (*window_hook) (instream, prompt); | |
1324 | ||
1325 | quit_flag = 0; | |
1326 | if (instream == stdin && stdin_is_tty) | |
1327 | reinitialize_more_filter (); | |
ad3b8c4a | 1328 | old_chain = make_cleanup ((make_cleanup_func) command_loop_marker, 0); |
65b07ddc DT |
1329 | |
1330 | #if defined(TUI) | |
1331 | /* A bit of paranoia: I want to make sure the "insert_mode" global | |
1332 | * is clear except when it is being used for command-line editing | |
1333 | * (see tuiIO.c, utils.c); otherwise normal output will | |
1334 | * get messed up in the TUI. So clear it before/after | |
1335 | * the command-line-input call. - RT | |
1336 | */ | |
1337 | insert_mode = 0; | |
1338 | #endif | |
1339 | /* Get a command-line. This calls the readline package. */ | |
172559ec JK |
1340 | command = command_line_input (instream == stdin ? prompt : (char *) NULL, |
1341 | instream == stdin, "prompt"); | |
65b07ddc DT |
1342 | #if defined(TUI) |
1343 | insert_mode = 0; | |
1344 | #endif | |
172559ec JK |
1345 | if (command == 0) |
1346 | return; | |
43ab4ba5 SS |
1347 | |
1348 | time_at_cmd_start = get_run_time (); | |
1349 | ||
83ebf439 SS |
1350 | if (display_space) |
1351 | { | |
38d715a4 | 1352 | #ifdef HAVE_SBRK |
83ebf439 SS |
1353 | extern char **environ; |
1354 | char *lim = (char *) sbrk (0); | |
1355 | ||
1356 | space_at_cmd_start = (long) (lim - (char *) &environ); | |
38d715a4 | 1357 | #endif |
83ebf439 SS |
1358 | } |
1359 | ||
172559ec JK |
1360 | execute_command (command, instream == stdin); |
1361 | /* Do any commands attached to breakpoint we stopped at. */ | |
1362 | bpstat_do_actions (&stop_bpstat); | |
1363 | do_cleanups (old_chain); | |
43ab4ba5 SS |
1364 | |
1365 | if (display_time) | |
1366 | { | |
1367 | long cmd_time = get_run_time () - time_at_cmd_start; | |
1368 | ||
1369 | printf_unfiltered ("Command execution time: %ld.%06ld\n", | |
1370 | cmd_time / 1000000, cmd_time % 1000000); | |
1371 | } | |
1372 | ||
1373 | if (display_space) | |
1374 | { | |
38d715a4 | 1375 | #ifdef HAVE_SBRK |
43ab4ba5 SS |
1376 | extern char **environ; |
1377 | char *lim = (char *) sbrk (0); | |
83ebf439 SS |
1378 | long space_now = lim - (char *) &environ; |
1379 | long space_diff = space_now - space_at_cmd_start; | |
43ab4ba5 | 1380 | |
83ebf439 SS |
1381 | printf_unfiltered ("Space used: %ld (%c%ld for this command)\n", |
1382 | space_now, | |
1383 | (space_diff >= 0 ? '+' : '-'), | |
1384 | space_diff); | |
38d715a4 | 1385 | #endif |
43ab4ba5 | 1386 | } |
172559ec JK |
1387 | } |
1388 | } | |
1389 | \f | |
1390 | /* Commands call this if they do not want to be repeated by null lines. */ | |
1391 | ||
1392 | void | |
1393 | dont_repeat () | |
1394 | { | |
1395 | if (server_command) | |
1396 | return; | |
1397 | ||
1398 | /* If we aren't reading from standard input, we are saving the last | |
1399 | thing read from stdin in line and don't want to delete it. Null lines | |
1400 | won't repeat here in any case. */ | |
1401 | if (instream == stdin) | |
1402 | *line = 0; | |
1403 | } | |
1404 | \f | |
1405 | /* Read a line from the stream "instream" without command line editing. | |
1406 | ||
1407 | It prints PRROMPT once at the start. | |
e52bfe0c | 1408 | Action is compatible with "readline", e.g. space for the result is |
172559ec JK |
1409 | malloc'd and should be freed by the caller. |
1410 | ||
1411 | A NULL return means end of file. */ | |
1412 | char * | |
1413 | gdb_readline (prrompt) | |
1414 | char *prrompt; | |
1415 | { | |
1416 | int c; | |
1417 | char *result; | |
1418 | int input_index = 0; | |
1419 | int result_size = 80; | |
1420 | ||
1421 | if (prrompt) | |
1422 | { | |
1423 | /* Don't use a _filtered function here. It causes the assumed | |
1424 | character position to be off, since the newline we read from | |
1425 | the user is not accounted for. */ | |
1426 | fputs_unfiltered (prrompt, gdb_stdout); | |
172559ec JK |
1427 | #ifdef MPW |
1428 | /* Move to a new line so the entered line doesn't have a prompt | |
1429 | on the front of it. */ | |
1430 | fputs_unfiltered ("\n", gdb_stdout); | |
1431 | #endif /* MPW */ | |
172559ec JK |
1432 | gdb_flush (gdb_stdout); |
1433 | } | |
e52bfe0c | 1434 | |
172559ec JK |
1435 | result = (char *) xmalloc (result_size); |
1436 | ||
1437 | while (1) | |
1438 | { | |
1439 | /* Read from stdin if we are executing a user defined command. | |
1440 | This is the right thing for prompt_for_continue, at least. */ | |
1441 | c = fgetc (instream ? instream : stdin); | |
1442 | ||
1443 | if (c == EOF) | |
1444 | { | |
1445 | if (input_index > 0) | |
1446 | /* The last line does not end with a newline. Return it, and | |
1447 | if we are called again fgetc will still return EOF and | |
1448 | we'll return NULL then. */ | |
1449 | break; | |
1450 | free (result); | |
1451 | return NULL; | |
1452 | } | |
1453 | ||
1454 | if (c == '\n') | |
3cee93ac | 1455 | #ifndef CRLF_SOURCE_FILES |
172559ec | 1456 | break; |
3cee93ac CF |
1457 | #else |
1458 | { | |
1459 | if (input_index > 0 && result[input_index - 1] == '\r') | |
1460 | input_index--; | |
1461 | break; | |
1462 | } | |
1463 | #endif | |
172559ec JK |
1464 | |
1465 | result[input_index++] = c; | |
1466 | while (input_index >= result_size) | |
1467 | { | |
1468 | result_size *= 2; | |
1469 | result = (char *) xrealloc (result, result_size); | |
1470 | } | |
1471 | } | |
1472 | ||
1473 | result[input_index++] = '\0'; | |
1474 | return result; | |
1475 | } | |
1476 | ||
1477 | /* Variables which control command line editing and history | |
1478 | substitution. These variables are given default values at the end | |
1479 | of this file. */ | |
1480 | static int command_editing_p; | |
1481 | static int history_expansion_p; | |
1482 | static int write_history_p; | |
1483 | static int history_size; | |
1484 | static char *history_filename; | |
1485 | ||
1486 | /* readline uses the word breaks for two things: | |
1487 | (1) In figuring out where to point the TEXT parameter to the | |
1488 | rl_completion_entry_function. Since we don't use TEXT for much, | |
1489 | it doesn't matter a lot what the word breaks are for this purpose, but | |
1490 | it does affect how much stuff M-? lists. | |
1491 | (2) If one of the matches contains a word break character, readline | |
1492 | will quote it. That's why we switch between | |
1493 | gdb_completer_word_break_characters and | |
1494 | gdb_completer_command_word_break_characters. I'm not sure when | |
1495 | we need this behavior (perhaps for funky characters in C++ symbols?). */ | |
1496 | ||
1497 | /* Variables which are necessary for fancy command line editing. */ | |
1498 | char *gdb_completer_word_break_characters = | |
1499 | " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; | |
1500 | ||
1501 | /* When completing on command names, we remove '-' from the list of | |
1502 | word break characters, since we use it in command names. If the | |
1503 | readline library sees one in any of the current completion strings, | |
1504 | it thinks that the string needs to be quoted and automatically supplies | |
1505 | a leading quote. */ | |
1506 | char *gdb_completer_command_word_break_characters = | |
1507 | " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,"; | |
1508 | ||
1509 | /* Characters that can be used to quote completion strings. Note that we | |
1510 | can't include '"' because the gdb C parser treats such quoted sequences | |
1511 | as strings. */ | |
1512 | char *gdb_completer_quote_characters = | |
1513 | "'"; | |
1514 | ||
1515 | /* Functions that are used as part of the fancy command line editing. */ | |
1516 | ||
1517 | /* This can be used for functions which don't want to complete on symbols | |
1518 | but don't want to complete on anything else either. */ | |
1519 | /* ARGSUSED */ | |
1520 | char ** | |
1521 | noop_completer (text, prefix) | |
1522 | char *text; | |
1523 | char *prefix; | |
1524 | { | |
1525 | return NULL; | |
1526 | } | |
1527 | ||
1528 | /* Complete on filenames. */ | |
1529 | char ** | |
1530 | filename_completer (text, word) | |
1531 | char *text; | |
1532 | char *word; | |
1533 | { | |
1534 | /* From readline. */ | |
3f550b59 | 1535 | extern char *filename_completion_function PARAMS ((char *, int)); |
172559ec JK |
1536 | int subsequent_name; |
1537 | char **return_val; | |
1538 | int return_val_used; | |
1539 | int return_val_alloced; | |
1540 | ||
1541 | return_val_used = 0; | |
1542 | /* Small for testing. */ | |
1543 | return_val_alloced = 1; | |
1544 | return_val = (char **) xmalloc (return_val_alloced * sizeof (char *)); | |
1545 | ||
1546 | subsequent_name = 0; | |
1547 | while (1) | |
1548 | { | |
1549 | char *p; | |
1550 | p = filename_completion_function (text, subsequent_name); | |
1551 | if (return_val_used >= return_val_alloced) | |
1552 | { | |
1553 | return_val_alloced *= 2; | |
1554 | return_val = | |
1555 | (char **) xrealloc (return_val, | |
1556 | return_val_alloced * sizeof (char *)); | |
1557 | } | |
1558 | if (p == NULL) | |
1559 | { | |
1560 | return_val[return_val_used++] = p; | |
1561 | break; | |
1562 | } | |
1563 | /* Like emacs, don't complete on old versions. Especially useful | |
1564 | in the "source" command. */ | |
1565 | if (p[strlen (p) - 1] == '~') | |
1566 | continue; | |
1567 | ||
1568 | { | |
1569 | char *q; | |
1570 | if (word == text) | |
1571 | /* Return exactly p. */ | |
1572 | return_val[return_val_used++] = p; | |
1573 | else if (word > text) | |
1574 | { | |
1575 | /* Return some portion of p. */ | |
1576 | q = xmalloc (strlen (p) + 5); | |
1577 | strcpy (q, p + (word - text)); | |
1578 | return_val[return_val_used++] = q; | |
1579 | free (p); | |
1580 | } | |
1581 | else | |
1582 | { | |
1583 | /* Return some of TEXT plus p. */ | |
1584 | q = xmalloc (strlen (p) + (text - word) + 5); | |
1585 | strncpy (q, word, text - word); | |
1586 | q[text - word] = '\0'; | |
1587 | strcat (q, p); | |
1588 | return_val[return_val_used++] = q; | |
1589 | free (p); | |
1590 | } | |
1591 | } | |
1592 | subsequent_name = 1; | |
1593 | } | |
1594 | #if 0 | |
1595 | /* There is no way to do this just long enough to affect quote inserting | |
1596 | without also affecting the next completion. This should be fixed in | |
1597 | readline. FIXME. */ | |
1598 | /* Insure that readline does the right thing | |
1599 | with respect to inserting quotes. */ | |
1600 | rl_completer_word_break_characters = ""; | |
1601 | #endif | |
1602 | return return_val; | |
1603 | } | |
1604 | ||
1605 | /* Here are some useful test cases for completion. FIXME: These should | |
1606 | be put in the test suite. They should be tested with both M-? and TAB. | |
1607 | ||
1608 | "show output-" "radix" | |
1609 | "show output" "-radix" | |
1610 | "p" ambiguous (commands starting with p--path, print, printf, etc.) | |
1611 | "p " ambiguous (all symbols) | |
1612 | "info t foo" no completions | |
1613 | "info t " no completions | |
1614 | "info t" ambiguous ("info target", "info terminal", etc.) | |
1615 | "info ajksdlfk" no completions | |
1616 | "info ajksdlfk " no completions | |
1617 | "info" " " | |
1618 | "info " ambiguous (all info commands) | |
1619 | "p \"a" no completions (string constant) | |
1620 | "p 'a" ambiguous (all symbols starting with a) | |
1621 | "p b-a" ambiguous (all symbols starting with a) | |
1622 | "p b-" ambiguous (all symbols) | |
1623 | "file Make" "file" (word break hard to screw up here) | |
1624 | "file ../gdb.stabs/we" "ird" (needs to not break word at slash) | |
1625 | */ | |
1626 | ||
1627 | /* Generate completions one by one for the completer. Each time we are | |
9ed8604f PS |
1628 | called return another potential completion to the caller. |
1629 | line_completion just completes on commands or passes the buck to the | |
1630 | command's completer function, the stuff specific to symbol completion | |
172559ec JK |
1631 | is in make_symbol_completion_list. |
1632 | ||
9ed8604f | 1633 | TEXT is the caller's idea of the "word" we are looking at. |
172559ec JK |
1634 | |
1635 | MATCHES is the number of matches that have currently been collected from | |
1636 | calling this completion function. When zero, then we need to initialize, | |
1637 | otherwise the initialization has already taken place and we can just | |
1638 | return the next potential completion string. | |
1639 | ||
9ed8604f PS |
1640 | LINE_BUFFER is available to be looked at; it contains the entire text |
1641 | of the line. POINT is the offset in that line of the cursor. You | |
1642 | should pretend that the line ends at POINT. | |
172559ec | 1643 | |
9ed8604f PS |
1644 | Returns NULL if there are no more completions, else a pointer to a string |
1645 | which is a possible completion, it is the caller's responsibility to | |
1646 | free the string. */ | |
172559ec JK |
1647 | |
1648 | static char * | |
9ed8604f | 1649 | line_completion_function (text, matches, line_buffer, point) |
172559ec JK |
1650 | char *text; |
1651 | int matches; | |
9ed8604f PS |
1652 | char *line_buffer; |
1653 | int point; | |
172559ec JK |
1654 | { |
1655 | static char **list = (char **)NULL; /* Cache of completions */ | |
1656 | static int index; /* Next cached completion */ | |
1657 | char *output = NULL; | |
1658 | char *tmp_command, *p; | |
1659 | /* Pointer within tmp_command which corresponds to text. */ | |
1660 | char *word; | |
1661 | struct cmd_list_element *c, *result_list; | |
1662 | ||
1663 | if (matches == 0) | |
1664 | { | |
1665 | /* The caller is beginning to accumulate a new set of completions, so | |
1666 | we need to find all of them now, and cache them for returning one at | |
1667 | a time on future calls. */ | |
1668 | ||
1669 | if (list) | |
1670 | { | |
1671 | /* Free the storage used by LIST, but not by the strings inside. | |
1672 | This is because rl_complete_internal () frees the strings. */ | |
1673 | free ((PTR)list); | |
1674 | } | |
1675 | list = 0; | |
1676 | index = 0; | |
1677 | ||
1678 | /* Choose the default set of word break characters to break completions. | |
1679 | If we later find out that we are doing completions on command strings | |
1680 | (as opposed to strings supplied by the individual command completer | |
1681 | functions, which can be any string) then we will switch to the | |
1682 | special word break set for command strings, which leaves out the | |
1683 | '-' character used in some commands. */ | |
1684 | ||
1685 | rl_completer_word_break_characters = | |
1686 | gdb_completer_word_break_characters; | |
1687 | ||
1688 | /* Decide whether to complete on a list of gdb commands or on symbols. */ | |
9ed8604f | 1689 | tmp_command = (char *) alloca (point + 1); |
172559ec JK |
1690 | p = tmp_command; |
1691 | ||
9ed8604f PS |
1692 | strncpy (tmp_command, line_buffer, point); |
1693 | tmp_command[point] = '\0'; | |
172559ec | 1694 | /* Since text always contains some number of characters leading up |
9ed8604f | 1695 | to point, we can find the equivalent position in tmp_command |
172559ec | 1696 | by subtracting that many characters from the end of tmp_command. */ |
9ed8604f | 1697 | word = tmp_command + point - strlen (text); |
172559ec | 1698 | |
9ed8604f | 1699 | if (point == 0) |
172559ec JK |
1700 | { |
1701 | /* An empty line we want to consider ambiguous; that is, it | |
1702 | could be any command. */ | |
1703 | c = (struct cmd_list_element *) -1; | |
1704 | result_list = 0; | |
1705 | } | |
1706 | else | |
1707 | { | |
1708 | c = lookup_cmd_1 (&p, cmdlist, &result_list, 1); | |
1709 | } | |
1710 | ||
1711 | /* Move p up to the next interesting thing. */ | |
1712 | while (*p == ' ' || *p == '\t') | |
1713 | { | |
1714 | p++; | |
1715 | } | |
1716 | ||
1717 | if (!c) | |
1718 | { | |
1719 | /* It is an unrecognized command. So there are no | |
1720 | possible completions. */ | |
1721 | list = NULL; | |
1722 | } | |
1723 | else if (c == (struct cmd_list_element *) -1) | |
1724 | { | |
1725 | char *q; | |
1726 | ||
1727 | /* lookup_cmd_1 advances p up to the first ambiguous thing, but | |
1728 | doesn't advance over that thing itself. Do so now. */ | |
1729 | q = p; | |
1730 | while (*q && (isalnum (*q) || *q == '-' || *q == '_')) | |
1731 | ++q; | |
9ed8604f | 1732 | if (q != tmp_command + point) |
172559ec JK |
1733 | { |
1734 | /* There is something beyond the ambiguous | |
1735 | command, so there are no possible completions. For | |
1736 | example, "info t " or "info t foo" does not complete | |
1737 | to anything, because "info t" can be "info target" or | |
1738 | "info terminal". */ | |
1739 | list = NULL; | |
1740 | } | |
1741 | else | |
1742 | { | |
1743 | /* We're trying to complete on the command which was ambiguous. | |
1744 | This we can deal with. */ | |
1745 | if (result_list) | |
1746 | { | |
1747 | list = complete_on_cmdlist (*result_list->prefixlist, p, | |
1748 | word); | |
1749 | } | |
1750 | else | |
1751 | { | |
1752 | list = complete_on_cmdlist (cmdlist, p, word); | |
1753 | } | |
1754 | /* Insure that readline does the right thing with respect to | |
1755 | inserting quotes. */ | |
1756 | rl_completer_word_break_characters = | |
1757 | gdb_completer_command_word_break_characters; | |
1758 | } | |
1759 | } | |
1760 | else | |
1761 | { | |
1762 | /* We've recognized a full command. */ | |
1763 | ||
9ed8604f | 1764 | if (p == tmp_command + point) |
172559ec JK |
1765 | { |
1766 | /* There is no non-whitespace in the line beyond the command. */ | |
1767 | ||
1768 | if (p[-1] == ' ' || p[-1] == '\t') | |
1769 | { | |
1770 | /* The command is followed by whitespace; we need to complete | |
1771 | on whatever comes after command. */ | |
1772 | if (c->prefixlist) | |
1773 | { | |
1774 | /* It is a prefix command; what comes after it is | |
1775 | a subcommand (e.g. "info "). */ | |
1776 | list = complete_on_cmdlist (*c->prefixlist, p, word); | |
1777 | ||
1778 | /* Insure that readline does the right thing | |
1779 | with respect to inserting quotes. */ | |
1780 | rl_completer_word_break_characters = | |
1781 | gdb_completer_command_word_break_characters; | |
1782 | } | |
09374c98 SG |
1783 | else if (c->enums) |
1784 | { | |
1785 | list = complete_on_enum (c->enums, p, word); | |
1786 | rl_completer_word_break_characters = | |
1787 | gdb_completer_command_word_break_characters; | |
1788 | } | |
172559ec JK |
1789 | else |
1790 | { | |
1791 | /* It is a normal command; what comes after it is | |
1792 | completed by the command's completer function. */ | |
1793 | list = (*c->completer) (p, word); | |
1794 | } | |
1795 | } | |
1796 | else | |
1797 | { | |
1798 | /* The command is not followed by whitespace; we need to | |
1799 | complete on the command itself. e.g. "p" which is a | |
1800 | command itself but also can complete to "print", "ptype" | |
1801 | etc. */ | |
1802 | char *q; | |
1803 | ||
1804 | /* Find the command we are completing on. */ | |
1805 | q = p; | |
1806 | while (q > tmp_command) | |
1807 | { | |
1808 | if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_') | |
1809 | --q; | |
1810 | else | |
1811 | break; | |
1812 | } | |
1813 | ||
1814 | list = complete_on_cmdlist (result_list, q, word); | |
1815 | ||
1816 | /* Insure that readline does the right thing | |
1817 | with respect to inserting quotes. */ | |
1818 | rl_completer_word_break_characters = | |
1819 | gdb_completer_command_word_break_characters; | |
1820 | } | |
1821 | } | |
1822 | else | |
1823 | { | |
1824 | /* There is non-whitespace beyond the command. */ | |
1825 | ||
1826 | if (c->prefixlist && !c->allow_unknown) | |
1827 | { | |
1828 | /* It is an unrecognized subcommand of a prefix command, | |
1829 | e.g. "info adsfkdj". */ | |
1830 | list = NULL; | |
1831 | } | |
09374c98 SG |
1832 | else if (c->enums) |
1833 | { | |
1834 | list = complete_on_enum (c->enums, p, word); | |
1835 | } | |
172559ec JK |
1836 | else |
1837 | { | |
1838 | /* It is a normal command. */ | |
1839 | list = (*c->completer) (p, word); | |
1840 | } | |
1841 | } | |
1842 | } | |
1843 | } | |
1844 | ||
1845 | /* If we found a list of potential completions during initialization then | |
1846 | dole them out one at a time. The vector of completions is NULL | |
1847 | terminated, so after returning the last one, return NULL (and continue | |
1848 | to do so) each time we are called after that, until a new list is | |
1849 | available. */ | |
1850 | ||
1851 | if (list) | |
1852 | { | |
1853 | output = list[index]; | |
1854 | if (output) | |
1855 | { | |
1856 | index++; | |
1857 | } | |
1858 | } | |
1859 | ||
1860 | #if 0 | |
1861 | /* Can't do this because readline hasn't yet checked the word breaks | |
1862 | for figuring out whether to insert a quote. */ | |
1863 | if (output == NULL) | |
1864 | /* Make sure the word break characters are set back to normal for the | |
1865 | next time that readline tries to complete something. */ | |
1866 | rl_completer_word_break_characters = | |
1867 | gdb_completer_word_break_characters; | |
1868 | #endif | |
1869 | ||
1870 | return (output); | |
1871 | } | |
1872 | ||
9ed8604f PS |
1873 | /* Line completion interface function for readline. */ |
1874 | ||
1875 | static char * | |
1876 | readline_line_completion_function (text, matches) | |
1877 | char *text; | |
1878 | int matches; | |
1879 | { | |
1880 | return line_completion_function (text, matches, rl_line_buffer, rl_point); | |
1881 | } | |
1882 | ||
172559ec JK |
1883 | /* Skip over a possibly quoted word (as defined by the quote characters |
1884 | and word break characters the completer uses). Returns pointer to the | |
1885 | location after the "word". */ | |
1886 | ||
1887 | char * | |
1888 | skip_quoted (str) | |
1889 | char *str; | |
1890 | { | |
1891 | char quote_char = '\0'; | |
1892 | char *scan; | |
1893 | ||
1894 | for (scan = str; *scan != '\0'; scan++) | |
1895 | { | |
1896 | if (quote_char != '\0') | |
1897 | { | |
1898 | /* Ignore everything until the matching close quote char */ | |
1899 | if (*scan == quote_char) | |
1900 | { | |
1901 | /* Found matching close quote. */ | |
1902 | scan++; | |
1903 | break; | |
1904 | } | |
1905 | } | |
1906 | else if (strchr (gdb_completer_quote_characters, *scan)) | |
1907 | { | |
1908 | /* Found start of a quoted string. */ | |
1909 | quote_char = *scan; | |
1910 | } | |
1911 | else if (strchr (gdb_completer_word_break_characters, *scan)) | |
1912 | { | |
1913 | break; | |
1914 | } | |
1915 | } | |
1916 | return (scan); | |
1917 | } | |
1918 | ||
1919 | \f | |
1920 | #ifdef STOP_SIGNAL | |
1921 | static void | |
1922 | stop_sig (signo) | |
1923 | int signo; | |
1924 | { | |
1925 | #if STOP_SIGNAL == SIGTSTP | |
1926 | signal (SIGTSTP, SIG_DFL); | |
1927 | sigsetmask (0); | |
1928 | kill (getpid (), SIGTSTP); | |
1929 | signal (SIGTSTP, stop_sig); | |
1930 | #else | |
1931 | signal (STOP_SIGNAL, stop_sig); | |
1932 | #endif | |
1933 | printf_unfiltered ("%s", prompt); | |
1934 | gdb_flush (gdb_stdout); | |
1935 | ||
1936 | /* Forget about any previous command -- null line now will do nothing. */ | |
1937 | dont_repeat (); | |
1938 | } | |
1939 | #endif /* STOP_SIGNAL */ | |
1940 | ||
1941 | /* Initialize signal handlers. */ | |
1942 | static void | |
1943 | do_nothing (signo) | |
1944 | int signo; | |
1945 | { | |
8d743926 JM |
1946 | /* Under System V the default disposition of a signal is reinstated after |
1947 | the signal is caught and delivered to an application process. On such | |
1948 | systems one must restore the replacement signal handler if one wishes | |
1949 | to continue handling the signal in one's program. On BSD systems this | |
1950 | is not needed but it is harmless, and it simplifies the code to just do | |
1951 | it unconditionally. */ | |
1952 | signal (signo, do_nothing); | |
172559ec JK |
1953 | } |
1954 | ||
1955 | static void | |
1956 | init_signals () | |
1957 | { | |
1958 | signal (SIGINT, request_quit); | |
1959 | ||
255181a9 PS |
1960 | /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed |
1961 | to the inferior and breakpoints will be ignored. */ | |
1962 | #ifdef SIGTRAP | |
1963 | signal (SIGTRAP, SIG_DFL); | |
1964 | #endif | |
1965 | ||
172559ec JK |
1966 | /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get |
1967 | passed to the inferior, which we don't want. It would be | |
1968 | possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but | |
1969 | on BSD4.3 systems using vfork, that can affect the | |
1970 | GDB process as well as the inferior (the signal handling tables | |
1971 | might be in memory, shared between the two). Since we establish | |
1972 | a handler for SIGQUIT, when we call exec it will set the signal | |
1973 | to SIG_DFL for us. */ | |
1974 | signal (SIGQUIT, do_nothing); | |
4ce7ba51 | 1975 | #ifdef SIGHUP |
172559ec JK |
1976 | if (signal (SIGHUP, do_nothing) != SIG_IGN) |
1977 | signal (SIGHUP, disconnect); | |
4ce7ba51 | 1978 | #endif |
172559ec JK |
1979 | signal (SIGFPE, float_handler); |
1980 | ||
1981 | #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER) | |
1982 | signal (SIGWINCH, SIGWINCH_HANDLER); | |
1983 | #endif | |
1984 | } | |
1985 | \f | |
1986 | /* Read one line from the command input stream `instream' | |
1987 | into the local static buffer `linebuffer' (whose current length | |
1988 | is `linelength'). | |
1989 | The buffer is made bigger as necessary. | |
1990 | Returns the address of the start of the line. | |
1991 | ||
1992 | NULL is returned for end of file. | |
1993 | ||
1994 | *If* the instream == stdin & stdin is a terminal, the line read | |
1995 | is copied into the file line saver (global var char *line, | |
1996 | length linesize) so that it can be duplicated. | |
1997 | ||
1998 | This routine either uses fancy command line editing or | |
1999 | simple input as the user has requested. */ | |
2000 | ||
2001 | char * | |
2002 | command_line_input (prrompt, repeat, annotation_suffix) | |
2003 | char *prrompt; | |
2004 | int repeat; | |
2005 | char *annotation_suffix; | |
2006 | { | |
2007 | static char *linebuffer = 0; | |
2008 | static unsigned linelength = 0; | |
2009 | register char *p; | |
2010 | char *p1; | |
2011 | char *rl; | |
2012 | char *local_prompt = prrompt; | |
172559ec JK |
2013 | char *nline; |
2014 | char got_eof = 0; | |
2015 | ||
dfb14bc8 SS |
2016 | /* The annotation suffix must be non-NULL. */ |
2017 | if (annotation_suffix == NULL) | |
2018 | annotation_suffix = ""; | |
2019 | ||
172559ec JK |
2020 | if (annotation_level > 1 && instream == stdin) |
2021 | { | |
2022 | local_prompt = alloca ((prrompt == NULL ? 0 : strlen (prrompt)) | |
2023 | + strlen (annotation_suffix) + 40); | |
2024 | if (prrompt == NULL) | |
2025 | local_prompt[0] = '\0'; | |
2026 | else | |
2027 | strcpy (local_prompt, prrompt); | |
2028 | strcat (local_prompt, "\n\032\032"); | |
2029 | strcat (local_prompt, annotation_suffix); | |
2030 | strcat (local_prompt, "\n"); | |
2031 | } | |
2032 | ||
2033 | if (linebuffer == 0) | |
2034 | { | |
2035 | linelength = 80; | |
2036 | linebuffer = (char *) xmalloc (linelength); | |
2037 | } | |
2038 | ||
2039 | p = linebuffer; | |
2040 | ||
2041 | /* Control-C quits instantly if typed while in this loop | |
2042 | since it should not wait until the user types a newline. */ | |
2043 | immediate_quit++; | |
2044 | #ifdef STOP_SIGNAL | |
2045 | if (job_control) | |
2046 | signal (STOP_SIGNAL, stop_sig); | |
2047 | #endif | |
2048 | ||
2049 | while (1) | |
2050 | { | |
2051 | /* Make sure that all output has been output. Some machines may let | |
2052 | you get away with leaving out some of the gdb_flush, but not all. */ | |
2053 | wrap_here (""); | |
2054 | gdb_flush (gdb_stdout); | |
2055 | gdb_flush (gdb_stderr); | |
2056 | ||
2057 | if (source_file_name != NULL) | |
2058 | { | |
2059 | ++source_line_number; | |
2060 | sprintf (source_error, | |
2061 | "%s%s:%d: Error in sourced command file:\n", | |
2062 | source_pre_error, | |
2063 | source_file_name, | |
2064 | source_line_number); | |
2065 | error_pre_print = source_error; | |
2066 | } | |
2067 | ||
2068 | if (annotation_level > 1 && instream == stdin) | |
2069 | { | |
2070 | printf_unfiltered ("\n\032\032pre-"); | |
2071 | printf_unfiltered (annotation_suffix); | |
2072 | printf_unfiltered ("\n"); | |
2073 | } | |
2074 | ||
2075 | /* Don't use fancy stuff if not talking to stdin. */ | |
41756e56 FF |
2076 | if (readline_hook && instream == NULL) |
2077 | { | |
2078 | rl = (*readline_hook) (local_prompt); | |
2079 | } | |
2080 | else if (command_editing_p && instream == stdin && ISATTY (instream)) | |
2081 | { | |
2082 | rl = readline (local_prompt); | |
2083 | } | |
172559ec | 2084 | else |
41756e56 FF |
2085 | { |
2086 | rl = gdb_readline (local_prompt); | |
2087 | } | |
172559ec JK |
2088 | |
2089 | if (annotation_level > 1 && instream == stdin) | |
2090 | { | |
2091 | printf_unfiltered ("\n\032\032post-"); | |
2092 | printf_unfiltered (annotation_suffix); | |
2093 | printf_unfiltered ("\n"); | |
2094 | } | |
2095 | ||
2096 | if (!rl || rl == (char *) EOF) | |
2097 | { | |
2098 | got_eof = 1; | |
2099 | break; | |
2100 | } | |
2101 | if (strlen(rl) + 1 + (p - linebuffer) > linelength) | |
2102 | { | |
2103 | linelength = strlen(rl) + 1 + (p - linebuffer); | |
2104 | nline = (char *) xrealloc (linebuffer, linelength); | |
2105 | p += nline - linebuffer; | |
2106 | linebuffer = nline; | |
2107 | } | |
2108 | p1 = rl; | |
2109 | /* Copy line. Don't copy null at end. (Leaves line alone | |
2110 | if this was just a newline) */ | |
2111 | while (*p1) | |
2112 | *p++ = *p1++; | |
2113 | ||
2114 | free (rl); /* Allocated in readline. */ | |
2115 | ||
2116 | if (p == linebuffer || *(p - 1) != '\\') | |
2117 | break; | |
2118 | ||
2119 | p--; /* Put on top of '\'. */ | |
2120 | local_prompt = (char *) 0; | |
2121 | } | |
2122 | ||
2123 | #ifdef STOP_SIGNAL | |
2124 | if (job_control) | |
2125 | signal (STOP_SIGNAL, SIG_DFL); | |
2126 | #endif | |
2127 | immediate_quit--; | |
2128 | ||
2129 | if (got_eof) | |
2130 | return NULL; | |
2131 | ||
2132 | #define SERVER_COMMAND_LENGTH 7 | |
2133 | server_command = | |
2134 | (p - linebuffer > SERVER_COMMAND_LENGTH) | |
2135 | && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH); | |
2136 | if (server_command) | |
2137 | { | |
2138 | /* Note that we don't set `line'. Between this and the check in | |
2139 | dont_repeat, this insures that repeating will still do the | |
2140 | right thing. */ | |
2141 | *p = '\0'; | |
2142 | return linebuffer + SERVER_COMMAND_LENGTH; | |
2143 | } | |
2144 | ||
2145 | /* Do history expansion if that is wished. */ | |
2146 | if (history_expansion_p && instream == stdin | |
2147 | && ISATTY (instream)) | |
2148 | { | |
2149 | char *history_value; | |
2150 | int expanded; | |
2151 | ||
2152 | *p = '\0'; /* Insert null now. */ | |
2153 | expanded = history_expand (linebuffer, &history_value); | |
2154 | if (expanded) | |
2155 | { | |
2156 | /* Print the changes. */ | |
2157 | printf_unfiltered ("%s\n", history_value); | |
2158 | ||
2159 | /* If there was an error, call this function again. */ | |
2160 | if (expanded < 0) | |
2161 | { | |
2162 | free (history_value); | |
2163 | return command_line_input (prrompt, repeat, annotation_suffix); | |
2164 | } | |
2165 | if (strlen (history_value) > linelength) | |
2166 | { | |
2167 | linelength = strlen (history_value) + 1; | |
2168 | linebuffer = (char *) xrealloc (linebuffer, linelength); | |
2169 | } | |
2170 | strcpy (linebuffer, history_value); | |
2171 | p = linebuffer + strlen(linebuffer); | |
2172 | free (history_value); | |
2173 | } | |
2174 | } | |
2175 | ||
2176 | /* If we just got an empty line, and that is supposed | |
2177 | to repeat the previous command, return the value in the | |
2178 | global buffer. */ | |
f2ed3a80 PB |
2179 | if (repeat && p == linebuffer) |
2180 | return line; | |
2181 | for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++) ; | |
2182 | if (repeat && !*p1) | |
2183 | return line; | |
172559ec JK |
2184 | |
2185 | *p = 0; | |
2186 | ||
2187 | /* Add line to history if appropriate. */ | |
2188 | if (instream == stdin | |
2189 | && ISATTY (stdin) && *linebuffer) | |
2190 | add_history (linebuffer); | |
2191 | ||
2192 | /* Note: lines consisting solely of comments are added to the command | |
2193 | history. This is useful when you type a command, and then | |
2194 | realize you don't want to execute it quite yet. You can comment | |
2195 | out the command and then later fetch it from the value history | |
2196 | and remove the '#'. The kill ring is probably better, but some | |
2197 | people are in the habit of commenting things out. */ | |
f2ed3a80 PB |
2198 | if (*p1 == '#') |
2199 | *p1 = '\0'; /* Found a comment. */ | |
172559ec JK |
2200 | |
2201 | /* Save into global buffer if appropriate. */ | |
2202 | if (repeat) | |
2203 | { | |
2204 | if (linelength > linesize) | |
2205 | { | |
2206 | line = xrealloc (line, linelength); | |
2207 | linesize = linelength; | |
2208 | } | |
2209 | strcpy (line, linebuffer); | |
2210 | return line; | |
2211 | } | |
2212 | ||
2213 | return linebuffer; | |
2214 | } | |
2215 | \f | |
e52bfe0c JL |
2216 | |
2217 | /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH | |
2218 | code bodies. This is typically used when we encounter an "else" | |
2219 | clause for an "if" command. */ | |
2220 | ||
2221 | static void | |
2222 | realloc_body_list (command, new_length) | |
2223 | struct command_line *command; | |
2224 | int new_length; | |
2225 | { | |
2226 | int n; | |
2227 | struct command_line **body_list; | |
2228 | ||
2229 | n = command->body_count; | |
2230 | ||
2231 | /* Nothing to do? */ | |
2232 | if (new_length <= n) | |
2233 | return; | |
2234 | ||
2235 | body_list = (struct command_line **) | |
2236 | xmalloc (sizeof (struct command_line *) * new_length); | |
2237 | ||
2238 | memcpy (body_list, command->body_list, sizeof (struct command_line *) * n); | |
2239 | ||
2240 | free (command->body_list); | |
2241 | command->body_list = body_list; | |
2242 | command->body_count = new_length; | |
2243 | } | |
2244 | ||
2245 | /* Read one line from the input stream. If the command is an "else" or | |
2246 | "end", return such an indication to the caller. */ | |
2247 | ||
2248 | static enum misc_command_type | |
2249 | read_next_line (command) | |
2250 | struct command_line **command; | |
2251 | { | |
2252 | char *p, *p1, *prompt_ptr, control_prompt[256]; | |
2253 | int i = 0; | |
2254 | ||
2255 | if (control_level >= 254) | |
2256 | error ("Control nesting too deep!\n"); | |
2257 | ||
2258 | /* Set a prompt based on the nesting of the control commands. */ | |
41756e56 | 2259 | if (instream == stdin || (instream == 0 && readline_hook != NULL)) |
e52bfe0c JL |
2260 | { |
2261 | for (i = 0; i < control_level; i++) | |
2262 | control_prompt[i] = ' '; | |
2263 | control_prompt[i] = '>'; | |
2264 | control_prompt[i+1] = '\0'; | |
2265 | prompt_ptr = (char *)&control_prompt[0]; | |
2266 | } | |
2267 | else | |
2268 | prompt_ptr = NULL; | |
2269 | ||
e04f8901 | 2270 | p = command_line_input (prompt_ptr, instream == stdin, "commands"); |
e52bfe0c JL |
2271 | |
2272 | /* Not sure what to do here. */ | |
2273 | if (p == NULL) | |
2274 | return end_command; | |
2275 | ||
2276 | /* Strip leading and trailing whitespace. */ | |
2277 | while (*p == ' ' || *p == '\t') | |
2278 | p++; | |
2279 | ||
2280 | p1 = p + strlen (p); | |
2281 | while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) | |
2282 | p1--; | |
2283 | ||
2284 | /* Blanks and comments don't really do anything, but we need to | |
2285 | distinguish them from else, end and other commands which can be | |
2286 | executed. */ | |
2287 | if (p1 == p || p[0] == '#') | |
2288 | return nop_command; | |
2289 | ||
2290 | /* Is this the end of a simple, while, or if control structure? */ | |
2291 | if (p1 - p == 3 && !strncmp (p, "end", 3)) | |
2292 | return end_command; | |
2293 | ||
2294 | /* Is the else clause of an if control structure? */ | |
2295 | if (p1 - p == 4 && !strncmp (p, "else", 4)) | |
2296 | return else_command; | |
2297 | ||
2298 | /* Check for while, if, break, continue, etc and build a new command | |
2299 | line structure for them. */ | |
2300 | if (p1 - p > 5 && !strncmp (p, "while", 5)) | |
2301 | *command = build_command_line (while_control, p + 6); | |
2302 | else if (p1 - p > 2 && !strncmp (p, "if", 2)) | |
2303 | *command = build_command_line (if_control, p + 3); | |
ecebd693 | 2304 | else if (p1 - p == 10 && !strncmp (p, "loop_break", 10)) |
e52bfe0c JL |
2305 | { |
2306 | *command = (struct command_line *) | |
2307 | xmalloc (sizeof (struct command_line)); | |
2308 | (*command)->next = NULL; | |
2309 | (*command)->line = NULL; | |
2310 | (*command)->control_type = break_control; | |
2311 | (*command)->body_count = 0; | |
2312 | (*command)->body_list = NULL; | |
2313 | } | |
ecebd693 | 2314 | else if (p1 - p == 13 && !strncmp (p, "loop_continue", 13)) |
e52bfe0c JL |
2315 | { |
2316 | *command = (struct command_line *) | |
2317 | xmalloc (sizeof (struct command_line)); | |
2318 | (*command)->next = NULL; | |
2319 | (*command)->line = NULL; | |
2320 | (*command)->control_type = continue_control; | |
2321 | (*command)->body_count = 0; | |
2322 | (*command)->body_list = NULL; | |
2323 | } | |
2324 | else | |
2325 | { | |
2326 | /* A normal command. */ | |
2327 | *command = (struct command_line *) | |
2328 | xmalloc (sizeof (struct command_line)); | |
2329 | (*command)->next = NULL; | |
2330 | (*command)->line = savestring (p, p1 - p); | |
2331 | (*command)->control_type = simple_control; | |
2332 | (*command)->body_count = 0; | |
2333 | (*command)->body_list = NULL; | |
2334 | } | |
2335 | ||
2336 | /* Nothing special. */ | |
2337 | return ok_command; | |
2338 | } | |
2339 | ||
2340 | /* Recursively read in the control structures and create a command_line | |
41756e56 | 2341 | structure from them. |
e52bfe0c JL |
2342 | |
2343 | The parent_control parameter is the control structure in which the | |
2344 | following commands are nested. */ | |
2345 | ||
2346 | static enum command_control_type | |
2347 | recurse_read_control_structure (current_cmd) | |
2348 | struct command_line *current_cmd; | |
2349 | { | |
2350 | int current_body, i; | |
2351 | enum misc_command_type val; | |
2352 | enum command_control_type ret; | |
2353 | struct command_line **body_ptr, *child_tail, *next; | |
e52bfe0c | 2354 | |
e52bfe0c JL |
2355 | child_tail = NULL; |
2356 | current_body = 1; | |
2357 | ||
2358 | /* Sanity checks. */ | |
2359 | if (current_cmd->control_type == simple_control) | |
2360 | { | |
2361 | error ("Recursed on a simple control type\n"); | |
2362 | return invalid_control; | |
2363 | } | |
2364 | ||
2365 | if (current_body > current_cmd->body_count) | |
2366 | { | |
2367 | error ("Allocated body is smaller than this command type needs\n"); | |
2368 | return invalid_control; | |
2369 | } | |
2370 | ||
2371 | /* Read lines from the input stream and build control structures. */ | |
2372 | while (1) | |
2373 | { | |
2374 | dont_repeat (); | |
2375 | ||
2376 | next = NULL; | |
2377 | val = read_next_line (&next); | |
2378 | ||
2379 | /* Just skip blanks and comments. */ | |
2380 | if (val == nop_command) | |
2381 | continue; | |
2382 | ||
2383 | if (val == end_command) | |
2384 | { | |
2385 | if (current_cmd->control_type == while_control | |
2386 | || current_cmd->control_type == if_control) | |
2387 | { | |
2388 | /* Success reading an entire control structure. */ | |
2389 | ret = simple_control; | |
2390 | break; | |
2391 | } | |
2392 | else | |
2393 | { | |
2394 | ret = invalid_control; | |
2395 | break; | |
2396 | } | |
2397 | } | |
2398 | ||
2399 | /* Not the end of a control structure. */ | |
2400 | if (val == else_command) | |
2401 | { | |
2402 | if (current_cmd->control_type == if_control | |
2403 | && current_body == 1) | |
2404 | { | |
2405 | realloc_body_list (current_cmd, 2); | |
2406 | current_body = 2; | |
2407 | child_tail = NULL; | |
2408 | continue; | |
2409 | } | |
2410 | else | |
2411 | { | |
2412 | ret = invalid_control; | |
2413 | break; | |
2414 | } | |
2415 | } | |
2416 | ||
2417 | if (child_tail) | |
2418 | { | |
2419 | child_tail->next = next; | |
2420 | } | |
2421 | else | |
2422 | { | |
e52bfe0c JL |
2423 | body_ptr = current_cmd->body_list; |
2424 | for (i = 1; i < current_body; i++) | |
2425 | body_ptr++; | |
2426 | ||
2427 | *body_ptr = next; | |
2428 | ||
e52bfe0c JL |
2429 | } |
2430 | ||
2431 | child_tail = next; | |
2432 | ||
2433 | /* If the latest line is another control structure, then recurse | |
2434 | on it. */ | |
2435 | if (next->control_type == while_control | |
2436 | || next->control_type == if_control) | |
2437 | { | |
2438 | control_level++; | |
2439 | ret = recurse_read_control_structure (next); | |
2440 | control_level--; | |
2441 | ||
2442 | if (ret != simple_control) | |
2443 | break; | |
2444 | } | |
2445 | } | |
2446 | ||
2447 | dont_repeat (); | |
e52bfe0c JL |
2448 | |
2449 | return ret; | |
2450 | } | |
2451 | ||
41756e56 FF |
2452 | /* Read lines from the input stream and accumulate them in a chain of |
2453 | struct command_line's, which is then returned. For input from a | |
2454 | terminal, the special command "end" is used to mark the end of the | |
2455 | input, and is not included in the returned chain of commands. */ | |
e52bfe0c | 2456 | |
41756e56 | 2457 | #define END_MESSAGE "End with a line saying just \"end\"." |
172559ec JK |
2458 | |
2459 | struct command_line * | |
41756e56 FF |
2460 | read_command_lines (prompt, from_tty) |
2461 | char *prompt; | |
2462 | int from_tty; | |
172559ec | 2463 | { |
e52bfe0c JL |
2464 | struct command_line *head, *tail, *next; |
2465 | struct cleanup *old_chain; | |
2466 | enum command_control_type ret; | |
2467 | enum misc_command_type val; | |
2468 | ||
41756e56 FF |
2469 | if (readline_begin_hook) |
2470 | { | |
2471 | /* Note - intentional to merge messages with no newline */ | |
2472 | (*readline_begin_hook) ("%s %s\n", prompt, END_MESSAGE); | |
2473 | } | |
2474 | else if (from_tty && input_from_terminal_p ()) | |
2475 | { | |
2476 | printf_unfiltered ("%s\n%s\n", prompt, END_MESSAGE); | |
2477 | gdb_flush (gdb_stdout); | |
2478 | } | |
2479 | ||
e52bfe0c JL |
2480 | head = tail = NULL; |
2481 | old_chain = NULL; | |
172559ec JK |
2482 | |
2483 | while (1) | |
2484 | { | |
e52bfe0c | 2485 | val = read_next_line (&next); |
172559ec | 2486 | |
e52bfe0c JL |
2487 | /* Ignore blank lines or comments. */ |
2488 | if (val == nop_command) | |
2489 | continue; | |
2490 | ||
2491 | if (val == end_command) | |
2492 | { | |
2493 | ret = simple_control; | |
2494 | break; | |
2495 | } | |
2496 | ||
2497 | if (val != ok_command) | |
2498 | { | |
2499 | ret = invalid_control; | |
2500 | break; | |
2501 | } | |
2502 | ||
2503 | if (next->control_type == while_control | |
2504 | || next->control_type == if_control) | |
2505 | { | |
2506 | control_level++; | |
2507 | ret = recurse_read_control_structure (next); | |
2508 | control_level--; | |
172559ec | 2509 | |
e52bfe0c JL |
2510 | if (ret == invalid_control) |
2511 | break; | |
2512 | } | |
2513 | ||
172559ec JK |
2514 | if (tail) |
2515 | { | |
2516 | tail->next = next; | |
2517 | } | |
2518 | else | |
2519 | { | |
e52bfe0c | 2520 | head = next; |
ad3b8c4a JM |
2521 | old_chain = make_cleanup ((make_cleanup_func) free_command_lines, |
2522 | &head); | |
172559ec JK |
2523 | } |
2524 | tail = next; | |
2525 | } | |
2526 | ||
2527 | dont_repeat (); | |
2528 | ||
e52bfe0c JL |
2529 | if (head) |
2530 | { | |
2531 | if (ret != invalid_control) | |
2532 | { | |
2533 | discard_cleanups (old_chain); | |
e52bfe0c JL |
2534 | } |
2535 | else | |
2536 | do_cleanups (old_chain); | |
2537 | } | |
2538 | ||
41756e56 FF |
2539 | if (readline_end_hook) |
2540 | { | |
2541 | (*readline_end_hook) (); | |
2542 | } | |
2543 | return (head); | |
172559ec JK |
2544 | } |
2545 | ||
2546 | /* Free a chain of struct command_line's. */ | |
2547 | ||
2548 | void | |
2549 | free_command_lines (lptr) | |
2550 | struct command_line **lptr; | |
2551 | { | |
2552 | register struct command_line *l = *lptr; | |
2553 | register struct command_line *next; | |
e52bfe0c JL |
2554 | struct command_line **blist; |
2555 | int i; | |
172559ec JK |
2556 | |
2557 | while (l) | |
2558 | { | |
e52bfe0c JL |
2559 | if (l->body_count > 0) |
2560 | { | |
2561 | blist = l->body_list; | |
2562 | for (i = 0; i < l->body_count; i++, blist++) | |
2563 | free_command_lines (blist); | |
2564 | } | |
172559ec JK |
2565 | next = l->next; |
2566 | free (l->line); | |
2567 | free ((PTR)l); | |
2568 | l = next; | |
2569 | } | |
2570 | } | |
2571 | \f | |
2572 | /* Add an element to the list of info subcommands. */ | |
2573 | ||
2574 | void | |
2575 | add_info (name, fun, doc) | |
2576 | char *name; | |
2577 | void (*fun) PARAMS ((char *, int)); | |
2578 | char *doc; | |
2579 | { | |
2580 | add_cmd (name, no_class, fun, doc, &infolist); | |
2581 | } | |
2582 | ||
2583 | /* Add an alias to the list of info subcommands. */ | |
2584 | ||
2585 | void | |
2586 | add_info_alias (name, oldname, abbrev_flag) | |
2587 | char *name; | |
2588 | char *oldname; | |
2589 | int abbrev_flag; | |
2590 | { | |
2591 | add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist); | |
2592 | } | |
2593 | ||
2594 | /* The "info" command is defined as a prefix, with allow_unknown = 0. | |
2595 | Therefore, its own definition is called only for "info" with no args. */ | |
2596 | ||
2597 | /* ARGSUSED */ | |
2598 | static void | |
2599 | info_command (arg, from_tty) | |
2600 | char *arg; | |
2601 | int from_tty; | |
2602 | { | |
2603 | printf_unfiltered ("\"info\" must be followed by the name of an info command.\n"); | |
2604 | help_list (infolist, "info ", -1, gdb_stdout); | |
2605 | } | |
2606 | ||
2607 | /* The "complete" command is used by Emacs to implement completion. */ | |
2608 | ||
2609 | /* ARGSUSED */ | |
2610 | static void | |
2611 | complete_command (arg, from_tty) | |
2612 | char *arg; | |
2613 | int from_tty; | |
2614 | { | |
2615 | int i; | |
9ed8604f | 2616 | int argpoint; |
172559ec JK |
2617 | char *completion; |
2618 | ||
2619 | dont_repeat (); | |
2620 | ||
2621 | if (arg == NULL) | |
9ed8604f PS |
2622 | arg = ""; |
2623 | argpoint = strlen (arg); | |
172559ec | 2624 | |
9ed8604f | 2625 | for (completion = line_completion_function (arg, i = 0, arg, argpoint); |
172559ec | 2626 | completion; |
9ed8604f PS |
2627 | completion = line_completion_function (arg, ++i, arg, argpoint)) |
2628 | { | |
2629 | printf_unfiltered ("%s\n", completion); | |
2630 | free (completion); | |
2631 | } | |
172559ec JK |
2632 | } |
2633 | ||
2634 | /* The "show" command with no arguments shows all the settings. */ | |
2635 | ||
2636 | /* ARGSUSED */ | |
2637 | static void | |
2638 | show_command (arg, from_tty) | |
2639 | char *arg; | |
2640 | int from_tty; | |
2641 | { | |
2642 | cmd_show_list (showlist, from_tty, ""); | |
2643 | } | |
2644 | \f | |
2645 | /* Add an element to the list of commands. */ | |
2646 | ||
2647 | void | |
2648 | add_com (name, class, fun, doc) | |
2649 | char *name; | |
2650 | enum command_class class; | |
2651 | void (*fun) PARAMS ((char *, int)); | |
2652 | char *doc; | |
2653 | { | |
2654 | add_cmd (name, class, fun, doc, &cmdlist); | |
2655 | } | |
2656 | ||
2657 | /* Add an alias or abbreviation command to the list of commands. */ | |
2658 | ||
2659 | void | |
2660 | add_com_alias (name, oldname, class, abbrev_flag) | |
2661 | char *name; | |
2662 | char *oldname; | |
2663 | enum command_class class; | |
2664 | int abbrev_flag; | |
2665 | { | |
2666 | add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist); | |
2667 | } | |
2668 | ||
2669 | void | |
2670 | error_no_arg (why) | |
2671 | char *why; | |
2672 | { | |
2673 | error ("Argument required (%s).", why); | |
2674 | } | |
2675 | ||
2676 | /* ARGSUSED */ | |
2677 | static void | |
2678 | help_command (command, from_tty) | |
2679 | char *command; | |
2680 | int from_tty; /* Ignored */ | |
2681 | { | |
2682 | help_cmd (command, gdb_stdout); | |
2683 | } | |
2684 | \f | |
2685 | static void | |
2686 | validate_comname (comname) | |
2687 | char *comname; | |
2688 | { | |
2689 | register char *p; | |
2690 | ||
2691 | if (comname == 0) | |
2692 | error_no_arg ("name of command to define"); | |
2693 | ||
2694 | p = comname; | |
2695 | while (*p) | |
2696 | { | |
080868b4 | 2697 | if (!isalnum(*p) && *p != '-' && *p != '_') |
172559ec JK |
2698 | error ("Junk in argument list: \"%s\"", p); |
2699 | p++; | |
2700 | } | |
2701 | } | |
2702 | ||
2703 | /* This is just a placeholder in the command data structures. */ | |
2704 | static void | |
2705 | user_defined_command (ignore, from_tty) | |
2706 | char *ignore; | |
2707 | int from_tty; | |
2708 | { | |
2709 | } | |
2710 | ||
2711 | static void | |
2712 | define_command (comname, from_tty) | |
2713 | char *comname; | |
2714 | int from_tty; | |
2715 | { | |
2716 | register struct command_line *cmds; | |
2717 | register struct cmd_list_element *c, *newc, *hookc = 0; | |
2718 | char *tem = comname; | |
41756e56 | 2719 | char tmpbuf[128]; |
172559ec JK |
2720 | #define HOOK_STRING "hook-" |
2721 | #define HOOK_LEN 5 | |
2722 | ||
2723 | validate_comname (comname); | |
2724 | ||
2725 | /* Look it up, and verify that we got an exact match. */ | |
2726 | c = lookup_cmd (&tem, cmdlist, "", -1, 1); | |
2727 | if (c && !STREQ (comname, c->name)) | |
2728 | c = 0; | |
e52bfe0c | 2729 | |
172559ec JK |
2730 | if (c) |
2731 | { | |
2732 | if (c->class == class_user || c->class == class_alias) | |
2733 | tem = "Redefine command \"%s\"? "; | |
2734 | else | |
2735 | tem = "Really redefine built-in command \"%s\"? "; | |
2736 | if (!query (tem, c->name)) | |
2737 | error ("Command \"%s\" not redefined.", c->name); | |
2738 | } | |
2739 | ||
2740 | /* If this new command is a hook, then mark the command which it | |
2741 | is hooking. Note that we allow hooking `help' commands, so that | |
2742 | we can hook the `stop' pseudo-command. */ | |
2743 | ||
2744 | if (!strncmp (comname, HOOK_STRING, HOOK_LEN)) | |
2745 | { | |
2746 | /* Look up cmd it hooks, and verify that we got an exact match. */ | |
2747 | tem = comname+HOOK_LEN; | |
2748 | hookc = lookup_cmd (&tem, cmdlist, "", -1, 0); | |
2749 | if (hookc && !STREQ (comname+HOOK_LEN, hookc->name)) | |
2750 | hookc = 0; | |
2751 | if (!hookc) | |
2752 | { | |
2753 | warning ("Your new `%s' command does not hook any existing command.", | |
2754 | comname); | |
e3033bb0 | 2755 | if (!query ("Proceed? ")) |
172559ec JK |
2756 | error ("Not confirmed."); |
2757 | } | |
2758 | } | |
2759 | ||
2760 | comname = savestring (comname, strlen (comname)); | |
2761 | ||
e52bfe0c | 2762 | /* If the rest of the commands will be case insensitive, this one |
172559ec JK |
2763 | should behave in the same manner. */ |
2764 | for (tem = comname; *tem; tem++) | |
2765 | if (isupper(*tem)) *tem = tolower(*tem); | |
2766 | ||
e52bfe0c | 2767 | control_level = 0; |
41756e56 FF |
2768 | sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname); |
2769 | cmds = read_command_lines (tmpbuf, from_tty); | |
172559ec JK |
2770 | |
2771 | if (c && c->class == class_user) | |
2772 | free_command_lines (&c->user_commands); | |
2773 | ||
2774 | newc = add_cmd (comname, class_user, user_defined_command, | |
2775 | (c && c->class == class_user) | |
2776 | ? c->doc : savestring ("User-defined.", 13), &cmdlist); | |
2777 | newc->user_commands = cmds; | |
2778 | ||
2779 | /* If this new command is a hook, then mark both commands as being | |
2780 | tied. */ | |
2781 | if (hookc) | |
2782 | { | |
2783 | hookc->hook = newc; /* Target gets hooked. */ | |
2784 | newc->hookee = hookc; /* We are marked as hooking target cmd. */ | |
2785 | } | |
2786 | } | |
2787 | ||
2788 | static void | |
2789 | document_command (comname, from_tty) | |
2790 | char *comname; | |
2791 | int from_tty; | |
2792 | { | |
2793 | struct command_line *doclines; | |
2794 | register struct cmd_list_element *c; | |
2795 | char *tem = comname; | |
41756e56 | 2796 | char tmpbuf[128]; |
172559ec JK |
2797 | |
2798 | validate_comname (comname); | |
2799 | ||
2800 | c = lookup_cmd (&tem, cmdlist, "", 0, 1); | |
2801 | ||
2802 | if (c->class != class_user) | |
2803 | error ("Command \"%s\" is built-in.", comname); | |
2804 | ||
41756e56 FF |
2805 | sprintf (tmpbuf, "Type documentation for \"%s\".", comname); |
2806 | doclines = read_command_lines (tmpbuf, from_tty); | |
172559ec JK |
2807 | |
2808 | if (c->doc) free (c->doc); | |
2809 | ||
2810 | { | |
2811 | register struct command_line *cl1; | |
2812 | register int len = 0; | |
2813 | ||
2814 | for (cl1 = doclines; cl1; cl1 = cl1->next) | |
2815 | len += strlen (cl1->line) + 1; | |
2816 | ||
2817 | c->doc = (char *) xmalloc (len + 1); | |
2818 | *c->doc = 0; | |
2819 | ||
2820 | for (cl1 = doclines; cl1; cl1 = cl1->next) | |
2821 | { | |
2822 | strcat (c->doc, cl1->line); | |
2823 | if (cl1->next) | |
2824 | strcat (c->doc, "\n"); | |
2825 | } | |
2826 | } | |
2827 | ||
2828 | free_command_lines (&doclines); | |
2829 | } | |
2830 | \f | |
65b07ddc | 2831 | /* Print the GDB banner. */ |
172559ec JK |
2832 | void |
2833 | print_gdb_version (stream) | |
2834 | GDB_FILE *stream; | |
2835 | { | |
50140ab2 FF |
2836 | /* From GNU coding standards, first line is meant to be easy for a |
2837 | program to parse, and is just canonical program name and version | |
2838 | number, which starts after last space. */ | |
2839 | ||
2840 | fprintf_filtered (stream, "GNU gdb %s\n", version); | |
2841 | ||
2842 | /* Second line is a copyright notice. */ | |
2843 | ||
bf9084c0 | 2844 | fprintf_filtered (stream, "Copyright 1998 Free Software Foundation, Inc.\n"); |
50140ab2 FF |
2845 | |
2846 | /* Following the copyright is a brief statement that the program is | |
2847 | free software, that users are free to copy and change it on | |
2848 | certain conditions, that it is covered by the GNU GPL, and that | |
2849 | there is no warranty. */ | |
2850 | ||
172559ec | 2851 | fprintf_filtered (stream, "\ |
50140ab2 FF |
2852 | GDB is free software, covered by the GNU General Public License, and you are\n\ |
2853 | welcome to change it and/or distribute copies of it under certain conditions.\n\ | |
59ae1b0f SS |
2854 | Type \"show copying\" to see the conditions.\n\ |
2855 | There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n"); | |
172559ec | 2856 | |
50140ab2 | 2857 | /* After the required info we print the configuration information. */ |
172559ec | 2858 | |
50140ab2 FF |
2859 | fprintf_filtered (stream, "This GDB was configured as \""); |
2860 | if (!STREQ (host_name, target_name)) | |
2861 | { | |
2862 | fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name); | |
2863 | } | |
2864 | else | |
2865 | { | |
2866 | fprintf_filtered (stream, "%s", host_name); | |
2867 | } | |
2868 | fprintf_filtered (stream, "\"."); | |
172559ec JK |
2869 | } |
2870 | ||
2871 | /* ARGSUSED */ | |
2872 | static void | |
2873 | show_version (args, from_tty) | |
2874 | char *args; | |
2875 | int from_tty; | |
2876 | { | |
2877 | immediate_quit++; | |
172559ec JK |
2878 | print_gdb_version (gdb_stdout); |
2879 | printf_filtered ("\n"); | |
2880 | immediate_quit--; | |
2881 | } | |
2882 | \f | |
2883 | /* xgdb calls this to reprint the usual GDB prompt. Obsolete now that xgdb | |
2884 | is obsolete. */ | |
2885 | ||
2886 | void | |
2887 | print_prompt () | |
2888 | { | |
2889 | printf_unfiltered ("%s", prompt); | |
2890 | gdb_flush (gdb_stdout); | |
2891 | } | |
018d76dd KS |
2892 | |
2893 | /* This replaces the above for the frontends: it returns a pointer | |
2894 | to the prompt. */ | |
2895 | char * | |
2896 | get_prompt () | |
2897 | { | |
2898 | return prompt; | |
2899 | } | |
65b07ddc DT |
2900 | |
2901 | void | |
2902 | set_prompt (s) | |
2903 | char *s; | |
2904 | { | |
2905 | /* ??rehrauer: I don't know why this fails, since it looks as though | |
2906 | assignments to prompt are wrapped in calls to savestring... | |
2907 | if (prompt != NULL) | |
2908 | free (prompt); | |
2909 | */ | |
2910 | prompt = savestring (s, strlen (s)); | |
2911 | } | |
2912 | ||
172559ec | 2913 | \f |
018d76dd KS |
2914 | /* If necessary, make the user confirm that we should quit. Return |
2915 | non-zero if we should quit, zero if we shouldn't. */ | |
2916 | ||
2917 | int | |
2918 | quit_confirm () | |
2919 | { | |
2920 | if (inferior_pid != 0 && target_has_execution) | |
2921 | { | |
2922 | char *s; | |
2923 | ||
929db6e5 EZ |
2924 | /* This is something of a hack. But there's no reliable way to |
2925 | see if a GUI is running. The `use_windows' variable doesn't | |
2926 | cut it. */ | |
2927 | if (init_ui_hook) | |
2928 | s = "A debugging session is active.\nDo you still want to close the debugger?"; | |
2929 | else if (attach_flag) | |
018d76dd KS |
2930 | s = "The program is running. Quit anyway (and detach it)? "; |
2931 | else | |
2932 | s = "The program is running. Exit anyway? "; | |
2933 | ||
2934 | if (! query (s)) | |
2935 | return 0; | |
2936 | } | |
2937 | ||
2938 | return 1; | |
2939 | } | |
2940 | ||
2941 | /* Quit without asking for confirmation. */ | |
2942 | ||
172559ec | 2943 | void |
018d76dd | 2944 | quit_force (args, from_tty) |
172559ec JK |
2945 | char *args; |
2946 | int from_tty; | |
2947 | { | |
641c7fdf SS |
2948 | int exit_code = 0; |
2949 | ||
2950 | /* An optional expression may be used to cause gdb to terminate with the | |
2951 | value of that expression. */ | |
2952 | if (args) | |
2953 | { | |
2954 | value_ptr val = parse_and_eval (args); | |
2955 | ||
2956 | exit_code = (int) value_as_long (val); | |
2957 | } | |
2958 | ||
172559ec JK |
2959 | if (inferior_pid != 0 && target_has_execution) |
2960 | { | |
2961 | if (attach_flag) | |
018d76dd | 2962 | target_detach (args, from_tty); |
172559ec | 2963 | else |
018d76dd | 2964 | target_kill (); |
172559ec | 2965 | } |
018d76dd | 2966 | |
172559ec JK |
2967 | /* UDI wants this, to kill the TIP. */ |
2968 | target_close (1); | |
2969 | ||
2970 | /* Save the history information if it is appropriate to do so. */ | |
2971 | if (write_history_p && history_filename) | |
2972 | write_history (history_filename); | |
2973 | ||
16a43bf4 DP |
2974 | do_final_cleanups(ALL_CLEANUPS); /* Do any final cleanups before exiting */ |
2975 | ||
65b07ddc DT |
2976 | #if defined(TUI) |
2977 | /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */ | |
2978 | /* The above does not need to be inside a tuiDo(), since | |
2979 | * it is not manipulating the curses screen, but rather, | |
2980 | * it is tearing it down. | |
2981 | */ | |
2982 | if (tui_version) | |
2983 | tuiCleanUp(); | |
2984 | #endif | |
2985 | ||
641c7fdf | 2986 | exit (exit_code); |
172559ec JK |
2987 | } |
2988 | ||
018d76dd KS |
2989 | /* Handle the quit command. */ |
2990 | ||
2991 | void | |
2992 | quit_command (args, from_tty) | |
2993 | char *args; | |
2994 | int from_tty; | |
2995 | { | |
2996 | if (! quit_confirm ()) | |
2997 | error ("Not confirmed."); | |
2998 | quit_force (args, from_tty); | |
2999 | } | |
3000 | ||
172559ec JK |
3001 | /* Returns whether GDB is running on a terminal and whether the user |
3002 | desires that questions be asked of them on that terminal. */ | |
3003 | ||
3004 | int | |
3005 | input_from_terminal_p () | |
3006 | { | |
3007 | return gdb_has_a_terminal () && (instream == stdin) & caution; | |
3008 | } | |
3009 | \f | |
3010 | /* ARGSUSED */ | |
3011 | static void | |
3012 | pwd_command (args, from_tty) | |
3013 | char *args; | |
3014 | int from_tty; | |
3015 | { | |
3016 | if (args) error ("The \"pwd\" command does not take an argument: %s", args); | |
b7ec5b8d | 3017 | getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); |
172559ec | 3018 | |
b7ec5b8d | 3019 | if (!STREQ (gdb_dirbuf, current_directory)) |
172559ec | 3020 | printf_unfiltered ("Working directory %s\n (canonically %s).\n", |
b7ec5b8d | 3021 | current_directory, gdb_dirbuf); |
172559ec JK |
3022 | else |
3023 | printf_unfiltered ("Working directory %s.\n", current_directory); | |
3024 | } | |
3025 | ||
3026 | void | |
3027 | cd_command (dir, from_tty) | |
3028 | char *dir; | |
3029 | int from_tty; | |
3030 | { | |
3031 | int len; | |
3032 | /* Found something other than leading repetitions of "/..". */ | |
3033 | int found_real_path; | |
3034 | char *p; | |
3035 | ||
3036 | /* If the new directory is absolute, repeat is a no-op; if relative, | |
3037 | repeat might be useful but is more likely to be a mistake. */ | |
3038 | dont_repeat (); | |
3039 | ||
3040 | if (dir == 0) | |
3041 | error_no_arg ("new working directory"); | |
3042 | ||
3043 | dir = tilde_expand (dir); | |
3044 | make_cleanup (free, dir); | |
3045 | ||
3046 | if (chdir (dir) < 0) | |
3047 | perror_with_name (dir); | |
3048 | ||
3049 | len = strlen (dir); | |
2e1cc801 SS |
3050 | dir = savestring (dir, len - (len > 1 && SLASH_P(dir[len-1]))); |
3051 | if (ROOTED_P(dir)) | |
172559ec JK |
3052 | current_directory = dir; |
3053 | else | |
3054 | { | |
2e1cc801 | 3055 | if (SLASH_P (current_directory[0]) && current_directory[1] == '\0') |
172559ec JK |
3056 | current_directory = concat (current_directory, dir, NULL); |
3057 | else | |
2e1cc801 | 3058 | current_directory = concat (current_directory, SLASH_STRING, dir, NULL); |
172559ec JK |
3059 | free (dir); |
3060 | } | |
3061 | ||
3062 | /* Now simplify any occurrences of `.' and `..' in the pathname. */ | |
3063 | ||
3064 | found_real_path = 0; | |
3065 | for (p = current_directory; *p;) | |
3066 | { | |
2e1cc801 | 3067 | if (SLASH_P (p[0]) && p[1] == '.' && (p[2] == 0 || SLASH_P (p[2]))) |
172559ec | 3068 | strcpy (p, p + 2); |
2e1cc801 SS |
3069 | else if (SLASH_P (p[0]) && p[1] == '.' && p[2] == '.' |
3070 | && (p[3] == 0 || SLASH_P (p[3]))) | |
172559ec JK |
3071 | { |
3072 | if (found_real_path) | |
3073 | { | |
3074 | /* Search backwards for the directory just before the "/.." | |
3075 | and obliterate it and the "/..". */ | |
3076 | char *q = p; | |
2e1cc801 | 3077 | while (q != current_directory && ! SLASH_P (q[-1])) |
172559ec JK |
3078 | --q; |
3079 | ||
3080 | if (q == current_directory) | |
3081 | /* current_directory is | |
3082 | a relative pathname ("can't happen"--leave it alone). */ | |
3083 | ++p; | |
3084 | else | |
3085 | { | |
3086 | strcpy (q - 1, p + 3); | |
3087 | p = q - 1; | |
3088 | } | |
3089 | } | |
3090 | else | |
3091 | /* We are dealing with leading repetitions of "/..", for example | |
3092 | "/../..", which is the Mach super-root. */ | |
3093 | p += 3; | |
3094 | } | |
3095 | else | |
3096 | { | |
3097 | found_real_path = 1; | |
3098 | ++p; | |
3099 | } | |
3100 | } | |
3101 | ||
3102 | forget_cached_source_info (); | |
3103 | ||
3104 | if (from_tty) | |
3105 | pwd_command ((char *) 0, 1); | |
3106 | } | |
3107 | \f | |
3108 | struct source_cleanup_lines_args { | |
3109 | int old_line; | |
3110 | char *old_file; | |
3111 | char *old_pre_error; | |
3112 | char *old_error_pre_print; | |
3113 | }; | |
3114 | ||
3115 | static void | |
3116 | source_cleanup_lines (args) | |
3117 | PTR args; | |
3118 | { | |
3119 | struct source_cleanup_lines_args *p = | |
3120 | (struct source_cleanup_lines_args *)args; | |
3121 | source_line_number = p->old_line; | |
3122 | source_file_name = p->old_file; | |
3123 | source_pre_error = p->old_pre_error; | |
3124 | error_pre_print = p->old_error_pre_print; | |
3125 | } | |
3126 | ||
3127 | /* ARGSUSED */ | |
3128 | void | |
3129 | source_command (args, from_tty) | |
3130 | char *args; | |
3131 | int from_tty; | |
3132 | { | |
3133 | FILE *stream; | |
3134 | struct cleanup *old_cleanups; | |
3135 | char *file = args; | |
3136 | struct source_cleanup_lines_args old_lines; | |
3137 | int needed_length; | |
3138 | ||
3139 | if (file == NULL) | |
3140 | { | |
3141 | error ("source command requires pathname of file to source."); | |
3142 | } | |
3143 | ||
3144 | file = tilde_expand (file); | |
3145 | old_cleanups = make_cleanup (free, file); | |
3146 | ||
3147 | stream = fopen (file, FOPEN_RT); | |
9e77e83d SG |
3148 | if (!stream) |
3149 | if (from_tty) | |
3150 | perror_with_name (file); | |
3151 | else | |
3152 | return; | |
172559ec | 3153 | |
ad3b8c4a | 3154 | make_cleanup ((make_cleanup_func) fclose, stream); |
172559ec JK |
3155 | |
3156 | old_lines.old_line = source_line_number; | |
3157 | old_lines.old_file = source_file_name; | |
3158 | old_lines.old_pre_error = source_pre_error; | |
3159 | old_lines.old_error_pre_print = error_pre_print; | |
3160 | make_cleanup (source_cleanup_lines, &old_lines); | |
3161 | source_line_number = 0; | |
3162 | source_file_name = file; | |
3163 | source_pre_error = error_pre_print == NULL ? "" : error_pre_print; | |
3164 | source_pre_error = savestring (source_pre_error, strlen (source_pre_error)); | |
3165 | make_cleanup (free, source_pre_error); | |
3166 | /* This will get set every time we read a line. So it won't stay "" for | |
3167 | long. */ | |
3168 | error_pre_print = ""; | |
3169 | ||
3170 | needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80; | |
3171 | if (source_error_allocated < needed_length) | |
3172 | { | |
3173 | source_error_allocated *= 2; | |
3174 | if (source_error_allocated < needed_length) | |
3175 | source_error_allocated = needed_length; | |
3176 | if (source_error == NULL) | |
3177 | source_error = xmalloc (source_error_allocated); | |
3178 | else | |
3179 | source_error = xrealloc (source_error, source_error_allocated); | |
3180 | } | |
3181 | ||
3182 | read_command_file (stream); | |
3183 | ||
3184 | do_cleanups (old_cleanups); | |
3185 | } | |
3186 | ||
3187 | /* ARGSUSED */ | |
3188 | static void | |
3189 | echo_command (text, from_tty) | |
3190 | char *text; | |
3191 | int from_tty; | |
3192 | { | |
3193 | char *p = text; | |
3194 | register int c; | |
3195 | ||
3196 | if (text) | |
3197 | while ((c = *p++) != '\0') | |
3198 | { | |
3199 | if (c == '\\') | |
3200 | { | |
3201 | /* \ at end of argument is used after spaces | |
3202 | so they won't be lost. */ | |
3203 | if (*p == 0) | |
3204 | return; | |
3205 | ||
3206 | c = parse_escape (&p); | |
3207 | if (c >= 0) | |
3208 | printf_filtered ("%c", c); | |
3209 | } | |
3210 | else | |
3211 | printf_filtered ("%c", c); | |
3212 | } | |
3213 | ||
3214 | /* Force this output to appear now. */ | |
3215 | wrap_here (""); | |
3216 | gdb_flush (gdb_stdout); | |
3217 | } | |
3218 | ||
cd10c7e3 SG |
3219 | /* ARGSUSED */ |
3220 | static void | |
3221 | dont_repeat_command (ignored, from_tty) | |
3222 | char *ignored; | |
3223 | int from_tty; | |
3224 | { | |
3225 | *line = 0; /* Can't call dont_repeat here because we're not | |
3226 | necessarily reading from stdin. */ | |
3227 | } | |
b8176214 | 3228 | \f |
172559ec JK |
3229 | /* Functions to manipulate command line editing control variables. */ |
3230 | ||
3231 | /* Number of commands to print in each call to show_commands. */ | |
3232 | #define Hist_print 10 | |
3233 | static void | |
3234 | show_commands (args, from_tty) | |
3235 | char *args; | |
3236 | int from_tty; | |
3237 | { | |
3238 | /* Index for history commands. Relative to history_base. */ | |
3239 | int offset; | |
3240 | ||
3241 | /* Number of the history entry which we are planning to display next. | |
3242 | Relative to history_base. */ | |
3243 | static int num = 0; | |
3244 | ||
3245 | /* The first command in the history which doesn't exist (i.e. one more | |
3246 | than the number of the last command). Relative to history_base. */ | |
3247 | int hist_len; | |
3248 | ||
3249 | extern HIST_ENTRY *history_get PARAMS ((int)); | |
3250 | ||
3251 | /* Print out some of the commands from the command history. */ | |
3252 | /* First determine the length of the history list. */ | |
3253 | hist_len = history_size; | |
3254 | for (offset = 0; offset < history_size; offset++) | |
3255 | { | |
3256 | if (!history_get (history_base + offset)) | |
3257 | { | |
3258 | hist_len = offset; | |
3259 | break; | |
3260 | } | |
3261 | } | |
3262 | ||
3263 | if (args) | |
3264 | { | |
3265 | if (args[0] == '+' && args[1] == '\0') | |
3266 | /* "info editing +" should print from the stored position. */ | |
3267 | ; | |
3268 | else | |
3269 | /* "info editing <exp>" should print around command number <exp>. */ | |
3270 | num = (parse_and_eval_address (args) - history_base) - Hist_print / 2; | |
3271 | } | |
3272 | /* "show commands" means print the last Hist_print commands. */ | |
3273 | else | |
3274 | { | |
3275 | num = hist_len - Hist_print; | |
3276 | } | |
3277 | ||
3278 | if (num < 0) | |
3279 | num = 0; | |
3280 | ||
3281 | /* If there are at least Hist_print commands, we want to display the last | |
3282 | Hist_print rather than, say, the last 6. */ | |
3283 | if (hist_len - num < Hist_print) | |
3284 | { | |
3285 | num = hist_len - Hist_print; | |
3286 | if (num < 0) | |
3287 | num = 0; | |
3288 | } | |
3289 | ||
3290 | for (offset = num; offset < num + Hist_print && offset < hist_len; offset++) | |
3291 | { | |
3292 | printf_filtered ("%5d %s\n", history_base + offset, | |
3293 | (history_get (history_base + offset))->line); | |
3294 | } | |
3295 | ||
3296 | /* The next command we want to display is the next one that we haven't | |
3297 | displayed yet. */ | |
3298 | num += Hist_print; | |
e52bfe0c | 3299 | |
172559ec JK |
3300 | /* If the user repeats this command with return, it should do what |
3301 | "show commands +" does. This is unnecessary if arg is null, | |
3302 | because "show commands +" is not useful after "show commands". */ | |
3303 | if (from_tty && args) | |
3304 | { | |
3305 | args[0] = '+'; | |
3306 | args[1] = '\0'; | |
3307 | } | |
3308 | } | |
3309 | ||
3310 | /* Called by do_setshow_command. */ | |
3311 | /* ARGSUSED */ | |
3312 | static void | |
3313 | set_history_size_command (args, from_tty, c) | |
3314 | char *args; | |
3315 | int from_tty; | |
3316 | struct cmd_list_element *c; | |
3317 | { | |
3318 | if (history_size == INT_MAX) | |
3319 | unstifle_history (); | |
3320 | else if (history_size >= 0) | |
3321 | stifle_history (history_size); | |
3322 | else | |
3323 | { | |
3324 | history_size = INT_MAX; | |
3325 | error ("History size must be non-negative"); | |
3326 | } | |
3327 | } | |
3328 | ||
3329 | /* ARGSUSED */ | |
3330 | static void | |
3331 | set_history (args, from_tty) | |
3332 | char *args; | |
3333 | int from_tty; | |
3334 | { | |
3335 | printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n"); | |
3336 | help_list (sethistlist, "set history ", -1, gdb_stdout); | |
3337 | } | |
3338 | ||
3339 | /* ARGSUSED */ | |
3340 | static void | |
3341 | show_history (args, from_tty) | |
3342 | char *args; | |
3343 | int from_tty; | |
3344 | { | |
3345 | cmd_show_list (showhistlist, from_tty, ""); | |
3346 | } | |
3347 | ||
3348 | int info_verbose = 0; /* Default verbose msgs off */ | |
3349 | ||
3350 | /* Called by do_setshow_command. An elaborate joke. */ | |
3351 | /* ARGSUSED */ | |
e52bfe0c | 3352 | static void |
172559ec JK |
3353 | set_verbose (args, from_tty, c) |
3354 | char *args; | |
3355 | int from_tty; | |
3356 | struct cmd_list_element *c; | |
3357 | { | |
3358 | char *cmdname = "verbose"; | |
3359 | struct cmd_list_element *showcmd; | |
e52bfe0c | 3360 | |
172559ec JK |
3361 | showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1); |
3362 | ||
3363 | if (info_verbose) | |
3364 | { | |
3365 | c->doc = "Set verbose printing of informational messages."; | |
3366 | showcmd->doc = "Show verbose printing of informational messages."; | |
3367 | } | |
3368 | else | |
3369 | { | |
3370 | c->doc = "Set verbosity."; | |
3371 | showcmd->doc = "Show verbosity."; | |
3372 | } | |
3373 | } | |
3374 | ||
3375 | static void | |
3376 | float_handler (signo) | |
3377 | int signo; | |
3378 | { | |
3379 | /* This message is based on ANSI C, section 4.7. Note that integer | |
3380 | divide by zero causes this, so "float" is a misnomer. */ | |
3381 | signal (SIGFPE, float_handler); | |
3382 | error ("Erroneous arithmetic operation."); | |
3383 | } | |
3384 | ||
172559ec JK |
3385 | \f |
3386 | static void | |
3387 | init_cmd_lists () | |
3388 | { | |
3389 | cmdlist = NULL; | |
3390 | infolist = NULL; | |
3391 | enablelist = NULL; | |
3392 | disablelist = NULL; | |
65b07ddc DT |
3393 | togglelist = NULL; |
3394 | stoplist = NULL; | |
172559ec JK |
3395 | deletelist = NULL; |
3396 | enablebreaklist = NULL; | |
3397 | setlist = NULL; | |
3398 | unsetlist = NULL; | |
3399 | showlist = NULL; | |
3400 | sethistlist = NULL; | |
3401 | showhistlist = NULL; | |
3402 | unsethistlist = NULL; | |
3403 | #if MAINTENANCE_CMDS | |
3404 | maintenancelist = NULL; | |
3405 | maintenanceinfolist = NULL; | |
3406 | maintenanceprintlist = NULL; | |
3407 | #endif | |
3408 | setprintlist = NULL; | |
3409 | showprintlist = NULL; | |
3410 | setchecklist = NULL; | |
3411 | showchecklist = NULL; | |
3412 | } | |
3413 | ||
3414 | /* Init the history buffer. Note that we are called after the init file(s) | |
3415 | * have been read so that the user can change the history file via his | |
3416 | * .gdbinit file (for instance). The GDBHISTFILE environment variable | |
3417 | * overrides all of this. | |
3418 | */ | |
3419 | ||
3420 | void | |
3421 | init_history() | |
3422 | { | |
3423 | char *tmpenv; | |
3424 | ||
3425 | tmpenv = getenv ("HISTSIZE"); | |
3426 | if (tmpenv) | |
3427 | history_size = atoi (tmpenv); | |
3428 | else if (!history_size) | |
3429 | history_size = 256; | |
3430 | ||
3431 | stifle_history (history_size); | |
3432 | ||
3433 | tmpenv = getenv ("GDBHISTFILE"); | |
3434 | if (tmpenv) | |
3435 | history_filename = savestring (tmpenv, strlen(tmpenv)); | |
3436 | else if (!history_filename) { | |
3437 | /* We include the current directory so that if the user changes | |
3438 | directories the file written will be the same as the one | |
3439 | that was read. */ | |
3440 | history_filename = concat (current_directory, "/.gdb_history", NULL); | |
3441 | } | |
3442 | read_history (history_filename); | |
3443 | } | |
3444 | ||
3445 | static void | |
3446 | init_main () | |
3447 | { | |
3448 | struct cmd_list_element *c; | |
e52bfe0c | 3449 | |
172559ec JK |
3450 | #ifdef DEFAULT_PROMPT |
3451 | prompt = savestring (DEFAULT_PROMPT, strlen(DEFAULT_PROMPT)); | |
3452 | #else | |
3453 | prompt = savestring ("(gdb) ", 6); | |
3454 | #endif | |
3455 | ||
3456 | /* Set the important stuff up for command editing. */ | |
3457 | command_editing_p = 1; | |
3458 | history_expansion_p = 0; | |
3459 | write_history_p = 0; | |
e52bfe0c | 3460 | |
172559ec | 3461 | /* Setup important stuff for command line editing. */ |
9ed8604f | 3462 | rl_completion_entry_function = (int (*)()) readline_line_completion_function; |
172559ec JK |
3463 | rl_completer_word_break_characters = gdb_completer_word_break_characters; |
3464 | rl_completer_quote_characters = gdb_completer_quote_characters; | |
3465 | rl_readline_name = "gdb"; | |
3466 | ||
3467 | /* Define the classes of commands. | |
3468 | They will appear in the help list in the reverse of this order. */ | |
3469 | ||
3470 | add_cmd ("internals", class_maintenance, NO_FUNCTION, | |
3471 | "Maintenance commands.\n\ | |
3472 | Some gdb commands are provided just for use by gdb maintainers.\n\ | |
3473 | These commands are subject to frequent change, and may not be as\n\ | |
3474 | well documented as user commands.", | |
3475 | &cmdlist); | |
3476 | add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist); | |
3477 | add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist); | |
3478 | add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\ | |
3479 | The commands in this class are those defined by the user.\n\ | |
3480 | Use the \"define\" command to define a command.", &cmdlist); | |
3481 | add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist); | |
65b07ddc DT |
3482 | if (!dbx_commands) |
3483 | add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist); | |
172559ec JK |
3484 | add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist); |
3485 | add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist); | |
3486 | add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist); | |
3487 | add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\ | |
3488 | The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\ | |
3489 | counting from zero for the innermost (currently executing) frame.\n\n\ | |
3490 | At any time gdb identifies one frame as the \"selected\" frame.\n\ | |
3491 | Variable lookups are done with respect to the selected frame.\n\ | |
3492 | When the program being debugged stops, gdb selects the innermost frame.\n\ | |
3493 | The commands below can be used to select other frames by number or address.", | |
3494 | &cmdlist); | |
3495 | add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist); | |
3496 | ||
3497 | add_com ("pwd", class_files, pwd_command, | |
3498 | "Print working directory. This is used for your program as well."); | |
3499 | c = add_cmd ("cd", class_files, cd_command, | |
3500 | "Set working directory to DIR for debugger and program being debugged.\n\ | |
3501 | The change does not take effect for the program being debugged\n\ | |
3502 | until the next time it is started.", &cmdlist); | |
3503 | c->completer = filename_completer; | |
3504 | ||
3505 | add_show_from_set | |
3506 | (add_set_cmd ("prompt", class_support, var_string, (char *)&prompt, | |
3507 | "Set gdb's prompt", | |
3508 | &setlist), | |
3509 | &showlist); | |
e52bfe0c | 3510 | |
172559ec JK |
3511 | add_com ("echo", class_support, echo_command, |
3512 | "Print a constant string. Give string as argument.\n\ | |
3513 | C escape sequences may be used in the argument.\n\ | |
3514 | No newline is added at the end of the argument;\n\ | |
3515 | use \"\\n\" if you want a newline to be printed.\n\ | |
3516 | Since leading and trailing whitespace are ignored in command arguments,\n\ | |
3517 | if you want to print some you must use \"\\\" before leading whitespace\n\ | |
3518 | to be printed or after trailing whitespace."); | |
3519 | add_com ("document", class_support, document_command, | |
3520 | "Document a user-defined command.\n\ | |
3521 | Give command name as argument. Give documentation on following lines.\n\ | |
3522 | End with a line of just \"end\"."); | |
3523 | add_com ("define", class_support, define_command, | |
3524 | "Define a new command name. Command name is argument.\n\ | |
3525 | Definition appears on following lines, one command per line.\n\ | |
3526 | End with a line of just \"end\".\n\ | |
3527 | Use the \"document\" command to give documentation for the new command.\n\ | |
59528079 | 3528 | Commands defined in this way may have up to ten arguments."); |
172559ec JK |
3529 | |
3530 | #ifdef __STDC__ | |
3531 | c = add_cmd ("source", class_support, source_command, | |
3532 | "Read commands from a file named FILE.\n\ | |
3533 | Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\ | |
3534 | when gdb is started.", &cmdlist); | |
3535 | #else | |
3536 | /* Punt file name, we can't help it easily. */ | |
3537 | c = add_cmd ("source", class_support, source_command, | |
3538 | "Read commands from a file named FILE.\n\ | |
3539 | Note that the file \".gdbinit\" is read automatically in this way\n\ | |
3540 | when gdb is started.", &cmdlist); | |
3541 | #endif | |
3542 | c->completer = filename_completer; | |
3543 | ||
3544 | add_com ("quit", class_support, quit_command, "Exit gdb."); | |
3545 | add_com ("help", class_support, help_command, "Print list of commands."); | |
3546 | add_com_alias ("q", "quit", class_support, 1); | |
3547 | add_com_alias ("h", "help", class_support, 1); | |
3548 | ||
cd10c7e3 SG |
3549 | add_com ("dont-repeat", class_support, dont_repeat_command, "Don't repeat this command.\n\ |
3550 | Primarily used inside of user-defined commands that should not be repeated when\n\ | |
3551 | hitting return."); | |
172559ec JK |
3552 | |
3553 | c = add_set_cmd ("verbose", class_support, var_boolean, (char *)&info_verbose, | |
3554 | "Set ", | |
3555 | &setlist), | |
3556 | add_show_from_set (c, &showlist); | |
3557 | c->function.sfunc = set_verbose; | |
3558 | set_verbose (NULL, 0, c); | |
e52bfe0c | 3559 | |
172559ec JK |
3560 | add_show_from_set |
3561 | (add_set_cmd ("editing", class_support, var_boolean, (char *)&command_editing_p, | |
3562 | "Set editing of command lines as they are typed.\n\ | |
6a85a617 | 3563 | Use \"on\" to enable the editing, and \"off\" to disable it.\n\ |
172559ec JK |
3564 | Without an argument, command line editing is enabled. To edit, use\n\ |
3565 | EMACS-like or VI-like commands like control-P or ESC.", &setlist), | |
3566 | &showlist); | |
3567 | ||
3568 | add_prefix_cmd ("history", class_support, set_history, | |
3569 | "Generic command for setting command history parameters.", | |
3570 | &sethistlist, "set history ", 0, &setlist); | |
3571 | add_prefix_cmd ("history", class_support, show_history, | |
3572 | "Generic command for showing command history parameters.", | |
3573 | &showhistlist, "show history ", 0, &showlist); | |
3574 | ||
3575 | add_show_from_set | |
3576 | (add_set_cmd ("expansion", no_class, var_boolean, (char *)&history_expansion_p, | |
3577 | "Set history expansion on command input.\n\ | |
3578 | Without an argument, history expansion is enabled.", &sethistlist), | |
3579 | &showhistlist); | |
3580 | ||
3581 | add_show_from_set | |
3582 | (add_set_cmd ("save", no_class, var_boolean, (char *)&write_history_p, | |
3583 | "Set saving of the history record on exit.\n\ | |
6a85a617 | 3584 | Use \"on\" to enable the saving, and \"off\" to disable it.\n\ |
172559ec JK |
3585 | Without an argument, saving is enabled.", &sethistlist), |
3586 | &showhistlist); | |
3587 | ||
3588 | c = add_set_cmd ("size", no_class, var_integer, (char *)&history_size, | |
3589 | "Set the size of the command history, \n\ | |
3590 | ie. the number of previous commands to keep a record of.", &sethistlist); | |
3591 | add_show_from_set (c, &showhistlist); | |
3592 | c->function.sfunc = set_history_size_command; | |
3593 | ||
3594 | add_show_from_set | |
3595 | (add_set_cmd ("filename", no_class, var_filename, (char *)&history_filename, | |
3596 | "Set the filename in which to record the command history\n\ | |
3597 | (the list of previous commands of which a record is kept).", &sethistlist), | |
3598 | &showhistlist); | |
3599 | ||
3600 | add_show_from_set | |
3601 | (add_set_cmd ("confirm", class_support, var_boolean, | |
3602 | (char *)&caution, | |
3603 | "Set whether to confirm potentially dangerous operations.", | |
3604 | &setlist), | |
3605 | &showlist); | |
3606 | ||
3607 | add_prefix_cmd ("info", class_info, info_command, | |
3608 | "Generic command for showing things about the program being debugged.", | |
3609 | &infolist, "info ", 0, &cmdlist); | |
3610 | add_com_alias ("i", "info", class_info, 1); | |
3611 | ||
3612 | add_com ("complete", class_obscure, complete_command, | |
3613 | "List the completions for the rest of the line as a command."); | |
3614 | ||
3615 | add_prefix_cmd ("show", class_info, show_command, | |
3616 | "Generic command for showing things about the debugger.", | |
3617 | &showlist, "show ", 0, &cmdlist); | |
3618 | /* Another way to get at the same thing. */ | |
3619 | add_info ("set", show_command, "Show all GDB settings."); | |
3620 | ||
3621 | add_cmd ("commands", no_class, show_commands, | |
943b7032 | 3622 | "Show the history of commands you typed.\n\ |
172559ec JK |
3623 | You can supply a command number to start with, or a `+' to start after\n\ |
3624 | the previous command number shown.", | |
3625 | &showlist); | |
3626 | ||
3627 | add_cmd ("version", no_class, show_version, | |
3628 | "Show what version of GDB this is.", &showlist); | |
3629 | ||
e52bfe0c JL |
3630 | add_com ("while", class_support, while_command, |
3631 | "Execute nested commands WHILE the conditional expression is non zero.\n\ | |
943b7032 PS |
3632 | The conditional expression must follow the word `while' and must in turn be\n\ |
3633 | followed by a new line. The nested commands must be entered one per line,\n\ | |
e52bfe0c JL |
3634 | and should be terminated by the word `end'."); |
3635 | ||
3636 | add_com ("if", class_support, if_command, | |
3637 | "Execute nested commands once IF the conditional expression is non zero.\n\ | |
943b7032 PS |
3638 | The conditional expression must follow the word `if' and must in turn be\n\ |
3639 | followed by a new line. The nested commands must be entered one per line,\n\ | |
3640 | and should be terminated by the word 'else' or `end'. If an else clause\n\ | |
e52bfe0c JL |
3641 | is used, the same rules apply to its nested commands as to the first ones."); |
3642 | ||
172559ec JK |
3643 | /* If target is open when baud changes, it doesn't take effect until the |
3644 | next open (I think, not sure). */ | |
3645 | add_show_from_set (add_set_cmd ("remotebaud", no_class, | |
3646 | var_zinteger, (char *)&baud_rate, | |
3647 | "Set baud rate for remote serial I/O.\n\ | |
3648 | This value is used to set the speed of the serial port when debugging\n\ | |
3649 | using remote targets.", &setlist), | |
3650 | &showlist); | |
3651 | ||
3652 | add_show_from_set ( | |
3653 | add_set_cmd ("remotedebug", no_class, var_zinteger, (char *)&remote_debug, | |
3654 | "Set debugging of remote protocol.\n\ | |
3655 | When enabled, each packet sent or received with the remote target\n\ | |
3656 | is displayed.", &setlist), | |
3657 | &showlist); | |
cb1709ae DP |
3658 | |
3659 | add_show_from_set ( | |
3660 | add_set_cmd ("remotetimeout", no_class, var_integer, (char *)&remote_timeout, | |
3661 | "Set timeout limit to wait for target to respond.\n\ | |
3662 | This value is used to set the time limit for gdb to wait for a response\n\ | |
3663 | from he target.", &setlist), | |
3664 | &showlist); | |
62dd860e MS |
3665 | |
3666 | c = add_set_cmd ("annotate", class_obscure, var_zinteger, | |
3667 | (char *)&annotation_level, "Set annotation_level.\n\ | |
3668 | 0 == normal; 1 == fullname (for use when running under emacs)\n\ | |
3669 | 2 == output annotated suitably for use by programs that control GDB.", | |
3670 | &setlist); | |
3671 | c = add_show_from_set (c, &showlist); | |
172559ec | 3672 | } |