[Lldb-commits] [lldb] r263858 - Delete the custom implementation of signal() on Windows.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 18 16:47:49 PDT 2016


Author: zturner
Date: Fri Mar 18 18:47:48 2016
New Revision: 263858

URL: http://llvm.org/viewvc/llvm-project?rev=263858&view=rev
Log:
Delete the custom implementation of signal() on Windows.

The Windows SDK provides a version of signal() that is much more
limited compared to other platforms.  It only supports about 5-6
signal values.  LLDB uses signals for a number of things, most
notably to handle Ctrl+C so we can gracefully shut down.  The
portability solution to this on Windows has been to provide a
hand-rolled implementation of `signal` using the name `signal`
so that you could write code that simply calls signal directly
and it would work.

But this introduces a multiply defined symbol with the builtin
version and depending on how you included header files, you could
get yourself into a situation where you had linker errors.  To
make matters worse, it led to a ton of compiler warnings.  Worst
of all though is that this custom implementation of signal was,
in fact, identical for the purposes of handling Ctrl+C as the
builtin implementation of signal.  So it seems to have literally
not been serving any useful purpose.

This patch deletes all the custom signal() functions for Windows,
and includes the signal.h system header, so that any calls to
signal now go to the actual version provided by the Windows SDK.

Differential Revision: http://reviews.llvm.org/D18287

Removed:
    lldb/trunk/tools/lldb-mi/Platform.cpp
Modified:
    lldb/trunk/tools/driver/Driver.cpp
    lldb/trunk/tools/driver/Platform.cpp
    lldb/trunk/tools/driver/Platform.h
    lldb/trunk/tools/lldb-mi/CMakeLists.txt
    lldb/trunk/tools/lldb-mi/Platform.h

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=263858&r1=263857&r2=263858&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Fri Mar 18 18:47:48 2016
@@ -1310,11 +1310,13 @@ main (int argc, char const *argv[], cons
     
     SBHostOS::ThreadCreated ("<lldb.driver.main-thread>");
 
+    signal(SIGINT, sigint_handler);
+#ifndef _MSC_VER
     signal (SIGPIPE, SIG_IGN);
     signal (SIGWINCH, sigwinch_handler);
-    signal (SIGINT, sigint_handler);
     signal (SIGTSTP, sigtstp_handler);
     signal (SIGCONT, sigcont_handler);
+#endif
 
     // Create a scope for driver so that the driver object will destroy itself
     // before SBDebugger::Terminate() is called.

Modified: lldb/trunk/tools/driver/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Platform.cpp?rev=263858&r1=263857&r2=263858&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Platform.cpp (original)
+++ lldb/trunk/tools/driver/Platform.cpp Fri Mar 18 18:47:48 2016
@@ -16,21 +16,6 @@
 
 #include "Platform.h"
 
-// the control handler or SIGINT handler
-static sighandler_t _ctrlHandler = NULL;
-
-// the default console control handler
-BOOL
-WINAPI CtrlHandler (DWORD ctrlType)
-{
-    if ( _ctrlHandler != NULL )
-    {
-        _ctrlHandler( 0 );
-        return TRUE;
-    }
-    return FALSE;
-}
-
 int
 ioctl (int d, int request, ...)
 {
@@ -84,29 +69,4 @@ tcgetattr (int fildes, struct termios *t
     return -1;
 }
 
-#ifdef _MSC_VER
-sighandler_t
-signal (int sig, sighandler_t sigFunc)
-{
-    switch ( sig )
-    {
-    case ( SIGINT ):
-        {
-            _ctrlHandler = sigFunc;
-            SetConsoleCtrlHandler( CtrlHandler, TRUE );
-        }
-        break;
-    case ( SIGPIPE  ):
-    case ( SIGWINCH ):
-    case ( SIGTSTP  ):
-    case ( SIGCONT  ):
-        // ignore these for now
-        break;
-    default:
-        assert( !"Not implemented!" );
-    }
-    return 0;
-}
-#endif
-
 #endif

Modified: lldb/trunk/tools/driver/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Platform.h?rev=263858&r1=263857&r2=263858&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Platform.h (original)
+++ lldb/trunk/tools/driver/Platform.h Fri Mar 18 18:47:48 2016
@@ -12,12 +12,11 @@
 
 #if defined( _WIN32 )
 
-    // this will stop signal.h being included
-    #define _INC_SIGNAL
     #include "lldb/Host/HostGetOpt.h"
     #include <io.h>
 #if defined( _MSC_VER )
     #include <eh.h>
+    #include <signal.h>
 #endif
     #include <inttypes.h>
     #include "lldb/Host/windows/windows.h"
@@ -37,17 +36,6 @@
     // ioctls.h
     #define TIOCGWINSZ 0x5413
 
-
-    // signal handler function pointer type
-    typedef void(*sighandler_t)(int);
-
-    // signal.h
-    #define SIGINT 2
-    // default handler
-    #define SIG_DFL ( (sighandler_t) -1 )
-    // ignored
-    #define SIG_IGN ( (sighandler_t) -2 )
-
     // signal.h
     #define SIGPIPE  13
     #define SIGCONT  18
@@ -80,7 +68,6 @@
     };
     typedef long pid_t;
     #define snprintf _snprintf
-    extern sighandler_t signal( int sig, sighandler_t );
     #define PATH_MAX MAX_PATH
 #endif
 

Modified: lldb/trunk/tools/lldb-mi/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/CMakeLists.txt?rev=263858&r1=263857&r2=263858&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/CMakeLists.txt (original)
+++ lldb/trunk/tools/lldb-mi/CMakeLists.txt Fri Mar 18 18:47:48 2016
@@ -73,7 +73,6 @@ set(LLDB_MI_SOURCES
   MIUtilString.cpp
   MIUtilThreadBaseStd.cpp
   MIUtilVariant.cpp
-  Platform.cpp
   )
 
 if ( CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" )

Removed: lldb/trunk/tools/lldb-mi/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/Platform.cpp?rev=263857&view=auto
==============================================================================
--- lldb/trunk/tools/lldb-mi/Platform.cpp (original)
+++ lldb/trunk/tools/lldb-mi/Platform.cpp (removed)
@@ -1,49 +0,0 @@
-//===-- Platform.cpp --------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// this file is only relevant for Visual C++
-#if defined(_MSC_VER)
-
-#include <process.h>
-#include <assert.h>
-
-#include "Platform.h"
-
-// the control handler or SIGINT handler
-static sighandler_t _ctrlHandler = NULL;
-
-// the default console control handler
-BOOL WINAPI CtrlHandler(DWORD ctrlType)
-{
-    if (_ctrlHandler != NULL)
-    {
-        _ctrlHandler(SIGINT);
-        return TRUE;
-    }
-    return FALSE;
-}
-
-sighandler_t
-signal(int sig, sighandler_t sigFunc)
-{
-    switch (sig)
-    {
-        case (SIGINT):
-        {
-            _ctrlHandler = sigFunc;
-            SetConsoleCtrlHandler(CtrlHandler, TRUE);
-        }
-        break;
-        default:
-            assert(!"Not implemented!");
-    }
-    return 0;
-}
-
-#endif

Modified: lldb/trunk/tools/lldb-mi/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/Platform.h?rev=263858&r1=263857&r2=263858&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/Platform.h (original)
+++ lldb/trunk/tools/lldb-mi/Platform.h Fri Mar 18 18:47:48 2016
@@ -10,12 +10,10 @@
 
 #if defined(_MSC_VER)
 
-// this will stop signal.h being included
-#define _INC_SIGNAL
-
 #include <io.h>
 #include <eh.h>
 #include <inttypes.h>
+#include <signal.h>
 #include <lldb/Host/windows/Windows.h>
 #include <lldb/Host/HostGetOpt.h>
 
@@ -73,7 +71,6 @@ typedef void (*sighandler_t)(int);
 
 // CODETAG_IOR_SIGNALS
 // signal.h
-#define SIGINT 2                   // Terminal interrupt signal
 #define SIGQUIT 3                  // Terminal quit signal
 #define SIGKILL 9                  // Kill (cannot be caught or ignored)
 #define SIGPIPE 13                 // Write on a pipe with no one to read it
@@ -81,10 +78,6 @@ typedef void (*sighandler_t)(int);
 #define SIGTSTP 20                 // Terminal stop signal
 #define SIGSTOP 23                 // Stop executing (cannot be caught or ignored)
 #define SIGWINCH 28                // (== SIGVTALRM)
-#define SIG_DFL ((sighandler_t)-1) // Default handler
-#define SIG_IGN ((sighandler_t)-2) // Ignored
-
-extern sighandler_t signal(int sig, sighandler_t);
 
 #else
 




More information about the lldb-commits mailing list