From 25d29d7093f2abd7f7eec5fd9564ad0276489222 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Sat, 9 Aug 2003 15:10:09 +0000 Subject: [PATCH] 2003-08-09 Andrew Cagney Fix GDB PR cli/926. * cli/cli-decode.c (add_setshow_uinteger_cmd): New function. * command.h (add_setshow_uinteger_cmd): Declare. * frame.c (set_backtrace_cmd): New function. (show_backtrace_cmd): New function. * frame.c (_initialize_frame): Replace "set/show backtrace-below-main" with "set/show backtrace past-main". Add command "set/show backtrace limit". (backtrace_past_main): Rename "backtrace_below_main". (backtrace_limit): New variable. (get_prev_frame): Update. Check the backtrace_limit. 2003-08-09 Andrew Cagney * gdb.texinfo (Backtrace): Replace "set/show backtrace-below-main" with "set/show backtrace past-main" and "set/show backtrace limit". Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.174 diff -u -r1.174 gdb.texinfo --- doc/gdb.texinfo 8 Aug 2003 01:58:00 -0000 1.174 +++ doc/gdb.texinfo 9 Aug 2003 14:57:10 -0000 @@ -3922,27 +3922,40 @@ value, indicating that your program has stopped at the beginning of the code for line @code{993} of @code{builtin.c}. -@kindex set backtrace-below-main -@kindex show backtrace-below-main +@kindex set backtrace past-main +@kindex show backtrace past-main +@kindex set backtrace limit +@kindex show backtrace limit -Most programs have a standard entry point---a place where system libraries -and startup code transition into user code. For C this is @code{main}. -When @value{GDBN} finds the entry function in a backtrace it will terminate -the backtrace, to avoid tracing into highly system-specific (and generally -uninteresting) code. If you need to examine the startup code, then you can -change this behavior. +Most programs have a standard user entry point---a place where system +libraries and startup code transition into user code. For C this is +@code{main}. When @value{GDBN} finds the entry function in a backtrace +it will terminate the backtrace, to avoid tracing into highly +system-specific (and generally uninteresting) code. + +If you need to examine the startup code, or limit the number of levels +in a backtrace, you can change this behavior: @table @code -@item set backtrace-below-main off +@item set backtrace past-main +@itemx set backtrace past-main on +Backtraces will continue past the user entry point. + +@item set backtrace past-main off Backtraces will stop when they encounter the user entry point. This is the default. -@item set backtrace-below-main -@itemx set backtrace-below-main on -Backtraces will continue past the user entry point to the top of the stack. +@item show backtrace past-main +Display the current user entry point backtrace policy. + +@item set backtrace limit @var{n} +@itemx set backtrace limit 0 +@cindex backtrace limit +Limit the backtrace to @var{n} levels. A value of zero means +unlimited. -@item show backtrace-below-main -Display the current backtrace policy. +@item show backtrace limit +Display the current limit on backtrace levels. @end table @node Selection --- gdb/ChangeLog | 14 +++++++++++ gdb/cli/cli-decode.c | 20 ++++++++++++++++ gdb/command.h | 10 ++++++++ gdb/doc/ChangeLog | 6 +++++ gdb/doc/gdb.texinfo | 41 ++++++++++++++++++++----------- gdb/frame.c | 57 ++++++++++++++++++++++++++++++++++++-------- 6 files changed, 124 insertions(+), 24 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b91d9a2047..59a57390d5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2003-08-09 Andrew Cagney + + Fix GDB PR cli/926. + * cli/cli-decode.c (add_setshow_uinteger_cmd): New function. + * command.h (add_setshow_uinteger_cmd): Declare. + * frame.c (set_backtrace_cmd): New function. + (show_backtrace_cmd): New function. + * frame.c (_initialize_frame): Replace "set/show + backtrace-below-main" with "set/show backtrace past-main". Add + command "set/show backtrace limit". + (backtrace_past_main): Rename "backtrace_below_main". + (backtrace_limit): New variable. + (get_prev_frame): Update. Check the backtrace_limit. + 2003-08-09 Andrew Cagney * defs.h (xstrprintf): Declare. diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index be516c9a6f..8a0d057257 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -448,6 +448,26 @@ add_setshow_boolean_cmd (char *name, c->enums = boolean_enums; } +/* Add element named NAME to both the set and show command LISTs (the + list for set/show or some sublist thereof). CLASS is as in + add_cmd. VAR is address of the variable which will contain the + value. SET_DOC and SHOW_DOR are the documentation strings. */ +void +add_setshow_uinteger_cmd (char *name, + enum command_class class, + unsigned int *var, char *set_doc, char *show_doc, + cmd_sfunc_ftype *set_func, + cmd_sfunc_ftype *show_func, + struct cmd_list_element **set_list, + struct cmd_list_element **show_list) +{ + add_setshow_cmd_full (name, class, var_uinteger, var, + set_doc, show_doc, + set_func, show_func, + set_list, show_list, + NULL, NULL); +} + /* Where SETCMD has already been added, add the corresponding show command to LIST and return a pointer to the added command (not necessarily the head of LIST). */ diff --git a/gdb/command.h b/gdb/command.h index 96c99abcab..9cadd63d24 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -262,6 +262,16 @@ extern void add_setshow_boolean_cmd (char *name, struct cmd_list_element **set_list, struct cmd_list_element **show_list); +extern void add_setshow_uinteger_cmd (char *name, + enum command_class class, + unsigned int *var, + char *set_doc, + char *show_doc, + cmd_sfunc_ftype *set_func, + cmd_sfunc_ftype *show_func, + struct cmd_list_element **set_list, + struct cmd_list_element **show_list); + extern struct cmd_list_element *add_show_from_set (struct cmd_list_element *, struct cmd_list_element **); diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 14e3887b5a..1c53074cbd 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,9 @@ +2003-08-09 Andrew Cagney + + * gdb.texinfo (Backtrace): Replace "set/show backtrace-below-main" + with "set/show backtrace past-main" and "set/show backtrace + limit". + 2003-08-08 H.J. Lu * Makefile.in (install-info): Support DESTDIR. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index ae10478b48..cf69fd3e74 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -3922,27 +3922,40 @@ The display for frame zero does not begin with a program counter value, indicating that your program has stopped at the beginning of the code for line @code{993} of @code{builtin.c}. -@kindex set backtrace-below-main -@kindex show backtrace-below-main +@kindex set backtrace past-main +@kindex show backtrace past-main +@kindex set backtrace limit +@kindex show backtrace limit -Most programs have a standard entry point---a place where system libraries -and startup code transition into user code. For C this is @code{main}. -When @value{GDBN} finds the entry function in a backtrace it will terminate -the backtrace, to avoid tracing into highly system-specific (and generally -uninteresting) code. If you need to examine the startup code, then you can -change this behavior. +Most programs have a standard user entry point---a place where system +libraries and startup code transition into user code. For C this is +@code{main}. When @value{GDBN} finds the entry function in a backtrace +it will terminate the backtrace, to avoid tracing into highly +system-specific (and generally uninteresting) code. + +If you need to examine the startup code, or limit the number of levels +in a backtrace, you can change this behavior: @table @code -@item set backtrace-below-main off +@item set backtrace past-main +@itemx set backtrace past-main on +Backtraces will continue past the user entry point. + +@item set backtrace past-main off Backtraces will stop when they encounter the user entry point. This is the default. -@item set backtrace-below-main -@itemx set backtrace-below-main on -Backtraces will continue past the user entry point to the top of the stack. +@item show backtrace past-main +Display the current user entry point backtrace policy. -@item show backtrace-below-main -Display the current backtrace policy. +@item set backtrace limit @var{n} +@itemx set backtrace limit 0 +@cindex backtrace limit +Limit the backtrace to @var{n} levels. A value of zero means +unlimited. + +@item show backtrace limit +Display the current limit on backtrace levels. @end table @node Selection diff --git a/gdb/frame.c b/gdb/frame.c index 2b54ed78d5..b3861963f6 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -135,9 +135,11 @@ struct frame_info static int frame_debug; -/* Flag to indicate whether backtraces should stop at main. */ +/* Flag to indicate whether backtraces should stop at main et.al. */ + +static int backtrace_past_main; +static unsigned int backtrace_limit = UINT_MAX; -static int backtrace_below_main; void fprint_frame_id (struct ui_file *file, struct frame_id id) @@ -1802,7 +1804,7 @@ get_prev_frame (struct frame_info *this_frame) gdb_assert (this_frame != NULL); if (this_frame->level >= 0 - && !backtrace_below_main + && !backtrace_past_main && inside_main_func (get_frame_pc (this_frame))) /* Don't unwind past main(), bug always unwind the sentinel frame. Note, this is done _before_ the frame has been marked as @@ -1814,6 +1816,11 @@ get_prev_frame (struct frame_info *this_frame) return NULL; } + if (this_frame->level > backtrace_limit) + { + error ("Backtrace limit of %d exceeded", backtrace_limit); + } + /* If we're already inside the entry function for the main objfile, then it isn't valid. Don't apply this test to a dummy frame - dummy frame PC's typically land in the entry func. Don't apply @@ -2370,18 +2377,39 @@ legacy_frame_p (struct gdbarch *current_gdbarch) extern initialize_file_ftype _initialize_frame; /* -Wmissing-prototypes */ +static struct cmd_list_element *set_backtrace_cmdlist; +static struct cmd_list_element *show_backtrace_cmdlist; + +static void +set_backtrace_cmd (char *args, int from_tty) +{ + help_list (set_backtrace_cmdlist, "set backtrace ", -1, gdb_stdout); +} + +static void +show_backtrace_cmd (char *args, int from_tty) +{ + cmd_show_list (show_backtrace_cmdlist, from_tty, ""); +} + void _initialize_frame (void) { obstack_init (&frame_cache_obstack); - /* FIXME: cagney/2003-01-19: This command needs a rename. Suggest - `set backtrace {past,beyond,...}-main'. Also suggest adding `set - backtrace ...-start' to control backtraces past start. The - problem with `below' is that it stops the `up' command. */ + add_prefix_cmd ("backtrace", class_maintenance, set_backtrace_cmd, "\ +Set backtrace specific variables.\n\ +Configure backtrace variables such as the backtrace limit", + &set_backtrace_cmdlist, "set backtrace ", + 0/*allow-unknown*/, &setlist); + add_prefix_cmd ("backtrace", class_maintenance, show_backtrace_cmd, "\ +Show backtrace specific variables\n\ +Show backtrace variables such as the backtrace limit", + &show_backtrace_cmdlist, "show backtrace ", + 0/*allow-unknown*/, &showlist); - add_setshow_boolean_cmd ("backtrace-below-main", class_obscure, - &backtrace_below_main, "\ + add_setshow_boolean_cmd ("past-main", class_obscure, + &backtrace_past_main, "\ Set whether backtraces should continue past \"main\".\n\ Normally the caller of \"main\" is not of interest, so GDB will terminate\n\ the backtrace at \"main\". Set this variable if you need to see the rest\n\ @@ -2390,8 +2418,17 @@ Show whether backtraces should continue past \"main\".\n\ Normally the caller of \"main\" is not of interest, so GDB will terminate\n\ the backtrace at \"main\". Set this variable if you need to see the rest\n\ of the stack trace.", - NULL, NULL, &setlist, &showlist); + NULL, NULL, &set_backtrace_cmdlist, + &show_backtrace_cmdlist); + add_setshow_uinteger_cmd ("limit", class_obscure, + &backtrace_limit, "\ +Set an upper bound on the number of backtrace levels.\n\ +No more than the specified number of frames can be displayed or examined.\n +Zero is unlimited.", "\ +Show the upper bound on the number of backtrace levels.", + NULL, NULL, &set_backtrace_cmdlist, + &show_backtrace_cmdlist); /* Debug this files internals. */ add_show_from_set (add_set_cmd ("frame", class_maintenance, var_zinteger,