From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2OhVG/6Vh2fp3Q8AWB0awg (envelope-from ) for ; Wed, 15 Jan 2025 06:03:26 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=LFENBgeO; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6C79A1E100; Wed, 15 Jan 2025 06:03:26 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A9DCF1E08E for ; Wed, 15 Jan 2025 06:03:25 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 437DE385DDDF for ; Wed, 15 Jan 2025 11:03:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 437DE385DDDF Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=LFENBgeO Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2061.outbound.protection.outlook.com [40.107.223.61]) by sourceware.org (Postfix) with ESMTPS id 055F3385DDC3 for ; Wed, 15 Jan 2025 11:02:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 055F3385DDC3 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 055F3385DDC3 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.223.61 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1736938961; cv=pass; b=gOcHZ/JbcW3q6EEVj3vAZ6FLJGB0irQdqStRDv3OS/PSqQ7bY5qaPjHKW1YDLB5X9KUDbqRqQca77VJpMZlUzz1D9fHC30N2HvlTNxg8+SxVp37gDbyDNwdy5CQxfNXz6nLPBFdTwCO/Hz6WBpePTqfmNV/N1aJ+9V6hAm6A6I4= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1736938961; c=relaxed/simple; bh=lHCAwV3zU87FuFhGOzQdmjsAgcKdmzFv5ozX4RIcr7s=; h=DKIM-Signature:Message-ID:Date:Subject:To:From:MIME-Version; b=vMmyI9QeL5E8n9/IpbOXIwPLwlRmm93/rt2M+ejZkmI+/88YAkjN2NiTGwXgyq6pxR2GBjaDknDnRiy/bauDA0vxnOEOnfXHvMZJonYc8bhwrZkhn+JMY330FsyFoRh4r6yb9E3qkPFj5w3tPYzUoC67qOyYqbpkteV4/q5jPQE= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 055F3385DDC3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uHEoCU9xeltp8wWdSPFOxS5xR+JUg4xDRFGLaHZ3oiAcw+Dzw1227+mDTUpDlIyFSwav0sDcuAF/1ZlCd8kwF1EcZyPpZTnbxRsqYLL2Sc00ndRghPIIArvDgn2xtdn+2POWm5dBf8dGz37SyW5WjXL488PF2mMVyGXXF9kFvdwU1o6Quu21jkIcoL7NUzBl52qtV9ygjmojHYAbfbAnb/Zlekx8HI7+6O8WbT5THtu8ss6XwG9BNNrvh82pVBI+UQF2V0NrMkAVnkzwZQaKI1g5PqZpeHXJ5wu+G2NTXOBk8ayE0jBLXjjZDMHIh9c0/umXgCSN77ZVBpJIbnxZWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XKMv+MEt32oiWtrap8LvBrwjmIb2aECr3woDQRZUuuQ=; b=Niui476hGVu8v0AC5QoVc2rfkJ4sTJjYJctda6askUq6/s3/4uzVSQqliD/hBgtp8Mg/pHBiyD4vWm7N77EmRIw7r6tJ/Sd952CP7G/tS/tLvhj6fstVFXNLdMnWoVxiP5VbEGm7xZtnNN8I+MEBFC2MgwMM92ZjjAsQbmwM5o8pqkbJIjiYQgWM9vE/kEwrvcCeYxBnYAKKrAn1d8XA2CKZik4+x4BalFRPsTS9iMLU8cqSSELuBwU0TOCltUwOVhb5CWK5nOx0YAij3Mbgpv/vuaeO2r2ctAFmYlpGpBBc1ZOUPwptWm++xQsuedDZwmJQq7HUQ60i3V8y4+y/2w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XKMv+MEt32oiWtrap8LvBrwjmIb2aECr3woDQRZUuuQ=; b=LFENBgeO8jcmRx1YSLdYWnNKooHLWO5Rb1u8WpZza2jp0uBs9Sn9zDeY0vkXHeaSVj3cJxYvQ+CzcHXQU9pdiebIWDuRk0PCOlJKU7ueal0im6dtBsyabQwkJFCLlziDN5NkVyA8nfTcRY+5D5ntEjBA3RYmqFkfmu8CDaJJPUQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from LV3PR12MB9095.namprd12.prod.outlook.com (2603:10b6:408:1a6::22) by DS0PR12MB6416.namprd12.prod.outlook.com (2603:10b6:8:cb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Wed, 15 Jan 2025 11:02:39 +0000 Received: from LV3PR12MB9095.namprd12.prod.outlook.com ([fe80::e8c:f2db:ab98:4538]) by LV3PR12MB9095.namprd12.prod.outlook.com ([fe80::e8c:f2db:ab98:4538%7]) with mapi id 15.20.8356.010; Wed, 15 Jan 2025 11:02:36 +0000 Message-ID: <8097b8ac-7d99-4472-bc59-599a358e8ede@amd.com> Date: Wed, 15 Jan 2025 11:02:31 +0000 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/3] gdb/amd-dbgapi: add displaced stepping support To: simon.marchi@polymtl.ca, gdb-patches@sourceware.org Cc: Simon Marchi References: <20250114191818.2393132-1-simon.marchi@polymtl.ca> <20250114191818.2393132-4-simon.marchi@polymtl.ca> Content-Language: en-US From: Lancelot SIX In-Reply-To: <20250114191818.2393132-4-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR0P281CA0148.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:96::9) To CH3PR12MB9079.namprd12.prod.outlook.com (2603:10b6:610:1a1::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV3PR12MB9095:EE_|DS0PR12MB6416:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f2b6d54-9b2d-46d7-7af9-08dd35541e3f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?utf-8?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R0aldOZmRWbFNsQ2wrbE1iaFd6VXNQS082?= =?utf-8?B?MkZHWWc3TWVHeW91eVRoZz09?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:LV3PR12MB9095.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(7053199007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?NlVwaXd5RjdJTlNFWGIvL2Fjd0RHSGdZejZtak1vd3REZlIvR01NYW82b09F?= =?utf-8?B?Mkg0bzhGY092dTc4QkNyTzdjRnBmWjNKUGt5Y0tydTE3YnFvNW0za2hjTVFq?= =?utf-8?B?UkhkbzU4dVo2K3FNN1pwRnJuNzNrcWJlWjhYZmZmS2dPVWhqY293bk12NHFo?= =?utf-8?B?WEhVZjRxU2pXdWtIYmpxUkQ0anBRUnpXSFJGc0g4V25NRnI1eVZDb2tvT2hT?= =?utf-8?B?QzAvWEpRMHp5TDVNOWNYZ3FNOEEwNkhTUWkxV010WnN0NG9lU0RDankraDRJ?= =?utf-8?B?bHhDbnZUMTBxeEQ5cGhxc2ZzUVRQZkwvVE1nWVJGTDZYd3Q0QkZhUC8xV29P?= =?utf-8?B?MUcyWlJKY216YXp6S0dOZzJOYWhsVEY5ZmlSR1plUkVpL2N6TzFUKzFjRVpO?= =?utf-8?B?UGdBSVBtelZDRExqQTBWd2l0dThKQXZ4Qk14VnZsRVhpNHVXVUR5Y2s2Tmt0?= =?utf-8?B?NEtxUWtRYXlMbmhxSmxFVEpxQThCc2R6ZnZveVkrcm1TbThiYS9neUdFMUdP?= =?utf-8?B?RjFuN0RnemJKeDE4SmFXNE9pRElDYXJQUlpPSFVDMDNzQ0lEOUZzMi90YmVw?= =?utf-8?B?dnk0NVVOWE5sczE4SCtmbTV2MUVMY0dyZDJPTnBRNXp6WGVHUXh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Gc4am5icVdUMlVmdjA2REsvcm5FQmVkMVJM?= =?utf-8?B?TVJmZkNxd1E0RHptUFdQbVVFQlpuWDFDUEVBUGUrZFpqQlZHTUpzZ0pYMFNE?= =?utf-8?B?d1FvTEkxTW9ycHJvWjNxRXNPcTNGSGE5VHArK0tMTnRJb0JVd2hRZFlvbzNn?= =?utf-8?B?Zm5CTklobVJnd0RCbUhDL21YY2VkTjMvZ2I2eDFrNEhCL0hYdk9uL3hFTEVN?= =?utf-8?B?d3h1a3dGOTl4d2wyK3VCSWI4bTlPOHpQNTFlMnZHTmp6cXdrY29TeVVQT0dz?= =?utf-8?B?VXdWMEh3LzJ3aWVKV3FFODlPbXpwVTE3UFRCTUZiaWZna3RLWlc0cjl0dkYx?= =?utf-8?B?cFkzYm1ZMDAxdFMvODBmandFQWZNeDMvTEpWa2ZPVXBZZks4VUpEQXdGMS9Q?= =?utf-8?B?elVxcXh5MzNicUJYOG5pVE9sMzZDa0FDN3FlQ0E3dTl5Q3pTV21FM2daRElm?= =?utf-8?B?SE5haS9tSWtEckdPMEhIZ21sdzhQWFhDNDlHbUk2b0twUFNtUzNyeDNHbnpL?= =?utf-8?B?TzZydXpCenUraFNMK1V0cTl2QkVRbHJnQ213VzVaNXozcGVCcmpqQWJrVVUz?= =?utf-8?Q?1+m+3+a/jPmeaSA90cxla0Y3Y?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f2b6d54-9b2d-46d7-7af9-08dd35541e3f X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB9079.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2025 11:02:36.7337 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hx4kCwyFsOjzChy8DeivyahBcKqfy4K9V5nJRTjy55bdCfn1DF/SJ9xaS2NSvjcVfLhG7+TAGW6X0MXRRk7dZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6416 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hi Simon, I have a couple of minor remarks below. On 14/01/2025 19:16, simon.marchi@polymtl.ca wrote: > Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. > > > From: Simon Marchi > > Implement the target_ops displaced stepping methods to add displaced > stepping support when debugging AMD GPU programs. The knowledge of how > to prepare and finish displaced steps is provided by the amd-dbgapi > library, so the code here is relatively straightforward. No need to > parse instructions or handle fixups, that is done by the lib We just > need to remember, for each thread doing a displaced step, the displaced > stepping id given by the library. > > Add a test to exercise the new functionality. The compiler generates > DWARF that GDB doesn't understand yet [1], so trying to step over a > breakpoint with DWARF present gives: > > (gdb) si > Unhandled dwarf expression opcode 0xe9 > > The test purposefully builds the binary without DWARF info to circumvent > this. > > [1] https://llvm.org/docs/AMDGPUDwarfExtensionsForHeterogeneousDebugging.html > > Change-Id: I53f459221a42d4b02a6041eadb8cf554500e2162 > --- > gdb/amd-dbgapi-target.c | 138 ++++++++++++++++++ > gdb/testsuite/gdb.rocm/displaced-stepping.exp | 54 +++++++ > 2 files changed, 192 insertions(+) > create mode 100644 gdb/testsuite/gdb.rocm/displaced-stepping.exp > > diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c > index 153a35f788ed..996e16abf591 100644 > --- a/gdb/amd-dbgapi-target.c > +++ b/gdb/amd-dbgapi-target.c > @@ -24,6 +24,7 @@ > #include "cli/cli-cmds.h" > #include "cli/cli-decode.h" > #include "cli/cli-style.h" > +#include "gdbcore.h" > #include "gdbsupport/unordered_map.h" > #include "inf-loop.h" > #include "inferior.h" > @@ -215,6 +216,12 @@ struct amd_dbgapi_inferior_info > /* List of pending events the amd-dbgapi target retrieved from the dbgapi. */ > std::list> wave_events; > > + /* Map of threads with ongoing displaced steps to corresponding amd-dbgapi > + displaced stepping handles. */ > + gdb::unordered_map + decltype (amd_dbgapi_displaced_stepping_id_t::handle)> > + stepping_id_map; > + > /* Map of wave ID to wave_info. We cache wave_info objects because > we need to access the info after the wave is gone, in the thread > exit nofication. E.g.: > @@ -291,6 +298,21 @@ struct amd_dbgapi_target final : public target_ops > bool stopped_by_sw_breakpoint () override; > bool stopped_by_hw_breakpoint () override; > > + bool supports_displaced_step (thread_info *thread) override > + { > + /* Handle displaced stepping for GPU threads only. */ > + if (!ptid_is_gpu (thread->ptid)) > + return beneath ()->supports_displaced_step (thread); > + > + return true; > + } > + > + displaced_step_prepare_status displaced_step_prepare > + (thread_info *thread, CORE_ADDR &displaced_pc) override; > + > + displaced_step_finish_status displaced_step_finish > + (thread_info *thread, const target_waitstatus &status) override; > + > private: > /* True if we must report thread events. */ > bool m_report_thread_events = false; > @@ -1897,6 +1919,122 @@ amd_dbgapi_target::update_thread_list () > this->beneath ()->update_thread_list (); > } > > +displaced_step_prepare_status > +amd_dbgapi_target::displaced_step_prepare (thread_info *thread, > + CORE_ADDR &displaced_pc) > +{ > + if (!ptid_is_gpu (thread->ptid)) > + return beneath ()->displaced_step_prepare (thread, displaced_pc); > + > + gdb_assert (!thread->displaced_step_state.in_progress ()); > + > + /* Read the bytes that were overwritten by the breakpoint instruction being > + stepped over. */ > + CORE_ADDR original_pc = regcache_read_pc (get_thread_regcache (thread)); > + gdbarch *arch = get_thread_regcache (thread)->arch (); > + size_t size = get_amdgpu_gdbarch_tdep (arch)->breakpoint_instruction_size; > + gdb::byte_vector overwritten_bytes (size); > + > + read_memory (original_pc, overwritten_bytes.data (), size); > + > + /* Ask dbgapi to start the displaced step. */ > + amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (thread->ptid); > + amd_dbgapi_displaced_stepping_id_t stepping_id; > + amd_dbgapi_status_t status > + = amd_dbgapi_displaced_stepping_start (wave_id, overwritten_bytes.data (), > + &stepping_id); > + > + switch (status) > + { > + case AMD_DBGAPI_STATUS_SUCCESS: > + break; > + > + case AMD_DBGAPI_STATUS_ERROR_DISPLACED_STEPPING_BUFFER_NOT_AVAILABLE: > + return DISPLACED_STEP_PREPARE_STATUS_UNAVAILABLE; > + > + case AMD_DBGAPI_STATUS_ERROR_ILLEGAL_INSTRUCTION: > + return DISPLACED_STEP_PREPARE_STATUS_CANT; > + > + default: > + error (_("amd_dbgapi_displaced_stepping_start failed (%s)"), > + get_status_string (status)); > + } > + > + /* Save the displaced stepping id in the per-inferior info. */ > + amd_dbgapi_inferior_info *info = get_amd_dbgapi_inferior_info (thread->inf); > + > + bool inserted > + = info->stepping_id_map.emplace (thread, stepping_id.handle).second; > + gdb_assert (inserted); > + > + /* Get the new (displaced) PC. */ > + status = amd_dbgapi_wave_get_info (wave_id, AMD_DBGAPI_WAVE_INFO_PC, > + sizeof (displaced_pc), &displaced_pc); > + if (status != AMD_DBGAPI_STATUS_SUCCESS) > + { > + amd_dbgapi_displaced_stepping_complete (wave_id, stepping_id); > + error (_("amd_dbgapi_wave_get_info failed (%s), could not get the " > + "thread's displaced PC."), > + get_status_string (status)); > + } > + > + displaced_debug_printf ("selected buffer at %#lx", displaced_pc); > + > + /* We may have written some registers, so flush the register cache. */ > + registers_changed_thread (thread); > + > + return DISPLACED_STEP_PREPARE_STATUS_OK; > +} > + > +displaced_step_finish_status > +amd_dbgapi_target::displaced_step_finish (thread_info *thread, > + const target_waitstatus &ws) > +{ > + if (!ptid_is_gpu (thread->ptid)) > + return beneath ()->displaced_step_finish (thread, ws); > + > + gdb_assert (thread->displaced_step_state.in_progress ()); > + > + /* Find the displaced stepping id for this thread. */ > + amd_dbgapi_inferior_info *info = get_amd_dbgapi_inferior_info (thread->inf); > + auto entry = info->stepping_id_map.extract (thread); > + > + gdb_assert (entry.has_value ()); > + amd_dbgapi_displaced_stepping_id_t stepping_id {entry->second}; > + > + /* If the thread exited while stepping, we are done. The code above > + cleared our associated resources. We don't want to call dbgapi > + below: since the thread is gone, we wouldn't be able to find the > + necessary wave ID. dbgapi already took care of releasing its > + displaced-stepping-related resources when it deleted the > + wave. */ > + if (ws.kind () == TARGET_WAITKIND_THREAD_EXITED) > + return DISPLACED_STEP_FINISH_STATUS_OK; > + > + amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (thread->ptid); > + amd_dbgapi_wave_stop_reasons_t stop_reason; > + amd_dbgapi_status_t status > + = amd_dbgapi_wave_get_info (wave_id, AMD_DBGAPI_WAVE_INFO_STOP_REASON, > + sizeof (stop_reason), &stop_reason); > + > + if (status != AMD_DBGAPI_STATUS_SUCCESS) > + error (_("wave_get_info for wave_%ld failed (%s)"), wave_id.handle, > + get_status_string (status)); > + > + status = amd_dbgapi_displaced_stepping_complete (wave_id, stepping_id); > + > + if (status != AMD_DBGAPI_STATUS_SUCCESS) > + error (_("amd_dbgapi_displaced_stepping_complete failed (%s)"), > + get_status_string (status)); > + > + /* We may have written some registers, so flush the register cache. */ > + registers_changed_thread (thread); > + > + return (stop_reason & AMD_DBGAPI_WAVE_STOP_REASON_SINGLE_STEP) != 0 > + ? DISPLACED_STEP_FINISH_STATUS_OK > + : DISPLACED_STEP_FINISH_STATUS_NOT_EXECUTED; > +} > + > /* inferior_created observer. */ > > static void > diff --git a/gdb/testsuite/gdb.rocm/displaced-stepping.exp b/gdb/testsuite/gdb.rocm/displaced-stepping.exp > new file mode 100644 > index 000000000000..6b26e1adfd7a > --- /dev/null > +++ b/gdb/testsuite/gdb.rocm/displaced-stepping.exp > @@ -0,0 +1,54 @@ > +# Copyright 2024 Free Software Foundation, Inc. Should probably 2025. > + > +# 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 . > + > +# Test displaced stepping on AMD GPUs. > + > +load_lib rocm.exp > + > +standard_testfile simple.cpp I though the usage in GDB testsuite was to not share the .cpp across multiple testcases. Should there be a displaced-stepping.cpp? > + > +require allow_hipcc_tests > + > +# Since GDB doesn't yet understand DWARF expressions generated by the HIP > +# compiler, purposefully generate the binary without debug info. > +if {[build_executable "failed to prepare" $testfile $srcfile {hip}]} { > + return > +} > + > +proc do_test {} { > + clean_restart $::binfile > + > + with_rocm_gpu_lock { > + if ![runto_main] { > + return > + } > + > + gdb_test "with breakpoint pending on -- break do_an_addition" \ > + "Breakpoint $::decimal \\(do_an_addition\\) pending." > + > + gdb_test "continue" \ > + "Thread $::decimal hit Breakpoint $::decimal, $::hex in do_an_addition.*" > + > + gdb_test_no_output "set debug displaced on" > + > + gdb_test "stepi" "displaced_step_prepare_throw: prepared successfully.*$::hex in do_an_addition.*" Just to reduce the noise in the gdb.log file when running the continue, this could be gdb_test "with debug displaced on -- stepi" ... > + > + gdb_test "continue" \ > + "Inferior 1 .* exited normally.*" \ > + "continue to end" > + } > +} > + > +do_test > -- > 2.47.1 > With those minor comments addressed, and given that it only touches amdgpu related code, Approved-By: Lancelot Six (amdgpu)