diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:04:10 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:04:10 +0000 |
commit | 74a628f776edb588bff8f8f5cc16eac947c9d631 (patch) | |
tree | dc32e010ac4902621e5a279bfeb48628f7f0e166 /source/Core/Debugger.cpp | |
parent | afed7be32164a598f8172282c249af7266c48b46 (diff) |
Notes
Diffstat (limited to 'source/Core/Debugger.cpp')
-rw-r--r-- | source/Core/Debugger.cpp | 165 |
1 files changed, 95 insertions, 70 deletions
diff --git a/source/Core/Debugger.cpp b/source/Core/Debugger.cpp index 8f888a518d5b..751ceed13149 100644 --- a/source/Core/Debugger.cpp +++ b/source/Core/Debugger.cpp @@ -9,57 +9,70 @@ #include "lldb/Core/Debugger.h" -// C Includes -// C++ Includes -#include <map> -#include <mutex> - -// Other libraries and framework includes -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/DynamicLibrary.h" - -// Project includes +#include "lldb/Breakpoint/Breakpoint.h" // for Breakpoint, Brea... +#include "lldb/Core/Event.h" // for Event, EventData... #include "lldb/Core/FormatEntity.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/PluginInterface.h" +#include "lldb/Core/Listener.h" // for Listener +#include "lldb/Core/Mangled.h" // for Mangled #include "lldb/Core/PluginManager.h" -#include "lldb/Core/RegisterValue.h" #include "lldb/Core/State.h" #include "lldb/Core/StreamAsynchronousIO.h" -#include "lldb/Core/StreamCallback.h" #include "lldb/Core/StreamFile.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Core/StructuredData.h" -#include "lldb/Core/Timer.h" -#include "lldb/Core/ValueObject.h" -#include "lldb/Core/ValueObjectVariable.h" #include "lldb/DataFormatters/DataVisualization.h" -#include "lldb/DataFormatters/FormatManager.h" -#include "lldb/DataFormatters/TypeSummary.h" #include "lldb/Expression/REPL.h" -#include "lldb/Host/ConnectionFileDescriptor.h" +#include "lldb/Host/File.h" // for File, File::kInv... #include "lldb/Host/HostInfo.h" #include "lldb/Host/Terminal.h" #include "lldb/Host/ThreadLauncher.h" #include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Interpreter/OptionValue.h" // for OptionValue, Opt... #include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Interpreter/OptionValueSInt64.h" #include "lldb/Interpreter/OptionValueString.h" -#include "lldb/Symbol/CompileUnit.h" +#include "lldb/Interpreter/Property.h" // for PropertyDefinition +#include "lldb/Interpreter/ScriptInterpreter.h" // for ScriptInterpreter #include "lldb/Symbol/Function.h" #include "lldb/Symbol/Symbol.h" -#include "lldb/Symbol/VariableList.h" +#include "lldb/Symbol/SymbolContext.h" // for SymbolContext #include "lldb/Target/Language.h" #include "lldb/Target/Process.h" -#include "lldb/Target/RegisterContext.h" -#include "lldb/Target/SectionLoadList.h" -#include "lldb/Target/StopInfo.h" #include "lldb/Target/StructuredDataPlugin.h" #include "lldb/Target/Target.h" #include "lldb/Target/TargetList.h" #include "lldb/Target/Thread.h" +#include "lldb/Target/ThreadList.h" // for ThreadList #include "lldb/Utility/AnsiTerminal.h" -#include "lldb/lldb-private.h" +#include "lldb/Utility/Log.h" // for LLDB_LOG_OPTION_... +#include "lldb/Utility/Stream.h" // for Stream +#include "lldb/Utility/StreamCallback.h" +#include "lldb/Utility/StreamString.h" + +#if defined(LLVM_ON_WIN32) +#include "lldb/Host/windows/PosixApi.h" // for PATH_MAX +#endif + +#include "llvm/ADT/None.h" // for None +#include "llvm/ADT/STLExtras.h" // for make_unique +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator.h" // for iterator_facade_... +#include "llvm/Support/DynamicLibrary.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Threading.h" +#include "llvm/Support/raw_ostream.h" // for raw_fd_ostream + +#include <list> // for list +#include <memory> // for make_shared +#include <mutex> +#include <set> // for set +#include <stdio.h> // for size_t, NULL +#include <stdlib.h> // for getenv +#include <string.h> // for strcmp +#include <string> // for string +#include <system_error> // for error_code + +namespace lldb_private { +class Address; +} using namespace lldb; using namespace lldb_private; @@ -125,7 +138,7 @@ OptionEnumValueElement g_language_enumerators[] = { "\\n" #define DEFAULT_FRAME_FORMAT \ - "frame #${frame.index}:{ ${frame.no-debug}${frame.pc}}" MODULE_WITH_FUNC FILE_AND_LINE \ + "frame #${frame.index}: ${frame.pc}" MODULE_WITH_FUNC FILE_AND_LINE \ IS_OPTIMIZED "\\n" // Three parts to this disassembly format specification: @@ -296,9 +309,9 @@ Error Debugger::SetPropertyValue(const ExecutionContext *exe_ctx, if (str.length()) new_prompt = str; GetCommandInterpreter().UpdatePrompt(new_prompt); - EventSP prompt_change_event_sp( - new Event(CommandInterpreter::eBroadcastBitResetPrompt, - new EventDataBytes(new_prompt))); + auto bytes = llvm::make_unique<EventDataBytes>(new_prompt); + auto prompt_change_event_sp = std::make_shared<Event>( + CommandInterpreter::eBroadcastBitResetPrompt, bytes.release()); GetCommandInterpreter().BroadcastEvent(prompt_change_event_sp); } else if (property_path == g_properties[ePropertyUseColor].name) { // use-color changed. Ping the prompt so it can reset the ansi terminal @@ -555,7 +568,7 @@ bool Debugger::LoadPlugin(const FileSpec &spec, Error &error) { } static FileSpec::EnumerateDirectoryResult -LoadPluginCallback(void *baton, FileSpec::FileType file_type, +LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { Error error; @@ -567,13 +580,13 @@ LoadPluginCallback(void *baton, FileSpec::FileType file_type, Debugger *debugger = (Debugger *)baton; + namespace fs = llvm::sys::fs; // If we have a regular file, a symbolic link or unknown file type, try // and process the file. We must handle unknown as sometimes the directory // enumeration might be enumerating a file system that doesn't have correct // file type information. - if (file_type == FileSpec::eFileTypeRegular || - file_type == FileSpec::eFileTypeSymbolicLink || - file_type == FileSpec::eFileTypeUnknown) { + if (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file || + ft == fs::file_type::type_unknown) { FileSpec plugin_file_spec(file_spec); plugin_file_spec.ResolvePath(); @@ -586,9 +599,9 @@ LoadPluginCallback(void *baton, FileSpec::FileType file_type, debugger->LoadPlugin(plugin_file_spec, plugin_load_error); return FileSpec::eEnumerateDirectoryResultNext; - } else if (file_type == FileSpec::eFileTypeUnknown || - file_type == FileSpec::eFileTypeDirectory || - file_type == FileSpec::eFileTypeSymbolicLink) { + } else if (ft == fs::file_type::directory_file || + ft == fs::file_type::symlink_file || + ft == fs::file_type::type_unknown) { // Try and recurse into anything that a directory or symbolic link. // We must also do this for unknown as sometimes the directory enumeration // might be enumerating a file system that doesn't have correct file type @@ -697,16 +710,16 @@ TargetSP Debugger::FindTargetWithProcess(Process *process) { Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) : UserID(g_unique_id++), - Properties(OptionValuePropertiesSP(new OptionValueProperties())), - m_input_file_sp(new StreamFile(stdin, false)), - m_output_file_sp(new StreamFile(stdout, false)), - m_error_file_sp(new StreamFile(stderr, false)), + Properties(std::make_shared<OptionValueProperties>()), + m_input_file_sp(std::make_shared<StreamFile>(stdin, false)), + m_output_file_sp(std::make_shared<StreamFile>(stdout, false)), + m_error_file_sp(std::make_shared<StreamFile>(stderr, false)), m_broadcaster_manager_sp(BroadcasterManager::MakeBroadcasterManager()), m_terminal_state(), m_target_list(*this), m_platform_list(), m_listener_sp(Listener::MakeListener("lldb.Debugger")), m_source_manager_ap(), m_source_file_cache(), - m_command_interpreter_ap( - new CommandInterpreter(*this, eScriptLanguageDefault, false)), + m_command_interpreter_ap(llvm::make_unique<CommandInterpreter>( + *this, eScriptLanguageDefault, false)), m_input_reader_stack(), m_instance_name(), m_loaded_plugins(), m_event_handler_thread(), m_io_handler_thread(), m_sync_broadcaster(nullptr, "lldb.debugger.sync"), @@ -715,7 +728,8 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID()); m_instance_name.SetCString(instance_cstr); if (log_callback) - m_log_callback_stream_sp.reset(new StreamCallback(log_callback, baton)); + m_log_callback_stream_sp = + std::make_shared<StreamCallback>(log_callback, baton); m_command_interpreter_ap->Initialize(); // Always add our default platform to the platform list PlatformSP default_platform_sp(Platform::GetHostPlatform()); @@ -762,7 +776,7 @@ void Debugger::Clear() { // static void Debugger::Destroy(lldb::DebuggerSP &debugger_sp); // static void Debugger::Terminate(); //---------------------------------------------------------------------- - std::call_once(m_clear_once, [this]() { + llvm::call_once(m_clear_once, [this]() { ClearIOHandlers(); StopIOHandlerThread(); StopEventHandlerThread(); @@ -811,7 +825,7 @@ void Debugger::SetInputFileHandle(FILE *fh, bool tranfer_ownership) { if (m_input_file_sp) m_input_file_sp->GetFile().SetStream(fh, tranfer_ownership); else - m_input_file_sp.reset(new StreamFile(fh, tranfer_ownership)); + m_input_file_sp = std::make_shared<StreamFile>(fh, tranfer_ownership); File &in_file = m_input_file_sp->GetFile(); if (!in_file.IsValid()) @@ -826,7 +840,7 @@ void Debugger::SetOutputFileHandle(FILE *fh, bool tranfer_ownership) { if (m_output_file_sp) m_output_file_sp->GetFile().SetStream(fh, tranfer_ownership); else - m_output_file_sp.reset(new StreamFile(fh, tranfer_ownership)); + m_output_file_sp = std::make_shared<StreamFile>(fh, tranfer_ownership); File &out_file = m_output_file_sp->GetFile(); if (!out_file.IsValid()) @@ -845,7 +859,7 @@ void Debugger::SetErrorFileHandle(FILE *fh, bool tranfer_ownership) { if (m_error_file_sp) m_error_file_sp->GetFile().SetStream(fh, tranfer_ownership); else - m_error_file_sp.reset(new StreamFile(fh, tranfer_ownership)); + m_error_file_sp = std::make_shared<StreamFile>(fh, tranfer_ownership); File &err_file = m_error_file_sp->GetFile(); if (!err_file.IsValid()) @@ -996,7 +1010,7 @@ void Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in, // If there is nothing, use stdin if (!in) - in = StreamFileSP(new StreamFile(stdin, false)); + in = std::make_shared<StreamFile>(stdin, false); } // If no STDOUT has been set, then set it appropriately if (!out) { @@ -1007,7 +1021,7 @@ void Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in, // If there is nothing, use stdout if (!out) - out = StreamFileSP(new StreamFile(stdout, false)); + out = std::make_shared<StreamFile>(stdout, false); } // If no STDERR has been set, then set it appropriately if (!err) { @@ -1018,7 +1032,7 @@ void Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in, // If there is nothing, use stderr if (!err) - err = StreamFileSP(new StreamFile(stdout, false)); + err = std::make_shared<StreamFile>(stdout, false); } } @@ -1075,11 +1089,11 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) { } StreamSP Debugger::GetAsyncOutputStream() { - return StreamSP(new StreamAsynchronousIO(*this, true)); + return std::make_shared<StreamAsynchronousIO>(*this, true); } StreamSP Debugger::GetAsyncErrorStream() { - return StreamSP(new StreamAsynchronousIO(*this, false)); + return std::make_shared<StreamAsynchronousIO>(*this, false); } size_t Debugger::GetNumDebuggers() { @@ -1234,31 +1248,42 @@ void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback, // For simplicity's sake, I am not going to deal with how to close down any // open logging streams, I just redirect everything from here on out to the // callback. - m_log_callback_stream_sp.reset(new StreamCallback(log_callback, baton)); + m_log_callback_stream_sp = + std::make_shared<StreamCallback>(log_callback, baton); } -bool Debugger::EnableLog(const char *channel, const char **categories, - const char *log_file, uint32_t log_options, - Stream &error_stream) { - StreamSP log_stream_sp; +bool Debugger::EnableLog(llvm::StringRef channel, + llvm::ArrayRef<const char *> categories, + llvm::StringRef log_file, uint32_t log_options, + llvm::raw_ostream &error_stream) { + const bool should_close = true; + const bool unbuffered = true; + + std::shared_ptr<llvm::raw_ostream> log_stream_sp; if (m_log_callback_stream_sp) { log_stream_sp = m_log_callback_stream_sp; // For now when using the callback mode you always get thread & timestamp. log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME; - } else if (log_file == nullptr || *log_file == '\0') { - log_stream_sp = GetOutputFile(); + } else if (log_file.empty()) { + log_stream_sp = std::make_shared<llvm::raw_fd_ostream>( + GetOutputFile()->GetFile().GetDescriptor(), !should_close, unbuffered); } else { - LogStreamMap::iterator pos = m_log_streams.find(log_file); + auto pos = m_log_streams.find(log_file); if (pos != m_log_streams.end()) log_stream_sp = pos->second.lock(); if (!log_stream_sp) { - uint32_t options = File::eOpenOptionWrite | File::eOpenOptionCanCreate | - File::eOpenOptionCloseOnExec | File::eOpenOptionAppend; - if (!(log_options & LLDB_LOG_OPTION_APPEND)) - options |= File::eOpenOptionTruncate; - - log_stream_sp.reset(new StreamFile(log_file, options)); + llvm::sys::fs::OpenFlags flags = llvm::sys::fs::F_Text; + if (log_options & LLDB_LOG_OPTION_APPEND) + flags |= llvm::sys::fs::F_Append; + int FD; + if (std::error_code ec = + llvm::sys::fs::openFileForWrite(log_file, FD, flags)) { + error_stream << "Unable to open log file: " << ec.message(); + return false; + } + log_stream_sp = + std::make_shared<llvm::raw_fd_ostream>(FD, should_close, unbuffered); m_log_streams[log_file] = log_stream_sp; } } @@ -1274,7 +1299,7 @@ bool Debugger::EnableLog(const char *channel, const char **categories, SourceManager &Debugger::GetSourceManager() { if (!m_source_manager_ap) - m_source_manager_ap.reset(new SourceManager(shared_from_this())); + m_source_manager_ap = llvm::make_unique<SourceManager>(shared_from_this()); return *m_source_manager_ap; } |