[Lldb-commits] [lldb] r143176 - in /lldb/trunk: source/Host/macosx/Host.mm tools/darwin-debug/darwin-debug.cpp tools/debugserver/source/MacOSX/MachProcess.cpp
Greg Clayton
gclayton at apple.com
Thu Oct 27 18:24:12 PDT 2011
Author: gclayton
Date: Thu Oct 27 20:24:12 2011
New Revision: 143176
URL: http://llvm.org/viewvc/llvm-project?rev=143176&view=rev
Log:
Python does some bad things to the signal masks in the current process and
then we spawn child processes (debugserver, etc) and those bad settings get
inherited. We stop this from happening by correctly mucking with the posix
spawn attributes.
Modified:
lldb/trunk/source/Host/macosx/Host.mm
lldb/trunk/tools/darwin-debug/darwin-debug.cpp
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
Modified: lldb/trunk/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=143176&r1=143175&r2=143176&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/Host.mm Thu Oct 27 20:24:12 2011
@@ -1210,7 +1210,14 @@
// we return in the middle of this function.
lldb_utility::CleanUp <posix_spawnattr_t *, int> posix_spawnattr_cleanup(&attr, posix_spawnattr_destroy);
- short flags = 0;
+ sigset_t no_signals;
+ sigset_t all_signals;
+ sigemptyset (&no_signals);
+ sigfillset (&all_signals);
+ ::posix_spawnattr_setsigmask(&attr, &no_signals);
+ ::posix_spawnattr_setsigdefault(&attr, &all_signals);
+
+ short flags = POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK;
if (launch_info.GetFlags().Test (eLaunchFlagExec))
flags |= POSIX_SPAWN_SETEXEC; // Darwin specific posix_spawn flag
Modified: lldb/trunk/tools/darwin-debug/darwin-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/darwin-debug/darwin-debug.cpp?rev=143176&r1=143175&r2=143176&view=diff
==============================================================================
--- lldb/trunk/tools/darwin-debug/darwin-debug.cpp (original)
+++ lldb/trunk/tools/darwin-debug/darwin-debug.cpp Thu Oct 27 20:24:12 2011
@@ -26,6 +26,7 @@
#include <getopt.h>
#include <mach/machine.h>
+#include <signal.h>
#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
@@ -117,12 +118,19 @@
// since we want this program to turn into the program we want to debug,
// and also have the new program start suspended (right at __dyld_start)
// so we can debug it
- short flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETEXEC;
+ short flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETEXEC | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK;
// Disable ASLR if we were asked to
if (disable_aslr)
flags |= _POSIX_SPAWN_DISABLE_ASLR;
+ sigset_t no_signals;
+ sigset_t all_signals;
+ sigemptyset (&no_signals);
+ sigfillset (&all_signals);
+ ::posix_spawnattr_setsigmask(&attr, &no_signals);
+ ::posix_spawnattr_setsigdefault(&attr, &all_signals);
+
// Set the flags we just made into our posix spawn attributes
exit_with_errno (::posix_spawnattr_setflags (&attr, flags), "::posix_spawnattr_setflags (&attr, flags) error: ");
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=143176&r1=143175&r2=143176&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Thu Oct 27 20:24:12 2011
@@ -13,6 +13,7 @@
#include "DNB.h"
#include <mach/mach.h>
+#include <signal.h>
#include <spawn.h>
#include <sys/fcntl.h>
#include <sys/types.h>
@@ -1653,10 +1654,17 @@
if (err.Fail())
return INVALID_NUB_PROCESS;
- flags = POSIX_SPAWN_START_SUSPENDED;
+ flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK;
if (disable_aslr)
flags |= _POSIX_SPAWN_DISABLE_ASLR;
-
+
+ sigset_t no_signals;
+ sigset_t all_signals;
+ sigemptyset (&no_signals);
+ sigfillset (&all_signals);
+ ::posix_spawnattr_setsigmask(&attr, &no_signals);
+ ::posix_spawnattr_setsigdefault(&attr, &all_signals);
+
err.SetError( ::posix_spawnattr_setflags (&attr, flags), DNBError::POSIX);
if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS))
err.LogThreaded("::posix_spawnattr_setflags ( &attr, POSIX_SPAWN_START_SUSPENDED%s )", flags & _POSIX_SPAWN_DISABLE_ASLR ? " | _POSIX_SPAWN_DISABLE_ASLR" : "");
More information about the lldb-commits
mailing list