[Lldb-commits] [PATCH] D106226: [lldb] Improve error message when "lldb attach" fails
Jordan Rupprecht via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 20 13:43:22 PDT 2021
rupprecht added a comment.
In D106226#2891107 <https://reviews.llvm.org/D106226#2891107>, @teemperor wrote:
> Congrats on getting started on your first patch! I improving this error message really seems like a good idea.
>
> From what I can see the error message here is identical to GDB's which is a different project with an incompatible license. No idea if this is large enough of a copy to bring us into the realm of copyright (not a lawyer), but I think formulating our own (maybe even better?) error message would anyway be a good idea. What about something along those lines:
>
> error: attach failed: <Whatever error we already would return here> (This line is just the normal LLDB attach error)
> Note that attaching might have failed due to the ptrace_scope security policy
> which restricts debuggers from attaching to other processes. See
> the ptrace_scope documentation for more information:
> https://www.kernel.org/doc/Documentation/security/Yama.txt
> The current ptrace_scope policy can be found here:
> /proc/sys/kernel/yama/ptrace_scope
It'd also be helpful to include the actual command to enable it, i.e. either `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope` or `sudo sysctl -w kernel.yama.ptrace_scope=0` (I think both commands are equivalent)
> (Not sure how I feel about linking to some internet URL, but I couldn't find any man page for Yama/ptrace_scope)
It's part of the `ptrace` man page: https://manpages.debian.org/buster/manpages-dev/ptrace.2.en.html#/proc/sys/kernel/yama/ptrace_scope (I think a URL is probably fine though... maybe we could put one on LLDB's page if we're worried about kernel.org not having a stable URL)
> Also I wonder how we could make sure we emit this diagnostic in cases where the ptrace_scope is actually the reason for the failed attach. The proper way to check this seems to be checking the `errno` after we call `ptrace` and then propagate the error all the way back to `lldb` from `lldb-server`. From the `lldb` side I don't think we have any way of knowing why the attach actually failed so we would emit this error speculatively which doesn't seem ideal. It still sounds like a better solution than having just this generic error message that doesn't help anyone, so I think David's suggestion + a FIXME is maybe a good compromise here.
Can we have LLDB read the value of `/proc/sys/kernel/yama/ptrace_scope`, and only print the error if the file exists and is not 0?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D106226/new/
https://reviews.llvm.org/D106226
More information about the lldb-commits
mailing list