diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index 671b378df807..a3c6d5eeb93d 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -17,9 +17,6 @@ #include #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 LoadedPluginsList; LoadedPluginsList m_loaded_plugins; diff --git a/lldb/include/lldb/Interpreter/PythonDataObjects.h b/lldb/include/lldb/Interpreter/PythonDataObjects.h index 568f6ac0724e..2762d452c0c8 100644 --- a/lldb/include/lldb/Interpreter/PythonDataObjects.h +++ b/lldb/include/lldb/Interpreter/PythonDataObjects.h @@ -19,7 +19,7 @@ #include "lldb/Core/ConstString.h" #include "lldb/Core/Flags.h" #include "lldb/Interpreter/OptionValue.h" -#include +#include "lldb/lldb-python.h" namespace lldb_private { diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h b/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h index 65647e367ed2..b729cb628007 100644 --- a/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h +++ b/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h @@ -17,8 +17,7 @@ #else -#include - +#include "lldb/lldb-python.h" #include "lldb/lldb-private.h" #include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Core/InputReader.h" diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 23903a669f7a..355c0528bed8 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -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); diff --git a/lldb/include/lldb/Utility/PythonPointer.h b/lldb/include/lldb/Utility/PythonPointer.h index de236c5a07d2..fe90670fd2e1 100644 --- a/lldb/include/lldb/Utility/PythonPointer.h +++ b/lldb/include/lldb/Utility/PythonPointer.h @@ -12,7 +12,7 @@ #include -#include +#include "lldb/lldb-python.h" namespace lldb_private { diff --git a/lldb/include/lldb/lldb-python.h b/lldb/include/lldb/lldb-python.h index ce5c8176a3c3..4be0133a6437 100644 --- a/lldb/include/lldb/lldb-python.h +++ b/lldb/include/lldb/lldb-python.h @@ -18,7 +18,7 @@ #else -#include +#include #endif // LLDB_DISABLE_PYTHON diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj index c563c830daff..6ec9896f2cfc 100644 --- a/lldb/lldb.xcodeproj/project.pbxproj +++ b/lldb/lldb.xcodeproj/project.pbxproj @@ -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\"", diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index 5aa5c133a167..10c0b7dea208 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -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("_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 diff --git a/lldb/source/Commands/CommandObjectPlugin.cpp b/lldb/source/Commands/CommandObjectPlugin.cpp index 1bc7632e2985..658c077bc3ea 100644 --- a/lldb/source/Commands/CommandObjectPlugin.cpp +++ b/lldb/source/Commands/CommandObjectPlugin.cpp @@ -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) diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 3941d82d47b0..b57c6051a961 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -9,8 +9,6 @@ #include "lldb/lldb-python.h" -#include "lldb/API/SBDebugger.h" - #include "lldb/Core/Debugger.h" #include @@ -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("_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; } diff --git a/lldb/source/Interpreter/PythonDataObjects.cpp b/lldb/source/Interpreter/PythonDataObjects.cpp index 8e5c2bf8fe64..1e2bd2391191 100644 --- a/lldb/source/Interpreter/PythonDataObjects.cpp +++ b/lldb/source/Interpreter/PythonDataObjects.cpp @@ -15,7 +15,7 @@ #else -#include +#include "lldb/lldb-python.h" #include diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index a44b5a9f68c6..fb60fedbe94b 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -15,8 +15,7 @@ #else -#include - +#include "lldb/lldb-python.h" #include "lldb/Interpreter/ScriptInterpreterPython.h" #include diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 0a484d8cc40c..ac5a615022ff 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -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()); diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 069ff0c8918d..248abaf6fea7 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -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 diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 9c6501f38943..66f9c0e552a8 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -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) { diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py index bcd6c64cd993..a4958ee17f2e 100644 --- a/lldb/test/lldbtest.py +++ b/lldb/test/lldbtest.py @@ -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) diff --git a/lldb/tools/lldb-gdbserver/exports b/lldb/tools/lldb-gdbserver/exports new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp index 01f64f9dc87c..b675dadceb76 100644 --- a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp +++ b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp @@ -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; diff --git a/lldb/tools/lldb-platform/exports b/lldb/tools/lldb-platform/exports new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lldb/tools/lldb-platform/lldb-platform.cpp b/lldb/tools/lldb-platform/lldb-platform.cpp index aa8b8830a757..bc9d62974771 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 @@ 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 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);