From patchwork Mon Jun 3 12:53:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 32972 Received: (qmail 23191 invoked by alias); 3 Jun 2019 12:53:54 -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 23183 invoked by uid 89); 3 Jun 2019 12:53:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: EUR04-VI1-obe.outbound.protection.outlook.com Received: from mail-eopbgr80087.outbound.protection.outlook.com (HELO EUR04-VI1-obe.outbound.protection.outlook.com) (40.107.8.87) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Jun 2019 12:53:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lMrzIDZiq305IH0SIqd7UT3KWUBjucxpNG1eq8MoBwM=; b=Kv8UfjOqiofU/YuwGdvMwJ36zbSvsHvy8czyOZbdm1XfJeikpXZHwVKXNbG5xlQPUc94etXAQQlioGkFMaSexSLTwX3hqghqZXacPjFY4CbqxFNnhQz8QreF4AdUTy6O8580do1GUXQBxBYkpYwiI2ln9c7xZAqNirFYNnoSs/U= Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com (10.172.227.22) by DB6PR0802MB2296.eurprd08.prod.outlook.com (10.172.228.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1943.22; Mon, 3 Jun 2019 12:53:47 +0000 Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::8c26:bb4b:6c93:9d40]) by DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::8c26:bb4b:6c93:9d40%2]) with mapi id 15.20.1943.018; Mon, 3 Jun 2019 12:53:47 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd , Alan Hayward Subject: [PATCH] Fix breakpoints on file reloads for PIE binaries Date: Mon, 3 Jun 2019 12:53:47 +0000 Message-ID: <20190603125344.40595-1-alan.hayward@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-oob-tlc-oobclassifiers: OLM:8882; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Alan.Hayward@arm.com X-IsSubscribed: yes When a binary is built using PIE, reloading the file will cause GDB to error on restart. For example: gdb ./a.out (gdb) break main (gdb) run (gdb) file ./a.out (gdb) continue Will cause GDB to error with: Continuing. Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x9e0 Command aborted. This is due to the symbol offsets not being relocated after reloading the file. Fix is to ensure solib_create_inferior_hook is called, in the same manner as infrun.c:follow_exec(). Expand the idempotent test to cover PIE scenarios. gdb/ChangeLog: 2019-06-03 Alan Hayward * symfile.c (symbol_file_command): Call solib_create_inferior_hook. gdb/testsuite/ChangeLog: 2019-06-03 Alan Hayward * gdb.base/break-idempotent.exp: Test both PIE and non PIE. --- gdb/symfile.c | 12 ++++ gdb/testsuite/gdb.base/break-idempotent.exp | 72 ++++++++++++--------- 2 files changed, 52 insertions(+), 32 deletions(-) -- 2.20.1 (Apple Git-117) diff --git a/gdb/symfile.c b/gdb/symfile.c index af99da18f7..0baed96e06 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1672,7 +1672,19 @@ symbol_file_command (const char *args, int from_tty) validate_readnow_readnever (flags); + /* Set SYMFILE_DEFER_BP_RESET because the proper displacement for a PIE + (Position Independent Executable) main symbol file will only be + computed by the solib_create_inferior_hook below. Without it, + breakpoint_re_set would fail to insert the breakpoints with the zero + displacement. */ + add_flags |= SYMFILE_DEFER_BP_RESET; + symbol_file_add_main_1 (name, add_flags, flags, offset); + + solib_create_inferior_hook (0); + + /* Now it's safe to re-add the breakpoints. */ + breakpoint_re_set (); } } diff --git a/gdb/testsuite/gdb.base/break-idempotent.exp b/gdb/testsuite/gdb.base/break-idempotent.exp index 902a5f818b..38e7cf4710 100644 --- a/gdb/testsuite/gdb.base/break-idempotent.exp +++ b/gdb/testsuite/gdb.base/break-idempotent.exp @@ -36,23 +36,6 @@ standard_testfile -if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { - return -1 -} - -if ![runto_main] then { - fail "can't run to main" - return 0 -} - -if [is_remote host] { - set arg [remote_download host $binfile] - if { $arg == "" } { - perror "download failed" - return -1 - } -} - # Force a breakpoint re-set in GDB. Currently this is done by # reloading symbols with the "file" command. @@ -62,11 +45,11 @@ proc force_breakpoint_re_set {} { set test "file \$binfile" gdb_test_multiple "file $binfile" $test { -re "Are you sure you want to change the file. .*y or n. $" { - send_gdb "y\n" + send_gdb "y\n" optional exp_continue } -re "Load new symbol table from \".*\".*y or n. $" { - send_gdb "y\n" + send_gdb "y\n" optional exp_continue } -re "Reading symbols from.*$gdb_prompt $" { @@ -123,7 +106,7 @@ proc set_breakpoint { break_command } { proc test_break { always_inserted break_command } { set cmd [lindex [split "$break_command"] 0] - with_test_prefix "always-inserted $always_inserted: $cmd" { + with_test_prefix "$cmd" { delete_breakpoints if ![runto_main] then { @@ -163,20 +146,45 @@ proc test_break { always_inserted break_command } { } } -foreach always_inserted { "off" "on" } { - test_break $always_inserted "break" +foreach_with_prefix pie { "nopie" "pie" } { + foreach_with_prefix always_inserted { "off" "on" } { - if {![skip_hw_breakpoint_tests]} { - test_break $always_inserted "hbreak" - } + set opts {debug} + lappend opts $pie - if {![skip_hw_watchpoint_tests]} { - test_break $always_inserted "watch" - } + if {[prepare_for_testing "failed to prepare" $testfile $srcfile $opts]} { + return -1 + } + + clean_restart $testfile + + if ![runto_main] then { + fail "can't run to main" + return 0 + } + + if [is_remote host] { + set arg [remote_download host $binfile] + if { $arg == "" } { + perror "download failed" + return -1 + } + } - if {![skip_hw_watchpoint_access_tests] - && ![skip_hw_watchpoint_multi_tests]} { - test_break $always_inserted "rwatch" - test_break $always_inserted "awatch" + test_break $always_inserted "break" + + if {![skip_hw_breakpoint_tests]} { + test_break $always_inserted "hbreak" + } + + if {![skip_hw_watchpoint_tests]} { + test_break $always_inserted "watch" + } + + if {![skip_hw_watchpoint_access_tests] + && ![skip_hw_watchpoint_multi_tests]} { + test_break $always_inserted "rwatch" + test_break $always_inserted "awatch" + } } }