Use the process's comm value for GPU threads name
authorLaurent Morichetti <laurent.morichetti@amd.com>
Thu, 23 Apr 2020 17:48:20 +0000 (10:48 -0700)
committerLaurent Morichetti <laurent.morichetti@amd.com>
Wed, 6 May 2020 20:50:52 +0000 (13:50 -0700)
Instead of using the dispatched kernel's name as the thread name,
use the process's comm value.  This will match the CPU threads, and
still allow to differentiate threads from different inferiors.

Change-Id: I0746f1d4cdbdd44e9f0ea65997ca9be80ef95bb6

gdb/rocm-tdep.c

index 1897a1ec378d65187b2b6403569d5a812e1a9654..de92f5aaf2b3dd39138b99fe611a189aba79e975 100644 (file)
@@ -375,40 +375,39 @@ rocm_target_ops::thread_name (thread_info *tp)
   if (!ptid_is_gpu (tp->ptid))
     return beneath ()->thread_name (tp);
 
-  amd_dbgapi_process_id_t process_id = get_amd_dbgapi_process_id (tp->inf);
-  amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (tp->ptid);
-  amd_dbgapi_dispatch_id_t dispatch_id;
-  amd_dbgapi_global_address_t kernel_addr;
+  /* Return the process's comm value—that is, the command name associated with
+     the process.  */
 
-  if (amd_dbgapi_wave_get_info (process_id, wave_id,
-                                AMD_DBGAPI_WAVE_INFO_DISPATCH,
-                                sizeof (dispatch_id), &dispatch_id)
-          != AMD_DBGAPI_STATUS_SUCCESS
-      || amd_dbgapi_dispatch_get_info (
-             process_id, dispatch_id,
-             AMD_DBGAPI_DISPATCH_INFO_KERNEL_ENTRY_ADDRESS,
-             sizeof (kernel_addr), &kernel_addr)
-             != AMD_DBGAPI_STATUS_SUCCESS)
-    return NULL;
+  char comm_path[128];
+  xsnprintf (comm_path, sizeof (comm_path), "/proc/%ld/comm",
+             (long)tp->ptid.pid ());
 
-  struct bound_minimal_symbol msymbol
-      = lookup_minimal_symbol_by_pc_section (kernel_addr, nullptr);
+  gdb_file_up comm_file = gdb_fopen_cloexec (comm_path, "r");
+  if (!comm_file)
+    return nullptr;
 
-  if (msymbol.minsym != NULL)
-    {
-      static char buf[256];
-      char *endp;
+#if !defined(TASK_COMM_LEN)
+#define TASK_COMM_LEN 16 /* As defined in the kernel's sched.h.  */
+#endif
 
-      xsnprintf (buf, sizeof (buf), "%s", msymbol.minsym->print_name ());
+  static char comm_buf[TASK_COMM_LEN];
+  const char *comm_value;
 
-      /* Strip the arguments from the demangled function name.  */
-      if ((endp = strchr (buf, '(')))
-        *endp = '\0';
+  comm_value = fgets (comm_buf, sizeof (comm_buf), comm_file.get ());
+  comm_buf[sizeof (comm_buf) - 1] = '\0';
 
-      return buf;
+  /* Make sure there is no newline at the end.  */
+  if (comm_value)
+    {
+      for (int i = 0; i < sizeof (comm_buf); i++)
+        if (comm_buf[i] == '\n')
+          {
+            comm_buf[i] = '\0';
+            break;
+          }
     }
 
-  return NULL;
+  return comm_value;
 }
 
 std::string
This page took 0.025387 seconds and 4 git commands to generate.