Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1817)

Unified Diff: base/debug_util_posix.cc

Issue 6582: mac beingdebugged (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug_util_posix.cc
===================================================================
--- base/debug_util_posix.cc (revision 2969)
+++ base/debug_util_posix.cc (working copy)
@@ -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 @@
pid_index += tracer.size();
return pid_index < status.size() && status[pid_index] != '0';
}
-#endif
+#endif // OS_LINUX
+
// static
void DebugUtil::BreakDebugger() {
asm ("int3");
}
-
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698