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