Fixed internal code to not link against and code from "lldb/API/*". 

lldb_private::Debugger was #including some "lldb/API" header files which causes tools (lldb-platform and lldb-gdbserver) that link against the internals only (no API layer) to fail to link depending on which calls were being used.

Also fixed the current working directory so that it gets set correctly for remote test suite runs. Now the remote working directory is set to: "ARCH/TESTNUM/..." where ARCH is the current architecture name and "TESTNUM" is the current test number. 

Fixed the "lldb-platform" and "lldb-gdbserver" to not warn about mismatched visibility settings by having each have their own exports file which contains nothing. This forces all symbols to not be exported, and also quiets the linker warnings.

llvm-svn: 196141
diff --git a/lldb/tools/lldb-platform/lldb-platform.cpp b/lldb/tools/lldb-platform/lldb-platform.cpp
index aa8b883..bc9d629 100644
--- a/lldb/tools/lldb-platform/lldb-platform.cpp
+++ b/lldb/tools/lldb-platform/lldb-platform.cpp
@@ -28,6 +28,8 @@
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Host/OptionParser.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
 using namespace lldb;
@@ -46,13 +48,12 @@
     { "debug",              no_argument,        &g_debug,           1   },
     { "verbose",            no_argument,        &g_verbose,         1   },
     { "stay-alive",         no_argument,        &g_stay_alive,      1   },
-    { "log-file",           required_argument,  NULL,               'l' },
-    { "log-flags",          required_argument,  NULL,               'f' },
     { "listen",             required_argument,  NULL,               'L' },
     { "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' },
+    { "lldb-command",       required_argument,  NULL,               'c' },
     { NULL,                 0,                  NULL,               0   }
 };
 
@@ -100,24 +101,25 @@
     signal (SIGPIPE, SIG_IGN);
     signal (SIGHUP, signal_handler);
     int long_option_index = 0;
-    StreamSP log_stream_sp;
-    Args log_args;
     Error error;
     std::string listen_host_port;
     int ch;
-    Debugger::Initialize();
+    Debugger::Initialize(NULL);
+
+    lldb::DebuggerSP debugger_sp = Debugger::CreateInstance ();
+
+    debugger_sp->SetInputFileHandle(stdin, false);
+    debugger_sp->SetOutputFileHandle(stdout, false);
+    debugger_sp->SetErrorFileHandle(stderr, false);
     
     GDBRemoteCommunicationServer::PortMap gdbserver_portmap;
     int min_gdbserver_port = 0;
     int max_gdbserver_port = 0;
     uint16_t port_offset = 0;
     
+    std::vector<std::string> lldb_commands;
     bool show_usage = false;
     int option_error = 0;
-    // 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);
     
     std::string short_options(OptionParser::GetShortOptionString(g_long_options));
                             
@@ -130,51 +132,11 @@
 
     while ((ch = getopt_long_only(argc, argv, short_options.c_str(), g_long_options, &long_option_index)) != -1)
     {
-//        DNBLogDebug("option: ch == %c (0x%2.2x) --%s%c%s\n",
-//                    ch, (uint8_t)ch,
-//                    g_long_options[long_option_index].name,
-//                    g_long_options[long_option_index].has_arg ? '=' : ' ',
-//                    optarg ? optarg : "");
         switch (ch)
         {
         case 0:   // Any optional that auto set themselves will return 0
             break;
 
-        case 'l': // Set Log File
-            if (optarg && optarg[0])
-            {
-                if ((strcasecmp(optarg, "stdout") == 0) || (strcmp(optarg, "/dev/stdout") == 0))
-                {
-                    log_stream_sp.reset (new StreamFile (stdout, false));
-                }
-                else if ((strcasecmp(optarg, "stderr") == 0) || (strcmp(optarg, "/dev/stderr") == 0))
-                {
-                    log_stream_sp.reset (new StreamFile (stderr, false));
-                }
-                else
-                {
-                    FILE *log_file = fopen(optarg, "w");
-                    if (log_file)
-                    {
-                        setlinebuf(log_file);
-                        log_stream_sp.reset (new StreamFile (log_file, true));
-                    }
-                    else
-                    {
-                        const char *errno_str = strerror(errno);
-                        fprintf (stderr, "Failed to open log file '%s' for writing: errno = %i (%s)", optarg, errno, errno_str ? errno_str : "unknown error");
-                    }
-
-                }
-                
-            }
-            break;
-
-        case 'f': // Log Flags
-            if (optarg && optarg[0])
-                log_args.AppendArgument(optarg);
-            break;
-        
         case 'L':
             listen_host_port.append (optarg);
             break;
@@ -234,13 +196,17 @@
             }
             break;
             
+        case 'c':
+            lldb_commands.push_back(optarg);
+            break;
+
         case 'h':   /* fall-through is intentional */
         case '?':
             show_usage = true;
             break;
         }
     }
-    
+
     // Make a port map for a port range that was specified.
     if (min_gdbserver_port < max_gdbserver_port)
     {
@@ -264,17 +230,21 @@
         exit(option_error);
     }
     
-    if (log_stream_sp)
-    {
-        if (log_args.GetArgumentCount() == 0)
-            log_args.AppendArgument("default");
-        ProcessGDBRemoteLog::EnableLog (log_stream_sp, 0,log_args.GetConstArgumentVector(), log_stream_sp.get());
-    }
-
     // Skip any options we consumed with getopt_long_only
     argc -= optind;
     argv += optind;
 
+    // Execute any LLDB commands that we were asked to evaluate.
+    for (const auto &lldb_command : lldb_commands)
+    {
+        lldb_private::CommandReturnObject result;
+        printf("(lldb) %s\n", lldb_command.c_str());
+        debugger_sp->GetCommandInterpreter().HandleCommand(lldb_command.c_str(), eLazyBoolNo, result);
+        const char *output = result.GetOutputData();
+        if (output && output[0])
+            puts(output);
+    }
+
 
     do {
         GDBRemoteCommunicationServer gdb_server (true);