From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kmFzGSnPumpfmxMAWB0awg (envelope-from ) for ; Mon, 28 Sep 2026 16:33:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1790627625; bh=Mv87ouL52Bv7a/oSQugww2bEd4KSB1DUKqRSq/xb1xY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=D+1V5iYgqQGFuZviuNI+yW7NZDH8yWQebumZ2avnSShrGNIqzZzMFmWA71bK1l8Yz v1C/R14TZ+iKc8yMx+0qSyAmMb0XkZqaM5KyyBXxYYHIK6r6ECt4LSOf2n6v5sEnZj +AzAGnvZMStRx7235ARsycS41yVSgk6Lg21HxT38= Received: by simark.ca (Postfix, from userid 112) id 5636D1E01F; Mon, 28 Sep 2026 16:33:45 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=fiPwWlOO; dkim-atps=neutral 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 617B11E01F for ; Mon, 28 Sep 2026 16:33:44 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DEE5A4BAE7D4 for ; Mon, 28 Sep 2026 20:33:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEE5A4BAE7D4 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=fiPwWlOO Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 5E3BF4BA9002 for ; Mon, 28 Sep 2026 20:33:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E3BF4BA9002 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5E3BF4BA9002 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790627598; cv=none; b=wtGVp0FD4+SKUCike3PqEW56bANJdhtUUSGDI0U9LEiBL+lUytpL3ix6v3eGw9Wk2cEFgcb2uTKwLN6q/lLOr9TxjyLIs/5J28tmEYOuQoO7rAFICgnJUpvQnlFOW2zeGgakps5cjN2CQ+OKCp4GRzk21UjTb4O8is3vi/frSCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790627598; c=relaxed/simple; bh=Mv87ouL52Bv7a/oSQugww2bEd4KSB1DUKqRSq/xb1xY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Xd5rowcuENTmfScy25wFmrBjljsDW4PiZddCLUCkx8LwhC7ZbHL4JLsyO2km9PrKV535geaTkXB66ulaWuWOhVXBnxXYeAa0Qb10OY2tO60005Mh80po3YoDRA0Wxkg2TjziPfMMcsFtJJQJHIdBFTPgly9vQm+Qg4osRz7+Oyg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=fiPwWlOO DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E3BF4BA9002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1790627597; bh=Mv87ouL52Bv7a/oSQugww2bEd4KSB1DUKqRSq/xb1xY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=fiPwWlOO2qb17j0FM2FHadw8pZLgqJ93clzfVRvZV10/WgGRwBvGAeuginI2YMLsp 9t+yNwS7Hw99HPA+B/01hWf60gyR3at7aT7cbUNiVxz1unkS2ok7Xuz9QlZ1JdH+Gc opHssoA1iqjGXwCjz98GUZGu97+2JrjZsGdxexQQ= Received: by simark.ca (Postfix) id E88D91E01F; Mon, 28 Sep 2026 16:33:16 -0400 (EDT) Message-ID: Date: Mon, 28 Sep 2026 16:33:16 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb: Implement stop-on-solib-events for GPU code objects To: Bratislav Filipovic , gdb-patches@sourceware.org Cc: luis.machado.foss@gmail.com, Lancelot.Six@amd.com, TankutBaris.Aktemur@amd.com, pedro@palves.net References: <20260924130451.89610-1-bfilipov@amd.com> Content-Language: fr From: Simon Marchi In-Reply-To: <20260924130451.89610-1-bfilipov@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 On 9/24/26 9:04 AM, Bratislav Filipovic wrote: > GDB's "set stop-on-solib-events 1" setting allows users to stop execution > when shared libraries are loaded or unloaded, enabling inspection and > breakpoint placement before library code executes. This feature works for > CPU shared libraries but is not working for GPU code objects loaded by the > AMD ROCm runtime. > > This commit implements stop-on-solib-events support for GPU code objects, > making GPU code object load/unload events behave consistently with CPU > shared library events. > > The root cause is in amd_dbgapi_target_breakpoint::check_status(), which > unconditionally sets bs->stop = 0 and bs->print_it = print_it_noop, > regardless of the stop_on_solib_events setting. This is in contrast to > internal_breakpoint::check_status() for CPU shared libraries, which > respects the setting. > > The fix includes: > > 1. Generalize print_solib_event() function to eliminate code duplication > between CPU and GPU event printing. The function now accepts parameters > for event description, field names, and plural forms. This reduces > ~50 lines of duplicated code. > > 2. Add code_object_list_updated flag to amd_dbgapi_inferior_info to track > when AMD_DBGAPI_EVENT_KIND_CODE_OBJECT_LIST_UPDATED events occur during > process_event_queue(). This flag does not need to live in amd_dbgapi_inferior_info, since it's only needed within the duration of one amd_dbgapi_target_breakpoint::check_status call. It's not a state that needs to be persisted. Perhaps have process_event_queue return that value, so check_status can use it? process_event_queue already returns a value (amd_dbgapi_event_id_t), it could return a small struct instead. > +enum print_stop_action > +amd_dbgapi_target_breakpoint::print_it (const bpstat *bs) const > +{ > + /* We only reach here when check_status set bs->print_it to print_it_normal, > + which happens only for GPU code object events when stop_on_solib_events > + is enabled. */ > + bool any_deleted = !current_program_space->deleted_solibs.empty (); > + bool any_added = !current_program_space->added_solibs.empty (); > + > + if (any_added || any_deleted) > + current_uiout->text (_("Stopped due to GPU code object event:\n")); > + else > + current_uiout->text (_("Stopped due to GPU code object event (no " > + "code objects added or removed)\n")); > + > + if (current_uiout->is_mi_like_p ()) > + { > + current_uiout->field_string > + ("reason", async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); > + current_uiout->field_string ("object-kind", gpu_code_object_kind); > + } This (and the change in print_solib_event) adds a new field tot he stops of kind "solib-event". I think it should be documented where "solib-event" is described, in section "GDB/MI Async Records" of the documentation. > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index a24f67cb8de..2c948737720 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -22513,14 +22513,15 @@ The surrounding square brackets are optional. > @item set stop-on-solib-events > @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 (AMD ROCm targets). > +The most common events of interest are loading or unloading of a new > +shared library or 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 92b21017b03..5e00f9d653c 100644 > --- a/gdb/infrun.c > +++ b/gdb/infrun.c > @@ -10849,8 +10849,9 @@ leave it stopped or free to run as needed."), > Set stopping for shared library events."), _("\ > Show stopping for shared library events."), _("\ > If nonzero, 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 (AMD ROCm targets). The most common events of interest to the\n\ As a GDB developer, I find this documentation change a bit unnecessary, because I know that GPU code objects are (in GDB) the same as shared libraries, just with another name. But I guess it's good to be explicit, because that might not be clear to end users. But I would not mention "(AMD ROCm targets)" part (same for the documentation part above), because we want to keep the documentation of these commands fairly target-agnostic. Will the term "GPU code objects" be applicable for the Intel GPU target too? > +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 1" > + > + with_test_prefix "file://" { > + gdb_breakpoint "test_file_load" -temporary > + gdb_continue_to_breakpoint "at test_file_load" > + > + # Test 1: file:// load event (hipModuleLoad). > + gdb_test "continue" \ > + "Stopped due to GPU code object event.*Inferior loaded file://\[^\r\n\]+" \ > + "load" > + > + # Test 2: file:// unload event (hipModuleUnload). > + gdb_test "continue" \ > + "Stopped due to GPU code object event.*Inferior unloaded file://\[^\r\n\]+" \ > + "unload" > + } > + > + with_test_prefix "memory://" { > + gdb_breakpoint "test_memory_load" -temporary > + gdb_continue_to_breakpoint "at test_memory_load" > + > + # Test 3: memory:// load event (hipModuleLoadData). > + gdb_test "continue" \ > + "Stopped due to GPU code object event.*Inferior loaded memory://\[^\r\n\]+" \ > + "load" > + > + # Test 4: memory:// unload event (hipModuleUnload). > + gdb_test "continue" \ > + "Stopped due to GPU code object event.*Inferior unloaded memory://.*" \ This last line should use \[^\r\n\]+ like the other ones I guess. Simon