backtrace changes current source location

Andrew Cagney cagney@gnu.org
Wed Oct 27 17:35:00 GMT 2004


Felix Lee wrote:
> patch for
>     http://sources.redhat.com/ml/gdb/2004-10/msg00414.html
> 
> gdb/ChangeLog
> 2004-10-26  Felix Lee  <felix+log1@specifixinc.com>
> 
>         * stack.c (backtrace_command_1): Backtrace shouldn't
>         change current source location.

Felix, can you find out where current_sal is being trashed?  GDB's 
trying to get away from all this global state - the code at that level 
shouldn't need to meddle with current_sal.

(Don't forget to consider the error case - if an error is thrown a 
restore would be lost)

> gdb/testsuite/ChangeLog
> 2004-10-26  Felix Lee  <felix+log1@specifixinc.com>
> 
>         * gdb.base/break.exp: Add test for line number after
>         backtrace.

Thanks for remembering this.  However, as a separate test, it should be 
in a separate file.

Andrew

> Index: gdb/stack.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/stack.c,v
> retrieving revision 1.112
> diff -u -p -r1.112 stack.c
> --- gdb/stack.c	3 Aug 2004 00:57:26 -0000	1.112
> +++ gdb/stack.c	26 Oct 2004 14:59:06 -0000
> @@ -1170,8 +1170,13 @@ backtrace_command_1 (char *count_exp, in
>         fi && count--;
>         i++, fi = get_prev_frame (fi))
>      {
> +      struct symtab_and_line savesal;
>        QUIT;
>  
> +      /* print_frame_info changes the current sal, which is not
> +         useful behavior when user asks for a backtrace. */
> +      savesal = get_current_source_symtab_and_line ();
> +
>        /* Don't use print_stack_frame; if an error() occurs it probably
>           means further attempts to backtrace would fail (on the other
>           hand, perhaps the code does or could be fixed to make sure
> @@ -1179,6 +1184,8 @@ backtrace_command_1 (char *count_exp, in
>        print_frame_info (fi, 1, LOCATION, 1);
>        if (show_locals)
>  	print_frame_local_vars (fi, 1, gdb_stdout);
> +
> +      set_current_source_symtab_and_line (&savesal);
>      }
>  
>    /* If we've stopped before the end, mention that.  */
> Index: gdb/testsuite/gdb.base/break.exp
> ===================================================================
> RCS file: /cvs/src/src/gdb/testsuite/gdb.base/break.exp,v
> retrieving revision 1.19
> diff -u -p -r1.19 break.exp
> --- gdb/testsuite/gdb.base/break.exp	9 Dec 2003 18:19:20 -0000	1.19
> +++ gdb/testsuite/gdb.base/break.exp	26 Oct 2004 14:59:06 -0000
> @@ -238,6 +238,21 @@ for {set i 6} {$i >= 1} {incr i -1} {
>  			"run until file:function($i) breakpoint"
>  }
>  
> +# make sure backtrace doesn't change current source location.
> +
> +gdb_test "set listsize 1" \
> +    ".*" \
> +    "set listsize 1"
> +gdb_test "list $bp_location7" \
> +    ".*" \
> +    "list before backtrace"
> +gdb_test "backtrace" \
> +    "\#0  factorial .*" \
> +    "backtrace at breakpoint"
> +gdb_test "list -1" \
> +    "$bp_location7\[\t ].*" \
> +    "list after backtrace"
> +
>  #
>  # Run until the breakpoint set at a quoted function
>  #
> 



More information about the Gdb-patches mailing list