Skip to content

[LLDB] Add SI_USER and SI_KERNEL to Linux signals #144800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2025

Conversation

Jlalond
Copy link
Contributor

@Jlalond Jlalond commented Jun 18, 2025

@dmpots and I were investigating a crash when he was developing LLDB earlier. When I loaded the core I was surprised to see LLDB didn't have information for the SI_CODE. Upon inspection we had an si_code of 128, which is the decimal of SI_KERNEL at 0x80.

These were overlooked in my last addition of the negative si_codes, and this patch adds SI_USER and SI_KERNEL to the list, covering us for all the codes available to all signals.

Linux reference link

image

I kept the code naming the same as what is defined in the Linux source code. SI_KERNEL to my understanding usually indicates something went awry in the Kernel itself, but I think adding that additional detail would not be helpful to most users. @DavidSpickett I'd appreciate your insight into that.

@Jlalond Jlalond requested a review from dmpots June 18, 2025 21:40
@Jlalond Jlalond requested a review from JDevlieghere as a code owner June 18, 2025 21:41
@Jlalond Jlalond added the lldb label Jun 18, 2025
@Jlalond Jlalond requested a review from DavidSpickett June 18, 2025 21:41
@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2025

@llvm/pr-subscribers-lldb

Author: Jacob Lalonde (Jlalond)

Changes

@dmpots and I were investigating a crash when he was developing LLDB earlier. When I loaded the core I was surprised to see LLDB didn't have information for the SI_CODE. Upon inspection we had an si_code of 128, which is the decimal of SI_KERNEL at 0x80.

These were overlooked in my last addition of the negative si_codes, and this patch adds SI_USER and SI_KERNEL to the list, covering us for all the codes available to all signals.

Linux reference link

image

I kept the code naming the same as what is defined in the Linux source code. SI_KERNEL to my understanding usually indicates something went awry in the Kernel itself, but I think adding that additional detail would not be helpful to most users. @DavidSpickett I'd appreciate your insight into that.


Full diff: https://github.com/llvm/llvm-project/pull/144800.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/Process/Utility/LinuxSignals.cpp (+4)
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index 15a77ce227ec5..ef3d2f2f845da 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -65,6 +65,10 @@
 // See siginfo.h in the Linux Kernel, these codes can be sent for any signal.
 #define ADD_LINUX_SIGNAL(signo, name, ...)                                     \
   AddSignal(signo, name, __VA_ARGS__);                                         \
+  ADD_SIGCODE(signo, signo, SI_USER, 0, "sent by kill, sigsend or raise",      \
+              SignalCodePrintOption::Sender);                                  \
+  ADD_SIGCODE(signo, signo, SI_KERNEL, 0x80, "Sent by kernel",                 \
+              SignalCodePrintOption::Sender);                                  \
   ADD_SIGCODE(signo, signo, SI_QUEUE, -1, "sent by sigqueue",                  \
               SignalCodePrintOption::Sender);                                  \
   ADD_SIGCODE(signo, signo, SI_TIMER, -2, "sent by timer expiration",          \

@Jlalond Jlalond force-pushed the linux-signals-si-kernel branch from 0b55d63 to 157b5a5 Compare June 18, 2025 21:41
Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

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

SI_KERNEL to my understanding usually indicates something went awry in the Kernel itself

If by that you mean "a kernel bug" then the answer is no. It's really a catch-all code for signals originating from inside the kernel. Looking at the sources, it looks like this may be sent in case there's a problem with the page tables (which would be a kernel bug or a hardware issue), but it's also used for things like "insufficient space to set up a signal handler frame" (which is definitely an application issue) and "IO on fd is possible (and application did not request a specific signal to be sent)" (which isn't an issue at all).

@DavidSpickett
Copy link
Collaborator

Depending on the user's knowledge of / interpretation of how signals work, I don't think "sent by kernel" is enough for them to find their specific problem.

Asking my nearest totally accurate AI model:

Yes, when an application receives a SIGILL (illegal instruction) signal, it is sent by the kernel.

And you can argue this is just the implementation of signals, not the way applications are supposed to think about it, but I think it's one a lot of people would subscribe to.

What you're saying here is that the cause of the generation of the signal (by whomever generates it), was located in a certain place. So the place that tried to execute the illegal instruction, not the place that wrapped up that exception data into a signal.

It's crude but maybe just include SI_KERNEL in there? "sent by kernel (SI_KERNEL)". Then we don't have to explain the meaning of SI_KERNEL but I the user do have something I can look up and read about it. And if they do have a kernel side problem, doing some reading is what they'll need to do anyway.

@Jlalond
Copy link
Contributor Author

Jlalond commented Jun 24, 2025

It's crude but maybe just include SI_KERNEL in there? "sent by kernel (SI_KERNEL)". Then we don't have to explain the meaning of SI_KERNEL but I the user do have something I can look up and read about it. And if they do have a kernel side problem, doing some reading is what they'll need to do anyway.

As @labath mentioned there are a lot of things that could cause this. So I think the crude approach is the right one! I've updated the patch.

Copy link

github-actions bot commented Jun 24, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@Jlalond Jlalond force-pushed the linux-signals-si-kernel branch from 8bf0011 to a3ce967 Compare June 24, 2025 16:43
@Jlalond Jlalond force-pushed the linux-signals-si-kernel branch from a3ce967 to 67b397b Compare June 24, 2025 16:43
@Jlalond Jlalond merged commit 353f754 into llvm:main Jun 24, 2025
5 of 7 checks passed
DrSergei pushed a commit to DrSergei/llvm-project that referenced this pull request Jun 24, 2025
@dmpots and I were investigating a crash when he was developing LLDB
earlier. When I loaded the core I was surprised to see LLDB didn't have
information for the SI_CODE. Upon inspection we had an si_code of `128`,
which is the decimal of SI_KERNEL at `0x80`.

These were overlooked in my last addition of the negative si_codes, and
this patch adds SI_USER and SI_KERNEL to the list, covering us for all
the codes available to all signals.

[Linux reference
link](https://github.com/torvalds/linux/blob/74b4cc9b8780bfe8a3992c9ac0033bf22ac01f19/include/uapi/asm-generic/siginfo.h#L175)


![image](https://github.com/user-attachments/assets/52fa58e6-13d4-48a1-8d82-184c07a47db8)

I kept the code naming the same as what is defined in the Linux source
code. SI_KERNEL to my understanding usually indicates something went
awry in the Kernel itself, but I think adding that additional detail
would not be helpful to most users. @DavidSpickett I'd appreciate your
insight into that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants