This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add compile time checks for signal codes when on the matching platform
ClosedPublic

Authored by DavidSpickett on Mar 16 2023, 5:46 AM.

Details

Summary

This adds a new macro to the UnixSignals subclasses, ADD_SIGCODE.

ADD_SIGCODE(4, ILL_ILLOPC, 1, "illegal opcode");

Adds a sigcode to signal 4. That code is ILL_ILLOPC and we expect
its value to be 1. When compiling on a system that matches the class
e.g. FreeBSD for FreeBSDSignals, the macro will check that that is true.

When you're not on FreeBSD we just use the number 1, and ILL_ILLOPC
won't be defined to anything because we don't include csignal.

Example error:
LinuxSignals.cpp:52:3: error: static_assert failed due to requirement
'ILL_COPROC == 9' "Value mismatch for signal code ILL_COPROC"

Diff Detail

Event Timeline

DavidSpickett created this revision.Mar 16 2023, 5:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2023, 5:46 AM
DavidSpickett requested review of this revision.Mar 16 2023, 5:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2023, 5:46 AM
emaste added inline comments.Mar 16 2023, 6:18 AM
lldb/source/Plugins/Process/Utility/FreeBSDSignals.cpp
14–16 ↗(On Diff #505782)

I'm curious what this is for; we don't use it below?

arichardson accepted this revision.Mar 16 2023, 5:52 PM

Much neater than my initial suggestion. LGTM

lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
14 ↗(On Diff #505782)

I guess these are needed to support older versions that don't have the defines yet?

This revision is now accepted and ready to land.Mar 16 2023, 5:52 PM
arichardson added inline comments.Mar 16 2023, 5:54 PM
lldb/source/Plugins/Process/Utility/NetBSDSignals.cpp
15 ↗(On Diff #505782)

Also unused like for FreeBSD?

Remove SEGV_BNDERR defines from FreeBSD and NetBSD. I cargo culted these from CrashReason
but on checking the latest sources, they are not in either.

It has been in Linux since kernel 3.19 which was February 2015. But it's doing no harm
there so why take the risk.

DavidSpickett marked 3 inline comments as done.Mar 17 2023, 3:14 AM
DavidSpickett added inline comments.
lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
14 ↗(On Diff #505782)

Yes, BNDERR is from 2015 so maybe it could go, but the memory tagging codes are certainly more recent.

DavidSpickett marked an inline comment as done.

Correct Linux macro definition when not on Linux.