Skip to content

Commit 74a012e

Browse files
authored
[lldb/aarch64] Fix PC register info augmentation (llvm#143499)
This fixes a regression caused by llvm#139817, where we would fail to unwind (using eh_frame) when using debug stubs (like qemu) which do not provide eh_frame register numbers. Unwinding fails because the unwinder tries to convert pc register number to the "eh_frame" scheme (and fails). Previously that worked because the code used a slightly different pattern which ended up comparing the number by converting it to the "generic" scheme (which we do provide). I don't think that's a bug in the unwinder -- we just need to make sure we provide the register number all the time. The associated test is not particularly useful, but I'm hoping it could be used to test other changes like this as well. Other register augmentation changes are tested in an end-to-end fashion (by injecting gdb-remote packets and then trying to read registers). That works well for testing the addition of subregisters, but it isn't particularly suitable for testing register numbers, as the only place (that I know of) where this manifests is during unwinding, and recreating an unwindable process in a test like this is fairly challenging. Probably the best way to ensure coverage for this scenario would be to have lldb-server stop sending eh_frame register numbers (align it with other gdb-like stubs).
1 parent 07a1d47 commit 74a012e

File tree

5 files changed

+84
-2
lines changed

5 files changed

+84
-2
lines changed

lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "ABIMacOSX_arm64.h"
1313
#include "ABISysV_arm64.h"
1414
#include "Utility/ARM64_DWARF_Registers.h"
15+
#include "Utility/ARM64_ehframe_Registers.h"
1516
#include "lldb/Core/PluginManager.h"
1617
#include "lldb/Target/Process.h"
1718

@@ -69,9 +70,9 @@ lldb::addr_t ABIAArch64::FixDataAddress(lldb::addr_t pc) {
6970
std::pair<uint32_t, uint32_t>
7071
ABIAArch64::GetEHAndDWARFNums(llvm::StringRef name) {
7172
if (name == "pc")
72-
return {LLDB_INVALID_REGNUM, arm64_dwarf::pc};
73+
return {arm64_ehframe::pc, arm64_dwarf::pc};
7374
if (name == "cpsr")
74-
return {LLDB_INVALID_REGNUM, arm64_dwarf::cpsr};
75+
return {arm64_ehframe::cpsr, arm64_dwarf::cpsr};
7576
return MCBasedABI::GetEHAndDWARFNums(name);
7677
}
7778

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//===-- ABIAArch64Test.cpp ------------------------------------------------===//
2+
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "Plugins/ABI/AArch64/ABIMacOSX_arm64.h"
11+
#include "Plugins/ABI/AArch64/ABISysV_arm64.h"
12+
#include "Utility/ARM64_DWARF_Registers.h"
13+
#include "Utility/ARM64_ehframe_Registers.h"
14+
#include "lldb/Target/DynamicRegisterInfo.h"
15+
#include "lldb/Utility/ArchSpec.h"
16+
#include "llvm/Support/ManagedStatic.h"
17+
#include "llvm/Support/TargetSelect.h"
18+
#include "gtest/gtest.h"
19+
#include <vector>
20+
21+
using namespace lldb_private;
22+
using namespace lldb;
23+
24+
class ABIAArch64TestFixture : public testing::TestWithParam<llvm::StringRef> {
25+
public:
26+
static void SetUpTestCase();
27+
static void TearDownTestCase();
28+
29+
// virtual void SetUp() override { }
30+
// virtual void TearDown() override { }
31+
32+
protected:
33+
};
34+
35+
void ABIAArch64TestFixture::SetUpTestCase() {
36+
LLVMInitializeAArch64TargetInfo();
37+
LLVMInitializeAArch64TargetMC();
38+
ABISysV_arm64::Initialize();
39+
ABIMacOSX_arm64::Initialize();
40+
}
41+
42+
void ABIAArch64TestFixture::TearDownTestCase() {
43+
ABISysV_arm64::Terminate();
44+
ABIMacOSX_arm64::Terminate();
45+
llvm::llvm_shutdown();
46+
}
47+
48+
TEST_P(ABIAArch64TestFixture, AugmentRegisterInfo) {
49+
ABISP abi_sp = ABI::FindPlugin(ProcessSP(), ArchSpec(GetParam()));
50+
ASSERT_TRUE(abi_sp);
51+
using Register = DynamicRegisterInfo::Register;
52+
53+
Register pc{ConstString("pc"), ConstString(), ConstString("GPR")};
54+
std::vector<Register> regs{pc};
55+
56+
abi_sp->AugmentRegisterInfo(regs);
57+
58+
ASSERT_EQ(regs.size(), 1);
59+
Register new_pc = regs[0];
60+
EXPECT_EQ(new_pc.name, pc.name);
61+
EXPECT_EQ(new_pc.set_name, pc.set_name);
62+
EXPECT_EQ(new_pc.regnum_ehframe, arm64_ehframe::pc);
63+
EXPECT_EQ(new_pc.regnum_dwarf, arm64_dwarf::pc);
64+
}
65+
66+
INSTANTIATE_TEST_SUITE_P(ABIAArch64Tests, ABIAArch64TestFixture,
67+
testing::Values("aarch64-pc-linux",
68+
"arm64-apple-macosx"));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
add_lldb_unittest(ABIAArch64Tests
2+
ABIAArch64Test.cpp
3+
LINK_COMPONENTS
4+
Support
5+
AArch64
6+
LINK_LIBS
7+
lldbTarget
8+
lldbPluginABIAArch64
9+
)

lldb/unittests/ABI/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if ("AArch64" IN_LIST LLVM_TARGETS_TO_BUILD)
2+
add_subdirectory(AArch64)
3+
endif()

lldb/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
5252
add_subdirectory(API)
5353
add_subdirectory(DAP)
5454
endif()
55+
add_subdirectory(ABI)
5556
add_subdirectory(Breakpoint)
5657
add_subdirectory(Callback)
5758
add_subdirectory(Core)

0 commit comments

Comments
 (0)