Skip to content

Commit 3986cff

Browse files
authored
[lldb] Add OpenBSD signals (#123005)
Signals 1-32 are matching the default UNIX platform. There are platform specific ones above 32.
1 parent 8ac35bd commit 3986cff

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

lldb/source/Plugins/Process/Utility/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_lldb_library(lldbPluginProcessUtility
1515
NativeRegisterContextDBReg_x86.cpp
1616
NativeRegisterContextRegisterInfo.cpp
1717
NetBSDSignals.cpp
18+
OpenBSDSignals.cpp
1819
RegisterContext_x86.cpp
1920
RegisterContextDarwin_arm.cpp
2021
RegisterContextDarwin_arm64.cpp
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//===-- OpenBSDSignals.cpp ------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "OpenBSDSignals.h"
10+
11+
#ifdef __OpenBSD__
12+
#include <csignal>
13+
14+
#define ADD_SIGCODE(signal_name, signal_value, code_name, code_value, ...) \
15+
static_assert(signal_name == signal_value, \
16+
"Value mismatch for signal number " #signal_name); \
17+
static_assert(code_name == code_value, \
18+
"Value mismatch for signal code " #code_name); \
19+
AddSignalCode(signal_value, code_value, __VA_ARGS__)
20+
#else
21+
#define ADD_SIGCODE(signal_name, signal_value, code_name, code_value, ...) \
22+
AddSignalCode(signal_value, code_value, __VA_ARGS__)
23+
#endif /* ifdef __OpenBSD */
24+
25+
using namespace lldb_private;
26+
27+
OpenBSDSignals::OpenBSDSignals() : UnixSignals() { Reset(); }
28+
29+
void OpenBSDSignals::Reset() {
30+
UnixSignals::Reset();
31+
32+
// clang-format off
33+
// SIGILL
34+
ADD_SIGCODE(SIGILL, 4, ILL_ILLOPC, 1, "illegal opcode");
35+
ADD_SIGCODE(SIGILL, 4, ILL_ILLOPN, 2, "illegal operand");
36+
ADD_SIGCODE(SIGILL, 4, ILL_ILLADR, 3, "illegal addressing mode");
37+
ADD_SIGCODE(SIGILL, 4, ILL_ILLTRP, 4, "illegal trap");
38+
ADD_SIGCODE(SIGILL, 4, ILL_PRVOPC, 5, "privileged opcode");
39+
ADD_SIGCODE(SIGILL, 4, ILL_PRVREG, 6, "privileged register");
40+
ADD_SIGCODE(SIGILL, 4, ILL_COPROC, 7, "coprocessor error");
41+
ADD_SIGCODE(SIGILL, 4, ILL_BADSTK, 8, "internal stack error");
42+
ADD_SIGCODE(SIGILL, 4, ILL_BTCFI, 9, "IBT missing on indirect call");
43+
44+
// SIGFPE
45+
ADD_SIGCODE(SIGFPE, 8, FPE_INTDIV, 1, "integer divide by zero");
46+
ADD_SIGCODE(SIGFPE, 8, FPE_INTOVF, 2, "integer overflow");
47+
ADD_SIGCODE(SIGFPE, 8, FPE_FLTDIV, 3, "floating point divide by zero");
48+
ADD_SIGCODE(SIGFPE, 8, FPE_FLTOVF, 4, "floating point overflow");
49+
ADD_SIGCODE(SIGFPE, 8, FPE_FLTUND, 5, "floating point underflow");
50+
ADD_SIGCODE(SIGFPE, 8, FPE_FLTRES, 6, "floating point inexact result");
51+
ADD_SIGCODE(SIGFPE, 8, FPE_FLTINV, 7, "invalid floating point operation");
52+
ADD_SIGCODE(SIGFPE, 8, FPE_FLTSUB, 8, "subscript out of range");
53+
54+
// SIGBUS
55+
ADD_SIGCODE(SIGBUS, 10, BUS_ADRALN, 1, "invalid address alignment");
56+
ADD_SIGCODE(SIGBUS, 10, BUS_ADRERR, 2, "non-existent physical address");
57+
ADD_SIGCODE(SIGBUS, 10, BUS_OBJERR, 3, "object specific hardware error");
58+
59+
// SIGSEGV
60+
ADD_SIGCODE(SIGSEGV, 11, SEGV_MAPERR, 1, "address not mapped to object",
61+
SignalCodePrintOption::Address);
62+
ADD_SIGCODE(SIGSEGV, 11, SEGV_ACCERR, 2, "invalid permissions for mapped object",
63+
SignalCodePrintOption::Address);
64+
65+
// SIGNO NAME SUPPRESS STOP NOTIFY DESCRIPTION
66+
// ===== ============== ======== ====== ====== ========================
67+
AddSignal(32, "SIGTHR", false, false, false, "thread library AST");
68+
// clang-format on
69+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===-- OpenBSDSignals.h ----------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_OPENBSDSIGNALS_H
10+
#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_OPENBSDSIGNALS_H
11+
12+
#include "lldb/Target/UnixSignals.h"
13+
14+
namespace lldb_private {
15+
16+
/// OpenBSD specific set of Unix signals.
17+
class OpenBSDSignals : public UnixSignals {
18+
public:
19+
OpenBSDSignals();
20+
21+
private:
22+
void Reset() override;
23+
};
24+
25+
} // namespace lldb_private
26+
27+
#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_OPENBSDSIGNALS_H

lldb/source/Target/UnixSignals.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Plugins/Process/Utility/FreeBSDSignals.h"
1111
#include "Plugins/Process/Utility/LinuxSignals.h"
1212
#include "Plugins/Process/Utility/NetBSDSignals.h"
13+
#include "Plugins/Process/Utility/OpenBSDSignals.h"
1314
#include "lldb/Host/HostInfo.h"
1415
#include "lldb/Utility/ArchSpec.h"
1516
#include <optional>
@@ -32,10 +33,11 @@ lldb::UnixSignalsSP UnixSignals::Create(const ArchSpec &arch) {
3233
case llvm::Triple::Linux:
3334
return std::make_shared<LinuxSignals>();
3435
case llvm::Triple::FreeBSD:
35-
case llvm::Triple::OpenBSD:
3636
return std::make_shared<FreeBSDSignals>();
3737
case llvm::Triple::NetBSD:
3838
return std::make_shared<NetBSDSignals>();
39+
case llvm::Triple::OpenBSD:
40+
return std::make_shared<OpenBSDSignals>();
3941
default:
4042
return std::make_shared<UnixSignals>();
4143
}

0 commit comments

Comments
 (0)