]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Have block_innermost_frame start from selected frame and document.
authorPaul N. Hilfinger <hilfinger@adacore.com>
Wed, 11 Jan 2012 10:34:21 +0000 (10:34 +0000)
committerPaul N. Hilfinger <hilfinger@adacore.com>
Wed, 11 Jan 2012 10:34:21 +0000 (10:34 +0000)
GDB used to search for the frame containing variables in a particular
lexical block starting from the current (top) frame, ignoring any
currently selected frame.  It is not clear why this is desirable for
variables that require a frame; why would a user deliberately select
one frame and then expect to see the value of a variable in a more
recent frame?  This change causes block_innermost_frame to start
looking from the selected frame, if there is one.  It may be
unnecessarily conservative: we use get_selected_frame_if_set rather
than get_selected_frame in order to avoid the side effect of calling
select_frame, which would probably be harmless.

Expression-parsing routines previously made the unwarranted assumption
that all block-qualified variables (written with the GDB extension
<block>::<variable>) are static.  As a result, they failed to update
innermost_block, which confused the watch commands about when
variables in watched expressions went out of scope, and also caused
the wrong variables to be watched.  This patch also modifies these
routines to treat all local variables the same whether or not they are
block-qualified.

Finally, we add a paragraph to the "Program Variables" section of the texinfo
documentation concerning the use of "::" for accessing non-static variables.

2012-01-11  Paul Hilfinger  <hilfingr@adacore.com>

* gdb/blockframe.c (block_innermost_frame): Start search from selected
frame, if present, or otherwise the current frame.

* gdb/c-exp.y (variable): Update innermost_block for
'block COLONCOLON NAME' clause.
* gdb/m2-exp.y (variable): Ditto.
* gdb/objc-exp.y (variable): Ditto.

* gdb/doc/gdb.texinfo (Variables): Document use of :: for non-static
variables.

gdb/ChangeLog
gdb/blockframe.c
gdb/c-exp.y
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/m2-exp.y
gdb/objc-exp.y

index 1ac251038b0daa0774ffd16b7a3fd4caa4a28ba4..29f2d1e652541cf459717d05405f4ca21a180dab 100644 (file)
@@ -1,3 +1,13 @@
+2012-01-11  Paul Hilfinger  <hilfingr@adacore.com>
+
+       * blockframe.c (block_innermost_frame): Start search from selected
+       frame, if present, or otherwise the current frame.
+
+       * c-exp.y (variable): Update innermost_block for
+       'block COLONCOLON NAME' clause.
+       * m2-exp.y (variable): Ditto.
+       * objc-exp.y (variable): Ditto.
+
 2012-01-10  Tom Tromey  <tromey@redhat.com>
 
        PR python/13199:
index 38973667cd2aab43d8671ce25fe66bc188f72e21..cb61cf30c5d0672bd843b077e1ce096eee20c9f6 100644 (file)
@@ -352,8 +352,9 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
   return find_pc_partial_function_gnu_ifunc (pc, name, address, endaddr, NULL);
 }
 
-/* Return the innermost stack frame executing inside of BLOCK, or NULL
-   if there is no such frame.  If BLOCK is NULL, just return NULL.  */
+/* Return the innermost stack frame that is executing inside of BLOCK and is
+   at least as old as the selected frame. Return NULL if there is no
+   such frame.  If BLOCK is NULL, just return NULL.  */
 
 struct frame_info *
 block_innermost_frame (const struct block *block)
@@ -368,7 +369,9 @@ block_innermost_frame (const struct block *block)
   start = BLOCK_START (block);
   end = BLOCK_END (block);
 
-  frame = get_current_frame ();
+  frame = get_selected_frame_if_set ();
+  if (frame == NULL)
+    frame = get_current_frame ();
   while (frame != NULL)
     {
       struct block *frame_block = get_frame_block (frame, NULL);
index 24a47616e275f965991177d494d4773dafbe00a4..bf4f4bc1a773bad3ca6b0861bd657c3fe78e2605 100644 (file)
@@ -778,6 +778,13 @@ variable:  block COLONCOLON name
                          if (sym == 0)
                            error (_("No symbol \"%s\" in specified context."),
                                   copy_name ($3));
+                         if (symbol_read_needs_frame (sym))
+                           {
+                             if (innermost_block == 0
+                                 || contained_in (block_found,
+                                                  innermost_block))
+                               innermost_block = block_found;
+                           }
 
                          write_exp_elt_opcode (OP_VAR_VALUE);
                          /* block_found is set by lookup_symbol.  */
index 5a9d2ff9dff21f5e8df4d33970ccbc2c076a4ffa..2914190f9fe959ddc9cd5db217e66c47cdb7e1c1 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-11  Paul Hilfinger  <hilfingr@adacore.com>
+
+       * gdb.texinfo (Variables): Document use of :: for non-static
+       variables.
+
 2012-01-05  Joel Brobecker  <brobecker@adacore.com>
 
        * gdbint.texinfo (Start of New Year Procedure): Update
index 2f4aa4f25f73bdd15556531c07bad13fe3f8efb5..4a8ff7b97b1af12a00ae584193b69a5ef8651b69 100644 (file)
@@ -7306,7 +7306,7 @@ scope is a single source file even if the current execution point is not
 in this file.  But it is possible to have more than one such variable or
 function with the same name (in different source files).  If that
 happens, referring to that name has unpredictable effects.  If you wish,
-you can specify a static variable in a particular function or file,
+you can specify a static variable in a particular function or file by
 using the colon-colon (@code{::}) notation:
 
 @cindex colon-colon, context for variables/functions
@@ -7329,8 +7329,49 @@ to print a global value of @code{x} defined in @file{f2.c}:
 (@value{GDBP}) p 'f2.c'::x
 @end smallexample
 
+The @code{::} notation is normally used for referring to
+static variables, since you typically disambiguate uses of local variables
+in functions by selecting the appropriate frame and using the
+simple name of the variable.  However, you may also use this notation
+to refer to local variables in frames enclosing the selected frame:
+
+@smallexample
+void
+foo (int a)
+@{
+  if (a < 10)
+    bar (a);
+  else
+    process (a);    /* Stop here */
+@}
+
+int
+bar (int a)
+@{
+  foo (a + 5);
+@}
+@end smallexample
+
+@noindent
+For example, if there is a breakpoint at the commented line,
+here is what you might see
+when the program stops after executing the call @code{bar(0)}:
+
+@smallexample
+(@value{GDBP}) p a
+$1 = 10
+(@value{GDBP}) p bar::a
+$2 = 5
+(@value{GDBP}) up 2
+#2  0x080483d0 in foo (a=5) at foobar.c:12
+(@value{GDBP}) p a
+$3 = 5
+(@value{GDBP}) p bar::a
+$4 = 0
+@end smallexample
+
 @cindex C@t{++} scope resolution
-This use of @samp{::} is very rarely in conflict with the very similar
+These uses of @samp{::} are very rarely in conflict with the very similar
 use of the same notation in C@t{++}.  @value{GDBN} also supports use of the C@t{++}
 scope resolution operator in @value{GDBN} expressions.
 @c FIXME: Um, so what happens in one of those rare cases where it's in
index 1e3e3cbcabc18dfd9c7b2d807c180ac4aeff1b63..ef9ec8e9eab708a318ff9011dfde0af58c8cb361 100644 (file)
@@ -588,6 +588,13 @@ variable:  block COLONCOLON NAME
                          if (sym == 0)
                            error (_("No symbol \"%s\" in specified context."),
                                   copy_name ($3));
+                         if (symbol_read_needs_frame (sym))
+                           {
+                             if (innermost_block == 0
+                                 || contained_in (block_found,
+                                                  innermost_block))
+                               innermost_block = block_found;
+                           }
 
                          write_exp_elt_opcode (OP_VAR_VALUE);
                          /* block_found is set by lookup_symbol.  */
index 346b404181d6bbd90698c8f64475cab34d6a90a8..b43ba666d9a2e61fd1bdb3e967c348fbc0ce4173 100644 (file)
@@ -648,6 +648,13 @@ variable:  block COLONCOLON name
                          if (sym == 0)
                            error (_("No symbol \"%s\" in specified context."),
                                   copy_name ($3));
+                         if (symbol_read_needs_frame (sym))
+                           {
+                             if (innermost_block == 0
+                                 || contained_in (block_found,
+                                                  innermost_block))
+                               innermost_block = block_found;
+                           }
 
                          write_exp_elt_opcode (OP_VAR_VALUE);
                          /* block_found is set by lookup_symbol.  */