diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-08 15:27:40 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-08 15:27:40 +0000 |
commit | e6f45624a5e05fcce4171080c56d5a671bd28e97 (patch) | |
tree | 8400f27d71658b81a2971bd9500587629d65002d | |
parent | fda28420d4964c01a7396be1c88695557c1d51b3 (diff) | |
download | chromium_src-e6f45624a5e05fcce4171080c56d5a671bd28e97.zip chromium_src-e6f45624a5e05fcce4171080c56d5a671bd28e97.tar.gz chromium_src-e6f45624a5e05fcce4171080c56d5a671bd28e97.tar.bz2 |
Add Mac BeingDebugged implementation
Review URL: http://codereview.chromium.org/6582
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3009 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/debug_util_posix.cc | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/base/debug_util_posix.cc b/base/debug_util_posix.cc index f4da37c..a83e144 100644 --- a/base/debug_util_posix.cc +++ b/base/debug_util_posix.cc @@ -4,32 +4,58 @@ #include "base/debug_util.h" -#include <unistd.h> +#include <fcntl.h> +#include <sys/stat.h> #include <sys/sysctl.h> #include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> +#include <unistd.h> +#include "base/basictypes.h" #include "base/logging.h" #include "base/string_piece.h" +// static bool DebugUtil::SpawnDebuggerOnProcess(unsigned /* process_id */) { NOTIMPLEMENTED(); return false; } #if defined(OS_MACOSX) + +// Based on Apple's recommended method as described in // http://developer.apple.com/qa/qa2004/qa1361.html +// static bool DebugUtil::BeingDebugged() { - NOTIMPLEMENTED(); - return false; + // Initialize mib, which tells sysctl what info we want. In this case, + // we're looking for information about a specific process ID. + int mib[] = { + CTL_KERN, + KERN_PROC, + KERN_PROC_PID, + getpid() + }; + + // Caution: struct kinfo_proc is marked __APPLE_API_UNSTABLE. The source and + // binary interfaces may change. + struct kinfo_proc info; + size_t info_size = sizeof(info); + + int sysctl_result = sysctl(mib, arraysize(mib), &info, &info_size, NULL, 0); + DCHECK(sysctl_result == 0); + if (sysctl_result != 0) + return false; + + // This process is being debugged if the P_TRACED flag is set. + return (info.kp_proc.p_flag & P_TRACED) != 0; } #elif defined(OS_LINUX) + // We can look in /proc/self/status for TracerPid. We are likely used in crash // handling, so we are careful not to use the heap or have side effects. // Another option that is common is to try to ptrace yourself, but then we // can't detach without forking(), and that's not so great. +// static bool DebugUtil::BeingDebugged() { int status_fd = open("/proc/self/status", O_RDONLY); if (status_fd == -1) @@ -57,10 +83,10 @@ bool DebugUtil::BeingDebugged() { pid_index += tracer.size(); return pid_index < status.size() && status[pid_index] != '0'; } -#endif + +#endif // OS_LINUX // static void DebugUtil::BreakDebugger() { asm ("int3"); } - |