diff options
Diffstat (limited to 'gdb/amd-dbgapi-target.c')
-rw-r--r-- | gdb/amd-dbgapi-target.c | 157 |
1 files changed, 83 insertions, 74 deletions
diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c index 996e16a..a0210f4 100644 --- a/gdb/amd-dbgapi-target.c +++ b/gdb/amd-dbgapi-target.c @@ -1,6 +1,6 @@ /* Target used to communicate with the AMD Debugger API. - Copyright (C) 2019-2024 Free Software Foundation, Inc. + Copyright (C) 2019-2025 Free Software Foundation, Inc. This file is part of GDB. @@ -104,12 +104,26 @@ amd_dbgapi_lib_debug_module () static gdb::observers::token amd_dbgapi_target_inferior_created_observer_token; +/* See amd-dbgapi-target.h. */ + const gdb::observers::token & get_amd_dbgapi_target_inferior_created_observer_token () { return amd_dbgapi_target_inferior_created_observer_token; } +/* inferior_execd observer token. */ + +static gdb::observers::token amd_dbgapi_target_inferior_execd_observer_token; + +/* See amd-dbgapi-target.h. */ + +const gdb::observers::token & +get_amd_dbgapi_target_inferior_execd_observer_token () +{ + return amd_dbgapi_target_inferior_execd_observer_token; +} + /* A type holding coordinates, etc. info for a given wave. */ struct wave_coordinates @@ -234,7 +248,7 @@ struct amd_dbgapi_inferior_info }; static amd_dbgapi_event_id_t process_event_queue - (amd_dbgapi_process_id_t process_id, + (amd_dbgapi_inferior_info &info, amd_dbgapi_event_kind_t until_event_kind = AMD_DBGAPI_EVENT_KIND_NONE); static const target_info amd_dbgapi_target_info = { @@ -443,6 +457,32 @@ async_event_handler_mark () mark_async_event_handler (amd_dbgapi_async_event_handler); } +/* Set forward progress requirement to REQUIRE for inferior INFO. */ + +static void +require_forward_progress (amd_dbgapi_inferior_info &info, bool require) +{ + /* If we try to disable forward progress requirement but the target expects + resumed threads to be committed to the target, we could wait for events + that will never arrive. */ + if (!require) + gdb_assert (!info.inf->process_target ()->commit_resumed_state); + + gdb_assert (info.process_id != AMD_DBGAPI_PROCESS_NONE); + + /* Don't do unnecessary calls to amd-dbgapi to avoid polluting the logs. */ + if (info.forward_progress_required == require) + return; + + const auto progress + = require ? AMD_DBGAPI_PROGRESS_NORMAL : AMD_DBGAPI_PROGRESS_NO_FORWARD; + const auto status + = amd_dbgapi_process_set_progress (info.process_id, progress); + gdb_assert (status == AMD_DBGAPI_STATUS_SUCCESS); + + info.forward_progress_required = require; +} + /* Set forward progress requirement to REQUIRE for all processes of PROC_TARGET matching PTID. */ @@ -457,21 +497,8 @@ require_forward_progress (ptid_t ptid, process_stratum_target *proc_target, amd_dbgapi_inferior_info *info = get_amd_dbgapi_inferior_info (inf); - if (info->process_id == AMD_DBGAPI_PROCESS_NONE) - continue; - - /* Don't do unnecessary calls to amd-dbgapi to avoid polluting the logs. */ - if (info->forward_progress_required == require) - continue; - - amd_dbgapi_status_t status - = amd_dbgapi_process_set_progress - (info->process_id, (require - ? AMD_DBGAPI_PROGRESS_NORMAL - : AMD_DBGAPI_PROGRESS_NO_FORWARD)); - gdb_assert (status == AMD_DBGAPI_STATUS_SUCCESS); - - info->forward_progress_required = require; + if (info->process_id != AMD_DBGAPI_PROCESS_NONE) + require_forward_progress (*info, require); /* If ptid targets a single inferior and we have found it, no need to continue. */ @@ -555,11 +582,12 @@ amd_dbgapi_target_breakpoint::check_status (struct bpstat *bs) if (action == AMD_DBGAPI_BREAKPOINT_ACTION_RESUME) return; + require_forward_progress (*info, false); + /* If the action is AMD_DBGAPI_BREAKPOINT_ACTION_HALT, we need to wait until a breakpoint resume event for this breakpoint_id is seen. */ amd_dbgapi_event_id_t resume_event_id - = process_event_queue (info->process_id, - AMD_DBGAPI_EVENT_KIND_BREAKPOINT_RESUME); + = process_event_queue (*info, AMD_DBGAPI_EVENT_KIND_BREAKPOINT_RESUME); /* We should always get a breakpoint_resume event after processing all events generated by reporting the breakpoint hit. */ @@ -1138,32 +1166,14 @@ add_gpu_thread (inferior *inf, ptid_t wave_ptid) /* Process an event that was just pulled out of the amd-dbgapi library. */ static void -process_one_event (amd_dbgapi_event_id_t event_id, +process_one_event (amd_dbgapi_inferior_info &info, + amd_dbgapi_event_id_t event_id, amd_dbgapi_event_kind_t event_kind) { /* Automatically mark this event processed when going out of scope. */ scoped_amd_dbgapi_event_processed mark_event_processed (event_id); - amd_dbgapi_process_id_t process_id; - amd_dbgapi_status_t status - = amd_dbgapi_event_get_info (event_id, AMD_DBGAPI_EVENT_INFO_PROCESS, - sizeof (process_id), &process_id); - if (status != AMD_DBGAPI_STATUS_SUCCESS) - error (_("event_get_info for event_%ld failed (%s)"), event_id.handle, - get_status_string (status)); - - amd_dbgapi_os_process_id_t pid; - status = amd_dbgapi_process_get_info (process_id, - AMD_DBGAPI_PROCESS_INFO_OS_ID, - sizeof (pid), &pid); - if (status != AMD_DBGAPI_STATUS_SUCCESS) - error (_("process_get_info for process_%ld failed (%s)"), - process_id.handle, get_status_string (status)); - - auto *proc_target = current_inferior ()->process_target (); - inferior *inf = find_inferior_pid (proc_target, pid); - gdb_assert (inf != nullptr); - amd_dbgapi_inferior_info *info = get_amd_dbgapi_inferior_info (inf); + gdb_assert (info.inf != nullptr); switch (event_kind) { @@ -1171,14 +1181,14 @@ process_one_event (amd_dbgapi_event_id_t event_id, case AMD_DBGAPI_EVENT_KIND_WAVE_STOP: { amd_dbgapi_wave_id_t wave_id; - status + amd_dbgapi_status_t status = amd_dbgapi_event_get_info (event_id, AMD_DBGAPI_EVENT_INFO_WAVE, sizeof (wave_id), &wave_id); if (status != AMD_DBGAPI_STATUS_SUCCESS) error (_("event_get_info for event_%ld failed (%s)"), event_id.handle, get_status_string (status)); - ptid_t event_ptid = make_gpu_ptid (pid, wave_id); + ptid_t event_ptid = make_gpu_ptid (info.inf->pid, wave_id); target_waitstatus ws; amd_dbgapi_wave_stop_reasons_t stop_reason; @@ -1219,9 +1229,10 @@ process_one_event (amd_dbgapi_event_id_t event_id, else ws.set_stopped (GDB_SIGNAL_0); - thread_info *thread = proc_target->find_thread (event_ptid); + thread_info *thread + = info.inf->process_target ()->find_thread (event_ptid); if (thread == nullptr) - thread = add_gpu_thread (inf, event_ptid); + thread = add_gpu_thread (info.inf, event_ptid); /* If the wave is stopped because of a software breakpoint, the program counter needs to be adjusted so that it points to the @@ -1243,7 +1254,7 @@ process_one_event (amd_dbgapi_event_id_t event_id, error (_("wave_get_info for wave_%ld failed (%s)"), wave_id.handle, get_status_string (status)); - info->wave_events.emplace_back (event_ptid, ws); + info.wave_events.emplace_back (event_ptid, ws); break; } @@ -1261,7 +1272,7 @@ process_one_event (amd_dbgapi_event_id_t event_id, When amd_dbgapi_target_breakpoint::check_status is called, the current inferior is the inferior that hit the breakpoint, which should still be the case now. */ - gdb_assert (inf == current_inferior ()); + gdb_assert (info.inf == current_inferior ()); handle_solib_event (); break; @@ -1275,22 +1286,22 @@ process_one_event (amd_dbgapi_event_id_t event_id, { amd_dbgapi_runtime_state_t runtime_state; - status = amd_dbgapi_event_get_info (event_id, - AMD_DBGAPI_EVENT_INFO_RUNTIME_STATE, - sizeof (runtime_state), - &runtime_state); + amd_dbgapi_status_t status + = amd_dbgapi_event_get_info (event_id, + AMD_DBGAPI_EVENT_INFO_RUNTIME_STATE, + sizeof (runtime_state), &runtime_state); if (status != AMD_DBGAPI_STATUS_SUCCESS) error (_("event_get_info for event_%ld failed (%s)"), event_id.handle, get_status_string (status)); gdb_assert (runtime_state == AMD_DBGAPI_RUNTIME_STATE_UNLOADED); gdb_assert - (info->runtime_state == AMD_DBGAPI_RUNTIME_STATE_LOADED_SUCCESS); + (info.runtime_state == AMD_DBGAPI_RUNTIME_STATE_LOADED_SUCCESS); - info->runtime_state = runtime_state; + info.runtime_state = runtime_state; - gdb_assert (inf->target_is_pushed (&the_amd_dbgapi_target)); - inf->unpush_target (&the_amd_dbgapi_target); + gdb_assert (info.inf->target_is_pushed (&the_amd_dbgapi_target)); + info.inf->unpush_target (&the_amd_dbgapi_target); } break; @@ -1331,20 +1342,18 @@ event_kind_str (amd_dbgapi_event_kind_t kind) gdb_assert_not_reached ("unhandled amd_dbgapi_event_kind_t value"); } -/* Drain the dbgapi event queue of a given process_id, or of all processes if - process_id is AMD_DBGAPI_PROCESS_NONE. Stop processing the events if an - event of a given kind is requested and `process_id` is not - AMD_DBGAPI_PROCESS_NONE. Wave stop events that are not returned are queued - into their inferior's amd_dbgapi_inferior_info pending wave events. */ +/* Drain the dbgapi event queue of a given inferior. Stop processing the + events if an event of a given kind is requested (not AMD_DBGAPI_EVENT_NONE). + Wave stop events that are not returned are queued into their inferior's + amd_dbgapi_inferior_info pending wave events. */ static amd_dbgapi_event_id_t -process_event_queue (amd_dbgapi_process_id_t process_id, +process_event_queue (amd_dbgapi_inferior_info &info, amd_dbgapi_event_kind_t until_event_kind) { - /* An event of a given type can only be requested from a single - process_id. */ - gdb_assert (until_event_kind == AMD_DBGAPI_EVENT_KIND_NONE - || process_id != AMD_DBGAPI_PROCESS_NONE); + /* Pulling events with forward progress required may result in bad + performance, make sure it is not required. */ + gdb_assert (!info.forward_progress_required); while (true) { @@ -1352,7 +1361,7 @@ process_event_queue (amd_dbgapi_process_id_t process_id, amd_dbgapi_event_kind_t event_kind; amd_dbgapi_status_t status - = amd_dbgapi_process_next_pending_event (process_id, &event_id, + = amd_dbgapi_process_next_pending_event (info.process_id, &event_id, &event_kind); if (status != AMD_DBGAPI_STATUS_SUCCESS) @@ -1368,7 +1377,7 @@ process_event_queue (amd_dbgapi_process_id_t process_id, if (event_id == AMD_DBGAPI_EVENT_NONE || event_kind == until_event_kind) return event_id; - process_one_event (event_id, event_kind); + process_one_event (info, event_id, event_kind); } } @@ -1473,7 +1482,7 @@ amd_dbgapi_target::wait (ptid_t ptid, struct target_waitstatus *ws, /* Drain the events for the current inferior from the amd_dbgapi and preserve the ordering. */ auto info = get_amd_dbgapi_inferior_info (current_inferior ()); - process_event_queue (info->process_id, AMD_DBGAPI_EVENT_KIND_NONE); + process_event_queue (*info); std::tie (event_ptid, gpu_waitstatus) = consume_one_event (ptid.pid ()); if (event_ptid == minus_one_ptid) @@ -1860,13 +1869,14 @@ amd_dbgapi_target::update_thread_list () if (changed == AMD_DBGAPI_CHANGED_NO) continue; + gdb::unique_xmalloc_ptr<amd_dbgapi_wave_id_t> wave_list_holder + (wave_list); + /* Create a set and free the wave list. */ std::set<ptid_t::tid_type> threads; for (size_t i = 0; i < count; ++i) threads.emplace (wave_list[i].handle); - xfree (wave_list); - /* Prune the wave_ids that already have a thread_info. Any thread_info which does not have a corresponding wave_id represents a wave which is gone at this point and should be deleted. */ @@ -2479,10 +2489,7 @@ maybe_reset_amd_dbgapi () get_status_string (status)); } -extern initialize_file_ftype _initialize_amd_dbgapi_target; - -void -_initialize_amd_dbgapi_target () +INIT_GDB_FILE (amd_dbgapi_target) { /* Make sure the loaded debugger library version is greater than or equal to the one used to build GDB. */ @@ -2510,7 +2517,9 @@ _initialize_amd_dbgapi_target () gdb::observers::inferior_created.attach (amd_dbgapi_target_inferior_created, amd_dbgapi_target_inferior_created_observer_token, "amd-dbgapi"); - gdb::observers::inferior_execd.attach (amd_dbgapi_inferior_execd, "amd-dbgapi"); + gdb::observers::inferior_execd.attach + (amd_dbgapi_inferior_execd, amd_dbgapi_target_inferior_execd_observer_token, + "amd-dbgapi"); gdb::observers::inferior_forked.attach (amd_dbgapi_inferior_forked, "amd-dbgapi"); gdb::observers::inferior_exit.attach (amd_dbgapi_inferior_exited, "amd-dbgapi"); gdb::observers::inferior_pre_detach.attach (amd_dbgapi_inferior_pre_detach, "amd-dbgapi"); |