Skip to content

Commit ac1fe66

Browse files
committed
FindTargetWithUniqueID -> FindTargetByGloballyUniqueID and test case cleanup
1 parent 2b9de97 commit ac1fe66

File tree

9 files changed

+36
-28
lines changed

9 files changed

+36
-28
lines changed

lldb/include/lldb/API/SBDebugger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class LLDB_API SBDebugger {
360360
const char *arch);
361361

362362
/// Find a target with the specified unique ID
363-
lldb::SBTarget FindTargetWithUniqueID(lldb::user_id_t id);
363+
lldb::SBTarget FindTargetByGloballyUniqueID(lldb::user_id_t id);
364364

365365
/// Get the number of targets in the debugger.
366366
uint32_t GetNumTargets();

lldb/include/lldb/API/SBTarget.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,12 @@ class LLDB_API SBTarget {
357357

358358
const char *GetLabel() const;
359359

360-
/// Get the globally unique ID for this target.
360+
/// Get the globally unique ID for this target. This ID is unique
361+
/// across all debugger instances within the same lldb process.
361362
///
362363
/// \return
363-
/// The globally unique ID for this target, or LLDB_INVALID_TARGET_ID if
364-
/// the target is invalid.
364+
/// The globally unique ID for this target, or
365+
/// LLDB_INVALID_GLOBALLY_UNIQUE_TARGET_ID if the target is invalid.
365366
lldb::user_id_t GetGloballyUniqueID() const;
366367

367368
SBError SetLabel(const char *label);

lldb/include/lldb/Target/Target.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class Target : public std::enable_shared_from_this<Target>,
603603
/// Get the globally unique ID for this target.
604604
///
605605
/// This ID is unique across all debugger instances and all targets,
606-
/// not just within this debugger's target list. The ID is assigned
606+
/// within the same lldb process. The ID is assigned
607607
/// during target construction and remains constant for the target's lifetime.
608608
/// The first target created (typically the dummy target) gets ID 1.
609609
///
@@ -1663,7 +1663,8 @@ class Target : public std::enable_shared_from_this<Target>,
16631663
bool m_is_dummy_target;
16641664
unsigned m_next_persistent_variable_index = 0;
16651665
lldb::user_id_t m_target_unique_id =
1666-
LLDB_INVALID_TARGET_ID; /// The unique ID assigned to this target
1666+
LLDB_INVALID_GLOBALLY_UNIQUE_TARGET_ID; /// The globally unique ID
1667+
/// assigned to this target
16671668
/// An optional \a lldb_private::Trace object containing processor trace
16681669
/// information of this target.
16691670
lldb::TraceSP m_trace_sp;

lldb/include/lldb/Target/TargetList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class TargetList : public Broadcaster {
168168
/// A shared pointer to a target object. The returned shared
169169
/// pointer will contain nullptr if no target objects has a
170170
/// matching target ID.
171-
lldb::TargetSP FindTargetWithUniqueID(lldb::user_id_t id) const;
171+
lldb::TargetSP FindTargetByGloballyUniqueID(lldb::user_id_t id) const;
172172

173173
lldb::TargetSP GetTargetSP(Target *target) const;
174174

lldb/include/lldb/lldb-defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
#define LLDB_INVALID_QUEUE_ID 0
9797
#define LLDB_INVALID_CPU_ID UINT32_MAX
9898
#define LLDB_INVALID_WATCHPOINT_RESOURCE_ID UINT32_MAX
99-
#define LLDB_INVALID_TARGET_ID 0
99+
#define LLDB_INVALID_GLOBALLY_UNIQUE_TARGET_ID 0
100100

101101
/// CPU Type definitions
102102
#define LLDB_ARCH_DEFAULT "systemArch"

lldb/source/API/SBDebugger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,12 +983,13 @@ uint32_t SBDebugger::GetIndexOfTarget(lldb::SBTarget target) {
983983
return m_opaque_sp->GetTargetList().GetIndexOfTarget(target.GetSP());
984984
}
985985

986-
SBTarget SBDebugger::FindTargetWithUniqueID(lldb::user_id_t id) {
986+
SBTarget SBDebugger::FindTargetByGloballyUniqueID(lldb::user_id_t id) {
987987
LLDB_INSTRUMENT_VA(this, id);
988988
SBTarget sb_target;
989989
if (m_opaque_sp) {
990990
// No need to lock, the target list is thread safe
991-
sb_target.SetSP(m_opaque_sp->GetTargetList().FindTargetWithUniqueID(id));
991+
sb_target.SetSP(
992+
m_opaque_sp->GetTargetList().FindTargetByGloballyUniqueID(id));
992993
}
993994
return sb_target;
994995
}

lldb/source/API/SBTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ lldb::user_id_t SBTarget::GetGloballyUniqueID() const {
16371637

16381638
if (TargetSP target_sp = GetSP())
16391639
return target_sp->GetGloballyUniqueID();
1640-
return LLDB_INVALID_TARGET_ID;
1640+
return LLDB_INVALID_GLOBALLY_UNIQUE_TARGET_ID;
16411641
}
16421642

16431643
SBError SBTarget::SetLabel(const char *label) {

lldb/source/Target/TargetList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ TargetSP TargetList::FindTargetWithProcess(Process *process) const {
428428
return target_sp;
429429
}
430430

431-
TargetSP TargetList::FindTargetWithUniqueID(lldb::user_id_t id) const {
431+
TargetSP TargetList::FindTargetByGloballyUniqueID(lldb::user_id_t id) const {
432432
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
433433
auto it = llvm::find_if(m_target_list, [id](const TargetSP &item) {
434434
return item->GetGloballyUniqueID() == id;

lldb/test/API/python_api/debugger/TestDebuggerAPI.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ def test_version(self):
296296
self.assertEqual(class_str, property_str)
297297

298298
def test_find_target_with_unique_id(self):
299-
"""Test SBDebugger.FindTargetWithUniqueID() functionality."""
299+
"""Test SBDebugger.FindTargetByGloballyUniqueID() functionality."""
300300

301301
# Test with invalid ID - should return invalid target
302-
invalid_target = self.dbg.FindTargetWithUniqueID(999999)
302+
invalid_target = self.dbg.FindTargetByGloballyUniqueID(999999)
303303
self.assertFalse(invalid_target.IsValid())
304304

305305
# Test with ID 0 - should return invalid target
306-
zero_target = self.dbg.FindTargetWithUniqueID(0)
306+
zero_target = self.dbg.FindTargetByGloballyUniqueID(0)
307307
self.assertFalse(zero_target.IsValid())
308308

309309
# Build a real executable and create target with it
@@ -314,8 +314,8 @@ def test_find_target_with_unique_id(self):
314314

315315
# Find the target using its unique ID
316316
unique_id = target.GetGloballyUniqueID()
317-
self.assertNotEqual(unique_id, 0)
318-
found_target = self.dbg.FindTargetWithUniqueID(unique_id)
317+
self.assertNotEqual(unique_id, lldb.LLDB_INVALID_GLOBALLY_UNIQUE_TARGET_ID)
318+
found_target = self.dbg.FindTargetByGloballyUniqueID(unique_id)
319319
self.assertTrue(found_target.IsValid())
320320
self.assertEqual(
321321
self.dbg.GetIndexOfTarget(target), self.dbg.GetIndexOfTarget(found_target)
@@ -349,7 +349,7 @@ def test_target_unique_id_uniqueness(self):
349349
# Verify all targets can still be found by their IDs
350350
for target in targets:
351351
unique_id = target.GetGloballyUniqueID()
352-
found = self.dbg.FindTargetWithUniqueID(unique_id)
352+
found = self.dbg.FindTargetByGloballyUniqueID(unique_id)
353353
self.assertTrue(found.IsValid())
354354
self.assertEqual(found.GetGloballyUniqueID(), unique_id)
355355

@@ -370,8 +370,8 @@ def test_target_unique_id_uniqueness_after_deletion(self):
370370
self.assertNotEqual(unique_id1, unique_id2)
371371

372372
# Verify we can find them initially
373-
found_target1 = self.dbg.FindTargetWithUniqueID(unique_id1)
374-
found_target2 = self.dbg.FindTargetWithUniqueID(unique_id2)
373+
found_target1 = self.dbg.FindTargetByGloballyUniqueID(unique_id1)
374+
found_target2 = self.dbg.FindTargetByGloballyUniqueID(unique_id2)
375375
self.assertTrue(found_target1.IsValid())
376376
self.assertTrue(found_target2.IsValid())
377377
target2_index = self.dbg.GetIndexOfTarget(target2)
@@ -381,7 +381,7 @@ def test_target_unique_id_uniqueness_after_deletion(self):
381381
self.assertTrue(deleted)
382382

383383
# Try to find the deleted target - should not be found
384-
not_found_target = self.dbg.FindTargetWithUniqueID(unique_id2)
384+
not_found_target = self.dbg.FindTargetByGloballyUniqueID(unique_id2)
385385
self.assertFalse(not_found_target.IsValid())
386386

387387
# Create a new target
@@ -395,7 +395,9 @@ def test_target_unique_id_uniqueness_after_deletion(self):
395395
self.assertNotEqual(unique_id3, unique_id2)
396396
self.assertNotEqual(unique_id3, unique_id1)
397397
# Make sure we can find the new target
398-
found_target3 = self.dbg.FindTargetWithUniqueID(target3.GetGloballyUniqueID())
398+
found_target3 = self.dbg.FindTargetByGloballyUniqueID(
399+
target3.GetGloballyUniqueID()
400+
)
399401
self.assertTrue(found_target3.IsValid())
400402

401403
def test_target_globally_unique_id_across_debuggers(self):
@@ -406,6 +408,8 @@ def test_target_globally_unique_id_across_debuggers(self):
406408
# Create two debuggers with targets each
407409
debugger1 = lldb.SBDebugger.Create()
408410
debugger2 = lldb.SBDebugger.Create()
411+
self.addTearDownHook(lambda: lldb.SBDebugger.Destroy(debugger1))
412+
self.addTearDownHook(lambda: lldb.SBDebugger.Destroy(debugger2))
409413

410414
# Create 2 targets per debugger
411415
targets_d1 = [debugger1.CreateTarget(exe), debugger1.CreateTarget(exe)]
@@ -417,22 +421,23 @@ def test_target_globally_unique_id_across_debuggers(self):
417421
self.assertEqual(
418422
len(set(ids)), len(ids), f"IDs should be globally unique: {ids}"
419423
)
420-
self.assertTrue(all(uid > 0 for uid in ids), "All IDs should be non-zero")
424+
self.assertTrue(
425+
all(uid != lldb.LLDB_INVALID_GLOBALLY_UNIQUE_TARGET_ID for uid in ids),
426+
"All IDs should be valid",
427+
)
421428

422429
# Verify targets can be found by their IDs in respective debuggers
423430
for debugger, target_pair in [
424431
(debugger1, targets[:2]),
425432
(debugger2, targets[2:]),
426433
]:
427434
for target in target_pair:
428-
found = debugger.FindTargetWithUniqueID(target.GetGloballyUniqueID())
435+
found = debugger.FindTargetByGloballyUniqueID(
436+
target.GetGloballyUniqueID()
437+
)
429438
self.assertTrue(
430439
found.IsValid(), "Target should be found by its unique ID"
431440
)
432441
self.assertEqual(
433442
found.GetGloballyUniqueID(), target.GetGloballyUniqueID()
434443
)
435-
436-
# Clean up
437-
lldb.SBDebugger.Destroy(debugger1)
438-
lldb.SBDebugger.Destroy(debugger2)

0 commit comments

Comments
 (0)