diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2017-12-13 11:37:09 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2017-12-13 11:44:28 -0500 |
commit | b89641bab55496e52094282fabe146289c57b6d1 (patch) | |
tree | e11073cae0fca2b9f16b9d55625fec84cad1af66 /gdb/testsuite/gdb.python | |
parent | 6892d2e4df57160f7103fef0340ae3f55ac8b2b3 (diff) | |
download | binutils-b89641bab55496e52094282fabe146289c57b6d1.zip binutils-b89641bab55496e52094282fabe146289c57b6d1.tar.gz binutils-b89641bab55496e52094282fabe146289c57b6d1.tar.bz2 |
python: Add qualified parameter to gdb.Breakpoint
This patch adds the possibility to pass a qualified=True|False parameter
when creating a breakpoint in Python. It is equivalent to using
-qualified in a linespec. The parameter actually accepts any Python
value, and converts it to boolean using Python's standard rules for
that (https://docs.python.org/3/library/stdtypes.html#truth).
Unlike the -source/-line/-function/-label parameters, it is possible to
use -qualified with a "normal" (non-explicit) linespec. Therefore, it
is possible (unlike these other parameters) to use this new parameter
along with the spec parameter.
I updated the py-breakpoint.exp test. To be able to test multiple
locations using a namespace, I had to switch the test case to compile as
C++. If we really wanted to, we could run it as both C and C++, but
omit the C++-specific parts when running it as C.
gdb/ChangeLog:
* location.h (string_to_event_location): Add match_type
parameter.
* location.c (string_to_event_location): Likewise.
* python/py-breakpoint.c (bppy_init): Handle qualified
parameter.
gdb/doc/ChangeLog:
* python.texi (Manipulating breakpoints using Python): Document
qualified parameter to gdb.Breakpoint.
gdb/testsuite/ChangeLog:
* gdb.python/py-breakpoint.c (foo_ns::multiply): New function.
* gdb.python/py-breakpoint.exp: Compile the test case as c++,
call test_bkpt_qualified.
(test_bkpt_qualified): New proc.
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/py-breakpoint.c | 8 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-breakpoint.exp | 76 |
2 files changed, 83 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.c b/gdb/testsuite/gdb.python/py-breakpoint.c index 562cab3..c9f124c 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.c +++ b/gdb/testsuite/gdb.python/py-breakpoint.c @@ -17,6 +17,14 @@ int result = 0; +namespace foo_ns +{ + int multiply (int i) + { + return i * i; + } +} + int multiply (int i) { return i * i; diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index 699c98f..0509414 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -20,7 +20,9 @@ load_lib gdb-python.exp standard_testfile -if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { +set options {debug c++} + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} ${options}] } { return -1 } @@ -608,6 +610,77 @@ proc_with_prefix test_bkpt_explicit_loc {} { "set invalid explicit breakpoint by missing function" } +proc_with_prefix test_bkpt_qualified {} { + global decimal hex testfile + + # Start with a fresh gdb. + clean_restart ${testfile} + + set one_location_re "Breakpoint $decimal at $hex:.*line $decimal." + set two_location_re "Breakpoint $decimal at $hex:.*2 locations." + + if ![runto_main] then { + fail "cannot run to main." + return 0 + } + + # Test the default value of "qualified". + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(\"multiply\")" \ + $two_location_re \ + "qualified implicitly false" + + # Test qualified=False. + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(\"multiply\", qualified=False)" \ + $two_location_re \ + "qualified false" + + # Test qualified=True. + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(\"multiply\", qualified=True)" \ + $one_location_re \ + "qualified true" + + # Test qualified=True with an explicit function. + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(function=\"multiply\", qualified=True)" \ + $one_location_re \ + "qualified true and explicit" + + # Test qualified=False with an explicit function. + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(function=\"multiply\", qualified=False)" \ + $two_location_re \ + "qualified false and explicit" + + # Test -q in the spec string. + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(\"-q multiply\")" \ + $one_location_re \ + "-q in spec string" + + # Test -q in the spec string with explicit location. + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(\"-q -function multiply\")" \ + $one_location_re \ + "-q in spec string with explicit location" + + # Test -q in the spec string and qualified=False (-q should win). + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(\"-q multiply\", qualified=False)" \ + $one_location_re \ + "-q in spec string and qualified false" +} + test_bkpt_basic test_bkpt_deletion test_bkpt_cond_and_cmds @@ -620,3 +693,4 @@ test_bkpt_address test_bkpt_pending test_bkpt_events test_bkpt_explicit_loc +test_bkpt_qualified |