summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2013-11-22 18:55:04 +0000
committerGreg Clayton <gclayton@apple.com>2013-11-22 18:55:04 +0000
commitd4724cfdb15b1929889e452c73876d4b3415a700 (patch)
treeb4cdf63cf8047e9b70ea0854068647b19461c80b /lldb
parent2b98c569966e29bb3335773bc620a175b1d620c8 (diff)
downloadbcm5719-llvm-d4724cfdb15b1929889e452c73876d4b3415a700.tar.gz
bcm5719-llvm-d4724cfdb15b1929889e452c73876d4b3415a700.zip
Make sure the getopt variables are correctly initialized for any option parsing.
Added a new "--port-offset PORT" option to lldb-platform so it can be used with USB mux type scenarios. llvm-svn: 195486
Diffstat (limited to 'lldb')
-rw-r--r--lldb/tools/darwin-debug/darwin-debug.cpp8
-rw-r--r--lldb/tools/debugserver/source/debugserver.cpp8
-rw-r--r--lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp6
-rw-r--r--lldb/tools/lldb-platform/lldb-platform.cpp47
4 files changed, 64 insertions, 5 deletions
diff --git a/lldb/tools/darwin-debug/darwin-debug.cpp b/lldb/tools/darwin-debug/darwin-debug.cpp
index d81c5974020..62e1b884a97 100644
--- a/lldb/tools/darwin-debug/darwin-debug.cpp
+++ b/lldb/tools/darwin-debug/darwin-debug.cpp
@@ -186,6 +186,14 @@ int main (int argc, char *const *argv, char *const *envp, const char **apple)
bool pass_env = true;
std::string unix_socket_name;
std::string working_dir;
+
+#if __GLIBC__
+ optind = 0;
+#else
+ optreset = 1;
+ optind = 1;
+#endif
+
while ((ch = getopt_long_only(argc, argv, "a:deE:hsu:?", g_long_options, NULL)) != -1)
{
switch (ch)
diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp
index 61b8604d177..baa0fb79400 100644
--- a/lldb/tools/debugserver/source/debugserver.cpp
+++ b/lldb/tools/debugserver/source/debugserver.cpp
@@ -878,6 +878,14 @@ main (int argc, char *argv[])
}
// NULL terminate the short option string.
short_options[short_options_idx++] = '\0';
+
+#if __GLIBC__
+ optind = 0;
+#else
+ optreset = 1;
+ optind = 1;
+#endif
+
while ((ch = getopt_long_only(argc, argv, short_options, g_long_options, &long_option_index)) != -1)
{
DNBLogDebug("option: ch == %c (0x%2.2x) --%s%c%s\n",
diff --git a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
index f8f44a87a73..0faf4c2c3f6 100644
--- a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
+++ b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
@@ -101,6 +101,12 @@ main (int argc, char *argv[])
// StreamSP stream_sp (new StreamFile(stdout, false));
// const char *log_channels[] = { "host", "process", NULL };
// EnableLog (stream_sp, 0, log_channels, NULL);
+#if __GLIBC__
+ optind = 0;
+#else
+ optreset = 1;
+ optind = 1;
+#endif
while ((ch = getopt_long_only(argc, argv, "l:f:h", g_long_options, &long_option_index)) != -1)
{
diff --git a/lldb/tools/lldb-platform/lldb-platform.cpp b/lldb/tools/lldb-platform/lldb-platform.cpp
index 1583b4ad3e4..fe69ea9f7dc 100644
--- a/lldb/tools/lldb-platform/lldb-platform.cpp
+++ b/lldb/tools/lldb-platform/lldb-platform.cpp
@@ -48,7 +48,8 @@ static struct option g_long_options[] =
{ "log-file", required_argument, NULL, 'l' },
{ "log-flags", required_argument, NULL, 'f' },
{ "listen", required_argument, NULL, 'L' },
- { "gdbserver-port", required_argument, NULL, 'p' },
+ { "port-offset", required_argument, NULL, 'p' },
+ { "gdbserver-port", required_argument, NULL, 'P' },
{ "min-gdbserver-port", required_argument, NULL, 'm' },
{ "max-gdbserver-port", required_argument, NULL, 'M' },
{ NULL, 0, NULL, 0 }
@@ -112,13 +113,22 @@ main (int argc, char *argv[])
GDBRemoteCommunicationServer::PortMap gdbserver_portmap;
int min_gdbserver_port = 0;
int max_gdbserver_port = 0;
+ uint16_t port_offset = 0;
bool show_usage = false;
int option_error = 0;
-// StreamSP stream_sp (new StreamFile(stdout, false));
-// const char *log_channels[] = { "host", "process", NULL };
-// EnableLog (stream_sp, 0, log_channels, NULL);
+ // Enable LLDB log channels...
+ StreamSP stream_sp (new StreamFile(stdout, false));
+ const char *log_channels[] = { "platform", "host", "process", NULL };
+ EnableLog (stream_sp, 0, log_channels, NULL);
+#if __GLIBC__
+ optind = 0;
+#else
+ optreset = 1;
+ optind = 1;
+#endif
+
while ((ch = getopt_long_only(argc, argv, "l:f:L:p:m:M:", g_long_options, &long_option_index)) != -1)
{
// DNBLogDebug("option: ch == %c (0x%2.2x) --%s%c%s\n",
@@ -171,6 +181,30 @@ main (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);
+ option_error = 4;
+ }
+ }
+ break;
+
+ case 'P':
case 'm':
case 'M':
{
@@ -180,7 +214,7 @@ main (int argc, char *argv[])
{
if (LOW_PORT <= portnum && portnum <= HIGH_PORT)
{
- if (ch == 'p')
+ if (ch == 'P')
gdbserver_portmap[(uint16_t)portnum] = LLDB_INVALID_PROCESS_ID;
else if (ch == 'm')
min_gdbserver_port = portnum;
@@ -246,6 +280,9 @@ main (int argc, char *argv[])
do {
GDBRemoteCommunicationServer gdb_server (true);
+ if (port_offset > 0)
+ gdb_server.SetPortOffset(port_offset);
+
if (!gdbserver_portmap.empty())
{
gdb_server.SetPortMap(std::move(gdbserver_portmap));
OpenPOWER on IntegriCloud