summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-07-13 19:26:17 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-07-13 19:26:17 +0000
commite75e363cb71a7339552b9d943e78ac62b737379b (patch)
tree29ec5bd173694acbbcbb8207114ef7ca189436ba /tools
parent1b306c26ade71504511d2fa75b03dfaee77f9620 (diff)
downloadsrc-test2-e75e363cb71a7339552b9d943e78ac62b737379b.tar.gz
src-test2-e75e363cb71a7339552b9d943e78ac62b737379b.zip
Notes
Diffstat (limited to 'tools')
-rw-r--r--tools/lldb-server/CMakeLists.txt12
-rw-r--r--tools/lldb-server/lldb-gdbserver.cpp34
-rw-r--r--tools/lldb-server/lldb-platform.cpp57
3 files changed, 70 insertions, 33 deletions
diff --git a/tools/lldb-server/CMakeLists.txt b/tools/lldb-server/CMakeLists.txt
index 4f76ebd6881c..f8c57cb9488f 100644
--- a/tools/lldb-server/CMakeLists.txt
+++ b/tools/lldb-server/CMakeLists.txt
@@ -59,6 +59,16 @@ if (LLVM_BUILD_STATIC)
endif()
endif()
+set(LLDB_PLUGINS)
+
+if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
+ list(APPEND LLDB_PLUGINS lldbPluginProcessLinux)
+endif()
+
+if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
+ list(APPEND LLDB_PLUGINS lldbPluginProcessNetBSD)
+endif()
+
add_lldb_tool(lldb-server INCLUDE_IN_FRAMEWORK
Acceptor.cpp
lldb-gdbserver.cpp
@@ -72,7 +82,7 @@ add_lldb_tool(lldb-server INCLUDE_IN_FRAMEWORK
lldbHost
lldbInitialization
lldbInterpreter
- ${EXTRA_LLDB_LIBS}
+ ${LLDB_PLUGINS}
${LLDB_SYSTEM_LIBS}
LINK_COMPONENTS
diff --git a/tools/lldb-server/lldb-gdbserver.cpp b/tools/lldb-server/lldb-gdbserver.cpp
index 412d775e8394..337f244c2c2d 100644
--- a/tools/lldb-server/lldb-gdbserver.cpp
+++ b/tools/lldb-server/lldb-gdbserver.cpp
@@ -33,10 +33,17 @@
#include "lldb/Host/Pipe.h"
#include "lldb/Host/Socket.h"
#include "lldb/Host/StringConvert.h"
+#include "lldb/Host/common/NativeProcessProtocol.h"
#include "lldb/Utility/Status.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Errno.h"
+#if defined(__linux__)
+#include "Plugins/Process/Linux/NativeProcessLinux.h"
+#elif defined(__NetBSD__)
+#include "Plugins/Process/NetBSD/NativeProcessNetBSD.h"
+#endif
+
#ifndef LLGS_PROGRAM_NAME
#define LLGS_PROGRAM_NAME "lldb-server"
#endif
@@ -51,6 +58,30 @@ using namespace lldb_private;
using namespace lldb_private::lldb_server;
using namespace lldb_private::process_gdb_remote;
+namespace {
+#if defined(__linux__)
+typedef process_linux::NativeProcessLinux::Factory NativeProcessFactory;
+#elif defined(__NetBSD__)
+typedef process_netbsd::NativeProcessNetBSD::Factory NativeProcessFactory;
+#else
+// Dummy implementation to make sure the code compiles
+class NativeProcessFactory : public NativeProcessProtocol::Factory {
+public:
+ llvm::Expected<NativeProcessProtocolSP>
+ Launch(ProcessLaunchInfo &launch_info,
+ NativeProcessProtocol::NativeDelegate &delegate,
+ MainLoop &mainloop) const override {
+ llvm_unreachable("Not implemented");
+ }
+ llvm::Expected<NativeProcessProtocolSP>
+ Attach(lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &delegate,
+ MainLoop &mainloop) const override {
+ llvm_unreachable("Not implemented");
+ }
+};
+#endif
+}
+
//----------------------------------------------------------------------
// option descriptors for getopt_long_only()
//----------------------------------------------------------------------
@@ -446,7 +477,8 @@ int main_gdbserver(int argc, char *argv[]) {
exit(255);
}
- GDBRemoteCommunicationServerLLGS gdb_server(mainloop);
+ NativeProcessFactory factory;
+ GDBRemoteCommunicationServerLLGS gdb_server(mainloop, factory);
const char *const host_and_port = argv[0];
argc -= 1;
diff --git a/tools/lldb-server/lldb-platform.cpp b/tools/lldb-server/lldb-platform.cpp
index 8d45682566b9..ec5b781dac48 100644
--- a/tools/lldb-server/lldb-platform.cpp
+++ b/tools/lldb-server/lldb-platform.cpp
@@ -197,46 +197,41 @@ int main_platform(int argc, char *argv[]) {
break;
case 'p': {
- char *end = NULL;
- long tmp_port_offset = strtoul(optarg, &end, 0);
- if (end && *end == '\0') {
- if (LOW_PORT <= tmp_port_offset && tmp_port_offset <= HIGH_PORT) {
- port_offset = (uint16_t)tmp_port_offset;
- } else {
- fprintf(stderr, "error: port offset %li is not in the valid user "
- "port range of %u - %u\n",
- tmp_port_offset, LOW_PORT, HIGH_PORT);
- option_error = 5;
- }
- } else {
- fprintf(stderr, "error: invalid port offset string %s\n", optarg);
+ if (!llvm::to_integer(optarg, port_offset)) {
+ llvm::errs() << "error: invalid port offset string " << optarg << "\n";
option_error = 4;
+ break;
+ }
+ if (port_offset < LOW_PORT || port_offset > HIGH_PORT) {
+ llvm::errs() << llvm::formatv("error: port offset {0} is not in the "
+ "valid user port range of {1} - {2}\n",
+ port_offset, LOW_PORT, HIGH_PORT);
+ option_error = 5;
}
} break;
case 'P':
case 'm':
case 'M': {
- char *end = NULL;
- long portnum = strtoul(optarg, &end, 0);
- if (end && *end == '\0') {
- if (LOW_PORT <= portnum && portnum <= HIGH_PORT) {
- if (ch == 'P')
- gdbserver_portmap[(uint16_t)portnum] = LLDB_INVALID_PROCESS_ID;
- else if (ch == 'm')
- min_gdbserver_port = portnum;
- else
- max_gdbserver_port = portnum;
- } else {
- fprintf(stderr, "error: port number %li is not in the valid user "
- "port range of %u - %u\n",
- portnum, LOW_PORT, HIGH_PORT);
- option_error = 1;
- }
- } else {
- fprintf(stderr, "error: invalid port number string %s\n", optarg);
+ uint16_t portnum;
+ if (!llvm::to_integer(optarg, portnum)) {
+ llvm::errs() << "error: invalid port number string " << optarg << "\n";
option_error = 2;
+ break;
+ }
+ if (portnum < LOW_PORT || portnum > HIGH_PORT) {
+ llvm::errs() << llvm::formatv("error: port number {0} is not in the "
+ "valid user port range of {1} - {2}\n",
+ portnum, LOW_PORT, HIGH_PORT);
+ option_error = 1;
+ break;
}
+ if (ch == 'P')
+ gdbserver_portmap[portnum] = LLDB_INVALID_PROCESS_ID;
+ else if (ch == 'm')
+ min_gdbserver_port = portnum;
+ else
+ max_gdbserver_port = portnum;
} break;
case 'h': /* fall-through is intentional */