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