summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-05 18:25:20 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-05 18:25:20 +0000
commitdbd9bfc0b4df5132997d1c4216ba4bbd860fed85 (patch)
treee4e6ec0a6e0468447d6b0337bd981c55c376099e
parentf505c31ba55975411a009f74a59b001a5a46bb56 (diff)
downloadchromium_src-dbd9bfc0b4df5132997d1c4216ba4bbd860fed85.zip
chromium_src-dbd9bfc0b4df5132997d1c4216ba4bbd860fed85.tar.gz
chromium_src-dbd9bfc0b4df5132997d1c4216ba4bbd860fed85.tar.bz2
Some fixes to ease debugging of the renderer process on OS X.
Review URL: http://codereview.chromium.org/21084 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9225 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/debug_util.h4
-rw-r--r--base/debug_util_posix.cc20
-rw-r--r--chrome/renderer/renderer_main.cc10
-rw-r--r--chrome/renderer/renderer_main_platform_delegate_mac.cc7
-rw-r--r--chrome/renderer/renderer_main_unittest.cc7
5 files changed, 40 insertions, 8 deletions
diff --git a/base/debug_util.h b/base/debug_util.h
index b7b5180..b61cb1e 100644
--- a/base/debug_util.h
+++ b/base/debug_util.h
@@ -43,6 +43,10 @@ class DebugUtil {
static bool WaitForDebugger(int wait_seconds, bool silent);
// Are we running under a debugger?
+ // On OS X, the underlying mechanism doesn't work when the sandbox is enabled.
+ // To get around this, this function caches it's value.
+ // WARNING: Because of this, on OS X, a call MUST be made to this function
+ // BEFORE the sandbox is enabled.
static bool BeingDebugged();
// Break into the debugger, assumes a debugger is present.
diff --git a/base/debug_util_posix.cc b/base/debug_util_posix.cc
index 3a25017..60e2ff5 100644
--- a/base/debug_util_posix.cc
+++ b/base/debug_util_posix.cc
@@ -29,6 +29,15 @@ bool DebugUtil::SpawnDebuggerOnProcess(unsigned /* process_id */) {
// http://developer.apple.com/qa/qa2004/qa1361.html
// static
bool DebugUtil::BeingDebugged() {
+ // If the process is sandboxed then we can't use the sysctl, so cache the
+ // value.
+ static bool is_set = false;
+ static bool being_debugged = false;
+
+ if (is_set) {
+ return being_debugged;
+ }
+
// Initialize mib, which tells sysctl what info we want. In this case,
// we're looking for information about a specific process ID.
int mib[] = {
@@ -45,11 +54,16 @@ bool DebugUtil::BeingDebugged() {
int sysctl_result = sysctl(mib, arraysize(mib), &info, &info_size, NULL, 0);
DCHECK(sysctl_result == 0);
- if (sysctl_result != 0)
- return false;
+ if (sysctl_result != 0) {
+ is_set = true;
+ being_debugged = false;
+ return being_debugged;
+ }
// This process is being debugged if the P_TRACED flag is set.
- return (info.kp_proc.p_flag & P_TRACED) != 0;
+ is_set = true;
+ being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0;
+ return being_debugged;
}
#elif defined(OS_LINUX)
diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc
index 1ae28a3..b6d4dfe 100644
--- a/chrome/renderer/renderer_main.cc
+++ b/chrome/renderer/renderer_main.cc
@@ -44,8 +44,14 @@ static void HandleRendererErrorTestParameters(const CommandLine& command_line) {
title += L" renderer"; // makes attaching to process easier
MessageBox(NULL, L"renderer starting...", title.c_str(),
MB_OK | MB_SETFOREGROUND);
-#else
- NOTIMPLEMENTED();
+#else if defined(OS_MACOSX)
+ // TODO(playmobil): In the long term, overriding this flag doesn't seem
+ // right, either use our own flag or open a dialog we can use.
+ // This is just to ease debugging in the interim.
+ LOG(WARNING) << "Renderer ("
+ << getpid()
+ << ") paused waiting for debugger to attach @ pid" ;
+ pause();
#endif // !OS_WIN
}
}
diff --git a/chrome/renderer/renderer_main_platform_delegate_mac.cc b/chrome/renderer/renderer_main_platform_delegate_mac.cc
index d7d5caa..cb5e750 100644
--- a/chrome/renderer/renderer_main_platform_delegate_mac.cc
+++ b/chrome/renderer/renderer_main_platform_delegate_mac.cc
@@ -4,6 +4,8 @@
#include "chrome/renderer/renderer_main_platform_delegate.h"
+#include "base/debug_util.h"
+
extern "C" {
#include <sandbox.h>
}
@@ -27,6 +29,11 @@ bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
}
bool RendererMainPlatformDelegate::EnableSandbox() {
+ // This call doesn't work when the sandbox is enabled, the implementation
+ // caches it's return value so we call it here and then future calls will
+ // succeed.
+ DebugUtil::BeingDebugged();
+
char* error_buff = NULL;
int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED,
&error_buff);
diff --git a/chrome/renderer/renderer_main_unittest.cc b/chrome/renderer/renderer_main_unittest.cc
index f003015..bfa3df0 100644
--- a/chrome/renderer/renderer_main_unittest.cc
+++ b/chrome/renderer/renderer_main_unittest.cc
@@ -78,10 +78,11 @@ class SuicidalListener : public IPC::Channel::Listener {
MULTIPROCESS_TEST_MAIN(SimpleRenderer) {
SandboxInitWrapper dummy_sandbox_init;
- CommandLine command_line(L"");
- command_line.AppendSwitchWithValue(switches::kProcessChannelID,
+ CommandLine cl(*CommandLine::ForCurrentProcess());
+ cl.AppendSwitchWithValue(switches::kProcessChannelID,
kRendererTestChannelName);
- MainFunctionParams dummy_params(command_line,
+
+ MainFunctionParams dummy_params(cl,
dummy_sandbox_init);
return RendererMain(dummy_params);
}