lldb

How to detect presence of the lldb at runtime?


Please note: this question is not about statically determined conditional code compilation.

My question is: how do I determine at runtime that my process is being debugged by LLDB by analyzing the process state? Assembly, C, Rust solutions welcome.

I looked for the answers here on StackOverflow, but the search seems to be broken, it just suggested me unrelated stuff.


Solution

  • This generally won't depend on the debugger, since all debuggers end up using the same system routines, and it's really their use that you are trying to detect. Instead, it depends on what platform your binaries are running on. For instance, the answers involving sysctl and P_TRACED here:

    Detecting if iOS app is run in debugger

    are correct for all the Darwin platforms.

    There's probably an equivalent way to do this on Linux and Windows. You'll need to tell us what platform you are debugging, so someone who knows that platform can give you the appropriate answer.