[Lldb-commits] [PATCH] D95164: Make SBDebugger::CreateTargetWithFileAndArch accept lldb.LLDB_DEFAULT_ARCH

Jim Ingham via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 21 12:41:37 PST 2021


jingham created this revision.
jingham added reviewers: clayborg, jasonmolenda, labath.
jingham requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The header docs in SBDebugger.i suggest:

  target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT)

but that call doesn't actually produce a valid target.  The equivalent API - FindTargetWithFileAndArch does work, because it uses the current platform to translate LLDB_ARCH_DEFAULT.  This patch just adds that same step to CreateTargetWithFileAndArch, and adds a test.

This API was untested so I also added a test for this one and the similar CreateTargetWithFileAndTargetTriple.

I don't see anywhere where we say what the difference between an "Arch" and a "TargetTriple" is.  If anybody has some good verbiage for that, I'll add it to the docs for the API.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95164

Files:
  lldb/source/API/SBDebugger.cpp
  lldb/test/API/python_api/target/TestTargetAPI.py


Index: lldb/test/API/python_api/target/TestTargetAPI.py
===================================================================
--- lldb/test/API/python_api/target/TestTargetAPI.py
+++ lldb/test/API/python_api/target/TestTargetAPI.py
@@ -476,3 +476,15 @@
         desc2 = get_description(symbol2)
         self.assertTrue(desc1 and desc2 and desc1 == desc2,
                         "The two addresses should resolve to the same symbol")
+    def test_default_arch(self):
+        """ Test the other two target create methods using LLDB_ARCH_DEFAULT. """
+        self.build()
+        exe = self.getBuildArtifact("a.out")
+        target = self.dbg.CreateTargetWithFileAndArch(exe, lldb.LLDB_ARCH_DEFAULT)
+        self.assertTrue(target.IsValid(), "Default arch made a valid target.")
+        # This should also work with the target's triple:
+        target2 = self.dbg.CreateTargetWithFileAndArch(exe, target.GetTriple())
+        self.assertTrue(target2.IsValid(), "Round trip with triple works")
+        # And this triple should work for the FileAndTriple API:
+        target3 = self.dbg.CreateTargetWithFileAndTargetTriple(exe, target.GetTriple())
+        self.assertTrue(target3.IsValid())
Index: lldb/source/API/SBDebugger.cpp
===================================================================
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -805,11 +805,13 @@
   if (m_opaque_sp) {
     Status error;
     const bool add_dependent_modules = true;
-
+    PlatformSP platform_sp = m_opaque_sp->GetPlatformList().GetSelectedPlatform();
+    ArchSpec arch = Platform::GetAugmentedArchSpec(
+        platform_sp.get(), arch_cstr);
     error = m_opaque_sp->GetTargetList().CreateTarget(
-        *m_opaque_sp, filename, arch_cstr,
-        add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
-        target_sp);
+        *m_opaque_sp, filename, arch,
+        add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, 
+        platform_sp, target_sp);
 
     if (error.Success())
       sb_target.SetSP(target_sp);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95164.318288.patch
Type: text/x-patch
Size: 2075 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210121/8df6f16b/attachment.bin>


More information about the lldb-commits mailing list