Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lldb/include/lldb/Host/common/NativeProcessProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ class NativeProcessProtocol {
return std::nullopt;
};



/// Extension flag constants, returned by Manager::GetSupportedExtensions()
/// and passed to SetEnabledExtension()
enum class Extension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,12 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited(
Log *log = GetLog(LLDBLog::Process);
LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);

// Notify GPU plugins that the native process has exited
std::optional<WaitStatus> exit_status = process->GetExitStatus();
if (exit_status.has_value())
for (std::unique_ptr<lldb_server::LLDBServerPlugin> &plugin_up : m_plugins)
plugin_up->NativeProcessDidExit(*exit_status);

PacketResult result = SendStopReasonForState(
*process, StateType::eStateExited, /*force_synchronous=*/false);
if (result != PacketResult::Success) {
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Plugins/Process/gdb-remote/LLDBServerPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ class LLDBServerPlugin {
return std::nullopt;
};

/// Get the GPU plug-in notified when the native process exits.
///
/// This function will get called when the native process exits. This allows
/// GPU plugins to perform proper termination.
///
/// \param[in] exit_status The exit status of the native process.
virtual void NativeProcessDidExit(const WaitStatus &exit_status) = 0;

/// Get the GPU plug-in initialization actions.
///
/// Each GPU plugin can return a structure that describes the GPU plug-in and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,13 @@ LLDBServerPluginAMDGPU::BreakpointWasHit(GPUPluginBreakpointHitArgs &args) {
return response;
}

void LLDBServerPluginAMDGPU::NativeProcessDidExit(const WaitStatus &exit_status) {
// Bare bones implementation for exit behavior if GPU process exits.
ProcessAMDGPU *gpu_process = GetGPUProcess();
if (gpu_process)
gpu_process->HandleNativeProcessExit(exit_status);
}

GPUActions LLDBServerPluginAMDGPU::GetInitializeActions() {
GPUActions init_actions;
init_actions.plugin_name = GetPluginName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class LLDBServerPluginAMDGPU : public LLDBServerPlugin {
bool HandleEventFileDescriptorEvent(int fd) override;
GPUActions GetInitializeActions() override;
std::optional<struct GPUActions> NativeProcessIsStopping() override;
void NativeProcessDidExit(const WaitStatus &exit_status) override;
llvm::Expected<GPUPluginBreakpointHitResponse>
BreakpointWasHit(GPUPluginBreakpointHitArgs &args) override;

Expand Down
5 changes: 5 additions & 0 deletions lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ void ProcessAMDGPU::SetLaunchInfo(ProcessLaunchInfo &launch_info) {
static_cast<ProcessInfo &>(launch_info);
}

void ProcessAMDGPU::HandleNativeProcessExit(const WaitStatus &exit_status) {
// Set our exit status to match the native process and notify delegates
SetExitStatus(exit_status, true);
}

bool ProcessAMDGPU::GetProcessInfo(ProcessInstanceInfo &proc_info) {
Log *log = GetLog(GDBRLog::Plugin);
LLDB_LOGF(log, "ProcessAMDGPU::%s() entered", __FUNCTION__);
Expand Down
3 changes: 3 additions & 0 deletions lldb/tools/lldb-server/Plugins/AMDGPU/ProcessAMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class ProcessAMDGPU : public NativeProcessProtocol {
std::optional<GPUDynamicLoaderResponse>
GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args) override;

/// Called when the native process exits to exit the GPU process
void HandleNativeProcessExit(const WaitStatus &exit_status);

bool handleWaveStop(amd_dbgapi_event_id_t eventId);

bool handleDebugEvent(amd_dbgapi_event_id_t eventId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ std::optional<GPUActions> LLDBServerPluginMockGPU::NativeProcessIsStopping() {
return std::nullopt;
}

void LLDBServerPluginMockGPU::NativeProcessDidExit(
const WaitStatus &exit_status) {
// Tell the GPU process to exit
NativeProcessProtocol *gpu_process = m_gdb_server->GetCurrentProcess();
if (auto *mock_gpu_process = static_cast<ProcessMockGPU *>(gpu_process))
mock_gpu_process->HandleNativeProcessExit(exit_status);
}

llvm::Expected<GPUPluginBreakpointHitResponse>
LLDBServerPluginMockGPU::BreakpointWasHit(GPUPluginBreakpointHitArgs &args) {
const auto bp_identifier = args.breakpoint.identifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class LLDBServerPluginMockGPU : public LLDBServerPlugin {
bool HandleEventFileDescriptorEvent(int fd) override;
GPUActions GetInitializeActions() override;
std::optional<struct GPUActions> NativeProcessIsStopping() override;
void NativeProcessDidExit(const WaitStatus &exit_status) override;
llvm::Expected<GPUPluginBreakpointHitResponse>
BreakpointWasHit(GPUPluginBreakpointHitArgs &args) override;

Expand Down
9 changes: 9 additions & 0 deletions lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,12 @@ ProcessMockGPU::Extension
ProcessMockGPU::Manager::GetSupportedExtensions() const {
return Extension::gpu_dyld | Extension::address_spaces;
}

void ProcessMockGPU::HandleNativeProcessExit(const WaitStatus &exit_status) {
Log *log = GetLog(GDBRLog::Plugin);
LLDB_LOG(log, "ProcessMockGPU::{0}() native process exited with status=({1})",
__FUNCTION__, exit_status);

// Set our exit status to match the native process and notify delegates
SetExitStatus(exit_status, true);
}
3 changes: 3 additions & 0 deletions lldb/tools/lldb-server/Plugins/MockGPU/ProcessMockGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class Manager : public NativeProcessProtocol::Manager {

// Custom accessors
void SetLaunchInfo(ProcessLaunchInfo &launch_info);

/// Called when the native process exits to set the GPU process exit status
void HandleNativeProcessExit(const WaitStatus &exit_status);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mark this as override

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is not an override. The only mandatory interface in this patch is at the plugin level.

};


Expand Down