binutils-gdb/gdb/testsuite/gdb.python/py-breakpoint.c
Andrew Burgess 6b95f5ad96 gdb/python: allow for catchpoint type breakpoints in python
This commit adds initial support for catchpoints to the python
breakpoint API.

This commit adds a BP_CATCHPOINT constant which corresponds to
GDB's internal bp_catchpoint.  The new constant is documented in the
manual.

The user can't create breakpoints with type BP_CATCHPOINT after this
commit, but breakpoints that already exist, obtained with the
`gdb.breakpoints` function, can now have this type.  Additionally,
when a stop event is reported for hitting a catchpoint, GDB will now
report a BreakpointEvent with the attached breakpoint being of type
BP_CATCHPOINT - previously GDB would report a generic StopEvent in
this situation.

gdb/ChangeLog:

	* NEWS: Mention Python BP_CATCHPOINT feature.
	* python/py-breakpoint.c (pybp_codes): Add bp_catchpoint support.
	(bppy_init): Likewise.
	(gdbpy_breakpoint_created): Likewise.

gdb/doc/ChangeLog:

	* python.texinfo (Breakpoints In Python): Add BP_CATCHPOINT
	description.

gdb/testsuite/ChangeLog:

	* gdb.python/py-breakpoint.c (do_throw): New function.
	(main): Call do_throw.
	* gdb.python/py-breakpoint.exp (test_catchpoints): New proc.
2021-06-25 18:22:07 +01:00

74 lines
1.4 KiB
C

/* This testcase is part of GDB, the GNU debugger.
Copyright 2010-2021 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/>. */
#ifdef USE_PROBES
#include <sys/sdt.h>
#endif
int result = 0;
namespace foo_ns
{
int multiply (int i)
{
return i * i;
}
}
int multiply (int i)
{
return i * i;
}
int add (int i)
{
return i + i; /* Break at function add. */
}
void
do_throw ()
{
throw 123;
}
int main (int argc, char *argv[])
{
int foo = 5;
int bar = 42;
int i;
try
{
do_throw ();
}
catch (...)
{
/* Nothing. */
}
for (i = 0; i < 10; i++)
{
result += multiply (foo); /* Break at multiply. */
result += add (bar); /* Break at add. */
#ifdef USE_PROBES
DTRACE_PROBE1 (test, result_updated, result);
#endif
}
return 0; /* Break at end. */
}