Skip to content

Commit f05dc40

Browse files
committed
Fix SBDebugger::CreateTargetWithFileAndArch to accept LLDB_ARCH_DEFAULT.
The API docs in SBDebugger.i claim this should work but it doesn't. This should fix it. Differential Revision: https://reviews.llvm.org/D95164
1 parent 0f0462c commit f05dc40

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lldb/source/API/SBDebugger.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,11 +805,13 @@ SBTarget SBDebugger::CreateTargetWithFileAndArch(const char *filename,
805805
if (m_opaque_sp) {
806806
Status error;
807807
const bool add_dependent_modules = true;
808-
808+
PlatformSP platform_sp = m_opaque_sp->GetPlatformList().GetSelectedPlatform();
809+
ArchSpec arch = Platform::GetAugmentedArchSpec(
810+
platform_sp.get(), arch_cstr);
809811
error = m_opaque_sp->GetTargetList().CreateTarget(
810-
*m_opaque_sp, filename, arch_cstr,
811-
add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
812-
target_sp);
812+
*m_opaque_sp, filename, arch,
813+
add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo,
814+
platform_sp, target_sp);
813815

814816
if (error.Success())
815817
sb_target.SetSP(target_sp);

lldb/test/API/python_api/target/TestTargetAPI.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,15 @@ def resolve_symbol_context_with_address(self):
476476
desc2 = get_description(symbol2)
477477
self.assertTrue(desc1 and desc2 and desc1 == desc2,
478478
"The two addresses should resolve to the same symbol")
479+
def test_default_arch(self):
480+
""" Test the other two target create methods using LLDB_ARCH_DEFAULT. """
481+
self.build()
482+
exe = self.getBuildArtifact("a.out")
483+
target = self.dbg.CreateTargetWithFileAndArch(exe, lldb.LLDB_ARCH_DEFAULT)
484+
self.assertTrue(target.IsValid(), "Default arch made a valid target.")
485+
# This should also work with the target's triple:
486+
target2 = self.dbg.CreateTargetWithFileAndArch(exe, target.GetTriple())
487+
self.assertTrue(target2.IsValid(), "Round trip with triple works")
488+
# And this triple should work for the FileAndTriple API:
489+
target3 = self.dbg.CreateTargetWithFileAndTargetTriple(exe, target.GetTriple())
490+
self.assertTrue(target3.IsValid())

0 commit comments

Comments
 (0)