diff options
author | Don Breazeal <donb@codesourcery.com> | 2016-03-15 15:18:28 -0700 |
---|---|---|
committer | Don Breazeal <donb@codesourcery.com> | 2016-03-15 15:25:15 -0700 |
commit | 1cafadb4e4eb329dea01355c6632b3077113d80c (patch) | |
tree | 2aa982ab01ff1f0649de210f67bdada496a42e0a /gdb/testsuite/gdb.cp | |
parent | 79427bd2f8edb59110f16a9c1652e3d6e41e08e7 (diff) | |
download | gdb-1cafadb4e4eb329dea01355c6632b3077113d80c.zip gdb-1cafadb4e4eb329dea01355c6632b3077113d80c.tar.gz gdb-1cafadb4e4eb329dea01355c6632b3077113d80c.tar.bz2 |
PR 18303, Tolerate malformed input for lookup_symbol-called functions
lookup_symbol is often called with user input. Consequently, any
function called from lookup_symbol{,_in_language} should attempt to
deal with malformed input gracefully. After all, malformed user
input is not a programming/API error.
This patch does not attempt to find/correct all instances of this. It
only fixes locations in the code that trigger test suite failures.
This patch fixes PR breakpoints/18303, "Assertion: -breakpoint-insert
with windows paths of file in non-current directory".
The patch includes three new tests related to this. One is just
gdb.linespec/ls-errs.exp copied and converted to use C++ instead of C, and
to add a case using a file name containing a Windows-style logical drive
specifier. The others include an MI test to provide a regression test for
the specific case reported in PR 18303, and a C++ test for proper error
handling of access to a program variable when using a file scope specifier
that refers to a non-existent file.
Tested on x86_64 native Linux.
gdb/ChangeLog
2016-01-28 Keith Seitz <keiths@redhat.com>
PR breakpoints/18303
* cp-namespace.c (cp_lookup_bare_symbol): Change assertion to
look for "::" instead of simply ":".
(cp_search_static_and_baseclasses): Return null_block_symbol for
malformed input.
Remove assertions.
* cp-support.c (cp_find_first_component_aux): Do not return
a prefix length for ':' unless the next character is also ':'.
gdb/testsuite/ChangeLog
2016-01-28 Don Breazeal <donb@codesourcery.com>
* gdb.cp/scope-err.cc: New test program.
* gdb.cp/scope-err.exp: New test script.
* gdb.linespec/ls-errs.c (myfunction): Expanded to have multiple
lines and "set breakpoint here" comment.
* gdb.linespec/ls-errs.exp: Added C++ testing and new test case.
Fixed some whitespace and format issues.
* gdb.mi/mi-linespec-err-cp.cc: New test program.
* gdb.mi/mi-linespec-err-cp.exp: New test script.
Diffstat (limited to 'gdb/testsuite/gdb.cp')
-rw-r--r-- | gdb/testsuite/gdb.cp/scope-err.cc | 35 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/scope-err.exp | 49 |
2 files changed, 84 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/scope-err.cc b/gdb/testsuite/gdb.cp/scope-err.cc new file mode 100644 index 0000000..19c92d8 --- /dev/null +++ b/gdb/testsuite/gdb.cp/scope-err.cc @@ -0,0 +1,35 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2016 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +int +myfunction (int aa) +{ + int i; + + i = aa + 42; + return i; /* set breakpoint here */ +} + +int +main (void) +{ + int a; + + a = myfunction (a); + + return a; +} diff --git a/gdb/testsuite/gdb.cp/scope-err.exp b/gdb/testsuite/gdb.cp/scope-err.exp new file mode 100644 index 0000000..b197829 --- /dev/null +++ b/gdb/testsuite/gdb.cp/scope-err.exp @@ -0,0 +1,49 @@ +# Copyright 2012-2016 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Tests for linespec errors with C++. +# Derived from gdb.linespec/ls-errs.exp. + +if {[skip_cplus_tests]} { + continue +} + +standard_testfile .cc +set exefile $testfile + +if {[prepare_for_testing $testfile $exefile $srcfile {debug c++}]} { + return -1 +} + +if {![runto_main]} { + fail "Can't run to main" + return 0 +} + +# Run to a location in the file. +set bp_location [gdb_get_line_number "set breakpoint here"] + +gdb_test "break $srcfile:$bp_location" \ + "Breakpoint.*at.* file .*$srcfile, line $bp_location\\." \ + "breakpoint line number in file" + +gdb_continue_to_breakpoint "$bp_location" + +# Try to access a variable using scope that is a non-existent filename +# with a Windows-style logical drive in the name. +set nonexistent_file C:/does/not/exist.cc +gdb_test "print '$nonexistent_file'::var" \ + ".*No symbol \"$nonexistent_file\" in current context.*" \ + "print var from \"$nonexistent_file\"" |