[Lldb-commits] [lldb] r280751 - *** This commit represents a complete reformatting of the LLDB source code
Kate Stone via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 6 13:58:36 PDT 2016
Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Tue Sep 6 15:57:50 2016
@@ -12,14 +12,16 @@
// C Includes
// C++ Includes
// Other libraries and framework includes
-#include "llvm/Support/raw_os_ostream.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_os_ostream.h"
// Project includes
+#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
+#include "Plugins/Language/ObjC/ObjCLanguage.h"
#include "lldb/Core/AddressResolverFileLine.h"
-#include "lldb/Core/Error.h"
#include "lldb/Core/DataBuffer.h"
#include "lldb/Core/DataBufferHeap.h"
+#include "lldb/Core/Error.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
@@ -37,14 +39,12 @@
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Symbol/TypeMap.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
-#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
-#include "Plugins/Language/ObjC/ObjCLanguage.h"
-#include "lldb/Symbol/TypeMap.h"
#include "Plugins/ObjectFile/JIT/ObjectFileJIT.h"
@@ -56,51 +56,49 @@ using namespace lldb_private;
// 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.
-
- static ModuleCollection *g_module_collection = nullptr;
- if (g_module_collection == nullptr)
- g_module_collection = new ModuleCollection();
-
- return *g_module_collection;
-}
-
-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
-
- static std::recursive_mutex *g_module_collection_mutex = nullptr;
- if (g_module_collection_mutex == nullptr)
- g_module_collection_mutex = new std::recursive_mutex; // NOTE: known leak
- return *g_module_collection_mutex;
-}
-
-size_t
-Module::GetNumberAllocatedModules ()
-{
- std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
- return GetModuleCollection().size();
-}
-
-Module *
-Module::GetAllocatedModuleAtIndex (size_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
- ModuleCollection &modules = GetModuleCollection();
- if (idx < modules.size())
- return modules[idx];
- return nullptr;
+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.
+
+ static ModuleCollection *g_module_collection = nullptr;
+ if (g_module_collection == nullptr)
+ g_module_collection = new ModuleCollection();
+
+ return *g_module_collection;
+}
+
+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
+
+ static std::recursive_mutex *g_module_collection_mutex = nullptr;
+ if (g_module_collection_mutex == nullptr)
+ g_module_collection_mutex = new std::recursive_mutex; // NOTE: known leak
+ return *g_module_collection_mutex;
+}
+
+size_t Module::GetNumberAllocatedModules() {
+ std::lock_guard<std::recursive_mutex> guard(
+ GetAllocationModuleCollectionMutex());
+ return GetModuleCollection().size();
+}
+
+Module *Module::GetAllocatedModuleAtIndex(size_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(
+ GetAllocationModuleCollectionMutex());
+ ModuleCollection &modules = GetModuleCollection();
+ if (idx < modules.size())
+ return modules[idx];
+ return nullptr;
}
#if 0
@@ -141,1779 +139,1544 @@ namespace lldb {
#endif
Module::Module(const ModuleSpec &module_spec)
- : m_mutex(),
- m_mod_time(),
- m_arch(),
- m_uuid(),
- m_file(),
- m_platform_file(),
- m_remote_install_file(),
- m_symfile_spec(),
- m_object_name(),
- m_object_offset(),
- m_object_mod_time(),
- m_objfile_sp(),
- m_symfile_ap(),
- m_type_system_map(),
- m_source_mappings(),
- m_sections_ap(),
- m_did_load_objfile(false),
- m_did_load_symbol_vendor(false),
- m_did_parse_uuid(false),
- m_file_has_changed(false),
- m_first_file_changed_log(false)
-{
- // Scope for locker below...
- {
- std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
- GetModuleCollection().push_back(this);
- }
-
- Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_MODULES));
- if (log != nullptr)
- log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this),
- module_spec.GetArchitecture().GetArchitectureName(), module_spec.GetFileSpec().GetPath().c_str(),
- module_spec.GetObjectName().IsEmpty() ? "" : "(",
- module_spec.GetObjectName().IsEmpty() ? "" : 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
- ModuleSpecList modules_specs;
- if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0, modules_specs) == 0)
- return;
-
- // 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
- // 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...
- ModuleSpec matching_module_spec;
- if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) == 0)
- return;
-
- if (module_spec.GetFileSpec())
- m_mod_time = module_spec.GetFileSpec().GetModificationTime();
- else if (matching_module_spec.GetFileSpec())
- m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime();
-
- // 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())
- m_arch = module_spec.GetArchitecture();
-
- // Copy the file spec over and use the specified one (if there was one) so we
- // don't use a path that might have gotten resolved a path in 'matching_module_spec'
- if (module_spec.GetFileSpec())
- m_file = module_spec.GetFileSpec();
- else if (matching_module_spec.GetFileSpec())
- m_file = matching_module_spec.GetFileSpec();
-
- // Copy the platform file spec over
- if (module_spec.GetPlatformFileSpec())
- m_platform_file = module_spec.GetPlatformFileSpec();
- else if (matching_module_spec.GetPlatformFileSpec())
- m_platform_file = matching_module_spec.GetPlatformFileSpec();
-
- // Copy the symbol file spec over
- if (module_spec.GetSymbolFileSpec())
- m_symfile_spec = module_spec.GetSymbolFileSpec();
- else if (matching_module_spec.GetSymbolFileSpec())
- m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
-
- // Copy the object name over
- if (matching_module_spec.GetObjectName())
- m_object_name = matching_module_spec.GetObjectName();
- else
- m_object_name = module_spec.GetObjectName();
+ : m_mutex(), m_mod_time(), m_arch(), m_uuid(), m_file(), m_platform_file(),
+ m_remote_install_file(), m_symfile_spec(), m_object_name(),
+ m_object_offset(), m_object_mod_time(), m_objfile_sp(), m_symfile_ap(),
+ m_type_system_map(), m_source_mappings(), m_sections_ap(),
+ m_did_load_objfile(false), m_did_load_symbol_vendor(false),
+ m_did_parse_uuid(false), m_file_has_changed(false),
+ m_first_file_changed_log(false) {
+ // Scope for locker below...
+ {
+ std::lock_guard<std::recursive_mutex> guard(
+ GetAllocationModuleCollectionMutex());
+ GetModuleCollection().push_back(this);
+ }
- // 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();
-}
-
-Module::Module(const FileSpec &file_spec, const ArchSpec &arch, const ConstString *object_name,
- lldb::offset_t object_offset, const TimeValue *object_mod_time_ptr)
- : m_mutex(),
- m_mod_time(file_spec.GetModificationTime()),
- m_arch(arch),
- m_uuid(),
- m_file(file_spec),
- m_platform_file(),
- m_remote_install_file(),
- m_symfile_spec(),
- m_object_name(),
- m_object_offset(object_offset),
- m_object_mod_time(),
- m_objfile_sp(),
- m_symfile_ap(),
- m_type_system_map(),
- m_source_mappings(),
- m_sections_ap(),
- m_did_load_objfile(false),
- m_did_load_symbol_vendor(false),
- m_did_parse_uuid(false),
- m_file_has_changed(false),
- m_first_file_changed_log(false)
-{
- // Scope for locker below...
- {
- std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
- GetModuleCollection().push_back(this);
- }
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT |
+ LIBLLDB_LOG_MODULES));
+ if (log != nullptr)
+ log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this),
+ module_spec.GetArchitecture().GetArchitectureName(),
+ module_spec.GetFileSpec().GetPath().c_str(),
+ module_spec.GetObjectName().IsEmpty() ? "" : "(",
+ module_spec.GetObjectName().IsEmpty()
+ ? ""
+ : 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
+ ModuleSpecList modules_specs;
+ if (ObjectFile::GetModuleSpecifications(module_spec.GetFileSpec(), 0, 0,
+ modules_specs) == 0)
+ return;
+
+ // 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
+ // 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...
+ ModuleSpec matching_module_spec;
+ if (modules_specs.FindMatchingModuleSpec(module_spec, matching_module_spec) ==
+ 0)
+ return;
+
+ if (module_spec.GetFileSpec())
+ m_mod_time = module_spec.GetFileSpec().GetModificationTime();
+ else if (matching_module_spec.GetFileSpec())
+ m_mod_time = matching_module_spec.GetFileSpec().GetModificationTime();
+
+ // 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())
+ m_arch = module_spec.GetArchitecture();
+
+ // Copy the file spec over and use the specified one (if there was one) so we
+ // don't use a path that might have gotten resolved a path in
+ // 'matching_module_spec'
+ if (module_spec.GetFileSpec())
+ m_file = module_spec.GetFileSpec();
+ else if (matching_module_spec.GetFileSpec())
+ m_file = matching_module_spec.GetFileSpec();
+
+ // Copy the platform file spec over
+ if (module_spec.GetPlatformFileSpec())
+ m_platform_file = module_spec.GetPlatformFileSpec();
+ else if (matching_module_spec.GetPlatformFileSpec())
+ m_platform_file = matching_module_spec.GetPlatformFileSpec();
+
+ // Copy the symbol file spec over
+ if (module_spec.GetSymbolFileSpec())
+ m_symfile_spec = module_spec.GetSymbolFileSpec();
+ else if (matching_module_spec.GetSymbolFileSpec())
+ m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
+
+ // Copy the object name over
+ if (matching_module_spec.GetObjectName())
+ m_object_name = matching_module_spec.GetObjectName();
+ 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
+ m_object_offset = matching_module_spec.GetObjectOffset();
+ m_object_mod_time = matching_module_spec.GetObjectModificationTime();
+}
+
+Module::Module(const FileSpec &file_spec, const ArchSpec &arch,
+ const ConstString *object_name, lldb::offset_t object_offset,
+ const TimeValue *object_mod_time_ptr)
+ : m_mutex(), m_mod_time(file_spec.GetModificationTime()), m_arch(arch),
+ m_uuid(), m_file(file_spec), m_platform_file(), m_remote_install_file(),
+ m_symfile_spec(), m_object_name(), m_object_offset(object_offset),
+ m_object_mod_time(), m_objfile_sp(), m_symfile_ap(), m_type_system_map(),
+ m_source_mappings(), m_sections_ap(), m_did_load_objfile(false),
+ m_did_load_symbol_vendor(false), m_did_parse_uuid(false),
+ m_file_has_changed(false), m_first_file_changed_log(false) {
+ // Scope for locker below...
+ {
+ std::lock_guard<std::recursive_mutex> guard(
+ GetAllocationModuleCollectionMutex());
+ GetModuleCollection().push_back(this);
+ }
- if (object_name)
- m_object_name = *object_name;
+ if (object_name)
+ m_object_name = *object_name;
- if (object_mod_time_ptr)
- m_object_mod_time = *object_mod_time_ptr;
+ if (object_mod_time_ptr)
+ m_object_mod_time = *object_mod_time_ptr;
- Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_MODULES));
- if (log != nullptr)
- log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this), m_arch.GetArchitectureName(),
- m_file.GetPath().c_str(), m_object_name.IsEmpty() ? "" : "(",
- m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""), m_object_name.IsEmpty() ? "" : ")");
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT |
+ LIBLLDB_LOG_MODULES));
+ if (log != nullptr)
+ log->Printf("%p Module::Module((%s) '%s%s%s%s')", static_cast<void *>(this),
+ m_arch.GetArchitectureName(), m_file.GetPath().c_str(),
+ m_object_name.IsEmpty() ? "" : "(",
+ m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
+ m_object_name.IsEmpty() ? "" : ")");
}
Module::Module()
- : m_mutex(),
- m_mod_time(),
- m_arch(),
- m_uuid(),
- m_file(),
- m_platform_file(),
- m_remote_install_file(),
- m_symfile_spec(),
- m_object_name(),
- m_object_offset(0),
- m_object_mod_time(),
- m_objfile_sp(),
- m_symfile_ap(),
- m_type_system_map(),
- m_source_mappings(),
- m_sections_ap(),
- m_did_load_objfile(false),
- m_did_load_symbol_vendor(false),
- m_did_parse_uuid(false),
- m_file_has_changed(false),
- m_first_file_changed_log(false)
-{
- std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
- GetModuleCollection().push_back(this);
-}
-
-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
+ : m_mutex(), m_mod_time(), m_arch(), m_uuid(), m_file(), m_platform_file(),
+ m_remote_install_file(), m_symfile_spec(), m_object_name(),
+ m_object_offset(0), m_object_mod_time(), m_objfile_sp(), m_symfile_ap(),
+ m_type_system_map(), m_source_mappings(), m_sections_ap(),
+ m_did_load_objfile(false), m_did_load_symbol_vendor(false),
+ m_did_parse_uuid(false), m_file_has_changed(false),
+ m_first_file_changed_log(false) {
+ std::lock_guard<std::recursive_mutex> guard(
+ GetAllocationModuleCollectionMutex());
+ GetModuleCollection().push_back(this);
+}
+
+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
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ // Scope for locker below...
+ {
+ std::lock_guard<std::recursive_mutex> guard(
+ GetAllocationModuleCollectionMutex());
+ ModuleCollection &modules = GetModuleCollection();
+ ModuleCollection::iterator end = modules.end();
+ ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
+ assert(pos != end);
+ modules.erase(pos);
+ }
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT |
+ LIBLLDB_LOG_MODULES));
+ if (log != nullptr)
+ log->Printf("%p Module::~Module((%s) '%s%s%s%s')",
+ static_cast<void *>(this), m_arch.GetArchitectureName(),
+ m_file.GetPath().c_str(), m_object_name.IsEmpty() ? "" : "(",
+ m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
+ m_object_name.IsEmpty() ? "" : ")");
+ // Release any auto pointers before we start tearing down our member
+ // variables since the object file and symbol files might need to make
+ // function calls back into this module object. The ordering is important
+ // here because symbol files can require the module object file. So we tear
+ // down the symbol file first, then the object file.
+ m_sections_ap.reset();
+ m_symfile_ap.reset();
+ m_objfile_sp.reset();
+}
+
+ObjectFile *Module::GetMemoryObjectFile(const lldb::ProcessSP &process_sp,
+ lldb::addr_t header_addr, Error &error,
+ size_t size_to_read) {
+ if (m_objfile_sp) {
+ error.SetErrorString("object file already exists");
+ } else {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
- // Scope for locker below...
- {
- std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
- ModuleCollection &modules = GetModuleCollection();
- ModuleCollection::iterator end = modules.end();
- ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
- assert (pos != end);
- modules.erase(pos);
- }
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
- if (log != nullptr)
- log->Printf ("%p Module::~Module((%s) '%s%s%s%s')",
- static_cast<void*>(this),
- m_arch.GetArchitectureName(),
- m_file.GetPath().c_str(),
- m_object_name.IsEmpty() ? "" : "(",
- m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
- m_object_name.IsEmpty() ? "" : ")");
- // Release any auto pointers before we start tearing down our member
- // variables since the object file and symbol files might need to make
- // function calls back into this module object. The ordering is important
- // here because symbol files can require the module object file. So we tear
- // down the symbol file first, then the object file.
- m_sections_ap.reset();
- m_symfile_ap.reset();
- m_objfile_sp.reset();
-}
-
-ObjectFile *
-Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error, size_t size_to_read)
-{
- if (m_objfile_sp)
- {
- error.SetErrorString ("object file already exists");
- }
- else
- {
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (process_sp)
- {
- m_did_load_objfile = true;
- std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (size_to_read, 0));
- Error readmem_error;
- const size_t bytes_read = process_sp->ReadMemory (header_addr,
- data_ap->GetBytes(),
- data_ap->GetByteSize(),
- readmem_error);
- if (bytes_read == size_to_read)
- {
- DataBufferSP data_sp(data_ap.release());
- m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
- if (m_objfile_sp)
- {
- StreamString s;
- s.Printf("0x%16.16" PRIx64, header_addr);
- m_object_name.SetCString (s.GetData());
-
- // 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.
- m_objfile_sp->GetArchitecture (m_arch);
- }
- else
- {
- error.SetErrorString ("unable to find suitable object file plug-in");
- }
- }
- else
- {
- error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString());
- }
- }
- else
- {
- error.SetErrorString ("invalid process");
- }
+ if (process_sp) {
+ m_did_load_objfile = true;
+ std::unique_ptr<DataBufferHeap> data_ap(
+ new DataBufferHeap(size_to_read, 0));
+ Error readmem_error;
+ const size_t bytes_read =
+ process_sp->ReadMemory(header_addr, data_ap->GetBytes(),
+ data_ap->GetByteSize(), readmem_error);
+ if (bytes_read == size_to_read) {
+ DataBufferSP data_sp(data_ap.release());
+ m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp,
+ header_addr, data_sp);
+ if (m_objfile_sp) {
+ StreamString s;
+ s.Printf("0x%16.16" PRIx64, header_addr);
+ m_object_name.SetCString(s.GetData());
+
+ // 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.
+ m_objfile_sp->GetArchitecture(m_arch);
+ } else {
+ error.SetErrorString("unable to find suitable object file plug-in");
+ }
+ } else {
+ error.SetErrorStringWithFormat("unable to read header from memory: %s",
+ readmem_error.AsCString());
+ }
+ } else {
+ error.SetErrorString("invalid process");
}
- return m_objfile_sp.get();
+ }
+ return m_objfile_sp.get();
}
-const lldb_private::UUID&
-Module::GetUUID()
-{
- if (!m_did_parse_uuid.load())
- {
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (!m_did_parse_uuid.load())
- {
- ObjectFile * obj_file = GetObjectFile ();
+const lldb_private::UUID &Module::GetUUID() {
+ if (!m_did_parse_uuid.load()) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ if (!m_did_parse_uuid.load()) {
+ ObjectFile *obj_file = GetObjectFile();
- if (obj_file != nullptr)
- {
- obj_file->GetUUID(&m_uuid);
- m_did_parse_uuid = true;
- }
- }
+ if (obj_file != nullptr) {
+ obj_file->GetUUID(&m_uuid);
+ m_did_parse_uuid = true;
+ }
}
- return m_uuid;
+ }
+ return m_uuid;
}
-TypeSystem *
-Module::GetTypeSystemForLanguage (LanguageType language)
-{
- return m_type_system_map.GetTypeSystemForLanguage(language, this, true);
+TypeSystem *Module::GetTypeSystemForLanguage(LanguageType language) {
+ return m_type_system_map.GetTypeSystemForLanguage(language, this, true);
}
-void
-Module::ParseAllDebugSymbols()
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- size_t num_comp_units = GetNumCompileUnits();
- if (num_comp_units == 0)
- return;
+void Module::ParseAllDebugSymbols() {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ size_t num_comp_units = GetNumCompileUnits();
+ if (num_comp_units == 0)
+ return;
- SymbolContext sc;
- sc.module_sp = shared_from_this();
- SymbolVendor *symbols = GetSymbolVendor ();
+ SymbolContext sc;
+ sc.module_sp = shared_from_this();
+ SymbolVendor *symbols = GetSymbolVendor();
- for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
- {
- sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
- if (sc.comp_unit)
- {
- sc.function = nullptr;
- symbols->ParseVariablesForContext(sc);
+ for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++) {
+ sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
+ if (sc.comp_unit) {
+ sc.function = nullptr;
+ symbols->ParseVariablesForContext(sc);
- symbols->ParseCompileUnitFunctions(sc);
+ symbols->ParseCompileUnitFunctions(sc);
- for (size_t func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != nullptr; ++func_idx)
- {
- symbols->ParseFunctionBlocks(sc);
+ for (size_t func_idx = 0;
+ (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) !=
+ nullptr;
+ ++func_idx) {
+ symbols->ParseFunctionBlocks(sc);
- // Parse the variables for this function and all its blocks
- symbols->ParseVariablesForContext(sc);
- }
+ // Parse the variables for this function and all its blocks
+ symbols->ParseVariablesForContext(sc);
+ }
- // Parse all types for this compile unit
- sc.function = nullptr;
- symbols->ParseTypes(sc);
- }
+ // Parse all types for this compile unit
+ sc.function = nullptr;
+ symbols->ParseTypes(sc);
}
+ }
}
-void
-Module::CalculateSymbolContext(SymbolContext* sc)
-{
- sc->module_sp = shared_from_this();
+void Module::CalculateSymbolContext(SymbolContext *sc) {
+ sc->module_sp = shared_from_this();
}
-ModuleSP
-Module::CalculateSymbolContextModule ()
-{
- return shared_from_this();
-}
+ModuleSP Module::CalculateSymbolContextModule() { return shared_from_this(); }
-void
-Module::DumpSymbolContext(Stream *s)
-{
- s->Printf(", Module{%p}", static_cast<void*>(this));
+void Module::DumpSymbolContext(Stream *s) {
+ s->Printf(", Module{%p}", static_cast<void *>(this));
}
-size_t
-Module::GetNumCompileUnits()
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- Timer scoped_timer(LLVM_PRETTY_FUNCTION,
- "Module::GetNumCompileUnits (module = %p)",
- static_cast<void*>(this));
- SymbolVendor *symbols = GetSymbolVendor ();
- if (symbols)
- return symbols->GetNumCompileUnits();
- return 0;
-}
-
-CompUnitSP
-Module::GetCompileUnitAtIndex (size_t index)
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- size_t num_comp_units = GetNumCompileUnits ();
- CompUnitSP cu_sp;
-
- if (index < num_comp_units)
- {
- SymbolVendor *symbols = GetSymbolVendor ();
- if (symbols)
- cu_sp = symbols->GetCompileUnitAtIndex(index);
- }
- return cu_sp;
-}
-
-bool
-Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- Timer scoped_timer(LLVM_PRETTY_FUNCTION, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr);
- SectionList *section_list = GetSectionList();
- if (section_list)
- return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list);
- return false;
+size_t Module::GetNumCompileUnits() {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ Timer scoped_timer(LLVM_PRETTY_FUNCTION,
+ "Module::GetNumCompileUnits (module = %p)",
+ static_cast<void *>(this));
+ SymbolVendor *symbols = GetSymbolVendor();
+ if (symbols)
+ return symbols->GetNumCompileUnits();
+ return 0;
}
-uint32_t
-Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc,
- bool resolve_tail_call_address)
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- uint32_t resolved_flags = 0;
-
- // Clear the result symbol context in case we don't find anything, but don't clear the target
- sc.Clear(false);
+CompUnitSP Module::GetCompileUnitAtIndex(size_t index) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ size_t num_comp_units = GetNumCompileUnits();
+ CompUnitSP cu_sp;
- // Get the section from the section/offset address.
- SectionSP section_sp (so_addr.GetSection());
-
- // 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.
- sc.module_sp = shared_from_this();
- resolved_flags |= eSymbolContextModule;
-
- SymbolVendor* sym_vendor = GetSymbolVendor();
- if (!sym_vendor)
- return resolved_flags;
-
- // Resolve the compile unit, function, block, line table or line
- // entry if requested.
- if (resolve_scope & eSymbolContextCompUnit ||
- resolve_scope & eSymbolContextFunction ||
- resolve_scope & eSymbolContextBlock ||
- resolve_scope & eSymbolContextLineEntry ||
- resolve_scope & eSymbolContextVariable )
- {
- resolved_flags |= 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.
- if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
- {
- Symtab *symtab = sym_vendor->GetSymtab();
- if (symtab && so_addr.IsSectionOffset())
- {
- Symbol *matching_symbol = nullptr;
-
- symtab->ForEachSymbolContainingFileAddress(so_addr.GetFileAddress(),
- [&matching_symbol](Symbol *symbol) -> bool {
- if (symbol->GetType() != eSymbolTypeInvalid)
- {
- matching_symbol = symbol;
- return false; // Stop iterating
- }
- return true; // Keep iterating
- });
- sc.symbol = matching_symbol;
- if (!sc.symbol &&
- resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction))
- {
- bool verify_unique = false; // No need to check again since ResolveSymbolContext failed to find a symbol at this address.
- if (ObjectFile *obj_file = sc.module_sp->GetObjectFile())
- sc.symbol = obj_file->ResolveSymbolForAddress(so_addr, verify_unique);
- }
-
- 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.
- ObjectFile *symtab_objfile = symtab->GetObjectFile();
- if (symtab_objfile && symtab_objfile->IsStripped())
- {
- SymbolFile *symfile = sym_vendor->GetSymbolFile();
- if (symfile)
- {
- ObjectFile *symfile_objfile = symfile->GetObjectFile();
- if (symfile_objfile != symtab_objfile)
- {
- Symtab *symfile_symtab = symfile_objfile->GetSymtab();
- if (symfile_symtab)
- {
- Symbol *symbol = symfile_symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
- if (symbol && !symbol->IsSynthetic())
- {
- sc.symbol = symbol;
- }
- }
- }
- }
- }
- }
- resolved_flags |= eSymbolContextSymbol;
- }
- }
- }
-
- // 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.
- if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol) &&
- resolve_tail_call_address && so_addr.IsSectionOffset())
- {
- Address previous_addr = so_addr;
- previous_addr.Slide(-1);
+ if (index < num_comp_units) {
+ SymbolVendor *symbols = GetSymbolVendor();
+ if (symbols)
+ cu_sp = symbols->GetCompileUnitAtIndex(index);
+ }
+ return cu_sp;
+}
+
+bool Module::ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ Timer scoped_timer(LLVM_PRETTY_FUNCTION,
+ "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")",
+ vm_addr);
+ SectionList *section_list = GetSectionList();
+ if (section_list)
+ return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list);
+ return false;
+}
+
+uint32_t Module::ResolveSymbolContextForAddress(
+ const Address &so_addr, uint32_t resolve_scope, SymbolContext &sc,
+ bool resolve_tail_call_address) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ uint32_t resolved_flags = 0;
+
+ // Clear the result symbol context in case we don't find anything, but don't
+ // clear the target
+ sc.Clear(false);
+
+ // Get the section from the section/offset address.
+ SectionSP section_sp(so_addr.GetSection());
+
+ // 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.
+ sc.module_sp = shared_from_this();
+ resolved_flags |= eSymbolContextModule;
- bool do_resolve_tail_call_address = false; // prevent recursion
- const uint32_t flags = ResolveSymbolContextForAddress(previous_addr, resolve_scope, sc,
- do_resolve_tail_call_address);
- if (flags & eSymbolContextSymbol)
- {
- AddressRange addr_range;
- if (sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, addr_range))
- {
- 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.
- if (so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() ||
- so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() + addr_range.GetByteSize())
- {
- resolved_flags |= flags;
- }
- }
- else
- {
- sc.symbol = nullptr; // Don't trust the symbol if the sections didn't match.
+ SymbolVendor *sym_vendor = GetSymbolVendor();
+ if (!sym_vendor)
+ return resolved_flags;
+
+ // Resolve the compile unit, function, block, line table or line
+ // entry if requested.
+ if (resolve_scope & eSymbolContextCompUnit ||
+ resolve_scope & eSymbolContextFunction ||
+ resolve_scope & eSymbolContextBlock ||
+ resolve_scope & eSymbolContextLineEntry ||
+ resolve_scope & eSymbolContextVariable) {
+ resolved_flags |=
+ 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.
+ if (resolve_scope & eSymbolContextSymbol &&
+ !(resolved_flags & eSymbolContextSymbol)) {
+ Symtab *symtab = sym_vendor->GetSymtab();
+ if (symtab && so_addr.IsSectionOffset()) {
+ Symbol *matching_symbol = nullptr;
+
+ symtab->ForEachSymbolContainingFileAddress(
+ so_addr.GetFileAddress(),
+ [&matching_symbol](Symbol *symbol) -> bool {
+ if (symbol->GetType() != eSymbolTypeInvalid) {
+ matching_symbol = symbol;
+ return false; // Stop iterating
+ }
+ return true; // Keep iterating
+ });
+ sc.symbol = matching_symbol;
+ if (!sc.symbol && resolve_scope & eSymbolContextFunction &&
+ !(resolved_flags & eSymbolContextFunction)) {
+ bool verify_unique = false; // No need to check again since
+ // ResolveSymbolContext failed to find a
+ // symbol at this address.
+ if (ObjectFile *obj_file = sc.module_sp->GetObjectFile())
+ sc.symbol =
+ obj_file->ResolveSymbolForAddress(so_addr, verify_unique);
+ }
+
+ 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.
+ ObjectFile *symtab_objfile = symtab->GetObjectFile();
+ if (symtab_objfile && symtab_objfile->IsStripped()) {
+ SymbolFile *symfile = sym_vendor->GetSymbolFile();
+ if (symfile) {
+ ObjectFile *symfile_objfile = symfile->GetObjectFile();
+ if (symfile_objfile != symtab_objfile) {
+ Symtab *symfile_symtab = symfile_objfile->GetSymtab();
+ if (symfile_symtab) {
+ Symbol *symbol =
+ symfile_symtab->FindSymbolContainingFileAddress(
+ so_addr.GetFileAddress());
+ if (symbol && !symbol->IsSynthetic()) {
+ sc.symbol = symbol;
}
+ }
}
+ }
}
+ }
+ resolved_flags |= eSymbolContextSymbol;
}
+ }
}
- return resolved_flags;
-}
-
-uint32_t
-Module::ResolveSymbolContextForFilePath
-(
- const char *file_path,
- uint32_t line,
- bool check_inlines,
- uint32_t resolve_scope,
- SymbolContextList& sc_list
-)
-{
- FileSpec file_spec(file_path, false);
- return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
-}
-
-uint32_t
-Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- Timer scoped_timer(LLVM_PRETTY_FUNCTION,
- "Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
- file_spec.GetPath().c_str(),
- line,
- check_inlines ? "yes" : "no",
- resolve_scope);
-
- const uint32_t initial_count = sc_list.GetSize();
- SymbolVendor *symbols = GetSymbolVendor ();
- if (symbols)
- symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);
-
- return sc_list.GetSize() - initial_count;
-}
-
-size_t
-Module::FindGlobalVariables (const ConstString &name,
- const CompilerDeclContext *parent_decl_ctx,
- bool append,
- size_t max_matches,
- VariableList& variables)
-{
- SymbolVendor *symbols = GetSymbolVendor ();
- if (symbols)
- return symbols->FindGlobalVariables(name, parent_decl_ctx, append, max_matches, variables);
- return 0;
-}
-
-size_t
-Module::FindGlobalVariables (const RegularExpression& regex,
- bool append,
- size_t max_matches,
- VariableList& variables)
-{
- SymbolVendor *symbols = GetSymbolVendor ();
- if (symbols)
- return symbols->FindGlobalVariables(regex, append, max_matches, variables);
- return 0;
-}
-
-size_t
-Module::FindCompileUnits (const FileSpec &path,
- bool append,
- SymbolContextList &sc_list)
-{
- if (!append)
- sc_list.Clear();
-
- const size_t start_size = sc_list.GetSize();
- const size_t num_compile_units = GetNumCompileUnits();
- SymbolContext sc;
- sc.module_sp = shared_from_this();
- const bool compare_directory = (bool)path.GetDirectory();
- for (size_t i = 0; i < num_compile_units; ++i)
- {
- sc.comp_unit = GetCompileUnitAtIndex(i).get();
- if (sc.comp_unit)
- {
- if (FileSpec::Equal (*sc.comp_unit, path, compare_directory))
- sc_list.Append(sc);
- }
- }
- return sc_list.GetSize() - start_size;
-}
-
-Module::LookupInfo::LookupInfo(const ConstString &name, uint32_t name_type_mask, lldb::LanguageType language) :
- m_name(name),
- m_lookup_name(),
- m_language(language),
- m_name_type_mask(0),
- m_match_name_after_lookup(false)
-{
- const char *name_cstr = name.GetCString();
- llvm::StringRef basename;
- llvm::StringRef context;
-
- if (name_type_mask & eFunctionNameTypeAuto)
- {
- if (CPlusPlusLanguage::IsCPPMangledName (name_cstr))
- m_name_type_mask = eFunctionNameTypeFull;
- else if ((language == eLanguageTypeUnknown ||
- Language::LanguageIsObjC(language)) &&
- ObjCLanguage::IsPossibleObjCMethodName (name_cstr))
- m_name_type_mask = eFunctionNameTypeFull;
- else if (Language::LanguageIsC(language))
- {
- m_name_type_mask = eFunctionNameTypeFull;
- }
+ // 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.
+ if (resolve_scope & eSymbolContextSymbol &&
+ !(resolved_flags & eSymbolContextSymbol) && resolve_tail_call_address &&
+ so_addr.IsSectionOffset()) {
+ Address previous_addr = so_addr;
+ previous_addr.Slide(-1);
+
+ bool do_resolve_tail_call_address = false; // prevent recursion
+ const uint32_t flags = ResolveSymbolContextForAddress(
+ previous_addr, resolve_scope, sc, do_resolve_tail_call_address);
+ if (flags & eSymbolContextSymbol) {
+ AddressRange addr_range;
+ if (sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
+ false, addr_range)) {
+ 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.
+ if (so_addr.GetOffset() ==
+ addr_range.GetBaseAddress().GetOffset() ||
+ so_addr.GetOffset() ==
+ addr_range.GetBaseAddress().GetOffset() +
+ addr_range.GetByteSize()) {
+ resolved_flags |= flags;
+ }
+ } else {
+ sc.symbol =
+ nullptr; // Don't trust the symbol if the sections didn't match.
+ }
+ }
+ }
+ }
+ }
+ return resolved_flags;
+}
+
+uint32_t Module::ResolveSymbolContextForFilePath(const char *file_path,
+ uint32_t line,
+ bool check_inlines,
+ uint32_t resolve_scope,
+ SymbolContextList &sc_list) {
+ FileSpec file_spec(file_path, false);
+ return ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
+ resolve_scope, sc_list);
+}
+
+uint32_t Module::ResolveSymbolContextsForFileSpec(const FileSpec &file_spec,
+ uint32_t line,
+ bool check_inlines,
+ uint32_t resolve_scope,
+ SymbolContextList &sc_list) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ Timer scoped_timer(LLVM_PRETTY_FUNCTION,
+ "Module::ResolveSymbolContextForFilePath (%s:%u, "
+ "check_inlines = %s, resolve_scope = 0x%8.8x)",
+ file_spec.GetPath().c_str(), line,
+ check_inlines ? "yes" : "no", resolve_scope);
+
+ const uint32_t initial_count = sc_list.GetSize();
+
+ SymbolVendor *symbols = GetSymbolVendor();
+ if (symbols)
+ symbols->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope,
+ sc_list);
+
+ return sc_list.GetSize() - initial_count;
+}
+
+size_t Module::FindGlobalVariables(const ConstString &name,
+ const CompilerDeclContext *parent_decl_ctx,
+ bool append, size_t max_matches,
+ VariableList &variables) {
+ SymbolVendor *symbols = GetSymbolVendor();
+ if (symbols)
+ return symbols->FindGlobalVariables(name, parent_decl_ctx, append,
+ max_matches, variables);
+ return 0;
+}
+
+size_t Module::FindGlobalVariables(const RegularExpression ®ex, bool append,
+ size_t max_matches,
+ VariableList &variables) {
+ SymbolVendor *symbols = GetSymbolVendor();
+ if (symbols)
+ return symbols->FindGlobalVariables(regex, append, max_matches, variables);
+ return 0;
+}
+
+size_t Module::FindCompileUnits(const FileSpec &path, bool append,
+ SymbolContextList &sc_list) {
+ if (!append)
+ sc_list.Clear();
+
+ const size_t start_size = sc_list.GetSize();
+ const size_t num_compile_units = GetNumCompileUnits();
+ SymbolContext sc;
+ sc.module_sp = shared_from_this();
+ const bool compare_directory = (bool)path.GetDirectory();
+ for (size_t i = 0; i < num_compile_units; ++i) {
+ sc.comp_unit = GetCompileUnitAtIndex(i).get();
+ if (sc.comp_unit) {
+ if (FileSpec::Equal(*sc.comp_unit, path, compare_directory))
+ sc_list.Append(sc);
+ }
+ }
+ return sc_list.GetSize() - start_size;
+}
+
+Module::LookupInfo::LookupInfo(const ConstString &name, uint32_t name_type_mask,
+ lldb::LanguageType language)
+ : m_name(name), m_lookup_name(), m_language(language), m_name_type_mask(0),
+ m_match_name_after_lookup(false) {
+ const char *name_cstr = name.GetCString();
+ llvm::StringRef basename;
+ llvm::StringRef context;
+
+ if (name_type_mask & eFunctionNameTypeAuto) {
+ if (CPlusPlusLanguage::IsCPPMangledName(name_cstr))
+ m_name_type_mask = eFunctionNameTypeFull;
+ else if ((language == eLanguageTypeUnknown ||
+ Language::LanguageIsObjC(language)) &&
+ ObjCLanguage::IsPossibleObjCMethodName(name_cstr))
+ m_name_type_mask = eFunctionNameTypeFull;
+ else if (Language::LanguageIsC(language)) {
+ m_name_type_mask = eFunctionNameTypeFull;
+ } else {
+ if ((language == eLanguageTypeUnknown ||
+ Language::LanguageIsObjC(language)) &&
+ ObjCLanguage::IsPossibleObjCSelector(name_cstr))
+ m_name_type_mask |= eFunctionNameTypeSelector;
+
+ CPlusPlusLanguage::MethodName cpp_method(name);
+ basename = cpp_method.GetBasename();
+ if (basename.empty()) {
+ if (CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context,
+ basename))
+ m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
else
- {
- if ((language == eLanguageTypeUnknown ||
- Language::LanguageIsObjC(language)) &&
- ObjCLanguage::IsPossibleObjCSelector(name_cstr))
- m_name_type_mask |= eFunctionNameTypeSelector;
-
- CPlusPlusLanguage::MethodName cpp_method (name);
- basename = cpp_method.GetBasename();
- if (basename.empty())
- {
- if (CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename))
- m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
- else
- m_name_type_mask |= eFunctionNameTypeFull;
- }
- else
- {
- m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
- }
- }
- }
- else
- {
- m_name_type_mask = 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.
- 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
- 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.
- CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename);
- }
- }
-
- if (name_type_mask & eFunctionNameTypeSelector)
- {
- if (!ObjCLanguage::IsPossibleObjCSelector(name_cstr))
- {
- m_name_type_mask &= ~(eFunctionNameTypeSelector);
- if (m_name_type_mask == eFunctionNameTypeNone)
- return;
- }
- }
-
- // Still try and get a basename in case someone specifies a name type mask of
- // eFunctionNameTypeFull and a name like "A::func"
+ m_name_type_mask |= eFunctionNameTypeFull;
+ } else {
+ m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
+ }
+ }
+ } else {
+ m_name_type_mask = 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.
+ 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
+ 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.
+ CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context,
+ basename);
+ }
+ }
+
+ if (name_type_mask & eFunctionNameTypeSelector) {
+ if (!ObjCLanguage::IsPossibleObjCSelector(name_cstr)) {
+ m_name_type_mask &= ~(eFunctionNameTypeSelector);
+ if (m_name_type_mask == eFunctionNameTypeNone)
+ return;
+ }
+ }
+
+ // Still try and get a basename in case someone specifies a name type mask
+ // of
+ // eFunctionNameTypeFull and a name like "A::func"
+ if (basename.empty()) {
+ if (name_type_mask & eFunctionNameTypeFull) {
+ CPlusPlusLanguage::MethodName cpp_method(name);
+ basename = cpp_method.GetBasename();
if (basename.empty())
- {
- if (name_type_mask & eFunctionNameTypeFull)
- {
- CPlusPlusLanguage::MethodName cpp_method (name);
- basename = cpp_method.GetBasename();
- if (basename.empty())
- CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename);
- }
+ CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context,
+ basename);
+ }
+ }
+ }
+
+ 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
+ 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"
+ m_lookup_name = name;
+ m_match_name_after_lookup = false;
+ }
+}
+
+void Module::LookupInfo::Prune(SymbolContextList &sc_list,
+ size_t start_idx) const {
+ if (m_match_name_after_lookup && m_name) {
+ SymbolContext sc;
+ size_t i = start_idx;
+ while (i < sc_list.GetSize()) {
+ if (!sc_list.GetContextAtIndex(i, sc))
+ break;
+ ConstString full_name(sc.GetFunctionName());
+ if (full_name &&
+ ::strstr(full_name.GetCString(), m_name.GetCString()) == nullptr) {
+ sc_list.RemoveContextAtIndex(i);
+ } else {
+ ++i;
+ }
+ }
+ }
+
+ // If we have only full name matches we might have tried to set breakpoint on
+ // "func"
+ // and specified eFunctionNameTypeFull, but we might have found "a::func()",
+ // "a::b::func()", "c::func()", "func()" and "func". Only "func()" and "func"
+ // should
+ // end up matching.
+ if (m_name_type_mask == eFunctionNameTypeFull) {
+ SymbolContext sc;
+ size_t i = start_idx;
+ while (i < sc_list.GetSize()) {
+ if (!sc_list.GetContextAtIndex(i, sc))
+ break;
+ ConstString full_name(sc.GetFunctionName());
+ CPlusPlusLanguage::MethodName cpp_method(full_name);
+ if (cpp_method.IsValid()) {
+ if (cpp_method.GetContext().empty()) {
+ if (cpp_method.GetBasename().compare(m_name.GetStringRef()) != 0) {
+ sc_list.RemoveContextAtIndex(i);
+ continue;
+ }
+ } else {
+ std::string qualified_name = cpp_method.GetScopeQualifiedName();
+ if (qualified_name.compare(m_name.GetCString()) != 0) {
+ sc_list.RemoveContextAtIndex(i);
+ continue;
+ }
}
+ }
+ ++i;
}
+ }
+}
- 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
- 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"
- m_lookup_name = name;
- m_match_name_after_lookup = false;
+size_t Module::FindFunctions(const ConstString &name,
+ const CompilerDeclContext *parent_decl_ctx,
+ uint32_t name_type_mask, bool include_symbols,
+ bool include_inlines, bool append,
+ SymbolContextList &sc_list) {
+ if (!append)
+ sc_list.Clear();
+
+ const size_t old_size = sc_list.GetSize();
+
+ // Find all the functions (not symbols, but debug information functions...
+ SymbolVendor *symbols = GetSymbolVendor();
+
+ if (name_type_mask & eFunctionNameTypeAuto) {
+ LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
+
+ if (symbols) {
+ symbols->FindFunctions(lookup_info.GetLookupName(), parent_decl_ctx,
+ lookup_info.GetNameTypeMask(), include_inlines,
+ append, sc_list);
+
+ // Now check our symbol table for symbols that are code symbols if
+ // requested
+ if (include_symbols) {
+ Symtab *symtab = symbols->GetSymtab();
+ if (symtab)
+ symtab->FindFunctionSymbols(lookup_info.GetLookupName(),
+ lookup_info.GetNameTypeMask(), sc_list);
+ }
+ }
+
+ const size_t new_size = sc_list.GetSize();
+
+ if (old_size < new_size)
+ lookup_info.Prune(sc_list, old_size);
+ } else {
+ if (symbols) {
+ symbols->FindFunctions(name, parent_decl_ctx, name_type_mask,
+ include_inlines, append, sc_list);
+
+ // Now check our symbol table for symbols that are code symbols if
+ // requested
+ if (include_symbols) {
+ Symtab *symtab = symbols->GetSymtab();
+ if (symtab)
+ symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
+ }
}
+ }
+ return sc_list.GetSize() - old_size;
}
-void
-Module::LookupInfo::Prune(SymbolContextList &sc_list, size_t start_idx) const
-{
- if (m_match_name_after_lookup && m_name)
- {
- SymbolContext sc;
- size_t i = start_idx;
- while (i < sc_list.GetSize())
- {
- if (!sc_list.GetContextAtIndex(i, sc))
- break;
- ConstString full_name(sc.GetFunctionName());
- if (full_name && ::strstr(full_name.GetCString(), m_name.GetCString()) == nullptr)
- {
- sc_list.RemoveContextAtIndex(i);
- }
- else
- {
- ++i;
+size_t Module::FindFunctions(const RegularExpression ®ex,
+ bool include_symbols, bool include_inlines,
+ bool append, SymbolContextList &sc_list) {
+ if (!append)
+ sc_list.Clear();
+
+ const size_t start_size = sc_list.GetSize();
+
+ SymbolVendor *symbols = GetSymbolVendor();
+ if (symbols) {
+ symbols->FindFunctions(regex, include_inlines, append, sc_list);
+
+ // Now check our symbol table for symbols that are code symbols if requested
+ if (include_symbols) {
+ Symtab *symtab = symbols->GetSymtab();
+ if (symtab) {
+ std::vector<uint32_t> symbol_indexes;
+ symtab->AppendSymbolIndexesMatchingRegExAndType(
+ regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny,
+ symbol_indexes);
+ const size_t num_matches = symbol_indexes.size();
+ if (num_matches) {
+ SymbolContext sc(this);
+ const size_t end_functions_added_index = sc_list.GetSize();
+ 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
+ for (size_t i = 0; i < num_matches; ++i) {
+ sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
+ SymbolType sym_type = sc.symbol->GetType();
+ if (sc.symbol && (sym_type == eSymbolTypeCode ||
+ sym_type == eSymbolTypeResolver))
+ sc_list.Append(sc);
}
- }
- }
-
- // If we have only full name matches we might have tried to set breakpoint on "func"
- // and specified eFunctionNameTypeFull, but we might have found "a::func()",
- // "a::b::func()", "c::func()", "func()" and "func". Only "func()" and "func" should
- // end up matching.
- if (m_name_type_mask == eFunctionNameTypeFull)
- {
- SymbolContext sc;
- size_t i = start_idx;
- while (i < sc_list.GetSize())
- {
- if (!sc_list.GetContextAtIndex(i, sc))
- break;
- ConstString full_name(sc.GetFunctionName());
- CPlusPlusLanguage::MethodName cpp_method(full_name);
- if (cpp_method.IsValid())
- {
- if (cpp_method.GetContext().empty())
- {
- if (cpp_method.GetBasename().compare(m_name.GetStringRef()) != 0)
- {
- sc_list.RemoveContextAtIndex(i);
- continue;
- }
- }
+ } else {
+ typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
+ FileAddrToIndexMap file_addr_to_index;
+ for (size_t i = start_size; i < end_functions_added_index; ++i) {
+ const SymbolContext &sc = sc_list[i];
+ if (sc.block)
+ continue;
+ file_addr_to_index[sc.function->GetAddressRange()
+ .GetBaseAddress()
+ .GetFileAddress()] = i;
+ }
+
+ FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
+ // Functions were added so we need to merge symbols into any
+ // existing function symbol contexts
+ for (size_t i = start_size; i < num_matches; ++i) {
+ sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
+ SymbolType sym_type = sc.symbol->GetType();
+ if (sc.symbol && sc.symbol->ValueIsAddress() &&
+ (sym_type == eSymbolTypeCode ||
+ sym_type == eSymbolTypeResolver)) {
+ FileAddrToIndexMap::const_iterator pos =
+ file_addr_to_index.find(
+ sc.symbol->GetAddressRef().GetFileAddress());
+ if (pos == end)
+ sc_list.Append(sc);
else
- {
- std::string qualified_name = cpp_method.GetScopeQualifiedName();
- if (qualified_name.compare(m_name.GetCString()) != 0)
- {
- sc_list.RemoveContextAtIndex(i);
- continue;
- }
- }
- }
- ++i;
- }
- }
-}
-
-
-size_t
-Module::FindFunctions (const ConstString &name,
- const CompilerDeclContext *parent_decl_ctx,
- uint32_t name_type_mask,
- bool include_symbols,
- bool include_inlines,
- bool append,
- SymbolContextList& sc_list)
-{
- if (!append)
- sc_list.Clear();
-
- const size_t old_size = sc_list.GetSize();
-
- // Find all the functions (not symbols, but debug information functions...
- SymbolVendor *symbols = GetSymbolVendor ();
-
- if (name_type_mask & eFunctionNameTypeAuto)
- {
- LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
-
- if (symbols)
- {
- symbols->FindFunctions(lookup_info.GetLookupName(),
- parent_decl_ctx,
- lookup_info.GetNameTypeMask(),
- include_inlines,
- append,
- sc_list);
-
- // Now check our symbol table for symbols that are code symbols if requested
- if (include_symbols)
- {
- Symtab *symtab = symbols->GetSymtab();
- if (symtab)
- symtab->FindFunctionSymbols(lookup_info.GetLookupName(), lookup_info.GetNameTypeMask(), sc_list);
+ sc_list[pos->second].symbol = sc.symbol;
+ }
}
+ }
}
-
- const size_t new_size = sc_list.GetSize();
-
- if (old_size < new_size)
- lookup_info.Prune (sc_list, old_size);
+ }
}
+ }
+ return sc_list.GetSize() - start_size;
+}
+
+void Module::FindAddressesForLine(const lldb::TargetSP target_sp,
+ const FileSpec &file, uint32_t line,
+ Function *function,
+ std::vector<Address> &output_local,
+ std::vector<Address> &output_extern) {
+ SearchFilterByModule filter(target_sp, m_file);
+ AddressResolverFileLine resolver(file, line, true);
+ resolver.ResolveAddress(filter);
+
+ for (size_t n = 0; n < resolver.GetNumberOfAddresses(); n++) {
+ Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
+ Function *f = addr.CalculateSymbolContextFunction();
+ if (f && f == function)
+ output_local.push_back(addr);
else
- {
- if (symbols)
- {
- symbols->FindFunctions(name, parent_decl_ctx, name_type_mask, include_inlines, append, sc_list);
-
- // Now check our symbol table for symbols that are code symbols if requested
- if (include_symbols)
- {
- Symtab *symtab = symbols->GetSymtab();
- if (symtab)
- symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
- }
- }
- }
-
- return sc_list.GetSize() - old_size;
+ output_extern.push_back(addr);
+ }
}
-size_t
-Module::FindFunctions (const RegularExpression& regex,
- bool include_symbols,
- bool include_inlines,
- bool append,
- SymbolContextList& sc_list)
-{
- if (!append)
- sc_list.Clear();
-
- const size_t start_size = sc_list.GetSize();
-
- SymbolVendor *symbols = GetSymbolVendor ();
+size_t Module::FindTypes_Impl(
+ const SymbolContext &sc, const ConstString &name,
+ const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches,
+ llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
+ TypeMap &types) {
+ Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
+ if (!sc.module_sp || sc.module_sp.get() == this) {
+ SymbolVendor *symbols = GetSymbolVendor();
if (symbols)
- {
- symbols->FindFunctions(regex, include_inlines, append, sc_list);
-
- // Now check our symbol table for symbols that are code symbols if requested
- if (include_symbols)
- {
- Symtab *symtab = symbols->GetSymtab();
- if (symtab)
- {
- std::vector<uint32_t> symbol_indexes;
- symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
- const size_t num_matches = symbol_indexes.size();
- if (num_matches)
- {
- SymbolContext sc(this);
- const size_t end_functions_added_index = sc_list.GetSize();
- 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
- for (size_t i = 0; i < num_matches; ++i)
- {
- sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
- SymbolType sym_type = sc.symbol->GetType();
- if (sc.symbol && (sym_type == eSymbolTypeCode ||
- sym_type == eSymbolTypeResolver))
- sc_list.Append(sc);
- }
- }
- else
- {
- typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
- FileAddrToIndexMap file_addr_to_index;
- for (size_t i = start_size; i < end_functions_added_index; ++i)
- {
- const SymbolContext &sc = sc_list[i];
- if (sc.block)
- continue;
- file_addr_to_index[sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()] = i;
- }
-
- FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
- // Functions were added so we need to merge symbols into any
- // existing function symbol contexts
- for (size_t i = start_size; i < num_matches; ++i)
- {
- sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
- SymbolType sym_type = sc.symbol->GetType();
- if (sc.symbol && sc.symbol->ValueIsAddress() && (sym_type == eSymbolTypeCode || sym_type == eSymbolTypeResolver))
- {
- FileAddrToIndexMap::const_iterator pos = file_addr_to_index.find(sc.symbol->GetAddressRef().GetFileAddress());
- if (pos == end)
- sc_list.Append(sc);
- else
- sc_list[pos->second].symbol = sc.symbol;
- }
- }
- }
- }
- }
- }
- }
- return sc_list.GetSize() - start_size;
-}
-
-void
-Module::FindAddressesForLine (const lldb::TargetSP target_sp,
- const FileSpec &file, uint32_t line,
- Function *function,
- std::vector<Address> &output_local, std::vector<Address> &output_extern)
-{
- SearchFilterByModule filter(target_sp, m_file);
- AddressResolverFileLine resolver(file, line, true);
- resolver.ResolveAddress (filter);
-
- for (size_t n = 0; n < resolver.GetNumberOfAddresses(); n++)
- {
- Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
- Function *f = addr.CalculateSymbolContextFunction();
- if (f && f == function)
- output_local.push_back (addr);
- else
- output_extern.push_back (addr);
- }
-}
-
-size_t
-Module::FindTypes_Impl (const SymbolContext& sc,
- const ConstString &name,
- const CompilerDeclContext *parent_decl_ctx,
- bool append,
- size_t max_matches,
- llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
- TypeMap& types)
-{
- Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
- if (!sc.module_sp || sc.module_sp.get() == this)
- {
- SymbolVendor *symbols = GetSymbolVendor ();
- if (symbols)
- return symbols->FindTypes(sc, name, parent_decl_ctx, append, max_matches, searched_symbol_files, types);
- }
- return 0;
-}
-
-size_t
-Module::FindTypesInNamespace (const SymbolContext& sc,
- const ConstString &type_name,
- const CompilerDeclContext *parent_decl_ctx,
- size_t max_matches,
- TypeList& type_list)
-{
- const bool append = true;
- TypeMap types_map;
- llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
- size_t num_types = FindTypes_Impl(sc, type_name, parent_decl_ctx, append, max_matches, searched_symbol_files, types_map);
- if (num_types > 0)
- sc.SortTypeList(types_map, type_list);
- return num_types;
-}
-
-lldb::TypeSP
-Module::FindFirstType (const SymbolContext& sc,
- const ConstString &name,
- bool exact_match)
-{
- TypeList type_list;
- llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
- const size_t num_matches = FindTypes (sc, name, exact_match, 1, searched_symbol_files, type_list);
- if (num_matches)
- return type_list.GetTypeAtIndex(0);
- return TypeSP();
-}
-
-size_t
-Module::FindTypes (const SymbolContext& sc,
- const ConstString &name,
- bool exact_match,
- size_t max_matches,
- llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
- TypeList& types)
-{
- size_t num_matches = 0;
- const char *type_name_cstr = name.GetCString();
- std::string type_scope;
- std::string type_basename;
- 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
- // from the root namespace and implies and exact match. The typenames we
- // get back from clang do not start with "::" so we need to strip this off
- // in order to get the qualified names to match
-
- if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':')
- {
- type_scope.erase(0,2);
- exact_match = true;
- }
- ConstString type_basename_const_str (type_basename.c_str());
- if (FindTypes_Impl(sc, type_basename_const_str, nullptr, append, max_matches, searched_symbol_files, typesmap))
- {
- typesmap.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
- num_matches = typesmap.GetSize();
- }
- }
- else
- {
- // The type is not in a namespace/class scope, just search for it by basename
- if (type_class != eTypeClassAny)
- {
- // The "type_name_cstr" will have been modified if we have a valid type class
- // prefix (like "struct", "class", "union", "typedef" etc).
- FindTypes_Impl(sc, ConstString(type_name_cstr), nullptr, append, max_matches, searched_symbol_files, typesmap);
- typesmap.RemoveMismatchedTypes (type_class);
- num_matches = typesmap.GetSize();
- }
- else
- {
- num_matches = FindTypes_Impl(sc, name, nullptr, append, max_matches, searched_symbol_files, typesmap);
- }
- }
- if (num_matches > 0)
- sc.SortTypeList(typesmap, types);
- return num_matches;
-}
-
-SymbolVendor*
-Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm)
-{
- if (!m_did_load_symbol_vendor.load())
- {
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (!m_did_load_symbol_vendor.load() && can_create)
- {
- ObjectFile *obj_file = GetObjectFile ();
- if (obj_file != nullptr)
- {
- Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
- m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
- m_did_load_symbol_vendor = true;
- }
- }
- }
- return m_symfile_ap.get();
-}
-
-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.
- m_file = file;
- m_mod_time = file.GetModificationTime();
- m_object_name = object_name;
-}
-
-const ArchSpec&
-Module::GetArchitecture () const
-{
- return m_arch;
-}
-
-std::string
-Module::GetSpecificationDescription () const
-{
- std::string spec(GetFileSpec().GetPath());
- if (m_object_name)
- {
- spec += '(';
- spec += m_object_name.GetCString();
- spec += ')';
- }
- return spec;
-}
-
-void
-Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
-{
+ return symbols->FindTypes(sc, name, parent_decl_ctx, append, max_matches,
+ searched_symbol_files, types);
+ }
+ return 0;
+}
+
+size_t Module::FindTypesInNamespace(const SymbolContext &sc,
+ const ConstString &type_name,
+ const CompilerDeclContext *parent_decl_ctx,
+ size_t max_matches, TypeList &type_list) {
+ const bool append = true;
+ TypeMap types_map;
+ llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
+ size_t num_types =
+ FindTypes_Impl(sc, type_name, parent_decl_ctx, append, max_matches,
+ searched_symbol_files, types_map);
+ if (num_types > 0)
+ sc.SortTypeList(types_map, type_list);
+ return num_types;
+}
+
+lldb::TypeSP Module::FindFirstType(const SymbolContext &sc,
+ const ConstString &name, bool exact_match) {
+ TypeList type_list;
+ llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
+ const size_t num_matches =
+ FindTypes(sc, name, exact_match, 1, searched_symbol_files, type_list);
+ if (num_matches)
+ return type_list.GetTypeAtIndex(0);
+ return TypeSP();
+}
+
+size_t Module::FindTypes(
+ const SymbolContext &sc, const ConstString &name, bool exact_match,
+ size_t max_matches,
+ llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
+ TypeList &types) {
+ size_t num_matches = 0;
+ const char *type_name_cstr = name.GetCString();
+ std::string type_scope;
+ std::string type_basename;
+ 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
+ // from the root namespace and implies and exact match. The typenames we
+ // get back from clang do not start with "::" so we need to strip this off
+ // in order to get the qualified names to match
+
+ if (type_scope.size() >= 2 && type_scope[0] == ':' &&
+ type_scope[1] == ':') {
+ type_scope.erase(0, 2);
+ exact_match = true;
+ }
+ ConstString type_basename_const_str(type_basename.c_str());
+ if (FindTypes_Impl(sc, type_basename_const_str, nullptr, append,
+ max_matches, searched_symbol_files, typesmap)) {
+ typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
+ exact_match);
+ num_matches = typesmap.GetSize();
+ }
+ } else {
+ // The type is not in a namespace/class scope, just search for it by
+ // basename
+ if (type_class != eTypeClassAny) {
+ // The "type_name_cstr" will have been modified if we have a valid type
+ // class
+ // prefix (like "struct", "class", "union", "typedef" etc).
+ FindTypes_Impl(sc, ConstString(type_name_cstr), nullptr, append,
+ max_matches, searched_symbol_files, typesmap);
+ typesmap.RemoveMismatchedTypes(type_class);
+ num_matches = typesmap.GetSize();
+ } else {
+ num_matches = FindTypes_Impl(sc, name, nullptr, append, max_matches,
+ searched_symbol_files, typesmap);
+ }
+ }
+ if (num_matches > 0)
+ sc.SortTypeList(typesmap, types);
+ return num_matches;
+}
+
+SymbolVendor *Module::GetSymbolVendor(bool can_create,
+ lldb_private::Stream *feedback_strm) {
+ if (!m_did_load_symbol_vendor.load()) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
-
- if (level >= eDescriptionLevelFull)
- {
- if (m_arch.IsValid())
- s->Printf("(%s) ", m_arch.GetArchitectureName());
- }
-
- if (level == eDescriptionLevelBrief)
- {
- const char *filename = m_file.GetFilename().GetCString();
- if (filename)
- s->PutCString (filename);
- }
- else
- {
- char path[PATH_MAX];
- if (m_file.GetPath(path, sizeof(path)))
- s->PutCString(path);
- }
-
- const char *object_name = m_object_name.GetCString();
- if (object_name)
- s->Printf("(%s)", object_name);
-}
-
-void
-Module::ReportError (const char *format, ...)
-{
- if (format && format[0])
- {
- StreamString strm;
- strm.PutCString("error: ");
- GetDescription(&strm, lldb::eDescriptionLevelBrief);
- strm.PutChar (' ');
- va_list args;
- va_start (args, format);
- strm.PrintfVarArg(format, args);
- va_end (args);
-
- const int format_len = strlen(format);
- if (format_len > 0)
- {
- const char last_char = format[format_len-1];
- if (last_char != '\n' || last_char != '\r')
- strm.EOL();
- }
- Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
- }
-}
-
-bool
-Module::FileHasChanged () const
-{
- if (!m_file_has_changed)
- m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
- return m_file_has_changed;
-}
-
-void
-Module::ReportErrorIfModifyDetected (const char *format, ...)
-{
- if (!m_first_file_changed_log)
- {
- if (FileHasChanged ())
- {
- m_first_file_changed_log = true;
- if (format)
- {
- StreamString strm;
- strm.PutCString("error: the object file ");
- GetDescription(&strm, lldb::eDescriptionLevelFull);
- strm.PutCString (" has been modified\n");
-
- va_list args;
- va_start (args, format);
- strm.PrintfVarArg(format, args);
- va_end (args);
-
- const int format_len = strlen(format);
- if (format_len > 0)
- {
- const char last_char = format[format_len-1];
- if (last_char != '\n' || last_char != '\r')
- strm.EOL();
- }
- strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n");
- Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
- }
- }
- }
-}
-
-void
-Module::ReportWarning (const char *format, ...)
-{
- if (format && format[0])
- {
+ if (!m_did_load_symbol_vendor.load() && can_create) {
+ ObjectFile *obj_file = GetObjectFile();
+ if (obj_file != nullptr) {
+ Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
+ m_symfile_ap.reset(
+ SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
+ m_did_load_symbol_vendor = true;
+ }
+ }
+ }
+ return m_symfile_ap.get();
+}
+
+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.
+ m_file = file;
+ m_mod_time = file.GetModificationTime();
+ m_object_name = object_name;
+}
+
+const ArchSpec &Module::GetArchitecture() const { return m_arch; }
+
+std::string Module::GetSpecificationDescription() const {
+ std::string spec(GetFileSpec().GetPath());
+ if (m_object_name) {
+ spec += '(';
+ spec += m_object_name.GetCString();
+ spec += ')';
+ }
+ return spec;
+}
+
+void Module::GetDescription(Stream *s, lldb::DescriptionLevel level) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+
+ if (level >= eDescriptionLevelFull) {
+ if (m_arch.IsValid())
+ s->Printf("(%s) ", m_arch.GetArchitectureName());
+ }
+
+ if (level == eDescriptionLevelBrief) {
+ const char *filename = m_file.GetFilename().GetCString();
+ if (filename)
+ s->PutCString(filename);
+ } else {
+ char path[PATH_MAX];
+ if (m_file.GetPath(path, sizeof(path)))
+ s->PutCString(path);
+ }
+
+ const char *object_name = m_object_name.GetCString();
+ if (object_name)
+ s->Printf("(%s)", object_name);
+}
+
+void Module::ReportError(const char *format, ...) {
+ if (format && format[0]) {
+ StreamString strm;
+ strm.PutCString("error: ");
+ GetDescription(&strm, lldb::eDescriptionLevelBrief);
+ strm.PutChar(' ');
+ va_list args;
+ va_start(args, format);
+ strm.PrintfVarArg(format, args);
+ va_end(args);
+
+ const int format_len = strlen(format);
+ if (format_len > 0) {
+ const char last_char = format[format_len - 1];
+ if (last_char != '\n' || last_char != '\r')
+ strm.EOL();
+ }
+ Host::SystemLog(Host::eSystemLogError, "%s", strm.GetString().c_str());
+ }
+}
+
+bool Module::FileHasChanged() const {
+ if (!m_file_has_changed)
+ m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
+ return m_file_has_changed;
+}
+
+void Module::ReportErrorIfModifyDetected(const char *format, ...) {
+ if (!m_first_file_changed_log) {
+ if (FileHasChanged()) {
+ m_first_file_changed_log = true;
+ if (format) {
StreamString strm;
- strm.PutCString("warning: ");
+ strm.PutCString("error: the object file ");
GetDescription(&strm, lldb::eDescriptionLevelFull);
- strm.PutChar (' ');
-
+ strm.PutCString(" has been modified\n");
+
va_list args;
- va_start (args, format);
+ va_start(args, format);
strm.PrintfVarArg(format, args);
- va_end (args);
-
- const int format_len = strlen(format);
- if (format_len > 0)
- {
- const char last_char = format[format_len-1];
- if (last_char != '\n' || last_char != '\r')
- strm.EOL();
- }
- Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str());
- }
-}
+ va_end(args);
-void
-Module::LogMessage (Log *log, const char *format, ...)
-{
- if (log != nullptr)
- {
- StreamString log_message;
- GetDescription(&log_message, lldb::eDescriptionLevelFull);
- log_message.PutCString (": ");
- va_list args;
- va_start (args, format);
- log_message.PrintfVarArg (format, args);
- va_end (args);
- log->PutCString(log_message.GetString().c_str());
- }
+ const int format_len = strlen(format);
+ if (format_len > 0) {
+ const char last_char = format[format_len - 1];
+ if (last_char != '\n' || last_char != '\r')
+ strm.EOL();
+ }
+ strm.PutCString("The debug session should be aborted as the original "
+ "debug information has been overwritten.\n");
+ Host::SystemLog(Host::eSystemLogError, "%s", strm.GetString().c_str());
+ }
+ }
+ }
+}
+
+void Module::ReportWarning(const char *format, ...) {
+ if (format && format[0]) {
+ StreamString strm;
+ strm.PutCString("warning: ");
+ GetDescription(&strm, lldb::eDescriptionLevelFull);
+ strm.PutChar(' ');
+
+ va_list args;
+ va_start(args, format);
+ strm.PrintfVarArg(format, args);
+ va_end(args);
+
+ const int format_len = strlen(format);
+ if (format_len > 0) {
+ const char last_char = format[format_len - 1];
+ if (last_char != '\n' || last_char != '\r')
+ strm.EOL();
+ }
+ Host::SystemLog(Host::eSystemLogWarning, "%s", strm.GetString().c_str());
+ }
+}
+
+void Module::LogMessage(Log *log, const char *format, ...) {
+ if (log != nullptr) {
+ StreamString log_message;
+ GetDescription(&log_message, lldb::eDescriptionLevelFull);
+ log_message.PutCString(": ");
+ va_list args;
+ va_start(args, format);
+ log_message.PrintfVarArg(format, args);
+ va_end(args);
+ log->PutCString(log_message.GetString().c_str());
+ }
+}
+
+void Module::LogMessageVerboseBacktrace(Log *log, const char *format, ...) {
+ if (log != nullptr) {
+ StreamString log_message;
+ GetDescription(&log_message, lldb::eDescriptionLevelFull);
+ log_message.PutCString(": ");
+ va_list args;
+ va_start(args, format);
+ log_message.PrintfVarArg(format, args);
+ va_end(args);
+ if (log->GetVerbose()) {
+ std::string back_trace;
+ llvm::raw_string_ostream stream(back_trace);
+ llvm::sys::PrintStackTrace(stream);
+ log_message.PutCString(back_trace.c_str());
+ }
+ log->PutCString(log_message.GetString().c_str());
+ }
+}
+
+void Module::Dump(Stream *s) {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
+ s->Indent();
+ s->Printf("Module %s%s%s%s\n", m_file.GetPath().c_str(),
+ m_object_name ? "(" : "",
+ m_object_name ? m_object_name.GetCString() : "",
+ m_object_name ? ")" : "");
+
+ s->IndentMore();
+
+ ObjectFile *objfile = GetObjectFile();
+ if (objfile)
+ objfile->Dump(s);
+
+ SymbolVendor *symbols = GetSymbolVendor();
+ if (symbols)
+ symbols->Dump(s);
+
+ s->IndentLess();
+}
+
+TypeList *Module::GetTypeList() {
+ SymbolVendor *symbols = GetSymbolVendor();
+ if (symbols)
+ return &symbols->GetTypeList();
+ return nullptr;
}
-void
-Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
-{
- if (log != nullptr)
- {
- StreamString log_message;
- GetDescription(&log_message, lldb::eDescriptionLevelFull);
- log_message.PutCString (": ");
- va_list args;
- va_start (args, format);
- log_message.PrintfVarArg (format, args);
- va_end (args);
- if (log->GetVerbose())
- {
- std::string back_trace;
- llvm::raw_string_ostream stream(back_trace);
- llvm::sys::PrintStackTrace(stream);
- log_message.PutCString(back_trace.c_str());
- }
- log->PutCString(log_message.GetString().c_str());
- }
-}
+const ConstString &Module::GetObjectName() const { return m_object_name; }
-void
-Module::Dump(Stream *s)
-{
+ObjectFile *Module::GetObjectFile() {
+ if (!m_did_load_objfile.load()) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
- //s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
- s->Indent();
- s->Printf("Module %s%s%s%s\n",
- m_file.GetPath().c_str(),
- m_object_name ? "(" : "",
- m_object_name ? m_object_name.GetCString() : "",
- m_object_name ? ")" : "");
-
- s->IndentMore();
-
- ObjectFile *objfile = GetObjectFile ();
- if (objfile)
- objfile->Dump(s);
-
- SymbolVendor *symbols = GetSymbolVendor ();
- if (symbols)
- symbols->Dump(s);
-
- s->IndentLess();
-}
-
-TypeList*
-Module::GetTypeList ()
-{
- SymbolVendor *symbols = GetSymbolVendor ();
- if (symbols)
- return &symbols->GetTypeList();
- return nullptr;
-}
-
-const ConstString &
-Module::GetObjectName() const
-{
- return m_object_name;
-}
-
-ObjectFile *
-Module::GetObjectFile()
-{
- if (!m_did_load_objfile.load())
- {
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- if (!m_did_load_objfile.load())
- {
- Timer scoped_timer(LLVM_PRETTY_FUNCTION,
- "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
- DataBufferSP data_sp;
- lldb::offset_t data_offset = 0;
- const lldb::offset_t file_size = m_file.GetByteSize();
- if (file_size > m_object_offset)
- {
- m_did_load_objfile = true;
- m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(),
- &m_file,
- m_object_offset,
- 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.
- ArchSpec new_arch;
- m_objfile_sp->GetArchitecture(new_arch);
- m_arch.MergeFrom(new_arch);
- }
- else
- {
- ReportError ("failed to load objfile for %s", GetFileSpec().GetPath().c_str());
- }
- }
- }
- }
- return m_objfile_sp.get();
-}
-
-SectionList *
-Module::GetSectionList()
-{
- // Populate m_unified_sections_ap with sections from objfile.
- if (!m_sections_ap)
- {
- ObjectFile *obj_file = GetObjectFile();
- if (obj_file != nullptr)
- obj_file->CreateSections(*GetUnifiedSectionList());
- }
- return m_sections_ap.get();
-}
-
-void
-Module::SectionFileAddressesChanged ()
-{
- ObjectFile *obj_file = GetObjectFile ();
- if (obj_file)
- obj_file->SectionFileAddressesChanged ();
- SymbolVendor* sym_vendor = GetSymbolVendor();
- if (sym_vendor != nullptr)
- sym_vendor->SectionFileAddressesChanged ();
-}
-
-SectionList *
-Module::GetUnifiedSectionList()
-{
- // Populate m_unified_sections_ap with sections from objfile.
- if (!m_sections_ap)
- m_sections_ap.reset(new SectionList());
- return m_sections_ap.get();
-}
-
-const Symbol *
-Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type)
-{
- Timer scoped_timer(LLVM_PRETTY_FUNCTION,
- "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
- name.AsCString(),
- symbol_type);
- SymbolVendor* sym_vendor = GetSymbolVendor();
- if (sym_vendor)
- {
- Symtab *symtab = sym_vendor->GetSymtab();
- if (symtab)
- return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
- }
- return nullptr;
-}
-void
-Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
-{
- // No need to protect this call using m_mutex all other method calls are
- // already thread safe.
+ if (!m_did_load_objfile.load()) {
+ Timer scoped_timer(LLVM_PRETTY_FUNCTION,
+ "Module::GetObjectFile () module = %s",
+ GetFileSpec().GetFilename().AsCString(""));
+ DataBufferSP data_sp;
+ lldb::offset_t data_offset = 0;
+ const lldb::offset_t file_size = m_file.GetByteSize();
+ if (file_size > m_object_offset) {
+ m_did_load_objfile = true;
+ m_objfile_sp = ObjectFile::FindPlugin(
+ shared_from_this(), &m_file, m_object_offset,
+ 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.
+ ArchSpec new_arch;
+ m_objfile_sp->GetArchitecture(new_arch);
+ m_arch.MergeFrom(new_arch);
+ } else {
+ ReportError("failed to load objfile for %s",
+ GetFileSpec().GetPath().c_str());
+ }
+ }
+ }
+ }
+ return m_objfile_sp.get();
+}
+
+SectionList *Module::GetSectionList() {
+ // Populate m_unified_sections_ap with sections from objfile.
+ if (!m_sections_ap) {
+ ObjectFile *obj_file = GetObjectFile();
+ if (obj_file != nullptr)
+ obj_file->CreateSections(*GetUnifiedSectionList());
+ }
+ return m_sections_ap.get();
+}
+
+void Module::SectionFileAddressesChanged() {
+ ObjectFile *obj_file = GetObjectFile();
+ if (obj_file)
+ obj_file->SectionFileAddressesChanged();
+ SymbolVendor *sym_vendor = GetSymbolVendor();
+ if (sym_vendor != nullptr)
+ sym_vendor->SectionFileAddressesChanged();
+}
+
+SectionList *Module::GetUnifiedSectionList() {
+ // Populate m_unified_sections_ap with sections from objfile.
+ if (!m_sections_ap)
+ m_sections_ap.reset(new SectionList());
+ return m_sections_ap.get();
+}
+
+const Symbol *Module::FindFirstSymbolWithNameAndType(const ConstString &name,
+ SymbolType symbol_type) {
+ Timer scoped_timer(
+ LLVM_PRETTY_FUNCTION,
+ "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
+ name.AsCString(), symbol_type);
+ SymbolVendor *sym_vendor = GetSymbolVendor();
+ if (sym_vendor) {
+ Symtab *symtab = sym_vendor->GetSymtab();
+ if (symtab)
+ return symtab->FindFirstSymbolWithNameAndType(
+ name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
+ }
+ return nullptr;
+}
+void Module::SymbolIndicesToSymbolContextList(
+ Symtab *symtab, std::vector<uint32_t> &symbol_indexes,
+ SymbolContextList &sc_list) {
+ // No need to protect this call using m_mutex all other method calls are
+ // already thread safe.
- size_t num_indices = symbol_indexes.size();
- if (num_indices > 0)
- {
- SymbolContext sc;
- CalculateSymbolContext (&sc);
- for (size_t i = 0; i < num_indices; i++)
- {
- sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]);
- if (sc.symbol)
- sc_list.Append (sc);
- }
- }
+ size_t num_indices = symbol_indexes.size();
+ if (num_indices > 0) {
+ SymbolContext sc;
+ CalculateSymbolContext(&sc);
+ for (size_t i = 0; i < num_indices; i++) {
+ sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
+ if (sc.symbol)
+ sc_list.Append(sc);
+ }
+ }
+}
+
+size_t Module::FindFunctionSymbols(const ConstString &name,
+ uint32_t name_type_mask,
+ SymbolContextList &sc_list) {
+ Timer scoped_timer(LLVM_PRETTY_FUNCTION,
+ "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
+ name.AsCString(), name_type_mask);
+ SymbolVendor *sym_vendor = GetSymbolVendor();
+ if (sym_vendor) {
+ Symtab *symtab = sym_vendor->GetSymtab();
+ if (symtab)
+ return symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
+ }
+ return 0;
+}
+
+size_t Module::FindSymbolsWithNameAndType(const ConstString &name,
+ SymbolType symbol_type,
+ SymbolContextList &sc_list) {
+ // No need to protect this call using m_mutex all other method calls are
+ // already thread safe.
+
+ Timer scoped_timer(
+ LLVM_PRETTY_FUNCTION,
+ "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
+ name.AsCString(), symbol_type);
+ const size_t initial_size = sc_list.GetSize();
+ SymbolVendor *sym_vendor = GetSymbolVendor();
+ if (sym_vendor) {
+ Symtab *symtab = sym_vendor->GetSymtab();
+ if (symtab) {
+ std::vector<uint32_t> symbol_indexes;
+ symtab->FindAllSymbolsWithNameAndType(name, symbol_type, symbol_indexes);
+ SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
+ }
+ }
+ return sc_list.GetSize() - initial_size;
+}
+
+size_t Module::FindSymbolsMatchingRegExAndType(const RegularExpression ®ex,
+ SymbolType symbol_type,
+ SymbolContextList &sc_list) {
+ // No need to protect this call using m_mutex all other method calls are
+ // already thread safe.
+
+ Timer scoped_timer(
+ LLVM_PRETTY_FUNCTION,
+ "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
+ regex.GetText(), symbol_type);
+ const size_t initial_size = sc_list.GetSize();
+ SymbolVendor *sym_vendor = GetSymbolVendor();
+ if (sym_vendor) {
+ Symtab *symtab = sym_vendor->GetSymtab();
+ if (symtab) {
+ std::vector<uint32_t> symbol_indexes;
+ symtab->FindAllSymbolsMatchingRexExAndType(
+ regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny,
+ symbol_indexes);
+ SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
+ }
+ }
+ return sc_list.GetSize() - initial_size;
+}
+
+void Module::SetSymbolFileFileSpec(const FileSpec &file) {
+ if (!file.Exists())
+ return;
+ if (m_symfile_ap) {
+ // Remove any sections in the unified section list that come from the
+ // current symbol vendor.
+ SectionList *section_list = GetSectionList();
+ SymbolFile *symbol_file = m_symfile_ap->GetSymbolFile();
+ 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...
+ if (obj_file) {
+ // Check to make sure we aren't trying to specify the file we already
+ // have
+ if (obj_file->GetFileSpec() == file) {
+ // We are being told to add the exact same file that we already have
+ // we don't have to do anything.
+ return;
+ }
+
+ // Cleare the current symtab as we are going to replace it with a new
+ // one
+ 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
+ // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to
+ // check this
+
+ if (file.IsDirectory()) {
+ std::string new_path(file.GetPath());
+ std::string old_path(obj_file->GetFileSpec().GetPath());
+ if (old_path.find(new_path) == 0) {
+ // We specified the same bundle as the symbol file that we already
+ // have
+ return;
+ }
+ }
+
+ if (obj_file != m_objfile_sp.get()) {
+ size_t num_sections = section_list->GetNumSections(0);
+ for (size_t idx = num_sections; idx > 0; --idx) {
+ lldb::SectionSP section_sp(
+ section_list->GetSectionAtIndex(idx - 1));
+ if (section_sp->GetObjectFile() == obj_file) {
+ section_list->DeleteSection(idx - 1);
+ }
+ }
+ }
+ }
+ }
+ // Keep all old symbol files around in case there are any lingering type
+ // 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;
+ m_symfile_ap.reset();
+ m_did_load_symbol_vendor = false;
}
-size_t
-Module::FindFunctionSymbols (const ConstString &name,
- uint32_t name_type_mask,
- SymbolContextList& sc_list)
-{
- Timer scoped_timer(LLVM_PRETTY_FUNCTION,
- "Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
- name.AsCString(),
- name_type_mask);
- SymbolVendor* sym_vendor = GetSymbolVendor();
- if (sym_vendor)
- {
- Symtab *symtab = sym_vendor->GetSymtab();
- if (symtab)
- return symtab->FindFunctionSymbols (name, name_type_mask, sc_list);
- }
- return 0;
+bool Module::IsExecutable() {
+ if (GetObjectFile() == nullptr)
+ return false;
+ else
+ return GetObjectFile()->IsExecutable();
}
-size_t
-Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list)
-{
- // No need to protect this call using m_mutex all other method calls are
- // already thread safe.
-
- Timer scoped_timer(LLVM_PRETTY_FUNCTION,
- "Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
- name.AsCString(),
- symbol_type);
- const size_t initial_size = sc_list.GetSize();
- SymbolVendor* sym_vendor = GetSymbolVendor();
- if (sym_vendor)
- {
- Symtab *symtab = sym_vendor->GetSymtab();
- if (symtab)
- {
- std::vector<uint32_t> symbol_indexes;
- symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes);
- SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
- }
- }
- return sc_list.GetSize() - initial_size;
-}
+bool Module::IsLoadedInTarget(Target *target) {
+ ObjectFile *obj_file = GetObjectFile();
+ if (obj_file) {
+ SectionList *sections = GetSectionList();
+ if (sections != nullptr) {
+ size_t num_sections = sections->GetSize();
+ for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++) {
+ SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
+ if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+bool Module::LoadScriptingResourceInTarget(Target *target, Error &error,
+ Stream *feedback_stream) {
+ if (!target) {
+ error.SetErrorString("invalid destination Target");
+ return false;
+ }
-size_t
-Module::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, SymbolType symbol_type, SymbolContextList &sc_list)
-{
- // No need to protect this call using m_mutex all other method calls are
- // already thread safe.
-
- Timer scoped_timer(LLVM_PRETTY_FUNCTION,
- "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
- regex.GetText(),
- symbol_type);
- const size_t initial_size = sc_list.GetSize();
- SymbolVendor* sym_vendor = GetSymbolVendor();
- if (sym_vendor)
- {
- Symtab *symtab = sym_vendor->GetSymtab();
- if (symtab)
- {
- std::vector<uint32_t> symbol_indexes;
- symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
- SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
- }
- }
- return sc_list.GetSize() - initial_size;
-}
+ LoadScriptFromSymFile should_load =
+ target->TargetProperties::GetLoadScriptFromSymbolFile();
-void
-Module::SetSymbolFileFileSpec (const FileSpec &file)
-{
- if (!file.Exists())
- return;
- if (m_symfile_ap)
- {
- // Remove any sections in the unified section list that come from the current symbol vendor.
- SectionList *section_list = GetSectionList();
- SymbolFile *symbol_file = m_symfile_ap->GetSymbolFile();
- 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...
- if (obj_file)
- {
- // Check to make sure we aren't trying to specify the file we already have
- if (obj_file->GetFileSpec() == file)
- {
- // We are being told to add the exact same file that we already have
- // we don't have to do anything.
- return;
- }
-
- // Cleare the current symtab as we are going to replace it with a new one
- 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
- // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to check this
-
- if (file.IsDirectory())
- {
- std::string new_path(file.GetPath());
- std::string old_path(obj_file->GetFileSpec().GetPath());
- if (old_path.find(new_path) == 0)
- {
- // We specified the same bundle as the symbol file that we already have
- return;
- }
- }
+ if (should_load == eLoadScriptFromSymFileFalse)
+ return false;
- if (obj_file != m_objfile_sp.get())
- {
- size_t num_sections = section_list->GetNumSections (0);
- for (size_t idx = num_sections; idx > 0; --idx)
- {
- lldb::SectionSP section_sp (section_list->GetSectionAtIndex (idx - 1));
- if (section_sp->GetObjectFile() == obj_file)
- {
- section_list->DeleteSection (idx - 1);
- }
- }
- }
- }
+ Debugger &debugger = target->GetDebugger();
+ const ScriptLanguage script_language = debugger.GetScriptLanguage();
+ if (script_language != eScriptLanguageNone) {
+
+ PlatformSP platform_sp(target->GetPlatform());
+
+ if (!platform_sp) {
+ error.SetErrorString("invalid Platform");
+ return false;
+ }
+
+ FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources(
+ target, *this, feedback_stream);
+
+ const uint32_t num_specs = file_specs.GetSize();
+ if (num_specs) {
+ ScriptInterpreter *script_interpreter =
+ debugger.GetCommandInterpreter().GetScriptInterpreter();
+ if (script_interpreter) {
+ for (uint32_t i = 0; i < num_specs; ++i) {
+ FileSpec scripting_fspec(file_specs.GetFileSpecAtIndex(i));
+ if (scripting_fspec && scripting_fspec.Exists()) {
+ if (should_load == eLoadScriptFromSymFileWarn) {
+ if (feedback_stream)
+ feedback_stream->Printf(
+ "warning: '%s' contains a debug script. To run this script "
+ "in "
+ "this debug session:\n\n command script import "
+ "\"%s\"\n\n"
+ "To run all discovered debug scripts in this session:\n\n"
+ " settings set target.load-script-from-symbol-file "
+ "true\n",
+ GetFileSpec().GetFileNameStrippingExtension().GetCString(),
+ scripting_fspec.GetPath().c_str());
+ return false;
+ }
+ StreamString scripting_stream;
+ scripting_fspec.Dump(&scripting_stream);
+ const bool can_reload = true;
+ const bool init_lldb_globals = false;
+ bool did_load = script_interpreter->LoadScriptingModule(
+ scripting_stream.GetData(), can_reload, init_lldb_globals,
+ error);
+ if (!did_load)
+ return false;
+ }
}
- // Keep all old symbol files around in case there are any lingering type 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;
- m_symfile_ap.reset();
- m_did_load_symbol_vendor = false;
-}
-
-bool
-Module::IsExecutable ()
-{
- if (GetObjectFile() == nullptr)
+ } else {
+ error.SetErrorString("invalid ScriptInterpreter");
return false;
- else
- return GetObjectFile()->IsExecutable();
-}
-
-bool
-Module::IsLoadedInTarget (Target *target)
-{
- ObjectFile *obj_file = GetObjectFile();
- if (obj_file)
- {
- SectionList *sections = GetSectionList();
- if (sections != nullptr)
- {
- size_t num_sections = sections->GetSize();
- for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
- {
- SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
- if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS)
- {
- return true;
- }
- }
- }
+ }
}
- return false;
+ }
+ return true;
}
-bool
-Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* feedback_stream)
-{
- if (!target)
- {
- error.SetErrorString("invalid destination Target");
- return false;
- }
-
- LoadScriptFromSymFile should_load = target->TargetProperties::GetLoadScriptFromSymbolFile();
-
- if (should_load == eLoadScriptFromSymFileFalse)
- return false;
-
- Debugger &debugger = target->GetDebugger();
- const ScriptLanguage script_language = debugger.GetScriptLanguage();
- if (script_language != eScriptLanguageNone)
- {
-
- PlatformSP platform_sp(target->GetPlatform());
-
- if (!platform_sp)
- {
- error.SetErrorString("invalid Platform");
- return false;
- }
-
- FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources (target,
- *this,
- feedback_stream);
-
- const uint32_t num_specs = file_specs.GetSize();
- if (num_specs)
- {
- ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter();
- if (script_interpreter)
- {
- for (uint32_t i = 0; i < num_specs; ++i)
- {
- FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i));
- if (scripting_fspec && scripting_fspec.Exists())
- {
- if (should_load == eLoadScriptFromSymFileWarn)
- {
- if (feedback_stream)
- feedback_stream->Printf("warning: '%s' contains a debug script. To run this script in "
- "this debug session:\n\n command script import \"%s\"\n\n"
- "To run all discovered debug scripts in this session:\n\n"
- " settings set target.load-script-from-symbol-file true\n",
- GetFileSpec().GetFileNameStrippingExtension().GetCString(),
- scripting_fspec.GetPath().c_str());
- return false;
- }
- StreamString scripting_stream;
- scripting_fspec.Dump(&scripting_stream);
- const bool can_reload = true;
- const bool init_lldb_globals = false;
- bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(),
- can_reload,
- init_lldb_globals,
- error);
- if (!did_load)
- return false;
- }
- }
- }
- else
- {
- error.SetErrorString("invalid ScriptInterpreter");
- return false;
- }
- }
- }
+bool Module::SetArchitecture(const ArchSpec &new_arch) {
+ if (!m_arch.IsValid()) {
+ m_arch = new_arch;
return true;
+ }
+ return m_arch.IsCompatibleMatch(new_arch);
}
-bool
-Module::SetArchitecture (const ArchSpec &new_arch)
-{
- if (!m_arch.IsValid())
- {
- m_arch = new_arch;
- return true;
- }
- return m_arch.IsCompatibleMatch(new_arch);
-}
-
-bool
-Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
-{
- ObjectFile *object_file = GetObjectFile();
- if (object_file != nullptr)
- {
- changed = object_file->SetLoadAddress(target, value, value_is_offset);
- return true;
- }
- else
- {
- changed = false;
- }
- return false;
-}
-
-
-bool
-Module::MatchesModuleSpec (const ModuleSpec &module_ref)
-{
- const UUID &uuid = module_ref.GetUUID();
-
- if (uuid.IsValid())
- {
- // If the UUID matches, then nothing more needs to match...
- return (uuid == GetUUID());
- }
-
- const FileSpec &file_spec = module_ref.GetFileSpec();
- if (file_spec)
- {
- if (!FileSpec::Equal (file_spec, m_file, (bool)file_spec.GetDirectory()) &&
- !FileSpec::Equal (file_spec, m_platform_file, (bool)file_spec.GetDirectory()))
- return false;
- }
-
- const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
- if (platform_file_spec)
- {
- if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), (bool)platform_file_spec.GetDirectory()))
- return false;
- }
-
- const ArchSpec &arch = module_ref.GetArchitecture();
- if (arch.IsValid())
- {
- if (!m_arch.IsCompatibleMatch(arch))
- return false;
- }
-
- const ConstString &object_name = module_ref.GetObjectName();
- if (object_name)
- {
- if (object_name != GetObjectName())
- return false;
- }
+bool Module::SetLoadAddress(Target &target, lldb::addr_t value,
+ bool value_is_offset, bool &changed) {
+ ObjectFile *object_file = GetObjectFile();
+ if (object_file != nullptr) {
+ changed = object_file->SetLoadAddress(target, value, value_is_offset);
return true;
-}
-
-bool
-Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- return m_source_mappings.FindFile (orig_spec, new_spec);
-}
-
-bool
-Module::RemapSourceFile (const char *path, std::string &new_path) const
-{
- std::lock_guard<std::recursive_mutex> guard(m_mutex);
- 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;
+ } else {
+ changed = false;
+ }
+ return false;
+}
+
+bool Module::MatchesModuleSpec(const ModuleSpec &module_ref) {
+ const UUID &uuid = module_ref.GetUUID();
+
+ if (uuid.IsValid()) {
+ // If the UUID matches, then nothing more needs to match...
+ return (uuid == GetUUID());
+ }
+
+ const FileSpec &file_spec = module_ref.GetFileSpec();
+ if (file_spec) {
+ if (!FileSpec::Equal(file_spec, m_file, (bool)file_spec.GetDirectory()) &&
+ !FileSpec::Equal(file_spec, m_platform_file,
+ (bool)file_spec.GetDirectory()))
+ return false;
+ }
+
+ const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
+ if (platform_file_spec) {
+ if (!FileSpec::Equal(platform_file_spec, GetPlatformFileSpec(),
+ (bool)platform_file_spec.GetDirectory()))
+ return false;
+ }
+
+ const ArchSpec &arch = module_ref.GetArchitecture();
+ if (arch.IsValid()) {
+ if (!m_arch.IsCompatibleMatch(arch))
+ return false;
+ }
+
+ const ConstString &object_name = module_ref.GetObjectName();
+ if (object_name) {
+ if (object_name != GetObjectName())
+ return false;
+ }
+ return true;
+}
+
+bool Module::FindSourceFile(const FileSpec &orig_spec,
+ FileSpec &new_spec) const {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ return m_source_mappings.FindFile(orig_spec, new_spec);
+}
+
+bool Module::RemapSourceFile(const char *path, std::string &new_path) const {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ 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.reset (new 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();
+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.reset(new 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();
}
-bool
-Module::GetIsDynamicLinkEditor()
-{
- ObjectFile * obj_file = GetObjectFile ();
+bool Module::GetIsDynamicLinkEditor() {
+ ObjectFile *obj_file = GetObjectFile();
- if (obj_file)
- return obj_file->GetIsDynamicLinkEditor();
+ if (obj_file)
+ return obj_file->GetIsDynamicLinkEditor();
- return false;
+ return false;
}
Modified: lldb/trunk/source/Core/ModuleChild.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleChild.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleChild.cpp (original)
+++ lldb/trunk/source/Core/ModuleChild.cpp Tue Sep 6 15:57:50 2016
@@ -11,36 +11,22 @@
using namespace lldb_private;
-ModuleChild::ModuleChild (const lldb::ModuleSP &module_sp) :
- m_module_wp (module_sp)
-{
-}
+ModuleChild::ModuleChild(const lldb::ModuleSP &module_sp)
+ : m_module_wp(module_sp) {}
-ModuleChild::ModuleChild (const ModuleChild& rhs) :
- m_module_wp(rhs.m_module_wp)
-{
-}
+ModuleChild::ModuleChild(const ModuleChild &rhs)
+ : m_module_wp(rhs.m_module_wp) {}
-ModuleChild::~ModuleChild()
-{
-}
+ModuleChild::~ModuleChild() {}
-const ModuleChild&
-ModuleChild::operator= (const ModuleChild& rhs)
-{
- if (this != &rhs)
- m_module_wp = rhs.m_module_wp;
- return *this;
+const ModuleChild &ModuleChild::operator=(const ModuleChild &rhs) {
+ if (this != &rhs)
+ m_module_wp = rhs.m_module_wp;
+ return *this;
}
-lldb::ModuleSP
-ModuleChild::GetModule () const
-{
- return m_module_wp.lock();
-}
+lldb::ModuleSP ModuleChild::GetModule() const { return m_module_wp.lock(); }
-void
-ModuleChild::SetModule (const lldb::ModuleSP &module_sp)
-{
- m_module_wp = module_sp;
+void ModuleChild::SetModule(const lldb::ModuleSP &module_sp) {
+ m_module_wp = module_sp;
}
Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Tue Sep 6 15:57:50 2016
@@ -28,1131 +28,934 @@
using namespace lldb;
using namespace lldb_private;
-ModuleList::ModuleList() : m_modules(), m_modules_mutex(), m_notifier(nullptr)
-{
-}
+ModuleList::ModuleList()
+ : m_modules(), m_modules_mutex(), m_notifier(nullptr) {}
-ModuleList::ModuleList(const ModuleList &rhs) : m_modules(), m_modules_mutex(), m_notifier(nullptr)
-{
- std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex);
- std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex);
- m_modules = rhs.m_modules;
-}
-
-ModuleList::ModuleList(ModuleList::Notifier *notifier) : m_modules(), m_modules_mutex(), m_notifier(notifier)
-{
-}
-
-const ModuleList&
-ModuleList::operator= (const ModuleList& rhs)
-{
- if (this != &rhs)
- {
- // That's probably me nit-picking, but in theoretical situation:
- //
- // * that two threads A B and
- // * two ModuleList's x y do opposite assignments ie.:
- //
- // in thread A: | in thread B:
- // x = y; | y = x;
- //
- // 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);
- m_modules = rhs.m_modules;
- }
- else
- {
- std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex);
- std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex);
- m_modules = rhs.m_modules;
- }
+ModuleList::ModuleList(const ModuleList &rhs)
+ : m_modules(), m_modules_mutex(), m_notifier(nullptr) {
+ std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex);
+ m_modules = rhs.m_modules;
+}
+
+ModuleList::ModuleList(ModuleList::Notifier *notifier)
+ : m_modules(), m_modules_mutex(), m_notifier(notifier) {}
+
+const ModuleList &ModuleList::operator=(const ModuleList &rhs) {
+ if (this != &rhs) {
+ // That's probably me nit-picking, but in theoretical situation:
+ //
+ // * that two threads A B and
+ // * two ModuleList's x y do opposite assignments ie.:
+ //
+ // in thread A: | in thread B:
+ // x = y; | y = x;
+ //
+ // 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);
+ m_modules = rhs.m_modules;
+ } else {
+ std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex);
+ m_modules = rhs.m_modules;
}
- return *this;
+ }
+ return *this;
}
ModuleList::~ModuleList() = default;
-void
-ModuleList::AppendImpl (const ModuleSP &module_sp, bool use_notifier)
-{
- if (module_sp)
- {
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- m_modules.push_back(module_sp);
- if (use_notifier && m_notifier)
- m_notifier->ModuleAdded(*this, module_sp);
- }
+void ModuleList::AppendImpl(const ModuleSP &module_sp, bool use_notifier) {
+ if (module_sp) {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ m_modules.push_back(module_sp);
+ if (use_notifier && m_notifier)
+ m_notifier->ModuleAdded(*this, module_sp);
+ }
}
-void
-ModuleList::Append (const ModuleSP &module_sp)
-{
- AppendImpl (module_sp);
-}
-
-void
-ModuleList::ReplaceEquivalent (const ModuleSP &module_sp)
-{
- if (module_sp)
- {
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
-
- // First remove any equivalent modules. Equivalent modules are modules
- // whose path, platform path and architecture match.
- ModuleSpec equivalent_module_spec (module_sp->GetFileSpec(), module_sp->GetArchitecture());
- equivalent_module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
-
- size_t idx = 0;
- while (idx < m_modules.size())
- {
- ModuleSP module_sp (m_modules[idx]);
- if (module_sp->MatchesModuleSpec (equivalent_module_spec))
- RemoveImpl(m_modules.begin() + idx);
- else
- ++idx;
- }
- // Now add the new module to the list
- Append(module_sp);
- }
-}
+void ModuleList::Append(const ModuleSP &module_sp) { AppendImpl(module_sp); }
-bool
-ModuleList::AppendIfNeeded (const ModuleSP &module_sp)
-{
- if (module_sp)
- {
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- collection::iterator pos, end = m_modules.end();
- for (pos = m_modules.begin(); pos != end; ++pos)
- {
- if (pos->get() == module_sp.get())
- return false; // Already in the list
- }
- // Only push module_sp on the list if it wasn't already in there.
- Append(module_sp);
- return true;
+void ModuleList::ReplaceEquivalent(const ModuleSP &module_sp) {
+ if (module_sp) {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+
+ // First remove any equivalent modules. Equivalent modules are modules
+ // whose path, platform path and architecture match.
+ ModuleSpec equivalent_module_spec(module_sp->GetFileSpec(),
+ module_sp->GetArchitecture());
+ equivalent_module_spec.GetPlatformFileSpec() =
+ module_sp->GetPlatformFileSpec();
+
+ size_t idx = 0;
+ while (idx < m_modules.size()) {
+ ModuleSP module_sp(m_modules[idx]);
+ if (module_sp->MatchesModuleSpec(equivalent_module_spec))
+ RemoveImpl(m_modules.begin() + idx);
+ else
+ ++idx;
}
- return false;
+ // Now add the new module to the list
+ Append(module_sp);
+ }
}
-void
-ModuleList::Append (const ModuleList& module_list)
-{
- for (auto pos : module_list.m_modules)
- Append(pos);
-}
-
-bool
-ModuleList::AppendIfNeeded (const ModuleList& module_list)
-{
- bool any_in = false;
- for (auto pos : module_list.m_modules)
- {
- if (AppendIfNeeded(pos))
- any_in = true;
- }
- return any_in;
-}
-
-bool
-ModuleList::RemoveImpl (const ModuleSP &module_sp, bool use_notifier)
-{
- if (module_sp)
- {
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- collection::iterator pos, end = m_modules.end();
- for (pos = m_modules.begin(); pos != end; ++pos)
- {
- if (pos->get() == module_sp.get())
- {
- m_modules.erase (pos);
- if (use_notifier && m_notifier)
- m_notifier->ModuleRemoved(*this, module_sp);
- return true;
- }
- }
+bool ModuleList::AppendIfNeeded(const ModuleSP &module_sp) {
+ if (module_sp) {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ collection::iterator pos, end = m_modules.end();
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ if (pos->get() == module_sp.get())
+ return false; // Already in the list
}
- return false;
+ // Only push module_sp on the list if it wasn't already in there.
+ Append(module_sp);
+ return true;
+ }
+ return false;
}
-ModuleList::collection::iterator
-ModuleList::RemoveImpl (ModuleList::collection::iterator pos, bool use_notifier)
-{
- ModuleSP module_sp(*pos);
- collection::iterator retval = m_modules.erase(pos);
- if (use_notifier && m_notifier)
- m_notifier->ModuleRemoved(*this, module_sp);
- return retval;
+void ModuleList::Append(const ModuleList &module_list) {
+ for (auto pos : module_list.m_modules)
+ Append(pos);
}
-bool
-ModuleList::Remove (const ModuleSP &module_sp)
-{
- return RemoveImpl (module_sp);
-}
-
-bool
-ModuleList::ReplaceModule (const lldb::ModuleSP &old_module_sp, const lldb::ModuleSP &new_module_sp)
-{
- if (!RemoveImpl(old_module_sp, false))
- return false;
- AppendImpl (new_module_sp, false);
- if (m_notifier)
- m_notifier->ModuleUpdated(*this, old_module_sp,new_module_sp);
- return true;
+bool ModuleList::AppendIfNeeded(const ModuleList &module_list) {
+ bool any_in = false;
+ for (auto pos : module_list.m_modules) {
+ if (AppendIfNeeded(pos))
+ any_in = true;
+ }
+ return any_in;
}
-bool
-ModuleList::RemoveIfOrphaned (const Module *module_ptr)
-{
- if (module_ptr)
- {
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- collection::iterator pos, end = m_modules.end();
- for (pos = m_modules.begin(); pos != end; ++pos)
- {
- if (pos->get() == module_ptr)
- {
- if (pos->unique())
- {
- pos = RemoveImpl(pos);
- return true;
- }
- else
- return false;
- }
- }
+bool ModuleList::RemoveImpl(const ModuleSP &module_sp, bool use_notifier) {
+ if (module_sp) {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ collection::iterator pos, end = m_modules.end();
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ if (pos->get() == module_sp.get()) {
+ m_modules.erase(pos);
+ if (use_notifier && m_notifier)
+ m_notifier->ModuleRemoved(*this, module_sp);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
-size_t
-ModuleList::RemoveOrphans (bool mandatory)
-{
- std::unique_lock<std::recursive_mutex> lock(m_modules_mutex, std::defer_lock);
-
- if (mandatory)
- {
- lock.lock();
- }
- else
- {
- // Not mandatory, remove orphans if we can get the mutex
- if (!lock.try_lock())
- return 0;
- }
- collection::iterator pos = m_modules.begin();
- size_t remove_count = 0;
- while (pos != m_modules.end())
- {
- if (pos->unique())
- {
- pos = RemoveImpl(pos);
- ++remove_count;
- }
- else
- {
- ++pos;
- }
- }
- return remove_count;
+ModuleList::collection::iterator
+ModuleList::RemoveImpl(ModuleList::collection::iterator pos,
+ bool use_notifier) {
+ ModuleSP module_sp(*pos);
+ collection::iterator retval = m_modules.erase(pos);
+ if (use_notifier && m_notifier)
+ m_notifier->ModuleRemoved(*this, module_sp);
+ return retval;
+}
+
+bool ModuleList::Remove(const ModuleSP &module_sp) {
+ return RemoveImpl(module_sp);
+}
+
+bool ModuleList::ReplaceModule(const lldb::ModuleSP &old_module_sp,
+ const lldb::ModuleSP &new_module_sp) {
+ if (!RemoveImpl(old_module_sp, false))
+ return false;
+ AppendImpl(new_module_sp, false);
+ if (m_notifier)
+ m_notifier->ModuleUpdated(*this, old_module_sp, new_module_sp);
+ return true;
}
-size_t
-ModuleList::Remove (ModuleList &module_list)
-{
+bool ModuleList::RemoveIfOrphaned(const Module *module_ptr) {
+ if (module_ptr) {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- size_t num_removed = 0;
- collection::iterator pos, end = module_list.m_modules.end();
- for (pos = module_list.m_modules.begin(); pos != end; ++pos)
- {
- if (Remove (*pos))
- ++num_removed;
+ collection::iterator pos, end = m_modules.end();
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ if (pos->get() == module_ptr) {
+ if (pos->unique()) {
+ pos = RemoveImpl(pos);
+ return true;
+ } else
+ return false;
+ }
}
- return num_removed;
+ }
+ return false;
}
+size_t ModuleList::RemoveOrphans(bool mandatory) {
+ std::unique_lock<std::recursive_mutex> lock(m_modules_mutex, std::defer_lock);
-void
-ModuleList::Clear()
-{
- ClearImpl();
+ if (mandatory) {
+ lock.lock();
+ } else {
+ // Not mandatory, remove orphans if we can get the mutex
+ if (!lock.try_lock())
+ return 0;
+ }
+ collection::iterator pos = m_modules.begin();
+ size_t remove_count = 0;
+ while (pos != m_modules.end()) {
+ if (pos->unique()) {
+ pos = RemoveImpl(pos);
+ ++remove_count;
+ } else {
+ ++pos;
+ }
+ }
+ return remove_count;
}
-void
-ModuleList::Destroy()
-{
- ClearImpl();
+size_t ModuleList::Remove(ModuleList &module_list) {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ size_t num_removed = 0;
+ collection::iterator pos, end = module_list.m_modules.end();
+ for (pos = module_list.m_modules.begin(); pos != end; ++pos) {
+ if (Remove(*pos))
+ ++num_removed;
+ }
+ return num_removed;
}
-void
-ModuleList::ClearImpl (bool use_notifier)
-{
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- if (use_notifier && m_notifier)
- m_notifier->WillClearList(*this);
- m_modules.clear();
-}
+void ModuleList::Clear() { ClearImpl(); }
-Module*
-ModuleList::GetModulePointerAtIndex (size_t idx) const
-{
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- return GetModulePointerAtIndexUnlocked(idx);
-}
+void ModuleList::Destroy() { ClearImpl(); }
-Module*
-ModuleList::GetModulePointerAtIndexUnlocked (size_t idx) const
-{
- if (idx < m_modules.size())
- return m_modules[idx].get();
- return nullptr;
+void ModuleList::ClearImpl(bool use_notifier) {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ if (use_notifier && m_notifier)
+ m_notifier->WillClearList(*this);
+ m_modules.clear();
}
-ModuleSP
-ModuleList::GetModuleAtIndex(size_t idx) const
-{
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- return GetModuleAtIndexUnlocked(idx);
+Module *ModuleList::GetModulePointerAtIndex(size_t idx) const {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ return GetModulePointerAtIndexUnlocked(idx);
}
-ModuleSP
-ModuleList::GetModuleAtIndexUnlocked(size_t idx) const
-{
- ModuleSP module_sp;
- if (idx < m_modules.size())
- module_sp = m_modules[idx];
- return module_sp;
+Module *ModuleList::GetModulePointerAtIndexUnlocked(size_t idx) const {
+ if (idx < m_modules.size())
+ return m_modules[idx].get();
+ return nullptr;
}
-size_t
-ModuleList::FindFunctions (const ConstString &name,
- uint32_t name_type_mask,
- bool include_symbols,
- bool include_inlines,
- bool append,
- SymbolContextList &sc_list) const
-{
- if (!append)
- sc_list.Clear();
-
- const size_t old_size = sc_list.GetSize();
-
- if (name_type_mask & eFunctionNameTypeAuto)
- {
- Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
-
- 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)->FindFunctions(lookup_info.GetLookupName(),
- nullptr,
- lookup_info.GetNameTypeMask(),
- include_symbols,
- include_inlines,
- true,
- sc_list);
- }
-
- const size_t new_size = sc_list.GetSize();
-
- if (old_size < new_size)
- lookup_info.Prune (sc_list, old_size);
- }
- else
- {
- 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)->FindFunctions(name, nullptr, name_type_mask, include_symbols, include_inlines, true, sc_list);
- }
- }
- return sc_list.GetSize() - old_size;
+ModuleSP ModuleList::GetModuleAtIndex(size_t idx) const {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ return GetModuleAtIndexUnlocked(idx);
}
-size_t
-ModuleList::FindFunctionSymbols (const ConstString &name,
- uint32_t name_type_mask,
- SymbolContextList& sc_list)
-{
- const size_t old_size = sc_list.GetSize();
-
- if (name_type_mask & eFunctionNameTypeAuto)
- {
- Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
-
- 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)->FindFunctionSymbols (lookup_info.GetLookupName(),
- lookup_info.GetNameTypeMask(),
- sc_list);
- }
-
-
- const size_t new_size = sc_list.GetSize();
+ModuleSP ModuleList::GetModuleAtIndexUnlocked(size_t idx) const {
+ ModuleSP module_sp;
+ if (idx < m_modules.size())
+ module_sp = m_modules[idx];
+ return module_sp;
+}
- if (old_size < new_size)
- lookup_info.Prune (sc_list, old_size);
- }
- else
- {
- 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)->FindFunctionSymbols (name, name_type_mask, sc_list);
- }
- }
+size_t ModuleList::FindFunctions(const ConstString &name,
+ uint32_t name_type_mask, bool include_symbols,
+ bool include_inlines, bool append,
+ SymbolContextList &sc_list) const {
+ if (!append)
+ sc_list.Clear();
- return sc_list.GetSize() - old_size;
-}
+ const size_t old_size = sc_list.GetSize();
-size_t
-ModuleList::FindFunctions(const RegularExpression &name,
- bool include_symbols,
- bool include_inlines,
- bool append,
- SymbolContextList& sc_list)
-{
- const size_t old_size = sc_list.GetSize();
+ if (name_type_mask & eFunctionNameTypeAuto) {
+ Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
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)->FindFunctions (name, include_symbols, include_inlines, append, sc_list);
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ (*pos)->FindFunctions(lookup_info.GetLookupName(), nullptr,
+ lookup_info.GetNameTypeMask(), include_symbols,
+ include_inlines, true, sc_list);
}
- return sc_list.GetSize() - old_size;
-}
-
-size_t
-ModuleList::FindCompileUnits (const FileSpec &path,
- bool append,
- SymbolContextList &sc_list) const
-{
- if (!append)
- sc_list.Clear();
+ const size_t new_size = sc_list.GetSize();
+ if (old_size < new_size)
+ lookup_info.Prune(sc_list, old_size);
+ } else {
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)->FindCompileUnits (path, true, sc_list);
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ (*pos)->FindFunctions(name, nullptr, name_type_mask, include_symbols,
+ include_inlines, true, sc_list);
}
-
- return sc_list.GetSize();
+ }
+ return sc_list.GetSize() - old_size;
}
-size_t
-ModuleList::FindGlobalVariables (const ConstString &name,
- bool append,
- size_t max_matches,
- VariableList& variable_list) const
-{
- size_t initial_size = variable_list.GetSize();
+size_t ModuleList::FindFunctionSymbols(const ConstString &name,
+ uint32_t name_type_mask,
+ SymbolContextList &sc_list) {
+ const size_t old_size = sc_list.GetSize();
+
+ if (name_type_mask & eFunctionNameTypeAuto) {
+ Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
+
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);
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ (*pos)->FindFunctionSymbols(lookup_info.GetLookupName(),
+ lookup_info.GetNameTypeMask(), sc_list);
}
- return variable_list.GetSize() - initial_size;
-}
-size_t
-ModuleList::FindGlobalVariables (const RegularExpression& regex,
- bool append,
- size_t max_matches,
- VariableList& variable_list) const
-{
- size_t initial_size = variable_list.GetSize();
+ const size_t new_size = sc_list.GetSize();
+
+ if (old_size < new_size)
+ lookup_info.Prune(sc_list, old_size);
+ } else {
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);
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ (*pos)->FindFunctionSymbols(name, name_type_mask, sc_list);
}
- return variable_list.GetSize() - initial_size;
-}
+ }
-size_t
-ModuleList::FindSymbolsWithNameAndType (const ConstString &name,
- SymbolType symbol_type,
- SymbolContextList &sc_list,
- bool append) const
-{
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- if (!append)
- sc_list.Clear();
- size_t initial_size = sc_list.GetSize();
-
- collection::const_iterator pos, end = m_modules.end();
- for (pos = m_modules.begin(); pos != end; ++pos)
- (*pos)->FindSymbolsWithNameAndType (name, symbol_type, sc_list);
- return sc_list.GetSize() - initial_size;
+ return sc_list.GetSize() - old_size;
}
-size_t
-ModuleList::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex,
- lldb::SymbolType symbol_type,
- SymbolContextList &sc_list,
- bool append) const
-{
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- if (!append)
- sc_list.Clear();
- size_t initial_size = sc_list.GetSize();
-
- collection::const_iterator pos, end = m_modules.end();
- for (pos = m_modules.begin(); pos != end; ++pos)
- (*pos)->FindSymbolsMatchingRegExAndType (regex, symbol_type, sc_list);
- return sc_list.GetSize() - initial_size;
-}
+size_t ModuleList::FindFunctions(const RegularExpression &name,
+ bool include_symbols, bool include_inlines,
+ bool append, SymbolContextList &sc_list) {
+ const size_t old_size = sc_list.GetSize();
-size_t
-ModuleList::FindModules (const ModuleSpec &module_spec, ModuleList& matching_module_list) const
-{
- size_t existing_matches = matching_module_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)->FindFunctions(name, include_symbols, include_inlines, append,
+ sc_list);
+ }
- 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)
- {
- ModuleSP module_sp(*pos);
- if (module_sp->MatchesModuleSpec (module_spec))
- matching_module_list.Append(module_sp);
- }
- return matching_module_list.GetSize() - existing_matches;
-}
-
-ModuleSP
-ModuleList::FindModule (const Module *module_ptr) const
-{
- ModuleSP module_sp;
-
- // Scope for "locker"
- {
- 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)
- {
- if ((*pos).get() == module_ptr)
- {
- module_sp = (*pos);
- break;
- }
- }
- }
- return module_sp;
+ return sc_list.GetSize() - old_size;
}
-ModuleSP
-ModuleList::FindModule (const UUID &uuid) const
-{
- ModuleSP module_sp;
-
- if (uuid.IsValid())
- {
- 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)
- {
- if ((*pos)->GetUUID() == uuid)
- {
- module_sp = (*pos);
- break;
- }
- }
- }
- return module_sp;
-}
+size_t ModuleList::FindCompileUnits(const FileSpec &path, bool append,
+ SymbolContextList &sc_list) const {
+ if (!append)
+ sc_list.Clear();
-size_t
-ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool name_is_fully_qualified, size_t max_matches, llvm::DenseSet<SymbolFile *> &searched_symbol_files, TypeList& types) const
-{
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ 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)->FindCompileUnits(path, true, sc_list);
+ }
- 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...
- for (pos = m_modules.begin(); pos != end; ++pos)
- {
- if (sc.module_sp.get() == (*pos).get())
- {
- total_matches += (*pos)->FindTypes (sc, name, name_is_fully_qualified, max_matches, searched_symbol_files, types);
-
- if (total_matches >= max_matches)
- break;
- }
- }
- }
-
- if (total_matches < max_matches)
- {
- 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).
- if (sc.module_sp.get() != (*pos).get())
- total_matches += (*pos)->FindTypes (world_sc, name, name_is_fully_qualified, max_matches, searched_symbol_files, types);
-
- if (total_matches >= max_matches)
- break;
- }
- }
-
- return total_matches;
+ return sc_list.GetSize();
}
-bool
-ModuleList::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
-{
- 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)
- {
- if ((*pos)->FindSourceFile (orig_spec, new_spec))
- return true;
- }
- return false;
+size_t ModuleList::FindGlobalVariables(const ConstString &name, bool append,
+ 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);
+ }
+ return variable_list.GetSize() - initial_size;
}
-void
-ModuleList::FindAddressesForLine (const lldb::TargetSP target_sp,
- const FileSpec &file, uint32_t line,
- Function *function,
- std::vector<Address> &output_local, std::vector<Address> &output_extern)
-{
- 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)->FindAddressesForLine(target_sp, file, line, function, output_local, output_extern);
- }
+size_t ModuleList::FindGlobalVariables(const RegularExpression ®ex,
+ bool append, 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);
+ }
+ return variable_list.GetSize() - initial_size;
}
-ModuleSP
-ModuleList::FindFirstModule (const ModuleSpec &module_spec) const
-{
- ModuleSP module_sp;
- 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)
- {
- ModuleSP module_sp(*pos);
- if (module_sp->MatchesModuleSpec (module_spec))
- return module_sp;
- }
- return module_sp;
+size_t ModuleList::FindSymbolsWithNameAndType(const ConstString &name,
+ SymbolType symbol_type,
+ SymbolContextList &sc_list,
+ bool append) const {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ if (!append)
+ sc_list.Clear();
+ size_t initial_size = sc_list.GetSize();
+ collection::const_iterator pos, end = m_modules.end();
+ for (pos = m_modules.begin(); pos != end; ++pos)
+ (*pos)->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
+ return sc_list.GetSize() - initial_size;
}
-size_t
-ModuleList::GetSize() const
-{
- size_t size = 0;
- {
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- size = m_modules.size();
- }
- return size;
-}
-
-void
-ModuleList::Dump(Stream *s) const
-{
- // s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
- // s.Indent();
- // s << "ModuleList\n";
+size_t ModuleList::FindSymbolsMatchingRegExAndType(
+ const RegularExpression ®ex, lldb::SymbolType symbol_type,
+ SymbolContextList &sc_list, bool append) const {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ if (!append)
+ sc_list.Clear();
+ size_t initial_size = sc_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)->Dump(s);
- }
+ collection::const_iterator pos, end = m_modules.end();
+ for (pos = m_modules.begin(); pos != end; ++pos)
+ (*pos)->FindSymbolsMatchingRegExAndType(regex, symbol_type, sc_list);
+ return sc_list.GetSize() - initial_size;
}
-void
-ModuleList::LogUUIDAndPaths (Log *log, const char *prefix_cstr)
-{
- if (log != nullptr)
- {
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- collection::const_iterator pos, begin = m_modules.begin(), end = m_modules.end();
- for (pos = begin; pos != end; ++pos)
- {
- Module *module = pos->get();
- const FileSpec &module_file_spec = module->GetFileSpec();
- log->Printf ("%s[%u] %s (%s) \"%s\"",
- prefix_cstr ? prefix_cstr : "",
- (uint32_t)std::distance (begin, pos),
- module->GetUUID().GetAsString().c_str(),
- module->GetArchitecture().GetArchitectureName(),
- module_file_spec.GetPath().c_str());
- }
- }
+size_t ModuleList::FindModules(const ModuleSpec &module_spec,
+ ModuleList &matching_module_list) const {
+ size_t existing_matches = matching_module_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) {
+ ModuleSP module_sp(*pos);
+ if (module_sp->MatchesModuleSpec(module_spec))
+ matching_module_list.Append(module_sp);
+ }
+ return matching_module_list.GetSize() - existing_matches;
}
-bool
-ModuleList::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) const
-{
+ModuleSP ModuleList::FindModule(const Module *module_ptr) const {
+ ModuleSP module_sp;
+
+ // Scope for "locker"
+ {
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)
- {
- if ((*pos)->ResolveFileAddress (vm_addr, so_addr))
- return true;
- }
-
- return false;
-}
-uint32_t
-ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) const
-{
- // The address is already section offset so it has a module
- uint32_t resolved_flags = 0;
- ModuleSP module_sp (so_addr.GetModule());
- if (module_sp)
- {
- resolved_flags = module_sp->ResolveSymbolContextForAddress (so_addr,
- resolve_scope,
- sc);
- }
- else
- {
- 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)
- {
- resolved_flags = (*pos)->ResolveSymbolContextForAddress (so_addr,
- resolve_scope,
- sc);
- if (resolved_flags != 0)
- break;
- }
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ if ((*pos).get() == module_ptr) {
+ module_sp = (*pos);
+ break;
+ }
}
-
- return resolved_flags;
+ }
+ return module_sp;
}
-uint32_t
-ModuleList::ResolveSymbolContextForFilePath(const char *file_path,
- uint32_t line,
- bool check_inlines,
- uint32_t resolve_scope,
- SymbolContextList& sc_list) const
-{
- FileSpec file_spec(file_path, false);
- return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
-}
-
-uint32_t
-ModuleList::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) const
-{
+ModuleSP ModuleList::FindModule(const UUID &uuid) const {
+ ModuleSP module_sp;
+
+ if (uuid.IsValid()) {
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)->ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
- }
- return sc_list.GetSize();
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ if ((*pos)->GetUUID() == uuid) {
+ module_sp = (*pos);
+ break;
+ }
+ }
+ }
+ return module_sp;
}
size_t
-ModuleList::GetIndexForModule (const Module *module) const
-{
- if (module)
- {
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- collection::const_iterator pos;
- collection::const_iterator begin = m_modules.begin();
- collection::const_iterator end = m_modules.end();
- for (pos = begin; pos != end; ++pos)
- {
- if ((*pos).get() == module)
- return std::distance (begin, pos);
- }
+ModuleList::FindTypes(const SymbolContext &sc, const ConstString &name,
+ bool name_is_fully_qualified, size_t max_matches,
+ llvm::DenseSet<SymbolFile *> &searched_symbol_files,
+ TypeList &types) const {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+
+ 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...
+ for (pos = m_modules.begin(); pos != end; ++pos) {
+ if (sc.module_sp.get() == (*pos).get()) {
+ total_matches +=
+ (*pos)->FindTypes(sc, name, name_is_fully_qualified, max_matches,
+ searched_symbol_files, types);
+
+ if (total_matches >= max_matches)
+ break;
+ }
}
- return LLDB_INVALID_INDEX32;
-}
+ }
+
+ if (total_matches < max_matches) {
+ 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).
+ if (sc.module_sp.get() != (*pos).get())
+ total_matches +=
+ (*pos)->FindTypes(world_sc, name, name_is_fully_qualified,
+ max_matches, searched_symbol_files, types);
-static ModuleList &
-GetSharedModuleList ()
-{
- static ModuleList *g_shared_module_list = nullptr;
- static std::once_flag g_once_flag;
- std::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!!!
- });
- return *g_shared_module_list;
-}
-
-bool
-ModuleList::ModuleIsInCache (const Module *module_ptr)
-{
- if (module_ptr)
- {
- ModuleList &shared_module_list = GetSharedModuleList ();
- return shared_module_list.FindModule(module_ptr).get() != nullptr;
+ if (total_matches >= max_matches)
+ break;
}
- return false;
-}
+ }
-size_t
-ModuleList::FindSharedModules (const ModuleSpec &module_spec, ModuleList &matching_module_list)
-{
- return GetSharedModuleList ().FindModules (module_spec, matching_module_list);
+ return total_matches;
}
-size_t
-ModuleList::RemoveOrphanSharedModules (bool mandatory)
-{
- return GetSharedModuleList ().RemoveOrphans(mandatory);
-}
-
-Error
-ModuleList::GetSharedModule(const ModuleSpec &module_spec,
- ModuleSP &module_sp,
- const FileSpecList *module_search_paths_ptr,
- ModuleSP *old_module_sp_ptr,
- bool *did_create_ptr,
- bool always_create)
-{
- ModuleList &shared_module_list = GetSharedModuleList ();
- std::lock_guard<std::recursive_mutex> guard(shared_module_list.m_modules_mutex);
- char path[PATH_MAX];
+bool ModuleList::FindSourceFile(const FileSpec &orig_spec,
+ FileSpec &new_spec) const {
+ 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) {
+ if ((*pos)->FindSourceFile(orig_spec, new_spec))
+ return true;
+ }
+ return false;
+}
- Error error;
+void ModuleList::FindAddressesForLine(const lldb::TargetSP target_sp,
+ const FileSpec &file, uint32_t line,
+ Function *function,
+ std::vector<Address> &output_local,
+ std::vector<Address> &output_extern) {
+ 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)->FindAddressesForLine(target_sp, file, line, function, output_local,
+ output_extern);
+ }
+}
- module_sp.reset();
+ModuleSP ModuleList::FindFirstModule(const ModuleSpec &module_spec) const {
+ ModuleSP module_sp;
+ 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) {
+ ModuleSP module_sp(*pos);
+ if (module_sp->MatchesModuleSpec(module_spec))
+ return module_sp;
+ }
+ return module_sp;
+}
+
+size_t ModuleList::GetSize() const {
+ size_t size = 0;
+ {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ size = m_modules.size();
+ }
+ return size;
+}
+
+void ModuleList::Dump(Stream *s) const {
+ // s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
+ // s.Indent();
+ // s << "ModuleList\n";
+
+ 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)->Dump(s);
+ }
+}
+
+void ModuleList::LogUUIDAndPaths(Log *log, const char *prefix_cstr) {
+ if (log != nullptr) {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ collection::const_iterator pos, begin = m_modules.begin(),
+ end = m_modules.end();
+ for (pos = begin; pos != end; ++pos) {
+ Module *module = pos->get();
+ const FileSpec &module_file_spec = module->GetFileSpec();
+ log->Printf("%s[%u] %s (%s) \"%s\"", prefix_cstr ? prefix_cstr : "",
+ (uint32_t)std::distance(begin, pos),
+ module->GetUUID().GetAsString().c_str(),
+ module->GetArchitecture().GetArchitectureName(),
+ module_file_spec.GetPath().c_str());
+ }
+ }
+}
+
+bool ModuleList::ResolveFileAddress(lldb::addr_t vm_addr,
+ Address &so_addr) const {
+ 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) {
+ if ((*pos)->ResolveFileAddress(vm_addr, so_addr))
+ return true;
+ }
+
+ return false;
+}
+
+uint32_t ModuleList::ResolveSymbolContextForAddress(const Address &so_addr,
+ uint32_t resolve_scope,
+ SymbolContext &sc) const {
+ // The address is already section offset so it has a module
+ uint32_t resolved_flags = 0;
+ ModuleSP module_sp(so_addr.GetModule());
+ if (module_sp) {
+ resolved_flags =
+ module_sp->ResolveSymbolContextForAddress(so_addr, resolve_scope, sc);
+ } else {
+ 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) {
+ resolved_flags =
+ (*pos)->ResolveSymbolContextForAddress(so_addr, resolve_scope, sc);
+ if (resolved_flags != 0)
+ break;
+ }
+ }
+
+ return resolved_flags;
+}
+
+uint32_t ModuleList::ResolveSymbolContextForFilePath(
+ const char *file_path, uint32_t line, bool check_inlines,
+ uint32_t resolve_scope, SymbolContextList &sc_list) const {
+ FileSpec file_spec(file_path, false);
+ return ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
+ resolve_scope, sc_list);
+}
+
+uint32_t ModuleList::ResolveSymbolContextsForFileSpec(
+ const FileSpec &file_spec, uint32_t line, bool check_inlines,
+ uint32_t resolve_scope, SymbolContextList &sc_list) const {
+ 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)->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
+ resolve_scope, sc_list);
+ }
+
+ return sc_list.GetSize();
+}
+
+size_t ModuleList::GetIndexForModule(const Module *module) const {
+ if (module) {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ collection::const_iterator pos;
+ collection::const_iterator begin = m_modules.begin();
+ collection::const_iterator end = m_modules.end();
+ for (pos = begin; pos != end; ++pos) {
+ if ((*pos).get() == module)
+ return std::distance(begin, pos);
+ }
+ }
+ return LLDB_INVALID_INDEX32;
+}
+
+static ModuleList &GetSharedModuleList() {
+ static ModuleList *g_shared_module_list = nullptr;
+ static std::once_flag g_once_flag;
+ std::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!!!
+ });
+ return *g_shared_module_list;
+}
+
+bool ModuleList::ModuleIsInCache(const Module *module_ptr) {
+ if (module_ptr) {
+ ModuleList &shared_module_list = GetSharedModuleList();
+ return shared_module_list.FindModule(module_ptr).get() != nullptr;
+ }
+ return false;
+}
+
+size_t ModuleList::FindSharedModules(const ModuleSpec &module_spec,
+ ModuleList &matching_module_list) {
+ return GetSharedModuleList().FindModules(module_spec, matching_module_list);
+}
+
+size_t ModuleList::RemoveOrphanSharedModules(bool mandatory) {
+ return GetSharedModuleList().RemoveOrphans(mandatory);
+}
+
+Error ModuleList::GetSharedModule(const ModuleSpec &module_spec,
+ ModuleSP &module_sp,
+ const FileSpecList *module_search_paths_ptr,
+ ModuleSP *old_module_sp_ptr,
+ bool *did_create_ptr, bool always_create) {
+ ModuleList &shared_module_list = GetSharedModuleList();
+ std::lock_guard<std::recursive_mutex> guard(
+ shared_module_list.m_modules_mutex);
+ char path[PATH_MAX];
+
+ Error error;
+
+ module_sp.reset();
+
+ if (did_create_ptr)
+ *did_create_ptr = false;
+ if (old_module_sp_ptr)
+ old_module_sp_ptr->reset();
+
+ const UUID *uuid_ptr = module_spec.GetUUIDPtr();
+ const FileSpec &module_file_spec = module_spec.GetFileSpec();
+ 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.
+ if (!always_create) {
+ ModuleList matching_module_list;
+ const size_t num_matching_modules =
+ shared_module_list.FindModules(module_spec, matching_module_list);
+ if (num_matching_modules > 0) {
+ for (size_t module_idx = 0; module_idx < num_matching_modules;
+ ++module_idx) {
+ module_sp = matching_module_list.GetModuleAtIndex(module_idx);
+
+ // Make sure the file for the module hasn't been modified
+ if (module_sp->FileHasChanged()) {
+ if (old_module_sp_ptr && !*old_module_sp_ptr)
+ *old_module_sp_ptr = module_sp;
+
+ Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES));
+ if (log != nullptr)
+ log->Printf("module changed: %p, removing from global module list",
+ static_cast<void *>(module_sp.get()));
+
+ 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.
+ return error;
+ }
+ }
+ }
+ }
- if (did_create_ptr)
- *did_create_ptr = false;
- if (old_module_sp_ptr)
- old_module_sp_ptr->reset();
-
- const UUID *uuid_ptr = module_spec.GetUUIDPtr();
- const FileSpec &module_file_spec = module_spec.GetFileSpec();
- const ArchSpec &arch = module_spec.GetArchitecture();
+ if (module_sp)
+ return error;
- // 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.
- if (!always_create)
- {
- ModuleList matching_module_list;
- const size_t num_matching_modules = shared_module_list.FindModules (module_spec, matching_module_list);
- if (num_matching_modules > 0)
- {
- for (size_t module_idx = 0; module_idx < num_matching_modules; ++module_idx)
- {
- module_sp = matching_module_list.GetModuleAtIndex(module_idx);
-
- // Make sure the file for the module hasn't been modified
- if (module_sp->FileHasChanged())
- {
- if (old_module_sp_ptr && !*old_module_sp_ptr)
- *old_module_sp_ptr = module_sp;
-
- Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_MODULES));
- if (log != nullptr)
- log->Printf("module changed: %p, removing from global module list",
- static_cast<void*>(module_sp.get()));
-
- 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.
- 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
+ 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 (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) {
+ module_sp.reset();
+ } else {
+ if (module_sp->GetObjectFile() &&
+ module_sp->GetObjectFile()->GetType() ==
+ ObjectFile::eTypeStubLibrary) {
+ module_sp.reset();
+ } else {
+ if (did_create_ptr) {
+ *did_create_ptr = true;
}
- }
- if (module_sp)
+ shared_module_list.ReplaceEquivalent(module_sp);
return error;
+ }
+ }
+ } else {
+ module_sp.reset();
+ }
- 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
- if (module_sp->GetObjectFile())
- {
+ if (module_search_paths_ptr) {
+ const auto num_directories = module_search_paths_ptr->GetSize();
+ for (size_t idx = 0; idx < num_directories; ++idx) {
+ auto search_path_spec = module_search_paths_ptr->GetFileSpecAtIndex(idx);
+ if (!search_path_spec.ResolvePath())
+ continue;
+ if (!search_path_spec.Exists() || !search_path_spec.IsDirectory())
+ continue;
+ search_path_spec.AppendPathComponent(
+ module_spec.GetFileSpec().GetFilename().AsCString());
+ if (!search_path_spec.Exists())
+ continue;
+
+ auto resolved_module_spec(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 (uuid_ptr && *uuid_ptr != module_sp->GetUUID())
- {
+ if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) {
+ module_sp.reset();
+ } else {
+ if (module_sp->GetObjectFile()->GetType() ==
+ ObjectFile::eTypeStubLibrary) {
module_sp.reset();
+ } else {
+ if (did_create_ptr)
+ *did_create_ptr = true;
+
+ shared_module_list.ReplaceEquivalent(module_sp);
+ return Error();
+ }
}
- else
- {
- if (module_sp->GetObjectFile() && module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeStubLibrary)
- {
- module_sp.reset();
- }
- else
- {
- if (did_create_ptr)
- {
- *did_create_ptr = true;
- }
-
- shared_module_list.ReplaceEquivalent(module_sp);
- return error;
- }
- }
+ } else {
+ module_sp.reset();
+ }
}
- else
- {
+ }
+
+ // Either the file didn't exist where at the path, or no path was given, so
+ // 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.
+ ModuleSpec located_binary_modulespec =
+ Symbols::LocateExecutableObjectFile(module_spec);
+
+ // Don't look for the file if it appears to be the same one we already
+ // checked for above...
+ if (located_binary_modulespec.GetFileSpec() != module_file_spec) {
+ if (!located_binary_modulespec.GetFileSpec().Exists()) {
+ located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));
+ if (path[0] == '\0')
+ module_file_spec.GetPath(path, sizeof(path));
+ // How can this check ever be true? This branch it is false, and we
+ // haven't modified file_spec.
+ if (located_binary_modulespec.GetFileSpec().Exists()) {
+ std::string uuid_str;
+ if (uuid_ptr && uuid_ptr->IsValid())
+ uuid_str = uuid_ptr->GetAsString();
+
+ if (arch.IsValid()) {
+ if (!uuid_str.empty())
+ error.SetErrorStringWithFormat(
+ "'%s' does not contain the %s architecture and UUID %s", path,
+ arch.GetArchitectureName(), uuid_str.c_str());
+ else
+ error.SetErrorStringWithFormat(
+ "'%s' does not contain the %s architecture.", path,
+ arch.GetArchitectureName());
+ }
+ } else {
+ error.SetErrorStringWithFormat("'%s' does not exist", path);
+ }
+ if (error.Fail())
module_sp.reset();
+ return error;
}
- if (module_search_paths_ptr)
- {
- const auto num_directories = module_search_paths_ptr->GetSize();
- for (size_t idx = 0; idx < num_directories; ++idx)
- {
- auto search_path_spec = module_search_paths_ptr->GetFileSpecAtIndex(idx);
- if (!search_path_spec.ResolvePath())
- continue;
- if (!search_path_spec.Exists() || !search_path_spec.IsDirectory())
- continue;
- search_path_spec.AppendPathComponent(module_spec.GetFileSpec().GetFilename().AsCString());
- if (!search_path_spec.Exists())
- continue;
-
- auto resolved_module_spec(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 (uuid_ptr && *uuid_ptr != module_sp->GetUUID())
- {
- module_sp.reset();
- }
- else
- {
- if (module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeStubLibrary)
- {
- module_sp.reset();
- }
- else
- {
- if (did_create_ptr)
- *did_create_ptr = true;
-
- shared_module_list.ReplaceEquivalent(module_sp);
- return Error();
- }
- }
- }
- else
- {
- module_sp.reset();
- }
+ // 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.
+ ModuleSpec platform_module_spec(module_spec);
+ platform_module_spec.GetFileSpec() =
+ located_binary_modulespec.GetFileSpec();
+ platform_module_spec.GetPlatformFileSpec() =
+ located_binary_modulespec.GetFileSpec();
+ platform_module_spec.GetSymbolFileSpec() =
+ located_binary_modulespec.GetSymbolFileSpec();
+ ModuleList matching_module_list;
+ if (shared_module_list.FindModules(platform_module_spec,
+ matching_module_list) > 0) {
+ module_sp = matching_module_list.GetModuleAtIndex(0);
+
+ // If we didn't have a UUID in mind when looking for the object file,
+ // then we should make sure the modification time hasn't changed!
+ if (platform_module_spec.GetUUIDPtr() == nullptr) {
+ TimeValue file_spec_mod_time(
+ located_binary_modulespec.GetFileSpec().GetModificationTime());
+ if (file_spec_mod_time.IsValid()) {
+ if (file_spec_mod_time != module_sp->GetModificationTime()) {
+ if (old_module_sp_ptr)
+ *old_module_sp_ptr = module_sp;
+ shared_module_list.Remove(module_sp);
+ module_sp.reset();
+ }
}
+ }
}
- // Either the file didn't exist where at the path, or no path was given, so
- // 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.
- ModuleSpec located_binary_modulespec = Symbols::LocateExecutableObjectFile (module_spec);
-
- // Don't look for the file if it appears to be the same one we already
- // checked for above...
- if (located_binary_modulespec.GetFileSpec() != module_file_spec)
- {
- if (!located_binary_modulespec.GetFileSpec().Exists())
- {
- located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));
- if (path[0] == '\0')
- module_file_spec.GetPath(path, sizeof(path));
- // How can this check ever be true? This branch it is false, and we haven't modified file_spec.
- if (located_binary_modulespec.GetFileSpec().Exists())
- {
- std::string uuid_str;
- if (uuid_ptr && uuid_ptr->IsValid())
- uuid_str = uuid_ptr->GetAsString();
-
- if (arch.IsValid())
- {
- if (!uuid_str.empty())
- error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s", path, arch.GetArchitectureName(), uuid_str.c_str());
- else
- error.SetErrorStringWithFormat("'%s' does not contain the %s architecture.", path, arch.GetArchitectureName());
- }
- }
- else
- {
- error.SetErrorStringWithFormat("'%s' does not exist", path);
- }
- if (error.Fail())
- module_sp.reset();
- return error;
- }
+ 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.
+ // By getting the object file we can guarantee that the architecture
+ // matches
+ if (module_sp && module_sp->GetObjectFile()) {
+ if (module_sp->GetObjectFile()->GetType() ==
+ ObjectFile::eTypeStubLibrary) {
+ module_sp.reset();
+ } else {
+ if (did_create_ptr)
+ *did_create_ptr = true;
- // 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.
- ModuleSpec platform_module_spec(module_spec);
- platform_module_spec.GetFileSpec() = located_binary_modulespec.GetFileSpec();
- platform_module_spec.GetPlatformFileSpec() = located_binary_modulespec.GetFileSpec();
- platform_module_spec.GetSymbolFileSpec() = located_binary_modulespec.GetSymbolFileSpec();
- ModuleList matching_module_list;
- if (shared_module_list.FindModules (platform_module_spec, matching_module_list) > 0)
- {
- module_sp = matching_module_list.GetModuleAtIndex(0);
-
- // If we didn't have a UUID in mind when looking for the object file,
- // then we should make sure the modification time hasn't changed!
- if (platform_module_spec.GetUUIDPtr() == nullptr)
- {
- TimeValue file_spec_mod_time(located_binary_modulespec.GetFileSpec().GetModificationTime());
- if (file_spec_mod_time.IsValid())
- {
- if (file_spec_mod_time != module_sp->GetModificationTime())
- {
- if (old_module_sp_ptr)
- *old_module_sp_ptr = module_sp;
- shared_module_list.Remove (module_sp);
- module_sp.reset();
- }
- }
- }
+ shared_module_list.ReplaceEquivalent(module_sp);
}
+ } else {
+ located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));
+
+ if (located_binary_modulespec.GetFileSpec()) {
+ if (arch.IsValid())
+ error.SetErrorStringWithFormat(
+ "unable to open %s architecture in '%s'",
+ arch.GetArchitectureName(), path);
+ else
+ error.SetErrorStringWithFormat("unable to open '%s'", path);
+ } else {
+ std::string uuid_str;
+ if (uuid_ptr && uuid_ptr->IsValid())
+ uuid_str = uuid_ptr->GetAsString();
- 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.
- // By getting the object file we can guarantee that the architecture matches
- if (module_sp && module_sp->GetObjectFile())
- {
- if (module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeStubLibrary)
- {
- module_sp.reset();
- }
- else
- {
- if (did_create_ptr)
- *did_create_ptr = true;
-
- shared_module_list.ReplaceEquivalent(module_sp);
- }
- }
- else
- {
- located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));
-
- if (located_binary_modulespec.GetFileSpec())
- {
- if (arch.IsValid())
- error.SetErrorStringWithFormat("unable to open %s architecture in '%s'", arch.GetArchitectureName(), path);
- else
- error.SetErrorStringWithFormat("unable to open '%s'", path);
- }
- else
- {
- std::string uuid_str;
- if (uuid_ptr && uuid_ptr->IsValid())
- uuid_str = uuid_ptr->GetAsString();
-
- if (!uuid_str.empty())
- error.SetErrorStringWithFormat("cannot locate a module for UUID '%s'", uuid_str.c_str());
- else
- error.SetErrorStringWithFormat("cannot locate a module");
- }
- }
+ if (!uuid_str.empty())
+ error.SetErrorStringWithFormat(
+ "cannot locate a module for UUID '%s'", uuid_str.c_str());
+ else
+ error.SetErrorStringWithFormat("cannot locate a module");
}
+ }
}
+ }
- return error;
+ return error;
}
-bool
-ModuleList::RemoveSharedModule (lldb::ModuleSP &module_sp)
-{
- return GetSharedModuleList ().Remove (module_sp);
-}
-
-bool
-ModuleList::RemoveSharedModuleIfOrphaned (const Module *module_ptr)
-{
- return GetSharedModuleList ().RemoveIfOrphaned (module_ptr);
-}
-
-bool
-ModuleList::LoadScriptingResourcesInTarget (Target *target,
- std::list<Error>& errors,
- Stream *feedback_stream,
- bool continue_on_error)
-{
- if (!target)
- return false;
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- for (auto module : m_modules)
- {
- Error error;
- if (module)
- {
- if (!module->LoadScriptingResourceInTarget(target, error, feedback_stream))
- {
- if (error.Fail() && error.AsCString())
- {
- error.SetErrorStringWithFormat("unable to load scripting data for module %s - error reported was %s",
- module->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
- error.AsCString());
- errors.push_back(error);
-
- if (!continue_on_error)
- return false;
- }
- }
- }
- }
- return errors.empty();
+bool ModuleList::RemoveSharedModule(lldb::ModuleSP &module_sp) {
+ return GetSharedModuleList().Remove(module_sp);
}
-void
-ModuleList::ForEach (std::function <bool (const ModuleSP &module_sp)> const &callback) const
-{
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- for (const auto &module : m_modules)
- {
- // If the callback returns false, then stop iterating and break out
- if (!callback (module))
- break;
- }
+bool ModuleList::RemoveSharedModuleIfOrphaned(const Module *module_ptr) {
+ return GetSharedModuleList().RemoveIfOrphaned(module_ptr);
+}
+
+bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
+ std::list<Error> &errors,
+ Stream *feedback_stream,
+ bool continue_on_error) {
+ if (!target)
+ return false;
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ for (auto module : m_modules) {
+ Error error;
+ if (module) {
+ if (!module->LoadScriptingResourceInTarget(target, error,
+ feedback_stream)) {
+ if (error.Fail() && error.AsCString()) {
+ error.SetErrorStringWithFormat("unable to load scripting data for "
+ "module %s - error reported was %s",
+ module->GetFileSpec()
+ .GetFileNameStrippingExtension()
+ .GetCString(),
+ error.AsCString());
+ errors.push_back(error);
+
+ if (!continue_on_error)
+ return false;
+ }
+ }
+ }
+ }
+ return errors.empty();
+}
+
+void ModuleList::ForEach(
+ std::function<bool(const ModuleSP &module_sp)> const &callback) const {
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
+ for (const auto &module : m_modules) {
+ // If the callback returns false, then stop iterating and break out
+ if (!callback(module))
+ break;
+ }
}
Modified: lldb/trunk/source/Core/Opcode.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Opcode.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/Opcode.cpp (original)
+++ lldb/trunk/source/Core/Opcode.cpp Tue Sep 6 15:57:50 2016
@@ -24,136 +24,119 @@
using namespace lldb;
using namespace lldb_private;
-int
-Opcode::Dump (Stream *s, uint32_t min_byte_width)
-{
- int bytes_written = 0;
- switch (m_type)
- {
- case Opcode::eTypeInvalid:
- bytes_written = s->PutCString ("<invalid>");
- break;
- case Opcode::eType8:
- bytes_written = s->Printf ("0x%2.2x", m_data.inst8);
- break;
- case Opcode::eType16:
- bytes_written = s->Printf ("0x%4.4x", m_data.inst16);
- break;
- case Opcode::eType16_2:
- case Opcode::eType32:
- bytes_written = s->Printf ("0x%8.8x", m_data.inst32);
- break;
-
- case Opcode::eType64:
- bytes_written = s->Printf ("0x%16.16" PRIx64, m_data.inst64);
- break;
-
- case Opcode::eTypeBytes:
- for (uint32_t i = 0; i < m_data.inst.length; ++i)
- {
- if (i > 0)
- bytes_written += s->PutChar (' ');
- bytes_written += s->Printf ("%2.2x", m_data.inst.bytes[i]);
- }
- break;
+int Opcode::Dump(Stream *s, uint32_t min_byte_width) {
+ int bytes_written = 0;
+ switch (m_type) {
+ case Opcode::eTypeInvalid:
+ bytes_written = s->PutCString("<invalid>");
+ break;
+ case Opcode::eType8:
+ bytes_written = s->Printf("0x%2.2x", m_data.inst8);
+ break;
+ case Opcode::eType16:
+ bytes_written = s->Printf("0x%4.4x", m_data.inst16);
+ break;
+ case Opcode::eType16_2:
+ case Opcode::eType32:
+ bytes_written = s->Printf("0x%8.8x", m_data.inst32);
+ break;
+
+ case Opcode::eType64:
+ bytes_written = s->Printf("0x%16.16" PRIx64, m_data.inst64);
+ break;
+
+ case Opcode::eTypeBytes:
+ for (uint32_t i = 0; i < m_data.inst.length; ++i) {
+ if (i > 0)
+ bytes_written += s->PutChar(' ');
+ bytes_written += s->Printf("%2.2x", m_data.inst.bytes[i]);
}
+ break;
+ }
- // 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;
+ // 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;
}
-lldb::ByteOrder
-Opcode::GetDataByteOrder () const
-{
- if (m_byte_order != eByteOrderInvalid)
- {
- return m_byte_order;
- }
- switch (m_type)
- {
- case Opcode::eTypeInvalid: break;
- case Opcode::eType8:
- case Opcode::eType16:
- case Opcode::eType16_2:
- case Opcode::eType32:
- case Opcode::eType64: return endian::InlHostByteOrder();
- case Opcode::eTypeBytes:
- break;
- }
- return eByteOrderInvalid;
+lldb::ByteOrder Opcode::GetDataByteOrder() const {
+ if (m_byte_order != eByteOrderInvalid) {
+ return m_byte_order;
+ }
+ switch (m_type) {
+ case Opcode::eTypeInvalid:
+ break;
+ case Opcode::eType8:
+ case Opcode::eType16:
+ case Opcode::eType16_2:
+ case Opcode::eType32:
+ case Opcode::eType64:
+ return endian::InlHostByteOrder();
+ case Opcode::eTypeBytes:
+ break;
+ }
+ return eByteOrderInvalid;
}
-uint32_t
-Opcode::GetData (DataExtractor &data) const
-{
- uint32_t byte_size = GetByteSize ();
- uint8_t swap_buf[8];
- const void *buf = nullptr;
-
- if (byte_size > 0)
- {
- if (!GetEndianSwap())
- {
- if (m_type == Opcode::eType16_2)
- {
- // 32 bit thumb instruction, we need to sizzle this a bit
- swap_buf[0] = m_data.inst.bytes[2];
- swap_buf[1] = m_data.inst.bytes[3];
- swap_buf[2] = m_data.inst.bytes[0];
- swap_buf[3] = m_data.inst.bytes[1];
- buf = swap_buf;
- }
- else
- {
- buf = GetOpcodeDataBytes();
- }
- }
- else
- {
- switch (m_type)
- {
- case Opcode::eTypeInvalid:
- break;
- case Opcode::eType8:
- buf = GetOpcodeDataBytes();
- break;
- case Opcode::eType16:
- *(uint16_t *)swap_buf = llvm::ByteSwap_16(m_data.inst16);
- buf = swap_buf;
- break;
- case Opcode::eType16_2:
- swap_buf[0] = m_data.inst.bytes[1];
- swap_buf[1] = m_data.inst.bytes[0];
- swap_buf[2] = m_data.inst.bytes[3];
- swap_buf[3] = m_data.inst.bytes[2];
- buf = swap_buf;
- break;
- case Opcode::eType32:
- *(uint32_t *)swap_buf = llvm::ByteSwap_32(m_data.inst32);
- buf = swap_buf;
- break;
- case Opcode::eType64:
- *(uint32_t *)swap_buf = llvm::ByteSwap_64(m_data.inst64);
- buf = swap_buf;
- break;
- case Opcode::eTypeBytes:
- buf = GetOpcodeDataBytes();
- break;
- }
- }
- }
- if (buf != nullptr)
- {
- DataBufferSP buffer_sp;
-
- buffer_sp.reset (new DataBufferHeap (buf, byte_size));
- data.SetByteOrder(GetDataByteOrder());
- data.SetData (buffer_sp);
- return byte_size;
+uint32_t Opcode::GetData(DataExtractor &data) const {
+ uint32_t byte_size = GetByteSize();
+ uint8_t swap_buf[8];
+ const void *buf = nullptr;
+
+ if (byte_size > 0) {
+ if (!GetEndianSwap()) {
+ if (m_type == Opcode::eType16_2) {
+ // 32 bit thumb instruction, we need to sizzle this a bit
+ swap_buf[0] = m_data.inst.bytes[2];
+ swap_buf[1] = m_data.inst.bytes[3];
+ swap_buf[2] = m_data.inst.bytes[0];
+ swap_buf[3] = m_data.inst.bytes[1];
+ buf = swap_buf;
+ } else {
+ buf = GetOpcodeDataBytes();
+ }
+ } else {
+ switch (m_type) {
+ case Opcode::eTypeInvalid:
+ break;
+ case Opcode::eType8:
+ buf = GetOpcodeDataBytes();
+ break;
+ case Opcode::eType16:
+ *(uint16_t *)swap_buf = llvm::ByteSwap_16(m_data.inst16);
+ buf = swap_buf;
+ break;
+ case Opcode::eType16_2:
+ swap_buf[0] = m_data.inst.bytes[1];
+ swap_buf[1] = m_data.inst.bytes[0];
+ swap_buf[2] = m_data.inst.bytes[3];
+ swap_buf[3] = m_data.inst.bytes[2];
+ buf = swap_buf;
+ break;
+ case Opcode::eType32:
+ *(uint32_t *)swap_buf = llvm::ByteSwap_32(m_data.inst32);
+ buf = swap_buf;
+ break;
+ case Opcode::eType64:
+ *(uint32_t *)swap_buf = llvm::ByteSwap_64(m_data.inst64);
+ buf = swap_buf;
+ break;
+ case Opcode::eTypeBytes:
+ buf = GetOpcodeDataBytes();
+ break;
+ }
}
- data.Clear();
- return 0;
+ }
+ if (buf != nullptr) {
+ DataBufferSP buffer_sp;
+
+ buffer_sp.reset(new DataBufferHeap(buf, byte_size));
+ data.SetByteOrder(GetDataByteOrder());
+ data.SetData(buffer_sp);
+ return byte_size;
+ }
+ data.Clear();
+ return 0;
}
Modified: lldb/trunk/source/Core/PluginManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/PluginManager.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/PluginManager.cpp (original)
+++ lldb/trunk/source/Core/PluginManager.cpp Tue Sep 6 15:57:50 2016
@@ -31,1890 +31,1534 @@
using namespace lldb;
using namespace lldb_private;
-enum PluginAction
-{
- ePluginRegisterInstance,
- ePluginUnregisterInstance,
- ePluginGetInstanceAtIndex
+enum PluginAction {
+ ePluginRegisterInstance,
+ ePluginUnregisterInstance,
+ ePluginGetInstanceAtIndex
};
typedef bool (*PluginInitCallback)();
typedef void (*PluginTermCallback)();
-struct PluginInfo
-{
- PluginInfo()
- : plugin_init_callback(nullptr), plugin_term_callback(nullptr)
- {
- }
+struct PluginInfo {
+ PluginInfo() : plugin_init_callback(nullptr), plugin_term_callback(nullptr) {}
- llvm::sys::DynamicLibrary library;
- PluginInitCallback plugin_init_callback;
- PluginTermCallback plugin_term_callback;
+ llvm::sys::DynamicLibrary library;
+ PluginInitCallback plugin_init_callback;
+ PluginTermCallback plugin_term_callback;
};
typedef std::map<FileSpec, PluginInfo> PluginTerminateMap;
-static std::recursive_mutex &
-GetPluginMapMutex()
-{
- static std::recursive_mutex g_plugin_map_mutex;
- return g_plugin_map_mutex;
-}
-
-static PluginTerminateMap &
-GetPluginMap ()
-{
- static PluginTerminateMap g_plugin_map;
- return g_plugin_map;
-}
-
-static bool
-PluginIsLoaded (const FileSpec &plugin_file_spec)
-{
- std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
- PluginTerminateMap &plugin_map = GetPluginMap ();
- return plugin_map.find (plugin_file_spec) != plugin_map.end();
-}
-
-static void
-SetPluginInfo (const FileSpec &plugin_file_spec, const PluginInfo &plugin_info)
-{
- std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
- PluginTerminateMap &plugin_map = GetPluginMap ();
- assert (plugin_map.find (plugin_file_spec) == plugin_map.end());
- plugin_map[plugin_file_spec] = plugin_info;
-}
-
-template <typename FPtrTy>
-static FPtrTy
-CastToFPtr (void *VPtr)
-{
- return reinterpret_cast<FPtrTy>(reinterpret_cast<intptr_t>(VPtr));
-}
-
-static FileSpec::EnumerateDirectoryResult
-LoadPluginCallback(void *baton,
- FileSpec::FileType file_type,
- const FileSpec &file_spec)
-{
-// PluginManager *plugin_manager = (PluginManager *)baton;
- Error error;
-
- // If we have a regular file, a symbolic link or unknown file type, try
- // and process the file. We must handle unknown as sometimes the directory
- // enumeration might be enumerating a file system that doesn't have correct
- // file type information.
- if (file_type == FileSpec::eFileTypeRegular ||
- file_type == FileSpec::eFileTypeSymbolicLink ||
- file_type == FileSpec::eFileTypeUnknown )
- {
- FileSpec plugin_file_spec (file_spec);
- plugin_file_spec.ResolvePath();
-
- if (PluginIsLoaded (plugin_file_spec))
- return FileSpec::eEnumerateDirectoryResultNext;
- else
- {
- PluginInfo plugin_info;
-
- std::string pluginLoadError;
- plugin_info.library = llvm::sys::DynamicLibrary::getPermanentLibrary (plugin_file_spec.GetPath().c_str(), &pluginLoadError);
- if (plugin_info.library.isValid())
- {
- bool success = false;
- plugin_info.plugin_init_callback =
- CastToFPtr<PluginInitCallback>(plugin_info.library.getAddressOfSymbol("LLDBPluginInitialize"));
- if (plugin_info.plugin_init_callback)
- {
- // Call the plug-in "bool LLDBPluginInitialize(void)" function
- success = plugin_info.plugin_init_callback();
- }
-
- if (success)
- {
- // It is ok for the "LLDBPluginTerminate" symbol to be nullptr
- plugin_info.plugin_term_callback =
- CastToFPtr<PluginTermCallback>(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.
- 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.
- SetPluginInfo (plugin_file_spec, plugin_info);
+static std::recursive_mutex &GetPluginMapMutex() {
+ static std::recursive_mutex g_plugin_map_mutex;
+ return g_plugin_map_mutex;
+}
+
+static PluginTerminateMap &GetPluginMap() {
+ static PluginTerminateMap g_plugin_map;
+ return g_plugin_map;
+}
+
+static bool PluginIsLoaded(const FileSpec &plugin_file_spec) {
+ std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
+ PluginTerminateMap &plugin_map = GetPluginMap();
+ return plugin_map.find(plugin_file_spec) != plugin_map.end();
+}
+
+static void SetPluginInfo(const FileSpec &plugin_file_spec,
+ const PluginInfo &plugin_info) {
+ std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
+ PluginTerminateMap &plugin_map = GetPluginMap();
+ assert(plugin_map.find(plugin_file_spec) == plugin_map.end());
+ plugin_map[plugin_file_spec] = plugin_info;
+}
+
+template <typename FPtrTy> static FPtrTy CastToFPtr(void *VPtr) {
+ return reinterpret_cast<FPtrTy>(reinterpret_cast<intptr_t>(VPtr));
+}
+
+static FileSpec::EnumerateDirectoryResult
+LoadPluginCallback(void *baton, FileSpec::FileType file_type,
+ const FileSpec &file_spec) {
+ // PluginManager *plugin_manager = (PluginManager *)baton;
+ Error error;
+
+ // If we have a regular file, a symbolic link or unknown file type, try
+ // and process the file. We must handle unknown as sometimes the directory
+ // enumeration might be enumerating a file system that doesn't have correct
+ // file type information.
+ if (file_type == FileSpec::eFileTypeRegular ||
+ file_type == FileSpec::eFileTypeSymbolicLink ||
+ file_type == FileSpec::eFileTypeUnknown) {
+ FileSpec plugin_file_spec(file_spec);
+ plugin_file_spec.ResolvePath();
+
+ if (PluginIsLoaded(plugin_file_spec))
+ return FileSpec::eEnumerateDirectoryResultNext;
+ else {
+ PluginInfo plugin_info;
+
+ std::string pluginLoadError;
+ plugin_info.library = llvm::sys::DynamicLibrary::getPermanentLibrary(
+ plugin_file_spec.GetPath().c_str(), &pluginLoadError);
+ if (plugin_info.library.isValid()) {
+ bool success = false;
+ plugin_info.plugin_init_callback = CastToFPtr<PluginInitCallback>(
+ plugin_info.library.getAddressOfSymbol("LLDBPluginInitialize"));
+ if (plugin_info.plugin_init_callback) {
+ // Call the plug-in "bool LLDBPluginInitialize(void)" function
+ success = plugin_info.plugin_init_callback();
+ }
+
+ if (success) {
+ // It is ok for the "LLDBPluginTerminate" symbol to be nullptr
+ plugin_info.plugin_term_callback = CastToFPtr<PluginTermCallback>(
+ 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.
+ 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.
+ SetPluginInfo(plugin_file_spec, plugin_info);
+
+ return FileSpec::eEnumerateDirectoryResultNext;
+ }
+ }
+ }
+
+ if (file_type == FileSpec::eFileTypeUnknown ||
+ file_type == FileSpec::eFileTypeDirectory ||
+ file_type == FileSpec::eFileTypeSymbolicLink) {
+ // 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;
+ }
- return FileSpec::eEnumerateDirectoryResultNext;
- }
- }
- }
-
- if (file_type == FileSpec::eFileTypeUnknown ||
- file_type == FileSpec::eFileTypeDirectory ||
- file_type == FileSpec::eFileTypeSymbolicLink )
- {
- // 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;
- }
-
- return FileSpec::eEnumerateDirectoryResultNext;
-}
-
-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 (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
- {
- FileSpec::EnumerateDirectory(dir_path,
- find_directories,
- find_files,
- find_other,
- LoadPluginCallback,
- nullptr);
- }
- }
+ return FileSpec::eEnumerateDirectoryResultNext;
+}
- if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec))
- {
- if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
- {
- FileSpec::EnumerateDirectory(dir_path,
- find_directories,
- find_files,
- find_other,
- LoadPluginCallback,
- nullptr);
- }
+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 (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 (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
+ FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
+ find_other, LoadPluginCallback, nullptr);
}
+ }
#endif
}
-void
-PluginManager::Terminate ()
-{
- std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
- PluginTerminateMap &plugin_map = GetPluginMap ();
-
- 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).
- if (pos->second.library.isValid())
- {
- if (pos->second.plugin_term_callback)
- pos->second.plugin_term_callback();
- }
+void PluginManager::Terminate() {
+ std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
+ PluginTerminateMap &plugin_map = GetPluginMap();
+
+ 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).
+ if (pos->second.library.isValid()) {
+ if (pos->second.plugin_term_callback)
+ pos->second.plugin_term_callback();
}
- plugin_map.clear();
+ }
+ plugin_map.clear();
}
#pragma mark ABI
-struct ABIInstance
-{
- ABIInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
+struct ABIInstance {
+ ABIInstance() : name(), description(), create_callback(nullptr) {}
- ConstString name;
- std::string description;
- ABICreateInstance create_callback;
+ ConstString name;
+ std::string description;
+ ABICreateInstance create_callback;
};
typedef std::vector<ABIInstance> ABIInstances;
-static std::recursive_mutex &
-GetABIInstancesMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static ABIInstances &
-GetABIInstances ()
-{
- static ABIInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- ABICreateInstance create_callback)
-{
- if (create_callback)
- {
- ABIInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
- GetABIInstances ().push_back (instance);
+static std::recursive_mutex &GetABIInstancesMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static ABIInstances &GetABIInstances() {
+ static ABIInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ ABICreateInstance create_callback) {
+ if (create_callback) {
+ ABIInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
+ GetABIInstances().push_back(instance);
+ return true;
+ }
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(ABICreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
+ ABIInstances &instances = GetABIInstances();
+
+ ABIInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
return true;
+ }
}
- return false;
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (ABICreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
- ABIInstances &instances = GetABIInstances ();
-
- ABIInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
- }
- return false;
+ABICreateInstance PluginManager::GetABICreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
+ ABIInstances &instances = GetABIInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
ABICreateInstance
-PluginManager::GetABICreateCallbackAtIndex (uint32_t idx)
-{
+PluginManager::GetABICreateCallbackForPluginName(const ConstString &name) {
+ if (name) {
std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
- ABIInstances &instances = GetABIInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
-}
+ ABIInstances &instances = GetABIInstances();
-ABICreateInstance
-PluginManager::GetABICreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
- ABIInstances &instances = GetABIInstances ();
-
- ABIInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+ ABIInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark Disassembler
-struct DisassemblerInstance
-{
- DisassemblerInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
+struct DisassemblerInstance {
+ DisassemblerInstance() : name(), description(), create_callback(nullptr) {}
- ConstString name;
- std::string description;
- DisassemblerCreateInstance create_callback;
+ ConstString name;
+ std::string description;
+ DisassemblerCreateInstance create_callback;
};
typedef std::vector<DisassemblerInstance> DisassemblerInstances;
-static std::recursive_mutex &
-GetDisassemblerMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static DisassemblerInstances &
-GetDisassemblerInstances ()
-{
- static DisassemblerInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- DisassemblerCreateInstance create_callback)
-{
- if (create_callback)
- {
- DisassemblerInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
- GetDisassemblerInstances ().push_back (instance);
- return true;
- }
- return false;
+static std::recursive_mutex &GetDisassemblerMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
}
-bool
-PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
- DisassemblerInstances &instances = GetDisassemblerInstances ();
-
- DisassemblerInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+static DisassemblerInstances &GetDisassemblerInstances() {
+ static DisassemblerInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ DisassemblerCreateInstance create_callback) {
+ if (create_callback) {
+ DisassemblerInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
+ GetDisassemblerInstances().push_back(instance);
+ return true;
+ }
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(
+ DisassemblerCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
+ DisassemblerInstances &instances = GetDisassemblerInstances();
+
+ DisassemblerInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
DisassemblerCreateInstance
-PluginManager::GetDisassemblerCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
- DisassemblerInstances &instances = GetDisassemblerInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetDisassemblerCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
+ DisassemblerInstances &instances = GetDisassemblerInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
DisassemblerCreateInstance
-PluginManager::GetDisassemblerCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
- DisassemblerInstances &instances = GetDisassemblerInstances ();
-
- DisassemblerInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetDisassemblerCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
+ DisassemblerInstances &instances = GetDisassemblerInstances();
+
+ DisassemblerInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark DynamicLoader
-struct DynamicLoaderInstance
-{
- DynamicLoaderInstance() :
- name(),
- description(),
- create_callback(nullptr),
- debugger_init_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- DynamicLoaderCreateInstance create_callback;
- DebuggerInitializeCallback debugger_init_callback;
+struct DynamicLoaderInstance {
+ DynamicLoaderInstance()
+ : name(), description(), create_callback(nullptr),
+ debugger_init_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ DynamicLoaderCreateInstance create_callback;
+ DebuggerInitializeCallback debugger_init_callback;
};
typedef std::vector<DynamicLoaderInstance> DynamicLoaderInstances;
-static std::recursive_mutex &
-GetDynamicLoaderMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static DynamicLoaderInstances &
-GetDynamicLoaderInstances ()
-{
- static DynamicLoaderInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- DynamicLoaderCreateInstance create_callback,
- DebuggerInitializeCallback debugger_init_callback)
-{
- if (create_callback)
- {
- DynamicLoaderInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.debugger_init_callback = debugger_init_callback;
- std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
- GetDynamicLoaderInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetDynamicLoaderMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static DynamicLoaderInstances &GetDynamicLoaderInstances() {
+ static DynamicLoaderInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ DynamicLoaderCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback) {
+ if (create_callback) {
+ DynamicLoaderInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.debugger_init_callback = debugger_init_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
+ GetDynamicLoaderInstances().push_back(instance);
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
- DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
-
- DynamicLoaderInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+bool PluginManager::UnregisterPlugin(
+ DynamicLoaderCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
+ DynamicLoaderInstances &instances = GetDynamicLoaderInstances();
+
+ DynamicLoaderInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
DynamicLoaderCreateInstance
-PluginManager::GetDynamicLoaderCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
- DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetDynamicLoaderCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
+ DynamicLoaderInstances &instances = GetDynamicLoaderInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
DynamicLoaderCreateInstance
-PluginManager::GetDynamicLoaderCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
- DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
-
- DynamicLoaderInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetDynamicLoaderCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
+ DynamicLoaderInstances &instances = GetDynamicLoaderInstances();
+
+ DynamicLoaderInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark JITLoader
-struct JITLoaderInstance
-{
- JITLoaderInstance() :
- name(),
- description(),
- create_callback(nullptr),
- debugger_init_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- JITLoaderCreateInstance create_callback;
- DebuggerInitializeCallback debugger_init_callback;
+struct JITLoaderInstance {
+ JITLoaderInstance()
+ : name(), description(), create_callback(nullptr),
+ debugger_init_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ JITLoaderCreateInstance create_callback;
+ DebuggerInitializeCallback debugger_init_callback;
};
typedef std::vector<JITLoaderInstance> JITLoaderInstances;
-static std::recursive_mutex &
-GetJITLoaderMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static JITLoaderInstances &
-GetJITLoaderInstances ()
-{
- static JITLoaderInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- JITLoaderCreateInstance create_callback,
- DebuggerInitializeCallback debugger_init_callback)
-{
- if (create_callback)
- {
- JITLoaderInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.debugger_init_callback = debugger_init_callback;
- std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
- GetJITLoaderInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetJITLoaderMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static JITLoaderInstances &GetJITLoaderInstances() {
+ static JITLoaderInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ JITLoaderCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback) {
+ if (create_callback) {
+ JITLoaderInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.debugger_init_callback = debugger_init_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
+ GetJITLoaderInstances().push_back(instance);
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (JITLoaderCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
- JITLoaderInstances &instances = GetJITLoaderInstances ();
-
- JITLoaderInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+bool PluginManager::UnregisterPlugin(JITLoaderCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
+ JITLoaderInstances &instances = GetJITLoaderInstances();
+
+ JITLoaderInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
JITLoaderCreateInstance
-PluginManager::GetJITLoaderCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
- JITLoaderInstances &instances = GetJITLoaderInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetJITLoaderCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
+ JITLoaderInstances &instances = GetJITLoaderInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
-JITLoaderCreateInstance
-PluginManager::GetJITLoaderCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
- JITLoaderInstances &instances = GetJITLoaderInstances ();
-
- JITLoaderInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+JITLoaderCreateInstance PluginManager::GetJITLoaderCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
+ JITLoaderInstances &instances = GetJITLoaderInstances();
+
+ JITLoaderInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark EmulateInstruction
-struct EmulateInstructionInstance
-{
- EmulateInstructionInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- EmulateInstructionCreateInstance create_callback;
+struct EmulateInstructionInstance {
+ EmulateInstructionInstance()
+ : name(), description(), create_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ EmulateInstructionCreateInstance create_callback;
};
typedef std::vector<EmulateInstructionInstance> EmulateInstructionInstances;
-static std::recursive_mutex &
-GetEmulateInstructionMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static EmulateInstructionInstances &
-GetEmulateInstructionInstances ()
-{
- static EmulateInstructionInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- EmulateInstructionCreateInstance create_callback)
-{
- if (create_callback)
- {
- EmulateInstructionInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
- GetEmulateInstructionInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetEmulateInstructionMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
}
-bool
-PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
- EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
-
- EmulateInstructionInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+static EmulateInstructionInstances &GetEmulateInstructionInstances() {
+ static EmulateInstructionInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ EmulateInstructionCreateInstance create_callback) {
+ if (create_callback) {
+ EmulateInstructionInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
+ GetEmulateInstructionInstances().push_back(instance);
+ }
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(
+ EmulateInstructionCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
+ EmulateInstructionInstances &instances = GetEmulateInstructionInstances();
+
+ EmulateInstructionInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
EmulateInstructionCreateInstance
-PluginManager::GetEmulateInstructionCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
- EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetEmulateInstructionCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
+ EmulateInstructionInstances &instances = GetEmulateInstructionInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
EmulateInstructionCreateInstance
-PluginManager::GetEmulateInstructionCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
- EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
-
- EmulateInstructionInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetEmulateInstructionCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
+ EmulateInstructionInstances &instances = GetEmulateInstructionInstances();
+
+ EmulateInstructionInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark OperatingSystem
-struct OperatingSystemInstance
-{
- OperatingSystemInstance () :
- name (),
- description (),
- create_callback (nullptr),
- debugger_init_callback (nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- OperatingSystemCreateInstance create_callback;
- DebuggerInitializeCallback debugger_init_callback;
+struct OperatingSystemInstance {
+ OperatingSystemInstance()
+ : name(), description(), create_callback(nullptr),
+ debugger_init_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ OperatingSystemCreateInstance create_callback;
+ DebuggerInitializeCallback debugger_init_callback;
};
typedef std::vector<OperatingSystemInstance> OperatingSystemInstances;
-static std::recursive_mutex &
-GetOperatingSystemMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static OperatingSystemInstances &
-GetOperatingSystemInstances ()
-{
- static OperatingSystemInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name, const char *description,
- OperatingSystemCreateInstance create_callback,
- DebuggerInitializeCallback debugger_init_callback)
-{
- if (create_callback)
- {
- OperatingSystemInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.debugger_init_callback = debugger_init_callback;
- std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
- GetOperatingSystemInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetOperatingSystemMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static OperatingSystemInstances &GetOperatingSystemInstances() {
+ static OperatingSystemInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ OperatingSystemCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback) {
+ if (create_callback) {
+ OperatingSystemInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.debugger_init_callback = debugger_init_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
+ GetOperatingSystemInstances().push_back(instance);
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (OperatingSystemCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
- OperatingSystemInstances &instances = GetOperatingSystemInstances ();
-
- OperatingSystemInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+bool PluginManager::UnregisterPlugin(
+ OperatingSystemCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
+ OperatingSystemInstances &instances = GetOperatingSystemInstances();
+
+ OperatingSystemInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
OperatingSystemCreateInstance
-PluginManager::GetOperatingSystemCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
- OperatingSystemInstances &instances = GetOperatingSystemInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetOperatingSystemCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
+ OperatingSystemInstances &instances = GetOperatingSystemInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
OperatingSystemCreateInstance
-PluginManager::GetOperatingSystemCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
- OperatingSystemInstances &instances = GetOperatingSystemInstances ();
-
- OperatingSystemInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetOperatingSystemCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
+ OperatingSystemInstances &instances = GetOperatingSystemInstances();
+
+ OperatingSystemInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark Language
-struct LanguageInstance
-{
- LanguageInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- LanguageCreateInstance create_callback;
+struct LanguageInstance {
+ LanguageInstance() : name(), description(), create_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ LanguageCreateInstance create_callback;
};
typedef std::vector<LanguageInstance> LanguageInstances;
-static std::recursive_mutex &
-GetLanguageMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static LanguageInstances &
-GetLanguageInstances ()
-{
- static LanguageInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- LanguageCreateInstance create_callback)
-{
- if (create_callback)
- {
- LanguageInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
- GetLanguageInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetLanguageMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
}
-bool
-PluginManager::UnregisterPlugin (LanguageCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
- LanguageInstances &instances = GetLanguageInstances ();
-
- LanguageInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+static LanguageInstances &GetLanguageInstances() {
+ static LanguageInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ LanguageCreateInstance create_callback) {
+ if (create_callback) {
+ LanguageInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
+ GetLanguageInstances().push_back(instance);
+ }
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(LanguageCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
+ LanguageInstances &instances = GetLanguageInstances();
+
+ LanguageInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
LanguageCreateInstance
-PluginManager::GetLanguageCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
- LanguageInstances &instances = GetLanguageInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetLanguageCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
+ LanguageInstances &instances = GetLanguageInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
LanguageCreateInstance
-PluginManager::GetLanguageCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
- LanguageInstances &instances = GetLanguageInstances ();
-
- LanguageInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetLanguageCreateCallbackForPluginName(const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
+ LanguageInstances &instances = GetLanguageInstances();
+
+ LanguageInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark LanguageRuntime
-struct LanguageRuntimeInstance
-{
- LanguageRuntimeInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
+struct LanguageRuntimeInstance {
+ LanguageRuntimeInstance() : name(), description(), create_callback(nullptr) {}
- ConstString name;
- std::string description;
- LanguageRuntimeCreateInstance create_callback;
- LanguageRuntimeGetCommandObject command_callback;
+ ConstString name;
+ std::string description;
+ LanguageRuntimeCreateInstance create_callback;
+ LanguageRuntimeGetCommandObject command_callback;
};
typedef std::vector<LanguageRuntimeInstance> LanguageRuntimeInstances;
-static std::recursive_mutex &
-GetLanguageRuntimeMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static LanguageRuntimeInstances &
-GetLanguageRuntimeInstances ()
-{
- static LanguageRuntimeInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- LanguageRuntimeCreateInstance create_callback,
- LanguageRuntimeGetCommandObject command_callback)
-{
- if (create_callback)
- {
- LanguageRuntimeInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.command_callback = command_callback;
- std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
- GetLanguageRuntimeInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetLanguageRuntimeMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static LanguageRuntimeInstances &GetLanguageRuntimeInstances() {
+ static LanguageRuntimeInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ LanguageRuntimeCreateInstance create_callback,
+ LanguageRuntimeGetCommandObject command_callback) {
+ if (create_callback) {
+ LanguageRuntimeInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.command_callback = command_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
+ GetLanguageRuntimeInstances().push_back(instance);
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
- LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
-
- LanguageRuntimeInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+bool PluginManager::UnregisterPlugin(
+ LanguageRuntimeCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
+ LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances();
+
+ LanguageRuntimeInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
LanguageRuntimeCreateInstance
-PluginManager::GetLanguageRuntimeCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
- LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
+ LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
LanguageRuntimeGetCommandObject
-PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
- LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
- if (idx < instances.size())
- return instances[idx].command_callback;
- return nullptr;
+PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
+ LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances();
+ if (idx < instances.size())
+ return instances[idx].command_callback;
+ return nullptr;
}
LanguageRuntimeCreateInstance
-PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
- LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
-
- LanguageRuntimeInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetLanguageRuntimeCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
+ LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances();
+
+ LanguageRuntimeInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark SystemRuntime
-struct SystemRuntimeInstance
-{
- SystemRuntimeInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
+struct SystemRuntimeInstance {
+ SystemRuntimeInstance() : name(), description(), create_callback(nullptr) {}
- ConstString name;
- std::string description;
- SystemRuntimeCreateInstance create_callback;
+ ConstString name;
+ std::string description;
+ SystemRuntimeCreateInstance create_callback;
};
typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances;
-static std::recursive_mutex &
-GetSystemRuntimeMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static SystemRuntimeInstances &
-GetSystemRuntimeInstances ()
-{
- static SystemRuntimeInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- SystemRuntimeCreateInstance create_callback)
-{
- if (create_callback)
- {
- SystemRuntimeInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
- GetSystemRuntimeInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetSystemRuntimeMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
}
-bool
-PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
- SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
-
- SystemRuntimeInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+static SystemRuntimeInstances &GetSystemRuntimeInstances() {
+ static SystemRuntimeInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ SystemRuntimeCreateInstance create_callback) {
+ if (create_callback) {
+ SystemRuntimeInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
+ GetSystemRuntimeInstances().push_back(instance);
+ }
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(
+ SystemRuntimeCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
+ SystemRuntimeInstances &instances = GetSystemRuntimeInstances();
+
+ SystemRuntimeInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
SystemRuntimeCreateInstance
-PluginManager::GetSystemRuntimeCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
- SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
+ SystemRuntimeInstances &instances = GetSystemRuntimeInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
SystemRuntimeCreateInstance
-PluginManager::GetSystemRuntimeCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
- SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
-
- SystemRuntimeInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetSystemRuntimeCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
+ SystemRuntimeInstances &instances = GetSystemRuntimeInstances();
+
+ SystemRuntimeInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark ObjectFile
-struct ObjectFileInstance
-{
- ObjectFileInstance() :
- name(),
- description(),
- create_callback(nullptr),
- create_memory_callback(nullptr),
- get_module_specifications(nullptr),
- save_core(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- ObjectFileCreateInstance create_callback;
- ObjectFileCreateMemoryInstance create_memory_callback;
- ObjectFileGetModuleSpecifications get_module_specifications;
- ObjectFileSaveCore save_core;
+struct ObjectFileInstance {
+ ObjectFileInstance()
+ : name(), description(), create_callback(nullptr),
+ create_memory_callback(nullptr), get_module_specifications(nullptr),
+ save_core(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ ObjectFileCreateInstance create_callback;
+ ObjectFileCreateMemoryInstance create_memory_callback;
+ ObjectFileGetModuleSpecifications get_module_specifications;
+ ObjectFileSaveCore save_core;
};
typedef std::vector<ObjectFileInstance> ObjectFileInstances;
-static std::recursive_mutex &
-GetObjectFileMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static ObjectFileInstances &
-GetObjectFileInstances ()
-{
- static ObjectFileInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin (const ConstString &name,
- const char *description,
- ObjectFileCreateInstance create_callback,
- ObjectFileCreateMemoryInstance create_memory_callback,
- ObjectFileGetModuleSpecifications get_module_specifications,
- ObjectFileSaveCore save_core)
-{
- if (create_callback)
- {
- ObjectFileInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.create_memory_callback = create_memory_callback;
- instance.save_core = save_core;
- instance.get_module_specifications = get_module_specifications;
- std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
- GetObjectFileInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetObjectFileMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static ObjectFileInstances &GetObjectFileInstances() {
+ static ObjectFileInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ ObjectFileCreateInstance create_callback,
+ ObjectFileCreateMemoryInstance create_memory_callback,
+ ObjectFileGetModuleSpecifications get_module_specifications,
+ ObjectFileSaveCore save_core) {
+ if (create_callback) {
+ ObjectFileInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.create_memory_callback = create_memory_callback;
+ instance.save_core = save_core;
+ instance.get_module_specifications = get_module_specifications;
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
+ GetObjectFileInstances().push_back(instance);
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
- ObjectFileInstances &instances = GetObjectFileInstances ();
-
- ObjectFileInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+bool PluginManager::UnregisterPlugin(ObjectFileCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
+ ObjectFileInstances &instances = GetObjectFileInstances();
+
+ ObjectFileInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
ObjectFileCreateInstance
-PluginManager::GetObjectFileCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
- ObjectFileInstances &instances = GetObjectFileInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetObjectFileCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
+ ObjectFileInstances &instances = GetObjectFileInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
ObjectFileCreateMemoryInstance
-PluginManager::GetObjectFileCreateMemoryCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
- ObjectFileInstances &instances = GetObjectFileInstances ();
- if (idx < instances.size())
- return instances[idx].create_memory_callback;
- return nullptr;
+PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
+ ObjectFileInstances &instances = GetObjectFileInstances();
+ if (idx < instances.size())
+ return instances[idx].create_memory_callback;
+ return nullptr;
}
ObjectFileGetModuleSpecifications
-PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
- ObjectFileInstances &instances = GetObjectFileInstances ();
- if (idx < instances.size())
- return instances[idx].get_module_specifications;
- return nullptr;
+PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(
+ uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
+ ObjectFileInstances &instances = GetObjectFileInstances();
+ if (idx < instances.size())
+ return instances[idx].get_module_specifications;
+ return nullptr;
}
ObjectFileCreateInstance
-PluginManager::GetObjectFileCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
- ObjectFileInstances &instances = GetObjectFileInstances ();
-
- ObjectFileInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
- }
- return nullptr;
-}
+PluginManager::GetObjectFileCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
+ ObjectFileInstances &instances = GetObjectFileInstances();
-ObjectFileCreateMemoryInstance
-PluginManager::GetObjectFileCreateMemoryCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
- ObjectFileInstances &instances = GetObjectFileInstances ();
-
- ObjectFileInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_memory_callback;
- }
+ ObjectFileInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
-Error
-PluginManager::SaveCore (const lldb::ProcessSP &process_sp, const FileSpec &outfile)
-{
- Error error;
+ObjectFileCreateMemoryInstance
+PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
- ObjectFileInstances &instances = GetObjectFileInstances ();
-
+ ObjectFileInstances &instances = GetObjectFileInstances();
+
ObjectFileInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->save_core && pos->save_core (process_sp, outfile, error))
- return error;
- }
- error.SetErrorString("no ObjectFile plugins were able to save a core for this process");
- return error;
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_memory_callback;
+ }
+ }
+ return nullptr;
+}
+
+Error PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
+ const FileSpec &outfile) {
+ Error error;
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
+ ObjectFileInstances &instances = GetObjectFileInstances();
+
+ ObjectFileInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->save_core && pos->save_core(process_sp, outfile, error))
+ return error;
+ }
+ error.SetErrorString(
+ "no ObjectFile plugins were able to save a core for this process");
+ return error;
}
#pragma mark ObjectContainer
-struct ObjectContainerInstance
-{
- ObjectContainerInstance() :
- name(),
- description(),
- create_callback(nullptr),
- get_module_specifications(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- ObjectContainerCreateInstance create_callback;
- ObjectFileGetModuleSpecifications get_module_specifications;
+struct ObjectContainerInstance {
+ ObjectContainerInstance()
+ : name(), description(), create_callback(nullptr),
+ get_module_specifications(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ ObjectContainerCreateInstance create_callback;
+ ObjectFileGetModuleSpecifications get_module_specifications;
};
typedef std::vector<ObjectContainerInstance> ObjectContainerInstances;
-static std::recursive_mutex &
-GetObjectContainerMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static ObjectContainerInstances &
-GetObjectContainerInstances ()
-{
- static ObjectContainerInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin (const ConstString &name,
- const char *description,
- ObjectContainerCreateInstance create_callback,
- ObjectFileGetModuleSpecifications get_module_specifications)
-{
- if (create_callback)
- {
- ObjectContainerInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.get_module_specifications = get_module_specifications;
- std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
- GetObjectContainerInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetObjectContainerMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static ObjectContainerInstances &GetObjectContainerInstances() {
+ static ObjectContainerInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ ObjectContainerCreateInstance create_callback,
+ ObjectFileGetModuleSpecifications get_module_specifications) {
+ if (create_callback) {
+ ObjectContainerInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.get_module_specifications = get_module_specifications;
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
+ GetObjectContainerInstances().push_back(instance);
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
- ObjectContainerInstances &instances = GetObjectContainerInstances ();
-
- ObjectContainerInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+bool PluginManager::UnregisterPlugin(
+ ObjectContainerCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
+ ObjectContainerInstances &instances = GetObjectContainerInstances();
+
+ ObjectContainerInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
ObjectContainerCreateInstance
-PluginManager::GetObjectContainerCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
- ObjectContainerInstances &instances = GetObjectContainerInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetObjectContainerCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
+ ObjectContainerInstances &instances = GetObjectContainerInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
ObjectContainerCreateInstance
-PluginManager::GetObjectContainerCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
- ObjectContainerInstances &instances = GetObjectContainerInstances ();
-
- ObjectContainerInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetObjectContainerCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
+ ObjectContainerInstances &instances = GetObjectContainerInstances();
+
+ ObjectContainerInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
ObjectFileGetModuleSpecifications
-PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
- ObjectContainerInstances &instances = GetObjectContainerInstances ();
- if (idx < instances.size())
- return instances[idx].get_module_specifications;
- return nullptr;
+PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex(
+ uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
+ ObjectContainerInstances &instances = GetObjectContainerInstances();
+ if (idx < instances.size())
+ return instances[idx].get_module_specifications;
+ return nullptr;
}
#pragma mark LogChannel
-struct LogInstance
-{
- LogInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
+struct LogInstance {
+ LogInstance() : name(), description(), create_callback(nullptr) {}
- ConstString name;
- std::string description;
- LogChannelCreateInstance create_callback;
+ ConstString name;
+ std::string description;
+ LogChannelCreateInstance create_callback;
};
typedef std::vector<LogInstance> LogInstances;
-static std::recursive_mutex &
-GetLogMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static LogInstances &
-GetLogInstances ()
-{
- static LogInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- LogChannelCreateInstance create_callback)
-{
- if (create_callback)
- {
- LogInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
- GetLogInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetLogMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
}
-bool
-PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
- LogInstances &instances = GetLogInstances ();
-
- LogInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
- }
- return false;
+static LogInstances &GetLogInstances() {
+ static LogInstances g_instances;
+ return g_instances;
}
-const char *
-PluginManager::GetLogChannelCreateNameAtIndex (uint32_t idx)
-{
+bool PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ LogChannelCreateInstance create_callback) {
+ if (create_callback) {
+ LogInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
- LogInstances &instances = GetLogInstances ();
- if (idx < instances.size())
- return instances[idx].name.GetCString();
- return nullptr;
+ GetLogInstances().push_back(instance);
+ }
+ return false;
}
-LogChannelCreateInstance
-PluginManager::GetLogChannelCreateCallbackAtIndex (uint32_t idx)
-{
+bool PluginManager::UnregisterPlugin(LogChannelCreateInstance create_callback) {
+ if (create_callback) {
std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
- LogInstances &instances = GetLogInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
-}
+ LogInstances &instances = GetLogInstances();
-LogChannelCreateInstance
-PluginManager::GetLogChannelCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
- LogInstances &instances = GetLogInstances ();
-
- LogInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+ LogInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return nullptr;
+ }
+ return false;
+}
+
+const char *PluginManager::GetLogChannelCreateNameAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
+ LogInstances &instances = GetLogInstances();
+ if (idx < instances.size())
+ return instances[idx].name.GetCString();
+ return nullptr;
+}
+
+LogChannelCreateInstance
+PluginManager::GetLogChannelCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
+ LogInstances &instances = GetLogInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
+}
+
+LogChannelCreateInstance
+PluginManager::GetLogChannelCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
+ LogInstances &instances = GetLogInstances();
+
+ LogInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
+ }
+ }
+ return nullptr;
}
#pragma mark Platform
-struct PlatformInstance
-{
- PlatformInstance() :
- name(),
- description(),
- create_callback(nullptr),
- debugger_init_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- PlatformCreateInstance create_callback;
- DebuggerInitializeCallback debugger_init_callback;
+struct PlatformInstance {
+ PlatformInstance()
+ : name(), description(), create_callback(nullptr),
+ debugger_init_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ PlatformCreateInstance create_callback;
+ DebuggerInitializeCallback debugger_init_callback;
};
typedef std::vector<PlatformInstance> PlatformInstances;
-static std::recursive_mutex &
-GetPlatformInstancesMutex()
-{
- static std::recursive_mutex g_platform_instances_mutex;
- return g_platform_instances_mutex;
-}
-
-static PlatformInstances &
-GetPlatformInstances ()
-{
- static PlatformInstances g_platform_instances;
- return g_platform_instances;
-}
-
-bool
-PluginManager::RegisterPlugin (const ConstString &name,
- const char *description,
- PlatformCreateInstance create_callback,
- DebuggerInitializeCallback debugger_init_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
-
- PlatformInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.debugger_init_callback = debugger_init_callback;
- GetPlatformInstances ().push_back (instance);
- return true;
- }
- return false;
+static std::recursive_mutex &GetPlatformInstancesMutex() {
+ static std::recursive_mutex g_platform_instances_mutex;
+ return g_platform_instances_mutex;
+}
+
+static PlatformInstances &GetPlatformInstances() {
+ static PlatformInstances g_platform_instances;
+ return g_platform_instances;
}
-const char *
-PluginManager::GetPlatformPluginNameAtIndex (uint32_t idx)
-{
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ PlatformCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback) {
+ if (create_callback) {
std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
- PlatformInstances &instances = GetPlatformInstances ();
- if (idx < instances.size())
- return instances[idx].name.GetCString();
- return nullptr;
+
+ PlatformInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.debugger_init_callback = debugger_init_callback;
+ GetPlatformInstances().push_back(instance);
+ return true;
+ }
+ return false;
+}
+
+const char *PluginManager::GetPlatformPluginNameAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
+ PlatformInstances &instances = GetPlatformInstances();
+ if (idx < instances.size())
+ return instances[idx].name.GetCString();
+ return nullptr;
+}
+
+const char *PluginManager::GetPlatformPluginDescriptionAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
+ PlatformInstances &instances = GetPlatformInstances();
+ if (idx < instances.size())
+ return instances[idx].description.c_str();
+ return nullptr;
}
-const char *
-PluginManager::GetPlatformPluginDescriptionAtIndex (uint32_t idx)
-{
+bool PluginManager::UnregisterPlugin(PlatformCreateInstance create_callback) {
+ if (create_callback) {
std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
- PlatformInstances &instances = GetPlatformInstances ();
- if (idx < instances.size())
- return instances[idx].description.c_str();
- return nullptr;
-}
-
-bool
-PluginManager::UnregisterPlugin (PlatformCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
- PlatformInstances &instances = GetPlatformInstances ();
-
- PlatformInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+ PlatformInstances &instances = GetPlatformInstances();
+
+ PlatformInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
PlatformCreateInstance
-PluginManager::GetPlatformCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
- PlatformInstances &instances = GetPlatformInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetPlatformCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
+ PlatformInstances &instances = GetPlatformInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
PlatformCreateInstance
-PluginManager::GetPlatformCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
- PlatformInstances &instances = GetPlatformInstances ();
-
- PlatformInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetPlatformCreateCallbackForPluginName(const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
+ PlatformInstances &instances = GetPlatformInstances();
+
+ PlatformInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
-size_t
-PluginManager::AutoCompletePlatformName (const char *name, StringList &matches)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
- PlatformInstances &instances = GetPlatformInstances ();
- llvm::StringRef name_sref(name);
-
- PlatformInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- llvm::StringRef plugin_name (pos->name.GetCString());
- if (plugin_name.startswith(name_sref))
- matches.AppendString (plugin_name.data());
- }
+size_t PluginManager::AutoCompletePlatformName(const char *name,
+ StringList &matches) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
+ PlatformInstances &instances = GetPlatformInstances();
+ llvm::StringRef name_sref(name);
+
+ PlatformInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ llvm::StringRef plugin_name(pos->name.GetCString());
+ if (plugin_name.startswith(name_sref))
+ matches.AppendString(plugin_name.data());
}
- return matches.GetSize();
+ }
+ return matches.GetSize();
}
#pragma mark Process
-struct ProcessInstance
-{
- ProcessInstance() :
- name(),
- description(),
- create_callback(nullptr),
- debugger_init_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- ProcessCreateInstance create_callback;
- DebuggerInitializeCallback debugger_init_callback;
+struct ProcessInstance {
+ ProcessInstance()
+ : name(), description(), create_callback(nullptr),
+ debugger_init_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ ProcessCreateInstance create_callback;
+ DebuggerInitializeCallback debugger_init_callback;
};
typedef std::vector<ProcessInstance> ProcessInstances;
-static std::recursive_mutex &
-GetProcessMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static ProcessInstances &
-GetProcessInstances ()
-{
- static ProcessInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin (const ConstString &name,
- const char *description,
- ProcessCreateInstance create_callback,
- DebuggerInitializeCallback debugger_init_callback)
-{
- if (create_callback)
- {
- ProcessInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.debugger_init_callback = debugger_init_callback;
- std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
- GetProcessInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetProcessMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static ProcessInstances &GetProcessInstances() {
+ static ProcessInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ ProcessCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback) {
+ if (create_callback) {
+ ProcessInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.debugger_init_callback = debugger_init_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
+ GetProcessInstances().push_back(instance);
+ }
+ return false;
}
-const char *
-PluginManager::GetProcessPluginNameAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
- ProcessInstances &instances = GetProcessInstances ();
- if (idx < instances.size())
- return instances[idx].name.GetCString();
- return nullptr;
+const char *PluginManager::GetProcessPluginNameAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
+ ProcessInstances &instances = GetProcessInstances();
+ if (idx < instances.size())
+ return instances[idx].name.GetCString();
+ return nullptr;
+}
+
+const char *PluginManager::GetProcessPluginDescriptionAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
+ ProcessInstances &instances = GetProcessInstances();
+ if (idx < instances.size())
+ return instances[idx].description.c_str();
+ return nullptr;
}
-const char *
-PluginManager::GetProcessPluginDescriptionAtIndex (uint32_t idx)
-{
+bool PluginManager::UnregisterPlugin(ProcessCreateInstance create_callback) {
+ if (create_callback) {
std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
- ProcessInstances &instances = GetProcessInstances ();
- if (idx < instances.size())
- return instances[idx].description.c_str();
- return nullptr;
-}
-
-bool
-PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
- ProcessInstances &instances = GetProcessInstances ();
-
- ProcessInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+ ProcessInstances &instances = GetProcessInstances();
+
+ ProcessInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
ProcessCreateInstance
-PluginManager::GetProcessCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
- ProcessInstances &instances = GetProcessInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetProcessCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
+ ProcessInstances &instances = GetProcessInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
ProcessCreateInstance
-PluginManager::GetProcessCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
- ProcessInstances &instances = GetProcessInstances ();
-
- ProcessInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetProcessCreateCallbackForPluginName(const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
+ ProcessInstances &instances = GetProcessInstances();
+
+ ProcessInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark ScriptInterpreter
-struct ScriptInterpreterInstance
-{
- ScriptInterpreterInstance()
- : name()
- , language(lldb::eScriptLanguageNone)
- , description()
- , create_callback(nullptr)
- {
- }
-
- ConstString name;
- lldb::ScriptLanguage language;
- std::string description;
- ScriptInterpreterCreateInstance create_callback;
+struct ScriptInterpreterInstance {
+ ScriptInterpreterInstance()
+ : name(), language(lldb::eScriptLanguageNone), description(),
+ create_callback(nullptr) {}
+
+ ConstString name;
+ lldb::ScriptLanguage language;
+ std::string description;
+ ScriptInterpreterCreateInstance create_callback;
};
typedef std::vector<ScriptInterpreterInstance> ScriptInterpreterInstances;
-static std::recursive_mutex &
-GetScriptInterpreterMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static ScriptInterpreterInstances &
-GetScriptInterpreterInstances()
-{
- static ScriptInterpreterInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name, const char *description, lldb::ScriptLanguage script_language,
- ScriptInterpreterCreateInstance create_callback)
-{
- if (!create_callback)
- return false;
- ScriptInterpreterInstance instance;
- assert((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.language = script_language;
- std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
- GetScriptInterpreterInstances().push_back(instance);
- return false;
-}
-
-bool
-PluginManager::UnregisterPlugin(ScriptInterpreterCreateInstance create_callback)
-{
- if (!create_callback)
- return false;
- std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
- ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
-
- ScriptInterpreterInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++pos)
- {
- if (pos->create_callback != create_callback)
- continue;
-
- instances.erase(pos);
- return true;
- }
- return false;
+static std::recursive_mutex &GetScriptInterpreterMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static ScriptInterpreterInstances &GetScriptInterpreterInstances() {
+ static ScriptInterpreterInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ lldb::ScriptLanguage script_language,
+ ScriptInterpreterCreateInstance create_callback) {
+ if (!create_callback)
+ return false;
+ ScriptInterpreterInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.language = script_language;
+ std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
+ GetScriptInterpreterInstances().push_back(instance);
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(
+ ScriptInterpreterCreateInstance create_callback) {
+ if (!create_callback)
+ return false;
+ std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
+ ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
+
+ ScriptInterpreterInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback != create_callback)
+ continue;
+
+ instances.erase(pos);
+ return true;
+ }
+ return false;
}
ScriptInterpreterCreateInstance
-PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
- ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
-}
-
-lldb::ScriptInterpreterSP
-PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter)
-{
- std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
- ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
-
- ScriptInterpreterInstances::iterator pos, end = instances.end();
- ScriptInterpreterCreateInstance none_instance = nullptr;
- for (pos = instances.begin(); pos != end; ++pos)
- {
- if (pos->language == lldb::eScriptLanguageNone)
- none_instance = pos->create_callback;
-
- if (script_lang == pos->language)
- return pos->create_callback(interpreter);
- }
-
- // If we didn't find one, return the ScriptInterpreter for the null language.
- assert(none_instance != nullptr);
- return none_instance(interpreter);
+PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
+ ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
+}
+
+lldb::ScriptInterpreterSP PluginManager::GetScriptInterpreterForLanguage(
+ lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter) {
+ std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
+ ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
+
+ ScriptInterpreterInstances::iterator pos, end = instances.end();
+ ScriptInterpreterCreateInstance none_instance = nullptr;
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->language == lldb::eScriptLanguageNone)
+ none_instance = pos->create_callback;
+
+ if (script_lang == pos->language)
+ return pos->create_callback(interpreter);
+ }
+
+ // If we didn't find one, return the ScriptInterpreter for the null language.
+ assert(none_instance != nullptr);
+ return none_instance(interpreter);
}
#pragma mark -
@@ -1924,1301 +1568,1070 @@ PluginManager::GetScriptInterpreterForLa
// StructuredDataPlugin
// -----------------------------------------------------------------------------
-struct StructuredDataPluginInstance
-{
- StructuredDataPluginInstance() :
- name(),
- description(),
- create_callback(nullptr),
- debugger_init_callback(nullptr),
- filter_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- StructuredDataPluginCreateInstance create_callback;
- DebuggerInitializeCallback debugger_init_callback;
- StructuredDataFilterLaunchInfo filter_callback;
+struct StructuredDataPluginInstance {
+ StructuredDataPluginInstance()
+ : name(), description(), create_callback(nullptr),
+ debugger_init_callback(nullptr), filter_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ StructuredDataPluginCreateInstance create_callback;
+ DebuggerInitializeCallback debugger_init_callback;
+ StructuredDataFilterLaunchInfo filter_callback;
};
typedef std::vector<StructuredDataPluginInstance> StructuredDataPluginInstances;
-static std::recursive_mutex &
-GetStructuredDataPluginMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static StructuredDataPluginInstances &
-GetStructuredDataPluginInstances ()
-{
- static StructuredDataPluginInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- StructuredDataPluginCreateInstance
- create_callback,
- DebuggerInitializeCallback debugger_init_callback,
- StructuredDataFilterLaunchInfo filter_callback)
-{
- if (create_callback)
- {
- StructuredDataPluginInstance instance;
- assert((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.debugger_init_callback = debugger_init_callback;
- instance.filter_callback = filter_callback;
- std::lock_guard<std::recursive_mutex> guard(
- GetStructuredDataPluginMutex());
- GetStructuredDataPluginInstances().push_back(instance);
- }
- return false;
-}
-
-bool
-PluginManager::UnregisterPlugin(StructuredDataPluginCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(
- GetStructuredDataPluginMutex());
- StructuredDataPluginInstances &instances =
- GetStructuredDataPluginInstances();
-
- StructuredDataPluginInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
- }
- return false;
+static std::recursive_mutex &GetStructuredDataPluginMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static StructuredDataPluginInstances &GetStructuredDataPluginInstances() {
+ static StructuredDataPluginInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ StructuredDataPluginCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback,
+ StructuredDataFilterLaunchInfo filter_callback) {
+ if (create_callback) {
+ StructuredDataPluginInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.debugger_init_callback = debugger_init_callback;
+ instance.filter_callback = filter_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
+ GetStructuredDataPluginInstances().push_back(instance);
+ }
+ return false;
}
-StructuredDataPluginCreateInstance
-PluginManager::GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx)
-{
+bool PluginManager::UnregisterPlugin(
+ StructuredDataPluginCreateInstance create_callback) {
+ if (create_callback) {
std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
StructuredDataPluginInstances &instances =
GetStructuredDataPluginInstances();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+
+ StructuredDataPluginInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
+ }
+ }
+ return false;
}
StructuredDataPluginCreateInstance
-PluginManager::GetStructuredDataPluginCreateCallbackForPluginName(
- const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(
- GetStructuredDataPluginMutex());
- StructuredDataPluginInstances &instances =
- GetStructuredDataPluginInstances();
-
- StructuredDataPluginInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
- }
- return nullptr;
+PluginManager::GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
+ StructuredDataPluginInstances &instances = GetStructuredDataPluginInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
-StructuredDataFilterLaunchInfo
-PluginManager::GetStructuredDataFilterCallbackAtIndex(uint32_t idx,
- bool &iteration_complete)
-{
+StructuredDataPluginCreateInstance
+PluginManager::GetStructuredDataPluginCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
StructuredDataPluginInstances &instances =
GetStructuredDataPluginInstances();
- if (idx < instances.size())
- {
- iteration_complete = false;
- return instances[idx].filter_callback;
- }
- else
- {
- iteration_complete = true;
+
+ StructuredDataPluginInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
-#pragma mark SymbolFile
+StructuredDataFilterLaunchInfo
+PluginManager::GetStructuredDataFilterCallbackAtIndex(
+ uint32_t idx, bool &iteration_complete) {
+ std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
+ StructuredDataPluginInstances &instances = GetStructuredDataPluginInstances();
+ if (idx < instances.size()) {
+ iteration_complete = false;
+ return instances[idx].filter_callback;
+ } else {
+ iteration_complete = true;
+ }
+ return nullptr;
+}
-struct SymbolFileInstance
-{
- SymbolFileInstance() :
- name(),
- description(),
- create_callback(nullptr),
- debugger_init_callback(nullptr)
- {
- }
+#pragma mark SymbolFile
- ConstString name;
- std::string description;
- SymbolFileCreateInstance create_callback;
- DebuggerInitializeCallback debugger_init_callback;
+struct SymbolFileInstance {
+ SymbolFileInstance()
+ : name(), description(), create_callback(nullptr),
+ debugger_init_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ SymbolFileCreateInstance create_callback;
+ DebuggerInitializeCallback debugger_init_callback;
};
typedef std::vector<SymbolFileInstance> SymbolFileInstances;
-static std::recursive_mutex &
-GetSymbolFileMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static SymbolFileInstances &
-GetSymbolFileInstances ()
-{
- static SymbolFileInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- SymbolFileCreateInstance create_callback,
- DebuggerInitializeCallback debugger_init_callback)
-{
- if (create_callback)
- {
- SymbolFileInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.debugger_init_callback = debugger_init_callback;
- std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
- GetSymbolFileInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetSymbolFileMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static SymbolFileInstances &GetSymbolFileInstances() {
+ static SymbolFileInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ SymbolFileCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback) {
+ if (create_callback) {
+ SymbolFileInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.debugger_init_callback = debugger_init_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
+ GetSymbolFileInstances().push_back(instance);
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
- SymbolFileInstances &instances = GetSymbolFileInstances ();
-
- SymbolFileInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+bool PluginManager::UnregisterPlugin(SymbolFileCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
+ SymbolFileInstances &instances = GetSymbolFileInstances();
+
+ SymbolFileInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
SymbolFileCreateInstance
-PluginManager::GetSymbolFileCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
- SymbolFileInstances &instances = GetSymbolFileInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetSymbolFileCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
+ SymbolFileInstances &instances = GetSymbolFileInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
SymbolFileCreateInstance
-PluginManager::GetSymbolFileCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
- SymbolFileInstances &instances = GetSymbolFileInstances ();
-
- SymbolFileInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetSymbolFileCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
+ SymbolFileInstances &instances = GetSymbolFileInstances();
+
+ SymbolFileInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark SymbolVendor
-struct SymbolVendorInstance
-{
- SymbolVendorInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
+struct SymbolVendorInstance {
+ SymbolVendorInstance() : name(), description(), create_callback(nullptr) {}
- ConstString name;
- std::string description;
- SymbolVendorCreateInstance create_callback;
+ ConstString name;
+ std::string description;
+ SymbolVendorCreateInstance create_callback;
};
typedef std::vector<SymbolVendorInstance> SymbolVendorInstances;
-static std::recursive_mutex &
-GetSymbolVendorMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static SymbolVendorInstances &
-GetSymbolVendorInstances ()
-{
- static SymbolVendorInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- SymbolVendorCreateInstance create_callback)
-{
- if (create_callback)
- {
- SymbolVendorInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
- GetSymbolVendorInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetSymbolVendorMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
}
-bool
-PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
- SymbolVendorInstances &instances = GetSymbolVendorInstances ();
-
- SymbolVendorInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+static SymbolVendorInstances &GetSymbolVendorInstances() {
+ static SymbolVendorInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ SymbolVendorCreateInstance create_callback) {
+ if (create_callback) {
+ SymbolVendorInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
+ GetSymbolVendorInstances().push_back(instance);
+ }
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(
+ SymbolVendorCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
+ SymbolVendorInstances &instances = GetSymbolVendorInstances();
+
+ SymbolVendorInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
SymbolVendorCreateInstance
-PluginManager::GetSymbolVendorCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
- SymbolVendorInstances &instances = GetSymbolVendorInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetSymbolVendorCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
+ SymbolVendorInstances &instances = GetSymbolVendorInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
SymbolVendorCreateInstance
-PluginManager::GetSymbolVendorCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
- SymbolVendorInstances &instances = GetSymbolVendorInstances ();
-
- SymbolVendorInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetSymbolVendorCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
+ SymbolVendorInstances &instances = GetSymbolVendorInstances();
+
+ SymbolVendorInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark UnwindAssembly
-struct UnwindAssemblyInstance
-{
- UnwindAssemblyInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
+struct UnwindAssemblyInstance {
+ UnwindAssemblyInstance() : name(), description(), create_callback(nullptr) {}
- ConstString name;
- std::string description;
- UnwindAssemblyCreateInstance create_callback;
+ ConstString name;
+ std::string description;
+ UnwindAssemblyCreateInstance create_callback;
};
typedef std::vector<UnwindAssemblyInstance> UnwindAssemblyInstances;
-static std::recursive_mutex &
-GetUnwindAssemblyMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static UnwindAssemblyInstances &
-GetUnwindAssemblyInstances ()
-{
- static UnwindAssemblyInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- UnwindAssemblyCreateInstance create_callback)
-{
- if (create_callback)
- {
- UnwindAssemblyInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
- GetUnwindAssemblyInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetUnwindAssemblyMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
}
-bool
-PluginManager::UnregisterPlugin (UnwindAssemblyCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
- UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
-
- UnwindAssemblyInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+static UnwindAssemblyInstances &GetUnwindAssemblyInstances() {
+ static UnwindAssemblyInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ UnwindAssemblyCreateInstance create_callback) {
+ if (create_callback) {
+ UnwindAssemblyInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
+ GetUnwindAssemblyInstances().push_back(instance);
+ }
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(
+ UnwindAssemblyCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
+ UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances();
+
+ UnwindAssemblyInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
UnwindAssemblyCreateInstance
-PluginManager::GetUnwindAssemblyCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
- UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetUnwindAssemblyCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
+ UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
UnwindAssemblyCreateInstance
-PluginManager::GetUnwindAssemblyCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
- UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
-
- UnwindAssemblyInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetUnwindAssemblyCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
+ UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances();
+
+ UnwindAssemblyInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark MemoryHistory
-struct MemoryHistoryInstance
-{
- MemoryHistoryInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- MemoryHistoryCreateInstance create_callback;
+struct MemoryHistoryInstance {
+ MemoryHistoryInstance() : name(), description(), create_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ MemoryHistoryCreateInstance create_callback;
};
typedef std::vector<MemoryHistoryInstance> MemoryHistoryInstances;
-static std::recursive_mutex &
-GetMemoryHistoryMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static MemoryHistoryInstances &
-GetMemoryHistoryInstances ()
-{
- static MemoryHistoryInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- MemoryHistoryCreateInstance create_callback)
-{
- if (create_callback)
- {
- MemoryHistoryInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
- GetMemoryHistoryInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetMemoryHistoryMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
}
-bool
-PluginManager::UnregisterPlugin (MemoryHistoryCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
- MemoryHistoryInstances &instances = GetMemoryHistoryInstances ();
-
- MemoryHistoryInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+static MemoryHistoryInstances &GetMemoryHistoryInstances() {
+ static MemoryHistoryInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ MemoryHistoryCreateInstance create_callback) {
+ if (create_callback) {
+ MemoryHistoryInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
+ GetMemoryHistoryInstances().push_back(instance);
+ }
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(
+ MemoryHistoryCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
+ MemoryHistoryInstances &instances = GetMemoryHistoryInstances();
+
+ MemoryHistoryInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
MemoryHistoryCreateInstance
-PluginManager::GetMemoryHistoryCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
- MemoryHistoryInstances &instances = GetMemoryHistoryInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetMemoryHistoryCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
+ MemoryHistoryInstances &instances = GetMemoryHistoryInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
MemoryHistoryCreateInstance
-PluginManager::GetMemoryHistoryCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
- MemoryHistoryInstances &instances = GetMemoryHistoryInstances ();
-
- MemoryHistoryInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetMemoryHistoryCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
+ MemoryHistoryInstances &instances = GetMemoryHistoryInstances();
+
+ MemoryHistoryInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark InstrumentationRuntime
-struct InstrumentationRuntimeInstance
-{
- InstrumentationRuntimeInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- InstrumentationRuntimeCreateInstance create_callback;
- InstrumentationRuntimeGetType get_type_callback;
-};
-
-typedef std::vector<InstrumentationRuntimeInstance> InstrumentationRuntimeInstances;
-
-static std::recursive_mutex &
-GetInstrumentationRuntimeMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static InstrumentationRuntimeInstances &
-GetInstrumentationRuntimeInstances ()
-{
- static InstrumentationRuntimeInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin(const ConstString &name,
- const char *description,
- InstrumentationRuntimeCreateInstance create_callback,
- InstrumentationRuntimeGetType get_type_callback)
-{
- if (create_callback)
- {
- InstrumentationRuntimeInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.get_type_callback = get_type_callback;
- std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
- GetInstrumentationRuntimeInstances ().push_back (instance);
- }
- return false;
+struct InstrumentationRuntimeInstance {
+ InstrumentationRuntimeInstance()
+ : name(), description(), create_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ InstrumentationRuntimeCreateInstance create_callback;
+ InstrumentationRuntimeGetType get_type_callback;
+};
+
+typedef std::vector<InstrumentationRuntimeInstance>
+ InstrumentationRuntimeInstances;
+
+static std::recursive_mutex &GetInstrumentationRuntimeMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
}
-bool
-PluginManager::UnregisterPlugin (InstrumentationRuntimeCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
- InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
-
- InstrumentationRuntimeInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+static InstrumentationRuntimeInstances &GetInstrumentationRuntimeInstances() {
+ static InstrumentationRuntimeInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ InstrumentationRuntimeCreateInstance create_callback,
+ InstrumentationRuntimeGetType get_type_callback) {
+ if (create_callback) {
+ InstrumentationRuntimeInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.get_type_callback = get_type_callback;
+ std::lock_guard<std::recursive_mutex> guard(
+ GetInstrumentationRuntimeMutex());
+ GetInstrumentationRuntimeInstances().push_back(instance);
+ }
+ return false;
+}
+
+bool PluginManager::UnregisterPlugin(
+ InstrumentationRuntimeCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(
+ GetInstrumentationRuntimeMutex());
+ InstrumentationRuntimeInstances &instances =
+ GetInstrumentationRuntimeInstances();
+
+ InstrumentationRuntimeInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
InstrumentationRuntimeGetType
-PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
- InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
- if (idx < instances.size())
- return instances[idx].get_type_callback;
- return nullptr;
+PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
+ InstrumentationRuntimeInstances &instances =
+ GetInstrumentationRuntimeInstances();
+ if (idx < instances.size())
+ return instances[idx].get_type_callback;
+ return nullptr;
}
InstrumentationRuntimeCreateInstance
-PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
- InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
+ InstrumentationRuntimeInstances &instances =
+ GetInstrumentationRuntimeInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
InstrumentationRuntimeCreateInstance
-PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
- InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
-
- InstrumentationRuntimeInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(
+ GetInstrumentationRuntimeMutex());
+ InstrumentationRuntimeInstances &instances =
+ GetInstrumentationRuntimeInstances();
+
+ InstrumentationRuntimeInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark TypeSystem
-struct TypeSystemInstance
-{
- TypeSystemInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
+struct TypeSystemInstance {
+ TypeSystemInstance() : name(), description(), create_callback(nullptr) {}
- ConstString name;
- std::string description;
- TypeSystemCreateInstance create_callback;
- TypeSystemEnumerateSupportedLanguages enumerate_callback;
+ ConstString name;
+ std::string description;
+ TypeSystemCreateInstance create_callback;
+ TypeSystemEnumerateSupportedLanguages enumerate_callback;
};
typedef std::vector<TypeSystemInstance> TypeSystemInstances;
-static std::recursive_mutex &
-GetTypeSystemMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static TypeSystemInstances &
-GetTypeSystemInstances ()
-{
- static TypeSystemInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin (const ConstString &name,
- const char *description,
- TypeSystemCreateInstance create_callback,
- TypeSystemEnumerateSupportedLanguages enumerate_supported_languages_callback)
-{
- if (create_callback)
- {
- TypeSystemInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.enumerate_callback = enumerate_supported_languages_callback;
- std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
- GetTypeSystemInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetTypeSystemMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static TypeSystemInstances &GetTypeSystemInstances() {
+ static TypeSystemInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ TypeSystemCreateInstance create_callback,
+ TypeSystemEnumerateSupportedLanguages
+ enumerate_supported_languages_callback) {
+ if (create_callback) {
+ TypeSystemInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.enumerate_callback = enumerate_supported_languages_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
+ GetTypeSystemInstances().push_back(instance);
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (TypeSystemCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
- TypeSystemInstances &instances = GetTypeSystemInstances ();
-
- TypeSystemInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+bool PluginManager::UnregisterPlugin(TypeSystemCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
+ TypeSystemInstances &instances = GetTypeSystemInstances();
+
+ TypeSystemInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
TypeSystemCreateInstance
-PluginManager::GetTypeSystemCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
- TypeSystemInstances &instances = GetTypeSystemInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+PluginManager::GetTypeSystemCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
+ TypeSystemInstances &instances = GetTypeSystemInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
TypeSystemCreateInstance
-PluginManager::GetTypeSystemCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
- TypeSystemInstances &instances = GetTypeSystemInstances ();
-
- TypeSystemInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetTypeSystemCreateCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
+ TypeSystemInstances &instances = GetTypeSystemInstances();
+
+ TypeSystemInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
TypeSystemEnumerateSupportedLanguages
-PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
- TypeSystemInstances &instances = GetTypeSystemInstances ();
- if (idx < instances.size())
- return instances[idx].enumerate_callback;
- return nullptr;
+PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex(
+ uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
+ TypeSystemInstances &instances = GetTypeSystemInstances();
+ if (idx < instances.size())
+ return instances[idx].enumerate_callback;
+ return nullptr;
}
TypeSystemEnumerateSupportedLanguages
-PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
- TypeSystemInstances &instances = GetTypeSystemInstances ();
-
- TypeSystemInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->enumerate_callback;
- }
+PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
+ TypeSystemInstances &instances = GetTypeSystemInstances();
+
+ TypeSystemInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->enumerate_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark REPL
-struct REPLInstance
-{
- REPLInstance() :
- name(),
- description(),
- create_callback(nullptr)
- {
- }
-
- ConstString name;
- std::string description;
- REPLCreateInstance create_callback;
- REPLEnumerateSupportedLanguages enumerate_languages_callback;
+struct REPLInstance {
+ REPLInstance() : name(), description(), create_callback(nullptr) {}
+
+ ConstString name;
+ std::string description;
+ REPLCreateInstance create_callback;
+ REPLEnumerateSupportedLanguages enumerate_languages_callback;
};
typedef std::vector<REPLInstance> REPLInstances;
-static std::recursive_mutex &
-GetREPLMutex()
-{
- static std::recursive_mutex g_instances_mutex;
- return g_instances_mutex;
-}
-
-static REPLInstances &
-GetREPLInstances ()
-{
- static REPLInstances g_instances;
- return g_instances;
-}
-
-bool
-PluginManager::RegisterPlugin (const ConstString &name,
- const char *description,
- REPLCreateInstance create_callback,
- REPLEnumerateSupportedLanguages enumerate_languages_callback)
-{
- if (create_callback)
- {
- REPLInstance instance;
- assert ((bool)name);
- instance.name = name;
- if (description && description[0])
- instance.description = description;
- instance.create_callback = create_callback;
- instance.enumerate_languages_callback = enumerate_languages_callback;
- std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
- GetREPLInstances ().push_back (instance);
- }
- return false;
+static std::recursive_mutex &GetREPLMutex() {
+ static std::recursive_mutex g_instances_mutex;
+ return g_instances_mutex;
+}
+
+static REPLInstances &GetREPLInstances() {
+ static REPLInstances g_instances;
+ return g_instances;
+}
+
+bool PluginManager::RegisterPlugin(
+ const ConstString &name, const char *description,
+ REPLCreateInstance create_callback,
+ REPLEnumerateSupportedLanguages enumerate_languages_callback) {
+ if (create_callback) {
+ REPLInstance instance;
+ assert((bool)name);
+ instance.name = name;
+ if (description && description[0])
+ instance.description = description;
+ instance.create_callback = create_callback;
+ instance.enumerate_languages_callback = enumerate_languages_callback;
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
+ GetREPLInstances().push_back(instance);
+ }
+ return false;
}
-bool
-PluginManager::UnregisterPlugin (REPLCreateInstance create_callback)
-{
- if (create_callback)
- {
- std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
- REPLInstances &instances = GetREPLInstances ();
-
- REPLInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->create_callback == create_callback)
- {
- instances.erase(pos);
- return true;
- }
- }
+bool PluginManager::UnregisterPlugin(REPLCreateInstance create_callback) {
+ if (create_callback) {
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
+ REPLInstances &instances = GetREPLInstances();
+
+ REPLInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->create_callback == create_callback) {
+ instances.erase(pos);
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
-REPLCreateInstance
-PluginManager::GetREPLCreateCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
- REPLInstances &instances = GetREPLInstances ();
- if (idx < instances.size())
- return instances[idx].create_callback;
- return nullptr;
+REPLCreateInstance PluginManager::GetREPLCreateCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
+ REPLInstances &instances = GetREPLInstances();
+ if (idx < instances.size())
+ return instances[idx].create_callback;
+ return nullptr;
}
REPLCreateInstance
-PluginManager::GetREPLCreateCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
- REPLInstances &instances = GetREPLInstances ();
-
- REPLInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->create_callback;
- }
+PluginManager::GetREPLCreateCallbackForPluginName(const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
+ REPLInstances &instances = GetREPLInstances();
+
+ REPLInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->create_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
REPLEnumerateSupportedLanguages
-PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx)
-{
- std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
- REPLInstances &instances = GetREPLInstances ();
- if (idx < instances.size())
- return instances[idx].enumerate_languages_callback;
- return nullptr;
+PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex(uint32_t idx) {
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
+ REPLInstances &instances = GetREPLInstances();
+ if (idx < instances.size())
+ return instances[idx].enumerate_languages_callback;
+ return nullptr;
}
REPLEnumerateSupportedLanguages
-PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName (const ConstString &name)
-{
- if (name)
- {
- std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
- REPLInstances &instances = GetREPLInstances ();
-
- REPLInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (name == pos->name)
- return pos->enumerate_languages_callback;
- }
+PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName(
+ const ConstString &name) {
+ if (name) {
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
+ REPLInstances &instances = GetREPLInstances();
+
+ REPLInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (name == pos->name)
+ return pos->enumerate_languages_callback;
}
- return nullptr;
+ }
+ return nullptr;
}
#pragma mark PluginManager
-void
-PluginManager::DebuggerInitialize (Debugger &debugger)
-{
- // Initialize the DynamicLoader plugins
- {
- std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
- DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
-
- DynamicLoaderInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->debugger_init_callback)
- pos->debugger_init_callback (debugger);
- }
+void PluginManager::DebuggerInitialize(Debugger &debugger) {
+ // Initialize the DynamicLoader plugins
+ {
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
+ DynamicLoaderInstances &instances = GetDynamicLoaderInstances();
+
+ DynamicLoaderInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->debugger_init_callback)
+ pos->debugger_init_callback(debugger);
}
+ }
- // Initialize the JITLoader plugins
- {
- std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
- JITLoaderInstances &instances = GetJITLoaderInstances ();
-
- JITLoaderInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->debugger_init_callback)
- pos->debugger_init_callback (debugger);
- }
+ // Initialize the JITLoader plugins
+ {
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
+ JITLoaderInstances &instances = GetJITLoaderInstances();
+
+ JITLoaderInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->debugger_init_callback)
+ pos->debugger_init_callback(debugger);
}
+ }
- // Initialize the Platform plugins
- {
- std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
- PlatformInstances &instances = GetPlatformInstances ();
-
- PlatformInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->debugger_init_callback)
- pos->debugger_init_callback (debugger);
- }
+ // Initialize the Platform plugins
+ {
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
+ PlatformInstances &instances = GetPlatformInstances();
+
+ PlatformInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->debugger_init_callback)
+ pos->debugger_init_callback(debugger);
}
+ }
- // Initialize the Process plugins
- {
- std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
- ProcessInstances &instances = GetProcessInstances();
-
- ProcessInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++ pos)
- {
- if (pos->debugger_init_callback)
- pos->debugger_init_callback (debugger);
- }
+ // Initialize the Process plugins
+ {
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
+ ProcessInstances &instances = GetProcessInstances();
+
+ ProcessInstances::iterator pos, end = instances.end();
+ for (pos = instances.begin(); pos != end; ++pos) {
+ if (pos->debugger_init_callback)
+ pos->debugger_init_callback(debugger);
}
+ }
- // Initialize the SymbolFile plugins
- {
- std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
- for (auto& sym_file: GetSymbolFileInstances())
- {
- if (sym_file.debugger_init_callback)
- sym_file.debugger_init_callback (debugger);
- }
+ // Initialize the SymbolFile plugins
+ {
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
+ for (auto &sym_file : GetSymbolFileInstances()) {
+ if (sym_file.debugger_init_callback)
+ sym_file.debugger_init_callback(debugger);
}
+ }
- // Initialize the OperatingSystem plugins
- {
- std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
- for (auto &os : GetOperatingSystemInstances())
- {
- if (os.debugger_init_callback)
- os.debugger_init_callback(debugger);
- }
+ // Initialize the OperatingSystem plugins
+ {
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
+ for (auto &os : GetOperatingSystemInstances()) {
+ if (os.debugger_init_callback)
+ os.debugger_init_callback(debugger);
}
+ }
- // Initialize the StructuredDataPlugin plugins
- {
- std::lock_guard<std::recursive_mutex>
- guard(GetStructuredDataPluginMutex());
- for (auto &plugin: GetStructuredDataPluginInstances())
- {
- if (plugin.debugger_init_callback)
- plugin.debugger_init_callback(debugger);
- }
+ // Initialize the StructuredDataPlugin plugins
+ {
+ std::lock_guard<std::recursive_mutex> guard(GetStructuredDataPluginMutex());
+ for (auto &plugin : GetStructuredDataPluginInstances()) {
+ if (plugin.debugger_init_callback)
+ plugin.debugger_init_callback(debugger);
}
+ }
}
// This is the preferred new way to register plugin specific settings. e.g.
-// This will put a plugin's settings under e.g. "plugin.<plugin_type_name>.<plugin_type_desc>.SETTINGNAME".
-static lldb::OptionValuePropertiesSP
-GetDebuggerPropertyForPlugins (Debugger &debugger,
- const ConstString &plugin_type_name,
- const ConstString &plugin_type_desc,
- bool can_create)
-{
- lldb::OptionValuePropertiesSP parent_properties_sp (debugger.GetValueProperties());
- if (parent_properties_sp)
- {
- static ConstString g_property_name("plugin");
-
- OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty(nullptr, g_property_name);
- if (!plugin_properties_sp && can_create)
- {
- plugin_properties_sp.reset (new OptionValueProperties (g_property_name));
- parent_properties_sp->AppendProperty (g_property_name,
- ConstString("Settings specify to plugins."),
- true,
- plugin_properties_sp);
- }
-
- if (plugin_properties_sp)
- {
- lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty(nullptr, plugin_type_name);
- if (!plugin_type_properties_sp && can_create)
- {
- plugin_type_properties_sp.reset (new OptionValueProperties (plugin_type_name));
- plugin_properties_sp->AppendProperty (plugin_type_name,
- plugin_type_desc,
- true,
- plugin_type_properties_sp);
- }
- return plugin_type_properties_sp;
- }
+// This will put a plugin's settings under e.g.
+// "plugin.<plugin_type_name>.<plugin_type_desc>.SETTINGNAME".
+static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPlugins(
+ Debugger &debugger, const ConstString &plugin_type_name,
+ const ConstString &plugin_type_desc, bool can_create) {
+ lldb::OptionValuePropertiesSP parent_properties_sp(
+ debugger.GetValueProperties());
+ if (parent_properties_sp) {
+ static ConstString g_property_name("plugin");
+
+ OptionValuePropertiesSP plugin_properties_sp =
+ parent_properties_sp->GetSubProperty(nullptr, g_property_name);
+ if (!plugin_properties_sp && can_create) {
+ plugin_properties_sp.reset(new OptionValueProperties(g_property_name));
+ parent_properties_sp->AppendProperty(
+ g_property_name, ConstString("Settings specify to plugins."), true,
+ plugin_properties_sp);
+ }
+
+ if (plugin_properties_sp) {
+ lldb::OptionValuePropertiesSP plugin_type_properties_sp =
+ plugin_properties_sp->GetSubProperty(nullptr, plugin_type_name);
+ if (!plugin_type_properties_sp && can_create) {
+ plugin_type_properties_sp.reset(
+ new OptionValueProperties(plugin_type_name));
+ plugin_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
+ true, plugin_type_properties_sp);
+ }
+ return plugin_type_properties_sp;
}
- return lldb::OptionValuePropertiesSP();
+ }
+ return lldb::OptionValuePropertiesSP();
}
// 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".
-static lldb::OptionValuePropertiesSP
-GetDebuggerPropertyForPluginsOldStyle (Debugger &debugger,
- const ConstString &plugin_type_name,
- const ConstString &plugin_type_desc,
- bool can_create)
-{
- static ConstString g_property_name("plugin");
- lldb::OptionValuePropertiesSP parent_properties_sp (debugger.GetValueProperties());
- if (parent_properties_sp)
- {
- OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty(nullptr, plugin_type_name);
- if (!plugin_properties_sp && can_create)
- {
- plugin_properties_sp.reset (new OptionValueProperties (plugin_type_name));
- parent_properties_sp->AppendProperty (plugin_type_name,
- plugin_type_desc,
- true,
- plugin_properties_sp);
- }
-
- if (plugin_properties_sp)
- {
- lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty(nullptr, g_property_name);
- if (!plugin_type_properties_sp && can_create)
- {
- plugin_type_properties_sp.reset (new OptionValueProperties (g_property_name));
- plugin_properties_sp->AppendProperty (g_property_name,
- ConstString("Settings specific to plugins"),
- true,
- plugin_type_properties_sp);
- }
- return plugin_type_properties_sp;
- }
+static lldb::OptionValuePropertiesSP GetDebuggerPropertyForPluginsOldStyle(
+ Debugger &debugger, const ConstString &plugin_type_name,
+ const ConstString &plugin_type_desc, bool can_create) {
+ static ConstString g_property_name("plugin");
+ lldb::OptionValuePropertiesSP parent_properties_sp(
+ debugger.GetValueProperties());
+ if (parent_properties_sp) {
+ OptionValuePropertiesSP plugin_properties_sp =
+ parent_properties_sp->GetSubProperty(nullptr, plugin_type_name);
+ if (!plugin_properties_sp && can_create) {
+ plugin_properties_sp.reset(new OptionValueProperties(plugin_type_name));
+ parent_properties_sp->AppendProperty(plugin_type_name, plugin_type_desc,
+ true, plugin_properties_sp);
+ }
+
+ if (plugin_properties_sp) {
+ lldb::OptionValuePropertiesSP plugin_type_properties_sp =
+ plugin_properties_sp->GetSubProperty(nullptr, g_property_name);
+ if (!plugin_type_properties_sp && can_create) {
+ plugin_type_properties_sp.reset(
+ new OptionValueProperties(g_property_name));
+ plugin_properties_sp->AppendProperty(
+ g_property_name, ConstString("Settings specific to plugins"), true,
+ plugin_type_properties_sp);
+ }
+ return plugin_type_properties_sp;
}
- return lldb::OptionValuePropertiesSP();
+ }
+ return lldb::OptionValuePropertiesSP();
}
namespace {
typedef lldb::OptionValuePropertiesSP
-GetDebuggerPropertyForPluginsPtr (Debugger&, const ConstString&, const ConstString&, bool can_create);
+GetDebuggerPropertyForPluginsPtr(Debugger &, const ConstString &,
+ const ConstString &, bool can_create);
lldb::OptionValuePropertiesSP
-GetSettingForPlugin (Debugger &debugger,
- const ConstString &setting_name,
- const ConstString &plugin_type_name,
- GetDebuggerPropertyForPluginsPtr get_debugger_property= GetDebuggerPropertyForPlugins)
-{
- lldb::OptionValuePropertiesSP properties_sp;
- lldb::OptionValuePropertiesSP plugin_type_properties_sp (get_debugger_property (debugger,
- plugin_type_name,
- ConstString(), // not creating to so we don't need the description
- false));
- if (plugin_type_properties_sp)
- properties_sp = plugin_type_properties_sp->GetSubProperty (nullptr, setting_name);
- return properties_sp;
-}
-
-bool
-CreateSettingForPlugin (Debugger &debugger,
- const ConstString &plugin_type_name,
- const ConstString &plugin_type_desc,
- const lldb::OptionValuePropertiesSP &properties_sp,
- const ConstString &description,
- bool is_global_property,
- GetDebuggerPropertyForPluginsPtr get_debugger_property = GetDebuggerPropertyForPlugins)
-{
- if (properties_sp)
- {
- lldb::OptionValuePropertiesSP plugin_type_properties_sp (get_debugger_property (
- debugger, plugin_type_name, plugin_type_desc, true));
- if (plugin_type_properties_sp)
- {
- plugin_type_properties_sp->AppendProperty (properties_sp->GetName(),
- description,
- is_global_property,
- properties_sp);
- return true;
- }
- }
- return false;
-}
-
-const char* kDynamicLoaderPluginName("dynamic-loader");
-const char* kPlatformPluginName("platform");
-const char* kProcessPluginName("process");
-const char* kSymbolFilePluginName("symbol-file");
-const char* kJITLoaderPluginName("jit-loader");
-const char* kStructuredDataPluginName("structured-data");
+GetSettingForPlugin(Debugger &debugger, const ConstString &setting_name,
+ const ConstString &plugin_type_name,
+ GetDebuggerPropertyForPluginsPtr get_debugger_property =
+ GetDebuggerPropertyForPlugins) {
+ lldb::OptionValuePropertiesSP properties_sp;
+ lldb::OptionValuePropertiesSP plugin_type_properties_sp(get_debugger_property(
+ debugger, plugin_type_name,
+ ConstString(), // not creating to so we don't need the description
+ false));
+ if (plugin_type_properties_sp)
+ properties_sp =
+ plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
+ return properties_sp;
+}
+
+bool CreateSettingForPlugin(
+ Debugger &debugger, const ConstString &plugin_type_name,
+ const ConstString &plugin_type_desc,
+ const lldb::OptionValuePropertiesSP &properties_sp,
+ const ConstString &description, bool is_global_property,
+ GetDebuggerPropertyForPluginsPtr get_debugger_property =
+ GetDebuggerPropertyForPlugins) {
+ if (properties_sp) {
+ lldb::OptionValuePropertiesSP plugin_type_properties_sp(
+ get_debugger_property(debugger, plugin_type_name, plugin_type_desc,
+ true));
+ if (plugin_type_properties_sp) {
+ plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
+ description, is_global_property,
+ properties_sp);
+ return true;
+ }
+ }
+ return false;
+}
+
+const char *kDynamicLoaderPluginName("dynamic-loader");
+const char *kPlatformPluginName("platform");
+const char *kProcessPluginName("process");
+const char *kSymbolFilePluginName("symbol-file");
+const char *kJITLoaderPluginName("jit-loader");
+const char *kStructuredDataPluginName("structured-data");
} // anonymous namespace
-lldb::OptionValuePropertiesSP
-PluginManager::GetSettingForDynamicLoaderPlugin (Debugger &debugger,
- const ConstString &setting_name)
-{
- return GetSettingForPlugin(debugger, setting_name, ConstString(kDynamicLoaderPluginName));
-}
-
-bool
-PluginManager::CreateSettingForDynamicLoaderPlugin (Debugger &debugger,
- const lldb::OptionValuePropertiesSP &properties_sp,
- const ConstString &description,
- bool is_global_property)
-{
- return CreateSettingForPlugin(debugger,
- ConstString(kDynamicLoaderPluginName),
- ConstString("Settings for dynamic loader plug-ins"),
- properties_sp,
- description,
- is_global_property);
+lldb::OptionValuePropertiesSP PluginManager::GetSettingForDynamicLoaderPlugin(
+ Debugger &debugger, const ConstString &setting_name) {
+ return GetSettingForPlugin(debugger, setting_name,
+ ConstString(kDynamicLoaderPluginName));
}
-lldb::OptionValuePropertiesSP
-PluginManager::GetSettingForPlatformPlugin (Debugger &debugger, const ConstString &setting_name)
-{
- return GetSettingForPlugin(debugger,
- setting_name,
- ConstString(kPlatformPluginName),
- GetDebuggerPropertyForPluginsOldStyle);
-}
-
-bool
-PluginManager::CreateSettingForPlatformPlugin (Debugger &debugger,
- const lldb::OptionValuePropertiesSP &properties_sp,
- const ConstString &description,
- bool is_global_property)
-{
- return CreateSettingForPlugin(debugger,
- ConstString(kPlatformPluginName),
- ConstString("Settings for platform plug-ins"),
- properties_sp,
- description,
- is_global_property,
- GetDebuggerPropertyForPluginsOldStyle);
+bool PluginManager::CreateSettingForDynamicLoaderPlugin(
+ Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
+ const ConstString &description, bool is_global_property) {
+ return CreateSettingForPlugin(
+ debugger, ConstString(kDynamicLoaderPluginName),
+ ConstString("Settings for dynamic loader plug-ins"), properties_sp,
+ description, is_global_property);
}
lldb::OptionValuePropertiesSP
-PluginManager::GetSettingForProcessPlugin (Debugger &debugger, const ConstString &setting_name)
-{
- return GetSettingForPlugin(debugger, setting_name, ConstString(kProcessPluginName));
-}
-
-bool
-PluginManager::CreateSettingForProcessPlugin (Debugger &debugger,
- const lldb::OptionValuePropertiesSP &properties_sp,
- const ConstString &description,
- bool is_global_property)
-{
- return CreateSettingForPlugin(debugger,
- ConstString(kProcessPluginName),
- ConstString("Settings for process plug-ins"),
- properties_sp,
- description,
- is_global_property);
+PluginManager::GetSettingForPlatformPlugin(Debugger &debugger,
+ const ConstString &setting_name) {
+ return GetSettingForPlugin(debugger, setting_name,
+ ConstString(kPlatformPluginName),
+ GetDebuggerPropertyForPluginsOldStyle);
}
-lldb::OptionValuePropertiesSP
-PluginManager::GetSettingForSymbolFilePlugin (Debugger &debugger,
- const ConstString &setting_name)
-{
- return GetSettingForPlugin(debugger, setting_name, ConstString(kSymbolFilePluginName));
-}
-
-bool
-PluginManager::CreateSettingForSymbolFilePlugin (Debugger &debugger,
- const lldb::OptionValuePropertiesSP &properties_sp,
- const ConstString &description,
- bool is_global_property)
-{
- return CreateSettingForPlugin(debugger,
- ConstString(kSymbolFilePluginName),
- ConstString("Settings for symbol file plug-ins"),
- properties_sp,
- description,
- is_global_property);
+bool PluginManager::CreateSettingForPlatformPlugin(
+ Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
+ const ConstString &description, bool is_global_property) {
+ return CreateSettingForPlugin(debugger, ConstString(kPlatformPluginName),
+ ConstString("Settings for platform plug-ins"),
+ properties_sp, description, is_global_property,
+ GetDebuggerPropertyForPluginsOldStyle);
}
lldb::OptionValuePropertiesSP
-PluginManager::GetSettingForJITLoaderPlugin (Debugger &debugger,
- const ConstString &setting_name)
-{
- return GetSettingForPlugin(debugger, setting_name, ConstString(kJITLoaderPluginName));
-}
-
-bool
-PluginManager::CreateSettingForJITLoaderPlugin (Debugger &debugger,
- const lldb::OptionValuePropertiesSP &properties_sp,
- const ConstString &description,
- bool is_global_property)
-{
- return CreateSettingForPlugin(debugger,
- ConstString(kJITLoaderPluginName),
- ConstString("Settings for JIT loader plug-ins"),
- properties_sp,
- description,
- is_global_property);
+PluginManager::GetSettingForProcessPlugin(Debugger &debugger,
+ const ConstString &setting_name) {
+ return GetSettingForPlugin(debugger, setting_name,
+ ConstString(kProcessPluginName));
}
-static const char *kOperatingSystemPluginName("os");
+bool PluginManager::CreateSettingForProcessPlugin(
+ Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
+ const ConstString &description, bool is_global_property) {
+ return CreateSettingForPlugin(debugger, ConstString(kProcessPluginName),
+ ConstString("Settings for process plug-ins"),
+ properties_sp, description, is_global_property);
+}
lldb::OptionValuePropertiesSP
-PluginManager::GetSettingForOperatingSystemPlugin(Debugger &debugger, const ConstString &setting_name)
-{
- lldb::OptionValuePropertiesSP properties_sp;
- lldb::OptionValuePropertiesSP plugin_type_properties_sp(
- GetDebuggerPropertyForPlugins(debugger, ConstString(kOperatingSystemPluginName),
- ConstString(), // not creating to so we don't need the description
- false));
- if (plugin_type_properties_sp)
- properties_sp = plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
- return properties_sp;
-}
-
-bool
-PluginManager::CreateSettingForOperatingSystemPlugin(Debugger &debugger,
- const lldb::OptionValuePropertiesSP &properties_sp,
- const ConstString &description, bool is_global_property)
-{
- if (properties_sp)
- {
- lldb::OptionValuePropertiesSP plugin_type_properties_sp(
- GetDebuggerPropertyForPlugins(debugger, ConstString(kOperatingSystemPluginName),
- ConstString("Settings for operating system plug-ins"), true));
- if (plugin_type_properties_sp)
- {
- plugin_type_properties_sp->AppendProperty(properties_sp->GetName(), description, is_global_property,
- properties_sp);
- return true;
- }
- }
- return false;
+PluginManager::GetSettingForSymbolFilePlugin(Debugger &debugger,
+ const ConstString &setting_name) {
+ return GetSettingForPlugin(debugger, setting_name,
+ ConstString(kSymbolFilePluginName));
+}
+
+bool PluginManager::CreateSettingForSymbolFilePlugin(
+ Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
+ const ConstString &description, bool is_global_property) {
+ return CreateSettingForPlugin(
+ debugger, ConstString(kSymbolFilePluginName),
+ ConstString("Settings for symbol file plug-ins"), properties_sp,
+ description, is_global_property);
}
lldb::OptionValuePropertiesSP
-PluginManager::GetSettingForStructuredDataPlugin(Debugger &debugger,
- const ConstString &setting_name)
-{
- return GetSettingForPlugin(debugger, setting_name, ConstString(kStructuredDataPluginName));
-}
-
-bool
-PluginManager::CreateSettingForStructuredDataPlugin(Debugger &debugger,
- const lldb::OptionValuePropertiesSP &properties_sp,
- const ConstString &description,
- bool is_global_property)
-{
- return CreateSettingForPlugin(debugger,
- ConstString(kStructuredDataPluginName),
- ConstString("Settings for structured data plug-ins"),
- properties_sp,
- description,
- is_global_property);
+PluginManager::GetSettingForJITLoaderPlugin(Debugger &debugger,
+ const ConstString &setting_name) {
+ return GetSettingForPlugin(debugger, setting_name,
+ ConstString(kJITLoaderPluginName));
+}
+
+bool PluginManager::CreateSettingForJITLoaderPlugin(
+ Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
+ const ConstString &description, bool is_global_property) {
+ return CreateSettingForPlugin(debugger, ConstString(kJITLoaderPluginName),
+ ConstString("Settings for JIT loader plug-ins"),
+ properties_sp, description, is_global_property);
+}
+
+static const char *kOperatingSystemPluginName("os");
+
+lldb::OptionValuePropertiesSP PluginManager::GetSettingForOperatingSystemPlugin(
+ Debugger &debugger, const ConstString &setting_name) {
+ lldb::OptionValuePropertiesSP properties_sp;
+ lldb::OptionValuePropertiesSP plugin_type_properties_sp(
+ GetDebuggerPropertyForPlugins(
+ debugger, ConstString(kOperatingSystemPluginName),
+ ConstString(), // not creating to so we don't need the description
+ false));
+ if (plugin_type_properties_sp)
+ properties_sp =
+ plugin_type_properties_sp->GetSubProperty(nullptr, setting_name);
+ return properties_sp;
+}
+
+bool PluginManager::CreateSettingForOperatingSystemPlugin(
+ Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
+ const ConstString &description, bool is_global_property) {
+ if (properties_sp) {
+ lldb::OptionValuePropertiesSP plugin_type_properties_sp(
+ GetDebuggerPropertyForPlugins(
+ debugger, ConstString(kOperatingSystemPluginName),
+ ConstString("Settings for operating system plug-ins"), true));
+ if (plugin_type_properties_sp) {
+ plugin_type_properties_sp->AppendProperty(properties_sp->GetName(),
+ description, is_global_property,
+ properties_sp);
+ return true;
+ }
+ }
+ return false;
+}
+
+lldb::OptionValuePropertiesSP PluginManager::GetSettingForStructuredDataPlugin(
+ Debugger &debugger, const ConstString &setting_name) {
+ return GetSettingForPlugin(debugger, setting_name,
+ ConstString(kStructuredDataPluginName));
+}
+
+bool PluginManager::CreateSettingForStructuredDataPlugin(
+ Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
+ const ConstString &description, bool is_global_property) {
+ return CreateSettingForPlugin(
+ debugger, ConstString(kStructuredDataPluginName),
+ ConstString("Settings for structured data plug-ins"), properties_sp,
+ description, is_global_property);
}
Modified: lldb/trunk/source/Core/RegisterValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegisterValue.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegisterValue.cpp (original)
+++ lldb/trunk/source/Core/RegisterValue.cpp Tue Sep 6 15:57:50 2016
@@ -23,1012 +23,934 @@
#include "lldb/Core/Scalar.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamString.h"
-#include "lldb/Interpreter/Args.h"
#include "lldb/Host/StringConvert.h"
+#include "lldb/Interpreter/Args.h"
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");
- const char *fmt = format_string.GetData();
- if (prefix_with_name)
- {
- if (reg_info->name)
- {
- s->Printf (fmt, reg_info->name);
- name_printed = true;
- }
- else if (reg_info->alt_name)
- {
- s->Printf (fmt, 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, 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, reg_info->name);
- name_printed = true;
- }
- }
- if (name_printed)
- s->PutCString (" = ");
-
- if (format == eFormatDefault)
- format = reg_info->format;
-
- data.Dump (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::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");
+ const char *fmt = format_string.GetData();
+ if (prefix_with_name) {
+ if (reg_info->name) {
+ s->Printf(fmt, reg_info->name);
+ name_printed = true;
+ } else if (reg_info->alt_name) {
+ s->Printf(fmt, 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, 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, reg_info->name);
+ name_printed = true;
+ }
+ }
+ if (name_printed)
+ s->PutCString(" = ");
+
+ if (format == eFormatDefault)
+ format = reg_info->format;
+
+ data.Dump(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;
+bool RegisterValue::GetData(DataExtractor &data) const {
+ return data.SetData(GetBytes(), GetByteSize(), GetByteOrder()) > 0;
}
-uint32_t
-RegisterValue::GetAsMemoryData (const RegisterInfo *reg_info,
- void *dst,
- uint32_t dst_len,
- lldb::ByteOrder dst_byte_order,
- Error &error) const
-{
- if (reg_info == nullptr)
- {
- error.SetErrorString ("invalid register info argument.");
- return 0;
- }
-
- // ReadRegister should have already been called on this object prior to
- // calling this.
- if (GetType() == eTypeInvalid)
- {
- // No value has been read into this object...
- error.SetErrorStringWithFormat("invalid register value type for register %s", reg_info->name);
- return 0;
- }
-
- if (dst_len > kMaxRegisterByteSize)
- {
- error.SetErrorString ("destination is too big");
- return 0;
- }
-
- const uint32_t src_len = reg_info->byte_size;
-
- // Extract the register data into a data extractor
- DataExtractor reg_data;
- if (!GetData(reg_data))
- {
- error.SetErrorString ("invalid register value to copy into");
- return 0;
- }
-
- // Prepare a memory buffer that contains some or all of the register value
- const uint32_t bytes_copied = reg_data.CopyByteOrderedData (0, // src offset
- src_len, // src length
- dst, // dst buffer
- dst_len, // dst length
- dst_byte_order); // dst byte order
- if (bytes_copied == 0)
- error.SetErrorStringWithFormat("failed to copy data for register write of %s", reg_info->name);
-
- return bytes_copied;
-}
-
-uint32_t
-RegisterValue::SetFromMemoryData (const RegisterInfo *reg_info,
- const void *src,
- uint32_t src_len,
- lldb::ByteOrder src_byte_order,
- Error &error)
-{
- if (reg_info == nullptr)
- {
- error.SetErrorString ("invalid register info argument.");
- return 0;
- }
-
- // Moving from addr into a register
- //
- // Case 1: src_len == dst_len
- //
- // |AABBCCDD| Address contents
- // |AABBCCDD| Register contents
- //
- // Case 2: src_len > dst_len
- //
- // Error! (The register should always be big enough to hold the data)
- //
- // Case 3: src_len < dst_len
- //
- // |AABB| Address contents
- // |AABB0000| Register contents [on little-endian hardware]
- // |0000AABB| Register contents [on big-endian hardware]
- if (src_len > kMaxRegisterByteSize)
- {
- error.SetErrorStringWithFormat ("register buffer is too small to receive %u bytes of data.", src_len);
- return 0;
- }
-
- const uint32_t dst_len = reg_info->byte_size;
-
- if (src_len > dst_len)
- {
- error.SetErrorStringWithFormat("%u bytes is too big to store in register %s (%u bytes)", src_len, reg_info->name, dst_len);
- return 0;
- }
-
- // Use a data extractor to correctly copy and pad the bytes read into the
- // register value
- DataExtractor src_data (src, src_len, src_byte_order, 4);
+uint32_t RegisterValue::GetAsMemoryData(const RegisterInfo *reg_info, void *dst,
+ uint32_t dst_len,
+ lldb::ByteOrder dst_byte_order,
+ Error &error) const {
+ if (reg_info == nullptr) {
+ error.SetErrorString("invalid register info argument.");
+ return 0;
+ }
- error = SetValueFromData(reg_info, src_data, 0, true);
- if (error.Fail())
- return 0;
+ // ReadRegister should have already been called on this object prior to
+ // calling this.
+ if (GetType() == eTypeInvalid) {
+ // No value has been read into this object...
+ error.SetErrorStringWithFormat(
+ "invalid register value type for register %s", reg_info->name);
+ return 0;
+ }
- // If SetValueFromData succeeded, we must have copied all of src_len
- return src_len;
-}
+ if (dst_len > kMaxRegisterByteSize) {
+ error.SetErrorString("destination is too big");
+ return 0;
+ }
-bool
-RegisterValue::GetScalarValue (Scalar &scalar) const
-{
- switch (m_type)
- {
- case eTypeInvalid: break;
- case eTypeBytes:
- {
- switch (buffer.length)
- {
- default: break;
- case 1: scalar = *(const uint8_t *)buffer.bytes; return true;
- case 2: scalar = *(const uint16_t *)buffer.bytes; return true;
- case 4: scalar = *(const uint32_t *)buffer.bytes; return true;
- case 8: scalar = *(const uint64_t *)buffer.bytes; return true;
- case 16:
- case 32:
- if (buffer.length % sizeof(uint64_t) == 0)
- {
- const auto length_in_bits = buffer.length * 8;
- const auto length_in_uint64 = buffer.length / sizeof(uint64_t);
- scalar = llvm::APInt(length_in_bits, llvm::ArrayRef<uint64_t>((const uint64_t *)buffer.bytes, length_in_uint64));
- return true;
- }
- break;
- }
- }
- break;
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble: scalar = m_scalar; return true;
- }
- return false;
-}
+ const uint32_t src_len = reg_info->byte_size;
-void
-RegisterValue::Clear()
-{
- m_type = eTypeInvalid;
-}
+ // Extract the register data into a data extractor
+ DataExtractor reg_data;
+ if (!GetData(reg_data)) {
+ error.SetErrorString("invalid register value to copy into");
+ return 0;
+ }
-RegisterValue::Type
-RegisterValue::SetType (const RegisterInfo *reg_info)
-{
- // To change the type, we simply copy the data in again, using the new format
- RegisterValue copy;
- DataExtractor copy_data;
- if (copy.CopyValue(*this) && copy.GetData(copy_data))
- SetValueFromData(reg_info, copy_data, 0, true);
-
- return m_type;
-}
-
-Error
-RegisterValue::SetValueFromData (const RegisterInfo *reg_info, DataExtractor &src, lldb::offset_t src_offset, bool partial_data_ok)
-{
- Error error;
-
- if (src.GetByteSize() == 0)
- {
- error.SetErrorString ("empty data.");
- return error;
- }
+ // Prepare a memory buffer that contains some or all of the register value
+ const uint32_t bytes_copied =
+ reg_data.CopyByteOrderedData(0, // src offset
+ src_len, // src length
+ dst, // dst buffer
+ dst_len, // dst length
+ dst_byte_order); // dst byte order
+ if (bytes_copied == 0)
+ error.SetErrorStringWithFormat(
+ "failed to copy data for register write of %s", reg_info->name);
+
+ return bytes_copied;
+}
+
+uint32_t RegisterValue::SetFromMemoryData(const RegisterInfo *reg_info,
+ const void *src, uint32_t src_len,
+ lldb::ByteOrder src_byte_order,
+ Error &error) {
+ if (reg_info == nullptr) {
+ error.SetErrorString("invalid register info argument.");
+ return 0;
+ }
- if (reg_info->byte_size == 0)
- {
- error.SetErrorString ("invalid register info.");
- return error;
- }
+ // Moving from addr into a register
+ //
+ // Case 1: src_len == dst_len
+ //
+ // |AABBCCDD| Address contents
+ // |AABBCCDD| Register contents
+ //
+ // Case 2: src_len > dst_len
+ //
+ // Error! (The register should always be big enough to hold the data)
+ //
+ // Case 3: src_len < dst_len
+ //
+ // |AABB| Address contents
+ // |AABB0000| Register contents [on little-endian hardware]
+ // |0000AABB| Register contents [on big-endian hardware]
+ if (src_len > kMaxRegisterByteSize) {
+ error.SetErrorStringWithFormat(
+ "register buffer is too small to receive %u bytes of data.", src_len);
+ return 0;
+ }
- uint32_t src_len = src.GetByteSize() - src_offset;
-
- if (!partial_data_ok && (src_len < reg_info->byte_size))
- {
- error.SetErrorString ("not enough data.");
- return error;
- }
-
- // Cap the data length if there is more than enough bytes for this register
- // value
- if (src_len > reg_info->byte_size)
- src_len = reg_info->byte_size;
+ const uint32_t dst_len = reg_info->byte_size;
- // Zero out the value in case we get partial data...
- memset (buffer.bytes, 0, sizeof (buffer.bytes));
+ if (src_len > dst_len) {
+ error.SetErrorStringWithFormat(
+ "%u bytes is too big to store in register %s (%u bytes)", src_len,
+ reg_info->name, dst_len);
+ return 0;
+ }
- type128 int128;
+ // Use a data extractor to correctly copy and pad the bytes read into the
+ // register value
+ DataExtractor src_data(src, src_len, src_byte_order, 4);
- m_type = eTypeInvalid;
- switch (reg_info->encoding)
- {
- case eEncodingInvalid:
- break;
- case eEncodingUint:
- case eEncodingSint:
- if (reg_info->byte_size == 1)
- SetUInt8(src.GetMaxU32(&src_offset, src_len));
- else if (reg_info->byte_size <= 2)
- SetUInt16(src.GetMaxU32(&src_offset, src_len));
- else if (reg_info->byte_size <= 4)
- SetUInt32(src.GetMaxU32(&src_offset, src_len));
- else if (reg_info->byte_size <= 8)
- SetUInt64(src.GetMaxU64(&src_offset, src_len));
- else if (reg_info->byte_size <= 16)
- {
- uint64_t data1 = src.GetU64 (&src_offset);
- uint64_t data2 = src.GetU64 (&src_offset);
- if (src.GetByteSize() == eByteOrderBig)
- {
- int128.x[0] = data1;
- int128.x[1] = data2;
- }
- else
- {
- int128.x[0] = data2;
- int128.x[1] = data1;
- }
- SetUInt128 (llvm::APInt(128, 2, int128.x));
- }
- break;
- case eEncodingIEEE754:
- if (reg_info->byte_size == sizeof(float))
- SetFloat(src.GetFloat(&src_offset));
- else if (reg_info->byte_size == sizeof(double))
- SetDouble(src.GetDouble(&src_offset));
- else if (reg_info->byte_size == sizeof(long double))
- SetLongDouble(src.GetLongDouble(&src_offset));
- break;
- case eEncodingVector:
- {
- m_type = eTypeBytes;
- buffer.length = reg_info->byte_size;
- buffer.byte_order = src.GetByteOrder();
- assert (buffer.length <= kMaxRegisterByteSize);
- if (buffer.length > kMaxRegisterByteSize)
- buffer.length = kMaxRegisterByteSize;
- if (src.CopyByteOrderedData (src_offset, // offset within "src" to start extracting data
- src_len, // src length
- buffer.bytes, // dst buffer
- buffer.length, // dst length
- buffer.byte_order) == 0)// dst byte order
- {
- error.SetErrorStringWithFormat("failed to copy data for register write of %s", reg_info->name);
- return error;
- }
- }
- }
+ error = SetValueFromData(reg_info, src_data, 0, true);
+ if (error.Fail())
+ return 0;
- if (m_type == eTypeInvalid)
- error.SetErrorStringWithFormat("invalid register value type for register %s", reg_info->name);
- return error;
+ // If SetValueFromData succeeded, we must have copied all of src_len
+ return src_len;
}
-static inline void StripSpaces(llvm::StringRef &Str)
-{
- while (!Str.empty() && isspace(Str[0]))
- Str = Str.substr(1);
- while (!Str.empty() && isspace(Str.back()))
- Str = Str.substr(0, Str.size()-1);
-}
-
-static inline void LStrip(llvm::StringRef &Str, char c)
-{
- if (!Str.empty() && Str.front() == c)
- Str = Str.substr(1);
-}
-
-static inline void RStrip(llvm::StringRef &Str, char c)
-{
- if (!Str.empty() && Str.back() == c)
- Str = Str.substr(0, Str.size()-1);
+bool RegisterValue::GetScalarValue(Scalar &scalar) const {
+ switch (m_type) {
+ case eTypeInvalid:
+ break;
+ case eTypeBytes: {
+ switch (buffer.length) {
+ default:
+ break;
+ case 1:
+ scalar = *(const uint8_t *)buffer.bytes;
+ return true;
+ case 2:
+ scalar = *(const uint16_t *)buffer.bytes;
+ return true;
+ case 4:
+ scalar = *(const uint32_t *)buffer.bytes;
+ return true;
+ case 8:
+ scalar = *(const uint64_t *)buffer.bytes;
+ return true;
+ case 16:
+ case 32:
+ if (buffer.length % sizeof(uint64_t) == 0) {
+ const auto length_in_bits = buffer.length * 8;
+ const auto length_in_uint64 = buffer.length / sizeof(uint64_t);
+ scalar =
+ llvm::APInt(length_in_bits,
+ llvm::ArrayRef<uint64_t>((const uint64_t *)buffer.bytes,
+ length_in_uint64));
+ return true;
+ }
+ break;
+ }
+ } break;
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ scalar = m_scalar;
+ return true;
+ }
+ return false;
}
-// Helper function for RegisterValue::SetValueFromCString()
-static bool
-ParseVectorEncoding(const RegisterInfo *reg_info, const char *vector_str, const uint32_t byte_size, RegisterValue *reg_value)
-{
- // Example: vector_str = "{0x2c 0x4b 0x2a 0x3e 0xd0 0x4f 0x2a 0x3e 0xac 0x4a 0x2a 0x3e 0x84 0x4f 0x2a 0x3e}".
- llvm::StringRef Str(vector_str);
- StripSpaces(Str);
- LStrip(Str, '{');
- RStrip(Str, '}');
- StripSpaces(Str);
-
- char Sep = ' ';
-
- // The first split should give us:
- // ('0x2c', '0x4b 0x2a 0x3e 0xd0 0x4f 0x2a 0x3e 0xac 0x4a 0x2a 0x3e 0x84 0x4f 0x2a 0x3e').
- std::pair<llvm::StringRef, llvm::StringRef> Pair = Str.split(Sep);
- 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.
- while (!Pair.first.getAsInteger(0, byte) && bytes.size() < byte_size) {
- bytes.push_back(byte);
- Pair = Pair.second.split(Sep);
- }
+void RegisterValue::Clear() { m_type = eTypeInvalid; }
- // Check for vector of exact byte_size elements.
- if (bytes.size() != byte_size)
- return false;
+RegisterValue::Type RegisterValue::SetType(const RegisterInfo *reg_info) {
+ // To change the type, we simply copy the data in again, using the new format
+ RegisterValue copy;
+ DataExtractor copy_data;
+ if (copy.CopyValue(*this) && copy.GetData(copy_data))
+ SetValueFromData(reg_info, copy_data, 0, true);
- reg_value->SetBytes(&(bytes.front()), byte_size, eByteOrderLittle);
- return true;
+ return m_type;
}
-Error
-RegisterValue::SetValueFromCString (const RegisterInfo *reg_info, const char *value_str)
-{
- Error error;
- if (reg_info == nullptr)
- {
- error.SetErrorString ("Invalid register info argument.");
- return error;
- }
+Error RegisterValue::SetValueFromData(const RegisterInfo *reg_info,
+ DataExtractor &src,
+ lldb::offset_t src_offset,
+ bool partial_data_ok) {
+ Error error;
- if (value_str == nullptr || value_str[0] == '\0')
- {
- error.SetErrorString ("Invalid c-string value string.");
- return error;
- }
- bool success = false;
- const uint32_t byte_size = reg_info->byte_size;
- static float flt_val;
- static double dbl_val;
- static long double ldbl_val;
- switch (reg_info->encoding)
- {
- case eEncodingInvalid:
- error.SetErrorString ("Invalid encoding.");
- break;
-
- case eEncodingUint:
- if (byte_size <= sizeof (uint64_t))
- {
- uint64_t uval64 = StringConvert::ToUInt64(value_str, UINT64_MAX, 0, &success);
- if (!success)
- error.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string value", value_str);
- else if (!Args::UInt64ValueIsValidForByteSize (uval64, byte_size))
- error.SetErrorStringWithFormat ("value 0x%" PRIx64 " is too large to fit in a %u byte unsigned integer value", uval64, byte_size);
- else
- {
- if (!SetUInt (uval64, reg_info->byte_size))
- error.SetErrorStringWithFormat ("unsupported unsigned integer byte size: %u", byte_size);
- }
- }
- else
- {
- error.SetErrorStringWithFormat ("unsupported unsigned integer byte size: %u", byte_size);
- return error;
- }
- break;
-
- case eEncodingSint:
- if (byte_size <= sizeof (long long))
- {
- uint64_t sval64 = StringConvert::ToSInt64(value_str, INT64_MAX, 0, &success);
- if (!success)
- error.SetErrorStringWithFormat ("'%s' is not a valid signed integer string value", value_str);
- else if (!Args::SInt64ValueIsValidForByteSize (sval64, byte_size))
- error.SetErrorStringWithFormat ("value 0x%" PRIx64 " is too large to fit in a %u byte signed integer value", sval64, byte_size);
- else
- {
- if (!SetUInt (sval64, reg_info->byte_size))
- error.SetErrorStringWithFormat ("unsupported signed integer byte size: %u", byte_size);
- }
- }
- else
- {
- error.SetErrorStringWithFormat ("unsupported signed integer byte size: %u", byte_size);
- return error;
- }
- break;
-
- case eEncodingIEEE754:
- if (byte_size == sizeof (float))
- {
- if (::sscanf (value_str, "%f", &flt_val) == 1)
- {
- m_scalar = flt_val;
- m_type = eTypeFloat;
- }
- else
- error.SetErrorStringWithFormat ("'%s' is not a valid float string value", value_str);
- }
- else if (byte_size == sizeof (double))
- {
- if (::sscanf (value_str, "%lf", &dbl_val) == 1)
- {
- m_scalar = dbl_val;
- m_type = eTypeDouble;
- }
- else
- error.SetErrorStringWithFormat ("'%s' is not a valid float string value", value_str);
- }
- else if (byte_size == sizeof (long double))
- {
- if (::sscanf (value_str, "%Lf", &ldbl_val) == 1)
- {
- m_scalar = ldbl_val;
- m_type = eTypeLongDouble;
- }
- else
- error.SetErrorStringWithFormat ("'%s' is not a valid float string value", value_str);
- }
- else
- {
- error.SetErrorStringWithFormat ("unsupported float byte size: %u", byte_size);
- return error;
- }
- break;
-
- case eEncodingVector:
- if (!ParseVectorEncoding(reg_info, value_str, byte_size, this))
- error.SetErrorString ("unrecognized vector encoding string value.");
- break;
- }
- if (error.Fail())
- m_type = eTypeInvalid;
-
+ if (src.GetByteSize() == 0) {
+ error.SetErrorString("empty data.");
return error;
+ }
+
+ if (reg_info->byte_size == 0) {
+ error.SetErrorString("invalid register info.");
+ return error;
+ }
+
+ uint32_t src_len = src.GetByteSize() - src_offset;
+
+ if (!partial_data_ok && (src_len < reg_info->byte_size)) {
+ error.SetErrorString("not enough data.");
+ return error;
+ }
+
+ // Cap the data length if there is more than enough bytes for this register
+ // value
+ if (src_len > reg_info->byte_size)
+ src_len = reg_info->byte_size;
+
+ // Zero out the value in case we get partial data...
+ memset(buffer.bytes, 0, sizeof(buffer.bytes));
+
+ type128 int128;
+
+ m_type = eTypeInvalid;
+ switch (reg_info->encoding) {
+ case eEncodingInvalid:
+ break;
+ case eEncodingUint:
+ case eEncodingSint:
+ if (reg_info->byte_size == 1)
+ SetUInt8(src.GetMaxU32(&src_offset, src_len));
+ else if (reg_info->byte_size <= 2)
+ SetUInt16(src.GetMaxU32(&src_offset, src_len));
+ else if (reg_info->byte_size <= 4)
+ SetUInt32(src.GetMaxU32(&src_offset, src_len));
+ else if (reg_info->byte_size <= 8)
+ SetUInt64(src.GetMaxU64(&src_offset, src_len));
+ else if (reg_info->byte_size <= 16) {
+ uint64_t data1 = src.GetU64(&src_offset);
+ uint64_t data2 = src.GetU64(&src_offset);
+ if (src.GetByteSize() == eByteOrderBig) {
+ int128.x[0] = data1;
+ int128.x[1] = data2;
+ } else {
+ int128.x[0] = data2;
+ int128.x[1] = data1;
+ }
+ SetUInt128(llvm::APInt(128, 2, int128.x));
+ }
+ break;
+ case eEncodingIEEE754:
+ if (reg_info->byte_size == sizeof(float))
+ SetFloat(src.GetFloat(&src_offset));
+ else if (reg_info->byte_size == sizeof(double))
+ SetDouble(src.GetDouble(&src_offset));
+ else if (reg_info->byte_size == sizeof(long double))
+ SetLongDouble(src.GetLongDouble(&src_offset));
+ break;
+ case eEncodingVector: {
+ m_type = eTypeBytes;
+ buffer.length = reg_info->byte_size;
+ buffer.byte_order = src.GetByteOrder();
+ assert(buffer.length <= kMaxRegisterByteSize);
+ if (buffer.length > kMaxRegisterByteSize)
+ buffer.length = kMaxRegisterByteSize;
+ if (src.CopyByteOrderedData(
+ src_offset, // offset within "src" to start extracting data
+ src_len, // src length
+ buffer.bytes, // dst buffer
+ buffer.length, // dst length
+ buffer.byte_order) == 0) // dst byte order
+ {
+ error.SetErrorStringWithFormat(
+ "failed to copy data for register write of %s", reg_info->name);
+ return error;
+ }
+ }
+ }
+
+ if (m_type == eTypeInvalid)
+ error.SetErrorStringWithFormat(
+ "invalid register value type for register %s", reg_info->name);
+ return error;
+}
+
+static inline void StripSpaces(llvm::StringRef &Str) {
+ while (!Str.empty() && isspace(Str[0]))
+ Str = Str.substr(1);
+ while (!Str.empty() && isspace(Str.back()))
+ Str = Str.substr(0, Str.size() - 1);
+}
+
+static inline void LStrip(llvm::StringRef &Str, char c) {
+ if (!Str.empty() && Str.front() == c)
+ Str = Str.substr(1);
+}
+
+static inline void RStrip(llvm::StringRef &Str, char c) {
+ if (!Str.empty() && Str.back() == c)
+ Str = Str.substr(0, Str.size() - 1);
}
-bool
-RegisterValue::SignExtend (uint32_t sign_bitpos)
-{
- switch (m_type)
- {
- case eTypeInvalid:
- break;
+// Helper function for RegisterValue::SetValueFromCString()
+static bool ParseVectorEncoding(const RegisterInfo *reg_info,
+ const char *vector_str,
+ const uint32_t byte_size,
+ RegisterValue *reg_value) {
+ // Example: vector_str = "{0x2c 0x4b 0x2a 0x3e 0xd0 0x4f 0x2a 0x3e 0xac 0x4a
+ // 0x2a 0x3e 0x84 0x4f 0x2a 0x3e}".
+ llvm::StringRef Str(vector_str);
+ StripSpaces(Str);
+ LStrip(Str, '{');
+ RStrip(Str, '}');
+ StripSpaces(Str);
+
+ char Sep = ' ';
+
+ // The first split should give us:
+ // ('0x2c', '0x4b 0x2a 0x3e 0xd0 0x4f 0x2a 0x3e 0xac 0x4a 0x2a 0x3e 0x84 0x4f
+ // 0x2a 0x3e').
+ std::pair<llvm::StringRef, llvm::StringRef> Pair = Str.split(Sep);
+ 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.
+ while (!Pair.first.getAsInteger(0, byte) && bytes.size() < byte_size) {
+ bytes.push_back(byte);
+ Pair = Pair.second.split(Sep);
+ }
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- return m_scalar.SignExtend(sign_bitpos);
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble:
- case eTypeBytes:
- break;
- }
+ // Check for vector of exact byte_size elements.
+ if (bytes.size() != byte_size)
return false;
-}
-bool
-RegisterValue::CopyValue (const RegisterValue &rhs)
-{
- m_type = rhs.m_type;
- switch (m_type)
- {
- case eTypeInvalid:
- return false;
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble: m_scalar = rhs.m_scalar; break;
- case eTypeBytes:
- assert (rhs.buffer.length <= kMaxRegisterByteSize);
- ::memcpy (buffer.bytes, rhs.buffer.bytes, kMaxRegisterByteSize);
- buffer.length = rhs.buffer.length;
- buffer.byte_order = rhs.buffer.byte_order;
- break;
- }
- return true;
+ reg_value->SetBytes(&(bytes.front()), byte_size, eByteOrderLittle);
+ return true;
}
-uint16_t
-RegisterValue::GetAsUInt16 (uint16_t fail_value, bool *success_ptr) const
-{
- if (success_ptr)
- *success_ptr = true;
-
- switch (m_type)
- {
- default: break;
- case eTypeUInt8:
- case eTypeUInt16: return m_scalar.UShort(fail_value);
- case eTypeBytes:
- {
- switch (buffer.length)
- {
- default: break;
- case 1:
- case 2: return *(const uint16_t *)buffer.bytes;
- }
- }
- break;
- }
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
-}
-
-uint32_t
-RegisterValue::GetAsUInt32 (uint32_t fail_value, bool *success_ptr) const
-{
- if (success_ptr)
- *success_ptr = true;
- switch (m_type)
- {
- default: break;
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble: return m_scalar.UInt(fail_value);
- case eTypeBytes:
- {
- switch (buffer.length)
- {
- default: break;
- case 1:
- case 2:
- case 4: return *(const uint32_t *)buffer.bytes;
- }
- }
- break;
- }
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
-}
-
-uint64_t
-RegisterValue::GetAsUInt64 (uint64_t fail_value, bool *success_ptr) const
-{
- if (success_ptr)
- *success_ptr = true;
- switch (m_type)
- {
- default: break;
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble: return m_scalar.ULongLong(fail_value);
- case eTypeBytes:
- {
- switch (buffer.length)
- {
- default: break;
- case 1:
- case 2:
- case 4:
- case 8: return *(const uint64_t *)buffer.bytes;
- }
- }
- break;
- }
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
-}
-
-llvm::APInt
-RegisterValue::GetAsUInt128 (const llvm::APInt& fail_value, bool *success_ptr) const
-{
- if (success_ptr)
- *success_ptr = true;
- switch (m_type)
- {
- default: break;
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble: return m_scalar.UInt128(fail_value);
- case eTypeBytes:
- {
- switch (buffer.length)
- {
- default:
- break;
- case 1:
- case 2:
- case 4:
- case 8:
- case 16:
- return llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)buffer.bytes)->x);
- }
- }
- break;
- }
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
-}
-
-float
-RegisterValue::GetAsFloat (float fail_value, bool *success_ptr) const
-{
- if (success_ptr)
- *success_ptr = true;
- switch (m_type)
- {
- default: break;
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble:
- return m_scalar.Float(fail_value);
- }
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
-}
-
-double
-RegisterValue::GetAsDouble (double fail_value, bool *success_ptr) const
-{
- if (success_ptr)
- *success_ptr = true;
- switch (m_type)
- {
- default:
- break;
-
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble:
- return m_scalar.Double(fail_value);
- }
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
-}
-
-long double
-RegisterValue::GetAsLongDouble (long double fail_value, bool *success_ptr) const
-{
- if (success_ptr)
- *success_ptr = true;
- switch (m_type)
- {
- default:
- break;
-
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble:
- return m_scalar.LongDouble();
- }
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
-}
-
-const void *
-RegisterValue::GetBytes () const
-{
- switch (m_type)
- {
- case eTypeInvalid: break;
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble: return m_scalar.GetBytes();
- case eTypeBytes: return buffer.bytes;
- }
- return nullptr;
-}
-
-uint32_t
-RegisterValue::GetByteSize () const
-{
- switch (m_type)
- {
- case eTypeInvalid: break;
- case eTypeUInt8: return 1;
- case eTypeUInt16: return 2;
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble: return m_scalar.GetByteSize();
- case eTypeBytes: return buffer.length;
- }
- return 0;
-}
+Error RegisterValue::SetValueFromCString(const RegisterInfo *reg_info,
+ const char *value_str) {
+ Error error;
+ if (reg_info == nullptr) {
+ error.SetErrorString("Invalid register info argument.");
+ return error;
+ }
-bool
-RegisterValue::SetUInt (uint64_t uint, uint32_t byte_size)
-{
- if (byte_size == 0)
- {
- SetUInt64 (uint);
- }
- else if (byte_size == 1)
- {
- SetUInt8 (uint);
- }
- else if (byte_size <= 2)
- {
- SetUInt16 (uint);
- }
- else if (byte_size <= 4)
- {
- SetUInt32 (uint);
- }
- else if (byte_size <= 8)
- {
- SetUInt64 (uint);
- }
- else if (byte_size <= 16)
- {
- SetUInt128 (llvm::APInt(128, uint));
- }
- else
- return false;
- return true;
-}
+ if (value_str == nullptr || value_str[0] == '\0') {
+ error.SetErrorString("Invalid c-string value string.");
+ return error;
+ }
+ bool success = false;
+ const uint32_t byte_size = reg_info->byte_size;
+ static float flt_val;
+ static double dbl_val;
+ static long double ldbl_val;
+ switch (reg_info->encoding) {
+ case eEncodingInvalid:
+ error.SetErrorString("Invalid encoding.");
+ break;
+
+ case eEncodingUint:
+ if (byte_size <= sizeof(uint64_t)) {
+ uint64_t uval64 =
+ StringConvert::ToUInt64(value_str, UINT64_MAX, 0, &success);
+ if (!success)
+ error.SetErrorStringWithFormat(
+ "'%s' is not a valid unsigned integer string value", value_str);
+ else if (!Args::UInt64ValueIsValidForByteSize(uval64, byte_size))
+ error.SetErrorStringWithFormat(
+ "value 0x%" PRIx64
+ " is too large to fit in a %u byte unsigned integer value",
+ uval64, byte_size);
+ else {
+ if (!SetUInt(uval64, reg_info->byte_size))
+ error.SetErrorStringWithFormat(
+ "unsupported unsigned integer byte size: %u", byte_size);
+ }
+ } else {
+ error.SetErrorStringWithFormat(
+ "unsupported unsigned integer byte size: %u", byte_size);
+ return error;
+ }
+ break;
+
+ case eEncodingSint:
+ if (byte_size <= sizeof(long long)) {
+ uint64_t sval64 =
+ StringConvert::ToSInt64(value_str, INT64_MAX, 0, &success);
+ if (!success)
+ error.SetErrorStringWithFormat(
+ "'%s' is not a valid signed integer string value", value_str);
+ else if (!Args::SInt64ValueIsValidForByteSize(sval64, byte_size))
+ error.SetErrorStringWithFormat(
+ "value 0x%" PRIx64
+ " is too large to fit in a %u byte signed integer value",
+ sval64, byte_size);
+ else {
+ if (!SetUInt(sval64, reg_info->byte_size))
+ error.SetErrorStringWithFormat(
+ "unsupported signed integer byte size: %u", byte_size);
+ }
+ } else {
+ error.SetErrorStringWithFormat("unsupported signed integer byte size: %u",
+ byte_size);
+ return error;
+ }
+ break;
+
+ case eEncodingIEEE754:
+ if (byte_size == sizeof(float)) {
+ if (::sscanf(value_str, "%f", &flt_val) == 1) {
+ m_scalar = flt_val;
+ m_type = eTypeFloat;
+ } else
+ error.SetErrorStringWithFormat("'%s' is not a valid float string value",
+ value_str);
+ } else if (byte_size == sizeof(double)) {
+ if (::sscanf(value_str, "%lf", &dbl_val) == 1) {
+ m_scalar = dbl_val;
+ m_type = eTypeDouble;
+ } else
+ error.SetErrorStringWithFormat("'%s' is not a valid float string value",
+ value_str);
+ } else if (byte_size == sizeof(long double)) {
+ if (::sscanf(value_str, "%Lf", &ldbl_val) == 1) {
+ m_scalar = ldbl_val;
+ m_type = eTypeLongDouble;
+ } else
+ error.SetErrorStringWithFormat("'%s' is not a valid float string value",
+ value_str);
+ } else {
+ error.SetErrorStringWithFormat("unsupported float byte size: %u",
+ byte_size);
+ return error;
+ }
+ break;
+
+ case eEncodingVector:
+ if (!ParseVectorEncoding(reg_info, value_str, byte_size, this))
+ error.SetErrorString("unrecognized vector encoding string value.");
+ break;
+ }
+ if (error.Fail())
+ m_type = eTypeInvalid;
-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 (bytes && length > 0)
- {
- assert (length <= sizeof (buffer.bytes) && "Storing too many bytes in a RegisterValue.");
- m_type = eTypeBytes;
- buffer.length = length;
- memcpy (buffer.bytes, bytes, length);
- buffer.byte_order = byte_order;
- }
- else
- {
- m_type = eTypeInvalid;
- buffer.length = 0;
- }
+ return error;
}
-bool
-RegisterValue::operator == (const RegisterValue &rhs) const
-{
- if (m_type == rhs.m_type)
- {
- switch (m_type)
- {
- case eTypeInvalid: return true;
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble: return m_scalar == rhs.m_scalar;
- case eTypeBytes:
- if (buffer.length != rhs.buffer.length)
- return false;
- else
- {
- uint8_t length = buffer.length;
- if (length > kMaxRegisterByteSize)
- length = kMaxRegisterByteSize;
- return memcmp (buffer.bytes, rhs.buffer.bytes, length) == 0;
- }
- break;
- }
- }
+bool RegisterValue::SignExtend(uint32_t sign_bitpos) {
+ switch (m_type) {
+ case eTypeInvalid:
+ break;
+
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ return m_scalar.SignExtend(sign_bitpos);
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ case eTypeBytes:
+ break;
+ }
+ return false;
+}
+
+bool RegisterValue::CopyValue(const RegisterValue &rhs) {
+ m_type = rhs.m_type;
+ switch (m_type) {
+ case eTypeInvalid:
return false;
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ m_scalar = rhs.m_scalar;
+ break;
+ case eTypeBytes:
+ assert(rhs.buffer.length <= kMaxRegisterByteSize);
+ ::memcpy(buffer.bytes, rhs.buffer.bytes, kMaxRegisterByteSize);
+ buffer.length = rhs.buffer.length;
+ buffer.byte_order = rhs.buffer.byte_order;
+ break;
+ }
+ return true;
+}
+
+uint16_t RegisterValue::GetAsUInt16(uint16_t fail_value,
+ bool *success_ptr) const {
+ if (success_ptr)
+ *success_ptr = true;
+
+ switch (m_type) {
+ default:
+ break;
+ case eTypeUInt8:
+ case eTypeUInt16:
+ return m_scalar.UShort(fail_value);
+ case eTypeBytes: {
+ switch (buffer.length) {
+ default:
+ break;
+ case 1:
+ case 2:
+ return *(const uint16_t *)buffer.bytes;
+ }
+ } break;
+ }
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+}
+
+uint32_t RegisterValue::GetAsUInt32(uint32_t fail_value,
+ bool *success_ptr) const {
+ if (success_ptr)
+ *success_ptr = true;
+ switch (m_type) {
+ default:
+ break;
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar.UInt(fail_value);
+ case eTypeBytes: {
+ switch (buffer.length) {
+ default:
+ break;
+ case 1:
+ case 2:
+ case 4:
+ return *(const uint32_t *)buffer.bytes;
+ }
+ } break;
+ }
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+}
+
+uint64_t RegisterValue::GetAsUInt64(uint64_t fail_value,
+ bool *success_ptr) const {
+ if (success_ptr)
+ *success_ptr = true;
+ switch (m_type) {
+ default:
+ break;
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar.ULongLong(fail_value);
+ case eTypeBytes: {
+ switch (buffer.length) {
+ default:
+ break;
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ return *(const uint64_t *)buffer.bytes;
+ }
+ } break;
+ }
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+}
+
+llvm::APInt RegisterValue::GetAsUInt128(const llvm::APInt &fail_value,
+ bool *success_ptr) const {
+ if (success_ptr)
+ *success_ptr = true;
+ switch (m_type) {
+ default:
+ break;
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar.UInt128(fail_value);
+ case eTypeBytes: {
+ switch (buffer.length) {
+ default:
+ break;
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ case 16:
+ return llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
+ ((const type128 *)buffer.bytes)->x);
+ }
+ } break;
+ }
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+}
+
+float RegisterValue::GetAsFloat(float fail_value, bool *success_ptr) const {
+ if (success_ptr)
+ *success_ptr = true;
+ switch (m_type) {
+ default:
+ break;
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar.Float(fail_value);
+ }
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+}
+
+double RegisterValue::GetAsDouble(double fail_value, bool *success_ptr) const {
+ if (success_ptr)
+ *success_ptr = true;
+ switch (m_type) {
+ default:
+ break;
+
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar.Double(fail_value);
+ }
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+}
+
+long double RegisterValue::GetAsLongDouble(long double fail_value,
+ bool *success_ptr) const {
+ if (success_ptr)
+ *success_ptr = true;
+ switch (m_type) {
+ default:
+ break;
+
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar.LongDouble();
+ }
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+}
+
+const void *RegisterValue::GetBytes() const {
+ switch (m_type) {
+ case eTypeInvalid:
+ break;
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar.GetBytes();
+ case eTypeBytes:
+ return buffer.bytes;
+ }
+ return nullptr;
+}
+
+uint32_t RegisterValue::GetByteSize() const {
+ switch (m_type) {
+ case eTypeInvalid:
+ break;
+ case eTypeUInt8:
+ return 1;
+ case eTypeUInt16:
+ return 2;
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar.GetByteSize();
+ case eTypeBytes:
+ return buffer.length;
+ }
+ return 0;
+}
+
+bool RegisterValue::SetUInt(uint64_t uint, uint32_t byte_size) {
+ if (byte_size == 0) {
+ SetUInt64(uint);
+ } else if (byte_size == 1) {
+ SetUInt8(uint);
+ } else if (byte_size <= 2) {
+ SetUInt16(uint);
+ } else if (byte_size <= 4) {
+ SetUInt32(uint);
+ } else if (byte_size <= 8) {
+ SetUInt64(uint);
+ } else if (byte_size <= 16) {
+ SetUInt128(llvm::APInt(128, uint));
+ } else
+ return false;
+ return true;
}
-bool
-RegisterValue::operator != (const RegisterValue &rhs) const
-{
- if (m_type != rhs.m_type)
- return true;
- switch (m_type)
- {
- case eTypeInvalid: return false;
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble: return m_scalar != rhs.m_scalar;
- case eTypeBytes:
- if (buffer.length != rhs.buffer.length)
- {
- return true;
- }
- else
- {
- uint8_t length = buffer.length;
- if (length > kMaxRegisterByteSize)
- length = kMaxRegisterByteSize;
- return memcmp (buffer.bytes, rhs.buffer.bytes, length) != 0;
- }
- break;
- }
- return true;
+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 (bytes && length > 0) {
+ assert(length <= sizeof(buffer.bytes) &&
+ "Storing too many bytes in a RegisterValue.");
+ m_type = eTypeBytes;
+ buffer.length = length;
+ memcpy(buffer.bytes, bytes, length);
+ buffer.byte_order = byte_order;
+ } else {
+ m_type = eTypeInvalid;
+ buffer.length = 0;
+ }
}
-bool
-RegisterValue::ClearBit (uint32_t bit)
-{
- switch (m_type)
- {
- case eTypeInvalid:
- break;
-
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- if (bit < (GetByteSize() * 8))
- {
- return m_scalar.ClearBit(bit);
- }
- break;
-
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble:
- break;
-
- case eTypeBytes:
- if (buffer.byte_order == eByteOrderBig || buffer.byte_order == eByteOrderLittle)
- {
- uint32_t byte_idx;
- if (buffer.byte_order == eByteOrderBig)
- byte_idx = buffer.length - (bit / 8) - 1;
- else
- byte_idx = bit / 8;
-
- const uint32_t byte_bit = bit % 8;
- if (byte_idx < buffer.length)
- {
- buffer.bytes[byte_idx] &= ~(1u << byte_bit);
- return true;
- }
- }
- break;
+bool RegisterValue::operator==(const RegisterValue &rhs) const {
+ if (m_type == rhs.m_type) {
+ switch (m_type) {
+ case eTypeInvalid:
+ return true;
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar == rhs.m_scalar;
+ case eTypeBytes:
+ if (buffer.length != rhs.buffer.length)
+ return false;
+ else {
+ uint8_t length = buffer.length;
+ if (length > kMaxRegisterByteSize)
+ length = kMaxRegisterByteSize;
+ return memcmp(buffer.bytes, rhs.buffer.bytes, length) == 0;
+ }
+ break;
}
- return false;
+ }
+ return false;
}
-bool
-RegisterValue::SetBit (uint32_t bit)
-{
- switch (m_type)
- {
- case eTypeInvalid:
- break;
-
- case eTypeUInt8:
- case eTypeUInt16:
- case eTypeUInt32:
- case eTypeUInt64:
- case eTypeUInt128:
- if (bit < (GetByteSize() * 8))
- {
- return m_scalar.SetBit(bit);
- }
- break;
-
- case eTypeFloat:
- case eTypeDouble:
- case eTypeLongDouble:
- break;
-
- case eTypeBytes:
- if (buffer.byte_order == eByteOrderBig || buffer.byte_order == eByteOrderLittle)
- {
- uint32_t byte_idx;
- if (buffer.byte_order == eByteOrderBig)
- byte_idx = buffer.length - (bit / 8) - 1;
- else
- byte_idx = bit / 8;
-
- const uint32_t byte_bit = bit % 8;
- if (byte_idx < buffer.length)
- {
- buffer.bytes[byte_idx] |= (1u << byte_bit);
- return true;
- }
- }
- break;
- }
+bool RegisterValue::operator!=(const RegisterValue &rhs) const {
+ if (m_type != rhs.m_type)
+ return true;
+ switch (m_type) {
+ case eTypeInvalid:
return false;
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ return m_scalar != rhs.m_scalar;
+ case eTypeBytes:
+ if (buffer.length != rhs.buffer.length) {
+ return true;
+ } else {
+ uint8_t length = buffer.length;
+ if (length > kMaxRegisterByteSize)
+ length = kMaxRegisterByteSize;
+ return memcmp(buffer.bytes, rhs.buffer.bytes, length) != 0;
+ }
+ break;
+ }
+ return true;
+}
+
+bool RegisterValue::ClearBit(uint32_t bit) {
+ switch (m_type) {
+ case eTypeInvalid:
+ break;
+
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ if (bit < (GetByteSize() * 8)) {
+ return m_scalar.ClearBit(bit);
+ }
+ break;
+
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ break;
+
+ case eTypeBytes:
+ if (buffer.byte_order == eByteOrderBig ||
+ buffer.byte_order == eByteOrderLittle) {
+ uint32_t byte_idx;
+ if (buffer.byte_order == eByteOrderBig)
+ byte_idx = buffer.length - (bit / 8) - 1;
+ else
+ byte_idx = bit / 8;
+
+ const uint32_t byte_bit = bit % 8;
+ if (byte_idx < buffer.length) {
+ buffer.bytes[byte_idx] &= ~(1u << byte_bit);
+ return true;
+ }
+ }
+ break;
+ }
+ return false;
+}
+
+bool RegisterValue::SetBit(uint32_t bit) {
+ switch (m_type) {
+ case eTypeInvalid:
+ break;
+
+ case eTypeUInt8:
+ case eTypeUInt16:
+ case eTypeUInt32:
+ case eTypeUInt64:
+ case eTypeUInt128:
+ if (bit < (GetByteSize() * 8)) {
+ return m_scalar.SetBit(bit);
+ }
+ break;
+
+ case eTypeFloat:
+ case eTypeDouble:
+ case eTypeLongDouble:
+ break;
+
+ case eTypeBytes:
+ if (buffer.byte_order == eByteOrderBig ||
+ buffer.byte_order == eByteOrderLittle) {
+ uint32_t byte_idx;
+ if (buffer.byte_order == eByteOrderBig)
+ byte_idx = buffer.length - (bit / 8) - 1;
+ else
+ byte_idx = bit / 8;
+
+ const uint32_t byte_bit = bit % 8;
+ if (byte_idx < buffer.length) {
+ buffer.bytes[byte_idx] |= (1u << byte_bit);
+ return true;
+ }
+ }
+ break;
+ }
+ return false;
}
Modified: lldb/trunk/source/Core/RegularExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegularExpression.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegularExpression.cpp (original)
+++ lldb/trunk/source/Core/RegularExpression.cpp Tue Sep 6 15:57:50 2016
@@ -25,46 +25,37 @@
// everywhere.
//----------------------------------------------------------------------
#if defined(REG_ENHANCED)
-#define DEFAULT_COMPILE_FLAGS (REG_ENHANCED|REG_EXTENDED)
+#define DEFAULT_COMPILE_FLAGS (REG_ENHANCED | REG_EXTENDED)
#else
#define DEFAULT_COMPILE_FLAGS (REG_EXTENDED)
#endif
using namespace lldb_private;
-RegularExpression::RegularExpression() :
- m_re(),
- m_comp_err (1),
- m_preg()
-{
- memset(&m_preg, 0, sizeof(m_preg));
+RegularExpression::RegularExpression() : m_re(), m_comp_err(1), m_preg() {
+ memset(&m_preg, 0, sizeof(m_preg));
}
//----------------------------------------------------------------------
// Constructor that compiles "re" using "flags" and stores the
// resulting compiled regular expression into this object.
//----------------------------------------------------------------------
-RegularExpression::RegularExpression(const char* re) :
- m_re(),
- m_comp_err (1),
- m_preg()
-{
- memset(&m_preg,0,sizeof(m_preg));
- Compile(re);
+RegularExpression::RegularExpression(const char *re)
+ : m_re(), m_comp_err(1), m_preg() {
+ memset(&m_preg, 0, sizeof(m_preg));
+ Compile(re);
}
-RegularExpression::RegularExpression(const RegularExpression &rhs)
-{
- memset(&m_preg,0,sizeof(m_preg));
- Compile(rhs.GetText());
+RegularExpression::RegularExpression(const RegularExpression &rhs) {
+ memset(&m_preg, 0, sizeof(m_preg));
+ Compile(rhs.GetText());
}
-const RegularExpression &
-RegularExpression::operator= (const RegularExpression &rhs)
-{
- if (&rhs != this)
- Compile (rhs.GetText());
- return *this;
+const RegularExpression &RegularExpression::
+operator=(const RegularExpression &rhs) {
+ if (&rhs != this)
+ Compile(rhs.GetText());
+ return *this;
}
//----------------------------------------------------------------------
@@ -73,10 +64,7 @@ RegularExpression::operator= (const Regu
// Any previously compiled regular expression contained in this
// object will be freed.
//----------------------------------------------------------------------
-RegularExpression::~RegularExpression()
-{
- Free();
-}
+RegularExpression::~RegularExpression() { Free(); }
//----------------------------------------------------------------------
// Compile a regular expression using the supplied regular
@@ -90,23 +78,18 @@ RegularExpression::~RegularExpression()
// True if the regular expression compiles successfully, false
// otherwise.
//----------------------------------------------------------------------
-bool
-RegularExpression::Compile(const char* re)
-{
- Free();
-
- if (re && re[0])
- {
- m_re = re;
- m_comp_err = ::regcomp (&m_preg, re, DEFAULT_COMPILE_FLAGS);
- }
- else
- {
- // No valid regular expression
- m_comp_err = 1;
- }
+bool RegularExpression::Compile(const char *re) {
+ Free();
- return m_comp_err == 0;
+ if (re && re[0]) {
+ m_re = re;
+ m_comp_err = ::regcomp(&m_preg, re, DEFAULT_COMPILE_FLAGS);
+ } else {
+ // No valid regular expression
+ m_comp_err = 1;
+ }
+
+ return m_comp_err == 0;
}
//----------------------------------------------------------------------
@@ -117,145 +100,109 @@ RegularExpression::Compile(const char* r
// values that are present in "match_ptr". The regular expression
// will be executed using the "execute_flags".
//---------------------------------------------------------------------
-bool
-RegularExpression::Execute (const char* s, Match *match) const
-{
- int err = 1;
- if (s != nullptr && m_comp_err == 0)
- {
- if (match)
- {
- err = ::regexec (&m_preg,
- s,
- match->GetSize(),
- match->GetData(),
- 0);
- }
- else
- {
- err = ::regexec(&m_preg,
- s,
- 0,
- nullptr,
- 0);
- }
- }
-
- if (err != 0)
- {
- // The regular expression didn't compile, so clear the matches
- if (match)
- match->Clear();
- return false;
- }
- return true;
-}
-
-bool
-RegularExpression::Match::GetMatchAtIndex (const char* s, uint32_t idx, std::string& match_str) const
-{
- llvm::StringRef match_str_ref;
- if (GetMatchAtIndex(s, idx, match_str_ref))
- {
- match_str = match_str_ref.str();
- return true;
- }
+bool RegularExpression::Execute(const char *s, Match *match) const {
+ int err = 1;
+ if (s != nullptr && m_comp_err == 0) {
+ if (match) {
+ err = ::regexec(&m_preg, s, match->GetSize(), match->GetData(), 0);
+ } else {
+ err = ::regexec(&m_preg, s, 0, nullptr, 0);
+ }
+ }
+
+ if (err != 0) {
+ // The regular expression didn't compile, so clear the matches
+ if (match)
+ match->Clear();
return false;
+ }
+ return true;
}
-bool
-RegularExpression::Match::GetMatchAtIndex (const char* s, uint32_t idx, llvm::StringRef& match_str) const
-{
- if (idx < m_matches.size())
- {
- if (m_matches[idx].rm_eo == -1 && m_matches[idx].rm_so == -1)
- return false;
-
- if (m_matches[idx].rm_eo == m_matches[idx].rm_so)
- {
- // Matched the empty string...
- match_str = llvm::StringRef();
- return true;
- }
- else if (m_matches[idx].rm_eo > m_matches[idx].rm_so)
- {
- match_str = llvm::StringRef (s + m_matches[idx].rm_so, m_matches[idx].rm_eo - m_matches[idx].rm_so);
- return true;
- }
- }
- return false;
+bool RegularExpression::Match::GetMatchAtIndex(const char *s, uint32_t idx,
+ std::string &match_str) const {
+ llvm::StringRef match_str_ref;
+ if (GetMatchAtIndex(s, idx, match_str_ref)) {
+ match_str = match_str_ref.str();
+ return true;
+ }
+ return false;
}
-bool
-RegularExpression::Match::GetMatchSpanningIndices (const char* s, uint32_t idx1, uint32_t idx2, llvm::StringRef& match_str) const
-{
- if (idx1 < m_matches.size() && idx2 < m_matches.size())
- {
- if (m_matches[idx1].rm_so == m_matches[idx2].rm_eo)
- {
- // Matched the empty string...
- match_str = llvm::StringRef();
- return true;
- }
- else if (m_matches[idx1].rm_so < m_matches[idx2].rm_eo)
- {
- match_str = llvm::StringRef (s + m_matches[idx1].rm_so, m_matches[idx2].rm_eo - m_matches[idx1].rm_so);
- return true;
- }
+bool RegularExpression::Match::GetMatchAtIndex(
+ const char *s, uint32_t idx, llvm::StringRef &match_str) const {
+ if (idx < m_matches.size()) {
+ if (m_matches[idx].rm_eo == -1 && m_matches[idx].rm_so == -1)
+ return false;
+
+ if (m_matches[idx].rm_eo == m_matches[idx].rm_so) {
+ // Matched the empty string...
+ match_str = llvm::StringRef();
+ return true;
+ } else if (m_matches[idx].rm_eo > m_matches[idx].rm_so) {
+ match_str = llvm::StringRef(s + m_matches[idx].rm_so,
+ m_matches[idx].rm_eo - m_matches[idx].rm_so);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool RegularExpression::Match::GetMatchSpanningIndices(
+ const char *s, uint32_t idx1, uint32_t idx2,
+ llvm::StringRef &match_str) const {
+ if (idx1 < m_matches.size() && idx2 < m_matches.size()) {
+ if (m_matches[idx1].rm_so == m_matches[idx2].rm_eo) {
+ // Matched the empty string...
+ match_str = llvm::StringRef();
+ return true;
+ } else if (m_matches[idx1].rm_so < m_matches[idx2].rm_eo) {
+ match_str =
+ llvm::StringRef(s + m_matches[idx1].rm_so,
+ m_matches[idx2].rm_eo - m_matches[idx1].rm_so);
+ return true;
}
- return false;
+ }
+ return false;
}
//----------------------------------------------------------------------
// Returns true if the regular expression compiled and is ready
// for execution.
//----------------------------------------------------------------------
-bool
-RegularExpression::IsValid () const
-{
- return m_comp_err == 0;
-}
+bool RegularExpression::IsValid() const { return m_comp_err == 0; }
//----------------------------------------------------------------------
// Returns the text that was used to compile the current regular
// expression.
//----------------------------------------------------------------------
-const char*
-RegularExpression::GetText () const
-{
- return (m_re.empty() ? nullptr : m_re.c_str());
+const char *RegularExpression::GetText() const {
+ return (m_re.empty() ? nullptr : m_re.c_str());
}
//----------------------------------------------------------------------
// Free any contained compiled regular expressions.
//----------------------------------------------------------------------
-void
-RegularExpression::Free()
-{
- if (m_comp_err == 0)
- {
- m_re.clear();
- regfree(&m_preg);
- // Set a compile error since we no longer have a valid regex
- m_comp_err = 1;
- }
-}
+void RegularExpression::Free() {
+ if (m_comp_err == 0) {
+ m_re.clear();
+ regfree(&m_preg);
+ // Set a compile error since we no longer have a valid regex
+ m_comp_err = 1;
+ }
+}
+
+size_t RegularExpression::GetErrorAsCString(char *err_str,
+ size_t err_str_max_len) const {
+ if (m_comp_err == 0) {
+ if (err_str && err_str_max_len)
+ *err_str = '\0';
+ return 0;
+ }
-size_t
-RegularExpression::GetErrorAsCString (char *err_str, size_t err_str_max_len) const
-{
- if (m_comp_err == 0)
- {
- if (err_str && err_str_max_len)
- *err_str = '\0';
- return 0;
- }
-
- return ::regerror (m_comp_err, &m_preg, err_str, err_str_max_len);
+ return ::regerror(m_comp_err, &m_preg, err_str, err_str_max_len);
}
-bool
-RegularExpression::operator < (const RegularExpression& rhs) const
-{
- return (m_re < rhs.m_re);
+bool RegularExpression::operator<(const RegularExpression &rhs) const {
+ return (m_re < rhs.m_re);
}
Modified: lldb/trunk/source/Core/Scalar.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Scalar.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/Scalar.cpp (original)
+++ lldb/trunk/source/Core/Scalar.cpp Tue Sep 6 15:57:50 2016
@@ -19,12 +19,12 @@
#include "llvm/ADT/SmallString.h"
// Project includes
-#include "lldb/Interpreter/Args.h"
+#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Error.h"
#include "lldb/Core/Stream.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Host/Endian.h"
#include "lldb/Host/StringConvert.h"
+#include "lldb/Interpreter/Args.h"
#include "Plugins/Process/Utility/InstructionUtils.h"
@@ -35,63 +35,57 @@ using namespace lldb_private;
// 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
- const Scalar& rhs, // The const right hand side object
- Scalar& temp_value, // A modifiable temp value than can be used to hold either the promoted lhs or rhs object
- const Scalar* &promoted_lhs_ptr, // Pointer to the resulting possibly promoted value of lhs (at most one of lhs/rhs will get promoted)
- const Scalar* &promoted_rhs_ptr // Pointer to the resulting possibly promoted value of rhs (at most one of 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.
- promoted_lhs_ptr = &lhs;
- promoted_rhs_ptr = &rhs;
- // Extract the types of both the right and left hand side values
- Scalar::Type lhs_type = lhs.GetType();
- Scalar::Type rhs_type = rhs.GetType();
-
- if (lhs_type > rhs_type)
- {
- // Right hand side need to be promoted
- temp_value = rhs; // Copy right hand side into the temp value
- if (temp_value.Promote(lhs_type)) // Promote it
- promoted_rhs_ptr = &temp_value; // Update the pointer for the promoted right hand side
- }
- else if (lhs_type < rhs_type)
- {
- // Left hand side need to be promoted
- temp_value = lhs; // Copy left hand side value into the temp value
- if (temp_value.Promote(rhs_type)) // Promote it
- promoted_lhs_ptr = &temp_value; // Update the pointer for the promoted left hand side
- }
-
- // Make sure our type promotion worked as expected
- if (promoted_lhs_ptr->GetType() == promoted_rhs_ptr->GetType())
- return promoted_lhs_ptr->GetType(); // Return the resulting max type
-
- // Return the void type (zero) if we fail to promote either of the values.
- return Scalar::e_void;
-}
-
-Scalar::Scalar() :
- m_type(e_void),
- m_float((float)0)
-{
-}
-
-Scalar::Scalar(const Scalar& rhs) :
- m_type(rhs.m_type),
- m_integer(rhs.m_integer),
- m_float(rhs.m_float)
-{
+static Scalar::Type PromoteToMaxType(
+ const Scalar &lhs, // The const left hand side object
+ const Scalar &rhs, // The const right hand side object
+ Scalar &temp_value, // A modifiable temp value than can be used to hold
+ // either the promoted lhs or rhs object
+ const Scalar *&promoted_lhs_ptr, // Pointer to the resulting possibly
+ // promoted value of lhs (at most one of
+ // lhs/rhs will get promoted)
+ const Scalar *&promoted_rhs_ptr // Pointer to the resulting possibly
+ // promoted value of rhs (at most one of
+ // 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.
+ promoted_lhs_ptr = &lhs;
+ promoted_rhs_ptr = &rhs;
+ // Extract the types of both the right and left hand side values
+ Scalar::Type lhs_type = lhs.GetType();
+ Scalar::Type rhs_type = rhs.GetType();
+
+ if (lhs_type > rhs_type) {
+ // Right hand side need to be promoted
+ temp_value = rhs; // Copy right hand side into the temp value
+ if (temp_value.Promote(lhs_type)) // Promote it
+ promoted_rhs_ptr =
+ &temp_value; // Update the pointer for the promoted right hand side
+ } else if (lhs_type < rhs_type) {
+ // Left hand side need to be promoted
+ temp_value = lhs; // Copy left hand side value into the temp value
+ if (temp_value.Promote(rhs_type)) // Promote it
+ promoted_lhs_ptr =
+ &temp_value; // Update the pointer for the promoted left hand side
+ }
+
+ // Make sure our type promotion worked as expected
+ if (promoted_lhs_ptr->GetType() == promoted_rhs_ptr->GetType())
+ return promoted_lhs_ptr->GetType(); // Return the resulting max type
+
+ // Return the void type (zero) if we fail to promote either of the values.
+ return Scalar::e_void;
}
-//Scalar::Scalar(const RegisterValue& reg) :
+Scalar::Scalar() : m_type(e_void), m_float((float)0) {}
+
+Scalar::Scalar(const Scalar &rhs)
+ : m_type(rhs.m_type), m_integer(rhs.m_integer), m_float(rhs.m_float) {}
+
+// Scalar::Scalar(const RegisterValue& reg) :
// m_type(e_void),
// m_data()
//{
@@ -103,7 +97,8 @@ Scalar::Scalar(const Scalar& rhs) :
// case 1: m_type = e_uint; m_data.uint = reg.value.uint8; break;
// case 2: m_type = e_uint; m_data.uint = reg.value.uint16; break;
// case 4: m_type = e_uint; m_data.uint = reg.value.uint32; break;
-// case 8: m_type = e_ulonglong; m_data.ulonglong = reg.value.uint64; break;
+// case 8: m_type = e_ulonglong; m_data.ulonglong = reg.value.uint64;
+// break;
// break;
// }
// break;
@@ -114,7 +109,8 @@ Scalar::Scalar(const Scalar& rhs) :
// case 1: m_type = e_sint; m_data.sint = reg.value.sint8; break;
// case 2: m_type = e_sint; m_data.sint = reg.value.sint16; break;
// case 4: m_type = e_sint; m_data.sint = reg.value.sint32; break;
-// case 8: m_type = e_slonglong; m_data.slonglong = reg.value.sint64; break;
+// case 8: m_type = e_slonglong; m_data.slonglong = reg.value.sint64;
+// break;
// break;
// }
// break;
@@ -132,1273 +128,702 @@ Scalar::Scalar(const Scalar& rhs) :
// }
//}
-bool
-Scalar::GetData (DataExtractor &data, size_t limit_byte_size) const
-{
- size_t byte_size = GetByteSize();
- if (byte_size > 0)
- {
- const uint8_t *bytes = reinterpret_cast<const uint8_t *>(GetBytes());
-
- 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...
- 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
- bytes += byte_size - limit_byte_size;
- byte_size = limit_byte_size;
- }
- }
-
- data.SetData(bytes, byte_size, endian::InlHostByteOrder());
- return true;
+bool Scalar::GetData(DataExtractor &data, size_t limit_byte_size) const {
+ size_t byte_size = GetByteSize();
+ if (byte_size > 0) {
+ const uint8_t *bytes = reinterpret_cast<const uint8_t *>(GetBytes());
+
+ 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...
+ 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
+ bytes += byte_size - limit_byte_size;
+ byte_size = limit_byte_size;
+ }
}
- data.Clear();
- return false;
+
+ data.SetData(bytes, byte_size, endian::InlHostByteOrder());
+ return true;
+ }
+ data.Clear();
+ return false;
+}
+
+const void *Scalar::GetBytes() const {
+ const uint64_t *apint_words;
+ const uint8_t *bytes;
+ static float_t flt_val;
+ static double_t dbl_val;
+ static uint64_t swapped_words[4];
+ 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:
+ 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.
+ if (endian::InlHostByteOrder() == eByteOrderBig) {
+ size_t byte_size = m_integer.getBitWidth() / 8;
+ if (byte_size < 8)
+ bytes += 8 - byte_size;
+ }
+ return bytes;
+ case e_sint128:
+ case e_uint128:
+ apint_words = m_integer.getRawData();
+ // getRawData always returns a pointer to an array of two uint64_t values,
+ // where the least-significant word always comes first. On big-endian
+ // systems we need to swap the two words.
+ if (endian::InlHostByteOrder() == eByteOrderBig) {
+ swapped_words[0] = apint_words[1];
+ swapped_words[1] = apint_words[0];
+ apint_words = swapped_words;
+ }
+ return reinterpret_cast<const void *>(apint_words);
+ case e_sint256:
+ case e_uint256:
+ apint_words = m_integer.getRawData();
+ // getRawData always returns a pointer to an array of four uint64_t values,
+ // where the least-significant word always comes first. On big-endian
+ // systems we need to swap the four words.
+ if (endian::InlHostByteOrder() == eByteOrderBig) {
+ swapped_words[0] = apint_words[3];
+ swapped_words[1] = apint_words[2];
+ swapped_words[2] = apint_words[1];
+ swapped_words[3] = apint_words[0];
+ apint_words = swapped_words;
+ }
+ return reinterpret_cast<const void *>(apint_words);
+ case e_float:
+ flt_val = m_float.convertToFloat();
+ return reinterpret_cast<const void *>(&flt_val);
+ case e_double:
+ dbl_val = m_float.convertToDouble();
+ return reinterpret_cast<const void *>(&dbl_val);
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ apint_words = ldbl_val.getRawData();
+ // getRawData always returns a pointer to an array of two uint64_t values,
+ // where the least-significant word always comes first. On big-endian
+ // systems we need to swap the two words.
+ if (endian::InlHostByteOrder() == eByteOrderBig) {
+ swapped_words[0] = apint_words[1];
+ swapped_words[1] = apint_words[0];
+ apint_words = swapped_words;
+ }
+ return reinterpret_cast<const void *>(apint_words);
+ }
+ return nullptr;
+}
+
+size_t Scalar::GetByteSize() const {
+ 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:
+ return (m_integer.getBitWidth() / 8);
+ case e_float:
+ return sizeof(float_t);
+ case e_double:
+ return sizeof(double_t);
+ case e_long_double:
+ return sizeof(long_double_t);
+ }
+ return 0;
+}
+
+bool Scalar::IsZero() const {
+ llvm::APInt zero_int = llvm::APInt::getNullValue(m_integer.getBitWidth() / 8);
+ 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:
+ return llvm::APInt::isSameValue(zero_int, m_integer);
+ case e_float:
+ case e_double:
+ case e_long_double:
+ return m_float.isZero();
+ }
+ return false;
+}
+
+void Scalar::GetValue(Stream *s, bool show_type) const {
+ if (show_type)
+ s->Printf("(%s) ", GetTypeAsCString());
+
+ switch (m_type) {
+ case e_void:
+ break;
+ case e_sint:
+ case e_slong:
+ case e_slonglong:
+ case e_sint128:
+ case e_sint256:
+ s->PutCString(m_integer.toString(10, true).c_str());
+ break;
+ case e_uint:
+ case e_ulong:
+ case e_ulonglong:
+ case e_uint128:
+ case e_uint256:
+ s->PutCString(m_integer.toString(10, false).c_str());
+ break;
+ case e_float:
+ case e_double:
+ case e_long_double:
+ llvm::SmallString<24> string;
+ m_float.toString(string);
+ s->Printf("%s", string.c_str());
+ break;
+ }
+}
+
+const char *Scalar::GetTypeAsCString() const {
+ switch (m_type) {
+ case e_void:
+ return "void";
+ case e_sint:
+ return "int";
+ case e_uint:
+ return "unsigned int";
+ case e_slong:
+ return "long";
+ case e_ulong:
+ return "unsigned long";
+ case e_slonglong:
+ return "long long";
+ case e_ulonglong:
+ return "unsigned long long";
+ case e_sint128:
+ return "int128_t";
+ case e_uint128:
+ return "unsigned int128_t";
+ case e_sint256:
+ return "int256_t";
+ case e_uint256:
+ return "unsigned int256_t";
+ case e_float:
+ return "float";
+ case e_double:
+ return "double";
+ case e_long_double:
+ return "long double";
+ }
+ return "<invalid Scalar type>";
+}
+
+Scalar &Scalar::operator=(const Scalar &rhs) {
+ if (this != &rhs) {
+ m_type = rhs.m_type;
+ m_integer = llvm::APInt(rhs.m_integer);
+ m_float = rhs.m_float;
+ }
+ return *this;
+}
+
+Scalar &Scalar::operator=(const int v) {
+ m_type = e_sint;
+ m_integer = llvm::APInt(sizeof(int) * 8, v, true);
+ return *this;
+}
+
+Scalar &Scalar::operator=(unsigned int v) {
+ m_type = e_uint;
+ m_integer = llvm::APInt(sizeof(int) * 8, v);
+ return *this;
+}
+
+Scalar &Scalar::operator=(long v) {
+ m_type = e_slong;
+ m_integer = llvm::APInt(sizeof(long) * 8, v, true);
+ return *this;
+}
+
+Scalar &Scalar::operator=(unsigned long v) {
+ m_type = e_ulong;
+ m_integer = llvm::APInt(sizeof(long) * 8, v);
+ return *this;
+}
+
+Scalar &Scalar::operator=(long long v) {
+ m_type = e_slonglong;
+ m_integer = llvm::APInt(sizeof(long) * 8, v, true);
+ return *this;
+}
+
+Scalar &Scalar::operator=(unsigned long long v) {
+ m_type = e_ulonglong;
+ m_integer = llvm::APInt(sizeof(long long) * 8, v);
+ return *this;
+}
+
+Scalar &Scalar::operator=(float v) {
+ m_type = e_float;
+ m_float = llvm::APFloat(v);
+ return *this;
+}
+
+Scalar &Scalar::operator=(double v) {
+ m_type = e_double;
+ m_float = llvm::APFloat(v);
+ return *this;
+}
+
+Scalar &Scalar::operator=(long double v) {
+ m_type = e_long_double;
+ if (m_ieee_quad)
+ m_float = llvm::APFloat(
+ llvm::APFloat::IEEEquad,
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&v)->x));
+ else
+ m_float = llvm::APFloat(
+ llvm::APFloat::x87DoubleExtended,
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&v)->x));
+ return *this;
+}
+
+Scalar &Scalar::operator=(llvm::APInt rhs) {
+ m_integer = llvm::APInt(rhs);
+ switch (m_integer.getBitWidth()) {
+ case 8:
+ case 16:
+ case 32:
+ if (m_integer.isSignedIntN(sizeof(sint_t) * 8))
+ m_type = e_sint;
+ else
+ m_type = e_uint;
+ break;
+ case 64:
+ if (m_integer.isSignedIntN(sizeof(slonglong_t) * 8))
+ m_type = e_slonglong;
+ else
+ m_type = e_ulonglong;
+ break;
+ case 128:
+ if (m_integer.isSignedIntN(BITWIDTH_INT128))
+ m_type = e_sint128;
+ else
+ m_type = e_uint128;
+ break;
+ case 256:
+ if (m_integer.isSignedIntN(BITWIDTH_INT256))
+ m_type = e_sint256;
+ else
+ m_type = e_uint256;
+ break;
+ }
+ return *this;
}
-const void *
-Scalar::GetBytes() const
-{
- const uint64_t *apint_words;
- const uint8_t *bytes;
- static float_t flt_val;
- static double_t dbl_val;
- static uint64_t swapped_words[4];
- switch (m_type)
- {
+Scalar::~Scalar() = default;
+
+bool Scalar::Promote(Scalar::Type type) {
+ bool success = false;
+ switch (m_type) {
+ case e_void:
+ break;
+
+ case e_sint:
+ switch (type) {
case e_void:
- break;
+ break;
case e_sint:
+ success = true;
+ break;
case e_uint:
+ m_integer = m_integer.sextOrTrunc(sizeof(uint_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.sextOrTrunc(sizeof(ulong_t) * 8);
+ success = true;
+ break;
+
case e_slonglong:
+ m_integer = m_integer.sextOrTrunc(sizeof(slonglong_t) * 8);
+ success = true;
+ break;
+
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.
- if (endian::InlHostByteOrder() == eByteOrderBig)
- {
- size_t byte_size = m_integer.getBitWidth() / 8;
- if (byte_size < 8)
- bytes += 8 - byte_size;
- }
- return bytes;
+ m_integer = m_integer.sextOrTrunc(sizeof(ulonglong_t) * 8);
+ success = true;
+ break;
+
case e_sint128:
case e_uint128:
- apint_words = m_integer.getRawData();
- // getRawData always returns a pointer to an array of two uint64_t values,
- // where the least-significant word always comes first. On big-endian
- // systems we need to swap the two words.
- if (endian::InlHostByteOrder() == eByteOrderBig)
- {
- swapped_words[0] = apint_words[1];
- swapped_words[1] = apint_words[0];
- apint_words = swapped_words;
- }
- return reinterpret_cast<const void *>(apint_words);
+ m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128);
+ success = true;
+ break;
+
case e_sint256:
case e_uint256:
- apint_words = m_integer.getRawData();
- // getRawData always returns a pointer to an array of four uint64_t values,
- // where the least-significant word always comes first. On big-endian
- // systems we need to swap the four words.
- if (endian::InlHostByteOrder() == eByteOrderBig)
- {
- swapped_words[0] = apint_words[3];
- swapped_words[1] = apint_words[2];
- swapped_words[2] = apint_words[1];
- swapped_words[3] = apint_words[0];
- apint_words = swapped_words;
- }
- return reinterpret_cast<const void *>(apint_words);
+ m_integer = m_integer.sextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ break;
+
case e_float:
- flt_val = m_float.convertToFloat();
- return reinterpret_cast<const void *>(&flt_val);
+ m_float = llvm::APFloat(m_integer.bitsToFloat());
+ success = true;
+ break;
+
case e_double:
- dbl_val = m_float.convertToDouble();
- return reinterpret_cast<const void *>(&dbl_val);
+ m_float = llvm::APFloat(m_integer.bitsToDouble());
+ success = true;
+ break;
+
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- apint_words = ldbl_val.getRawData();
- // getRawData always returns a pointer to an array of two uint64_t values,
- // where the least-significant word always comes first. On big-endian
- // systems we need to swap the two words.
- if (endian::InlHostByteOrder() == eByteOrderBig)
- {
- swapped_words[0] = apint_words[1];
- swapped_words[1] = apint_words[0];
- apint_words = swapped_words;
- }
- return reinterpret_cast<const void *>(apint_words);
+ 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;
}
- return nullptr;
-}
+ break;
-size_t
-Scalar::GetByteSize() const
-{
- switch (m_type)
- {
+ case e_uint:
+ switch (type) {
case e_void:
- break;
case e_sint:
+ break;
case e_uint:
+ success = true;
+ break;
case e_slong:
+ m_integer = m_integer.zextOrTrunc(sizeof(slong_t) * 8);
+ success = true;
+ break;
+
case e_ulong:
+ m_integer = m_integer.zextOrTrunc(sizeof(ulong_t) * 8);
+ success = true;
+ break;
+
case e_slonglong:
+ m_integer = m_integer.zextOrTrunc(sizeof(slonglong_t) * 8);
+ success = true;
+ break;
+
case e_ulonglong:
+ m_integer = m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8);
+ success = true;
+ break;
+
case e_sint128:
case e_uint128:
+ m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128);
+ success = true;
+ break;
+
case e_sint256:
case e_uint256:
- return (m_integer.getBitWidth() / 8);
- case e_float: return sizeof(float_t);
- case e_double: return sizeof(double_t);
- case e_long_double: return sizeof(long_double_t);
+ 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;
}
- return 0;
-}
+ break;
-bool
-Scalar::IsZero() const
-{
- llvm::APInt zero_int = llvm::APInt::getNullValue(m_integer.getBitWidth() / 8);
- switch (m_type)
- {
+ case e_slong:
+ switch (type) {
case e_void:
- break;
case e_sint:
case e_uint:
+ break;
case e_slong:
+ success = true;
+ break;
case e_ulong:
+ m_integer = m_integer.sextOrTrunc(sizeof(ulong_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.sextOrTrunc(sizeof(ulonglong_t) * 8);
+ success = true;
+ break;
+
case e_sint128:
case e_uint128:
+ m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128);
+ success = true;
+ break;
+
case e_sint256:
case e_uint256:
- return llvm::APInt::isSameValue(zero_int, m_integer);
+ m_integer = m_integer.sextOrTrunc(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:
- return m_float.isZero();
+ 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;
}
- return false;
-}
-
-void
-Scalar::GetValue (Stream *s, bool show_type) const
-{
- if (show_type)
- s->Printf("(%s) ", GetTypeAsCString());
+ break;
- switch (m_type)
- {
+ case e_ulong:
+ switch (type) {
case e_void:
- break;
case e_sint:
- case e_slong:
- case e_slonglong:
- case e_sint128:
- case e_sint256:
- s->PutCString(m_integer.toString(10, true).c_str());
- break;
case e_uint:
+ case e_slong:
+ break;
case e_ulong:
- case e_ulonglong:
- case e_uint128:
- case e_uint256:
- s->PutCString(m_integer.toString(10, false).c_str());
- break;
- case e_float:
- case e_double:
- case e_long_double:
- llvm::SmallString<24> string;
- m_float.toString(string);
- s->Printf("%s", string.c_str());
- break;
- }
-}
-
-const char *
-Scalar::GetTypeAsCString() const
-{
- switch (m_type)
- {
- case e_void: return "void";
- case e_sint: return "int";
- case e_uint: return "unsigned int";
- case e_slong: return "long";
- case e_ulong: return "unsigned long";
- case e_slonglong: return "long long";
- case e_ulonglong: return "unsigned long long";
- case e_sint128: return "int128_t";
- case e_uint128: return "unsigned int128_t";
- case e_sint256: return "int256_t";
- case e_uint256: return "unsigned int256_t";
- case e_float: return "float";
- case e_double: return "double";
- case e_long_double: return "long double";
- }
- return "<invalid Scalar type>";
-}
-
-Scalar&
-Scalar::operator=(const Scalar& rhs)
-{
- if (this != &rhs)
- {
- m_type = rhs.m_type;
- m_integer = llvm::APInt(rhs.m_integer);
- m_float = rhs.m_float;
- }
- return *this;
-}
-
-Scalar&
-Scalar::operator= (const int v)
-{
- m_type = e_sint;
- m_integer = llvm::APInt(sizeof(int) * 8, v, true);
- return *this;
-}
-
-Scalar&
-Scalar::operator= (unsigned int v)
-{
- m_type = e_uint;
- m_integer = llvm::APInt(sizeof(int) * 8, v);
- return *this;
-}
+ success = true;
+ break;
+ case e_slonglong:
+ m_integer = m_integer.zextOrTrunc(sizeof(slonglong_t) * 8);
+ success = true;
+ break;
-Scalar&
-Scalar::operator= (long v)
-{
- m_type = e_slong;
- m_integer = llvm::APInt(sizeof(long) * 8, v, true);
- return *this;
-}
+ case e_ulonglong:
+ m_integer = m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8);
+ success = true;
+ break;
-Scalar&
-Scalar::operator= (unsigned long v)
-{
- m_type = e_ulong;
- m_integer = llvm::APInt(sizeof(long) * 8, v);
- return *this;
-}
+ case e_sint128:
+ case e_uint128:
+ m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128);
+ success = true;
+ break;
-Scalar&
-Scalar::operator= (long long v)
-{
- m_type = e_slonglong;
- m_integer = llvm::APInt(sizeof(long) * 8, v, true);
- return *this;
-}
+ case e_sint256:
+ case e_uint256:
+ m_integer = m_integer.zextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ break;
-Scalar&
-Scalar::operator= (unsigned long long v)
-{
- m_type = e_ulonglong;
- m_integer = llvm::APInt(sizeof(long long) * 8, v);
- return *this;
-}
+ case e_float:
+ m_float = llvm::APFloat(m_integer.bitsToFloat());
+ success = true;
+ break;
-Scalar&
-Scalar::operator= (float v)
-{
- m_type = e_float;
- m_float = llvm::APFloat(v);
- return *this;
-}
-
-Scalar&
-Scalar::operator= (double v)
-{
- m_type = e_double;
- m_float = llvm::APFloat(v);
- return *this;
-}
-
-Scalar&
-Scalar::operator= (long double v)
-{
- m_type = e_long_double;
- if(m_ieee_quad)
- m_float = llvm::APFloat(llvm::APFloat::IEEEquad, llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&v)->x));
- else
- m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended, llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&v)->x));
- return *this;
-}
+ case e_double:
+ m_float = llvm::APFloat(m_integer.bitsToDouble());
+ success = true;
+ break;
-Scalar&
-Scalar::operator= (llvm::APInt rhs)
-{
- m_integer = llvm::APInt(rhs);
- switch(m_integer.getBitWidth())
- {
- case 8:
- case 16:
- case 32:
- if(m_integer.isSignedIntN(sizeof(sint_t) * 8))
- m_type = e_sint;
- else
- m_type = e_uint;
- break;
- case 64:
- if(m_integer.isSignedIntN(sizeof(slonglong_t) * 8))
- m_type = e_slonglong;
- else
- m_type = e_ulonglong;
- break;
- case 128:
- if(m_integer.isSignedIntN(BITWIDTH_INT128))
- m_type = e_sint128;
- else
- m_type = e_uint128;
- break;
- case 256:
- if(m_integer.isSignedIntN(BITWIDTH_INT256))
- m_type = e_sint256;
- else
- m_type = e_uint256;
- 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;
}
- return *this;
-}
-
-Scalar::~Scalar() = default;
-
-bool
-Scalar::Promote(Scalar::Type type)
-{
- bool success = false;
- switch (m_type)
- {
- case e_void:
- break;
-
- case e_sint:
- switch (type)
- {
- case e_void: break;
- case e_sint: success = true; break;
- case e_uint:
- m_integer = m_integer.sextOrTrunc(sizeof(uint_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.sextOrTrunc(sizeof(ulong_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.sextOrTrunc(sizeof(ulonglong_t) * 8);
- success = true;
- break;
-
- case e_sint128:
- case e_uint128:
- m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128);
- success = true;
- break;
-
- case e_sint256:
- case e_uint256:
- m_integer = m_integer.sextOrTrunc(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;
+ break;
+ case e_slonglong:
+ switch (type) {
+ case e_void:
+ case e_sint:
case e_uint:
- switch (type)
- {
- case e_void:
- case e_sint: break;
- case e_uint: success = true; break;
- case e_slong:
- m_integer = m_integer.zextOrTrunc(sizeof(slong_t) * 8);
- success = true;
- break;
-
- case e_ulong:
- m_integer = m_integer.zextOrTrunc(sizeof(ulong_t) * 8);
- success = true;
- break;
-
- case e_slonglong:
- m_integer = m_integer.zextOrTrunc(sizeof(slonglong_t) * 8);
- success = true;
- break;
-
- case e_ulonglong:
- m_integer = m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8);
- success = true;
- break;
-
- case e_sint128:
- case e_uint128:
- m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128);
- success = true;
- break;
-
- case e_sint256:
- 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_slong:
- switch (type)
- {
- case e_void:
- case e_sint:
- case e_uint: break;
- case e_slong: success = true; break;
- case e_ulong:
- m_integer = m_integer.sextOrTrunc(sizeof(ulong_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.sextOrTrunc(sizeof(ulonglong_t) * 8);
- success = true;
- break;
-
- case e_sint128:
- case e_uint128:
- m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128);
- success = true;
- break;
-
- case e_sint256:
- case e_uint256:
- m_integer = m_integer.sextOrTrunc(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_ulong:
- switch (type)
- {
- case e_void:
- case e_sint:
- case e_uint:
- case e_slong: break;
- case e_ulong: success = true; break;
- case e_slonglong:
- m_integer = m_integer.zextOrTrunc(sizeof(slonglong_t) * 8);
- success = true;
- break;
-
- case e_ulonglong:
- m_integer = m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8);
- success = true;
- break;
-
- case e_sint128:
- case e_uint128:
- m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128);
- success = true;
- break;
-
- case e_sint256:
- 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;
-
+ break;
case e_slonglong:
- switch (type)
- {
- case e_void:
- case e_sint:
- case e_uint:
- case e_slong:
- case e_ulong: break;
- case e_slonglong: success = true; break;
- case e_ulonglong:
- m_integer = m_integer.sextOrTrunc(sizeof(ulonglong_t) * 8);
- success = true;
- break;
-
- case e_sint128:
- case e_uint128:
- m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128);
- success = true;
- break;
-
- case e_sint256:
- case e_uint256:
- m_integer = m_integer.sextOrTrunc(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;
-
+ success = true;
+ break;
case e_ulonglong:
- switch (type)
- {
- case e_void:
- case e_sint:
- case e_uint:
- case e_slong:
- case e_ulong:
- case e_slonglong: break;
- case e_ulonglong: success = true; break;
- case e_sint128:
- case e_uint128:
- m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128);
- success = true;
- break;
-
- case e_sint256:
- 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;
+ m_integer = m_integer.sextOrTrunc(sizeof(ulonglong_t) * 8);
+ success = true;
+ break;
case e_sint128:
- switch (type)
- {
- case e_void:
- case e_sint:
- case e_uint:
- case e_slong:
- case e_ulong:
- case e_slonglong:
- case e_ulonglong: break;
- case e_sint128: success = true; break;
- case e_uint128:
- m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128);
- success = true;
- break;
-
- case e_sint256:
- case e_uint256:
- m_integer = m_integer.sextOrTrunc(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_uint128:
- switch (type)
- {
- case e_void:
- case e_sint:
- case e_uint:
- case e_slong:
- case e_ulong:
- case e_slonglong:
- case e_ulonglong:
- case e_sint128: break;
- case e_uint128: success = true; break;
- case e_sint256:
- 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;
+ m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128);
+ success = true;
+ break;
case e_sint256:
- switch (type)
- {
- case e_void:
- case e_sint:
- case e_uint:
- case e_slong:
- case e_ulong:
- case e_slonglong:
- case e_ulonglong:
- case e_sint128:
- case e_uint128: break;
- case e_sint256: success = true; break;
- case e_uint256:
- m_integer = m_integer.sextOrTrunc(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_uint256:
- switch (type)
- {
- case e_void:
- 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: break;
- case e_uint256: 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;
-
+ m_integer = m_integer.sextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ break;
+
case e_float:
- switch (type)
- {
- case e_void:
- 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: break;
- case e_float: success = true; break;
- case e_double:
- m_float = llvm::APFloat((float_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());
- success = true;
- break;
- }
- break;
+ m_float = llvm::APFloat(m_integer.bitsToFloat());
+ success = true;
+ break;
case e_double:
- switch (type)
- {
- case e_void:
- 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:
- case e_float: break;
- 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());
- success = true;
- break;
- }
- break;
+ m_float = llvm::APFloat(m_integer.bitsToDouble());
+ success = true;
+ break;
case e_long_double:
- switch (type)
- {
- case e_void:
- 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:
- case e_float:
- case e_double: break;
- case e_long_double: success = true; break;
- }
- break;
- }
-
- if (success)
- m_type = type;
- return success;
-}
-
-const char *
-Scalar::GetValueTypeAsCString (Scalar::Type type)
-{
- switch (type)
- {
- case e_void: return "void";
- case e_sint: return "int";
- case e_uint: return "unsigned int";
- case e_slong: return "long";
- case e_ulong: return "unsigned long";
- case e_slonglong: return "long long";
- case e_ulonglong: return "unsigned long long";
- case e_float: return "float";
- case e_double: return "double";
- case e_long_double: return "long double";
- case e_sint128: return "int128_t";
- case e_uint128: return "uint128_t";
- case e_sint256: return "int256_t";
- case e_uint256: return "uint256_t";
+ 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;
}
- return "???";
-}
-
-Scalar::Type
-Scalar::GetValueTypeForSignedIntegerWithByteSize (size_t byte_size)
-{
- if (byte_size <= sizeof(sint_t))
- return e_sint;
- if (byte_size <= sizeof(slong_t))
- return e_slong;
- if (byte_size <= sizeof(slonglong_t))
- return e_slonglong;
- return e_void;
-}
-
-Scalar::Type
-Scalar::GetValueTypeForUnsignedIntegerWithByteSize (size_t byte_size)
-{
- if (byte_size <= sizeof(uint_t))
- return e_uint;
- if (byte_size <= sizeof(ulong_t))
- return e_ulong;
- if (byte_size <= sizeof(ulonglong_t))
- return e_ulonglong;
- return e_void;
-}
-
-Scalar::Type
-Scalar::GetValueTypeForFloatWithByteSize (size_t byte_size)
-{
- if (byte_size == sizeof(float_t))
- return e_float;
- if (byte_size == sizeof(double_t))
- return e_double;
- if (byte_size == sizeof(long_double_t))
- return e_long_double;
- return e_void;
-}
+ break;
-bool
-Scalar::Cast(Scalar::Type type)
-{
- bool success = false;
- switch (m_type)
- {
+ case e_ulonglong:
+ switch (type) {
case e_void:
- break;
-
case e_sint:
case e_uint:
case e_slong:
case e_ulong:
case e_slonglong:
+ break;
case e_ulonglong:
+ success = true;
+ break;
case e_sint128:
case e_uint128:
+ m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128);
+ success = true;
+ break;
+
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;
+ m_integer = m_integer.zextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ 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;
+ m_float = llvm::APFloat(m_integer.bitsToFloat());
+ success = true;
+ 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;
+ m_float = llvm::APFloat(m_integer.bitsToDouble());
+ success = true;
+ 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;
-
- switch (m_type)
- {
- case e_void: break;
- case e_sint: success = true; break;
- case e_uint: m_type = e_sint; success = true; break;
- case e_slong: success = true; break;
- case e_ulong: m_type = e_slong; success = true; break;
- case e_slonglong: success = true; break;
- case e_ulonglong: m_type = e_slonglong; success = true; break;
- case e_sint128: success = true; break;
- case e_uint128: m_type = e_sint128; success = true; break;
- case e_sint256: success = true; break;
- case e_uint256: m_type = e_sint256; success = true; break;
- case e_float: success = true; break;
- case e_double: success = true; break;
- case e_long_double: success = true; break;
- }
-
- return success;
-}
-
-bool
-Scalar::MakeUnsigned ()
-{
- bool success = false;
-
- switch (m_type)
- {
- case e_void: break;
- case e_sint: success = true; break;
- case e_uint: m_type = e_uint; success = true; break;
- case e_slong: success = true; break;
- case e_ulong: m_type = e_ulong; success = true; break;
- case e_slonglong: success = true; break;
- case e_ulonglong: m_type = e_ulonglong; success = true; break;
- case e_sint128: success = true; break;
- case e_uint128: m_type = e_uint128; success = true; break;
- case e_sint256: success = true; break;
- case e_uint256: m_type = e_uint256; success = true; break;
- case e_float: success = true; break;
- case e_double: success = true; break;
- case e_long_double: success = true; break;
+ 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;
- return success;
-}
-
-signed char
-Scalar::SChar(char fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ case e_sint128:
+ switch (type) {
+ case e_void:
case e_sint:
case e_uint:
case e_slong:
case e_ulong:
case e_slonglong:
case e_ulonglong:
+ break;
case e_sint128:
+ success = true;
+ break;
case e_uint128:
+ m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128);
+ success = true;
+ break;
+
case e_sint256:
case e_uint256:
- return (schar_t)(m_integer.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue();
+ m_integer = m_integer.sextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ break;
+
case e_float:
- return (schar_t)m_float.convertToFloat();
+ m_float = llvm::APFloat(m_integer.bitsToFloat());
+ success = true;
+ break;
+
case e_double:
- return (schar_t)m_float.convertToDouble();
+ m_float = llvm::APFloat(m_integer.bitsToDouble());
+ success = true;
+ break;
+
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (schar_t)(ldbl_val.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue();
+ 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;
}
- return fail_value;
-}
+ break;
-unsigned char
-Scalar::UChar(unsigned char fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ case e_uint128:
+ switch (type) {
+ case e_void:
case e_sint:
case e_uint:
case e_slong:
@@ -1406,27 +831,39 @@ Scalar::UChar(unsigned char fail_value)
case e_slonglong:
case e_ulonglong:
case e_sint128:
+ break;
case e_uint128:
+ success = true;
+ break;
case e_sint256:
case e_uint256:
- return (uchar_t)(m_integer.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue();
+ m_integer = m_integer.zextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ break;
+
case e_float:
- return (uchar_t)m_float.convertToFloat();
+ m_float = llvm::APFloat(m_integer.bitsToFloat());
+ success = true;
+ break;
+
case e_double:
- return (uchar_t)m_float.convertToDouble();
+ m_float = llvm::APFloat(m_integer.bitsToDouble());
+ success = true;
+ break;
+
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (uchar_t)(ldbl_val.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue();
+ 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;
}
- return fail_value;
-}
+ break;
-short
-Scalar::SShort(short fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ case e_sint256:
+ switch (type) {
+ case e_void:
case e_sint:
case e_uint:
case e_slong:
@@ -1435,26 +872,38 @@ Scalar::SShort(short fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
+ break;
case e_sint256:
+ success = true;
+ break;
case e_uint256:
- return (sshort_t)(m_integer.sextOrTrunc(sizeof(sshort_t) * 8)).getSExtValue();
+ m_integer = m_integer.sextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ break;
+
case e_float:
- return (sshort_t)m_float.convertToFloat();
+ m_float = llvm::APFloat(m_integer.bitsToFloat());
+ success = true;
+ break;
+
case e_double:
- return (sshort_t)m_float.convertToDouble();
+ m_float = llvm::APFloat(m_integer.bitsToDouble());
+ success = true;
+ break;
+
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (sshort_t)(ldbl_val.sextOrTrunc(sizeof(sshort_t) * 8)).getSExtValue();
+ 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;
}
- return fail_value;
-}
+ break;
-unsigned short
-Scalar::UShort(unsigned short fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ case e_uint256:
+ switch (type) {
+ case e_void:
case e_sint:
case e_uint:
case e_slong:
@@ -1464,25 +913,33 @@ Scalar::UShort(unsigned short fail_value
case e_sint128:
case e_uint128:
case e_sint256:
+ break;
case e_uint256:
- return (ushort_t)(m_integer.zextOrTrunc(sizeof(ushort_t) * 8)).getZExtValue();
+ success = true;
+ break;
case e_float:
- return (ushort_t)m_float.convertToFloat();
+ m_float = llvm::APFloat(m_integer.bitsToFloat());
+ success = true;
+ break;
+
case e_double:
- return (ushort_t)m_float.convertToDouble();
+ m_float = llvm::APFloat(m_integer.bitsToDouble());
+ success = true;
+ break;
+
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (ushort_t)(ldbl_val.zextOrTrunc(sizeof(ushort_t) * 8)).getZExtValue();
+ 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;
}
- return fail_value;
-}
+ break;
-int
-Scalar::SInt(int fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ case e_float:
+ switch (type) {
+ case e_void:
case e_sint:
case e_uint:
case e_slong:
@@ -1493,24 +950,30 @@ Scalar::SInt(int fail_value) const
case e_uint128:
case e_sint256:
case e_uint256:
- return (sint_t)(m_integer.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue();
+ break;
case e_float:
- return (sint_t)m_float.convertToFloat();
+ success = true;
+ break;
case e_double:
- return (sint_t)m_float.convertToDouble();
+ m_float = llvm::APFloat((float_t)m_float.convertToFloat());
+ success = true;
+ break;
+
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (sint_t)(ldbl_val.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue();
+ 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;
}
- return fail_value;
-}
+ break;
-unsigned int
-Scalar::UInt(unsigned int fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ case e_double:
+ switch (type) {
+ case e_void:
case e_sint:
case e_uint:
case e_slong:
@@ -1521,24 +984,26 @@ Scalar::UInt(unsigned int fail_value) co
case e_uint128:
case e_sint256:
case e_uint256:
- return (uint_t)(m_integer.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue();
case e_float:
- return (uint_t)m_float.convertToFloat();
+ break;
case e_double:
- return (uint_t)m_float.convertToDouble();
+ success = true;
+ break;
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (uint_t)(ldbl_val.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue();
+ 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;
}
- return fail_value;
-}
+ break;
-long
-Scalar::SLong(long fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ case e_long_double:
+ switch (type) {
+ case e_void:
case e_sint:
case e_uint:
case e_slong:
@@ -1549,52 +1014,180 @@ Scalar::SLong(long fail_value) const
case e_uint128:
case e_sint256:
case e_uint256:
- return (slong_t)(m_integer.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue();
case e_float:
- return (slong_t)m_float.convertToFloat();
case e_double:
- return (slong_t)m_float.convertToDouble();
+ break;
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (slong_t)(ldbl_val.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue();
+ success = true;
+ break;
}
- return fail_value;
+ break;
+ }
+
+ if (success)
+ m_type = type;
+ return success;
+}
+
+const char *Scalar::GetValueTypeAsCString(Scalar::Type type) {
+ switch (type) {
+ case e_void:
+ return "void";
+ case e_sint:
+ return "int";
+ case e_uint:
+ return "unsigned int";
+ case e_slong:
+ return "long";
+ case e_ulong:
+ return "unsigned long";
+ case e_slonglong:
+ return "long long";
+ case e_ulonglong:
+ return "unsigned long long";
+ case e_float:
+ return "float";
+ case e_double:
+ return "double";
+ case e_long_double:
+ return "long double";
+ case e_sint128:
+ return "int128_t";
+ case e_uint128:
+ return "uint128_t";
+ case e_sint256:
+ return "int256_t";
+ case e_uint256:
+ return "uint256_t";
+ }
+ return "???";
+}
+
+Scalar::Type
+Scalar::GetValueTypeForSignedIntegerWithByteSize(size_t byte_size) {
+ if (byte_size <= sizeof(sint_t))
+ return e_sint;
+ if (byte_size <= sizeof(slong_t))
+ return e_slong;
+ if (byte_size <= sizeof(slonglong_t))
+ return e_slonglong;
+ return e_void;
}
-unsigned long
-Scalar::ULong(unsigned long fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+Scalar::Type
+Scalar::GetValueTypeForUnsignedIntegerWithByteSize(size_t byte_size) {
+ if (byte_size <= sizeof(uint_t))
+ return e_uint;
+ if (byte_size <= sizeof(ulong_t))
+ return e_ulong;
+ if (byte_size <= sizeof(ulonglong_t))
+ return e_ulonglong;
+ return e_void;
+}
+
+Scalar::Type Scalar::GetValueTypeForFloatWithByteSize(size_t byte_size) {
+ if (byte_size == sizeof(float_t))
+ return e_float;
+ if (byte_size == sizeof(double_t))
+ return e_double;
+ if (byte_size == sizeof(long_double_t))
+ return e_long_double;
+ 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:
- return (ulong_t)(m_integer.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue();
+ m_integer = m_integer.zextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ break;
+
case e_float:
- return (ulong_t)m_float.convertToFloat();
+ m_float = llvm::APFloat(m_integer.bitsToFloat());
+ success = true;
+ break;
+
case e_double:
- return (ulong_t)m_float.convertToDouble();
+ m_float = llvm::APFloat(m_integer.bitsToDouble());
+ success = true;
+ break;
+
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (ulong_t)(ldbl_val.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue();
+ 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;
}
- return fail_value;
-}
+ break;
-long long
-Scalar::SLongLong(long long fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ case e_float:
+ switch (type) {
+ case e_void:
+ break;
case e_sint:
case e_uint:
case e_slong:
@@ -1605,24 +1198,33 @@ Scalar::SLongLong(long long fail_value)
case e_uint128:
case e_sint256:
case e_uint256:
- return (slonglong_t)(m_integer.sextOrTrunc(sizeof(slonglong_t) * 8)).getSExtValue();
+ m_integer = m_float.bitcastToAPInt();
+ success = true;
+ break;
case e_float:
- return (slonglong_t)m_float.convertToFloat();
+ m_float = llvm::APFloat(m_float.convertToFloat());
+ success = true;
+ break;
case e_double:
- return (slonglong_t)m_float.convertToDouble();
+ m_float = llvm::APFloat(m_float.convertToFloat());
+ success = true;
+ break;
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (slonglong_t)(ldbl_val.sextOrTrunc(sizeof(slonglong_t) * 8)).getSExtValue();
+ 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;
}
- return fail_value;
-}
+ break;
-unsigned long long
-Scalar::ULongLong(unsigned long long fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ case e_double:
+ switch (type) {
+ case e_void:
+ break;
case e_sint:
case e_uint:
case e_slong:
@@ -1633,152 +1235,670 @@ Scalar::ULongLong(unsigned long long fai
case e_uint128:
case e_sint256:
case e_uint256:
- return (ulonglong_t)(m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8)).getZExtValue();
+ m_integer = m_float.bitcastToAPInt();
+ success = true;
+ break;
case e_float:
- return (ulonglong_t)m_float.convertToFloat();
+ m_float = llvm::APFloat(m_float.convertToDouble());
+ success = true;
+ break;
case e_double:
- return (ulonglong_t)m_float.convertToDouble();
+ m_float = llvm::APFloat(m_float.convertToDouble());
+ success = true;
+ break;
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (ulonglong_t)(ldbl_val.zextOrTrunc(sizeof(ulonglong_t) * 8)).getZExtValue();
- }
- return fail_value;
-}
-
-llvm::APInt
-Scalar::SInt128(llvm::APInt& fail_value) const
-{
- 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:
- return m_integer;
- case e_float:
- case e_double:
- case e_long_double:
- return m_float.bitcastToAPInt();
+ 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;
}
- return fail_value;
-}
+ break;
-llvm::APInt
-Scalar::UInt128(const llvm::APInt& fail_value) const
-{
- switch (m_type)
- {
- case e_void: 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:
- case e_slong:
- case e_ulong:
- case e_slonglong:
- case e_ulonglong:
- case e_sint128:
- case e_uint128:
- case e_sint256:
- case e_uint256:
- return m_integer;
- case e_float:
- case e_double:
- case e_long_double:
- return m_float.bitcastToAPInt();
- }
- return fail_value;
-}
+ m_integer = m_float.bitcastToAPInt();
+ m_integer = m_integer.zextOrTrunc(sizeof(sint_t) * 8);
+ success = true;
+ break;
-llvm::APInt
-Scalar::SInt256(llvm::APInt& fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
- case e_sint:
- case e_uint:
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:
- return m_integer;
+ 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:
- return m_float.bitcastToAPInt();
+ success = true;
+ break;
}
- return fail_value;
-}
+ break;
+ }
-llvm::APInt
-Scalar::UInt256(const llvm::APInt& fail_value) const
-{
- 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:
- return m_integer;
- case e_float:
- case e_double:
- case e_long_double:
- return m_float.bitcastToAPInt();
- }
- return fail_value;
+ if (success)
+ m_type = type;
+ return success;
}
-float
-Scalar::Float(float fail_value) const
-{
- 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:
- return m_integer.bitsToFloat();
- case e_float:
- return m_float.convertToFloat();
- case e_double:
- return (float_t)m_float.convertToDouble();
- case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return ldbl_val.bitsToFloat();
- }
- return fail_value;
-}
+bool Scalar::MakeSigned() {
+ bool success = false;
-double
-Scalar::Double(double fail_value) const
-{
- switch (m_type)
- {
- case e_void: break;
+ switch (m_type) {
+ case e_void:
+ break;
+ case e_sint:
+ success = true;
+ break;
+ case e_uint:
+ m_type = e_sint;
+ success = true;
+ break;
+ case e_slong:
+ success = true;
+ break;
+ case e_ulong:
+ m_type = e_slong;
+ success = true;
+ break;
+ case e_slonglong:
+ success = true;
+ break;
+ case e_ulonglong:
+ m_type = e_slonglong;
+ success = true;
+ break;
+ case e_sint128:
+ success = true;
+ break;
+ case e_uint128:
+ m_type = e_sint128;
+ success = true;
+ break;
+ case e_sint256:
+ success = true;
+ break;
+ case e_uint256:
+ m_type = e_sint256;
+ success = true;
+ break;
+ case e_float:
+ success = true;
+ break;
+ case e_double:
+ success = true;
+ break;
+ case e_long_double:
+ success = true;
+ break;
+ }
+
+ return success;
+}
+
+bool Scalar::MakeUnsigned() {
+ bool success = false;
+
+ switch (m_type) {
+ case e_void:
+ break;
+ case e_sint:
+ success = true;
+ break;
+ case e_uint:
+ m_type = e_uint;
+ success = true;
+ break;
+ case e_slong:
+ success = true;
+ break;
+ case e_ulong:
+ m_type = e_ulong;
+ success = true;
+ break;
+ case e_slonglong:
+ success = true;
+ break;
+ case e_ulonglong:
+ m_type = e_ulonglong;
+ success = true;
+ break;
+ case e_sint128:
+ success = true;
+ break;
+ case e_uint128:
+ m_type = e_uint128;
+ success = true;
+ break;
+ case e_sint256:
+ success = true;
+ break;
+ case e_uint256:
+ m_type = e_uint256;
+ success = true;
+ break;
+ case e_float:
+ success = true;
+ break;
+ case e_double:
+ success = true;
+ break;
+ case e_long_double:
+ success = true;
+ break;
+ }
+
+ return success;
+}
+
+signed char Scalar::SChar(char fail_value) const {
+ 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:
+ return (schar_t)(m_integer.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue();
+ case e_float:
+ return (schar_t)m_float.convertToFloat();
+ case e_double:
+ return (schar_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (schar_t)(ldbl_val.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue();
+ }
+ return fail_value;
+}
+
+unsigned char Scalar::UChar(unsigned char fail_value) const {
+ 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:
+ return (uchar_t)(m_integer.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue();
+ case e_float:
+ return (uchar_t)m_float.convertToFloat();
+ case e_double:
+ return (uchar_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (uchar_t)(ldbl_val.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue();
+ }
+ return fail_value;
+}
+
+short Scalar::SShort(short fail_value) const {
+ 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:
+ return (sshort_t)(m_integer.sextOrTrunc(sizeof(sshort_t) * 8))
+ .getSExtValue();
+ case e_float:
+ return (sshort_t)m_float.convertToFloat();
+ case e_double:
+ return (sshort_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (sshort_t)(ldbl_val.sextOrTrunc(sizeof(sshort_t) * 8))
+ .getSExtValue();
+ }
+ return fail_value;
+}
+
+unsigned short Scalar::UShort(unsigned short fail_value) const {
+ 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:
+ return (ushort_t)(m_integer.zextOrTrunc(sizeof(ushort_t) * 8))
+ .getZExtValue();
+ case e_float:
+ return (ushort_t)m_float.convertToFloat();
+ case e_double:
+ return (ushort_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (ushort_t)(ldbl_val.zextOrTrunc(sizeof(ushort_t) * 8))
+ .getZExtValue();
+ }
+ return fail_value;
+}
+
+int Scalar::SInt(int fail_value) const {
+ 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:
+ return (sint_t)(m_integer.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue();
+ case e_float:
+ return (sint_t)m_float.convertToFloat();
+ case e_double:
+ return (sint_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (sint_t)(ldbl_val.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue();
+ }
+ return fail_value;
+}
+
+unsigned int Scalar::UInt(unsigned int fail_value) const {
+ 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:
+ return (uint_t)(m_integer.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue();
+ case e_float:
+ return (uint_t)m_float.convertToFloat();
+ case e_double:
+ return (uint_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (uint_t)(ldbl_val.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue();
+ }
+ return fail_value;
+}
+
+long Scalar::SLong(long fail_value) const {
+ 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:
+ return (slong_t)(m_integer.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue();
+ case e_float:
+ return (slong_t)m_float.convertToFloat();
+ case e_double:
+ return (slong_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (slong_t)(ldbl_val.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue();
+ }
+ return fail_value;
+}
+
+unsigned long Scalar::ULong(unsigned long fail_value) const {
+ 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:
+ return (ulong_t)(m_integer.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue();
+ case e_float:
+ return (ulong_t)m_float.convertToFloat();
+ case e_double:
+ return (ulong_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (ulong_t)(ldbl_val.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue();
+ }
+ return fail_value;
+}
+
+long long Scalar::SLongLong(long long fail_value) const {
+ 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:
+ return (slonglong_t)(m_integer.sextOrTrunc(sizeof(slonglong_t) * 8))
+ .getSExtValue();
+ case e_float:
+ return (slonglong_t)m_float.convertToFloat();
+ case e_double:
+ return (slonglong_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (slonglong_t)(ldbl_val.sextOrTrunc(sizeof(slonglong_t) * 8))
+ .getSExtValue();
+ }
+ return fail_value;
+}
+
+unsigned long long Scalar::ULongLong(unsigned long long fail_value) const {
+ 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:
+ return (ulonglong_t)(m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8))
+ .getZExtValue();
+ case e_float:
+ return (ulonglong_t)m_float.convertToFloat();
+ case e_double:
+ return (ulonglong_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (ulonglong_t)(ldbl_val.zextOrTrunc(sizeof(ulonglong_t) * 8))
+ .getZExtValue();
+ }
+ return fail_value;
+}
+
+llvm::APInt Scalar::SInt128(llvm::APInt &fail_value) const {
+ 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:
+ return m_integer;
+ case e_float:
+ case e_double:
+ case e_long_double:
+ return m_float.bitcastToAPInt();
+ }
+ return fail_value;
+}
+
+llvm::APInt Scalar::UInt128(const llvm::APInt &fail_value) const {
+ 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:
+ return m_integer;
+ case e_float:
+ case e_double:
+ case e_long_double:
+ return m_float.bitcastToAPInt();
+ }
+ return fail_value;
+}
+
+llvm::APInt Scalar::SInt256(llvm::APInt &fail_value) const {
+ 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:
+ return m_integer;
+ case e_float:
+ case e_double:
+ case e_long_double:
+ return m_float.bitcastToAPInt();
+ }
+ return fail_value;
+}
+
+llvm::APInt Scalar::UInt256(const llvm::APInt &fail_value) const {
+ 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:
+ return m_integer;
+ case e_float:
+ case e_double:
+ case e_long_double:
+ return m_float.bitcastToAPInt();
+ }
+ return fail_value;
+}
+
+float Scalar::Float(float fail_value) const {
+ 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:
+ return m_integer.bitsToFloat();
+ case e_float:
+ return m_float.convertToFloat();
+ case e_double:
+ return (float_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return ldbl_val.bitsToFloat();
+ }
+ return fail_value;
+}
+
+double Scalar::Double(double fail_value) const {
+ 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:
+ return m_integer.bitsToDouble();
+ case e_float:
+ return (double_t)m_float.convertToFloat();
+ case e_double:
+ return m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return ldbl_val.bitsToFloat();
+ }
+ return fail_value;
+}
+
+long double Scalar::LongDouble(long double fail_value) const {
+ 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:
+ return (long_double_t)m_integer.bitsToDouble();
+ case e_float:
+ return (long_double_t)m_float.convertToFloat();
+ case e_double:
+ return (long_double_t)m_float.convertToDouble();
+ case e_long_double:
+ llvm::APInt ldbl_val = m_float.bitcastToAPInt();
+ return (long_double_t)ldbl_val.bitsToDouble();
+ }
+ return fail_value;
+}
+
+Scalar &Scalar::operator+=(const Scalar &rhs) {
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ if ((m_type = PromoteToMaxType(*this, rhs, temp_value, a, b)) !=
+ Scalar::e_void) {
+ switch (m_type) {
+ case e_void:
+ break;
case e_sint:
case e_uint:
case e_slong:
@@ -1789,92 +1909,45 @@ Scalar::Double(double fail_value) const
case e_uint128:
case e_sint256:
case e_uint256:
- return m_integer.bitsToDouble();
- case e_float:
- return (double_t)m_float.convertToFloat();
- case e_double:
- return m_float.convertToDouble();
- case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return ldbl_val.bitsToFloat();
- }
- return fail_value;
-}
+ m_integer = a->m_integer + b->m_integer;
+ break;
-long double
-Scalar::LongDouble(long double fail_value) const
-{
- 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:
- return (long_double_t)m_integer.bitsToDouble();
case e_float:
- return (long_double_t)m_float.convertToFloat();
case e_double:
- return (long_double_t)m_float.convertToDouble();
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (long_double_t)ldbl_val.bitsToDouble();
+ m_float = a->m_float + b->m_float;
+ break;
}
- return fail_value;
+ }
+ return *this;
}
-Scalar&
-Scalar::operator+= (const Scalar& rhs)
-{
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- if ((m_type = PromoteToMaxType(*this, rhs, temp_value, a, b)) != Scalar::e_void)
- {
- 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:
- m_integer = a->m_integer + b->m_integer;
- break;
+Scalar &Scalar::operator<<=(const Scalar &rhs) {
+ switch (m_type) {
+ case e_void:
+ case e_float:
+ case e_double:
+ case e_long_double:
+ m_type = e_void;
+ break;
- case e_float:
- case e_double:
- case e_long_double:
- m_float = a->m_float + b->m_float;
- break;
- }
- }
- return *this;
-}
-
-Scalar&
-Scalar::operator<<= (const Scalar& rhs)
-{
- switch (m_type)
- {
+ 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 (rhs.m_type) {
case e_void:
case e_float:
case e_double:
case e_long_double:
- m_type = e_void;
- break;
-
+ m_type = e_void;
+ break;
case e_sint:
case e_uint:
case e_slong:
@@ -1885,92 +1958,40 @@ Scalar::operator<<= (const Scalar& rhs)
case e_uint128:
case e_sint256:
case e_uint256:
- switch (rhs.m_type)
- {
- case e_void:
- case e_float:
- case e_double:
- case e_long_double:
- m_type = 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_integer << rhs.m_integer;
- break;
- }
- break;
+ m_integer = m_integer << rhs.m_integer;
+ break;
}
- return *this;
+ break;
+ }
+ return *this;
}
-bool
-Scalar::ShiftRightLogical(const Scalar& rhs)
-{
- switch (m_type)
- {
- case e_void:
- case e_float:
- case e_double:
- case e_long_double:
- m_type = e_void;
- break;
+bool Scalar::ShiftRightLogical(const Scalar &rhs) {
+ switch (m_type) {
+ case e_void:
+ case e_float:
+ case e_double:
+ case e_long_double:
+ m_type = 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 (rhs.m_type)
- {
- case e_void:
- case e_float:
- case e_double:
- case e_long_double:
- m_type = 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_integer.lshr(rhs.m_integer);
- break;
- }
- break;
- }
- return m_type != e_void;
-}
-
-Scalar&
-Scalar::operator>>= (const Scalar& rhs)
-{
- switch (m_type)
- {
+ 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 (rhs.m_type) {
case e_void:
case e_float:
case e_double:
case e_long_double:
- m_type = e_void;
- break;
-
+ m_type = e_void;
+ break;
case e_sint:
case e_uint:
case e_slong:
@@ -1981,44 +2002,40 @@ Scalar::operator>>= (const Scalar& rhs)
case e_uint128:
case e_sint256:
case e_uint256:
- switch (rhs.m_type)
- {
- case e_void:
- case e_float:
- case e_double:
- case e_long_double:
- m_type = 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_integer.ashr(rhs.m_integer);
- break;
- }
- break;
+ m_integer = m_integer.lshr(rhs.m_integer);
+ break;
}
- return *this;
+ break;
+ }
+ return m_type != e_void;
}
-Scalar&
-Scalar::operator&= (const Scalar& rhs)
-{
- switch (m_type)
- {
+Scalar &Scalar::operator>>=(const Scalar &rhs) {
+ switch (m_type) {
+ case e_void:
+ case e_float:
+ case e_double:
+ case e_long_double:
+ m_type = 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 (rhs.m_type) {
case e_void:
case e_float:
case e_double:
case e_long_double:
- m_type = e_void;
- break;
-
+ m_type = e_void;
+ break;
case e_sint:
case e_uint:
case e_slong:
@@ -2029,93 +2046,40 @@ Scalar::operator&= (const Scalar& rhs)
case e_uint128:
case e_sint256:
case e_uint256:
- switch (rhs.m_type)
- {
- case e_void:
- case e_float:
- case e_double:
- case e_long_double:
- m_type = 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 &= rhs.m_integer;
- break;
- }
- break;
+ m_integer = m_integer.ashr(rhs.m_integer);
+ break;
}
- return *this;
+ break;
+ }
+ return *this;
}
-bool
-Scalar::AbsoluteValue()
-{
- switch (m_type)
- {
- case e_void:
- break;
-
- case e_sint:
- case e_slong:
- case e_slonglong:
- case e_sint128:
- case e_sint256:
- if (m_integer.isNegative())
- m_integer = -m_integer;
- return true;
-
- case e_uint:
- case e_ulong:
- case e_ulonglong: return true;
- case e_uint128:
- case e_uint256:
- case e_float:
- case e_double:
- case e_long_double:
- m_float.clearSign();
- return true;
- }
- return false;
-}
+Scalar &Scalar::operator&=(const Scalar &rhs) {
+ switch (m_type) {
+ case e_void:
+ case e_float:
+ case e_double:
+ case e_long_double:
+ m_type = e_void;
+ break;
-bool
-Scalar::UnaryNegate()
-{
- 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:
- m_integer = -m_integer; return true;
+ 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 (rhs.m_type) {
+ case e_void:
case e_float:
case e_double:
case e_long_double:
- m_float.changeSign(); return true;
- }
- return false;
-}
-
-bool
-Scalar::OnesComplement()
-{
- switch (m_type)
- {
+ m_type = e_void;
+ break;
case e_sint:
case e_uint:
case e_slong:
@@ -2126,696 +2090,102 @@ Scalar::OnesComplement()
case e_uint128:
case e_sint256:
case e_uint256:
- m_integer = ~m_integer; return true;
-
- case e_void:
- case e_float:
- case e_double:
- case e_long_double:
- break;
- }
- return false;
-}
-
-const Scalar
-lldb_private::operator+ (const Scalar& lhs, const Scalar& rhs)
-{
- Scalar result;
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) != Scalar::e_void)
- {
- switch (result.m_type)
- {
- case Scalar::e_void: break;
- case Scalar::e_sint:
- case Scalar::e_uint:
- case Scalar::e_slong:
- case Scalar::e_ulong:
- case Scalar::e_slonglong:
- case Scalar::e_ulonglong:
- case Scalar::e_sint128:
- case Scalar::e_uint128:
- case Scalar::e_sint256:
- case Scalar::e_uint256:
- result.m_integer = a->m_integer + b->m_integer; break;
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- result.m_float = a->m_float + b->m_float; break;
- }
- }
- return result;
-}
-
-const Scalar
-lldb_private::operator- (const Scalar& lhs, const Scalar& rhs)
-{
- Scalar result;
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) != Scalar::e_void)
- {
- switch (result.m_type)
- {
- case Scalar::e_void: break;
- case Scalar::e_sint:
- case Scalar::e_uint:
- case Scalar::e_slong:
- case Scalar::e_ulong:
- case Scalar::e_slonglong:
- case Scalar::e_ulonglong:
- case Scalar::e_sint128:
- case Scalar::e_uint128:
- case Scalar::e_sint256:
- case Scalar::e_uint256:
- result.m_integer = a->m_integer - b->m_integer; break;
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- result.m_float = a->m_float - b->m_float; break;
- }
- }
- return result;
-}
-
-const Scalar
-lldb_private::operator/ (const Scalar& lhs, const Scalar& rhs)
-{
- Scalar result;
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) != Scalar::e_void)
- {
- switch (result.m_type)
- {
- case Scalar::e_void: break;
- case Scalar::e_sint:
- case Scalar::e_slong:
- case Scalar::e_slonglong:
- case Scalar::e_sint128:
- case Scalar::e_sint256:
- if (b->m_integer != 0)
- {
- result.m_integer = a->m_integer.sdiv(b->m_integer);
- return result;
- }
- break;
- case Scalar::e_uint:
- case Scalar::e_ulong:
- case Scalar::e_ulonglong:
- case Scalar::e_uint128:
- case Scalar::e_uint256:
- if (b->m_integer != 0)
- {
- result.m_integer = a->m_integer.udiv(b->m_integer);
- return result;
- }
- break;
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- if (b->m_float.isZero())
- {
- result.m_float = a->m_float / b->m_float;
- return result;
- }
- break;
- }
- }
- // 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.
- result.m_type = Scalar::e_void;
- return result;
-}
-
-const Scalar
-lldb_private::operator* (const Scalar& lhs, const Scalar& rhs)
-{
- Scalar result;
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) != Scalar::e_void)
- {
- switch (result.m_type)
- {
- case Scalar::e_void: break;
- case Scalar::e_sint:
- case Scalar::e_uint:
- case Scalar::e_slong:
- case Scalar::e_ulong:
- case Scalar::e_slonglong:
- case Scalar::e_ulonglong:
- case Scalar::e_sint128:
- case Scalar::e_uint128:
- case Scalar::e_sint256:
- case Scalar::e_uint256:
- result.m_integer = a->m_integer * b->m_integer; break;
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- result.m_float = a->m_float * b->m_float; break;
- }
- }
- return result;
-}
-
-const Scalar
-lldb_private::operator& (const Scalar& lhs, const Scalar& rhs)
-{
- Scalar result;
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) != Scalar::e_void)
- {
- switch (result.m_type)
- {
- case Scalar::e_sint:
- case Scalar::e_uint:
- case Scalar::e_slong:
- case Scalar::e_ulong:
- case Scalar::e_slonglong:
- case Scalar::e_ulonglong:
- case Scalar::e_sint128:
- case Scalar::e_uint128:
- case Scalar::e_sint256:
- case Scalar::e_uint256:
- result.m_integer = a->m_integer & b->m_integer; break;
- case Scalar::e_void:
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- // No bitwise AND on floats, doubles of long doubles
- result.m_type = Scalar::e_void;
- break;
- }
- }
- return result;
-}
-
-const Scalar
-lldb_private::operator| (const Scalar& lhs, const Scalar& rhs)
-{
- Scalar result;
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) != Scalar::e_void)
- {
- switch (result.m_type)
- {
- case Scalar::e_sint:
- case Scalar::e_uint:
- case Scalar::e_slong:
- case Scalar::e_ulong:
- case Scalar::e_slonglong:
- case Scalar::e_ulonglong:
- case Scalar::e_sint128:
- case Scalar::e_uint128:
- case Scalar::e_sint256:
- case Scalar::e_uint256:
- result.m_integer = a->m_integer | b->m_integer; break;
-
- case Scalar::e_void:
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- // No bitwise AND on floats, doubles of long doubles
- result.m_type = Scalar::e_void;
- break;
- }
- }
- return result;
-}
-
-const Scalar
-lldb_private::operator% (const Scalar& lhs, const Scalar& rhs)
-{
- Scalar result;
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) != Scalar::e_void)
- {
- switch (result.m_type)
- {
- default: break;
- case Scalar::e_void: break;
- case Scalar::e_sint:
- case Scalar::e_slong:
- case Scalar::e_slonglong:
- case Scalar::e_sint128:
- case Scalar::e_sint256:
- if (b->m_integer != 0)
- {
- result.m_integer = a->m_integer.srem(b->m_integer);
- return result;
- }
- break;
- case Scalar::e_uint:
- case Scalar::e_ulong:
- case Scalar::e_ulonglong:
- case Scalar::e_uint128:
- case Scalar::e_uint256:
- if (b->m_integer != 0)
- {
- result.m_integer = a->m_integer.urem(b->m_integer);
- return result;
- }
- break;
- }
- }
- result.m_type = Scalar::e_void;
- return result;
-}
-
-const Scalar
-lldb_private::operator^ (const Scalar& lhs, const Scalar& rhs)
-{
- Scalar result;
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) != Scalar::e_void)
- {
- switch (result.m_type)
- {
- case Scalar::e_sint:
- case Scalar::e_uint:
- case Scalar::e_slong:
- case Scalar::e_ulong:
- case Scalar::e_slonglong:
- case Scalar::e_ulonglong:
- case Scalar::e_sint128:
- case Scalar::e_uint128:
- case Scalar::e_sint256:
- case Scalar::e_uint256:
- result.m_integer = a->m_integer ^ b->m_integer; break;
-
- case Scalar::e_void:
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- // No bitwise AND on floats, doubles of long doubles
- result.m_type = Scalar::e_void;
- break;
- }
+ m_integer &= rhs.m_integer;
+ break;
}
- return result;
+ break;
+ }
+ return *this;
}
-const Scalar
-lldb_private::operator<< (const Scalar& lhs, const Scalar &rhs)
-{
- Scalar result = lhs;
- result <<= rhs;
- return result;
-}
-
-const Scalar
-lldb_private::operator>> (const Scalar& lhs, const Scalar &rhs)
-{
- Scalar result = lhs;
- result >>= rhs;
- return result;
-}
-
-Error
-Scalar::SetValueFromCString (const char *value_str, Encoding encoding, size_t byte_size)
-{
- Error error;
- if (value_str == nullptr || value_str[0] == '\0')
- {
- 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)
- error.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string value", value_str);
- else if (!UIntValueIsValidForSize (uval64, byte_size))
- error.SetErrorStringWithFormat("value 0x%" PRIx64 " is too large to fit in a %" PRIu64 " byte unsigned integer value", uval64, (uint64_t)byte_size);
- else
- {
- m_type = Scalar::GetValueTypeForUnsignedIntegerWithByteSize (byte_size);
- switch (m_type)
- {
- case e_uint: m_integer = llvm::APInt(sizeof(uint_t) * 8, uval64, false); break;
- case e_ulong: m_integer = llvm::APInt(sizeof(ulong_t) * 8, uval64, false); break;
- case e_ulonglong: m_integer = llvm::APInt(sizeof(ulonglong_t) * 8, uval64, false); break;
- default:
- error.SetErrorStringWithFormat("unsupported unsigned integer byte size: %" PRIu64 "", (uint64_t)byte_size);
- break;
- }
- }
- }
- else
- {
- error.SetErrorStringWithFormat("unsupported unsigned integer byte size: %" PRIu64 "", (uint64_t)byte_size);
- return error;
- }
- break;
-
- case eEncodingSint:
- if (byte_size <= sizeof (long long))
- {
- uint64_t sval64 = StringConvert::ToSInt64(value_str, INT64_MAX, 0, &success);
- if (!success)
- error.SetErrorStringWithFormat ("'%s' is not a valid signed integer string value", value_str);
- else if (!SIntValueIsValidForSize (sval64, byte_size))
- error.SetErrorStringWithFormat("value 0x%" PRIx64 " is too large to fit in a %" PRIu64 " byte signed integer value", sval64, (uint64_t)byte_size);
- else
- {
- m_type = Scalar::GetValueTypeForSignedIntegerWithByteSize (byte_size);
- switch (m_type)
- {
- case e_sint: m_integer = llvm::APInt(sizeof(sint_t) * 8, sval64, true); break;
- case e_slong: m_integer = llvm::APInt(sizeof(slong_t) * 8, sval64, true); break;
- case e_slonglong: m_integer = llvm::APInt(sizeof(slonglong_t) * 8, sval64, true); break;
- default:
- error.SetErrorStringWithFormat("unsupported signed integer byte size: %" PRIu64 "", (uint64_t)byte_size);
- break;
- }
- }
- }
- else
- {
- error.SetErrorStringWithFormat("unsupported signed integer byte size: %" PRIu64 "", (uint64_t)byte_size);
- return error;
- }
- break;
+bool Scalar::AbsoluteValue() {
+ switch (m_type) {
+ case e_void:
+ break;
- case eEncodingIEEE754:
- static float f_val;
- static double d_val;
- static long double l_val;
- if (byte_size == sizeof (float))
- {
- if (::sscanf (value_str, "%f", &f_val) == 1)
- {
- m_float = llvm::APFloat(f_val);
- m_type = e_float;
- }
- else
- error.SetErrorStringWithFormat ("'%s' is not a valid float string value", value_str);
- }
- else if (byte_size == sizeof (double))
- {
- if (::sscanf (value_str, "%lf", &d_val) == 1)
- {
- m_float = llvm::APFloat(d_val);
- m_type = e_double;
- }
- else
- error.SetErrorStringWithFormat ("'%s' is not a valid float string value", value_str);
- }
- else if (byte_size == sizeof (long double))
- {
- if (::sscanf (value_str, "%Lf", &l_val) == 1)
- {
- m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended, llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&l_val)->x));
- m_type = e_long_double;
- }
- else
- error.SetErrorStringWithFormat ("'%s' is not a valid float string value", value_str);
- }
- else
- {
- error.SetErrorStringWithFormat("unsupported float byte size: %" PRIu64 "", (uint64_t)byte_size);
- return error;
- }
- break;
-
- case eEncodingVector:
- error.SetErrorString ("vector encoding unsupported.");
- break;
- }
- if (error.Fail())
- m_type = e_void;
-
- return error;
-}
+ case e_sint:
+ case e_slong:
+ case e_slonglong:
+ case e_sint128:
+ case e_sint256:
+ if (m_integer.isNegative())
+ m_integer = -m_integer;
+ return true;
-Error
-Scalar::SetValueFromData (DataExtractor &data, lldb::Encoding encoding, size_t byte_size)
-{
- Error error;
-
- type128 int128;
- type256 int256;
- switch (encoding)
- {
- case lldb::eEncodingInvalid:
- error.SetErrorString ("invalid encoding");
- break;
- case lldb::eEncodingVector:
- error.SetErrorString ("vector encoding unsupported");
- break;
- case lldb::eEncodingUint:
- {
- lldb::offset_t offset = 0;
-
- switch (byte_size)
- {
- case 1: operator=((uint8_t)data.GetU8(&offset)); break;
- case 2: operator=((uint16_t)data.GetU16(&offset)); break;
- case 4: operator=((uint32_t)data.GetU32(&offset)); break;
- case 8: operator=((uint64_t)data.GetU64(&offset)); break;
- case 16:
- if (data.GetByteOrder() == eByteOrderBig)
- {
- int128.x[1] = (uint64_t)data.GetU64 (&offset);
- int128.x[0] = (uint64_t)data.GetU64 (&offset);
- }
- else
- {
- int128.x[0] = (uint64_t)data.GetU64 (&offset);
- int128.x[1] = (uint64_t)data.GetU64 (&offset);
- }
- operator=(llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, int128.x));
- break;
- case 32:
- if (data.GetByteOrder() == eByteOrderBig)
- {
- int256.x[3] = (uint64_t)data.GetU64 (&offset);
- int256.x[2] = (uint64_t)data.GetU64 (&offset);
- int256.x[1] = (uint64_t)data.GetU64 (&offset);
- int256.x[0] = (uint64_t)data.GetU64 (&offset);
- }
- else
- {
- int256.x[0] = (uint64_t)data.GetU64 (&offset);
- int256.x[1] = (uint64_t)data.GetU64 (&offset);
- int256.x[2] = (uint64_t)data.GetU64 (&offset);
- int256.x[3] = (uint64_t)data.GetU64 (&offset);
- }
- operator=(llvm::APInt(BITWIDTH_INT256, NUM_OF_WORDS_INT256, int256.x));
- break;
- default:
- error.SetErrorStringWithFormat("unsupported unsigned integer byte size: %" PRIu64 "", (uint64_t)byte_size);
- break;
- }
- }
- break;
- case lldb::eEncodingSint:
- {
- lldb::offset_t offset = 0;
-
- switch (byte_size)
- {
- case 1: operator=((int8_t)data.GetU8(&offset)); break;
- case 2: operator=((int16_t)data.GetU16(&offset)); break;
- case 4: operator=((int32_t)data.GetU32(&offset)); break;
- case 8: operator=((int64_t)data.GetU64(&offset)); break;
- case 16:
- if (data.GetByteOrder() == eByteOrderBig)
- {
- int128.x[1] = (uint64_t)data.GetU64 (&offset);
- int128.x[0] = (uint64_t)data.GetU64 (&offset);
- }
- else
- {
- int128.x[0] = (uint64_t)data.GetU64 (&offset);
- int128.x[1] = (uint64_t)data.GetU64 (&offset);
- }
- operator=(llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, int128.x));
- break;
- case 32:
- if (data.GetByteOrder() == eByteOrderBig)
- {
- int256.x[3] = (uint64_t)data.GetU64 (&offset);
- int256.x[2] = (uint64_t)data.GetU64 (&offset);
- int256.x[1] = (uint64_t)data.GetU64 (&offset);
- int256.x[0] = (uint64_t)data.GetU64 (&offset);
- }
- else
- {
- int256.x[0] = (uint64_t)data.GetU64 (&offset);
- int256.x[1] = (uint64_t)data.GetU64 (&offset);
- int256.x[2] = (uint64_t)data.GetU64 (&offset);
- int256.x[3] = (uint64_t)data.GetU64 (&offset);
- }
- operator=(llvm::APInt(BITWIDTH_INT256, NUM_OF_WORDS_INT256, int256.x));
- break;
- default:
- error.SetErrorStringWithFormat("unsupported signed integer byte size: %" PRIu64 "", (uint64_t)byte_size);
- break;
- }
- }
- break;
- case lldb::eEncodingIEEE754:
- {
- lldb::offset_t offset = 0;
-
- if (byte_size == sizeof (float))
- operator=((float)data.GetFloat(&offset));
- else if (byte_size == sizeof (double))
- operator=((double)data.GetDouble(&offset));
- else if (byte_size == sizeof (long double))
- operator=((long double)data.GetLongDouble(&offset));
- else
- error.SetErrorStringWithFormat("unsupported float byte size: %" PRIu64 "", (uint64_t)byte_size);
- }
- break;
- }
-
- return error;
+ case e_uint:
+ case e_ulong:
+ case e_ulonglong:
+ return true;
+ case e_uint128:
+ case e_uint256:
+ case e_float:
+ case e_double:
+ case e_long_double:
+ m_float.clearSign();
+ return true;
+ }
+ return false;
}
-bool
-Scalar::SignExtend (uint32_t sign_bit_pos)
-{
- const uint32_t max_bit_pos = GetByteSize() * 8;
-
- if (sign_bit_pos < max_bit_pos)
- {
- switch (m_type)
- {
- case Scalar::e_void:
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- return false;
-
- case Scalar::e_sint:
- case Scalar::e_uint:
- case Scalar::e_slong:
- case Scalar::e_ulong:
- case Scalar::e_slonglong:
- case Scalar::e_ulonglong:
- case Scalar::e_sint128:
- case Scalar::e_uint128:
- case Scalar::e_sint256:
- case Scalar::e_uint256:
- if (max_bit_pos == sign_bit_pos)
- return true;
- else if (sign_bit_pos < (max_bit_pos-1))
- {
- llvm::APInt sign_bit = llvm::APInt::getSignBit(sign_bit_pos + 1);
- llvm::APInt bitwize_and = m_integer & sign_bit;
- if (bitwize_and.getBoolValue())
- {
- const llvm::APInt mask = ~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
- m_integer |= mask;
- }
- return true;
- }
- break;
- }
- }
- return false;
+bool Scalar::UnaryNegate() {
+ 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:
+ m_integer = -m_integer;
+ return true;
+ case e_float:
+ case e_double:
+ case e_long_double:
+ m_float.changeSign();
+ return true;
+ }
+ return false;
}
-size_t
-Scalar::GetAsMemoryData (void *dst,
- size_t dst_len,
- lldb::ByteOrder dst_byte_order,
- Error &error) const
-{
- // Get a data extractor that points to the native scalar data
- DataExtractor data;
- if (!GetData(data))
- {
- error.SetErrorString ("invalid scalar value");
- return 0;
- }
-
- const size_t src_len = data.GetByteSize();
-
- // Prepare a memory buffer that contains some or all of the register value
- const size_t bytes_copied = data.CopyByteOrderedData (0, // src offset
- src_len, // src length
- dst, // dst buffer
- dst_len, // dst length
- dst_byte_order); // dst byte order
- if (bytes_copied == 0)
- error.SetErrorString ("failed to copy data");
-
- return bytes_copied;
-}
-
-bool
-Scalar::ExtractBitfield (uint32_t bit_size,
- uint32_t bit_offset)
-{
- if (bit_size == 0)
- return true;
-
- switch (m_type)
- {
- case Scalar::e_void:
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- break;
-
- case Scalar::e_sint:
- case Scalar::e_slong:
- case Scalar::e_slonglong:
- case Scalar::e_sint128:
- case Scalar::e_sint256:
- m_integer = m_integer.ashr(bit_offset).sextOrTrunc(bit_size).sextOrSelf(8 * GetByteSize());
- return true;
-
- case Scalar::e_uint:
- case Scalar::e_ulong:
- case Scalar::e_ulonglong:
- case Scalar::e_uint128:
- case Scalar::e_uint256:
- m_integer = m_integer.lshr(bit_offset).zextOrTrunc(bit_size).zextOrSelf(8 * GetByteSize());
- return true;
- }
- return false;
-}
+bool Scalar::OnesComplement() {
+ switch (m_type) {
+ 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_integer;
+ return true;
-bool
-lldb_private::operator== (const Scalar& lhs, const Scalar& rhs)
-{
- // If either entry is void then we can just compare the types
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return lhs.m_type == rhs.m_type;
-
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- llvm::APFloat::cmpResult result;
- switch (PromoteToMaxType(lhs, rhs, temp_value, a, b))
- {
- case Scalar::e_void: break;
+ case e_void:
+ case e_float:
+ case e_double:
+ case e_long_double:
+ break;
+ }
+ return false;
+}
+
+const Scalar lldb_private::operator+(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result;
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) !=
+ Scalar::e_void) {
+ switch (result.m_type) {
+ case Scalar::e_void:
+ break;
case Scalar::e_sint:
case Scalar::e_uint:
case Scalar::e_slong:
@@ -2826,31 +2196,28 @@ lldb_private::operator== (const Scalar&
case Scalar::e_uint128:
case Scalar::e_sint256:
case Scalar::e_uint256:
- return a->m_integer == b->m_integer;
+ result.m_integer = a->m_integer + b->m_integer;
+ break;
case Scalar::e_float:
case Scalar::e_double:
case Scalar::e_long_double:
- result = a->m_float.compare(b->m_float);
- if(result == llvm::APFloat::cmpEqual)
- return true;
+ result.m_float = a->m_float + b->m_float;
+ break;
}
- return false;
+ }
+ return result;
}
-bool
-lldb_private::operator!= (const Scalar& lhs, const Scalar& rhs)
-{
- // If either entry is void then we can just compare the types
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return lhs.m_type != rhs.m_type;
-
- Scalar temp_value; // A temp value that might get a copy of either promoted value
- const Scalar* a;
- const Scalar* b;
- llvm::APFloat::cmpResult result;
- switch (PromoteToMaxType(lhs, rhs, temp_value, a, b))
- {
- case Scalar::e_void: break;
+const Scalar lldb_private::operator-(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result;
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) !=
+ Scalar::e_void) {
+ switch (result.m_type) {
+ case Scalar::e_void:
+ break;
case Scalar::e_sint:
case Scalar::e_uint:
case Scalar::e_slong:
@@ -2861,202 +2228,849 @@ lldb_private::operator!= (const Scalar&
case Scalar::e_uint128:
case Scalar::e_sint256:
case Scalar::e_uint256:
- return a->m_integer != b->m_integer;
+ result.m_integer = a->m_integer - b->m_integer;
+ break;
case Scalar::e_float:
case Scalar::e_double:
case Scalar::e_long_double:
- result = a->m_float.compare(b->m_float);
- if(result != llvm::APFloat::cmpEqual)
- return true;
+ result.m_float = a->m_float - b->m_float;
+ break;
}
- return true;
+ }
+ return result;
}
-bool
-lldb_private::operator< (const Scalar& lhs, const Scalar& rhs)
-{
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return false;
-
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- llvm::APFloat::cmpResult result;
- switch (PromoteToMaxType(lhs, rhs, temp_value, a, b))
- {
- case Scalar::e_void: break;
+const Scalar lldb_private::operator/(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result;
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) !=
+ Scalar::e_void) {
+ switch (result.m_type) {
+ case Scalar::e_void:
+ break;
case Scalar::e_sint:
case Scalar::e_slong:
case Scalar::e_slonglong:
case Scalar::e_sint128:
case Scalar::e_sint256:
- return a->m_integer.slt(b->m_integer);
+ if (b->m_integer != 0) {
+ result.m_integer = a->m_integer.sdiv(b->m_integer);
+ return result;
+ }
+ break;
+ case Scalar::e_uint:
+ case Scalar::e_ulong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_uint128:
+ case Scalar::e_uint256:
+ if (b->m_integer != 0) {
+ result.m_integer = a->m_integer.udiv(b->m_integer);
+ return result;
+ }
+ break;
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ if (b->m_float.isZero()) {
+ result.m_float = a->m_float / b->m_float;
+ return result;
+ }
+ break;
+ }
+ }
+ // 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.
+ result.m_type = Scalar::e_void;
+ return result;
+}
+
+const Scalar lldb_private::operator*(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result;
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) !=
+ Scalar::e_void) {
+ switch (result.m_type) {
+ case Scalar::e_void:
+ break;
+ case Scalar::e_sint:
case Scalar::e_uint:
+ case Scalar::e_slong:
case Scalar::e_ulong:
+ case Scalar::e_slonglong:
case Scalar::e_ulonglong:
+ case Scalar::e_sint128:
case Scalar::e_uint128:
+ case Scalar::e_sint256:
case Scalar::e_uint256:
- return a->m_integer.ult(b->m_integer);
+ result.m_integer = a->m_integer * b->m_integer;
+ break;
case Scalar::e_float:
case Scalar::e_double:
case Scalar::e_long_double:
- result = a->m_float.compare(b->m_float);
- if(result == llvm::APFloat::cmpLessThan)
- return true;
+ result.m_float = a->m_float * b->m_float;
+ break;
}
- return false;
+ }
+ return result;
}
-bool
-lldb_private::operator<= (const Scalar& lhs, const Scalar& rhs)
-{
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return false;
-
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- llvm::APFloat::cmpResult result;
- switch (PromoteToMaxType(lhs, rhs, temp_value, a, b))
- {
- case Scalar::e_void: break;
+const Scalar lldb_private::operator&(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result;
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) !=
+ Scalar::e_void) {
+ switch (result.m_type) {
case Scalar::e_sint:
+ case Scalar::e_uint:
case Scalar::e_slong:
+ case Scalar::e_ulong:
case Scalar::e_slonglong:
+ case Scalar::e_ulonglong:
case Scalar::e_sint128:
+ case Scalar::e_uint128:
case Scalar::e_sint256:
- return a->m_integer.sle(b->m_integer);
+ case Scalar::e_uint256:
+ result.m_integer = a->m_integer & b->m_integer;
+ break;
+ case Scalar::e_void:
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ // No bitwise AND on floats, doubles of long doubles
+ result.m_type = Scalar::e_void;
+ break;
+ }
+ }
+ return result;
+}
+
+const Scalar lldb_private::operator|(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result;
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) !=
+ Scalar::e_void) {
+ switch (result.m_type) {
+ case Scalar::e_sint:
case Scalar::e_uint:
+ case Scalar::e_slong:
case Scalar::e_ulong:
+ case Scalar::e_slonglong:
case Scalar::e_ulonglong:
+ case Scalar::e_sint128:
case Scalar::e_uint128:
+ case Scalar::e_sint256:
case Scalar::e_uint256:
- return a->m_integer.ule(b->m_integer);
+ result.m_integer = a->m_integer | b->m_integer;
+ break;
+
+ case Scalar::e_void:
case Scalar::e_float:
case Scalar::e_double:
case Scalar::e_long_double:
- result = a->m_float.compare(b->m_float);
- if(result == llvm::APFloat::cmpLessThan || result == llvm::APFloat::cmpEqual)
- return true;
+ // No bitwise AND on floats, doubles of long doubles
+ result.m_type = Scalar::e_void;
+ break;
+ }
+ }
+ return result;
+}
+
+const Scalar lldb_private::operator%(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result;
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) !=
+ Scalar::e_void) {
+ switch (result.m_type) {
+ default:
+ break;
+ case Scalar::e_void:
+ break;
+ case Scalar::e_sint:
+ case Scalar::e_slong:
+ case Scalar::e_slonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_sint256:
+ if (b->m_integer != 0) {
+ result.m_integer = a->m_integer.srem(b->m_integer);
+ return result;
+ }
+ break;
+ case Scalar::e_uint:
+ case Scalar::e_ulong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_uint128:
+ case Scalar::e_uint256:
+ if (b->m_integer != 0) {
+ result.m_integer = a->m_integer.urem(b->m_integer);
+ return result;
+ }
+ break;
+ }
+ }
+ result.m_type = Scalar::e_void;
+ return result;
+}
+
+const Scalar lldb_private::operator^(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result;
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ if ((result.m_type = PromoteToMaxType(lhs, rhs, temp_value, a, b)) !=
+ Scalar::e_void) {
+ switch (result.m_type) {
+ case Scalar::e_sint:
+ case Scalar::e_uint:
+ case Scalar::e_slong:
+ case Scalar::e_ulong:
+ case Scalar::e_slonglong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_uint128:
+ case Scalar::e_sint256:
+ case Scalar::e_uint256:
+ result.m_integer = a->m_integer ^ b->m_integer;
+ break;
+
+ case Scalar::e_void:
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ // No bitwise AND on floats, doubles of long doubles
+ result.m_type = Scalar::e_void;
+ break;
}
- return false;
+ }
+ return result;
}
-bool
-lldb_private::operator> (const Scalar& lhs, const Scalar& rhs)
-{
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return false;
-
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- llvm::APFloat::cmpResult result;
- switch (PromoteToMaxType(lhs, rhs, temp_value, a, b))
- {
- case Scalar::e_void: break;
- case Scalar::e_sint:
- case Scalar::e_slong:
- case Scalar::e_slonglong:
- case Scalar::e_sint128:
- case Scalar::e_sint256:
- return a->m_integer.sgt(b->m_integer);
- case Scalar::e_uint:
- case Scalar::e_ulong:
- case Scalar::e_ulonglong:
- case Scalar::e_uint128:
- case Scalar::e_uint256:
- return a->m_integer.ugt(b->m_integer);
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- result = a->m_float.compare(b->m_float);
- if(result == llvm::APFloat::cmpGreaterThan)
- return true;
- }
- return false;
+const Scalar lldb_private::operator<<(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result = lhs;
+ result <<= rhs;
+ return result;
+}
+
+const Scalar lldb_private::operator>>(const Scalar &lhs, const Scalar &rhs) {
+ Scalar result = lhs;
+ result >>= rhs;
+ return result;
}
-bool
-lldb_private::operator>= (const Scalar& lhs, const Scalar& rhs)
-{
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return false;
-
- Scalar temp_value;
- const Scalar* a;
- const Scalar* b;
- llvm::APFloat::cmpResult result;
- switch (PromoteToMaxType(lhs, rhs, temp_value, a, b))
- {
- case Scalar::e_void: break;
- case Scalar::e_sint:
- case Scalar::e_slong:
- case Scalar::e_slonglong:
- case Scalar::e_sint128:
- case Scalar::e_sint256:
- return a->m_integer.sge(b->m_integer);
- case Scalar::e_uint:
- case Scalar::e_ulong:
- case Scalar::e_ulonglong:
- case Scalar::e_uint128:
- case Scalar::e_uint256:
- return a->m_integer.uge(b->m_integer);
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- result = a->m_float.compare(b->m_float);
- if(result == llvm::APFloat::cmpGreaterThan || result == llvm::APFloat::cmpEqual)
- return true;
+Error Scalar::SetValueFromCString(const char *value_str, Encoding encoding,
+ size_t byte_size) {
+ Error error;
+ if (value_str == nullptr || value_str[0] == '\0') {
+ 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)
+ error.SetErrorStringWithFormat(
+ "'%s' is not a valid unsigned integer string value", value_str);
+ else if (!UIntValueIsValidForSize(uval64, byte_size))
+ error.SetErrorStringWithFormat("value 0x%" PRIx64
+ " is too large to fit in a %" PRIu64
+ " byte unsigned integer value",
+ uval64, (uint64_t)byte_size);
+ else {
+ m_type = Scalar::GetValueTypeForUnsignedIntegerWithByteSize(byte_size);
+ switch (m_type) {
+ case e_uint:
+ m_integer = llvm::APInt(sizeof(uint_t) * 8, uval64, false);
+ break;
+ case e_ulong:
+ m_integer = llvm::APInt(sizeof(ulong_t) * 8, uval64, false);
+ break;
+ case e_ulonglong:
+ m_integer = llvm::APInt(sizeof(ulonglong_t) * 8, uval64, false);
+ break;
+ default:
+ error.SetErrorStringWithFormat(
+ "unsupported unsigned integer byte size: %" PRIu64 "",
+ (uint64_t)byte_size);
+ break;
+ }
+ }
+ } else {
+ error.SetErrorStringWithFormat(
+ "unsupported unsigned integer byte size: %" PRIu64 "",
+ (uint64_t)byte_size);
+ return error;
+ }
+ break;
+
+ case eEncodingSint:
+ if (byte_size <= sizeof(long long)) {
+ uint64_t sval64 =
+ StringConvert::ToSInt64(value_str, INT64_MAX, 0, &success);
+ if (!success)
+ error.SetErrorStringWithFormat(
+ "'%s' is not a valid signed integer string value", value_str);
+ else if (!SIntValueIsValidForSize(sval64, byte_size))
+ error.SetErrorStringWithFormat("value 0x%" PRIx64
+ " is too large to fit in a %" PRIu64
+ " byte signed integer value",
+ sval64, (uint64_t)byte_size);
+ else {
+ m_type = Scalar::GetValueTypeForSignedIntegerWithByteSize(byte_size);
+ switch (m_type) {
+ case e_sint:
+ m_integer = llvm::APInt(sizeof(sint_t) * 8, sval64, true);
+ break;
+ case e_slong:
+ m_integer = llvm::APInt(sizeof(slong_t) * 8, sval64, true);
+ break;
+ case e_slonglong:
+ m_integer = llvm::APInt(sizeof(slonglong_t) * 8, sval64, true);
+ break;
+ default:
+ error.SetErrorStringWithFormat(
+ "unsupported signed integer byte size: %" PRIu64 "",
+ (uint64_t)byte_size);
+ break;
+ }
+ }
+ } else {
+ error.SetErrorStringWithFormat(
+ "unsupported signed integer byte size: %" PRIu64 "",
+ (uint64_t)byte_size);
+ return error;
+ }
+ break;
+
+ case eEncodingIEEE754:
+ static float f_val;
+ static double d_val;
+ static long double l_val;
+ if (byte_size == sizeof(float)) {
+ if (::sscanf(value_str, "%f", &f_val) == 1) {
+ m_float = llvm::APFloat(f_val);
+ m_type = e_float;
+ } else
+ error.SetErrorStringWithFormat("'%s' is not a valid float string value",
+ value_str);
+ } else if (byte_size == sizeof(double)) {
+ if (::sscanf(value_str, "%lf", &d_val) == 1) {
+ m_float = llvm::APFloat(d_val);
+ m_type = e_double;
+ } else
+ error.SetErrorStringWithFormat("'%s' is not a valid float string value",
+ value_str);
+ } else if (byte_size == sizeof(long double)) {
+ if (::sscanf(value_str, "%Lf", &l_val) == 1) {
+ m_float =
+ llvm::APFloat(llvm::APFloat::x87DoubleExtended,
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
+ ((type128 *)&l_val)->x));
+ m_type = e_long_double;
+ } else
+ error.SetErrorStringWithFormat("'%s' is not a valid float string value",
+ value_str);
+ } else {
+ error.SetErrorStringWithFormat("unsupported float byte size: %" PRIu64 "",
+ (uint64_t)byte_size);
+ return error;
+ }
+ break;
+
+ case eEncodingVector:
+ error.SetErrorString("vector encoding unsupported.");
+ break;
+ }
+ if (error.Fail())
+ m_type = e_void;
+
+ return error;
+}
+
+Error Scalar::SetValueFromData(DataExtractor &data, lldb::Encoding encoding,
+ size_t byte_size) {
+ Error error;
+
+ type128 int128;
+ type256 int256;
+ switch (encoding) {
+ case lldb::eEncodingInvalid:
+ error.SetErrorString("invalid encoding");
+ break;
+ case lldb::eEncodingVector:
+ error.SetErrorString("vector encoding unsupported");
+ break;
+ case lldb::eEncodingUint: {
+ lldb::offset_t offset = 0;
+
+ switch (byte_size) {
+ case 1:
+ operator=((uint8_t)data.GetU8(&offset));
+ break;
+ case 2:
+ operator=((uint16_t)data.GetU16(&offset));
+ break;
+ case 4:
+ operator=((uint32_t)data.GetU32(&offset));
+ break;
+ case 8:
+ operator=((uint64_t)data.GetU64(&offset));
+ break;
+ case 16:
+ if (data.GetByteOrder() == eByteOrderBig) {
+ int128.x[1] = (uint64_t)data.GetU64(&offset);
+ int128.x[0] = (uint64_t)data.GetU64(&offset);
+ } else {
+ int128.x[0] = (uint64_t)data.GetU64(&offset);
+ int128.x[1] = (uint64_t)data.GetU64(&offset);
+ }
+ operator=(llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, int128.x));
+ break;
+ case 32:
+ if (data.GetByteOrder() == eByteOrderBig) {
+ int256.x[3] = (uint64_t)data.GetU64(&offset);
+ int256.x[2] = (uint64_t)data.GetU64(&offset);
+ int256.x[1] = (uint64_t)data.GetU64(&offset);
+ int256.x[0] = (uint64_t)data.GetU64(&offset);
+ } else {
+ int256.x[0] = (uint64_t)data.GetU64(&offset);
+ int256.x[1] = (uint64_t)data.GetU64(&offset);
+ int256.x[2] = (uint64_t)data.GetU64(&offset);
+ int256.x[3] = (uint64_t)data.GetU64(&offset);
+ }
+ operator=(llvm::APInt(BITWIDTH_INT256, NUM_OF_WORDS_INT256, int256.x));
+ break;
+ default:
+ error.SetErrorStringWithFormat(
+ "unsupported unsigned integer byte size: %" PRIu64 "",
+ (uint64_t)byte_size);
+ break;
+ }
+ } break;
+ case lldb::eEncodingSint: {
+ lldb::offset_t offset = 0;
+
+ switch (byte_size) {
+ case 1:
+ operator=((int8_t)data.GetU8(&offset));
+ break;
+ case 2:
+ operator=((int16_t)data.GetU16(&offset));
+ break;
+ case 4:
+ operator=((int32_t)data.GetU32(&offset));
+ break;
+ case 8:
+ operator=((int64_t)data.GetU64(&offset));
+ break;
+ case 16:
+ if (data.GetByteOrder() == eByteOrderBig) {
+ int128.x[1] = (uint64_t)data.GetU64(&offset);
+ int128.x[0] = (uint64_t)data.GetU64(&offset);
+ } else {
+ int128.x[0] = (uint64_t)data.GetU64(&offset);
+ int128.x[1] = (uint64_t)data.GetU64(&offset);
+ }
+ operator=(llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, int128.x));
+ break;
+ case 32:
+ if (data.GetByteOrder() == eByteOrderBig) {
+ int256.x[3] = (uint64_t)data.GetU64(&offset);
+ int256.x[2] = (uint64_t)data.GetU64(&offset);
+ int256.x[1] = (uint64_t)data.GetU64(&offset);
+ int256.x[0] = (uint64_t)data.GetU64(&offset);
+ } else {
+ int256.x[0] = (uint64_t)data.GetU64(&offset);
+ int256.x[1] = (uint64_t)data.GetU64(&offset);
+ int256.x[2] = (uint64_t)data.GetU64(&offset);
+ int256.x[3] = (uint64_t)data.GetU64(&offset);
+ }
+ operator=(llvm::APInt(BITWIDTH_INT256, NUM_OF_WORDS_INT256, int256.x));
+ break;
+ default:
+ error.SetErrorStringWithFormat(
+ "unsupported signed integer byte size: %" PRIu64 "",
+ (uint64_t)byte_size);
+ break;
+ }
+ } break;
+ case lldb::eEncodingIEEE754: {
+ lldb::offset_t offset = 0;
+
+ if (byte_size == sizeof(float))
+ operator=((float)data.GetFloat(&offset));
+ else if (byte_size == sizeof(double))
+ operator=((double)data.GetDouble(&offset));
+ else if (byte_size == sizeof(long double))
+ operator=((long double)data.GetLongDouble(&offset));
+ else
+ error.SetErrorStringWithFormat("unsupported float byte size: %" PRIu64 "",
+ (uint64_t)byte_size);
+ } break;
+ }
+
+ return error;
+}
+
+bool Scalar::SignExtend(uint32_t sign_bit_pos) {
+ const uint32_t max_bit_pos = GetByteSize() * 8;
+
+ if (sign_bit_pos < max_bit_pos) {
+ switch (m_type) {
+ case Scalar::e_void:
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ return false;
+
+ case Scalar::e_sint:
+ case Scalar::e_uint:
+ case Scalar::e_slong:
+ case Scalar::e_ulong:
+ case Scalar::e_slonglong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_uint128:
+ case Scalar::e_sint256:
+ case Scalar::e_uint256:
+ if (max_bit_pos == sign_bit_pos)
+ return true;
+ else if (sign_bit_pos < (max_bit_pos - 1)) {
+ llvm::APInt sign_bit = llvm::APInt::getSignBit(sign_bit_pos + 1);
+ llvm::APInt bitwize_and = m_integer & sign_bit;
+ if (bitwize_and.getBoolValue()) {
+ const llvm::APInt mask =
+ ~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
+ m_integer |= mask;
+ }
+ return true;
+ }
+ break;
}
+ }
+ return false;
+}
+
+size_t Scalar::GetAsMemoryData(void *dst, size_t dst_len,
+ lldb::ByteOrder dst_byte_order,
+ Error &error) const {
+ // Get a data extractor that points to the native scalar data
+ DataExtractor data;
+ if (!GetData(data)) {
+ error.SetErrorString("invalid scalar value");
+ return 0;
+ }
+
+ const size_t src_len = data.GetByteSize();
+
+ // Prepare a memory buffer that contains some or all of the register value
+ const size_t bytes_copied =
+ data.CopyByteOrderedData(0, // src offset
+ src_len, // src length
+ dst, // dst buffer
+ dst_len, // dst length
+ dst_byte_order); // dst byte order
+ if (bytes_copied == 0)
+ error.SetErrorString("failed to copy data");
+
+ return bytes_copied;
+}
+
+bool Scalar::ExtractBitfield(uint32_t bit_size, uint32_t bit_offset) {
+ if (bit_size == 0)
+ return true;
+
+ switch (m_type) {
+ case Scalar::e_void:
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ break;
+
+ case Scalar::e_sint:
+ case Scalar::e_slong:
+ case Scalar::e_slonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_sint256:
+ m_integer = m_integer.ashr(bit_offset)
+ .sextOrTrunc(bit_size)
+ .sextOrSelf(8 * GetByteSize());
+ return true;
+
+ case Scalar::e_uint:
+ case Scalar::e_ulong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_uint128:
+ case Scalar::e_uint256:
+ m_integer = m_integer.lshr(bit_offset)
+ .zextOrTrunc(bit_size)
+ .zextOrSelf(8 * GetByteSize());
+ return true;
+ }
+ return false;
+}
+
+bool lldb_private::operator==(const Scalar &lhs, const Scalar &rhs) {
+ // If either entry is void then we can just compare the types
+ if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
+ return lhs.m_type == rhs.m_type;
+
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ llvm::APFloat::cmpResult result;
+ switch (PromoteToMaxType(lhs, rhs, temp_value, a, b)) {
+ case Scalar::e_void:
+ break;
+ case Scalar::e_sint:
+ case Scalar::e_uint:
+ case Scalar::e_slong:
+ case Scalar::e_ulong:
+ case Scalar::e_slonglong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_uint128:
+ case Scalar::e_sint256:
+ case Scalar::e_uint256:
+ return a->m_integer == b->m_integer;
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ result = a->m_float.compare(b->m_float);
+ if (result == llvm::APFloat::cmpEqual)
+ return true;
+ }
+ return false;
+}
+
+bool lldb_private::operator!=(const Scalar &lhs, const Scalar &rhs) {
+ // If either entry is void then we can just compare the types
+ if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
+ return lhs.m_type != rhs.m_type;
+
+ Scalar
+ temp_value; // A temp value that might get a copy of either promoted value
+ const Scalar *a;
+ const Scalar *b;
+ llvm::APFloat::cmpResult result;
+ switch (PromoteToMaxType(lhs, rhs, temp_value, a, b)) {
+ case Scalar::e_void:
+ break;
+ case Scalar::e_sint:
+ case Scalar::e_uint:
+ case Scalar::e_slong:
+ case Scalar::e_ulong:
+ case Scalar::e_slonglong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_uint128:
+ case Scalar::e_sint256:
+ case Scalar::e_uint256:
+ return a->m_integer != b->m_integer;
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ result = a->m_float.compare(b->m_float);
+ if (result != llvm::APFloat::cmpEqual)
+ return true;
+ }
+ return true;
+}
+
+bool lldb_private::operator<(const Scalar &lhs, const Scalar &rhs) {
+ if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
return false;
+
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ llvm::APFloat::cmpResult result;
+ switch (PromoteToMaxType(lhs, rhs, temp_value, a, b)) {
+ case Scalar::e_void:
+ break;
+ case Scalar::e_sint:
+ case Scalar::e_slong:
+ case Scalar::e_slonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_sint256:
+ return a->m_integer.slt(b->m_integer);
+ case Scalar::e_uint:
+ case Scalar::e_ulong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_uint128:
+ case Scalar::e_uint256:
+ return a->m_integer.ult(b->m_integer);
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ result = a->m_float.compare(b->m_float);
+ if (result == llvm::APFloat::cmpLessThan)
+ return true;
+ }
+ return false;
}
-bool
-Scalar::ClearBit (uint32_t bit)
-{
- 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: m_integer.clearBit(bit); return true;
- case e_float:
- case e_double:
- case e_long_double: break;
- }
+bool lldb_private::operator<=(const Scalar &lhs, const Scalar &rhs) {
+ if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
return false;
+
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ llvm::APFloat::cmpResult result;
+ switch (PromoteToMaxType(lhs, rhs, temp_value, a, b)) {
+ case Scalar::e_void:
+ break;
+ case Scalar::e_sint:
+ case Scalar::e_slong:
+ case Scalar::e_slonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_sint256:
+ return a->m_integer.sle(b->m_integer);
+ case Scalar::e_uint:
+ case Scalar::e_ulong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_uint128:
+ case Scalar::e_uint256:
+ return a->m_integer.ule(b->m_integer);
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ result = a->m_float.compare(b->m_float);
+ if (result == llvm::APFloat::cmpLessThan ||
+ result == llvm::APFloat::cmpEqual)
+ return true;
+ }
+ return false;
}
-bool
-Scalar::SetBit (uint32_t bit)
-{
- 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: m_integer.setBit(bit); return true;
- case e_float:
- case e_double:
- case e_long_double: break;
- }
+bool lldb_private::operator>(const Scalar &lhs, const Scalar &rhs) {
+ if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
return false;
+
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ llvm::APFloat::cmpResult result;
+ switch (PromoteToMaxType(lhs, rhs, temp_value, a, b)) {
+ case Scalar::e_void:
+ break;
+ case Scalar::e_sint:
+ case Scalar::e_slong:
+ case Scalar::e_slonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_sint256:
+ return a->m_integer.sgt(b->m_integer);
+ case Scalar::e_uint:
+ case Scalar::e_ulong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_uint128:
+ case Scalar::e_uint256:
+ return a->m_integer.ugt(b->m_integer);
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ result = a->m_float.compare(b->m_float);
+ if (result == llvm::APFloat::cmpGreaterThan)
+ return true;
+ }
+ return false;
}
+bool lldb_private::operator>=(const Scalar &lhs, const Scalar &rhs) {
+ if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
+ return false;
+
+ Scalar temp_value;
+ const Scalar *a;
+ const Scalar *b;
+ llvm::APFloat::cmpResult result;
+ switch (PromoteToMaxType(lhs, rhs, temp_value, a, b)) {
+ case Scalar::e_void:
+ break;
+ case Scalar::e_sint:
+ case Scalar::e_slong:
+ case Scalar::e_slonglong:
+ case Scalar::e_sint128:
+ case Scalar::e_sint256:
+ return a->m_integer.sge(b->m_integer);
+ case Scalar::e_uint:
+ case Scalar::e_ulong:
+ case Scalar::e_ulonglong:
+ case Scalar::e_uint128:
+ case Scalar::e_uint256:
+ return a->m_integer.uge(b->m_integer);
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
+ result = a->m_float.compare(b->m_float);
+ if (result == llvm::APFloat::cmpGreaterThan ||
+ result == llvm::APFloat::cmpEqual)
+ return true;
+ }
+ return false;
+}
+
+bool Scalar::ClearBit(uint32_t bit) {
+ 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:
+ m_integer.clearBit(bit);
+ return true;
+ case e_float:
+ case e_double:
+ case e_long_double:
+ break;
+ }
+ return false;
+}
+
+bool Scalar::SetBit(uint32_t bit) {
+ 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:
+ m_integer.setBit(bit);
+ return true;
+ case e_float:
+ case e_double:
+ case e_long_double:
+ break;
+ }
+ return false;
+}
Modified: lldb/trunk/source/Core/SearchFilter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SearchFilter.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/SearchFilter.cpp (original)
+++ lldb/trunk/source/Core/SearchFilter.cpp Tue Sep 6 15:57:50 2016
@@ -12,11 +12,11 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
#include "lldb/Core/SearchFilter.h"
#include "lldb/Core/Module.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Target/Target.h"
+#include "lldb/lldb-private.h"
using namespace lldb;
using namespace lldb_private;
@@ -25,76 +25,40 @@ Searcher::Searcher() = default;
Searcher::~Searcher() = default;
-void
-Searcher::GetDescription (Stream *s)
-{
-}
+void Searcher::GetDescription(Stream *s) {}
-SearchFilter::SearchFilter(const TargetSP &target_sp) :
- m_target_sp (target_sp)
-{
-}
+SearchFilter::SearchFilter(const TargetSP &target_sp)
+ : m_target_sp(target_sp) {}
-SearchFilter::SearchFilter(const SearchFilter& rhs) = default;
+SearchFilter::SearchFilter(const SearchFilter &rhs) = default;
-SearchFilter&
-SearchFilter::operator=(const SearchFilter& rhs) = default;
+SearchFilter &SearchFilter::operator=(const SearchFilter &rhs) = default;
SearchFilter::~SearchFilter() = default;
-bool
-SearchFilter::ModulePasses (const FileSpec &spec)
-{
- return true;
-}
+bool SearchFilter::ModulePasses(const FileSpec &spec) { return true; }
-bool
-SearchFilter::ModulePasses (const ModuleSP &module_sp)
-{
- return true;
-}
+bool SearchFilter::ModulePasses(const ModuleSP &module_sp) { return true; }
-bool
-SearchFilter::AddressPasses (Address &address)
-{
- return true;
-}
+bool SearchFilter::AddressPasses(Address &address) { return true; }
-bool
-SearchFilter::CompUnitPasses (FileSpec &fileSpec)
-{
- return true;
-}
+bool SearchFilter::CompUnitPasses(FileSpec &fileSpec) { return true; }
-bool
-SearchFilter::CompUnitPasses (CompileUnit &compUnit)
-{
- return true;
-}
+bool SearchFilter::CompUnitPasses(CompileUnit &compUnit) { return true; }
-uint32_t
-SearchFilter::GetFilterRequiredItems()
-{
- return (lldb::SymbolContextItem) 0;
+uint32_t SearchFilter::GetFilterRequiredItems() {
+ return (lldb::SymbolContextItem)0;
}
-void
-SearchFilter::GetDescription (Stream *s)
-{
-}
+void SearchFilter::GetDescription(Stream *s) {}
-void
-SearchFilter::Dump (Stream *s) const
-{
-}
+void SearchFilter::Dump(Stream *s) const {}
-lldb::SearchFilterSP
-SearchFilter::CopyForBreakpoint (Breakpoint &breakpoint)
-{
- SearchFilterSP ret_sp = DoCopyForBreakpoint (breakpoint);
- TargetSP target_sp = breakpoint.GetTargetSP();
- ret_sp->SetTarget(target_sp);
- return ret_sp;
+lldb::SearchFilterSP SearchFilter::CopyForBreakpoint(Breakpoint &breakpoint) {
+ SearchFilterSP ret_sp = DoCopyForBreakpoint(breakpoint);
+ TargetSP target_sp = breakpoint.GetTargetSP();
+ ret_sp->SetTarget(target_sp);
+ return ret_sp;
}
//----------------------------------------------------------------------
@@ -102,191 +66,165 @@ SearchFilter::CopyForBreakpoint (Breakpo
// SymbolContext.
//----------------------------------------------------------------------
-void
-SearchFilter::Search (Searcher &searcher)
-{
- SymbolContext empty_sc;
-
- if (!m_target_sp)
- return;
- empty_sc.target_sp = m_target_sp;
-
- if (searcher.GetDepth() == Searcher::eDepthTarget)
- searcher.SearchCallback(*this, empty_sc, nullptr, false);
- else
- DoModuleIteration(empty_sc, searcher);
-}
+void SearchFilter::Search(Searcher &searcher) {
+ SymbolContext empty_sc;
-void
-SearchFilter::SearchInModuleList (Searcher &searcher, ModuleList &modules)
-{
- SymbolContext empty_sc;
-
- if (!m_target_sp)
- return;
- empty_sc.target_sp = m_target_sp;
-
- if (searcher.GetDepth() == Searcher::eDepthTarget)
- searcher.SearchCallback(*this, empty_sc, nullptr, false);
- else
- {
- std::lock_guard<std::recursive_mutex> guard(modules.GetMutex());
- const size_t numModules = modules.GetSize();
-
- for (size_t i = 0; i < numModules; i++)
- {
- ModuleSP module_sp(modules.GetModuleAtIndexUnlocked(i));
- if (ModulePasses(module_sp))
- {
- if (DoModuleIteration(module_sp, searcher) == Searcher::eCallbackReturnStop)
- return;
- }
- }
+ if (!m_target_sp)
+ return;
+ empty_sc.target_sp = m_target_sp;
+
+ if (searcher.GetDepth() == Searcher::eDepthTarget)
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
+ else
+ DoModuleIteration(empty_sc, searcher);
+}
+
+void SearchFilter::SearchInModuleList(Searcher &searcher, ModuleList &modules) {
+ SymbolContext empty_sc;
+
+ if (!m_target_sp)
+ return;
+ empty_sc.target_sp = m_target_sp;
+
+ if (searcher.GetDepth() == Searcher::eDepthTarget)
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
+ else {
+ std::lock_guard<std::recursive_mutex> guard(modules.GetMutex());
+ const size_t numModules = modules.GetSize();
+
+ for (size_t i = 0; i < numModules; i++) {
+ ModuleSP module_sp(modules.GetModuleAtIndexUnlocked(i));
+ if (ModulePasses(module_sp)) {
+ if (DoModuleIteration(module_sp, searcher) ==
+ Searcher::eCallbackReturnStop)
+ return;
+ }
}
+ }
}
Searcher::CallbackReturn
-SearchFilter::DoModuleIteration (const lldb::ModuleSP& module_sp, Searcher &searcher)
-{
- SymbolContext matchingContext (m_target_sp, module_sp);
- return DoModuleIteration(matchingContext, searcher);
+SearchFilter::DoModuleIteration(const lldb::ModuleSP &module_sp,
+ Searcher &searcher) {
+ SymbolContext matchingContext(m_target_sp, module_sp);
+ return DoModuleIteration(matchingContext, searcher);
}
Searcher::CallbackReturn
-SearchFilter::DoModuleIteration (const SymbolContext &context, Searcher &searcher)
-{
- if (searcher.GetDepth () >= Searcher::eDepthModule)
- {
- if (context.module_sp)
- {
- if (searcher.GetDepth () == Searcher::eDepthModule)
- {
- SymbolContext matchingContext(context.module_sp.get());
- searcher.SearchCallback(*this, matchingContext, nullptr, false);
- }
- else
- {
- return DoCUIteration(context.module_sp, context, searcher);
- }
- }
- else
- {
- const ModuleList &target_images = m_target_sp->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
-
- size_t n_modules = target_images.GetSize();
- for (size_t i = 0; i < n_modules; i++)
- {
- // If this is the last level supplied, then call the callback directly,
- // otherwise descend.
- ModuleSP module_sp(target_images.GetModuleAtIndexUnlocked (i));
- if (!ModulePasses (module_sp))
- continue;
-
- if (searcher.GetDepth () == Searcher::eDepthModule)
- {
- SymbolContext matchingContext(m_target_sp, module_sp);
-
- Searcher::CallbackReturn shouldContinue = searcher.SearchCallback(*this, matchingContext, nullptr, false);
- if (shouldContinue == Searcher::eCallbackReturnStop
- || shouldContinue == Searcher::eCallbackReturnPop)
- return shouldContinue;
- }
- else
- {
- Searcher::CallbackReturn shouldContinue = DoCUIteration(module_sp, context, searcher);
- if (shouldContinue == Searcher::eCallbackReturnStop)
- return shouldContinue;
- else if (shouldContinue == Searcher::eCallbackReturnPop)
- continue;
- }
- }
+SearchFilter::DoModuleIteration(const SymbolContext &context,
+ Searcher &searcher) {
+ if (searcher.GetDepth() >= Searcher::eDepthModule) {
+ if (context.module_sp) {
+ if (searcher.GetDepth() == Searcher::eDepthModule) {
+ SymbolContext matchingContext(context.module_sp.get());
+ searcher.SearchCallback(*this, matchingContext, nullptr, false);
+ } else {
+ return DoCUIteration(context.module_sp, context, searcher);
+ }
+ } else {
+ const ModuleList &target_images = m_target_sp->GetImages();
+ std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
+
+ size_t n_modules = target_images.GetSize();
+ for (size_t i = 0; i < n_modules; i++) {
+ // If this is the last level supplied, then call the callback directly,
+ // otherwise descend.
+ ModuleSP module_sp(target_images.GetModuleAtIndexUnlocked(i));
+ if (!ModulePasses(module_sp))
+ continue;
+
+ if (searcher.GetDepth() == Searcher::eDepthModule) {
+ SymbolContext matchingContext(m_target_sp, module_sp);
+
+ Searcher::CallbackReturn shouldContinue =
+ searcher.SearchCallback(*this, matchingContext, nullptr, false);
+ if (shouldContinue == Searcher::eCallbackReturnStop ||
+ shouldContinue == Searcher::eCallbackReturnPop)
+ return shouldContinue;
+ } else {
+ Searcher::CallbackReturn shouldContinue =
+ DoCUIteration(module_sp, context, searcher);
+ if (shouldContinue == Searcher::eCallbackReturnStop)
+ return shouldContinue;
+ else if (shouldContinue == Searcher::eCallbackReturnPop)
+ continue;
}
+ }
}
- return Searcher::eCallbackReturnContinue;
+ }
+ return Searcher::eCallbackReturnContinue;
}
Searcher::CallbackReturn
-SearchFilter::DoCUIteration (const ModuleSP &module_sp, const SymbolContext &context, Searcher &searcher)
-{
- Searcher::CallbackReturn shouldContinue;
- if (context.comp_unit == nullptr)
- {
- const size_t num_comp_units = module_sp->GetNumCompileUnits();
- for (size_t i = 0; i < num_comp_units; i++)
- {
- CompUnitSP cu_sp (module_sp->GetCompileUnitAtIndex (i));
- if (cu_sp)
- {
- if (!CompUnitPasses (*(cu_sp.get())))
- continue;
-
- if (searcher.GetDepth () == Searcher::eDepthCompUnit)
- {
- SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get());
-
- shouldContinue = searcher.SearchCallback(*this, matchingContext, nullptr, false);
-
- if (shouldContinue == Searcher::eCallbackReturnPop)
- return Searcher::eCallbackReturnContinue;
- else if (shouldContinue == Searcher::eCallbackReturnStop)
- return shouldContinue;
- }
- else
- {
- // FIXME Descend to block.
- }
- }
- }
- }
- else
- {
- if (CompUnitPasses(*context.comp_unit))
- {
- SymbolContext matchingContext (m_target_sp, module_sp, context.comp_unit);
- return searcher.SearchCallback(*this, matchingContext, nullptr, false);
- }
- }
- return Searcher::eCallbackReturnContinue;
-}
-
-Searcher::CallbackReturn
-SearchFilter::DoFunctionIteration (Function *function, const SymbolContext &context, Searcher &searcher)
-{
- // FIXME: Implement...
- return Searcher::eCallbackReturnContinue;
+SearchFilter::DoCUIteration(const ModuleSP &module_sp,
+ const SymbolContext &context, Searcher &searcher) {
+ Searcher::CallbackReturn shouldContinue;
+ if (context.comp_unit == nullptr) {
+ const size_t num_comp_units = module_sp->GetNumCompileUnits();
+ for (size_t i = 0; i < num_comp_units; i++) {
+ CompUnitSP cu_sp(module_sp->GetCompileUnitAtIndex(i));
+ if (cu_sp) {
+ if (!CompUnitPasses(*(cu_sp.get())))
+ continue;
+
+ if (searcher.GetDepth() == Searcher::eDepthCompUnit) {
+ SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get());
+
+ shouldContinue =
+ searcher.SearchCallback(*this, matchingContext, nullptr, false);
+
+ if (shouldContinue == Searcher::eCallbackReturnPop)
+ return Searcher::eCallbackReturnContinue;
+ else if (shouldContinue == Searcher::eCallbackReturnStop)
+ return shouldContinue;
+ } else {
+ // FIXME Descend to block.
+ }
+ }
+ }
+ } else {
+ if (CompUnitPasses(*context.comp_unit)) {
+ SymbolContext matchingContext(m_target_sp, module_sp, context.comp_unit);
+ return searcher.SearchCallback(*this, matchingContext, nullptr, false);
+ }
+ }
+ return Searcher::eCallbackReturnContinue;
+}
+
+Searcher::CallbackReturn SearchFilter::DoFunctionIteration(
+ Function *function, const SymbolContext &context, Searcher &searcher) {
+ // FIXME: Implement...
+ return Searcher::eCallbackReturnContinue;
}
//----------------------------------------------------------------------
// SearchFilterForUnconstrainedSearches:
-// Selects a shared library matching a given file spec, consulting the targets "black list".
+// Selects a shared library matching a given file spec, consulting the targets
+// "black list".
//----------------------------------------------------------------------
-bool
-SearchFilterForUnconstrainedSearches::ModulePasses (const FileSpec &module_spec)
-{
- if (m_target_sp->ModuleIsExcludedForUnconstrainedSearches (module_spec))
- return false;
- else
- return true;
-}
-
-bool
-SearchFilterForUnconstrainedSearches::ModulePasses (const lldb::ModuleSP &module_sp)
-{
- if (!module_sp)
- return true;
- else if (m_target_sp->ModuleIsExcludedForUnconstrainedSearches (module_sp))
- return false;
- else
- return true;
+bool SearchFilterForUnconstrainedSearches::ModulePasses(
+ const FileSpec &module_spec) {
+ if (m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_spec))
+ return false;
+ else
+ return true;
}
-lldb::SearchFilterSP
-SearchFilterForUnconstrainedSearches::DoCopyForBreakpoint (Breakpoint &breakpoint)
-{
- SearchFilterSP ret_sp(new SearchFilterForUnconstrainedSearches(*this));
- return ret_sp;
+bool SearchFilterForUnconstrainedSearches::ModulePasses(
+ const lldb::ModuleSP &module_sp) {
+ if (!module_sp)
+ return true;
+ else if (m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_sp))
+ return false;
+ else
+ return true;
+}
+
+lldb::SearchFilterSP SearchFilterForUnconstrainedSearches::DoCopyForBreakpoint(
+ Breakpoint &breakpoint) {
+ SearchFilterSP ret_sp(new SearchFilterForUnconstrainedSearches(*this));
+ return ret_sp;
}
//----------------------------------------------------------------------
@@ -294,126 +232,97 @@ SearchFilterForUnconstrainedSearches::Do
// Selects a shared library matching a given file spec
//----------------------------------------------------------------------
-SearchFilterByModule::SearchFilterByModule (const lldb::TargetSP &target_sp, const FileSpec &module) :
- SearchFilter (target_sp),
- m_module_spec (module)
-{
+SearchFilterByModule::SearchFilterByModule(const lldb::TargetSP &target_sp,
+ const FileSpec &module)
+ : SearchFilter(target_sp), m_module_spec(module) {}
+
+SearchFilterByModule::SearchFilterByModule(const SearchFilterByModule &rhs) =
+ default;
+
+SearchFilterByModule &SearchFilterByModule::
+operator=(const SearchFilterByModule &rhs) {
+ m_target_sp = rhs.m_target_sp;
+ m_module_spec = rhs.m_module_spec;
+ return *this;
}
-SearchFilterByModule::SearchFilterByModule(const SearchFilterByModule& rhs) = default;
+SearchFilterByModule::~SearchFilterByModule() = default;
-SearchFilterByModule&
-SearchFilterByModule::operator=(const SearchFilterByModule& rhs)
-{
- m_target_sp = rhs.m_target_sp;
- m_module_spec = rhs.m_module_spec;
- return *this;
+bool SearchFilterByModule::ModulePasses(const ModuleSP &module_sp) {
+ return (module_sp &&
+ FileSpec::Equal(module_sp->GetFileSpec(), m_module_spec, false));
}
-SearchFilterByModule::~SearchFilterByModule() = default;
-
-bool
-SearchFilterByModule::ModulePasses (const ModuleSP &module_sp)
-{
- return (module_sp && FileSpec::Equal(module_sp->GetFileSpec(), m_module_spec, false));
-}
-
-bool
-SearchFilterByModule::ModulePasses (const FileSpec &spec)
-{
- // Do a full match only if "spec" has a directory
- const bool full_match = (bool)spec.GetDirectory();
- return FileSpec::Equal(spec, m_module_spec, full_match);
-}
-
-bool
-SearchFilterByModule::AddressPasses (Address &address)
-{
- // FIXME: Not yet implemented
- return true;
+bool SearchFilterByModule::ModulePasses(const FileSpec &spec) {
+ // Do a full match only if "spec" has a directory
+ const bool full_match = (bool)spec.GetDirectory();
+ return FileSpec::Equal(spec, m_module_spec, full_match);
}
-bool
-SearchFilterByModule::CompUnitPasses (FileSpec &fileSpec)
-{
- return true;
+bool SearchFilterByModule::AddressPasses(Address &address) {
+ // FIXME: Not yet implemented
+ return true;
}
-bool
-SearchFilterByModule::CompUnitPasses (CompileUnit &compUnit)
-{
- return true;
+bool SearchFilterByModule::CompUnitPasses(FileSpec &fileSpec) { return true; }
+
+bool SearchFilterByModule::CompUnitPasses(CompileUnit &compUnit) {
+ return true;
}
-void
-SearchFilterByModule::Search (Searcher &searcher)
-{
- if (!m_target_sp)
- return;
+void SearchFilterByModule::Search(Searcher &searcher) {
+ if (!m_target_sp)
+ return;
- if (searcher.GetDepth() == Searcher::eDepthTarget)
- {
- SymbolContext empty_sc;
- empty_sc.target_sp = m_target_sp;
- searcher.SearchCallback(*this, empty_sc, nullptr, false);
- }
-
- // If the module file spec is a full path, then we can just find the one
- // filespec that passes. Otherwise, we need to go through all modules and
- // find the ones that match the file name.
-
- const ModuleList &target_modules = m_target_sp->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
-
- const size_t num_modules = target_modules.GetSize ();
- for (size_t i = 0; i < num_modules; i++)
- {
- Module* module = target_modules.GetModulePointerAtIndexUnlocked(i);
- const bool full_match = (bool)m_module_spec.GetDirectory();
- if (FileSpec::Equal (m_module_spec, module->GetFileSpec(), full_match))
- {
- SymbolContext matchingContext(m_target_sp, module->shared_from_this());
- Searcher::CallbackReturn shouldContinue;
+ if (searcher.GetDepth() == Searcher::eDepthTarget) {
+ SymbolContext empty_sc;
+ empty_sc.target_sp = m_target_sp;
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
+ }
- shouldContinue = DoModuleIteration(matchingContext, searcher);
- if (shouldContinue == Searcher::eCallbackReturnStop)
- return;
- }
- }
-}
+ // If the module file spec is a full path, then we can just find the one
+ // filespec that passes. Otherwise, we need to go through all modules and
+ // find the ones that match the file name.
+
+ const ModuleList &target_modules = m_target_sp->GetImages();
+ std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
+
+ const size_t num_modules = target_modules.GetSize();
+ for (size_t i = 0; i < num_modules; i++) {
+ Module *module = target_modules.GetModulePointerAtIndexUnlocked(i);
+ const bool full_match = (bool)m_module_spec.GetDirectory();
+ if (FileSpec::Equal(m_module_spec, module->GetFileSpec(), full_match)) {
+ SymbolContext matchingContext(m_target_sp, module->shared_from_this());
+ Searcher::CallbackReturn shouldContinue;
-void
-SearchFilterByModule::GetDescription (Stream *s)
-{
- s->PutCString(", module = ");
- if (s->GetVerbose())
- {
- char buffer[2048];
- m_module_spec.GetPath(buffer, 2047);
- s->PutCString(buffer);
- }
- else
- {
- s->PutCString(m_module_spec.GetFilename().AsCString("<Unknown>"));
+ shouldContinue = DoModuleIteration(matchingContext, searcher);
+ if (shouldContinue == Searcher::eCallbackReturnStop)
+ return;
}
+ }
}
-uint32_t
-SearchFilterByModule::GetFilterRequiredItems()
-{
- return eSymbolContextModule;
+void SearchFilterByModule::GetDescription(Stream *s) {
+ s->PutCString(", module = ");
+ if (s->GetVerbose()) {
+ char buffer[2048];
+ m_module_spec.GetPath(buffer, 2047);
+ s->PutCString(buffer);
+ } else {
+ s->PutCString(m_module_spec.GetFilename().AsCString("<Unknown>"));
+ }
}
-void
-SearchFilterByModule::Dump (Stream *s) const
-{
+uint32_t SearchFilterByModule::GetFilterRequiredItems() {
+ return eSymbolContextModule;
}
+void SearchFilterByModule::Dump(Stream *s) const {}
+
lldb::SearchFilterSP
-SearchFilterByModule::DoCopyForBreakpoint (Breakpoint &breakpoint)
-{
- SearchFilterSP ret_sp(new SearchFilterByModule(*this));
- return ret_sp;
+SearchFilterByModule::DoCopyForBreakpoint(Breakpoint &breakpoint) {
+ SearchFilterSP ret_sp(new SearchFilterByModule(*this));
+ return ret_sp;
}
//----------------------------------------------------------------------
@@ -421,160 +330,130 @@ SearchFilterByModule::DoCopyForBreakpoin
// Selects a shared library matching a given file spec
//----------------------------------------------------------------------
-SearchFilterByModuleList::SearchFilterByModuleList (const lldb::TargetSP &target_sp,
- const FileSpecList &module_list) :
- SearchFilter (target_sp),
- m_module_spec_list (module_list)
-{
-}
-
-SearchFilterByModuleList::SearchFilterByModuleList(const SearchFilterByModuleList& rhs) = default;
-
-SearchFilterByModuleList&
-SearchFilterByModuleList::operator=(const SearchFilterByModuleList& rhs)
-{
- m_target_sp = rhs.m_target_sp;
- m_module_spec_list = rhs.m_module_spec_list;
- return *this;
+SearchFilterByModuleList::SearchFilterByModuleList(
+ const lldb::TargetSP &target_sp, const FileSpecList &module_list)
+ : SearchFilter(target_sp), m_module_spec_list(module_list) {}
+
+SearchFilterByModuleList::SearchFilterByModuleList(
+ const SearchFilterByModuleList &rhs) = default;
+
+SearchFilterByModuleList &SearchFilterByModuleList::
+operator=(const SearchFilterByModuleList &rhs) {
+ m_target_sp = rhs.m_target_sp;
+ m_module_spec_list = rhs.m_module_spec_list;
+ return *this;
}
SearchFilterByModuleList::~SearchFilterByModuleList() = default;
-bool
-SearchFilterByModuleList::ModulePasses (const ModuleSP &module_sp)
-{
- if (m_module_spec_list.GetSize() == 0)
- return true;
-
- if (module_sp &&
- m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) != UINT32_MAX)
- return true;
- else
- return false;
-}
-
-bool
-SearchFilterByModuleList::ModulePasses (const FileSpec &spec)
-{
- if (m_module_spec_list.GetSize() == 0)
- return true;
-
- if (m_module_spec_list.FindFileIndex(0, spec, true) != UINT32_MAX)
- return true;
- else
- return false;
-}
-
-bool
-SearchFilterByModuleList::AddressPasses (Address &address)
-{
- // FIXME: Not yet implemented
+bool SearchFilterByModuleList::ModulePasses(const ModuleSP &module_sp) {
+ if (m_module_spec_list.GetSize() == 0)
return true;
-}
-bool
-SearchFilterByModuleList::CompUnitPasses (FileSpec &fileSpec)
-{
+ if (module_sp &&
+ m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) !=
+ UINT32_MAX)
return true;
+ else
+ return false;
}
-bool
-SearchFilterByModuleList::CompUnitPasses (CompileUnit &compUnit)
-{
+bool SearchFilterByModuleList::ModulePasses(const FileSpec &spec) {
+ if (m_module_spec_list.GetSize() == 0)
+ return true;
+
+ if (m_module_spec_list.FindFileIndex(0, spec, true) != UINT32_MAX)
return true;
+ else
+ return false;
}
-void
-SearchFilterByModuleList::Search (Searcher &searcher)
-{
- if (!m_target_sp)
- return;
+bool SearchFilterByModuleList::AddressPasses(Address &address) {
+ // FIXME: Not yet implemented
+ return true;
+}
- if (searcher.GetDepth() == Searcher::eDepthTarget)
- {
- SymbolContext empty_sc;
- empty_sc.target_sp = m_target_sp;
- searcher.SearchCallback(*this, empty_sc, nullptr, false);
- }
-
- // If the module file spec is a full path, then we can just find the one
- // filespec that passes. Otherwise, we need to go through all modules and
- // find the ones that match the file name.
-
- const ModuleList &target_modules = m_target_sp->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
-
- const size_t num_modules = target_modules.GetSize ();
- for (size_t i = 0; i < num_modules; i++)
- {
- Module* module = target_modules.GetModulePointerAtIndexUnlocked(i);
- if (m_module_spec_list.FindFileIndex(0, module->GetFileSpec(), false) != UINT32_MAX)
- {
- SymbolContext matchingContext(m_target_sp, module->shared_from_this());
- Searcher::CallbackReturn shouldContinue;
+bool SearchFilterByModuleList::CompUnitPasses(FileSpec &fileSpec) {
+ return true;
+}
- shouldContinue = DoModuleIteration(matchingContext, searcher);
- if (shouldContinue == Searcher::eCallbackReturnStop)
- return;
- }
- }
+bool SearchFilterByModuleList::CompUnitPasses(CompileUnit &compUnit) {
+ return true;
}
-void
-SearchFilterByModuleList::GetDescription (Stream *s)
-{
- size_t num_modules = m_module_spec_list.GetSize();
- if (num_modules == 1)
- {
- s->Printf (", module = ");
- if (s->GetVerbose())
- {
- char buffer[2048];
- m_module_spec_list.GetFileSpecAtIndex(0).GetPath(buffer, 2047);
- s->PutCString(buffer);
- }
- else
- {
- s->PutCString(m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString("<Unknown>"));
- }
- }
- else
- {
- s->Printf(", modules(%" PRIu64 ") = ", (uint64_t)num_modules);
- for (size_t i = 0; i < num_modules; i++)
- {
- if (s->GetVerbose())
- {
- char buffer[2048];
- m_module_spec_list.GetFileSpecAtIndex(i).GetPath(buffer, 2047);
- s->PutCString(buffer);
- }
- else
- {
- s->PutCString(m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString("<Unknown>"));
- }
- if (i != num_modules - 1)
- s->PutCString (", ");
- }
+void SearchFilterByModuleList::Search(Searcher &searcher) {
+ if (!m_target_sp)
+ return;
+
+ if (searcher.GetDepth() == Searcher::eDepthTarget) {
+ SymbolContext empty_sc;
+ empty_sc.target_sp = m_target_sp;
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
+ }
+
+ // If the module file spec is a full path, then we can just find the one
+ // filespec that passes. Otherwise, we need to go through all modules and
+ // find the ones that match the file name.
+
+ const ModuleList &target_modules = m_target_sp->GetImages();
+ std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
+
+ const size_t num_modules = target_modules.GetSize();
+ for (size_t i = 0; i < num_modules; i++) {
+ Module *module = target_modules.GetModulePointerAtIndexUnlocked(i);
+ if (m_module_spec_list.FindFileIndex(0, module->GetFileSpec(), false) !=
+ UINT32_MAX) {
+ SymbolContext matchingContext(m_target_sp, module->shared_from_this());
+ Searcher::CallbackReturn shouldContinue;
+
+ shouldContinue = DoModuleIteration(matchingContext, searcher);
+ if (shouldContinue == Searcher::eCallbackReturnStop)
+ return;
}
+ }
}
-uint32_t
-SearchFilterByModuleList::GetFilterRequiredItems()
-{
- return eSymbolContextModule;
+void SearchFilterByModuleList::GetDescription(Stream *s) {
+ size_t num_modules = m_module_spec_list.GetSize();
+ if (num_modules == 1) {
+ s->Printf(", module = ");
+ if (s->GetVerbose()) {
+ char buffer[2048];
+ m_module_spec_list.GetFileSpecAtIndex(0).GetPath(buffer, 2047);
+ s->PutCString(buffer);
+ } else {
+ s->PutCString(
+ m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString(
+ "<Unknown>"));
+ }
+ } else {
+ s->Printf(", modules(%" PRIu64 ") = ", (uint64_t)num_modules);
+ for (size_t i = 0; i < num_modules; i++) {
+ if (s->GetVerbose()) {
+ char buffer[2048];
+ m_module_spec_list.GetFileSpecAtIndex(i).GetPath(buffer, 2047);
+ s->PutCString(buffer);
+ } else {
+ s->PutCString(
+ m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString(
+ "<Unknown>"));
+ }
+ if (i != num_modules - 1)
+ s->PutCString(", ");
+ }
+ }
}
-void
-SearchFilterByModuleList::Dump (Stream *s) const
-{
+uint32_t SearchFilterByModuleList::GetFilterRequiredItems() {
+ return eSymbolContextModule;
}
+void SearchFilterByModuleList::Dump(Stream *s) const {}
+
lldb::SearchFilterSP
-SearchFilterByModuleList::DoCopyForBreakpoint (Breakpoint &breakpoint)
-{
- SearchFilterSP ret_sp(new SearchFilterByModuleList(*this));
- return ret_sp;
+SearchFilterByModuleList::DoCopyForBreakpoint(Breakpoint &breakpoint) {
+ SearchFilterSP ret_sp(new SearchFilterByModuleList(*this));
+ return ret_sp;
}
//----------------------------------------------------------------------
@@ -582,174 +461,140 @@ SearchFilterByModuleList::DoCopyForBreak
// Selects a shared library matching a given file spec
//----------------------------------------------------------------------
-SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU (const lldb::TargetSP &target_sp,
- const FileSpecList &module_list,
- const FileSpecList &cu_list) :
- SearchFilterByModuleList (target_sp, module_list),
- m_cu_spec_list (cu_list)
-{
-}
-
-SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU(const SearchFilterByModuleListAndCU& rhs) = default;
-
-SearchFilterByModuleListAndCU&
-SearchFilterByModuleListAndCU::operator=(const SearchFilterByModuleListAndCU& rhs)
-{
- if (&rhs != this)
- {
- m_target_sp = rhs.m_target_sp;
- m_module_spec_list = rhs.m_module_spec_list;
- m_cu_spec_list = rhs.m_cu_spec_list;
- }
- return *this;
+SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU(
+ const lldb::TargetSP &target_sp, const FileSpecList &module_list,
+ const FileSpecList &cu_list)
+ : SearchFilterByModuleList(target_sp, module_list),
+ m_cu_spec_list(cu_list) {}
+
+SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU(
+ const SearchFilterByModuleListAndCU &rhs) = default;
+
+SearchFilterByModuleListAndCU &SearchFilterByModuleListAndCU::
+operator=(const SearchFilterByModuleListAndCU &rhs) {
+ if (&rhs != this) {
+ m_target_sp = rhs.m_target_sp;
+ m_module_spec_list = rhs.m_module_spec_list;
+ m_cu_spec_list = rhs.m_cu_spec_list;
+ }
+ return *this;
}
SearchFilterByModuleListAndCU::~SearchFilterByModuleListAndCU() = default;
-bool
-SearchFilterByModuleListAndCU::AddressPasses (Address &address)
-{
- return true;
+bool SearchFilterByModuleListAndCU::AddressPasses(Address &address) {
+ return true;
}
-bool
-SearchFilterByModuleListAndCU::CompUnitPasses (FileSpec &fileSpec)
-{
- return m_cu_spec_list.FindFileIndex(0, fileSpec, false) != UINT32_MAX;
-}
-
-bool
-SearchFilterByModuleListAndCU::CompUnitPasses (CompileUnit &compUnit)
-{
- bool in_cu_list = m_cu_spec_list.FindFileIndex(0, compUnit, false) != UINT32_MAX;
- if (in_cu_list)
- {
- ModuleSP module_sp(compUnit.GetModule());
- if (module_sp)
- {
- bool module_passes = SearchFilterByModuleList::ModulePasses(module_sp);
- return module_passes;
- }
- else
- return true;
- }
- else
- return false;
+bool SearchFilterByModuleListAndCU::CompUnitPasses(FileSpec &fileSpec) {
+ return m_cu_spec_list.FindFileIndex(0, fileSpec, false) != UINT32_MAX;
}
-void
-SearchFilterByModuleListAndCU::Search (Searcher &searcher)
-{
- if (!m_target_sp)
- return;
+bool SearchFilterByModuleListAndCU::CompUnitPasses(CompileUnit &compUnit) {
+ bool in_cu_list =
+ m_cu_spec_list.FindFileIndex(0, compUnit, false) != UINT32_MAX;
+ if (in_cu_list) {
+ ModuleSP module_sp(compUnit.GetModule());
+ if (module_sp) {
+ bool module_passes = SearchFilterByModuleList::ModulePasses(module_sp);
+ return module_passes;
+ } else
+ return true;
+ } else
+ return false;
+}
- if (searcher.GetDepth() == Searcher::eDepthTarget)
- {
- SymbolContext empty_sc;
- empty_sc.target_sp = m_target_sp;
- searcher.SearchCallback(*this, empty_sc, nullptr, false);
- }
-
- // If the module file spec is a full path, then we can just find the one
- // filespec that passes. Otherwise, we need to go through all modules and
- // find the ones that match the file name.
-
- ModuleList matching_modules;
- const ModuleList &target_images = m_target_sp->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
-
- const size_t num_modules = target_images.GetSize ();
- bool no_modules_in_filter = m_module_spec_list.GetSize() == 0;
- for (size_t i = 0; i < num_modules; i++)
- {
- lldb::ModuleSP module_sp = target_images.GetModuleAtIndexUnlocked(i);
- if (no_modules_in_filter ||
- m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) != UINT32_MAX)
- {
- SymbolContext matchingContext(m_target_sp, module_sp);
- Searcher::CallbackReturn shouldContinue;
-
- if (searcher.GetDepth() == Searcher::eDepthModule)
- {
- shouldContinue = DoModuleIteration(matchingContext, searcher);
- if (shouldContinue == Searcher::eCallbackReturnStop)
- return;
- }
- else
- {
- const size_t num_cu = module_sp->GetNumCompileUnits();
- for (size_t cu_idx = 0; cu_idx < num_cu; cu_idx++)
- {
- CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(cu_idx);
- matchingContext.comp_unit = cu_sp.get();
- if (matchingContext.comp_unit)
- {
- if (m_cu_spec_list.FindFileIndex(0, *matchingContext.comp_unit, false) != UINT32_MAX)
- {
- shouldContinue = DoCUIteration(module_sp, matchingContext, searcher);
- if (shouldContinue == Searcher::eCallbackReturnStop)
- return;
- }
- }
- }
+void SearchFilterByModuleListAndCU::Search(Searcher &searcher) {
+ if (!m_target_sp)
+ return;
+
+ if (searcher.GetDepth() == Searcher::eDepthTarget) {
+ SymbolContext empty_sc;
+ empty_sc.target_sp = m_target_sp;
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
+ }
+
+ // If the module file spec is a full path, then we can just find the one
+ // filespec that passes. Otherwise, we need to go through all modules and
+ // find the ones that match the file name.
+
+ ModuleList matching_modules;
+ const ModuleList &target_images = m_target_sp->GetImages();
+ std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex());
+
+ const size_t num_modules = target_images.GetSize();
+ bool no_modules_in_filter = m_module_spec_list.GetSize() == 0;
+ for (size_t i = 0; i < num_modules; i++) {
+ lldb::ModuleSP module_sp = target_images.GetModuleAtIndexUnlocked(i);
+ if (no_modules_in_filter ||
+ m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) !=
+ UINT32_MAX) {
+ SymbolContext matchingContext(m_target_sp, module_sp);
+ Searcher::CallbackReturn shouldContinue;
+
+ if (searcher.GetDepth() == Searcher::eDepthModule) {
+ shouldContinue = DoModuleIteration(matchingContext, searcher);
+ if (shouldContinue == Searcher::eCallbackReturnStop)
+ return;
+ } else {
+ const size_t num_cu = module_sp->GetNumCompileUnits();
+ for (size_t cu_idx = 0; cu_idx < num_cu; cu_idx++) {
+ CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(cu_idx);
+ matchingContext.comp_unit = cu_sp.get();
+ if (matchingContext.comp_unit) {
+ if (m_cu_spec_list.FindFileIndex(0, *matchingContext.comp_unit,
+ false) != UINT32_MAX) {
+ shouldContinue =
+ DoCUIteration(module_sp, matchingContext, searcher);
+ if (shouldContinue == Searcher::eCallbackReturnStop)
+ return;
}
+ }
}
+ }
}
+ }
}
-void
-SearchFilterByModuleListAndCU::GetDescription (Stream *s)
-{
- size_t num_modules = m_module_spec_list.GetSize();
- if (num_modules == 1)
- {
- s->Printf (", module = ");
- if (s->GetVerbose())
- {
- char buffer[2048];
- m_module_spec_list.GetFileSpecAtIndex(0).GetPath(buffer, 2047);
- s->PutCString(buffer);
- }
- else
- {
- s->PutCString(m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString("<Unknown>"));
- }
- }
- else if (num_modules > 0)
- {
- s->Printf (", modules(%" PRIu64 ") = ", static_cast<uint64_t>(num_modules));
- for (size_t i = 0; i < num_modules; i++)
- {
- if (s->GetVerbose())
- {
- char buffer[2048];
- m_module_spec_list.GetFileSpecAtIndex(i).GetPath(buffer, 2047);
- s->PutCString(buffer);
- }
- else
- {
- s->PutCString(m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString("<Unknown>"));
- }
- if (i != num_modules - 1)
- s->PutCString (", ");
- }
+void SearchFilterByModuleListAndCU::GetDescription(Stream *s) {
+ size_t num_modules = m_module_spec_list.GetSize();
+ if (num_modules == 1) {
+ s->Printf(", module = ");
+ if (s->GetVerbose()) {
+ char buffer[2048];
+ m_module_spec_list.GetFileSpecAtIndex(0).GetPath(buffer, 2047);
+ s->PutCString(buffer);
+ } else {
+ s->PutCString(
+ m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString(
+ "<Unknown>"));
+ }
+ } else if (num_modules > 0) {
+ s->Printf(", modules(%" PRIu64 ") = ", static_cast<uint64_t>(num_modules));
+ for (size_t i = 0; i < num_modules; i++) {
+ if (s->GetVerbose()) {
+ char buffer[2048];
+ m_module_spec_list.GetFileSpecAtIndex(i).GetPath(buffer, 2047);
+ s->PutCString(buffer);
+ } else {
+ s->PutCString(
+ m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString(
+ "<Unknown>"));
+ }
+ if (i != num_modules - 1)
+ s->PutCString(", ");
}
+ }
}
-uint32_t
-SearchFilterByModuleListAndCU::GetFilterRequiredItems()
-{
- return eSymbolContextModule | eSymbolContextCompUnit;
+uint32_t SearchFilterByModuleListAndCU::GetFilterRequiredItems() {
+ return eSymbolContextModule | eSymbolContextCompUnit;
}
-void
-SearchFilterByModuleListAndCU::Dump (Stream *s) const
-{
-}
+void SearchFilterByModuleListAndCU::Dump(Stream *s) const {}
lldb::SearchFilterSP
-SearchFilterByModuleListAndCU::DoCopyForBreakpoint (Breakpoint &breakpoint)
-{
- SearchFilterSP ret_sp(new SearchFilterByModuleListAndCU(*this));
- return ret_sp;
+SearchFilterByModuleListAndCU::DoCopyForBreakpoint(Breakpoint &breakpoint) {
+ SearchFilterSP ret_sp(new SearchFilterByModuleListAndCU(*this));
+ return ret_sp;
}
Modified: lldb/trunk/source/Core/Section.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Section.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/Section.cpp (original)
+++ lldb/trunk/source/Core/Section.cpp Tue Sep 6 15:57:50 2016
@@ -17,600 +17,491 @@
using namespace lldb;
using namespace lldb_private;
-Section::Section(const ModuleSP &module_sp, ObjectFile *obj_file, user_id_t sect_id, const ConstString &name,
- SectionType sect_type, addr_t file_addr, addr_t byte_size, lldb::offset_t file_offset,
- lldb::offset_t file_size, uint32_t log2align, uint32_t flags, uint32_t target_byte_size /*=1*/)
- : ModuleChild(module_sp),
- UserID(sect_id),
- Flags(flags),
- m_obj_file(obj_file),
- m_type(sect_type),
- m_parent_wp(),
- m_name(name),
- m_file_addr(file_addr),
- m_byte_size(byte_size),
- m_file_offset(file_offset),
- m_file_size(file_size),
- m_log2align(log2align),
- m_children(),
- m_fake(false),
- m_encrypted(false),
- m_thread_specific(false),
- m_readable(false),
- m_writable(false),
- m_executable(false),
- m_target_byte_size(target_byte_size)
-{
-// printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16" PRIx64 ", addr=[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), file [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), flags = 0x%8.8x, name = %s\n",
-// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, name.GetCString());
-}
-
-Section::Section(const lldb::SectionSP &parent_section_sp, const ModuleSP &module_sp, ObjectFile *obj_file,
- user_id_t sect_id, const ConstString &name, SectionType sect_type, addr_t file_addr, addr_t byte_size,
- lldb::offset_t file_offset, lldb::offset_t file_size, uint32_t log2align, uint32_t flags,
+Section::Section(const ModuleSP &module_sp, ObjectFile *obj_file,
+ user_id_t sect_id, const ConstString &name,
+ SectionType sect_type, addr_t file_addr, addr_t byte_size,
+ lldb::offset_t file_offset, lldb::offset_t file_size,
+ uint32_t log2align, uint32_t flags,
uint32_t target_byte_size /*=1*/)
- : ModuleChild(module_sp),
- UserID(sect_id),
- Flags(flags),
- m_obj_file(obj_file),
- m_type(sect_type),
- m_parent_wp(),
- m_name(name),
- m_file_addr(file_addr),
- m_byte_size(byte_size),
- m_file_offset(file_offset),
- m_file_size(file_size),
- m_log2align(log2align),
- m_children(),
- m_fake(false),
- m_encrypted(false),
- m_thread_specific(false),
- m_readable(false),
- m_writable(false),
- m_executable(false),
- m_target_byte_size(target_byte_size)
-{
-// printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16" PRIx64 ", addr=[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), file [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), flags = 0x%8.8x, name = %s.%s\n",
-// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, parent_section_sp->GetName().GetCString(), name.GetCString());
- if (parent_section_sp)
- m_parent_wp = parent_section_sp;
-}
-
-Section::~Section()
-{
-// printf ("Section::~Section(%p)\n", this);
-}
-
-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
- return parent_sp->GetFileAddress() + m_file_addr;
- }
+ : ModuleChild(module_sp), UserID(sect_id), Flags(flags),
+ m_obj_file(obj_file), m_type(sect_type), m_parent_wp(), m_name(name),
+ m_file_addr(file_addr), m_byte_size(byte_size),
+ m_file_offset(file_offset), m_file_size(file_size),
+ m_log2align(log2align), m_children(), m_fake(false), m_encrypted(false),
+ m_thread_specific(false), m_readable(false), m_writable(false),
+ m_executable(false), m_target_byte_size(target_byte_size) {
+ // printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16" PRIx64 ",
+ // addr=[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), file [0x%16.16" PRIx64 "
+ // - 0x%16.16" PRIx64 "), flags = 0x%8.8x, name = %s\n",
+ // this, module_sp.get(), sect_id, file_addr, file_addr +
+ // byte_size, file_offset, file_offset + file_size, flags,
+ // name.GetCString());
+}
+
+Section::Section(const lldb::SectionSP &parent_section_sp,
+ const ModuleSP &module_sp, ObjectFile *obj_file,
+ user_id_t sect_id, const ConstString &name,
+ SectionType sect_type, addr_t file_addr, addr_t byte_size,
+ lldb::offset_t file_offset, lldb::offset_t file_size,
+ uint32_t log2align, uint32_t flags,
+ uint32_t target_byte_size /*=1*/)
+ : ModuleChild(module_sp), UserID(sect_id), Flags(flags),
+ m_obj_file(obj_file), m_type(sect_type), m_parent_wp(), m_name(name),
+ m_file_addr(file_addr), m_byte_size(byte_size),
+ m_file_offset(file_offset), m_file_size(file_size),
+ m_log2align(log2align), m_children(), m_fake(false), m_encrypted(false),
+ m_thread_specific(false), m_readable(false), m_writable(false),
+ m_executable(false), m_target_byte_size(target_byte_size) {
+ // printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16" PRIx64 ",
+ // addr=[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), file [0x%16.16" PRIx64 "
+ // - 0x%16.16" PRIx64 "), flags = 0x%8.8x, name = %s.%s\n",
+ // this, module_sp.get(), sect_id, file_addr, file_addr +
+ // byte_size, file_offset, file_offset + file_size, flags,
+ // parent_section_sp->GetName().GetCString(), name.GetCString());
+ if (parent_section_sp)
+ m_parent_wp = parent_section_sp;
+}
+
+Section::~Section() {
+ // printf ("Section::~Section(%p)\n", this);
+}
+
+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
+ return parent_sp->GetFileAddress() + m_file_addr;
+ }
+ // This section has no parent, so m_file_addr is the file base address
+ return m_file_addr;
+}
+
+bool Section::SetFileAddress(lldb::addr_t file_addr) {
+ SectionSP parent_sp(GetParent());
+ if (parent_sp) {
+ if (m_file_addr >= file_addr)
+ return parent_sp->SetFileAddress(m_file_addr - file_addr);
+ return false;
+ } else {
// This section has no parent, so m_file_addr is the file base address
- return m_file_addr;
+ m_file_addr = file_addr;
+ return true;
+ }
}
-bool
-Section::SetFileAddress (lldb::addr_t file_addr)
-{
- SectionSP parent_sp (GetParent ());
- if (parent_sp)
- {
- if (m_file_addr >= file_addr)
- return parent_sp->SetFileAddress (m_file_addr - file_addr);
- return false;
- }
- else
- {
- // This section has no parent, so m_file_addr is the file base address
- m_file_addr = file_addr;
- return true;
- }
-}
+lldb::addr_t Section::GetOffset() const {
+ // This section has a parent which means m_file_addr is an offset.
+ SectionSP parent_sp(GetParent());
+ if (parent_sp)
+ return m_file_addr;
-lldb::addr_t
-Section::GetOffset () const
-{
- // This section has a parent which means m_file_addr is an offset.
- SectionSP parent_sp (GetParent ());
- if (parent_sp)
- return m_file_addr;
-
- // This section has no parent, so there is no offset to be had
- return 0;
+ // This section has no parent, so there is no offset to be had
+ return 0;
}
-addr_t
-Section::GetLoadBaseAddress (Target *target) const
-{
- addr_t load_base_addr = LLDB_INVALID_ADDRESS;
- SectionSP parent_sp (GetParent ());
- if (parent_sp)
- {
- load_base_addr = parent_sp->GetLoadBaseAddress (target);
- if (load_base_addr != LLDB_INVALID_ADDRESS)
- load_base_addr += GetOffset();
- }
- if (load_base_addr == LLDB_INVALID_ADDRESS)
- {
- load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (const_cast<Section *>(this)->shared_from_this());
- }
- return load_base_addr;
-}
+addr_t Section::GetLoadBaseAddress(Target *target) const {
+ addr_t load_base_addr = LLDB_INVALID_ADDRESS;
+ SectionSP parent_sp(GetParent());
+ if (parent_sp) {
+ load_base_addr = parent_sp->GetLoadBaseAddress(target);
+ if (load_base_addr != LLDB_INVALID_ADDRESS)
+ load_base_addr += GetOffset();
+ }
+ if (load_base_addr == LLDB_INVALID_ADDRESS) {
+ load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress(
+ const_cast<Section *>(this)->shared_from_this());
+ }
+ return load_base_addr;
+}
+
+bool Section::ResolveContainedAddress(addr_t offset, Address &so_addr) const {
+ const size_t num_children = m_children.GetSize();
+ if (num_children > 0) {
+ for (size_t i = 0; i < num_children; i++) {
+ Section *child_section = m_children.GetSectionAtIndex(i).get();
+
+ addr_t child_offset = child_section->GetOffset();
+ if (child_offset <= offset &&
+ offset - child_offset < child_section->GetByteSize())
+ return child_section->ResolveContainedAddress(offset - child_offset,
+ so_addr);
+ }
+ }
+ so_addr.SetOffset(offset);
+ so_addr.SetSection(const_cast<Section *>(this)->shared_from_this());
-bool
-Section::ResolveContainedAddress (addr_t offset, Address &so_addr) const
-{
- const size_t num_children = m_children.GetSize();
- if (num_children > 0)
- {
- for (size_t i=0; i<num_children; i++)
- {
- Section* child_section = m_children.GetSectionAtIndex (i).get();
-
- addr_t child_offset = child_section->GetOffset();
- if (child_offset <= offset && offset - child_offset < child_section->GetByteSize())
- return child_section->ResolveContainedAddress (offset - child_offset, so_addr);
- }
- }
- so_addr.SetOffset(offset);
- so_addr.SetSection(const_cast<Section *>(this)->shared_from_this());
-
#ifdef LLDB_CONFIGURATION_DEBUG
- // For debug builds, ensure that there are no orphaned (i.e., moduleless) sections.
- assert(GetModule().get());
+ // For debug builds, ensure that there are no orphaned (i.e., moduleless)
+ // sections.
+ assert(GetModule().get());
#endif
- return true;
-}
-
-bool
-Section::ContainsFileAddress (addr_t vm_addr) const
-{
- const addr_t file_addr = GetFileAddress();
- if (file_addr != LLDB_INVALID_ADDRESS)
- {
- if (file_addr <= vm_addr)
- {
- const addr_t offset = (vm_addr - file_addr) * m_target_byte_size;
- return offset < GetByteSize();
- }
- }
- return false;
+ return true;
}
-int
-Section::Compare (const Section& a, const Section& b)
-{
- if (&a == &b)
- return 0;
-
- const ModuleSP a_module_sp = a.GetModule();
- const ModuleSP b_module_sp = b.GetModule();
- if (a_module_sp == b_module_sp)
- {
- user_id_t a_sect_uid = a.GetID();
- user_id_t b_sect_uid = b.GetID();
- if (a_sect_uid < b_sect_uid)
- return -1;
- if (a_sect_uid > b_sect_uid)
- return 1;
- return 0;
- }
- else
- {
- // The modules are different, just compare the module pointers
- if (a_module_sp.get() < b_module_sp.get())
- return -1;
- else
- return 1; // We already know the modules aren't equal
+bool Section::ContainsFileAddress(addr_t vm_addr) const {
+ const addr_t file_addr = GetFileAddress();
+ if (file_addr != LLDB_INVALID_ADDRESS) {
+ if (file_addr <= vm_addr) {
+ const addr_t offset = (vm_addr - file_addr) * m_target_byte_size;
+ return offset < GetByteSize();
}
+ }
+ return false;
}
+int Section::Compare(const Section &a, const Section &b) {
+ if (&a == &b)
+ return 0;
-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));
- bool resolved = true;
- addr_t addr = LLDB_INVALID_ADDRESS;
-
- if (GetByteSize() == 0)
- s->Printf("%39s", "");
+ const ModuleSP a_module_sp = a.GetModule();
+ const ModuleSP b_module_sp = b.GetModule();
+ if (a_module_sp == b_module_sp) {
+ user_id_t a_sect_uid = a.GetID();
+ user_id_t b_sect_uid = b.GetID();
+ if (a_sect_uid < b_sect_uid)
+ return -1;
+ if (a_sect_uid > b_sect_uid)
+ return 1;
+ return 0;
+ } else {
+ // The modules are different, just compare the module pointers
+ if (a_module_sp.get() < b_module_sp.get())
+ return -1;
else
- {
- if (target)
- addr = GetLoadBaseAddress (target);
-
- if (addr == LLDB_INVALID_ADDRESS)
- {
- if (target)
- resolved = false;
- addr = GetFileAddress();
- }
-
- VMRange range(addr, addr + m_byte_size);
- range.Dump (s, 0);
- }
-
- s->Printf("%c %c%c%c 0x%8.8" PRIx64 " 0x%8.8" PRIx64 " 0x%8.8x ", resolved ? ' ' : '*', m_readable ? 'r' : '-',
- m_writable ? 'w' : '-', m_executable ? 'x' : '-', m_file_offset, m_file_size, Get());
-
- DumpName (s);
-
- s->EOL();
-
- if (depth > 0)
- m_children.Dump(s, target, false, depth - 1);
+ return 1; // We already know the modules aren't equal
+ }
}
-void
-Section::DumpName (Stream *s) const
-{
- SectionSP parent_sp (GetParent ());
- if (parent_sp)
- {
- parent_sp->DumpName (s);
- s->PutChar('.');
- }
- else
- {
- // 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)
- name = file_spec.GetFilename().AsCString();
- if ((!name || !name[0]) && module_sp)
- name = module_sp->GetFileSpec().GetFilename().AsCString();
- if (name && name[0])
- s->Printf("%s.", name);
- }
- m_name.Dump(s);
+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));
+ bool resolved = true;
+ addr_t addr = LLDB_INVALID_ADDRESS;
+
+ if (GetByteSize() == 0)
+ s->Printf("%39s", "");
+ else {
+ if (target)
+ addr = GetLoadBaseAddress(target);
+
+ if (addr == LLDB_INVALID_ADDRESS) {
+ if (target)
+ resolved = false;
+ addr = GetFileAddress();
+ }
+
+ VMRange range(addr, addr + m_byte_size);
+ range.Dump(s, 0);
+ }
+
+ s->Printf("%c %c%c%c 0x%8.8" PRIx64 " 0x%8.8" PRIx64 " 0x%8.8x ",
+ resolved ? ' ' : '*', m_readable ? 'r' : '-',
+ m_writable ? 'w' : '-', m_executable ? 'x' : '-', m_file_offset,
+ m_file_size, Get());
+
+ DumpName(s);
+
+ s->EOL();
+
+ if (depth > 0)
+ m_children.Dump(s, target, false, depth - 1);
+}
+
+void Section::DumpName(Stream *s) const {
+ SectionSP parent_sp(GetParent());
+ if (parent_sp) {
+ parent_sp->DumpName(s);
+ s->PutChar('.');
+ } else {
+ // 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)
+ name = file_spec.GetFilename().AsCString();
+ if ((!name || !name[0]) && module_sp)
+ name = module_sp->GetFileSpec().GetFilename().AsCString();
+ if (name && name[0])
+ s->Printf("%s.", name);
+ }
+ m_name.Dump(s);
}
-bool
-Section::IsDescendant (const Section *section)
-{
- if (this == section)
- return true;
- SectionSP parent_sp (GetParent ());
- if (parent_sp)
- return parent_sp->IsDescendant (section);
- return false;
+bool Section::IsDescendant(const Section *section) {
+ if (this == section)
+ return true;
+ SectionSP parent_sp(GetParent());
+ if (parent_sp)
+ return parent_sp->IsDescendant(section);
+ return false;
}
-bool
-Section::Slide (addr_t slide_amount, bool slide_children)
-{
- if (m_file_addr != LLDB_INVALID_ADDRESS)
- {
- if (slide_amount == 0)
- return true;
+bool Section::Slide(addr_t slide_amount, bool slide_children) {
+ if (m_file_addr != LLDB_INVALID_ADDRESS) {
+ if (slide_amount == 0)
+ return true;
- m_file_addr += slide_amount;
+ m_file_addr += slide_amount;
- if (slide_children)
- m_children.Slide (slide_amount, slide_children);
+ if (slide_children)
+ m_children.Slide(slide_amount, slide_children);
- return true;
- }
- return false;
+ return true;
+ }
+ return false;
}
//------------------------------------------------------------------
/// Get the permissions as OR'ed bits from lldb::Permissions
//------------------------------------------------------------------
-uint32_t
-Section::GetPermissions() const
-{
- uint32_t permissions = 0;
- if (m_readable)
- permissions |= ePermissionsReadable;
- if (m_writable)
- permissions |= ePermissionsWritable;
- if (m_executable)
- permissions |= ePermissionsExecutable;
- return permissions;
+uint32_t Section::GetPermissions() const {
+ uint32_t permissions = 0;
+ if (m_readable)
+ permissions |= ePermissionsReadable;
+ if (m_writable)
+ permissions |= ePermissionsWritable;
+ if (m_executable)
+ permissions |= ePermissionsExecutable;
+ return permissions;
}
//------------------------------------------------------------------
/// Set the permissions using bits OR'ed from lldb::Permissions
//------------------------------------------------------------------
-void
-Section::SetPermissions(uint32_t permissions)
-{
- m_readable = (permissions & ePermissionsReadable) != 0;
- m_writable = (permissions & ePermissionsWritable) != 0;
- m_executable = (permissions & ePermissionsExecutable) != 0;
-}
-
-lldb::offset_t
-Section::GetSectionData (void *dst, lldb::offset_t dst_len, lldb::offset_t offset)
-{
- if (m_obj_file)
- return m_obj_file->ReadSectionData (this,
- offset,
- dst,
- dst_len);
- return 0;
-}
-
-lldb::offset_t
-Section::GetSectionData (DataExtractor& section_data) const
-{
- if (m_obj_file)
- return m_obj_file->ReadSectionData (this, section_data);
- return 0;
+void Section::SetPermissions(uint32_t permissions) {
+ m_readable = (permissions & ePermissionsReadable) != 0;
+ m_writable = (permissions & ePermissionsWritable) != 0;
+ m_executable = (permissions & ePermissionsExecutable) != 0;
+}
+
+lldb::offset_t Section::GetSectionData(void *dst, lldb::offset_t dst_len,
+ lldb::offset_t offset) {
+ if (m_obj_file)
+ return m_obj_file->ReadSectionData(this, offset, dst, dst_len);
+ return 0;
+}
+
+lldb::offset_t Section::GetSectionData(DataExtractor §ion_data) const {
+ if (m_obj_file)
+ return m_obj_file->ReadSectionData(this, section_data);
+ return 0;
}
#pragma mark SectionList
-SectionList::SectionList () :
- m_sections()
-{
-}
-
+SectionList::SectionList() : m_sections() {}
-SectionList::~SectionList ()
-{
-}
+SectionList::~SectionList() {}
-SectionList &
-SectionList::operator = (const SectionList& rhs)
-{
- if (this != &rhs)
- m_sections = rhs.m_sections;
- return *this;
+SectionList &SectionList::operator=(const SectionList &rhs) {
+ if (this != &rhs)
+ m_sections = rhs.m_sections;
+ return *this;
}
-size_t
-SectionList::AddSection (const lldb::SectionSP& section_sp)
-{
- if (section_sp)
- {
- size_t section_index = m_sections.size();
- m_sections.push_back(section_sp);
- return section_index;
- }
+size_t SectionList::AddSection(const lldb::SectionSP §ion_sp) {
+ if (section_sp) {
+ size_t section_index = m_sections.size();
+ m_sections.push_back(section_sp);
+ return section_index;
+ }
- return std::numeric_limits<size_t>::max ();
+ return std::numeric_limits<size_t>::max();
}
// Warning, this can be slow as it's removing items from a std::vector.
-bool
-SectionList::DeleteSection (size_t idx)
-{
- if (idx < m_sections.size())
- {
- m_sections.erase (m_sections.begin() + idx);
- return true;
- }
- return false;
-}
-
-size_t
-SectionList::FindSectionIndex (const Section* sect)
-{
- iterator sect_iter;
- iterator begin = m_sections.begin();
- iterator end = m_sections.end();
- for (sect_iter = begin; sect_iter != end; ++sect_iter)
- {
- if (sect_iter->get() == sect)
- {
- // The secton was already in this section list
- return std::distance (begin, sect_iter);
- }
- }
- return UINT32_MAX;
-}
-
-size_t
-SectionList::AddUniqueSection (const lldb::SectionSP& sect_sp)
-{
- size_t sect_idx = FindSectionIndex (sect_sp.get());
- if (sect_idx == UINT32_MAX)
- {
- sect_idx = AddSection (sect_sp);
- }
- return sect_idx;
-}
-
-bool
-SectionList::ReplaceSection (user_id_t sect_id, const lldb::SectionSP& sect_sp, uint32_t depth)
-{
- iterator sect_iter, end = m_sections.end();
- for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
- {
- if ((*sect_iter)->GetID() == sect_id)
- {
- *sect_iter = sect_sp;
- return true;
- }
- else if (depth > 0)
- {
- if ((*sect_iter)->GetChildren().ReplaceSection(sect_id, sect_sp, depth - 1))
- return true;
- }
- }
- return false;
-}
-
-size_t
-SectionList::GetNumSections (uint32_t depth) const
-{
- size_t count = m_sections.size();
- if (depth > 0)
- {
- const_iterator sect_iter, end = m_sections.end();
- for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
- {
- count += (*sect_iter)->GetChildren().GetNumSections(depth - 1);
- }
- }
- return count;
-}
-
-SectionSP
-SectionList::GetSectionAtIndex (size_t idx) const
-{
- SectionSP sect_sp;
- if (idx < m_sections.size())
- sect_sp = m_sections[idx];
- return sect_sp;
-}
-
-SectionSP
-SectionList::FindSectionByName (const ConstString §ion_dstr) const
-{
- SectionSP sect_sp;
- // Check if we have a valid section string
- if (section_dstr && !m_sections.empty())
- {
- const_iterator sect_iter;
- const_iterator end = m_sections.end();
- for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
- {
- Section *child_section = sect_iter->get();
- if (child_section)
- {
- if (child_section->GetName() == section_dstr)
- {
- sect_sp = *sect_iter;
- }
- else
- {
- sect_sp = child_section->GetChildren().FindSectionByName(section_dstr);
- }
- }
- }
- }
- return sect_sp;
+bool SectionList::DeleteSection(size_t idx) {
+ if (idx < m_sections.size()) {
+ m_sections.erase(m_sections.begin() + idx);
+ return true;
+ }
+ return false;
}
-SectionSP
-SectionList::FindSectionByID (user_id_t sect_id) const
-{
- SectionSP sect_sp;
- if (sect_id)
- {
- const_iterator sect_iter;
- const_iterator end = m_sections.end();
- for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
- {
- if ((*sect_iter)->GetID() == sect_id)
- {
- sect_sp = *sect_iter;
- break;
- }
- else
- {
- sect_sp = (*sect_iter)->GetChildren().FindSectionByID (sect_id);
- }
- }
+size_t SectionList::FindSectionIndex(const Section *sect) {
+ iterator sect_iter;
+ iterator begin = m_sections.begin();
+ iterator end = m_sections.end();
+ for (sect_iter = begin; sect_iter != end; ++sect_iter) {
+ if (sect_iter->get() == sect) {
+ // The secton was already in this section list
+ return std::distance(begin, sect_iter);
+ }
+ }
+ return UINT32_MAX;
+}
+
+size_t SectionList::AddUniqueSection(const lldb::SectionSP §_sp) {
+ size_t sect_idx = FindSectionIndex(sect_sp.get());
+ if (sect_idx == UINT32_MAX) {
+ sect_idx = AddSection(sect_sp);
+ }
+ return sect_idx;
+}
+
+bool SectionList::ReplaceSection(user_id_t sect_id,
+ const lldb::SectionSP §_sp,
+ uint32_t depth) {
+ iterator sect_iter, end = m_sections.end();
+ for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter) {
+ if ((*sect_iter)->GetID() == sect_id) {
+ *sect_iter = sect_sp;
+ return true;
+ } else if (depth > 0) {
+ if ((*sect_iter)
+ ->GetChildren()
+ .ReplaceSection(sect_id, sect_sp, depth - 1))
+ return true;
}
- return sect_sp;
+ }
+ return false;
}
-
-SectionSP
-SectionList::FindSectionByType (SectionType sect_type, bool check_children, size_t start_idx) const
-{
- SectionSP sect_sp;
- size_t num_sections = m_sections.size();
- for (size_t idx = start_idx; idx < num_sections; ++idx)
- {
- if (m_sections[idx]->GetType() == sect_type)
- {
- sect_sp = m_sections[idx];
- break;
- }
- else if (check_children)
- {
- sect_sp = m_sections[idx]->GetChildren().FindSectionByType (sect_type, check_children, 0);
- if (sect_sp)
- break;
- }
- }
- return sect_sp;
+size_t SectionList::GetNumSections(uint32_t depth) const {
+ size_t count = m_sections.size();
+ if (depth > 0) {
+ const_iterator sect_iter, end = m_sections.end();
+ for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter) {
+ count += (*sect_iter)->GetChildren().GetNumSections(depth - 1);
+ }
+ }
+ return count;
+}
+
+SectionSP SectionList::GetSectionAtIndex(size_t idx) const {
+ SectionSP sect_sp;
+ if (idx < m_sections.size())
+ sect_sp = m_sections[idx];
+ return sect_sp;
}
SectionSP
-SectionList::FindSectionContainingFileAddress (addr_t vm_addr, uint32_t depth) const
-{
- SectionSP sect_sp;
+SectionList::FindSectionByName(const ConstString §ion_dstr) const {
+ SectionSP sect_sp;
+ // Check if we have a valid section string
+ if (section_dstr && !m_sections.empty()) {
const_iterator sect_iter;
const_iterator end = m_sections.end();
- for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
- {
- 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.
- if (depth > 0)
- sect_sp = sect->GetChildren().FindSectionContainingFileAddress(vm_addr, depth - 1);
-
- if (sect_sp.get() == NULL && !sect->IsFake())
- sect_sp = *sect_iter;
- }
- }
- return sect_sp;
-}
-
-bool
-SectionList::ContainsSection(user_id_t sect_id) const
-{
- return FindSectionByID (sect_id).get() != NULL;
-}
-
-void
-SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const
-{
- bool target_has_loaded_sections = target && !target->GetSectionLoadList().IsEmpty();
- if (show_header && !m_sections.empty())
- {
- s->Indent();
- s->Printf("SectID Type %s Address Perm File Off. File Size Flags "
- " Section Name\n",
- target_has_loaded_sections ? "Load" : "File");
- s->Indent();
- s->PutCString("---------- ---------------- --------------------------------------- ---- ---------- ---------- "
- "---------- ----------------------------\n");
- }
-
-
+ for (sect_iter = m_sections.begin();
+ sect_iter != end && sect_sp.get() == NULL; ++sect_iter) {
+ Section *child_section = sect_iter->get();
+ if (child_section) {
+ if (child_section->GetName() == section_dstr) {
+ sect_sp = *sect_iter;
+ } else {
+ sect_sp =
+ child_section->GetChildren().FindSectionByName(section_dstr);
+ }
+ }
+ }
+ }
+ return sect_sp;
+}
+
+SectionSP SectionList::FindSectionByID(user_id_t sect_id) const {
+ SectionSP sect_sp;
+ if (sect_id) {
const_iterator sect_iter;
const_iterator end = m_sections.end();
- for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
- {
- (*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
- }
-
- if (show_header && !m_sections.empty())
- s->IndentLess();
-
-}
-
-size_t
-SectionList::Slide (addr_t slide_amount, bool slide_children)
-{
- size_t count = 0;
- const_iterator pos, end = m_sections.end();
- for (pos = m_sections.begin(); pos != end; ++pos)
- {
- if ((*pos)->Slide(slide_amount, slide_children))
- ++count;
- }
- return count;
+ for (sect_iter = m_sections.begin();
+ sect_iter != end && sect_sp.get() == NULL; ++sect_iter) {
+ if ((*sect_iter)->GetID() == sect_id) {
+ sect_sp = *sect_iter;
+ break;
+ } else {
+ sect_sp = (*sect_iter)->GetChildren().FindSectionByID(sect_id);
+ }
+ }
+ }
+ return sect_sp;
+}
+
+SectionSP SectionList::FindSectionByType(SectionType sect_type,
+ bool check_children,
+ size_t start_idx) const {
+ SectionSP sect_sp;
+ size_t num_sections = m_sections.size();
+ for (size_t idx = start_idx; idx < num_sections; ++idx) {
+ if (m_sections[idx]->GetType() == sect_type) {
+ sect_sp = m_sections[idx];
+ break;
+ } else if (check_children) {
+ sect_sp = m_sections[idx]->GetChildren().FindSectionByType(
+ sect_type, check_children, 0);
+ if (sect_sp)
+ break;
+ }
+ }
+ return sect_sp;
+}
+
+SectionSP SectionList::FindSectionContainingFileAddress(addr_t vm_addr,
+ uint32_t depth) const {
+ SectionSP sect_sp;
+ const_iterator sect_iter;
+ const_iterator end = m_sections.end();
+ for (sect_iter = m_sections.begin();
+ sect_iter != end && sect_sp.get() == NULL; ++sect_iter) {
+ 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.
+ if (depth > 0)
+ sect_sp = sect->GetChildren().FindSectionContainingFileAddress(
+ vm_addr, depth - 1);
+
+ if (sect_sp.get() == NULL && !sect->IsFake())
+ sect_sp = *sect_iter;
+ }
+ }
+ return sect_sp;
+}
+
+bool SectionList::ContainsSection(user_id_t sect_id) const {
+ return FindSectionByID(sect_id).get() != NULL;
+}
+
+void SectionList::Dump(Stream *s, Target *target, bool show_header,
+ uint32_t depth) const {
+ bool target_has_loaded_sections =
+ target && !target->GetSectionLoadList().IsEmpty();
+ if (show_header && !m_sections.empty()) {
+ s->Indent();
+ s->Printf("SectID Type %s Address "
+ " Perm File Off. File Size Flags "
+ " Section Name\n",
+ target_has_loaded_sections ? "Load" : "File");
+ s->Indent();
+ s->PutCString("---------- ---------------- "
+ "--------------------------------------- ---- ---------- "
+ "---------- "
+ "---------- ----------------------------\n");
+ }
+
+ const_iterator sect_iter;
+ const_iterator end = m_sections.end();
+ for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter) {
+ (*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
+ }
+
+ if (show_header && !m_sections.empty())
+ s->IndentLess();
+}
+
+size_t SectionList::Slide(addr_t slide_amount, bool slide_children) {
+ size_t count = 0;
+ const_iterator pos, end = m_sections.end();
+ for (pos = m_sections.begin(); pos != end; ++pos) {
+ if ((*pos)->Slide(slide_amount, slide_children))
+ ++count;
+ }
+ return count;
}
Modified: lldb/trunk/source/Core/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SourceManager.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/SourceManager.cpp (original)
+++ lldb/trunk/source/Core/SourceManager.cpp Tue Sep 6 15:57:50 2016
@@ -26,674 +26,554 @@
using namespace lldb;
using namespace lldb_private;
-
-static inline bool is_newline_char(char ch)
-{
- return ch == '\n' || ch == '\r';
-}
-
+static inline bool is_newline_char(char ch) { return ch == '\n' || ch == '\r'; }
//----------------------------------------------------------------------
// SourceManager constructor
//----------------------------------------------------------------------
-SourceManager::SourceManager(const TargetSP &target_sp) :
- m_last_file_sp (),
- m_last_line (0),
- m_last_count (0),
- m_default_set(false),
- m_target_wp (target_sp),
- m_debugger_wp(target_sp->GetDebugger().shared_from_this())
-{
-}
-
-SourceManager::SourceManager(const DebuggerSP &debugger_sp) :
- m_last_file_sp (),
- m_last_line (0),
- m_last_count (0),
- m_default_set(false),
- m_target_wp (),
- m_debugger_wp (debugger_sp)
-{
-}
+SourceManager::SourceManager(const TargetSP &target_sp)
+ : m_last_file_sp(), m_last_line(0), m_last_count(0), m_default_set(false),
+ m_target_wp(target_sp),
+ m_debugger_wp(target_sp->GetDebugger().shared_from_this()) {}
+
+SourceManager::SourceManager(const DebuggerSP &debugger_sp)
+ : m_last_file_sp(), m_last_line(0), m_last_count(0), m_default_set(false),
+ m_target_wp(), m_debugger_wp(debugger_sp) {}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
-SourceManager::~SourceManager()
-{
-}
+SourceManager::~SourceManager() {}
-SourceManager::FileSP
-SourceManager::GetFile (const FileSpec &file_spec)
-{
- bool same_as_previous = m_last_file_sp && m_last_file_sp->FileSpecMatches (file_spec);
-
- DebuggerSP debugger_sp (m_debugger_wp.lock());
- FileSP file_sp;
- if (same_as_previous)
- file_sp = m_last_file_sp;
- else if (debugger_sp)
- file_sp = debugger_sp->GetSourceFileCache().FindSourceFile (file_spec);
-
- TargetSP target_sp (m_target_wp.lock());
-
- // It the target source path map has been updated, get this file again so we
- // can successfully remap the source file
- if (target_sp && file_sp && file_sp->GetSourceMapModificationID() != target_sp->GetSourcePathMap().GetModificationID())
- file_sp.reset();
-
- // Update the file contents if needed if we found a file
- if (file_sp)
- file_sp->UpdateIfNeeded();
-
- // If file_sp is no good or it points to a non-existent file, reset it.
- if (!file_sp || !file_sp->GetFileSpec().Exists())
- {
- file_sp.reset (new File (file_spec, target_sp.get()));
+SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
+ bool same_as_previous =
+ m_last_file_sp && m_last_file_sp->FileSpecMatches(file_spec);
+
+ DebuggerSP debugger_sp(m_debugger_wp.lock());
+ FileSP file_sp;
+ if (same_as_previous)
+ file_sp = m_last_file_sp;
+ else if (debugger_sp)
+ file_sp = debugger_sp->GetSourceFileCache().FindSourceFile(file_spec);
+
+ TargetSP target_sp(m_target_wp.lock());
+
+ // It the target source path map has been updated, get this file again so we
+ // can successfully remap the source file
+ if (target_sp && file_sp &&
+ file_sp->GetSourceMapModificationID() !=
+ target_sp->GetSourcePathMap().GetModificationID())
+ file_sp.reset();
+
+ // Update the file contents if needed if we found a file
+ if (file_sp)
+ file_sp->UpdateIfNeeded();
+
+ // If file_sp is no good or it points to a non-existent file, reset it.
+ if (!file_sp || !file_sp->GetFileSpec().Exists()) {
+ file_sp.reset(new File(file_spec, target_sp.get()));
+
+ if (debugger_sp)
+ debugger_sp->GetSourceFileCache().AddSourceFile(file_sp);
+ }
+ return file_sp;
+}
+
+size_t SourceManager::DisplaySourceLinesWithLineNumbersUsingLastFile(
+ uint32_t start_line, uint32_t count, uint32_t curr_line,
+ const char *current_line_cstr, Stream *s,
+ const SymbolContextList *bp_locs) {
+ if (count == 0)
+ return 0;
+ size_t return_value = 0;
+ if (start_line == 0) {
+ if (m_last_line != 0 && m_last_line != UINT32_MAX)
+ start_line = m_last_line + m_last_count;
+ else
+ start_line = 1;
+ }
- if (debugger_sp)
- debugger_sp->GetSourceFileCache().AddSourceFile(file_sp);
- }
- return file_sp;
-}
+ if (!m_default_set) {
+ FileSpec tmp_spec;
+ uint32_t tmp_line;
+ GetDefaultFileAndLine(tmp_spec, tmp_line);
+ }
+
+ m_last_line = start_line;
+ m_last_count = count;
+
+ if (m_last_file_sp.get()) {
+ const uint32_t end_line = start_line + count - 1;
+ for (uint32_t line = start_line; line <= end_line; ++line) {
+ if (!m_last_file_sp->LineIsValid(line)) {
+ m_last_line = UINT32_MAX;
+ break;
+ }
+
+ char prefix[32] = "";
+ if (bp_locs) {
+ uint32_t bp_count = bp_locs->NumLineEntriesWithLine(line);
-size_t
-SourceManager::DisplaySourceLinesWithLineNumbersUsingLastFile (uint32_t start_line,
- uint32_t count,
- uint32_t curr_line,
- const char* current_line_cstr,
- Stream *s,
- const SymbolContextList *bp_locs)
-{
- if (count == 0)
- return 0;
- size_t return_value = 0;
- if (start_line == 0)
- {
- if (m_last_line != 0 && m_last_line != UINT32_MAX)
- start_line = m_last_line + m_last_count;
+ if (bp_count > 0)
+ ::snprintf(prefix, sizeof(prefix), "[%u] ", bp_count);
else
- start_line = 1;
- }
-
- if (!m_default_set)
- {
- FileSpec tmp_spec;
- uint32_t tmp_line;
- GetDefaultFileAndLine(tmp_spec, tmp_line);
- }
-
- m_last_line = start_line;
- m_last_count = count;
+ ::snprintf(prefix, sizeof(prefix), " ");
+ }
- if (m_last_file_sp.get())
- {
- const uint32_t end_line = start_line + count - 1;
- for (uint32_t line = start_line; line <= end_line; ++line)
- {
- if (!m_last_file_sp->LineIsValid (line))
- {
- m_last_line = UINT32_MAX;
- break;
- }
-
- char prefix[32] = "";
- if (bp_locs)
- {
- uint32_t bp_count = bp_locs->NumLineEntriesWithLine (line);
-
- if (bp_count > 0)
- ::snprintf (prefix, sizeof (prefix), "[%u] ", bp_count);
- else
- ::snprintf (prefix, sizeof (prefix), " ");
- }
-
- return_value += s->Printf("%s%2.2s %-4u\t",
- prefix,
- line == curr_line ? current_line_cstr : "",
- line);
- size_t this_line_size = m_last_file_sp->DisplaySourceLines (line, 0, 0, s);
- if (this_line_size == 0)
- {
- m_last_line = UINT32_MAX;
- break;
- }
- else
- return_value += this_line_size;
- }
- }
- return return_value;
-}
-
-size_t
-SourceManager::DisplaySourceLinesWithLineNumbers
-(
- const FileSpec &file_spec,
- uint32_t line,
- uint32_t context_before,
- uint32_t context_after,
- const char* current_line_cstr,
- Stream *s,
- const SymbolContextList *bp_locs
-)
-{
- FileSP file_sp (GetFile (file_spec));
-
- uint32_t start_line;
- uint32_t count = context_before + context_after + 1;
- if (line > context_before)
- start_line = line - context_before;
- else
- start_line = 1;
-
- if (m_last_file_sp.get() != file_sp.get())
- {
- if (line == 0)
- m_last_line = 0;
- m_last_file_sp = file_sp;
- }
- return DisplaySourceLinesWithLineNumbersUsingLastFile (start_line, count, line, current_line_cstr, s, bp_locs);
-}
+ return_value +=
+ s->Printf("%s%2.2s %-4u\t", prefix,
+ line == curr_line ? current_line_cstr : "", line);
+ size_t this_line_size = m_last_file_sp->DisplaySourceLines(line, 0, 0, s);
+ if (this_line_size == 0) {
+ m_last_line = UINT32_MAX;
+ break;
+ } else
+ return_value += this_line_size;
+ }
+ }
+ return return_value;
+}
+
+size_t SourceManager::DisplaySourceLinesWithLineNumbers(
+ const FileSpec &file_spec, uint32_t line, uint32_t context_before,
+ uint32_t context_after, const char *current_line_cstr, Stream *s,
+ const SymbolContextList *bp_locs) {
+ FileSP file_sp(GetFile(file_spec));
+
+ uint32_t start_line;
+ uint32_t count = context_before + context_after + 1;
+ if (line > context_before)
+ start_line = line - context_before;
+ else
+ start_line = 1;
-size_t
-SourceManager::DisplayMoreWithLineNumbers (Stream *s,
- uint32_t count,
- bool reverse,
- const SymbolContextList *bp_locs)
-{
- // If we get called before anybody has set a default file and line, then try to figure it out here.
- const bool have_default_file_line = m_last_file_sp && m_last_line > 0;
- if (!m_default_set)
- {
- FileSpec tmp_spec;
- uint32_t tmp_line;
- GetDefaultFileAndLine(tmp_spec, tmp_line);
- }
-
- if (m_last_file_sp)
- {
- if (m_last_line == UINT32_MAX)
- return 0;
-
- if (reverse && m_last_line == 1)
- return 0;
-
- if (count > 0)
- m_last_count = count;
- else if (m_last_count == 0)
- m_last_count = 10;
-
- 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 (m_last_line > m_last_count)
- m_last_line -= m_last_count;
- else
- m_last_line = 1;
- }
- else if (have_default_file_line)
- m_last_line += m_last_count;
- }
+ if (m_last_file_sp.get() != file_sp.get()) {
+ if (line == 0)
+ m_last_line = 0;
+ m_last_file_sp = file_sp;
+ }
+ return DisplaySourceLinesWithLineNumbersUsingLastFile(
+ start_line, count, line, current_line_cstr, s, bp_locs);
+}
+
+size_t SourceManager::DisplayMoreWithLineNumbers(
+ Stream *s, uint32_t count, bool reverse, const SymbolContextList *bp_locs) {
+ // If we get called before anybody has set a default file and line, then try
+ // to figure it out here.
+ const bool have_default_file_line = m_last_file_sp && m_last_line > 0;
+ if (!m_default_set) {
+ FileSpec tmp_spec;
+ uint32_t tmp_line;
+ GetDefaultFileAndLine(tmp_spec, tmp_line);
+ }
+
+ if (m_last_file_sp) {
+ if (m_last_line == UINT32_MAX)
+ return 0;
+
+ if (reverse && m_last_line == 1)
+ return 0;
+
+ if (count > 0)
+ m_last_count = count;
+ else if (m_last_count == 0)
+ m_last_count = 10;
+
+ 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 (m_last_line > m_last_count)
+ m_last_line -= m_last_count;
else
- m_last_line = 1;
-
- return DisplaySourceLinesWithLineNumbersUsingLastFile (m_last_line, m_last_count, UINT32_MAX, "", s, bp_locs);
- }
- return 0;
+ m_last_line = 1;
+ } else if (have_default_file_line)
+ m_last_line += m_last_count;
+ } else
+ m_last_line = 1;
+
+ return DisplaySourceLinesWithLineNumbersUsingLastFile(
+ m_last_line, m_last_count, UINT32_MAX, "", s, bp_locs);
+ }
+ return 0;
+}
+
+bool SourceManager::SetDefaultFileAndLine(const FileSpec &file_spec,
+ uint32_t line) {
+ FileSP old_file_sp = m_last_file_sp;
+ m_last_file_sp = GetFile(file_spec);
+
+ m_default_set = true;
+ if (m_last_file_sp) {
+ m_last_line = line;
+ return true;
+ } else {
+ m_last_file_sp = old_file_sp;
+ return false;
+ }
}
-bool
-SourceManager::SetDefaultFileAndLine (const FileSpec &file_spec, uint32_t line)
-{
- FileSP old_file_sp = m_last_file_sp;
- m_last_file_sp = GetFile (file_spec);
-
- m_default_set = true;
- if (m_last_file_sp)
- {
- m_last_line = line;
- return true;
- }
- else
- {
- m_last_file_sp = old_file_sp;
- return false;
- }
-}
+bool SourceManager::GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line) {
+ if (m_last_file_sp) {
+ file_spec = m_last_file_sp->GetFileSpec();
+ line = m_last_line;
+ return true;
+ } else if (!m_default_set) {
+ TargetSP target_sp(m_target_wp.lock());
-bool
-SourceManager::GetDefaultFileAndLine (FileSpec &file_spec, uint32_t &line)
-{
- if (m_last_file_sp)
- {
- file_spec = m_last_file_sp->GetFileSpec();
- line = m_last_line;
- return true;
- }
- else if (!m_default_set)
- {
- TargetSP target_sp (m_target_wp.lock());
-
- 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...)
- Module *executable_ptr = target_sp->GetExecutableModulePointer();
- if (executable_ptr)
- {
- SymbolContextList sc_list;
- ConstString main_name("main");
- bool symbols_okay = false; // Force it to be a debug symbol.
- bool inlines_okay = true;
- bool append = false;
- size_t num_matches = executable_ptr->FindFunctions (main_name,
- NULL,
- lldb::eFunctionNameTypeBase,
- inlines_okay,
- symbols_okay,
- append,
- sc_list);
- for (size_t idx = 0; idx < num_matches; idx++)
- {
- SymbolContext sc;
- sc_list.GetContextAtIndex(idx, sc);
- if (sc.function)
- {
- lldb_private::LineEntry line_entry;
- if (sc.function->GetAddressRange().GetBaseAddress().CalculateSymbolContextLineEntry (line_entry))
- {
- SetDefaultFileAndLine (line_entry.file,
- line_entry.line);
- file_spec = m_last_file_sp->GetFileSpec();
- line = m_last_line;
- return true;
- }
- }
- }
+ 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...)
+ Module *executable_ptr = target_sp->GetExecutableModulePointer();
+ if (executable_ptr) {
+ SymbolContextList sc_list;
+ ConstString main_name("main");
+ bool symbols_okay = false; // Force it to be a debug symbol.
+ bool inlines_okay = true;
+ bool append = false;
+ size_t num_matches = executable_ptr->FindFunctions(
+ main_name, NULL, lldb::eFunctionNameTypeBase, inlines_okay,
+ symbols_okay, append, sc_list);
+ for (size_t idx = 0; idx < num_matches; idx++) {
+ SymbolContext sc;
+ sc_list.GetContextAtIndex(idx, sc);
+ if (sc.function) {
+ lldb_private::LineEntry line_entry;
+ if (sc.function->GetAddressRange()
+ .GetBaseAddress()
+ .CalculateSymbolContextLineEntry(line_entry)) {
+ SetDefaultFileAndLine(line_entry.file, line_entry.line);
+ file_spec = m_last_file_sp->GetFileSpec();
+ line = m_last_line;
+ return true;
}
+ }
}
+ }
}
- return false;
+ }
+ return false;
}
-void
-SourceManager::FindLinesMatchingRegex (FileSpec &file_spec,
- RegularExpression& regex,
- uint32_t start_line,
- uint32_t end_line,
- std::vector<uint32_t> &match_lines)
-{
- match_lines.clear();
- FileSP file_sp = GetFile (file_spec);
- if (!file_sp)
- return;
- return file_sp->FindLinesMatchingRegex (regex, start_line, end_line, match_lines);
-}
-
-SourceManager::File::File(const FileSpec &file_spec, Target *target) :
- m_file_spec_orig (file_spec),
- m_file_spec(file_spec),
- m_mod_time (file_spec.GetModificationTime()),
- m_source_map_mod_id (0),
- m_data_sp(),
- m_offsets()
-{
- if (!m_mod_time.IsValid())
- {
- if (target)
- {
- m_source_map_mod_id = target->GetSourcePathMap().GetModificationID();
-
- if (!file_spec.GetDirectory() && file_spec.GetFilename())
- {
- // If this is just a file name, lets see if we can find it in the target:
- bool check_inlines = false;
- SymbolContextList sc_list;
- size_t num_matches = target->GetImages().ResolveSymbolContextForFilePath (file_spec.GetFilename().AsCString(),
- 0,
- check_inlines,
- lldb::eSymbolContextModule | lldb::eSymbolContextCompUnit,
- sc_list);
- bool got_multiple = false;
- if (num_matches != 0)
- {
- if (num_matches > 1)
- {
- SymbolContext sc;
- FileSpec *test_cu_spec = NULL;
-
- for (unsigned i = 0; i < num_matches; i++)
- {
- sc_list.GetContextAtIndex(i, sc);
- if (sc.comp_unit)
- {
- if (test_cu_spec)
- {
- if (test_cu_spec != static_cast<FileSpec *> (sc.comp_unit))
- got_multiple = true;
- break;
- }
- else
- test_cu_spec = sc.comp_unit;
- }
- }
- }
- if (!got_multiple)
- {
- SymbolContext sc;
- sc_list.GetContextAtIndex (0, sc);
- m_file_spec = sc.comp_unit;
- m_mod_time = m_file_spec.GetModificationTime();
- }
- }
- }
- // Try remapping if m_file_spec does not correspond to an existing file.
- if (!m_file_spec.Exists())
- {
- 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
- 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;
- m_mod_time = m_file_spec.GetModificationTime();
- }
+void SourceManager::FindLinesMatchingRegex(FileSpec &file_spec,
+ RegularExpression ®ex,
+ uint32_t start_line,
+ uint32_t end_line,
+ std::vector<uint32_t> &match_lines) {
+ match_lines.clear();
+ FileSP file_sp = GetFile(file_spec);
+ if (!file_sp)
+ return;
+ return file_sp->FindLinesMatchingRegex(regex, start_line, end_line,
+ match_lines);
+}
+
+SourceManager::File::File(const FileSpec &file_spec, Target *target)
+ : m_file_spec_orig(file_spec), m_file_spec(file_spec),
+ m_mod_time(file_spec.GetModificationTime()), m_source_map_mod_id(0),
+ m_data_sp(), m_offsets() {
+ if (!m_mod_time.IsValid()) {
+ if (target) {
+ m_source_map_mod_id = target->GetSourcePathMap().GetModificationID();
+
+ if (!file_spec.GetDirectory() && file_spec.GetFilename()) {
+ // If this is just a file name, lets see if we can find it in the
+ // target:
+ bool check_inlines = false;
+ SymbolContextList sc_list;
+ size_t num_matches =
+ target->GetImages().ResolveSymbolContextForFilePath(
+ file_spec.GetFilename().AsCString(), 0, check_inlines,
+ lldb::eSymbolContextModule | lldb::eSymbolContextCompUnit,
+ sc_list);
+ bool got_multiple = false;
+ if (num_matches != 0) {
+ if (num_matches > 1) {
+ SymbolContext sc;
+ FileSpec *test_cu_spec = NULL;
+
+ for (unsigned i = 0; i < num_matches; i++) {
+ sc_list.GetContextAtIndex(i, sc);
+ if (sc.comp_unit) {
+ if (test_cu_spec) {
+ if (test_cu_spec != static_cast<FileSpec *>(sc.comp_unit))
+ got_multiple = true;
+ break;
+ } else
+ test_cu_spec = sc.comp_unit;
+ }
}
+ }
+ if (!got_multiple) {
+ SymbolContext sc;
+ sc_list.GetContextAtIndex(0, sc);
+ m_file_spec = sc.comp_unit;
+ m_mod_time = m_file_spec.GetModificationTime();
+ }
+ }
+ }
+ // Try remapping if m_file_spec does not correspond to an existing file.
+ if (!m_file_spec.Exists()) {
+ 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
+ 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;
+ m_mod_time = m_file_spec.GetModificationTime();
}
+ }
}
-
- if (m_mod_time.IsValid())
- m_data_sp = m_file_spec.ReadFileContents ();
-}
+ }
-SourceManager::File::~File()
-{
+ if (m_mod_time.IsValid())
+ m_data_sp = m_file_spec.ReadFileContents();
}
-uint32_t
-SourceManager::File::GetLineOffset (uint32_t line)
-{
- if (line == 0)
- return UINT32_MAX;
-
- if (line == 1)
- return 0;
+SourceManager::File::~File() {}
- if (CalculateLineOffsets (line))
- {
- if (line < m_offsets.size())
- return m_offsets[line - 1]; // yes we want "line - 1" in the index
- }
+uint32_t SourceManager::File::GetLineOffset(uint32_t line) {
+ if (line == 0)
return UINT32_MAX;
-}
-
-uint32_t
-SourceManager::File::GetNumLines ()
-{
- CalculateLineOffsets();
- return m_offsets.size();
-}
-
-const char *
-SourceManager::File::PeekLineData (uint32_t line)
-{
- if (!LineIsValid(line))
- return NULL;
-
- size_t line_offset = GetLineOffset (line);
- if (line_offset < m_data_sp->GetByteSize())
- return (const char *)m_data_sp->GetBytes() + line_offset;
- return NULL;
-}
-uint32_t
-SourceManager::File::GetLineLength (uint32_t line, bool include_newline_chars)
-{
- if (!LineIsValid(line))
- return false;
-
- size_t start_offset = GetLineOffset (line);
- size_t end_offset = GetLineOffset (line + 1);
- if (end_offset == UINT32_MAX)
- end_offset = m_data_sp->GetByteSize();
-
- if (end_offset > start_offset)
- {
- uint32_t length = end_offset - start_offset;
- if (include_newline_chars == false)
- {
- const char *line_start = (const char *)m_data_sp->GetBytes() + start_offset;
- while (length > 0)
- {
- const char last_char = line_start[length-1];
- if ((last_char == '\r') || (last_char == '\n'))
- --length;
- else
- break;
- }
- }
- return length;
- }
+ if (line == 1)
return 0;
-}
-
-bool
-SourceManager::File::LineIsValid (uint32_t line)
-{
- if (line == 0)
- return false;
- if (CalculateLineOffsets (line))
- return line < m_offsets.size();
- return false;
+ if (CalculateLineOffsets(line)) {
+ if (line < m_offsets.size())
+ return m_offsets[line - 1]; // yes we want "line - 1" in the index
+ }
+ return UINT32_MAX;
}
-void
-SourceManager::File::UpdateIfNeeded ()
-{
- // TODO: use host API to sign up for file modifications to anything in our
- // source cache and only update when we determine a file has been updated.
- // For now we check each time we want to display info for the file.
- TimeValue curr_mod_time (m_file_spec.GetModificationTime());
-
- if (curr_mod_time.IsValid() && m_mod_time != curr_mod_time)
- {
- m_mod_time = curr_mod_time;
- m_data_sp = m_file_spec.ReadFileContents ();
- m_offsets.clear();
- }
+uint32_t SourceManager::File::GetNumLines() {
+ CalculateLineOffsets();
+ return m_offsets.size();
}
-size_t
-SourceManager::File::DisplaySourceLines (uint32_t line, uint32_t context_before, uint32_t context_after, Stream *s)
-{
- // Sanity check m_data_sp before proceeding.
- if (!m_data_sp)
- return 0;
-
- const uint32_t start_line = line <= context_before ? 1 : line - context_before;
- const uint32_t start_line_offset = GetLineOffset (start_line);
- if (start_line_offset != UINT32_MAX)
- {
- const uint32_t end_line = line + context_after;
- uint32_t end_line_offset = GetLineOffset (end_line + 1);
- if (end_line_offset == UINT32_MAX)
- end_line_offset = m_data_sp->GetByteSize();
-
- assert (start_line_offset <= end_line_offset);
- size_t bytes_written = 0;
- if (start_line_offset < end_line_offset)
- {
- size_t count = end_line_offset - start_line_offset;
- const uint8_t *cstr = m_data_sp->GetBytes() + start_line_offset;
- bytes_written = s->Write(cstr, count);
- if (!is_newline_char(cstr[count-1]))
- bytes_written += s->EOL();
- }
- return bytes_written;
- }
- return 0;
-}
+const char *SourceManager::File::PeekLineData(uint32_t line) {
+ if (!LineIsValid(line))
+ return NULL;
-void
-SourceManager::File::FindLinesMatchingRegex (RegularExpression& regex, uint32_t start_line, uint32_t end_line, std::vector<uint32_t> &match_lines)
-{
- match_lines.clear();
-
- if (!LineIsValid(start_line) || (end_line != UINT32_MAX && !LineIsValid(end_line)))
- return;
- if (start_line > end_line)
- return;
-
- for (uint32_t line_no = start_line; line_no < end_line; line_no++)
- {
- std::string buffer;
- if (!GetLine (line_no, buffer))
- break;
- if (regex.Execute(buffer.c_str()))
- {
- match_lines.push_back(line_no);
- }
- }
+ size_t line_offset = GetLineOffset(line);
+ if (line_offset < m_data_sp->GetByteSize())
+ return (const char *)m_data_sp->GetBytes() + line_offset;
+ return NULL;
}
-bool
-SourceManager::File::FileSpecMatches (const FileSpec &file_spec)
-{
- return FileSpec::Equal (m_file_spec, file_spec, false);
-}
-
-bool
-lldb_private::operator== (const SourceManager::File &lhs, const SourceManager::File &rhs)
-{
- if (lhs.m_file_spec == rhs.m_file_spec)
- {
- if (lhs.m_mod_time.IsValid())
- {
- if (rhs.m_mod_time.IsValid())
- return lhs.m_mod_time == rhs.m_mod_time;
- else
- return false;
- }
- else if (rhs.m_mod_time.IsValid())
- return false;
+uint32_t SourceManager::File::GetLineLength(uint32_t line,
+ bool include_newline_chars) {
+ if (!LineIsValid(line))
+ return false;
+
+ size_t start_offset = GetLineOffset(line);
+ size_t end_offset = GetLineOffset(line + 1);
+ if (end_offset == UINT32_MAX)
+ end_offset = m_data_sp->GetByteSize();
+
+ if (end_offset > start_offset) {
+ uint32_t length = end_offset - start_offset;
+ if (include_newline_chars == false) {
+ const char *line_start =
+ (const char *)m_data_sp->GetBytes() + start_offset;
+ while (length > 0) {
+ const char last_char = line_start[length - 1];
+ if ((last_char == '\r') || (last_char == '\n'))
+ --length;
else
- return true;
+ break;
+ }
}
- else
- return false;
+ return length;
+ }
+ return 0;
}
-bool
-SourceManager::File::CalculateLineOffsets (uint32_t line)
-{
- line = UINT32_MAX; // TODO: take this line out when we support partial indexing
- if (line == UINT32_MAX)
- {
- // Already done?
- if (!m_offsets.empty() && m_offsets[0] == UINT32_MAX)
- return true;
-
- if (m_offsets.empty())
- {
- if (m_data_sp.get() == NULL)
- return false;
-
- const char *start = (char *)m_data_sp->GetBytes();
- if (start)
- {
- const char *end = start + m_data_sp->GetByteSize();
-
- // Calculate all line offsets from scratch
-
- // Push a 1 at index zero to indicate the file has been completely indexed.
- m_offsets.push_back(UINT32_MAX);
- const char *s;
- for (s = start; s < end; ++s)
- {
- char curr_ch = *s;
- if (is_newline_char (curr_ch))
- {
- if (s + 1 < end)
- {
- char next_ch = s[1];
- if (is_newline_char (next_ch))
- {
- if (curr_ch != next_ch)
- ++s;
- }
- }
- m_offsets.push_back(s + 1 - start);
- }
- }
- if (!m_offsets.empty())
- {
- if (m_offsets.back() < end - start)
- m_offsets.push_back(end - start);
- }
- return true;
- }
- }
- else
- {
- // Some lines have been populated, start where we last left off
- assert("Not implemented yet" && false);
- }
+bool SourceManager::File::LineIsValid(uint32_t line) {
+ if (line == 0)
+ return false;
- }
+ if (CalculateLineOffsets(line))
+ return line < m_offsets.size();
+ return false;
+}
+
+void SourceManager::File::UpdateIfNeeded() {
+ // TODO: use host API to sign up for file modifications to anything in our
+ // source cache and only update when we determine a file has been updated.
+ // For now we check each time we want to display info for the file.
+ TimeValue curr_mod_time(m_file_spec.GetModificationTime());
+
+ if (curr_mod_time.IsValid() && m_mod_time != curr_mod_time) {
+ m_mod_time = curr_mod_time;
+ m_data_sp = m_file_spec.ReadFileContents();
+ m_offsets.clear();
+ }
+}
+
+size_t SourceManager::File::DisplaySourceLines(uint32_t line,
+ uint32_t context_before,
+ uint32_t context_after,
+ Stream *s) {
+ // Sanity check m_data_sp before proceeding.
+ if (!m_data_sp)
+ return 0;
+
+ const uint32_t start_line =
+ line <= context_before ? 1 : line - context_before;
+ const uint32_t start_line_offset = GetLineOffset(start_line);
+ if (start_line_offset != UINT32_MAX) {
+ const uint32_t end_line = line + context_after;
+ uint32_t end_line_offset = GetLineOffset(end_line + 1);
+ if (end_line_offset == UINT32_MAX)
+ end_line_offset = m_data_sp->GetByteSize();
+
+ assert(start_line_offset <= end_line_offset);
+ size_t bytes_written = 0;
+ if (start_line_offset < end_line_offset) {
+ size_t count = end_line_offset - start_line_offset;
+ const uint8_t *cstr = m_data_sp->GetBytes() + start_line_offset;
+ bytes_written = s->Write(cstr, count);
+ if (!is_newline_char(cstr[count - 1]))
+ bytes_written += s->EOL();
+ }
+ return bytes_written;
+ }
+ return 0;
+}
+
+void SourceManager::File::FindLinesMatchingRegex(
+ RegularExpression ®ex, uint32_t start_line, uint32_t end_line,
+ std::vector<uint32_t> &match_lines) {
+ match_lines.clear();
+
+ if (!LineIsValid(start_line) ||
+ (end_line != UINT32_MAX && !LineIsValid(end_line)))
+ return;
+ if (start_line > end_line)
+ return;
+
+ for (uint32_t line_no = start_line; line_no < end_line; line_no++) {
+ std::string buffer;
+ if (!GetLine(line_no, buffer))
+ break;
+ if (regex.Execute(buffer.c_str())) {
+ match_lines.push_back(line_no);
+ }
+ }
+}
+
+bool SourceManager::File::FileSpecMatches(const FileSpec &file_spec) {
+ return FileSpec::Equal(m_file_spec, file_spec, false);
+}
+
+bool lldb_private::operator==(const SourceManager::File &lhs,
+ const SourceManager::File &rhs) {
+ if (lhs.m_file_spec == rhs.m_file_spec) {
+ if (lhs.m_mod_time.IsValid()) {
+ if (rhs.m_mod_time.IsValid())
+ return lhs.m_mod_time == rhs.m_mod_time;
+ else
+ return false;
+ } else if (rhs.m_mod_time.IsValid())
+ return false;
else
- {
- // Calculate all line offsets up to "line"
- assert("Not implemented yet" && false);
- }
+ return true;
+ } else
return false;
}
-bool
-SourceManager::File::GetLine (uint32_t line_no, std::string &buffer)
-{
- if (!LineIsValid(line_no))
+bool SourceManager::File::CalculateLineOffsets(uint32_t line) {
+ line =
+ UINT32_MAX; // TODO: take this line out when we support partial indexing
+ if (line == UINT32_MAX) {
+ // Already done?
+ if (!m_offsets.empty() && m_offsets[0] == UINT32_MAX)
+ return true;
+
+ if (m_offsets.empty()) {
+ if (m_data_sp.get() == NULL)
return false;
- size_t start_offset = GetLineOffset (line_no);
- size_t end_offset = GetLineOffset (line_no + 1);
- if (end_offset == UINT32_MAX)
- {
- end_offset = m_data_sp->GetByteSize();
+ const char *start = (char *)m_data_sp->GetBytes();
+ if (start) {
+ const char *end = start + m_data_sp->GetByteSize();
+
+ // Calculate all line offsets from scratch
+
+ // Push a 1 at index zero to indicate the file has been completely
+ // indexed.
+ m_offsets.push_back(UINT32_MAX);
+ const char *s;
+ for (s = start; s < end; ++s) {
+ char curr_ch = *s;
+ if (is_newline_char(curr_ch)) {
+ if (s + 1 < end) {
+ char next_ch = s[1];
+ if (is_newline_char(next_ch)) {
+ if (curr_ch != next_ch)
+ ++s;
+ }
+ }
+ m_offsets.push_back(s + 1 - start);
+ }
+ }
+ if (!m_offsets.empty()) {
+ if (m_offsets.back() < end - start)
+ m_offsets.push_back(end - start);
+ }
+ return true;
+ }
+ } else {
+ // Some lines have been populated, start where we last left off
+ assert("Not implemented yet" && false);
}
- buffer.assign((char *) m_data_sp->GetBytes() + start_offset, end_offset - start_offset);
-
- return true;
-}
-void
-SourceManager::SourceFileCache::AddSourceFile (const FileSP &file_sp)
-{
- FileSpec file_spec;
- FileCache::iterator pos = m_file_cache.find(file_spec);
- if (pos == m_file_cache.end())
- m_file_cache[file_spec] = file_sp;
- else
- {
- if (file_sp != pos->second)
- m_file_cache[file_spec] = file_sp;
- }
+ } else {
+ // Calculate all line offsets up to "line"
+ assert("Not implemented yet" && false);
+ }
+ return false;
}
-SourceManager::FileSP
-SourceManager::SourceFileCache::FindSourceFile (const FileSpec &file_spec) const
-{
- FileSP file_sp;
- FileCache::const_iterator pos = m_file_cache.find(file_spec);
- if (pos != m_file_cache.end())
- file_sp = pos->second;
- return file_sp;
-}
+bool SourceManager::File::GetLine(uint32_t line_no, std::string &buffer) {
+ if (!LineIsValid(line_no))
+ return false;
+ size_t start_offset = GetLineOffset(line_no);
+ size_t end_offset = GetLineOffset(line_no + 1);
+ if (end_offset == UINT32_MAX) {
+ end_offset = m_data_sp->GetByteSize();
+ }
+ buffer.assign((char *)m_data_sp->GetBytes() + start_offset,
+ end_offset - start_offset);
+
+ return true;
+}
+
+void SourceManager::SourceFileCache::AddSourceFile(const FileSP &file_sp) {
+ FileSpec file_spec;
+ FileCache::iterator pos = m_file_cache.find(file_spec);
+ if (pos == m_file_cache.end())
+ m_file_cache[file_spec] = file_sp;
+ else {
+ if (file_sp != pos->second)
+ m_file_cache[file_spec] = file_sp;
+ }
+}
+
+SourceManager::FileSP SourceManager::SourceFileCache::FindSourceFile(
+ const FileSpec &file_spec) const {
+ FileSP file_sp;
+ FileCache::const_iterator pos = m_file_cache.find(file_spec);
+ if (pos != m_file_cache.end())
+ file_sp = pos->second;
+ return file_sp;
+}
Modified: lldb/trunk/source/Core/State.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/State.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/State.cpp (original)
+++ lldb/trunk/source/Core/State.cpp Tue Sep 6 15:57:50 2016
@@ -17,99 +17,103 @@
using namespace lldb;
using namespace lldb_private;
-const char *
-lldb_private::StateAsCString (StateType state)
-{
- switch (state)
- {
- case eStateInvalid: return "invalid";
- case eStateUnloaded: return "unloaded";
- case eStateConnected: return "connected";
- case eStateAttaching: return "attaching";
- case eStateLaunching: return "launching";
- case eStateStopped: return "stopped";
- case eStateRunning: return "running";
- case eStateStepping: return "stepping";
- case eStateCrashed: return "crashed";
- case eStateDetached: return "detached";
- case eStateExited: return "exited";
- case eStateSuspended: return "suspended";
- }
- static char unknown_state_string[64];
- snprintf(unknown_state_string, sizeof (unknown_state_string), "StateType = %i", state);
- return unknown_state_string;
+const char *lldb_private::StateAsCString(StateType state) {
+ switch (state) {
+ case eStateInvalid:
+ return "invalid";
+ case eStateUnloaded:
+ return "unloaded";
+ case eStateConnected:
+ return "connected";
+ case eStateAttaching:
+ return "attaching";
+ case eStateLaunching:
+ return "launching";
+ case eStateStopped:
+ return "stopped";
+ case eStateRunning:
+ return "running";
+ case eStateStepping:
+ return "stepping";
+ case eStateCrashed:
+ return "crashed";
+ case eStateDetached:
+ return "detached";
+ case eStateExited:
+ return "exited";
+ case eStateSuspended:
+ return "suspended";
+ }
+ static char unknown_state_string[64];
+ snprintf(unknown_state_string, sizeof(unknown_state_string), "StateType = %i",
+ state);
+ return unknown_state_string;
}
-const char *
-lldb_private::GetPermissionsAsCString (uint32_t permissions)
-{
- switch (permissions)
- {
- case 0: return "---";
- case ePermissionsWritable: return "-w-";
- case ePermissionsReadable: return "r--";
- case ePermissionsExecutable: return "--x";
- case ePermissionsReadable |
- ePermissionsWritable: return "rw-";
- case ePermissionsReadable |
- ePermissionsExecutable: return "r-x";
- case ePermissionsWritable |
- ePermissionsExecutable: return "-wx";
- case ePermissionsReadable |
- ePermissionsWritable |
- ePermissionsExecutable: return "rwx";
- default:
- break;
- }
- return "???";
+const char *lldb_private::GetPermissionsAsCString(uint32_t permissions) {
+ switch (permissions) {
+ case 0:
+ return "---";
+ case ePermissionsWritable:
+ return "-w-";
+ case ePermissionsReadable:
+ return "r--";
+ case ePermissionsExecutable:
+ return "--x";
+ case ePermissionsReadable | ePermissionsWritable:
+ return "rw-";
+ case ePermissionsReadable | ePermissionsExecutable:
+ return "r-x";
+ case ePermissionsWritable | ePermissionsExecutable:
+ return "-wx";
+ case ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable:
+ return "rwx";
+ default:
+ break;
+ }
+ return "???";
}
-bool
-lldb_private::StateIsRunningState (StateType state)
-{
- switch (state)
- {
- case eStateAttaching:
- case eStateLaunching:
- case eStateRunning:
- case eStateStepping:
- return true;
-
- case eStateConnected:
- case eStateDetached:
- case eStateInvalid:
- case eStateUnloaded:
- case eStateStopped:
- case eStateCrashed:
- case eStateExited:
- case eStateSuspended:
- break;
- }
- return false;
+bool lldb_private::StateIsRunningState(StateType state) {
+ switch (state) {
+ case eStateAttaching:
+ case eStateLaunching:
+ case eStateRunning:
+ case eStateStepping:
+ return true;
+
+ case eStateConnected:
+ case eStateDetached:
+ case eStateInvalid:
+ case eStateUnloaded:
+ case eStateStopped:
+ case eStateCrashed:
+ case eStateExited:
+ case eStateSuspended:
+ break;
+ }
+ return false;
}
-bool
-lldb_private::StateIsStoppedState (StateType state, bool must_exist)
-{
- switch (state)
- {
- case eStateInvalid:
- case eStateConnected:
- case eStateAttaching:
- case eStateLaunching:
- case eStateRunning:
- case eStateStepping:
- case eStateDetached:
- break;
-
- case eStateUnloaded:
- case eStateExited:
- return !must_exist;
-
- case eStateStopped:
- case eStateCrashed:
- case eStateSuspended:
- return true;
- }
- return false;
+bool lldb_private::StateIsStoppedState(StateType state, bool must_exist) {
+ switch (state) {
+ case eStateInvalid:
+ case eStateConnected:
+ case eStateAttaching:
+ case eStateLaunching:
+ case eStateRunning:
+ case eStateStepping:
+ case eStateDetached:
+ break;
+
+ case eStateUnloaded:
+ case eStateExited:
+ return !must_exist;
+
+ case eStateStopped:
+ case eStateCrashed:
+ case eStateSuspended:
+ return true;
+ }
+ return false;
}
Modified: lldb/trunk/source/Core/Stream.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Stream.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/Stream.cpp (original)
+++ lldb/trunk/source/Core/Stream.cpp Tue Sep 6 15:57:50 2016
@@ -12,776 +12,608 @@
#include "lldb/Host/PosixApi.h"
#include <stddef.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#include <inttypes.h>
using namespace lldb;
using namespace lldb_private;
-Stream::Stream (uint32_t flags, uint32_t addr_size, ByteOrder byte_order) :
- m_flags (flags),
- m_addr_size (addr_size),
- m_byte_order (byte_order),
- m_indent_level(0)
-{
-}
-
-Stream::Stream () :
- m_flags (0),
- m_addr_size (4),
- m_byte_order (endian::InlHostByteOrder()),
- m_indent_level(0)
-{
-}
+Stream::Stream(uint32_t flags, uint32_t addr_size, ByteOrder byte_order)
+ : m_flags(flags), m_addr_size(addr_size), m_byte_order(byte_order),
+ m_indent_level(0) {}
+
+Stream::Stream()
+ : m_flags(0), m_addr_size(4), m_byte_order(endian::InlHostByteOrder()),
+ m_indent_level(0) {}
//------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------
-Stream::~Stream ()
-{
-}
+Stream::~Stream() {}
-ByteOrder
-Stream::SetByteOrder (ByteOrder byte_order)
-{
- ByteOrder old_byte_order = m_byte_order;
- m_byte_order = byte_order;
- return old_byte_order;
+ByteOrder Stream::SetByteOrder(ByteOrder byte_order) {
+ ByteOrder old_byte_order = m_byte_order;
+ m_byte_order = byte_order;
+ return old_byte_order;
}
//------------------------------------------------------------------
// Put an offset "uval" out to the stream using the printf format
// in "format".
//------------------------------------------------------------------
-void
-Stream::Offset (uint32_t uval, const char *format)
-{
- Printf (format, uval);
-}
+void Stream::Offset(uint32_t uval, const char *format) { Printf(format, uval); }
//------------------------------------------------------------------
// Put an SLEB128 "uval" out to the stream using the printf format
// in "format".
//------------------------------------------------------------------
-size_t
-Stream::PutSLEB128 (int64_t sval)
-{
- size_t bytes_written = 0;
- if (m_flags.Test(eBinary))
- {
- bool more = true;
- while (more)
- {
- uint8_t byte = sval & 0x7fu;
- sval >>= 7;
- /* sign bit of byte is 2nd high order bit (0x40) */
- if ((sval == 0 && !(byte & 0x40)) ||
- (sval == -1 && (byte & 0x40)) )
- more = false;
- else
- // more bytes to come
- byte |= 0x80u;
- bytes_written += Write(&byte, 1);
- }
- }
- else
- {
- bytes_written = Printf ("0x%" PRIi64, sval);
- }
-
- return bytes_written;
+size_t Stream::PutSLEB128(int64_t sval) {
+ size_t bytes_written = 0;
+ if (m_flags.Test(eBinary)) {
+ bool more = true;
+ while (more) {
+ uint8_t byte = sval & 0x7fu;
+ sval >>= 7;
+ /* sign bit of byte is 2nd high order bit (0x40) */
+ if ((sval == 0 && !(byte & 0x40)) || (sval == -1 && (byte & 0x40)))
+ more = false;
+ else
+ // more bytes to come
+ byte |= 0x80u;
+ bytes_written += Write(&byte, 1);
+ }
+ } else {
+ bytes_written = Printf("0x%" PRIi64, sval);
+ }
+ return bytes_written;
}
//------------------------------------------------------------------
// Put an ULEB128 "uval" out to the stream using the printf format
// in "format".
//------------------------------------------------------------------
-size_t
-Stream::PutULEB128 (uint64_t uval)
-{
- size_t bytes_written = 0;
- if (m_flags.Test(eBinary))
- {
- do
- {
-
- uint8_t byte = uval & 0x7fu;
- uval >>= 7;
- if (uval != 0)
- {
- // more bytes to come
- byte |= 0x80u;
- }
- bytes_written += Write(&byte, 1);
- } while (uval != 0);
- }
- else
- {
- bytes_written = Printf ("0x%" PRIx64, uval);
- }
- return bytes_written;
+size_t Stream::PutULEB128(uint64_t uval) {
+ size_t bytes_written = 0;
+ if (m_flags.Test(eBinary)) {
+ do {
+
+ uint8_t byte = uval & 0x7fu;
+ uval >>= 7;
+ if (uval != 0) {
+ // more bytes to come
+ byte |= 0x80u;
+ }
+ bytes_written += Write(&byte, 1);
+ } while (uval != 0);
+ } else {
+ bytes_written = Printf("0x%" PRIx64, uval);
+ }
+ return bytes_written;
}
//------------------------------------------------------------------
// Print a raw NULL terminated C string to the stream.
//------------------------------------------------------------------
-size_t
-Stream::PutCString (const char *cstr)
-{
- size_t cstr_len = strlen(cstr);
- // when in binary mode, emit the NULL terminator
- if (m_flags.Test(eBinary))
- ++cstr_len;
- return Write (cstr, cstr_len);
+size_t Stream::PutCString(const char *cstr) {
+ size_t cstr_len = strlen(cstr);
+ // when in binary mode, emit the NULL terminator
+ if (m_flags.Test(eBinary))
+ ++cstr_len;
+ return Write(cstr, cstr_len);
}
//------------------------------------------------------------------
// Print a double quoted NULL terminated C string to the stream
// using the printf format in "format".
//------------------------------------------------------------------
-void
-Stream::QuotedCString (const char *cstr, const char *format)
-{
- Printf (format, cstr);
+void Stream::QuotedCString(const char *cstr, const char *format) {
+ Printf(format, cstr);
}
//------------------------------------------------------------------
// Put an address "addr" out to the stream with optional prefix
// and suffix strings.
//------------------------------------------------------------------
-void
-Stream::Address (uint64_t addr, uint32_t addr_size, const char *prefix, const char *suffix)
-{
- if (prefix == NULL)
- prefix = "";
- if (suffix == NULL)
- suffix = "";
-// int addr_width = m_addr_size << 1;
-// Printf ("%s0x%0*" PRIx64 "%s", prefix, addr_width, addr, suffix);
- Printf ("%s0x%0*" PRIx64 "%s", prefix, addr_size * 2, (uint64_t)addr, suffix);
+void Stream::Address(uint64_t addr, uint32_t addr_size, const char *prefix,
+ const char *suffix) {
+ if (prefix == NULL)
+ prefix = "";
+ if (suffix == NULL)
+ suffix = "";
+ // int addr_width = m_addr_size << 1;
+ // Printf ("%s0x%0*" PRIx64 "%s", prefix, addr_width, addr, suffix);
+ Printf("%s0x%0*" PRIx64 "%s", prefix, addr_size * 2, (uint64_t)addr, suffix);
}
//------------------------------------------------------------------
// Put an address range out to the stream with optional prefix
// and suffix strings.
//------------------------------------------------------------------
-void
-Stream::AddressRange(uint64_t lo_addr, uint64_t hi_addr, uint32_t addr_size, const char *prefix, const char *suffix)
-{
- if (prefix && prefix[0])
- PutCString (prefix);
- Address (lo_addr, addr_size, "[");
- Address (hi_addr, addr_size, "-", ")");
- if (suffix && suffix[0])
- PutCString (suffix);
-}
-
-
-size_t
-Stream::PutChar (char ch)
-{
- return Write (&ch, 1);
+void Stream::AddressRange(uint64_t lo_addr, uint64_t hi_addr,
+ uint32_t addr_size, const char *prefix,
+ const char *suffix) {
+ if (prefix && prefix[0])
+ PutCString(prefix);
+ Address(lo_addr, addr_size, "[");
+ Address(hi_addr, addr_size, "-", ")");
+ if (suffix && suffix[0])
+ PutCString(suffix);
}
+size_t Stream::PutChar(char ch) { return Write(&ch, 1); }
//------------------------------------------------------------------
// Print some formatted output to the stream.
//------------------------------------------------------------------
-size_t
-Stream::Printf (const char *format, ...)
-{
- va_list args;
- va_start (args, format);
- size_t result = PrintfVarArg(format, args);
- va_end (args);
- return result;
+size_t Stream::Printf(const char *format, ...) {
+ va_list args;
+ va_start(args, format);
+ size_t result = PrintfVarArg(format, args);
+ va_end(args);
+ return result;
}
//------------------------------------------------------------------
// Print some formatted output to the stream.
//------------------------------------------------------------------
-size_t
-Stream::PrintfVarArg (const char *format, va_list args)
-{
- char str[1024];
- va_list args_copy;
-
- va_copy (args_copy, args);
-
- size_t bytes_written = 0;
- // Try and format our string into a fixed buffer first and see if it fits
- size_t length = ::vsnprintf (str, sizeof(str), format, args);
- if (length < sizeof(str))
- {
- // Include the NULL termination byte for binary output
- if (m_flags.Test(eBinary))
- length += 1;
- // The formatted string fit into our stack based buffer, so we can just
- // append that to our packet
- bytes_written = Write (str, length);
- }
- else
- {
- // Our stack buffer wasn't big enough to contain the entire formatted
- // string, so lets let vasprintf create the string for us!
- char *str_ptr = NULL;
- length = ::vasprintf (&str_ptr, format, args_copy);
- if (str_ptr)
- {
- // Include the NULL termination byte for binary output
- if (m_flags.Test(eBinary))
- length += 1;
- bytes_written = Write (str_ptr, length);
- ::free (str_ptr);
- }
- }
- va_end (args_copy);
- return bytes_written;
+size_t Stream::PrintfVarArg(const char *format, va_list args) {
+ char str[1024];
+ va_list args_copy;
+
+ va_copy(args_copy, args);
+
+ size_t bytes_written = 0;
+ // Try and format our string into a fixed buffer first and see if it fits
+ size_t length = ::vsnprintf(str, sizeof(str), format, args);
+ if (length < sizeof(str)) {
+ // Include the NULL termination byte for binary output
+ if (m_flags.Test(eBinary))
+ length += 1;
+ // The formatted string fit into our stack based buffer, so we can just
+ // append that to our packet
+ bytes_written = Write(str, length);
+ } else {
+ // Our stack buffer wasn't big enough to contain the entire formatted
+ // string, so lets let vasprintf create the string for us!
+ char *str_ptr = NULL;
+ length = ::vasprintf(&str_ptr, format, args_copy);
+ if (str_ptr) {
+ // Include the NULL termination byte for binary output
+ if (m_flags.Test(eBinary))
+ length += 1;
+ bytes_written = Write(str_ptr, length);
+ ::free(str_ptr);
+ }
+ }
+ va_end(args_copy);
+ return bytes_written;
}
//------------------------------------------------------------------
// Print and End of Line character to the stream
//------------------------------------------------------------------
-size_t
-Stream::EOL()
-{
- return PutChar ('\n');
-}
+size_t Stream::EOL() { return PutChar('\n'); }
//------------------------------------------------------------------
// Indent the current line using the current indentation level and
// print an optional string following the indentation spaces.
//------------------------------------------------------------------
-size_t
-Stream::Indent(const char *s)
-{
- return Printf ("%*.*s%s", m_indent_level, m_indent_level, "", s ? s : "");
+size_t Stream::Indent(const char *s) {
+ return Printf("%*.*s%s", m_indent_level, m_indent_level, "", s ? s : "");
}
//------------------------------------------------------------------
// Stream a character "ch" out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (char ch)
-{
- PutChar (ch);
- return *this;
+Stream &Stream::operator<<(char ch) {
+ PutChar(ch);
+ return *this;
}
//------------------------------------------------------------------
// Stream the NULL terminated C string out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (const char *s)
-{
- Printf ("%s", s);
- return *this;
+Stream &Stream::operator<<(const char *s) {
+ Printf("%s", s);
+ return *this;
}
//------------------------------------------------------------------
// Stream the pointer value out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (const void *p)
-{
- Printf ("0x%.*tx", (int)sizeof(const void*) * 2, (ptrdiff_t)p);
- return *this;
+Stream &Stream::operator<<(const void *p) {
+ Printf("0x%.*tx", (int)sizeof(const void *) * 2, (ptrdiff_t)p);
+ return *this;
}
//------------------------------------------------------------------
// Stream a uint8_t "uval" out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (uint8_t uval)
-{
- PutHex8(uval);
- return *this;
+Stream &Stream::operator<<(uint8_t uval) {
+ PutHex8(uval);
+ return *this;
}
//------------------------------------------------------------------
// Stream a uint16_t "uval" out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (uint16_t uval)
-{
- PutHex16(uval, m_byte_order);
- return *this;
+Stream &Stream::operator<<(uint16_t uval) {
+ PutHex16(uval, m_byte_order);
+ return *this;
}
//------------------------------------------------------------------
// Stream a uint32_t "uval" out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (uint32_t uval)
-{
- PutHex32(uval, m_byte_order);
- return *this;
+Stream &Stream::operator<<(uint32_t uval) {
+ PutHex32(uval, m_byte_order);
+ return *this;
}
//------------------------------------------------------------------
// Stream a uint64_t "uval" out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (uint64_t uval)
-{
- PutHex64(uval, m_byte_order);
- return *this;
+Stream &Stream::operator<<(uint64_t uval) {
+ PutHex64(uval, m_byte_order);
+ return *this;
}
//------------------------------------------------------------------
// Stream a int8_t "sval" out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (int8_t sval)
-{
- Printf ("%i", (int)sval);
- return *this;
+Stream &Stream::operator<<(int8_t sval) {
+ Printf("%i", (int)sval);
+ return *this;
}
//------------------------------------------------------------------
// Stream a int16_t "sval" out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (int16_t sval)
-{
- Printf ("%i", (int)sval);
- return *this;
+Stream &Stream::operator<<(int16_t sval) {
+ Printf("%i", (int)sval);
+ return *this;
}
//------------------------------------------------------------------
// Stream a int32_t "sval" out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (int32_t sval)
-{
- Printf ("%i", (int)sval);
- return *this;
+Stream &Stream::operator<<(int32_t sval) {
+ Printf("%i", (int)sval);
+ return *this;
}
//------------------------------------------------------------------
// Stream a int64_t "sval" out to this stream.
//------------------------------------------------------------------
-Stream&
-Stream::operator<< (int64_t sval)
-{
- Printf ("%" PRIi64, sval);
- return *this;
+Stream &Stream::operator<<(int64_t sval) {
+ Printf("%" PRIi64, sval);
+ return *this;
}
//------------------------------------------------------------------
// Get the current indentation level
//------------------------------------------------------------------
-int
-Stream::GetIndentLevel() const
-{
- return m_indent_level;
-}
+int Stream::GetIndentLevel() const { return m_indent_level; }
//------------------------------------------------------------------
// Set the current indentation level
//------------------------------------------------------------------
-void
-Stream::SetIndentLevel(int indent_level)
-{
- m_indent_level = indent_level;
-}
+void Stream::SetIndentLevel(int indent_level) { m_indent_level = indent_level; }
//------------------------------------------------------------------
// Increment the current indentation level
//------------------------------------------------------------------
-void
-Stream::IndentMore(int amount)
-{
- m_indent_level += amount;
-}
+void Stream::IndentMore(int amount) { m_indent_level += amount; }
//------------------------------------------------------------------
// Decrement the current indentation level
//------------------------------------------------------------------
-void
-Stream::IndentLess (int amount)
-{
- if (m_indent_level >= amount)
- m_indent_level -= amount;
- else
- m_indent_level = 0;
+void Stream::IndentLess(int amount) {
+ if (m_indent_level >= amount)
+ m_indent_level -= amount;
+ else
+ m_indent_level = 0;
}
//------------------------------------------------------------------
// Get the address size in bytes
//------------------------------------------------------------------
-uint32_t
-Stream::GetAddressByteSize() const
-{
- return m_addr_size;
-}
+uint32_t Stream::GetAddressByteSize() const { return m_addr_size; }
//------------------------------------------------------------------
// Set the address size in bytes
//------------------------------------------------------------------
-void
-Stream::SetAddressByteSize(uint32_t addr_size)
-{
- m_addr_size = addr_size;
-}
+void Stream::SetAddressByteSize(uint32_t addr_size) { m_addr_size = addr_size; }
//------------------------------------------------------------------
// Returns true if the verbose flag bit is set in this stream.
//------------------------------------------------------------------
-bool
-Stream::GetVerbose() const
-{
- return m_flags.Test(eVerbose);
-}
+bool Stream::GetVerbose() const { return m_flags.Test(eVerbose); }
//------------------------------------------------------------------
// Returns true if the debug flag bit is set in this stream.
//------------------------------------------------------------------
-bool
-Stream::GetDebug() const
-{
- return m_flags.Test(eDebug);
-}
+bool Stream::GetDebug() const { return m_flags.Test(eDebug); }
//------------------------------------------------------------------
// The flags get accessor
//------------------------------------------------------------------
-Flags&
-Stream::GetFlags()
-{
- return m_flags;
-}
+Flags &Stream::GetFlags() { return m_flags; }
//------------------------------------------------------------------
// The flags const get accessor
//------------------------------------------------------------------
-const Flags&
-Stream::GetFlags() const
-{
- return m_flags;
-}
+const Flags &Stream::GetFlags() const { return m_flags; }
//------------------------------------------------------------------
// The byte order get accessor
//------------------------------------------------------------------
-lldb::ByteOrder
-Stream::GetByteOrder() const
-{
- return m_byte_order;
-}
-
-size_t
-Stream::PrintfAsRawHex8 (const char *format, ...)
-{
- va_list args;
- va_list args_copy;
- va_start (args, format);
- va_copy (args_copy,args); // Copy this so we
-
- char str[1024];
- size_t bytes_written = 0;
- // Try and format our string into a fixed buffer first and see if it fits
- size_t length = ::vsnprintf (str, sizeof(str), format, args);
- if (length < sizeof(str))
- {
- // The formatted string fit into our stack based buffer, so we can just
- // append that to our packet
- for (size_t i=0; i<length; ++i)
- bytes_written += _PutHex8 (str[i], false);
- }
- else
- {
- // Our stack buffer wasn't big enough to contain the entire formatted
- // string, so lets let vasprintf create the string for us!
- char *str_ptr = NULL;
- length = ::vasprintf (&str_ptr, format, args_copy);
- if (str_ptr)
- {
- for (size_t i=0; i<length; ++i)
- bytes_written += _PutHex8 (str_ptr[i], false);
- ::free (str_ptr);
- }
- }
- va_end (args);
- va_end (args_copy);
-
- return bytes_written;
-}
-
-size_t
-Stream::PutNHex8 (size_t n, uint8_t uvalue)
-{
- size_t bytes_written = 0;
- for (size_t i=0; i<n; ++i)
- bytes_written += _PutHex8 (uvalue, m_flags.Test(eAddPrefix));
- return bytes_written;
-}
+lldb::ByteOrder Stream::GetByteOrder() const { return m_byte_order; }
-size_t
-Stream::_PutHex8 (uint8_t uvalue, bool add_prefix)
-{
- size_t bytes_written = 0;
- if (m_flags.Test(eBinary))
- {
- bytes_written = Write (&uvalue, 1);
- }
- else
- {
- if (add_prefix)
- PutCString("0x");
-
- static char g_hex_to_ascii_hex_char[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
- char nibble_chars[2];
- nibble_chars[0] = g_hex_to_ascii_hex_char[(uvalue >> 4) & 0xf];
- nibble_chars[1] = g_hex_to_ascii_hex_char[(uvalue >> 0) & 0xf];
- bytes_written = Write (nibble_chars, sizeof(nibble_chars));
- }
- return bytes_written;
-}
-
-size_t
-Stream::PutHex8 (uint8_t uvalue)
-{
- return _PutHex8 (uvalue, m_flags.Test(eAddPrefix));
-}
-
-size_t
-Stream::PutHex16 (uint16_t uvalue, ByteOrder byte_order)
-{
- if (byte_order == eByteOrderInvalid)
- byte_order = m_byte_order;
-
- bool add_prefix = m_flags.Test(eAddPrefix);
- size_t bytes_written = 0;
- if (byte_order == eByteOrderLittle)
- {
- for (size_t byte = 0; byte < sizeof(uvalue); ++byte, add_prefix = false)
- bytes_written += _PutHex8 ((uint8_t)(uvalue >> (byte * 8)), add_prefix);
- }
- else
- {
- for (size_t byte = sizeof(uvalue)-1; byte < sizeof(uvalue); --byte, add_prefix = false)
- bytes_written += _PutHex8 ((uint8_t)(uvalue >> (byte * 8)), add_prefix);
- }
- return bytes_written;
-}
-
-size_t
-Stream::PutHex32(uint32_t uvalue, ByteOrder byte_order)
-{
- if (byte_order == eByteOrderInvalid)
- byte_order = m_byte_order;
-
- bool add_prefix = m_flags.Test(eAddPrefix);
- size_t bytes_written = 0;
- if (byte_order == eByteOrderLittle)
- {
- for (size_t byte = 0; byte < sizeof(uvalue); ++byte, add_prefix = false)
- bytes_written += _PutHex8 ((uint8_t)(uvalue >> (byte * 8)), add_prefix);
- }
- else
- {
- for (size_t byte = sizeof(uvalue)-1; byte < sizeof(uvalue); --byte, add_prefix = false)
- bytes_written += _PutHex8 ((uint8_t)(uvalue >> (byte * 8)), add_prefix);
- }
- return bytes_written;
-}
-
-size_t
-Stream::PutHex64(uint64_t uvalue, ByteOrder byte_order)
-{
- if (byte_order == eByteOrderInvalid)
- byte_order = m_byte_order;
-
- bool add_prefix = m_flags.Test(eAddPrefix);
- size_t bytes_written = 0;
- if (byte_order == eByteOrderLittle)
- {
- for (size_t byte = 0; byte < sizeof(uvalue); ++byte, add_prefix = false)
- bytes_written += _PutHex8 ((uint8_t)(uvalue >> (byte * 8)), add_prefix);
- }
- else
- {
- for (size_t byte = sizeof(uvalue)-1; byte < sizeof(uvalue); --byte, add_prefix = false)
- bytes_written += _PutHex8 ((uint8_t)(uvalue >> (byte * 8)), add_prefix);
- }
- return bytes_written;
-}
-
-size_t
-Stream::PutMaxHex64
-(
- uint64_t uvalue,
- size_t byte_size,
- lldb::ByteOrder byte_order
-)
-{
- switch (byte_size)
- {
- case 1: return PutHex8 ((uint8_t)uvalue);
- case 2: return PutHex16 ((uint16_t)uvalue);
- case 4: return PutHex32 ((uint32_t)uvalue);
- case 8: return PutHex64 (uvalue);
- }
- return 0;
-}
-
-size_t
-Stream::PutPointer (void *ptr)
-{
- return PutRawBytes (&ptr, sizeof(ptr), endian::InlHostByteOrder(), endian::InlHostByteOrder());
-}
-
-size_t
-Stream::PutFloat(float f, ByteOrder byte_order)
-{
- if (byte_order == eByteOrderInvalid)
- byte_order = m_byte_order;
-
- return PutRawBytes (&f, sizeof(f), endian::InlHostByteOrder(), byte_order);
-}
-
-size_t
-Stream::PutDouble(double d, ByteOrder byte_order)
-{
- if (byte_order == eByteOrderInvalid)
- byte_order = m_byte_order;
-
- return PutRawBytes (&d, sizeof(d), endian::InlHostByteOrder(), byte_order);
-}
-
-size_t
-Stream::PutLongDouble(long double ld, ByteOrder byte_order)
-{
- if (byte_order == eByteOrderInvalid)
- byte_order = m_byte_order;
-
- return PutRawBytes (&ld, sizeof(ld), endian::InlHostByteOrder(), byte_order);
-}
-
-size_t
-Stream::PutRawBytes (const void *s, size_t src_len, ByteOrder src_byte_order, ByteOrder dst_byte_order)
-{
- if (src_byte_order == eByteOrderInvalid)
- src_byte_order = m_byte_order;
-
- if (dst_byte_order == eByteOrderInvalid)
- dst_byte_order = m_byte_order;
-
- size_t bytes_written = 0;
- const uint8_t *src = (const uint8_t *)s;
- bool binary_was_set = m_flags.Test (eBinary);
- if (!binary_was_set)
- m_flags.Set (eBinary);
- if (src_byte_order == dst_byte_order)
- {
- for (size_t i = 0; i < src_len; ++i)
- bytes_written += _PutHex8 (src[i], false);
- }
- else
- {
- for (size_t i = src_len-1; i < src_len; --i)
- bytes_written += _PutHex8 (src[i], false);
- }
- if (!binary_was_set)
- m_flags.Clear (eBinary);
-
- return bytes_written;
-}
-
-size_t
-Stream::PutBytesAsRawHex8 (const void *s, size_t src_len, ByteOrder src_byte_order, ByteOrder dst_byte_order)
-{
- if (src_byte_order == eByteOrderInvalid)
- src_byte_order = m_byte_order;
-
- if (dst_byte_order == eByteOrderInvalid)
- dst_byte_order = m_byte_order;
-
- size_t bytes_written = 0;
- const uint8_t *src = (const uint8_t *)s;
- bool binary_is_set = m_flags.Test(eBinary);
+size_t Stream::PrintfAsRawHex8(const char *format, ...) {
+ va_list args;
+ va_list args_copy;
+ va_start(args, format);
+ va_copy(args_copy, args); // Copy this so we
+
+ char str[1024];
+ size_t bytes_written = 0;
+ // Try and format our string into a fixed buffer first and see if it fits
+ size_t length = ::vsnprintf(str, sizeof(str), format, args);
+ if (length < sizeof(str)) {
+ // The formatted string fit into our stack based buffer, so we can just
+ // append that to our packet
+ for (size_t i = 0; i < length; ++i)
+ bytes_written += _PutHex8(str[i], false);
+ } else {
+ // Our stack buffer wasn't big enough to contain the entire formatted
+ // string, so lets let vasprintf create the string for us!
+ char *str_ptr = NULL;
+ length = ::vasprintf(&str_ptr, format, args_copy);
+ if (str_ptr) {
+ for (size_t i = 0; i < length; ++i)
+ bytes_written += _PutHex8(str_ptr[i], false);
+ ::free(str_ptr);
+ }
+ }
+ va_end(args);
+ va_end(args_copy);
+
+ return bytes_written;
+}
+
+size_t Stream::PutNHex8(size_t n, uint8_t uvalue) {
+ size_t bytes_written = 0;
+ for (size_t i = 0; i < n; ++i)
+ bytes_written += _PutHex8(uvalue, m_flags.Test(eAddPrefix));
+ return bytes_written;
+}
+
+size_t Stream::_PutHex8(uint8_t uvalue, bool add_prefix) {
+ size_t bytes_written = 0;
+ if (m_flags.Test(eBinary)) {
+ bytes_written = Write(&uvalue, 1);
+ } else {
+ if (add_prefix)
+ PutCString("0x");
+
+ static char g_hex_to_ascii_hex_char[16] = {'0', '1', '2', '3', '4', '5',
+ '6', '7', '8', '9', 'a', 'b',
+ 'c', 'd', 'e', 'f'};
+ char nibble_chars[2];
+ nibble_chars[0] = g_hex_to_ascii_hex_char[(uvalue >> 4) & 0xf];
+ nibble_chars[1] = g_hex_to_ascii_hex_char[(uvalue >> 0) & 0xf];
+ bytes_written = Write(nibble_chars, sizeof(nibble_chars));
+ }
+ return bytes_written;
+}
+
+size_t Stream::PutHex8(uint8_t uvalue) {
+ return _PutHex8(uvalue, m_flags.Test(eAddPrefix));
+}
+
+size_t Stream::PutHex16(uint16_t uvalue, ByteOrder byte_order) {
+ if (byte_order == eByteOrderInvalid)
+ byte_order = m_byte_order;
+
+ bool add_prefix = m_flags.Test(eAddPrefix);
+ size_t bytes_written = 0;
+ if (byte_order == eByteOrderLittle) {
+ for (size_t byte = 0; byte < sizeof(uvalue); ++byte, add_prefix = false)
+ bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), add_prefix);
+ } else {
+ for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue);
+ --byte, add_prefix = false)
+ bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), add_prefix);
+ }
+ return bytes_written;
+}
+
+size_t Stream::PutHex32(uint32_t uvalue, ByteOrder byte_order) {
+ if (byte_order == eByteOrderInvalid)
+ byte_order = m_byte_order;
+
+ bool add_prefix = m_flags.Test(eAddPrefix);
+ size_t bytes_written = 0;
+ if (byte_order == eByteOrderLittle) {
+ for (size_t byte = 0; byte < sizeof(uvalue); ++byte, add_prefix = false)
+ bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), add_prefix);
+ } else {
+ for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue);
+ --byte, add_prefix = false)
+ bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), add_prefix);
+ }
+ return bytes_written;
+}
+
+size_t Stream::PutHex64(uint64_t uvalue, ByteOrder byte_order) {
+ if (byte_order == eByteOrderInvalid)
+ byte_order = m_byte_order;
+
+ bool add_prefix = m_flags.Test(eAddPrefix);
+ size_t bytes_written = 0;
+ if (byte_order == eByteOrderLittle) {
+ for (size_t byte = 0; byte < sizeof(uvalue); ++byte, add_prefix = false)
+ bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), add_prefix);
+ } else {
+ for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue);
+ --byte, add_prefix = false)
+ bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), add_prefix);
+ }
+ return bytes_written;
+}
+
+size_t Stream::PutMaxHex64(uint64_t uvalue, size_t byte_size,
+ lldb::ByteOrder byte_order) {
+ switch (byte_size) {
+ case 1:
+ return PutHex8((uint8_t)uvalue);
+ case 2:
+ return PutHex16((uint16_t)uvalue);
+ case 4:
+ return PutHex32((uint32_t)uvalue);
+ case 8:
+ return PutHex64(uvalue);
+ }
+ return 0;
+}
+
+size_t Stream::PutPointer(void *ptr) {
+ return PutRawBytes(&ptr, sizeof(ptr), endian::InlHostByteOrder(),
+ endian::InlHostByteOrder());
+}
+
+size_t Stream::PutFloat(float f, ByteOrder byte_order) {
+ if (byte_order == eByteOrderInvalid)
+ byte_order = m_byte_order;
+
+ return PutRawBytes(&f, sizeof(f), endian::InlHostByteOrder(), byte_order);
+}
+
+size_t Stream::PutDouble(double d, ByteOrder byte_order) {
+ if (byte_order == eByteOrderInvalid)
+ byte_order = m_byte_order;
+
+ return PutRawBytes(&d, sizeof(d), endian::InlHostByteOrder(), byte_order);
+}
+
+size_t Stream::PutLongDouble(long double ld, ByteOrder byte_order) {
+ if (byte_order == eByteOrderInvalid)
+ byte_order = m_byte_order;
+
+ return PutRawBytes(&ld, sizeof(ld), endian::InlHostByteOrder(), byte_order);
+}
+
+size_t Stream::PutRawBytes(const void *s, size_t src_len,
+ ByteOrder src_byte_order, ByteOrder dst_byte_order) {
+ if (src_byte_order == eByteOrderInvalid)
+ src_byte_order = m_byte_order;
+
+ if (dst_byte_order == eByteOrderInvalid)
+ dst_byte_order = m_byte_order;
+
+ size_t bytes_written = 0;
+ const uint8_t *src = (const uint8_t *)s;
+ bool binary_was_set = m_flags.Test(eBinary);
+ if (!binary_was_set)
+ m_flags.Set(eBinary);
+ if (src_byte_order == dst_byte_order) {
+ for (size_t i = 0; i < src_len; ++i)
+ bytes_written += _PutHex8(src[i], false);
+ } else {
+ for (size_t i = src_len - 1; i < src_len; --i)
+ bytes_written += _PutHex8(src[i], false);
+ }
+ if (!binary_was_set)
m_flags.Clear(eBinary);
- if (src_byte_order == dst_byte_order)
- {
- for (size_t i = 0; i < src_len; ++i)
- bytes_written += _PutHex8 (src[i], false);
- }
- else
- {
- for (size_t i = src_len-1; i < src_len; --i)
- bytes_written += _PutHex8 (src[i], false);
- }
- if (binary_is_set)
- m_flags.Set(eBinary);
- return bytes_written;
+ return bytes_written;
}
-size_t
-Stream::PutCStringAsRawHex8 (const char *s)
-{
- size_t bytes_written = 0;
- bool binary_is_set = m_flags.Test(eBinary);
- m_flags.Clear(eBinary);
- do
- {
- bytes_written += _PutHex8 (*s, false);
- ++s;
- } while (*s);
- if (binary_is_set)
- m_flags.Set(eBinary);
- return bytes_written;
-}
-
-void
-Stream::UnitTest(Stream *s)
-{
- s->PutHex8(0x12);
-
- s->PutChar(' ');
- s->PutHex16(0x3456, endian::InlHostByteOrder());
- s->PutChar(' ');
- s->PutHex16(0x3456, eByteOrderBig);
- s->PutChar(' ');
- s->PutHex16(0x3456, eByteOrderLittle);
-
- s->PutChar(' ');
- s->PutHex32(0x789abcde, endian::InlHostByteOrder());
- s->PutChar(' ');
- s->PutHex32(0x789abcde, eByteOrderBig);
- s->PutChar(' ');
- s->PutHex32(0x789abcde, eByteOrderLittle);
-
- s->PutChar(' ');
- s->PutHex64(0x1122334455667788ull, endian::InlHostByteOrder());
- s->PutChar(' ');
- s->PutHex64(0x1122334455667788ull, eByteOrderBig);
- s->PutChar(' ');
- s->PutHex64(0x1122334455667788ull, eByteOrderLittle);
-
- const char *hola = "Hello World!!!";
- s->PutChar(' ');
- s->PutCString (hola);
-
- s->PutChar(' ');
- s->Write (hola, 5);
-
- s->PutChar(' ');
- s->PutCStringAsRawHex8 (hola);
-
- s->PutChar(' ');
- s->PutCStringAsRawHex8 ("01234");
-
- s->PutChar(' ');
- s->Printf ("pid=%i", 12733);
-
- s->PutChar(' ');
- s->PrintfAsRawHex8 ("pid=%i", 12733);
- s->PutChar('\n');
+size_t Stream::PutBytesAsRawHex8(const void *s, size_t src_len,
+ ByteOrder src_byte_order,
+ ByteOrder dst_byte_order) {
+ if (src_byte_order == eByteOrderInvalid)
+ src_byte_order = m_byte_order;
+
+ if (dst_byte_order == eByteOrderInvalid)
+ dst_byte_order = m_byte_order;
+
+ size_t bytes_written = 0;
+ const uint8_t *src = (const uint8_t *)s;
+ bool binary_is_set = m_flags.Test(eBinary);
+ m_flags.Clear(eBinary);
+ if (src_byte_order == dst_byte_order) {
+ for (size_t i = 0; i < src_len; ++i)
+ bytes_written += _PutHex8(src[i], false);
+ } else {
+ for (size_t i = src_len - 1; i < src_len; --i)
+ bytes_written += _PutHex8(src[i], false);
+ }
+ if (binary_is_set)
+ m_flags.Set(eBinary);
+
+ return bytes_written;
+}
+
+size_t Stream::PutCStringAsRawHex8(const char *s) {
+ size_t bytes_written = 0;
+ bool binary_is_set = m_flags.Test(eBinary);
+ m_flags.Clear(eBinary);
+ do {
+ bytes_written += _PutHex8(*s, false);
+ ++s;
+ } while (*s);
+ if (binary_is_set)
+ m_flags.Set(eBinary);
+ return bytes_written;
+}
+
+void Stream::UnitTest(Stream *s) {
+ s->PutHex8(0x12);
+
+ s->PutChar(' ');
+ s->PutHex16(0x3456, endian::InlHostByteOrder());
+ s->PutChar(' ');
+ s->PutHex16(0x3456, eByteOrderBig);
+ s->PutChar(' ');
+ s->PutHex16(0x3456, eByteOrderLittle);
+
+ s->PutChar(' ');
+ s->PutHex32(0x789abcde, endian::InlHostByteOrder());
+ s->PutChar(' ');
+ s->PutHex32(0x789abcde, eByteOrderBig);
+ s->PutChar(' ');
+ s->PutHex32(0x789abcde, eByteOrderLittle);
+
+ s->PutChar(' ');
+ s->PutHex64(0x1122334455667788ull, endian::InlHostByteOrder());
+ s->PutChar(' ');
+ s->PutHex64(0x1122334455667788ull, eByteOrderBig);
+ s->PutChar(' ');
+ s->PutHex64(0x1122334455667788ull, eByteOrderLittle);
+
+ const char *hola = "Hello World!!!";
+ s->PutChar(' ');
+ s->PutCString(hola);
+
+ s->PutChar(' ');
+ s->Write(hola, 5);
+
+ s->PutChar(' ');
+ s->PutCStringAsRawHex8(hola);
+
+ s->PutChar(' ');
+ s->PutCStringAsRawHex8("01234");
+
+ s->PutChar(' ');
+ s->Printf("pid=%i", 12733);
+
+ s->PutChar(' ');
+ s->PrintfAsRawHex8("pid=%i", 12733);
+ s->PutChar('\n');
}
-
Modified: lldb/trunk/source/Core/StreamAsynchronousIO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamAsynchronousIO.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/StreamAsynchronousIO.cpp (original)
+++ lldb/trunk/source/Core/StreamAsynchronousIO.cpp Tue Sep 6 15:57:50 2016
@@ -9,40 +9,29 @@
#include "lldb/Core/StreamAsynchronousIO.h"
-#include "lldb/lldb-private.h"
#include "lldb/Core/Debugger.h"
+#include "lldb/lldb-private.h"
using namespace lldb;
using namespace lldb_private;
-
-StreamAsynchronousIO::StreamAsynchronousIO (Debugger &debugger, bool for_stdout) :
- Stream (0, 4, eByteOrderBig),
- m_debugger (debugger),
- m_data (),
- m_for_stdout (for_stdout)
-{
-}
-
-StreamAsynchronousIO::~StreamAsynchronousIO ()
-{
- // Flush when we destroy to make sure we display the data
- Flush();
+StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout)
+ : Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(),
+ m_for_stdout(for_stdout) {}
+
+StreamAsynchronousIO::~StreamAsynchronousIO() {
+ // Flush when we destroy to make sure we display the data
+ Flush();
}
-void
-StreamAsynchronousIO::Flush ()
-{
- if (!m_data.empty())
- {
- m_debugger.PrintAsync (m_data.data(), m_data.size(), m_for_stdout);
- m_data = std::string();
- }
+void StreamAsynchronousIO::Flush() {
+ if (!m_data.empty()) {
+ m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout);
+ m_data = std::string();
+ }
}
-size_t
-StreamAsynchronousIO::Write (const void *s, size_t length)
-{
- m_data.append ((const char *)s, length);
- return length;
+size_t StreamAsynchronousIO::Write(const void *s, size_t length) {
+ m_data.append((const char *)s, length);
+ return length;
}
Modified: lldb/trunk/source/Core/StreamCallback.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamCallback.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/StreamCallback.cpp (original)
+++ lldb/trunk/source/Core/StreamCallback.cpp Tue Sep 6 15:57:50 2016
@@ -9,51 +9,42 @@
#include <stdio.h>
-#include "lldb/lldb-private.h"
#include "lldb/Core/Broadcaster.h"
#include "lldb/Core/Event.h"
#include "lldb/Core/StreamCallback.h"
#include "lldb/Host/Host.h"
+#include "lldb/lldb-private.h"
using namespace lldb;
using namespace lldb_private;
StreamCallback::StreamCallback(lldb::LogOutputCallback callback, void *baton)
- : Stream(0, 4, eByteOrderBig), m_callback(callback), m_baton(baton), m_accumulated_data(), m_collection_mutex()
-{
-}
+ : Stream(0, 4, eByteOrderBig), m_callback(callback), m_baton(baton),
+ m_accumulated_data(), m_collection_mutex() {}
-StreamCallback::~StreamCallback ()
-{
-}
+StreamCallback::~StreamCallback() {}
-StreamString &
-StreamCallback::FindStreamForThread(lldb::tid_t cur_tid)
-{
- std::lock_guard<std::mutex> guard(m_collection_mutex);
- collection::iterator iter = m_accumulated_data.find (cur_tid);
- if (iter == m_accumulated_data.end())
- {
- std::pair<collection::iterator, bool> ret;
- ret = m_accumulated_data.insert(std::pair<lldb::tid_t,StreamString>(cur_tid, StreamString()));
- iter = ret.first;
- }
- return (*iter).second;
+StreamString &StreamCallback::FindStreamForThread(lldb::tid_t cur_tid) {
+ std::lock_guard<std::mutex> guard(m_collection_mutex);
+ collection::iterator iter = m_accumulated_data.find(cur_tid);
+ if (iter == m_accumulated_data.end()) {
+ std::pair<collection::iterator, bool> ret;
+ ret = m_accumulated_data.insert(
+ std::pair<lldb::tid_t, StreamString>(cur_tid, StreamString()));
+ iter = ret.first;
+ }
+ return (*iter).second;
}
-void
-StreamCallback::Flush ()
-{
- lldb::tid_t cur_tid = Host::GetCurrentThreadID();
- StreamString &out_stream = FindStreamForThread(cur_tid);
- m_callback (out_stream.GetData(), m_baton);
- out_stream.Clear();
+void StreamCallback::Flush() {
+ lldb::tid_t cur_tid = Host::GetCurrentThreadID();
+ StreamString &out_stream = FindStreamForThread(cur_tid);
+ m_callback(out_stream.GetData(), m_baton);
+ out_stream.Clear();
}
-size_t
-StreamCallback::Write (const void *s, size_t length)
-{
- lldb::tid_t cur_tid = Host::GetCurrentThreadID();
- FindStreamForThread(cur_tid).Write (s, length);
- return length;
+size_t StreamCallback::Write(const void *s, size_t length) {
+ lldb::tid_t cur_tid = Host::GetCurrentThreadID();
+ FindStreamForThread(cur_tid).Write(s, length);
+ return length;
}
Modified: lldb/trunk/source/Core/StreamFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamFile.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/StreamFile.cpp (original)
+++ lldb/trunk/source/Core/StreamFile.cpp Tue Sep 6 15:57:50 2016
@@ -16,65 +16,37 @@
// Project includes
#include "lldb/Core/Error.h"
-
using namespace lldb;
using namespace lldb_private;
//----------------------------------------------------------------------
// StreamFile constructor
//----------------------------------------------------------------------
-StreamFile::StreamFile () :
- Stream (),
- m_file ()
-{
-}
+StreamFile::StreamFile() : Stream(), m_file() {}
-StreamFile::StreamFile (uint32_t flags, uint32_t addr_size, ByteOrder byte_order) :
- Stream (flags, addr_size, byte_order),
- m_file ()
-{
-}
+StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order)
+ : Stream(flags, addr_size, byte_order), m_file() {}
-StreamFile::StreamFile (int fd, bool transfer_ownership) :
- Stream (),
- m_file (fd, transfer_ownership)
-{
-}
+StreamFile::StreamFile(int fd, bool transfer_ownership)
+ : Stream(), m_file(fd, transfer_ownership) {}
-StreamFile::StreamFile (FILE *fh, bool transfer_ownership) :
- Stream (),
- m_file (fh, transfer_ownership)
-{
-}
+StreamFile::StreamFile(FILE *fh, bool transfer_ownership)
+ : Stream(), m_file(fh, transfer_ownership) {}
-StreamFile::StreamFile (const char *path) :
- Stream (),
- m_file (path, File::eOpenOptionWrite | File::eOpenOptionCanCreate | File::eOpenOptionCloseOnExec,
- lldb::eFilePermissionsFileDefault)
-{
-}
+StreamFile::StreamFile(const char *path)
+ : Stream(),
+ m_file(path, File::eOpenOptionWrite | File::eOpenOptionCanCreate |
+ File::eOpenOptionCloseOnExec,
+ lldb::eFilePermissionsFileDefault) {}
-StreamFile::StreamFile (const char *path,
- uint32_t options,
- uint32_t permissions) :
- Stream(),
- m_file(path, options, permissions)
-{
-}
+StreamFile::StreamFile(const char *path, uint32_t options, uint32_t permissions)
+ : Stream(), m_file(path, options, permissions) {}
-StreamFile::~StreamFile()
-{
-}
+StreamFile::~StreamFile() {}
-void
-StreamFile::Flush ()
-{
- m_file.Flush();
-}
+void StreamFile::Flush() { m_file.Flush(); }
-size_t
-StreamFile::Write (const void *s, size_t length)
-{
- m_file.Write (s, length);
- return length;
+size_t StreamFile::Write(const void *s, size_t length) {
+ m_file.Write(s, length);
+ return length;
}
Modified: lldb/trunk/source/Core/StreamGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamGDBRemote.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/StreamGDBRemote.cpp (original)
+++ lldb/trunk/source/Core/StreamGDBRemote.cpp Tue Sep 6 15:57:50 2016
@@ -13,42 +13,30 @@
using namespace lldb;
using namespace lldb_private;
-StreamGDBRemote::StreamGDBRemote () :
-StreamString ()
-{
-}
-
-StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size, ByteOrder byte_order) :
-StreamString (flags, addr_size, byte_order)
-{
-}
+StreamGDBRemote::StreamGDBRemote() : StreamString() {}
-StreamGDBRemote::~StreamGDBRemote()
-{
+StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size,
+ ByteOrder byte_order)
+ : StreamString(flags, addr_size, byte_order) {}
+
+StreamGDBRemote::~StreamGDBRemote() {}
+
+int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) {
+ int bytes_written = 0;
+ const uint8_t *src = (const uint8_t *)s;
+ bool binary_is_set = m_flags.Test(eBinary);
+ m_flags.Clear(eBinary);
+ while (src_len) {
+ uint8_t byte = *src;
+ src++;
+ src_len--;
+ if (byte == 0x23 || byte == 0x24 || byte == 0x7d || byte == 0x2a) {
+ bytes_written += PutChar(0x7d);
+ byte ^= 0x20;
+ }
+ bytes_written += PutChar(byte);
+ };
+ if (binary_is_set)
+ m_flags.Set(eBinary);
+ return bytes_written;
}
-
-
-int
-StreamGDBRemote::PutEscapedBytes (const void* s,
- size_t src_len)
-{
- int bytes_written = 0;
- const uint8_t *src = (const uint8_t *)s;
- bool binary_is_set = m_flags.Test(eBinary);
- m_flags.Clear(eBinary);
- while (src_len)
- {
- uint8_t byte = *src;
- src++; src_len--;
- if (byte == 0x23 || byte == 0x24 || byte == 0x7d || byte == 0x2a)
- {
- bytes_written += PutChar(0x7d);
- byte ^= 0x20;
- }
- bytes_written += PutChar(byte);
- };
- if (binary_is_set)
- m_flags.Set(eBinary);
- return bytes_written;
-}
-
Modified: lldb/trunk/source/Core/StreamString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamString.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/StreamString.cpp (original)
+++ lldb/trunk/source/Core/StreamString.cpp Tue Sep 6 15:57:50 2016
@@ -13,104 +13,57 @@
using namespace lldb;
using namespace lldb_private;
-StreamString::StreamString () :
- Stream (0, 4, eByteOrderBig)
-{
-}
-
-StreamString::StreamString(uint32_t flags, uint32_t addr_size, ByteOrder byte_order) :
- Stream (flags, addr_size, byte_order),
- m_packet ()
-{
-}
-
-StreamString::~StreamString()
-{
-}
-
-void
-StreamString::Flush ()
-{
- // Nothing to do when flushing a buffer based stream...
-}
+StreamString::StreamString() : Stream(0, 4, eByteOrderBig) {}
-size_t
-StreamString::Write (const void *s, size_t length)
-{
- m_packet.append (reinterpret_cast<const char *>(s), length);
- return length;
-}
+StreamString::StreamString(uint32_t flags, uint32_t addr_size,
+ ByteOrder byte_order)
+ : Stream(flags, addr_size, byte_order), m_packet() {}
-void
-StreamString::Clear()
-{
- m_packet.clear();
-}
+StreamString::~StreamString() {}
-bool
-StreamString::Empty() const
-{
- return GetSize() == 0;
+void StreamString::Flush() {
+ // Nothing to do when flushing a buffer based stream...
}
-const char *
-StreamString::GetData () const
-{
- return m_packet.c_str();
+size_t StreamString::Write(const void *s, size_t length) {
+ m_packet.append(reinterpret_cast<const char *>(s), length);
+ return length;
}
-size_t
-StreamString::GetSize () const
-{
- return m_packet.size();
-}
+void StreamString::Clear() { m_packet.clear(); }
-size_t
-StreamString::GetSizeOfLastLine () const
-{
- const size_t length = m_packet.size();
- size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
- if (last_line_begin_pos == std::string::npos)
- {
- return length;
- }
- else
- {
- ++last_line_begin_pos;
- return length - last_line_begin_pos;
- }
-}
+bool StreamString::Empty() const { return GetSize() == 0; }
-std::string &
-StreamString::GetString()
-{
- return m_packet;
-}
+const char *StreamString::GetData() const { return m_packet.c_str(); }
-const std::string &
-StreamString::GetString() const
-{
- return m_packet;
-}
+size_t StreamString::GetSize() const { return m_packet.size(); }
-void
-StreamString::FillLastLineToColumn (uint32_t column, char fill_char)
-{
- const size_t length = m_packet.size();
- size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
- if (last_line_begin_pos == std::string::npos)
- {
- last_line_begin_pos = 0;
- }
- else
- {
- ++last_line_begin_pos;
- }
-
- const size_t line_columns = length - last_line_begin_pos;
- if (column > line_columns)
- {
- m_packet.append(column - line_columns, fill_char);
- }
+size_t StreamString::GetSizeOfLastLine() const {
+ const size_t length = m_packet.size();
+ size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
+ if (last_line_begin_pos == std::string::npos) {
+ return length;
+ } else {
+ ++last_line_begin_pos;
+ return length - last_line_begin_pos;
+ }
+}
+
+std::string &StreamString::GetString() { return m_packet; }
+
+const std::string &StreamString::GetString() const { return m_packet; }
+
+void StreamString::FillLastLineToColumn(uint32_t column, char fill_char) {
+ const size_t length = m_packet.size();
+ size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
+ if (last_line_begin_pos == std::string::npos) {
+ last_line_begin_pos = 0;
+ } else {
+ ++last_line_begin_pos;
+ }
+
+ const size_t line_columns = length - last_line_begin_pos;
+ if (column > line_columns) {
+ m_packet.append(column - line_columns, fill_char);
+ }
}
-
Modified: lldb/trunk/source/Core/StringList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StringList.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/StringList.cpp (original)
+++ lldb/trunk/source/Core/StringList.cpp Tue Sep 6 15:57:50 2016
@@ -9,369 +9,275 @@
#include "lldb/Core/StringList.h"
+#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Host/FileSpec.h"
-#include "lldb/Core/Log.h"
#include <string>
using namespace lldb_private;
-StringList::StringList () :
- m_strings ()
-{
-}
-
-StringList::StringList (const char *str) :
- m_strings ()
-{
- if (str)
- m_strings.push_back (str);
-}
-
-StringList::StringList (const char **strv, int strc) :
- m_strings ()
-{
- for (int i = 0; i < strc; ++i)
- {
- if (strv[i])
- m_strings.push_back (strv[i]);
- }
-}
+StringList::StringList() : m_strings() {}
-StringList::~StringList ()
-{
+StringList::StringList(const char *str) : m_strings() {
+ if (str)
+ m_strings.push_back(str);
}
-void
-StringList::AppendString (const char *str)
-{
- if (str)
- m_strings.push_back (str);
+StringList::StringList(const char **strv, int strc) : m_strings() {
+ for (int i = 0; i < strc; ++i) {
+ if (strv[i])
+ m_strings.push_back(strv[i]);
+ }
}
-void
-StringList::AppendString (const std::string &s)
-{
- m_strings.push_back (s);
+StringList::~StringList() {}
+
+void StringList::AppendString(const char *str) {
+ if (str)
+ m_strings.push_back(str);
}
-void
-StringList::AppendString (std::string &&s)
-{
- m_strings.push_back (s);
+void StringList::AppendString(const std::string &s) { m_strings.push_back(s); }
+
+void StringList::AppendString(std::string &&s) { m_strings.push_back(s); }
+
+void StringList::AppendString(const char *str, size_t str_len) {
+ if (str)
+ m_strings.push_back(std::string(str, str_len));
}
-void
-StringList::AppendString (const char *str, size_t str_len)
-{
- if (str)
- m_strings.push_back (std::string (str, str_len));
+void StringList::AppendString(llvm::StringRef str) {
+ m_strings.push_back(str.str());
}
-void
-StringList::AppendString(llvm::StringRef str)
-{
- m_strings.push_back(str.str());
+void StringList::AppendList(const char **strv, int strc) {
+ for (int i = 0; i < strc; ++i) {
+ if (strv[i])
+ m_strings.push_back(strv[i]);
+ }
}
-void
-StringList::AppendList (const char **strv, int strc)
-{
- for (int i = 0; i < strc; ++i)
- {
- if (strv[i])
- m_strings.push_back (strv[i]);
- }
+void StringList::AppendList(StringList strings) {
+ size_t len = strings.GetSize();
+
+ for (size_t i = 0; i < len; ++i)
+ m_strings.push_back(strings.GetStringAtIndex(i));
}
-void
-StringList::AppendList (StringList strings)
-{
- size_t len = strings.GetSize();
-
- for (size_t i = 0; i < len; ++i)
- m_strings.push_back (strings.GetStringAtIndex(i));
-}
-
-bool
-StringList::ReadFileLines (FileSpec &input_file)
-{
- return input_file.ReadFileLines (m_strings);
-}
-
-size_t
-StringList::GetSize () const
-{
- return m_strings.size();
-}
-
-size_t
-StringList::GetMaxStringLength () const
-{
- size_t max_length = 0;
- for (const auto &s : m_strings)
- {
- const size_t len = s.size();
- if (max_length < len)
- max_length = len;
- }
- return max_length;
+bool StringList::ReadFileLines(FileSpec &input_file) {
+ return input_file.ReadFileLines(m_strings);
}
+size_t StringList::GetSize() const { return m_strings.size(); }
-const char *
-StringList::GetStringAtIndex (size_t idx) const
-{
- if (idx < m_strings.size())
- return m_strings[idx].c_str();
- return NULL;
+size_t StringList::GetMaxStringLength() const {
+ size_t max_length = 0;
+ for (const auto &s : m_strings) {
+ const size_t len = s.size();
+ if (max_length < len)
+ max_length = len;
+ }
+ return max_length;
}
-void
-StringList::Join (const char *separator, Stream &strm)
-{
- size_t size = GetSize();
-
- if (size == 0)
- return;
-
- for (uint32_t i = 0; i < size; ++i)
- {
- if (i > 0)
- strm.PutCString(separator);
- strm.PutCString(GetStringAtIndex(i));
- }
+const char *StringList::GetStringAtIndex(size_t idx) const {
+ if (idx < m_strings.size())
+ return m_strings[idx].c_str();
+ return NULL;
}
-void
-StringList::Clear ()
-{
- m_strings.clear();
+void StringList::Join(const char *separator, Stream &strm) {
+ size_t size = GetSize();
+
+ if (size == 0)
+ return;
+
+ for (uint32_t i = 0; i < size; ++i) {
+ if (i > 0)
+ strm.PutCString(separator);
+ strm.PutCString(GetStringAtIndex(i));
+ }
}
-void
-StringList::LongestCommonPrefix (std::string &common_prefix)
-{
- const size_t num_strings = m_strings.size();
+void StringList::Clear() { m_strings.clear(); }
- if (num_strings == 0)
- {
- common_prefix.clear();
- }
- else
- {
- common_prefix = m_strings.front();
+void StringList::LongestCommonPrefix(std::string &common_prefix) {
+ const size_t num_strings = m_strings.size();
+
+ if (num_strings == 0) {
+ common_prefix.clear();
+ } else {
+ common_prefix = m_strings.front();
+
+ for (size_t idx = 1; idx < num_strings; ++idx) {
+ std::string &curr_string = m_strings[idx];
+ size_t new_size = curr_string.size();
- for (size_t idx = 1; idx < num_strings; ++idx)
- {
- std::string &curr_string = m_strings[idx];
- size_t new_size = curr_string.size();
-
- // First trim common_prefix if it is longer than the current element:
- if (common_prefix.size() > new_size)
- common_prefix.erase (new_size);
-
- // Then trim it at the first disparity:
- for (size_t i = 0; i < common_prefix.size(); i++)
- {
- if (curr_string[i] != common_prefix[i])
- {
- common_prefix.erase(i);
- break;
- }
- }
-
- // If we've emptied the common prefix, we're done.
- if (common_prefix.empty())
- break;
+ // First trim common_prefix if it is longer than the current element:
+ if (common_prefix.size() > new_size)
+ common_prefix.erase(new_size);
+
+ // Then trim it at the first disparity:
+ for (size_t i = 0; i < common_prefix.size(); i++) {
+ if (curr_string[i] != common_prefix[i]) {
+ common_prefix.erase(i);
+ break;
}
- }
-}
+ }
-void
-StringList::InsertStringAtIndex (size_t idx, const char *str)
-{
- if (str)
- {
- if (idx < m_strings.size())
- m_strings.insert (m_strings.begin() + idx, str);
- else
- m_strings.push_back (str);
+ // If we've emptied the common prefix, we're done.
+ if (common_prefix.empty())
+ break;
}
+ }
}
-void
-StringList::InsertStringAtIndex (size_t idx, const std::string &str)
-{
+void StringList::InsertStringAtIndex(size_t idx, const char *str) {
+ if (str) {
if (idx < m_strings.size())
- m_strings.insert (m_strings.begin() + idx, str);
+ m_strings.insert(m_strings.begin() + idx, str);
else
- m_strings.push_back (str);
+ m_strings.push_back(str);
+ }
}
-void
-StringList::InsertStringAtIndex (size_t idx, std::string &&str)
-{
- if (idx < m_strings.size())
- m_strings.insert (m_strings.begin() + idx, str);
+void StringList::InsertStringAtIndex(size_t idx, const std::string &str) {
+ if (idx < m_strings.size())
+ m_strings.insert(m_strings.begin() + idx, str);
+ else
+ m_strings.push_back(str);
+}
+
+void StringList::InsertStringAtIndex(size_t idx, std::string &&str) {
+ if (idx < m_strings.size())
+ m_strings.insert(m_strings.begin() + idx, str);
+ else
+ m_strings.push_back(str);
+}
+
+void StringList::DeleteStringAtIndex(size_t idx) {
+ if (idx < m_strings.size())
+ m_strings.erase(m_strings.begin() + idx);
+}
+
+size_t StringList::SplitIntoLines(const std::string &lines) {
+ return SplitIntoLines(lines.c_str(), lines.size());
+}
+
+size_t StringList::SplitIntoLines(const char *lines, size_t len) {
+ const size_t orig_size = m_strings.size();
+
+ if (len == 0)
+ return 0;
+
+ const char *k_newline_chars = "\r\n";
+ const char *p = lines;
+ const char *end = lines + len;
+ while (p < end) {
+ size_t count = strcspn(p, k_newline_chars);
+ if (count == 0) {
+ if (p[count] == '\r' || p[count] == '\n')
+ m_strings.push_back(std::string());
+ else
+ break;
+ } else {
+ if (p + count > end)
+ count = end - p;
+ m_strings.push_back(std::string(p, count));
+ }
+ if (p[count] == '\r' && p[count + 1] == '\n')
+ count++; // Skip an extra newline char for the DOS newline
+ count++; // Skip the newline character
+ p += count;
+ }
+ return m_strings.size() - orig_size;
+}
+
+void StringList::RemoveBlankLines() {
+ if (GetSize() == 0)
+ return;
+
+ size_t idx = 0;
+ while (idx < m_strings.size()) {
+ if (m_strings[idx].empty())
+ DeleteStringAtIndex(idx);
else
- m_strings.push_back (str);
+ idx++;
+ }
}
-void
-StringList::DeleteStringAtIndex (size_t idx)
-{
- if (idx < m_strings.size())
- m_strings.erase (m_strings.begin() + idx);
+std::string StringList::CopyList(const char *item_preamble,
+ const char *items_sep) const {
+ StreamString strm;
+ for (size_t i = 0; i < GetSize(); i++) {
+ if (i && items_sep && items_sep[0])
+ strm << items_sep;
+ if (item_preamble)
+ strm << item_preamble;
+ strm << GetStringAtIndex(i);
+ }
+ return std::string(strm.GetData());
}
-size_t
-StringList::SplitIntoLines (const std::string &lines)
-{
- return SplitIntoLines (lines.c_str(), lines.size());
-}
-
-size_t
-StringList::SplitIntoLines (const char *lines, size_t len)
-{
- const size_t orig_size = m_strings.size();
-
- if (len == 0)
- return 0;
-
- const char *k_newline_chars = "\r\n";
- const char *p = lines;
- const char *end = lines + len;
- while (p < end)
- {
- size_t count = strcspn (p, k_newline_chars);
- if (count == 0)
- {
- if (p[count] == '\r' || p[count] == '\n')
- m_strings.push_back(std::string());
- else
- break;
- }
- else
- {
- if (p + count > end)
- count = end - p;
- m_strings.push_back(std::string(p, count));
- }
- if (p[count] == '\r' && p[count+1] == '\n')
- count++; // Skip an extra newline char for the DOS newline
- count++; // Skip the newline character
- p += count;
- }
- return m_strings.size() - orig_size;
+StringList &StringList::operator<<(const char *str) {
+ AppendString(str);
+ return *this;
}
-void
-StringList::RemoveBlankLines ()
-{
- if (GetSize() == 0)
- return;
-
- size_t idx = 0;
- while (idx < m_strings.size())
- {
- if (m_strings[idx].empty())
- DeleteStringAtIndex(idx);
- else
- idx++;
- }
+StringList &StringList::operator<<(const std::string &str) {
+ AppendString(str);
+ return *this;
}
-std::string
-StringList::CopyList(const char* item_preamble, const char* items_sep) const
-{
- StreamString strm;
- for (size_t i = 0; i < GetSize(); i++)
- {
- if (i && items_sep && items_sep[0])
- strm << items_sep;
- if (item_preamble)
- strm << item_preamble;
- strm << GetStringAtIndex(i);
- }
- return std::string(strm.GetData());
+StringList &StringList::operator<<(StringList strings) {
+ AppendList(strings);
+ return *this;
}
-StringList&
-StringList::operator << (const char* str)
-{
- AppendString(str);
- return *this;
-}
-
-StringList&
-StringList::operator << (const std::string& str)
-{
- AppendString(str);
- return *this;
-}
-
-StringList&
-StringList::operator << (StringList strings)
-{
- AppendList(strings);
- return *this;
-}
-
-StringList&
-StringList::operator = (const std::vector<std::string> &rhs)
-{
- Clear();
- for (const auto &s : rhs)
- m_strings.push_back(s);
-
- return *this;
-}
-
-size_t
-StringList::AutoComplete (const char *s, StringList &matches, size_t &exact_idx) const
-{
- matches.Clear();
- exact_idx = SIZE_MAX;
- if (s && s[0])
- {
- const size_t s_len = strlen (s);
- const size_t num_strings = m_strings.size();
-
- for (size_t i=0; i<num_strings; ++i)
- {
- if (m_strings[i].find(s) == 0)
- {
- if (exact_idx == SIZE_MAX && m_strings[i].size() == s_len)
- exact_idx = matches.GetSize();
- matches.AppendString (m_strings[i]);
- }
- }
- }
- else
- {
- // No string, so it matches everything
- matches = *this;
- }
- return matches.GetSize();
+StringList &StringList::operator=(const std::vector<std::string> &rhs) {
+ Clear();
+ for (const auto &s : rhs)
+ m_strings.push_back(s);
+
+ return *this;
}
-void
-StringList::LogDump(Log *log, const char *name)
-{
- if (!log)
- return;
-
- StreamString strm;
- if (name)
- strm.Printf("Begin %s:\n", name);
- for (const auto &s : m_strings) {
- strm.Indent();
- strm.Printf("%s\n", s.c_str());
- }
- if (name)
- strm.Printf("End %s.\n", name);
+size_t StringList::AutoComplete(const char *s, StringList &matches,
+ size_t &exact_idx) const {
+ matches.Clear();
+ exact_idx = SIZE_MAX;
+ if (s && s[0]) {
+ const size_t s_len = strlen(s);
+ const size_t num_strings = m_strings.size();
+
+ for (size_t i = 0; i < num_strings; ++i) {
+ if (m_strings[i].find(s) == 0) {
+ if (exact_idx == SIZE_MAX && m_strings[i].size() == s_len)
+ exact_idx = matches.GetSize();
+ matches.AppendString(m_strings[i]);
+ }
+ }
+ } else {
+ // No string, so it matches everything
+ matches = *this;
+ }
+ return matches.GetSize();
+}
+
+void StringList::LogDump(Log *log, const char *name) {
+ if (!log)
+ return;
+
+ StreamString strm;
+ if (name)
+ strm.Printf("Begin %s:\n", name);
+ for (const auto &s : m_strings) {
+ strm.Indent();
+ strm.Printf("%s\n", s.c_str());
+ }
+ if (name)
+ strm.Printf("End %s.\n", name);
- log->Debug("%s", strm.GetData());
+ log->Debug("%s", strm.GetData());
}
Modified: lldb/trunk/source/Core/StructuredData.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StructuredData.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/StructuredData.cpp (original)
+++ lldb/trunk/source/Core/StructuredData.cpp Tue Sep 6 15:57:50 2016
@@ -1,4 +1,5 @@
-//===---------------------StructuredData.cpp ---------------------*- C++ -*-===//
+//===---------------------StructuredData.cpp ---------------------*- C++
+//-*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,8 +11,8 @@
#include "lldb/Core/StructuredData.h"
#include <errno.h>
-#include <stdlib.h>
#include <inttypes.h>
+#include <stdlib.h>
#include "lldb/Core/StreamString.h"
#include "lldb/Host/StringConvert.h"
@@ -19,313 +20,247 @@
using namespace lldb_private;
-
//----------------------------------------------------------------------
// Functions that use a JSONParser to parse JSON into StructuredData
//----------------------------------------------------------------------
-static StructuredData::ObjectSP ParseJSONValue (JSONParser &json_parser);
-static StructuredData::ObjectSP ParseJSONObject (JSONParser &json_parser);
-static StructuredData::ObjectSP ParseJSONArray (JSONParser &json_parser);
-
-static StructuredData::ObjectSP
-ParseJSONObject (JSONParser &json_parser)
-{
- // The "JSONParser::Token::ObjectStart" token should have already been consumed
- // by the time this function is called
- std::unique_ptr<StructuredData::Dictionary> dict_up(new StructuredData::Dictionary());
-
- std::string value;
- std::string key;
- while (1)
- {
- JSONParser::Token token = json_parser.GetToken(value);
-
- if (token == JSONParser::Token::String)
- {
- key.swap(value);
- token = json_parser.GetToken(value);
- if (token == JSONParser::Token::Colon)
- {
- StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser);
- if (value_sp)
- dict_up->AddItem(key, value_sp);
- else
- break;
- }
- }
- else if (token == JSONParser::Token::ObjectEnd)
- {
- return StructuredData::ObjectSP(dict_up.release());
- }
- else if (token == JSONParser::Token::Comma)
- {
- continue;
- }
- else
- {
- break;
- }
- }
- return StructuredData::ObjectSP();
-}
-
-static StructuredData::ObjectSP
-ParseJSONArray (JSONParser &json_parser)
-{
- // The "JSONParser::Token::ObjectStart" token should have already been consumed
- // by the time this function is called
- std::unique_ptr<StructuredData::Array> array_up(new StructuredData::Array());
-
- std::string value;
- std::string key;
- while (1)
- {
+static StructuredData::ObjectSP ParseJSONValue(JSONParser &json_parser);
+static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser);
+static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser);
+
+static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser) {
+ // The "JSONParser::Token::ObjectStart" token should have already been
+ // consumed
+ // by the time this function is called
+ std::unique_ptr<StructuredData::Dictionary> dict_up(
+ new StructuredData::Dictionary());
+
+ std::string value;
+ std::string key;
+ while (1) {
+ JSONParser::Token token = json_parser.GetToken(value);
+
+ if (token == JSONParser::Token::String) {
+ key.swap(value);
+ token = json_parser.GetToken(value);
+ if (token == JSONParser::Token::Colon) {
StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser);
if (value_sp)
- array_up->AddItem(value_sp);
- else
- break;
-
- JSONParser::Token token = json_parser.GetToken(value);
- if (token == JSONParser::Token::Comma)
- {
- continue;
- }
- else if (token == JSONParser::Token::ArrayEnd)
- {
- return StructuredData::ObjectSP(array_up.release());
- }
+ dict_up->AddItem(key, value_sp);
else
- {
- break;
- }
- }
- return StructuredData::ObjectSP();
-}
-
-static StructuredData::ObjectSP
-ParseJSONValue (JSONParser &json_parser)
-{
- std::string value;
- const JSONParser::Token token = json_parser.GetToken(value);
- switch (token)
- {
- case JSONParser::Token::ObjectStart:
- return ParseJSONObject(json_parser);
-
- case JSONParser::Token::ArrayStart:
- return ParseJSONArray(json_parser);
-
- case JSONParser::Token::Integer:
- {
- bool success = false;
- uint64_t uval = StringConvert::ToUInt64(value.c_str(), 0, 0, &success);
- if (success)
- return StructuredData::ObjectSP(new StructuredData::Integer(uval));
- }
- break;
-
- case JSONParser::Token::Float:
- {
- bool success = false;
- double val = StringConvert::ToDouble(value.c_str(), 0.0, &success);
- if (success)
- return StructuredData::ObjectSP(new StructuredData::Float(val));
- }
- break;
-
- case JSONParser::Token::String:
- return StructuredData::ObjectSP(new StructuredData::String(value));
-
- case JSONParser::Token::True:
- case JSONParser::Token::False:
- return StructuredData::ObjectSP(new StructuredData::Boolean(token == JSONParser::Token::True));
-
- case JSONParser::Token::Null:
- return StructuredData::ObjectSP(new StructuredData::Null());
-
- default:
- break;
- }
- return StructuredData::ObjectSP();
+ break;
+ }
+ } else if (token == JSONParser::Token::ObjectEnd) {
+ return StructuredData::ObjectSP(dict_up.release());
+ } else if (token == JSONParser::Token::Comma) {
+ continue;
+ } else {
+ break;
+ }
+ }
+ return StructuredData::ObjectSP();
+}
+
+static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser) {
+ // The "JSONParser::Token::ObjectStart" token should have already been
+ // consumed
+ // by the time this function is called
+ std::unique_ptr<StructuredData::Array> array_up(new StructuredData::Array());
+
+ std::string value;
+ std::string key;
+ while (1) {
+ StructuredData::ObjectSP value_sp = ParseJSONValue(json_parser);
+ if (value_sp)
+ array_up->AddItem(value_sp);
+ else
+ break;
+ JSONParser::Token token = json_parser.GetToken(value);
+ if (token == JSONParser::Token::Comma) {
+ continue;
+ } else if (token == JSONParser::Token::ArrayEnd) {
+ return StructuredData::ObjectSP(array_up.release());
+ } else {
+ break;
+ }
+ }
+ return StructuredData::ObjectSP();
+}
+
+static StructuredData::ObjectSP ParseJSONValue(JSONParser &json_parser) {
+ std::string value;
+ const JSONParser::Token token = json_parser.GetToken(value);
+ switch (token) {
+ case JSONParser::Token::ObjectStart:
+ return ParseJSONObject(json_parser);
+
+ case JSONParser::Token::ArrayStart:
+ return ParseJSONArray(json_parser);
+
+ case JSONParser::Token::Integer: {
+ bool success = false;
+ uint64_t uval = StringConvert::ToUInt64(value.c_str(), 0, 0, &success);
+ if (success)
+ return StructuredData::ObjectSP(new StructuredData::Integer(uval));
+ } break;
+
+ case JSONParser::Token::Float: {
+ bool success = false;
+ double val = StringConvert::ToDouble(value.c_str(), 0.0, &success);
+ if (success)
+ return StructuredData::ObjectSP(new StructuredData::Float(val));
+ } break;
+
+ case JSONParser::Token::String:
+ return StructuredData::ObjectSP(new StructuredData::String(value));
+
+ case JSONParser::Token::True:
+ case JSONParser::Token::False:
+ return StructuredData::ObjectSP(
+ new StructuredData::Boolean(token == JSONParser::Token::True));
+
+ case JSONParser::Token::Null:
+ return StructuredData::ObjectSP(new StructuredData::Null());
+
+ default:
+ break;
+ }
+ return StructuredData::ObjectSP();
+}
+
+StructuredData::ObjectSP StructuredData::ParseJSON(std::string json_text) {
+ JSONParser json_parser(json_text.c_str());
+ StructuredData::ObjectSP object_sp = ParseJSONValue(json_parser);
+ return object_sp;
}
StructuredData::ObjectSP
-StructuredData::ParseJSON (std::string json_text)
-{
- JSONParser json_parser(json_text.c_str());
- StructuredData::ObjectSP object_sp = ParseJSONValue(json_parser);
- return object_sp;
-}
-
-StructuredData::ObjectSP
-StructuredData::Object::GetObjectForDotSeparatedPath (llvm::StringRef path)
-{
- if (this->GetType() == Type::eTypeDictionary)
- {
- std::pair<llvm::StringRef, llvm::StringRef> match = path.split('.');
- std::string key = match.first.str();
- ObjectSP value = this->GetAsDictionary()->GetValueForKey (key.c_str());
- if (value.get())
- {
- // Do we have additional words to descend? If not, return the
- // value we're at right now.
- if (match.second.empty())
- {
- return value;
- }
- else
- {
- return value->GetObjectForDotSeparatedPath (match.second);
- }
- }
- return ObjectSP();
- }
-
- if (this->GetType() == Type::eTypeArray)
- {
- std::pair<llvm::StringRef, llvm::StringRef> match = path.split('[');
- if (match.second.size() == 0)
- {
- return this->shared_from_this();
- }
- errno = 0;
- uint64_t val = strtoul (match.second.str().c_str(), NULL, 10);
- if (errno == 0)
- {
- return this->GetAsArray()->GetItemAtIndex(val);
- }
- return ObjectSP();
- }
-
- return this->shared_from_this();
-}
-
-void
-StructuredData::Object::DumpToStdout(bool pretty_print) const
-{
- StreamString stream;
- Dump(stream, pretty_print);
- printf("%s\n", stream.GetString().c_str());
-}
-
-void
-StructuredData::Array::Dump(Stream &s, bool pretty_print) const
-{
- bool first = true;
- s << "[";
- if (pretty_print)
- {
+StructuredData::Object::GetObjectForDotSeparatedPath(llvm::StringRef path) {
+ if (this->GetType() == Type::eTypeDictionary) {
+ std::pair<llvm::StringRef, llvm::StringRef> match = path.split('.');
+ std::string key = match.first.str();
+ ObjectSP value = this->GetAsDictionary()->GetValueForKey(key.c_str());
+ if (value.get()) {
+ // Do we have additional words to descend? If not, return the
+ // value we're at right now.
+ if (match.second.empty()) {
+ return value;
+ } else {
+ return value->GetObjectForDotSeparatedPath(match.second);
+ }
+ }
+ return ObjectSP();
+ }
+
+ if (this->GetType() == Type::eTypeArray) {
+ std::pair<llvm::StringRef, llvm::StringRef> match = path.split('[');
+ if (match.second.size() == 0) {
+ return this->shared_from_this();
+ }
+ errno = 0;
+ uint64_t val = strtoul(match.second.str().c_str(), NULL, 10);
+ if (errno == 0) {
+ return this->GetAsArray()->GetItemAtIndex(val);
+ }
+ return ObjectSP();
+ }
+
+ return this->shared_from_this();
+}
+
+void StructuredData::Object::DumpToStdout(bool pretty_print) const {
+ StreamString stream;
+ Dump(stream, pretty_print);
+ printf("%s\n", stream.GetString().c_str());
+}
+
+void StructuredData::Array::Dump(Stream &s, bool pretty_print) const {
+ bool first = true;
+ s << "[";
+ if (pretty_print) {
+ s << "\n";
+ s.IndentMore();
+ }
+ for (const auto &item_sp : m_items) {
+ if (first) {
+ first = false;
+ } else {
+ s << ",";
+ if (pretty_print)
s << "\n";
- s.IndentMore();
- }
- for (const auto &item_sp : m_items)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- s << ",";
- if (pretty_print)
- s << "\n";
- }
-
- if (pretty_print)
- s.Indent();
- item_sp->Dump(s, pretty_print);
- }
- if (pretty_print)
- {
- s.IndentLess();
- s.EOL();
- s.Indent();
}
- s << "]";
-}
-
-void
-StructuredData::Integer::Dump (Stream &s, bool pretty_print) const
-{
- s.Printf ("%" PRIu64, m_value);
-}
-
-void
-StructuredData::Float::Dump (Stream &s, bool pretty_print) const
-{
- s.Printf ("%lg", m_value);
-}
-
-void
-StructuredData::Boolean::Dump (Stream &s, bool pretty_print) const
-{
- if (m_value == true)
- s.PutCString ("true");
- else
- s.PutCString ("false");
-}
-
-
-void
-StructuredData::String::Dump (Stream &s, bool pretty_print) const
-{
- std::string quoted;
- const size_t strsize = m_value.size();
- for (size_t i = 0; i < strsize ; ++i)
- {
- char ch = m_value[i];
- if (ch == '"')
- quoted.push_back ('\\');
- quoted.push_back (ch);
- }
- s.Printf ("\"%s\"", quoted.c_str());
-}
-
-void
-StructuredData::Dictionary::Dump (Stream &s, bool pretty_print) const
-{
- bool first = true;
- s << "{";
if (pretty_print)
- {
+ s.Indent();
+ item_sp->Dump(s, pretty_print);
+ }
+ if (pretty_print) {
+ s.IndentLess();
+ s.EOL();
+ s.Indent();
+ }
+ s << "]";
+}
+
+void StructuredData::Integer::Dump(Stream &s, bool pretty_print) const {
+ s.Printf("%" PRIu64, m_value);
+}
+
+void StructuredData::Float::Dump(Stream &s, bool pretty_print) const {
+ s.Printf("%lg", m_value);
+}
+
+void StructuredData::Boolean::Dump(Stream &s, bool pretty_print) const {
+ if (m_value == true)
+ s.PutCString("true");
+ else
+ s.PutCString("false");
+}
+
+void StructuredData::String::Dump(Stream &s, bool pretty_print) const {
+ std::string quoted;
+ const size_t strsize = m_value.size();
+ for (size_t i = 0; i < strsize; ++i) {
+ char ch = m_value[i];
+ if (ch == '"')
+ quoted.push_back('\\');
+ quoted.push_back(ch);
+ }
+ s.Printf("\"%s\"", quoted.c_str());
+}
+
+void StructuredData::Dictionary::Dump(Stream &s, bool pretty_print) const {
+ bool first = true;
+ s << "{";
+ if (pretty_print) {
+ s << "\n";
+ s.IndentMore();
+ }
+ for (const auto &pair : m_dict) {
+ if (first)
+ first = false;
+ else {
+ s << ",";
+ if (pretty_print)
s << "\n";
- s.IndentMore();
- }
- for (const auto &pair : m_dict)
- {
- if (first)
- first = false;
- else
- {
- s << ",";
- if (pretty_print)
- s << "\n";
- }
- if (pretty_print)
- s.Indent();
- s << "\"" << pair.first.AsCString() << "\" : ";
- pair.second->Dump(s, pretty_print);
}
if (pretty_print)
- {
- s.IndentLess();
- s.EOL();
- s.Indent();
- }
- s << "}";
+ s.Indent();
+ s << "\"" << pair.first.AsCString() << "\" : ";
+ pair.second->Dump(s, pretty_print);
+ }
+ if (pretty_print) {
+ s.IndentLess();
+ s.EOL();
+ s.Indent();
+ }
+ s << "}";
}
-void
-StructuredData::Null::Dump (Stream &s, bool pretty_print) const
-{
- s << "null";
+void StructuredData::Null::Dump(Stream &s, bool pretty_print) const {
+ s << "null";
}
-void
-StructuredData::Generic::Dump(Stream &s, bool pretty_print) const
-{
- s << "0x" << m_object;
+void StructuredData::Generic::Dump(Stream &s, bool pretty_print) const {
+ s << "0x" << m_object;
}
Modified: lldb/trunk/source/Core/Timer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Timer.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/Timer.cpp (original)
+++ lldb/trunk/source/Core/Timer.cpp Tue Sep 6 15:57:50 2016
@@ -22,245 +22,198 @@ using namespace lldb_private;
#define TIMER_INDENT_AMOUNT 2
-namespace
-{
- typedef std::map<const char*, uint64_t> TimerCategoryMap;
-
- struct TimerStack
- {
- TimerStack() :
- m_depth(0)
- {}
-
- uint32_t m_depth;
- std::vector<Timer*> m_stack;
- };
+namespace {
+typedef std::map<const char *, uint64_t> TimerCategoryMap;
+
+struct TimerStack {
+ TimerStack() : m_depth(0) {}
+
+ uint32_t m_depth;
+ std::vector<Timer *> m_stack;
+};
} // end of anonymous namespace
std::atomic<bool> Timer::g_quiet(true);
std::atomic<unsigned> Timer::g_display_depth(0);
-static std::mutex &
-GetFileMutex()
-{
- static std::mutex *g_file_mutex_ptr = nullptr;
- static std::once_flag g_once_flag;
- std::call_once(g_once_flag, []() {
- // leaked on purpose to ensure this mutex works after main thread has run
- // global C++ destructor chain
- g_file_mutex_ptr = new std::mutex();
- });
- return *g_file_mutex_ptr;
-}
-
-static std::mutex &
-GetCategoryMutex()
-{
- static std::mutex g_category_mutex;
- return g_category_mutex;
-}
-
-static TimerCategoryMap &
-GetCategoryMap()
-{
- static TimerCategoryMap g_category_map;
- return g_category_map;
-}
-
-static void
-ThreadSpecificCleanup(void *p)
-{
- delete static_cast<TimerStack *>(p);
-}
-
-static TimerStack *
-GetTimerStackForCurrentThread ()
-{
- static lldb::thread_key_t g_key = Host::ThreadLocalStorageCreate(ThreadSpecificCleanup);
-
- void *timer_stack = Host::ThreadLocalStorageGet(g_key);
- if (timer_stack == NULL)
- {
- Host::ThreadLocalStorageSet(g_key, new TimerStack);
- timer_stack = Host::ThreadLocalStorageGet(g_key);
- }
- return (TimerStack *)timer_stack;
+static std::mutex &GetFileMutex() {
+ static std::mutex *g_file_mutex_ptr = nullptr;
+ static std::once_flag g_once_flag;
+ std::call_once(g_once_flag, []() {
+ // leaked on purpose to ensure this mutex works after main thread has run
+ // global C++ destructor chain
+ g_file_mutex_ptr = new std::mutex();
+ });
+ return *g_file_mutex_ptr;
}
-void
-Timer::SetQuiet (bool value)
-{
- g_quiet = value;
-}
-
-Timer::Timer (const char *category, const char *format, ...) :
- m_category (category),
- m_total_start (),
- m_timer_start (),
- m_total_ticks (0),
- m_timer_ticks (0)
-{
- TimerStack *stack = GetTimerStackForCurrentThread ();
- if (!stack)
- return;
-
- if (stack->m_depth++ < g_display_depth)
- {
- if (g_quiet == false)
- {
- std::lock_guard<std::mutex> lock(GetFileMutex());
-
- // Indent
- ::fprintf(stdout, "%*s", stack->m_depth * TIMER_INDENT_AMOUNT, "");
- // Print formatted string
- va_list args;
- va_start (args, format);
- ::vfprintf(stdout, format, args);
- va_end (args);
-
- // Newline
- ::fprintf(stdout, "\n");
- }
- TimeValue start_time(TimeValue::Now());
- m_total_start = start_time;
- m_timer_start = start_time;
-
- if (!stack->m_stack.empty())
- stack->m_stack.back()->ChildStarted (start_time);
- stack->m_stack.push_back(this);
- }
+static std::mutex &GetCategoryMutex() {
+ static std::mutex g_category_mutex;
+ return g_category_mutex;
}
-Timer::~Timer()
-{
- TimerStack *stack = GetTimerStackForCurrentThread ();
- if (!stack)
- return;
-
- if (m_total_start.IsValid())
- {
- TimeValue stop_time = TimeValue::Now();
- if (m_total_start.IsValid())
- {
- m_total_ticks += (stop_time - m_total_start);
- m_total_start.Clear();
- }
- if (m_timer_start.IsValid())
- {
- m_timer_ticks += (stop_time - m_timer_start);
- m_timer_start.Clear();
- }
-
- assert (stack->m_stack.back() == this);
- stack->m_stack.pop_back();
- if (stack->m_stack.empty() == false)
- stack->m_stack.back()->ChildStopped(stop_time);
-
- const uint64_t total_nsec_uint = GetTotalElapsedNanoSeconds();
- const uint64_t timer_nsec_uint = GetTimerElapsedNanoSeconds();
- const double total_nsec = total_nsec_uint;
- const double timer_nsec = timer_nsec_uint;
-
- if (g_quiet == false)
- {
- std::lock_guard<std::mutex> lock(GetFileMutex());
- ::fprintf(stdout, "%*s%.9f sec (%.9f sec)\n", (stack->m_depth - 1) * TIMER_INDENT_AMOUNT, "",
- total_nsec / 1000000000.0, timer_nsec / 1000000000.0);
- }
-
- // Keep total results for each category so we can dump results.
- std::lock_guard<std::mutex> guard(GetCategoryMutex());
- TimerCategoryMap &category_map = GetCategoryMap();
- category_map[m_category] += timer_nsec_uint;
- }
- if (stack->m_depth > 0)
- --stack->m_depth;
+static TimerCategoryMap &GetCategoryMap() {
+ static TimerCategoryMap g_category_map;
+ return g_category_map;
}
-uint64_t
-Timer::GetTotalElapsedNanoSeconds()
-{
- uint64_t total_ticks = m_total_ticks;
+static void ThreadSpecificCleanup(void *p) {
+ delete static_cast<TimerStack *>(p);
+}
- // If we are currently running, we need to add the current
- // elapsed time of the running timer...
- if (m_total_start.IsValid())
- total_ticks += (TimeValue::Now() - m_total_start);
+static TimerStack *GetTimerStackForCurrentThread() {
+ static lldb::thread_key_t g_key =
+ Host::ThreadLocalStorageCreate(ThreadSpecificCleanup);
- return total_ticks;
+ void *timer_stack = Host::ThreadLocalStorageGet(g_key);
+ if (timer_stack == NULL) {
+ Host::ThreadLocalStorageSet(g_key, new TimerStack);
+ timer_stack = Host::ThreadLocalStorageGet(g_key);
+ }
+ return (TimerStack *)timer_stack;
}
-uint64_t
-Timer::GetTimerElapsedNanoSeconds()
-{
- uint64_t timer_ticks = m_timer_ticks;
+void Timer::SetQuiet(bool value) { g_quiet = value; }
- // If we are currently running, we need to add the current
- // elapsed time of the running timer...
- if (m_timer_start.IsValid())
- timer_ticks += (TimeValue::Now() - m_timer_start);
+Timer::Timer(const char *category, const char *format, ...)
+ : m_category(category), m_total_start(), m_timer_start(), m_total_ticks(0),
+ m_timer_ticks(0) {
+ TimerStack *stack = GetTimerStackForCurrentThread();
+ if (!stack)
+ return;
- return timer_ticks;
-}
+ if (stack->m_depth++ < g_display_depth) {
+ if (g_quiet == false) {
+ std::lock_guard<std::mutex> lock(GetFileMutex());
+
+ // Indent
+ ::fprintf(stdout, "%*s", stack->m_depth * TIMER_INDENT_AMOUNT, "");
+ // Print formatted string
+ va_list args;
+ va_start(args, format);
+ ::vfprintf(stdout, format, args);
+ va_end(args);
-void
-Timer::ChildStarted (const TimeValue& start_time)
-{
- if (m_timer_start.IsValid())
- {
- m_timer_ticks += (start_time - m_timer_start);
- m_timer_start.Clear();
+ // Newline
+ ::fprintf(stdout, "\n");
}
+ TimeValue start_time(TimeValue::Now());
+ m_total_start = start_time;
+ m_timer_start = start_time;
+
+ if (!stack->m_stack.empty())
+ stack->m_stack.back()->ChildStarted(start_time);
+ stack->m_stack.push_back(this);
+ }
}
-void
-Timer::ChildStopped (const TimeValue& stop_time)
-{
- if (!m_timer_start.IsValid())
- m_timer_start = stop_time;
+Timer::~Timer() {
+ TimerStack *stack = GetTimerStackForCurrentThread();
+ if (!stack)
+ return;
+
+ if (m_total_start.IsValid()) {
+ TimeValue stop_time = TimeValue::Now();
+ if (m_total_start.IsValid()) {
+ m_total_ticks += (stop_time - m_total_start);
+ m_total_start.Clear();
+ }
+ if (m_timer_start.IsValid()) {
+ m_timer_ticks += (stop_time - m_timer_start);
+ m_timer_start.Clear();
+ }
+
+ assert(stack->m_stack.back() == this);
+ stack->m_stack.pop_back();
+ if (stack->m_stack.empty() == false)
+ stack->m_stack.back()->ChildStopped(stop_time);
+
+ const uint64_t total_nsec_uint = GetTotalElapsedNanoSeconds();
+ const uint64_t timer_nsec_uint = GetTimerElapsedNanoSeconds();
+ const double total_nsec = total_nsec_uint;
+ const double timer_nsec = timer_nsec_uint;
+
+ if (g_quiet == false) {
+ std::lock_guard<std::mutex> lock(GetFileMutex());
+ ::fprintf(stdout, "%*s%.9f sec (%.9f sec)\n",
+ (stack->m_depth - 1) * TIMER_INDENT_AMOUNT, "",
+ total_nsec / 1000000000.0, timer_nsec / 1000000000.0);
+ }
+
+ // Keep total results for each category so we can dump results.
+ std::lock_guard<std::mutex> guard(GetCategoryMutex());
+ TimerCategoryMap &category_map = GetCategoryMap();
+ category_map[m_category] += timer_nsec_uint;
+ }
+ if (stack->m_depth > 0)
+ --stack->m_depth;
}
-void
-Timer::SetDisplayDepth (uint32_t depth)
-{
- g_display_depth = depth;
+uint64_t Timer::GetTotalElapsedNanoSeconds() {
+ uint64_t total_ticks = m_total_ticks;
+
+ // If we are currently running, we need to add the current
+ // elapsed time of the running timer...
+ if (m_total_start.IsValid())
+ total_ticks += (TimeValue::Now() - m_total_start);
+
+ return total_ticks;
}
+uint64_t Timer::GetTimerElapsedNanoSeconds() {
+ uint64_t timer_ticks = m_timer_ticks;
-/* binary function predicate:
- * - returns whether a person is less than another person
- */
-static bool
-CategoryMapIteratorSortCriterion (const TimerCategoryMap::const_iterator& lhs, const TimerCategoryMap::const_iterator& rhs)
-{
- return lhs->second > rhs->second;
+ // If we are currently running, we need to add the current
+ // elapsed time of the running timer...
+ if (m_timer_start.IsValid())
+ timer_ticks += (TimeValue::Now() - m_timer_start);
+
+ return timer_ticks;
}
+void Timer::ChildStarted(const TimeValue &start_time) {
+ if (m_timer_start.IsValid()) {
+ m_timer_ticks += (start_time - m_timer_start);
+ m_timer_start.Clear();
+ }
+}
-void
-Timer::ResetCategoryTimes ()
-{
- std::lock_guard<std::mutex> guard(GetCategoryMutex());
- TimerCategoryMap &category_map = GetCategoryMap();
- category_map.clear();
+void Timer::ChildStopped(const TimeValue &stop_time) {
+ if (!m_timer_start.IsValid())
+ m_timer_start = stop_time;
}
-void
-Timer::DumpCategoryTimes (Stream *s)
-{
- std::lock_guard<std::mutex> guard(GetCategoryMutex());
- TimerCategoryMap &category_map = GetCategoryMap();
- std::vector<TimerCategoryMap::const_iterator> sorted_iterators;
- TimerCategoryMap::const_iterator pos, end = category_map.end();
- for (pos = category_map.begin(); pos != end; ++pos)
- {
- sorted_iterators.push_back (pos);
- }
- std::sort (sorted_iterators.begin(), sorted_iterators.end(), CategoryMapIteratorSortCriterion);
+void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; }
- const size_t count = sorted_iterators.size();
- for (size_t i=0; i<count; ++i)
- {
- const double timer_nsec = sorted_iterators[i]->second;
- s->Printf("%.9f sec for %s\n", timer_nsec / 1000000000.0, sorted_iterators[i]->first);
- }
+/* binary function predicate:
+ * - returns whether a person is less than another person
+ */
+static bool
+CategoryMapIteratorSortCriterion(const TimerCategoryMap::const_iterator &lhs,
+ const TimerCategoryMap::const_iterator &rhs) {
+ return lhs->second > rhs->second;
+}
+
+void Timer::ResetCategoryTimes() {
+ std::lock_guard<std::mutex> guard(GetCategoryMutex());
+ TimerCategoryMap &category_map = GetCategoryMap();
+ category_map.clear();
+}
+
+void Timer::DumpCategoryTimes(Stream *s) {
+ std::lock_guard<std::mutex> guard(GetCategoryMutex());
+ TimerCategoryMap &category_map = GetCategoryMap();
+ std::vector<TimerCategoryMap::const_iterator> sorted_iterators;
+ TimerCategoryMap::const_iterator pos, end = category_map.end();
+ for (pos = category_map.begin(); pos != end; ++pos) {
+ sorted_iterators.push_back(pos);
+ }
+ std::sort(sorted_iterators.begin(), sorted_iterators.end(),
+ CategoryMapIteratorSortCriterion);
+
+ const size_t count = sorted_iterators.size();
+ for (size_t i = 0; i < count; ++i) {
+ const double timer_nsec = sorted_iterators[i]->second;
+ s->Printf("%.9f sec for %s\n", timer_nsec / 1000000000.0,
+ sorted_iterators[i]->first);
+ }
}
Modified: lldb/trunk/source/Core/UUID.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/UUID.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/UUID.cpp (original)
+++ lldb/trunk/source/Core/UUID.cpp Tue Sep 6 15:57:50 2016
@@ -9,9 +9,9 @@
#include "lldb/Core/UUID.h"
// C Includes
-#include <string.h>
-#include <stdio.h>
#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
// C++ Includes
#include <string>
@@ -22,261 +22,202 @@
namespace lldb_private {
-UUID::UUID() : m_num_uuid_bytes(16)
-{
- ::memset (m_uuid, 0, sizeof(m_uuid));
-}
+UUID::UUID() : m_num_uuid_bytes(16) { ::memset(m_uuid, 0, sizeof(m_uuid)); }
-UUID::UUID(const UUID& rhs)
-{
- m_num_uuid_bytes = rhs.m_num_uuid_bytes;
- ::memcpy (m_uuid, rhs.m_uuid, sizeof (m_uuid));
+UUID::UUID(const UUID &rhs) {
+ m_num_uuid_bytes = rhs.m_num_uuid_bytes;
+ ::memcpy(m_uuid, rhs.m_uuid, sizeof(m_uuid));
}
-UUID::UUID (const void *uuid_bytes, uint32_t num_uuid_bytes)
-{
- SetBytes (uuid_bytes, num_uuid_bytes);
+UUID::UUID(const void *uuid_bytes, uint32_t num_uuid_bytes) {
+ SetBytes(uuid_bytes, num_uuid_bytes);
}
-const UUID&
-UUID::operator=(const UUID& rhs)
-{
- if (this != &rhs)
- {
- m_num_uuid_bytes = rhs.m_num_uuid_bytes;
- ::memcpy (m_uuid, rhs.m_uuid, sizeof (m_uuid));
- }
- return *this;
+const UUID &UUID::operator=(const UUID &rhs) {
+ if (this != &rhs) {
+ m_num_uuid_bytes = rhs.m_num_uuid_bytes;
+ ::memcpy(m_uuid, rhs.m_uuid, sizeof(m_uuid));
+ }
+ return *this;
+}
+
+UUID::~UUID() {}
+
+void UUID::Clear() {
+ m_num_uuid_bytes = 16;
+ ::memset(m_uuid, 0, sizeof(m_uuid));
+}
+
+const void *UUID::GetBytes() const { return m_uuid; }
+
+std::string UUID::GetAsString(const char *separator) const {
+ std::string result;
+ char buf[256];
+ if (!separator)
+ separator = "-";
+ const uint8_t *u = (const uint8_t *)GetBytes();
+ if (sizeof(buf) >
+ (size_t)snprintf(buf, sizeof(buf), "%2.2X%2.2X%2.2X%2.2X%s%2.2X%2.2X%s%2."
+ "2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%2.2X%"
+ "2.2X%2.2X%2.2X",
+ u[0], u[1], u[2], u[3], separator, u[4], u[5], separator,
+ u[6], u[7], separator, u[8], u[9], separator, u[10],
+ u[11], u[12], u[13], u[14], u[15])) {
+ result.append(buf);
+ if (m_num_uuid_bytes == 20) {
+ if (sizeof(buf) > (size_t)snprintf(buf, sizeof(buf),
+ "%s%2.2X%2.2X%2.2X%2.2X", separator,
+ u[16], u[17], u[18], u[19]))
+ result.append(buf);
+ }
+ }
+ return result;
+}
+
+void UUID::Dump(Stream *s) const {
+ const uint8_t *u = (const uint8_t *)GetBytes();
+ s->Printf("%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%"
+ "2.2X%2.2X%2.2X%2.2X",
+ u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7], u[8], u[9], u[10],
+ u[11], u[12], u[13], u[14], u[15]);
+ if (m_num_uuid_bytes == 20) {
+ s->Printf("-%2.2X%2.2X%2.2X%2.2X", u[16], u[17], u[18], u[19]);
+ }
+}
+
+bool UUID::SetBytes(const void *uuid_bytes, uint32_t num_uuid_bytes) {
+ if (uuid_bytes) {
+ switch (num_uuid_bytes) {
+ case 20:
+ m_num_uuid_bytes = 20;
+ break;
+ case 16:
+ m_num_uuid_bytes = 16;
+ m_uuid[16] = m_uuid[17] = m_uuid[18] = m_uuid[19] = 0;
+ break;
+ default:
+ // Unsupported UUID byte size
+ m_num_uuid_bytes = 0;
+ break;
+ }
+
+ if (m_num_uuid_bytes > 0) {
+ ::memcpy(m_uuid, uuid_bytes, m_num_uuid_bytes);
+ return true;
+ }
+ }
+ ::memset(m_uuid, 0, sizeof(m_uuid));
+ return false;
+}
+
+size_t UUID::GetByteSize() { return m_num_uuid_bytes; }
+
+bool UUID::IsValid() const {
+ return m_uuid[0] || m_uuid[1] || m_uuid[2] || m_uuid[3] || m_uuid[4] ||
+ m_uuid[5] || m_uuid[6] || m_uuid[7] || m_uuid[8] || m_uuid[9] ||
+ m_uuid[10] || m_uuid[11] || m_uuid[12] || m_uuid[13] || m_uuid[14] ||
+ m_uuid[15] || m_uuid[16] || m_uuid[17] || m_uuid[18] || m_uuid[19];
+}
+
+static inline int xdigit_to_int(char ch) {
+ ch = tolower(ch);
+ if (ch >= 'a' && ch <= 'f')
+ return 10 + ch - 'a';
+ return ch - '0';
+}
+
+size_t UUID::DecodeUUIDBytesFromCString(const char *p, ValueType &uuid_bytes,
+ const char **end,
+ uint32_t num_uuid_bytes) {
+ size_t uuid_byte_idx = 0;
+ if (p) {
+ while (*p) {
+ if (isxdigit(p[0]) && isxdigit(p[1])) {
+ int hi_nibble = xdigit_to_int(p[0]);
+ int lo_nibble = xdigit_to_int(p[1]);
+ // Translate the two hex nibble characters into a byte
+ uuid_bytes[uuid_byte_idx] = (hi_nibble << 4) + lo_nibble;
+
+ // Skip both hex digits
+ p += 2;
+
+ // Increment the byte that we are decoding within the UUID value
+ // and break out if we are done
+ if (++uuid_byte_idx == num_uuid_bytes)
+ break;
+ } else if (*p == '-') {
+ // Skip dashes
+ p++;
+ } else {
+ // UUID values can only consist of hex characters and '-' chars
+ break;
+ }
+ }
+ }
+ if (end)
+ *end = p;
+ // Clear trailing bytes to 0.
+ for (uint32_t i = uuid_byte_idx; i < sizeof(ValueType); i++)
+ uuid_bytes[i] = 0;
+ return uuid_byte_idx;
}
+size_t UUID::SetFromCString(const char *cstr, uint32_t num_uuid_bytes) {
+ if (cstr == NULL)
+ return 0;
-UUID::~UUID()
-{
-}
+ const char *p = cstr;
-void
-UUID::Clear()
-{
- m_num_uuid_bytes = 16;
- ::memset (m_uuid, 0, sizeof(m_uuid));
-}
-
-const void *
-UUID::GetBytes() const
-{
- return m_uuid;
-}
-
-std::string
-UUID::GetAsString (const char *separator) const
-{
- std::string result;
- char buf[256];
- if (!separator)
- separator = "-";
- const uint8_t *u = (const uint8_t *)GetBytes();
- if (sizeof (buf) > (size_t)snprintf (buf,
- sizeof (buf),
- "%2.2X%2.2X%2.2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X",
- u[0],u[1],u[2],u[3],separator,
- u[4],u[5],separator,
- u[6],u[7],separator,
- u[8],u[9],separator,
- u[10],u[11],u[12],u[13],u[14],u[15]))
- {
- result.append (buf);
- if (m_num_uuid_bytes == 20)
- {
- if (sizeof (buf) > (size_t)snprintf (buf, sizeof (buf), "%s%2.2X%2.2X%2.2X%2.2X", separator,u[16],u[17],u[18],u[19]))
- result.append (buf);
- }
- }
- return result;
-}
+ // Skip leading whitespace characters
+ while (isspace(*p))
+ ++p;
-void
-UUID::Dump (Stream *s) const
-{
- const uint8_t *u = (const uint8_t *)GetBytes();
- s->Printf ("%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X",
- u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8],u[9],u[10],u[11],u[12],u[13],u[14],u[15]);
- if (m_num_uuid_bytes == 20)
- {
- s->Printf ("-%2.2X%2.2X%2.2X%2.2X", u[16],u[17],u[18],u[19]);
- }
-}
-
-bool
-UUID::SetBytes (const void *uuid_bytes, uint32_t num_uuid_bytes)
-{
- if (uuid_bytes)
- {
- switch (num_uuid_bytes)
- {
- case 20:
- m_num_uuid_bytes = 20;
- break;
- case 16:
- m_num_uuid_bytes = 16;
- m_uuid[16] = m_uuid[17] = m_uuid[18] = m_uuid[19] = 0;
- break;
- default:
- // Unsupported UUID byte size
- m_num_uuid_bytes = 0;
- break;
- }
-
- if (m_num_uuid_bytes > 0)
- {
- ::memcpy (m_uuid, uuid_bytes, m_num_uuid_bytes);
- return true;
- }
- }
- ::memset (m_uuid, 0, sizeof(m_uuid));
- return false;
-}
+ const size_t uuid_byte_idx =
+ UUID::DecodeUUIDBytesFromCString(p, m_uuid, &p, num_uuid_bytes);
-size_t
-UUID::GetByteSize()
-{
- return m_num_uuid_bytes;
-}
-
-bool
-UUID::IsValid () const
-{
- return m_uuid[0] ||
- m_uuid[1] ||
- m_uuid[2] ||
- m_uuid[3] ||
- m_uuid[4] ||
- m_uuid[5] ||
- m_uuid[6] ||
- m_uuid[7] ||
- m_uuid[8] ||
- m_uuid[9] ||
- m_uuid[10] ||
- m_uuid[11] ||
- m_uuid[12] ||
- m_uuid[13] ||
- m_uuid[14] ||
- m_uuid[15] ||
- m_uuid[16] ||
- m_uuid[17] ||
- m_uuid[18] ||
- m_uuid[19];
-}
-
-static inline int
-xdigit_to_int (char ch)
-{
- ch = tolower(ch);
- if (ch >= 'a' && ch <= 'f')
- return 10 + ch - 'a';
- return ch - '0';
-}
-
-size_t
-UUID::DecodeUUIDBytesFromCString (const char *p, ValueType &uuid_bytes, const char **end, uint32_t num_uuid_bytes)
-{
- size_t uuid_byte_idx = 0;
- if (p)
- {
- while (*p)
- {
- if (isxdigit(p[0]) && isxdigit(p[1]))
- {
- int hi_nibble = xdigit_to_int(p[0]);
- int lo_nibble = xdigit_to_int(p[1]);
- // Translate the two hex nibble characters into a byte
- uuid_bytes[uuid_byte_idx] = (hi_nibble << 4) + lo_nibble;
-
- // Skip both hex digits
- p += 2;
-
- // Increment the byte that we are decoding within the UUID value
- // and break out if we are done
- if (++uuid_byte_idx == num_uuid_bytes)
- break;
- }
- else if (*p == '-')
- {
- // Skip dashes
- p++;
- }
- else
- {
- // UUID values can only consist of hex characters and '-' chars
- break;
- }
- }
- }
- if (end)
- *end = p;
- // Clear trailing bytes to 0.
- for (uint32_t i = uuid_byte_idx; i < sizeof(ValueType); i++)
- uuid_bytes[i] = 0;
- return uuid_byte_idx;
-}
-size_t
-UUID::SetFromCString (const char *cstr, uint32_t num_uuid_bytes)
-{
- if (cstr == NULL)
- return 0;
-
- const char *p = cstr;
-
- // Skip leading whitespace characters
- while (isspace(*p))
- ++p;
-
- const size_t uuid_byte_idx = UUID::DecodeUUIDBytesFromCString (p, m_uuid, &p, num_uuid_bytes);
-
- // If we successfully decoded a UUID, return the amount of characters that
- // were consumed
- if (uuid_byte_idx == num_uuid_bytes)
- {
- m_num_uuid_bytes = num_uuid_bytes;
- return p - cstr;
- }
+ // If we successfully decoded a UUID, return the amount of characters that
+ // were consumed
+ if (uuid_byte_idx == num_uuid_bytes) {
+ m_num_uuid_bytes = num_uuid_bytes;
+ return p - cstr;
+ }
- // Else return zero to indicate we were not able to parse a UUID value
- return 0;
+ // Else return zero to indicate we were not able to parse a UUID value
+ return 0;
}
-
}
-bool
-lldb_private::operator == (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
-{
- return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) == 0;
+bool lldb_private::operator==(const lldb_private::UUID &lhs,
+ const lldb_private::UUID &rhs) {
+ return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
+ sizeof(lldb_private::UUID::ValueType)) == 0;
}
-bool
-lldb_private::operator != (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
-{
- return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) != 0;
+bool lldb_private::operator!=(const lldb_private::UUID &lhs,
+ const lldb_private::UUID &rhs) {
+ return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
+ sizeof(lldb_private::UUID::ValueType)) != 0;
}
-bool
-lldb_private::operator < (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
-{
- return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) < 0;
+bool lldb_private::operator<(const lldb_private::UUID &lhs,
+ const lldb_private::UUID &rhs) {
+ return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
+ sizeof(lldb_private::UUID::ValueType)) < 0;
}
-bool
-lldb_private::operator <= (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
-{
- return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) <= 0;
+bool lldb_private::operator<=(const lldb_private::UUID &lhs,
+ const lldb_private::UUID &rhs) {
+ return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
+ sizeof(lldb_private::UUID::ValueType)) <= 0;
}
-bool
-lldb_private::operator > (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
-{
- return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) > 0;
+bool lldb_private::operator>(const lldb_private::UUID &lhs,
+ const lldb_private::UUID &rhs) {
+ return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
+ sizeof(lldb_private::UUID::ValueType)) > 0;
}
-bool
-lldb_private::operator >= (const lldb_private::UUID &lhs, const lldb_private::UUID &rhs)
-{
- return ::memcmp (lhs.GetBytes(), rhs.GetBytes(), sizeof (lldb_private::UUID::ValueType)) >= 0;
+bool lldb_private::operator>=(const lldb_private::UUID &lhs,
+ const lldb_private::UUID &rhs) {
+ return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
+ sizeof(lldb_private::UUID::ValueType)) >= 0;
}
Modified: lldb/trunk/source/Core/UserID.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/UserID.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/UserID.cpp (original)
+++ lldb/trunk/source/Core/UserID.cpp Tue Sep 6 15:57:50 2016
@@ -15,9 +15,7 @@
using namespace lldb;
using namespace lldb_private;
-Stream&
-lldb_private::operator << (Stream& strm, const UserID& uid)
-{
- strm.Printf("{0x%8.8" PRIx64 "}", uid.GetID());
- return strm;
+Stream &lldb_private::operator<<(Stream &strm, const UserID &uid) {
+ strm.Printf("{0x%8.8" PRIx64 "}", uid.GetID());
+ return strm;
}
Modified: lldb/trunk/source/Core/UserSettingsController.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/UserSettingsController.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/UserSettingsController.cpp (original)
+++ lldb/trunk/source/Core/UserSettingsController.cpp Tue Sep 6 15:57:50 2016
@@ -1,4 +1,5 @@
-//====-- UserSettingsController.cpp ------------------------------*- C++ -*-===//
+//====-- UserSettingsController.cpp ------------------------------*- C++
+//-*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,14 +8,14 @@
//
//===----------------------------------------------------------------------===//
-#include <string.h>
#include <algorithm>
+#include <string.h>
-#include "lldb/Core/UserSettingsController.h"
#include "lldb/Core/Error.h"
#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamString.h"
+#include "lldb/Core/UserSettingsController.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Interpreter/OptionValueString.h"
@@ -22,113 +23,86 @@
using namespace lldb;
using namespace lldb_private;
-
lldb::OptionValueSP
-Properties::GetPropertyValue (const ExecutionContext *exe_ctx,
- const char *path,
- bool will_modify,
- Error &error) const
-{
- OptionValuePropertiesSP properties_sp (GetValueProperties ());
- if (properties_sp)
- return properties_sp->GetSubValue(exe_ctx, path, will_modify, error);
- return lldb::OptionValueSP();
-}
-
-Error
-Properties::SetPropertyValue (const ExecutionContext *exe_ctx,
- VarSetOperationType op,
- const char *path,
- const char *value)
-{
- OptionValuePropertiesSP properties_sp (GetValueProperties ());
- if (properties_sp)
- return properties_sp->SetSubValue(exe_ctx, op, path, value);
- Error error;
- error.SetErrorString ("no properties");
- return error;
-}
-
-void
-Properties::DumpAllPropertyValues (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
-{
- OptionValuePropertiesSP properties_sp (GetValueProperties ());
- if (properties_sp)
- return properties_sp->DumpValue (exe_ctx, strm, dump_mask);
-}
-
-void
-Properties::DumpAllDescriptions (CommandInterpreter &interpreter,
- Stream &strm) const
-{
- strm.PutCString("Top level variables:\n\n");
-
- OptionValuePropertiesSP properties_sp (GetValueProperties ());
- if (properties_sp)
- return properties_sp->DumpAllDescriptions (interpreter, strm);
-}
-
-
-
-Error
-Properties::DumpPropertyValue (const ExecutionContext *exe_ctx, Stream &strm, const char *property_path, uint32_t dump_mask)
-{
- OptionValuePropertiesSP properties_sp (GetValueProperties ());
- if (properties_sp)
- {
- return properties_sp->DumpPropertyValue (exe_ctx,
- strm,
- property_path,
- dump_mask);
- }
- Error error;
- error.SetErrorString("empty property list");
- return error;
+Properties::GetPropertyValue(const ExecutionContext *exe_ctx, const char *path,
+ bool will_modify, Error &error) const {
+ OptionValuePropertiesSP properties_sp(GetValueProperties());
+ if (properties_sp)
+ return properties_sp->GetSubValue(exe_ctx, path, will_modify, error);
+ return lldb::OptionValueSP();
+}
+
+Error Properties::SetPropertyValue(const ExecutionContext *exe_ctx,
+ VarSetOperationType op, const char *path,
+ const char *value) {
+ OptionValuePropertiesSP properties_sp(GetValueProperties());
+ if (properties_sp)
+ return properties_sp->SetSubValue(exe_ctx, op, path, value);
+ Error error;
+ error.SetErrorString("no properties");
+ return error;
+}
+
+void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx,
+ Stream &strm, uint32_t dump_mask) {
+ OptionValuePropertiesSP properties_sp(GetValueProperties());
+ if (properties_sp)
+ return properties_sp->DumpValue(exe_ctx, strm, dump_mask);
+}
+
+void Properties::DumpAllDescriptions(CommandInterpreter &interpreter,
+ Stream &strm) const {
+ strm.PutCString("Top level variables:\n\n");
+
+ OptionValuePropertiesSP properties_sp(GetValueProperties());
+ if (properties_sp)
+ return properties_sp->DumpAllDescriptions(interpreter, strm);
+}
+
+Error Properties::DumpPropertyValue(const ExecutionContext *exe_ctx,
+ Stream &strm, const char *property_path,
+ uint32_t dump_mask) {
+ OptionValuePropertiesSP properties_sp(GetValueProperties());
+ if (properties_sp) {
+ return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path,
+ dump_mask);
+ }
+ Error error;
+ error.SetErrorString("empty property list");
+ return error;
}
size_t
-Properties::Apropos (const char *keyword, std::vector<const Property *> &matching_properties) const
-{
- OptionValuePropertiesSP properties_sp (GetValueProperties ());
- if (properties_sp)
- {
- properties_sp->Apropos (keyword, matching_properties);
- }
- return matching_properties.size();
+Properties::Apropos(const char *keyword,
+ std::vector<const Property *> &matching_properties) const {
+ OptionValuePropertiesSP properties_sp(GetValueProperties());
+ if (properties_sp) {
+ properties_sp->Apropos(keyword, matching_properties);
+ }
+ return matching_properties.size();
}
-
lldb::OptionValuePropertiesSP
-Properties::GetSubProperty (const ExecutionContext *exe_ctx,
- const ConstString &name)
-{
- OptionValuePropertiesSP properties_sp (GetValueProperties ());
- if (properties_sp)
- return properties_sp->GetSubProperty (exe_ctx, name);
- return lldb::OptionValuePropertiesSP();
-}
-
-const char *
-Properties::GetExperimentalSettingsName()
-{
- return "experimental";
-}
-
-bool
-Properties::IsSettingExperimental(const char *setting)
-{
- if (setting == nullptr)
- return false;
-
- const char *experimental = GetExperimentalSettingsName();
- const char *dot_pos = strchr(setting, '.');
- if (dot_pos == nullptr)
- return strcmp(experimental, setting) == 0;
- else
- {
- size_t first_elem_len = dot_pos - setting;
- return strncmp(experimental, setting, first_elem_len) == 0;
- }
-
+Properties::GetSubProperty(const ExecutionContext *exe_ctx,
+ const ConstString &name) {
+ OptionValuePropertiesSP properties_sp(GetValueProperties());
+ if (properties_sp)
+ return properties_sp->GetSubProperty(exe_ctx, name);
+ return lldb::OptionValuePropertiesSP();
+}
+
+const char *Properties::GetExperimentalSettingsName() { return "experimental"; }
+
+bool Properties::IsSettingExperimental(const char *setting) {
+ if (setting == nullptr)
+ return false;
+
+ const char *experimental = GetExperimentalSettingsName();
+ const char *dot_pos = strchr(setting, '.');
+ if (dot_pos == nullptr)
+ return strcmp(experimental, setting) == 0;
+ else {
+ size_t first_elem_len = dot_pos - setting;
+ return strncmp(experimental, setting, first_elem_len) == 0;
+ }
}
-
Modified: lldb/trunk/source/Core/VMRange.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/VMRange.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/VMRange.cpp (original)
+++ lldb/trunk/source/Core/VMRange.cpp Tue Sep 6 15:57:50 2016
@@ -16,97 +16,82 @@
using namespace lldb;
using namespace lldb_private;
-bool
-VMRange::ContainsValue(const VMRange::collection& coll, lldb::addr_t value)
-{
- ValueInRangeUnaryPredicate in_range_predicate(value);
- VMRange::const_iterator pos;
- VMRange::const_iterator end = coll.end();
- pos = std::find_if( coll.begin(), end, in_range_predicate );
- if (pos != end)
- return true;
+bool VMRange::ContainsValue(const VMRange::collection &coll,
+ lldb::addr_t value) {
+ ValueInRangeUnaryPredicate in_range_predicate(value);
+ VMRange::const_iterator pos;
+ VMRange::const_iterator end = coll.end();
+ pos = std::find_if(coll.begin(), end, in_range_predicate);
+ if (pos != end)
+ return true;
+ return false;
+}
+
+bool VMRange::ContainsRange(const VMRange::collection &coll,
+ const VMRange &range) {
+ RangeInRangeUnaryPredicate in_range_predicate(range);
+ VMRange::const_iterator pos;
+ VMRange::const_iterator end = coll.end();
+ pos = std::find_if(coll.begin(), end, in_range_predicate);
+ if (pos != end)
+ return true;
+ return false;
+}
+
+size_t VMRange::FindRangeIndexThatContainsValue(const VMRange::collection &coll,
+ lldb::addr_t value) {
+ ValueInRangeUnaryPredicate in_range_predicate(value);
+ VMRange::const_iterator begin = coll.begin();
+ VMRange::const_iterator end = coll.end();
+ VMRange::const_iterator pos = std::find_if(begin, end, in_range_predicate);
+ if (pos != end)
+ return std::distance(begin, pos);
+ return UINT32_MAX;
+}
+
+void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const {
+ s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(),
+ addr_width);
+}
+
+bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
+ return lhs.GetBaseAddress() == rhs.GetBaseAddress() &&
+ lhs.GetEndAddress() == rhs.GetEndAddress();
+}
+
+bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) {
+ return lhs.GetBaseAddress() != rhs.GetBaseAddress() ||
+ lhs.GetEndAddress() != rhs.GetEndAddress();
+}
+
+bool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) {
+ if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
+ return true;
+ else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
return false;
+ return lhs.GetEndAddress() < rhs.GetEndAddress();
}
-bool
-VMRange::ContainsRange(const VMRange::collection& coll, const VMRange& range)
-{
- RangeInRangeUnaryPredicate in_range_predicate(range);
- VMRange::const_iterator pos;
- VMRange::const_iterator end = coll.end();
- pos = std::find_if( coll.begin(), end, in_range_predicate );
- if (pos != end)
- return true;
+bool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) {
+ if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
+ return true;
+ else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
return false;
+ return lhs.GetEndAddress() <= rhs.GetEndAddress();
}
-size_t
-VMRange::FindRangeIndexThatContainsValue (const VMRange::collection& coll, lldb::addr_t value)
-{
- ValueInRangeUnaryPredicate in_range_predicate(value);
- VMRange::const_iterator begin = coll.begin();
- VMRange::const_iterator end = coll.end();
- VMRange::const_iterator pos = std::find_if (begin, end, in_range_predicate);
- if (pos != end)
- return std::distance (begin, pos);
- return UINT32_MAX;
-}
-
-void
-VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const
-{
- s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(), addr_width);
-}
-
-bool
-lldb_private::operator== (const VMRange& lhs, const VMRange& rhs)
-{
- return lhs.GetBaseAddress() == rhs.GetBaseAddress() && lhs.GetEndAddress() == rhs.GetEndAddress();
-}
-
-bool
-lldb_private::operator!= (const VMRange& lhs, const VMRange& rhs)
-{
- return lhs.GetBaseAddress() != rhs.GetBaseAddress() || lhs.GetEndAddress() != rhs.GetEndAddress();
-}
-
-bool
-lldb_private::operator< (const VMRange& lhs, const VMRange& rhs)
-{
- if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
- return true;
- else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
- return false;
- return lhs.GetEndAddress() < rhs.GetEndAddress();
-}
-
-bool
-lldb_private::operator<= (const VMRange& lhs, const VMRange& rhs)
-{
- if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
- return true;
- else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
- return false;
- return lhs.GetEndAddress() <= rhs.GetEndAddress();
-}
-
-bool
-lldb_private::operator> (const VMRange& lhs, const VMRange& rhs)
-{
- if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
- return true;
- else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
- return false;
- return lhs.GetEndAddress() > rhs.GetEndAddress();
-}
-
-bool
-lldb_private::operator>= (const VMRange& lhs, const VMRange& rhs)
-{
- if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
- return true;
- else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
- return false;
- return lhs.GetEndAddress() >= rhs.GetEndAddress();
+bool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) {
+ if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
+ return true;
+ else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
+ return false;
+ return lhs.GetEndAddress() > rhs.GetEndAddress();
}
+bool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) {
+ if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
+ return true;
+ else if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
+ return false;
+ return lhs.GetEndAddress() >= rhs.GetEndAddress();
+}
Modified: lldb/trunk/source/Core/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Value.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Core/Value.cpp (original)
+++ lldb/trunk/source/Core/Value.cpp Tue Sep 6 15:57:50 2016
@@ -13,13 +13,13 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/DataBufferHeap.h"
+#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/State.h"
#include "lldb/Core/Stream.h"
-#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/Type.h"
@@ -32,828 +32,675 @@
using namespace lldb;
using namespace lldb_private;
-Value::Value() :
- m_value (),
- m_vector (),
- m_compiler_type (),
- m_context (NULL),
- m_value_type (eValueTypeScalar),
- m_context_type (eContextTypeInvalid),
- m_data_buffer ()
-{
-}
-
-Value::Value(const Scalar& scalar) :
- m_value (scalar),
- m_vector (),
- m_compiler_type (),
- m_context (NULL),
- m_value_type (eValueTypeScalar),
- m_context_type (eContextTypeInvalid),
- m_data_buffer ()
-{
-}
-
-
-Value::Value(const void *bytes, int len) :
- m_value (),
- m_vector (),
- m_compiler_type (),
- m_context (NULL),
- m_value_type (eValueTypeHostAddress),
- m_context_type (eContextTypeInvalid),
- m_data_buffer ()
-{
- SetBytes(bytes, len);
-}
-
-Value::Value(const Value &v) :
- m_value (v.m_value),
- m_vector (v.m_vector),
- m_compiler_type (v.m_compiler_type),
- m_context (v.m_context),
- m_value_type (v.m_value_type),
- m_context_type (v.m_context_type),
- m_data_buffer ()
-{
- const uintptr_t rhs_value = (uintptr_t)v.m_value.ULongLong(LLDB_INVALID_ADDRESS);
- if ((rhs_value != 0) && (rhs_value == (uintptr_t)v.m_data_buffer.GetBytes()))
- {
- m_data_buffer.CopyData(v.m_data_buffer.GetBytes(),
- v.m_data_buffer.GetByteSize());
-
- m_value = (uintptr_t)m_data_buffer.GetBytes();
- }
-}
-
-Value &
-Value::operator=(const Value &rhs)
-{
- if (this != &rhs)
- {
- m_value = rhs.m_value;
- m_vector = rhs.m_vector;
- m_compiler_type = rhs.m_compiler_type;
- m_context = rhs.m_context;
- m_value_type = rhs.m_value_type;
- m_context_type = rhs.m_context_type;
- const uintptr_t rhs_value = (uintptr_t)rhs.m_value.ULongLong(LLDB_INVALID_ADDRESS);
- if ((rhs_value != 0) && (rhs_value == (uintptr_t)rhs.m_data_buffer.GetBytes()))
- {
- m_data_buffer.CopyData(rhs.m_data_buffer.GetBytes(),
- rhs.m_data_buffer.GetByteSize());
-
- m_value = (uintptr_t)m_data_buffer.GetBytes();
- }
- }
- return *this;
-}
-
-void
-Value::SetBytes (const void *bytes, int len)
-{
- m_value_type = eValueTypeHostAddress;
- m_data_buffer.CopyData(bytes, len);
- m_value = (uintptr_t)m_data_buffer.GetBytes();
-}
-
-void
-Value::AppendBytes (const void *bytes, int len)
-{
- m_value_type = eValueTypeHostAddress;
- m_data_buffer.AppendData (bytes, len);
- m_value = (uintptr_t)m_data_buffer.GetBytes();
-}
-
-void
-Value::Dump (Stream* strm)
-{
- m_value.GetValue (strm, true);
- strm->Printf(", value_type = %s, context = %p, context_type = %s",
- Value::GetValueTypeAsCString(m_value_type),
- m_context,
- Value::GetContextTypeAsCString(m_context_type));
-}
-
-Value::ValueType
-Value::GetValueType() const
-{
- return m_value_type;
-}
-
-AddressType
-Value::GetValueAddressType () const
-{
- switch (m_value_type)
- {
- default:
- case eValueTypeScalar:
- break;
- case eValueTypeLoadAddress: return eAddressTypeLoad;
- case eValueTypeFileAddress: return eAddressTypeFile;
- case eValueTypeHostAddress: return eAddressTypeHost;
- }
- return eAddressTypeInvalid;
-}
-
-RegisterInfo *
-Value::GetRegisterInfo() const
-{
- if (m_context_type == eContextTypeRegisterInfo)
- return static_cast<RegisterInfo *> (m_context);
- return NULL;
-}
-
-Type *
-Value::GetType()
-{
- if (m_context_type == eContextTypeLLDBType)
- return static_cast<Type *> (m_context);
- return NULL;
-}
-
-size_t
-Value::AppendDataToHostBuffer (const Value &rhs)
-{
- size_t curr_size = m_data_buffer.GetByteSize();
- Error error;
- switch (rhs.GetValueType())
- {
- case eValueTypeScalar:
- {
- const size_t scalar_size = rhs.m_value.GetByteSize();
- if (scalar_size > 0)
- {
- const size_t new_size = curr_size + scalar_size;
- if (ResizeData(new_size) == new_size)
- {
- rhs.m_value.GetAsMemoryData (m_data_buffer.GetBytes() + curr_size,
- scalar_size,
- endian::InlHostByteOrder(),
- error);
- return scalar_size;
- }
- }
- }
- break;
- case eValueTypeVector:
- {
- const size_t vector_size = rhs.m_vector.length;
- if (vector_size > 0)
- {
- const size_t new_size = curr_size + vector_size;
- if (ResizeData(new_size) == new_size)
- {
- ::memcpy (m_data_buffer.GetBytes() + curr_size,
- rhs.m_vector.bytes,
- vector_size);
- return vector_size;
- }
- }
- }
- break;
- case eValueTypeFileAddress:
- case eValueTypeLoadAddress:
- case eValueTypeHostAddress:
- {
- const uint8_t *src = rhs.GetBuffer().GetBytes();
- const size_t src_len = rhs.GetBuffer().GetByteSize();
- if (src && src_len > 0)
- {
- const size_t new_size = curr_size + src_len;
- if (ResizeData(new_size) == new_size)
- {
- ::memcpy (m_data_buffer.GetBytes() + curr_size, src, src_len);
- return src_len;
- }
- }
- }
- break;
- }
- return 0;
-}
+Value::Value()
+ : m_value(), m_vector(), m_compiler_type(), m_context(NULL),
+ m_value_type(eValueTypeScalar), m_context_type(eContextTypeInvalid),
+ m_data_buffer() {}
+
+Value::Value(const Scalar &scalar)
+ : m_value(scalar), m_vector(), m_compiler_type(), m_context(NULL),
+ m_value_type(eValueTypeScalar), m_context_type(eContextTypeInvalid),
+ m_data_buffer() {}
+
+Value::Value(const void *bytes, int len)
+ : m_value(), m_vector(), m_compiler_type(), m_context(NULL),
+ m_value_type(eValueTypeHostAddress), m_context_type(eContextTypeInvalid),
+ m_data_buffer() {
+ SetBytes(bytes, len);
+}
+
+Value::Value(const Value &v)
+ : m_value(v.m_value), m_vector(v.m_vector),
+ m_compiler_type(v.m_compiler_type), m_context(v.m_context),
+ m_value_type(v.m_value_type), m_context_type(v.m_context_type),
+ m_data_buffer() {
+ const uintptr_t rhs_value =
+ (uintptr_t)v.m_value.ULongLong(LLDB_INVALID_ADDRESS);
+ if ((rhs_value != 0) &&
+ (rhs_value == (uintptr_t)v.m_data_buffer.GetBytes())) {
+ m_data_buffer.CopyData(v.m_data_buffer.GetBytes(),
+ v.m_data_buffer.GetByteSize());
-size_t
-Value::ResizeData(size_t len)
-{
- m_value_type = eValueTypeHostAddress;
- m_data_buffer.SetByteSize(len);
m_value = (uintptr_t)m_data_buffer.GetBytes();
- return m_data_buffer.GetByteSize();
+ }
}
-bool
-Value::ValueOf(ExecutionContext *exe_ctx)
-{
- switch (m_context_type)
- {
+Value &Value::operator=(const Value &rhs) {
+ if (this != &rhs) {
+ m_value = rhs.m_value;
+ m_vector = rhs.m_vector;
+ m_compiler_type = rhs.m_compiler_type;
+ m_context = rhs.m_context;
+ m_value_type = rhs.m_value_type;
+ m_context_type = rhs.m_context_type;
+ const uintptr_t rhs_value =
+ (uintptr_t)rhs.m_value.ULongLong(LLDB_INVALID_ADDRESS);
+ if ((rhs_value != 0) &&
+ (rhs_value == (uintptr_t)rhs.m_data_buffer.GetBytes())) {
+ m_data_buffer.CopyData(rhs.m_data_buffer.GetBytes(),
+ rhs.m_data_buffer.GetByteSize());
+
+ m_value = (uintptr_t)m_data_buffer.GetBytes();
+ }
+ }
+ return *this;
+}
+
+void Value::SetBytes(const void *bytes, int len) {
+ m_value_type = eValueTypeHostAddress;
+ m_data_buffer.CopyData(bytes, len);
+ m_value = (uintptr_t)m_data_buffer.GetBytes();
+}
+
+void Value::AppendBytes(const void *bytes, int len) {
+ m_value_type = eValueTypeHostAddress;
+ m_data_buffer.AppendData(bytes, len);
+ m_value = (uintptr_t)m_data_buffer.GetBytes();
+}
+
+void Value::Dump(Stream *strm) {
+ m_value.GetValue(strm, true);
+ strm->Printf(", value_type = %s, context = %p, context_type = %s",
+ Value::GetValueTypeAsCString(m_value_type), m_context,
+ Value::GetContextTypeAsCString(m_context_type));
+}
+
+Value::ValueType Value::GetValueType() const { return m_value_type; }
+
+AddressType Value::GetValueAddressType() const {
+ switch (m_value_type) {
+ default:
+ case eValueTypeScalar:
+ break;
+ case eValueTypeLoadAddress:
+ return eAddressTypeLoad;
+ case eValueTypeFileAddress:
+ return eAddressTypeFile;
+ case eValueTypeHostAddress:
+ return eAddressTypeHost;
+ }
+ return eAddressTypeInvalid;
+}
+
+RegisterInfo *Value::GetRegisterInfo() const {
+ if (m_context_type == eContextTypeRegisterInfo)
+ return static_cast<RegisterInfo *>(m_context);
+ return NULL;
+}
+
+Type *Value::GetType() {
+ if (m_context_type == eContextTypeLLDBType)
+ return static_cast<Type *>(m_context);
+ return NULL;
+}
+
+size_t Value::AppendDataToHostBuffer(const Value &rhs) {
+ size_t curr_size = m_data_buffer.GetByteSize();
+ Error error;
+ switch (rhs.GetValueType()) {
+ case eValueTypeScalar: {
+ const size_t scalar_size = rhs.m_value.GetByteSize();
+ if (scalar_size > 0) {
+ const size_t new_size = curr_size + scalar_size;
+ if (ResizeData(new_size) == new_size) {
+ rhs.m_value.GetAsMemoryData(m_data_buffer.GetBytes() + curr_size,
+ scalar_size, endian::InlHostByteOrder(),
+ error);
+ return scalar_size;
+ }
+ }
+ } break;
+ case eValueTypeVector: {
+ const size_t vector_size = rhs.m_vector.length;
+ if (vector_size > 0) {
+ const size_t new_size = curr_size + vector_size;
+ if (ResizeData(new_size) == new_size) {
+ ::memcpy(m_data_buffer.GetBytes() + curr_size, rhs.m_vector.bytes,
+ vector_size);
+ return vector_size;
+ }
+ }
+ } break;
+ case eValueTypeFileAddress:
+ case eValueTypeLoadAddress:
+ case eValueTypeHostAddress: {
+ const uint8_t *src = rhs.GetBuffer().GetBytes();
+ const size_t src_len = rhs.GetBuffer().GetByteSize();
+ if (src && src_len > 0) {
+ const size_t new_size = curr_size + src_len;
+ if (ResizeData(new_size) == new_size) {
+ ::memcpy(m_data_buffer.GetBytes() + curr_size, src, src_len);
+ return src_len;
+ }
+ }
+ } break;
+ }
+ return 0;
+}
+
+size_t Value::ResizeData(size_t len) {
+ m_value_type = eValueTypeHostAddress;
+ m_data_buffer.SetByteSize(len);
+ m_value = (uintptr_t)m_data_buffer.GetBytes();
+ return m_data_buffer.GetByteSize();
+}
+
+bool Value::ValueOf(ExecutionContext *exe_ctx) {
+ switch (m_context_type) {
+ case eContextTypeInvalid:
+ case eContextTypeRegisterInfo: // RegisterInfo *
+ case eContextTypeLLDBType: // Type *
+ break;
+
+ case eContextTypeVariable: // Variable *
+ ResolveValue(exe_ctx);
+ return true;
+ }
+ return false;
+}
+
+uint64_t Value::GetValueByteSize(Error *error_ptr, ExecutionContext *exe_ctx) {
+ uint64_t byte_size = 0;
+
+ switch (m_context_type) {
+ case eContextTypeRegisterInfo: // RegisterInfo *
+ if (GetRegisterInfo())
+ byte_size = GetRegisterInfo()->byte_size;
+ break;
+
+ case eContextTypeInvalid:
+ case eContextTypeLLDBType: // Type *
+ case eContextTypeVariable: // Variable *
+ {
+ const CompilerType &ast_type = GetCompilerType();
+ if (ast_type.IsValid())
+ byte_size = ast_type.GetByteSize(
+ exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
+ } break;
+ }
+
+ if (error_ptr) {
+ if (byte_size == 0) {
+ if (error_ptr->Success())
+ error_ptr->SetErrorString("Unable to determine byte size.");
+ } else {
+ error_ptr->Clear();
+ }
+ }
+ return byte_size;
+}
+
+const CompilerType &Value::GetCompilerType() {
+ if (!m_compiler_type.IsValid()) {
+ switch (m_context_type) {
case eContextTypeInvalid:
- case eContextTypeRegisterInfo: // RegisterInfo *
- case eContextTypeLLDBType: // Type *
- break;
-
- case eContextTypeVariable: // Variable *
- ResolveValue(exe_ctx);
- return true;
- }
- return false;
-}
+ break;
-uint64_t
-Value::GetValueByteSize (Error *error_ptr, ExecutionContext *exe_ctx)
-{
- uint64_t byte_size = 0;
-
- switch (m_context_type)
- {
- case eContextTypeRegisterInfo: // RegisterInfo *
- if (GetRegisterInfo())
- byte_size = GetRegisterInfo()->byte_size;
- break;
-
- case eContextTypeInvalid:
- case eContextTypeLLDBType: // Type *
- case eContextTypeVariable: // Variable *
- {
- const CompilerType &ast_type = GetCompilerType();
- if (ast_type.IsValid())
- byte_size = ast_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
- }
- break;
- }
-
- if (error_ptr)
- {
- if (byte_size == 0)
- {
- if (error_ptr->Success())
- error_ptr->SetErrorString("Unable to determine byte size.");
- }
- else
- {
- error_ptr->Clear();
- }
- }
- return byte_size;
-}
-
-const CompilerType &
-Value::GetCompilerType ()
-{
- if (!m_compiler_type.IsValid())
- {
- switch (m_context_type)
- {
- case eContextTypeInvalid:
- break;
-
- case eContextTypeRegisterInfo:
- break; // TODO: Eventually convert into a compiler type?
-
- case eContextTypeLLDBType:
- {
- Type *lldb_type = GetType();
- if (lldb_type)
- m_compiler_type = lldb_type->GetForwardCompilerType ();
- }
- break;
-
- case eContextTypeVariable:
- {
- Variable *variable = GetVariable();
- if (variable)
- {
- Type *variable_type = variable->GetType();
- if (variable_type)
- m_compiler_type = variable_type->GetForwardCompilerType ();
- }
- }
- break;
- }
- }
-
- return m_compiler_type;
-}
-
-void
-Value::SetCompilerType (const CompilerType &compiler_type)
-{
- m_compiler_type = compiler_type;
-}
-
-lldb::Format
-Value::GetValueDefaultFormat ()
-{
- switch (m_context_type)
- {
case eContextTypeRegisterInfo:
- if (GetRegisterInfo())
- return GetRegisterInfo()->format;
- break;
+ break; // TODO: Eventually convert into a compiler type?
- case eContextTypeInvalid:
- case eContextTypeLLDBType:
- case eContextTypeVariable:
- {
- const CompilerType &ast_type = GetCompilerType();
- if (ast_type.IsValid())
- return ast_type.GetFormat();
- }
- break;
-
- }
-
- // Return a good default in case we can't figure anything out
- return eFormatHex;
-}
-
-bool
-Value::GetData (DataExtractor &data)
-{
- switch (m_value_type)
- {
- default:
- break;
-
- case eValueTypeScalar:
- if (m_value.GetData (data))
- return true;
- break;
-
- case eValueTypeLoadAddress:
- case eValueTypeFileAddress:
- case eValueTypeHostAddress:
- if (m_data_buffer.GetByteSize())
- {
- data.SetData(m_data_buffer.GetBytes(), m_data_buffer.GetByteSize(), data.GetByteOrder());
- return true;
- }
- break;
- }
-
- return false;
-
-}
-
-Error
-Value::GetValueAsData (ExecutionContext *exe_ctx,
- DataExtractor &data,
- uint32_t data_offset,
- Module *module)
-{
- data.Clear();
-
- Error error;
- lldb::addr_t address = LLDB_INVALID_ADDRESS;
- AddressType address_type = eAddressTypeFile;
- Address file_so_addr;
+ case eContextTypeLLDBType: {
+ Type *lldb_type = GetType();
+ if (lldb_type)
+ m_compiler_type = lldb_type->GetForwardCompilerType();
+ } break;
+
+ case eContextTypeVariable: {
+ Variable *variable = GetVariable();
+ if (variable) {
+ Type *variable_type = variable->GetType();
+ if (variable_type)
+ m_compiler_type = variable_type->GetForwardCompilerType();
+ }
+ } break;
+ }
+ }
+
+ return m_compiler_type;
+}
+
+void Value::SetCompilerType(const CompilerType &compiler_type) {
+ m_compiler_type = compiler_type;
+}
+
+lldb::Format Value::GetValueDefaultFormat() {
+ switch (m_context_type) {
+ case eContextTypeRegisterInfo:
+ if (GetRegisterInfo())
+ return GetRegisterInfo()->format;
+ break;
+
+ case eContextTypeInvalid:
+ case eContextTypeLLDBType:
+ case eContextTypeVariable: {
const CompilerType &ast_type = GetCompilerType();
- switch (m_value_type)
- {
- case eValueTypeVector:
- if (ast_type.IsValid())
- data.SetAddressByteSize (ast_type.GetPointerByteSize());
- else
- data.SetAddressByteSize(sizeof(void *));
- data.SetData(m_vector.bytes, m_vector.length, m_vector.byte_order);
- break;
+ if (ast_type.IsValid())
+ return ast_type.GetFormat();
+ } break;
+ }
+
+ // Return a good default in case we can't figure anything out
+ return eFormatHex;
+}
+
+bool Value::GetData(DataExtractor &data) {
+ switch (m_value_type) {
+ default:
+ break;
+
+ case eValueTypeScalar:
+ if (m_value.GetData(data))
+ return true;
+ break;
+
+ case eValueTypeLoadAddress:
+ case eValueTypeFileAddress:
+ case eValueTypeHostAddress:
+ if (m_data_buffer.GetByteSize()) {
+ data.SetData(m_data_buffer.GetBytes(), m_data_buffer.GetByteSize(),
+ data.GetByteOrder());
+ return true;
+ }
+ break;
+ }
+
+ return false;
+}
+
+Error Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data,
+ uint32_t data_offset, Module *module) {
+ data.Clear();
+
+ Error error;
+ lldb::addr_t address = LLDB_INVALID_ADDRESS;
+ AddressType address_type = eAddressTypeFile;
+ Address file_so_addr;
+ const CompilerType &ast_type = GetCompilerType();
+ switch (m_value_type) {
+ case eValueTypeVector:
+ if (ast_type.IsValid())
+ data.SetAddressByteSize(ast_type.GetPointerByteSize());
+ else
+ data.SetAddressByteSize(sizeof(void *));
+ data.SetData(m_vector.bytes, m_vector.length, m_vector.byte_order);
+ break;
+
+ case eValueTypeScalar: {
+ data.SetByteOrder(endian::InlHostByteOrder());
+ if (ast_type.IsValid())
+ data.SetAddressByteSize(ast_type.GetPointerByteSize());
+ else
+ data.SetAddressByteSize(sizeof(void *));
- case eValueTypeScalar:
- {
- data.SetByteOrder (endian::InlHostByteOrder());
- if (ast_type.IsValid())
- data.SetAddressByteSize (ast_type.GetPointerByteSize());
- else
- data.SetAddressByteSize(sizeof(void *));
-
- uint32_t limit_byte_size = UINT32_MAX;
-
- if (ast_type.IsValid())
- {
- limit_byte_size = ast_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
- }
-
- if (limit_byte_size <= m_value.GetByteSize())
- {
- if (m_value.GetData (data, limit_byte_size))
- return error; // Success;
- }
-
- error.SetErrorStringWithFormat("extracting data from value failed");
- break;
- }
- case eValueTypeLoadAddress:
- if (exe_ctx == NULL)
- {
- error.SetErrorString ("can't read load address (no execution context)");
- }
- else
- {
- Process *process = exe_ctx->GetProcessPtr();
- 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.
- const SectionLoadList &target_sections = target->GetSectionLoadList();
- if (!target_sections.IsEmpty())
- {
- address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
- if (target_sections.ResolveLoadAddress(address, file_so_addr))
- {
- address_type = eAddressTypeLoad;
- data.SetByteOrder(target->GetArchitecture().GetByteOrder());
- data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
- }
- else
- address = LLDB_INVALID_ADDRESS;
- }
-// else
-// {
-// ModuleSP exe_module_sp (target->GetExecutableModule());
-// if (exe_module_sp)
-// {
-// address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
-// if (address != LLDB_INVALID_ADDRESS)
-// {
-// if (exe_module_sp->ResolveFileAddress(address, file_so_addr))
-// {
-// data.SetByteOrder(target->GetArchitecture().GetByteOrder());
-// data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
-// address_type = eAddressTypeFile;
-// }
-// else
-// {
-// address = LLDB_INVALID_ADDRESS;
-// }
-// }
-// }
-// }
- }
- else
- {
- error.SetErrorString ("can't read load address (invalid process)");
- }
- }
- else
- {
- address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
- address_type = eAddressTypeLoad;
- data.SetByteOrder(process->GetTarget().GetArchitecture().GetByteOrder());
- data.SetAddressByteSize(process->GetTarget().GetArchitecture().GetAddressByteSize());
- }
- }
- break;
+ uint32_t limit_byte_size = UINT32_MAX;
- case eValueTypeFileAddress:
- if (exe_ctx == NULL)
- {
- error.SetErrorString ("can't read file address (no execution context)");
- }
- else if (exe_ctx->GetTargetPtr() == NULL)
- {
- error.SetErrorString ("can't read file address (invalid target)");
- }
- else
- {
+ if (ast_type.IsValid()) {
+ limit_byte_size = ast_type.GetByteSize(
+ exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
+ }
+
+ if (limit_byte_size <= m_value.GetByteSize()) {
+ if (m_value.GetData(data, limit_byte_size))
+ return error; // Success;
+ }
+
+ error.SetErrorStringWithFormat("extracting data from value failed");
+ break;
+ }
+ case eValueTypeLoadAddress:
+ if (exe_ctx == NULL) {
+ error.SetErrorString("can't read load address (no execution context)");
+ } else {
+ Process *process = exe_ctx->GetProcessPtr();
+ 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.
+ const SectionLoadList &target_sections = target->GetSectionLoadList();
+ if (!target_sections.IsEmpty()) {
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
- if (address == LLDB_INVALID_ADDRESS)
- {
- 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.
- Variable *variable = GetVariable();
- if (variable)
- {
- SymbolContext var_sc;
- variable->CalculateSymbolContext(&var_sc);
- module = var_sc.module_sp.get();
- }
- }
-
- if (module)
- {
- bool resolved = false;
- ObjectFile *objfile = module->GetObjectFile();
- if (objfile)
- {
- Address so_addr(address, objfile->GetSectionList());
- addr_t load_address = so_addr.GetLoadAddress (exe_ctx->GetTargetPtr());
- bool process_launched_and_stopped = exe_ctx->GetProcessPtr()
- ? StateIsStoppedState(exe_ctx->GetProcessPtr()->GetState(), true /* must_exist */)
- : false;
- // Don't use the load address if the process has exited.
- if (load_address != LLDB_INVALID_ADDRESS && process_launched_and_stopped)
- {
- resolved = true;
- address = load_address;
- address_type = eAddressTypeLoad;
- data.SetByteOrder(exe_ctx->GetTargetRef().GetArchitecture().GetByteOrder());
- data.SetAddressByteSize(exe_ctx->GetTargetRef().GetArchitecture().GetAddressByteSize());
- }
- else
- {
- if (so_addr.IsSectionOffset())
- {
- resolved = true;
- file_so_addr = so_addr;
- data.SetByteOrder(objfile->GetByteOrder());
- data.SetAddressByteSize(objfile->GetAddressByteSize());
- }
- }
- }
- if (!resolved)
- {
- Variable *variable = GetVariable();
-
- if (module)
- {
- if (variable)
- error.SetErrorStringWithFormat ("unable to resolve the module for file address 0x%" PRIx64 " for variable '%s' in %s",
- address,
- variable->GetName().AsCString(""),
- module->GetFileSpec().GetPath().c_str());
- else
- error.SetErrorStringWithFormat ("unable to resolve the module for file address 0x%" PRIx64 " in %s",
- address,
- module->GetFileSpec().GetPath().c_str());
- }
- else
- {
- if (variable)
- error.SetErrorStringWithFormat ("unable to resolve the module for file address 0x%" PRIx64 " for variable '%s'",
- address,
- variable->GetName().AsCString(""));
- else
- error.SetErrorStringWithFormat ("unable to resolve the module for file address 0x%" PRIx64, address);
- }
- }
- }
- else
- {
- // Can't convert a file address to anything valid without more
- // context (which Module it came from)
- error.SetErrorString ("can't read memory from file address without more context");
- }
- }
+ if (target_sections.ResolveLoadAddress(address, file_so_addr)) {
+ address_type = eAddressTypeLoad;
+ data.SetByteOrder(target->GetArchitecture().GetByteOrder());
+ data.SetAddressByteSize(
+ target->GetArchitecture().GetAddressByteSize());
+ } else
+ address = LLDB_INVALID_ADDRESS;
+ }
+ // else
+ // {
+ // ModuleSP exe_module_sp
+ // (target->GetExecutableModule());
+ // if (exe_module_sp)
+ // {
+ // address =
+ // m_value.ULongLong(LLDB_INVALID_ADDRESS);
+ // if (address != LLDB_INVALID_ADDRESS)
+ // {
+ // if
+ // (exe_module_sp->ResolveFileAddress(address,
+ // file_so_addr))
+ // {
+ // data.SetByteOrder(target->GetArchitecture().GetByteOrder());
+ // data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
+ // address_type = eAddressTypeFile;
+ // }
+ // else
+ // {
+ // address = LLDB_INVALID_ADDRESS;
+ // }
+ // }
+ // }
+ // }
+ } else {
+ error.SetErrorString("can't read load address (invalid process)");
}
- break;
-
- case eValueTypeHostAddress:
+ } else {
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
- address_type = eAddressTypeHost;
- if (exe_ctx)
- {
- Target *target = exe_ctx->GetTargetPtr();
- if (target)
- {
- data.SetByteOrder(target->GetArchitecture().GetByteOrder());
- data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
- break;
- }
- }
- // fallback to host settings
- data.SetByteOrder(endian::InlHostByteOrder());
- data.SetAddressByteSize(sizeof(void *));
- break;
- }
+ address_type = eAddressTypeLoad;
+ data.SetByteOrder(
+ process->GetTarget().GetArchitecture().GetByteOrder());
+ data.SetAddressByteSize(
+ process->GetTarget().GetArchitecture().GetAddressByteSize());
+ }
+ }
+ break;
+
+ case eValueTypeFileAddress:
+ if (exe_ctx == NULL) {
+ error.SetErrorString("can't read file address (no execution context)");
+ } else if (exe_ctx->GetTargetPtr() == NULL) {
+ error.SetErrorString("can't read file address (invalid target)");
+ } else {
+ address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
+ if (address == LLDB_INVALID_ADDRESS) {
+ 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.
+ Variable *variable = GetVariable();
+ if (variable) {
+ SymbolContext var_sc;
+ variable->CalculateSymbolContext(&var_sc);
+ module = var_sc.module_sp.get();
+ }
+ }
+
+ if (module) {
+ bool resolved = false;
+ ObjectFile *objfile = module->GetObjectFile();
+ if (objfile) {
+ Address so_addr(address, objfile->GetSectionList());
+ addr_t load_address =
+ so_addr.GetLoadAddress(exe_ctx->GetTargetPtr());
+ bool process_launched_and_stopped =
+ exe_ctx->GetProcessPtr()
+ ? StateIsStoppedState(exe_ctx->GetProcessPtr()->GetState(),
+ true /* must_exist */)
+ : false;
+ // Don't use the load address if the process has exited.
+ if (load_address != LLDB_INVALID_ADDRESS &&
+ process_launched_and_stopped) {
+ resolved = true;
+ address = load_address;
+ address_type = eAddressTypeLoad;
+ data.SetByteOrder(
+ exe_ctx->GetTargetRef().GetArchitecture().GetByteOrder());
+ data.SetAddressByteSize(exe_ctx->GetTargetRef()
+ .GetArchitecture()
+ .GetAddressByteSize());
+ } else {
+ if (so_addr.IsSectionOffset()) {
+ resolved = true;
+ file_so_addr = so_addr;
+ data.SetByteOrder(objfile->GetByteOrder());
+ data.SetAddressByteSize(objfile->GetAddressByteSize());
+ }
+ }
+ }
+ if (!resolved) {
+ Variable *variable = GetVariable();
+
+ if (module) {
+ if (variable)
+ error.SetErrorStringWithFormat(
+ "unable to resolve the module for file address 0x%" PRIx64
+ " for variable '%s' in %s",
+ address, variable->GetName().AsCString(""),
+ module->GetFileSpec().GetPath().c_str());
+ else
+ error.SetErrorStringWithFormat(
+ "unable to resolve the module for file address 0x%" PRIx64
+ " in %s",
+ address, module->GetFileSpec().GetPath().c_str());
+ } else {
+ if (variable)
+ error.SetErrorStringWithFormat(
+ "unable to resolve the module for file address 0x%" PRIx64
+ " for variable '%s'",
+ address, variable->GetName().AsCString(""));
+ else
+ error.SetErrorStringWithFormat(
+ "unable to resolve the module for file address 0x%" PRIx64,
+ address);
+ }
+ }
+ } else {
+ // Can't convert a file address to anything valid without more
+ // context (which Module it came from)
+ error.SetErrorString(
+ "can't read memory from file address without more context");
+ }
+ }
+ }
+ break;
+
+ case eValueTypeHostAddress:
+ address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
+ address_type = eAddressTypeHost;
+ if (exe_ctx) {
+ Target *target = exe_ctx->GetTargetPtr();
+ if (target) {
+ data.SetByteOrder(target->GetArchitecture().GetByteOrder());
+ data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
+ break;
+ }
+ }
+ // fallback to host settings
+ data.SetByteOrder(endian::InlHostByteOrder());
+ data.SetAddressByteSize(sizeof(void *));
+ break;
+ }
- // Bail if we encountered any errors
- if (error.Fail())
- return error;
-
- if (address == LLDB_INVALID_ADDRESS)
- {
- error.SetErrorStringWithFormat ("invalid %s address", address_type == eAddressTypeHost ? "host" : "load");
- return error;
- }
-
- // If we got here, we need to read the value from memory
- size_t byte_size = GetValueByteSize (&error, exe_ctx);
-
- // Bail if we encountered any errors getting the byte size
- if (error.Fail())
- return error;
+ // Bail if we encountered any errors
+ if (error.Fail())
+ return error;
- // Make sure we have enough room within "data", and if we don't make
- // something large enough that does
- if (!data.ValidOffsetForDataOfSize (data_offset, byte_size))
- {
- DataBufferSP data_sp(new DataBufferHeap (data_offset + byte_size, '\0'));
- data.SetData(data_sp);
- }
+ if (address == LLDB_INVALID_ADDRESS) {
+ error.SetErrorStringWithFormat("invalid %s address",
+ address_type == eAddressTypeHost ? "host"
+ : "load");
+ return error;
+ }
- uint8_t* dst = const_cast<uint8_t*>(data.PeekData (data_offset, byte_size));
- if (dst != NULL)
- {
- if (address_type == eAddressTypeHost)
- {
- // The address is an address in this process, so just copy it.
- if (address == 0)
- {
- error.SetErrorStringWithFormat("trying to read from host address of 0.");
- return error;
- }
- memcpy (dst, (uint8_t*)NULL + address, byte_size);
- }
- 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.
- const bool prefer_file_cache = false;
- if (exe_ctx->GetTargetRef().ReadMemory(file_so_addr, prefer_file_cache, dst, byte_size, error) != byte_size)
- {
- error.SetErrorStringWithFormat("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.
- Process *process = exe_ctx->GetProcessPtr();
-
- if (process)
- {
- const size_t bytes_read = process->ReadMemory(address, dst, byte_size, error);
- if (bytes_read != byte_size)
- error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed (%u of %u bytes read)",
- (uint64_t)address,
- (uint32_t)bytes_read,
- (uint32_t)byte_size);
- }
- else
- {
- error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed (invalid process)", (uint64_t)address);
- }
- }
- }
- else
- {
- error.SetErrorStringWithFormat ("unsupported AddressType value (%i)", address_type);
- }
- }
- else
- {
- error.SetErrorStringWithFormat ("out of memory");
- }
+ // If we got here, we need to read the value from memory
+ size_t byte_size = GetValueByteSize(&error, exe_ctx);
+ // Bail if we encountered any errors getting the byte size
+ if (error.Fail())
return error;
-}
-Scalar &
-Value::ResolveValue(ExecutionContext *exe_ctx)
-{
- const CompilerType &compiler_type = GetCompilerType();
- if (compiler_type.IsValid())
- {
- switch (m_value_type)
- {
- case eValueTypeScalar: // raw scalar value
- break;
-
- default:
- case eValueTypeFileAddress:
- case eValueTypeLoadAddress: // load address value
- case eValueTypeHostAddress: // host address value (for memory in the process that is using liblldb)
- {
- DataExtractor data;
- lldb::addr_t addr = m_value.ULongLong(LLDB_INVALID_ADDRESS);
- Error error (GetValueAsData (exe_ctx, data, 0, NULL));
- if (error.Success())
- {
- Scalar scalar;
- if (compiler_type.GetValueAsScalar (data, 0, data.GetByteSize(), scalar))
- {
- m_value = scalar;
- m_value_type = eValueTypeScalar;
- }
- else
- {
- if ((uintptr_t)addr != (uintptr_t)m_data_buffer.GetBytes())
- {
- m_value.Clear();
- m_value_type = eValueTypeScalar;
- }
- }
- }
- else
- {
- if ((uintptr_t)addr != (uintptr_t)m_data_buffer.GetBytes())
- {
- m_value.Clear();
- m_value_type = eValueTypeScalar;
- }
- }
- }
- break;
- }
- }
- return m_value;
-}
+ // Make sure we have enough room within "data", and if we don't make
+ // something large enough that does
+ if (!data.ValidOffsetForDataOfSize(data_offset, byte_size)) {
+ DataBufferSP data_sp(new DataBufferHeap(data_offset + byte_size, '\0'));
+ data.SetData(data_sp);
+ }
+
+ uint8_t *dst = const_cast<uint8_t *>(data.PeekData(data_offset, byte_size));
+ if (dst != NULL) {
+ if (address_type == eAddressTypeHost) {
+ // The address is an address in this process, so just copy it.
+ if (address == 0) {
+ error.SetErrorStringWithFormat(
+ "trying to read from host address of 0.");
+ return error;
+ }
+ memcpy(dst, (uint8_t *)NULL + address, byte_size);
+ } 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.
+ const bool prefer_file_cache = false;
+ if (exe_ctx->GetTargetRef().ReadMemory(file_so_addr, prefer_file_cache,
+ dst, byte_size,
+ error) != byte_size) {
+ error.SetErrorStringWithFormat(
+ "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.
+ Process *process = exe_ctx->GetProcessPtr();
+
+ if (process) {
+ const size_t bytes_read =
+ process->ReadMemory(address, dst, byte_size, error);
+ if (bytes_read != byte_size)
+ error.SetErrorStringWithFormat(
+ "read memory from 0x%" PRIx64 " failed (%u of %u bytes read)",
+ (uint64_t)address, (uint32_t)bytes_read, (uint32_t)byte_size);
+ } else {
+ error.SetErrorStringWithFormat("read memory from 0x%" PRIx64
+ " failed (invalid process)",
+ (uint64_t)address);
+ }
+ }
+ } else {
+ error.SetErrorStringWithFormat("unsupported AddressType value (%i)",
+ address_type);
+ }
+ } else {
+ error.SetErrorStringWithFormat("out of memory");
+ }
+
+ return error;
+}
+
+Scalar &Value::ResolveValue(ExecutionContext *exe_ctx) {
+ const CompilerType &compiler_type = GetCompilerType();
+ if (compiler_type.IsValid()) {
+ switch (m_value_type) {
+ case eValueTypeScalar: // raw scalar value
+ break;
-Variable *
-Value::GetVariable()
-{
- if (m_context_type == eContextTypeVariable)
- return static_cast<Variable *> (m_context);
+ default:
+ case eValueTypeFileAddress:
+ case eValueTypeLoadAddress: // load address value
+ case eValueTypeHostAddress: // host address value (for memory in the process
+ // that is using liblldb)
+ {
+ DataExtractor data;
+ lldb::addr_t addr = m_value.ULongLong(LLDB_INVALID_ADDRESS);
+ Error error(GetValueAsData(exe_ctx, data, 0, NULL));
+ if (error.Success()) {
+ Scalar scalar;
+ if (compiler_type.GetValueAsScalar(data, 0, data.GetByteSize(),
+ scalar)) {
+ m_value = scalar;
+ m_value_type = eValueTypeScalar;
+ } else {
+ if ((uintptr_t)addr != (uintptr_t)m_data_buffer.GetBytes()) {
+ m_value.Clear();
+ m_value_type = eValueTypeScalar;
+ }
+ }
+ } else {
+ if ((uintptr_t)addr != (uintptr_t)m_data_buffer.GetBytes()) {
+ m_value.Clear();
+ m_value_type = eValueTypeScalar;
+ }
+ }
+ } break;
+ }
+ }
+ return m_value;
+}
+
+Variable *Value::GetVariable() {
+ if (m_context_type == eContextTypeVariable)
+ return static_cast<Variable *>(m_context);
+ return NULL;
+}
+
+void Value::Clear() {
+ m_value.Clear();
+ m_vector.Clear();
+ m_compiler_type.Clear();
+ m_value_type = eValueTypeScalar;
+ m_context = NULL;
+ m_context_type = eContextTypeInvalid;
+ m_data_buffer.Clear();
+}
+
+const char *Value::GetValueTypeAsCString(ValueType value_type) {
+ switch (value_type) {
+ case eValueTypeScalar:
+ return "scalar";
+ case eValueTypeVector:
+ return "vector";
+ case eValueTypeFileAddress:
+ return "file address";
+ case eValueTypeLoadAddress:
+ return "load address";
+ case eValueTypeHostAddress:
+ return "host address";
+ };
+ return "???";
+}
+
+const char *Value::GetContextTypeAsCString(ContextType context_type) {
+ switch (context_type) {
+ case eContextTypeInvalid:
+ return "invalid";
+ case eContextTypeRegisterInfo:
+ return "RegisterInfo *";
+ case eContextTypeLLDBType:
+ return "Type *";
+ case eContextTypeVariable:
+ return "Variable *";
+ };
+ return "???";
+}
+
+ValueList::ValueList(const ValueList &rhs) { m_values = rhs.m_values; }
+
+const ValueList &ValueList::operator=(const ValueList &rhs) {
+ m_values = rhs.m_values;
+ return *this;
+}
+
+void ValueList::PushValue(const Value &value) { m_values.push_back(value); }
+
+size_t ValueList::GetSize() { return m_values.size(); }
+
+Value *ValueList::GetValueAtIndex(size_t idx) {
+ if (idx < GetSize()) {
+ return &(m_values[idx]);
+ } else
return NULL;
}
-void
-Value::Clear()
-{
- m_value.Clear();
- m_vector.Clear();
- m_compiler_type.Clear();
- m_value_type = eValueTypeScalar;
- m_context = NULL;
- m_context_type = eContextTypeInvalid;
- m_data_buffer.Clear();
-}
-
-
-const char *
-Value::GetValueTypeAsCString (ValueType value_type)
-{
- switch (value_type)
- {
- case eValueTypeScalar: return "scalar";
- case eValueTypeVector: return "vector";
- case eValueTypeFileAddress: return "file address";
- case eValueTypeLoadAddress: return "load address";
- case eValueTypeHostAddress: return "host address";
- };
- return "???";
-}
-
-const char *
-Value::GetContextTypeAsCString (ContextType context_type)
-{
- switch (context_type)
- {
- case eContextTypeInvalid: return "invalid";
- case eContextTypeRegisterInfo: return "RegisterInfo *";
- case eContextTypeLLDBType: return "Type *";
- case eContextTypeVariable: return "Variable *";
- };
- return "???";
-}
-
-ValueList::ValueList (const ValueList &rhs)
-{
- m_values = rhs.m_values;
-}
-
-const ValueList &
-ValueList::operator= (const ValueList &rhs)
-{
- m_values = rhs.m_values;
- return *this;
-}
-
-void
-ValueList::PushValue (const Value &value)
-{
- m_values.push_back (value);
-}
-
-size_t
-ValueList::GetSize()
-{
- return m_values.size();
-}
-
-Value *
-ValueList::GetValueAtIndex (size_t idx)
-{
- if (idx < GetSize())
- {
- return &(m_values[idx]);
- }
- else
- return NULL;
-}
-
-void
-ValueList::Clear ()
-{
- m_values.clear();
-}
-
+void ValueList::Clear() { m_values.clear(); }
More information about the lldb-commits
mailing list