91#define amd_dbgapi_debug_printf(fmt, ...) \
92 debug_prefixed_printf_cond (debug_amd_dbgapi, \
93 amd_dbgapi_debug_module (), \
98#define AMD_DBGAPI_SCOPED_DEBUG_START_END(fmt, ...) \
99 scoped_debug_start_end (debug_infrun, amd_dbgapi_debug_module (), \
106const gdb::observers::token &
114#define AMDGPU_MAX_REGISTER_SIZE 256
121 bool precise_memory_requested =
false)
131 amd_dbgapi_process_id_t
process_id = AMD_DBGAPI_PROCESS_NONE;
137 amd_dbgapi_runtime_state_t
runtime_state = AMD_DBGAPI_RUNTIME_STATE_UNLOADED;
157 std::unordered_map<
decltype (amd_dbgapi_breakpoint_id_t::handle),
166 (amd_dbgapi_process_id_t process_id,
167 amd_dbgapi_event_kind_t until_event_kind = AMD_DBGAPI_EVENT_KIND_NONE);
171 N_(
"AMD Debugger API"),
172 N_(
"GPU debugging using the AMD Debugger API")
190 void close ()
override;
198 void resume (ptid_t,
int,
enum gdb_signal)
override;
200 void stop (ptid_t ptid)
override;
211 std::string
pid_to_str (ptid_t ptid)
override;
220 const char *annex, gdb_byte *readbuf,
221 const gdb_byte *writebuf,
222 ULONGEST offset, ULONGEST len,
223 ULONGEST *xfered_len)
override;
264 amd_dbgapi_dispatch_id_t dispatch_id;
265 amd_dbgapi_queue_id_t queue_id;
266 amd_dbgapi_agent_id_t agent_id;
267 uint32_t group_ids[3], wave_in_group;
268 std::string str =
"AMDGPU Wave";
270 amd_dbgapi_status_t
status
271 = amd_dbgapi_wave_get_info (wave_id, AMD_DBGAPI_WAVE_INFO_AGENT,
272 sizeof (agent_id), &agent_id);
273 str += (
status == AMD_DBGAPI_STATUS_SUCCESS
274 ? string_printf (
" %ld", agent_id.handle)
277 status = amd_dbgapi_wave_get_info (wave_id, AMD_DBGAPI_WAVE_INFO_QUEUE,
278 sizeof (queue_id), &queue_id);
279 str += (
status == AMD_DBGAPI_STATUS_SUCCESS
280 ? string_printf (
":%ld", queue_id.handle)
283 status = amd_dbgapi_wave_get_info (wave_id, AMD_DBGAPI_WAVE_INFO_DISPATCH,
284 sizeof (dispatch_id), &dispatch_id);
285 str += (
status == AMD_DBGAPI_STATUS_SUCCESS
286 ? string_printf (
":%ld", dispatch_id.handle)
289 str += string_printf (
":%ld", wave_id.handle);
291 status = amd_dbgapi_wave_get_info (wave_id,
292 AMD_DBGAPI_WAVE_INFO_WORKGROUP_COORD,
293 sizeof (group_ids), &group_ids);
294 str += (
status == AMD_DBGAPI_STATUS_SUCCESS
295 ? string_printf (
" (%d,%d,%d)", group_ids[0], group_ids[1],
299 status = amd_dbgapi_wave_get_info
300 (wave_id, AMD_DBGAPI_WAVE_INFO_WAVE_NUMBER_IN_WORKGROUP,
301 sizeof (wave_in_group), &wave_in_group);
302 str += (
status == AMD_DBGAPI_STATUS_SUCCESS
303 ? string_printf (
"/%d", wave_in_group)
349 if (ptid != minus_one_ptid &&
inf->
pid != ptid.pid ())
354 if (info->process_id == AMD_DBGAPI_PROCESS_NONE)
358 if (info->forward_progress_required == require)
361 amd_dbgapi_status_t
status
362 = amd_dbgapi_process_set_progress
363 (info->process_id, (require
364 ? AMD_DBGAPI_PROGRESS_NORMAL
365 : AMD_DBGAPI_PROGRESS_NO_FORWARD));
366 gdb_assert (
status == AMD_DBGAPI_STATUS_SUCCESS);
368 info->forward_progress_required = require;
372 if (ptid != minus_one_ptid)
379amd_dbgapi_process_id_t
418 amd_dbgapi_status_t
status;
424 auto match_breakpoint
425 = [bs] (
const decltype (info->breakpoint_map)::value_type &
value)
428 = std::find_if (info->breakpoint_map.begin (), info->breakpoint_map.end (),
431 if (it == info->breakpoint_map.end ())
432 error (_(
"Could not find breakpoint_id for breakpoint at %s"),
435 amd_dbgapi_breakpoint_id_t breakpoint_id { it->first };
436 amd_dbgapi_breakpoint_action_t action;
438 status = amd_dbgapi_report_breakpoint_hit
443 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
444 error (_(
"amd_dbgapi_report_breakpoint_hit failed for breakpoint %ld "
449 if (action == AMD_DBGAPI_BREAKPOINT_ACTION_RESUME)
454 amd_dbgapi_event_id_t resume_event_id
456 AMD_DBGAPI_EVENT_KIND_BREAKPOINT_RESUME);
460 gdb_assert (resume_event_id != AMD_DBGAPI_EVENT_NONE);
462 amd_dbgapi_breakpoint_id_t resume_breakpoint_id;
463 status = amd_dbgapi_event_get_info (resume_event_id,
464 AMD_DBGAPI_EVENT_INFO_BREAKPOINT,
465 sizeof (resume_breakpoint_id),
466 &resume_breakpoint_id);
468 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
474 if (resume_breakpoint_id != breakpoint_id)
475 error (_(
"breakpoint resume event is not for this breakpoint. "
476 "Expected breakpoint_%ld, got breakpoint_%ld"),
477 breakpoint_id.handle, resume_breakpoint_id.handle);
479 amd_dbgapi_event_processed (resume_event_id);
490 amd_dbgapi_wave_state_t state;
491 amd_dbgapi_status_t
status
493 AMD_DBGAPI_WAVE_INFO_STATE,
sizeof (state),
495 return status == AMD_DBGAPI_STATUS_SUCCESS;
527 gdb_byte *readbuf,
const gdb_byte *writebuf,
528 ULONGEST offset, ULONGEST requested_len,
529 ULONGEST *xfered_len)
531 gdb::optional<scoped_restore_current_thread> maybe_restore_thread;
535 requested_len, xfered_len);
537 gdb_assert (requested_len > 0);
538 gdb_assert (xfered_len !=
nullptr);
543 amd_dbgapi_process_id_t process_id
547 size_t len = requested_len;
548 amd_dbgapi_status_t
status;
550 if (readbuf !=
nullptr)
551 status = amd_dbgapi_read_memory (process_id, wave_id, 0,
552 AMD_DBGAPI_ADDRESS_SPACE_GLOBAL,
553 offset, &len, readbuf);
555 status = amd_dbgapi_write_memory (process_id, wave_id, 0,
556 AMD_DBGAPI_ADDRESS_SPACE_GLOBAL,
557 offset, &len, writebuf);
559 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
584 amd_dbgapi_exceptions_t exception = AMD_DBGAPI_EXCEPTION_NONE;
590 exception = AMD_DBGAPI_EXCEPTION_WAVE_APERTURE_VIOLATION;
592 case GDB_SIGNAL_SEGV:
593 exception = AMD_DBGAPI_EXCEPTION_WAVE_MEMORY_VIOLATION;
596 exception = AMD_DBGAPI_EXCEPTION_WAVE_ILLEGAL_INSTRUCTION;
599 exception = AMD_DBGAPI_EXCEPTION_WAVE_MATH_ERROR;
601 case GDB_SIGNAL_ABRT:
602 exception = AMD_DBGAPI_EXCEPTION_WAVE_ABORT;
604 case GDB_SIGNAL_TRAP:
605 exception = AMD_DBGAPI_EXCEPTION_WAVE_TRAP;
608 exception = AMD_DBGAPI_EXCEPTION_NONE;
611 error (_(
"Resuming with signal %s is not supported by this agent."),
612 gdb_signal_to_name (signo));
636 amd_dbgapi_status_t
status;
638 status = amd_dbgapi_wave_resume (wave_id,
640 ? AMD_DBGAPI_RESUME_MODE_SINGLE_STEP
641 : AMD_DBGAPI_RESUME_MODE_NORMAL),
644 status = amd_dbgapi_wave_resume (wave_id, AMD_DBGAPI_RESUME_MODE_NORMAL,
645 AMD_DBGAPI_EXCEPTION_NONE);
647 if (
status != AMD_DBGAPI_STATUS_SUCCESS
651 &&
status != AMD_DBGAPI_STATUS_ERROR_INVALID_WAVE_ID)
652 error (_(
"wave_resume for wave_%ld failed (%s)"), wave_id.handle,
673 bool many_threads = ptid == minus_one_ptid || ptid.is_pid ();
684 auto stop_one_thread = [
this] (
thread_info *thread)
686 gdb_assert (thread !=
nullptr);
689 amd_dbgapi_wave_state_t state;
690 amd_dbgapi_status_t
status
691 = amd_dbgapi_wave_get_info (wave_id, AMD_DBGAPI_WAVE_INFO_STATE,
692 sizeof (state), &state);
693 if (
status == AMD_DBGAPI_STATUS_SUCCESS)
696 if (state == AMD_DBGAPI_WAVE_STATE_STOP)
699 status = amd_dbgapi_wave_stop (wave_id);
700 if (
status == AMD_DBGAPI_STATUS_SUCCESS)
703 if (
status != AMD_DBGAPI_STATUS_ERROR_INVALID_WAVE_ID)
704 error (_(
"wave_stop for wave_%ld failed (%s)"), wave_id.handle,
707 else if (
status != AMD_DBGAPI_STATUS_ERROR_INVALID_WAVE_ID)
708 error (_(
"wave_get_info for wave_%ld failed (%s)"), wave_id.handle,
743 for (
auto *thread :
inf->threads_safe ())
744 if (thread->state !=
THREAD_EXITED && thread->ptid.matches (ptid)
746 stop_one_thread (thread);
762 gdb_assert (event_id != AMD_DBGAPI_EVENT_NONE);
768 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
769 warning (_(
"Failed to acknowledge amd-dbgapi event %" PRIu64),
792 ret =
read (info->notifier, &buf, 1);
794 while (ret >= 0 || (ret == -1 && errno == EINTR));
810 amd_dbgapi_event_id_t event_id;
811 amd_dbgapi_event_kind_t event_kind;
812 amd_dbgapi_status_t
status
813 = amd_dbgapi_process_next_pending_event (info->process_id, &event_id,
815 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
818 if (event_id == AMD_DBGAPI_EVENT_NONE)
821 gdb_assert (event_kind == AMD_DBGAPI_EVENT_KIND_RUNTIME);
825 amd_dbgapi_runtime_state_t runtime_state;
826 status = amd_dbgapi_event_get_info (event_id,
827 AMD_DBGAPI_EVENT_INFO_RUNTIME_STATE,
828 sizeof (runtime_state),
830 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
831 error (_(
"event_get_info for event_%ld failed (%s)"),
834 switch (runtime_state)
836 case AMD_DBGAPI_RUNTIME_STATE_LOADED_SUCCESS:
837 gdb_assert (info->runtime_state == AMD_DBGAPI_RUNTIME_STATE_UNLOADED);
838 info->runtime_state = runtime_state;
844 if (info->inf->process_target ()->is_async_p ())
854 case AMD_DBGAPI_RUNTIME_STATE_UNLOADED:
855 gdb_assert (info->runtime_state
856 == AMD_DBGAPI_RUNTIME_STATE_LOADED_ERROR_RESTRICTION);
857 info->runtime_state = runtime_state;
860 case AMD_DBGAPI_RUNTIME_STATE_LOADED_ERROR_RESTRICTION:
861 gdb_assert (info->runtime_state == AMD_DBGAPI_RUNTIME_STATE_UNLOADED);
862 info->runtime_state = runtime_state;
863 warning (_(
"amd-dbgapi: unable to enable GPU debugging "
864 "due to a restriction error"));
893 if (
info->notifier != -1)
895 string_printf (
"amd-dbgapi notifier for pid %d",
916 if (
info->notifier != -1)
917 delete_file_handler (
info->notifier);
929 return ptid_t (
pid, 1, wave_id.handle);
936 amd_dbgapi_event_kind_t event_kind)
941 amd_dbgapi_process_id_t process_id;
942 amd_dbgapi_status_t
status
943 = amd_dbgapi_event_get_info (event_id, AMD_DBGAPI_EVENT_INFO_PROCESS,
944 sizeof (process_id), &process_id);
945 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
946 error (_(
"event_get_info for event_%ld failed (%s)"), event_id.handle,
949 amd_dbgapi_os_process_id_t
pid;
950 status = amd_dbgapi_process_get_info (process_id,
951 AMD_DBGAPI_PROCESS_INFO_OS_ID,
953 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
954 error (_(
"process_get_info for process_%ld failed (%s)"),
959 gdb_assert (
inf !=
nullptr);
964 case AMD_DBGAPI_EVENT_KIND_WAVE_COMMAND_TERMINATED:
965 case AMD_DBGAPI_EVENT_KIND_WAVE_STOP:
967 amd_dbgapi_wave_id_t wave_id;
969 = amd_dbgapi_event_get_info (event_id, AMD_DBGAPI_EVENT_INFO_WAVE,
970 sizeof (wave_id), &wave_id);
971 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
972 error (_(
"event_get_info for event_%ld failed (%s)"),
978 amd_dbgapi_wave_stop_reasons_t stop_reason;
979 status = amd_dbgapi_wave_get_info (wave_id,
980 AMD_DBGAPI_WAVE_INFO_STOP_REASON,
981 sizeof (stop_reason), &stop_reason);
982 if (
status == AMD_DBGAPI_STATUS_ERROR_INVALID_WAVE_ID
983 && event_kind == AMD_DBGAPI_EVENT_KIND_WAVE_COMMAND_TERMINATED)
985 else if (
status == AMD_DBGAPI_STATUS_SUCCESS)
987 if (stop_reason & AMD_DBGAPI_WAVE_STOP_REASON_APERTURE_VIOLATION)
990 & AMD_DBGAPI_WAVE_STOP_REASON_MEMORY_VIOLATION)
993 & AMD_DBGAPI_WAVE_STOP_REASON_ILLEGAL_INSTRUCTION)
996 & (AMD_DBGAPI_WAVE_STOP_REASON_FP_INPUT_DENORMAL
997 | AMD_DBGAPI_WAVE_STOP_REASON_FP_DIVIDE_BY_0
998 | AMD_DBGAPI_WAVE_STOP_REASON_FP_OVERFLOW
999 | AMD_DBGAPI_WAVE_STOP_REASON_FP_UNDERFLOW
1000 | AMD_DBGAPI_WAVE_STOP_REASON_FP_INEXACT
1001 | AMD_DBGAPI_WAVE_STOP_REASON_FP_INVALID_OPERATION
1002 | AMD_DBGAPI_WAVE_STOP_REASON_INT_DIVIDE_BY_0))
1004 else if (stop_reason
1005 & (AMD_DBGAPI_WAVE_STOP_REASON_BREAKPOINT
1006 | AMD_DBGAPI_WAVE_STOP_REASON_WATCHPOINT
1007 | AMD_DBGAPI_WAVE_STOP_REASON_SINGLE_STEP
1008 | AMD_DBGAPI_WAVE_STOP_REASON_DEBUG_TRAP
1009 | AMD_DBGAPI_WAVE_STOP_REASON_TRAP))
1011 else if (stop_reason & AMD_DBGAPI_WAVE_STOP_REASON_ASSERT_TRAP)
1016 thread_info *thread = proc_target->find_thread (event_ptid);
1017 if (thread ==
nullptr)
1029 if ((stop_reason & AMD_DBGAPI_WAVE_STOP_REASON_BREAKPOINT) != 0)
1035 CORE_ADDR adjusted_pc
1038 if (adjusted_pc != pc)
1043 error (_(
"wave_get_info for wave_%ld failed (%s)"),
1046 info->wave_events.emplace_back (event_ptid, ws);
1050 case AMD_DBGAPI_EVENT_KIND_CODE_OBJECT_LIST_UPDATED:
1068 case AMD_DBGAPI_EVENT_KIND_BREAKPOINT_RESUME:
1071 gdb_assert_not_reached (
"unhandled event kind");
1074 case AMD_DBGAPI_EVENT_KIND_RUNTIME:
1076 amd_dbgapi_runtime_state_t runtime_state;
1078 status = amd_dbgapi_event_get_info (event_id,
1079 AMD_DBGAPI_EVENT_INFO_RUNTIME_STATE,
1080 sizeof (runtime_state),
1082 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1083 error (_(
"event_get_info for event_%ld failed (%s)"),
1086 gdb_assert (runtime_state == AMD_DBGAPI_RUNTIME_STATE_UNLOADED);
1088 (info->runtime_state == AMD_DBGAPI_RUNTIME_STATE_LOADED_SUCCESS);
1090 info->runtime_state = runtime_state;
1098 error (_(
"event kind (%d) not supported"), event_kind);
1109 case AMD_DBGAPI_EVENT_KIND_NONE:
1112 case AMD_DBGAPI_EVENT_KIND_WAVE_STOP:
1115 case AMD_DBGAPI_EVENT_KIND_WAVE_COMMAND_TERMINATED:
1116 return "WAVE_COMMAND_TERMINATED";
1118 case AMD_DBGAPI_EVENT_KIND_CODE_OBJECT_LIST_UPDATED:
1119 return "CODE_OBJECT_LIST_UPDATED";
1121 case AMD_DBGAPI_EVENT_KIND_BREAKPOINT_RESUME:
1122 return "BREAKPOINT_RESUME";
1124 case AMD_DBGAPI_EVENT_KIND_RUNTIME:
1127 case AMD_DBGAPI_EVENT_KIND_QUEUE_ERROR:
1128 return "QUEUE_ERROR";
1131 gdb_assert_not_reached (
"unhandled amd_dbgapi_event_kind_t value");
1140static amd_dbgapi_event_id_t
1142 amd_dbgapi_event_kind_t until_event_kind)
1146 gdb_assert (until_event_kind == AMD_DBGAPI_EVENT_KIND_NONE
1147 || process_id != AMD_DBGAPI_PROCESS_NONE);
1151 amd_dbgapi_event_id_t event_id;
1152 amd_dbgapi_event_kind_t event_kind;
1154 amd_dbgapi_status_t
status
1155 = amd_dbgapi_process_next_pending_event (process_id, &event_id,
1158 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1161 if (event_kind != AMD_DBGAPI_EVENT_KIND_NONE)
1163 "event_id.handle = %" PRIu64
", "
1168 if (event_id == AMD_DBGAPI_EVENT_NONE || event_kind == until_event_kind)
1189static std::pair<ptid_t, target_waitstatus>
1200 if (!info->wave_events.empty ())
1204 gdb_assert (info !=
nullptr);
1210 gdb_assert (
inf !=
nullptr);
1214 if (info->wave_events.empty ())
1215 return { minus_one_ptid, {} };
1217 auto event = info->wave_events.front ();
1218 info->wave_events.pop_front ();
1225 target_wait_flags target_options)
1227 gdb_assert (!
current_inferior ()->process_target ()->commit_resumed_state);
1228 gdb_assert (ptid == minus_one_ptid || ptid.is_pid ());
1232 ptid_t event_ptid =
beneath ()->
wait (ptid, ws, target_options);
1233 if (event_ptid != minus_one_ptid)
1257 auto more_events = make_scope_exit ([] ()
1271 if (event_ptid == minus_one_ptid)
1279 if (event_ptid == minus_one_ptid)
1284 if (ptid == minus_one_ptid)
1285 more_events.release ();
1299 == AMD_DBGAPI_RUNTIME_STATE_LOADED_SUCCESS)
1308 return minus_one_ptid;
1312 *ws = gpu_waitstatus;
1324 amd_dbgapi_wave_stop_reasons_t stop_reason;
1325 amd_dbgapi_status_t
status
1326 = amd_dbgapi_wave_get_info (wave_id, AMD_DBGAPI_WAVE_INFO_STOP_REASON,
1327 sizeof (stop_reason), &stop_reason);
1329 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1332 return (stop_reason & AMD_DBGAPI_WAVE_STOP_REASON_BREAKPOINT) != 0;
1354 auto mode = (info.precise_memory.requested
1355 ? AMD_DBGAPI_MEMORY_PRECISION_PRECISE
1356 : AMD_DBGAPI_MEMORY_PRECISION_NONE);
1357 amd_dbgapi_status_t
status
1358 = amd_dbgapi_set_memory_precision (info.process_id, mode);
1360 if (
status == AMD_DBGAPI_STATUS_SUCCESS)
1361 info.precise_memory.enabled = info.precise_memory.requested;
1362 else if (
status == AMD_DBGAPI_STATUS_ERROR_NOT_SUPPORTED)
1363 warning (_(
"AMDGPU precise memory access reporting could not be enabled."));
1364 else if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1365 error (_(
"amd_dbgapi_set_memory_precision failed (%s)"),
1383 warning (_(
"The amd-dbgapi target requires the target beneath to be "
1384 "asynchronous, GPU debugging is disabled"));
1396 if (
inf->vfork_parent !=
nullptr)
1402 if (info->process_id != AMD_DBGAPI_PROCESS_NONE)
1405 (
"already attached: process_id = %" PRIu64, info->process_id.handle);
1409 amd_dbgapi_status_t
status
1410 = amd_dbgapi_process_attach
1411 (
reinterpret_cast<amd_dbgapi_client_process_id_t
> (
inf),
1413 if (
status == AMD_DBGAPI_STATUS_ERROR_RESTRICTION)
1415 warning (_(
"amd-dbgapi: unable to enable GPU debugging due to a "
1416 "restriction error"));
1419 else if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1421 warning (_(
"amd-dbgapi: could not attach to process %d (%s), GPU "
1422 "debugging will not be available."),
inf->
pid,
1427 if (amd_dbgapi_process_get_info (info->process_id,
1428 AMD_DBGAPI_PROCESS_INFO_NOTIFIER,
1429 sizeof (info->notifier), &info->notifier)
1430 != AMD_DBGAPI_STATUS_SUCCESS)
1432 amd_dbgapi_process_detach (info->process_id);
1433 info->process_id = AMD_DBGAPI_PROCESS_NONE;
1434 warning (_(
"amd-dbgapi: could not retrieve process %d's notifier, GPU "
1435 "debugging will not be available."),
inf->
pid);
1440 info->process_id.handle, info->notifier);
1450 "amd-dbgapi notifier");
1468 if (info->process_id == AMD_DBGAPI_PROCESS_NONE)
1471 info->runtime_state = AMD_DBGAPI_RUNTIME_STATE_UNLOADED;
1473 amd_dbgapi_status_t
status = amd_dbgapi_process_detach (info->process_id);
1474 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1475 warning (_(
"amd-dbgapi: could not detach from process %d (%s)"),
1478 gdb_assert (info->notifier != -1);
1479 delete_file_handler (info->notifier);
1485 for (
auto &&
value : info->breakpoint_map)
1531 amd_dbgapi_status_t
status
1532 = amd_dbgapi_read_register (wave_id, tdep->
register_ids[regno], 0,
1536 if (
status == AMD_DBGAPI_STATUS_SUCCESS)
1538 else if (
status != AMD_DBGAPI_STATUS_ERROR_REGISTER_NOT_AVAILABLE)
1539 warning (_(
"Couldn't read register %s (#%d) (%s)."),
1564 & AMD_DBGAPI_REGISTER_PROPERTY_READONLY_BITS)
1571 & AMD_DBGAPI_REGISTER_PROPERTY_INVALIDATE_VOLATILE)
1579 amd_dbgapi_status_t
status
1580 = amd_dbgapi_write_register (wave_id, tdep->
register_ids[regno], 0,
1584 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1585 warning (_(
"Couldn't write register %s (#%d)."),
1601 amd_dbgapi_architecture_id_t architecture_id;
1602 amd_dbgapi_status_t
status;
1604 status = amd_dbgapi_wave_get_info (wave_id, AMD_DBGAPI_WAVE_INFO_ARCHITECTURE,
1605 sizeof (architecture_id),
1607 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1608 error (_(
"Couldn't get architecture for wave_%ld"), ptid.tid ());
1610 uint32_t elf_amdgpu_machine;
1611 status = amd_dbgapi_architecture_get_info
1612 (architecture_id, AMD_DBGAPI_ARCHITECTURE_INFO_ELF_AMDGPU_MACHINE,
1613 sizeof (elf_amdgpu_machine), &elf_amdgpu_machine);
1614 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1615 error (_(
"Couldn't get elf_amdgpu_machine for architecture_%ld"),
1616 architecture_id.handle);
1619 info.bfd_arch_info = bfd_lookup_arch (bfd_arch_amdgcn, elf_amdgpu_machine);
1620 info.byte_order = BFD_ENDIAN_LITTLE;
1625 error (_(
"Couldn't get elf_amdgpu_machine (%#x)"), elf_amdgpu_machine);
1642 amd_dbgapi_process_id_t process_id
1644 if (process_id == AMD_DBGAPI_PROCESS_NONE)
1651 amd_dbgapi_wave_id_t *wave_list;
1652 amd_dbgapi_changed_t changed;
1653 amd_dbgapi_status_t
status
1654 = amd_dbgapi_process_wave_list (process_id, &count, &wave_list,
1656 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
1657 error (_(
"amd_dbgapi_wave_list failed (%s)"),
1660 if (changed == AMD_DBGAPI_CHANGED_NO)
1664 std::set<ptid_t::tid_type> threads;
1665 for (
size_t i = 0; i < count; ++i)
1666 threads.emplace (wave_list[i].handle);
1676 auto it = threads.find (tp->ptid.tid ());
1678 if (it == threads.end ())
1685 for (ptid_t::tid_type tid : threads)
1725 gdb_assert (new_info->process_id == AMD_DBGAPI_PROCESS_NONE);
1726 new_info->precise_memory.requested = orig_info->precise_memory.requested;
1754 if (child_inf !=
nullptr)
1798static amd_dbgapi_status_t
1800 (amd_dbgapi_client_process_id_t client_process_id, pid_t *
pid)
1805 return AMD_DBGAPI_STATUS_ERROR_PROCESS_EXITED;
1808 return AMD_DBGAPI_STATUS_SUCCESS;
1813static amd_dbgapi_status_t
1815 (amd_dbgapi_client_process_id_t client_process_id,
1816 amd_dbgapi_global_address_t address,
1817 amd_dbgapi_breakpoint_id_t breakpoint_id)
1822 auto it = info->breakpoint_map.find (breakpoint_id.handle);
1823 if (it != info->breakpoint_map.end ())
1824 return AMD_DBGAPI_STATUS_ERROR_INVALID_BREAKPOINT_ID;
1832 if (section ==
nullptr || section->
objfile ==
nullptr)
1833 return AMD_DBGAPI_STATUS_ERROR;
1835 std::unique_ptr<breakpoint> bp_up
1840 info->breakpoint_map.emplace (breakpoint_id.handle,
bp);
1841 return AMD_DBGAPI_STATUS_SUCCESS;
1846static amd_dbgapi_status_t
1848 (amd_dbgapi_client_process_id_t client_process_id,
1849 amd_dbgapi_breakpoint_id_t breakpoint_id)
1854 auto it = info->breakpoint_map.find (breakpoint_id.handle);
1855 if (it == info->breakpoint_map.end ())
1856 return AMD_DBGAPI_STATUS_ERROR_INVALID_BREAKPOINT_ID;
1859 info->breakpoint_map.erase (it);
1861 return AMD_DBGAPI_STATUS_SUCCESS;
1872 if (info->process_id == AMD_DBGAPI_PROCESS_NONE)
1878 if (sig != GDB_SIGNAL_SEGV && sig != GDB_SIGNAL_BUS)
1881 if (!info->precise_memory.enabled)
1883Warning: precise memory violation signal reporting is not enabled, reported\n\
1884location may not be accurate. See \"show amdgpu precise-memory\".\n"));
1902 const char *message)
1904 gdb::optional<target_terminal::scoped_restore_terminal_state> tstate;
1913 if (level == AMD_DBGAPI_LOG_LEVEL_FATAL_ERROR
1914 || level == AMD_DBGAPI_LOG_LEVEL_WARNING)
1917 ui_file_style style = (level == AMD_DBGAPI_LOG_LEVEL_FATAL_ERROR
1926 if (level >= AMD_DBGAPI_LOG_LEVEL_TRACE)
1940 .allocate_memory = malloc,
1941 .deallocate_memory = free,
1965 _(
"AMDGPU precise memory access reporting is %s "
1966 "(currently %s).\n"),
1967 info->precise_memory.requested ?
"on" :
"off",
1968 info->precise_memory.enabled ?
"enabled" :
"disabled");
1979 info->precise_memory.requested =
value;
1981 if (info->process_id != AMD_DBGAPI_PROCESS_NONE)
1993 return info->precise_memory.requested;
2024static amd_dbgapi_log_level_t
2027 for (
size_t pos = 0;
2032 return static_cast<amd_dbgapi_log_level_t
> (pos);
2034 gdb_assert_not_reached (
"invalid log level");
2054 gdb_printf (file, _(
"The amd-dbgapi library log level is %s.\n"),
value);
2068 if (info->process_id != AMD_DBGAPI_PROCESS_NONE)
2072 amd_dbgapi_status_t
status = amd_dbgapi_finalize ();
2073 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
2074 error (_(
"amd-dbgapi failed to finalize (%s)"),
2078 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
2079 error (_(
"amd-dbgapi failed to initialize (%s)"),
2090 uint32_t major, minor, patch;
2091 amd_dbgapi_get_version (&major, &minor, &patch);
2092 if (major != AMD_DBGAPI_VERSION_MAJOR || minor < AMD_DBGAPI_VERSION_MINOR)
2093 error (_(
"amd-dbgapi library version mismatch, got %d.%d.%d, need %d.%d+"),
2094 major, minor, patch, AMD_DBGAPI_VERSION_MAJOR,
2095 AMD_DBGAPI_VERSION_MINOR);
2099 if (
status != AMD_DBGAPI_STATUS_SUCCESS)
2100 error (_(
"amd-dbgapi failed to initialize (%s)"),
2120 _(
"Generic command for setting amdgpu flags."),
2124 _(
"Generic command for showing amdgpu flags."),
2128 _(
"Set precise-memory mode."),
2129 _(
"Show precise-memory mode."), _(
"\
2130If on, precise memory reporting is enabled if/when the inferior is running.\n\
2131If off (default), precise memory reporting is disabled."),
2138 _(
"Generic command for setting amd-dbgapi library "
2139 "debugging flags."),
2143 _(
"Generic command for showing amd-dbgapi library "
2144 "debugging flags."),
2150 _(
"Set the amd-dbgapi library log level."),
2151 _(
"Show the amd-dbgapi library log level."),
2152 _(
"off == no logging is enabled\n"
2153 "error == fatal errors are reported\n"
2154 "warning == fatal errors and warnings are reported\n"
2155 "info == fatal errors, warnings, and info "
2156 "messages are reported\n"
2157 "trace == fatal errors, warnings, info, and "
2158 "API tracing messages are reported\n"
2159 "verbose == all messages are reported"),
2167 _(
"Set debugging of amd-dbgapi target."),
2168 _(
"Show debugging of amd-dbgapi target."),
2170When on, print debug messages relating to the amd-dbgapi target."),
static amd_dbgapi_log_level_t get_debug_amd_dbgapi_lib_log_level()
initialize_file_ftype _initialize_amd_dbgapi_target
static std::string wave_target_id_string(amd_dbgapi_wave_id_t wave_id)
static void show_debug_amd_dbgapi_lib_log_level(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static struct amd_dbgapi_inferior_info * get_amd_dbgapi_inferior_info(struct inferior *inferior)
static constexpr const char * debug_amd_dbgapi_lib_log_level_enums[]
static cli_style_option fatal_error_style("amd_dbgapi_fatal_error", ui_file_style::RED)
static void amd_dbgapi_target_inferior_cloned(inferior *original_inferior, inferior *new_inferior)
static const target_info amd_dbgapi_target_info
static cli_style_option trace_style("amd_dbgapi_trace", ui_file_style::BLACK, ui_file_style::BOLD)
static const char * amd_dbgapi_lib_debug_module_unstyled
static amd_dbgapi_callbacks_t dbgapi_callbacks
static std::pair< ptid_t, target_waitstatus > consume_one_event(int pid)
static void require_forward_progress(ptid_t ptid, process_stratum_target *proc_target, bool require)
static amd_dbgapi_status_t amd_dbgapi_insert_breakpoint_callback(amd_dbgapi_client_process_id_t client_process_id, amd_dbgapi_global_address_t address, amd_dbgapi_breakpoint_id_t breakpoint_id)
struct cmd_list_element * set_debug_amd_dbgapi_lib_list
static const char * amd_dbgapi_debug_module_unstyled
static const registry< inferior >::key< amd_dbgapi_inferior_info > amd_dbgapi_inferior_data
static bool get_precise_memory_mode()
static const char * debug_amd_dbgapi_lib_log_level
static void amd_dbgapi_target_signal_received(gdb_signal sig)
static const char * amd_dbgapi_lib_debug_module()
static void dbgapi_notifier_handler(int err, gdb_client_data client_data)
static void amd_dbgapi_log_message_callback(amd_dbgapi_log_level_t level, const char *message)
static void set_process_memory_precision(amd_dbgapi_inferior_info &info)
static const std::string amd_dbgapi_lib_debug_module_styled
amd_dbgapi_process_id_t get_amd_dbgapi_process_id(inferior *inf)
static async_event_handler * amd_dbgapi_async_event_handler
static void amd_dbgapi_inferior_execd(inferior *exec_inf, inferior *follow_inf)
const gdb::observers::token & get_amd_dbgapi_target_inferior_created_observer_token()
static void detach_amd_dbgapi(inferior *inf)
static struct amd_dbgapi_target the_amd_dbgapi_target
static void process_one_event(amd_dbgapi_event_id_t event_id, amd_dbgapi_event_kind_t event_kind)
#define AMD_DBGAPI_SCOPED_DEBUG_START_END(fmt,...)
#define AMDGPU_MAX_REGISTER_SIZE
static void attach_amd_dbgapi(inferior *inf)
static const std::string amd_dbgapi_debug_module_styled
static void async_event_handler_mark()
static void maybe_reset_amd_dbgapi()
static void handle_target_event(gdb_client_data client_data)
static amd_dbgapi_status_t amd_dbgapi_remove_breakpoint_callback(amd_dbgapi_client_process_id_t client_process_id, amd_dbgapi_breakpoint_id_t breakpoint_id)
static void set_debug_amd_dbgapi_lib_log_level(const char *args, int from_tty, struct cmd_list_element *c)
struct cmd_list_element * set_amdgpu_list
static const char * event_kind_str(amd_dbgapi_event_kind_t kind)
struct cmd_list_element * show_amdgpu_list
static amd_dbgapi_event_id_t process_event_queue(amd_dbgapi_process_id_t process_id, amd_dbgapi_event_kind_t until_event_kind=AMD_DBGAPI_EVENT_KIND_NONE)
static void amd_dbgapi_target_inferior_created(inferior *inf)
static void async_event_handler_clear()
static const char * amd_dbgapi_debug_module()
static void amd_dbgapi_inferior_pre_detach(inferior *inf)
struct cmd_list_element * show_debug_amd_dbgapi_lib_list
static std::string make_green(const char *s)
static ptid_t make_gpu_ptid(ptid_t::pid_type pid, amd_dbgapi_wave_id_t wave_id)
#define amd_dbgapi_debug_printf(fmt,...)
static amd_dbgapi_status_t amd_dbgapi_get_os_pid_callback(amd_dbgapi_client_process_id_t client_process_id, pid_t *pid)
static void set_precise_memory_mode(bool value)
static void show_precise_memory_mode(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static gdb::observers::token amd_dbgapi_target_inferior_created_observer_token
static cli_style_option warning_style("amd_dbgapi_warning", ui_file_style::YELLOW)
static void amd_dbgapi_inferior_exited(inferior *inf)
static void amd_dbgapi_inferior_forked(inferior *parent_inf, inferior *child_inf, target_waitkind fork_kind)
static bool debug_amd_dbgapi
static const char * get_status_string(amd_dbgapi_status_t status)
static bool ptid_is_gpu(ptid_t ptid)
static amd_dbgapi_wave_id_t get_amd_dbgapi_wave_id(ptid_t ptid)
amdgpu_gdbarch_tdep * get_amdgpu_gdbarch_tdep(gdbarch *arch)
bool is_amdgpu_arch(struct gdbarch *arch)
struct gdbarch * gdbarch_find_by_info(struct gdbarch_info info)
void mark_async_event_handler(async_event_handler *async_handler_ptr)
async_event_handler * create_async_event_handler(async_event_handler_func *proc, gdb_client_data client_data, const char *name)
void clear_async_event_handler(async_event_handler *async_handler_ptr)
void delete_async_event_handler(async_event_handler **async_handler_ptr)
bool async_event_handler_marked(async_event_handler *handler)
void delete_breakpoint(struct breakpoint *bpt)
breakpoint * install_breakpoint(int internal, std::unique_ptr< breakpoint > &&arg, int update_gll)
void remove_breakpoints_inf(inferior *inf)
ui_file_style style() const
struct process_stratum_target * process_target()
inf_threads_range threads()
thread_info * find_thread(ptid_t ptid)
void invalidate(int regnum)
void raw_collect(int regnum, void *buf) const override
void raw_supply(int regnum, const void *buf) override
static void ours_for_output()
struct cmd_list_element * showlist
struct cmd_list_element * setlist
struct cmd_list_element * showdebuglist
struct cmd_list_element * setdebuglist
struct cmd_list_element * add_show_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
set_show_commands add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * add_basic_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
void initialize_file_ftype(void)
ssize_t read(int fd, void *buf, size_t count)
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
CORE_ADDR gdbarch_decr_pc_after_break(struct gdbarch *gdbarch)
struct thread_info * add_thread_silent(process_stratum_target *targ, ptid_t ptid)
all_non_exited_threads_range all_non_exited_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
void set_executing(process_stratum_target *targ, ptid_t ptid, bool executing)
struct thread_info * inferior_thread(void)
void set_thread_exited(thread_info *tp, gdb::optional< ULONGEST > exit_code={}, bool silent=false)
void switch_to_thread(struct thread_info *thr)
void set_running(process_stratum_target *targ, ptid_t ptid, bool running)
void delete_thread_silent(struct thread_info *thread)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
void inferior_event_handler(enum inferior_event_type event_type)
struct inferior * find_inferior_pid(process_stratum_target *targ, int pid)
struct inferior * current_inferior(void)
void switch_to_inferior_no_thread(inferior *inf)
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
all_non_exited_inferiors_range all_non_exited_inferiors(process_stratum_target *proc_target=nullptr)
observable< struct inferior * > inferior_exit
observable< inferior *, inferior * > inferior_execd
observable< inferior *, inferior *, target_waitkind > inferior_forked
observable< inferior * > inferior_created
observable< struct inferior * > inferior_pre_detach
observable< enum gdb_signal > signal_received
observable< struct inferior *, struct inferior * > inferior_cloned
struct obj_section * find_pc_section(CORE_ADDR pc)
struct program_space * current_program_space
CORE_ADDR regcache_read_pc(struct regcache *regcache)
void regcache_write_pc(struct regcache *regcache, CORE_ADDR pc)
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
struct type * register_type(struct gdbarch *gdbarch, int regnum)
void handle_solib_event(void)
amd_dbgapi_notifier_t notifier
bool forward_progress_required
std::list< std::pair< ptid_t, target_waitstatus > > wave_events
std::unordered_map< decltype(amd_dbgapi_breakpoint_id_t::handle), struct breakpoint * > breakpoint_map
amd_dbgapi_process_id_t process_id
amd_dbgapi_runtime_state_t runtime_state
amd_dbgapi_inferior_info(inferior *inf, bool precise_memory_requested=false)
struct amd_dbgapi_inferior_info::@7 precise_memory
amd_dbgapi_target_breakpoint(struct gdbarch *gdbarch, CORE_ADDR address)
void check_status(struct bpstat *bs) override
const target_info & info() const override
void fetch_registers(struct regcache *, int) override
void mourn_inferior() override
ptid_t::tid_type m_cached_arch_tid
const char * extra_thread_info(thread_info *tp) override
bool stopped_by_hw_breakpoint() override
void async(bool enable) override
bool has_pending_events() override
void resume(ptid_t, int, enum gdb_signal) override
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
bool m_report_thread_events
void store_registers(struct regcache *, int) override
void thread_events(int enable) override
bool stopped_by_watchpoint() override
bool thread_alive(ptid_t ptid) override
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
std::string pid_to_str(ptid_t ptid) override
const char * thread_name(thread_info *tp) override
void detach(inferior *inf, int from_tty) override
struct gdbarch * thread_architecture(ptid_t) override
bool stopped_by_sw_breakpoint() override
strata stratum() const override
void update_thread_list() override
void commit_resumed() override
std::vector< amd_dbgapi_register_id_t > register_ids
std::vector< amd_dbgapi_register_properties_t > register_properties
bp_location_ref_ptr bp_location_at
enum bp_print_how print_it
struct breakpoint * breakpoint_at
bp_location * add_location(const symtab_and_line &sal)
struct gdbarch * arch() const
DISABLE_COPY_AND_ASSIGN(scoped_amd_dbgapi_event_processed)
~scoped_amd_dbgapi_event_processed()
amd_dbgapi_event_id_t m_event_id
scoped_amd_dbgapi_event_processed(amd_dbgapi_event_id_t event_id)
struct obj_section * section
struct program_space * pspace
virtual ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags options) TARGET_DEFAULT_FUNC(default_target_wait)
virtual std::string pid_to_str(ptid_t) TARGET_DEFAULT_FUNC(default_pid_to_str)
virtual void fetch_registers(struct regcache *, int) TARGET_DEFAULT_IGNORE()
virtual bool stopped_by_sw_breakpoint() TARGET_DEFAULT_RETURN(false)
virtual void detach(inferior *, int) TARGET_DEFAULT_IGNORE()
virtual bool stopped_by_watchpoint() TARGET_DEFAULT_RETURN(false)
target_ops * beneath() const
virtual void commit_resumed() TARGET_DEFAULT_IGNORE()
virtual void store_registers(struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
virtual enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
virtual gdb::array_view< const_gdb_byte > virtual thread_info_to_thread_handle(struct thread_info *) TARGET_DEFAULT_RETURN(gdb voi stop)(ptid_t) TARGET_DEFAULT_IGNORE()
virtual bool stopped_by_hw_breakpoint() TARGET_DEFAULT_RETURN(false)
virtual const char * extra_thread_info(thread_info *) TARGET_DEFAULT_RETURN(NULL)
virtual void async(bool) TARGET_DEFAULT_NORETURN(tcomplain())
virtual void resume(ptid_t, int TARGET_DEBUG_PRINTER(target_debug_print_step), enum gdb_signal) TARGET_DEFAULT_NORETURN(noprocess())
virtual struct gdbarch * thread_architecture(ptid_t) TARGET_DEFAULT_RETURN(NULL)
virtual void thread_events(int) TARGET_DEFAULT_IGNORE()
virtual void update_thread_list() TARGET_DEFAULT_IGNORE()
virtual const char * thread_name(thread_info *) TARGET_DEFAULT_RETURN(NULL)
virtual void mourn_inferior() TARGET_DEFAULT_FUNC(default_mourn_inferior)
virtual bool thread_alive(ptid_t ptid) TARGET_DEFAULT_RETURN(false)
virtual bool has_pending_events() TARGET_DEFAULT_RETURN(false)
target_waitstatus & set_stopped(gdb_signal sig)
target_waitstatus & set_thread_exited(int exit_status)
target_waitstatus & set_ignore()
target_waitkind kind() const
struct obj_section * find_pc_overlay(CORE_ADDR pc)
target_ops * get_native_target()
void target_async(bool enable)
bool target_supports_terminal_ours(void)
bool target_can_async_p()
static styled_string_s * styled_string(const ui_file_style &style, const char *str, styled_string_s &&tmp={})
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
void gdb_printf(struct ui_file *stream, const char *format,...)
@ TARGET_WAITKIND_NO_RESUMED
@ TARGET_WAITKIND_SIGNALLED
@ TARGET_WAITKIND_VFORKED