Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lldb/bindings/interface/SBTargetExtensions.i
Original file line number Diff line number Diff line change
Expand Up @@ -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.''')
Expand Down
4 changes: 1 addition & 3 deletions lldb/examples/python/templates/scripted_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ class LLDB_API SBTarget {

const char *GetTriple();

const char *GetArchName();

const char *GetABIName();

const char *GetLabel() const;
Expand Down
13 changes: 13 additions & 0 deletions lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions lldb/test/API/python_api/target/TestTargetAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better test would check for a specific arch name. Since the binary doesn't need to run, can we target a specific arg in the build dictionary and then check for that, rather than the fact that we have "something"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

I tried to specify architecture when calling self.build, like in this commit 329aec5
but it does not work as expected, looks like the architecture is still the runtime one (if I put arm there GetArchName still returns x86_64, which is what I use to run the test).
Or how one properly specifies the specific architecture?

So, I used the value from self.getArchitecture() to assert the value from arch_name, it is working fine on my platform, will it be ok to use this value for assertion?

Also we could probably just assert that the arch_name is eq to the first element of the `triple, as this is probably we expect from this method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is not a correct one, if I run test specifying a different arch, like this

./build/bin/lldb-dotest \
        -v -p TestTargetAPI.py \
        -f test_get_arch_name_dwarf \
        -f test_get_arch_name_dwo \
        -f test_get_arch_name_dsym \
        --arch aarch64 \
        lldb/test/API/python_api/target

arch_name returns me x86_64 😢
let me double check why . . .

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think right now when performing build in tests, it does not take into account architecture from --arch or from self.build.

I assume it prepares build command in builder.py:293 which uses builder.py::getTriple which does not take into account provided arch and always use arch from configuration.

I can suggest for now to only check that arch_name is eq to first part of triple.
And I could probably create a ticket to investigate / solve this issue with taking into account architecture during test build, what do you think?

Copy link
Author

@n2h9 n2h9 Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated for now to only compare that arch_name is same as triple first element ✅ .
And created and issue from above comment #168286

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify the ARCH in the build dictionary?

dictionary={
  "EXE": "b.out",
  "arch": arch,
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case build also does not take architecture into account, tried both arch and architecture 😢 .

        expected_arch = "aarch64"
        d = {
            "EXE": "b.out",
            "arch": expected_arch,
        }
        self.build(dictionary=d)

       ....

        print(">>>>")
        print(f"target.arch_name = {target.arch_name}")
        print("<<<<")

test command output with traces
./build/bin/lldb-dotest \
	-v -t -p TestTargetAPI.py \
	-f test_get_arch_name_dwarf \
	-f test_get_arch_name_dwo \
	-f test_get_arch_name_dsym \
	--arch aarch64 \
	lldb/test/API/python_api/target



/usr/bin/python3 /home/ubuntu/code/llvm-project/lldb/test/API/dotest.py --arch x86_64 -u CXXFLAGS -u CFLAGS --build-dir /home/ubuntu/code/llvm-project/build/lldb-test-build.noindex --executable /home/ubuntu/code/llvm-project/build/./bin/lldb --compiler /home/ubuntu/code/llvm-project/build/./bin/clang --dsymutil /home/ubuntu/code/llvm-project/build/./bin/dsymutil --make /usr/bin/gmake --lldb-libs-dir /home/ubuntu/code/llvm-project/build/./lib --llvm-tools-dir /home/ubuntu/code/llvm-project/build/./bin --lldb-obj-root /home/ubuntu/code/llvm-project/build/tools/lldb --cmake-build-type Debug -v -t -p TestTargetAPI.py -f test_get_arch_name_dwarf -f test_get_arch_name_dwo -f test_get_arch_name_dsym --arch aarch64 lldb/test/API/python_api/target
lldb version 22.0.0git (https://github.com/n2h9/fork-llvm-project revision 0dfb712313fa7689e936e572fde6ac99197806df)
  clang revision 0dfb712313fa7689e936e572fde6ac99197806df
  llvm revision 0dfb712313fa7689e936e572fde6ac99197806df
libc++ tests will not be run because: API tests require a locally built libc++.
msvcstl tests will not be run because: Don't know how to build with MSVC's STL on linux
objc tests will be skipped because of unsupported platform
Skipping the following test categories: ['libc++', 'msvcstl', 'dsym', 'pdb', 'gmodules', 'debugserver', 'objc']
adding filter spec TargetAPITestCase.test_get_arch_name_dwarf to module <module 'TestTargetAPI' from '/home/ubuntu/code/llvm-project/lldb/test/API/python_api/target/TestTargetAPI.py'>
adding filter spec TargetAPITestCase.test_get_arch_name_dwo to module <module 'TestTargetAPI' from '/home/ubuntu/code/llvm-project/lldb/test/API/python_api/target/TestTargetAPI.py'>
adding filter spec TargetAPITestCase.test_get_arch_name_dsym to module <module 'TestTargetAPI' from '/home/ubuntu/code/llvm-project/lldb/test/API/python_api/target/TestTargetAPI.py'>
compiler=/home/ubuntu/code/llvm-project/build/bin/clang

Configuration: arch=aarch64 compiler=/home/ubuntu/code/llvm-project/build/bin/clang
----------------------------------------------------------------------
Collected 3 tests

Change dir to: /home/ubuntu/code/llvm-project/lldb/test/API/python_api/target
1: test_get_arch_name_dwarf (TestTargetAPI.TargetAPITestCase.test_get_arch_name_dwarf) ... runCmd: settings clear --all

output: 

runCmd: settings set symbols.enable-external-lookup false

output: 

runCmd: settings set target.inherit-tcc true

output: 

runCmd: settings set target.disable-aslr false

output: 

runCmd: settings set target.detach-on-error false

output: 

runCmd: settings set target.auto-apply-fixits false

output: 

runCmd: settings set plugin.process.gdb-remote.packet-timeout 60

output: 

runCmd: settings set symbols.clang-modules-cache-path "/home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/module-cache-lldb"

output: 

runCmd: settings set use-color false

output: 

runCmd: settings set show-statusline false

output: 

/usr/bin/gmake VPATH=/home/ubuntu/code/llvm-project/lldb/test/API/python_api/target -C /home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/python_api/target/TestTargetAPI.test_get_arch_name_dwarf -I /home/ubuntu/code/llvm-project/lldb/test/API/python_api/target -I /home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make -f /home/ubuntu/code/llvm-project/lldb/test/API/python_api/target/Makefile MAKE_DSYM=NO all ARCH=aarch64 CC=/home/ubuntu/code/llvm-project/build/bin/clang CC_TYPE=clang CXX=/home/ubuntu/code/llvm-project/build/bin/clang++ LLVM_AR=/home/ubuntu/code/llvm-project/build/./bin/llvm-ar AR=/home/ubuntu/code/llvm-project/build/./bin/llvm-ar OBJCOPY=/home/ubuntu/code/llvm-project/build/./bin/llvm-objcopy STRIP=/home/ubuntu/code/llvm-project/build/./bin/llvm-strip ARCHIVER=/home/ubuntu/code/llvm-project/build/./bin/llvm-ar DWP=/home/ubuntu/code/llvm-project/build/./bin/llvm-dwp CLANG_MODULE_CACHE_DIR=/home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/module-cache-clang LLDB_OBJ_ROOT=/home/ubuntu/code/llvm-project/build/tools/lldb EXE=b.out arch=aarch64 OS=Linux HOST_OS=Linux

gmake: Entering directory '/home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/python_api/target/TestTargetAPI.test_get_arch_name_dwarf'
/home/ubuntu/code/llvm-project/build/bin/clang -g -O0   -I/home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/home/ubuntu/code/llvm-project/build/tools/lldb/include -I/home/ubuntu/code/llvm-project/lldb/test/API/python_api/target -I/home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info  -D_DEFAULT_SOURCE  -MT main.o -MD -MP -MF main.d -c -o main.o /home/ubuntu/code/llvm-project/lldb/test/API/python_api/target/main.c
/home/ubuntu/code/llvm-project/build/bin/clang main.o -g -O0   -I/home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/home/ubuntu/code/llvm-project/build/tools/lldb/include -I/home/ubuntu/code/llvm-project/lldb/test/API/python_api/target -I/home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info  -D_DEFAULT_SOURCE     --driver-mode=g++ -o "b.out"
gmake: Leaving directory '/home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/python_api/target/TestTargetAPI.test_get_arch_name_dwarf'


>>>>
target.arch_name = x86_64
<<<<
ok
PASS: LLDB (/home/ubuntu/code/llvm-project/build/bin/clang-aarch64) :: test_get_arch_name_dwarf (TestTargetAPI.TargetAPITestCase.test_get_arch_name_dwarf)
2: test_get_arch_name_dwo (TestTargetAPI.TargetAPITestCase.test_get_arch_name_dwo) ... runCmd: settings clear --all

output: 

runCmd: settings set symbols.enable-external-lookup false

output: 

runCmd: settings set target.inherit-tcc true

output: 

runCmd: settings set target.disable-aslr false

output: 

runCmd: settings set target.detach-on-error false

output: 

runCmd: settings set target.auto-apply-fixits false

output: 

runCmd: settings set plugin.process.gdb-remote.packet-timeout 60

output: 

runCmd: settings set symbols.clang-modules-cache-path "/home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/module-cache-lldb"

output: 

runCmd: settings set use-color false

output: 

runCmd: settings set show-statusline false

output: 

/usr/bin/gmake VPATH=/home/ubuntu/code/llvm-project/lldb/test/API/python_api/target -C /home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/python_api/target/TestTargetAPI.test_get_arch_name_dwo -I /home/ubuntu/code/llvm-project/lldb/test/API/python_api/target -I /home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make -f /home/ubuntu/code/llvm-project/lldb/test/API/python_api/target/Makefile MAKE_DSYM=NO MAKE_DWO=YES all ARCH=aarch64 CC=/home/ubuntu/code/llvm-project/build/bin/clang CC_TYPE=clang CXX=/home/ubuntu/code/llvm-project/build/bin/clang++ LLVM_AR=/home/ubuntu/code/llvm-project/build/./bin/llvm-ar AR=/home/ubuntu/code/llvm-project/build/./bin/llvm-ar OBJCOPY=/home/ubuntu/code/llvm-project/build/./bin/llvm-objcopy STRIP=/home/ubuntu/code/llvm-project/build/./bin/llvm-strip ARCHIVER=/home/ubuntu/code/llvm-project/build/./bin/llvm-ar DWP=/home/ubuntu/code/llvm-project/build/./bin/llvm-dwp CLANG_MODULE_CACHE_DIR=/home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/module-cache-clang LLDB_OBJ_ROOT=/home/ubuntu/code/llvm-project/build/tools/lldb EXE=b.out arch=aarch64 OS=Linux HOST_OS=Linux

gmake: Entering directory '/home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/python_api/target/TestTargetAPI.test_get_arch_name_dwo'
/home/ubuntu/code/llvm-project/build/bin/clang -g -O0   -I/home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/home/ubuntu/code/llvm-project/build/tools/lldb/include -I/home/ubuntu/code/llvm-project/lldb/test/API/python_api/target -I/home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info  -gsplit-dwarf -D_DEFAULT_SOURCE  -MT main.o -MD -MP -MF main.d -c -o main.o /home/ubuntu/code/llvm-project/lldb/test/API/python_api/target/main.c
/home/ubuntu/code/llvm-project/build/bin/clang main.o -g -O0   -I/home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/home/ubuntu/code/llvm-project/build/tools/lldb/include -I/home/ubuntu/code/llvm-project/lldb/test/API/python_api/target -I/home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /home/ubuntu/code/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info  -gsplit-dwarf -D_DEFAULT_SOURCE     --driver-mode=g++ -o "b.out"
gmake: Leaving directory '/home/ubuntu/code/llvm-project/build/lldb-test-build.noindex/python_api/target/TestTargetAPI.test_get_arch_name_dwo'


>>>>
target.arch_name = x86_64
<<<<
ok
PASS: LLDB (/home/ubuntu/code/llvm-project/build/bin/clang-aarch64) :: test_get_arch_name_dwo (TestTargetAPI.TargetAPITestCase.test_get_arch_name_dwo)
3: test_get_arch_name_dsym (TestTargetAPI.TargetAPITestCase.test_get_arch_name_dsym) ... skipped 'test case does not fall in any category of interest for this run'
UNSUPPORTED: LLDB (/home/ubuntu/code/llvm-project/build/bin/clang-aarch64) :: test_get_arch_name_dsym (TestTargetAPI.TargetAPITestCase.test_get_arch_name_dsym) (test case does not fall in any category of interest for this run) 
Restore dir to: /home/ubuntu/code/llvm-project

----------------------------------------------------------------------
Ran 3 tests in 0.659s

OK (skipped=1)
Session logs for test failures/errors/unexpected successes can be found in the test build directory


# Test consistency with triple.
triple = target.triple
if triple:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a scenario where there wouldn't be a triple? Should we assert that there is one instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated ✅ thank you 🙇‍♀️

self.assertEqual(triple.split("-")[0], arch_name)

def test_get_ABIName(self):
d = {"EXE": "b.out"}
self.build(dictionary=d)
Expand Down