Skip to content

Commit 29365da

Browse files
author
Zachary Turner
committedMar 18, 2016
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 llvm-svn: 263858
1 parent a3a019c commit 29365da

File tree

6 files changed

+5
-113
lines changed

6 files changed

+5
-113
lines changed
 

Diff for: ‎lldb/tools/driver/Driver.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1310,11 +1310,13 @@ main (int argc, char const *argv[], const char *envp[])
13101310

13111311
SBHostOS::ThreadCreated ("<lldb.driver.main-thread>");
13121312

1313+
signal(SIGINT, sigint_handler);
1314+
#ifndef _MSC_VER
13131315
signal (SIGPIPE, SIG_IGN);
13141316
signal (SIGWINCH, sigwinch_handler);
1315-
signal (SIGINT, sigint_handler);
13161317
signal (SIGTSTP, sigtstp_handler);
13171318
signal (SIGCONT, sigcont_handler);
1319+
#endif
13181320

13191321
// Create a scope for driver so that the driver object will destroy itself
13201322
// before SBDebugger::Terminate() is called.

Diff for: ‎lldb/tools/driver/Platform.cpp

-40
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@
1616

1717
#include "Platform.h"
1818

19-
// the control handler or SIGINT handler
20-
static sighandler_t _ctrlHandler = NULL;
21-
22-
// the default console control handler
23-
BOOL
24-
WINAPI CtrlHandler (DWORD ctrlType)
25-
{
26-
if ( _ctrlHandler != NULL )
27-
{
28-
_ctrlHandler( 0 );
29-
return TRUE;
30-
}
31-
return FALSE;
32-
}
33-
3419
int
3520
ioctl (int d, int request, ...)
3621
{
@@ -84,29 +69,4 @@ tcgetattr (int fildes, struct termios *termios_p)
8469
return -1;
8570
}
8671

87-
#ifdef _MSC_VER
88-
sighandler_t
89-
signal (int sig, sighandler_t sigFunc)
90-
{
91-
switch ( sig )
92-
{
93-
case ( SIGINT ):
94-
{
95-
_ctrlHandler = sigFunc;
96-
SetConsoleCtrlHandler( CtrlHandler, TRUE );
97-
}
98-
break;
99-
case ( SIGPIPE ):
100-
case ( SIGWINCH ):
101-
case ( SIGTSTP ):
102-
case ( SIGCONT ):
103-
// ignore these for now
104-
break;
105-
default:
106-
assert( !"Not implemented!" );
107-
}
108-
return 0;
109-
}
110-
#endif
111-
11272
#endif

Diff for: ‎lldb/tools/driver/Platform.h

+1-14
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212

1313
#if defined( _WIN32 )
1414

15-
// this will stop signal.h being included
16-
#define _INC_SIGNAL
1715
#include "lldb/Host/HostGetOpt.h"
1816
#include <io.h>
1917
#if defined( _MSC_VER )
2018
#include <eh.h>
19+
#include <signal.h>
2120
#endif
2221
#include <inttypes.h>
2322
#include "lldb/Host/windows/windows.h"
@@ -37,17 +36,6 @@
3736
// ioctls.h
3837
#define TIOCGWINSZ 0x5413
3938

40-
41-
// signal handler function pointer type
42-
typedef void(*sighandler_t)(int);
43-
44-
// signal.h
45-
#define SIGINT 2
46-
// default handler
47-
#define SIG_DFL ( (sighandler_t) -1 )
48-
// ignored
49-
#define SIG_IGN ( (sighandler_t) -2 )
50-
5139
// signal.h
5240
#define SIGPIPE 13
5341
#define SIGCONT 18
@@ -80,7 +68,6 @@
8068
};
8169
typedef long pid_t;
8270
#define snprintf _snprintf
83-
extern sighandler_t signal( int sig, sighandler_t );
8471
#define PATH_MAX MAX_PATH
8572
#endif
8673

Diff for: ‎lldb/tools/lldb-mi/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ set(LLDB_MI_SOURCES
7373
MIUtilString.cpp
7474
MIUtilThreadBaseStd.cpp
7575
MIUtilVariant.cpp
76-
Platform.cpp
7776
)
7877

7978
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" )

Diff for: ‎lldb/tools/lldb-mi/Platform.cpp

-49
This file was deleted.

Diff for: ‎lldb/tools/lldb-mi/Platform.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111
#if defined(_MSC_VER)
1212

13-
// this will stop signal.h being included
14-
#define _INC_SIGNAL
15-
1613
#include <io.h>
1714
#include <eh.h>
1815
#include <inttypes.h>
16+
#include <signal.h>
1917
#include <lldb/Host/windows/Windows.h>
2018
#include <lldb/Host/HostGetOpt.h>
2119

@@ -73,18 +71,13 @@ typedef void (*sighandler_t)(int);
7371

7472
// CODETAG_IOR_SIGNALS
7573
// signal.h
76-
#define SIGINT 2 // Terminal interrupt signal
7774
#define SIGQUIT 3 // Terminal quit signal
7875
#define SIGKILL 9 // Kill (cannot be caught or ignored)
7976
#define SIGPIPE 13 // Write on a pipe with no one to read it
8077
#define SIGCONT 18 // Continue executing, if stopped.
8178
#define SIGTSTP 20 // Terminal stop signal
8279
#define SIGSTOP 23 // Stop executing (cannot be caught or ignored)
8380
#define SIGWINCH 28 // (== SIGVTALRM)
84-
#define SIG_DFL ((sighandler_t)-1) // Default handler
85-
#define SIG_IGN ((sighandler_t)-2) // Ignored
86-
87-
extern sighandler_t signal(int sig, sighandler_t);
8881

8982
#else
9083

0 commit comments

Comments
 (0)
Please sign in to comment.