コード例 #1
0
bool is_hsail_step(void)
{
  /* true if the focus thread is the debug thread */
  bool is_hsail_thread_focus_thread = hsail_infcmd_is_focus_thread_dispach_thread();

  /* currently only consider if hsail device is focused.
     TODO: check if the current frame is hsail code, etc.
  */


  /* We handle each known case of is_hsail_step individually by && all
   * required checks together to make it more cleaner
   * */

  /* GPU Stepping: Case#1
     Check if we are focused on the debug thread, we can step into
     GPU execution from here.
     Single step on the CPU happens when the debug thread is not the focus
  */
  if (  hsail_is_focus_device() &&
        is_hsail_thread_focus_thread &&
        (hsail_is_debug_facilities_loaded() == HSAIL_AGENT_BINARY_AVAILABLE)
      )
    {
	  hsail_info_command();

      return true;
    }
  /* GPU Stepping: Case#2
     Check if we are "in the predispatch" callback state, we can step into
     GPU execution from here */
  else if (  hsail_is_focus_device() &&
             hsail_is_focus_predispatch() &&
             (hsail_is_debug_facilities_loaded() == HSAIL_AGENT_BINARY_AVAILABLE)
           )
    {
	  hsail_info_command();
      return true;
    }

  return false;
}
コード例 #2
0
HwDbgInfo_debug hsail_init_hwdbginfo(HsailNotificationPayload* payload)
{
  struct ui_out *uiout = NULL;
  /* pointer to shared memory*/
  void* pShm = NULL;

  /* HwDbgFacilities objects */
  HwDbgInfo_err errout_twolevel= HWDBGINFO_E_UNEXPECTED;
  HwDbgInfo_err errout_onelevel= HWDBGINFO_E_UNEXPECTED;

  HwDbgInfo_debug dbg_op = NULL;

  const int max_shared_mem_size = hsail_get_agent_binary_shmem_max_size();

  if (payload == NULL)
    {
      /* return the cached dbgInfo there exists */
      return gs_DbgInfo;
    }

  gdb_assert(payload->m_Notification == HSAIL_NOTIFY_NEW_BINARY);

  uiout = current_uiout;
  /* Shared memory buffer pointer*/

  dbg_op = NULL;
  if(hsail_is_debug_facilities_loaded())
    {
      /* A copy of the shared memory segment )*/
      void* dbe_binary = NULL;
      size_t dbe_binary_size = 0;
      int shmid = -1;

      hsail_segment_update_loadmap();

      /*1M used is hard wired for now*/
      shmid = shmget(hsail_get_agent_binary_shmem_key(), max_shared_mem_size, 0666);

      if (shmid <= 0)
        {
          ui_out_text(uiout, "GDB: HwDbgFacilities init: shmid is invalid\n");
        }

      gdb_assert(shmid > 0);

      /* Get shm pointer */
      pShm = (int*)shmat(shmid, NULL, 0);

      if (pShm == NULL)
        {
          ui_out_text(uiout, "GDB: HwDbgFacilities init: pShm is NULL\n");
        }

      gdb_assert(pShm != NULL);

      dbe_binary_size = ((size_t*)pShm)[0];

      gdb_assert(dbe_binary_size > 0 && dbe_binary_size < max_shared_mem_size);

      dbe_binary = xmalloc(dbe_binary_size);

      gdb_assert(dbe_binary != NULL);

      memcpy(dbe_binary,(size_t*)pShm+1,dbe_binary_size);


      /* Uncomment this call if you need to save the binary to the file
      hsail_breakpoint_save_binary_to_file(dbe_binary_size, dbe_binary);
      */

      /* Attempt to initialize as a HSAIL backend binary*/
      dbg_op = hwdbginfo_init_with_hsa_1_0_binary(dbe_binary,
                                                  dbe_binary_size,
                                                  &errout_twolevel);

      /* Keep this printf here as a reminder for a
       * quick way to check that the IPC happened correctly*/
      /*
      int i = 0;
      for(i = 0; i<10;i++)
        {
          printf("%d \t %d\n",i,*((int*)dbe_binary + i));
        } */

      /* If we get a no HL binary, return code, we try to initialize as a single level binary */
      if (errout_twolevel == HWDBGINFO_E_NOHLBINARY)
        {
          /*
          dbg_op = hwdbginfo_init_with_single_level_binary(dbe_binary,
                                                           dbe_binary_size,
                                                           &errout_onelevel);
          */
          dbg_op = NULL;
        }

      /*
       * In the near future, debug facilities needs to be able to tell the difference
       * between an incomplete 2 level code object and a complete 1 level code object.
       * Since we dont support debugging LC for 1.3, this is not a big issue.
       *  */

      /* If we have a single level binary, thats good, we dont need to check the
       * two level return code */
      if (errout_twolevel == HWDBGINFO_E_NOHLBINARY && errout_onelevel == HWDBGINFO_E_SUCCESS)
        {
          fflush(stdout);
        }
      else if (errout_twolevel != HWDBGINFO_E_SUCCESS )
        {
          /* HwDbgFacilities init: Called DebugFacilities Incorrectly.
           * We can add more detailed messages such as low-level dwarf or high level dwarf missing in the future
           * */
          ui_out_text(uiout, "[ROCm-gdb]: The code object for the current dispatch does not contain debug information\n");
          fflush(stdout);

          dbg_op = NULL;

        }


      /* Test function to print all the mapped addresses and line numbers */
      /* hsail_dbginfo_test_all_mapped_addrs(dbg_op); */

      /* We can clear the dbe_binary buffer once we have initialized HWDbgFacilities */
      if (dbe_binary != NULL)
        {
          free_current_contents(&dbe_binary);
        }


      /* Get the kernel source, only if the 2 level initialization was good*/
      if (errout_twolevel == HWDBGINFO_E_SUCCESS)
        {
          if (!hsail_dbginfo_init_source_buffer(dbg_op))
          {
            ui_out_text(uiout, "[ROCm-gdb]: HwDbgFacilities get hsail text error\n");
          }
        }

      /* Detach shared memory */
      if (shmdt(pShm) == -1)
        {
          ui_out_text(uiout, "GDB: HwDbgFacilities init: Error detaching shm\n");
        }

    }

  /* cache the dgbInfo */
  gs_DbgInfo = dbg_op;

  return gs_DbgInfo;
  /*
   * This function's caller will use the returned context to query the
   * Debug Facilities API */
}