python/19506 -- gdb.Breakpoint address location regression
authorKeith Seitz <keiths@redhat.com>
Tue, 9 Feb 2016 18:02:53 +0000 (10:02 -0800)
committerKeith Seitz <keiths@redhat.com>
Tue, 9 Feb 2016 22:27:50 +0000 (14:27 -0800)
Now that "legacy" linespecs benefit from consolidated support in
string_to_event_location_basic, python's Breakpoint command should use this
function to turn strings into event locations.

As a result, this patch fixes python/19506. Before:

(gdb) python gdb.Breakpoint("*main")
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: Function "*main" not defined.
Error while executing Python code.

After:

(gdb) python gdb.Breakpoint("*main")
Breakpoint 1 at 0x4005fb: file ../../../src/gdb/testsuite/gdb.python/py-breakpoint.c, line 32.

gdb/ChangeLog

PR python/19506
* python/py-breakpoint.c (bppy_init): Use
string_to_event_location_basic instead of new_linespec_location.

gdb/testsuite/ChangeLog

PR python/19506
* gdb.python/py-breakpoint.exp (test_bkpt_address): New procedure.
(toplevel): Call test_bkpt_address.

gdb/ChangeLog
gdb/python/py-breakpoint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-breakpoint.exp

index 1077d605bbba5422dc193b56e174573ec1a1fb8c..64fc796668272fa9ac04a739435477447b47db74 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-09  Keith Seitz  <keiths@redhat.com>
+
+       PR python/19506
+       * python/py-breakpoint.c (bppy_init): Use
+       string_to_event_location_basic instead of new_linespec_location.
+
 2016-02-09  Keith Seitz  <keiths@redhat.com>
 
        * location.c (string_to_explicit_location): Note that "-p" is
index 85b17d5aa5fba972fcbff828d241088529045dc1..964ec6204fe8fba8181fc5bbd290d09342a591a4 100644 (file)
@@ -663,7 +663,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
   TRY
     {
-      char *copy = xstrdup (spec);
+      char *copy = xstrdup (skip_spaces_const (spec));
       struct cleanup *cleanup = make_cleanup (xfree, copy);
 
       switch (type)
@@ -672,7 +672,8 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
          {
            struct event_location *location;
 
-           location = new_linespec_location (&copy);
+           location
+             = string_to_event_location_basic (&copy, current_language);
            make_cleanup_delete_event_location (location);
            create_breakpoint (python_gdbarch,
                               location, NULL, -1, NULL,
index 68b4e4298362d06b08d244cbedec7a9402b67c63..38f1fc5e8e3c00aae94be4a47288cb08a7eebf1b 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-09  Keith Seitz  <keiths@redhat.com>
+
+       PR python/19506
+       * gdb.python/py-breakpoint.exp (test_bkpt_address): New procedure.
+       (toplevel): Call test_bkpt_address.
+
 2016-02-09  Simon Marchi  <simon.marchi@ericsson.com>
 
        * configure.ac: Use AC_CONFIG_FILES instead of passing arguments
index af6c5fce3b00a2a59f7cd4854582480b36f3bfec..d1d1b2253f93a35c8eecf408923272a7ad81b5a2 100644 (file)
@@ -462,6 +462,38 @@ proc test_bkpt_temporary { } {
     }
 }
 
+# Test address locations.
+
+proc test_bkpt_address {} {
+    global gdb_prompt decimal srcfile
+
+    # Delete all breakpoints
+    delete_breakpoints
+
+    gdb_test "python gdb.Breakpoint(\"*main\")" \
+       ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
+
+    gdb_py_test_silent_cmd \
+       "python main_loc = gdb.parse_and_eval(\"main\").address" \
+       "eval address of main" 0
+
+    # Python 2 vs 3 ... Check `int' first. If that fails, try `long'.
+    gdb_test_multiple "python main_addr = int(main_loc)" "int value of main" {
+       -re "Traceback.*$gdb_prompt $" {
+           gdb_test_no_output "python main_addr = long(main_loc)" \
+               "long value of main"
+       }
+       -re "$gdb_prompt $" {
+           pass "int value of main"
+       }
+    }
+
+    # Include whitespace in the linespec to double-check proper
+    # grokking of argument to gdb.Breakpoint.
+    gdb_test "python gdb.Breakpoint(\"  *{}\".format(str(main_addr)))" \
+       ".*Breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\."
+}
+
 test_bkpt_basic
 test_bkpt_deletion
 test_bkpt_cond_and_cmds
@@ -470,3 +502,4 @@ test_watchpoints
 test_bkpt_internal
 test_bkpt_eval_funcs
 test_bkpt_temporary
+test_bkpt_address