diff options
author | Bruno Larsen <blarsen@redhat.com> | 2022-10-19 16:57:44 +0200 |
---|---|---|
committer | Bruno Larsen <blarsen@redhat.com> | 2022-12-21 16:26:44 +0100 |
commit | 68ce1575fc902958a9b1d197e2c79ea842a7776d (patch) | |
tree | b933242e4ad2faacb3df1245e241602356bfe69f /gdb/testsuite/gdb.cp | |
parent | ea6ed58e630eb1ae94116e0100831109bff994b7 (diff) | |
download | fsf-binutils-gdb-68ce1575fc902958a9b1d197e2c79ea842a7776d.zip fsf-binutils-gdb-68ce1575fc902958a9b1d197e2c79ea842a7776d.tar.gz fsf-binutils-gdb-68ce1575fc902958a9b1d197e2c79ea842a7776d.tar.bz2 |
gdb/c++: validate 'using' directives based on the current line
When asking GDB to print a variable from an imported namespace, we only
want to see variables imported in lines that the inferior has already
gone through, as is being tested last in gdb.cp/nsusing.exp. However
with the proposed change to gdb.cp/nsusing.exp, we get the following
failures:
(gdb) PASS: gdb.cp/nsusing.exp: continue to breakpoint: marker10 stop
print x
$9 = 911
(gdb) FAIL: gdb.cp/nsusing.exp: print x, before using statement
next
15 y += x;
(gdb) PASS: gdb.cp/nsusing.exp: using namespace M
print x
$10 = 911
(gdb) PASS: gdb.cp/nsusing.exp: print x, only using M
Showing that the feature wasn't functioning properly, it just so
happened that gcc ordered the namespaces in a convenient way.
This happens because GDB doesn't take into account the line where the
"using namespace" directive is written. So long as it shows up in the
current scope, we assume it is valid.
To fix this, add a new member to struct using_direct, that stores the
line where the directive was written, and a new function that informs if
the using directive is valid already.
Unfortunately, due to a GCC bug, the failure still shows up. Compilers
that set the declaration line of the using directive correctly (such as
Clang) do not show such a bug, so the test includes an XFAIL for gcc
code.
Finally, because the final test of gdb.cp/nsusing.exp has turned into
multiple that all would need XFAILs for older GCCs (<= 4.3), and that
GCC is very old, if it is detected, the test just exits early.
Approved-by: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite/gdb.cp')
-rw-r--r-- | gdb/testsuite/gdb.cp/nsusing.cc | 3 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/nsusing.exp | 16 |
2 files changed, 15 insertions, 4 deletions
diff --git a/gdb/testsuite/gdb.cp/nsusing.cc b/gdb/testsuite/gdb.cp/nsusing.cc index fa5c9d0..dcf0ba9 100644 --- a/gdb/testsuite/gdb.cp/nsusing.cc +++ b/gdb/testsuite/gdb.cp/nsusing.cc @@ -10,8 +10,9 @@ namespace N int marker10 () { + int y = 1; // marker10 stop using namespace M; - int y = x + 1; // marker10 stop + y += x; using namespace N; return y; } diff --git a/gdb/testsuite/gdb.cp/nsusing.exp b/gdb/testsuite/gdb.cp/nsusing.exp index 18bb282..0d374e5 100644 --- a/gdb/testsuite/gdb.cp/nsusing.exp +++ b/gdb/testsuite/gdb.cp/nsusing.exp @@ -119,8 +119,18 @@ gdb_continue_to_breakpoint "marker10 stop" if { [test_compiler_info {gcc-[0-3]-*}] || [test_compiler_info {gcc-4-[0-3]-*}]} { - setup_xfail *-*-* + return } -# Assert that M::x is printed and not N::x -gdb_test "print x" "= 911" "print x (from M::x)" +gdb_test_multiple "print x" "print x, before using statement" { + -re -wrap "No symbol .x. in current context.*" { + pass $gdb_test_name + } + -re -wrap "= 911.*" { + # GCC doesn't properly set the decl_line for namespaces, so GDB believes + # that the "using namespace M" line has already passed at this point. + xfail $gdb_test_name + } +} +gdb_test "next" ".*" "using namespace M" +gdb_test "print x" "= 911" "print x, only using M" |