Skip to content

Commit d98da7c

Browse files
committed
[lldb] 167388 chore: add api to return arch name for target
Signed-off-by: Nikita B <[email protected]>
1 parent a464e38 commit d98da7c

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

lldb/examples/python/templates/scripted_process.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ def __init__(self, exe_ctx, args):
3535
target = exe_ctx.target
3636
if isinstance(target, lldb.SBTarget) and target.IsValid():
3737
self.target = target
38-
triple = self.target.triple
39-
if triple:
40-
self.arch = triple.split("-")[0]
38+
self.arch = target.arch_name
4139
self.dbg = target.GetDebugger()
4240
if isinstance(args, lldb.SBStructuredData) and args.IsValid():
4341
self.args = args

lldb/include/lldb/API/SBTarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ class LLDB_API SBTarget {
353353

354354
const char *GetTriple();
355355

356+
const char *GetArchName();
357+
356358
const char *GetABIName();
357359

358360
const char *GetLabel() const;

lldb/source/API/SBTarget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,19 @@ const char *SBTarget::GetTriple() {
16141614
return nullptr;
16151615
}
16161616

1617+
const char *SBTarget::GetArchName() {
1618+
LLDB_INSTRUMENT_VA(this);
1619+
1620+
if (TargetSP target_sp = GetSP()) {
1621+
std::string arch_name =
1622+
target_sp->GetArchitecture().GetTriple().getArchName().str();
1623+
ConstString const_arch_name(arch_name.c_str());
1624+
1625+
return const_arch_name.GetCString();
1626+
}
1627+
return nullptr;
1628+
}
1629+
16171630
const char *SBTarget::GetABIName() {
16181631
LLDB_INSTRUMENT_VA(this);
16191632

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ def test_resolve_file_address(self):
105105
self.assertIsNotNone(data_section2)
106106
self.assertEqual(data_section.name, data_section2.name)
107107

108+
def test_get_arch_name(self):
109+
d = {"EXE": "b.out"}
110+
self.build(dictionary=d)
111+
self.setTearDownCleanup(dictionary=d)
112+
target = self.create_simple_target("b.out")
113+
114+
arch_name = target.arch_name
115+
self.assertNotEqual(len(arch_name), 0, "Got an arch name string")
116+
117+
# Test consistency with GetTriple().
118+
triple = target.triple
119+
if triple:
120+
self.assertEqual(triple.split("-")[0], arch_name)
121+
108122
def test_get_ABIName(self):
109123
d = {"EXE": "b.out"}
110124
self.build(dictionary=d)

0 commit comments

Comments
 (0)