aboutsummaryrefslogtreecommitdiff
path: root/gdb/doc
diff options
context:
space:
mode:
authorPaul N. Hilfinger <hilfinger@adacore.com>2012-01-11 10:34:21 +0000
committerPaul N. Hilfinger <hilfinger@adacore.com>2012-01-11 10:34:21 +0000
commit72384ba31a5433c15d67313b339556239bf0c316 (patch)
tree7b5ce42824c1fc1291e41a6d510c8f546180481d /gdb/doc
parent794e51c094034378e14eec48b628957e71887265 (diff)
downloadgdb-72384ba31a5433c15d67313b339556239bf0c316.zip
gdb-72384ba31a5433c15d67313b339556239bf0c316.tar.gz
gdb-72384ba31a5433c15d67313b339556239bf0c316.tar.bz2
Have block_innermost_frame start from selected frame and document.
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.
Diffstat (limited to 'gdb/doc')
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo45
2 files changed, 48 insertions, 2 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 5a9d2ff..2914190 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -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
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 2f4aa4f..4a8ff7b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -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