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
This commit is contained in:
Greg Clayton
2013-12-02 19:35:49 +00:00
parent 2c86a72331
commit 5fb8f79738
20 changed files with 147 additions and 135 deletions

View File

@@ -17,9 +17,6 @@
#include <stack>
#include "lldb/lldb-public.h"
#include "lldb/API/SBDefines.h"
#include "lldb/Core/Broadcaster.h"
#include "lldb/Core/Communication.h"
#include "lldb/Core/InputReaderStack.h"
@@ -55,6 +52,10 @@ friend class SourceManager; // For GetSourceFileCache.
public:
typedef lldb::DynamicLibrarySP (*LoadPluginCallbackType) (const lldb::DebuggerSP &debugger_sp,
const FileSpec& spec,
Error& error);
static lldb::DebuggerSP
CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL);
@@ -65,7 +66,7 @@ public:
FindTargetWithProcess (Process *process);
static void
Initialize ();
Initialize (LoadPluginCallbackType load_plugin_callback);
static void
Terminate ();
@@ -333,9 +334,7 @@ public:
{
return m_instance_name;
}
typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
bool
LoadPlugin (const FileSpec& spec, Error& error);
@@ -377,6 +376,7 @@ protected:
LogStreamMap m_log_streams;
lldb::StreamSP m_log_callback_stream_sp;
ConstString m_instance_name;
static LoadPluginCallbackType g_load_plugin_callback;
typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList;
LoadedPluginsList m_loaded_plugins;

View File

@@ -19,7 +19,7 @@
#include "lldb/Core/ConstString.h"
#include "lldb/Core/Flags.h"
#include "lldb/Interpreter/OptionValue.h"
#include <Python.h>
#include "lldb/lldb-python.h"
namespace lldb_private {

View File

@@ -17,8 +17,7 @@
#else
#include <Python.h>
#include "lldb/lldb-python.h"
#include "lldb/lldb-private.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Core/InputReader.h"

View File

@@ -277,11 +277,7 @@ namespace lldb_private {
}
virtual bool
SetRemoteWorkingDirectory(const ConstString &path)
{
m_working_dir = path;
return true;
}
SetRemoteWorkingDirectory(const ConstString &path);
virtual const char *
GetUserName (uint32_t uid);

View File

@@ -12,7 +12,7 @@
#include <algorithm>
#include <Python.h>
#include "lldb/lldb-python.h"
namespace lldb_private {

View File

@@ -18,7 +18,7 @@
#else
#include <Python.h>
#include <Python/Python.h>
#endif // LLDB_DISABLE_PYTHON

View File

@@ -108,6 +108,7 @@
265205A813D3E3F700132FE2 /* RegisterContextKDP_arm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 265205A213D3E3F700132FE2 /* RegisterContextKDP_arm.cpp */; };
265205AA13D3E3F700132FE2 /* RegisterContextKDP_i386.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 265205A413D3E3F700132FE2 /* RegisterContextKDP_i386.cpp */; };
265205AC13D3E3F700132FE2 /* RegisterContextKDP_x86_64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 265205A613D3E3F700132FE2 /* RegisterContextKDP_x86_64.cpp */; };
2654283F184D025800F27E00 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C74CB6212288704006A8171 /* Carbon.framework */; };
2660AAB914622483003A9694 /* LLDBWrapPython.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A4EEB511682AAC007A372A /* LLDBWrapPython.cpp */; };
2663E379152BD1890091EC22 /* ReadWriteLock.h in Headers */ = {isa = PBXBuildFile; fileRef = 2663E378152BD1890091EC22 /* ReadWriteLock.h */; };
26651A18133BF9E0005B64B7 /* Opcode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26651A17133BF9DF005B64B7 /* Opcode.cpp */; };
@@ -1875,6 +1876,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2654283F184D025800F27E00 /* Carbon.framework in Frameworks */,
4C701C1E15ABB70C00B50001 /* libxml2.dylib in Frameworks */,
26DC6A171337FE8000FF7998 /* liblldb-core.a in Frameworks */,
26B1FCB813381071002886E2 /* CoreFoundation.framework in Frameworks */,
@@ -5353,6 +5355,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = lldb_codesign;
DEAD_CODE_STRIPPING = YES;
EXPORTED_SYMBOLS_FILE = "tools/lldb-gdbserver/exports";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
@@ -5361,6 +5364,7 @@
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_CPP_RTTI = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
@@ -5424,6 +5428,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = lldb_codesign;
DEAD_CODE_STRIPPING = YES;
EXPORTED_SYMBOLS_FILE = "tools/lldb-gdbserver/exports";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
@@ -5432,6 +5437,7 @@
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_CPP_RTTI = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
@@ -5496,6 +5502,7 @@
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
ENABLE_NS_ASSERTIONS = NO;
EXPORTED_SYMBOLS_FILE = "tools/lldb-gdbserver/exports";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
@@ -5503,6 +5510,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_CPP_RTTI = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
@@ -5562,6 +5570,7 @@
COPY_PHASE_STRIP = YES;
DEAD_CODE_STRIPPING = YES;
ENABLE_NS_ASSERTIONS = NO;
EXPORTED_SYMBOLS_FILE = "tools/lldb-gdbserver/exports";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
@@ -5569,6 +5578,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_CPP_RTTI = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
@@ -5626,6 +5636,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = lldb_codesign;
DEAD_CODE_STRIPPING = YES;
EXPORTED_SYMBOLS_FILE = "tools/lldb-platform/exports";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
@@ -5695,6 +5706,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = lldb_codesign;
DEAD_CODE_STRIPPING = YES;
EXPORTED_SYMBOLS_FILE = "tools/lldb-platform/exports";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
@@ -5761,6 +5773,7 @@
buildSettings = {
COPY_PHASE_STRIP = YES;
DEAD_CODE_STRIPPING = YES;
EXPORTED_SYMBOLS_FILE = "tools/lldb-platform/exports";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",
@@ -6122,6 +6135,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = lldb_codesign;
DEAD_CODE_STRIPPING = YES;
EXPORTED_SYMBOLS_FILE = "tools/lldb-platform/exports";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"",

View File

@@ -38,6 +38,7 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/State.h"
#include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/Host/DynamicLibrary.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/OptionGroupPlatform.h"
@@ -47,6 +48,41 @@
using namespace lldb;
using namespace lldb_private;
static lldb::DynamicLibrarySP
LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error)
{
lldb::DynamicLibrarySP dynlib_sp(new lldb_private::DynamicLibrary(spec));
if (dynlib_sp && dynlib_sp->IsValid())
{
typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
lldb::SBDebugger debugger_sb(debugger_sp);
// This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function.
// TODO: mangle this differently for your system - on OSX, the first underscore needs to be removed and the second one stays
LLDBCommandPluginInit init_func = dynlib_sp->GetSymbol<LLDBCommandPluginInit>("_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
if (init_func)
{
if (init_func(debugger_sb))
return dynlib_sp;
else
error.SetErrorString("plug-in refused to load (lldb::PluginInitialize(lldb::SBDebugger) returned false)");
}
else
{
error.SetErrorString("plug-in is missing the required initialization: lldb::PluginInitialize(lldb::SBDebugger)");
}
}
else
{
if (spec.Exists())
error.SetErrorString("this file does not represent a loadable dylib");
else
error.SetErrorString("no such file");
}
return lldb::DynamicLibrarySP();
}
void
SBDebugger::Initialize ()
{
@@ -57,7 +93,7 @@ SBDebugger::Initialize ()
SBCommandInterpreter::InitializeSWIG ();
Debugger::Initialize();
Debugger::Initialize(LoadPlugin);
}
void

View File

@@ -11,10 +11,6 @@
#include "CommandObjectPlugin.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBCommandInterpreter.h"
#include "lldb/API/SBCommandReturnObject.h"
#include "lldb/Host/Host.h"
#include "lldb/Interpreter/CommandInterpreter.h"
@@ -79,8 +75,6 @@ protected:
bool
DoExecute (Args& command, CommandReturnObject &result)
{
typedef void (*LLDBCommandPluginInit) (lldb::SBDebugger debugger);
size_t argc = command.GetArgumentCount();
if (argc != 1)

View File

@@ -9,8 +9,6 @@
#include "lldb/lldb-python.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/Core/Debugger.h"
#include <map>
@@ -46,6 +44,7 @@
#include "lldb/Target/TargetList.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
@@ -155,19 +154,7 @@ enum
ePropertyAutoOneLineSummaries
};
//
//const char *
//Debugger::GetFrameFormat() const
//{
// return m_properties_sp->GetFrameFormat();
//}
//const char *
//Debugger::GetThreadFormat() const
//{
// return m_properties_sp->GetThreadFormat();
//}
//
Debugger::LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL;
Error
Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
@@ -373,8 +360,9 @@ Debugger::TestDebuggerRefCount ()
}
void
Debugger::Initialize ()
Debugger::Initialize (LoadPluginCallbackType load_plugin_callback)
{
g_load_plugin_callback = load_plugin_callback;
if (g_shared_debugger_refcount++ == 0)
lldb_private::Initialize();
}
@@ -412,31 +400,22 @@ Debugger::SettingsTerminate ()
bool
Debugger::LoadPlugin (const FileSpec& spec, Error& error)
{
lldb::DynamicLibrarySP dynlib_sp(new lldb_private::DynamicLibrary(spec));
if (!dynlib_sp || dynlib_sp->IsValid() == false)
if (g_load_plugin_callback)
{
if (spec.Exists())
error.SetErrorString("this file does not represent a loadable dylib");
else
error.SetErrorString("no such file");
return false;
lldb::DynamicLibrarySP dynlib_sp = g_load_plugin_callback (shared_from_this(), spec, error);
if (dynlib_sp)
{
m_loaded_plugins.push_back(dynlib_sp);
return true;
}
}
lldb::DebuggerSP debugger_sp(shared_from_this());
lldb::SBDebugger debugger_sb(debugger_sp);
// This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function.
// TODO: mangle this differently for your system - on OSX, the first underscore needs to be removed and the second one stays
LLDBCommandPluginInit init_func = dynlib_sp->GetSymbol<LLDBCommandPluginInit>("_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
if (!init_func)
else
{
error.SetErrorString("cannot find the initialization function lldb::PluginInitialize(lldb::SBDebugger)");
return false;
// The g_load_plugin_callback is registered in SBDebugger::Initialize()
// and if the public API layer isn't available (code is linking against
// all of the internal LLDB static libraries), then we can't load plugins
error.SetErrorString("Public API layer is not available");
}
if (init_func(debugger_sb))
{
m_loaded_plugins.push_back(dynlib_sp);
return true;
}
error.SetErrorString("dylib refused to be loaded");
return false;
}

View File

@@ -15,7 +15,7 @@
#else
#include <Python.h>
#include "lldb/lldb-python.h"
#include <stdio.h>

View File

@@ -15,8 +15,7 @@
#else
#include <Python.h>
#include "lldb/lldb-python.h"
#include "lldb/Interpreter/ScriptInterpreterPython.h"
#include <stdlib.h>

View File

@@ -303,7 +303,7 @@ PlatformDarwin::GetSharedModuleWithLocalCache (const lldb_private::ModuleSpec &m
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (log)
log->Printf("[%s] Trying to find module %s/%s - platform path %s/%s symbol path %s/%s\n",
log->Printf("[%s] Trying to find module %s/%s - platform path %s/%s symbol path %s/%s",
(IsHost() ? "host" : "remote"),
module_spec.GetFileSpec().GetDirectory().AsCString(),
module_spec.GetFileSpec().GetFilename().AsCString(),
@@ -328,7 +328,7 @@ PlatformDarwin::GetSharedModuleWithLocalCache (const lldb_private::ModuleSpec &m
{
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (log)
log->Printf("[%s] module %s/%s was rsynced and is now there\n",
log->Printf("[%s] module %s/%s was rsynced and is now there",
(IsHost() ? "host" : "remote"),
module_spec.GetFileSpec().GetDirectory().AsCString(),
module_spec.GetFileSpec().GetFilename().AsCString());
@@ -361,7 +361,7 @@ PlatformDarwin::GetSharedModuleWithLocalCache (const lldb_private::ModuleSpec &m
// bring in the remote file
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (log)
log->Printf("[%s] module %s/%s needs to be replaced from remote copy\n",
log->Printf("[%s] module %s/%s needs to be replaced from remote copy",
(IsHost() ? "host" : "remote"),
module_spec.GetFileSpec().GetDirectory().AsCString(),
module_spec.GetFileSpec().GetFilename().AsCString());
@@ -376,7 +376,7 @@ PlatformDarwin::GetSharedModuleWithLocalCache (const lldb_private::ModuleSpec &m
module_sp->SetPlatformFileSpec(module_spec.GetFileSpec());
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (log)
log->Printf("[%s] module %s/%s was found in the cache\n",
log->Printf("[%s] module %s/%s was found in the cache",
(IsHost() ? "host" : "remote"),
module_spec.GetFileSpec().GetDirectory().AsCString(),
module_spec.GetFileSpec().GetFilename().AsCString());
@@ -385,7 +385,7 @@ PlatformDarwin::GetSharedModuleWithLocalCache (const lldb_private::ModuleSpec &m
// bring in the remote module file
if (log)
log->Printf("[%s] module %s/%s needs to come in remotely\n",
log->Printf("[%s] module %s/%s needs to come in remotely",
(IsHost() ? "host" : "remote"),
module_spec.GetFileSpec().GetDirectory().AsCString(),
module_spec.GetFileSpec().GetFilename().AsCString());
@@ -396,7 +396,7 @@ PlatformDarwin::GetSharedModuleWithLocalCache (const lldb_private::ModuleSpec &m
{
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (log)
log->Printf("[%s] module %s/%s is now cached and fine\n",
log->Printf("[%s] module %s/%s is now cached and fine",
(IsHost() ? "host" : "remote"),
module_spec.GetFileSpec().GetDirectory().AsCString(),
module_spec.GetFileSpec().GetFilename().AsCString());

View File

@@ -199,13 +199,19 @@ PlatformRemoteGDBServer::GetRemoteWorkingDirectory()
{
if (IsConnected())
{
if (!m_working_dir)
Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
std::string cwd;
if (m_gdb_client.GetWorkingDir(cwd))
{
std::string cwd;
if (m_gdb_client.GetWorkingDir(cwd))
m_working_dir = ConstString(cwd.c_str());
ConstString working_dir(cwd.c_str());
if (log)
log->Printf("PlatformRemoteGDBServer::GetRemoteWorkingDirectory() -> '%s'", working_dir.GetCString());
return working_dir;
}
else
{
return ConstString();
}
return m_working_dir;
}
else
{
@@ -220,7 +226,9 @@ PlatformRemoteGDBServer::SetRemoteWorkingDirectory(const lldb_private::ConstStri
{
// Clear the working directory it case it doesn't get set correctly. This will
// for use to re-read it
m_working_dir.Clear();
Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
if (log)
log->Printf("PlatformRemoteGDBServer::SetRemoteWorkingDirectory('%s')", path.GetCString());
return m_gdb_client.SetWorkingDir(path.GetCString()) == 0;
}
else

View File

@@ -671,6 +671,9 @@ Platform::SetWorkingDirectory (const ConstString &path)
{
if (IsHost())
{
Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
if (log)
log->Printf("Platform::SetWorkingDirectory('%s')", path.GetCString());
#ifdef _WIN32
// Not implemented on Windows
return false;
@@ -685,6 +688,7 @@ Platform::SetWorkingDirectory (const ConstString &path)
}
else
{
m_working_dir.Clear();
return SetRemoteWorkingDirectory(path);
}
}
@@ -745,6 +749,16 @@ Platform::GetHostname ()
return m_name.c_str();
}
bool
Platform::SetRemoteWorkingDirectory(const ConstString &path)
{
Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
if (log)
log->Printf("Platform::SetRemoteWorkingDirectory('%s')", path.GetCString());
m_working_dir = path;
return true;
}
const char *
Platform::GetUserName (uint32_t uid)
{

View File

@@ -1686,7 +1686,10 @@ class TestBase(Base):
if lldb.remote_platform:
#remote_test_dir = os.path.join(lldb.remote_platform_working_dir, self.mydir)
remote_test_dir = os.path.join(lldb.remote_platform_working_dir, str(self.test_number), self.mydir)
remote_test_dir = os.path.join(lldb.remote_platform_working_dir,
self.getArchitecture(),
str(self.test_number),
self.mydir)
error = lldb.remote_platform.MakeDirectory(remote_test_dir, 0700)
if error.Success():
print "successfully made remote directory '%s'" % (remote_test_dir)

View File

View File

@@ -93,7 +93,7 @@ main (int argc, char *argv[])
Args log_args;
Error error;
int ch;
Debugger::Initialize();
Debugger::Initialize(NULL);
ProcessLaunchInfo launch_info;
ProcessAttachInfo attach_info;

View File

View File

@@ -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 @@ static struct option g_long_options[] =
{ "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 @@ main (int argc, char *argv[])
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 @@ main (int argc, char *argv[])
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 @@ main (int argc, char *argv[])
}
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 @@ main (int argc, char *argv[])
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);