From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 36543 invoked by alias); 21 Jan 2016 22:05:30 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 36523 invoked by uid 89); 21 Jan 2016 22:05:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:gdbpar, UD:parse_and_eval, UD:gdb.parse_and_eval, sk:gdb.par X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 21 Jan 2016 22:05:28 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 4221CA2C3F for ; Thu, 21 Jan 2016 22:05:27 +0000 (UTC) Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0LM5Q0r018538 for ; Thu, 21 Jan 2016 17:05:27 -0500 From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH] python/19506 -- gdb.Breakpoint address location regression Date: Thu, 21 Jan 2016 22:05:00 -0000 Message-Id: <1453413926-24995-1-git-send-email-keiths@redhat.com> X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg00550.txt.bz2 When the locations API was committed, it assumed that all valid arguments to the gdb.Breakpoint command were a linespec (aside from keywords describing various breakpoint properties). However, address locations are a separate class of locations which were overlooked by my patch. This patch introduces a new function analogous to the CLI function string_to_event_location. This new function only handles address and linespec locations. I have made no attempt to fully implement explicit locations. This patch fixes python/19506: (gdb) python gdb.Breakpoint("*main") Traceback (most recent call last): File "", line 1, in RuntimeError: Function "*main" not defined. Error while executing Python code. Now: (gdb) python gdb.Breakpoint("*main") Breakpoint 1 at 0x4005fb: file ../../../src/gdb/testsuite/gdb.python/py-breakpoint.c, line 32. gdb/ChangeLog * python/py-breakpoint.c (python_string_to_event_location): New function. (bppy_init): Use python_string_to_event_location instead of new_linespec_location. gdb/testsuite/gdb.python * gdb.python/py-breakpoint.exp (test_bkpt_address): New proc. (toplevel): Call test_bkpt_address. --- gdb/python/py-breakpoint.c | 35 +++++++++++++++++++++++++++++- gdb/testsuite/gdb.python/py-breakpoint.exp | 31 ++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 85b17d5..588b41f 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -31,6 +31,7 @@ #include "arch-utils.h" #include "language.h" #include "location.h" +#include "linespec.h" /* Number of live breakpoints. */ static int bppy_live; @@ -624,6 +625,38 @@ bppy_get_ignore_count (PyObject *self, void *closure) return PyInt_FromLong (self_bp->bp->ignore_count); } +/* Attempt to convert the string in *STRINGP to an event_location. + STRINGP is advanced past any processed input. Returns an event_location + (malloc'd). + + The return result must be freed with delete_event_location. */ + +static struct event_location * +python_string_to_event_location (char **stringp) +{ + struct event_location *location; + + /* First check if the string represents a address location. */ + if (*stringp != NULL && **stringp == '*') + { + const char *arg, *orig; + CORE_ADDR addr; + + orig = arg = *stringp; + addr = linespec_expression_to_pc (&arg); + location = new_address_location (addr, orig, arg - orig); + *stringp += arg - orig; + } + else + { + /* Explicit locations are not yet implemented, so everything else + must be a linespec location. */ + location = new_linespec_location (stringp); + } + + return location; +} + /* Python function to create a new breakpoint. */ static int bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) @@ -672,7 +705,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) { struct event_location *location; - location = new_linespec_location (©); + location = python_string_to_event_location (©); make_cleanup_delete_event_location (location); create_breakpoint (python_gdbarch, location, NULL, -1, NULL, diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index af6c5fc..fe535c9 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -462,6 +462,36 @@ 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" + } + } + + 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 +500,4 @@ test_watchpoints test_bkpt_internal test_bkpt_eval_funcs test_bkpt_temporary +test_bkpt_address -- 2.1.0