[PATCH 1/1] gdb, python: fix python breakpoint with extra spec

Christina Schimpe christina.schimpe@intel.com
Fri Jun 2 10:59:46 GMT 2023


From: Mihails Strasuns <mihails.strasuns@intel.com>

Python module `Breakpoint` constructor implementation is not
passing through any remaining spec tail after parsing location.

For example this works as expected:

(gdb) python bp1 = Breakpoint ("file:42")

But here "thread 1000" is silently ignored:

(gdb) python bp1 = Breakpoint ("file:42 thread 1000")

This patch modifies `create_breakpoint` function call from the Python
implementation so that full spec string is processed.  Unnecessary
string duplication for "spec" is removed as it is not used after the
call (tests still pass).
---
 gdb/python/py-breakpoint.c                 | 12 +++++-------
 gdb/testsuite/gdb.python/py-breakpoint.exp |  4 +++-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index d11fc64df20..3a2f8f5f2b8 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -893,6 +893,8 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   bppy_pending_object->number = -1;
   bppy_pending_object->bp = NULL;
 
+  spec = skip_spaces (spec);
+
   try
     {
       switch (type)
@@ -908,11 +910,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
 	    if (spec != NULL)
 	      {
-		gdb::unique_xmalloc_ptr<char>
-		  copy_holder (xstrdup (skip_spaces (spec)));
-		const char *copy = copy_holder.get ();
-
-		locspec  = string_to_location_spec (&copy,
+		locspec  = string_to_location_spec (&spec,
 						    current_language,
 						    func_name_match_type);
 	      }
@@ -941,8 +939,8 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	      = breakpoint_ops_for_location_spec (locspec.get (), false);
 
 	    create_breakpoint (gdbpy_enter::get_gdbarch (),
-			       locspec.get (), NULL, -1, NULL, false,
-			       0,
+			       locspec.get (), NULL, -1, spec, false,
+			       1,
 			       temporary_bp, type,
 			       0,
 			       AUTO_BOOLEAN_TRUE,
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 76094c95d10..3c747677fc7 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -170,8 +170,10 @@ proc_with_prefix test_bkpt_cond_and_cmds { } {
 
     # Test conditional setting.
     set bp_location1 [gdb_get_line_number "Break at multiply."]
-    gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" \
+    gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1 thread 1\")" \
 	"Set breakpoint" 0
+    gdb_test "python print (bp1.thread == 1)" "True" \
+	"Extra thread spec has been parsed"
     gdb_continue_to_breakpoint "Break at multiply" \
 	".*Break at multiply.*"
     gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" \
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928



More information about the Gdb-patches mailing list