diff options
Diffstat (limited to 'lldb/source/Host/common')
20 files changed, 266 insertions, 271 deletions
diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp index 026a05da45b2..a5598c387b8c 100644 --- a/lldb/source/Host/common/Editline.cpp +++ b/lldb/source/Host/common/Editline.cpp @@ -6,11 +6,12 @@ // //===----------------------------------------------------------------------===// +#include <climits> #include <iomanip> -#include <limits.h> -#include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/Editline.h" + +#include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" #include "lldb/Utility/CompletionRequest.h" @@ -152,6 +153,11 @@ std::vector<EditLineStringType> SplitLines(const EditLineStringType &input) { result.push_back(input.substr(start, end - start)); start = end + 1; } + // Treat an empty history session as a single command of zero-length instead + // of returning an empty vector. + if (result.empty()) { + result.emplace_back(); + } return result; } @@ -641,8 +647,7 @@ unsigned char Editline::BreakLineCommand(int ch) { lines.AppendString(new_line_fragment); #endif - int indent_correction = m_fix_indentation_callback( - this, lines, 0, m_fix_indentation_callback_baton); + int indent_correction = m_fix_indentation_callback(this, lines, 0); new_line_fragment = FixIndentation(new_line_fragment, indent_correction); m_revert_cursor_index = GetIndentation(new_line_fragment); } @@ -677,8 +682,7 @@ unsigned char Editline::EndOrAddLineCommand(int ch) { info->cursor == info->lastchar) { if (m_is_input_complete_callback) { auto lines = GetInputAsStringList(); - if (!m_is_input_complete_callback(this, lines, - m_is_input_complete_callback_baton)) { + if (!m_is_input_complete_callback(this, lines)) { return BreakLineCommand(ch); } @@ -811,8 +815,7 @@ unsigned char Editline::NextLineCommand(int ch) { if (m_fix_indentation_callback) { StringList lines = GetInputAsStringList(); lines.AppendString(""); - indentation = m_fix_indentation_callback( - this, lines, 0, m_fix_indentation_callback_baton); + indentation = m_fix_indentation_callback(this, lines, 0); } m_input_lines.insert( m_input_lines.end(), @@ -857,8 +860,8 @@ unsigned char Editline::FixIndentationCommand(int ch) { // Save the edits and determine the correct indentation level SaveEditedLine(); StringList lines = GetInputAsStringList(m_current_line_index + 1); - int indent_correction = m_fix_indentation_callback( - this, lines, cursor_position, m_fix_indentation_callback_baton); + int indent_correction = + m_fix_indentation_callback(this, lines, cursor_position); // If it is already correct no special work is needed if (indent_correction == 0) @@ -977,7 +980,7 @@ DisplayCompletions(::EditLine *editline, FILE *output_file, } unsigned char Editline::TabCommand(int ch) { - if (m_completion_callback == nullptr) + if (!m_completion_callback) return CC_ERROR; const LineInfo *line_info = el_line(m_editline); @@ -988,7 +991,7 @@ unsigned char Editline::TabCommand(int ch) { CompletionResult result; CompletionRequest request(line, cursor_index, result); - m_completion_callback(request, m_completion_callback_baton); + m_completion_callback(request); llvm::ArrayRef<CompletionResult::Completion> results = result.GetResults(); @@ -1047,12 +1050,15 @@ unsigned char Editline::TabCommand(int ch) { } unsigned char Editline::ApplyAutosuggestCommand(int ch) { + if (!m_suggestion_callback) { + return CC_REDISPLAY; + } + const LineInfo *line_info = el_line(m_editline); llvm::StringRef line(line_info->buffer, line_info->lastchar - line_info->buffer); - if (llvm::Optional<std::string> to_add = - m_suggestion_callback(line, m_suggestion_callback_baton)) + if (llvm::Optional<std::string> to_add = m_suggestion_callback(line)) el_insertstr(m_editline, to_add->c_str()); return CC_REDISPLAY; @@ -1061,12 +1067,16 @@ unsigned char Editline::ApplyAutosuggestCommand(int ch) { unsigned char Editline::TypedCharacter(int ch) { std::string typed = std::string(1, ch); el_insertstr(m_editline, typed.c_str()); + + if (!m_suggestion_callback) { + return CC_REDISPLAY; + } + const LineInfo *line_info = el_line(m_editline); llvm::StringRef line(line_info->buffer, line_info->lastchar - line_info->buffer); - if (llvm::Optional<std::string> to_add = - m_suggestion_callback(line, m_suggestion_callback_baton)) { + if (llvm::Optional<std::string> to_add = m_suggestion_callback(line)) { std::string to_add_color = ANSI_FAINT + to_add.getValue() + ANSI_UNFAINT; fputs(typed.c_str(), m_output_file); fputs(to_add_color.c_str(), m_output_file); @@ -1092,6 +1102,21 @@ unsigned char Editline::TypedCharacter(int ch) { return CC_REDISPLAY; } +void Editline::AddFunctionToEditLine(const EditLineCharType *command, + const EditLineCharType *helptext, + EditlineCommandCallbackType callbackFn) { + el_wset(m_editline, EL_ADDFN, command, helptext, callbackFn); +} + +void Editline::SetEditLinePromptCallback( + EditlinePromptCallbackType callbackFn) { + el_set(m_editline, EL_PROMPT, callbackFn); +} + +void Editline::SetGetCharacterFunction(EditlineGetCharCallbackType callbackFn) { + el_wset(m_editline, EL_GETCFN, callbackFn); +} + void Editline::ConfigureEditor(bool multiline) { if (m_editline && m_multiline_enabled == multiline) return; @@ -1118,74 +1143,83 @@ void Editline::ConfigureEditor(bool multiline) { el_set(m_editline, EL_CLIENTDATA, this); el_set(m_editline, EL_SIGNAL, 0); el_set(m_editline, EL_EDITOR, "emacs"); - el_set(m_editline, EL_PROMPT, - (EditlinePromptCallbackType)([](EditLine *editline) { - return Editline::InstanceFor(editline)->Prompt(); - })); - el_wset(m_editline, EL_GETCFN, (EditlineGetCharCallbackType)([]( - EditLine *editline, EditLineGetCharType *c) { - return Editline::InstanceFor(editline)->GetCharacter(c); - })); + SetGetCharacterFunction([](EditLine *editline, EditLineGetCharType *c) { + return Editline::InstanceFor(editline)->GetCharacter(c); + }); + + SetEditLinePromptCallback([](EditLine *editline) { + return Editline::InstanceFor(editline)->Prompt(); + }); // Commands used for multiline support, registered whether or not they're // used - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-break-line"), - EditLineConstString("Insert a line break"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->BreakLineCommand(ch); - })); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-end-or-add-line"), - EditLineConstString("End editing or continue when incomplete"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->EndOrAddLineCommand(ch); - })); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-delete-next-char"), - EditLineConstString("Delete next character"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->DeleteNextCharCommand(ch); - })); - el_wset( - m_editline, EL_ADDFN, EditLineConstString("lldb-delete-previous-char"), + AddFunctionToEditLine( + EditLineConstString("lldb-break-line"), + EditLineConstString("Insert a line break"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->BreakLineCommand(ch); + }); + + AddFunctionToEditLine( + EditLineConstString("lldb-end-or-add-line"), + EditLineConstString("End editing or continue when incomplete"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->EndOrAddLineCommand(ch); + }); + AddFunctionToEditLine( + EditLineConstString("lldb-delete-next-char"), + EditLineConstString("Delete next character"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->DeleteNextCharCommand(ch); + }); + AddFunctionToEditLine( + EditLineConstString("lldb-delete-previous-char"), EditLineConstString("Delete previous character"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { + [](EditLine *editline, int ch) { return Editline::InstanceFor(editline)->DeletePreviousCharCommand(ch); - })); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-previous-line"), - EditLineConstString("Move to previous line"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->PreviousLineCommand(ch); - })); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-next-line"), - EditLineConstString("Move to next line"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->NextLineCommand(ch); - })); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-previous-history"), - EditLineConstString("Move to previous history"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->PreviousHistoryCommand(ch); - })); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-next-history"), - EditLineConstString("Move to next history"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->NextHistoryCommand(ch); - })); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-buffer-start"), - EditLineConstString("Move to start of buffer"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->BufferStartCommand(ch); - })); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-buffer-end"), - EditLineConstString("Move to end of buffer"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->BufferEndCommand(ch); - })); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-fix-indentation"), - EditLineConstString("Fix line indentation"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->FixIndentationCommand(ch); - })); + }); + AddFunctionToEditLine( + EditLineConstString("lldb-previous-line"), + EditLineConstString("Move to previous line"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->PreviousLineCommand(ch); + }); + AddFunctionToEditLine( + EditLineConstString("lldb-next-line"), + EditLineConstString("Move to next line"), [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->NextLineCommand(ch); + }); + AddFunctionToEditLine( + EditLineConstString("lldb-previous-history"), + EditLineConstString("Move to previous history"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->PreviousHistoryCommand(ch); + }); + AddFunctionToEditLine( + EditLineConstString("lldb-next-history"), + EditLineConstString("Move to next history"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->NextHistoryCommand(ch); + }); + AddFunctionToEditLine( + EditLineConstString("lldb-buffer-start"), + EditLineConstString("Move to start of buffer"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->BufferStartCommand(ch); + }); + AddFunctionToEditLine( + EditLineConstString("lldb-buffer-end"), + EditLineConstString("Move to end of buffer"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->BufferEndCommand(ch); + }); + AddFunctionToEditLine( + EditLineConstString("lldb-fix-indentation"), + EditLineConstString("Fix line indentation"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->FixIndentationCommand(ch); + }); // Register the complete callback under two names for compatibility with // older clients using custom .editrc files (largely because libedit has a @@ -1196,10 +1230,12 @@ void Editline::ConfigureEditor(bool multiline) { int ch) { return Editline::InstanceFor(editline)->TabCommand(ch); }; - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-complete"), - EditLineConstString("Invoke completion"), complete_callback); - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb_complete"), - EditLineConstString("Invoke completion"), complete_callback); + AddFunctionToEditLine(EditLineConstString("lldb-complete"), + EditLineConstString("Invoke completion"), + complete_callback); + AddFunctionToEditLine(EditLineConstString("lldb_complete"), + EditLineConstString("Invoke completion"), + complete_callback); // General bindings we don't mind being overridden if (!multiline) { @@ -1207,21 +1243,22 @@ void Editline::ConfigureEditor(bool multiline) { NULL); // Cycle through backwards search, entering string if (m_suggestion_callback) { - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-apply-complete"), - EditLineConstString("Adopt autocompletion"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->ApplyAutosuggestCommand( - ch); - })); + AddFunctionToEditLine( + EditLineConstString("lldb-apply-complete"), + EditLineConstString("Adopt autocompletion"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->ApplyAutosuggestCommand(ch); + }); el_set(m_editline, EL_BIND, "^f", "lldb-apply-complete", NULL); // Apply a part that is suggested automatically - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-typed-character"), - EditLineConstString("Typed character"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->TypedCharacter(ch); - })); + AddFunctionToEditLine( + EditLineConstString("lldb-typed-character"), + EditLineConstString("Typed character"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->TypedCharacter(ch); + }); char bind_key[2] = {0, 0}; llvm::StringRef ascii_chars = @@ -1256,11 +1293,12 @@ void Editline::ConfigureEditor(bool multiline) { el_source(m_editline, nullptr); // Register an internal binding that external developers shouldn't use - el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-revert-line"), - EditLineConstString("Revert line to saved state"), - (EditlineCommandCallbackType)([](EditLine *editline, int ch) { - return Editline::InstanceFor(editline)->RevertLineCommand(ch); - })); + AddFunctionToEditLine( + EditLineConstString("lldb-revert-line"), + EditLineConstString("Revert line to saved state"), + [](EditLine *editline, int ch) { + return Editline::InstanceFor(editline)->RevertLineCommand(ch); + }); // Register keys that perform auto-indent correction if (m_fix_indentation_callback && m_fix_indentation_callback_chars) { @@ -1447,33 +1485,6 @@ bool Editline::Cancel() { return result; } -void Editline::SetSuggestionCallback(SuggestionCallbackType callback, - void *baton) { - m_suggestion_callback = callback; - m_suggestion_callback_baton = baton; -} - -void Editline::SetAutoCompleteCallback(CompleteCallbackType callback, - void *baton) { - m_completion_callback = callback; - m_completion_callback_baton = baton; -} - -void Editline::SetIsInputCompleteCallback(IsInputCompleteCallbackType callback, - void *baton) { - m_is_input_complete_callback = callback; - m_is_input_complete_callback_baton = baton; -} - -bool Editline::SetFixIndentationCallback(FixIndentationCallbackType callback, - void *baton, - const char *indent_chars) { - m_fix_indentation_callback = callback; - m_fix_indentation_callback_baton = baton; - m_fix_indentation_callback_chars = indent_chars; - return false; -} - bool Editline::GetLine(std::string &line, bool &interrupted) { ConfigureEditor(false); m_input_lines = std::vector<EditLineStringType>(); diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp index a5b970907e64..e302e0a0de09 100644 --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -8,11 +8,11 @@ #include "lldb/Host/File.h" -#include <errno.h> +#include <cerrno> +#include <climits> +#include <cstdarg> +#include <cstdio> #include <fcntl.h> -#include <limits.h> -#include <stdarg.h> -#include <stdio.h> #ifdef _WIN32 #include "lldb/Host/windows/windows.h" diff --git a/lldb/source/Host/common/FileAction.cpp b/lldb/source/Host/common/FileAction.cpp index 8b4e7f4c2208..e399c7ec47cd 100644 --- a/lldb/source/Host/common/FileAction.cpp +++ b/lldb/source/Host/common/FileAction.cpp @@ -16,8 +16,7 @@ using namespace lldb_private; // FileAction member functions -FileAction::FileAction() - : m_action(eFileActionNone), m_fd(-1), m_arg(-1), m_file_spec() {} +FileAction::FileAction() : m_file_spec() {} void FileAction::Clear() { m_action = eFileActionNone; diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp index 9fa8854d950e..a2c3b3556a6c 100644 --- a/lldb/source/Host/common/FileSystem.cpp +++ b/lldb/source/Host/common/FileSystem.cpp @@ -19,11 +19,11 @@ #include "llvm/Support/Program.h" #include "llvm/Support/Threading.h" -#include <errno.h> +#include <cerrno> +#include <climits> +#include <cstdarg> +#include <cstdio> #include <fcntl.h> -#include <limits.h> -#include <stdarg.h> -#include <stdio.h> #ifdef _WIN32 #include "lldb/Host/windows/windows.h" @@ -307,7 +307,7 @@ FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size, std::unique_ptr<llvm::WritableMemoryBuffer> buffer; if (size == 0) { auto buffer_or_error = - llvm::WritableMemoryBuffer::getFile(*external_path, -1, is_volatile); + llvm::WritableMemoryBuffer::getFile(*external_path, is_volatile); if (!buffer_or_error) return nullptr; buffer = std::move(*buffer_or_error); @@ -478,20 +478,18 @@ ErrorOr<std::string> FileSystem::GetExternalPath(const llvm::Twine &path) { return path.str(); // If VFS mapped we know the underlying FS is a RedirectingFileSystem. - ErrorOr<vfs::RedirectingFileSystem::Entry *> E = + ErrorOr<vfs::RedirectingFileSystem::LookupResult> Result = static_cast<vfs::RedirectingFileSystem &>(*m_fs).lookupPath(path.str()); - if (!E) { - if (E.getError() == llvm::errc::no_such_file_or_directory) { + if (!Result) { + if (Result.getError() == llvm::errc::no_such_file_or_directory) { return path.str(); } - return E.getError(); + return Result.getError(); } - auto *F = dyn_cast<vfs::RedirectingFileSystem::RedirectingFileEntry>(*E); - if (!F) - return make_error_code(llvm::errc::not_supported); - - return F->getExternalContentsPath().str(); + if (Optional<StringRef> ExtRedirect = Result->getExternalRedirect()) + return std::string(*ExtRedirect); + return make_error_code(llvm::errc::not_supported); } ErrorOr<std::string> FileSystem::GetExternalPath(const FileSpec &file_spec) { diff --git a/lldb/source/Host/common/GetOptInc.cpp b/lldb/source/Host/common/GetOptInc.cpp index 62ce7428e8cc..c2044b687322 100644 --- a/lldb/source/Host/common/GetOptInc.cpp +++ b/lldb/source/Host/common/GetOptInc.cpp @@ -12,9 +12,9 @@ defined(REPLACE_GETOPT_LONG_ONLY) // getopt.cpp -#include <errno.h> -#include <stdlib.h> -#include <string.h> +#include <cerrno> +#include <cstdlib> +#include <cstring> #if defined(REPLACE_GETOPT) int opterr = 1; /* if error message should be printed */ diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index 99316660908e..d14ebe99fd15 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// // C includes -#include <errno.h> -#include <limits.h> -#include <stdlib.h> +#include <cerrno> +#include <climits> +#include <cstdlib> #include <sys/types.h> #ifndef _WIN32 #include <dlfcn.h> @@ -442,14 +442,12 @@ bool Host::FindProcessThreads(const lldb::pid_t pid, TidMap &tids_to_attach) { #endif struct ShellInfo { - ShellInfo() - : process_reaped(false), pid(LLDB_INVALID_PROCESS_ID), signo(-1), - status(-1) {} + ShellInfo() : process_reaped(false) {} lldb_private::Predicate<bool> process_reaped; - lldb::pid_t pid; - int signo; - int status; + lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; + int signo = -1; + int status = -1; }; static bool diff --git a/lldb/source/Host/common/HostInfoBase.cpp b/lldb/source/Host/common/HostInfoBase.cpp index 333137a7fd25..a6239a3208bc 100644 --- a/lldb/source/Host/common/HostInfoBase.cpp +++ b/lldb/source/Host/common/HostInfoBase.cpp @@ -31,12 +31,7 @@ using namespace lldb; using namespace lldb_private; namespace { -// The HostInfoBaseFields is a work around for windows not supporting static -// variables correctly in a thread safe way. Really each of the variables in -// HostInfoBaseFields should live in the functions in which they are used and -// each one should be static, but the work around is in place to avoid this -// restriction. Ick. - +/// Contains the state of the HostInfoBase plugin. struct HostInfoBaseFields { ~HostInfoBaseFields() { if (FileSystem::Instance().Exists(m_lldb_process_tmp_dir)) { @@ -71,13 +66,18 @@ struct HostInfoBaseFields { llvm::once_flag m_lldb_global_tmp_dir_once; FileSpec m_lldb_global_tmp_dir; }; +} // namespace -HostInfoBaseFields *g_fields = nullptr; -} +static HostInfoBaseFields *g_fields = nullptr; +static HostInfoBase::SharedLibraryDirectoryHelper *g_shlib_dir_helper = nullptr; -void HostInfoBase::Initialize() { g_fields = new HostInfoBaseFields(); } +void HostInfoBase::Initialize(SharedLibraryDirectoryHelper *helper) { + g_shlib_dir_helper = helper; + g_fields = new HostInfoBaseFields(); +} void HostInfoBase::Terminate() { + g_shlib_dir_helper = nullptr; delete g_fields; g_fields = nullptr; } @@ -249,9 +249,8 @@ bool HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) { reinterpret_cast<void *>( HostInfoBase::ComputeSharedLibraryDirectory))); - // This is necessary because when running the testsuite the shlib might be a - // symbolic link inside the Python resource dir. - FileSystem::Instance().ResolveSymbolicLink(lldb_file_spec, lldb_file_spec); + if (g_shlib_dir_helper) + g_shlib_dir_helper(lldb_file_spec); // Remove the filename so that this FileSpec only represents the directory. file_spec.GetDirectory() = lldb_file_spec.GetDirectory(); diff --git a/lldb/source/Host/common/HostNativeThreadBase.cpp b/lldb/source/Host/common/HostNativeThreadBase.cpp index a79431f61d88..b15160b143ca 100644 --- a/lldb/source/Host/common/HostNativeThreadBase.cpp +++ b/lldb/source/Host/common/HostNativeThreadBase.cpp @@ -17,9 +17,6 @@ using namespace lldb; using namespace lldb_private; -HostNativeThreadBase::HostNativeThreadBase() - : m_thread(LLDB_INVALID_HOST_THREAD), m_result(0) {} - HostNativeThreadBase::HostNativeThreadBase(thread_t thread) : m_thread(thread), m_result(0) {} diff --git a/lldb/source/Host/common/HostProcess.cpp b/lldb/source/Host/common/HostProcess.cpp index 256a73bb6716..06dd192013ba 100644 --- a/lldb/source/Host/common/HostProcess.cpp +++ b/lldb/source/Host/common/HostProcess.cpp @@ -18,7 +18,7 @@ HostProcess::HostProcess() : m_native_process(new HostNativeProcess) {} HostProcess::HostProcess(lldb::process_t process) : m_native_process(new HostNativeProcess(process)) {} -HostProcess::~HostProcess() {} +HostProcess::~HostProcess() = default; Status HostProcess::Terminate() { return m_native_process->Terminate(); } diff --git a/lldb/source/Host/common/MainLoop.cpp b/lldb/source/Host/common/MainLoop.cpp index 02cabbc93550..d36587ce2346 100644 --- a/lldb/source/Host/common/MainLoop.cpp +++ b/lldb/source/Host/common/MainLoop.cpp @@ -16,7 +16,7 @@ #include <cassert> #include <cerrno> #include <csignal> -#include <time.h> +#include <ctime> #include <vector> // Multiplexing is implemented using kqueue on systems that support it (BSD @@ -302,13 +302,15 @@ MainLoop::RegisterSignal(int signo, const Callback &callback, Status &error) { error.SetErrorString("Signal polling is not supported on this platform."); return nullptr; #else - if (m_signals.find(signo) != m_signals.end()) { - error.SetErrorStringWithFormat("Signal %d already monitored.", signo); - return nullptr; + auto signal_it = m_signals.find(signo); + if (signal_it != m_signals.end()) { + auto callback_it = signal_it->second.callbacks.insert( + signal_it->second.callbacks.end(), callback); + return SignalHandleUP(new SignalHandle(*this, signo, callback_it)); } SignalInfo info; - info.callback = callback; + info.callbacks.push_back(callback); struct sigaction new_action; new_action.sa_sigaction = &SignalHandler; new_action.sa_flags = SA_SIGINFO; @@ -338,9 +340,10 @@ MainLoop::RegisterSignal(int signo, const Callback &callback, Status &error) { &new_action.sa_mask, &old_set); assert(ret == 0 && "pthread_sigmask failed"); info.was_blocked = sigismember(&old_set, signo); - m_signals.insert({signo, info}); + auto insert_ret = m_signals.insert({signo, info}); - return SignalHandleUP(new SignalHandle(*this, signo)); + return SignalHandleUP(new SignalHandle( + *this, signo, insert_ret.first->second.callbacks.begin())); #endif } @@ -350,13 +353,19 @@ void MainLoop::UnregisterReadObject(IOObject::WaitableHandle handle) { assert(erased); } -void MainLoop::UnregisterSignal(int signo) { +void MainLoop::UnregisterSignal(int signo, + std::list<Callback>::iterator callback_it) { #if SIGNAL_POLLING_UNSUPPORTED Status("Signal polling is not supported on this platform."); #else auto it = m_signals.find(signo); assert(it != m_signals.end()); + it->second.callbacks.erase(callback_it); + // Do not remove the signal handler unless all callbacks have been erased. + if (!it->second.callbacks.empty()) + return; + sigaction(signo, &it->second.old_action, nullptr); sigset_t set; @@ -398,8 +407,14 @@ Status MainLoop::Run() { void MainLoop::ProcessSignal(int signo) { auto it = m_signals.find(signo); - if (it != m_signals.end()) - it->second.callback(*this); // Do the work + if (it != m_signals.end()) { + // The callback may actually register/unregister signal handlers, + // so we need to create a copy first. + llvm::SmallVector<Callback, 4> callbacks_to_run{ + it->second.callbacks.begin(), it->second.callbacks.end()}; + for (auto &x : callbacks_to_run) + x(*this); // Do the work + } } void MainLoop::ProcessReadObject(IOObject::WaitableHandle handle) { diff --git a/lldb/source/Host/common/NativeProcessProtocol.cpp b/lldb/source/Host/common/NativeProcessProtocol.cpp index 493e14cb904b..ea80a05430f7 100644 --- a/lldb/source/Host/common/NativeProcessProtocol.cpp +++ b/lldb/source/Host/common/NativeProcessProtocol.cpp @@ -25,10 +25,8 @@ using namespace lldb_private; NativeProcessProtocol::NativeProcessProtocol(lldb::pid_t pid, int terminal_fd, NativeDelegate &delegate) - : m_pid(pid), m_terminal_fd(terminal_fd) { - bool registered = RegisterNativeDelegate(delegate); - assert(registered); - (void)registered; + : m_pid(pid), m_delegate(delegate), m_terminal_fd(terminal_fd) { + delegate.InitializeDelegate(this); } lldb_private::Status NativeProcessProtocol::Interrupt() { @@ -54,6 +52,19 @@ NativeProcessProtocol::GetMemoryRegionInfo(lldb::addr_t load_addr, return Status("not implemented"); } +lldb_private::Status +NativeProcessProtocol::ReadMemoryTags(int32_t type, lldb::addr_t addr, + size_t len, std::vector<uint8_t> &tags) { + return Status("not implemented"); +} + +lldb_private::Status +NativeProcessProtocol::WriteMemoryTags(int32_t type, lldb::addr_t addr, + size_t len, + const std::vector<uint8_t> &tags) { + return Status("not implemented"); +} + llvm::Optional<WaitStatus> NativeProcessProtocol::GetExitStatus() { if (m_state == lldb::eStateExited) return m_exit_status; @@ -295,64 +306,21 @@ Status NativeProcessProtocol::RemoveHardwareBreakpoint(lldb::addr_t addr) { return error; } -bool NativeProcessProtocol::RegisterNativeDelegate( - NativeDelegate &native_delegate) { - std::lock_guard<std::recursive_mutex> guard(m_delegates_mutex); - if (llvm::is_contained(m_delegates, &native_delegate)) - return false; - - m_delegates.push_back(&native_delegate); - native_delegate.InitializeDelegate(this); - return true; -} - -bool NativeProcessProtocol::UnregisterNativeDelegate( - NativeDelegate &native_delegate) { - std::lock_guard<std::recursive_mutex> guard(m_delegates_mutex); - - const auto initial_size = m_delegates.size(); - m_delegates.erase( - remove(m_delegates.begin(), m_delegates.end(), &native_delegate), - m_delegates.end()); - - // We removed the delegate if the count of delegates shrank after removing - // all copies of the given native_delegate from the vector. - return m_delegates.size() < initial_size; -} - void NativeProcessProtocol::SynchronouslyNotifyProcessStateChanged( lldb::StateType state) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); - std::lock_guard<std::recursive_mutex> guard(m_delegates_mutex); - for (auto native_delegate : m_delegates) - native_delegate->ProcessStateChanged(this, state); + m_delegate.ProcessStateChanged(this, state); - if (log) { - if (!m_delegates.empty()) { - LLDB_LOGF(log, - "NativeProcessProtocol::%s: sent state notification [%s] " - "from process %" PRIu64, - __FUNCTION__, lldb_private::StateAsCString(state), GetID()); - } else { - LLDB_LOGF(log, - "NativeProcessProtocol::%s: would send state notification " - "[%s] from process %" PRIu64 ", but no delegates", - __FUNCTION__, lldb_private::StateAsCString(state), GetID()); - } - } + LLDB_LOG(log, "sent state notification [{0}] from process {1}", state, + GetID()); } void NativeProcessProtocol::NotifyDidExec() { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); - LLDB_LOGF(log, "NativeProcessProtocol::%s - preparing to call delegates", - __FUNCTION__); + LLDB_LOG(log, "process {0} exec()ed", GetID()); - { - std::lock_guard<std::recursive_mutex> guard(m_delegates_mutex); - for (auto native_delegate : m_delegates) - native_delegate->DidExec(this); - } + m_delegate.DidExec(this); } Status NativeProcessProtocol::SetSoftwareBreakpoint(lldb::addr_t addr, @@ -522,7 +490,8 @@ NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) { static const uint8_t g_mips64_opcode[] = {0x00, 0x00, 0x00, 0x0d}; static const uint8_t g_mips64el_opcode[] = {0x0d, 0x00, 0x00, 0x00}; static const uint8_t g_s390x_opcode[] = {0x00, 0x01}; - static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap + static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08}; // trap + static const uint8_t g_ppcle_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap switch (GetArchitecture().GetMachine()) { case llvm::Triple::aarch64: @@ -544,8 +513,12 @@ NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) { case llvm::Triple::systemz: return llvm::makeArrayRef(g_s390x_opcode); + case llvm::Triple::ppc: + case llvm::Triple::ppc64: + return llvm::makeArrayRef(g_ppc_opcode); + case llvm::Triple::ppc64le: - return llvm::makeArrayRef(g_ppc64le_opcode); + return llvm::makeArrayRef(g_ppcle_opcode); default: return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -568,6 +541,8 @@ size_t NativeProcessProtocol::GetSoftwareBreakpointPCOffset() { case llvm::Triple::mips64el: case llvm::Triple::mips: case llvm::Triple::mipsel: + case llvm::Triple::ppc: + case llvm::Triple::ppc64: case llvm::Triple::ppc64le: // On these architectures the PC doesn't get updated for breakpoint hits. return 0; diff --git a/lldb/source/Host/common/NativeRegisterContext.cpp b/lldb/source/Host/common/NativeRegisterContext.cpp index 9bb877fff878..04d10aba4e63 100644 --- a/lldb/source/Host/common/NativeRegisterContext.cpp +++ b/lldb/source/Host/common/NativeRegisterContext.cpp @@ -22,7 +22,7 @@ NativeRegisterContext::NativeRegisterContext(NativeThreadProtocol &thread) : m_thread(thread) {} // Destructor -NativeRegisterContext::~NativeRegisterContext() {} +NativeRegisterContext::~NativeRegisterContext() = default; // FIXME revisit invalidation, process stop ids, etc. Right now we don't // support caching in NativeRegisterContext. We can do this later by utilizing @@ -60,8 +60,8 @@ NativeRegisterContext::GetRegisterInfoByName(llvm::StringRef reg_name, for (uint32_t reg = start_idx; reg < num_registers; ++reg) { const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg); - if (reg_name.equals_lower(reg_info->name) || - reg_name.equals_lower(reg_info->alt_name)) + if (reg_name.equals_insensitive(reg_info->name) || + reg_name.equals_insensitive(reg_info->alt_name)) return reg_info; } return nullptr; diff --git a/lldb/source/Host/common/ProcessLaunchInfo.cpp b/lldb/source/Host/common/ProcessLaunchInfo.cpp index 1b4b2c6c3ac2..8d281b80e8f0 100644 --- a/lldb/source/Host/common/ProcessLaunchInfo.cpp +++ b/lldb/source/Host/common/ProcessLaunchInfo.cpp @@ -20,7 +20,7 @@ #include "llvm/Support/FileSystem.h" #if !defined(_WIN32) -#include <limits.h> +#include <climits> #endif using namespace lldb; @@ -30,9 +30,9 @@ using namespace lldb_private; ProcessLaunchInfo::ProcessLaunchInfo() : ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(0), - m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0), - m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr), - m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() {} + m_file_actions(), m_pty(new PseudoTerminal), m_monitor_callback(nullptr), + m_listener_sp(), m_hijack_listener_sp(), m_scripted_process_class_name(), + m_scripted_process_dictionary_sp() {} ProcessLaunchInfo::ProcessLaunchInfo(const FileSpec &stdin_file_spec, const FileSpec &stdout_file_spec, @@ -42,7 +42,8 @@ ProcessLaunchInfo::ProcessLaunchInfo(const FileSpec &stdin_file_spec, : ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(launch_flags), m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0), m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr), - m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() { + m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp(), + m_scripted_process_class_name(), m_scripted_process_dictionary_sp() { if (stdin_file_spec) { FileAction file_action; const bool read = true; @@ -171,6 +172,8 @@ void ProcessLaunchInfo::Clear() { m_resume_count = 0; m_listener_sp.reset(); m_hijack_listener_sp.reset(); + m_scripted_process_class_name.clear(); + m_scripted_process_dictionary_sp.reset(); } void ProcessLaunchInfo::SetMonitorProcessCallback( diff --git a/lldb/source/Host/common/ProcessRunLock.cpp b/lldb/source/Host/common/ProcessRunLock.cpp index 3b6f033d33ab..aee15779d919 100644 --- a/lldb/source/Host/common/ProcessRunLock.cpp +++ b/lldb/source/Host/common/ProcessRunLock.cpp @@ -11,7 +11,7 @@ namespace lldb_private { -ProcessRunLock::ProcessRunLock() : m_running(false) { +ProcessRunLock::ProcessRunLock() { int err = ::pthread_rwlock_init(&m_rwlock, nullptr); (void)err; } diff --git a/lldb/source/Host/common/PseudoTerminal.cpp b/lldb/source/Host/common/PseudoTerminal.cpp index de76e8ab4f68..dce4c5185c7b 100644 --- a/lldb/source/Host/common/PseudoTerminal.cpp +++ b/lldb/source/Host/common/PseudoTerminal.cpp @@ -11,11 +11,11 @@ #include "llvm/Support/Errc.h" #include "llvm/Support/Errno.h" #include <cassert> -#include <limits.h> +#include <climits> +#include <cstdio> +#include <cstdlib> +#include <cstring> #include <mutex> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> #if defined(TIOCSCTTY) #include <sys/ioctl.h> #endif @@ -29,8 +29,7 @@ int posix_openpt(int flags); using namespace lldb_private; // PseudoTerminal constructor -PseudoTerminal::PseudoTerminal() - : m_primary_fd(invalid_fd), m_secondary_fd(invalid_fd) {} +PseudoTerminal::PseudoTerminal() = default; // Destructor // diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp index 4bcf34a6b456..d1c327dcb790 100644 --- a/lldb/source/Host/common/Socket.cpp +++ b/lldb/source/Host/common/Socket.cpp @@ -41,9 +41,9 @@ #ifdef __ANDROID__ #include <arpa/inet.h> #include <asm-generic/errno-base.h> -#include <errno.h> -#include <linux/tcp.h> +#include <cerrno> #include <fcntl.h> +#include <linux/tcp.h> #include <sys/syscall.h> #include <unistd.h> #endif // __ANDROID__ diff --git a/lldb/source/Host/common/SocketAddress.cpp b/lldb/source/Host/common/SocketAddress.cpp index e98944d6cdc8..3f47d32d4652 100644 --- a/lldb/source/Host/common/SocketAddress.cpp +++ b/lldb/source/Host/common/SocketAddress.cpp @@ -17,15 +17,15 @@ #endif #include "lldb/Host/SocketAddress.h" -#include <stddef.h> -#include <stdio.h> +#include <cstddef> +#include <cstdio> #if !defined(_WIN32) #include <arpa/inet.h> #endif -#include <assert.h> -#include <string.h> +#include <cassert> +#include <cstring> #include "lldb/Host/PosixApi.h" @@ -93,7 +93,7 @@ SocketAddress::SocketAddress(const struct addrinfo *addr_info) { } // Destructor -SocketAddress::~SocketAddress() {} +SocketAddress::~SocketAddress() = default; void SocketAddress::Clear() { memset(&m_socket_addr, 0, sizeof(m_socket_addr)); diff --git a/lldb/source/Host/common/StringConvert.cpp b/lldb/source/Host/common/StringConvert.cpp index e5f05e628c7c..b4eb92755367 100644 --- a/lldb/source/Host/common/StringConvert.cpp +++ b/lldb/source/Host/common/StringConvert.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include <stdlib.h> +#include <cstdlib> #include "lldb/Host/StringConvert.h" diff --git a/lldb/source/Host/common/Terminal.cpp b/lldb/source/Host/common/Terminal.cpp index 9990dbf74356..2301abe9afb1 100644 --- a/lldb/source/Host/common/Terminal.cpp +++ b/lldb/source/Host/common/Terminal.cpp @@ -12,8 +12,8 @@ #include "lldb/Host/PosixApi.h" #include "llvm/ADT/STLExtras.h" +#include <csignal> #include <fcntl.h> -#include <signal.h> #if LLDB_ENABLE_TERMIOS #include <termios.h> @@ -83,15 +83,16 @@ bool Terminal::SetCanonical(bool enabled) { // Default constructor TerminalState::TerminalState() - : m_tty(), m_tflags(-1), + : m_tty() #if LLDB_ENABLE_TERMIOS - m_termios_up(), + , + m_termios_up() #endif - m_process_group(-1) { +{ } // Destructor -TerminalState::~TerminalState() {} +TerminalState::~TerminalState() = default; void TerminalState::Clear() { m_tty.Clear(); @@ -189,10 +190,10 @@ bool TerminalState::ProcessGroupIsValid() const { } // Constructor -TerminalStateSwitcher::TerminalStateSwitcher() : m_currentState(UINT32_MAX) {} +TerminalStateSwitcher::TerminalStateSwitcher() = default; // Destructor -TerminalStateSwitcher::~TerminalStateSwitcher() {} +TerminalStateSwitcher::~TerminalStateSwitcher() = default; // Returns the number of states that this switcher contains uint32_t TerminalStateSwitcher::GetNumberOfStates() const { diff --git a/lldb/source/Host/common/XML.cpp b/lldb/source/Host/common/XML.cpp index 456c879b0148..c3225d3f4433 100644 --- a/lldb/source/Host/common/XML.cpp +++ b/lldb/source/Host/common/XML.cpp @@ -17,7 +17,7 @@ using namespace lldb_private; #pragma mark-- XMLDocument -XMLDocument::XMLDocument() : m_document(nullptr) {} +XMLDocument::XMLDocument() = default; XMLDocument::~XMLDocument() { Clear(); } @@ -91,11 +91,11 @@ bool XMLDocument::XMLEnabled() { #pragma mark-- XMLNode -XMLNode::XMLNode() : m_node(nullptr) {} +XMLNode::XMLNode() = default; XMLNode::XMLNode(XMLNodeImpl node) : m_node(node) {} -XMLNode::~XMLNode() {} +XMLNode::~XMLNode() = default; void XMLNode::Clear() { m_node = nullptr; } @@ -398,7 +398,7 @@ ApplePropertyList::ApplePropertyList(const char *path) ParseFile(path); } -ApplePropertyList::~ApplePropertyList() {} +ApplePropertyList::~ApplePropertyList() = default; llvm::StringRef ApplePropertyList::GetErrors() const { return m_xml_doc.GetErrors(); |