From d98da7c2df181f89560cc382208a9b4c6cff88f7 Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 15:46:12 +0100 Subject: [PATCH 01/11] [lldb] 167388 chore: add api to return arch name for target Signed-off-by: Nikita B --- lldb/examples/python/templates/scripted_process.py | 4 +--- lldb/include/lldb/API/SBTarget.h | 2 ++ lldb/source/API/SBTarget.cpp | 13 +++++++++++++ lldb/test/API/python_api/target/TestTargetAPI.py | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lldb/examples/python/templates/scripted_process.py b/lldb/examples/python/templates/scripted_process.py index 49059d533f38a..b4232f632a30a 100644 --- a/lldb/examples/python/templates/scripted_process.py +++ b/lldb/examples/python/templates/scripted_process.py @@ -35,9 +35,7 @@ def __init__(self, exe_ctx, args): target = exe_ctx.target if isinstance(target, lldb.SBTarget) and target.IsValid(): self.target = target - triple = self.target.triple - if triple: - self.arch = triple.split("-")[0] + self.arch = target.arch_name self.dbg = target.GetDebugger() if isinstance(args, lldb.SBStructuredData) and args.IsValid(): self.args = args diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index 379a0bb7e9513..d0da6aaa6044c 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -353,6 +353,8 @@ class LLDB_API SBTarget { const char *GetTriple(); + const char *GetArchName(); + const char *GetABIName(); const char *GetLabel() const; diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 98d10aa07c53f..f0458bb6b5fe5 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1614,6 +1614,19 @@ const char *SBTarget::GetTriple() { return nullptr; } +const char *SBTarget::GetArchName() { + LLDB_INSTRUMENT_VA(this); + + if (TargetSP target_sp = GetSP()) { + std::string arch_name = + target_sp->GetArchitecture().GetTriple().getArchName().str(); + ConstString const_arch_name(arch_name.c_str()); + + return const_arch_name.GetCString(); + } + return nullptr; +} + const char *SBTarget::GetABIName() { LLDB_INSTRUMENT_VA(this); diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index d346563af18e2..fdb8d820bcd08 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -105,6 +105,20 @@ def test_resolve_file_address(self): self.assertIsNotNone(data_section2) self.assertEqual(data_section.name, data_section2.name) + def test_get_arch_name(self): + d = {"EXE": "b.out"} + self.build(dictionary=d) + self.setTearDownCleanup(dictionary=d) + target = self.create_simple_target("b.out") + + arch_name = target.arch_name + self.assertNotEqual(len(arch_name), 0, "Got an arch name string") + + # Test consistency with GetTriple(). + triple = target.triple + if triple: + self.assertEqual(triple.split("-")[0], arch_name) + def test_get_ABIName(self): d = {"EXE": "b.out"} self.build(dictionary=d) From 0c966e6a0c3ff194a27664ef7c24f38793f0e641 Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 18:03:51 +0100 Subject: [PATCH 02/11] [lldb] 167388 chore: add api to return arch name for target: use target.GetArchName() instead of target.arch_name in script Signed-off-by: Nikita B --- lldb/examples/python/templates/scripted_process.py | 2 +- lldb/test/API/python_api/target/TestTargetAPI.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/examples/python/templates/scripted_process.py b/lldb/examples/python/templates/scripted_process.py index b4232f632a30a..25f17d7e71784 100644 --- a/lldb/examples/python/templates/scripted_process.py +++ b/lldb/examples/python/templates/scripted_process.py @@ -35,7 +35,7 @@ def __init__(self, exe_ctx, args): target = exe_ctx.target if isinstance(target, lldb.SBTarget) and target.IsValid(): self.target = target - self.arch = target.arch_name + self.arch = target.GetArchName() self.dbg = target.GetDebugger() if isinstance(args, lldb.SBStructuredData) and args.IsValid(): self.args = args diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index fdb8d820bcd08..b4a7bcbf3c8e3 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -111,7 +111,7 @@ def test_get_arch_name(self): self.setTearDownCleanup(dictionary=d) target = self.create_simple_target("b.out") - arch_name = target.arch_name + arch_name = target.GetArchName() self.assertNotEqual(len(arch_name), 0, "Got an arch name string") # Test consistency with GetTriple(). From 83750ddad6fd65cad4d62610d7dafb2cf8f091f1 Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 18:28:08 +0100 Subject: [PATCH 03/11] [lldb] 167388 chore: add api to return arch name for target: add arch_name readonly property to the binding Signed-off-by: Nikita B --- lldb/bindings/interface/SBTargetExtensions.i | 1 + 1 file changed, 1 insertion(+) diff --git a/lldb/bindings/interface/SBTargetExtensions.i b/lldb/bindings/interface/SBTargetExtensions.i index 43125d8970615..ef1093b03ced9 100644 --- a/lldb/bindings/interface/SBTargetExtensions.i +++ b/lldb/bindings/interface/SBTargetExtensions.i @@ -190,6 +190,7 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, lldb::eDescriptionLevelBrief) byte_order = property(GetByteOrder, None, doc='''A read only property that returns an lldb enumeration value (lldb.eByteOrderLittle, lldb.eByteOrderBig, lldb.eByteOrderInvalid) that represents the byte order for this target.''') addr_size = property(GetAddressByteSize, None, doc='''A read only property that returns the size in bytes of an address for this target.''') triple = property(GetTriple, None, doc='''A read only property that returns the target triple (arch-vendor-os) for this target as a string.''') + arch_name = property(GetArchName, None, doc='''A read only property that returns the architecture name for this target as a string.''') data_byte_size = property(GetDataByteSize, None, doc='''A read only property that returns the size in host bytes of a byte in the data address space for this target.''') code_byte_size = property(GetCodeByteSize, None, doc='''A read only property that returns the size in host bytes of a byte in the code address space for this target.''') platform = property(GetPlatform, None, doc='''A read only property that returns the platform associated with with this target.''') From 36497abb887c2392d27a17b5c80f2d3848e5d077 Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 18:53:05 +0100 Subject: [PATCH 04/11] [lldb] 167388 chore: add api to return arch name for target: use target.arch_name instead of target.GetArchName() in script Signed-off-by: Nikita B --- lldb/examples/python/templates/scripted_process.py | 2 +- lldb/test/API/python_api/target/TestTargetAPI.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/examples/python/templates/scripted_process.py b/lldb/examples/python/templates/scripted_process.py index 25f17d7e71784..b4232f632a30a 100644 --- a/lldb/examples/python/templates/scripted_process.py +++ b/lldb/examples/python/templates/scripted_process.py @@ -35,7 +35,7 @@ def __init__(self, exe_ctx, args): target = exe_ctx.target if isinstance(target, lldb.SBTarget) and target.IsValid(): self.target = target - self.arch = target.GetArchName() + self.arch = target.arch_name self.dbg = target.GetDebugger() if isinstance(args, lldb.SBStructuredData) and args.IsValid(): self.args = args diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index b4a7bcbf3c8e3..fdb8d820bcd08 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -111,7 +111,7 @@ def test_get_arch_name(self): self.setTearDownCleanup(dictionary=d) target = self.create_simple_target("b.out") - arch_name = target.GetArchName() + arch_name = target.arch_name self.assertNotEqual(len(arch_name), 0, "Got an arch name string") # Test consistency with GetTriple(). From 1b1d466ecdbcb0c11f860375d581bea2f54f5e5b Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 18:59:24 +0100 Subject: [PATCH 05/11] [lldb] 167388 chore: add api to return arch name for target: update comment in test Signed-off-by: Nikita B --- lldb/test/API/python_api/target/TestTargetAPI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index fdb8d820bcd08..7cb9a514b0f7d 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -114,7 +114,7 @@ def test_get_arch_name(self): arch_name = target.arch_name self.assertNotEqual(len(arch_name), 0, "Got an arch name string") - # Test consistency with GetTriple(). + # Test consistency with triple. triple = target.triple if triple: self.assertEqual(triple.split("-")[0], arch_name) From a3620de44fb6fd42aca8b469d24825a63a6d3223 Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 19:28:55 +0100 Subject: [PATCH 06/11] [lldb] 167388 chore: add api to return arch name for target: update formatting according to darker Signed-off-by: Nikita B --- lldb/test/API/python_api/target/TestTargetAPI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index 7cb9a514b0f7d..3eb6cb428e9ef 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -117,7 +117,7 @@ def test_get_arch_name(self): # Test consistency with triple. triple = target.triple if triple: - self.assertEqual(triple.split("-")[0], arch_name) + self.assertEqual(triple.split("-")[0], arch_name) def test_get_ABIName(self): d = {"EXE": "b.out"} From 2a4f2a3c00b9786f4e2ea3a1f9f44bc06a4f793d Mon Sep 17 00:00:00 2001 From: n2h9 <13541181+n2h9@users.noreply.github.com> Date: Sun, 16 Nov 2025 19:50:35 +0100 Subject: [PATCH 07/11] Update lldb/source/API/SBTarget.cpp Co-authored-by: Jonas Devlieghere --- lldb/source/API/SBTarget.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index f0458bb6b5fe5..f3b6794a4222e 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1618,9 +1618,9 @@ const char *SBTarget::GetArchName() { LLDB_INSTRUMENT_VA(this); if (TargetSP target_sp = GetSP()) { - std::string arch_name = - target_sp->GetArchitecture().GetTriple().getArchName().str(); - ConstString const_arch_name(arch_name.c_str()); + llvm::StringRef arch_name = + target_sp->GetArchitecture().GetTriple().getArchName(); + ConstString const_arch_name(arch_name); return const_arch_name.GetCString(); } From 329aec5b1a5f619247ae64d36944885e58cba142 Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 20:24:16 +0100 Subject: [PATCH 08/11] [lldb] 167388 chore: add api to return arch name for target: update test to check exact arch name string, repalce check if triple exists with assertion Signed-off-by: Nikita B --- lldb/test/API/python_api/target/TestTargetAPI.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index 3eb6cb428e9ef..a1520b9856b90 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -107,17 +107,18 @@ def test_resolve_file_address(self): def test_get_arch_name(self): d = {"EXE": "b.out"} - self.build(dictionary=d) + expected_arch = "x86_64" + self.build(dictionary=d, architecture=expected_arch) self.setTearDownCleanup(dictionary=d) target = self.create_simple_target("b.out") arch_name = target.arch_name - self.assertNotEqual(len(arch_name), 0, "Got an arch name string") + self.assertEqual(expected_arch, arch_name, "Got an expected arch name") # Test consistency with triple. triple = target.triple - if triple: - self.assertEqual(triple.split("-")[0], arch_name) + self.assertTrue(len(triple) > 0, "Got a triple") + self.assertEqual(triple.split("-")[0], arch_name, "Arch name is equal to the first item of the triple") def test_get_ABIName(self): d = {"EXE": "b.out"} From deddd048cdb8cba1fa6bc3fd2c4d45de90342ac9 Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 20:26:49 +0100 Subject: [PATCH 09/11] [lldb] 167388 chore: add api to return arch name for target: format with darker Signed-off-by: Nikita B --- lldb/test/API/python_api/target/TestTargetAPI.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index a1520b9856b90..98ff0de8dbffe 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -118,7 +118,11 @@ def test_get_arch_name(self): # Test consistency with triple. triple = target.triple self.assertTrue(len(triple) > 0, "Got a triple") - self.assertEqual(triple.split("-")[0], arch_name, "Arch name is equal to the first item of the triple") + self.assertEqual( + triple.split("-")[0], + arch_name, + "Arch name is equal to the first item of the triple", + ) def test_get_ABIName(self): d = {"EXE": "b.out"} From 0dfb712313fa7689e936e572fde6ac99197806df Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 20:42:16 +0100 Subject: [PATCH 10/11] [lldb] 167388 chore: add api to return arch name for target: update test to check exact arch name string, use current arch Signed-off-by: Nikita B --- lldb/test/API/python_api/target/TestTargetAPI.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index 98ff0de8dbffe..673960ee55538 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -107,11 +107,11 @@ def test_resolve_file_address(self): def test_get_arch_name(self): d = {"EXE": "b.out"} - expected_arch = "x86_64" - self.build(dictionary=d, architecture=expected_arch) + self.build(dictionary=d) self.setTearDownCleanup(dictionary=d) target = self.create_simple_target("b.out") + expected_arch = self.getArchitecture() arch_name = target.arch_name self.assertEqual(expected_arch, arch_name, "Got an expected arch name") From 92f654410e7fbe2e1780207484046bc550dda43a Mon Sep 17 00:00:00 2001 From: Nikita B Date: Sun, 16 Nov 2025 21:30:43 +0100 Subject: [PATCH 11/11] [lldb] 167388 chore: add api to return arch name for target: update to check only that arch_name is eq to triple first element Signed-off-by: Nikita B --- lldb/test/API/python_api/target/TestTargetAPI.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index 673960ee55538..d3c64d87375b4 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -111,9 +111,8 @@ def test_get_arch_name(self): self.setTearDownCleanup(dictionary=d) target = self.create_simple_target("b.out") - expected_arch = self.getArchitecture() arch_name = target.arch_name - self.assertEqual(expected_arch, arch_name, "Got an expected arch name") + self.assertTrue(len(arch_name) > 0, "Got an arch name") # Test consistency with triple. triple = target.triple