diff options
author | David Spickett <david.spickett@linaro.org> | 2023-03-14 11:52:36 +0000 |
---|---|---|
committer | David Spickett <david.spickett@linaro.org> | 2023-03-20 11:39:32 +0000 |
commit | 0107513fe79da7670e37c29c0862794a2213a89c (patch) | |
tree | 93d9e1f589986bf68b3db48f27ab556a3c9c2de9 /lldb/unittests | |
parent | 2d4042f4b78ebd4303f558c01b67f8ecabfe47e6 (diff) | |
download | llvm-0107513fe79da7670e37c29c0862794a2213a89c.tar.gz |
[lldb] Implement CrashReason using UnixSignals
By adding signal codes to UnixSignals and adding a new function
where you can get a string with optional address and bounds.
Added signal codes to the Linux, FreeBSD and NetBSD signal sets.
I've checked the numbers against the relevant sources.
Each signal code has a code number, description and printing options.
By default you just get the descripton, you can opt into adding either
a fault address or bounds information.
Bounds signals we'll use the description, unless we have the bounds
values in which case we say whether it is an upper or lower bound
issue.
GetCrashReasonString remains in CrashReason because we need it to
be compiled only for platforms with siginfo_t. Ideally it would
move into NativeProcessProtocol, but that is also used
by NativeRegisterContextWindows, where there would be no siginfo_t.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D146044
Diffstat (limited to 'lldb/unittests')
-rw-r--r-- | lldb/unittests/Signals/UnixSignalsTest.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lldb/unittests/Signals/UnixSignalsTest.cpp b/lldb/unittests/Signals/UnixSignalsTest.cpp index e4c463486244..2ae1b4ee5138 100644 --- a/lldb/unittests/Signals/UnixSignalsTest.cpp +++ b/lldb/unittests/Signals/UnixSignalsTest.cpp @@ -23,6 +23,10 @@ public: AddSignal(4, "SIG4", true, false, true, "DESC4"); AddSignal(8, "SIG8", true, true, true, "DESC8"); AddSignal(16, "SIG16", true, false, false, "DESC16"); + AddSignalCode(16, 1, "a specific type of SIG16"); + AddSignalCode(16, 2, "SIG16 with a fault address", + SignalCodePrintOption::Address); + AddSignalCode(16, 3, "bounds violation", SignalCodePrintOption::Bounds); } }; @@ -93,6 +97,50 @@ TEST(UnixSignalsTest, GetInfo) { EXPECT_EQ(name, signals.GetSignalAsCString(signo)); } +TEST(UnixSignalsTest, GetAsCString) { + TestSignals signals; + + ASSERT_EQ(nullptr, signals.GetSignalAsCString(100)); + std::string name = signals.GetSignalAsCString(16); + ASSERT_EQ("SIG16", name); +} + +TEST(UnixSignalsTest, GetAsString) { + TestSignals signals; + + ASSERT_EQ("", signals.GetSignalDescription(100, std::nullopt)); + ASSERT_EQ("SIG16", signals.GetSignalDescription(16, std::nullopt)); + ASSERT_EQ("", signals.GetSignalDescription(100, 100)); + ASSERT_EQ("SIG16", signals.GetSignalDescription(16, 100)); + ASSERT_EQ("SIG16: a specific type of SIG16", + signals.GetSignalDescription(16, 1)); + + // Unknown code, won't use the address. + ASSERT_EQ("SIG16", signals.GetSignalDescription(16, 100, 0xCAFEF00D)); + // Known code, that shouldn't print fault address. + ASSERT_EQ("SIG16: a specific type of SIG16", + signals.GetSignalDescription(16, 1, 0xCAFEF00D)); + // Known code that should. + ASSERT_EQ("SIG16: SIG16 with a fault address (fault address: 0xcafef00d)", + signals.GetSignalDescription(16, 2, 0xCAFEF00D)); + // No address given just print the code description. + ASSERT_EQ("SIG16: SIG16 with a fault address", + signals.GetSignalDescription(16, 2)); + + const char *expected = "SIG16: bounds violation"; + // Must pass all needed info to get full output. + ASSERT_EQ(expected, signals.GetSignalDescription(16, 3)); + ASSERT_EQ(expected, signals.GetSignalDescription(16, 3, 0xcafef00d)); + ASSERT_EQ(expected, signals.GetSignalDescription(16, 3, 0xcafef00d, 0x1234)); + + ASSERT_EQ("SIG16: upper bound violation (fault address: 0x5679, lower bound: " + "0x1234, upper bound: 0x5678)", + signals.GetSignalDescription(16, 3, 0x5679, 0x1234, 0x5678)); + ASSERT_EQ("SIG16: lower bound violation (fault address: 0x1233, lower bound: " + "0x1234, upper bound: 0x5678)", + signals.GetSignalDescription(16, 3, 0x1233, 0x1234, 0x5678)); +} + TEST(UnixSignalsTest, VersionChange) { TestSignals signals; |