From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 6B5893858C83; Thu, 26 Jan 2023 20:23:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B5893858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674764598; bh=HSWXdZdOdzIOLEQucggZp8JYffhDms9mP05Ak7ki8gM=; h=From:To:Subject:Date:From; b=dUOzffpyCe/G1Ve0pcQT28h5mAE3cbcg4NhXXKYBFYVF7nyzXFiF2/RPA1NmLWH2p byNMsbOsjMcKrzUHOKLVATHNFBeCggrEW86SZvyus8swsXB0HnN83832fBgC15ZDao peevCk7P6YygUEf8+Kic7ecx8qAzz9mGlKzNG8RY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite/dap: fix gdb.dap/basic-dap.exp disassembly test for PIE X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 8abd06e066be7ad41d608b500187e90736c9e8fa X-Git-Newrev: d4c4ea75838091b6bf52d97208bd2fa4021951db Message-Id: <20230126202318.6B5893858C83@sourceware.org> Date: Thu, 26 Jan 2023 20:23:18 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd4c4ea758380= 91b6bf52d97208bd2fa4021951db commit d4c4ea75838091b6bf52d97208bd2fa4021951db Author: Simon Marchi Date: Fri Jan 6 13:26:19 2023 -0500 gdb/testsuite/dap: fix gdb.dap/basic-dap.exp disassembly test for PIE =20 Prior to this patch, I get: =20 >>> {"seq": 17, "type": "request", "command": "disassemble", "argum= ents": {"memoryReference": "0x115d", "instructionCount": 1}} Content-Length: 147 =20 {"request_seq": 17, "type": "response", "command": "disassemble", "= success": false, "message": "Cannot access memory at address 0x115d", "seq"= : 41}FAIL: gdb.dap/basic-dap.exp: disassemble one instruction success FAIL: gdb.dap/basic-dap.exp: instructions in disassemble output =20 The problem is that the PC to disassemble is taken from the breakpoint insertion response, which happens before running. With a PIE executable, that PC is unrelocated, but the disassembly request happens after relocation. =20 I chose to fix this by watching for a breakpoint changed event giving the new breakpoint address, and recording the address from there. I think this is an interesting way to fix it, because it adds a bit of test coverage, I don't think these events are checked right now. =20 Other ways to fix it would be: =20 - Get the address by doing a breakpoint insertion after the program is started, or some other way. - Do the disassembly by symbol instead of by address. - Do the disassembly before running the program. =20 Change-Id: I3c396f796ac4c8b22e7dfd2fa1c5467f7a47e84e Diff: --- gdb/testsuite/gdb.dap/basic-dap.exp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/ba= sic-dap.exp index 795702a5a8f..5303e943320 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -90,9 +90,36 @@ set insn_pc [dict get [lindex $bplist 0] instructionRefe= rence] dap_check_request_and_response "start inferior" configurationDone dap_wait_for_event_and_check "inferior started" thread "body reason" start= ed =20 -dap_wait_for_event_and_check "stopped at function breakpoint" stopped \ - "body reason" breakpoint \ - "body hitBreakpointIds" $fn_bpno +# While waiting for the stopped event, we might receive breakpoint changed +# events indicating some breakpoint addresses were relocated. Update INSN= _PC +# if necessary. +lassign [dap_wait_for_event_and_check "stopped at function breakpoint" sto= pped \ + "body reason" breakpoint \ + "body hitBreakpointIds" $fn_bpno] unused objs +foreach obj $objs { + if { [dict get $obj "type"] !=3D "event" } { + continue + } + + if { [dict get $obj "event"] !=3D "breakpoint" } { + continue + } + + set body [dict get $obj "body"] + + if { [dict get $body "reason"] !=3D "changed" } { + continue + } + + set breakpoint [dict get $body "breakpoint"] + set breakpoint_id [dict get $breakpoint "id"] + + if { $breakpoint_id !=3D $insn_bpno } { + continue + } + + set insn_pc [dict get $breakpoint "instructionReference"] +} =20 set obj [dap_check_request_and_response "evaluate global in function" \ evaluate {o expression [s global_variable]}]