[binutils-gdb] gdb, amd-dbgapi-target: split wave_coordinates::to_string

Tankut Baris Aktemur via Gdb-cvs <[email protected]> Mon, 6 Jul 2026 10:49:19 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=57f5450b760afbc0c0cdf70f602cf02a513123d3

commit 57f5450b760afbc0c0cdf70f602cf02a513123d3
Author: Tankut Baris Aktemur <[email protected]>
Date:   Mon Jul 6 05:33:04 2026 -0500

    gdb, amd-dbgapi-target: split wave_coordinates::to_string
    
    wave_coordinates::to_string() produces a string in the following format:
    
      AMDGPU Wave a:q:d:w (x,y,z)/i
    
    Split the method into smaller pieces:
    
      a:q:d:w   : hierarchy_str
      (x,y,z)   : workgroup_coord_str
      (x,y,z)/i : dispatch_pos_str
    
    This is a refactoring to allow reusing pieces and also to let the code
    document itself better.  Currently the reuse opportunity exists in the
    downstream debugger.
    
    Approved-By: Simon Marchi <[email protected]>
    Approved-by: Lancelot Six <[email protected]> (amdgpu)

Diff:
---
 gdb/amd-dbgapi-target.c | 56 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 45 insertions(+), 11 deletions(-)

diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c
index 6f71f5ff5d0..f273d5076bd 100644
--- a/gdb/amd-dbgapi-target.c
+++ b/gdb/amd-dbgapi-target.c
@@ -147,6 +147,17 @@ struct wave_coordinates
     : wave_id (wave_id)
   {}
 
+  /* Return the string showing the agent -> queue -> dispatch -> wave
+     hierarchy.  */
+  std::string hierarchy_str () const;
+
+  /* Return the workgroup coordinates as a string.  */
+  std::string workgroup_coord_str () const;
+
+  /* Return the dispatch position string for the wave this
+     wave_coordinates is for.  */
+  std::string dispatch_pos_str () const;
+
   /* Return the target ID string for the wave this wave_coordinates is
      for.  */
   std::string to_string () const;
@@ -387,13 +398,12 @@ get_amd_dbgapi_inferior_info (inferior *inferior)
 static async_event_handler *amd_dbgapi_async_event_handler = nullptr;
 
 std::string
-wave_coordinates::to_string () const
+wave_coordinates::hierarchy_str () const
 {
-  std::string str = "AMDGPU Wave";
-
-  str += (agent_id != AMD_DBGAPI_AGENT_NONE
-	  ? string_printf (" %s", pulongest (agent_id.handle))
-	  : " ?");
+  std::string str
+    = (agent_id != AMD_DBGAPI_AGENT_NONE
+       ? string_printf (" %s", pulongest (agent_id.handle))
+       : "?");
 
   str += (queue_id != AMD_DBGAPI_QUEUE_NONE
 	  ? string_printf (":%s", pulongest (queue_id.handle))
@@ -405,12 +415,25 @@ wave_coordinates::to_string () const
 
   str += string_printf (":%s", pulongest (wave_id.handle));
 
-  str += (group_ids[0] != UINT32_MAX
-	  ? string_printf (" (%s,%s,%s)", pulongest (group_ids[0]),
-			   pulongest (group_ids[1]),
-			   pulongest (group_ids[2]))
-	  : " (?,?,?)");
+  return str;
+}
+
+std::string
+wave_coordinates::workgroup_coord_str () const
+{
+  std::string str
+    = (group_ids[0] != UINT32_MAX
+       ? string_printf (" (%s,%s,%s)", pulongest (group_ids[0]),
+			pulongest (group_ids[1]), pulongest (group_ids[2]))
+       : "(?,?,?)");
 
+  return str;
+}
+
+std::string
+wave_coordinates::dispatch_pos_str () const
+{
+  std::string str = workgroup_coord_str ();
   str += (wave_in_group != UINT32_MAX
 	  ? string_printf ("/%s", pulongest (wave_in_group))
 	  : "/?");
@@ -418,6 +441,17 @@ wave_coordinates::to_string () const
   return str;
 }
 
+std::string
+wave_coordinates::to_string () const
+{
+  std::string str = "AMDGPU Wave";
+
+  str += " " + hierarchy_str ();
+  str += " " + dispatch_pos_str ();
+
+  return str;
+}
+
 /* Read in wave_info for WAVE_ID.  */
 
 void