From patchwork Wed Aug 23 13:58:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Muldoon X-Patchwork-Id: 22329 Received: (qmail 127721 invoked by alias); 23 Aug 2017 13:59:01 -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 125171 invoked by uid 89); 23 Aug 2017 13:58:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy=watch X-HELO: mail-wr0-f176.google.com Received: from mail-wr0-f176.google.com (HELO mail-wr0-f176.google.com) (209.85.128.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Aug 2017 13:58:58 +0000 Received: by mail-wr0-f176.google.com with SMTP id k46so634115wre.2 for ; Wed, 23 Aug 2017 06:58:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:mime-version :content-language:content-transfer-encoding; bh=PKOiAkpXqe7pH3G4pLylZwrjWS0daDGXYlt7U87Kwes=; b=VZKJ0PFK/uR0XfWskwiSih9o4SAc34gltS1ivxR384u4AX+hba84Soec6ZprQ63eGk LWRmY0MLNIJ0IP9R0lwFSYfqD+YsalIKyMmM3BNp+0YDv2aAsuR8L78vG9sCBzTnAVr0 KLGB2/2s/XMleCPQpHDSkLh7jWqVlvkMF/R/TishIz/jKolzaMSufhymsZcsVGPDRb5B R5KEOIndQ2MvQ1X9eE+VlwCxfFGp062SMbHA7s4LvhSGAdojzJ91k7+F+AWXWOmi4TQs Qt/+iBVJuYwHDKCbojCQLmJAKxpFk5wqEaQ4NyoQ/hgdIxurb4EiTZ3geG4z0XQJZUyt 6h+A== X-Gm-Message-State: AHYfb5iUgoNtH3j5NtCJoPJKhsvzNsEG1JseHyo14SeJP4ax6W5cUIBY RoY/6v3KfQOMjANrEMldUA== X-Received: by 10.223.183.35 with SMTP id l35mr1664184wre.266.1503496735622; Wed, 23 Aug 2017 06:58:55 -0700 (PDT) Received: from ?IPv6:2a02:c7f:ae15:7800:4685:ff:fe66:9f4? ([2a02:c7f:ae15:7800:4685:ff:fe66:9f4]) by smtp.gmail.com with ESMTPSA id e2sm1426566wrd.60.2017.08.23.06.58.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 06:58:54 -0700 (PDT) From: Phil Muldoon Subject: [python] Allow explicit locations in breakpoints. To: "gdb-patches@sourceware.org" Message-ID: <04ccc2c4-7827-eedc-d8db-a83a0167acb6@redhat.com> Date: Wed, 23 Aug 2017 14:58:53 +0100 MIME-Version: 1.0 X-IsSubscribed: yes Hello, This minor patch allows for explicit locations to be specified in the gdb.Breakpoint constructor. It's a minor tweak, and the patch largely consists of tests to make sure the existing explicit locations mechanisms work in Python. Cheers Phil --- 2017-08-23 Phil Muldoon * python/py-breakpoint.c (bppy_init): Use string_to_event_location over basic location code. 2017-08-23 Phil Muldoon * python.texi (Breakpoints In Python): Add text relating to allowed explicit location in gdb.Breakpoints. 2017-08-23 Phil Muldoon * gdb.python/py-breakpoint.exp (test_bkpt_explicit_loc): Add new tests for explicit locations. -- diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 32d7939e66..a214c2a9e7 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -4825,7 +4825,8 @@ class. Create a new breakpoint according to @var{spec}, which is a string naming the location of the breakpoint, or an expression that defines a watchpoint. The contents can be any location recognized by the -@code{break} command, or in the case of a watchpoint, by the +@code{break} command, including those set as explicit locations +(@pxref{Explicit Locations}), or in the case of a watchpoint, by the @code{watch} command. The optional @var{type} denotes the breakpoint to create from the types defined later in this chapter. This argument can be either @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}; it diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 6156eb6179..8431bed939 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -681,7 +681,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) case bp_breakpoint: { event_location_up location - = string_to_event_location_basic (©, current_language); + = string_to_event_location (©, current_language); create_breakpoint (python_gdbarch, location.get (), NULL, -1, NULL, 0, diff --git a/gdb/testsuite/gdb.python/py-breakpoint.c b/gdb/testsuite/gdb.python/py-breakpoint.c index df6163e53a..562cab35f7 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.c +++ b/gdb/testsuite/gdb.python/py-breakpoint.c @@ -24,7 +24,7 @@ int multiply (int i) int add (int i) { - return i + i; + return i + i; /* Break at function add. */ } diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index bd138ac3d2..228489f74e 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -547,6 +547,72 @@ proc test_bkpt_events {} { check_last_event breakpoint_deleted } +proc test_bkpt_explicit_loc {} { + global srcfile testfile + + with_test_prefix test_bkpt_invisible { + # Start with a fresh gdb. + clean_restart ${testfile} + + if ![runto_main] then { + fail "cannot run to main." + return 0 + } + + delete_breakpoints + + set bp_location1 [gdb_get_line_number "Break at multiply."] + set bp_location2 [gdb_get_line_number "Break at add."] + + gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"-li $bp_location1\")" \ + "Set explicit breakpoint by line" 0 + gdb_continue_to_breakpoint "Break at multiply" \ + ".*Break at multiply.*" + gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"-li +1\")" \ + "Set explicit breakpoint by relative line" 0 + gdb_continue_to_breakpoint "Break at add" \ + ".*Break at add.*" + delete_breakpoints + gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"-li -1\")" \ + "Set explicit breakpoint by relative negative line" 0 + gdb_continue_to_breakpoint "Break at multiply" \ + ".*Break at multiply.*" + delete_breakpoints + gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"-function add\")" \ + "Set explicit breakpoint by function" 0 + gdb_continue_to_breakpoint "Break at function add" \ + ".*Break at function add.*" + delete_breakpoints + gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"-source $srcfile -function add\")" \ + "Set explicit breakpoint by source file and function" 0 + gdb_continue_to_breakpoint "Break at function add" \ + ".*Break at function add.*" + delete_breakpoints + gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"-source $srcfile -li $bp_location2\")" \ + "Set explicit breakpoint by source file and line number" 0 + gdb_continue_to_breakpoint "Break at add" \ + ".*Break at add.*" + delete_breakpoints + gdb_test "python bp1 = gdb.Breakpoint (\"-source $srcfile\")" \ + "RuntimeError: Source filename requires function, label, or line offset.*" \ + "Set invalid explicit breakpoint by source only" + # The below will print a warning but set pending breakpoints. + gdb_test "python bp1 = gdb.Breakpoint (\"-source foo.c -li 5\")" \ + "No source file named foo.*" \ + "Set invalid explicit breakpoint by missing source and line" + gdb_test "python bp1 = gdb.Breakpoint (\"-source $srcfile -li 900\")" \ + "No line 900 in file \"$srcfile\".*" \ + "Set invalid explicit breakpoint by source and invalid line." + gdb_test "python bp1 = gdb.Breakpoint (\"-function blah\")" \ + "Function \"blah\" not defined.*" \ + "Set invalid explicit breakpoint by missing function." + # Invalid explicit location flags. + gdb_test "python bp1 = gdb.Breakpoint (\"-foo -li 5\")" \ + "RuntimeError: invalid explicit location argument, \"-foo\".*" \ + "Set invalid explicit breakpoint by wrong flag" + } +} + test_bkpt_basic test_bkpt_deletion test_bkpt_cond_and_cmds @@ -558,3 +624,4 @@ test_bkpt_temporary test_bkpt_address test_bkpt_pending test_bkpt_events +test_bkpt_explicit_loc