0

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
This commit is contained in:
mark@chromium.org
2008-10-08 15:27:40 +00:00
parent fda28420d4
commit e6f45624a5

@ -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");
}