From patchwork Mon Feb 1 22:10:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 10694 Received: (qmail 26950 invoked by alias); 1 Feb 2016 22:10:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 26850 invoked by uid 89); 1 Feb 2016 22:10:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=consolidated, (unknown), 5024, sk:test_wa 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; Mon, 01 Feb 2016 22:10:08 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id D1C295A57 for ; Mon, 1 Feb 2016 22:10:06 +0000 (UTC) Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u11MA6YL021781 for ; Mon, 1 Feb 2016 17:10:06 -0500 Subject: [PATCH V2 2/4] python/19506 -- gdb.Breakpoint address location regression From: Keith Seitz To: gdb-patches@sourceware.org Date: Mon, 01 Feb 2016 14:10:06 -0800 Message-ID: <20160201221006.1415.70680.stgit@valrhona.uglyboxes.com> In-Reply-To: <20160201220928.1415.59039.stgit@valrhona.uglyboxes.com> References: <20160201220928.1415.59039.stgit@valrhona.uglyboxes.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes 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 "", line 1, in 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/python/py-breakpoint.c | 5 +++- gdb/testsuite/gdb.python/py-breakpoint.exp | 33 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 85b17d5..964ec62 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -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 (©); + location + = string_to_event_location_basic (©, current_language); 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..d1d1b22 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -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