From bbd71927d239e63cdac7fd6197e2e927619a7097 Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Sat, 16 Jul 2022 14:59:12 -0700 Subject: [PATCH] WIP --- src/SOS/lldbplugin/services.cpp | 39 +++++++++++++++++++++++++++++++ src/SOS/lldbplugin/services.h | 2 ++ src/SOS/lldbplugin/soscommand.cpp | 19 ++------------- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/SOS/lldbplugin/services.cpp b/src/SOS/lldbplugin/services.cpp index c278558289..95cf915917 100644 --- a/src/SOS/lldbplugin/services.cpp +++ b/src/SOS/lldbplugin/services.cpp @@ -2784,6 +2784,45 @@ LLDBServices::AddCommand( return command; } +bool +LLDBServices::ExecuteCommand( + const char* commandName, + char** arguments, + lldb::SBCommandReturnObject &result) +{ + std::string commandLine; + commandLine.append(commandName); + commandLine.append(" "); + for (const char* arg = *arguments; arg != nullptr; arg = *(++arguments)) + { + commandLine.append(arg); + commandLine.append(" "); + } + if (m_commands.find(commandName) == m_commands.end()) + { + lldb::ReturnStatus status = m_interpreter.HandleCommand(commandLine.c_str(), result); + result.SetStatus(status); + return true; + } + IHostServices* hostservices = GetHostServices(); + if (hostservices != nullptr) + { + g_services->FlushCheck(); + HRESULT hr = hostservices->DispatchCommand(commandLine.c_str()); + if (hr != S_OK) + { + result.SetStatus(lldb::eReturnStatusFailed); + } + else + { + result.SetStatus(lldb::eReturnStatusSuccessFinishResult); + } + return true; + } + // This means command not found + return false; +} + HRESULT LLDBServices::InternalOutputVaList( ULONG mask, diff --git a/src/SOS/lldbplugin/services.h b/src/SOS/lldbplugin/services.h index 558f30d856..9ad4348eb1 100644 --- a/src/SOS/lldbplugin/services.h +++ b/src/SOS/lldbplugin/services.h @@ -414,5 +414,7 @@ class LLDBServices : public ILLDBServices, public ILLDBServices2, public IDebugg lldb::SBCommand AddCommand(const char *name, lldb::SBCommandPluginInterface *impl, const char *help); + bool ExecuteCommand( const char* commandName, char** arguments, lldb::SBCommandReturnObject &result); + HRESULT InternalOutputVaList(ULONG mask, PCSTR format, va_list args); }; diff --git a/src/SOS/lldbplugin/soscommand.cpp b/src/SOS/lldbplugin/soscommand.cpp index c0a2474092..8966edac04 100644 --- a/src/SOS/lldbplugin/soscommand.cpp +++ b/src/SOS/lldbplugin/soscommand.cpp @@ -48,24 +48,9 @@ class sosCommand : public lldb::SBCommandPluginInterface else { sosCommand = *arguments++; - - IHostServices* hostservices = GetHostServices(); - if (hostservices != nullptr) + if (g_services->ExecuteCommand(sosCommand, arguments, result)) { - std::string commandLine; - commandLine.append(sosCommand); - commandLine.append(" "); - for (const char* arg = *arguments; arg != nullptr; arg = *(++arguments)) - { - commandLine.append(arg); - commandLine.append(" "); - } - g_services->FlushCheck(); - HRESULT hr = hostservices->DispatchCommand(commandLine.c_str()); - if (hr == S_OK) - { - return result.Succeeded(); - } + return result.Succeeded(); } } }