From patchwork Wed May 23 08:48:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Bunt X-Patchwork-Id: 27456 Received: (qmail 85714 invoked by alias); 23 May 2018 08:49:21 -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 85354 invoked by uid 89); 23 May 2018 08:49:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=launching, 4*, mirrors X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-he1eur01on0090.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.90) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 May 2018 08:49:03 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Richard.Bunt@arm.com; Received: from [10.32.32.27] (217.140.96.140) by AM6PR08MB3192.eurprd08.prod.outlook.com (2603:10a6:209:46::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.797.11; Wed, 23 May 2018 08:48:59 +0000 From: Richard Bunt Subject: [PATCH] Enable hardware watchpoints on attach for aarch64 To: gdb-patches@sourceware.org Cc: nd@arm.com, dirk.schubert@arm.com Message-ID: <17719981-eb06-6e22-6d3e-6bfe6ae411ba@arm.com> Date: Wed, 23 May 2018 09:48:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-ClientProxiedBy: CWLP265CA0018.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:10::30) To AM6PR08MB3192.eurprd08.prod.outlook.com (2603:10a6:209:46::29) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(2017052603328)(7153060)(7193020); SRVR:AM6PR08MB3192; X-Microsoft-Exchange-Diagnostics: 1; AM6PR08MB3192; 3:mvmN7aDEyE+EVySzTnINzoOiu+Ugeiw9AUrxOSe+ZERQfn3OUqQkbm07QgqFP4xAw6VvUxPCxG5HHMQqGZZ8d+fZh2BsEnor1HdZdAIm00XbMimJMDb41E1uQSpfMbXzVRlxVoXdQXzJPVck1rBNRxKsxAEJf6XBiFJSN7/lXJp0lLZmKxI/bxPW2/XNTnMm701GnAGiqs0i/s9eYApAgXIQDL4Dfq2aRhqB7ILuIk9xBweproaSGzXwrhlfvmAK; 25:TB2ilLBK+oI5sPFAWP1cglPfbOqHEAm2vk3oAJhdAT8a9xfVAEPVzl+4TuBHzn7K9w92fZVPNgCz2t6HlfmZ0n30VRrtJVPbb8qtSZ8Jtdp7qEiVMWMa4Ux/fQwvUk6ew5RAR38tb56azoHc0+kjsMnQR1TWyiR8f2qPIwnHqjmjSEV45OGPdfiOkRRGr8VoDgtMIskKUNdHYETuXo++HMQ8pPPauDK0v7bf1qLqhpTLU6aL7+gtlyt21V2TAWFKv5LaGpWxtNld3iOTlEEBVfY1DVCc9/RN4c9dB6NX6cRLutmUB7QFKJYrIh66GN/XUoQ15J6bUjvymUiGGQ96Rw==; 31:hMZYMywEr926MCMiqyzsNQ0rmjtU6hC2dD4FO2Dt66eart5/hiZNiChrnCob7pgPB1706qRkNJQ7tu2+53btUTp5oIdoyM2eMlMVBZ3CVbMirD7w657lqkw4+FYDtM7XyED+jeioUxXgG3hAO+LjaXfSb5tuZCZ0dPViHSBJ0fg4L0hB/d1D80ygX4E8QDVxz8X0FYoKTI3fyxg581uhzy1QxN+g5rsl3x0QAAehWyk= X-MS-TrafficTypeDiagnostic: AM6PR08MB3192: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; AM6PR08MB3192; 20:7vzuWLsPKShDkY1FM6dGwTPO+OHihhBwISoV68aZ7wNwBZYRCqHcH/MIgLp4BdEor55E1GUPJTnaGpbQnL5m6bhpjT9cry4Fzk7t92tlje/lladDcVT9H3+d5OTyx1Jfc4JLRxxG/g1vCqrzcYgAYO3rv1CiTPsK1pxL0Dq2nFjE6bob0MWUgRwLlHKmmo8TabSMN2FdSebIv3p3xhMJxqaA/hQA0xiBZ/cBzLUb0UlzNPYZTA2eftyR7ErLv9pa; 4:D7+5YN9ckQkfj2eEd+bXUiy5r2Bf3Qs6LcuFuVmF76NuqaAuf/yZgB9yqp1dPjZrjXKkXBSb0VxQCYkMVD+Pei0bhPPQPj1JO+ckla9tRz9Ks+V/YI6LLCzDsBs5Q/CNqZeJvEJ9djvVylVP+GWBU/+LXNPIEzDPQ+dbOtkTDke+QKJ7X8j4bRt4rY7t/S+gBVQXp8mmpB/fzL4b+FeTmHCoDVt1gm75OkDvbdBFPbbrx1qgfgVwgKOIZ6pcQitX+S+88qXV8uB/7cxjCK6PSHdwZRul/98L0oze3jEiJR9nldwboHX31FTXk9uIw1SXsxVcVOBhY/NhJ7a1f6cMWBfybgwTXAbKmXhd1RMD1GjWVV56GpJZKaPnfSSsaaR+ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(180628864354917)(22074186197030); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(3231254)(944501410)(52105095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:AM6PR08MB3192; BCL:0; PCL:0; RULEID:; SRVR:AM6PR08MB3192; X-Forefront-PRVS: 06818431B9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019001)(6009001)(6049001)(428001)(377424004)(54534003)(199002)(189002)(20776003)(69226001)(63696002)(47776003)(74876001)(74706001)(36756003)(77096001)(23676002)(76786001)(76796001)(81542001)(42186004)(54356001)(31686003)(93136001)(76176001)(92566001)(46102001)(64706001)(81342001)(92726001)(15975445006)(77982001)(59766001)(56816005)(33646001)(80022001)(65956001)(66066001)(76482001)(90146001)(65806001)(65816001)(87936001)(56776001)(15202345003)(54316002)(74366001)(44376005)(87266001)(4396001)(47976001)(50986001)(95666003)(49866001)(47736001)(51856001)(50466002)(85306002)(79102001)(85852003)(83072002)(83506001)(21056001)(97336001)(94946001)(93516002)(95416001)(94316002)(86362001)(97186001)(80976001)(31696002)(64126003)(575784001)(81686001)(83322001)(19580405001)(81816001)(31966008)(74662001)(19580395003)(53806001)(74502001)(47446002)(65826005)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM6PR08MB3192; H:[10.32.32.27]; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTZQUjA4TUIzMTkyOzIzOmdmYk0wbm5ZVDVZMXhCZG83RlM2V2Z4TWt6?= =?utf-8?B?WnVneGhRRlVucDVUTXJYcTg3UHh5a3lOZWwvZ0hMaTFpNkZSZEJFK01hQkEy?= =?utf-8?B?UzlCaEtCL3Y5Y0NFQk93cDh5Tzd2cXFhdU9wK0ZYeXpZVGVCWlFrUWo2YmdX?= =?utf-8?B?ckhlcldUdWFuYWU4anl3WEJDUkppVDMxVndOL3RXbmVSVGNvWkNaRWlLQXh3?= =?utf-8?B?WGlyTll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ation-Id: d85c3ee8-a98e-4568-d859-08d5c08a0742 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2018 08:48:59.7790 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d85c3ee8-a98e-4568-d859-08d5c08a0742 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3192 X-IsSubscribed: yes This patch fixes a bug whereby hardware watchpoints are not used on aarch64 when attaching to a target. The fix adds an aarch64 specialization of post_attach which records the number of available hardware debug registers using aarch64_linux_get_debug_reg_capacity. This implementation mirrors that of aarch64_linux_child_post_startup_inferior which successfully enables the use of hardware watchpoints when launching the target under the debugger. 2018-05-14 Richard Bunt Dirk Schubert * aarch64-linux-nat.c (post_attach): New. (aarch64_linux_nat_target::post_attach): Override post_attach to record the number of hardware debug registers. gdb/testsuite/ChangeLog: 2018-05-14 Richard Bunt * gdb.base/watchpoint-hw-attach.c: New test. * gdb.base/watchpoint-hw-attach.exp: New file. --- Annotation for this patch gdb/aarch64-linux-nat.c | 18 ++++++ gdb/testsuite/gdb.base/watchpoint-hw-attach.c | 44 +++++++++++++ gdb/testsuite/gdb.base/watchpoint-hw-attach.exp | 85 +++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 gdb/testsuite/gdb.base/watchpoint-hw-attach.c create mode 100644 gdb/testsuite/gdb.base/watchpoint-hw-attach.exp -- 1.8.5.6 diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 908b83a..e0f75d0 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -76,6 +76,9 @@ public: /* Override the GNU/Linux inferior startup hook. */ void post_startup_inferior (ptid_t) override; + /* Override the GNU/Linux post attach hook. */ + void post_attach (int pid) override; + /* These three defer to common nat/ code. */ void low_new_thread (struct lwp_info *lp) override { aarch64_linux_new_thread (lp); } @@ -521,6 +524,21 @@ aarch64_linux_nat_target::post_startup_inferior (ptid_t ptid) linux_nat_target::post_startup_inferior (ptid); } +/* Implement the "post_attach" target_ops method. */ + +void +aarch64_linux_nat_target::post_attach (int pid) +{ + low_forget_process (pid); + /* Set the hardware debug register capacity. If + aarch64_linux_get_debug_reg_capacity is not called + (as it is in aarch64_linux_child_post_startup_inferior) then + software watchpoints will be used instead of hardware + watchpoints when attaching to a target. */ + aarch64_linux_get_debug_reg_capacity (pid); + linux_nat_target::post_attach (pid); +} + extern struct target_desc *tdesc_arm_with_neon; /* Implement the "read_description" target_ops method. */ diff --git a/gdb/testsuite/gdb.base/watchpoint-hw-attach.c b/gdb/testsuite/gdb.base/watchpoint-hw-attach.c new file mode 100644 index 0000000..9d55b28 --- /dev/null +++ b/gdb/testsuite/gdb.base/watchpoint-hw-attach.c @@ -0,0 +1,44 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2018 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see. */ + +#include +#include +#include + +/* This is set to 1 by the debugger post attach to continue to the + watchpoint trigger. */ +volatile int should_continue = 0; +/* The variable to place a watchpoint on. */ +volatile int watched_variable = 0; + +int +main (void) +{ + unsigned int counter = 1; + int mypid = getpid (); + + /* Wait for the debugger to attach, but not indefinitely so this + test program is not left hanging around. */ + for (counter = 0; !should_continue && counter < 100; counter++) + sleep (1); /* pidacquired */ + + watched_variable = 0; /* prewatchtrigger */ + /* Trigger a watchpoint. */ + watched_variable = 4; + printf ("My variable is %d\n", watched_variable); + return 0; +} diff --git a/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp new file mode 100644 index 0000000..a030cb7 --- /dev/null +++ b/gdb/testsuite/gdb.base/watchpoint-hw-attach.exp @@ -0,0 +1,85 @@ +# Copyright 2018 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see. + +# watchpoint-hw-attach.exp -- Test if hardware watchpoints are used +# when attaching to a target. + +if {[skip_hw_watchpoint_tests]} { + return 0 +} + +if {![can_spawn_for_attach]} { + return 0 +} + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + +clean_restart $binfile + +if ![runto_main] { + untested "can't run to main" + return -1 +} +# Run to the point where mypid in the test program has been +# populated. +gdb_breakpoint [gdb_get_line_number "pidacquired"] +gdb_continue_to_breakpoint "pidacquired" + +# Get the PID of the test process. +set testpid "" +set test "get inferior process ID" + gdb_test_multiple "p mypid" $test { + -re " = ($decimal)\r\n$gdb_prompt $" { + set testpid $expect_out(1,string) + pass $test + } +} + +gdb_test "detach" "Detaching from program: .*" + +if {$testpid == ""} { + return -1 +} + +# A clean restart is needed to force the hardware watchpoint setup +# logic to run post attach rather than post inferior launch. +clean_restart $binfile + +set test "attach $testpid" +gdb_test_multiple $test $test { + -re "Attaching to program.*process $testpid\r\n.*$gdb_prompt $" { + pass "$test" + } + timeout { + fail "$test" + } +} + +gdb_test_no_output "set should_continue = 1" +# Ensure the test program is in the top frame so the required +# variables are in scope. +gdb_breakpoint [gdb_get_line_number "prewatchtrigger"] +gdb_continue_to_breakpoint "prewatchtrigger" + +gdb_test "watch watched_variable" \ + "Hardware watchpoint $decimal: watched_variable" + +gdb_test "continue" \ + "continue.*Continuing.*\.Hardware watchpoint $decimal:\ + watched_variable.*Old value = 0.*New value = 4.*"