Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5a6179a
lldb-server with GPU plugins.
clayborg Mar 20, 2025
677a0eb
Made the mock GPU plug-in functional.
clayborg Apr 2, 2025
35a4a86
Add missing file.
clayborg Apr 2, 2025
5c60a00
Moved LLDBServerPlugin into LLDB library.
clayborg Apr 9, 2025
cf005a8
Flesh out plugin system.
clayborg Apr 11, 2025
fbe1914
Add a JSON response to jGPUPluginBreakpointHit
clayborg Apr 11, 2025
a152eff
Add StreamGDBRemote methods to facilitate sending JSON.
clayborg Apr 11, 2025
3c1c238
Many fixes listed below.
clayborg Apr 12, 2025
9523096
Add arch and target triple support for AMD and NVidia GPUs.
clayborg Apr 16, 2025
0fc9010
Changes to the plug-in models.
clayborg Apr 23, 2025
6b18f90
Clean up the register context code for the Mock GPU.
clayborg Apr 29, 2025
3133713
Added the ability for GPU plug-ins to return shared libraries.
clayborg Apr 30, 2025
51a42b9
Add dynamic loader support for GPUs.
clayborg Apr 30, 2025
f051971
Get dynamic loader working and hooked up.
clayborg May 1, 2025
2de87a2
Added logging to GPU dynamic loader and fixed load address to be sent.
clayborg May 2, 2025
6eb4b23
Add the ability to set breakpoints by address.
clayborg May 5, 2025
65cc3e4
Added "bool load_libraries;" to the GPUActions structure.
clayborg May 6, 2025
cbc63f7
Add a stop reason class for the dynamic loader.
clayborg May 7, 2025
adc4a16
Fix typo in comment.
clayborg May 7, 2025
c5fcff7
Add the GDBRemoteCommunication this pointer to log.
clayborg May 7, 2025
7516ccd
Add gpu plug-ins as an extension.
clayborg May 7, 2025
33ca2a0
Rename some features and enums for gpu plug-ins and dyld.
clayborg May 7, 2025
cc4aaa5
Allow GPUActions to auto resume the GPU process.
clayborg May 8, 2025
1782a4c
Make module loading work within a file.
clayborg May 8, 2025
095224c
Add the ability to halt the native process from the GPU plug-in.
clayborg May 9, 2025
2e050ba
Added the ability to have the native process wait for the GPU process to
clayborg May 22, 2025
e5d5071
Fix ProcessGDBRemote::HandleGPUActions() to return an error.
clayborg May 28, 2025
0b720b8
[To upstream] Add proper error handling for GPU packets
walter-erquinigo Jun 5, 2025
88cd797
[To upstream] minor changes in the packets files
walter-erquinigo Jun 5, 2025
bc51f65
[To upstream] Add a name to server comm channels and include them in …
walter-erquinigo Jun 9, 2025
9a6f0df
Add a name to server comm channels and include them in the logs
walter-erquinigo Jun 9, 2025
1d8707e
[LLDB] Some minor changes in the packets files
walter-erquinigo Jun 9, 2025
67da4ab
[LLDB] Add proper error handling for GPU packets
walter-erquinigo Jun 9, 2025
7bbb34e
Check object offset in ModuleSpec matching
Jun 10, 2025
7e75eaf
Merge pull request #5 from clayborg/fix_module_spec_match
clayborg Jun 11, 2025
3fda41c
AMD GPU plugin v0
Jun 2, 2025
ca0b83a
Feedback from Greg
Jun 10, 2025
8dc5653
Some refactoring
Jun 12, 2025
2368a38
Merge pull request #4 from clayborg/amd-gpu-plugin
jeffreytan81 Jun 12, 2025
a919c5c
Add tests for amdgpu lldb-server plugin
dmpots Jun 18, 2025
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
17 changes: 15 additions & 2 deletions lldb/include/lldb/Host/common/NativeProcessProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/Iterable.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/GPUGDBRemotePackets.h"
#include "lldb/Utility/TraceGDBRemotePackets.h"
#include "lldb/Utility/UnimplementedError.h"
#include "lldb/lldb-private-forward.h"
Expand Down Expand Up @@ -179,6 +180,9 @@ class NativeProcessProtocol {
// Accessors
lldb::pid_t GetID() const { return m_pid; }

// Get process info
virtual bool GetProcessInfo(ProcessInstanceInfo &proc_info);

lldb::StateType GetState() const;

bool IsRunning() const {
Expand All @@ -187,7 +191,9 @@ class NativeProcessProtocol {

bool IsStepping() const { return m_state == lldb::eStateStepping; }

bool CanResume() const { return m_state == lldb::eStateStopped; }
bool IsStopped() const { return m_state == lldb::eStateStopped; }

bool CanResume() const { return IsStopped(); }

lldb::ByteOrder GetByteOrder() const {
return GetArchitecture().GetByteOrder();
Expand Down Expand Up @@ -252,6 +258,11 @@ class NativeProcessProtocol {
virtual Status GetFileLoadAddress(const llvm::StringRef &file_name,
lldb::addr_t &load_addr) = 0;

virtual std::optional<GPUDynamicLoaderResponse>
GetGPUDynamicLoaderLibraryInfos(const GPUDynamicLoaderArgs &args) {
return std::nullopt;
}

/// Extension flag constants, returned by Manager::GetSupportedExtensions()
/// and passed to SetEnabledExtension()
enum class Extension {
Expand All @@ -264,8 +275,10 @@ class NativeProcessProtocol {
memory_tagging = (1u << 6),
savecore = (1u << 7),
siginfo_read = (1u << 8),
gpu_plugins = (1u << 9),
gpu_dyld = (1u << 10),

LLVM_MARK_AS_BITMASK_ENUM(siginfo_read)
LLVM_MARK_AS_BITMASK_ENUM(gpu_dyld)
};

class Manager {
Expand Down
11 changes: 11 additions & 0 deletions lldb/include/lldb/Target/DynamicLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ class DynamicLoader : public PluginInterface {
/// loader often knows what the program entry point is. So the process and
/// the dynamic loader can work together to detect this.
virtual bool ProcessDidExec() { return false; }

/// A function that allows dynamic loader to handle eStopReasonDynammicLoader
/// stop reasons. This is intended for dynamic loaders that aren't able to
/// set a breakpoint in the process, but rely on being notified by a driver or
/// debug services that shared libraries are available.
///
/// \returns True if handled, false otherwise.
virtual bool HandleStopReasonDynammicLoader() {
return false;
}

/// Get whether the process should stop when images change.
///
/// When images (executables and shared libraries) get loaded or unloaded,
Expand Down
15 changes: 15 additions & 0 deletions lldb/include/lldb/Target/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,21 @@ class Process : public std::enable_shared_from_this<Process>,
SelectMostRelevant select_most_relevant =
DoNoSelectMostRelevantFrame);

/// Wait for the process to resume.
///
/// Given the current ProcessModID that identifies a current state, wait for
/// the process to resume.
///
/// \param[in] curr_resume_id
/// The resume ID that identifies the resume ID from a stopped state.
///
/// \param[in] timeout_sec
/// The maximum time in seconds to wait for the process to transition to
/// the eStateRunning state. If no timeout is supplied, block and wait
/// indefinitely.
Status WaitForNextResume(const uint32_t curr_resume_id,
std::optional<uint32_t> timeout_sec);

uint32_t GetIOHandlerID() const { return m_iohandler_sync.GetValue(); }

/// Waits for the process state to be running within a given msec timeout.
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/Target/StopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ class StopInfo : public std::enable_shared_from_this<StopInfo> {
static lldb::StopInfoSP
CreateStopReasonHistoryBoundary(Thread &thread, const char *description);

static lldb::StopInfoSP
CreateStopReasonDyld(Thread &thread, const char *description = nullptr);

static lldb::StopInfoSP CreateStopReasonFork(Thread &thread,
lldb::pid_t child_pid,
lldb::tid_t child_tid);
Expand Down
23 changes: 23 additions & 0 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,21 @@ class Target : public std::enable_shared_from_this<Target>,
/// Print all the signals set in this target.
void PrintDummySignals(Stream &strm, Args &signals);


lldb::TargetSP GetGPUPluginTarget(llvm::StringRef plugin_name) {
return m_gpu_plugin_targets.lookup(plugin_name).lock();
}

void SetGPUPluginTarget(llvm::StringRef plugin_name,
lldb::TargetSP target_sp) {
m_native_target_gpu_wp = shared_from_this();
m_gpu_plugin_targets[plugin_name] = target_sp;
}

lldb::TargetSP GetNativeTargetForGPU() {
return m_native_target_gpu_wp.lock();
}

protected:
/// Implementing of ModuleList::Notifier.

Expand Down Expand Up @@ -1634,6 +1649,14 @@ class Target : public std::enable_shared_from_this<Target>,
/// signals you will have.
llvm::StringMap<DummySignalValues> m_dummy_signals;

/// If a process spawns another target for a GPU plug-in, this map tracks the
/// associated plug-in targets so they can be accessed.
llvm::StringMap<lldb::TargetWP> m_gpu_plugin_targets;
/// If a target has a parent target, this can be used to synchronize the two
/// targets. For example if a GPU target wants to resume but it requires its
/// native target to resume as well, we can use this to make this happen.
lldb::TargetWP m_native_target_gpu_wp;

static void ImageSearchPathsChanged(const PathMappingList &path_list,
void *baton);

Expand Down
6 changes: 6 additions & 0 deletions lldb/include/lldb/Utility/ArchSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ class ArchSpec {

eCore_wasm32,

eCore_amd_gpu_r600,
eCore_amd_gpu_gcn,

eCore_nvidia_nvptx,
eCore_nvidia_nvptx64,

kNumCores,

kCore_invalid,
Expand Down
58 changes: 57 additions & 1 deletion lldb/include/lldb/Utility/GDBRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-public.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/JSON.h"

#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>

namespace lldb_private {

Expand All @@ -43,6 +43,62 @@ class StreamGDBRemote : public StreamString {
/// Number of bytes written.
// TODO: Convert this function to take ArrayRef<uint8_t>
int PutEscapedBytes(const void *s, size_t src_len);

/// Convert an object into JSON and add the JSON text to the packet.
///
/// Any special characters in the JSON will be escaped to make sure it doesn't
/// interfere with the GDB remote protocol packet format.
///
/// \param[in] obj
/// The object to convert to JSON which must have a method written that
/// converts the object to a llvm::json::Value:
///
/// \code llvm::json::Value toJSON(const T &obj);
///
/// \param[in] hex_ascii
/// If \a true then encode JSON as hex ASCII bytes. If \a false, then
/// encode as an escaped string value.
///
/// \return
/// Number of bytes written.
template<class T> int PutAsJSON(const T &obj, bool hex_ascii) {
std::string json_string;
llvm::raw_string_ostream os(json_string);
os << toJSON(obj);
if (hex_ascii)
return PutStringAsRawHex8(json_string);
else
return PutEscapedBytes(json_string.c_str(), json_string.size());
}
/// Convert an array of objects into JSON and add the JSON text to the packet.
///
/// Any special characters in the JSON will be escaped to make sure it doesn't
/// interfere with the GDB remote protocol packet format.
///
/// \param[in] array
/// An array of objects to convert to JSON. The object't type must have a
/// method written that converts the object to a llvm::json::Value:
///
/// \code llvm::json::Value toJSON(const T &obj);
///
/// \return
/// Number of bytes written.
template<class T> int PutAsJSONArray(const std::vector<T> &array) {
std::string json_string;
llvm::raw_string_ostream os(json_string);
bool first = true;
os << "[";
for (auto &obj: array) {
if (first)
first = false;
else
os << ",";
os << toJSON(obj);
}
os << "]";
return PutEscapedBytes(json_string.data(), json_string.size());
}

};

/// GDB remote packet as used by the GDB remote communication history. Packets
Expand Down
Loading