You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes, it is desirable to perform extra actions in a process only when a debugger is already attached, e.g. log more information, trigger a debugger break, or implement #4263. Although the extra actions can be conditionally guarded using some compile-time flag, more convenient would be detecting the debugger's presence at execution time; this reduces recompilations, and allows the process to react to live debugger attachments and detachments.
On Windows, the implementation is very simple, and supports Visual Studio / LLDB / GDB:
libLibC
fun IsDebuggerPresent : BOOLenddefdebugger_present? : BoolLibC.IsDebuggerPresent!=0end
On Linux, the conventional way seems to be reading from /proc/self/status. It is slower, but more expressive as it can obtain the debugger's process ID and handle other processes:
defdebugger_present? : BoolFile.each_line("/proc/self/status") do |line|
if tracer_pid = line.lchop?("TracerPid:").try(&.to_i?)
returntrueif tracer_pid !=0endendfalseend
Sometimes, it is desirable to perform extra actions in a process only when a debugger is already attached, e.g. log more information, trigger a debugger break, or implement #4263. Although the extra actions can be conditionally guarded using some compile-time flag, more convenient would be detecting the debugger's presence at execution time; this reduces recompilations, and allows the process to react to live debugger attachments and detachments.
On Windows, the implementation is very simple, and supports Visual Studio / LLDB / GDB:
On Linux, the conventional way seems to be reading from
/proc/self/status
. It is slower, but more expressive as it can obtain the debugger's process ID and handle other processes:However, some BSDs, including macOS, do not have procfs. It seems
sysctl
would do the job.On Solaris
/proc/*/status
is a binary blob.The text was updated successfully, but these errors were encountered: