diff options
-rw-r--r-- | base/debug_util.h | 4 | ||||
-rw-r--r-- | base/debug_util_posix.cc | 20 | ||||
-rw-r--r-- | chrome/renderer/renderer_main.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/renderer_main_platform_delegate_mac.cc | 7 | ||||
-rw-r--r-- | chrome/renderer/renderer_main_unittest.cc | 7 |
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); } |