From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id nyFcAQ8G/2r/QCAAWB0awg (envelope-from ) for ; Thu, 19 Nov 2026 09:22:07 -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=26CAsMUo; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DB3CF1E0BC; Thu, 19 Nov 2026 09:22:06 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 C664E1E023 for ; Thu, 19 Nov 2026 09:22:04 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D45034BA2E2C for ; Thu, 19 Nov 2026 14:22:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D45034BA2E2C 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=26CAsMUo Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazlp170100001.outbound.protection.outlook.com [IPv6:2a01:111:f403:c105::1]) by sourceware.org (Postfix) with ESMTPS id C51E94BA2E05 for ; Thu, 19 Nov 2026 14:21:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C51E94BA2E05 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 C51E94BA2E05 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c105::1 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1795098093; cv=pass; b=OLdoWo9+sCkRS9K0bWzoaek0dTAXo6lrfvi4/I5HT+4M2sarMKl86yhbocnePKDqORQb6NzDPZdnDrHplElimHW/VWYN1tQ4lCM8n5dcxxvf6KjLfp36cha1MMgihUFvtD4+QoSDqjHGfb15D7WlfOo9kKjQMSLGvScc2Mew0BQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1795098093; c=relaxed/simple; bh=31J3K1FbV26KVn/9Dv9wpBbGGhnZkRNrAeMpz7w6WYI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KNRSO/1Dm5ol0zR0w8YogleAyh0pzre3MnIDOGRo2NllRlNSoi0aetgbE9iy0MgvfLrUm98/dJbcZMwzypgX4Wz++gFQGAjY4pb0zCzNsX6OpO/sz4nj+GNxa1TTh7C+P88hHN0qD+LJQ60mHgOaEo7iQPcsocm7DjRIViaexZc= ARC-Authentication-Results: i=2; 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=26CAsMUo DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C51E94BA2E05 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SPm4B7M1mHknv/5zk+hsbt0O0RzLqjBCsM+9LbamXMlAbb6OhyXCkdEOhWQ3gn0+Db9Ya2MXUxBzw89WklHuEl70j+pl1BWj4nvQNAy6iuJRzDNlfPYYZ3l4naDkA25VGioeVW8fFSoxblOH0NREdMWmkNl8ky29e/pIP4jDtbuur2AIlZnsSZL1dz6LXhk9GIgl4yMwXi9cRt3Xzer4roLt2CSXJhIQhbM3ZZ+uixXtFw0YkNjbSIBo7KtJpthoOkNSP4HemNFXjZ8y8ic1ijrTsnn1dkR7AI5IYPxu4Jc+EmH+XnhUrKpLA0VCe0xuLfzrqe/EejSWZGwIWCRNCw== 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=bALGCXQisHbetIsdD7D0I8pJs4M3z1q8ao0Ozn0VnSI=; b=cb0rFGL2rAqvZAlSUndivy9qh7GA+llAKDFuGmXsXpLpk/BKL8l3fD/naFEWAlFp2HeTqifDb7MLIHEjJ78OmJ+K10y8wxBQk2cs3aqFegaPx/fe9RN1ZmcV+q7sDUEuxD3uik94lJ6JPSYdn4cuffLzQ62OCbJDrKwSQfsCc0PTucycxI9Tj6FDqTyeQcH12XpFZIDZGX58GW1QBcTHtcGmbENy2iLXg3fXImj4UN5pzxSZJy95kYKffsy1GoDeuXn24UDjXfUOUFP6KPdZVeRpa7jrzgrTCirTagNGGaxecOuM6CLWZGky3aGKRwFpWd95Ny5uoYVyDSVxEqTm9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=bALGCXQisHbetIsdD7D0I8pJs4M3z1q8ao0Ozn0VnSI=; b=26CAsMUokae57LM8d24wBFsldcFX1gYusvumbh0JALLMHcgF/WvHt7a+Fu52AAh6F0OZDANpVnDPkPTeq7GmAfX5hOXJGwn4RR/J5uGm3653C3WlBrp169UbC229BFdqoklh7A0JG42pzKph7VIe+Faln7Rkpu0ASjT1CVFe/bI= Received: from PH8PR07CA0022.namprd07.prod.outlook.com (2603:10b6:510:2cd::21) by SJ1PR12MB6361.namprd12.prod.outlook.com (2603:10b6:a03:455::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.615.14; Thu, 19 Nov 2026 14:21:19 +0000 Received: from BY1PEPF00026969.namprd05.prod.outlook.com (2603:10b6:510:2cd:cafe::2c) by PH8PR07CA0022.outlook.office365.com (2603:10b6:510:2cd::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.615.10 via Frontend Transport; Thu, 19 Nov 2026 14:21:19 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BY1PEPF00026969.mail.protection.outlook.com (10.167.244.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.639.5 via Frontend Transport; Thu, 19 Nov 2026 14:21:18 +0000 Received: from RSBBFILIPOV02.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 19 Nov 2026 08:21:17 -0600 From: Bratislav Filipovic To: CC: , Subject: [PATCH v5] gdb: Implement stop-on-solib-events for GPU code objects Date: Thu, 19 Nov 2026 15:09:57 +0100 Message-ID: <20261119142057.58123-1-bfilipov@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY1PEPF00026969:EE_|SJ1PR12MB6361:EE_ X-MS-Office365-Filtering-Correlation-Id: 08128f31-3477-473f-70a1-08df4648611e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|23010399003|36860700016|82310400026|261026121527099003|10067099003|261026140227099003|5023799004|56012099006|11063799006|261021123027099003|261022075727099003|261021121427099003|261022105027099003|261028144727099003|261102123227099003|22082099003|18002099003|6133799003|13003099007|3023799007|261009223027099003; X-Microsoft-Antispam-Message-Info: pIjtLKlc2fx17InmugQCl9KysBmTvV5qXEOOK7xpsapDw/yoXc+kBJZD+DUuPeFSd+nqyItsEmcHEVHdUJDPTVtl85WhQbIGUlk7QPXZycghLICDrJnRD2/N6xOGLYP0E9KxI3kMO3UpbR8bucKVshYJUhUk6W0YZuNnYAyG5dRBmqEV6Lx9W9IPE3C/cVnLmff8gNTUWjw1gJtnyv/FCTbrcaeKle58SPtQ7T8rcJzkxym2ysifkcxRvf6SWveMpXTp7x81aP4kVIXc8fLqAsZXQ4hsXnY85u9f2IZHxAJmGuvvL7/CN0TxP/zjPlnZNkOX4aq6ONRRJ2VFPPPk/hzi5G5JxvwgsGuM80HePFrt0IQMi+PUxryw/fsYSyPsZqw9i86fbzjr8aKRUSxQhpZh+d2II/RXWeQvpoz9l+rxFqAxHz3WoNHYsMncLERElQAmEfhcTpah55/dbYrlmlR2JCBmAgsEdZUKvyBZoY8w5UvlcecUMKNiKoxBwD5hqdFxk1OoHxBczSJJitaoqS2i+4MS205Djt0xPPXLRtEz8If5gUAB2zi/gD72EPxL4aSjSx+N7RGxICNWop3wDqltz61JxTeTIAHjrHy7h1NPbEzKmPc7Ef9U/BKwonRGLz2aNWXAGNgZihy3jLtM7W1O07wmR6pSvoDxX+59dgE= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(376014)(23010399003)(36860700016)(82310400026)(261026121527099003)(10067099003)(261026140227099003)(5023799004)(56012099006)(11063799006)(261021123027099003)(261022075727099003)(261021121427099003)(261022105027099003)(261028144727099003)(261102123227099003)(22082099003)(18002099003)(6133799003)(13003099007)(3023799007)(261009223027099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /SBcJQ4yIEGlzjhbb6lsFmLGDbQdEqc8AcRj78oMhbk4BkP8QdCjtlZTvPgxEmtLh8Z3f0Dm6gvXMU1s6dAsEKipdW60m4jDEt/5KqMHSO3G0rhd0QmuEA199hXgVikR8e98HDcq+DXkTmPGJIlvY7pRkMLCE0vijCUD6kegeXh6PMBjKdqoXLafVr7nWKpHx6rNqjfw+Jjr5h1wfz2TqzFHQ6fkd9BsdGWTbGrLjY0yHrCI2Xci8rxWF6t+LBvQAgxi3AZ/WwJV1xdkCkh1u2TYAXS1ZE7a9A3byCsjCWp6mX4a94EELJN8/eXQFHB53aLQnmQbkHBaP7xCGLF7oVIWk1WzSKl0++f1ORlQfDG4tFR5rwmPk0FhBX699KOLxanf2774ko11PMMK9Se+mg8b4rzoVUefDYrqe/WJ/siMXlSt1+Gk0O3K+ShUTHkK X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2026 14:21:18.9481 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 08128f31-3477-473f-70a1-08df4648611e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BY1PEPF00026969.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6361 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 GDB's "set stop-on-solib-events" setting allows users to stop execution when shared libraries are loaded or unloaded, enabling inspection and breakpoint placement before library code executes. This works for CPU shared libraries, but has no effect on GPU code objects loaded by the AMD ROCm runtime, even though those are reported as shared libraries (e.g. in "info sharedlibrary"). The reason is that amd_dbgapi_target_breakpoint::check_status unconditionally sets bs->stop to 0. This is in contrast to internal_breakpoint::check_status for CPU shared libraries, which honors stop_on_solib_events. Fix this by having process_event_queue report whether a CODE_OBJECT_LIST_UPDATED event was processed while draining the event queue. check_status then sets bs->stop and bs->print the same way internal_breakpoint::check_status does for bp_shlib_event breakpoints. It no longer sets bs->print_it to print_it_noop: bpstat_stop_status already does that when the breakpoint does not stop. A print_it override reports the stop through print_solib_event, so the stop is presented like a CPU shared library event, both in the CLI ("Stopped due to shared library event") and in MI (*stopped,reason="solib-event"). "catch load" and "catch unload" catchpoints are not affected by this change and still do not trigger for GPU code objects. Add gdb.rocm/solib-event.exp, which tests both file:// code objects (hipModuleLoad) and memory:// code objects (hipModuleLoadData), their unload events, that nothing stops when the setting is off, and the MI stop record. --- Changes in v5 (addressing Lancelot's review of v4): - Drop the CPU/GPU-specific messages: breakpoint.{c,h} and break-catch-load.c are no longer touched. GPU code object events now print "Stopped due to shared library event", like CPU ones. - Remove the leftover object-kind paragraph from the MI documentation. - Fix the print_it comment; process_one_event is unchanged and process_event_queue sets code_object_list_updated itself. - check_status now mirrors internal_breakpoint::check_status. - Test: empty kernel body (no inline asm), unambiguous end-of-test marker, remove the test_file_load/test_memory_load breakpoints, use the default MI version, simplify the MI solib-event check. - Rebased on current master; the int -> bool change for stop_on_solib_events is now upstream and is no longer part of this patch. Tested on gfx90a: gdb.rocm/solib-event.exp, gdb.base/catch-load.exp, gdb.mi/mi-catch-load.exp. gdb/NEWS | 5 + gdb/amd-dbgapi-target.c | 47 +++++- gdb/doc/gdb.texinfo | 9 +- gdb/infrun.c | 5 +- gdb/testsuite/gdb.rocm/solib-event-kernel.cpp | 26 +++ gdb/testsuite/gdb.rocm/solib-event.cpp | 105 ++++++++++++ gdb/testsuite/gdb.rocm/solib-event.exp | 155 ++++++++++++++++++ 7 files changed, 340 insertions(+), 12 deletions(-) create mode 100644 gdb/testsuite/gdb.rocm/solib-event-kernel.cpp create mode 100644 gdb/testsuite/gdb.rocm/solib-event.cpp create mode 100644 gdb/testsuite/gdb.rocm/solib-event.exp diff --git a/gdb/NEWS b/gdb/NEWS index db3fa820df1..e9335955b1a 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -7,6 +7,11 @@ Support displaying and modifying Intel APX registers (Extended GPRs $r16 - $r31) including byte, word and dword pseudo registers. +* The 'set stop-on-solib-events' setting now applies to GPU code objects + loaded by the AMD ROCm runtime, in addition to CPU shared libraries. + When enabled, GDB will stop execution whenever GPU code objects are + loaded or unloaded, allowing inspection and breakpoint placement. + * GDB now distinguishes between the GNU (MinGW) and MSVC Windows ABIs. The "set osabi" command accepts two new values, "Windows-GNU" and diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c index a38a8bafb90..bbb6b633a44 100644 --- a/gdb/amd-dbgapi-target.c +++ b/gdb/amd-dbgapi-target.c @@ -30,6 +30,7 @@ #include "gdbsupport/unordered_map.h" #include "inf-loop.h" #include "inferior.h" +#include "infrun.h" #include "objfiles.h" #include "observable.h" #include "registry.h" @@ -275,7 +276,17 @@ struct amd_dbgapi_inferior_info wave_info_map; }; -static amd_dbgapi_event_id_t process_event_queue +/* Return value for process_event_queue. */ +struct process_event_queue_result +{ + /* The event ID, or AMD_DBGAPI_EVENT_NONE if no event was found. */ + amd_dbgapi_event_id_t event_id; + + /* True if a CODE_OBJECT_LIST_UPDATED event was seen during processing. */ + bool code_object_list_updated; +}; + +static process_event_queue_result process_event_queue (amd_dbgapi_inferior_info &info, amd_dbgapi_event_kind_t until_event_kind = AMD_DBGAPI_EVENT_KIND_NONE); @@ -587,6 +598,7 @@ struct amd_dbgapi_target_breakpoint : public code_breakpoint void re_set (program_space *) override; void check_status (struct bpstat *bs) override; + enum print_stop_action print_it (const bpstat *bs) const override; }; void @@ -603,7 +615,6 @@ amd_dbgapi_target_breakpoint::check_status (struct bpstat *bs) amd_dbgapi_status_t status; bs->stop = 0; - bs->print_it = print_it_noop; /* Find the address the breakpoint is set at. */ auto match_breakpoint @@ -639,7 +650,7 @@ amd_dbgapi_target_breakpoint::check_status (struct bpstat *bs) /* If the action is AMD_DBGAPI_BREAKPOINT_ACTION_HALT, we need to wait until a breakpoint resume event for this breakpoint_id is seen. */ - amd_dbgapi_event_id_t resume_event_id + auto [resume_event_id, code_object_list_updated] = process_event_queue (info, AMD_DBGAPI_EVENT_KIND_BREAKPOINT_RESUME); /* We should always get a breakpoint_resume event after processing all @@ -665,6 +676,23 @@ amd_dbgapi_target_breakpoint::check_status (struct bpstat *bs) pulongest (resume_breakpoint_id.handle)); amd_dbgapi_event_processed (resume_event_id); + + /* If the code object list was updated, stop if the user requested to + stop on shared library events, as internal_breakpoint::check_status + does for bp_shlib_event breakpoints. */ + bs->stop = code_object_list_updated && stop_on_solib_events; + bs->print = bs->stop; +} + +enum print_stop_action +amd_dbgapi_target_breakpoint::print_it (const bpstat *bs) const +{ + /* This is only called if check_status decided to stop, which happens + when the code object list was updated while stop_on_solib_events is + enabled. Report it the same way as a shared library event. */ + print_solib_event (false); + + return PRINT_NOTHING; } bool @@ -1645,9 +1673,11 @@ event_kind_str (amd_dbgapi_event_kind_t kind) /* Drain the dbgapi event queue of a given inferior. Stop processing the events if an event of a given kind is requested (not AMD_DBGAPI_EVENT_NONE). Wave stop events that are not returned are queued into their inferior's - amd_dbgapi_inferior_info pending wave events. */ + amd_dbgapi_inferior_info pending wave events. The code_object_list_updated + field of the result is true if a CODE_OBJECT_LIST_UPDATED event was + processed. */ -static amd_dbgapi_event_id_t +static process_event_queue_result process_event_queue (amd_dbgapi_inferior_info &info, amd_dbgapi_event_kind_t until_event_kind) { @@ -1655,6 +1685,8 @@ process_event_queue (amd_dbgapi_inferior_info &info, performance, make sure it is not required. */ gdb_assert (!info.forward_progress_required); + bool code_object_list_updated = false; + while (true) { amd_dbgapi_event_id_t event_id; @@ -1675,7 +1707,10 @@ process_event_queue (amd_dbgapi_inferior_info &info, event_kind_str (event_kind)); if (event_id == AMD_DBGAPI_EVENT_NONE || event_kind == until_event_kind) - return event_id; + return {event_id, code_object_list_updated}; + + if (event_kind == AMD_DBGAPI_EVENT_KIND_CODE_OBJECT_LIST_UPDATED) + code_object_list_updated = true; process_one_event (info, event_id, event_kind); } diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 7998dfb58c8..64a91e6a5c1 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -22536,14 +22536,15 @@ The surrounding square brackets are optional. @item set stop-on-solib-events @r{[}on@r{|}off@r{]} @kindex set stop-on-solib-events This command controls whether @value{GDBN} should give you control -when the dynamic linker notifies it about some shared library event. -The most common event of interest is loading or unloading of a new -shared library. +when the dynamic linker notifies it about some shared library event, +or when GPU code objects are loaded or unloaded. +The most common events of interest are loading or unloading of a new +shared library or GPU code object. @item show stop-on-solib-events @kindex show stop-on-solib-events Show whether @value{GDBN} stops and gives you control when shared -library events happen. +library events or GPU code object events happen. @end table Shared libraries are also supported in many cross or remote debugging diff --git a/gdb/infrun.c b/gdb/infrun.c index 08fac30e9e8..432c2eb27ae 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -10851,8 +10851,9 @@ leave it stopped or free to run as needed."), Set stopping for shared library events."), _("\ Show stopping for shared library events."), _("\ If on, gdb will give control to the user when the dynamic linker\n\ -notifies gdb of shared library events. The most common event of interest\n\ -to the user would be loading/unloading of a new library."), +notifies gdb of shared library events, or when GPU code objects are loaded\n\ +or unloaded. The most common events of interest to the user would be\n\ +loading/unloading of a new library or GPU code object."), set_stop_on_solib_events, show_stop_on_solib_events, &setlist, &showlist); diff --git a/gdb/testsuite/gdb.rocm/solib-event-kernel.cpp b/gdb/testsuite/gdb.rocm/solib-event-kernel.cpp new file mode 100644 index 00000000000..3e1c895f95e --- /dev/null +++ b/gdb/testsuite/gdb.rocm/solib-event-kernel.cpp @@ -0,0 +1,26 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 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 . */ + +/* Device kernel for solib-event test. + Compiled with --cuda-device-only to produce .co file. */ + +#include + +extern "C" __global__ void +test_kernel () +{ +} diff --git a/gdb/testsuite/gdb.rocm/solib-event.cpp b/gdb/testsuite/gdb.rocm/solib-event.cpp new file mode 100644 index 00000000000..161c7c15b17 --- /dev/null +++ b/gdb/testsuite/gdb.rocm/solib-event.cpp @@ -0,0 +1,105 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 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 "rocm-test-utils.h" +#include +#include +#include + +/* Test file:// events (hipModuleLoad). */ +static void +test_file_load (const char *module_path) +{ + hipModule_t module; + CHECK (hipModuleLoad (&module, module_path)); + + hipFunction_t function; + CHECK (hipModuleGetFunction (&function, module, "test_kernel")); + + CHECK (hipModuleLaunchKernel (function, 1, 1, 1, 1, 1, 1, + 0, nullptr, nullptr, nullptr)); + + CHECK (hipDeviceSynchronize ()); + CHECK (hipModuleUnload (module)); +} + +/* Test memory:// events (hipModuleLoadData). */ +static void +test_memory_load (const char *module_path) +{ + /* Read module file into memory buffer. */ + std::ifstream mod (module_path, std::ios::binary | std::ios::ate); + if (!mod.is_open ()) + { + fprintf (stderr, "Failed to open module file\n"); + exit (EXIT_FAILURE); + } + + size_t module_size = mod.tellg (); + mod.seekg (0, std::ios::beg); + std::vector module_buffer (module_size); + + if (!mod.read (reinterpret_cast (module_buffer.data ()), + module_size)) + { + fprintf (stderr, "Failed to read module into memory\n"); + exit (EXIT_FAILURE); + } + mod.close (); + + /* Load from memory buffer. */ + hipModule_t module; + CHECK (hipModuleLoadData (&module, module_buffer.data ())); + + hipFunction_t function; + CHECK (hipModuleGetFunction (&function, module, "test_kernel")); + + CHECK (hipModuleLaunchKernel (function, 1, 1, 1, 1, 1, 1, + 0, nullptr, nullptr, nullptr)); + + CHECK (hipDeviceSynchronize ()); + CHECK (hipModuleUnload (module)); +} + +__global__ void +warm_up () +{ +} + +int +main (int argc, char **argv) +{ + if (argc != 2) + { + fprintf (stderr, "Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + + const char *module_path = argv[1]; + + /* Submit an empty kernel to force the runtime to do any necessary + setup which might include loading internal code objects. */ + warm_up<<<1, 1>>>(); + CHECK (hipDeviceSynchronize ()); + + /* Enable SOLIB events here. */ + + test_file_load (module_path); + test_memory_load (module_path); + + return 0; /* Break here at end of test. */ +} diff --git a/gdb/testsuite/gdb.rocm/solib-event.exp b/gdb/testsuite/gdb.rocm/solib-event.exp new file mode 100644 index 00000000000..0fde181c5cb --- /dev/null +++ b/gdb/testsuite/gdb.rocm/solib-event.exp @@ -0,0 +1,155 @@ +# Copyright 2026 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 . + +# Test that "set stop-on-solib-events on" works for GPU code objects. +# Tests both file:// events (hipModuleLoad) and memory:// events +# (hipModuleLoadData), as well as unload events (hipModuleUnload). +# Also tests that the default setting (off) does not stop execution, +# and that the MI stop record reports a solib-event. + +load_lib rocm.exp +load_lib mi-support.exp + +require allow_hip_tests + +standard_testfile .cpp + +# Build GPU code object. +set kernel_srcfile ${testfile}-kernel.cpp +set hipmodule_path [standard_output_file ${testfile}.co] + +if {[gdb_compile $srcdir/$subdir/$kernel_srcfile \ + $hipmodule_path object \ + {debug hip additional_flags=--cuda-device-only}] != ""} { + return +} + +# Build host executable. +if {[build_executable "failed to prepare" $testfile $srcfile \ + {debug hip}] == -1} { + return +} + +proc test_disabled {} { + with_rocm_gpu_lock { + clean_restart $::testfile + + if {![runto_main -inferior-args $::hipmodule_path]} { + return + } + + # Set breakpoint at program exit and verify execution continues + # through all code object load/unload events without stopping. + gdb_breakpoint [gdb_get_line_number "Break here at end of test"] + gdb_test "continue" \ + "Breakpoint .* main .*Break here at end of test.*" \ + "no stops for code object events when disabled" + } +} + +proc test_enabled {} { + with_rocm_gpu_lock { + clean_restart $::testfile + + if {![runto_main -inferior-args $::hipmodule_path]} { + return + } + + gdb_breakpoint [gdb_get_line_number "Enable SOLIB events here"] \ + -temporary + gdb_continue_to_breakpoint "at enable solib-event" + + gdb_test_no_output "set stop-on-solib-events on" + + with_test_prefix "file://" { + # Test 1: file:// load event (hipModuleLoad). + gdb_test "continue" \ + "Stopped due to shared library event.*Inferior loaded file://\[^\r\n\]+" \ + "load" + + # Test 2: file:// unload event (hipModuleUnload). + gdb_test "continue" \ + "Stopped due to shared library event.*Inferior unloaded file://\[^\r\n\]+" \ + "unload" + } + + with_test_prefix "memory://" { + # Test 3: memory:// load event (hipModuleLoadData). + gdb_test "continue" \ + "Stopped due to shared library event.*Inferior loaded memory://\[^\r\n\]+" \ + "load" + + # Test 4: memory:// unload event (hipModuleUnload). + gdb_test "continue" \ + "Stopped due to shared library event.*Inferior unloaded memory://\[^\r\n\]+" \ + "unload" + } + } +} + +proc test_mi_output {} { + with_rocm_gpu_lock { + if {[mi_clean_restart $::testfile]} { + return + } + + # Set inferior arguments before running to main. + mi_gdb_test "-gdb-set args $::hipmodule_path" "\\^done" \ + "set inferior arguments" + + if {![mi_runto_main]} { + return + } + + mi_create_breakpoint [gdb_get_line_number "Enable SOLIB events here"] \ + "insert breakpoint at enable marker" + + mi_execute_to "exec-continue" "breakpoint-hit" "main" ".*" \ + ".*$::srcfile" [gdb_get_line_number "test_file_load (module_path);"] \ + {"" "disp=\"keep\""} "stop at enable marker" + + mi_gdb_test "111-gdb-set stop-on-solib-events on" "111\\^done" \ + "set stop-on-solib-events via MI" + + # The file:// code object load must be reported as a solib-event + # stop. The stop record is preceded by =library-loaded and console + # output, which the unanchored pattern skips. + mi_send_resuming_command "exec-continue" "continue to GPU load event" + + gdb_expect { + -re "\\*stopped,reason=\"solib-event\",added=\\\[library=\"file://\[^\r\n\]*\r\n$::mi_gdb_prompt$" { + pass "solib-event stop" + } + -re "$::mi_gdb_prompt$" { + fail "solib-event stop" + } + timeout { + fail "solib-event stop (timeout)" + } + } + } +} + +with_test_prefix "stop-on-solib-events=off" { + test_disabled +} + +with_test_prefix "stop-on-solib-events=on" { + test_enabled +} + +with_test_prefix "MI output" { + test_mi_output +} base-commit: 20a3bfdbee7e4615e96d779744e25e272beb1f4c -- 2.43.0