summaryrefslogtreecommitdiffstats
path: root/lldb/tools/lldb-vscode/lldb-vscode.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2019-03-07 21:23:21 +0000
committerZachary Turner <zturner@google.com>2019-03-07 21:23:21 +0000
commit29e8754172031ed217d25e3de0bc4047192a3453 (patch)
treea937f8971212dcbd47fc516d9b3cb4fbf1255b58 /lldb/tools/lldb-vscode/lldb-vscode.cpp
parentd0c2dba644e27210ed13cd638aa8b8e677ed757d (diff)
downloadbcm5719-llvm-29e8754172031ed217d25e3de0bc4047192a3453.tar.gz
bcm5719-llvm-29e8754172031ed217d25e3de0bc4047192a3453.zip
[lldb-vscode] Support running in server mode on Windows.
Windows can't use standard i/o system calls such as read and write to work with sockets, it instead needs to use the specific send and recv calls. This complicates matters for the debug adapter, since it needs to be able to work in both server mode where it communicates over a socket, as well as non-server mode where it communicates via stdin and stdout. To abstract this out, I've introduced a class IOStream which hides all these details and exposes a read/write interface that does the right on each platform. Differential Revision: https://reviews.llvm.org/D59104 llvm-svn: 355637
Diffstat (limited to 'lldb/tools/lldb-vscode/lldb-vscode.cpp')
-rw-r--r--lldb/tools/lldb-vscode/lldb-vscode.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index 82637c6246a..4b17f71df87 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -23,6 +23,7 @@
#define NOMINMAX
#include <windows.h>
#undef GetObject
+#include <io.h>
#else
#include <netinet/in.h>
#include <sys/socket.h>
@@ -53,7 +54,6 @@ typedef int socklen_t;
constexpr const char *dev_null_path = "nul";
#else
-typedef int SOCKET;
constexpr const char *dev_null_path = "/dev/null";
#endif
@@ -68,9 +68,9 @@ enum LaunchMethod { Launch, Attach, AttachForSuspendedLaunch };
enum VSCodeBroadcasterBits { eBroadcastBitStopEventThread = 1u << 0 };
-int AcceptConnection(int portno) {
+SOCKET AcceptConnection(int portno) {
// Accept a socket connection from any host on "portno".
- int newsockfd = -1;
+ SOCKET newsockfd = -1;
struct sockaddr_in serv_addr, cli_addr;
SOCKET sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
@@ -2635,23 +2635,19 @@ int main(int argc, char *argv[]) {
#endif
int portno = atoi(arg);
printf("Listening on port %i...\n", portno);
- int socket_fd = AcceptConnection(portno);
+ SOCKET socket_fd = AcceptConnection(portno);
if (socket_fd >= 0) {
- // We must open two FILE objects, one for reading and one for writing
- // the FILE objects have a mutex in them that won't allow reading and
- // writing to the socket stream.
- g_vsc.in = fdopen(socket_fd, "r");
- g_vsc.out = fdopen(socket_fd, "w");
- if (g_vsc.in == nullptr || g_vsc.out == nullptr) {
- if (g_vsc.log)
- *g_vsc.log << "fdopen failed (" << strerror(errno) << ")"
- << std::endl;
- exit(1);
- }
+ g_vsc.input.descriptor = StreamDescriptor::from_socket(socket_fd, true);
+ g_vsc.output.descriptor =
+ StreamDescriptor::from_socket(socket_fd, false);
} else {
exit(1);
}
}
+ } else {
+ g_vsc.input.descriptor = StreamDescriptor::from_file(fileno(stdin), false);
+ g_vsc.output.descriptor =
+ StreamDescriptor::from_file(fileno(stdout), false);
}
auto request_handlers = GetRequestHandlers();
uint32_t packet_idx = 0;
OpenPOWER on IntegriCloud