Skip to content

Commit 79a88ef

Browse files
committed
Unique target ids + dap_session_name -> session_name
1 parent fef5e1f commit 79a88ef

File tree

12 files changed

+57
-47
lines changed

12 files changed

+57
-47
lines changed

lldb/include/lldb/API/SBTarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class LLDB_API SBTarget {
7070
static lldb::SBModule GetModuleAtIndexFromEvent(const uint32_t idx,
7171
const lldb::SBEvent &event);
7272

73-
static const char *GetDAPSessionNameFromEvent(const SBEvent &event);
73+
static const char *GetSessionNameFromEvent(const SBEvent &event);
7474

7575
static const char *GetBroadcasterClassName();
7676

lldb/include/lldb/Target/Target.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,10 @@ class Target : public std::enable_shared_from_this<Target>,
558558
TargetEventData(const lldb::TargetSP &target_sp,
559559
const ModuleList &module_list);
560560

561-
TargetEventData(const lldb::TargetSP &target_sp,
562-
std::string dap_session_name);
561+
TargetEventData(const lldb::TargetSP &target_sp, std::string session_name);
563562

564563
TargetEventData(const lldb::TargetSP &target_sp,
565-
const ModuleList &module_list,
566-
std::string dap_session_name);
564+
const ModuleList &module_list, std::string session_name);
567565

568566
~TargetEventData() override;
569567

@@ -573,7 +571,7 @@ class Target : public std::enable_shared_from_this<Target>,
573571
return TargetEventData::GetFlavorString();
574572
}
575573

576-
static llvm::StringRef GetDAPSessionNameFromEvent(const Event *event_ptr);
574+
static llvm::StringRef GetSessionNameFromEvent(const Event *event_ptr);
577575

578576
void Dump(Stream *s) const override;
579577

@@ -590,7 +588,7 @@ class Target : public std::enable_shared_from_this<Target>,
590588
private:
591589
lldb::TargetSP m_target_sp;
592590
ModuleList m_module_list;
593-
std::string m_dap_session_name = "";
591+
std::string m_session_name = "";
594592

595593
TargetEventData(const TargetEventData &) = delete;
596594
const TargetEventData &operator=(const TargetEventData &) = delete;
@@ -612,6 +610,12 @@ class Target : public std::enable_shared_from_this<Target>,
612610

613611
bool IsDummyTarget() const { return m_is_dummy_target; }
614612

613+
/// Get the unique ID for this target.
614+
///
615+
/// \return
616+
/// The unique ID for this target, or 0 if no ID has been assigned.
617+
uint32_t GetUniqueID() const { return m_target_unique_id; }
618+
615619
const std::string &GetLabel() const { return m_label; }
616620

617621
/// Set a label for a target.
@@ -1700,6 +1704,7 @@ class Target : public std::enable_shared_from_this<Target>,
17001704
bool m_suppress_stop_hooks; /// Used to not run stop hooks for expressions
17011705
bool m_is_dummy_target;
17021706
unsigned m_next_persistent_variable_index = 0;
1707+
uint32_t m_target_unique_id = 0; /// The unique ID assigned to this target
17031708
/// An optional \a lldb_private::Trace object containing processor trace
17041709
/// information of this target.
17051710
lldb::TraceSP m_trace_sp;

lldb/include/lldb/Utility/GPUGDBRemotePackets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct GPUActions {
228228
/// The name of the plugin.
229229
std::string plugin_name;
230230
/// The name to give a DAP session
231-
std::string dap_session_name;
231+
std::string session_name;
232232
/// Unique identifier for every GPU action.
233233
uint32_t identifier = 0;
234234
/// The stop ID in the process that this action is associated with. If the

lldb/source/API/SBTarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx,
145145
return SBModule(module_list.GetModuleAtIndex(idx));
146146
}
147147

148-
const char *SBTarget::GetDAPSessionNameFromEvent(const SBEvent &event) {
148+
const char *SBTarget::GetSessionNameFromEvent(const SBEvent &event) {
149149
LLDB_INSTRUMENT_VA(event);
150150

151151
return ConstString(
152-
Target::TargetEventData::GetDAPSessionNameFromEvent(event.get()))
152+
Target::TargetEventData::GetSessionNameFromEvent(event.get()))
153153
.AsCString();
154154
}
155155

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ Status ProcessGDBRemote::HandleConnectionRequest(const GPUActions &gpu_action) {
11151115
"created process!!!");
11161116
auto event_sp = std::make_shared<Event>(
11171117
Target::eBroadcastBitNewTargetCreated,
1118-
new Target::TargetEventData(gpu_target_sp, gpu_action.dap_session_name));
1118+
new Target::TargetEventData(gpu_target_sp, gpu_action.session_name));
11191119
GetTarget().BroadcastEvent(event_sp);
11201120
return Status();
11211121
}

lldb/source/Target/Target.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5153,14 +5153,14 @@ Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp,
51535153
: TargetEventData(target_sp, module_list, "") {}
51545154

51555155
Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp,
5156-
std::string dap_session_name)
5157-
: TargetEventData(target_sp, ModuleList(), std::move(dap_session_name)) {}
5156+
std::string session_name)
5157+
: TargetEventData(target_sp, ModuleList(), std::move(session_name)) {}
51585158

51595159
Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp,
51605160
const ModuleList &module_list,
5161-
std::string dap_session_name)
5161+
std::string session_name)
51625162
: EventData(), m_target_sp(target_sp), m_module_list(module_list),
5163-
m_dap_session_name(std::move(dap_session_name)) {}
5163+
m_session_name(std::move(session_name)) {}
51645164

51655165
Target::TargetEventData::~TargetEventData() = default;
51665166

@@ -5197,10 +5197,10 @@ TargetSP Target::TargetEventData::GetTargetFromEvent(const Event *event_ptr) {
51975197
}
51985198

51995199
llvm::StringRef
5200-
Target::TargetEventData::GetDAPSessionNameFromEvent(const Event *event_ptr) {
5200+
Target::TargetEventData::GetSessionNameFromEvent(const Event *event_ptr) {
52015201
const TargetEventData *event_data = GetEventDataFromEvent(event_ptr);
52025202
if (event_data)
5203-
return event_data->m_dap_session_name;
5203+
return event_data->m_session_name;
52045204
return llvm::StringRef();
52055205
}
52065206

lldb/source/Target/TargetList.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Status TargetList::CreateTargetInternal(
176176
module_spec.GetArchitecture() = arch;
177177
if (module_specs.FindMatchingModuleSpec(module_spec,
178178
matching_module_spec))
179-
update_platform_arch(matching_module_spec.GetArchitecture());
179+
update_platform_arch(matching_module_spec.GetArchitecture());
180180
} else {
181181
// Fat binary. No architecture specified, check if there is
182182
// only one platform for all of the architectures.
@@ -256,6 +256,9 @@ Status TargetList::CreateTargetInternal(Debugger &debugger,
256256
Status error;
257257
const bool is_dummy_target = false;
258258

259+
// Global static counter for assigning unique IDs to targets
260+
static uint32_t g_target_unique_id = 0;
261+
259262
ArchSpec arch(specified_arch);
260263

261264
if (arch.IsValid()) {
@@ -294,7 +297,7 @@ Status TargetList::CreateTargetInternal(Debugger &debugger,
294297

295298
if (file.IsRelative() && !user_exe_path.empty()) {
296299
llvm::SmallString<64> cwd;
297-
if (! llvm::sys::fs::current_path(cwd)) {
300+
if (!llvm::sys::fs::current_path(cwd)) {
298301
FileSpec cwd_file(cwd.c_str());
299302
cwd_file.AppendPathComponent(file);
300303
if (FileSystem::Instance().Exists(cwd_file))
@@ -344,6 +347,8 @@ Status TargetList::CreateTargetInternal(Debugger &debugger,
344347
if (!target_sp)
345348
return error;
346349

350+
target_sp->m_target_unique_id = ++g_target_unique_id;
351+
347352
// Set argv0 with what the user typed, unless the user specified a
348353
// directory. If the user specified a directory, then it is probably a
349354
// bundle that was resolved and we need to use the resolved bundle path
@@ -431,8 +436,7 @@ TargetSP TargetList::FindTargetWithProcess(Process *process) const {
431436
TargetSP TargetList::FindTargetWithUniqueID(uint32_t id) const {
432437
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
433438
auto it = llvm::find_if(m_target_list, [id](const TargetSP &item) {
434-
auto *process_ptr = item->GetProcessSP().get();
435-
return process_ptr && (process_ptr->GetUniqueID() == id);
439+
return item->GetUniqueID() == id;
436440
});
437441

438442
if (it != m_target_list.end())
@@ -567,29 +571,27 @@ bool TargetList::AnyTargetContainsModule(Module &module) {
567571
if (target_sp->GetImages().FindModule(&module))
568572
return true;
569573
}
570-
for (const auto &target_sp: m_in_process_target_list) {
574+
for (const auto &target_sp : m_in_process_target_list) {
571575
if (target_sp->GetImages().FindModule(&module))
572576
return true;
573577
}
574578
return false;
575579
}
576580

577-
void TargetList::RegisterInProcessTarget(TargetSP target_sp) {
578-
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
579-
[[maybe_unused]] bool was_added;
580-
std::tie(std::ignore, was_added) =
581-
m_in_process_target_list.insert(target_sp);
582-
assert(was_added && "Target pointer was left in the in-process map");
583-
}
584-
585-
void TargetList::UnregisterInProcessTarget(TargetSP target_sp) {
586-
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
587-
[[maybe_unused]] bool was_present =
588-
m_in_process_target_list.erase(target_sp);
589-
assert(was_present && "Target pointer being removed was not registered");
590-
}
591-
592-
bool TargetList::IsTargetInProcess(TargetSP target_sp) {
593-
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
594-
return m_in_process_target_list.count(target_sp) == 1;
595-
}
581+
void TargetList::RegisterInProcessTarget(TargetSP target_sp) {
582+
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
583+
[[maybe_unused]] bool was_added;
584+
std::tie(std::ignore, was_added) = m_in_process_target_list.insert(target_sp);
585+
assert(was_added && "Target pointer was left in the in-process map");
586+
}
587+
588+
void TargetList::UnregisterInProcessTarget(TargetSP target_sp) {
589+
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
590+
[[maybe_unused]] bool was_present = m_in_process_target_list.erase(target_sp);
591+
assert(was_present && "Target pointer being removed was not registered");
592+
}
593+
594+
bool TargetList::IsTargetInProcess(TargetSP target_sp) {
595+
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
596+
return m_in_process_target_list.count(target_sp) == 1;
597+
}

lldb/source/Utility/GPUGDBRemotePackets.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool fromJSON(const llvm::json::Value &value, GPUActions &data,
166166
llvm::json::Path path) {
167167
ObjectMapper o(value, path);
168168
return o && o.map("plugin_name", data.plugin_name) &&
169-
o.map("dap_session_name", data.dap_session_name) &&
169+
o.map("session_name", data.session_name) &&
170170
o.map("identifier", data.identifier) &&
171171
o.mapOptional("stop_id", data.stop_id) &&
172172
o.map("breakpoints", data.breakpoints) &&
@@ -192,6 +192,9 @@ llvm::json::Value toJSON(const GPUActions &data) {
192192

193193
return json::Value(Object{
194194
{"plugin_name", data.plugin_name},
195+
{"session_name", data.session_name},
196+
{"identifier", data.identifier},
197+
{"stop_id", data.stop_id},
195198
{"breakpoints", data.breakpoints},
196199
{"connect_info", data.connect_info},
197200
{"wait_for_gpu_process_to_stop", data.wait_for_gpu_process_to_stop},

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ void DAP::EventThread() {
14981498
attach_config.try_emplace("type", "lldb");
14991499
attach_config.try_emplace("targetId", target_id);
15001500
const char *session_name =
1501-
lldb::SBTarget::GetDAPSessionNameFromEvent(event);
1501+
lldb::SBTarget::GetSessionNameFromEvent(event);
15021502
if (session_name && *session_name) {
15031503
attach_config.try_emplace("name", session_name);
15041504
} else {

lldb/tools/lldb-server/Plugins/AMDGPU/LLDBServerPluginAMDGPU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ LLDBServerPluginAMDGPU::~LLDBServerPluginAMDGPU() { }
164164

165165
llvm::StringRef LLDBServerPluginAMDGPU::GetPluginName() { return "amd-gpu"; }
166166

167-
llvm::StringRef LLDBServerPluginAMDGPU::GetDAPSessionName() {
167+
llvm::StringRef LLDBServerPluginAMDGPU::GetSessionName() {
168168
return "AMD GPU Session";
169169
}
170170

@@ -467,7 +467,7 @@ bool LLDBServerPluginAMDGPU::ReadyToSetGpuLoaderBreakpointByAddress() {
467467
GPUActions LLDBServerPluginAMDGPU::SetConnectionInfo() {
468468
GPUActions actions = GetNewGPUAction();
469469
actions.connect_info = CreateConnection();
470-
actions.dap_session_name = GetDAPSessionName();
470+
actions.session_name = GetSessionName();
471471
return actions;
472472
}
473473

0 commit comments

Comments
 (0)