Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Top level stuff for GDB, the GNU debugger. |
b6ba6518 KB |
2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
3 | 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. | |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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. | |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b JM |
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 | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "gdbcmd.h" | |
24 | #include "call-cmds.h" | |
25 | #include "symtab.h" | |
26 | #include "inferior.h" | |
042be3a9 | 27 | #include <signal.h> |
c906108c SS |
28 | #include "target.h" |
29 | #include "breakpoint.h" | |
30 | #include "gdbtypes.h" | |
31 | #include "expression.h" | |
32 | #include "value.h" | |
33 | #include "language.h" | |
c5aa993b | 34 | #include "terminal.h" /* For job_control. */ |
c906108c | 35 | #include "annotate.h" |
c5f0f3d0 | 36 | #include "completer.h" |
c906108c | 37 | #include "top.h" |
d4f3574e | 38 | #include "version.h" |
c906108c SS |
39 | |
40 | /* readline include files */ | |
41 | #include <readline/readline.h> | |
42 | #include <readline/history.h> | |
43 | ||
44 | /* readline defines this. */ | |
45 | #undef savestring | |
46 | ||
47 | #include <sys/types.h> | |
c906108c | 48 | |
c4093a6a | 49 | #include <setjmp.h> |
2acceee2 | 50 | |
c2c6d25f | 51 | #include "event-top.h" |
c906108c SS |
52 | #include "gdb_string.h" |
53 | #include "gdb_stat.h" | |
54 | #include <ctype.h> | |
8b93c638 JM |
55 | #ifdef UI_OUT |
56 | #include "ui-out.h" | |
57 | #include "cli-out.h" | |
58 | #endif | |
c906108c | 59 | |
d318976c | 60 | /* From completer.c */ |
c906108c | 61 | |
d318976c | 62 | extern int is_complete_command (void (*func) (char *args, int from_tty)); |
c906108c | 63 | |
d318976c | 64 | /* From cli/cli-cmds.c */ |
c906108c | 65 | |
d318976c | 66 | extern void init_cmd_lists (void); |
c906108c | 67 | |
d318976c | 68 | extern void init_cli_cmds (void); |
c906108c | 69 | |
d318976c | 70 | extern void execute_user_command (struct cmd_list_element *c, char *args); |
c906108c | 71 | |
d318976c FN |
72 | /* From cli/cli-setshow.c */ |
73 | ||
74 | extern void do_setshow_command (char *, int, struct cmd_list_element *); | |
c906108c | 75 | |
d318976c | 76 | /* Exported to CLI cli/cli-cmds.c. */ |
c906108c | 77 | |
d318976c | 78 | void set_verbose (char *, int, struct cmd_list_element *); |
c906108c | 79 | |
d318976c | 80 | void show_history (char *, int); |
c906108c | 81 | |
d318976c | 82 | void set_history (char *, int); |
c906108c | 83 | |
d318976c | 84 | void show_commands (char *, int); |
c906108c | 85 | |
d318976c | 86 | void do_restore_instream_cleanup (void *stream); |
c906108c | 87 | |
d318976c | 88 | /* Prototypes for local functions */ |
c906108c | 89 | |
d318976c | 90 | static void dont_repeat_command (char *, int); |
c906108c | 91 | |
d318976c | 92 | static void init_signals (void); |
c906108c | 93 | |
d318976c FN |
94 | #ifdef STOP_SIGNAL |
95 | static void stop_sig (int); | |
96 | #endif | |
c906108c | 97 | |
d318976c | 98 | static char *readline_line_completion_function (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void init_main (void); |
c906108c | 101 | |
a14ed312 | 102 | static void float_handler (int); |
c906108c | 103 | |
a14ed312 | 104 | static void init_signals (void); |
c906108c | 105 | |
a14ed312 | 106 | static void set_history_size_command (char *, int, struct cmd_list_element *); |
c906108c | 107 | |
a14ed312 | 108 | static void do_nothing (int); |
c906108c SS |
109 | |
110 | #ifdef SIGHUP | |
392a587b | 111 | /* NOTE 1999-04-29: This function will be static again, once we modify |
cd0fc7c3 SS |
112 | gdb to use the event loop as the default command loop and we merge |
113 | event-top.c into this file, top.c */ | |
a14ed312 | 114 | /* static */ int quit_cover (PTR); |
c906108c | 115 | |
a14ed312 | 116 | static void disconnect (int); |
c906108c SS |
117 | #endif |
118 | ||
104c1213 JM |
119 | /* Default command line prompt. This is overriden in some configs. */ |
120 | ||
121 | #ifndef DEFAULT_PROMPT | |
122 | #define DEFAULT_PROMPT "(gdb) " | |
c906108c SS |
123 | #endif |
124 | ||
125 | /* Initialization file name for gdb. This is overridden in some configs. */ | |
126 | ||
127 | #ifndef GDBINIT_FILENAME | |
128 | #define GDBINIT_FILENAME ".gdbinit" | |
129 | #endif | |
130 | char gdbinit[] = GDBINIT_FILENAME; | |
131 | ||
132 | int inhibit_gdbinit = 0; | |
133 | ||
134 | /* If nonzero, and GDB has been configured to be able to use windows, | |
135 | attempt to open them upon startup. */ | |
136 | ||
137 | int use_windows = 1; | |
138 | ||
c906108c SS |
139 | extern char lang_frame_mismatch_warn[]; /* language.c */ |
140 | ||
141 | /* Flag for whether we want all the "from_tty" gubbish printed. */ | |
142 | ||
c5aa993b | 143 | int caution = 1; /* Default is yes, sigh. */ |
c906108c | 144 | |
c906108c SS |
145 | /* stdio stream that command input is being read from. Set to stdin normally. |
146 | Set by source_command to the file we are sourcing. Set to NULL if we are | |
147 | executing a user-defined command or interacting via a GUI. */ | |
148 | ||
149 | FILE *instream; | |
150 | ||
151 | /* Current working directory. */ | |
152 | ||
153 | char *current_directory; | |
154 | ||
155 | /* The directory name is actually stored here (usually). */ | |
156 | char gdb_dirbuf[1024]; | |
157 | ||
158 | /* Function to call before reading a command, if nonzero. | |
159 | The function receives two args: an input stream, | |
160 | and a prompt string. */ | |
161 | ||
507f3c78 | 162 | void (*window_hook) (FILE *, char *); |
c906108c SS |
163 | |
164 | int epoch_interface; | |
165 | int xgdb_verbose; | |
166 | ||
167 | /* gdb prints this when reading a command interactively */ | |
c5aa993b | 168 | static char *gdb_prompt_string; /* the global prompt string */ |
a14ed312 | 169 | extern char *get_prompt (void); /* access function for prompt string */ |
c906108c SS |
170 | |
171 | /* Buffer used for reading command lines, and the size | |
172 | allocated for it so far. */ | |
173 | ||
174 | char *line; | |
175 | int linesize = 100; | |
176 | ||
177 | /* Nonzero if the current command is modified by "server ". This | |
c2d11a7d | 178 | affects things like recording into the command history, commands |
c906108c SS |
179 | repeating on RETURN, etc. This is so a user interface (emacs, GUI, |
180 | whatever) can issue its own commands and also send along commands | |
181 | from the user, and have the user not notice that the user interface | |
182 | is issuing commands too. */ | |
183 | int server_command; | |
184 | ||
185 | /* Baud rate specified for talking to serial target systems. Default | |
186 | is left as -1, so targets can choose their own defaults. */ | |
187 | /* FIXME: This means that "show remotebaud" and gr_files_info can print -1 | |
188 | or (unsigned int)-1. This is a Bad User Interface. */ | |
189 | ||
190 | int baud_rate = -1; | |
191 | ||
192 | /* Timeout limit for response from target. */ | |
193 | ||
ce808e91 AC |
194 | /* The default value has been changed many times over the years. It |
195 | was originally 5 seconds. But that was thought to be a long time | |
196 | to sit and wait, so it was changed to 2 seconds. That was thought | |
197 | to be plenty unless the connection was going through some terminal | |
198 | server or multiplexer or other form of hairy serial connection. | |
199 | ||
200 | In mid-1996, remote_timeout was moved from remote.c to top.c and | |
201 | it began being used in other remote-* targets. It appears that the | |
202 | default was changed to 20 seconds at that time, perhaps because the | |
203 | Hitachi E7000 ICE didn't always respond in a timely manner. | |
204 | ||
205 | But if 5 seconds is a long time to sit and wait for retransmissions, | |
206 | 20 seconds is far worse. This demonstrates the difficulty of using | |
207 | a single variable for all protocol timeouts. | |
208 | ||
209 | As remote.c is used much more than remote-e7000.c, it was changed | |
210 | back to 2 seconds in 1999. */ | |
211 | ||
212 | int remote_timeout = 2; | |
c906108c SS |
213 | |
214 | /* Non-zero tells remote* modules to output debugging info. */ | |
215 | ||
216 | int remote_debug = 0; | |
217 | ||
43ff13b4 JM |
218 | /* Non-zero means the target is running. Note: this is different from |
219 | saying that there is an active target and we are stopped at a | |
220 | breakpoint, for instance. This is a real indicator whether the | |
221 | target is off and running, which gdb is doing something else. */ | |
222 | int target_executing = 0; | |
223 | ||
c906108c SS |
224 | /* Level of control structure. */ |
225 | static int control_level; | |
226 | ||
227 | /* Structure for arguments to user defined functions. */ | |
228 | #define MAXUSERARGS 10 | |
229 | struct user_args | |
c5aa993b JM |
230 | { |
231 | struct user_args *next; | |
232 | struct | |
233 | { | |
234 | char *arg; | |
235 | int len; | |
236 | } | |
237 | a[MAXUSERARGS]; | |
238 | int count; | |
239 | } | |
240 | *user_args; | |
c906108c SS |
241 | |
242 | /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */ | |
243 | ||
244 | #ifndef STOP_SIGNAL | |
245 | #ifdef SIGTSTP | |
246 | #define STOP_SIGNAL SIGTSTP | |
a14ed312 | 247 | static void stop_sig (int); |
c906108c SS |
248 | #endif |
249 | #endif | |
250 | ||
251 | /* Some System V have job control but not sigsetmask(). */ | |
252 | #if !defined (HAVE_SIGSETMASK) | |
253 | #if !defined (USG) | |
254 | #define HAVE_SIGSETMASK 1 | |
255 | #else | |
256 | #define HAVE_SIGSETMASK 0 | |
257 | #endif | |
258 | #endif | |
259 | ||
260 | #if 0 == (HAVE_SIGSETMASK) | |
261 | #define sigsetmask(n) | |
262 | #endif | |
263 | ||
264 | /* Hooks for alternate command interfaces. */ | |
265 | ||
266 | /* Called after most modules have been initialized, but before taking users | |
267 | command file. */ | |
268 | ||
507f3c78 | 269 | void (*init_ui_hook) (char *argv0); |
7a292a7a SS |
270 | |
271 | /* This hook is called from within gdb's many mini-event loops which could | |
272 | steal control from a real user interface's event loop. It returns | |
273 | non-zero if the user is requesting a detach, zero otherwise. */ | |
274 | ||
507f3c78 | 275 | int (*ui_loop_hook) (int); |
c906108c SS |
276 | |
277 | /* Called instead of command_loop at top level. Can be invoked via | |
278 | return_to_top_level. */ | |
279 | ||
507f3c78 | 280 | void (*command_loop_hook) (void); |
c906108c SS |
281 | |
282 | ||
c906108c SS |
283 | /* Called from print_frame_info to list the line we stopped in. */ |
284 | ||
507f3c78 KB |
285 | void (*print_frame_info_listing_hook) (struct symtab * s, int line, |
286 | int stopline, int noerror); | |
c906108c SS |
287 | /* Replaces most of query. */ |
288 | ||
507f3c78 | 289 | int (*query_hook) (const char *, va_list); |
c906108c SS |
290 | |
291 | /* Replaces most of warning. */ | |
292 | ||
507f3c78 | 293 | void (*warning_hook) (const char *, va_list); |
c906108c | 294 | |
c906108c SS |
295 | /* These three functions support getting lines of text from the user. They |
296 | are used in sequence. First readline_begin_hook is called with a text | |
297 | string that might be (for example) a message for the user to type in a | |
298 | sequence of commands to be executed at a breakpoint. If this function | |
299 | calls back to a GUI, it might take this opportunity to pop up a text | |
300 | interaction window with this message. Next, readline_hook is called | |
301 | with a prompt that is emitted prior to collecting the user input. | |
302 | It can be called multiple times. Finally, readline_end_hook is called | |
303 | to notify the GUI that we are done with the interaction window and it | |
304 | can close it. */ | |
305 | ||
507f3c78 KB |
306 | void (*readline_begin_hook) (char *, ...); |
307 | char *(*readline_hook) (char *); | |
308 | void (*readline_end_hook) (void); | |
c906108c SS |
309 | |
310 | /* Called as appropriate to notify the interface of the specified breakpoint | |
311 | conditions. */ | |
312 | ||
507f3c78 KB |
313 | void (*create_breakpoint_hook) (struct breakpoint * bpt); |
314 | void (*delete_breakpoint_hook) (struct breakpoint * bpt); | |
315 | void (*modify_breakpoint_hook) (struct breakpoint * bpt); | |
c906108c | 316 | |
6426a772 JM |
317 | /* Called as appropriate to notify the interface that we have attached |
318 | to or detached from an already running process. */ | |
319 | ||
507f3c78 KB |
320 | void (*attach_hook) (void); |
321 | void (*detach_hook) (void); | |
6426a772 | 322 | |
c906108c SS |
323 | /* Called during long calculations to allow GUI to repair window damage, and to |
324 | check for stop buttons, etc... */ | |
325 | ||
507f3c78 | 326 | void (*interactive_hook) (void); |
c906108c SS |
327 | |
328 | /* Called when the registers have changed, as a hint to a GUI | |
329 | to minimize window update. */ | |
330 | ||
507f3c78 | 331 | void (*registers_changed_hook) (void); |
c906108c SS |
332 | |
333 | /* Tell the GUI someone changed the register REGNO. -1 means | |
334 | that the caller does not know which register changed or | |
c5aa993b | 335 | that several registers have changed (see value_assign). */ |
507f3c78 | 336 | void (*register_changed_hook) (int regno); |
c906108c SS |
337 | |
338 | /* Tell the GUI someone changed LEN bytes of memory at ADDR */ | |
507f3c78 | 339 | void (*memory_changed_hook) (CORE_ADDR addr, int len); |
c906108c SS |
340 | |
341 | /* Called when going to wait for the target. Usually allows the GUI to run | |
342 | while waiting for target events. */ | |
343 | ||
507f3c78 | 344 | int (*target_wait_hook) (int pid, struct target_waitstatus * status); |
c906108c SS |
345 | |
346 | /* Used by UI as a wrapper around command execution. May do various things | |
347 | like enabling/disabling buttons, etc... */ | |
348 | ||
507f3c78 KB |
349 | void (*call_command_hook) (struct cmd_list_element * c, char *cmd, |
350 | int from_tty); | |
c906108c | 351 | |
96baa820 JM |
352 | /* Called after a `set' command has finished. Is only run if the |
353 | `set' command succeeded. */ | |
354 | ||
eb2f494a | 355 | void (*set_hook) (struct cmd_list_element * c); |
96baa820 | 356 | |
c906108c SS |
357 | /* Called when the current thread changes. Argument is thread id. */ |
358 | ||
507f3c78 | 359 | void (*context_hook) (int id); |
c906108c SS |
360 | |
361 | /* Takes control from error (). Typically used to prevent longjmps out of the | |
362 | middle of the GUI. Usually used in conjunction with a catch routine. */ | |
363 | ||
eb2f494a | 364 | NORETURN void (*error_hook) (void) ATTR_NORETURN; |
c906108c | 365 | \f |
c5aa993b | 366 | |
99eeeb0f ND |
367 | /* One should use catch_errors rather than manipulating these |
368 | directly. */ | |
c4093a6a JM |
369 | #if defined(HAVE_SIGSETJMP) |
370 | #define SIGJMP_BUF sigjmp_buf | |
371 | #define SIGSETJMP(buf) sigsetjmp(buf, 1) | |
372 | #define SIGLONGJMP(buf,val) siglongjmp(buf,val) | |
373 | #else | |
374 | #define SIGJMP_BUF jmp_buf | |
375 | #define SIGSETJMP(buf) setjmp(buf) | |
376 | #define SIGLONGJMP(buf,val) longjmp(buf,val) | |
377 | #endif | |
378 | ||
99eeeb0f ND |
379 | /* Where to go for return_to_top_level. */ |
380 | static SIGJMP_BUF *catch_return; | |
c906108c | 381 | |
99eeeb0f | 382 | /* Return for reason REASON to the nearest containing catch_errors(). */ |
c906108c | 383 | |
c2d11a7d | 384 | NORETURN void |
fba45db2 | 385 | return_to_top_level (enum return_reason reason) |
c906108c SS |
386 | { |
387 | quit_flag = 0; | |
388 | immediate_quit = 0; | |
389 | ||
390 | /* Perhaps it would be cleaner to do this via the cleanup chain (not sure | |
391 | I can think of a reason why that is vital, though). */ | |
c5aa993b | 392 | bpstat_clear_actions (stop_bpstat); /* Clear queued breakpoint commands */ |
c906108c SS |
393 | |
394 | disable_current_display (); | |
395 | do_cleanups (ALL_CLEANUPS); | |
c4093a6a | 396 | if (event_loop_p && target_can_async_p () && !target_executing) |
43ff13b4 | 397 | do_exec_cleanups (ALL_CLEANUPS); |
6426a772 JM |
398 | if (event_loop_p && sync_execution) |
399 | do_exec_error_cleanups (ALL_CLEANUPS); | |
c906108c SS |
400 | |
401 | if (annotation_level > 1) | |
402 | switch (reason) | |
403 | { | |
404 | case RETURN_QUIT: | |
405 | annotate_quit (); | |
406 | break; | |
407 | case RETURN_ERROR: | |
408 | annotate_error (); | |
409 | break; | |
410 | } | |
411 | ||
99eeeb0f ND |
412 | /* Jump to the containing catch_errors() call, communicating REASON |
413 | to that call via setjmp's return value. Note that REASON can't | |
414 | be zero, by definition in defs.h. */ | |
415 | ||
eb2f494a | 416 | (NORETURN void) SIGLONGJMP (*catch_return, (int) reason); |
c906108c SS |
417 | } |
418 | ||
419 | /* Call FUNC with arg ARGS, catching any errors. If there is no | |
420 | error, return the value returned by FUNC. If there is an error, | |
421 | print ERRSTRING, print the specific error message, then return | |
422 | zero. | |
423 | ||
424 | Must not be called with immediate_quit in effect (bad things might | |
425 | happen, say we got a signal in the middle of a memcpy to quit_return). | |
426 | This is an OK restriction; with very few exceptions immediate_quit can | |
427 | be replaced by judicious use of QUIT. | |
428 | ||
429 | MASK specifies what to catch; it is normally set to | |
430 | RETURN_MASK_ALL, if for no other reason than that the code which | |
431 | calls catch_errors might not be set up to deal with a quit which | |
432 | isn't caught. But if the code can deal with it, it generally | |
433 | should be RETURN_MASK_ERROR, unless for some reason it is more | |
434 | useful to abort only the portion of the operation inside the | |
435 | catch_errors. Note that quit should return to the command line | |
436 | fairly quickly, even if some further processing is being done. */ | |
437 | ||
11cf8741 JM |
438 | /* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with |
439 | error() et.al. could maintain a set of flags that indicate the the | |
440 | current state of each of the longjmp buffers. This would give the | |
441 | longjmp code the chance to detect a longjmp botch (before it gets | |
442 | to longjmperror()). Prior to 1999-11-05 this wasn't possible as | |
443 | code also randomly used a SET_TOP_LEVEL macro that directly | |
444 | initialize the longjmp buffers. */ | |
445 | ||
e26cc349 | 446 | /* MAYBE: cagney/1999-11-05: Should the catch_errors and cleanups code |
11cf8741 JM |
447 | be consolidated into a single file instead of being distributed |
448 | between utils.c and top.c? */ | |
449 | ||
c906108c | 450 | int |
fba45db2 KB |
451 | catch_errors (catch_errors_ftype *func, PTR args, char *errstring, |
452 | return_mask mask) | |
c906108c | 453 | { |
99eeeb0f ND |
454 | SIGJMP_BUF *saved_catch; |
455 | SIGJMP_BUF catch; | |
c906108c SS |
456 | int val; |
457 | struct cleanup *saved_cleanup_chain; | |
458 | char *saved_error_pre_print; | |
459 | char *saved_quit_pre_print; | |
460 | ||
99eeeb0f ND |
461 | /* Return value from SIGSETJMP(): enum return_reason if error or |
462 | quit caught, 0 otherwise. */ | |
463 | int caught; | |
464 | ||
465 | /* Override error/quit messages during FUNC. */ | |
466 | ||
c906108c SS |
467 | saved_error_pre_print = error_pre_print; |
468 | saved_quit_pre_print = quit_pre_print; | |
469 | ||
470 | if (mask & RETURN_MASK_ERROR) | |
99eeeb0f | 471 | error_pre_print = errstring; |
c906108c | 472 | if (mask & RETURN_MASK_QUIT) |
99eeeb0f ND |
473 | quit_pre_print = errstring; |
474 | ||
475 | /* Prevent error/quit during FUNC from calling cleanups established | |
476 | prior to here. */ | |
477 | ||
478 | saved_cleanup_chain = save_cleanups (); | |
479 | ||
480 | /* Call FUNC, catching error/quit events. */ | |
481 | ||
482 | saved_catch = catch_return; | |
483 | catch_return = &catch; | |
484 | caught = SIGSETJMP (catch); | |
485 | if (!caught) | |
486 | val = (*func) (args); | |
7f7e9482 AC |
487 | else |
488 | val = 0; | |
99eeeb0f ND |
489 | catch_return = saved_catch; |
490 | ||
e26cc349 | 491 | /* FIXME: cagney/1999-11-05: A correct FUNC implementation will |
99eeeb0f | 492 | clean things up (restoring the cleanup chain) to the state they |
e26cc349 | 493 | were just prior to the call. Unfortunately, many FUNC's are not |
99eeeb0f ND |
494 | that well behaved. This could be fixed by adding either a |
495 | do_cleanups call (to cover the problem) or an assertion check to | |
496 | detect bad FUNCs code. */ | |
497 | ||
498 | /* Restore the cleanup chain and error/quit messages to their | |
499 | original states. */ | |
c906108c SS |
500 | |
501 | restore_cleanups (saved_cleanup_chain); | |
502 | ||
c906108c | 503 | if (mask & RETURN_MASK_QUIT) |
99eeeb0f ND |
504 | quit_pre_print = saved_quit_pre_print; |
505 | if (mask & RETURN_MASK_ERROR) | |
506 | error_pre_print = saved_error_pre_print; | |
507 | ||
508 | /* Return normally if no error/quit event occurred. */ | |
509 | ||
510 | if (!caught) | |
511 | return val; | |
512 | ||
513 | /* If the caller didn't request that the event be caught, relay the | |
514 | event to the next containing catch_errors(). */ | |
515 | ||
516 | if (!(mask & RETURN_MASK (caught))) | |
517 | return_to_top_level (caught); | |
518 | ||
519 | /* Tell the caller that an event was caught. | |
520 | ||
521 | FIXME: nsd/2000-02-22: When MASK is RETURN_MASK_ALL, the caller | |
522 | can't tell what type of event occurred. | |
523 | ||
524 | A possible fix is to add a new interface, catch_event(), that | |
525 | returns enum return_reason after catching an error or a quit. | |
526 | ||
527 | When returning normally, i.e. without catching an error or a | |
528 | quit, catch_event() could return RETURN_NORMAL, which would be | |
529 | added to enum return_reason. FUNC would return information | |
530 | exclusively via ARGS. | |
531 | ||
532 | Alternatively, normal catch_event() could return FUNC's return | |
533 | value. The caller would need to be aware of potential overlap | |
534 | with enum return_reason, which could be publicly restricted to | |
535 | negative values to simplify return value processing in FUNC and | |
536 | in the caller. */ | |
537 | ||
538 | return 0; | |
c906108c SS |
539 | } |
540 | ||
11cf8741 JM |
541 | struct captured_command_args |
542 | { | |
543 | catch_command_errors_ftype *command; | |
544 | char *arg; | |
545 | int from_tty; | |
546 | }; | |
547 | ||
548 | static int | |
549 | do_captured_command (void *data) | |
550 | { | |
551 | struct captured_command_args *context = data; | |
552 | context->command (context->arg, context->from_tty); | |
553 | /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call | |
554 | isn't needed. Instead an assertion check could be made that | |
555 | simply confirmed that the called function correctly cleaned up | |
e26cc349 | 556 | after itself. Unfortunately, old code (prior to 1999-11-04) in |
11cf8741 JM |
557 | main.c was calling SET_TOP_LEVEL(), calling the command function, |
558 | and then *always* calling do_cleanups(). For the moment we | |
559 | remain ``bug compatible'' with that old code.. */ | |
560 | do_cleanups (ALL_CLEANUPS); | |
561 | return 1; | |
562 | } | |
563 | ||
564 | int | |
eb2f494a | 565 | catch_command_errors (catch_command_errors_ftype * command, |
11cf8741 JM |
566 | char *arg, int from_tty, return_mask mask) |
567 | { | |
568 | struct captured_command_args args; | |
569 | args.command = command; | |
570 | args.arg = arg; | |
571 | args.from_tty = from_tty; | |
572 | return catch_errors (do_captured_command, &args, "", mask); | |
573 | } | |
574 | ||
575 | ||
c906108c SS |
576 | /* Handler for SIGHUP. */ |
577 | ||
578 | #ifdef SIGHUP | |
579 | static void | |
fba45db2 | 580 | disconnect (int signo) |
c906108c SS |
581 | { |
582 | catch_errors (quit_cover, NULL, | |
c5aa993b | 583 | "Could not kill the program being debugged", RETURN_MASK_ALL); |
c906108c SS |
584 | signal (SIGHUP, SIG_DFL); |
585 | kill (getpid (), SIGHUP); | |
586 | } | |
587 | ||
588 | /* Just a little helper function for disconnect(). */ | |
589 | ||
392a587b | 590 | /* NOTE 1999-04-29: This function will be static again, once we modify |
cd0fc7c3 SS |
591 | gdb to use the event loop as the default command loop and we merge |
592 | event-top.c into this file, top.c */ | |
593 | /* static */ int | |
fba45db2 | 594 | quit_cover (PTR s) |
c906108c | 595 | { |
c5aa993b JM |
596 | caution = 0; /* Throw caution to the wind -- we're exiting. |
597 | This prevents asking the user dumb questions. */ | |
598 | quit_command ((char *) 0, 0); | |
c906108c SS |
599 | return 0; |
600 | } | |
601 | #endif /* defined SIGHUP */ | |
602 | \f | |
603 | /* Line number we are currently in in a file which is being sourced. */ | |
392a587b | 604 | /* NOTE 1999-04-29: This variable will be static again, once we modify |
cd0fc7c3 SS |
605 | gdb to use the event loop as the default command loop and we merge |
606 | event-top.c into this file, top.c */ | |
607 | /* static */ int source_line_number; | |
c906108c SS |
608 | |
609 | /* Name of the file we are sourcing. */ | |
392a587b | 610 | /* NOTE 1999-04-29: This variable will be static again, once we modify |
cd0fc7c3 SS |
611 | gdb to use the event loop as the default command loop and we merge |
612 | event-top.c into this file, top.c */ | |
613 | /* static */ char *source_file_name; | |
c906108c SS |
614 | |
615 | /* Buffer containing the error_pre_print used by the source stuff. | |
616 | Malloc'd. */ | |
392a587b | 617 | /* NOTE 1999-04-29: This variable will be static again, once we modify |
cd0fc7c3 SS |
618 | gdb to use the event loop as the default command loop and we merge |
619 | event-top.c into this file, top.c */ | |
620 | /* static */ char *source_error; | |
c906108c SS |
621 | static int source_error_allocated; |
622 | ||
623 | /* Something to glom on to the start of error_pre_print if source_file_name | |
624 | is set. */ | |
392a587b | 625 | /* NOTE 1999-04-29: This variable will be static again, once we modify |
cd0fc7c3 SS |
626 | gdb to use the event loop as the default command loop and we merge |
627 | event-top.c into this file, top.c */ | |
628 | /* static */ char *source_pre_error; | |
c906108c SS |
629 | |
630 | /* Clean up on error during a "source" command (or execution of a | |
631 | user-defined command). */ | |
632 | ||
d318976c | 633 | void |
e41a3b1a | 634 | do_restore_instream_cleanup (void *stream) |
c906108c SS |
635 | { |
636 | /* Restore the previous input stream. */ | |
637 | instream = stream; | |
638 | } | |
639 | ||
640 | /* Read commands from STREAM. */ | |
641 | void | |
fba45db2 | 642 | read_command_file (FILE *stream) |
c906108c SS |
643 | { |
644 | struct cleanup *cleanups; | |
645 | ||
e41a3b1a | 646 | cleanups = make_cleanup (do_restore_instream_cleanup, instream); |
c906108c | 647 | instream = stream; |
c5aa993b | 648 | command_loop (); |
c906108c SS |
649 | do_cleanups (cleanups); |
650 | } | |
651 | \f | |
a14ed312 | 652 | extern void init_proc (void); |
c906108c | 653 | |
507f3c78 | 654 | void (*pre_init_ui_hook) (void); |
c906108c | 655 | |
e41a3b1a AC |
656 | #ifdef __MSDOS__ |
657 | void | |
658 | do_chdir_cleanup (void *old_dir) | |
659 | { | |
660 | chdir (old_dir); | |
b8c9b27d | 661 | xfree (old_dir); |
e41a3b1a AC |
662 | } |
663 | #endif | |
664 | ||
c906108c | 665 | void |
fba45db2 | 666 | gdb_init (char *argv0) |
c906108c SS |
667 | { |
668 | if (pre_init_ui_hook) | |
669 | pre_init_ui_hook (); | |
670 | ||
671 | /* Run the init function of each source file */ | |
672 | ||
673 | getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); | |
674 | current_directory = gdb_dirbuf; | |
675 | ||
a0b3c4fd JM |
676 | #ifdef __MSDOS__ |
677 | /* Make sure we return to the original directory upon exit, come | |
678 | what may, since the OS doesn't do that for us. */ | |
e41a3b1a | 679 | make_final_cleanup (do_chdir_cleanup, xstrdup (current_directory)); |
a0b3c4fd JM |
680 | #endif |
681 | ||
c5aa993b JM |
682 | init_cmd_lists (); /* This needs to be done first */ |
683 | initialize_targets (); /* Setup target_terminal macros for utils.c */ | |
684 | initialize_utils (); /* Make errors and warnings possible */ | |
c906108c | 685 | initialize_all_files (); |
e514a9d6 | 686 | initialize_current_architecture (); |
d318976c | 687 | init_cli_cmds(); |
c5aa993b | 688 | init_main (); /* But that omits this file! Do it now */ |
cd0fc7c3 SS |
689 | |
690 | /* The signal handling mechanism is different depending whether or | |
691 | not the async version is run. NOTE: in the future we plan to make | |
692 | the event loop be the default engine of gdb, and this difference | |
693 | will disappear. */ | |
6426a772 | 694 | if (event_loop_p) |
cd0fc7c3 SS |
695 | async_init_signals (); |
696 | else | |
c5aa993b | 697 | init_signals (); |
c906108c | 698 | |
c906108c SS |
699 | /* We need a default language for parsing expressions, so simple things like |
700 | "set width 0" won't fail if no language is explicitly set in a config file | |
701 | or implicitly set by reading an executable during startup. */ | |
702 | set_language (language_c); | |
c5aa993b | 703 | expected_language = current_language; /* don't warn about the change. */ |
c906108c | 704 | |
8b93c638 JM |
705 | #ifdef UI_OUT |
706 | /* Install the default UI */ | |
707 | uiout = cli_out_new (gdb_stdout); | |
708 | #endif | |
fb40c209 AC |
709 | |
710 | #ifdef UI_OUT | |
711 | /* All the interpreters should have had a look at things by now. | |
712 | Initialize the selected interpreter. */ | |
713 | if (interpreter_p && !init_ui_hook) | |
714 | { | |
715 | fprintf_unfiltered (gdb_stderr, "Interpreter `%s' unrecognized.\n", | |
716 | interpreter_p); | |
717 | exit (1); | |
718 | } | |
719 | #endif | |
8b93c638 | 720 | |
c906108c SS |
721 | if (init_ui_hook) |
722 | init_ui_hook (argv0); | |
723 | } | |
724 | ||
d318976c FN |
725 | /* Execute the line P as a command. |
726 | Pass FROM_TTY as second argument to the defining function. */ | |
c906108c | 727 | |
d318976c FN |
728 | void |
729 | execute_command (char *p, int from_tty) | |
c906108c | 730 | { |
d318976c FN |
731 | register struct cmd_list_element *c; |
732 | register enum language flang; | |
733 | static int warned = 0; | |
734 | char *line; | |
735 | /* FIXME: These should really be in an appropriate header file */ | |
736 | extern void serial_log_command (const char *); | |
c906108c | 737 | |
d318976c | 738 | free_all_values (); |
c906108c | 739 | |
d318976c FN |
740 | /* Force cleanup of any alloca areas if using C alloca instead of |
741 | a builtin alloca. */ | |
742 | alloca (0); | |
c906108c | 743 | |
d318976c FN |
744 | /* This can happen when command_line_input hits end of file. */ |
745 | if (p == NULL) | |
746 | return; | |
c906108c | 747 | |
d318976c | 748 | serial_log_command (p); |
8b93c638 | 749 | |
d318976c FN |
750 | while (*p == ' ' || *p == '\t') |
751 | p++; | |
752 | if (*p) | |
8b93c638 | 753 | { |
d318976c FN |
754 | char *arg; |
755 | line = p; | |
8b93c638 | 756 | |
d318976c | 757 | c = lookup_cmd (&p, cmdlist, "", 0, 1); |
8b93c638 | 758 | |
d318976c FN |
759 | /* If the target is running, we allow only a limited set of |
760 | commands. */ | |
761 | if (event_loop_p && target_can_async_p () && target_executing) | |
762 | if (!strcmp (c->name, "help") | |
763 | && !strcmp (c->name, "pwd") | |
764 | && !strcmp (c->name, "show") | |
765 | && !strcmp (c->name, "stop")) | |
766 | error ("Cannot execute this command while the target is running."); | |
8b93c638 | 767 | |
d318976c FN |
768 | /* Pass null arg rather than an empty one. */ |
769 | arg = *p ? p : 0; | |
8b93c638 | 770 | |
d318976c FN |
771 | /* Clear off trailing whitespace, except for set and complete command. */ |
772 | if (arg | |
773 | && c->type != set_cmd | |
774 | && !is_complete_command (c->function.cfunc)) | |
8b93c638 | 775 | { |
d318976c FN |
776 | p = arg + strlen (arg) - 1; |
777 | while (p >= arg && (*p == ' ' || *p == '\t')) | |
778 | p--; | |
779 | *(p + 1) = '\0'; | |
8b93c638 JM |
780 | } |
781 | ||
d318976c FN |
782 | /* If this command has been pre-hooked, run the hook first. */ |
783 | if ((c->hook_pre) && (!c->hook_in)) | |
784 | { | |
785 | c->hook_in = 1; /* Prevent recursive hooking */ | |
786 | execute_user_command (c->hook_pre, (char *) 0); | |
787 | c->hook_in = 0; /* Allow hook to work again once it is complete */ | |
788 | } | |
c906108c | 789 | |
d318976c FN |
790 | if (c->flags & DEPRECATED_WARN_USER) |
791 | deprecated_cmd_warning (&line); | |
c906108c | 792 | |
d318976c FN |
793 | if (c->class == class_user) |
794 | execute_user_command (c, arg); | |
795 | else if (c->type == set_cmd || c->type == show_cmd) | |
796 | do_setshow_command (arg, from_tty & caution, c); | |
797 | else if (c->function.cfunc == NO_FUNCTION) | |
798 | error ("That is not a command, just a help topic."); | |
799 | else if (call_command_hook) | |
800 | call_command_hook (c, arg, from_tty & caution); | |
801 | else | |
802 | (*c->function.cfunc) (arg, from_tty & caution); | |
803 | ||
804 | /* If this command has been post-hooked, run the hook last. */ | |
805 | if ((c->hook_post) && (!c->hook_in)) | |
806 | { | |
807 | c->hook_in = 1; /* Prevent recursive hooking */ | |
808 | execute_user_command (c->hook_post, (char *) 0); | |
809 | c->hook_in = 0; /* allow hook to work again once it is complete */ | |
810 | } | |
c906108c | 811 | |
c906108c SS |
812 | } |
813 | ||
d318976c FN |
814 | /* Tell the user if the language has changed (except first time). */ |
815 | if (current_language != expected_language) | |
c906108c | 816 | { |
d318976c | 817 | if (language_mode == language_mode_auto) |
c906108c | 818 | { |
d318976c | 819 | language_info (1); /* Print what changed. */ |
c906108c | 820 | } |
d318976c | 821 | warned = 0; |
c906108c SS |
822 | } |
823 | ||
d318976c FN |
824 | /* Warn the user if the working language does not match the |
825 | language of the current frame. Only warn the user if we are | |
826 | actually running the program, i.e. there is a stack. */ | |
827 | /* FIXME: This should be cacheing the frame and only running when | |
828 | the frame changes. */ | |
829 | ||
830 | if (target_has_stack) | |
c906108c | 831 | { |
d318976c FN |
832 | flang = get_frame_language (); |
833 | if (!warned | |
834 | && flang != language_unknown | |
835 | && flang != current_language->la_language) | |
c906108c | 836 | { |
d318976c FN |
837 | printf_filtered ("%s\n", lang_frame_mismatch_warn); |
838 | warned = 1; | |
c906108c | 839 | } |
c906108c SS |
840 | } |
841 | } | |
842 | ||
d318976c FN |
843 | /* Read commands from `instream' and execute them |
844 | until end of file or error reading instream. */ | |
c906108c | 845 | |
d318976c FN |
846 | void |
847 | command_loop (void) | |
c906108c | 848 | { |
d318976c FN |
849 | struct cleanup *old_chain; |
850 | char *command; | |
851 | int stdin_is_tty = ISATTY (stdin); | |
852 | long time_at_cmd_start; | |
853 | #ifdef HAVE_SBRK | |
854 | long space_at_cmd_start = 0; | |
855 | #endif | |
856 | extern int display_time; | |
857 | extern int display_space; | |
c5aa993b | 858 | |
d318976c FN |
859 | while (instream && !feof (instream)) |
860 | { | |
861 | #if defined(TUI) | |
862 | extern int insert_mode; | |
863 | #endif | |
864 | if (window_hook && instream == stdin) | |
865 | (*window_hook) (instream, get_prompt ()); | |
c906108c | 866 | |
d318976c FN |
867 | quit_flag = 0; |
868 | if (instream == stdin && stdin_is_tty) | |
869 | reinitialize_more_filter (); | |
870 | old_chain = make_cleanup (null_cleanup, 0); | |
c906108c | 871 | |
d318976c FN |
872 | #if defined(TUI) |
873 | /* A bit of paranoia: I want to make sure the "insert_mode" global | |
874 | * is clear except when it is being used for command-line editing | |
875 | * (see tuiIO.c, utils.c); otherwise normal output will | |
876 | * get messed up in the TUI. So clear it before/after | |
877 | * the command-line-input call. - RT | |
878 | */ | |
879 | insert_mode = 0; | |
880 | #endif | |
881 | /* Get a command-line. This calls the readline package. */ | |
882 | command = command_line_input (instream == stdin ? | |
883 | get_prompt () : (char *) NULL, | |
884 | instream == stdin, "prompt"); | |
885 | #if defined(TUI) | |
886 | insert_mode = 0; | |
887 | #endif | |
888 | if (command == 0) | |
889 | return; | |
c906108c | 890 | |
d318976c | 891 | time_at_cmd_start = get_run_time (); |
c906108c | 892 | |
d318976c | 893 | if (display_space) |
9e0b60a8 | 894 | { |
d318976c FN |
895 | #ifdef HAVE_SBRK |
896 | extern char **environ; | |
897 | char *lim = (char *) sbrk (0); | |
9e0b60a8 | 898 | |
d318976c | 899 | space_at_cmd_start = (long) (lim - (char *) &environ); |
9e0b60a8 | 900 | #endif |
d318976c | 901 | } |
9e0b60a8 | 902 | |
d318976c FN |
903 | execute_command (command, instream == stdin); |
904 | /* Do any commands attached to breakpoint we stopped at. */ | |
905 | bpstat_do_actions (&stop_bpstat); | |
906 | do_cleanups (old_chain); | |
9e0b60a8 | 907 | |
d318976c | 908 | if (display_time) |
9e0b60a8 | 909 | { |
d318976c | 910 | long cmd_time = get_run_time () - time_at_cmd_start; |
9e0b60a8 | 911 | |
d318976c FN |
912 | printf_unfiltered ("Command execution time: %ld.%06ld\n", |
913 | cmd_time / 1000000, cmd_time % 1000000); | |
9e0b60a8 | 914 | } |
9e0b60a8 | 915 | |
d318976c | 916 | if (display_space) |
9e0b60a8 | 917 | { |
d318976c FN |
918 | #ifdef HAVE_SBRK |
919 | extern char **environ; | |
920 | char *lim = (char *) sbrk (0); | |
921 | long space_now = lim - (char *) &environ; | |
922 | long space_diff = space_now - space_at_cmd_start; | |
923 | ||
924 | printf_unfiltered ("Space used: %ld (%c%ld for this command)\n", | |
925 | space_now, | |
926 | (space_diff >= 0 ? '+' : '-'), | |
927 | space_diff); | |
928 | #endif | |
9e0b60a8 | 929 | } |
9e0b60a8 | 930 | } |
9e0b60a8 | 931 | } |
9e0b60a8 | 932 | |
d318976c FN |
933 | /* Read commands from `instream' and execute them until end of file or |
934 | error reading instream. This command loop doesnt care about any | |
935 | such things as displaying time and space usage. If the user asks | |
936 | for those, they won't work. */ | |
937 | void | |
938 | simplified_command_loop (char *(*read_input_func) (char *), | |
939 | void (*execute_command_func) (char *, int)) | |
9e0b60a8 | 940 | { |
d318976c FN |
941 | struct cleanup *old_chain; |
942 | char *command; | |
943 | int stdin_is_tty = ISATTY (stdin); | |
9e0b60a8 | 944 | |
d318976c | 945 | while (instream && !feof (instream)) |
9e0b60a8 | 946 | { |
d318976c FN |
947 | quit_flag = 0; |
948 | if (instream == stdin && stdin_is_tty) | |
949 | reinitialize_more_filter (); | |
950 | old_chain = make_cleanup (null_cleanup, 0); | |
951 | ||
952 | /* Get a command-line. */ | |
953 | command = (*read_input_func) (instream == stdin ? | |
954 | get_prompt () : (char *) NULL); | |
9e0b60a8 | 955 | |
d318976c FN |
956 | if (command == 0) |
957 | return; | |
9e0b60a8 | 958 | |
d318976c | 959 | (*execute_command_func) (command, instream == stdin); |
9e0b60a8 | 960 | |
d318976c FN |
961 | /* Do any commands attached to breakpoint we stopped at. */ |
962 | bpstat_do_actions (&stop_bpstat); | |
9e0b60a8 | 963 | |
d318976c | 964 | do_cleanups (old_chain); |
c5aa993b | 965 | } |
9e0b60a8 | 966 | } |
d318976c FN |
967 | \f |
968 | /* Commands call this if they do not want to be repeated by null lines. */ | |
9e0b60a8 | 969 | |
d318976c FN |
970 | void |
971 | dont_repeat (void) | |
9e0b60a8 | 972 | { |
d318976c FN |
973 | if (server_command) |
974 | return; | |
9e0b60a8 | 975 | |
d318976c FN |
976 | /* If we aren't reading from standard input, we are saving the last |
977 | thing read from stdin in line and don't want to delete it. Null lines | |
978 | won't repeat here in any case. */ | |
979 | if (instream == stdin) | |
980 | *line = 0; | |
9e0b60a8 | 981 | } |
d318976c FN |
982 | \f |
983 | /* Read a line from the stream "instream" without command line editing. | |
9e0b60a8 | 984 | |
d318976c FN |
985 | It prints PROMPT_ARG once at the start. |
986 | Action is compatible with "readline", e.g. space for the result is | |
987 | malloc'd and should be freed by the caller. | |
9e0b60a8 | 988 | |
d318976c FN |
989 | A NULL return means end of file. */ |
990 | char * | |
991 | gdb_readline (char *prompt_arg) | |
9e0b60a8 | 992 | { |
d318976c FN |
993 | int c; |
994 | char *result; | |
995 | int input_index = 0; | |
996 | int result_size = 80; | |
9e0b60a8 | 997 | |
d318976c | 998 | if (prompt_arg) |
9e0b60a8 | 999 | { |
d318976c FN |
1000 | /* Don't use a _filtered function here. It causes the assumed |
1001 | character position to be off, since the newline we read from | |
1002 | the user is not accounted for. */ | |
1003 | fputs_unfiltered (prompt_arg, gdb_stdout); | |
1004 | #ifdef MPW | |
1005 | /* Move to a new line so the entered line doesn't have a prompt | |
1006 | on the front of it. */ | |
1007 | fputs_unfiltered ("\n", gdb_stdout); | |
1008 | #endif /* MPW */ | |
9e0b60a8 JM |
1009 | gdb_flush (gdb_stdout); |
1010 | } | |
1011 | ||
d318976c | 1012 | result = (char *) xmalloc (result_size); |
9e0b60a8 JM |
1013 | |
1014 | while (1) | |
1015 | { | |
d318976c FN |
1016 | /* Read from stdin if we are executing a user defined command. |
1017 | This is the right thing for prompt_for_continue, at least. */ | |
1018 | c = fgetc (instream ? instream : stdin); | |
9e0b60a8 | 1019 | |
d318976c | 1020 | if (c == EOF) |
9e0b60a8 | 1021 | { |
d318976c FN |
1022 | if (input_index > 0) |
1023 | /* The last line does not end with a newline. Return it, and | |
1024 | if we are called again fgetc will still return EOF and | |
1025 | we'll return NULL then. */ | |
9e0b60a8 | 1026 | break; |
b8c9b27d | 1027 | xfree (result); |
d318976c | 1028 | return NULL; |
9e0b60a8 | 1029 | } |
c5aa993b | 1030 | |
d318976c FN |
1031 | if (c == '\n') |
1032 | #ifndef CRLF_SOURCE_FILES | |
1033 | break; | |
1034 | #else | |
9e0b60a8 | 1035 | { |
d318976c FN |
1036 | if (input_index > 0 && result[input_index - 1] == '\r') |
1037 | input_index--; | |
1038 | break; | |
9e0b60a8 | 1039 | } |
d318976c | 1040 | #endif |
9e0b60a8 | 1041 | |
d318976c FN |
1042 | result[input_index++] = c; |
1043 | while (input_index >= result_size) | |
9e0b60a8 | 1044 | { |
d318976c FN |
1045 | result_size *= 2; |
1046 | result = (char *) xrealloc (result, result_size); | |
9e0b60a8 | 1047 | } |
9e0b60a8 JM |
1048 | } |
1049 | ||
d318976c FN |
1050 | result[input_index++] = '\0'; |
1051 | return result; | |
9e0b60a8 JM |
1052 | } |
1053 | ||
d318976c FN |
1054 | /* Variables which control command line editing and history |
1055 | substitution. These variables are given default values at the end | |
1056 | of this file. */ | |
1057 | static int command_editing_p; | |
1058 | /* NOTE 1999-04-29: This variable will be static again, once we modify | |
1059 | gdb to use the event loop as the default command loop and we merge | |
1060 | event-top.c into this file, top.c */ | |
1061 | /* static */ int history_expansion_p; | |
1062 | static int write_history_p; | |
1063 | static int history_size; | |
1064 | static char *history_filename; | |
9e0b60a8 | 1065 | |
d318976c | 1066 | /* Functions that are used as part of the fancy command line editing. */ |
e41a3b1a | 1067 | |
d318976c FN |
1068 | /* This can be used for functions which don't want to complete on symbols |
1069 | but don't want to complete on anything else either. */ | |
1070 | /* ARGSUSED */ | |
1071 | char ** | |
1072 | noop_completer (char *text, char *prefix) | |
e41a3b1a | 1073 | { |
d318976c | 1074 | return NULL; |
e41a3b1a AC |
1075 | } |
1076 | ||
d318976c FN |
1077 | /* Line completion interface function for readline. */ |
1078 | ||
1079 | static char * | |
1080 | readline_line_completion_function (char *text, int matches) | |
e41a3b1a | 1081 | { |
d318976c | 1082 | return line_completion_function (text, matches, rl_line_buffer, rl_point); |
e41a3b1a | 1083 | } |
9e0b60a8 | 1084 | \f |
d318976c FN |
1085 | #ifdef STOP_SIGNAL |
1086 | static void | |
1087 | stop_sig (int signo) | |
9e0b60a8 | 1088 | { |
d318976c FN |
1089 | #if STOP_SIGNAL == SIGTSTP |
1090 | signal (SIGTSTP, SIG_DFL); | |
1091 | sigsetmask (0); | |
1092 | kill (getpid (), SIGTSTP); | |
1093 | signal (SIGTSTP, stop_sig); | |
1094 | #else | |
1095 | signal (STOP_SIGNAL, stop_sig); | |
1096 | #endif | |
1097 | printf_unfiltered ("%s", get_prompt ()); | |
1098 | gdb_flush (gdb_stdout); | |
9e0b60a8 | 1099 | |
d318976c FN |
1100 | /* Forget about any previous command -- null line now will do nothing. */ |
1101 | dont_repeat (); | |
9e0b60a8 | 1102 | } |
d318976c | 1103 | #endif /* STOP_SIGNAL */ |
9e0b60a8 | 1104 | |
d318976c | 1105 | /* Initialize signal handlers. */ |
9e0b60a8 | 1106 | static void |
d318976c | 1107 | do_nothing (int signo) |
9e0b60a8 | 1108 | { |
d318976c FN |
1109 | /* Under System V the default disposition of a signal is reinstated after |
1110 | the signal is caught and delivered to an application process. On such | |
1111 | systems one must restore the replacement signal handler if one wishes | |
1112 | to continue handling the signal in one's program. On BSD systems this | |
1113 | is not needed but it is harmless, and it simplifies the code to just do | |
1114 | it unconditionally. */ | |
1115 | signal (signo, do_nothing); | |
9e0b60a8 JM |
1116 | } |
1117 | ||
9e0b60a8 | 1118 | static void |
d318976c | 1119 | init_signals (void) |
9e0b60a8 | 1120 | { |
d318976c | 1121 | signal (SIGINT, request_quit); |
9e0b60a8 | 1122 | |
d318976c FN |
1123 | /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed |
1124 | to the inferior and breakpoints will be ignored. */ | |
1125 | #ifdef SIGTRAP | |
1126 | signal (SIGTRAP, SIG_DFL); | |
1127 | #endif | |
9e0b60a8 | 1128 | |
d318976c FN |
1129 | /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get |
1130 | passed to the inferior, which we don't want. It would be | |
1131 | possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but | |
1132 | on BSD4.3 systems using vfork, that can affect the | |
1133 | GDB process as well as the inferior (the signal handling tables | |
1134 | might be in memory, shared between the two). Since we establish | |
1135 | a handler for SIGQUIT, when we call exec it will set the signal | |
1136 | to SIG_DFL for us. */ | |
1137 | signal (SIGQUIT, do_nothing); | |
1138 | #ifdef SIGHUP | |
1139 | if (signal (SIGHUP, do_nothing) != SIG_IGN) | |
1140 | signal (SIGHUP, disconnect); | |
1141 | #endif | |
1142 | signal (SIGFPE, float_handler); | |
9e0b60a8 | 1143 | |
d318976c FN |
1144 | #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER) |
1145 | signal (SIGWINCH, SIGWINCH_HANDLER); | |
1146 | #endif | |
9e0b60a8 JM |
1147 | } |
1148 | \f | |
d318976c FN |
1149 | /* Read one line from the command input stream `instream' |
1150 | into the local static buffer `linebuffer' (whose current length | |
1151 | is `linelength'). | |
1152 | The buffer is made bigger as necessary. | |
1153 | Returns the address of the start of the line. | |
9e0b60a8 | 1154 | |
d318976c | 1155 | NULL is returned for end of file. |
9e0b60a8 | 1156 | |
d318976c FN |
1157 | *If* the instream == stdin & stdin is a terminal, the line read |
1158 | is copied into the file line saver (global var char *line, | |
1159 | length linesize) so that it can be duplicated. | |
9e0b60a8 | 1160 | |
d318976c FN |
1161 | This routine either uses fancy command line editing or |
1162 | simple input as the user has requested. */ | |
10689f25 | 1163 | |
d318976c FN |
1164 | char * |
1165 | command_line_input (char *prompt_arg, int repeat, char *annotation_suffix) | |
9e0b60a8 | 1166 | { |
d318976c FN |
1167 | static char *linebuffer = 0; |
1168 | static unsigned linelength = 0; | |
9e0b60a8 | 1169 | register char *p; |
d318976c FN |
1170 | char *p1; |
1171 | char *rl; | |
1172 | char *local_prompt = prompt_arg; | |
1173 | char *nline; | |
1174 | char got_eof = 0; | |
1175 | ||
1176 | /* The annotation suffix must be non-NULL. */ | |
1177 | if (annotation_suffix == NULL) | |
1178 | annotation_suffix = ""; | |
9e0b60a8 | 1179 | |
d318976c FN |
1180 | if (annotation_level > 1 && instream == stdin) |
1181 | { | |
1182 | local_prompt = alloca ((prompt_arg == NULL ? 0 : strlen (prompt_arg)) | |
1183 | + strlen (annotation_suffix) + 40); | |
1184 | if (prompt_arg == NULL) | |
1185 | local_prompt[0] = '\0'; | |
1186 | else | |
1187 | strcpy (local_prompt, prompt_arg); | |
1188 | strcat (local_prompt, "\n\032\032"); | |
1189 | strcat (local_prompt, annotation_suffix); | |
1190 | strcat (local_prompt, "\n"); | |
1191 | } | |
9e0b60a8 | 1192 | |
d318976c | 1193 | if (linebuffer == 0) |
9e0b60a8 | 1194 | { |
d318976c FN |
1195 | linelength = 80; |
1196 | linebuffer = (char *) xmalloc (linelength); | |
9e0b60a8 | 1197 | } |
9e0b60a8 | 1198 | |
d318976c | 1199 | p = linebuffer; |
9e0b60a8 | 1200 | |
d318976c FN |
1201 | /* Control-C quits instantly if typed while in this loop |
1202 | since it should not wait until the user types a newline. */ | |
1203 | immediate_quit++; | |
1204 | #ifdef STOP_SIGNAL | |
1205 | if (job_control) | |
73bc900d | 1206 | { |
d318976c FN |
1207 | if (event_loop_p) |
1208 | signal (STOP_SIGNAL, handle_stop_sig); | |
1209 | else | |
1210 | signal (STOP_SIGNAL, stop_sig); | |
1211 | } | |
1212 | #endif | |
1213 | ||
1214 | while (1) | |
9e0b60a8 | 1215 | { |
d318976c FN |
1216 | /* Make sure that all output has been output. Some machines may let |
1217 | you get away with leaving out some of the gdb_flush, but not all. */ | |
1218 | wrap_here (""); | |
1219 | gdb_flush (gdb_stdout); | |
1220 | gdb_flush (gdb_stderr); | |
1221 | ||
1222 | if (source_file_name != NULL) | |
1223 | { | |
1224 | ++source_line_number; | |
1225 | sprintf (source_error, | |
1226 | "%s%s:%d: Error in sourced command file:\n", | |
1227 | source_pre_error, | |
1228 | source_file_name, | |
1229 | source_line_number); | |
1230 | error_pre_print = source_error; | |
1231 | } | |
1232 | ||
1233 | if (annotation_level > 1 && instream == stdin) | |
1234 | { | |
1235 | printf_unfiltered ("\n\032\032pre-"); | |
1236 | printf_unfiltered (annotation_suffix); | |
1237 | printf_unfiltered ("\n"); | |
1238 | } | |
1239 | ||
1240 | /* Don't use fancy stuff if not talking to stdin. */ | |
1241 | if (readline_hook && instream == NULL) | |
1242 | { | |
1243 | rl = (*readline_hook) (local_prompt); | |
1244 | } | |
1245 | else if (command_editing_p && instream == stdin && ISATTY (instream)) | |
1246 | { | |
1247 | rl = readline (local_prompt); | |
1248 | } | |
9e0b60a8 | 1249 | else |
d318976c FN |
1250 | { |
1251 | rl = gdb_readline (local_prompt); | |
1252 | } | |
9e0b60a8 | 1253 | |
d318976c FN |
1254 | if (annotation_level > 1 && instream == stdin) |
1255 | { | |
1256 | printf_unfiltered ("\n\032\032post-"); | |
1257 | printf_unfiltered (annotation_suffix); | |
1258 | printf_unfiltered ("\n"); | |
1259 | } | |
9e0b60a8 | 1260 | |
d318976c | 1261 | if (!rl || rl == (char *) EOF) |
9e0b60a8 | 1262 | { |
d318976c FN |
1263 | got_eof = 1; |
1264 | break; | |
9e0b60a8 | 1265 | } |
d318976c FN |
1266 | if (strlen (rl) + 1 + (p - linebuffer) > linelength) |
1267 | { | |
1268 | linelength = strlen (rl) + 1 + (p - linebuffer); | |
1269 | nline = (char *) xrealloc (linebuffer, linelength); | |
1270 | p += nline - linebuffer; | |
1271 | linebuffer = nline; | |
1272 | } | |
1273 | p1 = rl; | |
1274 | /* Copy line. Don't copy null at end. (Leaves line alone | |
1275 | if this was just a newline) */ | |
1276 | while (*p1) | |
1277 | *p++ = *p1++; | |
9e0b60a8 | 1278 | |
b8c9b27d | 1279 | xfree (rl); /* Allocated in readline. */ |
9e0b60a8 | 1280 | |
d318976c FN |
1281 | if (p == linebuffer || *(p - 1) != '\\') |
1282 | break; | |
9e0b60a8 | 1283 | |
d318976c FN |
1284 | p--; /* Put on top of '\'. */ |
1285 | local_prompt = (char *) 0; | |
1286 | } | |
9e0b60a8 | 1287 | |
d318976c FN |
1288 | #ifdef STOP_SIGNAL |
1289 | if (job_control) | |
1290 | signal (STOP_SIGNAL, SIG_DFL); | |
1291 | #endif | |
1292 | immediate_quit--; | |
9e0b60a8 | 1293 | |
d318976c FN |
1294 | if (got_eof) |
1295 | return NULL; | |
9e0b60a8 | 1296 | |
d318976c FN |
1297 | #define SERVER_COMMAND_LENGTH 7 |
1298 | server_command = | |
1299 | (p - linebuffer > SERVER_COMMAND_LENGTH) | |
1300 | && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH); | |
1301 | if (server_command) | |
9e0b60a8 | 1302 | { |
d318976c FN |
1303 | /* Note that we don't set `line'. Between this and the check in |
1304 | dont_repeat, this insures that repeating will still do the | |
1305 | right thing. */ | |
1306 | *p = '\0'; | |
1307 | return linebuffer + SERVER_COMMAND_LENGTH; | |
9e0b60a8 | 1308 | } |
9e0b60a8 | 1309 | |
d318976c FN |
1310 | /* Do history expansion if that is wished. */ |
1311 | if (history_expansion_p && instream == stdin | |
1312 | && ISATTY (instream)) | |
1313 | { | |
1314 | char *history_value; | |
1315 | int expanded; | |
9e0b60a8 | 1316 | |
d318976c FN |
1317 | *p = '\0'; /* Insert null now. */ |
1318 | expanded = history_expand (linebuffer, &history_value); | |
1319 | if (expanded) | |
1320 | { | |
1321 | /* Print the changes. */ | |
1322 | printf_unfiltered ("%s\n", history_value); | |
9e0b60a8 | 1323 | |
d318976c FN |
1324 | /* If there was an error, call this function again. */ |
1325 | if (expanded < 0) | |
1326 | { | |
b8c9b27d | 1327 | xfree (history_value); |
d318976c FN |
1328 | return command_line_input (prompt_arg, repeat, annotation_suffix); |
1329 | } | |
1330 | if (strlen (history_value) > linelength) | |
1331 | { | |
1332 | linelength = strlen (history_value) + 1; | |
1333 | linebuffer = (char *) xrealloc (linebuffer, linelength); | |
1334 | } | |
1335 | strcpy (linebuffer, history_value); | |
1336 | p = linebuffer + strlen (linebuffer); | |
b8c9b27d | 1337 | xfree (history_value); |
d318976c FN |
1338 | } |
1339 | } | |
9e0b60a8 | 1340 | |
d318976c FN |
1341 | /* If we just got an empty line, and that is supposed |
1342 | to repeat the previous command, return the value in the | |
1343 | global buffer. */ | |
1344 | if (repeat && p == linebuffer) | |
1345 | return line; | |
1346 | for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++); | |
1347 | if (repeat && !*p1) | |
1348 | return line; | |
9e0b60a8 | 1349 | |
d318976c | 1350 | *p = 0; |
9e0b60a8 | 1351 | |
d318976c FN |
1352 | /* Add line to history if appropriate. */ |
1353 | if (instream == stdin | |
1354 | && ISATTY (stdin) && *linebuffer) | |
1355 | add_history (linebuffer); | |
9e0b60a8 | 1356 | |
d318976c FN |
1357 | /* Note: lines consisting solely of comments are added to the command |
1358 | history. This is useful when you type a command, and then | |
1359 | realize you don't want to execute it quite yet. You can comment | |
1360 | out the command and then later fetch it from the value history | |
1361 | and remove the '#'. The kill ring is probably better, but some | |
1362 | people are in the habit of commenting things out. */ | |
1363 | if (*p1 == '#') | |
1364 | *p1 = '\0'; /* Found a comment. */ | |
9e0b60a8 | 1365 | |
d318976c FN |
1366 | /* Save into global buffer if appropriate. */ |
1367 | if (repeat) | |
1368 | { | |
1369 | if (linelength > linesize) | |
1370 | { | |
1371 | line = xrealloc (line, linelength); | |
1372 | linesize = linelength; | |
1373 | } | |
1374 | strcpy (line, linebuffer); | |
1375 | return line; | |
1376 | } | |
9e0b60a8 | 1377 | |
d318976c | 1378 | return linebuffer; |
9e0b60a8 JM |
1379 | } |
1380 | \f | |
1381 | /* Print the GDB banner. */ | |
1382 | void | |
fba45db2 | 1383 | print_gdb_version (struct ui_file *stream) |
9e0b60a8 JM |
1384 | { |
1385 | /* From GNU coding standards, first line is meant to be easy for a | |
1386 | program to parse, and is just canonical program name and version | |
1387 | number, which starts after last space. */ | |
1388 | ||
b4df4f68 | 1389 | #ifdef MI_OUT |
8b93c638 | 1390 | /* Print it console style until a format is defined */ |
b4df4f68 | 1391 | fprintf_filtered (stream, "GNU gdb %s (MI_OUT)\n", version); |
8b93c638 | 1392 | #else |
9e0b60a8 | 1393 | fprintf_filtered (stream, "GNU gdb %s\n", version); |
8b93c638 | 1394 | #endif |
9e0b60a8 JM |
1395 | |
1396 | /* Second line is a copyright notice. */ | |
1397 | ||
388e1ff2 | 1398 | fprintf_filtered (stream, "Copyright 2001 Free Software Foundation, Inc.\n"); |
9e0b60a8 JM |
1399 | |
1400 | /* Following the copyright is a brief statement that the program is | |
1401 | free software, that users are free to copy and change it on | |
1402 | certain conditions, that it is covered by the GNU GPL, and that | |
1403 | there is no warranty. */ | |
1404 | ||
1405 | fprintf_filtered (stream, "\ | |
1406 | GDB is free software, covered by the GNU General Public License, and you are\n\ | |
1407 | welcome to change it and/or distribute copies of it under certain conditions.\n\ | |
1408 | Type \"show copying\" to see the conditions.\n\ | |
1409 | There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n"); | |
1410 | ||
1411 | /* After the required info we print the configuration information. */ | |
1412 | ||
1413 | fprintf_filtered (stream, "This GDB was configured as \""); | |
1414 | if (!STREQ (host_name, target_name)) | |
1415 | { | |
1416 | fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name); | |
1417 | } | |
1418 | else | |
1419 | { | |
1420 | fprintf_filtered (stream, "%s", host_name); | |
1421 | } | |
1422 | fprintf_filtered (stream, "\"."); | |
1423 | } | |
9e0b60a8 JM |
1424 | \f |
1425 | /* get_prompt: access method for the GDB prompt string. */ | |
1426 | ||
1427 | #define MAX_PROMPT_SIZE 256 | |
1428 | ||
1429 | /* | |
1430 | * int get_prompt_1 (char * buf); | |
1431 | * | |
1432 | * Work-horse for get_prompt (called via catch_errors). | |
1433 | * Argument is buffer to hold the formatted prompt. | |
1434 | * | |
1435 | * Returns: 1 for success (use formatted prompt) | |
1436 | * 0 for failure (use gdb_prompt_string). | |
c5aa993b | 1437 | */ |
9e0b60a8 JM |
1438 | |
1439 | static int gdb_prompt_escape; | |
1440 | ||
1441 | static int | |
710b33bd | 1442 | get_prompt_1 (void *data) |
9e0b60a8 | 1443 | { |
710b33bd | 1444 | char *formatted_prompt = data; |
9e0b60a8 JM |
1445 | char *local_prompt; |
1446 | ||
6426a772 | 1447 | if (event_loop_p) |
9e0b60a8 JM |
1448 | local_prompt = PROMPT (0); |
1449 | else | |
1450 | local_prompt = gdb_prompt_string; | |
1451 | ||
1452 | ||
1453 | if (gdb_prompt_escape == 0) | |
1454 | { | |
c5aa993b | 1455 | return 0; /* do no formatting */ |
9e0b60a8 | 1456 | } |
c5aa993b JM |
1457 | else |
1458 | /* formatted prompt */ | |
9e0b60a8 | 1459 | { |
c5aa993b | 1460 | char fmt[40], *promptp, *outp, *tmp; |
9e0b60a8 | 1461 | value_ptr arg_val; |
c5aa993b JM |
1462 | DOUBLEST doubleval; |
1463 | LONGEST longval; | |
9e0b60a8 JM |
1464 | CORE_ADDR addrval; |
1465 | ||
1466 | int i, len; | |
1467 | struct type *arg_type, *elt_type; | |
1468 | ||
1469 | promptp = local_prompt; | |
c5aa993b | 1470 | outp = formatted_prompt; |
9e0b60a8 JM |
1471 | |
1472 | while (*promptp != '\0') | |
1473 | { | |
1474 | int available = MAX_PROMPT_SIZE - (outp - formatted_prompt) - 1; | |
1475 | ||
1476 | if (*promptp != gdb_prompt_escape) | |
1477 | { | |
c5aa993b | 1478 | if (available >= 1) /* overflow protect */ |
9e0b60a8 JM |
1479 | *outp++ = *promptp++; |
1480 | } | |
1481 | else | |
1482 | { | |
1483 | /* GDB prompt string contains escape char. Parse for arg. | |
c5aa993b JM |
1484 | Two consecutive escape chars followed by arg followed by |
1485 | a comma means to insert the arg using a default format. | |
1486 | Otherwise a printf format string may be included between | |
1487 | the two escape chars. eg: | |
1488 | %%foo, insert foo using default format | |
1489 | %2.2f%foo, insert foo using "%2.2f" format | |
1490 | A mismatch between the format string and the data type | |
1491 | of "foo" is an error (which we don't know how to protect | |
1492 | against). */ | |
9e0b60a8 JM |
1493 | |
1494 | fmt[0] = '\0'; /* assume null format string */ | |
1495 | if (promptp[1] == gdb_prompt_escape) /* double esc char */ | |
1496 | { | |
1497 | promptp += 2; /* skip past two escape chars. */ | |
1498 | } | |
1499 | else | |
1500 | { | |
1501 | /* extract format string from between two esc chars */ | |
1502 | i = 0; | |
c5aa993b JM |
1503 | do |
1504 | { | |
1505 | fmt[i++] = *promptp++; /* copy format string */ | |
1506 | } | |
1507 | while (i < sizeof (fmt) - 1 && | |
1508 | *promptp != gdb_prompt_escape && | |
1509 | *promptp != '\0'); | |
9e0b60a8 JM |
1510 | |
1511 | if (*promptp != gdb_prompt_escape) | |
1512 | error ("Syntax error at prompt position %d", | |
1513 | promptp - local_prompt); | |
1514 | else | |
1515 | { | |
1516 | promptp++; /* skip second escape char */ | |
1517 | fmt[i++] = '\0'; /* terminate the format string */ | |
1518 | } | |
1519 | } | |
1520 | ||
1521 | arg_val = parse_to_comma_and_eval (&promptp); | |
1522 | if (*promptp == ',') | |
c5aa993b | 1523 | promptp++; /* skip past the comma */ |
9e0b60a8 | 1524 | arg_type = check_typedef (VALUE_TYPE (arg_val)); |
c5aa993b | 1525 | switch (TYPE_CODE (arg_type)) |
9e0b60a8 JM |
1526 | { |
1527 | case TYPE_CODE_ARRAY: | |
1528 | elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type)); | |
c5aa993b | 1529 | if (TYPE_LENGTH (arg_type) > 0 && |
9e0b60a8 JM |
1530 | TYPE_LENGTH (elt_type) == 1 && |
1531 | TYPE_CODE (elt_type) == TYPE_CODE_INT) | |
1532 | { | |
1533 | int len = TYPE_LENGTH (arg_type); | |
1534 | ||
1535 | if (VALUE_LAZY (arg_val)) | |
1536 | value_fetch_lazy (arg_val); | |
1537 | tmp = VALUE_CONTENTS (arg_val); | |
1538 | ||
1539 | if (len > available) | |
c5aa993b | 1540 | len = available; /* overflow protect */ |
9e0b60a8 JM |
1541 | |
1542 | /* FIXME: how to protect GDB from crashing | |
c5aa993b | 1543 | from bad user-supplied format string? */ |
9e0b60a8 JM |
1544 | if (fmt[0] != 0) |
1545 | sprintf (outp, fmt, tmp); | |
1546 | else | |
1547 | strncpy (outp, tmp, len); | |
1548 | outp[len] = '\0'; | |
1549 | } | |
1550 | break; | |
1551 | case TYPE_CODE_PTR: | |
1552 | elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type)); | |
1553 | addrval = value_as_pointer (arg_val); | |
1554 | ||
1555 | if (TYPE_LENGTH (elt_type) == 1 && | |
c5aa993b | 1556 | TYPE_CODE (elt_type) == TYPE_CODE_INT && |
9e0b60a8 JM |
1557 | addrval != 0) |
1558 | { | |
1559 | /* display it as a string */ | |
1560 | char *default_fmt = "%s"; | |
1561 | char *tmp; | |
1562 | int err = 0; | |
1563 | ||
1564 | /* Limiting the number of bytes that the following call | |
c5aa993b JM |
1565 | will read protects us from sprintf overflow later. */ |
1566 | i = target_read_string (addrval, /* src */ | |
1567 | &tmp, /* dest */ | |
1568 | available, /* len */ | |
9e0b60a8 JM |
1569 | &err); |
1570 | if (err) /* read failed */ | |
1571 | error ("%s on target_read", safe_strerror (err)); | |
1572 | ||
1573 | tmp[i] = '\0'; /* force-terminate string */ | |
1574 | /* FIXME: how to protect GDB from crashing | |
c5aa993b JM |
1575 | from bad user-supplied format string? */ |
1576 | sprintf (outp, fmt[0] == 0 ? default_fmt : fmt, | |
9e0b60a8 | 1577 | tmp); |
b8c9b27d | 1578 | xfree (tmp); |
9e0b60a8 JM |
1579 | } |
1580 | else | |
1581 | { | |
1582 | /* display it as a pointer */ | |
1583 | char *default_fmt = "0x%x"; | |
1584 | ||
1585 | /* FIXME: how to protect GDB from crashing | |
c5aa993b JM |
1586 | from bad user-supplied format string? */ |
1587 | if (available >= 16 /*? */ ) /* overflow protect */ | |
9e0b60a8 JM |
1588 | sprintf (outp, fmt[0] == 0 ? default_fmt : fmt, |
1589 | (long) addrval); | |
1590 | } | |
1591 | break; | |
1592 | case TYPE_CODE_FLT: | |
1593 | { | |
1594 | char *default_fmt = "%g"; | |
1595 | ||
1596 | doubleval = value_as_double (arg_val); | |
1597 | /* FIXME: how to protect GDB from crashing | |
1598 | from bad user-supplied format string? */ | |
c5aa993b | 1599 | if (available >= 16 /*? */ ) /* overflow protect */ |
9e0b60a8 JM |
1600 | sprintf (outp, fmt[0] == 0 ? default_fmt : fmt, |
1601 | (double) doubleval); | |
1602 | break; | |
1603 | } | |
1604 | case TYPE_CODE_INT: | |
1605 | { | |
1606 | char *default_fmt = "%d"; | |
1607 | ||
1608 | longval = value_as_long (arg_val); | |
1609 | /* FIXME: how to protect GDB from crashing | |
1610 | from bad user-supplied format string? */ | |
c5aa993b | 1611 | if (available >= 16 /*? */ ) /* overflow protect */ |
9e0b60a8 JM |
1612 | sprintf (outp, fmt[0] == 0 ? default_fmt : fmt, |
1613 | (long) longval); | |
1614 | break; | |
1615 | } | |
1616 | case TYPE_CODE_BOOL: | |
1617 | { | |
1618 | /* no default format for bool */ | |
1619 | longval = value_as_long (arg_val); | |
c5aa993b | 1620 | if (available >= 8 /*? */ ) /* overflow protect */ |
9e0b60a8 JM |
1621 | { |
1622 | if (longval) | |
1623 | strcpy (outp, "<true>"); | |
1624 | else | |
1625 | strcpy (outp, "<false>"); | |
1626 | } | |
1627 | break; | |
1628 | } | |
1629 | case TYPE_CODE_ENUM: | |
1630 | { | |
1631 | /* no default format for enum */ | |
1632 | longval = value_as_long (arg_val); | |
1633 | len = TYPE_NFIELDS (arg_type); | |
1634 | /* find enum name if possible */ | |
1635 | for (i = 0; i < len; i++) | |
1636 | if (TYPE_FIELD_BITPOS (arg_type, i) == longval) | |
c5aa993b | 1637 | break; /* match -- end loop */ |
9e0b60a8 JM |
1638 | |
1639 | if (i < len) /* enum name found */ | |
1640 | { | |
1641 | char *name = TYPE_FIELD_NAME (arg_type, i); | |
1642 | ||
1643 | strncpy (outp, name, available); | |
1644 | /* in casel available < strlen (name), */ | |
1645 | outp[available] = '\0'; | |
1646 | } | |
1647 | else | |
1648 | { | |
c5aa993b | 1649 | if (available >= 16 /*? */ ) /* overflow protect */ |
d4f3574e | 1650 | sprintf (outp, "%ld", (long) longval); |
9e0b60a8 JM |
1651 | } |
1652 | break; | |
1653 | } | |
1654 | case TYPE_CODE_VOID: | |
1655 | *outp = '\0'; | |
1656 | break; /* void type -- no output */ | |
1657 | default: | |
1658 | error ("bad data type at prompt position %d", | |
1659 | promptp - local_prompt); | |
1660 | break; | |
1661 | } | |
1662 | outp += strlen (outp); | |
1663 | } | |
1664 | } | |
1665 | *outp++ = '\0'; /* terminate prompt string */ | |
1666 | return 1; | |
1667 | } | |
1668 | } | |
1669 | ||
1670 | char * | |
fba45db2 | 1671 | get_prompt (void) |
9e0b60a8 JM |
1672 | { |
1673 | static char buf[MAX_PROMPT_SIZE]; | |
1674 | ||
c5aa993b | 1675 | if (catch_errors (get_prompt_1, buf, "bad formatted prompt: ", |
9e0b60a8 JM |
1676 | RETURN_MASK_ALL)) |
1677 | { | |
c5aa993b | 1678 | return &buf[0]; /* successful formatted prompt */ |
9e0b60a8 JM |
1679 | } |
1680 | else | |
1681 | { | |
1682 | /* Prompt could not be formatted. */ | |
6426a772 | 1683 | if (event_loop_p) |
9e0b60a8 JM |
1684 | return PROMPT (0); |
1685 | else | |
1686 | return gdb_prompt_string; | |
1687 | } | |
1688 | } | |
1689 | ||
1690 | void | |
fba45db2 | 1691 | set_prompt (char *s) |
9e0b60a8 JM |
1692 | { |
1693 | /* ??rehrauer: I don't know why this fails, since it looks as though | |
1694 | assignments to prompt are wrapped in calls to savestring... | |
c5aa993b | 1695 | if (prompt != NULL) |
b8c9b27d | 1696 | xfree (prompt); |
c5aa993b | 1697 | */ |
6426a772 | 1698 | if (event_loop_p) |
9e0b60a8 JM |
1699 | PROMPT (0) = savestring (s, strlen (s)); |
1700 | else | |
1701 | gdb_prompt_string = savestring (s, strlen (s)); | |
1702 | } | |
9e0b60a8 | 1703 | \f |
c5aa993b | 1704 | |
9e0b60a8 JM |
1705 | /* If necessary, make the user confirm that we should quit. Return |
1706 | non-zero if we should quit, zero if we shouldn't. */ | |
1707 | ||
1708 | int | |
fba45db2 | 1709 | quit_confirm (void) |
9e0b60a8 JM |
1710 | { |
1711 | if (inferior_pid != 0 && target_has_execution) | |
1712 | { | |
1713 | char *s; | |
1714 | ||
1715 | /* This is something of a hack. But there's no reliable way to | |
c5aa993b JM |
1716 | see if a GUI is running. The `use_windows' variable doesn't |
1717 | cut it. */ | |
9e0b60a8 JM |
1718 | if (init_ui_hook) |
1719 | s = "A debugging session is active.\nDo you still want to close the debugger?"; | |
1720 | else if (attach_flag) | |
1721 | s = "The program is running. Quit anyway (and detach it)? "; | |
1722 | else | |
1723 | s = "The program is running. Exit anyway? "; | |
1724 | ||
c5aa993b | 1725 | if (!query (s)) |
9e0b60a8 JM |
1726 | return 0; |
1727 | } | |
1728 | ||
1729 | return 1; | |
1730 | } | |
1731 | ||
1732 | /* Quit without asking for confirmation. */ | |
1733 | ||
1734 | void | |
fba45db2 | 1735 | quit_force (char *args, int from_tty) |
9e0b60a8 JM |
1736 | { |
1737 | int exit_code = 0; | |
1738 | ||
1739 | /* An optional expression may be used to cause gdb to terminate with the | |
1740 | value of that expression. */ | |
1741 | if (args) | |
1742 | { | |
1743 | value_ptr val = parse_and_eval (args); | |
1744 | ||
1745 | exit_code = (int) value_as_long (val); | |
1746 | } | |
1747 | ||
1748 | if (inferior_pid != 0 && target_has_execution) | |
1749 | { | |
1750 | if (attach_flag) | |
1751 | target_detach (args, from_tty); | |
1752 | else | |
1753 | target_kill (); | |
1754 | } | |
1755 | ||
1756 | /* UDI wants this, to kill the TIP. */ | |
1757 | target_close (1); | |
1758 | ||
1759 | /* Save the history information if it is appropriate to do so. */ | |
1760 | if (write_history_p && history_filename) | |
1761 | write_history (history_filename); | |
1762 | ||
c5aa993b | 1763 | do_final_cleanups (ALL_CLEANUPS); /* Do any final cleanups before exiting */ |
9e0b60a8 JM |
1764 | |
1765 | #if defined(TUI) | |
1766 | /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */ | |
1767 | /* The above does not need to be inside a tuiDo(), since | |
1768 | * it is not manipulating the curses screen, but rather, | |
1769 | * it is tearing it down. | |
1770 | */ | |
1771 | if (tui_version) | |
c5aa993b | 1772 | tuiCleanUp (); |
9e0b60a8 JM |
1773 | #endif |
1774 | ||
1775 | exit (exit_code); | |
1776 | } | |
1777 | ||
9e0b60a8 JM |
1778 | /* Returns whether GDB is running on a terminal and whether the user |
1779 | desires that questions be asked of them on that terminal. */ | |
1780 | ||
1781 | int | |
fba45db2 | 1782 | input_from_terminal_p (void) |
9e0b60a8 JM |
1783 | { |
1784 | return gdb_has_a_terminal () && (instream == stdin) & caution; | |
1785 | } | |
1786 | \f | |
9e0b60a8 JM |
1787 | /* ARGSUSED */ |
1788 | static void | |
fba45db2 | 1789 | dont_repeat_command (char *ignored, int from_tty) |
9e0b60a8 | 1790 | { |
c5aa993b JM |
1791 | *line = 0; /* Can't call dont_repeat here because we're not |
1792 | necessarily reading from stdin. */ | |
9e0b60a8 JM |
1793 | } |
1794 | \f | |
1795 | /* Functions to manipulate command line editing control variables. */ | |
1796 | ||
1797 | /* Number of commands to print in each call to show_commands. */ | |
1798 | #define Hist_print 10 | |
d318976c | 1799 | void |
fba45db2 | 1800 | show_commands (char *args, int from_tty) |
9e0b60a8 JM |
1801 | { |
1802 | /* Index for history commands. Relative to history_base. */ | |
1803 | int offset; | |
1804 | ||
1805 | /* Number of the history entry which we are planning to display next. | |
1806 | Relative to history_base. */ | |
1807 | static int num = 0; | |
1808 | ||
1809 | /* The first command in the history which doesn't exist (i.e. one more | |
1810 | than the number of the last command). Relative to history_base. */ | |
1811 | int hist_len; | |
1812 | ||
a14ed312 | 1813 | extern HIST_ENTRY *history_get (int); |
9e0b60a8 JM |
1814 | |
1815 | /* Print out some of the commands from the command history. */ | |
1816 | /* First determine the length of the history list. */ | |
1817 | hist_len = history_size; | |
1818 | for (offset = 0; offset < history_size; offset++) | |
1819 | { | |
1820 | if (!history_get (history_base + offset)) | |
1821 | { | |
1822 | hist_len = offset; | |
1823 | break; | |
1824 | } | |
1825 | } | |
1826 | ||
1827 | if (args) | |
1828 | { | |
1829 | if (args[0] == '+' && args[1] == '\0') | |
1830 | /* "info editing +" should print from the stored position. */ | |
1831 | ; | |
1832 | else | |
1833 | /* "info editing <exp>" should print around command number <exp>. */ | |
0e828ed1 | 1834 | num = (parse_and_eval_long (args) - history_base) - Hist_print / 2; |
9e0b60a8 JM |
1835 | } |
1836 | /* "show commands" means print the last Hist_print commands. */ | |
1837 | else | |
1838 | { | |
1839 | num = hist_len - Hist_print; | |
1840 | } | |
1841 | ||
1842 | if (num < 0) | |
1843 | num = 0; | |
1844 | ||
1845 | /* If there are at least Hist_print commands, we want to display the last | |
1846 | Hist_print rather than, say, the last 6. */ | |
1847 | if (hist_len - num < Hist_print) | |
1848 | { | |
1849 | num = hist_len - Hist_print; | |
1850 | if (num < 0) | |
1851 | num = 0; | |
1852 | } | |
1853 | ||
1854 | for (offset = num; offset < num + Hist_print && offset < hist_len; offset++) | |
1855 | { | |
1856 | printf_filtered ("%5d %s\n", history_base + offset, | |
c5aa993b | 1857 | (history_get (history_base + offset))->line); |
9e0b60a8 JM |
1858 | } |
1859 | ||
1860 | /* The next command we want to display is the next one that we haven't | |
1861 | displayed yet. */ | |
1862 | num += Hist_print; | |
1863 | ||
1864 | /* If the user repeats this command with return, it should do what | |
1865 | "show commands +" does. This is unnecessary if arg is null, | |
1866 | because "show commands +" is not useful after "show commands". */ | |
1867 | if (from_tty && args) | |
1868 | { | |
1869 | args[0] = '+'; | |
1870 | args[1] = '\0'; | |
1871 | } | |
1872 | } | |
1873 | ||
1874 | /* Called by do_setshow_command. */ | |
1875 | /* ARGSUSED */ | |
1876 | static void | |
fba45db2 | 1877 | set_history_size_command (char *args, int from_tty, struct cmd_list_element *c) |
9e0b60a8 JM |
1878 | { |
1879 | if (history_size == INT_MAX) | |
1880 | unstifle_history (); | |
1881 | else if (history_size >= 0) | |
1882 | stifle_history (history_size); | |
1883 | else | |
1884 | { | |
1885 | history_size = INT_MAX; | |
1886 | error ("History size must be non-negative"); | |
1887 | } | |
1888 | } | |
1889 | ||
1890 | /* ARGSUSED */ | |
d318976c | 1891 | void |
fba45db2 | 1892 | set_history (char *args, int from_tty) |
9e0b60a8 JM |
1893 | { |
1894 | printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n"); | |
1895 | help_list (sethistlist, "set history ", -1, gdb_stdout); | |
1896 | } | |
1897 | ||
1898 | /* ARGSUSED */ | |
d318976c | 1899 | void |
fba45db2 | 1900 | show_history (char *args, int from_tty) |
9e0b60a8 JM |
1901 | { |
1902 | cmd_show_list (showhistlist, from_tty, ""); | |
1903 | } | |
1904 | ||
1905 | int info_verbose = 0; /* Default verbose msgs off */ | |
1906 | ||
1907 | /* Called by do_setshow_command. An elaborate joke. */ | |
1908 | /* ARGSUSED */ | |
d318976c | 1909 | void |
fba45db2 | 1910 | set_verbose (char *args, int from_tty, struct cmd_list_element *c) |
9e0b60a8 JM |
1911 | { |
1912 | char *cmdname = "verbose"; | |
1913 | struct cmd_list_element *showcmd; | |
1914 | ||
1915 | showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1); | |
1916 | ||
1917 | if (info_verbose) | |
1918 | { | |
1919 | c->doc = "Set verbose printing of informational messages."; | |
1920 | showcmd->doc = "Show verbose printing of informational messages."; | |
1921 | } | |
1922 | else | |
1923 | { | |
1924 | c->doc = "Set verbosity."; | |
1925 | showcmd->doc = "Show verbosity."; | |
1926 | } | |
1927 | } | |
1928 | ||
1929 | static void | |
fba45db2 | 1930 | float_handler (int signo) |
9e0b60a8 JM |
1931 | { |
1932 | /* This message is based on ANSI C, section 4.7. Note that integer | |
1933 | divide by zero causes this, so "float" is a misnomer. */ | |
1934 | signal (SIGFPE, float_handler); | |
1935 | error ("Erroneous arithmetic operation."); | |
1936 | } | |
5d161b24 | 1937 | |
9e0b60a8 JM |
1938 | /* Init the history buffer. Note that we are called after the init file(s) |
1939 | * have been read so that the user can change the history file via his | |
1940 | * .gdbinit file (for instance). The GDBHISTFILE environment variable | |
1941 | * overrides all of this. | |
1942 | */ | |
1943 | ||
1944 | void | |
fba45db2 | 1945 | init_history (void) |
9e0b60a8 JM |
1946 | { |
1947 | char *tmpenv; | |
1948 | ||
1949 | tmpenv = getenv ("HISTSIZE"); | |
1950 | if (tmpenv) | |
1951 | history_size = atoi (tmpenv); | |
1952 | else if (!history_size) | |
1953 | history_size = 256; | |
1954 | ||
1955 | stifle_history (history_size); | |
1956 | ||
1957 | tmpenv = getenv ("GDBHISTFILE"); | |
1958 | if (tmpenv) | |
c5aa993b JM |
1959 | history_filename = savestring (tmpenv, strlen (tmpenv)); |
1960 | else if (!history_filename) | |
1961 | { | |
1962 | /* We include the current directory so that if the user changes | |
1963 | directories the file written will be the same as the one | |
1964 | that was read. */ | |
a0b3c4fd | 1965 | #ifdef __MSDOS__ |
eb2f494a AC |
1966 | /* No leading dots in file names are allowed on MSDOS. */ |
1967 | history_filename = concat (current_directory, "/_gdb_history", NULL); | |
a0b3c4fd | 1968 | #else |
c5aa993b | 1969 | history_filename = concat (current_directory, "/.gdb_history", NULL); |
a0b3c4fd | 1970 | #endif |
c5aa993b | 1971 | } |
9e0b60a8 JM |
1972 | read_history (history_filename); |
1973 | } | |
1974 | ||
1975 | static void | |
fba45db2 | 1976 | init_main (void) |
9e0b60a8 JM |
1977 | { |
1978 | struct cmd_list_element *c; | |
1979 | ||
1980 | /* If we are running the asynchronous version, | |
1981 | we initialize the prompts differently. */ | |
6426a772 | 1982 | if (!event_loop_p) |
9e0b60a8 | 1983 | { |
c5aa993b | 1984 | gdb_prompt_string = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT)); |
9e0b60a8 JM |
1985 | } |
1986 | else | |
1987 | { | |
1988 | /* initialize the prompt stack to a simple "(gdb) " prompt or to | |
96baa820 | 1989 | whatever the DEFAULT_PROMPT is. */ |
9e0b60a8 | 1990 | the_prompts.top = 0; |
c5aa993b | 1991 | PREFIX (0) = ""; |
c5aa993b | 1992 | PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT)); |
c5aa993b | 1993 | SUFFIX (0) = ""; |
9e0b60a8 | 1994 | /* Set things up for annotation_level > 1, if the user ever decides |
c5aa993b | 1995 | to use it. */ |
9e0b60a8 JM |
1996 | async_annotation_suffix = "prompt"; |
1997 | /* Set the variable associated with the setshow prompt command. */ | |
1998 | new_async_prompt = savestring (PROMPT (0), strlen (PROMPT (0))); | |
1999 | } | |
2000 | gdb_prompt_escape = 0; /* default to none. */ | |
2001 | ||
2002 | /* Set the important stuff up for command editing. */ | |
2003 | command_editing_p = 1; | |
9e0b60a8 JM |
2004 | history_expansion_p = 0; |
2005 | write_history_p = 0; | |
2006 | ||
2007 | /* Setup important stuff for command line editing. */ | |
2008 | rl_completion_entry_function = (int (*)()) readline_line_completion_function; | |
d318976c FN |
2009 | rl_completer_word_break_characters = |
2010 | get_gdb_completer_word_break_characters (); | |
2011 | rl_completer_quote_characters = get_gdb_completer_quote_characters (); | |
9e0b60a8 JM |
2012 | rl_readline_name = "gdb"; |
2013 | ||
9e0b60a8 JM |
2014 | /* The set prompt command is different depending whether or not the |
2015 | async version is run. NOTE: this difference is going to | |
2016 | disappear as we make the event loop be the default engine of | |
2017 | gdb. */ | |
6426a772 | 2018 | if (!event_loop_p) |
9e0b60a8 JM |
2019 | { |
2020 | add_show_from_set | |
c5aa993b | 2021 | (add_set_cmd ("prompt", class_support, var_string, |
9e0b60a8 JM |
2022 | (char *) &gdb_prompt_string, "Set gdb's prompt", |
2023 | &setlist), | |
2024 | &showlist); | |
2025 | } | |
2026 | else | |
2027 | { | |
c5aa993b JM |
2028 | c = add_set_cmd ("prompt", class_support, var_string, |
2029 | (char *) &new_async_prompt, "Set gdb's prompt", | |
9e0b60a8 JM |
2030 | &setlist); |
2031 | add_show_from_set (c, &showlist); | |
2032 | c->function.sfunc = set_async_prompt; | |
2033 | } | |
2034 | ||
2035 | add_show_from_set | |
c5aa993b | 2036 | (add_set_cmd ("prompt-escape-char", class_support, var_zinteger, |
9e0b60a8 JM |
2037 | (char *) &gdb_prompt_escape, |
2038 | "Set escape character for formatting of gdb's prompt", | |
2039 | &setlist), | |
2040 | &showlist); | |
2041 | ||
9e0b60a8 JM |
2042 | add_com ("dont-repeat", class_support, dont_repeat_command, "Don't repeat this command.\n\ |
2043 | Primarily used inside of user-defined commands that should not be repeated when\n\ | |
2044 | hitting return."); | |
2045 | ||
9e0b60a8 JM |
2046 | /* The set editing command is different depending whether or not the |
2047 | async version is run. NOTE: this difference is going to disappear | |
2048 | as we make the event loop be the default engine of gdb. */ | |
6426a772 | 2049 | if (!event_loop_p) |
9e0b60a8 JM |
2050 | { |
2051 | add_show_from_set | |
c5aa993b | 2052 | (add_set_cmd ("editing", class_support, var_boolean, (char *) &command_editing_p, |
9e0b60a8 JM |
2053 | "Set editing of command lines as they are typed.\n\ |
2054 | Use \"on\" to enable the editing, and \"off\" to disable it.\n\ | |
2055 | Without an argument, command line editing is enabled. To edit, use\n\ | |
2056 | EMACS-like or VI-like commands like control-P or ESC.", &setlist), | |
2057 | &showlist); | |
2058 | } | |
2059 | else | |
2060 | { | |
c5aa993b | 2061 | c = add_set_cmd ("editing", class_support, var_boolean, (char *) &async_command_editing_p, |
9e0b60a8 JM |
2062 | "Set editing of command lines as they are typed.\n\ |
2063 | Use \"on\" to enable the editing, and \"off\" to disable it.\n\ | |
2064 | Without an argument, command line editing is enabled. To edit, use\n\ | |
2065 | EMACS-like or VI-like commands like control-P or ESC.", &setlist); | |
2066 | ||
2067 | add_show_from_set (c, &showlist); | |
2068 | c->function.sfunc = set_async_editing_command; | |
2069 | } | |
2070 | ||
9e0b60a8 | 2071 | add_show_from_set |
c5aa993b JM |
2072 | (add_set_cmd ("save", no_class, var_boolean, (char *) &write_history_p, |
2073 | "Set saving of the history record on exit.\n\ | |
9e0b60a8 JM |
2074 | Use \"on\" to enable the saving, and \"off\" to disable it.\n\ |
2075 | Without an argument, saving is enabled.", &sethistlist), | |
2076 | &showhistlist); | |
2077 | ||
c5aa993b | 2078 | c = add_set_cmd ("size", no_class, var_integer, (char *) &history_size, |
9e0b60a8 JM |
2079 | "Set the size of the command history, \n\ |
2080 | ie. the number of previous commands to keep a record of.", &sethistlist); | |
2081 | add_show_from_set (c, &showhistlist); | |
2082 | c->function.sfunc = set_history_size_command; | |
2083 | ||
7a1bd56a EZ |
2084 | c = add_set_cmd ("filename", no_class, var_filename, |
2085 | (char *) &history_filename, | |
2086 | "Set the filename in which to record the command history\n\ | |
2087 | (the list of previous commands of which a record is kept).", &sethistlist); | |
2088 | c->completer = filename_completer; | |
2089 | add_show_from_set (c, &showhistlist); | |
9e0b60a8 JM |
2090 | |
2091 | add_show_from_set | |
2092 | (add_set_cmd ("confirm", class_support, var_boolean, | |
c5aa993b | 2093 | (char *) &caution, |
9e0b60a8 JM |
2094 | "Set whether to confirm potentially dangerous operations.", |
2095 | &setlist), | |
2096 | &showlist); | |
2097 | ||
9e0b60a8 JM |
2098 | /* The set annotate command is different depending whether or not |
2099 | the async version is run. NOTE: this difference is going to | |
2100 | disappear as we make the event loop be the default engine of | |
2101 | gdb. */ | |
6426a772 | 2102 | if (!event_loop_p) |
9e0b60a8 | 2103 | { |
c5aa993b JM |
2104 | c = add_set_cmd ("annotate", class_obscure, var_zinteger, |
2105 | (char *) &annotation_level, "Set annotation_level.\n\ | |
9e0b60a8 JM |
2106 | 0 == normal; 1 == fullname (for use when running under emacs)\n\ |
2107 | 2 == output annotated suitably for use by programs that control GDB.", | |
2108 | &setlist); | |
2109 | c = add_show_from_set (c, &showlist); | |
2110 | } | |
2111 | else | |
2112 | { | |
c5aa993b JM |
2113 | c = add_set_cmd ("annotate", class_obscure, var_zinteger, |
2114 | (char *) &annotation_level, "Set annotation_level.\n\ | |
9e0b60a8 JM |
2115 | 0 == normal; 1 == fullname (for use when running under emacs)\n\ |
2116 | 2 == output annotated suitably for use by programs that control GDB.", | |
c5aa993b | 2117 | &setlist); |
9e0b60a8 JM |
2118 | add_show_from_set (c, &showlist); |
2119 | c->function.sfunc = set_async_annotation_level; | |
2120 | } | |
6426a772 | 2121 | if (event_loop_p) |
104c1213 JM |
2122 | { |
2123 | add_show_from_set | |
2124 | (add_set_cmd ("exec-done-display", class_support, var_boolean, (char *) &exec_done_display_p, | |
2125 | "Set notification of completion for asynchronous execution commands.\n\ | |
2126 | Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist), | |
2127 | &showlist); | |
2128 | } | |
9e0b60a8 | 2129 | } |