diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
commit | f73363f1dd94996356cefbf24388f561891acf0b (patch) | |
tree | e3c31248bdb36eaec5fd833490d4278162dba2a0 /source/Core | |
parent | 160ee69dd7ae18978f4068116777639ea98dc951 (diff) |
Notes
Diffstat (limited to 'source/Core')
35 files changed, 1113 insertions, 1430 deletions
diff --git a/source/Core/Address.cpp b/source/Core/Address.cpp index 54b485ce03549..f183245f7d36d 100644 --- a/source/Core/Address.cpp +++ b/source/Core/Address.cpp @@ -141,8 +141,8 @@ static bool ReadAddress(ExecutionContextScope *exe_scope, deref_so_addr)) return true; } else { - // If we were not running, yet able to read an integer, we must - // have a module + // If we were not running, yet able to read an integer, we must have a + // module ModuleSP module_sp(address.GetModule()); assert(module_sp); @@ -151,8 +151,8 @@ static bool ReadAddress(ExecutionContextScope *exe_scope, } // We couldn't make "deref_addr" into a section offset value, but we were - // able to read the address, so we return a section offset address with - // no section and "deref_addr" as the offset (address). + // able to read the address, so we return a section offset address with no + // section and "deref_addr" as the offset (address). deref_so_addr.SetRawAddress(deref_addr); return true; } @@ -278,12 +278,12 @@ addr_t Address::GetFileAddress() const { // Section isn't resolved, we can't return a valid file address return LLDB_INVALID_ADDRESS; } - // We have a valid file range, so we can return the file based - // address by adding the file base address to our offset + // We have a valid file range, so we can return the file based address by + // adding the file base address to our offset return sect_file_addr + m_offset; } else if (SectionWasDeletedPrivate()) { - // Used to have a valid section but it got deleted so the - // offset doesn't mean anything without the section + // Used to have a valid section but it got deleted so the offset doesn't + // mean anything without the section return LLDB_INVALID_ADDRESS; } // No section, we just return the offset since it is the value in this case @@ -297,21 +297,21 @@ addr_t Address::GetLoadAddress(Target *target) const { addr_t sect_load_addr = section_sp->GetLoadBaseAddress(target); if (sect_load_addr != LLDB_INVALID_ADDRESS) { - // We have a valid file range, so we can return the file based - // address by adding the file base address to our offset + // We have a valid file range, so we can return the file based address + // by adding the file base address to our offset return sect_load_addr + m_offset; } } } else if (SectionWasDeletedPrivate()) { - // Used to have a valid section but it got deleted so the - // offset doesn't mean anything without the section + // Used to have a valid section but it got deleted so the offset doesn't + // mean anything without the section return LLDB_INVALID_ADDRESS; } else { // We don't have a section so the offset is the load address return m_offset; } - // The section isn't resolved or an invalid target was passed in - // so we can't return a valid load address. + // The section isn't resolved or an invalid target was passed in so we can't + // return a valid load address. return LLDB_INVALID_ADDRESS; } @@ -351,7 +351,7 @@ addr_t Address::GetOpcodeLoadAddress(Target *target, AddressClass addr_class) const { addr_t code_addr = GetLoadAddress(target); if (code_addr != LLDB_INVALID_ADDRESS) { - if (addr_class == eAddressClassInvalid) + if (addr_class == AddressClass::eInvalid) addr_class = GetAddressClass(); code_addr = target->GetOpcodeLoadAddress(code_addr, addr_class); } @@ -363,7 +363,7 @@ bool Address::SetOpcodeLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end) { if (SetLoadAddress(load_addr, target, allow_section_end)) { if (target) { - if (addr_class == eAddressClassInvalid) + if (addr_class == AddressClass::eInvalid) addr_class = GetAddressClass(); m_offset = target->GetOpcodeLoadAddress(m_offset, addr_class); } @@ -375,16 +375,15 @@ bool Address::SetOpcodeLoadAddress(lldb::addr_t load_addr, Target *target, bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const { // If the section was nullptr, only load address is going to work unless we - // are - // trying to deref a pointer + // are trying to deref a pointer SectionSP section_sp(GetSection()); if (!section_sp && style != DumpStyleResolvedPointerDescription) style = DumpStyleLoadAddress; ExecutionContext exe_ctx(exe_scope); Target *target = exe_ctx.GetTargetPtr(); - // If addr_byte_size is UINT32_MAX, then determine the correct address - // byte size for the process or default to the size of addr_t + // If addr_byte_size is UINT32_MAX, then determine the correct address byte + // size for the process or default to the size of addr_t if (addr_size == UINT32_MAX) { if (target) addr_size = target->GetArchitecture().GetAddressByteSize(); @@ -439,7 +438,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, /* * MIPS: * Display address in compressed form for MIPS16 or microMIPS - * if the address belongs to eAddressClassCodeAlternateISA. + * if the address belongs to AddressClass::eCodeAlternateISA. */ if (target) { const llvm::Triple::ArchType llvm_arch = @@ -651,15 +650,15 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, } } if (show_stop_context) { - // We have a function or a symbol from the same - // sections as this address. + // We have a function or a symbol from the same sections as this + // address. sc.DumpStopContext(s, exe_scope, *this, show_fullpaths, show_module, show_inlined_frames, show_function_arguments, show_function_name); } else { - // We found a symbol but it was in a different - // section so it isn't the symbol we should be - // showing, just show the section name + offset + // We found a symbol but it was in a different section so it + // isn't the symbol we should be showing, just show the section + // name + offset Dump(s, exe_scope, DumpStyleSectionNameOffset); } } @@ -680,10 +679,10 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, module_sp->ResolveSymbolContextForAddress( *this, eSymbolContextEverything | eSymbolContextVariable, sc); if (sc.symbol) { - // If we have just a symbol make sure it is in the same section - // as our address. If it isn't, then we might have just found - // the last symbol that came before the address that we are - // looking up that has nothing to do with our address lookup. + // If we have just a symbol make sure it is in the same section as + // our address. If it isn't, then we might have just found the last + // symbol that came before the address that we are looking up that + // has nothing to do with our address lookup. if (sc.symbol->ValueIsAddress() && sc.symbol->GetAddressRef().GetSection() != GetSection()) sc.symbol = nullptr; @@ -771,14 +770,11 @@ bool Address::SectionWasDeletedPrivate() const { lldb::SectionWP empty_section_wp; // If either call to "std::weak_ptr::owner_before(...) value returns true, - // this - // indicates that m_section_wp once contained (possibly still does) a - // reference - // to a valid shared pointer. This helps us know if we had a valid reference - // to - // a section which is now invalid because the module it was in was - // unloaded/deleted, - // or if the address doesn't have a valid reference to a section. + // this indicates that m_section_wp once contained (possibly still does) a + // reference to a valid shared pointer. This helps us know if we had a valid + // reference to a section which is now invalid because the module it was in + // was unloaded/deleted, or if the address doesn't have a valid reference to + // a section. return empty_section_wp.owner_before(m_section_wp) || m_section_wp.owner_before(empty_section_wp); } @@ -914,8 +910,8 @@ int Address::CompareModulePointerAndOffset(const Address &a, const Address &b) { return -1; if (a_module > b_module) return +1; - // Modules are the same, just compare the file address since they should - // be unique + // Modules are the same, just compare the file address since they should be + // unique addr_t a_file_addr = a.GetFileAddress(); addr_t b_file_addr = b.GetFileAddress(); if (a_file_addr < b_file_addr) @@ -926,24 +922,23 @@ int Address::CompareModulePointerAndOffset(const Address &a, const Address &b) { } size_t Address::MemorySize() const { - // Noting special for the memory size of a single Address object, - // it is just the size of itself. + // Noting special for the memory size of a single Address object, it is just + // the size of itself. return sizeof(Address); } //---------------------------------------------------------------------- // NOTE: Be careful using this operator. It can correctly compare two -// addresses from the same Module correctly. It can't compare two -// addresses from different modules in any meaningful way, but it will -// compare the module pointers. +// addresses from the same Module correctly. It can't compare two addresses +// from different modules in any meaningful way, but it will compare the module +// pointers. // // To sum things up: -// - works great for addresses within the same module -// - it works for addresses across multiple modules, but don't expect the +// - works great for addresses within the same module - it works for addresses +// across multiple modules, but don't expect the // address results to make much sense // -// This basically lets Address objects be used in ordered collection -// classes. +// This basically lets Address objects be used in ordered collection classes. //---------------------------------------------------------------------- bool lldb_private::operator<(const Address &lhs, const Address &rhs) { @@ -955,8 +950,8 @@ bool lldb_private::operator<(const Address &lhs, const Address &rhs) { // Addresses are in the same module, just compare the file addresses return lhs.GetFileAddress() < rhs.GetFileAddress(); } else { - // The addresses are from different modules, just use the module - // pointer value to get consistent ordering + // The addresses are from different modules, just use the module pointer + // value to get consistent ordering return lhs_module < rhs_module; } } @@ -970,8 +965,8 @@ bool lldb_private::operator>(const Address &lhs, const Address &rhs) { // Addresses are in the same module, just compare the file addresses return lhs.GetFileAddress() > rhs.GetFileAddress(); } else { - // The addresses are from different modules, just use the module - // pointer value to get consistent ordering + // The addresses are from different modules, just use the module pointer + // value to get consistent ordering return lhs_module > rhs_module; } } @@ -997,7 +992,7 @@ AddressClass Address::GetAddressClass() const { return obj_file->GetAddressClass(GetFileAddress()); } } - return eAddressClassUnknown; + return AddressClass::eUnknown; } bool Address::SetLoadAddress(lldb::addr_t load_addr, Target *target, diff --git a/source/Core/AddressResolverName.cpp b/source/Core/AddressResolverName.cpp index 9935362e0e987..c3dab6d108103 100644 --- a/source/Core/AddressResolverName.cpp +++ b/source/Core/AddressResolverName.cpp @@ -62,9 +62,8 @@ AddressResolverName::~AddressResolverName() = default; // FIXME: Right now we look at the module level, and call the module's // "FindFunctions". // Greg says he will add function tables, maybe at the CompileUnit level to -// accelerate function -// lookup. At that point, we should switch the depth to CompileUnit, and look -// in these tables. +// accelerate function lookup. At that point, we should switch the depth to +// CompileUnit, and look in these tables. Searcher::CallbackReturn AddressResolverName::SearchCallback(SearchFilter &filter, diff --git a/source/Core/Broadcaster.cpp b/source/Core/Broadcaster.cpp index 7a4932c4987e8..198434b46c295 100644 --- a/source/Core/Broadcaster.cpp +++ b/source/Core/Broadcaster.cpp @@ -74,9 +74,8 @@ Broadcaster::BroadcasterImpl::GetListeners() { void Broadcaster::BroadcasterImpl::Clear() { std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex); - // Make sure the listener forgets about this broadcaster. We do - // this in the broadcaster in case the broadcaster object initiates - // the removal. + // Make sure the listener forgets about this broadcaster. We do this in the + // broadcaster in case the broadcaster object initiates the removal. for (auto &pair : GetListeners()) pair.first->BroadcasterWillDestruct(&m_broadcaster); diff --git a/source/Core/CMakeLists.txt b/source/Core/CMakeLists.txt index cac56e29fc191..927a0dcc2ec18 100644 --- a/source/Core/CMakeLists.txt +++ b/source/Core/CMakeLists.txt @@ -18,6 +18,7 @@ add_lldb_library(lldbCore Debugger.cpp Disassembler.cpp DumpDataExtractor.cpp + DumpRegisterValue.cpp DynamicLoader.cpp EmulateInstruction.cpp Event.cpp @@ -69,7 +70,6 @@ add_lldb_library(lldbCore lldbPluginProcessUtility lldbPluginCPlusPlusLanguage lldbPluginObjCLanguage - lldbPluginObjectFileJIT ${LLDB_CURSES_LIBS} LINK_COMPONENTS diff --git a/source/Core/Communication.cpp b/source/Core/Communication.cpp index 38ab902ab4b73..5ca338639de05 100644 --- a/source/Core/Communication.cpp +++ b/source/Core/Communication.cpp @@ -97,15 +97,15 @@ ConnectionStatus Communication::Disconnect(Status *error_ptr) { lldb::ConnectionSP connection_sp(m_connection_sp); if (connection_sp) { ConnectionStatus status = connection_sp->Disconnect(error_ptr); - // We currently don't protect connection_sp with any mutex for - // multi-threaded environments. So lets not nuke our connection class - // without putting some multi-threaded protections in. We also probably - // don't want to pay for the overhead it might cause if every time we - // access the connection we have to take a lock. + // We currently don't protect connection_sp with any mutex for multi- + // threaded environments. So lets not nuke our connection class without + // putting some multi-threaded protections in. We also probably don't want + // to pay for the overhead it might cause if every time we access the + // connection we have to take a lock. // - // This unique pointer will cleanup after itself when this object goes away, - // so there is no need to currently have it destroy itself immediately - // upon disconnnect. + // This unique pointer will cleanup after itself when this object goes + // away, so there is no need to currently have it destroy itself + // immediately upon disconnect. // connection_sp.reset(); return status; } @@ -240,8 +240,8 @@ bool Communication::JoinReadThread(Status *error_ptr) { size_t Communication::GetCachedBytes(void *dst, size_t dst_len) { std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex); if (!m_bytes.empty()) { - // If DST is nullptr and we have a thread, then return the number - // of bytes that are available so the caller can call again + // If DST is nullptr and we have a thread, then return the number of bytes + // that are available so the caller can call again if (dst == nullptr) return m_bytes.size(); @@ -337,8 +337,7 @@ lldb::thread_result_t Communication::ReadThread(lldb::thread_arg_t p) { case eConnectionStatusInterrupted: // Synchronization signal from // SynchronizeWithReadThread() // The connection returns eConnectionStatusInterrupted only when there is - // no - // input pending to be read, so we can signal that. + // no input pending to be read, so we can signal that. comm->BroadcastEvent(eBroadcastBitNoMorePendingInput); break; case eConnectionStatusNoConnection: // No connection diff --git a/source/Core/Debugger.cpp b/source/Core/Debugger.cpp index a4d78151c75fd..972d0bc0a6d76 100644 --- a/source/Core/Debugger.cpp +++ b/source/Core/Debugger.cpp @@ -14,6 +14,7 @@ #include "lldb/Core/FormatEntity.h" #include "lldb/Core/Listener.h" // for Listener #include "lldb/Core/Mangled.h" // for Mangled +#include "lldb/Core/ModuleList.h" // for Mangled #include "lldb/Core/PluginManager.h" #include "lldb/Core/State.h" #include "lldb/Core/StreamAsynchronousIO.h" @@ -47,7 +48,7 @@ #include "lldb/Utility/StreamCallback.h" #include "lldb/Utility/StreamString.h" -#if defined(LLVM_ON_WIN32) +#if defined(_WIN32) #include "lldb/Host/windows/PosixApi.h" // for PATH_MAX #endif @@ -166,13 +167,15 @@ OptionEnumValueElement g_language_enumerators[] = { "}${addr-file-or-load}{ " \ "<${function.concrete-only-addr-offset-no-padding}>}: " -// gdb's disassembly format can be emulated with -// ${current-pc-arrow}${addr-file-or-load}{ -// <${function.name-without-args}${function.concrete-only-addr-offset-no-padding}>}: +// gdb's disassembly format can be emulated with ${current-pc-arrow}${addr- +// file-or-load}{ <${function.name-without-args}${function.concrete-only-addr- +// offset-no-padding}>}: // lldb's original format for disassembly would look like this format string - -// {${function.initial-function}{${module.file.basename}`}{${function.name-without-args}}:\n}{${function.changed}\n{${module.file.basename}`}{${function.name-without-args}}:\n}{${current-pc-arrow} -// }{${addr-file-or-load}}: +// {${function.initial-function}{${module.file.basename}`}{${function.name- +// without- +// args}}:\n}{${function.changed}\n{${module.file.basename}`}{${function.name- +// without-args}}:\n}{${current-pc-arrow} }{${addr-file-or-load}}: #define DEFAULT_STOP_SHOW_COLUMN_ANSI_PREFIX "${ansi.underline}" #define DEFAULT_STOP_SHOW_COLUMN_ANSI_SUFFIX "${ansi.normal}" @@ -589,9 +592,9 @@ bool Debugger::LoadPlugin(const FileSpec &spec, Status &error) { return true; } } else { - // 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 + // 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"); } return false; @@ -602,8 +605,8 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, const FileSpec &file_spec) { Status error; - static ConstString g_dylibext("dylib"); - static ConstString g_solibext("so"); + static ConstString g_dylibext(".dylib"); + static ConstString g_solibext(".so"); if (!baton) return FileSpec::eEnumerateDirectoryResultQuit; @@ -611,8 +614,8 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, 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 + // 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 (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file || @@ -632,9 +635,9 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, } 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 + // 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 // information. return FileSpec::eEnumerateDirectoryResultEnter; } @@ -643,19 +646,18 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, } void Debugger::InstanceInitialize() { - FileSpec dir_spec; const bool find_directories = true; const bool find_files = true; const bool find_other = true; char dir_path[PATH_MAX]; - if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec)) { + if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) { if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, find_other, LoadPluginCallback, this); } } - if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec)) { + if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) { if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, find_other, LoadPluginCallback, this); @@ -774,6 +776,9 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) m_collection_sp->AppendProperty( ConstString("platform"), ConstString("Platform settings."), true, Platform::GetGlobalPlatformProperties()->GetValueProperties()); + m_collection_sp->AppendProperty( + ConstString("symbols"), ConstString("Symbol lookup and cache settings."), + true, ModuleList::GetGlobalModuleListProperties().GetValueProperties()); if (m_command_interpreter_ap) { m_collection_sp->AppendProperty( ConstString("interpreter"), @@ -796,10 +801,9 @@ Debugger::~Debugger() { Clear(); } void Debugger::Clear() { //---------------------------------------------------------------------- - // Make sure we call this function only once. With the C++ global - // destructor chain having a list of debuggers and with code that can be - // running on other threads, we need to ensure this doesn't happen - // multiple times. + // Make sure we call this function only once. With the C++ global destructor + // chain having a list of debuggers and with code that can be running on + // other threads, we need to ensure this doesn't happen multiple times. // // The following functions call Debugger::Clear(): // Debugger::~Debugger(); @@ -824,8 +828,7 @@ void Debugger::Clear() { m_broadcaster_manager_sp->Clear(); // Close the input file _before_ we close the input read communications - // class - // as it does NOT own the input file, our m_input_file does. + // class as it does NOT own the input file, our m_input_file does. m_terminal_state.Clear(); if (m_input_file_sp) m_input_file_sp->GetFile().Close(); @@ -861,8 +864,8 @@ void Debugger::SetInputFileHandle(FILE *fh, bool tranfer_ownership) { if (!in_file.IsValid()) in_file.SetStream(stdin, true); - // Save away the terminal state if that is relevant, so that we can restore it - // in RestoreInputState. + // Save away the terminal state if that is relevant, so that we can restore + // it in RestoreInputState. SaveInputTerminalState(); } @@ -876,8 +879,8 @@ void Debugger::SetOutputFileHandle(FILE *fh, bool tranfer_ownership) { if (!out_file.IsValid()) out_file.SetStream(stdout, false); - // do not create the ScriptInterpreter just for setting the output file handle - // as the constructor will know how to do the right thing on its own + // do not create the ScriptInterpreter just for setting the output file + // handle as the constructor will know how to do the right thing on its own const bool can_create = false; ScriptInterpreter *script_interpreter = GetCommandInterpreter().GetScriptInterpreter(can_create); @@ -1023,11 +1026,10 @@ void Debugger::RunIOHandler(const IOHandlerSP &reader_sp) { void Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in, StreamFileSP &out, StreamFileSP &err) { - // Before an IOHandler runs, it must have in/out/err streams. - // This function is called when one ore more of the streams - // are nullptr. We use the top input reader's in/out/err streams, - // or fall back to the debugger file handles, or we fall back - // onto stdin/stdout/stderr as a last resort. + // Before an IOHandler runs, it must have in/out/err streams. This function + // is called when one ore more of the streams are nullptr. We use the top + // input reader's in/out/err streams, or fall back to the debugger file + // handles, or we fall back onto stdin/stdout/stderr as a last resort. std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); IOHandlerSP top_reader_sp(m_input_reader_stack.Top()); @@ -1083,8 +1085,8 @@ void Debugger::PushIOHandler(const IOHandlerSP &reader_sp) { m_input_reader_stack.Push(reader_sp); reader_sp->Activate(); - // Interrupt the top input reader to it will exit its Run() function - // and let this new input reader take over + // Interrupt the top input reader to it will exit its Run() function and let + // this new input reader take over if (top_reader_sp) { top_reader_sp->Deactivate(); top_reader_sp->Cancel(); @@ -1097,8 +1099,8 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) { std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex()); - // The reader on the stop of the stack is done, so let the next - // read on the stack refresh its prompt and if there is one... + // The reader on the stop of the stack is done, so let the next read on the + // stack refresh its prompt and if there is one... if (m_input_reader_stack.IsEmpty()) return false; @@ -1162,75 +1164,6 @@ DebuggerSP Debugger::FindDebuggerWithID(lldb::user_id_t id) { return debugger_sp; } -#if 0 -static void -TestPromptFormats (StackFrame *frame) -{ - if (frame == nullptr) - return; - - StreamString s; - const char *prompt_format = - "{addr = '${addr}'\n}" - "{addr-file-or-load = '${addr-file-or-load}'\n}" - "{current-pc-arrow = '${current-pc-arrow}'\n}" - "{process.id = '${process.id}'\n}" - "{process.name = '${process.name}'\n}" - "{process.file.basename = '${process.file.basename}'\n}" - "{process.file.fullpath = '${process.file.fullpath}'\n}" - "{thread.id = '${thread.id}'\n}" - "{thread.index = '${thread.index}'\n}" - "{thread.name = '${thread.name}'\n}" - "{thread.queue = '${thread.queue}'\n}" - "{thread.stop-reason = '${thread.stop-reason}'\n}" - "{target.arch = '${target.arch}'\n}" - "{module.file.basename = '${module.file.basename}'\n}" - "{module.file.fullpath = '${module.file.fullpath}'\n}" - "{file.basename = '${file.basename}'\n}" - "{file.fullpath = '${file.fullpath}'\n}" - "{frame.index = '${frame.index}'\n}" - "{frame.pc = '${frame.pc}'\n}" - "{frame.sp = '${frame.sp}'\n}" - "{frame.fp = '${frame.fp}'\n}" - "{frame.flags = '${frame.flags}'\n}" - "{frame.reg.rdi = '${frame.reg.rdi}'\n}" - "{frame.reg.rip = '${frame.reg.rip}'\n}" - "{frame.reg.rsp = '${frame.reg.rsp}'\n}" - "{frame.reg.rbp = '${frame.reg.rbp}'\n}" - "{frame.reg.rflags = '${frame.reg.rflags}'\n}" - "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}" - "{frame.reg.carp = '${frame.reg.carp}'\n}" - "{function.id = '${function.id}'\n}" - "{function.changed = '${function.changed}'\n}" - "{function.initial-function = '${function.initial-function}'\n}" - "{function.name = '${function.name}'\n}" - "{function.name-without-args = '${function.name-without-args}'\n}" - "{function.name-with-args = '${function.name-with-args}'\n}" - "{function.addr-offset = '${function.addr-offset}'\n}" - "{function.concrete-only-addr-offset-no-padding = '${function.concrete-only-addr-offset-no-padding}'\n}" - "{function.line-offset = '${function.line-offset}'\n}" - "{function.pc-offset = '${function.pc-offset}'\n}" - "{line.file.basename = '${line.file.basename}'\n}" - "{line.file.fullpath = '${line.file.fullpath}'\n}" - "{line.number = '${line.number}'\n}" - "{line.start-addr = '${line.start-addr}'\n}" - "{line.end-addr = '${line.end-addr}'\n}" -; - - SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything)); - ExecutionContext exe_ctx; - frame->CalculateExecutionContext(exe_ctx); - if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s)) - { - printf("%s\n", s.GetData()); - } - else - { - printf ("what we got: %s\n", s.GetData()); - } -} -#endif - bool Debugger::FormatDisassemblerAddress(const FormatEntity::Entry *format, const SymbolContext *sc, const SymbolContext *prev_sc, @@ -1262,8 +1195,8 @@ bool Debugger::FormatDisassemblerAddress(const FormatEntity::Entry *format, } } } - // The first context on a list of instructions will have a prev_sc that - // has no Function or Symbol -- if SymbolContext had an IsValid() method, it + // The first context on a list of instructions will have a prev_sc that has + // no Function or Symbol -- if SymbolContext had an IsValid() method, it // would return false. But we do get a prev_sc pointer. if ((sc && (sc->function || sc->symbol)) && prev_sc && (prev_sc->function == nullptr && prev_sc->symbol == nullptr)) { @@ -1307,8 +1240,8 @@ bool Debugger::EnableLog(llvm::StringRef channel, 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)) { + if (std::error_code ec = llvm::sys::fs::openFileForWrite( + log_file, FD, llvm::sys::fs::CD_CreateAlways, flags)) { error_stream << "Unable to open log file: " << ec.message(); return false; } @@ -1529,8 +1462,8 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) { } void Debugger::HandleThreadEvent(const EventSP &event_sp) { - // At present the only thread event we handle is the Frame Changed event, - // and all we do for that is just reprint the thread status for that thread. + // At present the only thread event we handle is the Frame Changed event, and + // all we do for that is just reprint the thread status for that thread. using namespace lldb; const uint32_t event_type = event_sp->GetType(); const bool stop_format = true; @@ -1583,8 +1516,8 @@ void Debugger::DefaultEventHandler() { CommandInterpreter::eBroadcastBitAsynchronousOutputData | CommandInterpreter::eBroadcastBitAsynchronousErrorData); - // Let the thread that spawned us know that we have started up and - // that we are now listening to all required events so no events get missed + // Let the thread that spawned us know that we have started up and that we + // are now listening to all required events so no events get missed m_sync_broadcaster.BroadcastEvent(eBroadcastBitEventThreadIsListening); bool done = false; @@ -1649,27 +1582,28 @@ lldb::thread_result_t Debugger::EventHandlerThread(lldb::thread_arg_t arg) { bool Debugger::StartEventHandlerThread() { if (!m_event_handler_thread.IsJoinable()) { - // We must synchronize with the DefaultEventHandler() thread to ensure - // it is up and running and listening to events before we return from - // this function. We do this by listening to events for the + // We must synchronize with the DefaultEventHandler() thread to ensure it + // is up and running and listening to events before we return from this + // function. We do this by listening to events for the // eBroadcastBitEventThreadIsListening from the m_sync_broadcaster - ListenerSP listener_sp( - Listener::MakeListener("lldb.debugger.event-handler")); + ConstString full_name("lldb.debugger.event-handler"); + ListenerSP listener_sp(Listener::MakeListener(full_name.AsCString())); listener_sp->StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening); + auto thread_name = + full_name.GetLength() < llvm::get_max_thread_name_length() ? + full_name.AsCString() : "dbg.evt-handler"; + // Use larger 8MB stack for this thread - m_event_handler_thread = ThreadLauncher::LaunchThread( - "lldb.debugger.event-handler", EventHandlerThread, this, nullptr, - g_debugger_event_thread_stack_bytes); - - // Make sure DefaultEventHandler() is running and listening to events before - // we return - // from this function. We are only listening for events of type - // eBroadcastBitEventThreadIsListening so we don't need to check the event, - // we just need - // to wait an infinite amount of time for it (nullptr timeout as the first - // parameter) + m_event_handler_thread = ThreadLauncher::LaunchThread(thread_name, + EventHandlerThread, this, nullptr, g_debugger_event_thread_stack_bytes); + + // Make sure DefaultEventHandler() is running and listening to events + // before we return from this function. We are only listening for events of + // type eBroadcastBitEventThreadIsListening so we don't need to check the + // event, we just need to wait an infinite amount of time for it (nullptr + // timeout as the first parameter) lldb::EventSP event_sp; listener_sp->GetEvent(event_sp, llvm::None); } diff --git a/source/Core/Disassembler.cpp b/source/Core/Disassembler.cpp index 6d463d552da65..d41a19465280e 100644 --- a/source/Core/Disassembler.cpp +++ b/source/Core/Disassembler.cpp @@ -96,8 +96,8 @@ DisassemblerSP Disassembler::FindPluginForTarget(const TargetSP target_sp, const char *plugin_name) { if (target_sp && flavor == nullptr) { // FIXME - we don't have the mechanism in place to do per-architecture - // settings. But since we know that for now - // we only support flavors on x86 & x86_64, + // settings. But since we know that for now we only support flavors on x86 + // & x86_64, if (arch.GetTriple().getArch() == llvm::Triple::x86 || arch.GetTriple().getArch() == llvm::Triple::x86_64) flavor = target_sp->GetDisassemblyFlavor(); @@ -108,19 +108,19 @@ DisassemblerSP Disassembler::FindPluginForTarget(const TargetSP target_sp, static void ResolveAddress(const ExecutionContext &exe_ctx, const Address &addr, Address &resolved_addr) { if (!addr.IsSectionOffset()) { - // If we weren't passed in a section offset address range, - // try and resolve it to something + // If we weren't passed in a section offset address range, try and resolve + // it to something Target *target = exe_ctx.GetTargetPtr(); if (target) { - if (target->GetSectionLoadList().IsEmpty()) { - target->GetImages().ResolveFileAddress(addr.GetOffset(), resolved_addr); - } else { - target->GetSectionLoadList().ResolveLoadAddress(addr.GetOffset(), - resolved_addr); - } - // We weren't able to resolve the address, just treat it as a - // raw address - if (resolved_addr.IsValid()) + bool is_resolved = + target->GetSectionLoadList().IsEmpty() ? + target->GetImages().ResolveFileAddress(addr.GetOffset(), + resolved_addr) : + target->GetSectionLoadList().ResolveLoadAddress(addr.GetOffset(), + resolved_addr); + + // We weren't able to resolve the address, just treat it as a raw address + if (is_resolved && resolved_addr.IsValid()) return; } } @@ -410,15 +410,13 @@ bool Disassembler::PrintInstructions(Disassembler *disasm_ptr, disassembly_format = &format; } - // First pass: step through the list of instructions, - // find how long the initial addresses strings are, insert padding - // in the second pass so the opcodes all line up nicely. + // First pass: step through the list of instructions, find how long the + // initial addresses strings are, insert padding in the second pass so the + // opcodes all line up nicely. // Also build up the source line mapping if this is mixed source & assembly - // mode. - // Calculate the source line for each assembly instruction (eliding inlined - // functions - // which the user wants to skip). + // mode. Calculate the source line for each assembly instruction (eliding + // inlined functions which the user wants to skip). std::map<FileSpec, std::set<uint32_t>> source_lines_seen; Symbol *previous_symbol = nullptr; @@ -495,17 +493,13 @@ bool Disassembler::PrintInstructions(Disassembler *disasm_ptr, if (mixed_source_and_assembly) { // If we've started a new function (non-inlined), print all of the - // source lines from the - // function declaration until the first line table entry - typically - // the opening curly brace of - // the function. + // source lines from the function declaration until the first line + // table entry - typically the opening curly brace of the function. if (previous_symbol != sc.symbol) { - // The default disassembly format puts an extra blank line between - // functions - so - // when we're displaying the source context for a function, we - // don't want to add - // a blank line after the source context or we'll end up with two - // of them. + // The default disassembly format puts an extra blank line + // between functions - so when we're displaying the source + // context for a function, we don't want to add a blank line + // after the source context or we'll end up with two of them. if (previous_symbol != nullptr) source_lines_to_display.print_source_context_end_eol = false; @@ -520,9 +514,9 @@ bool Disassembler::PrintInstructions(Disassembler *disasm_ptr, func_decl_line); if (func_decl_file == prologue_end_line.file || func_decl_file == prologue_end_line.original_file) { - // Add all the lines between the function declaration - // and the first non-prologue source line to the list - // of lines to print. + // Add all the lines between the function declaration and + // the first non-prologue source line to the list of lines + // to print. for (uint32_t lineno = func_decl_line; lineno <= prologue_end_line.line; lineno++) { SourceLine this_line; @@ -530,8 +524,8 @@ bool Disassembler::PrintInstructions(Disassembler *disasm_ptr, this_line.line = lineno; source_lines_to_display.lines.push_back(this_line); } - // Mark the last line as the "current" one. Usually - // this is the open curly brace. + // Mark the last line as the "current" one. Usually this + // is the open curly brace. if (source_lines_to_display.lines.size() > 0) source_lines_to_display.current_source_line = source_lines_to_display.lines.size() - 1; @@ -542,8 +536,8 @@ bool Disassembler::PrintInstructions(Disassembler *disasm_ptr, current_source_line_range); } - // If we've left a previous source line's address range, print a new - // source line + // If we've left a previous source line's address range, print a + // new source line if (!current_source_line_range.ContainsFileAddress(addr)) { sc.GetAddressRange(scope, 0, use_inline_block_range, current_source_line_range); @@ -558,8 +552,8 @@ bool Disassembler::PrintInstructions(Disassembler *disasm_ptr, // Only print this source line if it is different from the // last source line we printed. There may have been inlined // functions between these lines that we elided, resulting in - // the same line being printed twice in a row for a contiguous - // block of assembly instructions. + // the same line being printed twice in a row for a + // contiguous block of assembly instructions. if (this_line != previous_line) { std::vector<uint32_t> previous_lines; @@ -683,7 +677,7 @@ Instruction::Instruction(const Address &address, AddressClass addr_class) Instruction::~Instruction() = default; AddressClass Instruction::GetAddressClass() { - if (m_address_class == eAddressClassInvalid) + if (m_address_class == AddressClass::eInvalid) m_address_class = m_address.GetAddressClass(); return m_address_class; } @@ -710,16 +704,16 @@ void Instruction::Dump(lldb_private::Stream *s, uint32_t max_opcode_byte_size, if (show_bytes) { if (m_opcode.GetType() == Opcode::eTypeBytes) { - // x86_64 and i386 are the only ones that use bytes right now so - // pad out the byte dump to be able to always show 15 bytes (3 chars each) - // plus a space + // x86_64 and i386 are the only ones that use bytes right now so pad out + // the byte dump to be able to always show 15 bytes (3 chars each) plus a + // space if (max_opcode_byte_size > 0) m_opcode.Dump(&ss, max_opcode_byte_size * 3 + 1); else m_opcode.Dump(&ss, 15 * 3 + 1); } else { - // Else, we have ARM or MIPS which can show up to a uint32_t - // 0x00000000 (10 spaces) plus two for padding... + // Else, we have ARM or MIPS which can show up to a uint32_t 0x00000000 + // (10 spaces) plus two for padding... if (max_opcode_byte_size > 0) m_opcode.Dump(&ss, max_opcode_byte_size * 3 + 1); else @@ -903,7 +897,8 @@ OptionValueSP Instruction::ReadDictionary(FILE *in_file, Stream *out_stream) { option_value_sp.reset(); return option_value_sp; } - // We've used the data_type to read an array; re-set the type to Invalid + // We've used the data_type to read an array; re-set the type to + // Invalid data_type = OptionValue::eTypeInvalid; } else if ((value[0] == '0') && (value[1] == 'x')) { value_sp = std::make_shared<OptionValueUInt64>(0, 0); @@ -1107,9 +1102,9 @@ InstructionList::GetIndexOfNextBranchInstruction(uint32_t start, } } - // Hexagon needs the first instruction of the packet with the branch. - // Go backwards until we find an instruction marked end-of-packet, or - // until we hit start. + // Hexagon needs the first instruction of the packet with the branch. Go + // backwards until we find an instruction marked end-of-packet, or until we + // hit start. if (target.GetArchitecture().GetTriple().getArch() == llvm::Triple::hexagon) { // If we didn't find a branch, find the last packet start. if (next_branch == UINT32_MAX) { @@ -1128,8 +1123,8 @@ InstructionList::GetIndexOfNextBranchInstruction(uint32_t start, // If we have an error reading memory, return start if (!error.Success()) return start; - // check if this is the last instruction in a packet - // bits 15:14 will be 11b or 00b for a duplex + // check if this is the last instruction in a packet bits 15:14 will be + // 11b or 00b for a duplex if (((inst_bytes & 0xC000) == 0xC000) || ((inst_bytes & 0xC000) == 0x0000)) { // instruction after this should be the start of next packet @@ -1257,8 +1252,7 @@ Disassembler::Disassembler(const ArchSpec &arch, const char *flavor) m_flavor.assign(flavor); // If this is an arm variant that can only include thumb (T16, T32) - // instructions, force the arch triple to be "thumbv.." instead of - // "armv..." + // instructions, force the arch triple to be "thumbv.." instead of "armv..." if (arch.IsAlwaysThumbInstructions()) { std::string thumb_arch_name(arch.GetTriple().getArchName().str()); // Replace "arm" with "thumb" so we get all thumb variants correct @@ -1285,7 +1279,7 @@ const InstructionList &Disassembler::GetInstructionList() const { //---------------------------------------------------------------------- PseudoInstruction::PseudoInstruction() - : Instruction(Address(), eAddressClassUnknown), m_description() {} + : Instruction(Address(), AddressClass::eUnknown), m_description() {} PseudoInstruction::~PseudoInstruction() = default; diff --git a/source/Core/DumpDataExtractor.cpp b/source/Core/DumpDataExtractor.cpp index e564e86478fc1..049f4d3805a13 100644 --- a/source/Core/DumpDataExtractor.cpp +++ b/source/Core/DumpDataExtractor.cpp @@ -239,8 +239,8 @@ lldb::offset_t lldb_private::DumpDataExtractor( if (item_byte_size <= 8) { uint64_t uval64 = DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset); - // Avoid std::bitset<64>::to_string() since it is missing in - // earlier C++ libraries + // Avoid std::bitset<64>::to_string() since it is missing in earlier + // C++ libraries std::string binary_value(64, '0'); std::bitset<64> bits(uval64); for (uint32_t i = 0; i < 64; ++i) @@ -263,8 +263,8 @@ lldb::offset_t lldb_private::DumpDataExtractor( s->Printf("%2.2x", DE.GetU8(&offset)); } - // Put an extra space between the groups of bytes if more than one - // is being dumped in a group (item_byte_size is more than 1). + // Put an extra space between the groups of bytes if more than one is + // being dumped in a group (item_byte_size is more than 1). if (item_byte_size > 1) s->PutChar(' '); break; @@ -279,8 +279,7 @@ lldb::offset_t lldb_private::DumpDataExtractor( return offset; } - // If we are only printing one character surround it with single - // quotes + // If we are only printing one character surround it with single quotes if (item_count == 1 && item_format == eFormatChar) s->PutChar('\''); @@ -583,8 +582,10 @@ lldb::offset_t lldb_private::DumpDataExtractor( } else if (item_bit_size == ast->getTypeSize(ast->LongDoubleTy)) { const auto &semantics = ast->getFloatTypeSemantics(ast->LongDoubleTy); - const auto byte_size = - (llvm::APFloat::getSizeInBits(semantics) + 7) / 8; + + offset_t byte_size = item_byte_size; + if (&semantics == &llvm::APFloatBase::x87DoubleExtended()) + byte_size = (llvm::APFloat::getSizeInBits(semantics) + 7) / 8; llvm::APInt apint; if (GetAPInt(DE, &offset, byte_size, apint)) { @@ -691,10 +692,9 @@ lldb::offset_t lldb_private::DumpDataExtractor( break; // please keep the single-item formats below in sync with - // FormatManager::GetSingleItemFormat - // if you fail to do so, users will start getting different outputs - // depending on internal - // implementation details they should not care about || + // FormatManager::GetSingleItemFormat if you fail to do so, users will + // start getting different outputs depending on internal implementation + // details they should not care about || case eFormatVectorOfChar: // || s->PutChar('{'); // \/ offset = diff --git a/source/Core/DumpRegisterValue.cpp b/source/Core/DumpRegisterValue.cpp new file mode 100644 index 0000000000000..99334ca78a6d4 --- /dev/null +++ b/source/Core/DumpRegisterValue.cpp @@ -0,0 +1,79 @@ +//===-- DumpRegisterValue.cpp -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Core/DumpRegisterValue.h" +#include "lldb/Core/DumpDataExtractor.h" +#include "lldb/Core/RegisterValue.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/StreamString.h" +#include "lldb/lldb-private-types.h" + +using namespace lldb; + +bool lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream *s, + const RegisterInfo *reg_info, + bool prefix_with_name, + bool prefix_with_alt_name, Format format, + uint32_t reg_name_right_align_at) { + DataExtractor data; + if (reg_val.GetData(data)) { + bool name_printed = false; + // For simplicity, alignment of the register name printing applies only in + // the most common case where: + // + // prefix_with_name^prefix_with_alt_name is true + // + StreamString format_string; + if (reg_name_right_align_at && (prefix_with_name ^ prefix_with_alt_name)) + format_string.Printf("%%%us", reg_name_right_align_at); + else + format_string.Printf("%%s"); + std::string fmt = format_string.GetString(); + if (prefix_with_name) { + if (reg_info->name) { + s->Printf(fmt.c_str(), reg_info->name); + name_printed = true; + } else if (reg_info->alt_name) { + s->Printf(fmt.c_str(), reg_info->alt_name); + prefix_with_alt_name = false; + name_printed = true; + } + } + if (prefix_with_alt_name) { + if (name_printed) + s->PutChar('/'); + if (reg_info->alt_name) { + s->Printf(fmt.c_str(), reg_info->alt_name); + name_printed = true; + } else if (!name_printed) { + // No alternate name but we were asked to display a name, so show the + // main name + s->Printf(fmt.c_str(), reg_info->name); + name_printed = true; + } + } + if (name_printed) + s->PutCString(" = "); + + if (format == eFormatDefault) + format = reg_info->format; + + DumpDataExtractor(data, s, + 0, // Offset in "data" + format, // Format to use when dumping + reg_info->byte_size, // item_byte_size + 1, // item_count + UINT32_MAX, // num_per_line + LLDB_INVALID_ADDRESS, // base_addr + 0, // item_bit_size + 0); // item_bit_offset + return true; + } + return false; +} diff --git a/source/Core/DynamicLoader.cpp b/source/Core/DynamicLoader.cpp index 5477498dadc8c..16f1ffca1a20d 100644 --- a/source/Core/DynamicLoader.cpp +++ b/source/Core/DynamicLoader.cpp @@ -64,8 +64,8 @@ DynamicLoader::DynamicLoader(Process *process) : m_process(process) {} DynamicLoader::~DynamicLoader() = default; //---------------------------------------------------------------------- -// Accessosors to the global setting as to whether to stop at image -// (shared library) loading/unloading. +// Accessosors to the global setting as to whether to stop at image (shared +// library) loading/unloading. //---------------------------------------------------------------------- bool DynamicLoader::GetStopWhenImagesChange() const { @@ -86,8 +86,8 @@ ModuleSP DynamicLoader::GetTargetExecutable() { executable->GetArchitecture()); auto module_sp = std::make_shared<Module>(module_spec); - // Check if the executable has changed and set it to the target executable - // if they differ. + // Check if the executable has changed and set it to the target + // executable if they differ. if (module_sp && module_sp->GetUUID().IsValid() && executable->GetUUID().IsValid()) { if (module_sp->GetUUID() != executable->GetUUID()) @@ -99,8 +99,8 @@ ModuleSP DynamicLoader::GetTargetExecutable() { if (!executable) { executable = target.GetSharedModule(module_spec); if (executable.get() != target.GetExecutableModulePointer()) { - // Don't load dependent images since we are in dyld where we will know - // and find out about all images that are loaded + // Don't load dependent images since we are in dyld where we will + // know and find out about all images that are loaded const bool get_dependent_images = false; target.SetExecutableModule(executable, get_dependent_images); } @@ -177,8 +177,8 @@ ModuleSP DynamicLoader::LoadModuleAtAddress(const FileSpec &file, bool check_alternative_file_name = true; if (base_addr_is_offset) { // Try to fetch the load address of the file from the process as we need - // absolute load - // address to read the file out of the memory instead of a load bias. + // absolute load address to read the file out of the memory instead of a + // load bias. bool is_loaded = false; lldb::addr_t load_addr; Status error = m_process->GetFileLoadAddress(file, is_loaded, load_addr); @@ -188,9 +188,8 @@ ModuleSP DynamicLoader::LoadModuleAtAddress(const FileSpec &file, } } - // We failed to find the module based on its name. Lets try to check if we can - // find a - // different name based on the memory region info. + // We failed to find the module based on its name. Lets try to check if we + // can find a different name based on the memory region info. if (check_alternative_file_name) { MemoryRegionInfo memory_info; Status error = m_process->GetMemoryRegionInfo(base_addr, memory_info); diff --git a/source/Core/EmulateInstruction.cpp b/source/Core/EmulateInstruction.cpp index 2ee2c79de2708..469022119c9ec 100644 --- a/source/Core/EmulateInstruction.cpp +++ b/source/Core/EmulateInstruction.cpp @@ -10,6 +10,7 @@ #include "lldb/Core/EmulateInstruction.h" #include "lldb/Core/Address.h" +#include "lldb/Core/DumpRegisterValue.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" #include "lldb/Core/StreamFile.h" @@ -361,7 +362,7 @@ bool EmulateInstruction::WriteRegisterDefault(EmulateInstruction *instruction, const RegisterValue ®_value) { StreamFile strm(stdout, false); strm.Printf(" Write to Register (name = %s, value = ", reg_info->name); - reg_value.Dump(&strm, reg_info, false, false, eFormatDefault); + DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault); strm.PutCString(", context = "); context.Dump(strm, instruction); strm.EOL(); diff --git a/source/Core/Event.cpp b/source/Core/Event.cpp index 8d351d8ba1a52..3ebad7acdef78 100644 --- a/source/Core/Event.cpp +++ b/source/Core/Event.cpp @@ -10,7 +10,6 @@ #include "lldb/Core/Event.h" #include "lldb/Core/Broadcaster.h" -#include "lldb/Core/DumpDataExtractor.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/Endian.h" #include "lldb/Utility/Stream.h" @@ -134,14 +133,13 @@ const ConstString &EventDataBytes::GetFlavor() const { void EventDataBytes::Dump(Stream *s) const { size_t num_printable_chars = std::count_if(m_bytes.begin(), m_bytes.end(), isprint); - if (num_printable_chars == m_bytes.size()) { - s->Printf("\"%s\"", m_bytes.c_str()); - } else if (!m_bytes.empty()) { - DataExtractor data; - data.SetData(m_bytes.data(), m_bytes.size(), endian::InlHostByteOrder()); - DumpDataExtractor(data, s, 0, eFormatBytes, 1, m_bytes.size(), 32, - LLDB_INVALID_ADDRESS, 0, 0); - } + if (num_printable_chars == m_bytes.size()) + s->Format("\"{0}\"", m_bytes); + else + s->Format("{0:$[ ]@[x-2]}", llvm::make_range( + reinterpret_cast<const uint8_t *>(m_bytes.data()), + reinterpret_cast<const uint8_t *>(m_bytes.data() + + m_bytes.size()))); } const void *EventDataBytes::GetBytes() const { diff --git a/source/Core/FileLineResolver.cpp b/source/Core/FileLineResolver.cpp index 36f37f4a14d5c..7f0f440252e79 100644 --- a/source/Core/FileLineResolver.cpp +++ b/source/Core/FileLineResolver.cpp @@ -54,8 +54,8 @@ FileLineResolver::SearchCallback(SearchFilter &filter, SymbolContext &context, while (file_idx != UINT32_MAX) { line_table->FineLineEntriesForFileIndex(file_idx, append, m_sc_list); - // Get the next file index in case we have multiple file - // entries for the same file + // Get the next file index in case we have multiple file entries + // for the same file file_idx = cu->GetSupportFiles().FindFileIndex(file_idx + 1, m_file_spec, false); } diff --git a/source/Core/FileSpecList.cpp b/source/Core/FileSpecList.cpp index 5b0bdac654e13..66e27b1974479 100644 --- a/source/Core/FileSpecList.cpp +++ b/source/Core/FileSpecList.cpp @@ -42,11 +42,10 @@ void FileSpecList::Append(const FileSpec &file_spec) { } //------------------------------------------------------------------ -// Only append the "file_spec" if this list doesn't already contain -// it. +// Only append the "file_spec" if this list doesn't already contain it. // -// Returns true if "file_spec" was added, false if this list already -// contained a copy of "file_spec". +// Returns true if "file_spec" was added, false if this list already contained +// a copy of "file_spec". //------------------------------------------------------------------ bool FileSpecList::AppendIfUnique(const FileSpec &file_spec) { collection::iterator end = m_files.end(); @@ -75,18 +74,18 @@ void FileSpecList::Dump(Stream *s, const char *separator_cstr) const { } //------------------------------------------------------------------ -// Find the index of the file in the file spec list that matches -// "file_spec" starting "start_idx" entries into the file spec list. +// Find the index of the file in the file spec list that matches "file_spec" +// starting "start_idx" entries into the file spec list. // -// Returns the valid index of the file that matches "file_spec" if -// it is found, else std::numeric_limits<uint32_t>::max() is returned. +// Returns the valid index of the file that matches "file_spec" if it is found, +// else std::numeric_limits<uint32_t>::max() is returned. //------------------------------------------------------------------ size_t FileSpecList::FindFileIndex(size_t start_idx, const FileSpec &file_spec, - bool full, bool remove_dots) const { + bool full) const { const size_t num_files = m_files.size(); - // When looking for files, we will compare only the filename if the - // FILE_SPEC argument is empty + // When looking for files, we will compare only the filename if the FILE_SPEC + // argument is empty bool compare_filename_only = file_spec.GetDirectory().IsEmpty(); for (size_t idx = start_idx; idx < num_files; ++idx) { @@ -96,7 +95,7 @@ size_t FileSpecList::FindFileIndex(size_t start_idx, const FileSpec &file_spec, file_spec.IsCaseSensitive() || m_files[idx].IsCaseSensitive())) return idx; } else { - if (FileSpec::Equal(m_files[idx], file_spec, full, remove_dots)) + if (FileSpec::Equal(m_files[idx], file_spec, full)) return idx; } } @@ -106,8 +105,8 @@ size_t FileSpecList::FindFileIndex(size_t start_idx, const FileSpec &file_spec, } //------------------------------------------------------------------ -// Returns the FileSpec object at index "idx". If "idx" is out of -// range, then an empty FileSpec object will be returned. +// Returns the FileSpec object at index "idx". If "idx" is out of range, then +// an empty FileSpec object will be returned. //------------------------------------------------------------------ const FileSpec &FileSpecList::GetFileSpecAtIndex(size_t idx) const { if (idx < m_files.size()) @@ -123,11 +122,10 @@ const FileSpec *FileSpecList::GetFileSpecPointerAtIndex(size_t idx) const { } //------------------------------------------------------------------ -// Return the size in bytes that this object takes in memory. This -// returns the size in bytes of this object's member variables and -// any FileSpec objects its member variables contain, the result -// doesn't not include the string values for the directories any -// filenames as those are in shared string pools. +// Return the size in bytes that this object takes in memory. This returns the +// size in bytes of this object's member variables and any FileSpec objects its +// member variables contain, the result doesn't not include the string values +// for the directories any filenames as those are in shared string pools. //------------------------------------------------------------------ size_t FileSpecList::MemorySize() const { size_t mem_size = sizeof(FileSpecList); diff --git a/source/Core/FormatEntity.cpp b/source/Core/FormatEntity.cpp index 0cb74cc7658da..2257b7e273e84 100644 --- a/source/Core/FormatEntity.cpp +++ b/source/Core/FormatEntity.cpp @@ -12,6 +12,7 @@ #include "lldb/Core/Address.h" #include "lldb/Core/AddressRange.h" // for AddressRange #include "lldb/Core/Debugger.h" +#include "lldb/Core/DumpRegisterValue.h" #include "lldb/Core/Module.h" #include "lldb/Core/RegisterValue.h" // for RegisterValue #include "lldb/Core/ValueObject.h" @@ -467,10 +468,9 @@ static bool DumpAddressOffsetFromFunction(Stream &s, const SymbolContext *sc, if (sc->function) { func_addr = sc->function->GetAddressRange().GetBaseAddress(); if (sc->block && !concrete_only) { - // Check to make sure we aren't in an inline - // function. If we are, use the inline block - // range that contains "format_addr" since - // blocks can be discontiguous. + // Check to make sure we aren't in an inline function. If we are, use + // the inline block range that contains "format_addr" since blocks + // can be discontiguous. Block *inline_block = sc->block->GetContainingInlinedBlock(); AddressRange inline_range; if (inline_block && @@ -622,7 +622,7 @@ static bool DumpRegister(Stream &s, StackFrame *frame, RegisterKind reg_kind, if (reg_info) { RegisterValue reg_value; if (reg_ctx->ReadRegister(reg_info, reg_value)) { - reg_value.Dump(&s, reg_info, false, false, format); + DumpRegisterValue(reg_value, &s, reg_info, false, false, format); return true; } } @@ -822,8 +822,7 @@ static bool DumpValue(Stream &s, const SymbolContext *sc, if (do_deref_pointer && !is_array_range) { // I have not deref-ed yet, let's do it // this happens when we are not going through - // GetValueForVariableExpressionPath - // to get to the target ValueObject + // GetValueForVariableExpressionPath to get to the target ValueObject Status error; target = target->Dereference(error).get(); if (error.Fail()) { @@ -842,9 +841,9 @@ static bool DumpValue(Stream &s, const SymbolContext *sc, return false; } - // we do not want to use the summary for a bitfield of type T:n - // if we were originally dealing with just a T - that would get - // us into an endless recursion + // we do not want to use the summary for a bitfield of type T:n if we were + // originally dealing with just a T - that would get us into an endless + // recursion if (target->IsBitfield() && was_var_indexed) { // TODO: check for a (T:n)-specific summary - we should still obey that StreamString bitfield_name; @@ -905,8 +904,7 @@ static bool DumpValue(Stream &s, const SymbolContext *sc, } // if directly trying to print ${var}, and this is an aggregate, display a - // nice - // type @ location message + // nice type @ location message if (is_aggregate && was_plain_var) { s << target->GetTypeName() << " @ " << target->GetLocationAsCString(); return true; @@ -1021,7 +1019,7 @@ static bool DumpRegister(Stream &s, StackFrame *frame, const char *reg_name, if (reg_info) { RegisterValue reg_value; if (reg_ctx->ReadRegister(reg_info, reg_value)) { - reg_value.Dump(&s, reg_info, false, false, format); + DumpRegisterValue(reg_value, &s, reg_info, false, false, format); return true; } } @@ -1142,8 +1140,8 @@ bool FormatEntity::Format(const Entry &entry, Stream &s, if (!success) break; } - // Only if all items in a scope succeed, then do we - // print the output into the main stream + // Only if all items in a scope succeed, then do we print the output into + // the main stream if (success) s.Write(scope_stream.GetString().data(), scope_stream.GetString().size()); } @@ -1206,9 +1204,8 @@ bool FormatEntity::Format(const Entry &entry, Stream &s, // Watch for the special "tid" format... if (entry.printf_format == "tid") { // TODO(zturner): Rather than hardcoding this to be platform - // specific, it should be controlled by a - // setting and the default value of the setting can be different - // depending on the platform. + // specific, it should be controlled by a setting and the default + // value of the setting can be different depending on the platform. Target &target = thread->GetProcess()->GetTarget(); ArchSpec arch(target.GetArchitecture()); llvm::Triple::OSType ostype = arch.IsValid() @@ -1914,9 +1911,9 @@ static Status ParseEntry(const llvm::StringRef &format_str, error.SetErrorStringWithFormat("%s", error_strm.GetData()); } else if (sep_char == ':') { // Any value whose separator is a with a ':' means this value has a - // string argument - // that needs to be stored in the entry (like "${script.var:}"). - // In this case the string value is the empty string which is ok. + // string argument that needs to be stored in the entry (like + // "${script.var:}"). In this case the string value is the empty + // string which is ok. } else { error.SetErrorStringWithFormat("%s", "invalid entry definitions"); } @@ -1926,8 +1923,7 @@ static Status ParseEntry(const llvm::StringRef &format_str, error = ParseEntry(value, entry_def, entry); } else if (sep_char == ':') { // Any value whose separator is a with a ':' means this value has a - // string argument - // that needs to be stored in the entry (like + // string argument that needs to be stored in the entry (like // "${script.var:modulename.function}") entry.string = value.str(); } else { @@ -2065,17 +2061,17 @@ Status FormatEntity::ParseInternal(llvm::StringRef &format, Entry &parent_entry, case '0': // 1 to 3 octal chars { - // Make a string that can hold onto the initial zero char, - // up to 3 octal digits, and a terminating NULL. + // Make a string that can hold onto the initial zero char, up to 3 + // octal digits, and a terminating NULL. char oct_str[5] = {0, 0, 0, 0, 0}; int i; for (i = 0; (format[i] >= '0' && format[i] <= '7') && i < 4; ++i) oct_str[i] = format[i]; - // We don't want to consume the last octal character since - // the main for loop will do this for us, so we advance p by - // one less than i (even if i is zero) + // We don't want to consume the last octal character since the main + // for loop will do this for us, so we advance p by one less than i + // (even if i is zero) format = format.drop_front(i); unsigned long octal_value = ::strtoul(oct_str, nullptr, 8); if (octal_value <= UINT8_MAX) { @@ -2115,8 +2111,8 @@ Status FormatEntity::ParseInternal(llvm::StringRef &format, Entry &parent_entry, break; default: - // Just desensitize any other character by just printing what - // came after the '\' + // Just desensitize any other character by just printing what came + // after the '\' parent_entry.AppendChar(desens_char); break; } @@ -2142,10 +2138,9 @@ Status FormatEntity::ParseInternal(llvm::StringRef &format, Entry &parent_entry, if (!variable_format.empty()) { entry.printf_format = variable_format.str(); - // If the format contains a '%' we are going to assume this is - // a printf style format. So if you want to format your thread ID - // using "0x%llx" you can use: - // ${thread.id%0x%llx} + // If the format contains a '%' we are going to assume this is a + // printf style format. So if you want to format your thread ID + // using "0x%llx" you can use: ${thread.id%0x%llx} // // If there is no '%' in the format, then it is assumed to be a // LLDB format name, or one of the extended formats specified in @@ -2264,9 +2259,9 @@ Status FormatEntity::ParseInternal(llvm::StringRef &format, Entry &parent_entry, return error; } } - // Check if this entry just wants to insert a constant string - // value into the parent_entry, if so, insert the string with - // AppendText, else append the entry to the parent_entry. + // Check if this entry just wants to insert a constant string value + // into the parent_entry, if so, insert the string with AppendText, + // else append the entry to the parent_entry. if (entry.type == Entry::Type::InsertString) parent_entry.AppendText(entry.string.c_str()); else @@ -2350,12 +2345,12 @@ static void AddMatches(const FormatEntity::Entry::Definition *def, } } -size_t FormatEntity::AutoComplete(llvm::StringRef str, int match_start_point, - int max_return_elements, bool &word_complete, - StringList &matches) { - word_complete = false; - str = str.drop_front(match_start_point); - matches.Clear(); +size_t FormatEntity::AutoComplete(CompletionRequest &request) { + llvm::StringRef str = request.GetCursorArgumentPrefix().str(); + + request.SetWordComplete(false); + str = str.drop_front(request.GetMatchStartPoint()); + request.GetMatches().Clear(); const size_t dollar_pos = str.rfind('$'); if (dollar_pos == llvm::StringRef::npos) @@ -2365,7 +2360,7 @@ size_t FormatEntity::AutoComplete(llvm::StringRef str, int match_start_point, if (dollar_pos == str.size() - 1) { std::string match = str.str(); match.append("{"); - matches.AppendString(match); + request.GetMatches().AppendString(match); return 1; } @@ -2383,8 +2378,8 @@ size_t FormatEntity::AutoComplete(llvm::StringRef str, int match_start_point, llvm::StringRef partial_variable(str.substr(dollar_pos + 2)); if (partial_variable.empty()) { // Suggest all top level entites as we are just past "${" - AddMatches(&g_root, str, llvm::StringRef(), matches); - return matches.GetSize(); + AddMatches(&g_root, str, llvm::StringRef(), request.GetMatches()); + return request.GetMatches().GetSize(); } // We have a partially specified variable, find it @@ -2400,19 +2395,19 @@ size_t FormatEntity::AutoComplete(llvm::StringRef str, int match_start_point, // Exact match if (n > 0) { // "${thread.info" <TAB> - matches.AppendString(MakeMatch(str, ".")); + request.GetMatches().AppendString(MakeMatch(str, ".")); } else { // "${thread.id" <TAB> - matches.AppendString(MakeMatch(str, "}")); - word_complete = true; + request.GetMatches().AppendString(MakeMatch(str, "}")); + request.SetWordComplete(true); } } else if (remainder.equals(".")) { // "${thread." <TAB> - AddMatches(entry_def, str, llvm::StringRef(), matches); + AddMatches(entry_def, str, llvm::StringRef(), request.GetMatches()); } else { // We have a partial match // "${thre" <TAB> - AddMatches(entry_def, str, remainder, matches); + AddMatches(entry_def, str, remainder, request.GetMatches()); } - return matches.GetSize(); + return request.GetMatches().GetSize(); } diff --git a/source/Core/IOHandler.cpp b/source/Core/IOHandler.cpp index 103b5ecde94a8..8474e4b8c564d 100644 --- a/source/Core/IOHandler.cpp +++ b/source/Core/IOHandler.cpp @@ -67,6 +67,7 @@ #include <assert.h> // for assert #include <ctype.h> // for isspace #include <errno.h> // for EINTR, errno +#include <locale.h> // for setlocale #include <stdint.h> // for uint32_t, UINT32_MAX #include <stdio.h> // for size_t, fprintf, feof #include <string.h> // for strlen @@ -238,27 +239,21 @@ int IOHandlerDelegate::IOHandlerComplete(IOHandler &io_handler, matches); case Completion::Expression: { - bool word_complete = false; - const char *word_start = cursor; - if (cursor > current_line) - --word_start; - while (word_start > current_line && !isspace(*word_start)) - --word_start; + CompletionRequest request(current_line, current_line - cursor, + skip_first_n_matches, max_matches, matches); CommandCompletions::InvokeCommonCompletionCallbacks( io_handler.GetDebugger().GetCommandInterpreter(), - CommandCompletions::eVariablePathCompletion, word_start, - skip_first_n_matches, max_matches, nullptr, word_complete, matches); + CommandCompletions::eVariablePathCompletion, request, nullptr); - size_t num_matches = matches.GetSize(); + size_t num_matches = request.GetMatches().GetSize(); if (num_matches > 0) { std::string common_prefix; - matches.LongestCommonPrefix(common_prefix); - const size_t partial_name_len = strlen(word_start); + request.GetMatches().LongestCommonPrefix(common_prefix); + const size_t partial_name_len = request.GetCursorArgumentPrefix().size(); - // If we matched a unique single command, add a space... - // Only do this if the completer told us this was a complete word, - // however... - if (num_matches == 1 && word_complete) { + // If we matched a unique single command, add a space... Only do this if + // the completer told us this was a complete word, however... + if (num_matches == 1 && request.GetWordComplete()) { common_prefix.push_back(' '); } common_prefix.erase(0, partial_name_len); @@ -320,8 +315,7 @@ IOHandlerEditline::IOHandlerEditline( const char *indent_chars = delegate.IOHandlerGetFixIndentationCharacters(); if (indent_chars) { // The delegate does support indentation, hook it up so when any - // indentation - // character is typed, the delegate gets a chance to fix it + // indentation character is typed, the delegate gets a chance to fix it m_editline_ap->SetFixIndentationCallback(FixIndentationCallback, this, indent_chars); } @@ -407,8 +401,8 @@ bool IOHandlerEditline::GetLine(std::string &line, bool &interrupted) { } } m_editing = false; - // We might have gotten a newline on a line by itself - // make sure to return true in this case. + // We might have gotten a newline on a line by itself make sure to return + // true in this case. return got_line; } else { // No more input file, we are done... @@ -544,9 +538,8 @@ bool IOHandlerEditline::GetLines(StringList &lines, bool &interrupted) { return success; } -// Each IOHandler gets to run until it is done. It should read data -// from the "in" and place output into "out" and "err and return -// when done. +// Each IOHandler gets to run until it is done. It should read data from the +// "in" and place output into "out" and "err and return when done. void IOHandlerEditline::Run() { std::string line; while (IsActive()) { @@ -634,8 +627,7 @@ void IOHandlerEditline::PrintAsync(Stream *stream, const char *s, size_t len) { } } -// we may want curses to be disabled for some builds -// for instance, windows +// we may want curses to be disabled for some builds for instance, windows #ifndef LLDB_DISABLE_CURSES #define KEY_RETURN 10 @@ -737,9 +729,8 @@ struct Rect { origin.y += h; } - // Return a status bar rectangle which is the last line of - // this rectangle. This rectangle will be modified to not - // include the status bar area. + // Return a status bar rectangle which is the last line of this rectangle. + // This rectangle will be modified to not include the status bar area. Rect MakeStatusBar() { Rect status_bar; if (size.height > 1) { @@ -752,9 +743,8 @@ struct Rect { return status_bar; } - // Return a menubar rectangle which is the first line of - // this rectangle. This rectangle will be modified to not - // include the menubar area. + // Return a menubar rectangle which is the first line of this rectangle. This + // rectangle will be modified to not include the menubar area. Rect MakeMenuBar() { Rect menubar; if (size.height > 1) { @@ -1203,12 +1193,10 @@ public: return result; } - // Then check for any windows that want any keys - // that weren't handled. This is typically only - // for a menubar. - // Make a copy of the subwindows in case any HandleChar() - // functions muck with the subwindows. If we don't do this, - // we can crash when iterating over the subwindows. + // Then check for any windows that want any keys that weren't handled. This + // is typically only for a menubar. Make a copy of the subwindows in case + // any HandleChar() functions muck with the subwindows. If we don't do + // this, we can crash when iterating over the subwindows. Windows subwindows(m_subwindows); for (auto subwindow_sp : subwindows) { if (!subwindow_sp->m_can_activate) { @@ -1395,8 +1383,8 @@ public: } MenuActionResult Action() { - // Call the recursive action so it can try to handle it - // with the menu delegate, and if not, try our parent menu + // Call the recursive action so it can try to handle it with the menu + // delegate, and if not, try our parent menu return ActionPrivate(*this); } @@ -1665,9 +1653,9 @@ HandleCharResult Menu::WindowDelegateHandleChar(Window &window, int key) { } if (run_menu_sp) { - // Run the action on this menu in case we need to populate the - // menu with dynamic content and also in case check marks, and - // any other menu decorations need to be calculated + // Run the action on this menu in case we need to populate the menu with + // dynamic content and also in case check marks, and any other menu + // decorations need to be calculated if (run_menu_sp->Action() == MenuActionResult::Quit) return eQuitApplication; @@ -1781,12 +1769,11 @@ public: bool done = false; int delay_in_tenths_of_a_second = 1; - // Alas the threading model in curses is a bit lame so we need to - // resort to polling every 0.5 seconds. We could poll for stdin - // ourselves and then pass the keys down but then we need to - // translate all of the escape sequences ourselves. So we resort to - // polling for input because we need to receive async process events - // while in this loop. + // Alas the threading model in curses is a bit lame so we need to resort to + // polling every 0.5 seconds. We could poll for stdin ourselves and then + // pass the keys down but then we need to translate all of the escape + // sequences ourselves. So we resort to polling for input because we need + // to receive async process events while in this loop. halfdelay(delay_in_tenths_of_a_second); // Poll using some number of tenths // of seconds seconds when calling @@ -1807,9 +1794,9 @@ public: while (!done) { if (update) { m_window_sp->Draw(false); - // All windows should be calling Window::DeferredRefresh() instead - // of Window::Refresh() so we can do a single update and avoid - // any screen blinking + // All windows should be calling Window::DeferredRefresh() instead of + // Window::Refresh() so we can do a single update and avoid any screen + // blinking update_panels(); // Cursor hiding isn't working on MacOSX, so hide it in the top left @@ -1821,8 +1808,8 @@ public: } #if defined(__APPLE__) - // Terminal.app doesn't map its function keys correctly, F1-F4 default to: - // \033OP, \033OQ, \033OR, \033OS, so lets take care of this here if + // Terminal.app doesn't map its function keys correctly, F1-F4 default + // to: \033OP, \033OQ, \033OR, \033OS, so lets take care of this here if // possible int ch; if (escape_chars.empty()) @@ -1985,8 +1972,8 @@ struct Row { parent->DrawTreeForChild(window, this, 0); if (might_have_children) { - // It we can get UTF8 characters to work we should try to use the "symbol" - // UTF8 string below + // It we can get UTF8 characters to work we should try to use the + // "symbol" UTF8 string below // const char *symbol = ""; // if (row.expanded) // symbol = "\xe2\x96\xbd "; @@ -1994,14 +1981,14 @@ struct Row { // symbol = "\xe2\x96\xb7 "; // window.PutCString (symbol); - // The ACS_DARROW and ACS_RARROW don't look very nice they are just a - // 'v' or '>' character... + // The ACS_DARROW and ACS_RARROW don't look very nice they are just a 'v' + // or '>' character... // if (expanded) // window.PutChar (ACS_DARROW); // else // window.PutChar (ACS_RARROW); - // Since we can't find any good looking right arrow/down arrow - // symbols, just use a diamond... + // Since we can't find any good looking right arrow/down arrow symbols, + // just use a diamond... window.PutChar(ACS_DIAMOND); window.PutChar(ACS_HLINE); } @@ -2101,9 +2088,8 @@ public: const bool expanded = IsExpanded(); - // The root item must calculate its children, - // or we must calculate the number of children - // if the item is expanded + // The root item must calculate its children, or we must calculate the + // number of children if the item is expanded if (m_parent == nullptr || expanded) GetNumChildren(); @@ -2136,8 +2122,7 @@ public: if (m_might_have_children) { // It we can get UTF8 characters to work we should try to use the - // "symbol" - // UTF8 string below + // "symbol" UTF8 string below // const char *symbol = ""; // if (row.expanded) // symbol = "\xe2\x96\xbd "; @@ -2151,8 +2136,8 @@ public: // window.PutChar (ACS_DARROW); // else // window.PutChar (ACS_RARROW); - // Since we can't find any good looking right arrow/down arrow - // symbols, just use a diamond... + // Since we can't find any good looking right arrow/down arrow symbols, + // just use a diamond... window.PutChar(ACS_DIAMOND); window.PutChar(ACS_HLINE); } @@ -2175,8 +2160,8 @@ public: if (IsExpanded()) { for (auto &item : m_children) { - // If we displayed all the rows and item.Draw() returns - // false we are done drawing and can exit this for loop + // If we displayed all the rows and item.Draw() returns false we are + // done drawing and can exit this for loop if (!item.Draw(window, first_visible_row, selected_row_idx, row_idx, num_rows_left)) break; @@ -2286,10 +2271,9 @@ public: m_num_rows = 0; m_root.CalculateRowIndexes(m_num_rows); - // If we unexpanded while having something selected our - // total number of rows is less than the num visible rows, - // then make sure we show all the rows by setting the first - // visible row accordingly. + // If we unexpanded while having something selected our total number of + // rows is less than the num visible rows, then make sure we show all the + // rows by setting the first visible row accordingly. if (m_first_visible_row > 0 && m_num_rows < num_visible_rows) m_first_visible_row = 0; @@ -2695,10 +2679,9 @@ public: const int num_visible_rows = NumVisibleRows(); const int num_rows = CalculateTotalNumberRows(m_rows); - // If we unexpanded while having something selected our - // total number of rows is less than the num visible rows, - // then make sure we show all the rows by setting the first - // visible row accordingly. + // If we unexpanded while having something selected our total number of + // rows is less than the num visible rows, then make sure we show all the + // rows by setting the first visible row accordingly. if (m_first_visible_row > 0 && num_rows < num_visible_rows) m_first_visible_row = 0; @@ -2714,8 +2697,8 @@ public: // Get the selected row m_selected_row = GetRowForRowIndex(m_selected_row_idx); - // Keep the cursor on the selected row so the highlight and the cursor - // are always on the same line + // Keep the cursor on the selected row so the highlight and the cursor are + // always on the same line if (m_selected_row) window.MoveCursor(m_selected_row->x, m_selected_row->y); @@ -3127,8 +3110,8 @@ public: if (process && process->IsAlive()) return true; // Don't do any updating if we are running else { - // Update the values with an empty list if there - // is no process or the process isn't alive anymore + // Update the values with an empty list if there is no process or the + // process isn't alive anymore SetValues(value_list); } } @@ -3392,8 +3375,8 @@ HandleCharResult HelpDialogDelegate::WindowDelegateHandleChar(Window &window, if (num_lines <= num_visible_lines) { done = true; - // If we have all lines visible and don't need scrolling, then any - // key press will cause us to exit + // If we have all lines visible and don't need scrolling, then any key + // press will cause us to exit } else { switch (key) { case KEY_UP: @@ -3606,8 +3589,8 @@ public: case eMenuID_Process: { // Populate the menu with all of the threads if the process is stopped - // when - // the Process menu gets selected and is about to display its submenu. + // when the Process menu gets selected and is about to display its + // submenu. Menus &submenus = menu.GetSubmenus(); ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext(); @@ -3642,8 +3625,8 @@ public: nullptr, menu_char, thread_sp->GetID()))); } } else if (submenus.size() > 7) { - // Remove the separator and any other thread submenu items - // that were previously added + // Remove the separator and any other thread submenu items that were + // previously added submenus.erase(submenus.begin() + 7, submenus.end()); } // Since we are adding and removing items we need to recalculate the name @@ -3671,8 +3654,8 @@ public: registers_bounds.size.width = source_bounds.size.width; registers_window_sp->SetBounds(registers_bounds); } else { - // We have no registers window showing so give the bottom - // area back to the source view + // We have no registers window showing so give the bottom area back + // to the source view source_window_sp->Resize(source_bounds.size.width, source_bounds.size.height + variables_bounds.size.height); @@ -3721,8 +3704,8 @@ public: registers_window_sp->GetWidth(), variables_bounds.size.height); } else { - // We have no variables window showing so give the bottom - // area back to the source view + // We have no variables window showing so give the bottom area back + // to the source view source_window_sp->Resize(source_bounds.size.width, source_bounds.size.height + registers_window_sp->GetHeight()); @@ -3731,9 +3714,9 @@ public: } else { Rect new_regs_rect; if (variables_window_sp) { - // We have a variables window, split it into two columns - // where the left hand side will be the variables and the - // right hand side will be the registers + // We have a variables window, split it into two columns where the + // left hand side will be the variables and the right hand side will + // be the registers const Rect variables_bounds = variables_window_sp->GetBounds(); Rect new_vars_rect; variables_bounds.VerticalSplitPercentage(0.50, new_vars_rect, @@ -3945,8 +3928,8 @@ public: m_selected_line = m_pc_line; if (m_file_sp && m_file_sp->FileSpecMatches(m_sc.line_entry.file)) { - // Same file, nothing to do, we should either have the - // lines or not (source file missing) + // Same file, nothing to do, we should either have the lines or not + // (source file missing) if (m_selected_line >= static_cast<size_t>(m_first_visible_line)) { if (m_selected_line >= m_first_visible_line + num_visible_lines) m_first_visible_line = m_selected_line - 10; @@ -4627,8 +4610,8 @@ void IOHandlerCursesGUI::Activate() { WindowSP menubar_window_sp = main_window_sp->CreateSubWindow("Menubar", menubar_bounds, false); - // Let the menubar get keys if the active window doesn't handle the - // keys that are typed so it can respond to menubar key presses. + // Let the menubar get keys if the active window doesn't handle the keys + // that are typed so it can respond to menubar key presses. menubar_window_sp->SetCanBeActive( false); // Don't let the menubar become the active window menubar_window_sp->SetDelegate(menubar_sp); diff --git a/source/Core/Listener.cpp b/source/Core/Listener.cpp index 1afa11649b596..a39ce6121b327 100644 --- a/source/Core/Listener.cpp +++ b/source/Core/Listener.cpp @@ -304,11 +304,9 @@ bool Listener::FindNextEventInternal( if (remove) { m_events.erase(pos); - // Unlock the event queue here. We've removed this event and are about to - // return - // it so it should be okay to get the next event off the queue here - and - // it might - // be useful to do that in the "DoOnRemoval". + // Unlock the event queue here. We've removed this event and are about + // to return it so it should be okay to get the next event off the queue + // here - and it might be useful to do that in the "DoOnRemoval". lock.unlock(); event_sp->DoOnRemoval(); } @@ -434,8 +432,8 @@ Listener::StartListeningForEventSpec(BroadcasterManagerSP manager_sp, if (!manager_sp) return 0; - // The BroadcasterManager mutex must be locked before m_broadcasters_mutex - // to avoid violating the lock hierarchy (manager before broadcasters). + // The BroadcasterManager mutex must be locked before m_broadcasters_mutex to + // avoid violating the lock hierarchy (manager before broadcasters). std::lock_guard<std::recursive_mutex> manager_guard( manager_sp->m_manager_mutex); std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex); diff --git a/source/Core/Mangled.cpp b/source/Core/Mangled.cpp index 211a0c32cee7f..545ac51c870f2 100644 --- a/source/Core/Mangled.cpp +++ b/source/Core/Mangled.cpp @@ -16,34 +16,24 @@ #pragma comment(lib, "dbghelp.lib") #endif -#ifdef LLDB_USE_BUILTIN_DEMANGLER -// Provide a fast-path demangler implemented in FastDemangle.cpp until it can -// replace the existing C++ demangler with a complete implementation -#include "lldb/Utility/FastDemangle.h" -#include "llvm/Demangle/Demangle.h" -#else -// FreeBSD9-STABLE requires this to know about size_t in cxxabi. -#include <cstddef> -#include <cxxabi.h> -#endif - #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Logging.h" #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/Timer.h" -#include "lldb/lldb-enumerations.h" // for LanguageType +#include "lldb/lldb-enumerations.h" #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" -#include "llvm/ADT/StringRef.h" // for StringRef -#include "llvm/Support/Compiler.h" // for LLVM_PRETT... +#include "llvm/ADT/StringRef.h" +#include "llvm/Demangle/Demangle.h" +#include "llvm/Support/Compiler.h" -#include <mutex> // for mutex, loc... -#include <string> // for string -#include <utility> // for pair +#include <mutex> +#include <string> +#include <utility> #include <stdlib.h> #include <string.h> @@ -90,10 +80,8 @@ get_demangled_name_without_arguments(ConstString mangled, g_most_recent_mangled_to_name_sans_args; // Need to have the mangled & demangled names we're currently examining as - // statics - // so we can return a const ref to them at the end of the func if we don't - // have - // anything better. + // statics so we can return a const ref to them at the end of the func if we + // don't have anything better. static ConstString g_last_mangled; static ConstString g_last_demangled; @@ -142,8 +130,8 @@ get_demangled_name_without_arguments(ConstString mangled, Mangled::Mangled() : m_mangled(), m_demangled() {} //---------------------------------------------------------------------- -// Constructor with an optional string and a boolean indicating if it is -// the mangled version. +// Constructor with an optional string and a boolean indicating if it is the +// mangled version. //---------------------------------------------------------------------- Mangled::Mangled(const ConstString &s, bool mangled) : m_mangled(), m_demangled() { @@ -172,8 +160,8 @@ Mangled::Mangled(llvm::StringRef name) { Mangled::~Mangled() {} //---------------------------------------------------------------------- -// Convert to pointer operator. This allows code to check any Mangled -// objects to see if they contain anything valid using code such as: +// Convert to pointer operator. This allows code to check any Mangled objects +// to see if they contain anything valid using code such as: // // Mangled mangled(...); // if (mangled) @@ -184,8 +172,8 @@ Mangled::operator void *() const { } //---------------------------------------------------------------------- -// Logical NOT operator. This allows code to check any Mangled -// objects to see if they are invalid using code such as: +// Logical NOT operator. This allows code to check any Mangled objects to see +// if they are invalid using code such as: // // Mangled mangled(...); // if (!file_spec) @@ -211,9 +199,8 @@ int Mangled::Compare(const Mangled &a, const Mangled &b) { } //---------------------------------------------------------------------- -// Set the string value in this objects. If "mangled" is true, then -// the mangled named is set with the new value in "s", else the -// demangled name is set. +// Set the string value in this objects. If "mangled" is true, then the mangled +// named is set with the new value in "s", else the demangled name is set. //---------------------------------------------------------------------- void Mangled::SetValue(const ConstString &s, bool mangled) { if (s) { @@ -246,16 +233,15 @@ void Mangled::SetValue(const ConstString &name) { } //---------------------------------------------------------------------- -// Generate the demangled name on demand using this accessor. Code in -// this class will need to use this accessor if it wishes to decode -// the demangled name. The result is cached and will be kept until a -// new string value is supplied to this object, or until the end of the -// object's lifetime. +// Generate the demangled name on demand using this accessor. Code in this +// class will need to use this accessor if it wishes to decode the demangled +// name. The result is cached and will be kept until a new string value is +// supplied to this object, or until the end of the object's lifetime. //---------------------------------------------------------------------- const ConstString & Mangled::GetDemangledName(lldb::LanguageType language) const { - // Check to make sure we have a valid mangled name and that we - // haven't already decoded our mangled name. + // Check to make sure we have a valid mangled name and that we haven't + // already decoded our mangled name. if (m_mangled && !m_demangled) { // We need to generate and cache the demangled name. static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); @@ -299,19 +285,15 @@ Mangled::GetDemangledName(lldb::LanguageType language) const { break; } case eManglingSchemeItanium: { -#ifdef LLDB_USE_BUILTIN_DEMANGLER - if (log) - log->Printf("demangle itanium: %s", mangled_name); - // Try to use the fast-path demangler first for the - // performance win, falling back to the full demangler only - // when necessary - demangled_name = FastDemangle(mangled_name, m_mangled.GetLength()); - if (!demangled_name) - demangled_name = - llvm::itaniumDemangle(mangled_name, NULL, NULL, NULL); -#else - demangled_name = abi::__cxa_demangle(mangled_name, NULL, NULL, NULL); -#endif + llvm::ItaniumPartialDemangler IPD; + bool demangle_err = IPD.partialDemangle(mangled_name); + if (!demangle_err) { + // Default buffer and size (realloc is used in case it's too small). + size_t demangled_size = 80; + demangled_name = static_cast<char *>(::malloc(demangled_size)); + demangled_name = IPD.finishDemangle(demangled_name, &demangled_size); + } + if (log) { if (demangled_name) log->Printf("demangled itanium: %s -> \"%s\"", mangled_name, @@ -331,8 +313,8 @@ Mangled::GetDemangledName(lldb::LanguageType language) const { } } if (!m_demangled) { - // Set the demangled string to the empty string to indicate we - // tried to parse it once and failed. + // Set the demangled string to the empty string to indicate we tried to + // parse it once and failed. m_demangled.SetCString(""); } } @@ -370,8 +352,8 @@ ConstString Mangled::GetName(lldb::LanguageType language, return get_demangled_name_without_arguments(m_mangled, demangled); } if (preference == ePreferDemangled) { - // Call the accessor to make sure we get a demangled name in case - // it hasn't been demangled yet... + // Call the accessor to make sure we get a demangled name in case it hasn't + // been demangled yet... if (demangled) return demangled; return m_mangled; @@ -380,8 +362,8 @@ ConstString Mangled::GetName(lldb::LanguageType language, } //---------------------------------------------------------------------- -// Dump a Mangled object to stream "s". We don't force our -// demangled name to be computed currently (we don't use the accessor). +// Dump a Mangled object to stream "s". We don't force our demangled name to be +// computed currently (we don't use the accessor). //---------------------------------------------------------------------- void Mangled::Dump(Stream *s) const { if (m_mangled) { @@ -394,8 +376,8 @@ void Mangled::Dump(Stream *s) const { } //---------------------------------------------------------------------- -// Dumps a debug version of this string with extra object and state -// information to stream "s". +// Dumps a debug version of this string with extra object and state information +// to stream "s". //---------------------------------------------------------------------- void Mangled::DumpDebug(Stream *s) const { s->Printf("%*p: Mangled mangled = ", static_cast<int>(sizeof(void *) * 2), @@ -406,21 +388,21 @@ void Mangled::DumpDebug(Stream *s) const { } //---------------------------------------------------------------------- -// Return the size in byte that this object takes in memory. The size -// includes the size of the objects it owns, and not the strings that -// it references because they are shared strings. +// Return the size in byte that this object takes in memory. The size includes +// the size of the objects it owns, and not the strings that it references +// because they are shared strings. //---------------------------------------------------------------------- size_t Mangled::MemorySize() const { return m_mangled.MemorySize() + m_demangled.MemorySize(); } //---------------------------------------------------------------------- -// We "guess" the language because we can't determine a symbol's language -// from it's name. For example, a Pascal symbol can be mangled using the -// C++ Itanium scheme, and defined in a compilation unit within the same -// module as other C++ units. In addition, different targets could have -// different ways of mangling names from a given language, likewise the -// compilation units within those targets. +// We "guess" the language because we can't determine a symbol's language from +// it's name. For example, a Pascal symbol can be mangled using the C++ +// Itanium scheme, and defined in a compilation unit within the same module as +// other C++ units. In addition, different targets could have different ways +// of mangling names from a given language, likewise the compilation units +// within those targets. //---------------------------------------------------------------------- lldb::LanguageType Mangled::GuessLanguage() const { ConstString mangled = GetMangledName(); @@ -433,7 +415,7 @@ lldb::LanguageType Mangled::GuessLanguage() const { return lldb::eLanguageTypeObjC; } } else { - // ObjC names aren't really mangled, so they won't necessarily be in the + // ObjC names aren't really mangled, so they won't necessarily be in the // mangled name slot. ConstString demangled_name = GetDemangledName(lldb::eLanguageTypeUnknown); if (demangled_name diff --git a/source/Core/Module.cpp b/source/Core/Module.cpp index 8f80be45f1b06..3b1a4fd7be0f3 100644 --- a/source/Core/Module.cpp +++ b/source/Core/Module.cpp @@ -38,6 +38,7 @@ #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Logging.h" // for GetLogIfAn... #include "lldb/Utility/RegularExpression.h" @@ -46,13 +47,12 @@ #include "lldb/Utility/StreamString.h" #include "lldb/Utility/Timer.h" -#if defined(LLVM_ON_WIN32) +#if defined(_WIN32) #include "lldb/Host/windows/PosixApi.h" // for PATH_MAX #endif #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" -#include "Plugins/ObjectFile/JIT/ObjectFileJIT.h" #include "llvm/ADT/STLExtras.h" // for make_unique #include "llvm/Support/Compiler.h" // for LLVM_PRETT... @@ -79,21 +79,17 @@ class VariableList; using namespace lldb; using namespace lldb_private; -// Shared pointers to modules track module lifetimes in -// targets and in the global module, but this collection -// will track all module objects that are still alive +// Shared pointers to modules track module lifetimes in targets and in the +// global module, but this collection will track all module objects that are +// still alive typedef std::vector<Module *> ModuleCollection; static ModuleCollection &GetModuleCollection() { // This module collection needs to live past any module, so we could either - // make it a - // shared pointer in each module or just leak is. Since it is only an empty - // vector by - // the time all the modules have gone away, we just leak it for now. If we - // decide this - // is a big problem we can introduce a Finalize method that will tear - // everything down in - // a predictable order. + // make it a shared pointer in each module or just leak is. Since it is only + // an empty vector by the time all the modules have gone away, we just leak + // it for now. If we decide this is a big problem we can introduce a + // Finalize method that will tear everything down in a predictable order. static ModuleCollection *g_module_collection = nullptr; if (g_module_collection == nullptr) @@ -104,9 +100,9 @@ static ModuleCollection &GetModuleCollection() { std::recursive_mutex &Module::GetAllocationModuleCollectionMutex() { // NOTE: The mutex below must be leaked since the global module list in - // the ModuleList class will get torn at some point, and we can't know - // if it will tear itself down before the "g_module_collection_mutex" below - // will. So we leak a Mutex object below to safeguard against that + // the ModuleList class will get torn at some point, and we can't know if it + // will tear itself down before the "g_module_collection_mutex" below will. + // So we leak a Mutex object below to safeguard against that static std::recursive_mutex *g_module_collection_mutex = nullptr; if (g_module_collection_mutex == nullptr) @@ -151,8 +147,8 @@ Module::Module(const ModuleSpec &module_spec) : module_spec.GetObjectName().AsCString(""), module_spec.GetObjectName().IsEmpty() ? "" : ")"); - // First extract all module specifications from the file using the local - // file path. If there are no specifications, then don't fill anything in + // First extract all module specifications from the file using the local file + // path. If there are no specifications, then don't fill anything in ModuleSpecList modules_specs; if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0, modules_specs) == 0) @@ -160,9 +156,8 @@ Module::Module(const ModuleSpec &module_spec) // Now make sure that one of the module specifications matches what we just // extract. We might have a module specification that specifies a file - // "/usr/lib/dyld" - // with UUID XXX, but we might have a local version of "/usr/lib/dyld" that - // has + // "/usr/lib/dyld" with UUID XXX, but we might have a local version of + // "/usr/lib/dyld" that has // UUID YYY and we don't want those to match. If they don't match, just don't // fill any ivars in so we don't accidentally grab the wrong file later since // they don't match... @@ -177,8 +172,8 @@ Module::Module(const ModuleSpec &module_spec) m_mod_time = FileSystem::GetModificationTime(matching_module_spec.GetFileSpec()); - // Copy the architecture from the actual spec if we got one back, else use the - // one that was specified + // Copy the architecture from the actual spec if we got one back, else use + // the one that was specified if (matching_module_spec.GetArchitecture().IsValid()) m_arch = matching_module_spec.GetArchitecture(); else if (module_spec.GetArchitecture().IsValid()) @@ -210,9 +205,9 @@ Module::Module(const ModuleSpec &module_spec) else m_object_name = module_spec.GetObjectName(); - // Always trust the object offset (file offset) and object modification - // time (for mod time in a BSD static archive) of from the matching - // module specification + // Always trust the object offset (file offset) and object modification time + // (for mod time in a BSD static archive) of from the matching module + // specification m_object_offset = matching_module_spec.GetObjectOffset(); m_object_mod_time = matching_module_spec.GetObjectModificationTime(); } @@ -253,8 +248,8 @@ Module::Module() } Module::~Module() { - // Lock our module down while we tear everything down to make sure - // we don't get any access to the module while it is being destroyed + // Lock our module down while we tear everything down to make sure we don't + // get any access to the module while it is being destroyed std::lock_guard<std::recursive_mutex> guard(m_mutex); // Scope for locker below... { @@ -308,9 +303,8 @@ ObjectFile *Module::GetMemoryObjectFile(const lldb::ProcessSP &process_sp, m_object_name.SetString(s.GetString()); // Once we get the object file, update our module with the object - // file's - // architecture since it might differ in vendor/os if some parts were - // unknown. + // file's architecture since it might differ in vendor/os if some + // parts were unknown. m_objfile_sp->GetArchitecture(m_arch); } else { error.SetErrorString("unable to find suitable object file plug-in"); @@ -327,20 +321,30 @@ ObjectFile *Module::GetMemoryObjectFile(const lldb::ProcessSP &process_sp, } const lldb_private::UUID &Module::GetUUID() { - if (!m_did_parse_uuid.load()) { + if (!m_did_set_uuid.load()) { std::lock_guard<std::recursive_mutex> guard(m_mutex); - if (!m_did_parse_uuid.load()) { + if (!m_did_set_uuid.load()) { ObjectFile *obj_file = GetObjectFile(); if (obj_file != nullptr) { obj_file->GetUUID(&m_uuid); - m_did_parse_uuid = true; + m_did_set_uuid = true; } } } return m_uuid; } +void Module::SetUUID(const lldb_private::UUID &uuid) { + std::lock_guard<std::recursive_mutex> guard(m_mutex); + if (!m_did_set_uuid) { + m_uuid = uuid; + m_did_set_uuid = true; + } else { + lldbassert(0 && "Attempting to overwrite the existing module UUID"); + } +} + TypeSystem *Module::GetTypeSystemForLanguage(LanguageType language) { return m_type_system_map.GetTypeSystemForLanguage(language, this, true); } @@ -441,8 +445,8 @@ uint32_t Module::ResolveSymbolContextForAddress( // Make sure the section matches this module before we try and match anything if (section_sp && section_sp->GetModule().get() == this) { - // If the section offset based address resolved itself, then this - // is the right module. + // If the section offset based address resolved itself, then this is the + // right module. sc.module_sp = shared_from_this(); resolved_flags |= eSymbolContextModule; @@ -450,8 +454,8 @@ uint32_t Module::ResolveSymbolContextForAddress( if (!sym_vendor) return resolved_flags; - // Resolve the compile unit, function, block, line table or line - // entry if requested. + // Resolve the compile unit, function, block, line table or line entry if + // requested. if (resolve_scope & eSymbolContextCompUnit || resolve_scope & eSymbolContextFunction || resolve_scope & eSymbolContextBlock || @@ -461,8 +465,8 @@ uint32_t Module::ResolveSymbolContextForAddress( sym_vendor->ResolveSymbolContext(so_addr, resolve_scope, sc); } - // Resolve the symbol if requested, but don't re-look it up if we've already - // found it. + // Resolve the symbol if requested, but don't re-look it up if we've + // already found it. if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol)) { Symtab *symtab = sym_vendor->GetSymtab(); @@ -491,12 +495,11 @@ uint32_t Module::ResolveSymbolContextForAddress( if (sc.symbol) { if (sc.symbol->IsSynthetic()) { - // We have a synthetic symbol so lets check if the object file - // from the symbol file in the symbol vendor is different than - // the object file for the module, and if so search its symbol - // table to see if we can come up with a better symbol. For example - // dSYM files on MacOSX have an unstripped symbol table inside of - // them. + // We have a synthetic symbol so lets check if the object file from + // the symbol file in the symbol vendor is different than the + // object file for the module, and if so search its symbol table to + // see if we can come up with a better symbol. For example dSYM + // files on MacOSX have an unstripped symbol table inside of them. ObjectFile *symtab_objfile = symtab->GetObjectFile(); if (symtab_objfile && symtab_objfile->IsStripped()) { SymbolFile *symfile = sym_vendor->GetSymbolFile(); @@ -522,10 +525,8 @@ uint32_t Module::ResolveSymbolContextForAddress( } // For function symbols, so_addr may be off by one. This is a convention - // consistent - // with FDE row indices in eh_frame sections, but requires extra logic here - // to permit - // symbol lookup for disassembly and unwind. + // consistent with FDE row indices in eh_frame sections, but requires extra + // logic here to permit symbol lookup for disassembly and unwind. if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol) && resolve_tail_call_address && so_addr.IsSectionOffset()) { @@ -542,10 +543,9 @@ uint32_t Module::ResolveSymbolContextForAddress( if (addr_range.GetBaseAddress().GetSection() == so_addr.GetSection()) { // If the requested address is one past the address range of a - // function (i.e. a tail call), - // or the decremented address is the start of a function (i.e. some - // forms of trampoline), - // indicate that the symbol has been resolved. + // function (i.e. a tail call), or the decremented address is the + // start of a function (i.e. some forms of trampoline), indicate + // that the symbol has been resolved. if (so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() || so_addr.GetOffset() == @@ -599,21 +599,21 @@ uint32_t Module::ResolveSymbolContextsForFileSpec(const FileSpec &file_spec, size_t Module::FindGlobalVariables(const ConstString &name, const CompilerDeclContext *parent_decl_ctx, - bool append, size_t max_matches, + size_t max_matches, VariableList &variables) { SymbolVendor *symbols = GetSymbolVendor(); if (symbols) - return symbols->FindGlobalVariables(name, parent_decl_ctx, append, - max_matches, variables); + return symbols->FindGlobalVariables(name, parent_decl_ctx, max_matches, + variables); return 0; } -size_t Module::FindGlobalVariables(const RegularExpression ®ex, bool append, +size_t Module::FindGlobalVariables(const RegularExpression ®ex, size_t max_matches, VariableList &variables) { SymbolVendor *symbols = GetSymbolVendor(); if (symbols) - return symbols->FindGlobalVariables(regex, append, max_matches, variables); + return symbols->FindGlobalVariables(regex, max_matches, variables); return 0; } @@ -677,25 +677,22 @@ Module::LookupInfo::LookupInfo(const ConstString &name, uint32_t name_type_mask, if (name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase) { // If they've asked for a CPP method or function name and it can't be - // that, we don't - // even need to search for CPP methods or names. + // that, we don't even need to search for CPP methods or names. CPlusPlusLanguage::MethodName cpp_method(name); if (cpp_method.IsValid()) { basename = cpp_method.GetBasename(); if (!cpp_method.GetQualifiers().empty()) { // There is a "const" or other qualifier following the end of the - // function parens, - // this can't be a eFunctionNameTypeBase + // function parens, this can't be a eFunctionNameTypeBase m_name_type_mask &= ~(eFunctionNameTypeBase); if (m_name_type_mask == eFunctionNameTypeNone) return; } } else { // If the CPP method parser didn't manage to chop this up, try to fill - // in the base name if we can. - // If a::b::c is passed in, we need to just look up "c", and then we'll - // filter the result later. + // in the base name if we can. If a::b::c is passed in, we need to just + // look up "c", and then we'll filter the result later. CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context, basename); } @@ -724,19 +721,15 @@ Module::LookupInfo::LookupInfo(const ConstString &name, uint32_t name_type_mask, } if (!basename.empty()) { - // The name supplied was a partial C++ path like "a::count". In this case we - // want to do a - // lookup on the basename "count" and then make sure any matching results - // contain "a::count" - // so that it would match "b::a::count" and "a::count". This is why we set - // "match_name_after_lookup" - // to true + // The name supplied was a partial C++ path like "a::count". In this case + // we want to do a lookup on the basename "count" and then make sure any + // matching results contain "a::count" so that it would match "b::a::count" + // and "a::count". This is why we set "match_name_after_lookup" to true m_lookup_name.SetString(basename); m_match_name_after_lookup = true; } else { // The name is already correct, just use the exact name as supplied, and we - // won't need - // to check if any matches contain "name" + // won't need to check if any matches contain "name" m_lookup_name = name; m_match_name_after_lookup = false; } @@ -770,8 +763,8 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list, while (i < sc_list.GetSize()) { if (!sc_list.GetContextAtIndex(i, sc)) break; - // Make sure the mangled and demangled names don't match before we try - // to pull anything out + // Make sure the mangled and demangled names don't match before we try to + // pull anything out ConstString mangled_name(sc.GetFunctionName(Mangled::ePreferMangled)); ConstString full_name(sc.GetFunctionName()); if (mangled_name != m_name && full_name != m_name) @@ -867,7 +860,8 @@ size_t Module::FindFunctions(const RegularExpression ®ex, if (symbols) { symbols->FindFunctions(regex, include_inlines, append, sc_list); - // Now check our symbol table for symbols that are code symbols if requested + // Now check our symbol table for symbols that are code symbols if + // requested if (include_symbols) { Symtab *symtab = symbols->GetSymtab(); if (symtab) { @@ -882,7 +876,8 @@ size_t Module::FindFunctions(const RegularExpression ®ex, size_t num_functions_added_to_sc_list = end_functions_added_index - start_size; if (num_functions_added_to_sc_list == 0) { - // No functions were added, just symbols, so we can just append them + // No functions were added, just symbols, so we can just append + // them for (size_t i = 0; i < num_matches; ++i) { sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]); SymbolType sym_type = sc.symbol->GetType(); @@ -1001,6 +996,7 @@ size_t Module::FindTypes( const bool append = true; TypeClass type_class = eTypeClassAny; TypeMap typesmap; + if (Type::GetTypeScopeAndBasename(type_name_cstr, type_scope, type_basename, type_class)) { // Check if "name" starts with "::" which means the qualified type starts @@ -1019,17 +1015,23 @@ size_t Module::FindTypes( } else { // The type is not in a namespace/class scope, just search for it by // basename - if (type_class != eTypeClassAny) { + if (type_class != eTypeClassAny && !type_basename.empty()) { // The "type_name_cstr" will have been modified if we have a valid type - // class - // prefix (like "struct", "class", "union", "typedef" etc). + // class prefix (like "struct", "class", "union", "typedef" etc). FindTypes_Impl(sc, ConstString(type_basename), nullptr, append, - max_matches, searched_symbol_files, typesmap); - typesmap.RemoveMismatchedTypes(type_class); + UINT_MAX, searched_symbol_files, typesmap); + typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class, + exact_match); num_matches = typesmap.GetSize(); } else { - num_matches = FindTypes_Impl(sc, name, nullptr, append, max_matches, + num_matches = FindTypes_Impl(sc, name, nullptr, append, UINT_MAX, searched_symbol_files, typesmap); + if (exact_match) { + std::string name_str(name.AsCString("")); + typesmap.RemoveMismatchedTypes(type_scope, name_str, type_class, + exact_match); + num_matches = typesmap.GetSize(); + } } } if (num_matches > 0) @@ -1057,8 +1059,8 @@ SymbolVendor *Module::GetSymbolVendor(bool can_create, void Module::SetFileSpecAndObjectName(const FileSpec &file, const ConstString &object_name) { - // Container objects whose paths do not specify a file directly can call - // this function to correct the file and object names. + // Container objects whose paths do not specify a file directly can call this + // function to correct the file and object names. m_file = file; m_mod_time = FileSystem::GetModificationTime(file); m_object_name = object_name; @@ -1258,12 +1260,10 @@ ObjectFile *Module::GetObjectFile() { file_size - m_object_offset, data_sp, data_offset); if (m_objfile_sp) { // Once we get the object file, update our module with the object - // file's - // architecture since it might differ in vendor/os if some parts were - // unknown. But since the matching arch might already be more - // specific - // than the generic COFF architecture, only merge in those values that - // overwrite unspecified unknown values. + // file's architecture since it might differ in vendor/os if some + // parts were unknown. But since the matching arch might already be + // more specific than the generic COFF architecture, only merge in + // those values that overwrite unspecified unknown values. ArchSpec new_arch; m_objfile_sp->GetArchitecture(new_arch); m_arch.MergeFrom(new_arch); @@ -1278,7 +1278,7 @@ ObjectFile *Module::GetObjectFile() { } SectionList *Module::GetSectionList() { - // Populate m_unified_sections_ap with sections from objfile. + // Populate m_sections_ap with sections from objfile. if (!m_sections_ap) { ObjectFile *obj_file = GetObjectFile(); if (obj_file != nullptr) @@ -1297,7 +1297,6 @@ void Module::SectionFileAddressesChanged() { } SectionList *Module::GetUnifiedSectionList() { - // Populate m_unified_sections_ap with sections from objfile. if (!m_sections_ap) m_sections_ap = llvm::make_unique<SectionList>(); return m_sections_ap.get(); @@ -1428,9 +1427,8 @@ void Module::SetSymbolFileFileSpec(const FileSpec &file) { if (section_list && symbol_file) { ObjectFile *obj_file = symbol_file->GetObjectFile(); // Make sure we have an object file and that the symbol vendor's objfile - // isn't - // the same as the module's objfile before we remove any sections for - // it... + // isn't the same as the module's objfile before we remove any sections + // for it... if (obj_file) { // Check to make sure we aren't trying to specify the file we already // have @@ -1445,8 +1443,7 @@ void Module::SetSymbolFileFileSpec(const FileSpec &file) { obj_file->ClearSymtab(); // The symbol file might be a directory bundle ("/tmp/a.out.dSYM") - // instead - // of a full path to the symbol file within the bundle + // instead of a full path to the symbol file within the bundle // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to // check this @@ -1473,8 +1470,7 @@ void Module::SetSymbolFileFileSpec(const FileSpec &file) { } } // Keep all old symbol files around in case there are any lingering type - // references in - // any SBValue objects that might have been handed out. + // references in any SBValue objects that might have been handed out. m_old_symfiles.push_back(std::move(m_symfile_ap)); } m_symfile_spec = file; @@ -1644,37 +1640,10 @@ bool Module::RemapSourceFile(llvm::StringRef path, return m_source_mappings.RemapPath(path, new_path); } -uint32_t Module::GetVersion(uint32_t *versions, uint32_t num_versions) { - ObjectFile *obj_file = GetObjectFile(); - if (obj_file) - return obj_file->GetVersion(versions, num_versions); - - if (versions != nullptr && num_versions != 0) { - for (uint32_t i = 0; i < num_versions; ++i) - versions[i] = LLDB_INVALID_MODULE_VERSION; - } - return 0; -} - -ModuleSP -Module::CreateJITModule(const lldb::ObjectFileJITDelegateSP &delegate_sp) { - if (delegate_sp) { - // Must create a module and place it into a shared pointer before - // we can create an object file since it has a std::weak_ptr back - // to the module, so we need to control the creation carefully in - // this static function - ModuleSP module_sp(new Module()); - module_sp->m_objfile_sp = - std::make_shared<ObjectFileJIT>(module_sp, delegate_sp); - if (module_sp->m_objfile_sp) { - // Once we get the object file, update our module with the object file's - // architecture since it might differ in vendor/os if some parts were - // unknown. - module_sp->m_objfile_sp->GetArchitecture(module_sp->m_arch); - } - return module_sp; - } - return ModuleSP(); +llvm::VersionTuple Module::GetVersion() { + if (ObjectFile *obj_file = GetObjectFile()) + return obj_file->GetVersion(); + return llvm::VersionTuple(); } bool Module::GetIsDynamicLinkEditor() { @@ -1685,7 +1654,3 @@ bool Module::GetIsDynamicLinkEditor() { return false; } - -Status Module::LoadInMemory(Target &target, bool set_pc) { - return m_objfile_sp->LoadInMemory(target, set_pc); -} diff --git a/source/Core/ModuleList.cpp b/source/Core/ModuleList.cpp index 3970052b7bf3f..d2896da1adcaf 100644 --- a/source/Core/ModuleList.cpp +++ b/source/Core/ModuleList.cpp @@ -13,6 +13,9 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Symbols.h" +#include "lldb/Interpreter/OptionValueProperties.h" +#include "lldb/Interpreter/OptionValueFileSpec.h" +#include "lldb/Interpreter/Property.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolContext.h" // for SymbolContextList, SymbolCon... #include "lldb/Symbol/VariableList.h" @@ -23,7 +26,7 @@ #include "lldb/Utility/UUID.h" // for UUID, operator!=, operator== #include "lldb/lldb-defines.h" // for LLDB_INVALID_INDEX32 -#if defined(LLVM_ON_WIN32) +#if defined(_WIN32) #include "lldb/Host/windows/PosixApi.h" // for PATH_MAX #endif @@ -31,6 +34,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" // for fs +#include "clang/Driver/Driver.h" #include <chrono> // for operator!=, time_point #include <memory> // for shared_ptr @@ -60,6 +64,51 @@ class TypeList; using namespace lldb; using namespace lldb_private; +namespace { + +PropertyDefinition g_properties[] = { + {"enable-external-lookup", OptionValue::eTypeBoolean, true, true, nullptr, + nullptr, + "Control the use of external tools or libraries to locate symbol files. " + "On macOS, Spotlight is used to locate a matching .dSYM bundle based on " + "the UUID of the executable."}, + {"clang-modules-cache-path", OptionValue::eTypeFileSpec, true, 0, nullptr, + nullptr, + "The path to the clang modules cache directory (-fmodules-cache-path)."}, + {nullptr, OptionValue::eTypeInvalid, false, 0, nullptr, nullptr, nullptr}}; + +enum { ePropertyEnableExternalLookup, ePropertyClangModulesCachePath }; + +} // namespace + +ModuleListProperties::ModuleListProperties() { + m_collection_sp.reset(new OptionValueProperties(ConstString("symbols"))); + m_collection_sp->Initialize(g_properties); + + llvm::SmallString<128> path; + clang::driver::Driver::getDefaultModuleCachePath(path); + SetClangModulesCachePath(path); +} + +bool ModuleListProperties::GetEnableExternalLookup() const { + const uint32_t idx = ePropertyEnableExternalLookup; + return m_collection_sp->GetPropertyAtIndexAsBoolean( + nullptr, idx, g_properties[idx].default_uint_value != 0); +} + +FileSpec ModuleListProperties::GetClangModulesCachePath() const { + return m_collection_sp + ->GetPropertyAtIndexAsOptionValueFileSpec(nullptr, false, + ePropertyClangModulesCachePath) + ->GetCurrentValue(); +} + +bool ModuleListProperties::SetClangModulesCachePath(llvm::StringRef path) { + return m_collection_sp->SetPropertyAtIndexAsString( + nullptr, ePropertyClangModulesCachePath, path); +} + + ModuleList::ModuleList() : m_modules(), m_modules_mutex(), m_notifier(nullptr) {} @@ -83,8 +132,8 @@ const ModuleList &ModuleList::operator=(const ModuleList &rhs) { // in thread A: | in thread B: // x = y; | y = x; // - // This establishes correct(same) lock taking order and thus - // avoids priority inversion. + // This establishes correct(same) lock taking order and thus avoids + // priority inversion. if (uintptr_t(this) > uintptr_t(&rhs)) { std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex); std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex); @@ -383,27 +432,26 @@ size_t ModuleList::FindCompileUnits(const FileSpec &path, bool append, return sc_list.GetSize(); } -size_t ModuleList::FindGlobalVariables(const ConstString &name, bool append, +size_t ModuleList::FindGlobalVariables(const ConstString &name, size_t max_matches, VariableList &variable_list) const { size_t initial_size = variable_list.GetSize(); std::lock_guard<std::recursive_mutex> guard(m_modules_mutex); collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) { - (*pos)->FindGlobalVariables(name, nullptr, append, max_matches, - variable_list); + (*pos)->FindGlobalVariables(name, nullptr, max_matches, variable_list); } return variable_list.GetSize() - initial_size; } size_t ModuleList::FindGlobalVariables(const RegularExpression ®ex, - bool append, size_t max_matches, + size_t max_matches, VariableList &variable_list) const { size_t initial_size = variable_list.GetSize(); std::lock_guard<std::recursive_mutex> guard(m_modules_mutex); collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) { - (*pos)->FindGlobalVariables(regex, append, max_matches, variable_list); + (*pos)->FindGlobalVariables(regex, max_matches, variable_list); } return variable_list.GetSize() - initial_size; } @@ -496,8 +544,8 @@ ModuleList::FindTypes(const SymbolContext &sc, const ConstString &name, size_t total_matches = 0; collection::const_iterator pos, end = m_modules.end(); if (sc.module_sp) { - // The symbol context "sc" contains a module so we want to search that - // one first if it is in our list... + // The symbol context "sc" contains a module so we want to search that one + // first if it is in our list... for (pos = m_modules.begin(); pos != end; ++pos) { if (sc.module_sp.get() == (*pos).get()) { total_matches += @@ -514,8 +562,8 @@ ModuleList::FindTypes(const SymbolContext &sc, const ConstString &name, SymbolContext world_sc; for (pos = m_modules.begin(); pos != end; ++pos) { // Search the module if the module is not equal to the one in the symbol - // context "sc". If "sc" contains a empty module shared pointer, then - // the comparison will always be true (valid_module_ptr != nullptr). + // context "sc". If "sc" contains a empty module shared pointer, then the + // comparison will always be true (valid_module_ptr != nullptr). if (sc.module_sp.get() != (*pos).get()) total_matches += (*pos)->FindTypes(world_sc, name, name_is_fully_qualified, @@ -673,17 +721,32 @@ size_t ModuleList::GetIndexForModule(const Module *module) const { return LLDB_INVALID_INDEX32; } -static ModuleList &GetSharedModuleList() { - static ModuleList *g_shared_module_list = nullptr; +namespace { +struct SharedModuleListInfo { + ModuleList module_list; + ModuleListProperties module_list_properties; +}; +} +static SharedModuleListInfo &GetSharedModuleListInfo() +{ + static SharedModuleListInfo *g_shared_module_list_info = nullptr; static llvm::once_flag g_once_flag; llvm::call_once(g_once_flag, []() { // NOTE: Intentionally leak the module list so a program doesn't have to // cleanup all modules and object files as it exits. This just wastes time // doing a bunch of cleanup that isn't required. - if (g_shared_module_list == nullptr) - g_shared_module_list = new ModuleList(); // <--- Intentional leak!!! + if (g_shared_module_list_info == nullptr) + g_shared_module_list_info = new SharedModuleListInfo(); }); - return *g_shared_module_list; + return *g_shared_module_list_info; +} + +static ModuleList &GetSharedModuleList() { + return GetSharedModuleListInfo().module_list; +} + +ModuleListProperties &ModuleList::GetGlobalModuleListProperties() { + return GetSharedModuleListInfo().module_list_properties; } bool ModuleList::ModuleIsInCache(const Module *module_ptr) { @@ -727,8 +790,8 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec, const ArchSpec &arch = module_spec.GetArchitecture(); // Make sure no one else can try and get or create a module while this - // function is actively working on it by doing an extra lock on the - // global mutex list. + // function is actively working on it by doing an extra lock on the global + // mutex list. if (!always_create) { ModuleList matching_module_list; const size_t num_matching_modules = @@ -751,8 +814,8 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec, shared_module_list.Remove(module_sp); module_sp.reset(); } else { - // The module matches and the module was not modified from - // when it was last loaded. + // The module matches and the module was not modified from when it + // was last loaded. return error; } } @@ -763,12 +826,12 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec, return error; module_sp.reset(new Module(module_spec)); - // Make sure there are a module and an object file since we can specify - // a valid file path with an architecture that might not be in that file. - // By getting the object file we can guarantee that the architecture matches + // Make sure there are a module and an object file since we can specify a + // valid file path with an architecture that might not be in that file. By + // getting the object file we can guarantee that the architecture matches if (module_sp->GetObjectFile()) { - // If we get in here we got the correct arch, now we just need - // to verify the UUID if one was given + // If we get in here we got the correct arch, now we just need to verify + // the UUID if one was given if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) { module_sp.reset(); } else { @@ -807,8 +870,8 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec, resolved_module_spec.GetFileSpec() = search_path_spec; module_sp.reset(new Module(resolved_module_spec)); if (module_sp->GetObjectFile()) { - // If we get in here we got the correct arch, now we just need - // to verify the UUID if one was given + // If we get in here we got the correct arch, now we just need to + // verify the UUID if one was given if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) { module_sp.reset(); } else { @@ -833,8 +896,8 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec, // we now have to use more extreme measures to try and find the appropriate // module. - // Fixup the incoming path in case the path points to a valid file, yet - // the arch or UUID (if one was passed in) don't match. + // Fixup the incoming path in case the path points to a valid file, yet the + // arch or UUID (if one was passed in) don't match. ModuleSpec located_binary_modulespec = Symbols::LocateExecutableObjectFile(module_spec); @@ -871,8 +934,8 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec, } // Make sure no one else can try and get or create a module while this - // function is actively working on it by doing an extra lock on the - // global mutex list. + // function is actively working on it by doing an extra lock on the global + // mutex list. ModuleSpec platform_module_spec(module_spec); platform_module_spec.GetFileSpec() = located_binary_modulespec.GetFileSpec(); @@ -903,8 +966,8 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec, if (!module_sp) { module_sp.reset(new Module(platform_module_spec)); - // Make sure there are a module and an object file since we can specify - // a valid file path with an architecture that might not be in that file. + // Make sure there are a module and an object file since we can specify a + // valid file path with an architecture that might not be in that file. // By getting the object file we can guarantee that the architecture // matches if (module_sp && module_sp->GetObjectFile()) { diff --git a/source/Core/Opcode.cpp b/source/Core/Opcode.cpp index b4e691c1ddcd8..d15fdb3b17be5 100644 --- a/source/Core/Opcode.cpp +++ b/source/Core/Opcode.cpp @@ -52,8 +52,8 @@ int Opcode::Dump(Stream *s, uint32_t min_byte_width) { break; } - // Add spaces to make sure bytes dispay comes out even in case opcodes - // aren't all the same size + // Add spaces to make sure bytes dispay comes out even in case opcodes aren't + // all the same size if (static_cast<uint32_t>(bytes_written) < min_byte_width) bytes_written = s->Printf("%*s", min_byte_width - bytes_written, ""); return bytes_written; diff --git a/source/Core/PluginManager.cpp b/source/Core/PluginManager.cpp index a49fbc3f90fef..55affb6a10306 100644 --- a/source/Core/PluginManager.cpp +++ b/source/Core/PluginManager.cpp @@ -17,7 +17,7 @@ #include "lldb/Utility/Status.h" #include "lldb/Utility/StringList.h" // for StringList -#if defined(LLVM_ON_WIN32) +#if defined(_WIN32) #include "lldb/Host/windows/PosixApi.h" // for PATH_MAX #endif @@ -96,8 +96,8 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, Status error; 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 + // 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 (ft == fs::file_type::regular_file || ft == fs::file_type::symlink_file || @@ -128,17 +128,14 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, plugin_info.library.getAddressOfSymbol("LLDBPluginTerminate")); } else { // The initialize function returned FALSE which means the plug-in - // might not be - // compatible, or might be too new or too old, or might not want to - // run on this - // machine. Set it to a default-constructed instance to invalidate - // it. + // might not be compatible, or might be too new or too old, or might + // not want to run on this machine. Set it to a default-constructed + // instance to invalidate it. plugin_info = PluginInfo(); } - // Regardless of success or failure, cache the plug-in load - // in our plug-in info so we don't try to load it again and - // again. + // Regardless of success or failure, cache the plug-in load in our + // plug-in info so we don't try to load it again and again. SetPluginInfo(plugin_file_spec, plugin_info); return FileSpec::eEnumerateDirectoryResultNext; @@ -148,9 +145,9 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, 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 + // 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 // information. return FileSpec::eEnumerateDirectoryResultEnter; } @@ -160,19 +157,18 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft, void PluginManager::Initialize() { #if 1 - FileSpec dir_spec; const bool find_directories = true; const bool find_files = true; const bool find_other = true; char dir_path[PATH_MAX]; - if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec)) { + if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) { if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, find_other, LoadPluginCallback, nullptr); } } - if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec)) { + if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) { if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) { FileSpec::EnumerateDirectory(dir_path, find_directories, find_files, find_other, LoadPluginCallback, nullptr); @@ -187,8 +183,8 @@ void PluginManager::Terminate() { PluginTerminateMap::const_iterator pos, end = plugin_map.end(); for (pos = plugin_map.begin(); pos != end; ++pos) { - // Call the plug-in "void LLDBPluginTerminate (void)" function if there - // is one (if the symbol was not nullptr). + // Call the plug-in "void LLDBPluginTerminate (void)" function if there is + // one (if the symbol was not nullptr). if (pos->second.library.isValid()) { if (pos->second.plugin_term_callback) pos->second.plugin_term_callback(); @@ -2397,8 +2393,8 @@ static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPlugins( } // This is deprecated way to register plugin specific settings. e.g. -// "<plugin_type_name>.plugin.<plugin_type_desc>.SETTINGNAME" -// and Platform generic settings would be under "platform.SETTINGNAME". +// "<plugin_type_name>.plugin.<plugin_type_desc>.SETTINGNAME" and Platform +// generic settings would be under "platform.SETTINGNAME". static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle( Debugger &debugger, const ConstString &plugin_type_name, const ConstString &plugin_type_desc, bool can_create) { diff --git a/source/Core/RegisterValue.cpp b/source/Core/RegisterValue.cpp index f64c14019cc62..4f908609dde9d 100644 --- a/source/Core/RegisterValue.cpp +++ b/source/Core/RegisterValue.cpp @@ -9,9 +9,8 @@ #include "lldb/Core/RegisterValue.h" -#include "lldb/Core/DumpDataExtractor.h" #include "lldb/Core/Scalar.h" -#include "lldb/Interpreter/Args.h" +#include "lldb/Utility/Args.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/Stream.h" @@ -34,67 +33,6 @@ using namespace lldb; using namespace lldb_private; -bool RegisterValue::Dump(Stream *s, const RegisterInfo *reg_info, - bool prefix_with_name, bool prefix_with_alt_name, - Format format, - uint32_t reg_name_right_align_at) const { - DataExtractor data; - if (GetData(data)) { - bool name_printed = false; - // For simplicity, alignment of the register name printing applies only - // in the most common case where: - // - // prefix_with_name^prefix_with_alt_name is true - // - StreamString format_string; - if (reg_name_right_align_at && (prefix_with_name ^ prefix_with_alt_name)) - format_string.Printf("%%%us", reg_name_right_align_at); - else - format_string.Printf("%%s"); - std::string fmt = format_string.GetString(); - if (prefix_with_name) { - if (reg_info->name) { - s->Printf(fmt.c_str(), reg_info->name); - name_printed = true; - } else if (reg_info->alt_name) { - s->Printf(fmt.c_str(), reg_info->alt_name); - prefix_with_alt_name = false; - name_printed = true; - } - } - if (prefix_with_alt_name) { - if (name_printed) - s->PutChar('/'); - if (reg_info->alt_name) { - s->Printf(fmt.c_str(), reg_info->alt_name); - name_printed = true; - } else if (!name_printed) { - // No alternate name but we were asked to display a name, so show the - // main name - s->Printf(fmt.c_str(), reg_info->name); - name_printed = true; - } - } - if (name_printed) - s->PutCString(" = "); - - if (format == eFormatDefault) - format = reg_info->format; - - DumpDataExtractor(data, s, - 0, // Offset in "data" - format, // Format to use when dumping - reg_info->byte_size, // item_byte_size - 1, // item_count - UINT32_MAX, // num_per_line - LLDB_INVALID_ADDRESS, // base_addr - 0, // item_bit_size - 0); // item_bit_offset - return true; - } - return false; -} - bool RegisterValue::GetData(DataExtractor &data) const { return data.SetData(GetBytes(), GetByteSize(), GetByteOrder()) > 0; } @@ -375,9 +313,9 @@ static bool ParseVectorEncoding(const RegisterInfo *reg_info, std::vector<uint8_t> bytes; unsigned byte = 0; - // Using radix auto-sensing by passing 0 as the radix. - // Keep on processing the vector elements as long as the parsing succeeds and - // the vector size is < byte_size. + // Using radix auto-sensing by passing 0 as the radix. Keep on processing the + // vector elements as long as the parsing succeeds and the vector size is < + // byte_size. while (!car.getAsInteger(0, byte) && bytes.size() < byte_size) { bytes.push_back(byte); std::tie(car, cdr) = cdr.split(Sep); @@ -812,10 +750,9 @@ bool RegisterValue::SetUInt(uint64_t uint, uint32_t byte_size) { void RegisterValue::SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order) { - // If this assertion fires off we need to increase the size of - // buffer.bytes, or make it something that is allocated on - // the heap. Since the data buffer is in a union, we can't make it - // a collection class like SmallVector... + // If this assertion fires off we need to increase the size of buffer.bytes, + // or make it something that is allocated on the heap. Since the data buffer + // is in a union, we can't make it a collection class like SmallVector... if (bytes && length > 0) { assert(length <= sizeof(buffer.bytes) && "Storing too many bytes in a RegisterValue."); diff --git a/source/Core/Scalar.cpp b/source/Core/Scalar.cpp index 630083bae9308..6a7186969ef2c 100644 --- a/source/Core/Scalar.cpp +++ b/source/Core/Scalar.cpp @@ -9,7 +9,6 @@ #include "lldb/Core/Scalar.h" -#include "lldb/Host/StringConvert.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/Endian.h" #include "lldb/Utility/Status.h" @@ -25,8 +24,8 @@ using namespace lldb; using namespace lldb_private; //---------------------------------------------------------------------- -// Promote to max type currently follows the ANSI C rule for type -// promotion in expressions. +// Promote to max type currently follows the ANSI C rule for type promotion in +// expressions. //---------------------------------------------------------------------- static Scalar::Type PromoteToMaxType( const Scalar &lhs, // The const left hand side object @@ -41,10 +40,9 @@ static Scalar::Type PromoteToMaxType( // lhs/rhs will get promoted) ) { Scalar result; - // Initialize the promoted values for both the right and left hand side values - // to be the objects themselves. If no promotion is needed (both right and - // left - // have the same type), then the temp_value will not get used. + // Initialize the promoted values for both the right and left hand side + // values to be the objects themselves. If no promotion is needed (both right + // and left have the same type), then the temp_value will not get used. promoted_lhs_ptr = &lhs; promoted_rhs_ptr = &rhs; // Extract the types of both the right and left hand side values @@ -128,14 +126,13 @@ bool Scalar::GetData(DataExtractor &data, size_t limit_byte_size) const { if (limit_byte_size < byte_size) { if (endian::InlHostByteOrder() == eByteOrderLittle) { - // On little endian systems if we want fewer bytes from the - // current type we just specify fewer bytes since the LSByte - // is first... + // On little endian systems if we want fewer bytes from the current + // type we just specify fewer bytes since the LSByte is first... byte_size = limit_byte_size; } else if (endian::InlHostByteOrder() == eByteOrderBig) { - // On big endian systems if we want fewer bytes from the - // current type have to advance our initial byte pointer and - // trim down the number of bytes since the MSByte is first + // On big endian systems if we want fewer bytes from the current type + // have to advance our initial byte pointer and trim down the number of + // bytes since the MSByte is first bytes += byte_size - limit_byte_size; byte_size = limit_byte_size; } @@ -164,9 +161,8 @@ const void *Scalar::GetBytes() const { case e_slonglong: case e_ulonglong: bytes = reinterpret_cast<const uint8_t *>(m_integer.getRawData()); - // getRawData always returns a pointer to an uint64_t. If we have a smaller - // type, - // we need to update the pointer on big-endian systems. + // getRawData always returns a pointer to an uint64_t. If we have a + // smaller type, we need to update the pointer on big-endian systems. if (endian::InlHostByteOrder() == eByteOrderBig) { size_t byte_size = m_integer.getBitWidth() / 8; if (byte_size < 8) @@ -491,20 +487,24 @@ bool Scalar::Promote(Scalar::Type type) { break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -551,20 +551,24 @@ bool Scalar::Promote(Scalar::Type type) { break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -607,20 +611,24 @@ bool Scalar::Promote(Scalar::Type type) { break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -659,20 +667,24 @@ bool Scalar::Promote(Scalar::Type type) { break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -707,20 +719,24 @@ bool Scalar::Promote(Scalar::Type type) { break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -751,20 +767,24 @@ bool Scalar::Promote(Scalar::Type type) { break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -795,20 +815,24 @@ bool Scalar::Promote(Scalar::Type type) { break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -835,20 +859,24 @@ bool Scalar::Promote(Scalar::Type type) { break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -875,20 +903,24 @@ bool Scalar::Promote(Scalar::Type type) { break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, true, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -911,20 +943,24 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); + m_float = llvm::APFloat(llvm::APFloat::IEEEsingle()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); + m_float = llvm::APFloat(llvm::APFloat::IEEEdouble()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); + m_float = llvm::APFloat(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended()); + m_float.convertFromAPInt(m_integer, false, + llvm::APFloat::rmNearestTiesToEven); success = true; break; } @@ -948,20 +984,19 @@ bool Scalar::Promote(Scalar::Type type) { success = true; break; case e_double: - m_float = llvm::APFloat((float_t)m_float.convertToFloat()); + m_float = llvm::APFloat((double_t)m_float.convertToFloat()); success = true; break; - case e_long_double: - if (m_ieee_quad) - m_float = - llvm::APFloat(llvm::APFloat::IEEEquad(), m_float.bitcastToAPInt()); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), - m_float.bitcastToAPInt()); + case e_long_double: { + bool ignore; + m_float.convert(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended(), + llvm::APFloat::rmNearestTiesToEven, &ignore); success = true; break; } + } break; case e_double: @@ -982,16 +1017,15 @@ bool Scalar::Promote(Scalar::Type type) { case e_double: success = true; break; - case e_long_double: - if (m_ieee_quad) - m_float = - llvm::APFloat(llvm::APFloat::IEEEquad(), m_float.bitcastToAPInt()); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), - m_float.bitcastToAPInt()); + case e_long_double: { + bool ignore; + m_float.convert(m_ieee_quad ? llvm::APFloat::IEEEquad() + : llvm::APFloat::x87DoubleExtended(), + llvm::APFloat::rmNearestTiesToEven, &ignore); success = true; break; } + } break; case e_long_double: @@ -1088,253 +1122,6 @@ Scalar::Type Scalar::GetValueTypeForFloatWithByteSize(size_t byte_size) { return e_void; } -bool Scalar::Cast(Scalar::Type type) { - bool success = false; - switch (m_type) { - case e_void: - break; - - case e_sint: - case e_uint: - case e_slong: - case e_ulong: - case e_slonglong: - case e_ulonglong: - case e_sint128: - case e_uint128: - case e_sint256: - case e_uint256: - switch (type) { - case e_void: - break; - case e_sint: - m_integer = m_integer.sextOrTrunc(sizeof(sint_t) * 8); - success = true; - break; - - case e_uint: - m_integer = m_integer.zextOrTrunc(sizeof(sint_t) * 8); - success = true; - break; - - case e_slong: - m_integer = m_integer.sextOrTrunc(sizeof(slong_t) * 8); - success = true; - break; - - case e_ulong: - m_integer = m_integer.zextOrTrunc(sizeof(slong_t) * 8); - success = true; - break; - - case e_slonglong: - m_integer = m_integer.sextOrTrunc(sizeof(slonglong_t) * 8); - success = true; - break; - - case e_ulonglong: - m_integer = m_integer.zextOrTrunc(sizeof(slonglong_t) * 8); - success = true; - break; - - case e_sint128: - m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128); - success = true; - break; - - case e_uint128: - m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128); - success = true; - break; - - case e_sint256: - m_integer = m_integer.sextOrTrunc(BITWIDTH_INT256); - success = true; - break; - - case e_uint256: - m_integer = m_integer.zextOrTrunc(BITWIDTH_INT256); - success = true; - break; - - case e_float: - m_float = llvm::APFloat(m_integer.bitsToFloat()); - success = true; - break; - - case e_double: - m_float = llvm::APFloat(m_integer.bitsToDouble()); - success = true; - break; - - case e_long_double: - if (m_ieee_quad) - m_float = llvm::APFloat(llvm::APFloat::IEEEquad(), m_integer); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), m_integer); - success = true; - break; - } - break; - - case e_float: - switch (type) { - case e_void: - break; - case e_sint: - case e_uint: - case e_slong: - case e_ulong: - case e_slonglong: - case e_ulonglong: - case e_sint128: - case e_uint128: - case e_sint256: - case e_uint256: - m_integer = m_float.bitcastToAPInt(); - success = true; - break; - case e_float: - m_float = llvm::APFloat(m_float.convertToFloat()); - success = true; - break; - case e_double: - m_float = llvm::APFloat(m_float.convertToFloat()); - success = true; - break; - case e_long_double: - if (m_ieee_quad) - m_float = - llvm::APFloat(llvm::APFloat::IEEEquad(), m_float.bitcastToAPInt()); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), - m_float.bitcastToAPInt()); - success = true; - break; - } - break; - - case e_double: - switch (type) { - case e_void: - break; - case e_sint: - case e_uint: - case e_slong: - case e_ulong: - case e_slonglong: - case e_ulonglong: - case e_sint128: - case e_uint128: - case e_sint256: - case e_uint256: - m_integer = m_float.bitcastToAPInt(); - success = true; - break; - case e_float: - m_float = llvm::APFloat(m_float.convertToDouble()); - success = true; - break; - case e_double: - m_float = llvm::APFloat(m_float.convertToDouble()); - success = true; - break; - case e_long_double: - if (m_ieee_quad) - m_float = - llvm::APFloat(llvm::APFloat::IEEEquad(), m_float.bitcastToAPInt()); - else - m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(), - m_float.bitcastToAPInt()); - success = true; - break; - } - break; - - case e_long_double: - switch (type) { - case e_void: - break; - case e_sint: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.sextOrTrunc(sizeof(sint_t) * 8); - success = true; - break; - - case e_uint: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.zextOrTrunc(sizeof(sint_t) * 8); - success = true; - break; - - case e_slong: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.sextOrTrunc(sizeof(slong_t) * 8); - success = true; - break; - - case e_ulong: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.zextOrTrunc(sizeof(slong_t) * 8); - success = true; - break; - - case e_slonglong: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.sextOrTrunc(sizeof(slonglong_t) * 8); - success = true; - break; - - case e_ulonglong: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.zextOrTrunc(sizeof(slonglong_t) * 8); - success = true; - break; - - case e_sint128: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128); - success = true; - break; - - case e_uint128: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128); - success = true; - break; - - case e_sint256: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.sextOrTrunc(BITWIDTH_INT256); - success = true; - break; - - case e_uint256: - m_integer = m_float.bitcastToAPInt(); - m_integer = m_integer.zextOrTrunc(BITWIDTH_INT256); - success = true; - break; - - case e_float: - m_float = llvm::APFloat(m_float.convertToFloat()); - success = true; - break; - case e_double: - m_float = llvm::APFloat(m_float.convertToFloat()); - success = true; - break; - case e_long_double: - success = true; - break; - } - break; - } - - if (success) - m_type = type; - return success; -} - bool Scalar::MakeSigned() { bool success = false; @@ -1397,38 +1184,38 @@ bool Scalar::MakeUnsigned() { case e_void: break; case e_sint: + m_type = e_uint; success = true; break; case e_uint: - m_type = e_uint; success = true; break; case e_slong: + m_type = e_ulong; success = true; break; case e_ulong: - m_type = e_ulong; success = true; break; case e_slonglong: + m_type = e_ulonglong; success = true; break; case e_ulonglong: - m_type = e_ulonglong; success = true; break; case e_sint128: + m_type = e_uint128; success = true; break; case e_uint128: - m_type = e_uint128; success = true; break; case e_sint256: + m_type = e_uint256; success = true; break; case e_uint256: - m_type = e_uint256; success = true; break; case e_float: @@ -1819,7 +1606,7 @@ float Scalar::Float(float fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return m_integer.bitsToFloat(); + return llvm::APIntOps::RoundAPIntToFloat(m_integer); case e_float: return m_float.convertToFloat(); case e_double: @@ -1845,7 +1632,7 @@ double Scalar::Double(double fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return m_integer.bitsToDouble(); + return llvm::APIntOps::RoundAPIntToDouble(m_integer); case e_float: return (double_t)m_float.convertToFloat(); case e_double: @@ -1871,7 +1658,7 @@ long double Scalar::LongDouble(long double fail_value) const { case e_uint128: case e_sint256: case e_uint256: - return (long_double_t)m_integer.bitsToDouble(); + return (long_double_t)llvm::APIntOps::RoundAPIntToDouble(m_integer); case e_float: return (long_double_t)m_float.convertToFloat(); case e_double: @@ -2266,7 +2053,7 @@ const Scalar lldb_private::operator/(const Scalar &lhs, const Scalar &rhs) { case Scalar::e_float: case Scalar::e_double: case Scalar::e_long_double: - if (b->m_float.isZero()) { + if (!b->m_float.isZero()) { result.m_float = a->m_float / b->m_float; return result; } @@ -2274,8 +2061,7 @@ const Scalar lldb_private::operator/(const Scalar &lhs, const Scalar &rhs) { } } // For division only, the only way it should make it here is if a promotion - // failed, - // or if we are trying to do a divide by zero. + // failed, or if we are trying to do a divide by zero. result.m_type = Scalar::e_void; return result; } @@ -2467,17 +2253,15 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding, error.SetErrorString("Invalid c-string value string."); return error; } - bool success = false; switch (encoding) { case eEncodingInvalid: error.SetErrorString("Invalid encoding."); break; case eEncodingUint: - if (byte_size <= sizeof(unsigned long long)) { - uint64_t uval64 = - StringConvert::ToUInt64(value_str, UINT64_MAX, 0, &success); - if (!success) + if (byte_size <= sizeof(uint64_t)) { + uint64_t uval64; + if (!llvm::to_integer(value_str, uval64)) error.SetErrorStringWithFormat( "'%s' is not a valid unsigned integer string value", value_str); else if (!UIntValueIsValidForSize(uval64, byte_size)) @@ -2513,10 +2297,9 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding, break; case eEncodingSint: - if (byte_size <= sizeof(long long)) { - uint64_t sval64 = - StringConvert::ToSInt64(value_str, INT64_MAX, 0, &success); - if (!success) + if (byte_size <= sizeof(int64_t)) { + int64_t sval64; + if (!llvm::to_integer(value_str, sval64)) error.SetErrorStringWithFormat( "'%s' is not a valid signed integer string value", value_str); else if (!SIntValueIsValidForSize(sval64, byte_size)) diff --git a/source/Core/Section.cpp b/source/Core/Section.cpp index c9faf9f891571..d9c5d32ee13c9 100644 --- a/source/Core/Section.cpp +++ b/source/Core/Section.cpp @@ -27,8 +27,8 @@ class DataExtractor; using namespace lldb; using namespace lldb_private; -static const char *GetSectionTypeAsCString(lldb::SectionType sect_type) { - switch (sect_type) { +const char *Section::GetTypeAsCString() const { + switch (m_type) { case eSectionTypeInvalid: return "invalid"; case eSectionTypeCode: @@ -89,6 +89,10 @@ static const char *GetSectionTypeAsCString(lldb::SectionType sect_type) { return "dwarf-str"; case eSectionTypeDWARFDebugStrOffsets: return "dwarf-str-offsets"; + case eSectionTypeDWARFDebugTypes: + return "dwarf-types"; + case eSectionTypeDWARFDebugNames: + return "dwarf-names"; case eSectionTypeELFSymbolTable: return "elf-symbol-table"; case eSectionTypeELFDynamicSymbols: @@ -117,6 +121,8 @@ static const char *GetSectionTypeAsCString(lldb::SectionType sect_type) { return "go-symtab"; case eSectionTypeAbsoluteAddress: return "absolute"; + case eSectionTypeDWARFGNUDebugAltLink: + return "dwarf-gnu-debugaltlink"; case eSectionTypeOther: return "regular"; } @@ -175,9 +181,9 @@ Section::~Section() { addr_t Section::GetFileAddress() const { SectionSP parent_sp(GetParent()); if (parent_sp) { - // This section has a parent which means m_file_addr is an offset into - // the parent section, so the file address for this section is the file - // address of the parent plus the offset + // This section has a parent which means m_file_addr is an offset into the + // parent section, so the file address for this section is the file address + // of the parent plus the offset return parent_sp->GetFileAddress() + m_file_addr; } // This section has no parent, so m_file_addr is the file base address @@ -283,8 +289,7 @@ int Section::Compare(const Section &a, const Section &b) { void Section::Dump(Stream *s, Target *target, uint32_t depth) const { // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); s->Indent(); - s->Printf("0x%8.8" PRIx64 " %-16s ", GetID(), - GetSectionTypeAsCString(m_type)); + s->Printf("0x%8.8" PRIx64 " %-16s ", GetID(), GetTypeAsCString()); bool resolved = true; addr_t addr = LLDB_INVALID_ADDRESS; @@ -326,10 +331,11 @@ void Section::DumpName(Stream *s) const { // The top most section prints the module basename const char *name = NULL; ModuleSP module_sp(GetModule()); - const FileSpec &file_spec = m_obj_file->GetFileSpec(); - if (m_obj_file) + if (m_obj_file) { + const FileSpec &file_spec = m_obj_file->GetFileSpec(); name = file_spec.GetFilename().AsCString(); + } if ((!name || !name[0]) && module_sp) name = module_sp->GetFileSpec().GetFilename().AsCString(); if (name && name[0]) @@ -556,10 +562,8 @@ SectionSP SectionList::FindSectionContainingFileAddress(addr_t vm_addr, Section *sect = sect_iter->get(); if (sect->ContainsFileAddress(vm_addr)) { // The file address is in this section. We need to make sure one of our - // child - // sections doesn't contain this address as well as obeying the depth - // limit - // that was passed in. + // child sections doesn't contain this address as well as obeying the + // depth limit that was passed in. if (depth > 0) sect_sp = sect->GetChildren().FindSectionContainingFileAddress( vm_addr, depth - 1); diff --git a/source/Core/SourceManager.cpp b/source/Core/SourceManager.cpp index b284ff1dbaaa3..a6afd64f30541 100644 --- a/source/Core/SourceManager.cpp +++ b/source/Core/SourceManager.cpp @@ -109,8 +109,8 @@ static bool should_show_stop_column_with_ansi(DebuggerSP debugger_sp) { if (!debugger_sp) return false; - // We don't use ANSI stop column formatting if the debugger doesn't think - // it should be using color. + // We don't use ANSI stop column formatting if the debugger doesn't think it + // should be using color. if (!debugger_sp->GetUseColor()) return false; @@ -128,8 +128,8 @@ static bool should_show_stop_column_with_caret(DebuggerSP debugger_sp) { if (!debugger_sp) return false; - // If we're asked to show the first available of ANSI or caret, then - // we do show the caret when ANSI is not available. + // If we're asked to show the first available of ANSI or caret, then we do + // show the caret when ANSI is not available. const auto value = debugger_sp->GetStopShowColumn(); if ((value == eStopShowColumnAnsiOrCaret) && !debugger_sp->GetUseColor()) return true; @@ -255,9 +255,9 @@ size_t SourceManager::DisplayMoreWithLineNumbers( if (m_last_line > 0) { if (reverse) { - // If this is the first time we've done a reverse, then back up one more - // time so we end - // up showing the chunk before the last one we've shown: + // If this is the first time we've done a reverse, then back up one + // more time so we end up showing the chunk before the last one we've + // shown: if (m_last_line > m_last_count) m_last_line -= m_last_count; else @@ -299,10 +299,9 @@ bool SourceManager::GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line) { if (target_sp) { // If nobody has set the default file and line then try here. If there's - // no executable, then we - // will try again later when there is one. Otherwise, if we can't find it - // we won't look again, - // somebody will have to set it (for instance when we stop somewhere...) + // no executable, then we will try again later when there is one. + // Otherwise, if we can't find it we won't look again, somebody will have + // to set it (for instance when we stop somewhere...) Module *executable_ptr = target_sp->GetExecutableModulePointer(); if (executable_ptr) { SymbolContextList sc_list; @@ -410,9 +409,7 @@ void SourceManager::File::CommonInitializer(const FileSpec &file_spec, FileSpec new_file_spec; // Check target specific source remappings first, then fall back to // modules objects can have individual path remappings that were - // detected - // when the debug info for a module was found. - // then + // detected when the debug info for a module was found. then if (target->GetSourcePathMap().FindFile(m_file_spec, new_file_spec) || target->GetImages().FindSourceFile(m_file_spec, new_file_spec)) { m_file_spec = new_file_spec; @@ -538,8 +535,8 @@ size_t SourceManager::File::DisplaySourceLines(uint32_t line, uint32_t column, if (column && (column < count)) { auto debugger_sp = m_debugger_wp.lock(); if (should_show_stop_column_with_ansi(debugger_sp) && debugger_sp) { - // Check if we have any ANSI codes with which to mark this column. - // If not, no need to do this work. + // Check if we have any ANSI codes with which to mark this column. If + // not, no need to do this work. auto ansi_prefix_entry = debugger_sp->GetStopShowColumnAnsiPrefix(); auto ansi_suffix_entry = debugger_sp->GetStopShowColumnAnsiSuffix(); diff --git a/source/Core/Value.cpp b/source/Core/Value.cpp index d415f1b09eb79..254c9008babb5 100644 --- a/source/Core/Value.cpp +++ b/source/Core/Value.cpp @@ -365,11 +365,10 @@ Status Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, if (process == NULL || !process->IsAlive()) { Target *target = exe_ctx->GetTargetPtr(); if (target) { - // Allow expressions to run and evaluate things when the target - // has memory sections loaded. This allows you to use "target modules - // load" - // to load your executable and any shared libraries, then execute - // commands where you can look at types in data sections. + // Allow expressions to run and evaluate things when the target has + // memory sections loaded. This allows you to use "target modules + // load" to load your executable and any shared libraries, then + // execute commands where you can look at types in data sections. const SectionLoadList &target_sections = target->GetSectionLoadList(); if (!target_sections.IsEmpty()) { address = m_value.ULongLong(LLDB_INVALID_ADDRESS); @@ -406,8 +405,8 @@ Status Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, error.SetErrorString("invalid file address"); } else { if (module == NULL) { - // The only thing we can currently lock down to a module so that - // we can resolve a file address, is a variable. + // The only thing we can currently lock down to a module so that we + // can resolve a file address, is a variable. Variable *variable = GetVariable(); if (variable) { SymbolContext var_sc; @@ -541,12 +540,11 @@ Status Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, } else if ((address_type == eAddressTypeLoad) || (address_type == eAddressTypeFile)) { if (file_so_addr.IsValid()) { - // We have a file address that we were able to translate into a - // section offset address so we might be able to read this from - // the object files if we don't have a live process. Lets always - // try and read from the process if we have one though since we - // want to read the actual value by setting "prefer_file_cache" - // to false. + // We have a file address that we were able to translate into a section + // offset address so we might be able to read this from the object + // files if we don't have a live process. Lets always try and read from + // the process if we have one though since we want to read the actual + // value by setting "prefer_file_cache" to false. const bool prefer_file_cache = false; if (exe_ctx->GetTargetRef().ReadMemory(file_so_addr, prefer_file_cache, dst, byte_size, @@ -555,10 +553,10 @@ Status Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, "read memory from 0x%" PRIx64 " failed", (uint64_t)address); } } else { - // The execution context might have a NULL process, but it - // might have a valid process in the exe_ctx->target, so use - // the ExecutionContext::GetProcess accessor to ensure we - // get the process if there is one. + // The execution context might have a NULL process, but it might have a + // valid process in the exe_ctx->target, so use the + // ExecutionContext::GetProcess accessor to ensure we get the process + // if there is one. Process *process = exe_ctx->GetProcessPtr(); if (process) { @@ -671,6 +669,25 @@ const char *Value::GetContextTypeAsCString(ContextType context_type) { return "???"; } +void Value::ConvertToLoadAddress(Module *module, Target *target) { + if (!module || !target || (GetValueType() != eValueTypeFileAddress)) + return; + + lldb::addr_t file_addr = GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + if (file_addr == LLDB_INVALID_ADDRESS) + return; + + Address so_addr; + if (!module->ResolveFileAddress(file_addr, so_addr)) + return; + lldb::addr_t load_addr = so_addr.GetLoadAddress(target); + if (load_addr == LLDB_INVALID_ADDRESS) + return; + + SetValueType(Value::eValueTypeLoadAddress); + GetScalar() = load_addr; +} + ValueList::ValueList(const ValueList &rhs) { m_values = rhs.m_values; } const ValueList &ValueList::operator=(const ValueList &rhs) { diff --git a/source/Core/ValueObject.cpp b/source/Core/ValueObject.cpp index c09139fe2b09e..244ea2936fb4f 100644 --- a/source/Core/ValueObject.cpp +++ b/source/Core/ValueObject.cpp @@ -19,6 +19,7 @@ #include "lldb/Core/ValueObjectMemory.h" #include "lldb/Core/ValueObjectSyntheticFilter.h" #include "lldb/DataFormatters/DataVisualization.h" +#include "lldb/DataFormatters/DumpValueObjectOptions.h" // for DumpValueObj... #include "lldb/DataFormatters/FormatManager.h" // for FormatManager #include "lldb/DataFormatters/StringPrinter.h" #include "lldb/DataFormatters/TypeFormat.h" // for TypeFormatImpl_F... @@ -146,16 +147,15 @@ bool ValueObject::UpdateValueIfNeeded(bool update_format) { if (update_format) did_change_formats = UpdateFormatsIfNeeded(); - // If this is a constant value, then our success is predicated on whether - // we have an error or not + // If this is a constant value, then our success is predicated on whether we + // have an error or not if (GetIsConstant()) { // if you are constant, things might still have changed behind your back // (e.g. you are a frozen object and things have changed deeper than you - // cared to freeze-dry yourself) - // in this case, your value has not changed, but "computed" entries might - // have, so you might now have - // a different summary, or a different object description. clear these so we - // will recompute them + // cared to freeze-dry yourself) in this case, your value has not changed, + // but "computed" entries might have, so you might now have a different + // summary, or a different object description. clear these so we will + // recompute them if (update_format && !did_change_formats) ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription); @@ -167,8 +167,8 @@ bool ValueObject::UpdateValueIfNeeded(bool update_format) { if (NeedsUpdating()) { m_update_point.SetUpdated(); - // Save the old value using swap to avoid a string copy which - // also will clear our m_value_str + // Save the old value using swap to avoid a string copy which also will + // clear our m_value_str if (m_value_str.empty()) { m_old_value_valid = false; } else { @@ -215,8 +215,8 @@ bool ValueObject::UpdateValueIfNeeded(bool update_format) { if (first_update) SetValueDidChange(false); else if (!m_value_did_change && success == false) { - // The value wasn't gotten successfully, so we mark this - // as changed if the value used to be valid and now isn't + // The value wasn't gotten successfully, so we mark this as changed if + // the value used to be valid and now isn't SetValueDidChange(value_was_valid); } else if (need_compare_checksums) { SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], @@ -261,8 +261,7 @@ bool ValueObject::UpdateFormatsIfNeeded() { void ValueObject::SetNeedsUpdate() { m_update_point.SetNeedsUpdate(); // We have to clear the value string here so ConstResult children will notice - // if their values are - // changed by hand (i.e. with SetValueAsCString). + // if their values are changed by hand (i.e. with SetValueAsCString). ClearUserVisibleData(eClearUserVisibleDataItemsValue); } @@ -556,9 +555,9 @@ size_t ValueObject::GetIndexOfChildWithName(const ConstString &name) { ValueObjectSP ValueObject::GetChildMemberWithName(const ConstString &name, bool can_create) { - // when getting a child by name, it could be buried inside some base - // classes (which really aren't part of the expression path), so we - // need a vector of indexes that can get us down to the correct child + // when getting a child by name, it could be buried inside some base classes + // (which really aren't part of the expression path), so we need a vector of + // indexes that can get us down to the correct child ValueObjectSP child_sp; // We may need to update our value if we are dynamic @@ -682,8 +681,8 @@ bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr, const TypeSummaryOptions &options) { destination.clear(); - // ideally we would like to bail out if passing NULL, but if we do so - // we end up not providing the summary for function pointers anymore + // ideally we would like to bail out if passing NULL, but if we do so we end + // up not providing the summary for function pointers anymore if (/*summary_ptr == NULL ||*/ m_is_getting_summary) return false; @@ -695,9 +694,8 @@ bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr, actual_options.SetLanguage(GetPreferredDisplayLanguage()); // this is a hot path in code and we prefer to avoid setting this string all - // too often also clearing out other - // information that we might care to see in a crash log. might be useful in - // very specific situations though. + // too often also clearing out other information that we might care to see in + // a crash log. might be useful in very specific situations though. /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s", GetTypeName().GetCString(), @@ -925,7 +923,8 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) { break; } - // If we have reached this point, then we have successfully changed the value. + // If we have reached this point, then we have successfully changed the + // value. SetNeedsUpdate(); return true; } @@ -1010,9 +1009,9 @@ ValueObject::ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error, DataExtractor data; if (cstr_len > 0 && honor_array) { // I am using GetPointeeData() here to abstract the fact that some - // ValueObjects are actually frozen pointers in the host - // but the pointed-to data lives in the debuggee, and GetPointeeData() - // automatically takes care of this + // ValueObjects are actually frozen pointers in the host but the pointed- + // to data lives in the debuggee, and GetPointeeData() automatically + // takes care of this GetPointeeData(data, 0, cstr_len); if ((bytes_read = data.GetByteSize()) > 0) { @@ -1031,9 +1030,9 @@ ValueObject::ReadPointedString(lldb::DataBufferSP &buffer_sp, Status &error, int cstr_len_displayed = -1; bool capped_cstr = false; // I am using GetPointeeData() here to abstract the fact that some - // ValueObjects are actually frozen pointers in the host - // but the pointed-to data lives in the debuggee, and GetPointeeData() - // automatically takes care of this + // ValueObjects are actually frozen pointers in the host but the pointed- + // to data lives in the debuggee, and GetPointeeData() automatically + // takes care of this while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) { total_bytes_read += bytes_read; const char *cstr = data.PeekCStr(0); @@ -1175,8 +1174,8 @@ const char *ValueObject::GetValueAsCString() { format_sp.reset(new TypeFormatImpl_Format(my_format)); if (GetValueAsCString(*format_sp.get(), m_value_str)) { if (!m_value_did_change && m_old_value_valid) { - // The value was gotten successfully, so we consider the - // value as changed if the value string differs + // The value was gotten successfully, so we consider the value as + // changed if the value string differs SetValueDidChange(m_old_value_str != m_value_str); } } @@ -1187,8 +1186,8 @@ const char *ValueObject::GetValueAsCString() { return m_value_str.c_str(); } -// if > 8bytes, 0 is returned. this method should mostly be used -// to read address values out of pointers +// if > 8bytes, 0 is returned. this method should mostly be used to read +// address values out of pointers uint64_t ValueObject::GetValueAsUnsigned(uint64_t fail_value, bool *success) { // If our byte size is zero this is an aggregate type that has children if (CanProvideValue()) { @@ -1224,10 +1223,9 @@ int64_t ValueObject::GetValueAsSigned(int64_t fail_value, bool *success) { } // if any more "special cases" are added to -// ValueObject::DumpPrintableRepresentation() please keep -// this call up to date by returning true for your new special cases. We will -// eventually move -// to checking this call result before trying to display special cases +// ValueObject::DumpPrintableRepresentation() please keep this call up to date +// by returning true for your new special cases. We will eventually move to +// checking this call result before trying to display special cases bool ValueObject::HasSpecialPrintableRepresentation( ValueObjectRepresentationStyle val_obj_display, Format custom_format) { Flags flags(GetTypeInfo()); @@ -1276,8 +1274,7 @@ bool ValueObject::DumpPrintableRepresentation( if (flags.AnySet(eTypeIsArray | eTypeIsPointer) && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) { // when being asked to get a printable display an array or pointer type - // directly, - // try to "do the right thing" + // directly, try to "do the right thing" if (IsCStringContainer(true) && (custom_format == eFormatCString || @@ -1309,8 +1306,8 @@ bool ValueObject::DumpPrintableRepresentation( if (custom_format == eFormatEnum) return false; - // this only works for arrays, because I have no way to know when - // the pointed memory ends, and no special \0 end of data marker + // this only works for arrays, because I have no way to know when the + // pointed memory ends, and no special \0 end of data marker if (flags.Test(eTypeIsArray)) { if ((custom_format == eFormatBytes) || (custom_format == eFormatBytesWithASCII)) { @@ -1406,8 +1403,8 @@ bool ValueObject::DumpPrintableRepresentation( llvm::StringRef str; // this is a local stream that we are using to ensure that the data pointed - // to by cstr survives long enough for us to copy it to its destination - it - // is necessary to have this temporary storage area for cases where our + // to by cstr survives long enough for us to copy it to its destination - + // it is necessary to have this temporary storage area for cases where our // desired output is not backed by some other longer-term storage StreamString strm; @@ -1485,9 +1482,9 @@ bool ValueObject::DumpPrintableRepresentation( s.PutCString("<no printable representation>"); } - // we should only return false here if we could not do *anything* - // even if we have an error message as output, that's a success - // from our callers' perspective, so return true + // we should only return false here if we could not do *anything* even if + // we have an error message as output, that's a success from our callers' + // perspective, so return true var_success = true; if (custom_format != eFormatInvalid) @@ -1590,9 +1587,8 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { switch (value_type) { case Value::eValueTypeLoadAddress: { // If it is a load address, then the scalar value is the storage - // location - // of the data, and we have to shove this value down to that load - // location. + // location of the data, and we have to shove this value down to that + // load location. ExecutionContext exe_ctx(GetExecutionContextRef()); Process *process = exe_ctx.GetProcessPtr(); if (process) { @@ -1639,7 +1635,8 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { return false; } - // If we have reached this point, then we have successfully changed the value. + // If we have reached this point, then we have successfully changed the + // value. SetNeedsUpdate(); return true; } @@ -1734,16 +1731,14 @@ bool ValueObject::IsUninitializedReference() { return false; } -// This allows you to create an array member using and index -// that doesn't not fall in the normal bounds of the array. -// Many times structure can be defined as: -// struct Collection -// { +// This allows you to create an array member using and index that doesn't not +// fall in the normal bounds of the array. Many times structure can be defined +// as: struct Collection { // uint32_t item_count; // Item item_array[0]; // }; -// The size of the "item_array" is 1, but many times in practice -// there are more items in "item_array". +// The size of the "item_array" is 1, but many times in practice there are more +// items in "item_array". ValueObjectSP ValueObject::GetSyntheticArrayMember(size_t index, bool can_create) { @@ -1752,13 +1747,13 @@ ValueObjectSP ValueObject::GetSyntheticArrayMember(size_t index, char index_str[64]; snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index); ConstString index_const_str(index_str); - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(index_const_str); if (!synthetic_child_sp) { ValueObject *synthetic_child; - // We haven't made a synthetic array member for INDEX yet, so - // lets make one and cache it for any future reference. + // We haven't made a synthetic array member for INDEX yet, so lets make + // one and cache it for any future reference. synthetic_child = CreateChildAtIndex(0, true, index); // Cache the value if we got one back... @@ -1780,8 +1775,8 @@ ValueObjectSP ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to, char index_str[64]; snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); ConstString index_const_str(index_str); - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(index_const_str); if (!synthetic_child_sp) { uint32_t bit_field_size = to - from + 1; @@ -1789,8 +1784,8 @@ ValueObjectSP ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to, if (GetDataExtractor().GetByteOrder() == eByteOrderBig) bit_field_offset = GetByteSize() * 8 - bit_field_size - bit_field_offset; - // We haven't made a synthetic array member for INDEX yet, so - // lets make one and cache it for any future reference. + // We haven't made a synthetic array member for INDEX yet, so lets make + // one and cache it for any future reference. ValueObjectChild *synthetic_child = new ValueObjectChild( *this, GetCompilerType(), index_const_str, GetByteSize(), 0, bit_field_size, bit_field_offset, false, false, eAddressTypeInvalid, @@ -1820,8 +1815,8 @@ ValueObjectSP ValueObject::GetSyntheticChildAtOffset( name_const_str.SetCString(name_str); } - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(name_const_str); if (synthetic_child_sp.get()) @@ -1858,8 +1853,8 @@ ValueObjectSP ValueObject::GetSyntheticBase(uint32_t offset, name_const_str.SetCString(name_str); } - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(name_const_str); if (synthetic_child_sp.get()) @@ -1884,11 +1879,10 @@ ValueObjectSP ValueObject::GetSyntheticBase(uint32_t offset, return synthetic_child_sp; } -// your expression path needs to have a leading . or -> -// (unless it somehow "looks like" an array, in which case it has -// a leading [ symbol). while the [ is meaningful and should be shown -// to the user, . and -> are just parser design, but by no means -// added information for the user.. strip them off +// your expression path needs to have a leading . or -> (unless it somehow +// "looks like" an array, in which case it has a leading [ symbol). while the [ +// is meaningful and should be shown to the user, . and -> are just parser +// design, but by no means added information for the user.. strip them off static const char *SkipLeadingExpressionPathSeparators(const char *expression) { if (!expression || !expression[0]) return expression; @@ -1904,12 +1898,12 @@ ValueObject::GetSyntheticExpressionPathChild(const char *expression, bool can_create) { ValueObjectSP synthetic_child_sp; ConstString name_const_string(expression); - // Check if we have already created a synthetic array member in this - // valid object. If we have we will re-use it. + // Check if we have already created a synthetic array member in this valid + // object. If we have we will re-use it. synthetic_child_sp = GetSyntheticChild(name_const_string); if (!synthetic_child_sp) { - // We haven't made a synthetic array member for expression yet, so - // lets make one and cache it for any future reference. + // We haven't made a synthetic array member for expression yet, so lets + // make one and cache it for any future reference. synthetic_child_sp = GetValueForExpressionPath( expression, NULL, NULL, GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal( @@ -2055,10 +2049,9 @@ bool ValueObject::IsBaseClass(uint32_t &depth) { void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat) { // synthetic children do not actually "exist" as part of the hierarchy, and - // sometimes they are consed up in ways - // that don't make sense from an underlying language/API standpoint. So, use a - // special code path here to return - // something that can hopefully be used in expression + // sometimes they are consed up in ways that don't make sense from an + // underlying language/API standpoint. So, use a special code path here to + // return something that can hopefully be used in expression if (m_is_synthetic_children_generated) { UpdateValueIfNeeded(); @@ -2092,11 +2085,10 @@ void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers) { // this is the original format of GetExpressionPath() producing code like - // *(a_ptr).memberName, which is entirely - // fine, until you put this into + // *(a_ptr).memberName, which is entirely fine, until you put this into // StackFrame::GetValueForVariableExpressionPath() which prefers to see - // a_ptr->memberName. - // the eHonorPointers mode is meant to produce strings in this latter format + // a_ptr->memberName. the eHonorPointers mode is meant to produce strings + // in this latter format s.PutCString("*("); } @@ -2105,9 +2097,9 @@ void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, if (parent) parent->GetExpressionPath(s, qualify_cxx_base_classes, epformat); - // if we are a deref_of_parent just because we are synthetic array - // members made up to allow ptr[%d] syntax to work in variable - // printing, then add our name ([%d]) to the expression path + // if we are a deref_of_parent just because we are synthetic array members + // made up to allow ptr[%d] syntax to work in variable printing, then add our + // name ([%d]) to the expression path if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers) s.PutCString(m_name.AsCString()); @@ -2355,8 +2347,8 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( } // if we are here and options.m_no_synthetic_children is true, - // child_valobj_sp is going to be a NULL SP, - // so we hit the "else" branch, and return an error + // child_valobj_sp is going to be a NULL SP, so we hit the "else" + // branch, and return an error if (child_valobj_sp.get()) // if it worked, just return { *reason_to_stop = @@ -2424,8 +2416,8 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( } // if we are here and options.m_no_synthetic_children is true, - // child_valobj_sp is going to be a NULL SP, - // so we hit the "else" branch, and return an error + // child_valobj_sp is going to be a NULL SP, so we hit the "else" + // branch, and return an error if (child_valobj_sp.get()) // if it worked, move on { root = child_valobj_sp; @@ -2506,8 +2498,8 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( assert(!bracket_expr.empty()); if (!bracket_expr.contains('-')) { - // if no separator, this is of the form [N]. Note that this cannot - // be an unbounded range of the form [], because that case was handled + // if no separator, this is of the form [N]. Note that this cannot be + // an unbounded range of the form [], because that case was handled // above with an unconditional return. unsigned long index = 0; if (bracket_expr.getAsInteger(0, index)) { @@ -2631,8 +2623,8 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; return nullptr; } - // if we are here, then root itself is a synthetic VO.. should be good - // to go + // if we are here, then root itself is a synthetic VO.. should be + // good to go if (!root) { *reason_to_stop = @@ -3031,20 +3023,17 @@ ValueObject::EvaluationPoint::EvaluationPoint( ValueObject::EvaluationPoint::~EvaluationPoint() {} // This function checks the EvaluationPoint against the current process state. -// If the current -// state matches the evaluation point, or the evaluation point is already -// invalid, then we return -// false, meaning "no change". If the current state is different, we update our -// state, and return -// true meaning "yes, change". If we did see a change, we also set -// m_needs_update to true, so -// future calls to NeedsUpdate will return true. -// exe_scope will be set to the current execution context scope. +// If the current state matches the evaluation point, or the evaluation point +// is already invalid, then we return false, meaning "no change". If the +// current state is different, we update our state, and return true meaning +// "yes, change". If we did see a change, we also set m_needs_update to true, +// so future calls to NeedsUpdate will return true. exe_scope will be set to +// the current execution context scope. bool ValueObject::EvaluationPoint::SyncWithProcessState( bool accept_invalid_exe_ctx) { - // Start with the target, if it is NULL, then we're obviously not going to get - // any further: + // Start with the target, if it is NULL, then we're obviously not going to + // get any further: const bool thread_and_frame_only_if_stopped = true; ExecutionContext exe_ctx( m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped)); @@ -3061,8 +3050,8 @@ bool ValueObject::EvaluationPoint::SyncWithProcessState( ProcessModID current_mod_id = process->GetModID(); // If the current stop id is 0, either we haven't run yet, or the process - // state has been cleared. - // In either case, we aren't going to be able to sync with the process state. + // state has been cleared. In either case, we aren't going to be able to sync + // with the process state. if (current_mod_id.GetStopID() == 0) return false; @@ -3070,8 +3059,8 @@ bool ValueObject::EvaluationPoint::SyncWithProcessState( const bool was_valid = m_mod_id.IsValid(); if (was_valid) { if (m_mod_id == current_mod_id) { - // Everything is already up to date in this object, no need to - // update the execution context scope. + // Everything is already up to date in this object, no need to update the + // execution context scope. changed = false; } else { m_mod_id = current_mod_id; @@ -3081,10 +3070,9 @@ bool ValueObject::EvaluationPoint::SyncWithProcessState( } // Now re-look up the thread and frame in case the underlying objects have - // gone away & been recreated. - // That way we'll be sure to return a valid exe_scope. - // If we used to have a thread or a frame but can't find it anymore, then mark - // ourselves as invalid. + // gone away & been recreated. That way we'll be sure to return a valid + // exe_scope. If we used to have a thread or a frame but can't find it + // anymore, then mark ourselves as invalid. if (!accept_invalid_exe_ctx) { if (m_exe_ctx_ref.HasThreadRef()) { @@ -3299,11 +3287,9 @@ void ValueObject::SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType lt) { } bool ValueObject::CanProvideValue() { - // we need to support invalid types as providers of values because some - // bare-board - // debugging scenarios have no notion of types, but still manage to have raw - // numeric - // values for things like registers. sigh. + // we need to support invalid types as providers of values because some bare- + // board debugging scenarios have no notion of types, but still manage to + // have raw numeric values for things like registers. sigh. const CompilerType &type(GetCompilerType()); return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue)); @@ -3326,7 +3312,9 @@ ValueObjectSP ValueObject::Persist() { if (!persistent_state) return nullptr; - ConstString name(persistent_state->GetNextPersistentVariableName()); + auto prefix = persistent_state->GetPersistentVariablePrefix(); + ConstString name = + persistent_state->GetNextPersistentVariableName(*target_sp, prefix); ValueObjectSP const_result_sp = ValueObjectConstResult::Create(target_sp.get(), GetValue(), name); diff --git a/source/Core/ValueObjectCast.cpp b/source/Core/ValueObjectCast.cpp index a489bdc74f5fd..e0978f692bc53 100644 --- a/source/Core/ValueObjectCast.cpp +++ b/source/Core/ValueObjectCast.cpp @@ -71,9 +71,9 @@ bool ValueObjectCast::UpdateValue() { m_value.SetCompilerType(compiler_type); SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren()); if (!CanProvideValue()) { - // this value object represents an aggregate type whose - // children have values, but this object does not. So we - // say we are changed if our location has changed. + // this value object represents an aggregate type whose children have + // values, but this object does not. So we say we are changed if our + // location has changed. SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); } diff --git a/source/Core/ValueObjectChild.cpp b/source/Core/ValueObjectChild.cpp index 591bc21711aec..019daa2fd3d29 100644 --- a/source/Core/ValueObjectChild.cpp +++ b/source/Core/ValueObjectChild.cpp @@ -172,8 +172,8 @@ bool ValueObjectChild::UpdateValue() { } else if (addr == 0) { m_error.SetErrorString("parent is NULL"); } else { - // Set this object's scalar value to the address of its - // value by adding its byte offset to the parent address + // Set this object's scalar value to the address of its value by + // adding its byte offset to the parent address m_value.GetScalar() += GetByteOffset(); } } break; diff --git a/source/Core/ValueObjectDynamicValue.cpp b/source/Core/ValueObjectDynamicValue.cpp index 0013d0dbf740f..e9b48310b0c61 100644 --- a/source/Core/ValueObjectDynamicValue.cpp +++ b/source/Core/ValueObjectDynamicValue.cpp @@ -122,8 +122,8 @@ bool ValueObjectDynamicValue::UpdateValue() { return false; } - // Setting our type_sp to NULL will route everything back through our - // parent which is equivalent to not using dynamic values. + // Setting our type_sp to NULL will route everything back through our parent + // which is equivalent to not using dynamic values. if (m_use_dynamic == lldb::eNoDynamicValues) { m_dynamic_type_info.Clear(); return true; @@ -173,8 +173,7 @@ bool ValueObjectDynamicValue::UpdateValue() { } // Getting the dynamic value may have run the program a bit, and so marked us - // as needing updating, but we really - // don't... + // as needing updating, but we really don't... m_update_point.SetUpdated(); @@ -192,8 +191,8 @@ bool ValueObjectDynamicValue::UpdateValue() { } // If we don't have a dynamic type, then make ourselves just a echo of our - // parent. - // Or we could return false, and make ourselves an echo of our parent? + // parent. Or we could return false, and make ourselves an echo of our + // parent? if (!found_dynamic_type) { if (m_dynamic_type_info) SetValueDidChange(true); @@ -248,14 +247,14 @@ bool ValueObjectDynamicValue::UpdateValue() { static_cast<void *>(this), GetTypeName().GetCString()); if (m_address.IsValid() && m_dynamic_type_info) { - // The variable value is in the Scalar value inside the m_value. - // We can point our m_data right to it. + // The variable value is in the Scalar value inside the m_value. We can + // point our m_data right to it. m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get()); if (m_error.Success()) { if (!CanProvideValue()) { - // this value object represents an aggregate type whose - // children have values, but this object does not. So we - // say we are changed if our location has changed. + // this value object represents an aggregate type whose children have + // values, but this object does not. So we say we are changed if our + // location has changed. SetValueDidChange(m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); } @@ -287,13 +286,11 @@ bool ValueObjectDynamicValue::SetValueFromCString(const char *value_str, return false; } - // if we are at an offset from our parent, in order to set ourselves correctly - // we would need - // to change the new value so that it refers to the correct dynamic type. we - // choose not to deal - // with that - if anything more than a value overwrite is required, you should - // be using the - // expression parser instead of the value editing facility + // if we are at an offset from our parent, in order to set ourselves + // correctly we would need to change the new value so that it refers to the + // correct dynamic type. we choose not to deal with that - if anything more + // than a value overwrite is required, you should be using the expression + // parser instead of the value editing facility if (my_value != parent_value) { // but NULL'ing out a value should always be allowed if (strcmp(value_str, "0")) { @@ -322,13 +319,11 @@ bool ValueObjectDynamicValue::SetData(DataExtractor &data, Status &error) { return false; } - // if we are at an offset from our parent, in order to set ourselves correctly - // we would need - // to change the new value so that it refers to the correct dynamic type. we - // choose not to deal - // with that - if anything more than a value overwrite is required, you should - // be using the - // expression parser instead of the value editing facility + // if we are at an offset from our parent, in order to set ourselves + // correctly we would need to change the new value so that it refers to the + // correct dynamic type. we choose not to deal with that - if anything more + // than a value overwrite is required, you should be using the expression + // parser instead of the value editing facility if (my_value != parent_value) { // but NULL'ing out a value should always be allowed lldb::offset_t offset = 0; diff --git a/source/Core/ValueObjectList.cpp b/source/Core/ValueObjectList.cpp index 00aee798c0e3c..0dd07252888fe 100644 --- a/source/Core/ValueObjectList.cpp +++ b/source/Core/ValueObjectList.cpp @@ -87,8 +87,8 @@ ValueObjectSP ValueObjectList::FindValueObjectByUID(lldb::user_id_t uid) { collection::iterator pos, end = m_value_objects.end(); for (pos = m_value_objects.begin(); pos != end; ++pos) { - // Watch out for NULL objects in our list as the list - // might get resized to a specific size and lazily filled in + // Watch out for NULL objects in our list as the list might get resized to + // a specific size and lazily filled in ValueObject *valobj = (*pos).get(); if (valobj && valobj->GetID() == uid) { valobj_sp = *pos; diff --git a/source/Core/ValueObjectMemory.cpp b/source/Core/ValueObjectMemory.cpp index e26900014c9da..3e71fea6bb35e 100644 --- a/source/Core/ValueObjectMemory.cpp +++ b/source/Core/ValueObjectMemory.cpp @@ -165,21 +165,20 @@ bool ValueObjectMemory::UpdateValue() { llvm_unreachable("Unhandled expression result value kind..."); case Value::eValueTypeScalar: - // The variable value is in the Scalar value inside the m_value. - // We can point our m_data right to it. + // The variable value is in the Scalar value inside the m_value. We can + // point our m_data right to it. m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get()); break; case Value::eValueTypeFileAddress: case Value::eValueTypeLoadAddress: case Value::eValueTypeHostAddress: - // The DWARF expression result was an address in the inferior - // process. If this variable is an aggregate type, we just need - // the address as the main value as all child variable objects - // will rely upon this location and add an offset and then read - // their own values as needed. If this variable is a simple - // type, we read all data for it into m_data. - // Make sure this type has a value before we try and read it + // The DWARF expression result was an address in the inferior process. If + // this variable is an aggregate type, we just need the address as the + // main value as all child variable objects will rely upon this location + // and add an offset and then read their own values as needed. If this + // variable is a simple type, we read all data for it into m_data. Make + // sure this type has a value before we try and read it // If we have a file address, convert it to a load address if we can. if (value_type == Value::eValueTypeFileAddress && @@ -192,14 +191,14 @@ bool ValueObjectMemory::UpdateValue() { } if (!CanProvideValue()) { - // this value object represents an aggregate type whose - // children have values, but this object does not. So we - // say we are changed if our location has changed. + // this value object represents an aggregate type whose children have + // values, but this object does not. So we say we are changed if our + // location has changed. SetValueDidChange(value_type != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); } else { - // Copy the Value and set the context to use our Variable - // so it can extract read its value into m_data appropriately + // Copy the Value and set the context to use our Variable so it can + // extract read its value into m_data appropriately Value value(m_value); if (m_type_sp) value.SetContext(Value::eContextTypeLLDBType, m_type_sp.get()); diff --git a/source/Core/ValueObjectSyntheticFilter.cpp b/source/Core/ValueObjectSyntheticFilter.cpp index 87310c423cb89..044387a4ae122 100644 --- a/source/Core/ValueObjectSyntheticFilter.cpp +++ b/source/Core/ValueObjectSyntheticFilter.cpp @@ -129,7 +129,19 @@ lldb::ValueType ValueObjectSynthetic::GetValueType() const { } void ValueObjectSynthetic::CreateSynthFilter() { - m_synth_filter_ap = (m_synth_sp->GetFrontEnd(*m_parent)); + ValueObject *valobj_for_frontend = m_parent; + if (m_synth_sp->WantsDereference()) + { + CompilerType type = m_parent->GetCompilerType(); + if (type.IsValid() && type.IsPointerOrReferenceType()) + { + Status error; + lldb::ValueObjectSP deref_sp = m_parent->Dereference(error); + if (error.Success()) + valobj_for_frontend = deref_sp.get(); + } + } + m_synth_filter_ap = (m_synth_sp->GetFrontEnd(*valobj_for_frontend)); if (!m_synth_filter_ap.get()) m_synth_filter_ap = llvm::make_unique<DummySyntheticFrontEnd>(*m_parent); } @@ -171,10 +183,9 @@ bool ValueObjectSynthetic::UpdateValue() { m_children_byindex.Clear(); m_name_toindex.Clear(); // usually, an object's value can change but this does not alter its - // children count - // for a synthetic VO that might indeed happen, so we need to tell the upper - // echelons - // that they need to come back to us asking for children + // children count for a synthetic VO that might indeed happen, so we need + // to tell the upper echelons that they need to come back to us asking for + // children m_children_count_valid = false; m_synthetic_children_cache.Clear(); m_synthetic_children_count = UINT32_MAX; diff --git a/source/Core/ValueObjectVariable.cpp b/source/Core/ValueObjectVariable.cpp index 8436ba529a54c..bfe5c3de7fbfc 100644 --- a/source/Core/ValueObjectVariable.cpp +++ b/source/Core/ValueObjectVariable.cpp @@ -175,9 +175,8 @@ bool ValueObjectVariable::UpdateValue() { switch (value_type) { case Value::eValueTypeFileAddress: // If this type is a pointer, then its children will be considered load - // addresses - // if the pointer or reference is dereferenced, but only if the process - // is alive. + // addresses if the pointer or reference is dereferenced, but only if + // the process is alive. // // There could be global variables like in the following code: // struct LinkedListNode { Foo* foo; LinkedListNode* next; }; @@ -187,14 +186,11 @@ bool ValueObjectVariable::UpdateValue() { // LinkedListNode g_first_node = { &g_foo1, &g_second_node }; // // When we aren't running, we should be able to look at these variables - // using - // the "target variable" command. Children of the "g_first_node" always - // will - // be of the same address type as the parent. But children of the "next" - // member of - // LinkedListNode will become load addresses if we have a live process, - // or remain - // what a file address if it what a file address. + // using the "target variable" command. Children of the "g_first_node" + // always will be of the same address type as the parent. But children + // of the "next" member of LinkedListNode will become load addresses if + // we have a live process, or remain what a file address if it what a + // file address. if (process_is_alive && is_pointer_or_ref) SetAddressTypeOfChildren(eAddressTypeLoad); else @@ -202,12 +198,10 @@ bool ValueObjectVariable::UpdateValue() { break; case Value::eValueTypeHostAddress: // Same as above for load addresses, except children of pointer or refs - // are always - // load addresses. Host addresses are used to store freeze dried - // variables. If this - // type is a struct, the entire struct contents will be copied into the - // heap of the - // LLDB process, but we do not currrently follow any pointers. + // are always load addresses. Host addresses are used to store freeze + // dried variables. If this type is a struct, the entire struct + // contents will be copied into the heap of the + // LLDB process, but we do not currently follow any pointers. if (is_pointer_or_ref) SetAddressTypeOfChildren(eAddressTypeLoad); else @@ -224,8 +218,8 @@ bool ValueObjectVariable::UpdateValue() { case Value::eValueTypeVector: // fall through case Value::eValueTypeScalar: - // The variable value is in the Scalar value inside the m_value. - // We can point our m_data right to it. + // The variable value is in the Scalar value inside the m_value. We can + // point our m_data right to it. m_error = m_value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get()); break; @@ -233,44 +227,26 @@ bool ValueObjectVariable::UpdateValue() { case Value::eValueTypeFileAddress: case Value::eValueTypeLoadAddress: case Value::eValueTypeHostAddress: - // The DWARF expression result was an address in the inferior - // process. If this variable is an aggregate type, we just need - // the address as the main value as all child variable objects - // will rely upon this location and add an offset and then read - // their own values as needed. If this variable is a simple - // type, we read all data for it into m_data. - // Make sure this type has a value before we try and read it + // The DWARF expression result was an address in the inferior process. + // If this variable is an aggregate type, we just need the address as + // the main value as all child variable objects will rely upon this + // location and add an offset and then read their own values as needed. + // If this variable is a simple type, we read all data for it into + // m_data. Make sure this type has a value before we try and read it // If we have a file address, convert it to a load address if we can. - if (value_type == Value::eValueTypeFileAddress && process_is_alive) { - lldb::addr_t file_addr = - m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); - if (file_addr != LLDB_INVALID_ADDRESS) { - SymbolContext var_sc; - variable->CalculateSymbolContext(&var_sc); - if (var_sc.module_sp) { - ObjectFile *objfile = var_sc.module_sp->GetObjectFile(); - if (objfile) { - Address so_addr(file_addr, objfile->GetSectionList()); - lldb::addr_t load_addr = so_addr.GetLoadAddress(target); - if (load_addr != LLDB_INVALID_ADDRESS) { - m_value.SetValueType(Value::eValueTypeLoadAddress); - m_value.GetScalar() = load_addr; - } - } - } - } - } + if (value_type == Value::eValueTypeFileAddress && process_is_alive) + m_value.ConvertToLoadAddress(GetModule().get(), target); if (!CanProvideValue()) { - // this value object represents an aggregate type whose - // children have values, but this object does not. So we - // say we are changed if our location has changed. + // this value object represents an aggregate type whose children have + // values, but this object does not. So we say we are changed if our + // location has changed. SetValueDidChange(value_type != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); } else { - // Copy the Value and set the context to use our Variable - // so it can extract read its value into m_data appropriately + // Copy the Value and set the context to use our Variable so it can + // extract read its value into m_data appropriately Value value(m_value); value.SetContext(Value::eContextTypeVariable, variable); m_error = @@ -299,14 +275,13 @@ bool ValueObjectVariable::IsInScope() { if (frame) { return m_variable_sp->IsInScope(frame); } else { - // This ValueObject had a frame at one time, but now we - // can't locate it, so return false since we probably aren't - // in scope. + // This ValueObject had a frame at one time, but now we can't locate it, + // so return false since we probably aren't in scope. return false; } } - // We have a variable that wasn't tied to a frame, which - // means it is a global and is always in scope. + // We have a variable that wasn't tied to a frame, which means it is a global + // and is always in scope. return true; } |