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.
This commit is contained in:
Simon Marchi 2017-12-13 11:37:09 -05:00
parent 6892d2e4df
commit b89641bab5
10 changed files with 138 additions and 15 deletions

View file

@ -694,7 +694,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
{
static const char *keywords[] = { "spec", "type", "wp_class", "internal",
"temporary","source", "function",
"label", "line", NULL };
"label", "line", "qualified", NULL };
const char *spec = NULL;
enum bptype type = bp_breakpoint;
int access_type = hw_write;
@ -707,12 +707,14 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
char *label = NULL;
char *source = NULL;
char *function = NULL;
int qualified = 0;
if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssO", keywords,
if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOp", keywords,
&spec, &type, &access_type,
&internal,
&temporary, &source,
&function, &label, &lineobj))
&function, &label, &lineobj,
&qualified))
return -1;
@ -759,6 +761,10 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
case bp_breakpoint:
{
event_location_up location;
symbol_name_match_type func_name_match_type
= (qualified
? symbol_name_match_type::FULL
: symbol_name_match_type::WILD);
if (spec != NULL)
{
@ -767,7 +773,8 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
const char *copy = copy_holder.get ();
location = string_to_event_location (&copy,
current_language);
current_language,
func_name_match_type);
}
else
{
@ -782,6 +789,8 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
explicit_loc.line_offset =
linespec_parse_line_offset (line.get ());
explicit_loc.func_name_match_type = func_name_match_type;
location = new_explicit_location (&explicit_loc);
}