aboutsummaryrefslogtreecommitdiff
path: root/source/Core
diff options
context:
space:
mode:
Diffstat (limited to 'source/Core')
-rw-r--r--source/Core/Address.cpp159
-rw-r--r--source/Core/AddressRange.cpp2
-rw-r--r--source/Core/AddressResolverName.cpp80
-rw-r--r--source/Core/ArchSpec.cpp205
-rw-r--r--source/Core/Broadcaster.cpp389
-rw-r--r--source/Core/Communication.cpp139
-rw-r--r--source/Core/ConnectionSharedMemory.cpp39
-rw-r--r--source/Core/ConstString.cpp70
-rw-r--r--source/Core/CxaDemangle.cpp3
-rw-r--r--source/Core/DataBufferHeap.cpp22
-rw-r--r--source/Core/DataBufferMemoryMap.cpp66
-rw-r--r--source/Core/DataEncoder.cpp58
-rw-r--r--source/Core/DataExtractor.cpp230
-rw-r--r--source/Core/Debugger.cpp459
-rw-r--r--source/Core/Disassembler.cpp333
-rw-r--r--source/Core/DynamicLoader.cpp40
-rw-r--r--source/Core/EmulateInstruction.cpp108
-rw-r--r--source/Core/Error.cpp65
-rw-r--r--source/Core/Event.cpp104
-rw-r--r--source/Core/FastDemangle.cpp11
-rw-r--r--source/Core/FileSpecList.cpp42
-rw-r--r--source/Core/FormatEntity.cpp114
-rw-r--r--source/Core/IOHandler.cpp368
-rw-r--r--source/Core/Listener.cpp378
-rw-r--r--source/Core/Log.cpp55
-rw-r--r--source/Core/Logging.cpp37
-rw-r--r--source/Core/Makefile14
-rw-r--r--source/Core/Mangled.cpp23
-rw-r--r--source/Core/Module.cpp691
-rw-r--r--source/Core/ModuleList.cpp299
-rw-r--r--source/Core/Opcode.cpp20
-rw-r--r--source/Core/PluginManager.cpp806
-rw-r--r--source/Core/RegisterValue.cpp192
-rw-r--r--source/Core/RegularExpression.cpp33
-rw-r--r--source/Core/Scalar.cpp1152
-rw-r--r--source/Core/SearchFilter.cpp181
-rw-r--r--source/Core/Section.cpp145
-rw-r--r--source/Core/StreamCallback.cpp11
-rw-r--r--source/Core/Timer.cpp67
-rw-r--r--source/Core/UserSettingsController.cpp24
-rw-r--r--source/Core/Value.cpp15
-rw-r--r--source/Core/ValueObject.cpp71
-rw-r--r--source/Core/ValueObjectConstResult.cpp7
-rw-r--r--source/Core/ValueObjectConstResultCast.cpp5
-rw-r--r--source/Core/ValueObjectConstResultChild.cpp10
-rw-r--r--source/Core/ValueObjectConstResultImpl.cpp10
-rw-r--r--source/Core/ValueObjectDynamicValue.cpp16
-rw-r--r--source/Core/ValueObjectSyntheticFilter.cpp111
-rw-r--r--source/Core/ValueObjectVariable.cpp10
49 files changed, 3759 insertions, 3730 deletions
diff --git a/source/Core/Address.cpp b/source/Core/Address.cpp
index 83100dea93bc..f3ea1718d6f2 100644
--- a/source/Core/Address.cpp
+++ b/source/Core/Address.cpp
@@ -8,6 +8,13 @@
//===----------------------------------------------------------------------===//
#include "lldb/Core/Address.h"
+
+// C Includes
+// C++ Includes
+#include "llvm/ADT/Triple.h"
+
+// Other libraries and framework includes
+// Project includes
#include "lldb/Core/Module.h"
#include "lldb/Core/Section.h"
#include "lldb/Symbol/Block.h"
@@ -20,15 +27,13 @@
#include "lldb/Target/Target.h"
#include "lldb/Symbol/SymbolVendor.h"
-#include "llvm/ADT/Triple.h"
-
using namespace lldb;
using namespace lldb_private;
static size_t
ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len)
{
- if (exe_scope == NULL)
+ if (exe_scope == nullptr)
return 0;
TargetSP target_sp (exe_scope->CalculateTarget());
@@ -46,7 +51,7 @@ GetByteOrderAndAddressSize (ExecutionContextScope *exe_scope, const Address &add
{
byte_order = eByteOrderInvalid;
addr_size = 0;
- if (exe_scope == NULL)
+ if (exe_scope == nullptr)
return false;
TargetSP target_sp (exe_scope->CalculateTarget());
@@ -72,7 +77,7 @@ static uint64_t
ReadUIntMax64 (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, bool &success)
{
uint64_t uval64 = 0;
- if (exe_scope == NULL || byte_size > sizeof(uint64_t))
+ if (exe_scope == nullptr || byte_size > sizeof(uint64_t))
{
success = false;
return 0;
@@ -99,10 +104,9 @@ ReadUIntMax64 (ExecutionContextScope *exe_scope, const Address &address, uint32_
static bool
ReadAddress (ExecutionContextScope *exe_scope, const Address &address, uint32_t pointer_size, Address &deref_so_addr)
{
- if (exe_scope == NULL)
+ if (exe_scope == nullptr)
return false;
-
bool success = false;
addr_t deref_addr = ReadUIntMax64 (exe_scope, address, pointer_size, success);
if (success)
@@ -140,7 +144,7 @@ ReadAddress (ExecutionContextScope *exe_scope, const Address &address, uint32_t
static bool
DumpUInt (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, Stream* strm)
{
- if (exe_scope == NULL || byte_size == 0)
+ if (exe_scope == nullptr || byte_size == 0)
return 0;
std::vector<uint8_t> buf(byte_size, 0);
@@ -168,11 +172,10 @@ DumpUInt (ExecutionContextScope *exe_scope, const Address &address, uint32_t byt
return false;
}
-
static size_t
ReadCStringFromMemory (ExecutionContextScope *exe_scope, const Address &address, Stream *strm)
{
- if (exe_scope == NULL)
+ if (exe_scope == nullptr)
return 0;
const size_t k_buf_len = 256;
char buf[k_buf_len+1];
@@ -334,7 +337,7 @@ Address::GetCallableLoadAddress (Target *target, bool is_indirect) const
{
ProcessSP processSP = target->GetProcessSP();
Error error;
- if (processSP.get())
+ if (processSP)
{
code_addr = processSP->ResolveIndirectFunction(this, error);
if (!error.Success())
@@ -398,7 +401,7 @@ Address::SetOpcodeLoadAddress (lldb::addr_t load_addr, Target *target, AddressCl
bool
Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const
{
- // If the section was NULL, only load address is going to work unless we are
+ // If the section was nullptr, only load address is going to work unless we are
// trying to deref a pointer
SectionSP section_sp (GetSection());
if (!section_sp && style != DumpStyleResolvedPointerDescription)
@@ -442,9 +445,13 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
case DumpStyleModuleWithFileAddress:
if (section_sp)
{
- s->Printf("%s[", section_sp->GetModule()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
+ ModuleSP module_sp = section_sp->GetModule();
+ if (module_sp)
+ s->Printf("%s[", module_sp->GetFileSpec().GetFilename().AsCString("<Unknown>"));
+ else
+ s->Printf("%s[","<Unknown>");
}
- // Fall through
+ LLVM_FALLTHROUGH;
case DumpStyleFileAddress:
{
addr_t file_addr = GetFileAddress();
@@ -541,59 +548,55 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
break;
case eSectionTypeDataCStringPointers:
+ if (ReadAddress(exe_scope, *this, pointer_size, so_addr))
{
- if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
- {
#if VERBOSE_OUTPUT
- s->PutCString("(char *)");
- so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
- s->PutCString(": ");
+ s->PutCString("(char *)");
+ so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
+ s->PutCString(": ");
#endif
- showed_info = true;
- ReadCStringFromMemory (exe_scope, so_addr, s);
- }
+ showed_info = true;
+ ReadCStringFromMemory(exe_scope, so_addr, s);
}
break;
case eSectionTypeDataObjCMessageRefs:
+ if (ReadAddress(exe_scope, *this, pointer_size, so_addr))
{
- if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
+ if (target && so_addr.IsSectionOffset())
{
- if (target && so_addr.IsSectionOffset())
+ SymbolContext func_sc;
+ target->GetImages().ResolveSymbolContextForAddress(so_addr,
+ eSymbolContextEverything,
+ func_sc);
+ if (func_sc.function != nullptr || func_sc.symbol != nullptr)
{
- SymbolContext func_sc;
- target->GetImages().ResolveSymbolContextForAddress (so_addr,
- eSymbolContextEverything,
- func_sc);
- if (func_sc.function || func_sc.symbol)
- {
- showed_info = true;
+ showed_info = true;
#if VERBOSE_OUTPUT
- s->PutCString ("(objc_msgref *) -> { (func*)");
- so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
+ s->PutCString ("(objc_msgref *) -> { (func*)");
+ so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
#else
- s->PutCString ("{ ");
+ s->PutCString ("{ ");
#endif
- Address cstr_addr(*this);
- cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
- func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false, true, true);
- if (ReadAddress (exe_scope, cstr_addr, pointer_size, so_addr))
- {
+ Address cstr_addr(*this);
+ cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
+ func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false, true, true);
+ if (ReadAddress(exe_scope, cstr_addr, pointer_size, so_addr))
+ {
#if VERBOSE_OUTPUT
- s->PutCString("), (char *)");
- so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
- s->PutCString(" (");
+ s->PutCString("), (char *)");
+ so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
+ s->PutCString(" (");
#else
- s->PutCString(", ");
+ s->PutCString(", ");
#endif
- ReadCStringFromMemory (exe_scope, so_addr, s);
- }
+ ReadCStringFromMemory (exe_scope, so_addr, s);
+ }
#if VERBOSE_OUTPUT
- s->PutCString(") }");
+ s->PutCString(") }");
#else
- s->PutCString(" }");
+ s->PutCString(" }");
#endif
- }
}
}
}
@@ -641,26 +644,24 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
case eSectionTypeDataPointers:
// Read the pointer data and display it
+ if (ReadAddress(exe_scope, *this, pointer_size, so_addr))
{
- if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
- {
- s->PutCString ("(void *)");
- so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
+ s->PutCString ("(void *)");
+ so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
- showed_info = true;
- if (so_addr.IsSectionOffset())
+ showed_info = true;
+ if (so_addr.IsSectionOffset())
+ {
+ SymbolContext pointer_sc;
+ if (target)
{
- SymbolContext pointer_sc;
- if (target)
+ target->GetImages().ResolveSymbolContextForAddress(so_addr,
+ eSymbolContextEverything,
+ pointer_sc);
+ if (pointer_sc.function != nullptr || pointer_sc.symbol != nullptr)
{
- target->GetImages().ResolveSymbolContextForAddress (so_addr,
- eSymbolContextEverything,
- pointer_sc);
- if (pointer_sc.function || pointer_sc.symbol)
- {
- s->PutCString(": ");
- pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false, true, true);
- }
+ s->PutCString(": ");
+ pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false, true, true);
}
}
}
@@ -677,7 +678,7 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
if (module_sp)
{
SymbolContext sc;
- module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything | eSymbolContextVariable, sc);
+ module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
if (sc.function || sc.symbol)
{
bool show_stop_context = true;
@@ -686,7 +687,7 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
const bool show_inlined_frames = true;
const bool show_function_arguments = (style != DumpStyleResolvedDescriptionNoFunctionArguments);
const bool show_function_name = (style != DumpStyleNoFunctionName);
- if (sc.function == NULL && sc.symbol != NULL)
+ if (sc.function == nullptr && sc.symbol != nullptr)
{
// If we have just a symbol make sure it is in the right section
if (sc.symbol->ValueIsAddress())
@@ -745,7 +746,7 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
// the last symbol that came before the address that we are
// looking up that has nothing to do with our address lookup.
if (sc.symbol->ValueIsAddress() && sc.symbol->GetAddressRef().GetSection() != GetSection())
- sc.symbol = NULL;
+ sc.symbol = nullptr;
}
sc.GetDescription(s, eDescriptionLevelBrief, target);
@@ -756,10 +757,11 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
bool stop_if_block_is_inlined_function = false;
VariableList variable_list;
sc.block->AppendVariables (can_create,
- get_parent_variables,
- stop_if_block_is_inlined_function,
+ get_parent_variables,
+ stop_if_block_is_inlined_function,
+ [](Variable*) { return true; },
&variable_list);
-
+
const size_t num_variables = variable_list.GetSize();
for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
{
@@ -792,6 +794,7 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
return false;
}
break;
+
case DumpStyleResolvedPointerDescription:
{
Process *process = exe_ctx.GetProcessPtr();
@@ -892,7 +895,7 @@ Address::CalculateSymbolContextCompileUnit () const
return sc.comp_unit;
}
}
- return NULL;
+ return nullptr;
}
Function *
@@ -909,7 +912,7 @@ Address::CalculateSymbolContextFunction () const
return sc.function;
}
}
- return NULL;
+ return nullptr;
}
Block *
@@ -926,7 +929,7 @@ Address::CalculateSymbolContextBlock () const
return sc.block;
}
}
- return NULL;
+ return nullptr;
}
Symbol *
@@ -943,7 +946,7 @@ Address::CalculateSymbolContextSymbol () const
return sc.symbol;
}
}
- return NULL;
+ return nullptr;
}
bool
@@ -980,11 +983,10 @@ Address::CompareFileAddress (const Address& a, const Address& b)
return 0;
}
-
int
Address::CompareLoadAddress (const Address& a, const Address& b, Target *target)
{
- assert (target != NULL);
+ assert(target != nullptr);
addr_t a_load_addr = a.GetLoadAddress (target);
addr_t b_load_addr = b.GetLoadAddress (target);
if (a_load_addr < b_load_addr)
@@ -1016,7 +1018,6 @@ Address::CompareModulePointerAndOffset (const Address& a, const Address& b)
return 0;
}
-
size_t
Address::MemorySize () const
{
@@ -1025,7 +1026,6 @@ Address::MemorySize () const
return sizeof(Address);
}
-
//----------------------------------------------------------------------
// NOTE: Be careful using this operator. It can correctly compare two
// addresses from the same Module correctly. It can't compare two
@@ -1081,7 +1081,6 @@ lldb_private::operator> (const Address& lhs, const Address& rhs)
}
}
-
// The operator == checks for exact equality only (same section, same offset)
bool
lldb_private::operator== (const Address& a, const Address& rhs)
@@ -1089,6 +1088,7 @@ lldb_private::operator== (const Address& a, const Address& rhs)
return a.GetOffset() == rhs.GetOffset() &&
a.GetSection() == rhs.GetSection();
}
+
// The operator != checks for exact inequality only (differing section, or
// different offset)
bool
@@ -1124,4 +1124,3 @@ Address::SetLoadAddress (lldb::addr_t load_addr, Target *target)
m_offset = load_addr;
return false;
}
-
diff --git a/source/Core/AddressRange.cpp b/source/Core/AddressRange.cpp
index ac64833884ee..072c2450836c 100644
--- a/source/Core/AddressRange.cpp
+++ b/source/Core/AddressRange.cpp
@@ -163,7 +163,7 @@ AddressRange::Dump(Stream *s, Target *target, Address::DumpStyle style, Address:
case Address::DumpStyleModuleWithFileAddress:
show_module = true;
- // fall through
+ LLVM_FALLTHROUGH;
case Address::DumpStyleFileAddress:
vmaddr = m_base_addr.GetFileAddress();
break;
diff --git a/source/Core/AddressResolverName.cpp b/source/Core/AddressResolverName.cpp
index 293002ad517f..dacc7d777f85 100644
--- a/source/Core/AddressResolverName.cpp
+++ b/source/Core/AddressResolverName.cpp
@@ -9,6 +9,9 @@
#include "lldb/Core/AddressResolverName.h"
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
// Project includes
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
@@ -20,16 +23,13 @@
using namespace lldb;
using namespace lldb_private;
-AddressResolverName::AddressResolverName
-(
- const char *func_name,
- AddressResolver::MatchType type
-) :
- AddressResolver (),
- m_func_name (func_name),
- m_class_name (NULL),
- m_regex (),
- m_match_type (type)
+AddressResolverName::AddressResolverName(const char *func_name,
+ AddressResolver::MatchType type) :
+ AddressResolver(),
+ m_func_name(func_name),
+ m_class_name(nullptr),
+ m_regex(),
+ m_match_type(type)
{
if (m_match_type == AddressResolver::Regexp)
{
@@ -43,50 +43,37 @@ AddressResolverName::AddressResolverName
}
}
-AddressResolverName::AddressResolverName
-(
- RegularExpression &func_regex
-) :
- AddressResolver (),
- m_func_name (NULL),
- m_class_name (NULL),
- m_regex (func_regex),
- m_match_type (AddressResolver::Regexp)
+AddressResolverName::AddressResolverName(RegularExpression &func_regex) :
+ AddressResolver(),
+ m_func_name(nullptr),
+ m_class_name(nullptr),
+ m_regex(func_regex),
+ m_match_type(AddressResolver::Regexp)
{
-
}
-AddressResolverName::AddressResolverName
-(
- const char *class_name,
- const char *method,
- AddressResolver::MatchType type
-) :
+AddressResolverName::AddressResolverName(const char *class_name,
+ const char *method,
+ AddressResolver::MatchType type) :
AddressResolver (),
m_func_name (method),
m_class_name (class_name),
m_regex (),
m_match_type (type)
{
-
}
-AddressResolverName::~AddressResolverName ()
-{
-}
+AddressResolverName::~AddressResolverName() = default;
// FIXME: Right now we look at the module level, and call the module's "FindFunctions".
// Greg says he will add function tables, maybe at the CompileUnit level to accelerate function
// lookup. At that point, we should switch the depth to CompileUnit, and look in these tables.
Searcher::CallbackReturn
-AddressResolverName::SearchCallback
-(
- SearchFilter &filter,
- SymbolContext &context,
- Address *addr,
- bool containing
-)
+AddressResolverName::SearchCallback(SearchFilter &filter,
+ SymbolContext &context,
+ Address *addr,
+ bool containing)
{
SymbolContextList func_list;
SymbolContextList sym_list;
@@ -116,13 +103,13 @@ AddressResolverName::SearchCallback
context.module_sp->FindSymbolsWithNameAndType (m_func_name,
eSymbolTypeCode,
sym_list);
- context.module_sp->FindFunctions (m_func_name,
- NULL,
- eFunctionNameTypeAuto,
- include_symbols,
- include_inlines,
- append,
- func_list);
+ context.module_sp->FindFunctions(m_func_name,
+ nullptr,
+ eFunctionNameTypeAuto,
+ include_symbols,
+ include_inlines,
+ append,
+ func_list);
}
break;
@@ -151,10 +138,10 @@ AddressResolverName::SearchCallback
{
for (i = 0; i < func_list.GetSize(); i++)
{
- if (func_list.GetContextAtIndex(i, sc) == false)
+ if (!func_list.GetContextAtIndex(i, sc))
continue;
- if (sc.function == NULL)
+ if (sc.function == nullptr)
continue;
uint32_t j = 0;
while (j < sym_list.GetSize())
@@ -250,4 +237,3 @@ AddressResolverName::GetDescription (Stream *s)
else
s->Printf("'%s'", m_func_name.AsCString());
}
-
diff --git a/source/Core/ArchSpec.cpp b/source/Core/ArchSpec.cpp
index ffe717f29c43..24aba81350a6 100644
--- a/source/Core/ArchSpec.cpp
+++ b/source/Core/ArchSpec.cpp
@@ -9,16 +9,19 @@
#include "lldb/Core/ArchSpec.h"
-#include <stdio.h>
-#include <errno.h>
-
+// C Includes
+// C++ Includes
+#include <cstdio>
+#include <cerrno>
#include <string>
+// Other libraries and framework includes
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/COFF.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/Host.h"
+// Project includes
#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/StringList.h"
#include "lldb/Host/Endian.h"
@@ -35,9 +38,6 @@
using namespace lldb;
using namespace lldb_private;
-#define ARCH_SPEC_SEPARATOR_CHAR '-'
-
-
static bool cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_inverse, bool enforce_exact_match);
namespace lldb_private {
@@ -53,7 +53,7 @@ namespace lldb_private {
const char * const name;
};
-}
+} // namespace lldb_private
// This core information can be looked using the ArchSpec::Core as the index
static const CoreDefinition g_core_definitions[] =
@@ -130,6 +130,8 @@ static const CoreDefinition g_core_definitions[] =
{ eByteOrderBig , 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_generic , "powerpc64" },
{ eByteOrderBig , 8, 4, 4, llvm::Triple::ppc64 , ArchSpec::eCore_ppc64_ppc970_64 , "ppc970-64" },
+ { eByteOrderBig , 8, 2, 6, llvm::Triple::systemz, ArchSpec::eCore_s390x_generic , "s390x" },
+
{ eByteOrderLittle, 4, 4, 4, llvm::Triple::sparc , ArchSpec::eCore_sparc_generic , "sparc" },
{ eByteOrderLittle, 8, 4, 4, llvm::Triple::sparcv9, ArchSpec::eCore_sparc9_generic , "sparcv9" },
@@ -156,7 +158,6 @@ static const CoreDefinition g_core_definitions[] =
// you will need to comment out the corresponding ArchSpec::Core enumeration.
static_assert(sizeof(g_core_definitions) / sizeof(CoreDefinition) == ArchSpec::kNumCores, "make sure we have one core definition for each core");
-
struct ArchDefinitionEntry
{
ArchSpec::Core core;
@@ -174,14 +175,12 @@ struct ArchDefinition
const char *name;
};
-
size_t
ArchSpec::AutoComplete (const char *name, StringList &matches)
{
- uint32_t i;
if (name && name[0])
{
- for (i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
+ for (uint32_t i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
{
if (NameMatches(g_core_definitions[i].name, eNameMatchStartsWith, name))
matches.AppendString (g_core_definitions[i].name);
@@ -189,14 +188,12 @@ ArchSpec::AutoComplete (const char *name, StringList &matches)
}
else
{
- for (i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
+ for (uint32_t i = 0; i < llvm::array_lengthof(g_core_definitions); ++i)
matches.AppendString (g_core_definitions[i].name);
}
return matches.GetSize();
}
-
-
#define CPU_ANY (UINT32_MAX)
//===----------------------------------------------------------------------===//
@@ -205,6 +202,7 @@ ArchSpec::AutoComplete (const char *name, StringList &matches)
// architecture names to cpu types and subtypes. The ordering is important and
// allows the precedence to be set when the table is built.
#define SUBTYPE_MASK 0x00FFFFFFu
+
static const ArchDefinitionEntry g_macho_arch_entries[] =
{
{ ArchSpec::eCore_arm_generic , llvm::MachO::CPU_TYPE_ARM , CPU_ANY, UINT32_MAX , UINT32_MAX },
@@ -267,6 +265,7 @@ static const ArchDefinitionEntry g_macho_arch_entries[] =
{ ArchSpec::eCore_uknownMach32 , 0 , 0 , 0xFF000000u, 0x00000000u },
{ ArchSpec::eCore_uknownMach64 , llvm::MachO::CPU_ARCH_ABI64 , 0 , 0xFF000000u, 0x00000000u }
};
+
static const ArchDefinition g_macho_arch_def = {
eArchTypeMachO,
llvm::array_lengthof(g_macho_arch_entries),
@@ -288,6 +287,7 @@ static const ArchDefinitionEntry g_elf_arch_entries[] =
{ ArchSpec::eCore_ppc64_generic , llvm::ELF::EM_PPC64 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC64
{ ArchSpec::eCore_arm_generic , llvm::ELF::EM_ARM , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARM
{ ArchSpec::eCore_arm_aarch64 , llvm::ELF::EM_AARCH64, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARM64
+ { ArchSpec::eCore_s390x_generic , llvm::ELF::EM_S390 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // SystemZ
{ ArchSpec::eCore_sparc9_generic , llvm::ELF::EM_SPARCV9, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // SPARC V9
{ ArchSpec::eCore_x86_64_x86_64 , llvm::ELF::EM_X86_64 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // AMD64
{ ArchSpec::eCore_mips32 , llvm::ELF::EM_MIPS , ArchSpec::eMIPSSubType_mips32, 0xFFFFFFFFu, 0xFFFFFFFFu }, // mips32
@@ -346,7 +346,6 @@ static const size_t k_num_arch_definitions = llvm::array_lengthof(g_arch_definit
//===----------------------------------------------------------------------===//
// Static helper functions.
-
// Get the architecture definition for a given object type.
static const ArchDefinition *
FindArchDefinition (ArchitectureType arch_type)
@@ -357,7 +356,7 @@ FindArchDefinition (ArchitectureType arch_type)
if (def->type == arch_type)
return def;
}
- return NULL;
+ return nullptr;
}
// Get an architecture definition by name.
@@ -369,7 +368,7 @@ FindCoreDefinition (llvm::StringRef name)
if (name.equals_lower(g_core_definitions[i].name))
return &g_core_definitions[i];
}
- return NULL;
+ return nullptr;
}
static inline const CoreDefinition *
@@ -377,15 +376,15 @@ FindCoreDefinition (ArchSpec::Core core)
{
if (core >= 0 && core < llvm::array_lengthof(g_core_definitions))
return &g_core_definitions[core];
- return NULL;
+ return nullptr;
}
// Get a definition entry by cpu type and subtype.
static const ArchDefinitionEntry *
FindArchDefinitionEntry (const ArchDefinition *def, uint32_t cpu, uint32_t sub)
{
- if (def == NULL)
- return NULL;
+ if (def == nullptr)
+ return nullptr;
const ArchDefinitionEntry *entries = def->entries;
for (size_t i = 0; i < def->num_entries; ++i)
@@ -394,14 +393,14 @@ FindArchDefinitionEntry (const ArchDefinition *def, uint32_t cpu, uint32_t sub)
if (entries[i].sub == (sub & entries[i].sub_mask))
return &entries[i];
}
- return NULL;
+ return nullptr;
}
static const ArchDefinitionEntry *
FindArchDefinitionEntry (const ArchDefinition *def, ArchSpec::Core core)
{
- if (def == NULL)
- return NULL;
+ if (def == nullptr)
+ return nullptr;
const ArchDefinitionEntry *entries = def->entries;
for (size_t i = 0; i < def->num_entries; ++i)
@@ -409,7 +408,7 @@ FindArchDefinitionEntry (const ArchDefinition *def, ArchSpec::Core core)
if (entries[i].core == core)
return &entries[i];
}
- return NULL;
+ return nullptr;
}
//===----------------------------------------------------------------------===//
@@ -467,9 +466,7 @@ ArchSpec::ArchSpec (ArchitectureType arch_type, uint32_t cpu, uint32_t subtype)
SetArchitecture (arch_type, cpu, subtype);
}
-ArchSpec::~ArchSpec()
-{
-}
+ArchSpec::~ArchSpec() = default;
//===----------------------------------------------------------------------===//
// Assignment and initialization.
@@ -501,7 +498,6 @@ ArchSpec::Clear()
//===----------------------------------------------------------------------===//
// Predicates.
-
const char *
ArchSpec::GetArchitectureName () const
{
@@ -511,6 +507,68 @@ ArchSpec::GetArchitectureName () const
return "unknown";
}
+bool
+ArchSpec::IsMIPS() const
+{
+ const llvm::Triple::ArchType machine = GetMachine();
+ if(machine == llvm::Triple::mips ||
+ machine == llvm::Triple::mipsel ||
+ machine == llvm::Triple::mips64 ||
+ machine == llvm::Triple::mips64el)
+ return true;
+ return false;
+}
+
+std::string
+ArchSpec::GetClangTargetCPU ()
+{
+ std::string cpu;
+ const llvm::Triple::ArchType machine = GetMachine();
+
+ if (machine == llvm::Triple::mips ||
+ machine == llvm::Triple::mipsel ||
+ machine == llvm::Triple::mips64 ||
+ machine == llvm::Triple::mips64el)
+ {
+ switch (m_core)
+ {
+ case ArchSpec::eCore_mips32:
+ case ArchSpec::eCore_mips32el:
+ cpu = "mips32"; break;
+ case ArchSpec::eCore_mips32r2:
+ case ArchSpec::eCore_mips32r2el:
+ cpu = "mips32r2"; break;
+ case ArchSpec::eCore_mips32r3:
+ case ArchSpec::eCore_mips32r3el:
+ cpu = "mips32r3"; break;
+ case ArchSpec::eCore_mips32r5:
+ case ArchSpec::eCore_mips32r5el:
+ cpu = "mips32r5"; break;
+ case ArchSpec::eCore_mips32r6:
+ case ArchSpec::eCore_mips32r6el:
+ cpu = "mips32r6"; break;
+ case ArchSpec::eCore_mips64:
+ case ArchSpec::eCore_mips64el:
+ cpu = "mips64"; break;
+ case ArchSpec::eCore_mips64r2:
+ case ArchSpec::eCore_mips64r2el:
+ cpu = "mips64r2"; break;
+ case ArchSpec::eCore_mips64r3:
+ case ArchSpec::eCore_mips64r3el:
+ cpu = "mips64r3"; break;
+ case ArchSpec::eCore_mips64r5:
+ case ArchSpec::eCore_mips64r5el:
+ cpu = "mips64r5"; break;
+ case ArchSpec::eCore_mips64r6:
+ case ArchSpec::eCore_mips64r6el:
+ cpu = "mips64r6"; break;
+ default:
+ break;
+ }
+ }
+ return cpu;
+}
+
uint32_t
ArchSpec::GetMachOCPUType () const
{
@@ -680,7 +738,6 @@ ArchSpec::SetTriple (const llvm::Triple &triple)
Clear();
}
-
return IsValid();
}
@@ -690,7 +747,7 @@ ParseMachCPUDashSubtypeTriple (const char *triple_cstr, ArchSpec &arch)
// Accept "12-10" or "12.10" as cpu type/subtype
if (isdigit(triple_cstr[0]))
{
- char *end = NULL;
+ char *end = nullptr;
errno = 0;
uint32_t cpu = (uint32_t)::strtoul (triple_cstr, &end, 0);
if (errno == 0 && cpu != 0 && end && ((*end == '-') || (*end == '.')))
@@ -729,6 +786,7 @@ ParseMachCPUDashSubtypeTriple (const char *triple_cstr, ArchSpec &arch)
}
return false;
}
+
bool
ArchSpec::SetTriple (const char *triple_cstr)
{
@@ -855,6 +913,17 @@ ArchSpec::MergeFrom(const ArchSpec &other)
if (other.TripleVendorWasSpecified())
GetTriple().setEnvironment(other.GetTriple().getEnvironment());
}
+ // If this and other are both arm ArchSpecs and this ArchSpec is a generic "some kind of arm"
+ // spec but the other ArchSpec is a specific arm core, adopt the specific arm core.
+ if (GetTriple().getArch() == llvm::Triple::arm
+ && other.GetTriple().getArch() == llvm::Triple::arm
+ && IsCompatibleMatch (other)
+ && GetCore() == ArchSpec::eCore_arm_generic
+ && other.GetCore() != ArchSpec::eCore_arm_generic)
+ {
+ m_core = other.GetCore();
+ CoreUpdated (true);
+ }
}
bool
@@ -945,6 +1014,30 @@ ArchSpec::IsCompatibleMatch (const ArchSpec& rhs) const
return IsEqualTo (rhs, false);
}
+static bool
+isCompatibleEnvironment(llvm::Triple::EnvironmentType lhs, llvm::Triple::EnvironmentType rhs)
+{
+ if (lhs == rhs)
+ return true;
+
+ // If any of the environment is unknown then they are compatible
+ if (lhs == llvm::Triple::UnknownEnvironment || rhs == llvm::Triple::UnknownEnvironment)
+ return true;
+
+ // If one of the environment is Android and the other one is EABI then they are considered to
+ // be compatible. This is required as a workaround for shared libraries compiled for Android
+ // without the NOTE section indicating that they are using the Android ABI.
+ if ((lhs == llvm::Triple::Android && rhs == llvm::Triple::EABI) ||
+ (rhs == llvm::Triple::Android && lhs == llvm::Triple::EABI) ||
+ (lhs == llvm::Triple::GNUEABI && rhs == llvm::Triple::EABI) ||
+ (rhs == llvm::Triple::GNUEABI && lhs == llvm::Triple::EABI) ||
+ (lhs == llvm::Triple::GNUEABIHF && rhs == llvm::Triple::EABIHF) ||
+ (rhs == llvm::Triple::GNUEABIHF && lhs == llvm::Triple::EABIHF))
+ return true;
+
+ return false;
+}
+
bool
ArchSpec::IsEqualTo (const ArchSpec& rhs, bool exact_match) const
{
@@ -999,14 +1092,9 @@ ArchSpec::IsEqualTo (const ArchSpec& rhs, bool exact_match) const
const llvm::Triple::EnvironmentType lhs_triple_env = lhs_triple.getEnvironment();
const llvm::Triple::EnvironmentType rhs_triple_env = rhs_triple.getEnvironment();
-
- if (lhs_triple_env != rhs_triple_env)
- {
- // Only fail if both environment types are not unknown
- if (lhs_triple_env != llvm::Triple::UnknownEnvironment &&
- rhs_triple_env != llvm::Triple::UnknownEnvironment)
- return false;
- }
+
+ if (!isCompatibleEnvironment(lhs_triple_env, rhs_triple_env))
+ return false;
return true;
}
return false;
@@ -1050,7 +1138,7 @@ cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_in
case ArchSpec::eCore_arm_generic:
if (enforce_exact_match)
break;
- // Fall through to case below
+ LLVM_FALLTHROUGH;
case ArchSpec::kCore_arm_any:
if (core2 >= ArchSpec::kCore_arm_first && core2 <= ArchSpec::kCore_arm_last)
return true;
@@ -1207,6 +1295,7 @@ cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_in
return true;
try_inverse = false;
}
+ break;
case ArchSpec::eCore_mips64:
if (!enforce_exact_match)
@@ -1217,6 +1306,7 @@ cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_in
return true;
try_inverse = false;
}
+ break;
case ArchSpec::eCore_mips64el:
if (!enforce_exact_match)
@@ -1227,6 +1317,7 @@ cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_in
return true;
try_inverse = false;
}
+ break;
case ArchSpec::eCore_mips64r2:
case ArchSpec::eCore_mips64r3:
@@ -1287,7 +1378,6 @@ cores_match (const ArchSpec::Core core1, const ArchSpec::Core core2, bool try_in
{
if (core2 == ArchSpec::eCore_mips32el || core2 == ArchSpec::eCore_mips32r6el)
return true;
- return true;
}
break;
@@ -1393,7 +1483,7 @@ StopInfoOverrideCallbackTypeARM(lldb_private::Thread &thread)
if (opcode <= UINT32_MAX)
{
const uint32_t condition = Bits32((uint32_t)opcode, 31, 28);
- if (ARMConditionPassed(condition, cpsr) == false)
+ if (!ARMConditionPassed(condition, cpsr))
{
// We ARE stopped on an ARM instruction whose condition doesn't
// pass so this instruction won't get executed.
@@ -1410,7 +1500,7 @@ StopInfoOverrideCallbackTypeARM(lldb_private::Thread &thread)
if (ITSTATE != 0)
{
const uint32_t condition = Bits32(ITSTATE, 7, 4);
- if (ARMConditionPassed(condition, cpsr) == false)
+ if (!ARMConditionPassed(condition, cpsr))
{
// We ARE stopped in a Thumb IT instruction on an instruction whose
// condition doesn't pass so this instruction won't get executed.
@@ -1429,7 +1519,7 @@ ArchSpec::GetStopInfoOverrideCallback () const
const llvm::Triple::ArchType machine = GetMachine();
if (machine == llvm::Triple::arm)
return StopInfoOverrideCallbackTypeARM;
- return NULL;
+ return nullptr;
}
bool
@@ -1476,6 +1566,31 @@ ArchSpec::PiecewiseTripleCompare (const ArchSpec &other,
env_different = (me.getEnvironment() != them.getEnvironment());
}
+bool
+ArchSpec::IsAlwaysThumbInstructions () const
+{
+ std::string Error;
+ if (GetTriple().getArch() == llvm::Triple::arm || GetTriple().getArch() == llvm::Triple::thumb)
+ {
+ // v. https://en.wikipedia.org/wiki/ARM_Cortex-M
+ //
+ // Cortex-M0 through Cortex-M7 are ARM processor cores which can only
+ // execute thumb instructions. We map the cores to arch names like this:
+ //
+ // Cortex-M0, Cortex-M0+, Cortex-M1: armv6m
+ // Cortex-M3: armv7m
+ // Cortex-M4, Cortex-M7: armv7em
+
+ if (GetCore() == ArchSpec::Core::eCore_arm_armv7m
+ || GetCore() == ArchSpec::Core::eCore_arm_armv7em
+ || GetCore() == ArchSpec::Core::eCore_arm_armv6m)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
void
ArchSpec::DumpTriple(Stream &s) const
{
@@ -1483,10 +1598,14 @@ ArchSpec::DumpTriple(Stream &s) const
llvm::StringRef arch_str = triple.getArchName();
llvm::StringRef vendor_str = triple.getVendorName();
llvm::StringRef os_str = triple.getOSName();
+ llvm::StringRef environ_str = triple.getEnvironmentName();
s.Printf("%s-%s-%s",
arch_str.empty() ? "*" : arch_str.str().c_str(),
vendor_str.empty() ? "*" : vendor_str.str().c_str(),
os_str.empty() ? "*" : os_str.str().c_str()
);
+
+ if (!environ_str.empty())
+ s.Printf("-%s", environ_str.str().c_str());
}
diff --git a/source/Core/Broadcaster.cpp b/source/Core/Broadcaster.cpp
index 351487401f6b..30bc78b48220 100644
--- a/source/Core/Broadcaster.cpp
+++ b/source/Core/Broadcaster.cpp
@@ -15,23 +15,26 @@
// Project includes
#include "lldb/Core/Log.h"
#include "lldb/Core/Event.h"
+#include "lldb/Core/Listener.h"
#include "lldb/Core/StreamString.h"
using namespace lldb;
using namespace lldb_private;
-Broadcaster::Broadcaster (BroadcasterManager *manager, const char *name) :
- m_broadcaster_name (name),
- m_listeners (),
- m_listeners_mutex (Mutex::eMutexTypeRecursive),
- m_hijacking_listeners(),
- m_hijacking_masks(),
- m_manager (manager)
+Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, const char *name) :
+ m_broadcaster_sp(new BroadcasterImpl(*this)),
+ m_manager_sp(manager_sp),
+ m_broadcaster_name(name)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
if (log)
log->Printf ("%p Broadcaster::Broadcaster(\"%s\")",
- static_cast<void*>(this), m_broadcaster_name.AsCString());
+ static_cast<void*>(this), GetBroadcasterName().AsCString());
+}
+
+Broadcaster::BroadcasterImpl::BroadcasterImpl(Broadcaster &broadcaster)
+ : m_broadcaster(broadcaster), m_listeners(), m_listeners_mutex(), m_hijacking_listeners(), m_hijacking_masks()
+{
}
Broadcaster::~Broadcaster()
@@ -47,35 +50,64 @@ Broadcaster::~Broadcaster()
void
Broadcaster::CheckInWithManager ()
{
- if (m_manager != NULL)
+ if (m_manager_sp)
{
- m_manager->SignUpListenersForBroadcaster(*this);
+ m_manager_sp->SignUpListenersForBroadcaster(*this);
}
}
void
-Broadcaster::Clear()
+Broadcaster::BroadcasterImpl::ListenerIterator (std::function <bool (const lldb::ListenerSP &listener_sp, uint32_t &event_mask)> const &callback)
{
- Mutex::Locker listeners_locker(m_listeners_mutex);
-
+ // Private iterator that should be used by everyone except BroadcasterImpl::RemoveListener().
+ // We have weak pointers to our listeners which means that at any point the listener can
+ // expire which means we will need to take it out of our list. To take care of this, we
+ // iterate and check that the weak pointer can be made into a valid shared pointer before
+ // we call the callback. If the weak pointer has expired, we remove it from our list.
+ collection::iterator pos = m_listeners.begin();
+ while (pos != m_listeners.end())
+ {
+ lldb::ListenerSP curr_listener_sp(pos->first.lock());
+ if (curr_listener_sp)
+ {
+ if (callback(curr_listener_sp, pos->second))
+ ++pos; // Keep iterating
+ else
+ return; // Done iterating
+ }
+ else
+ {
+ // The listener has been expired. Remove this entry.
+ pos = m_listeners.erase(pos);
+ }
+ }
+}
+
+void
+Broadcaster::BroadcasterImpl::Clear()
+{
+ std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex);
+
// Make sure the listener forgets about this broadcaster. We do
// this in the broadcaster in case the broadcaster object initiates
// the removal.
-
- collection::iterator pos, end = m_listeners.end();
- for (pos = m_listeners.begin(); pos != end; ++pos)
- pos->first->BroadcasterWillDestruct (this);
+
+ ListenerIterator([this](const lldb::ListenerSP &curr_listener_sp, uint32_t &curr_event_mask) -> bool {
+ curr_listener_sp->BroadcasterWillDestruct (&m_broadcaster);
+ return true; // Keep iterating
+ });
m_listeners.clear();
}
-const ConstString &
-Broadcaster::GetBroadcasterName ()
+
+Broadcaster *
+Broadcaster::BroadcasterImpl::GetBroadcaster()
{
- return m_broadcaster_name;
+ return &m_broadcaster;
}
bool
-Broadcaster::GetEventNames (Stream &s, uint32_t event_mask, bool prefix_with_broadcaster_name) const
+Broadcaster::BroadcasterImpl::GetEventNames (Stream &s, uint32_t event_mask, bool prefix_with_broadcaster_name) const
{
uint32_t num_names_added = 0;
if (event_mask && !m_event_names.empty())
@@ -93,7 +125,7 @@ Broadcaster::GetEventNames (Stream &s, uint32_t event_mask, bool prefix_with_bro
if (prefix_with_broadcaster_name)
{
- s.PutCString (m_broadcaster_name.GetCString());
+ s.PutCString (GetBroadcasterName());
s.PutChar('.');
}
s.PutCString(pos->second.c_str());
@@ -106,134 +138,149 @@ Broadcaster::GetEventNames (Stream &s, uint32_t event_mask, bool prefix_with_bro
}
void
-Broadcaster::AddInitialEventsToListener (Listener *listener, uint32_t requested_events)
+Broadcaster::AddInitialEventsToListener (const lldb::ListenerSP &listener_sp, uint32_t requested_events)
{
-
}
uint32_t
-Broadcaster::AddListener (Listener* listener, uint32_t event_mask)
+Broadcaster::BroadcasterImpl::AddListener (const lldb::ListenerSP &listener_sp, uint32_t event_mask)
{
- if (listener == NULL)
+ if (!listener_sp)
return 0;
- Mutex::Locker locker(m_listeners_mutex);
- collection::iterator pos, end = m_listeners.end();
+ std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex);
- collection::iterator existing_pos = end;
// See if we already have this listener, and if so, update its mask
- uint32_t taken_event_types = 0;
- for (pos = m_listeners.begin(); pos != end; ++pos)
- {
- if (pos->first == listener)
- existing_pos = pos;
- // For now don't descriminate on who gets what
- // FIXME: Implement "unique listener for this bit" mask
- // taken_event_types |= pos->second;
- }
- // Each event bit in a Broadcaster object can only be used
- // by one listener
- uint32_t available_event_types = ~taken_event_types & event_mask;
+ bool handled = false;
- if (available_event_types)
- {
- // If we didn't find our listener, add it
- if (existing_pos == end)
- {
- // Grant a new listener the available event bits
- m_listeners.push_back(std::make_pair(listener, available_event_types));
- }
- else
+ ListenerIterator([this, &listener_sp, &handled, event_mask](const lldb::ListenerSP &curr_listener_sp, uint32_t &curr_event_mask) -> bool {
+ if (curr_listener_sp == listener_sp)
{
- // Grant the existing listener the available event bits
- existing_pos->second |= available_event_types;
+ handled = true;
+ curr_event_mask |= event_mask;
+ m_broadcaster.AddInitialEventsToListener (listener_sp, event_mask);
+ return false; // Stop iterating
}
+ return true; // Keep iterating
+ });
+
+ if (!handled)
+ {
+ // Grant a new listener the available event bits
+ m_listeners.push_back(std::make_pair(lldb::ListenerWP(listener_sp), event_mask));
// Individual broadcasters decide whether they have outstanding data when a
// listener attaches, and insert it into the listener with this method.
-
- AddInitialEventsToListener (listener, available_event_types);
+ m_broadcaster.AddInitialEventsToListener (listener_sp, event_mask);
}
// Return the event bits that were granted to the listener
- return available_event_types;
+ return event_mask;
}
bool
-Broadcaster::EventTypeHasListeners (uint32_t event_type)
+Broadcaster::BroadcasterImpl::EventTypeHasListeners (uint32_t event_type)
{
- Mutex::Locker locker (m_listeners_mutex);
-
- if (m_hijacking_listeners.size() > 0 && event_type & m_hijacking_masks.back())
+ std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex);
+
+ if (!m_hijacking_listeners.empty() && event_type & m_hijacking_masks.back())
return true;
if (m_listeners.empty())
return false;
- collection::iterator pos, end = m_listeners.end();
- for (pos = m_listeners.begin(); pos != end; ++pos)
- {
- if (pos->second & event_type)
- return true;
- }
- return false;
+ bool result = false;
+ ListenerIterator([this, event_type, &result](const lldb::ListenerSP &curr_listener_sp, uint32_t &curr_event_mask) -> bool {
+
+ if (curr_event_mask & event_type)
+ {
+ result = true;
+ return false; // Stop iterating
+ }
+ else
+ {
+ return true; // Keep iterating
+ }
+ });
+ return result;
}
bool
-Broadcaster::RemoveListener (Listener* listener, uint32_t event_mask)
+Broadcaster::BroadcasterImpl::RemoveListener (lldb_private::Listener *listener, uint32_t event_mask)
{
- Mutex::Locker locker(m_listeners_mutex);
- collection::iterator pos, end = m_listeners.end();
- // See if we already have this listener, and if so, update its mask
- for (pos = m_listeners.begin(); pos != end; ++pos)
+ if (listener)
{
- if (pos->first == listener)
+ std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex);
+ collection::iterator pos = m_listeners.begin();
+ // See if we already have this listener, and if so, update its mask
+ while (pos != m_listeners.end())
{
- // Relinquish all event bits in "event_mask"
- pos->second &= ~event_mask;
- // If all bits have been relinquished then remove this listener
- if (pos->second == 0)
- m_listeners.erase (pos);
- return true;
+ lldb::ListenerSP curr_listener_sp(pos->first.lock());
+ if (curr_listener_sp)
+ {
+ if (curr_listener_sp.get() == listener)
+ {
+ // Relinquish all event bits in "event_mask"
+ pos->second &= ~event_mask;
+ // If all bits have been relinquished then remove this listener
+ if (pos->second == 0)
+ m_listeners.erase (pos);
+ return true;
+ }
+ ++pos;
+ }
+ else
+ {
+ // The listener has been destroyed since we couldn't turn the std::weak_ptr
+ // into a valid shared pointer, so we can remove it.
+ pos = m_listeners.erase (pos);
+ }
}
}
return false;
}
+bool
+Broadcaster::BroadcasterImpl::RemoveListener (const lldb::ListenerSP &listener_sp, uint32_t event_mask)
+{
+ return RemoveListener (listener_sp.get(), event_mask);
+}
+
void
-Broadcaster::BroadcastEvent (EventSP &event_sp)
+Broadcaster::BroadcasterImpl::BroadcastEvent (EventSP &event_sp)
{
return PrivateBroadcastEvent (event_sp, false);
}
void
-Broadcaster::BroadcastEventIfUnique (EventSP &event_sp)
+Broadcaster::BroadcasterImpl::BroadcastEventIfUnique (EventSP &event_sp)
{
return PrivateBroadcastEvent (event_sp, true);
}
void
-Broadcaster::PrivateBroadcastEvent (EventSP &event_sp, bool unique)
+Broadcaster::BroadcasterImpl::PrivateBroadcastEvent (EventSP &event_sp, bool unique)
{
- // Can't add a NULL event...
- if (event_sp.get() == NULL)
+ // Can't add a nullptr event...
+ if (!event_sp)
return;
// Update the broadcaster on this event
- event_sp->SetBroadcaster (this);
+ event_sp->SetBroadcaster (&m_broadcaster);
const uint32_t event_type = event_sp->GetType();
- Mutex::Locker event_types_locker(m_listeners_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex);
+
+ ListenerSP hijacking_listener_sp;
- Listener *hijacking_listener = NULL;
if (!m_hijacking_listeners.empty())
{
assert (!m_hijacking_masks.empty());
- hijacking_listener = m_hijacking_listeners.back();
+ hijacking_listener_sp = m_hijacking_listeners.back();
if ((event_type & m_hijacking_masks.back()) == 0)
- hijacking_listener = NULL;
+ hijacking_listener_sp.reset();
}
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS));
@@ -242,91 +289,106 @@ Broadcaster::PrivateBroadcastEvent (EventSP &event_sp, bool unique)
StreamString event_description;
event_sp->Dump (&event_description);
log->Printf ("%p Broadcaster(\"%s\")::BroadcastEvent (event_sp = {%s}, unique =%i) hijack = %p",
- static_cast<void*>(this), m_broadcaster_name.AsCString(""),
+ static_cast<void*>(this), GetBroadcasterName(),
event_description.GetData(), unique,
- static_cast<void*>(hijacking_listener));
+ static_cast<void*>(hijacking_listener_sp.get()));
}
- if (hijacking_listener)
+ if (hijacking_listener_sp)
{
- if (unique && hijacking_listener->PeekAtNextEventForBroadcasterWithType (this, event_type))
+ if (unique && hijacking_listener_sp->PeekAtNextEventForBroadcasterWithType (&m_broadcaster, event_type))
return;
- hijacking_listener->AddEvent (event_sp);
+ hijacking_listener_sp->AddEvent (event_sp);
}
else
{
- collection::iterator pos, end = m_listeners.end();
+ ListenerIterator([this, unique, event_type, &event_sp](const lldb::ListenerSP &curr_listener_sp, uint32_t &curr_event_mask) -> bool {
- // Iterate through all listener/mask pairs
- for (pos = m_listeners.begin(); pos != end; ++pos)
- {
- // If the listener's mask matches any bits that we just set, then
- // put the new event on its event queue.
- if (event_type & pos->second)
+ if (event_type & curr_event_mask)
{
- if (unique && pos->first->PeekAtNextEventForBroadcasterWithType (this, event_type))
- continue;
- pos->first->AddEvent (event_sp);
+ if (!unique || curr_listener_sp->PeekAtNextEventForBroadcasterWithType (&m_broadcaster, event_type) == nullptr)
+ curr_listener_sp->AddEvent (event_sp);
}
- }
+ return true; // Keep iterating
+ });
}
}
void
-Broadcaster::BroadcastEvent (uint32_t event_type, EventData *event_data)
+Broadcaster::BroadcasterImpl::BroadcastEvent (uint32_t event_type, EventData *event_data)
{
EventSP event_sp (new Event (event_type, event_data));
PrivateBroadcastEvent (event_sp, false);
}
void
-Broadcaster::BroadcastEventIfUnique (uint32_t event_type, EventData *event_data)
+Broadcaster::BroadcasterImpl::BroadcastEvent (uint32_t event_type, const lldb::EventDataSP &event_data_sp)
+{
+ EventSP event_sp (new Event (event_type, event_data_sp));
+ PrivateBroadcastEvent (event_sp, false);
+}
+
+void
+Broadcaster::BroadcasterImpl::BroadcastEventIfUnique (uint32_t event_type, EventData *event_data)
{
EventSP event_sp (new Event (event_type, event_data));
PrivateBroadcastEvent (event_sp, true);
}
bool
-Broadcaster::HijackBroadcaster (Listener *listener, uint32_t event_mask)
+Broadcaster::BroadcasterImpl::HijackBroadcaster (const lldb::ListenerSP &listener_sp, uint32_t event_mask)
{
- Mutex::Locker event_types_locker(m_listeners_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex);
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS));
if (log)
log->Printf ("%p Broadcaster(\"%s\")::HijackBroadcaster (listener(\"%s\")=%p)",
- static_cast<void*>(this), m_broadcaster_name.AsCString(""),
- listener->m_name.c_str(), static_cast<void*>(listener));
- m_hijacking_listeners.push_back(listener);
+ static_cast<void*>(this), GetBroadcasterName(),
+ listener_sp->m_name.c_str(), static_cast<void*>(listener_sp.get()));
+ m_hijacking_listeners.push_back(listener_sp);
m_hijacking_masks.push_back(event_mask);
return true;
}
bool
-Broadcaster::IsHijackedForEvent (uint32_t event_mask)
+Broadcaster::BroadcasterImpl::IsHijackedForEvent (uint32_t event_mask)
{
- Mutex::Locker event_types_locker(m_listeners_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex);
if (!m_hijacking_listeners.empty())
return (event_mask & m_hijacking_masks.back()) != 0;
return false;
}
+const char *
+Broadcaster::BroadcasterImpl::GetHijackingListenerName()
+{
+ if (m_hijacking_listeners.size())
+ {
+ return m_hijacking_listeners.back()->GetName();
+ }
+ else
+ {
+ return nullptr;
+ }
+}
+
void
-Broadcaster::RestoreBroadcaster ()
+Broadcaster::BroadcasterImpl::RestoreBroadcaster ()
{
- Mutex::Locker event_types_locker(m_listeners_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_listeners_mutex);
if (!m_hijacking_listeners.empty())
{
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS));
if (log)
{
- Listener *listener = m_hijacking_listeners.back();
+ ListenerSP listener_sp = m_hijacking_listeners.back();
log->Printf ("%p Broadcaster(\"%s\")::RestoreBroadcaster (about to pop listener(\"%s\")=%p)",
static_cast<void*>(this),
- m_broadcaster_name.AsCString(""),
- listener->m_name.c_str(), static_cast<void*>(listener));
+ GetBroadcasterName(),
+ listener_sp->m_name.c_str(), static_cast<void*>(listener_sp.get()));
}
m_hijacking_listeners.pop_back();
}
@@ -341,11 +403,7 @@ Broadcaster::GetBroadcasterClass() const
return class_name;
}
-BroadcastEventSpec::BroadcastEventSpec (const BroadcastEventSpec &rhs) :
- m_broadcaster_class (rhs.m_broadcaster_class),
- m_event_bits (rhs.m_event_bits)
-{
-}
+BroadcastEventSpec::BroadcastEventSpec(const BroadcastEventSpec &rhs) = default;
bool
BroadcastEventSpec::operator< (const BroadcastEventSpec &rhs) const
@@ -360,25 +418,24 @@ BroadcastEventSpec::operator< (const BroadcastEventSpec &rhs) const
}
}
-const BroadcastEventSpec &
-BroadcastEventSpec::operator= (const BroadcastEventSpec &rhs)
+BroadcastEventSpec &
+BroadcastEventSpec::operator=(const BroadcastEventSpec &rhs) = default;
+
+BroadcasterManager::BroadcasterManager() : m_manager_mutex()
{
- m_broadcaster_class = rhs.m_broadcaster_class;
- m_event_bits = rhs.m_event_bits;
- return *this;
}
-BroadcasterManager::BroadcasterManager() :
- m_manager_mutex(Mutex::eMutexTypeRecursive)
+lldb::BroadcasterManagerSP
+BroadcasterManager::MakeBroadcasterManager()
{
-
+ return BroadcasterManagerSP(new BroadcasterManager());
}
uint32_t
-BroadcasterManager::RegisterListenerForEvents (Listener &listener, BroadcastEventSpec event_spec)
+BroadcasterManager::RegisterListenerForEvents (const lldb::ListenerSP &listener_sp, BroadcastEventSpec event_spec)
{
- Mutex::Locker locker(m_manager_mutex);
-
+ std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
+
collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end();
uint32_t available_bits = event_spec.GetEventBits();
@@ -391,28 +448,28 @@ BroadcasterManager::RegisterListenerForEvents (Listener &listener, BroadcastEven
if (available_bits != 0)
{
- m_event_map.insert (event_listener_key (BroadcastEventSpec (event_spec.GetBroadcasterClass(), available_bits), &listener));
- m_listeners.insert(&listener);
+ m_event_map.insert (event_listener_key (BroadcastEventSpec (event_spec.GetBroadcasterClass(), available_bits), listener_sp));
+ m_listeners.insert(listener_sp);
}
return available_bits;
}
bool
-BroadcasterManager::UnregisterListenerForEvents (Listener &listener, BroadcastEventSpec event_spec)
+BroadcasterManager::UnregisterListenerForEvents (const lldb::ListenerSP &listener_sp, BroadcastEventSpec event_spec)
{
- Mutex::Locker locker(m_manager_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
bool removed_some = false;
- if (m_listeners.erase(&listener) == 0)
+ if (m_listeners.erase(listener_sp) == 0)
return false;
- ListenerMatchesAndSharedBits predicate (event_spec, listener);
+ ListenerMatchesAndSharedBits predicate (event_spec, listener_sp);
std::vector<BroadcastEventSpec> to_be_readded;
uint32_t event_bits_to_remove = event_spec.GetEventBits();
// Go through the map and delete the exact matches, and build a list of matches that weren't exact to re-add:
- while (1)
+ while (true)
{
collection::iterator iter, end_iter = m_event_map.end();
iter = find_if (m_event_map.begin(), end_iter, predicate);
@@ -437,36 +494,57 @@ BroadcasterManager::UnregisterListenerForEvents (Listener &listener, BroadcastEv
// Okay now add back the bits that weren't completely removed:
for (size_t i = 0; i < to_be_readded.size(); i++)
{
- m_event_map.insert (event_listener_key (to_be_readded[i], &listener));
+ m_event_map.insert (event_listener_key (to_be_readded[i], listener_sp));
}
return removed_some;
}
-Listener *
+ListenerSP
BroadcasterManager::GetListenerForEventSpec (BroadcastEventSpec event_spec) const
{
- Mutex::Locker locker(*(const_cast<Mutex *> (&m_manager_mutex)));
-
+ std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
+
collection::const_iterator iter, end_iter = m_event_map.end();
iter = find_if (m_event_map.begin(), end_iter, BroadcastEventSpecMatches (event_spec));
if (iter != end_iter)
return (*iter).second;
else
- return NULL;
+ return nullptr;
}
void
-BroadcasterManager::RemoveListener (Listener &listener)
+BroadcasterManager::RemoveListener(Listener *listener)
{
- Mutex::Locker locker(m_manager_mutex);
- ListenerMatches predicate (listener);
+ std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
+ ListenerMatchesPointer predicate (listener);
+ listener_collection::iterator iter = m_listeners.begin(), end_iter = m_listeners.end();
+
+ std::find_if (iter, end_iter, predicate);
+ if (iter != end_iter)
+ m_listeners.erase(iter);
+
+ while (true)
+ {
+ collection::iterator iter, end_iter = m_event_map.end();
+ iter = find_if (m_event_map.begin(), end_iter, predicate);
+ if (iter == end_iter)
+ break;
+ else
+ m_event_map.erase(iter);
+ }
+}
+void
+BroadcasterManager::RemoveListener (const lldb::ListenerSP &listener_sp)
+{
+ std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
+ ListenerMatches predicate (listener_sp);
- if (m_listeners.erase (&listener) == 0)
+ if (m_listeners.erase (listener_sp) == 0)
return;
- while (1)
+ while (true)
{
collection::iterator iter, end_iter = m_event_map.end();
iter = find_if (m_event_map.begin(), end_iter, predicate);
@@ -480,8 +558,8 @@ BroadcasterManager::RemoveListener (Listener &listener)
void
BroadcasterManager::SignUpListenersForBroadcaster (Broadcaster &broadcaster)
{
- Mutex::Locker locker(m_manager_mutex);
-
+ std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
+
collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end();
while (iter != end_iter
@@ -495,12 +573,11 @@ BroadcasterManager::SignUpListenersForBroadcaster (Broadcaster &broadcaster)
void
BroadcasterManager::Clear ()
{
- Mutex::Locker locker(m_manager_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
listener_collection::iterator end_iter = m_listeners.end();
for (listener_collection::iterator iter = m_listeners.begin(); iter != end_iter; iter++)
- (*iter)->BroadcasterManagerWillDestruct(this);
+ (*iter)->BroadcasterManagerWillDestruct(this->shared_from_this());
m_listeners.clear();
m_event_map.clear();
-
}
diff --git a/source/Core/Communication.cpp b/source/Core/Communication.cpp
index ae579d1b00ae..f1dcb95e8af0 100644
--- a/source/Core/Communication.cpp
+++ b/source/Core/Communication.cpp
@@ -9,17 +9,19 @@
// C Includes
// C++ Includes
+#include <cstring>
+
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Communication.h"
#include "lldb/Core/Connection.h"
+#include "lldb/Core/Listener.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Timer.h"
#include "lldb/Core/Event.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/ThreadLauncher.h"
-#include <string.h>
using namespace lldb;
using namespace lldb_private;
@@ -31,54 +33,47 @@ Communication::GetStaticBroadcasterClass ()
return class_name;
}
-//----------------------------------------------------------------------
-// Constructor
-//----------------------------------------------------------------------
-Communication::Communication(const char *name) :
- Broadcaster (NULL, name),
- m_connection_sp (),
- m_read_thread_enabled (false),
- m_read_thread_did_exit (false),
- m_bytes(),
- m_bytes_mutex (Mutex::eMutexTypeRecursive),
- m_write_mutex (Mutex::eMutexTypeNormal),
- m_synchronize_mutex (Mutex::eMutexTypeNormal),
- m_callback (NULL),
- m_callback_baton (NULL),
- m_close_on_eof (true)
+Communication::Communication(const char *name)
+ : Broadcaster(nullptr, name),
+ m_connection_sp(),
+ m_read_thread_enabled(false),
+ m_read_thread_did_exit(false),
+ m_bytes(),
+ m_bytes_mutex(),
+ m_write_mutex(),
+ m_synchronize_mutex(),
+ m_callback(nullptr),
+ m_callback_baton(nullptr),
+ m_close_on_eof(true)
{
- lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
- "%p Communication::Communication (name = %s)",
- this, name);
-
- SetEventName (eBroadcastBitDisconnected, "disconnected");
- SetEventName (eBroadcastBitReadThreadGotBytes, "got bytes");
- SetEventName (eBroadcastBitReadThreadDidExit, "read thread did exit");
- SetEventName (eBroadcastBitReadThreadShouldExit, "read thread should exit");
- SetEventName (eBroadcastBitPacketAvailable, "packet available");
- SetEventName (eBroadcastBitNoMorePendingInput, "no more pending input");
-
+ lldb_private::LogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
+ "%p Communication::Communication (name = %s)", this, name);
+
+ SetEventName(eBroadcastBitDisconnected, "disconnected");
+ SetEventName(eBroadcastBitReadThreadGotBytes, "got bytes");
+ SetEventName(eBroadcastBitReadThreadDidExit, "read thread did exit");
+ SetEventName(eBroadcastBitReadThreadShouldExit, "read thread should exit");
+ SetEventName(eBroadcastBitPacketAvailable, "packet available");
+ SetEventName(eBroadcastBitNoMorePendingInput, "no more pending input");
+
CheckInWithManager();
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
Communication::~Communication()
{
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
"%p Communication::~Communication (name = %s)",
- this, m_broadcaster_name.AsCString(""));
+ this, GetBroadcasterName().AsCString());
Clear();
}
void
Communication::Clear()
{
- SetReadThreadBytesReceivedCallback (NULL, NULL);
- Disconnect (NULL);
- StopReadThread (NULL);
+ SetReadThreadBytesReceivedCallback(nullptr, nullptr);
+ Disconnect(nullptr);
+ StopReadThread(nullptr);
}
ConnectionStatus
@@ -89,7 +84,7 @@ Communication::Connect (const char *url, Error *error_ptr)
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION, "%p Communication::Connect (url = %s)", this, url);
lldb::ConnectionSP connection_sp (m_connection_sp);
- if (connection_sp.get())
+ if (connection_sp)
return connection_sp->Connect (url, error_ptr);
if (error_ptr)
error_ptr->SetErrorString("Invalid connection.");
@@ -102,7 +97,7 @@ Communication::Disconnect (Error *error_ptr)
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION, "%p Communication::Disconnect ()", this);
lldb::ConnectionSP connection_sp (m_connection_sp);
- if (connection_sp.get())
+ if (connection_sp)
{
ConnectionStatus status = connection_sp->Disconnect (error_ptr);
// We currently don't protect connection_sp with any mutex for
@@ -123,16 +118,14 @@ Communication::Disconnect (Error *error_ptr)
bool
Communication::IsConnected () const
{
- lldb::ConnectionSP connection_sp (m_connection_sp);
- if (connection_sp.get())
- return connection_sp->IsConnected ();
- return false;
+ lldb::ConnectionSP connection_sp(m_connection_sp);
+ return (connection_sp ? connection_sp->IsConnected() : false);
}
bool
Communication::HasConnection () const
{
- return m_connection_sp.get() != NULL;
+ return m_connection_sp.get() != nullptr;
}
size_t
@@ -156,7 +149,7 @@ Communication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, Connectio
return cached_bytes;
}
- if (m_connection_sp.get() == NULL)
+ if (!m_connection_sp)
{
if (error_ptr)
error_ptr->SetErrorString("Invalid connection.");
@@ -171,10 +164,10 @@ Communication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, Connectio
timeout_time.OffsetWithMicroSeconds (timeout_usec);
}
- Listener listener ("Communication::Read");
- listener.StartListeningForEvents (this, eBroadcastBitReadThreadGotBytes | eBroadcastBitReadThreadDidExit);
+ ListenerSP listener_sp(Listener::MakeListener("Communication::Read"));
+ listener_sp->StartListeningForEvents (this, eBroadcastBitReadThreadGotBytes | eBroadcastBitReadThreadDidExit);
EventSP event_sp;
- while (listener.WaitForEvent (timeout_time.IsValid() ? &timeout_time : NULL, event_sp))
+ while (listener_sp->WaitForEvent (timeout_time.IsValid() ? &timeout_time : nullptr, event_sp))
{
const uint32_t event_type = event_sp->GetType();
if (event_type & eBroadcastBitReadThreadGotBytes)
@@ -185,7 +178,7 @@ Communication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, Connectio
if (event_type & eBroadcastBitReadThreadDidExit)
{
if (GetCloseOnEOF ())
- Disconnect (NULL);
+ Disconnect(nullptr);
break;
}
}
@@ -195,7 +188,7 @@ Communication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, Connectio
// We aren't using a read thread, just read the data synchronously in this
// thread.
lldb::ConnectionSP connection_sp (m_connection_sp);
- if (connection_sp.get())
+ if (connection_sp)
{
return connection_sp->Read (dst, dst_len, timeout_usec, status, error_ptr);
}
@@ -206,13 +199,12 @@ Communication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, Connectio
return 0;
}
-
size_t
Communication::Write (const void *src, size_t src_len, ConnectionStatus &status, Error *error_ptr)
{
lldb::ConnectionSP connection_sp (m_connection_sp);
- Mutex::Locker locker(m_write_mutex);
+ std::lock_guard<std::mutex> guard(m_write_mutex);
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
"%p Communication::Write (src = %p, src_len = %" PRIu64 ") connection = %p",
this,
@@ -220,7 +212,7 @@ Communication::Write (const void *src, size_t src_len, ConnectionStatus &status,
(uint64_t)src_len,
connection_sp.get());
- if (connection_sp.get())
+ if (connection_sp)
return connection_sp->Write (src, src_len, status, error_ptr);
if (error_ptr)
@@ -229,7 +221,6 @@ Communication::Write (const void *src, size_t src_len, ConnectionStatus &status,
return 0;
}
-
bool
Communication::StartReadThread (Error *error_ptr)
{
@@ -242,9 +233,8 @@ Communication::StartReadThread (Error *error_ptr)
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
"%p Communication::StartReadThread ()", this);
-
char thread_name[1024];
- snprintf(thread_name, sizeof(thread_name), "<lldb.comm.%s>", m_broadcaster_name.AsCString());
+ snprintf(thread_name, sizeof(thread_name), "<lldb.comm.%s>", GetBroadcasterName().AsCString());
m_read_thread_enabled = true;
m_read_thread_did_exit = false;
@@ -265,7 +255,7 @@ Communication::StopReadThread (Error *error_ptr)
m_read_thread_enabled = false;
- BroadcastEvent (eBroadcastBitReadThreadShouldExit, NULL);
+ BroadcastEvent(eBroadcastBitReadThreadShouldExit, nullptr);
// error = m_read_thread.Cancel();
@@ -286,12 +276,12 @@ Communication::JoinReadThread (Error *error_ptr)
size_t
Communication::GetCachedBytes (void *dst, size_t dst_len)
{
- Mutex::Locker locker(m_bytes_mutex);
- if (m_bytes.size() > 0)
+ std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex);
+ if (!m_bytes.empty())
{
- // If DST is NULL and we have a thread, then return the number
+ // If DST is nullptr and we have a thread, then return the number
// of bytes that are available so the caller can call again
- if (dst == NULL)
+ if (dst == nullptr)
return m_bytes.size();
const size_t len = std::min<size_t>(dst_len, m_bytes.size());
@@ -310,7 +300,7 @@ Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broad
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
"%p Communication::AppendBytesToCache (src = %p, src_len = %" PRIu64 ", broadcast = %i)",
this, bytes, (uint64_t)len, broadcast);
- if ((bytes == NULL || len == 0)
+ if ((bytes == nullptr || len == 0)
&& (status != lldb::eConnectionStatusEndOfFile))
return;
if (m_callback)
@@ -318,9 +308,9 @@ Communication::AppendBytesToCache (const uint8_t * bytes, size_t len, bool broad
// If the user registered a callback, then call it and do not broadcast
m_callback (m_callback_baton, bytes, len);
}
- else if (bytes != NULL && len > 0)
+ else if (bytes != nullptr && len > 0)
{
- Mutex::Locker locker(m_bytes_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex);
m_bytes.append ((const char *)bytes, len);
if (broadcast)
BroadcastEventIfUnique (eBroadcastBitReadThreadGotBytes);
@@ -334,10 +324,8 @@ Communication::ReadFromConnection (void *dst,
ConnectionStatus &status,
Error *error_ptr)
{
- lldb::ConnectionSP connection_sp (m_connection_sp);
- if (connection_sp.get())
- return connection_sp->Read (dst, dst_len, timeout_usec, status, error_ptr);
- return 0;
+ lldb::ConnectionSP connection_sp(m_connection_sp);
+ return (connection_sp ? connection_sp->Read(dst, dst_len, timeout_usec, status, error_ptr) : 0);
}
bool
@@ -403,7 +391,7 @@ Communication::ReadThread (lldb::thread_arg_t p)
case eConnectionStatusNoConnection: // No connection
case eConnectionStatusLostConnection: // Lost connection while connected to a valid connection
done = true;
- // Fall through...
+ LLVM_FALLTHROUGH;
case eConnectionStatusTimedOut: // Request timed out
if (log)
error.LogIfError (log,
@@ -425,11 +413,8 @@ Communication::ReadThread (lldb::thread_arg_t p)
}
void
-Communication::SetReadThreadBytesReceivedCallback
-(
- ReadThreadBytesReceived callback,
- void *callback_baton
-)
+Communication::SetReadThreadBytesReceivedCallback(ReadThreadBytesReceived callback,
+ void *callback_baton)
{
m_callback = callback;
m_callback_baton = callback_baton;
@@ -439,11 +424,11 @@ void
Communication::SynchronizeWithReadThread ()
{
// Only one thread can do the synchronization dance at a time.
- Mutex::Locker locker(m_synchronize_mutex);
+ std::lock_guard<std::mutex> guard(m_synchronize_mutex);
// First start listening for the synchronization event.
- Listener listener("Communication::SyncronizeWithReadThread");
- listener.StartListeningForEvents(this, eBroadcastBitNoMorePendingInput);
+ ListenerSP listener_sp(Listener::MakeListener("Communication::SyncronizeWithReadThread"));
+ listener_sp->StartListeningForEvents(this, eBroadcastBitNoMorePendingInput);
// If the thread is not running, there is no point in synchronizing.
if (!m_read_thread_enabled || m_read_thread_did_exit)
@@ -454,14 +439,14 @@ Communication::SynchronizeWithReadThread ()
// Wait for the synchronization event.
EventSP event_sp;
- listener.WaitForEvent(NULL, event_sp);
+ listener_sp->WaitForEvent(nullptr, event_sp);
}
void
Communication::SetConnection (Connection *connection)
{
- Disconnect (NULL);
- StopReadThread(NULL);
+ Disconnect(nullptr);
+ StopReadThread(nullptr);
m_connection_sp.reset(connection);
}
diff --git a/source/Core/ConnectionSharedMemory.cpp b/source/Core/ConnectionSharedMemory.cpp
index e417347579eb..707644d36b1c 100644
--- a/source/Core/ConnectionSharedMemory.cpp
+++ b/source/Core/ConnectionSharedMemory.cpp
@@ -1,4 +1,4 @@
-//===-- ConnectionSharedMemory.cpp ----------------------------*- C++ -*-===//
+//===-- ConnectionSharedMemory.cpp ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -6,13 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+
#ifndef __ANDROID_NDK__
#include "lldb/Core/ConnectionSharedMemory.h"
// C Includes
-#include <errno.h>
-#include <stdlib.h>
#ifdef _WIN32
#include "lldb/Host/windows/windows.h"
#else
@@ -23,12 +22,18 @@
#endif
// C++ Includes
+#include <cerrno>
+#include <cstdlib>
+
// Other libraries and framework includes
-// Project includes
#include "llvm/Support/MathExtras.h"
+
+// Project includes
#include "lldb/Core/Communication.h"
#include "lldb/Core/Log.h"
+#include "llvm/Support/ConvertUTF.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -42,7 +47,7 @@ ConnectionSharedMemory::ConnectionSharedMemory () :
ConnectionSharedMemory::~ConnectionSharedMemory ()
{
- Disconnect (NULL);
+ Disconnect(nullptr);
}
bool
@@ -132,18 +137,18 @@ ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error
m_name.assign (name);
#ifdef _WIN32
- HANDLE handle;
- if (create) {
- handle = CreateFileMapping(
- INVALID_HANDLE_VALUE,
- NULL,
- PAGE_READWRITE,
- llvm::Hi_32(size),
- llvm::Lo_32(size),
- name);
+ HANDLE handle = INVALID_HANDLE_VALUE;
+ std::wstring wname;
+ if (llvm::ConvertUTF8toWide(name, wname))
+ {
+ if (create)
+ {
+ handle = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, llvm::Hi_32(size),
+ llvm::Lo_32(size), wname.c_str());
+ }
+ else
+ handle = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, wname.c_str());
}
- else
- handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name);
m_fd = _open_osfhandle((intptr_t)handle, 0);
#else
@@ -159,7 +164,7 @@ ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error
if (m_mmap.MemoryMapFromFileDescriptor(m_fd, 0, size, true, false) == size)
return eConnectionStatusSuccess;
- Disconnect(NULL);
+ Disconnect(nullptr);
return eConnectionStatusError;
}
diff --git a/source/Core/ConstString.cpp b/source/Core/ConstString.cpp
index c2e95d801723..f983f1444d7c 100644
--- a/source/Core/ConstString.cpp
+++ b/source/Core/ConstString.cpp
@@ -6,14 +6,21 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+
#include "lldb/Core/ConstString.h"
-#include "lldb/Core/Stream.h"
+
+// C Includes
+// C++ Includes
+#include <array>
+#include <mutex>
+
+// Other libraries and framework includes
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/RWMutex.h"
-#include <array>
-#include <mutex>
+// Project includes
+#include "lldb/Core/Stream.h"
using namespace lldb_private;
@@ -34,7 +41,7 @@ public:
size_t
GetConstCStringLength (const char *ccstr) const
{
- if (ccstr)
+ if (ccstr != nullptr)
{
const uint8_t h = hash (llvm::StringRef(ccstr));
llvm::sys::SmartScopedReader<false> rlock(m_string_pools[h].m_mutex);
@@ -47,19 +54,19 @@ public:
StringPoolValueType
GetMangledCounterpart (const char *ccstr) const
{
- if (ccstr)
+ if (ccstr != nullptr)
{
const uint8_t h = hash (llvm::StringRef(ccstr));
llvm::sys::SmartScopedReader<false> rlock(m_string_pools[h].m_mutex);
return GetStringMapEntryFromKeyData (ccstr).getValue();
}
- return 0;
+ return nullptr;
}
bool
SetMangledCounterparts (const char *key_ccstr, const char *value_ccstr)
{
- if (key_ccstr && value_ccstr)
+ if (key_ccstr != nullptr && value_ccstr != nullptr)
{
{
const uint8_t h = hash (llvm::StringRef(key_ccstr));
@@ -79,7 +86,7 @@ public:
const char *
GetConstCString (const char *cstr)
{
- if (cstr)
+ if (cstr != nullptr)
return GetConstCStringWithLength (cstr, strlen (cstr));
return nullptr;
}
@@ -87,7 +94,7 @@ public:
const char *
GetConstCStringWithLength (const char *cstr, size_t cstr_len)
{
- if (cstr)
+ if (cstr != nullptr)
return GetConstCStringWithStringRef(llvm::StringRef(cstr, cstr_len));
return nullptr;
}
@@ -116,7 +123,7 @@ public:
const char *
GetConstCStringAndSetMangledCounterPart (const char *demangled_cstr, const char *mangled_ccstr)
{
- if (demangled_cstr)
+ if (demangled_cstr != nullptr)
{
const char *demangled_ccstr = nullptr;
@@ -150,7 +157,7 @@ public:
const char *
GetConstTrimmedCStringWithLength (const char *cstr, size_t cstr_len)
{
- if (cstr)
+ if (cstr != nullptr)
{
const size_t trimmed_len = std::min<size_t> (strlen (cstr), cstr_len);
return GetConstCStringWithLength (cstr, trimmed_len);
@@ -253,7 +260,7 @@ Stream&
lldb_private::operator << (Stream& s, const ConstString& str)
{
const char *cstr = str.GetCString();
- if (cstr)
+ if (cstr != nullptr)
s << cstr;
return s;
@@ -265,8 +272,25 @@ ConstString::GetLength () const
return StringPool().GetConstCStringLength (m_string);
}
+bool
+ConstString::Equals(const ConstString &lhs, const ConstString &rhs, const bool case_sensitive)
+{
+ if (lhs.m_string == rhs.m_string)
+ return true;
+
+ // Since the pointers weren't equal, and identical ConstStrings always have identical pointers,
+ // the result must be false for case sensitive equality test.
+ if (case_sensitive)
+ return false;
+
+ // perform case insensitive equality test
+ llvm::StringRef lhs_string_ref(lhs.m_string, StringPool().GetConstCStringLength(lhs.m_string));
+ llvm::StringRef rhs_string_ref(rhs.m_string, StringPool().GetConstCStringLength(rhs.m_string));
+ return lhs_string_ref.equals_lower(rhs_string_ref);
+}
+
int
-ConstString::Compare (const ConstString& lhs, const ConstString& rhs)
+ConstString::Compare(const ConstString &lhs, const ConstString &rhs, const bool case_sensitive)
{
// If the iterators are the same, this is the same string
const char *lhs_cstr = lhs.m_string;
@@ -277,22 +301,30 @@ ConstString::Compare (const ConstString& lhs, const ConstString& rhs)
{
llvm::StringRef lhs_string_ref (lhs_cstr, StringPool().GetConstCStringLength (lhs_cstr));
llvm::StringRef rhs_string_ref (rhs_cstr, StringPool().GetConstCStringLength (rhs_cstr));
- return lhs_string_ref.compare(rhs_string_ref);
+
+ if (case_sensitive)
+ {
+ return lhs_string_ref.compare(rhs_string_ref);
+ }
+ else
+ {
+ return lhs_string_ref.compare_lower(rhs_string_ref);
+ }
}
if (lhs_cstr)
- return +1; // LHS isn't NULL but RHS is
+ return +1; // LHS isn't nullptr but RHS is
else
- return -1; // LHS is NULL but RHS isn't
+ return -1; // LHS is nullptr but RHS isn't
}
void
ConstString::Dump(Stream *s, const char *fail_value) const
{
- if (s)
+ if (s != nullptr)
{
const char *cstr = AsCString (fail_value);
- if (cstr)
+ if (cstr != nullptr)
s->PutCString (cstr);
}
}
@@ -302,7 +334,7 @@ ConstString::DumpDebug(Stream *s) const
{
const char *cstr = GetCString ();
size_t cstr_len = GetLength();
- // Only print the parens if we have a non-NULL string
+ // Only print the parens if we have a non-nullptr string
const char *parens = cstr ? "\"" : "";
s->Printf("%*p: ConstString, string = %s%s%s, length = %" PRIu64,
static_cast<int>(sizeof(void*) * 2),
diff --git a/source/Core/CxaDemangle.cpp b/source/Core/CxaDemangle.cpp
index 7d21138c2899..62335a9175cd 100644
--- a/source/Core/CxaDemangle.cpp
+++ b/source/Core/CxaDemangle.cpp
@@ -20,6 +20,7 @@
#include "lldb/Host/windows/win32.h" // snprintf
#endif
#include "llvm/Support/Compiler.h" // LLVM_{NOEXCEPT, CONSTEXPR, ALIGNAS}
+#include "lldb/lldb-private.h"
#undef _LIBCPP_EXTERN_TEMPLATE // Avoid warning below
//===-------------------------- cxa_demangle.cpp --------------------------===//
@@ -2262,7 +2263,7 @@ parse_type(const char* first, const char* last, C& db)
break;
}
}
- // drop through
+ LLVM_FALLTHROUGH;
default:
// must check for builtin-types before class-enum-types to avoid
// ambiguities with operator-names
diff --git a/source/Core/DataBufferHeap.cpp b/source/Core/DataBufferHeap.cpp
index ba1314448bbd..4e5389e053e9 100644
--- a/source/Core/DataBufferHeap.cpp
+++ b/source/Core/DataBufferHeap.cpp
@@ -9,6 +9,11 @@
#include "lldb/Core/DataBufferHeap.h"
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+
using namespace lldb_private;
//----------------------------------------------------------------------
@@ -44,32 +49,26 @@ DataBufferHeap::DataBufferHeap (const void *src, lldb::offset_t src_len) :
// Virtual destructor since this class inherits from a pure virtual
// base class.
//----------------------------------------------------------------------
-DataBufferHeap::~DataBufferHeap ()
-{
-}
+DataBufferHeap::~DataBufferHeap() = default;
//----------------------------------------------------------------------
-// Return a pointer to the bytes owned by this object, or NULL if
+// Return a pointer to the bytes owned by this object, or nullptr if
// the object contains no bytes.
//----------------------------------------------------------------------
uint8_t *
DataBufferHeap::GetBytes ()
{
- if (m_data.empty())
- return NULL;
- return &m_data[0];
+ return (m_data.empty() ? nullptr : m_data.data());
}
//----------------------------------------------------------------------
-// Return a const pointer to the bytes owned by this object, or NULL
+// Return a const pointer to the bytes owned by this object, or nullptr
// if the object contains no bytes.
//----------------------------------------------------------------------
const uint8_t *
DataBufferHeap::GetBytes () const
{
- if (m_data.empty())
- return NULL;
- return &m_data[0];
+ return (m_data.empty() ? nullptr : m_data.data());
}
//----------------------------------------------------------------------
@@ -81,7 +80,6 @@ DataBufferHeap::GetByteSize () const
return m_data.size();
}
-
//----------------------------------------------------------------------
// Sets the number of bytes that this object should be able to
// contain. This can be used prior to copying data into the buffer.
diff --git a/source/Core/DataBufferMemoryMap.cpp b/source/Core/DataBufferMemoryMap.cpp
index b3211b35af85..48fe9e58d07d 100644
--- a/source/Core/DataBufferMemoryMap.cpp
+++ b/source/Core/DataBufferMemoryMap.cpp
@@ -7,19 +7,44 @@
//
//===----------------------------------------------------------------------===//
-
-#include <errno.h>
+// C Includes
#include <fcntl.h>
-#include <limits.h>
#include <sys/stat.h>
#ifdef _WIN32
#include "lldb/Host/windows/windows.h"
#else
#include <sys/mman.h>
-#endif
+#define MAP_EXTRA_HOST_READ_FLAGS 0
+
+#if defined (__APPLE__)
+//----------------------------------------------------------------------
+// Newer versions of MacOSX have a flag that will allow us to read from
+// binaries whose code signature is invalid without crashing by using
+// the MAP_RESILIENT_CODESIGN flag. Also if a file from removable media
+// is mapped we can avoid crashing and return zeroes to any pages we try
+// to read if the media becomes unavailable by using the
+// MAP_RESILIENT_MEDIA flag.
+//----------------------------------------------------------------------
+#if defined(MAP_RESILIENT_CODESIGN)
+ #undef MAP_EXTRA_HOST_READ_FLAGS
+ #if defined(MAP_RESILIENT_MEDIA)
+ #define MAP_EXTRA_HOST_READ_FLAGS MAP_RESILIENT_CODESIGN | MAP_RESILIENT_MEDIA
+ #else
+ #define MAP_EXTRA_HOST_READ_FLAGS MAP_RESILIENT_CODESIGN
+ #endif
+#endif // #if defined(MAP_RESILIENT_CODESIGN)
+#endif // #if defined (__APPLE__)
+
+#endif // #else #ifdef _WIN32
+// C++ Includes
+#include <cerrno>
+#include <climits>
+
+// Other libraries and framework includes
#include "llvm/Support/MathExtras.h"
+// Project includes
#include "lldb/Core/DataBufferMemoryMap.h"
#include "lldb/Core/Error.h"
#include "lldb/Host/File.h"
@@ -34,9 +59,9 @@ using namespace lldb_private;
// Default Constructor
//----------------------------------------------------------------------
DataBufferMemoryMap::DataBufferMemoryMap() :
- m_mmap_addr(NULL),
+ m_mmap_addr(nullptr),
m_mmap_size(0),
- m_data(NULL),
+ m_data(nullptr),
m_size(0)
{
}
@@ -51,7 +76,7 @@ DataBufferMemoryMap::~DataBufferMemoryMap()
}
//----------------------------------------------------------------------
-// Return a pointer to the bytes owned by this object, or NULL if
+// Return a pointer to the bytes owned by this object, or nullptr if
// the object contains no bytes.
//----------------------------------------------------------------------
uint8_t *
@@ -61,7 +86,7 @@ DataBufferMemoryMap::GetBytes()
}
//----------------------------------------------------------------------
-// Return a const pointer to the bytes owned by this object, or NULL
+// Return a const pointer to the bytes owned by this object, or nullptr
// if the object contains no bytes.
//----------------------------------------------------------------------
const uint8_t *
@@ -86,7 +111,7 @@ DataBufferMemoryMap::GetByteSize() const
void
DataBufferMemoryMap::Clear()
{
- if (m_mmap_addr != NULL)
+ if (m_mmap_addr != nullptr)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_MMAP));
if (log)
@@ -97,9 +122,9 @@ DataBufferMemoryMap::Clear()
#else
::munmap((void *)m_mmap_addr, m_mmap_size);
#endif
- m_mmap_addr = NULL;
+ m_mmap_addr = nullptr;
m_mmap_size = 0;
- m_data = NULL;
+ m_data = nullptr;
m_size = 0;
}
}
@@ -118,7 +143,7 @@ DataBufferMemoryMap::MemoryMapFromFileSpec (const FileSpec* filespec,
size_t length,
bool writeable)
{
- if (filespec != NULL)
+ if (filespec != nullptr)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_MMAP));
if (log)
@@ -150,7 +175,6 @@ DataBufferMemoryMap::MemoryMapFromFileSpec (const FileSpec* filespec,
return 0;
}
-
#ifdef _WIN32
static size_t win32memmapalignment = 0;
void LoadWin32MemMapAlignment ()
@@ -208,8 +232,8 @@ DataBufferMemoryMap::MemoryMapFromFileDescriptor (int fd,
if (length > 0)
{
- HANDLE fileMapping = CreateFileMapping(handle, NULL, writeable ? PAGE_READWRITE : PAGE_READONLY, file_size_high, file_size_low, NULL);
- if (fileMapping != NULL)
+ HANDLE fileMapping = CreateFileMapping(handle, nullptr, writeable ? PAGE_READWRITE : PAGE_READONLY, file_size_high, file_size_low, nullptr);
+ if (fileMapping != nullptr)
{
if (win32memmapalignment == 0) LoadWin32MemMapAlignment();
lldb::offset_t realoffset = offset;
@@ -252,14 +276,16 @@ DataBufferMemoryMap::MemoryMapFromFileDescriptor (int fd,
if (length > 0)
{
int prot = PROT_READ;
+ int flags = MAP_PRIVATE;
if (writeable)
prot |= PROT_WRITE;
+ else
+ flags |= MAP_EXTRA_HOST_READ_FLAGS;
- int flags = MAP_PRIVATE;
if (fd_is_file)
flags |= MAP_FILE;
- m_mmap_addr = (uint8_t *)::mmap(NULL, length, prot, flags, fd, offset);
+ m_mmap_addr = (uint8_t *)::mmap(nullptr, length, prot, flags, fd, offset);
Error error;
if (m_mmap_addr == (void*)-1)
@@ -271,13 +297,13 @@ DataBufferMemoryMap::MemoryMapFromFileDescriptor (int fd,
size_t page_offset = offset % HostInfo::GetPageSize();
if (page_offset != 0)
{
- m_mmap_addr = (uint8_t *)::mmap(NULL, length + page_offset, prot, flags, fd, offset - page_offset);
+ m_mmap_addr = (uint8_t *)::mmap(nullptr, length + page_offset, prot, flags, fd, offset - page_offset);
if (m_mmap_addr == (void*)-1)
{
// Failed to map file
- m_mmap_addr = NULL;
+ m_mmap_addr = nullptr;
}
- else if (m_mmap_addr != NULL)
+ else if (m_mmap_addr != nullptr)
{
// We recovered and were able to memory map
// after we aligned things to page boundaries
diff --git a/source/Core/DataEncoder.cpp b/source/Core/DataEncoder.cpp
index 040d09647562..3ef829507704 100644
--- a/source/Core/DataEncoder.cpp
+++ b/source/Core/DataEncoder.cpp
@@ -1,4 +1,4 @@
-//===-- DataEncoder.cpp ---------------------------------------*- C++ -*-===//
+//===-- DataEncoder.cpp -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -9,11 +9,15 @@
#include "lldb/Core/DataEncoder.h"
-#include <assert.h>
-#include <stddef.h>
+// C Includes
+// C++ Includes
+#include <cassert>
+#include <cstddef>
+// Other libraries and framework includes
#include "llvm/Support/MathExtras.h"
+// Project includes
#include "lldb/Core/DataBuffer.h"
#include "lldb/Host/Endian.h"
@@ -25,6 +29,7 @@ WriteInt16(unsigned char* ptr, unsigned offset, uint16_t value)
{
*(uint16_t *)(ptr + offset) = value;
}
+
static inline void
WriteInt32 (unsigned char* ptr, unsigned offset, uint32_t value)
{
@@ -59,11 +64,11 @@ WriteSwappedInt64(unsigned char* ptr, unsigned offset, uint64_t value)
// Default constructor.
//----------------------------------------------------------------------
DataEncoder::DataEncoder () :
- m_start (NULL),
- m_end (NULL),
+ m_start(nullptr),
+ m_end(nullptr),
m_byte_order(endian::InlHostByteOrder()),
- m_addr_size (sizeof(void*)),
- m_data_sp ()
+ m_addr_size(sizeof(void*)),
+ m_data_sp()
{
}
@@ -88,21 +93,16 @@ DataEncoder::DataEncoder (void* data, uint32_t length, ByteOrder endian, uint8_t
// this data.
//----------------------------------------------------------------------
DataEncoder::DataEncoder (const DataBufferSP& data_sp, ByteOrder endian, uint8_t addr_size) :
- m_start (NULL),
- m_end (NULL),
+ m_start(nullptr),
+ m_end(nullptr),
m_byte_order(endian),
- m_addr_size (addr_size),
- m_data_sp ()
+ m_addr_size(addr_size),
+ m_data_sp()
{
SetData (data_sp);
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-DataEncoder::~DataEncoder ()
-{
-}
+DataEncoder::~DataEncoder() = default;
//------------------------------------------------------------------
// Clears the object contents back to a default invalid state, and
@@ -112,8 +112,8 @@ DataEncoder::~DataEncoder ()
void
DataEncoder::Clear ()
{
- m_start = NULL;
- m_end = NULL;
+ m_start = nullptr;
+ m_end = nullptr;
m_byte_order = endian::InlHostByteOrder();
m_addr_size = sizeof(void*);
m_data_sp.reset();
@@ -126,13 +126,13 @@ DataEncoder::Clear ()
size_t
DataEncoder::GetSharedDataOffset () const
{
- if (m_start != NULL)
+ if (m_start != nullptr)
{
const DataBuffer * data = m_data_sp.get();
- if (data != NULL)
+ if (data != nullptr)
{
const uint8_t * data_bytes = data->GetBytes();
- if (data_bytes != NULL)
+ if (data_bytes != nullptr)
{
assert(m_start >= data_bytes);
return m_start - data_bytes;
@@ -157,10 +157,10 @@ DataEncoder::SetData (void *bytes, uint32_t length, ByteOrder endian)
{
m_byte_order = endian;
m_data_sp.reset();
- if (bytes == NULL || length == 0)
+ if (bytes == nullptr || length == 0)
{
- m_start = NULL;
- m_end = NULL;
+ m_start = nullptr;
+ m_end = nullptr;
}
else
{
@@ -187,12 +187,12 @@ DataEncoder::SetData (void *bytes, uint32_t length, ByteOrder endian)
uint32_t
DataEncoder::SetData (const DataBufferSP& data_sp, uint32_t data_offset, uint32_t data_length)
{
- m_start = m_end = NULL;
+ m_start = m_end = nullptr;
if (data_length > 0)
{
m_data_sp = data_sp;
- if (data_sp.get())
+ if (data_sp)
{
const size_t data_size = data_sp->GetByteSize();
if (data_offset < data_size)
@@ -309,7 +309,7 @@ DataEncoder::PutMaxU64 (uint32_t offset, uint32_t byte_size, uint64_t value)
uint32_t
DataEncoder::PutData (uint32_t offset, const void *src, uint32_t src_len)
{
- if (src == NULL || src_len == 0)
+ if (src == nullptr || src_len == 0)
return offset;
if (ValidOffsetForDataOfSize(offset, src_len))
@@ -329,7 +329,7 @@ DataEncoder::PutAddress (uint32_t offset, lldb::addr_t addr)
uint32_t
DataEncoder::PutCString (uint32_t offset, const char *cstr)
{
- if (cstr)
+ if (cstr != nullptr)
return PutData (offset, cstr, strlen(cstr) + 1);
return UINT32_MAX;
}
diff --git a/source/Core/DataExtractor.cpp b/source/Core/DataExtractor.cpp
index dc7857fe9cb7..84446147a363 100644
--- a/source/Core/DataExtractor.cpp
+++ b/source/Core/DataExtractor.cpp
@@ -7,17 +7,16 @@
//
//===----------------------------------------------------------------------===//
-#include <assert.h>
-#include <stddef.h>
-
+// C Includes
+// C++ Includes
#include <bitset>
-#include <limits>
+#include <cassert>
+#include <cstddef>
+#include <cmath>
#include <sstream>
#include <string>
-#include <math.h>
-
-#include "clang/AST/ASTContext.h"
+// Other libraries and framework includes
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
@@ -25,6 +24,9 @@
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MD5.h"
+#include "clang/AST/ASTContext.h"
+
+// Project includes
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/DataBuffer.h"
@@ -125,15 +127,13 @@ ReadSwapInt64(const void* ptr)
}
#define NON_PRINTABLE_CHAR '.'
-//----------------------------------------------------------------------
-// Default constructor.
-//----------------------------------------------------------------------
+
DataExtractor::DataExtractor () :
- m_start (NULL),
- m_end (NULL),
+ m_start(nullptr),
+ m_end(nullptr),
m_byte_order(endian::InlHostByteOrder()),
- m_addr_size (sizeof(void *)),
- m_data_sp (),
+ m_addr_size(sizeof(void *)),
+ m_data_sp(),
m_target_byte_size(1)
{
}
@@ -163,11 +163,11 @@ DataExtractor::DataExtractor (const void* data, offset_t length, ByteOrder endia
// this data.
//----------------------------------------------------------------------
DataExtractor::DataExtractor (const DataBufferSP& data_sp, ByteOrder endian, uint32_t addr_size, uint32_t target_byte_size/*=1*/) :
- m_start (NULL),
- m_end (NULL),
+ m_start(nullptr),
+ m_end(nullptr),
m_byte_order(endian),
- m_addr_size (addr_size),
- m_data_sp (),
+ m_addr_size(addr_size),
+ m_data_sp(),
m_target_byte_size(target_byte_size)
{
#ifdef LLDB_CONFIGURATION_DEBUG
@@ -184,8 +184,8 @@ DataExtractor::DataExtractor (const DataBufferSP& data_sp, ByteOrder endian, uin
// swap and address size settings are copied from "data".
//----------------------------------------------------------------------
DataExtractor::DataExtractor (const DataExtractor& data, offset_t offset, offset_t length, uint32_t target_byte_size/*=1*/) :
- m_start(NULL),
- m_end(NULL),
+ m_start(nullptr),
+ m_end(nullptr),
m_byte_order(data.m_byte_order),
m_addr_size(data.m_addr_size),
m_data_sp(),
@@ -233,12 +233,7 @@ DataExtractor::operator= (const DataExtractor& rhs)
return *this;
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-DataExtractor::~DataExtractor ()
-{
-}
+DataExtractor::~DataExtractor() = default;
//------------------------------------------------------------------
// Clears the object contents back to a default invalid state, and
@@ -248,8 +243,8 @@ DataExtractor::~DataExtractor ()
void
DataExtractor::Clear ()
{
- m_start = NULL;
- m_end = NULL;
+ m_start = nullptr;
+ m_end = nullptr;
m_byte_order = endian::InlHostByteOrder();
m_addr_size = sizeof(void *);
m_data_sp.reset();
@@ -262,13 +257,13 @@ DataExtractor::Clear ()
size_t
DataExtractor::GetSharedDataOffset () const
{
- if (m_start != NULL)
+ if (m_start != nullptr)
{
const DataBuffer * data = m_data_sp.get();
- if (data != NULL)
+ if (data != nullptr)
{
const uint8_t * data_bytes = data->GetBytes();
- if (data_bytes != NULL)
+ if (data_bytes != nullptr)
{
assert(m_start >= data_bytes);
return m_start - data_bytes;
@@ -293,10 +288,10 @@ DataExtractor::SetData (const void *bytes, offset_t length, ByteOrder endian)
{
m_byte_order = endian;
m_data_sp.reset();
- if (bytes == NULL || length == 0)
+ if (bytes == nullptr || length == 0)
{
- m_start = NULL;
- m_end = NULL;
+ m_start = nullptr;
+ m_end = nullptr;
}
else
{
@@ -328,7 +323,7 @@ DataExtractor::SetData (const DataExtractor& data, offset_t data_offset, offset_
assert (m_addr_size == 4 || m_addr_size == 8);
#endif
// If "data" contains shared pointer to data, then we can use that
- if (data.m_data_sp.get())
+ if (data.m_data_sp)
{
m_byte_order = data.m_byte_order;
return SetData(data.m_data_sp, data.GetSharedDataOffset() + data_offset, data_length);
@@ -361,12 +356,12 @@ DataExtractor::SetData (const DataExtractor& data, offset_t data_offset, offset_
lldb::offset_t
DataExtractor::SetData (const DataBufferSP& data_sp, offset_t data_offset, offset_t data_length)
{
- m_start = m_end = NULL;
+ m_start = m_end = nullptr;
if (data_length > 0)
{
m_data_sp = data_sp;
- if (data_sp.get())
+ if (data_sp)
{
const size_t data_size = data_sp->GetByteSize();
if (data_offset < data_size)
@@ -412,8 +407,8 @@ DataExtractor::GetU8 (offset_t *offset_ptr) const
// offset pointed to by "offset_ptr". The extracted data is copied into
// "dst".
//
-// RETURNS the non-NULL buffer pointer upon successful extraction of
-// all the requested bytes, or NULL when the data is not available in
+// RETURNS the non-nullptr buffer pointer upon successful extraction of
+// all the requested bytes, or nullptr when the data is not available in
// the buffer due to being out of bounds, or insufficient data.
//----------------------------------------------------------------------
void *
@@ -424,10 +419,10 @@ DataExtractor::GetU8 (offset_t *offset_ptr, void *dst, uint32_t count) const
{
// Copy the data into the buffer
memcpy (dst, data, count);
- // Return a non-NULL pointer to the converted data as an indicator of success
+ // Return a non-nullptr pointer to the converted data as an indicator of success
return dst;
}
- return NULL;
+ return nullptr;
}
//----------------------------------------------------------------------
@@ -487,14 +482,13 @@ DataExtractor::GetU64_unchecked (offset_t *offset_ptr) const
return val;
}
-
//----------------------------------------------------------------------
// Extract "count" uint16_t values from the binary data and update
// the offset pointed to by "offset_ptr". The extracted data is
// copied into "dst".
//
-// RETURNS the non-NULL buffer pointer upon successful extraction of
-// all the requested bytes, or NULL when the data is not available
+// RETURNS the non-nullptr buffer pointer upon successful extraction of
+// all the requested bytes, or nullptr when the data is not available
// in the buffer due to being out of bounds, or insufficient data.
//----------------------------------------------------------------------
void *
@@ -520,10 +514,10 @@ DataExtractor::GetU16 (offset_t *offset_ptr, void *void_dst, uint32_t count) con
{
memcpy (void_dst, src, src_size);
}
- // Return a non-NULL pointer to the converted data as an indicator of success
+ // Return a non-nullptr pointer to the converted data as an indicator of success
return void_dst;
}
- return NULL;
+ return nullptr;
}
//----------------------------------------------------------------------
@@ -556,8 +550,8 @@ DataExtractor::GetU32 (offset_t *offset_ptr) const
// the offset pointed to by "offset_ptr". The extracted data is
// copied into "dst".
//
-// RETURNS the non-NULL buffer pointer upon successful extraction of
-// all the requested bytes, or NULL when the data is not available
+// RETURNS the non-nullptr buffer pointer upon successful extraction of
+// all the requested bytes, or nullptr when the data is not available
// in the buffer due to being out of bounds, or insufficient data.
//----------------------------------------------------------------------
void *
@@ -583,10 +577,10 @@ DataExtractor::GetU32 (offset_t *offset_ptr, void *void_dst, uint32_t count) con
{
memcpy (void_dst, src, src_size);
}
- // Return a non-NULL pointer to the converted data as an indicator of success
+ // Return a non-nullptr pointer to the converted data as an indicator of success
return void_dst;
}
- return NULL;
+ return nullptr;
}
//----------------------------------------------------------------------
@@ -644,10 +638,10 @@ DataExtractor::GetU64 (offset_t *offset_ptr, void *void_dst, uint32_t count) con
{
memcpy (void_dst, src, src_size);
}
- // Return a non-NULL pointer to the converted data as an indicator of success
+ // Return a non-nullptr pointer to the converted data as an indicator of success
return void_dst;
}
- return NULL;
+ return nullptr;
}
//----------------------------------------------------------------------
@@ -739,8 +733,11 @@ DataExtractor::GetMaxU64Bitfield (offset_t *offset_ptr, size_t size, uint32_t bi
uint64_t uval64 = GetMaxU64 (offset_ptr, size);
if (bitfield_bit_size > 0)
{
- if (bitfield_bit_offset > 0)
- uval64 >>= bitfield_bit_offset;
+ int32_t lsbcount = bitfield_bit_offset;
+ if (m_byte_order == eByteOrderBig)
+ lsbcount = size * 8 - bitfield_bit_offset - bitfield_bit_size;
+ if (lsbcount > 0)
+ uval64 >>= lsbcount;
uint64_t bitfield_mask = ((1ul << bitfield_bit_size) - 1);
if (!bitfield_mask && bitfield_bit_offset == 0 && bitfield_bit_size == 64)
return uval64;
@@ -755,8 +752,11 @@ DataExtractor::GetMaxS64Bitfield (offset_t *offset_ptr, size_t size, uint32_t bi
int64_t sval64 = GetMaxS64 (offset_ptr, size);
if (bitfield_bit_size > 0)
{
- if (bitfield_bit_offset > 0)
- sval64 >>= bitfield_bit_offset;
+ int32_t lsbcount = bitfield_bit_offset;
+ if (m_byte_order == eByteOrderBig)
+ lsbcount = size * 8 - bitfield_bit_offset - bitfield_bit_size;
+ if (lsbcount > 0)
+ sval64 >>= lsbcount;
uint64_t bitfield_mask = (((uint64_t)1) << bitfield_bit_size) - 1;
sval64 &= bitfield_mask;
// sign extend if needed
@@ -780,7 +780,7 @@ DataExtractor::GetFloat (offset_t *offset_ptr) const
{
const uint8_t *src_data = (const uint8_t *)src;
uint8_t *dst_data = (uint8_t *)&val;
- for (size_t i=0; i<sizeof(float_type); ++i)
+ for (size_t i = 0; i < sizeof(float_type); ++i)
dst_data[sizeof(float_type) - 1 - i] = src_data[i];
}
else
@@ -804,7 +804,7 @@ DataExtractor::GetDouble (offset_t *offset_ptr) const
{
const uint8_t *src_data = (const uint8_t *)src;
uint8_t *dst_data = (uint8_t *)&val;
- for (size_t i=0; i<sizeof(float_type); ++i)
+ for (size_t i = 0; i < sizeof(float_type); ++i)
dst_data[sizeof(float_type) - 1 - i] = src_data[i];
}
else
@@ -828,7 +828,6 @@ DataExtractor::GetLongDouble (offset_t *offset_ptr) const
return val;
}
-
//------------------------------------------------------------------
// Extract a single address from the data and update the offset
// pointed to by "offset_ptr". The size of the extracted address
@@ -941,7 +940,7 @@ DataExtractor::GetGNUEHPointer (offset_t *offset_ptr, uint32_t eh_ptr_enc, lldb:
break;
default:
- break;
+ break;
}
// Decode the value part
@@ -963,9 +962,9 @@ DataExtractor::GetGNUEHPointer (offset_t *offset_ptr, uint32_t eh_ptr_enc, lldb:
case DW_EH_PE_sdata4 : addressValue = (int32_t)GetU32(offset_ptr); break;
case DW_EH_PE_sdata8 : addressValue = (int64_t)GetU64(offset_ptr); break;
default:
- // Unhandled encoding type
- assert(eh_ptr_enc);
- break;
+ // Unhandled encoding type
+ assert(eh_ptr_enc);
+ break;
}
// Since we promote everything to 64 bit, we may need to sign extend
@@ -993,7 +992,7 @@ DataExtractor::ExtractBytes (offset_t offset, offset_t length, ByteOrder dst_byt
assert (length == 1 || length == 2 || length == 4 || length == 8 ||
length == 10 || length == 16 || length == 32);
- for (uint32_t i=0; i<length; ++i)
+ for (uint32_t i = 0; i < length; ++i)
((uint8_t*)dst)[i] = src[length - i - 1];
}
else
@@ -1033,7 +1032,7 @@ DataExtractor::CopyByteOrderedData (offset_t src_offset,
assert (m_byte_order == eByteOrderBig || m_byte_order == eByteOrderLittle);
// Validate the destination info
- assert (dst_void_ptr != NULL);
+ assert(dst_void_ptr != nullptr);
assert (dst_len > 0);
assert (dst_byte_order == eByteOrderBig || dst_byte_order == eByteOrderLittle);
@@ -1047,7 +1046,6 @@ DataExtractor::CopyByteOrderedData (offset_t src_offset,
!(m_byte_order == eByteOrderBig || m_byte_order == eByteOrderLittle))
return 0;
- uint32_t i;
uint8_t* dst = (uint8_t*)dst_void_ptr;
const uint8_t* src = (const uint8_t *)PeekData (src_offset, src_len);
if (src)
@@ -1070,7 +1068,7 @@ DataExtractor::CopyByteOrderedData (offset_t src_offset,
}
else
{
- for (i=0; i<src_len; ++i)
+ for (uint32_t i = 0; i < src_len; ++i)
dst[i+num_zeroes] = src[src_len - 1 - i];
}
}
@@ -1079,7 +1077,7 @@ DataExtractor::CopyByteOrderedData (offset_t src_offset,
// Little endian destination, so we lead the value bytes
if (m_byte_order == eByteOrderBig)
{
- for (i=0; i<src_len; ++i)
+ for (uint32_t i = 0; i < src_len; ++i)
dst[i] = src[src_len - 1 - i];
}
else
@@ -1107,7 +1105,7 @@ DataExtractor::CopyByteOrderedData (offset_t src_offset,
else
{
// Big endian dst, with little endian src
- for (i=0; i<dst_len; ++i)
+ for (uint32_t i = 0; i < dst_len; ++i)
dst[i] = src[dst_len - 1 - i];
}
}
@@ -1117,7 +1115,7 @@ DataExtractor::CopyByteOrderedData (offset_t src_offset,
if (m_byte_order == eByteOrderBig)
{
// Little endian dst, with big endian src
- for (i=0; i<dst_len; ++i)
+ for (uint32_t i = 0; i < dst_len; ++i)
dst[i] = src[src_len - 1 - i];
}
else
@@ -1128,12 +1126,10 @@ DataExtractor::CopyByteOrderedData (offset_t src_offset,
}
return dst_len;
}
-
}
return 0;
}
-
//----------------------------------------------------------------------
// Extracts a variable length NULL terminated C string from
// the data at the offset pointed to by "offset_ptr". The
@@ -1142,7 +1138,7 @@ DataExtractor::CopyByteOrderedData (offset_t src_offset,
//
// If the offset pointed to by "offset_ptr" is out of bounds, or if
// "length" is non-zero and there aren't enough available
-// bytes, NULL will be returned and "offset_ptr" will not be
+// bytes, nullptr will be returned and "offset_ptr" will not be
// updated.
//----------------------------------------------------------------------
const char*
@@ -1166,11 +1162,11 @@ DataExtractor::GetCStr (offset_t *offset_ptr) const
}
// We reached the end of the data without finding a NULL C string
- // terminator. Fall through and return NULL otherwise anyone that
+ // terminator. Fall through and return nullptr otherwise anyone that
// would have used the result as a C string can wander into
// unknown memory...
}
- return NULL;
+ return nullptr;
}
//----------------------------------------------------------------------
@@ -1181,23 +1177,23 @@ DataExtractor::GetCStr (offset_t *offset_ptr) const
//
// If the offset pointed to by "offset_ptr" is out of bounds, or if
// the offset plus the length of the field is out of bounds, or if the
-// field does not contain a NULL terminator byte, NULL will be returned
+// field does not contain a NULL terminator byte, nullptr will be returned
// and "offset_ptr" will not be updated.
//----------------------------------------------------------------------
const char*
DataExtractor::GetCStr (offset_t *offset_ptr, offset_t len) const
{
const char *cstr = (const char *)PeekData (*offset_ptr, len);
- if (cstr)
+ if (cstr != nullptr)
{
- if (memchr (cstr, '\0', len) == NULL)
+ if (memchr(cstr, '\0', len) == nullptr)
{
- return NULL;
+ return nullptr;
}
*offset_ptr += len;
return cstr;
}
- return NULL;
+ return nullptr;
}
//------------------------------------------------------------------
@@ -1206,7 +1202,7 @@ DataExtractor::GetCStr (offset_t *offset_ptr, offset_t len) const
// object's data, only "offset" is verified to be a valid offset.
//
// Returns a valid C string pointer if "offset" is a valid offset in
-// this object's data, else NULL is returned.
+// this object's data, else nullptr is returned.
//------------------------------------------------------------------
const char *
DataExtractor::PeekCStr (offset_t offset) const
@@ -1226,7 +1222,7 @@ uint64_t
DataExtractor::GetULEB128 (offset_t *offset_ptr) const
{
const uint8_t *src = (const uint8_t *)PeekData (*offset_ptr, 1);
- if (src == NULL)
+ if (src == nullptr)
return 0;
const uint8_t *end = m_end;
@@ -1241,7 +1237,7 @@ DataExtractor::GetULEB128 (offset_t *offset_ptr) const
while (src < end)
{
uint8_t byte = *src++;
- result |= (byte & 0x7f) << shift;
+ result |= (uint64_t)(byte & 0x7f) << shift;
if ((byte & 0x80) == 0)
break;
shift += 7;
@@ -1266,7 +1262,7 @@ int64_t
DataExtractor::GetSLEB128 (offset_t *offset_ptr) const
{
const uint8_t *src = (const uint8_t *)PeekData (*offset_ptr, 1);
- if (src == NULL)
+ if (src == nullptr)
return 0;
const uint8_t *end = m_end;
@@ -1284,7 +1280,7 @@ DataExtractor::GetSLEB128 (offset_t *offset_ptr) const
{
bytecount++;
byte = *src++;
- result |= (byte & 0x7f) << shift;
+ result |= (int64_t)(byte & 0x7f) << shift;
shift += 7;
if ((byte & 0x80) == 0)
break;
@@ -1313,7 +1309,7 @@ DataExtractor::Skip_LEB128 (offset_t *offset_ptr) const
{
uint32_t bytes_consumed = 0;
const uint8_t *src = (const uint8_t *)PeekData (*offset_ptr, 1);
- if (src == NULL)
+ if (src == nullptr)
return 0;
const uint8_t *end = m_end;
@@ -1435,7 +1431,7 @@ DataExtractor::Dump (Stream *s,
uint32_t item_bit_offset, // If "item_bit_size" is non-zero, this is the shift amount to apply to a bitfield
ExecutionContextScope *exe_scope) const
{
- if (s == NULL)
+ if (s == nullptr)
return start_offset;
if (item_format == eFormatPointer)
@@ -1453,7 +1449,7 @@ DataExtractor::Dump (Stream *s,
target_sp = exe_scope->CalculateTarget();
if (target_sp)
{
- DisassemblerSP disassembler_sp (Disassembler::FindPlugin(target_sp->GetArchitecture(), NULL, NULL));
+ DisassemblerSP disassembler_sp(Disassembler::FindPlugin(target_sp->GetArchitecture(), nullptr, nullptr));
if (disassembler_sp)
{
lldb::addr_t addr = base_addr + start_offset;
@@ -1479,10 +1475,6 @@ DataExtractor::Dump (Stream *s,
ExecutionContext exe_ctx;
exe_scope->CalculateExecutionContext(exe_ctx);
disassembler_sp->GetInstructionList().Dump (s, show_address, show_bytes, &exe_ctx);
-
- // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
- // I'll fix that but for now, just clear the list and it will go away nicely.
- disassembler_sp->GetInstructionList().Clear();
}
}
}
@@ -1515,16 +1507,14 @@ DataExtractor::Dump (Stream *s,
line_start_offset = offset;
}
- else
- if (item_format != eFormatChar &&
- item_format != eFormatCharPrintable &&
- item_format != eFormatCharArray &&
- count > 0)
+ else if (item_format != eFormatChar &&
+ item_format != eFormatCharPrintable &&
+ item_format != eFormatCharArray &&
+ count > 0)
{
s->PutChar(' ');
}
- uint32_t i;
switch (item_format)
{
case eFormatBoolean:
@@ -1545,7 +1535,7 @@ DataExtractor::Dump (Stream *s,
// earlier C++ libraries
std::string binary_value(64, '0');
std::bitset<64> bits(uval64);
- for (i = 0; i < 64; ++i)
+ for (uint32_t i = 0; i < 64; ++i)
if (bits[i])
binary_value[64 - 1 - i] = '1';
if (item_bit_size > 0)
@@ -1563,7 +1553,7 @@ DataExtractor::Dump (Stream *s,
case eFormatBytes:
case eFormatBytesWithASCII:
- for (i=0; i<item_byte_size; ++i)
+ for (uint32_t i = 0; i < item_byte_size; ++i)
{
s->Printf ("%2.2x", GetU8(&offset));
}
@@ -1656,7 +1646,7 @@ DataExtractor::Dump (Stream *s,
{
uint64_t uval64 = GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset);
s->PutChar('\'');
- for (i=0; i<item_byte_size; ++i)
+ for (uint32_t i = 0; i < item_byte_size; ++i)
{
uint8_t ch = (uint8_t)(uval64 >> ((item_byte_size - i - 1) * 8));
if (isprint(ch))
@@ -2079,23 +2069,20 @@ DataExtractor::Dump (Stream *s,
// output information. "num_per_line" objects of type "type" will
// be dumped with the option to override the format for each object
// with "type_format". "type_format" is a printf style formatting
-// string. If "type_format" is NULL, then an appropriate format
+// string. If "type_format" is nullptr, then an appropriate format
// string will be used for the supplied "type". If the stream "s"
-// is NULL, then the output will be send to Log().
+// is nullptr, then the output will be send to Log().
//----------------------------------------------------------------------
lldb::offset_t
-DataExtractor::PutToLog
-(
- Log *log,
- offset_t start_offset,
- offset_t length,
- uint64_t base_addr,
- uint32_t num_per_line,
- DataExtractor::Type type,
- const char *format
-) const
-{
- if (log == NULL)
+DataExtractor::PutToLog(Log *log,
+ offset_t start_offset,
+ offset_t length,
+ uint64_t base_addr,
+ uint32_t num_per_line,
+ DataExtractor::Type type,
+ const char *format) const
+{
+ if (log == nullptr)
return start_offset;
offset_t offset;
@@ -2185,7 +2172,7 @@ DataExtractor::DumpHexBytes (Stream *s,
size_t
DataExtractor::Copy (DataExtractor &dest_data) const
{
- if (m_data_sp.get())
+ if (m_data_sp)
{
// we can pass along the SP to the data
dest_data.SetData(m_data_sp);
@@ -2213,10 +2200,10 @@ DataExtractor::Append(DataExtractor& rhs)
size_t bytes = GetByteSize() + rhs.GetByteSize();
- DataBufferHeap *buffer_heap_ptr = NULL;
+ DataBufferHeap *buffer_heap_ptr = nullptr;
DataBufferSP buffer_sp(buffer_heap_ptr = new DataBufferHeap(bytes, 0));
- if (buffer_sp.get() == NULL || buffer_heap_ptr == NULL)
+ if (!buffer_sp || buffer_heap_ptr == nullptr)
return false;
uint8_t* bytes_ptr = buffer_heap_ptr->GetBytes();
@@ -2232,7 +2219,7 @@ DataExtractor::Append(DataExtractor& rhs)
bool
DataExtractor::Append(void* buf, offset_t length)
{
- if (buf == NULL)
+ if (buf == nullptr)
return false;
if (length == 0)
@@ -2240,10 +2227,10 @@ DataExtractor::Append(void* buf, offset_t length)
size_t bytes = GetByteSize() + length;
- DataBufferHeap *buffer_heap_ptr = NULL;
+ DataBufferHeap *buffer_heap_ptr = nullptr;
DataBufferSP buffer_sp(buffer_heap_ptr = new DataBufferHeap(bytes, 0));
- if (buffer_sp.get() == NULL || buffer_heap_ptr == NULL)
+ if (!buffer_sp || buffer_heap_ptr == nullptr)
return false;
uint8_t* bytes_ptr = buffer_heap_ptr->GetBytes();
@@ -2280,4 +2267,3 @@ DataExtractor::Checksum (llvm::SmallVectorImpl<uint8_t> &dest,
result+16,
dest.begin());
}
-
diff --git a/source/Core/Debugger.cpp b/source/Core/Debugger.cpp
index d36800e20bc0..34608d0193fc 100644
--- a/source/Core/Debugger.cpp
+++ b/source/Core/Debugger.cpp
@@ -9,10 +9,16 @@
#include "lldb/Core/Debugger.h"
+// C Includes
+// C++ Includes
#include <map>
+#include <mutex>
+// Other libraries and framework includes
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/DynamicLibrary.h"
+// Project includes
#include "lldb/lldb-private.h"
#include "lldb/Core/FormatEntity.h"
#include "lldb/Core/Module.h"
@@ -54,34 +60,17 @@
#include "lldb/Target/Thread.h"
#include "lldb/Utility/AnsiTerminal.h"
-#include "llvm/Support/DynamicLibrary.h"
-
using namespace lldb;
using namespace lldb_private;
-
static lldb::user_id_t g_unique_id = 1;
static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024;
#pragma mark Static Functions
-static Mutex &
-GetDebuggerListMutex ()
-{
- static Mutex g_mutex(Mutex::eMutexTypeRecursive);
- return g_mutex;
-}
-
typedef std::vector<DebuggerSP> DebuggerList;
-
-static DebuggerList &
-GetDebuggerList()
-{
- // hide the static debugger list inside a singleton accessor to avoid
- // global init constructors
- static DebuggerList g_list;
- return g_list;
-}
+static std::recursive_mutex *g_debugger_list_mutex_ptr = nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
+static DebuggerList *g_debugger_list_ptr = nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
OptionEnumValueElement
g_show_disassembly_enum_values[] =
@@ -90,7 +79,7 @@ g_show_disassembly_enum_values[] =
{ Debugger::eStopDisassemblyTypeNoDebugInfo, "no-debuginfo", "Show disassembly when there is no debug information."},
{ Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
{ Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
- { 0, NULL, NULL }
+ { 0, nullptr, nullptr }
};
OptionEnumValueElement
@@ -99,7 +88,7 @@ g_language_enumerators[] =
{ eScriptLanguageNone, "none", "Disable scripting languages."},
{ eScriptLanguagePython, "python", "Select python as the default scripting language."},
{ eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."},
- { 0, NULL, NULL }
+ { 0, nullptr, nullptr }
};
#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}"
@@ -140,30 +129,29 @@ g_language_enumerators[] =
// lldb's original format for disassembly would look like this format string -
// {${function.initial-function}{${module.file.basename}`}{${function.name-without-args}}:\n}{${function.changed}\n{${module.file.basename}`}{${function.name-without-args}}:\n}{${current-pc-arrow} }{${addr-file-or-load}}:
-
static PropertyDefinition
g_properties[] =
{
-{ "auto-confirm", OptionValue::eTypeBoolean , true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." },
-{ "disassembly-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_DISASSEMBLY_FORMAT, NULL, "The default disassembly format string to use when disassembling instruction sequences." },
-{ "frame-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." },
-{ "notify-void", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Notify the user explicitly if an expression returns void (default: false)." },
-{ "prompt", OptionValue::eTypeString , true, OptionValueString::eOptionEncodeCharacterEscapeSequences, "(lldb) ", NULL, "The debugger command line prompt displayed for the user." },
-{ "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, NULL, g_language_enumerators, "The script language to be used for evaluating user-written scripts." },
-{ "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , NULL, NULL, "The number of disassembly lines to show when displaying a stopped context." },
-{ "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoDebugInfo, NULL, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." },
-{ "stop-line-count-after", OptionValue::eTypeSInt64 , true, 3 , NULL, NULL, "The number of sources lines to display that come after the current source line when displaying a stopped context." },
-{ "stop-line-count-before", OptionValue::eTypeSInt64 , true, 3 , NULL, NULL, "The number of sources lines to display that come before the current source line when displaying a stopped context." },
-{ "term-width", OptionValue::eTypeSInt64 , true, 80 , NULL, NULL, "The maximum number of columns to use for displaying text." },
-{ "thread-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
-{ "use-external-editor", OptionValue::eTypeBoolean , true, false, NULL, NULL, "Whether to use an external editor or not." },
-{ "use-color", OptionValue::eTypeBoolean , true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
-{ "auto-one-line-summaries", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
-{ "auto-indent", OptionValue::eTypeBoolean , true, true , NULL, NULL, "If true, LLDB will auto indent/outdent code. Currently only supported in the REPL (default: true)." },
-{ "print-decls", OptionValue::eTypeBoolean , true, true , NULL, NULL, "If true, LLDB will print the values of variables declared in an expression. Currently only supported in the REPL (default: true)." },
-{ "tab-size", OptionValue::eTypeUInt64 , true, 4 , NULL, NULL, "The tab size to use when indenting code in multi-line input mode (default: 4)." },
-{ "escape-non-printables", OptionValue::eTypeBoolean , true, true, NULL, NULL, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." },
-{ NULL, OptionValue::eTypeInvalid , true, 0 , NULL, NULL, NULL }
+{ "auto-confirm", OptionValue::eTypeBoolean , true, false, nullptr, nullptr, "If true all confirmation prompts will receive their default reply." },
+{ "disassembly-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_DISASSEMBLY_FORMAT, nullptr, "The default disassembly format string to use when disassembling instruction sequences." },
+{ "frame-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_FRAME_FORMAT, nullptr, "The default frame format string to use when displaying stack frame information for threads." },
+{ "notify-void", OptionValue::eTypeBoolean , true, false, nullptr, nullptr, "Notify the user explicitly if an expression returns void (default: false)." },
+{ "prompt", OptionValue::eTypeString , true, OptionValueString::eOptionEncodeCharacterEscapeSequences, "(lldb) ", nullptr, "The debugger command line prompt displayed for the user." },
+{ "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, nullptr, g_language_enumerators, "The script language to be used for evaluating user-written scripts." },
+{ "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , nullptr, nullptr, "The number of disassembly lines to show when displaying a stopped context." },
+{ "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoDebugInfo, nullptr, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." },
+{ "stop-line-count-after", OptionValue::eTypeSInt64 , true, 3 , nullptr, nullptr, "The number of sources lines to display that come after the current source line when displaying a stopped context." },
+{ "stop-line-count-before", OptionValue::eTypeSInt64 , true, 3 , nullptr, nullptr, "The number of sources lines to display that come before the current source line when displaying a stopped context." },
+{ "term-width", OptionValue::eTypeSInt64 , true, 80 , nullptr, nullptr, "The maximum number of columns to use for displaying text." },
+{ "thread-format", OptionValue::eTypeFormatEntity, true, 0 , DEFAULT_THREAD_FORMAT, nullptr, "The default thread format string to use when displaying thread information." },
+{ "use-external-editor", OptionValue::eTypeBoolean , true, false, nullptr, nullptr, "Whether to use an external editor or not." },
+{ "use-color", OptionValue::eTypeBoolean , true, true , nullptr, nullptr, "Whether to use Ansi color codes or not." },
+{ "auto-one-line-summaries", OptionValue::eTypeBoolean , true, true, nullptr, nullptr, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
+{ "auto-indent", OptionValue::eTypeBoolean , true, true , nullptr, nullptr, "If true, LLDB will auto indent/outdent code. Currently only supported in the REPL (default: true)." },
+{ "print-decls", OptionValue::eTypeBoolean , true, true , nullptr, nullptr, "If true, LLDB will print the values of variables declared in an expression. Currently only supported in the REPL (default: true)." },
+{ "tab-size", OptionValue::eTypeUInt64 , true, 4 , nullptr, nullptr, "The tab size to use when indenting code in multi-line input mode (default: 4)." },
+{ "escape-non-printables", OptionValue::eTypeBoolean , true, true, nullptr, nullptr, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." },
+{ nullptr, OptionValue::eTypeInvalid , true, 0 , nullptr, nullptr, nullptr }
};
enum
@@ -189,7 +177,7 @@ enum
ePropertyEscapeNonPrintables
};
-LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL;
+LoadPluginCallbackType Debugger::g_load_plugin_callback = nullptr;
Error
Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
@@ -258,42 +246,42 @@ bool
Debugger::GetAutoConfirm () const
{
const uint32_t idx = ePropertyAutoConfirm;
- return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
+ return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
}
const FormatEntity::Entry *
Debugger::GetDisassemblyFormat() const
{
const uint32_t idx = ePropertyDisassemblyFormat;
- return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
+ return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
}
const FormatEntity::Entry *
Debugger::GetFrameFormat() const
{
const uint32_t idx = ePropertyFrameFormat;
- return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
+ return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
}
bool
Debugger::GetNotifyVoid () const
{
const uint32_t idx = ePropertyNotiftVoid;
- return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
+ return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
}
const char *
Debugger::GetPrompt() const
{
const uint32_t idx = ePropertyPrompt;
- return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_properties[idx].default_cstr_value);
+ return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, g_properties[idx].default_cstr_value);
}
void
Debugger::SetPrompt(const char *p)
{
const uint32_t idx = ePropertyPrompt;
- m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
+ m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, p);
const char *new_prompt = GetPrompt();
std::string str = lldb_utility::ansi::FormatAnsiTerminalCodes (new_prompt, GetUseColor());
if (str.length())
@@ -305,63 +293,63 @@ const FormatEntity::Entry *
Debugger::GetThreadFormat() const
{
const uint32_t idx = ePropertyThreadFormat;
- return m_collection_sp->GetPropertyAtIndexAsFormatEntity(NULL, idx);
+ return m_collection_sp->GetPropertyAtIndexAsFormatEntity(nullptr, idx);
}
lldb::ScriptLanguage
Debugger::GetScriptLanguage() const
{
const uint32_t idx = ePropertyScriptLanguage;
- return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
+ return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
}
bool
Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang)
{
const uint32_t idx = ePropertyScriptLanguage;
- return m_collection_sp->SetPropertyAtIndexAsEnumeration (NULL, idx, script_lang);
+ return m_collection_sp->SetPropertyAtIndexAsEnumeration(nullptr, idx, script_lang);
}
uint32_t
Debugger::GetTerminalWidth () const
{
const uint32_t idx = ePropertyTerminalWidth;
- return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
+ return m_collection_sp->GetPropertyAtIndexAsSInt64(nullptr, idx, g_properties[idx].default_uint_value);
}
bool
Debugger::SetTerminalWidth (uint32_t term_width)
{
const uint32_t idx = ePropertyTerminalWidth;
- return m_collection_sp->SetPropertyAtIndexAsSInt64 (NULL, idx, term_width);
+ return m_collection_sp->SetPropertyAtIndexAsSInt64(nullptr, idx, term_width);
}
bool
Debugger::GetUseExternalEditor () const
{
const uint32_t idx = ePropertyUseExternalEditor;
- return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
+ return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
}
bool
Debugger::SetUseExternalEditor (bool b)
{
const uint32_t idx = ePropertyUseExternalEditor;
- return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
+ return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
}
bool
Debugger::GetUseColor () const
{
const uint32_t idx = ePropertyUseColor;
- return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
+ return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, g_properties[idx].default_uint_value != 0);
}
bool
Debugger::SetUseColor (bool b)
{
const uint32_t idx = ePropertyUseColor;
- bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
+ bool ret = m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
SetPrompt (GetPrompt());
return ret;
}
@@ -370,80 +358,79 @@ uint32_t
Debugger::GetStopSourceLineCount (bool before) const
{
const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
- return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
+ return m_collection_sp->GetPropertyAtIndexAsSInt64(nullptr, idx, g_properties[idx].default_uint_value);
}
Debugger::StopDisassemblyType
Debugger::GetStopDisassemblyDisplay () const
{
const uint32_t idx = ePropertyStopDisassemblyDisplay;
- return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
+ return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
}
uint32_t
Debugger::GetDisassemblyLineCount () const
{
const uint32_t idx = ePropertyStopDisassemblyCount;
- return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
+ return m_collection_sp->GetPropertyAtIndexAsSInt64(nullptr, idx, g_properties[idx].default_uint_value);
}
bool
Debugger::GetAutoOneLineSummaries () const
{
const uint32_t idx = ePropertyAutoOneLineSummaries;
- return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
+ return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true);
}
bool
Debugger::GetEscapeNonPrintables () const
{
const uint32_t idx = ePropertyEscapeNonPrintables;
- return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
+ return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true);
}
bool
Debugger::GetAutoIndent () const
{
const uint32_t idx = ePropertyAutoIndent;
- return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
+ return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true);
}
bool
Debugger::SetAutoIndent (bool b)
{
const uint32_t idx = ePropertyAutoIndent;
- return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
+ return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
}
bool
Debugger::GetPrintDecls () const
{
const uint32_t idx = ePropertyPrintDecls;
- return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
+ return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, true);
}
bool
Debugger::SetPrintDecls (bool b)
{
const uint32_t idx = ePropertyPrintDecls;
- return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
+ return m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
}
uint32_t
Debugger::GetTabSize () const
{
const uint32_t idx = ePropertyTabSize;
- return m_collection_sp->GetPropertyAtIndexAsUInt64 (NULL, idx, g_properties[idx].default_uint_value);
+ return m_collection_sp->GetPropertyAtIndexAsUInt64(nullptr, idx, g_properties[idx].default_uint_value);
}
bool
Debugger::SetTabSize (uint32_t tab_size)
{
const uint32_t idx = ePropertyTabSize;
- return m_collection_sp->SetPropertyAtIndexAsUInt64 (NULL, idx, tab_size);
+ return m_collection_sp->SetPropertyAtIndexAsUInt64(nullptr, idx, tab_size);
}
-
#pragma mark Debugger
//const DebuggerPropertiesSP &
@@ -453,28 +440,30 @@ Debugger::SetTabSize (uint32_t tab_size)
//}
//
-static bool lldb_initialized = false;
void
Debugger::Initialize(LoadPluginCallbackType load_plugin_callback)
{
- assert(!lldb_initialized && "Debugger::Initialize called more than once!");
-
- lldb_initialized = true;
+ assert(g_debugger_list_ptr == nullptr && "Debugger::Initialize called more than once!");
+ g_debugger_list_mutex_ptr = new std::recursive_mutex();
+ g_debugger_list_ptr = new DebuggerList();
g_load_plugin_callback = load_plugin_callback;
}
void
Debugger::Terminate ()
{
- assert(lldb_initialized && "Debugger::Terminate called without a matching Debugger::Initialize!");
-
- // Clear our master list of debugger objects
- Mutex::Locker locker (GetDebuggerListMutex ());
- auto& debuggers = GetDebuggerList();
- for (const auto& debugger: debuggers)
- debugger->Clear();
+ assert(g_debugger_list_ptr && "Debugger::Terminate called without a matching Debugger::Initialize!");
- debuggers.clear();
+ if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
+ {
+ // Clear our master list of debugger objects
+ {
+ std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
+ for (const auto& debugger: *g_debugger_list_ptr)
+ debugger->Clear();
+ g_debugger_list_ptr->clear();
+ }
+ }
}
void
@@ -512,12 +501,9 @@ Debugger::LoadPlugin (const FileSpec& spec, Error& error)
}
static FileSpec::EnumerateDirectoryResult
-LoadPluginCallback
-(
- void *baton,
- FileSpec::FileType file_type,
- const FileSpec &file_spec
- )
+LoadPluginCallback(void *baton,
+ FileSpec::FileType file_type,
+ const FileSpec &file_spec)
{
Error error;
@@ -551,7 +537,6 @@ LoadPluginCallback
return FileSpec::eEnumerateDirectoryResultNext;
}
-
else if (file_type == FileSpec::eFileTypeUnknown ||
file_type == FileSpec::eFileTypeDirectory ||
file_type == FileSpec::eFileTypeSymbolicLink )
@@ -607,10 +592,10 @@ DebuggerSP
Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
{
DebuggerSP debugger_sp (new Debugger(log_callback, baton));
- if (lldb_initialized)
+ if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
{
- Mutex::Locker locker (GetDebuggerListMutex ());
- GetDebuggerList().push_back(debugger_sp);
+ std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
+ g_debugger_list_ptr->push_back(debugger_sp);
}
debugger_sp->InstanceInitialize ();
return debugger_sp;
@@ -619,21 +604,20 @@ Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
void
Debugger::Destroy (DebuggerSP &debugger_sp)
{
- if (debugger_sp.get() == NULL)
+ if (!debugger_sp)
return;
debugger_sp->Clear();
- if (lldb_initialized)
+ if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
{
- Mutex::Locker locker (GetDebuggerListMutex ());
- DebuggerList &debugger_list = GetDebuggerList ();
- DebuggerList::iterator pos, end = debugger_list.end();
- for (pos = debugger_list.begin (); pos != end; ++pos)
+ std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
+ DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
+ for (pos = g_debugger_list_ptr->begin (); pos != end; ++pos)
{
if ((*pos).get() == debugger_sp.get())
{
- debugger_list.erase (pos);
+ g_debugger_list_ptr->erase (pos);
return;
}
}
@@ -644,15 +628,13 @@ DebuggerSP
Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
{
DebuggerSP debugger_sp;
- if (lldb_initialized)
+ if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
{
- Mutex::Locker locker (GetDebuggerListMutex ());
- DebuggerList &debugger_list = GetDebuggerList();
- DebuggerList::iterator pos, end = debugger_list.end();
-
- for (pos = debugger_list.begin(); pos != end; ++pos)
+ std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
+ DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
+ for (pos = g_debugger_list_ptr->begin (); pos != end; ++pos)
{
- if ((*pos).get()->m_instance_name == instance_name)
+ if ((*pos)->m_instance_name == instance_name)
{
debugger_sp = *pos;
break;
@@ -666,12 +648,11 @@ TargetSP
Debugger::FindTargetWithProcessID (lldb::pid_t pid)
{
TargetSP target_sp;
- if (lldb_initialized)
+ if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
{
- Mutex::Locker locker (GetDebuggerListMutex ());
- DebuggerList &debugger_list = GetDebuggerList();
- DebuggerList::iterator pos, end = debugger_list.end();
- for (pos = debugger_list.begin(); pos != end; ++pos)
+ std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
+ DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
+ for (pos = g_debugger_list_ptr->begin (); pos != end; ++pos)
{
target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
if (target_sp)
@@ -685,12 +666,11 @@ TargetSP
Debugger::FindTargetWithProcess (Process *process)
{
TargetSP target_sp;
- if (lldb_initialized)
+ if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
{
- Mutex::Locker locker (GetDebuggerListMutex ());
- DebuggerList &debugger_list = GetDebuggerList();
- DebuggerList::iterator pos, end = debugger_list.end();
- for (pos = debugger_list.begin(); pos != end; ++pos)
+ std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
+ DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
+ for (pos = g_debugger_list_ptr->begin (); pos != end; ++pos)
{
target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
if (target_sp)
@@ -706,19 +686,22 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
m_input_file_sp(new StreamFile(stdin, false)),
m_output_file_sp(new StreamFile(stdout, false)),
m_error_file_sp(new StreamFile(stderr, false)),
+ m_broadcaster_manager_sp(BroadcasterManager::MakeBroadcasterManager()),
m_terminal_state(),
m_target_list(*this),
m_platform_list(),
- m_listener("lldb.Debugger"),
+ m_listener_sp(Listener::MakeListener("lldb.Debugger")),
m_source_manager_ap(),
m_source_file_cache(),
m_command_interpreter_ap(new CommandInterpreter(*this, eScriptLanguageDefault, false)),
m_input_reader_stack(),
m_instance_name(),
m_loaded_plugins(),
- m_event_handler_thread (),
- m_io_handler_thread (),
- m_sync_broadcaster (NULL, "lldb.debugger.sync")
+ m_event_handler_thread(),
+ m_io_handler_thread(),
+ m_sync_broadcaster(nullptr, "lldb.debugger.sync"),
+ m_forward_listener_sp(),
+ m_clear_once()
{
char instance_cstr[256];
snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
@@ -728,7 +711,7 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
m_command_interpreter_ap->Initialize ();
// Always add our default platform to the platform list
PlatformSP default_platform_sp (Platform::GetHostPlatform());
- assert (default_platform_sp.get());
+ assert(default_platform_sp);
m_platform_list.Append (default_platform_sp, true);
m_collection_sp->Initialize (g_properties);
@@ -740,14 +723,14 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
ConstString("Platform settings."),
true,
Platform::GetGlobalPlatformProperties()->GetValueProperties());
- if (m_command_interpreter_ap.get())
+ if (m_command_interpreter_ap)
{
m_collection_sp->AppendProperty (ConstString("interpreter"),
ConstString("Settings specify to the debugger's command interpreter."),
true,
m_command_interpreter_ap->GetValueProperties());
}
- OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
+ OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64(nullptr, ePropertyTerminalWidth);
term_width->SetMinimumValue(10);
term_width->SetMaximumValue(1024);
@@ -765,31 +748,44 @@ Debugger::~Debugger ()
void
Debugger::Clear()
{
- ClearIOHandlers();
- StopIOHandlerThread();
- StopEventHandlerThread();
- m_listener.Clear();
- int num_targets = m_target_list.GetNumTargets();
- for (int i = 0; i < num_targets; i++)
- {
- TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
- if (target_sp)
+ //----------------------------------------------------------------------
+ // Make sure we call this function only once. With the C++ global
+ // destructor chain having a list of debuggers and with code that can be
+ // running on other threads, we need to ensure this doesn't happen
+ // multiple times.
+ //
+ // The following functions call Debugger::Clear():
+ // Debugger::~Debugger();
+ // static void Debugger::Destroy(lldb::DebuggerSP &debugger_sp);
+ // static void Debugger::Terminate();
+ //----------------------------------------------------------------------
+ std::call_once(m_clear_once, [this]() {
+ ClearIOHandlers();
+ StopIOHandlerThread();
+ StopEventHandlerThread();
+ m_listener_sp->Clear();
+ int num_targets = m_target_list.GetNumTargets();
+ for (int i = 0; i < num_targets; i++)
{
- ProcessSP process_sp (target_sp->GetProcessSP());
- if (process_sp)
- process_sp->Finalize();
- target_sp->Destroy();
+ TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
+ if (target_sp)
+ {
+ ProcessSP process_sp (target_sp->GetProcessSP());
+ if (process_sp)
+ process_sp->Finalize();
+ target_sp->Destroy();
+ }
}
- }
- BroadcasterManager::Clear ();
-
- // Close the input file _before_ we close the input read communications class
- // as it does NOT own the input file, our m_input_file does.
- m_terminal_state.Clear();
- if (m_input_file_sp)
- m_input_file_sp->GetFile().Close ();
-
- m_command_interpreter_ap->Clear();
+ m_broadcaster_manager_sp->Clear ();
+
+ // Close the input file _before_ we close the input read communications class
+ // as it does NOT own the input file, our m_input_file does.
+ m_terminal_state.Clear();
+ if (m_input_file_sp)
+ m_input_file_sp->GetFile().Close ();
+
+ m_command_interpreter_ap->Clear();
+ });
}
bool
@@ -817,7 +813,6 @@ Debugger::SetAsyncExecution (bool async_execution)
m_command_interpreter_ap->SetSynchronous (!async_execution);
}
-
void
Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
{
@@ -827,7 +822,7 @@ Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
m_input_file_sp.reset (new StreamFile (fh, tranfer_ownership));
File &in_file = m_input_file_sp->GetFile();
- if (in_file.IsValid() == false)
+ if (!in_file.IsValid())
in_file.SetStream (stdin, true);
// Save away the terminal state if that is relevant, so that we can restore it in RestoreInputState.
@@ -843,7 +838,7 @@ Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
m_output_file_sp.reset (new StreamFile (fh, tranfer_ownership));
File &out_file = m_output_file_sp->GetFile();
- if (out_file.IsValid() == false)
+ if (!out_file.IsValid())
out_file.SetStream (stdout, false);
// do not create the ScriptInterpreter just for setting the output file handle
@@ -863,7 +858,7 @@ Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
m_error_file_sp.reset (new StreamFile (fh, tranfer_ownership));
File &err_file = m_error_file_sp->GetFile();
- if (err_file.IsValid() == false)
+ if (!err_file.IsValid())
err_file.SetStream (stderr, false);
}
@@ -895,14 +890,14 @@ Debugger::GetSelectedExecutionContext ()
{
ProcessSP process_sp (target_sp->GetProcessSP());
exe_ctx.SetProcessSP (process_sp);
- if (process_sp && process_sp->IsRunning() == false)
+ if (process_sp && !process_sp->IsRunning())
{
ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
if (thread_sp)
{
exe_ctx.SetThreadSP (thread_sp);
exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
- if (exe_ctx.GetFramePtr() == NULL)
+ if (exe_ctx.GetFramePtr() == nullptr)
exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
}
}
@@ -911,40 +906,40 @@ Debugger::GetSelectedExecutionContext ()
}
void
-Debugger::DispatchInputInterrupt ()
+Debugger::DispatchInputInterrupt()
{
- Mutex::Locker locker (m_input_reader_stack.GetMutex());
- IOHandlerSP reader_sp (m_input_reader_stack.Top());
+ std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
+ IOHandlerSP reader_sp(m_input_reader_stack.Top());
if (reader_sp)
reader_sp->Interrupt();
}
void
-Debugger::DispatchInputEndOfFile ()
+Debugger::DispatchInputEndOfFile()
{
- Mutex::Locker locker (m_input_reader_stack.GetMutex());
- IOHandlerSP reader_sp (m_input_reader_stack.Top());
+ std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
+ IOHandlerSP reader_sp(m_input_reader_stack.Top());
if (reader_sp)
reader_sp->GotEOF();
}
void
-Debugger::ClearIOHandlers ()
+Debugger::ClearIOHandlers()
{
// The bottom input reader should be the main debugger input reader. We do not want to close that one here.
- Mutex::Locker locker (m_input_reader_stack.GetMutex());
+ std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
while (m_input_reader_stack.GetSize() > 1)
{
- IOHandlerSP reader_sp (m_input_reader_stack.Top());
+ IOHandlerSP reader_sp(m_input_reader_stack.Top());
if (reader_sp)
- PopIOHandler (reader_sp);
+ PopIOHandler(reader_sp);
}
}
void
Debugger::ExecuteIOHandlers()
{
- while (1)
+ while (true)
{
IOHandlerSP reader_sp(m_input_reader_stack.Top());
if (!reader_sp)
@@ -953,7 +948,7 @@ Debugger::ExecuteIOHandlers()
reader_sp->Run();
// Remove all input readers that are done from the top of the stack
- while (1)
+ while (true)
{
IOHandlerSP top_reader_sp = m_input_reader_stack.Top();
if (top_reader_sp && top_reader_sp->GetIsDone())
@@ -1018,7 +1013,7 @@ Debugger::RunIOHandler (const IOHandlerSP& reader_sp)
break;
}
- while (1)
+ while (true)
{
top_reader_sp = m_input_reader_stack.Top();
if (top_reader_sp && top_reader_sp->GetIsDone())
@@ -1030,16 +1025,16 @@ Debugger::RunIOHandler (const IOHandlerSP& reader_sp)
}
void
-Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
+Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
{
// Before an IOHandler runs, it must have in/out/err streams.
// This function is called when one ore more of the streams
- // are NULL. We use the top input reader's in/out/err streams,
+ // are nullptr. We use the top input reader's in/out/err streams,
// or fall back to the debugger file handles, or we fall back
// onto stdin/stdout/stderr as a last resort.
-
- Mutex::Locker locker (m_input_reader_stack.GetMutex());
- IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
+
+ std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
+ IOHandlerSP top_reader_sp(m_input_reader_stack.Top());
// If no STDIN has been set, then set it appropriately
if (!in)
{
@@ -1047,7 +1042,7 @@ Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out,
in = top_reader_sp->GetInputStreamFile();
else
in = GetInputFile();
-
+
// If there is nothing, use stdin
if (!in)
in = StreamFileSP(new StreamFile(stdin, false));
@@ -1059,7 +1054,7 @@ Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out,
out = top_reader_sp->GetOutputStreamFile();
else
out = GetOutputFile();
-
+
// If there is nothing, use stdout
if (!out)
out = StreamFileSP(new StreamFile(stdout, false));
@@ -1071,31 +1066,30 @@ Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out,
err = top_reader_sp->GetErrorStreamFile();
else
err = GetErrorFile();
-
+
// If there is nothing, use stderr
if (!err)
err = StreamFileSP(new StreamFile(stdout, false));
-
}
}
void
-Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
+Debugger::PushIOHandler(const IOHandlerSP &reader_sp)
{
if (!reader_sp)
return;
-
- Mutex::Locker locker (m_input_reader_stack.GetMutex());
+
+ std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
// Get the current top input reader...
- IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
-
+ IOHandlerSP top_reader_sp(m_input_reader_stack.Top());
+
// Don't push the same IO handler twice...
if (reader_sp == top_reader_sp)
return;
// Push our new input reader
- m_input_reader_stack.Push (reader_sp);
+ m_input_reader_stack.Push(reader_sp);
reader_sp->Activate();
// Interrupt the top input reader to it will exit its Run() function
@@ -1108,12 +1102,12 @@ Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
}
bool
-Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
+Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp)
{
- if (! pop_reader_sp)
+ if (!pop_reader_sp)
return false;
- Mutex::Locker locker (m_input_reader_stack.GetMutex());
+ std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
// The reader on the stop of the stack is done, so let the next
// read on the stack refresh its prompt and if there is one...
@@ -1127,7 +1121,7 @@ Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
reader_sp->Deactivate();
reader_sp->Cancel();
- m_input_reader_stack.Pop ();
+ m_input_reader_stack.Pop();
reader_sp = m_input_reader_stack.Top();
if (reader_sp)
@@ -1151,10 +1145,10 @@ Debugger::GetAsyncErrorStream ()
size_t
Debugger::GetNumDebuggers()
{
- if (lldb_initialized)
+ if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
{
- Mutex::Locker locker (GetDebuggerListMutex ());
- return GetDebuggerList().size();
+ std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
+ return g_debugger_list_ptr->size();
}
return 0;
}
@@ -1164,13 +1158,11 @@ Debugger::GetDebuggerAtIndex (size_t index)
{
DebuggerSP debugger_sp;
- if (lldb_initialized)
+ if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
{
- Mutex::Locker locker (GetDebuggerListMutex ());
- DebuggerList &debugger_list = GetDebuggerList();
-
- if (index < debugger_list.size())
- debugger_sp = debugger_list[index];
+ std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
+ if (index < g_debugger_list_ptr->size())
+ debugger_sp = g_debugger_list_ptr->at(index);
}
return debugger_sp;
@@ -1181,14 +1173,13 @@ Debugger::FindDebuggerWithID (lldb::user_id_t id)
{
DebuggerSP debugger_sp;
- if (lldb_initialized)
+ if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
{
- Mutex::Locker locker (GetDebuggerListMutex ());
- DebuggerList &debugger_list = GetDebuggerList();
- DebuggerList::iterator pos, end = debugger_list.end();
- for (pos = debugger_list.begin(); pos != end; ++pos)
+ std::lock_guard<std::recursive_mutex> guard(*g_debugger_list_mutex_ptr);
+ DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
+ for (pos = g_debugger_list_ptr->begin (); pos != end; ++pos)
{
- if ((*pos).get()->GetID() == id)
+ if ((*pos)->GetID() == id)
{
debugger_sp = *pos;
break;
@@ -1202,7 +1193,7 @@ Debugger::FindDebuggerWithID (lldb::user_id_t id)
static void
TestPromptFormats (StackFrame *frame)
{
- if (frame == NULL)
+ if (frame == nullptr)
return;
StreamString s;
@@ -1277,11 +1268,11 @@ Debugger::FormatDisassemblerAddress (const FormatEntity::Entry *format,
{
FormatEntity::Entry format_entry;
- if (format == NULL)
+ if (format == nullptr)
{
- if (exe_ctx != NULL && exe_ctx->HasTargetScope())
+ if (exe_ctx != nullptr && exe_ctx->HasTargetScope())
format = exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
- if (format == NULL)
+ if (format == nullptr)
{
FormatEntity::Parse("${addr}: ", format_entry);
format = &format_entry;
@@ -1313,14 +1304,13 @@ Debugger::FormatDisassemblerAddress (const FormatEntity::Entry *format,
// has no Function or Symbol -- if SymbolContext had an IsValid() method, it
// would return false. But we do get a prev_sc pointer.
if ((sc && (sc->function || sc->symbol))
- && prev_sc && (prev_sc->function == NULL && prev_sc->symbol == NULL))
+ && prev_sc && (prev_sc->function == nullptr && prev_sc->symbol == nullptr))
{
initial_function = true;
}
- return FormatEntity::Format(*format, s, sc, exe_ctx, addr, NULL, function_changed, initial_function);
+ return FormatEntity::Format(*format, s, sc, exe_ctx, addr, nullptr, function_changed, initial_function);
}
-
void
Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
{
@@ -1340,7 +1330,7 @@ Debugger::EnableLog (const char *channel, const char **categories, const char *l
// For now when using the callback mode you always get thread & timestamp.
log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
}
- else if (log_file == NULL || *log_file == '\0')
+ else if (log_file == nullptr || *log_file == '\0')
{
log_stream_sp = GetOutputFile();
}
@@ -1360,7 +1350,7 @@ Debugger::EnableLog (const char *channel, const char **categories, const char *l
m_log_streams[log_file] = log_stream_sp;
}
}
- assert (log_stream_sp.get());
+ assert(log_stream_sp);
if (log_options == 0)
log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
@@ -1371,13 +1361,11 @@ Debugger::EnableLog (const char *channel, const char **categories, const char *l
SourceManager &
Debugger::GetSourceManager ()
{
- if (m_source_manager_ap.get() == NULL)
+ if (!m_source_manager_ap)
m_source_manager_ap.reset (new SourceManager (shared_from_this()));
return *m_source_manager_ap;
}
-
-
// This function handles events that were broadcast by the process.
void
Debugger::HandleBreakpointEvent (const EventSP &event_sp)
@@ -1428,13 +1416,13 @@ size_t
Debugger::GetProcessSTDOUT (Process *process, Stream *stream)
{
size_t total_bytes = 0;
- if (stream == NULL)
+ if (stream == nullptr)
stream = GetOutputFile().get();
if (stream)
{
// The process has stuff waiting for stdout; get it and write it out to the appropriate place.
- if (process == NULL)
+ if (process == nullptr)
{
TargetSP target_sp = GetTargetList().GetSelectedTarget();
if (target_sp)
@@ -1460,13 +1448,13 @@ size_t
Debugger::GetProcessSTDERR (Process *process, Stream *stream)
{
size_t total_bytes = 0;
- if (stream == NULL)
+ if (stream == nullptr)
stream = GetOutputFile().get();
if (stream)
{
// The process has stuff waiting for stderr; get it and write it out to the appropriate place.
- if (process == NULL)
+ if (process == nullptr)
{
TargetSP target_sp = GetTargetList().GetSelectedTarget();
if (target_sp)
@@ -1588,7 +1576,7 @@ Debugger::CancelForwardEvents (const ListenerSP &listener_sp)
void
Debugger::DefaultEventHandler()
{
- Listener& listener(GetListener());
+ ListenerSP listener_sp(GetListener());
ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
@@ -1604,10 +1592,10 @@ Debugger::DefaultEventHandler()
Thread::eBroadcastBitStackChanged |
Thread::eBroadcastBitThreadSelected );
- listener.StartListeningForEventSpec (*this, target_event_spec);
- listener.StartListeningForEventSpec (*this, process_event_spec);
- listener.StartListeningForEventSpec (*this, thread_event_spec);
- listener.StartListeningForEvents (m_command_interpreter_ap.get(),
+ listener_sp->StartListeningForEventSpec (m_broadcaster_manager_sp, target_event_spec);
+ listener_sp->StartListeningForEventSpec (m_broadcaster_manager_sp, process_event_spec);
+ listener_sp->StartListeningForEventSpec (m_broadcaster_manager_sp, thread_event_spec);
+ listener_sp->StartListeningForEvents (m_command_interpreter_ap.get(),
CommandInterpreter::eBroadcastBitQuitCommandReceived |
CommandInterpreter::eBroadcastBitAsynchronousOutputData |
CommandInterpreter::eBroadcastBitAsynchronousErrorData );
@@ -1620,7 +1608,7 @@ Debugger::DefaultEventHandler()
while (!done)
{
EventSP event_sp;
- if (listener.WaitForEvent(NULL, event_sp))
+ if (listener_sp->WaitForEvent(nullptr, event_sp))
{
if (event_sp)
{
@@ -1702,21 +1690,22 @@ Debugger::StartEventHandlerThread()
// it is up and running and listening to events before we return from
// this function. We do this by listening to events for the
// eBroadcastBitEventThreadIsListening from the m_sync_broadcaster
- Listener listener("lldb.debugger.event-handler");
- listener.StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening);
+ ListenerSP listener_sp(Listener::MakeListener("lldb.debugger.event-handler"));
+ listener_sp->StartListeningForEvents(&m_sync_broadcaster, eBroadcastBitEventThreadIsListening);
// Use larger 8MB stack for this thread
- m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler", EventHandlerThread,
+ m_event_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.event-handler",
+ EventHandlerThread,
this,
- NULL,
+ nullptr,
g_debugger_event_thread_stack_bytes);
// Make sure DefaultEventHandler() is running and listening to events before we return
// from this function. We are only listening for events of type
// eBroadcastBitEventThreadIsListening so we don't need to check the event, we just need
- // to wait an infinite amount of time for it (NULL timeout as the first parameter)
+ // to wait an infinite amount of time for it (nullptr timeout as the first parameter)
lldb::EventSP event_sp;
- listener.WaitForEvent(NULL, event_sp);
+ listener_sp->WaitForEvent(nullptr, event_sp);
}
return m_event_handler_thread.IsJoinable();
}
@@ -1731,7 +1720,6 @@ Debugger::StopEventHandlerThread()
}
}
-
lldb::thread_result_t
Debugger::IOHandlerThread (lldb::thread_arg_t arg)
{
@@ -1751,11 +1739,11 @@ bool
Debugger::StartIOHandlerThread()
{
if (!m_io_handler_thread.IsJoinable())
- m_io_handler_thread = ThreadLauncher::LaunchThread ("lldb.debugger.io-handler",
- IOHandlerThread,
- this,
- NULL,
- 8*1024*1024); // Use larger 8MB stack for this thread
+ m_io_handler_thread = ThreadLauncher::LaunchThread("lldb.debugger.io-handler",
+ IOHandlerThread,
+ this,
+ nullptr,
+ 8*1024*1024); // Use larger 8MB stack for this thread
return m_io_handler_thread.IsJoinable();
}
@@ -1817,9 +1805,9 @@ Debugger::RunREPL (LanguageType language, const char *repl_options)
{
language = *repl_languages.begin();
}
- else if (repl_languages.size() == 0)
+ else if (repl_languages.empty())
{
- err.SetErrorStringWithFormat("LLDB isn't configured with support support for any REPLs.");
+ err.SetErrorStringWithFormat("LLDB isn't configured with REPL support for any languages.");
return err;
}
else
@@ -1849,4 +1837,3 @@ Debugger::RunREPL (LanguageType language, const char *repl_options)
return err;
}
-
diff --git a/source/Core/Disassembler.cpp b/source/Core/Disassembler.cpp
index bb5f106ca611..1e6a245261bb 100644
--- a/source/Core/Disassembler.cpp
+++ b/source/Core/Disassembler.cpp
@@ -11,18 +11,21 @@
// C Includes
// C++ Includes
+#include <cstdio>
+#include <cstring>
+
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
-#include "lldb/Core/Error.h"
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/EmulateInstruction.h"
+#include "lldb/Core/Error.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/Timer.h"
+#include "lldb/Host/FileSystem.h"
#include "lldb/Interpreter/OptionValue.h"
#include "lldb/Interpreter/OptionValueArray.h"
#include "lldb/Interpreter/OptionValueDictionary.h"
@@ -35,13 +38,13 @@
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
+#include "lldb/lldb-private.h"
#define DEFAULT_DISASM_BYTE_SIZE 32
using namespace lldb;
using namespace lldb_private;
-
DisassemblerSP
Disassembler::FindPlugin (const ArchSpec &arch, const char *flavor, const char *plugin_name)
{
@@ -50,7 +53,7 @@ Disassembler::FindPlugin (const ArchSpec &arch, const char *flavor, const char *
arch.GetArchitectureName(),
plugin_name);
- DisassemblerCreateInstance create_callback = NULL;
+ DisassemblerCreateInstance create_callback = nullptr;
if (plugin_name)
{
@@ -60,17 +63,17 @@ Disassembler::FindPlugin (const ArchSpec &arch, const char *flavor, const char *
{
DisassemblerSP disassembler_sp(create_callback(arch, flavor));
- if (disassembler_sp.get())
+ if (disassembler_sp)
return disassembler_sp;
}
}
else
{
- for (uint32_t idx = 0; (create_callback = PluginManager::GetDisassemblerCreateCallbackAtIndex(idx)) != NULL; ++idx)
+ for (uint32_t idx = 0; (create_callback = PluginManager::GetDisassemblerCreateCallbackAtIndex(idx)) != nullptr; ++idx)
{
DisassemblerSP disassembler_sp(create_callback(arch, flavor));
- if (disassembler_sp.get())
+ if (disassembler_sp)
return disassembler_sp;
}
}
@@ -80,7 +83,7 @@ Disassembler::FindPlugin (const ArchSpec &arch, const char *flavor, const char *
DisassemblerSP
Disassembler::FindPluginForTarget(const TargetSP target_sp, const ArchSpec &arch, const char *flavor, const char *plugin_name)
{
- if (target_sp && flavor == NULL)
+ if (target_sp && flavor == nullptr)
{
// FIXME - we don't have the mechanism in place to do per-architecture settings. But since we know that for now
// we only support flavors on x86 & x86_64,
@@ -91,7 +94,6 @@ Disassembler::FindPluginForTarget(const TargetSP target_sp, const ArchSpec &arch
return FindPlugin(arch, flavor, plugin_name);
}
-
static void
ResolveAddress (const ExecutionContext &exe_ctx,
const Address &addr,
@@ -122,19 +124,16 @@ ResolveAddress (const ExecutionContext &exe_ctx,
}
size_t
-Disassembler::Disassemble
-(
- Debugger &debugger,
- const ArchSpec &arch,
- const char *plugin_name,
- const char *flavor,
- const ExecutionContext &exe_ctx,
- SymbolContextList &sc_list,
- uint32_t num_instructions,
- uint32_t num_mixed_context_lines,
- uint32_t options,
- Stream &strm
-)
+Disassembler::Disassemble(Debugger &debugger,
+ const ArchSpec &arch,
+ const char *plugin_name,
+ const char *flavor,
+ const ExecutionContext &exe_ctx,
+ SymbolContextList &sc_list,
+ uint32_t num_instructions,
+ uint32_t num_mixed_context_lines,
+ uint32_t options,
+ Stream &strm)
{
size_t success_count = 0;
const size_t count = sc_list.GetSize();
@@ -142,9 +141,9 @@ Disassembler::Disassemble
AddressRange range;
const uint32_t scope = eSymbolContextBlock | eSymbolContextFunction | eSymbolContextSymbol;
const bool use_inline_block_range = true;
- for (size_t i=0; i<count; ++i)
+ for (size_t i = 0; i < count; ++i)
{
- if (sc_list.GetContextAtIndex(i, sc) == false)
+ if (!sc_list.GetContextAtIndex(i, sc))
break;
for (uint32_t range_idx = 0; sc.GetAddressRange(scope, range_idx, use_inline_block_range, range); ++range_idx)
{
@@ -168,20 +167,17 @@ Disassembler::Disassemble
}
bool
-Disassembler::Disassemble
-(
- Debugger &debugger,
- const ArchSpec &arch,
- const char *plugin_name,
- const char *flavor,
- const ExecutionContext &exe_ctx,
- const ConstString &name,
- Module *module,
- uint32_t num_instructions,
- uint32_t num_mixed_context_lines,
- uint32_t options,
- Stream &strm
-)
+Disassembler::Disassemble(Debugger &debugger,
+ const ArchSpec &arch,
+ const char *plugin_name,
+ const char *flavor,
+ const ExecutionContext &exe_ctx,
+ const ConstString &name,
+ Module *module,
+ uint32_t num_instructions,
+ uint32_t num_mixed_context_lines,
+ uint32_t options,
+ Stream &strm)
{
SymbolContextList sc_list;
if (name)
@@ -190,13 +186,13 @@ Disassembler::Disassemble
const bool include_inlines = true;
if (module)
{
- module->FindFunctions (name,
- NULL,
- eFunctionNameTypeAuto,
- include_symbols,
- include_inlines,
- true,
- sc_list);
+ module->FindFunctions(name,
+ nullptr,
+ eFunctionNameTypeAuto,
+ include_symbols,
+ include_inlines,
+ true,
+ sc_list);
}
else if (exe_ctx.GetTargetPtr())
{
@@ -225,17 +221,13 @@ Disassembler::Disassemble
return false;
}
-
lldb::DisassemblerSP
-Disassembler::DisassembleRange
-(
- const ArchSpec &arch,
- const char *plugin_name,
- const char *flavor,
- const ExecutionContext &exe_ctx,
- const AddressRange &range,
- bool prefer_file_cache
-)
+Disassembler::DisassembleRange(const ArchSpec &arch,
+ const char *plugin_name,
+ const char *flavor,
+ const ExecutionContext &exe_ctx,
+ const AddressRange &range,
+ bool prefer_file_cache)
{
lldb::DisassemblerSP disasm_sp;
if (range.GetByteSize() > 0 && range.GetBaseAddress().IsValid())
@@ -244,7 +236,7 @@ Disassembler::DisassembleRange
if (disasm_sp)
{
- size_t bytes_disassembled = disasm_sp->ParseInstructions (&exe_ctx, range, NULL, prefer_file_cache);
+ size_t bytes_disassembled = disasm_sp->ParseInstructions(&exe_ctx, range, nullptr, prefer_file_cache);
if (bytes_disassembled == 0)
disasm_sp.reset();
}
@@ -284,27 +276,23 @@ Disassembler::DisassembleBytes (const ArchSpec &arch,
return disasm_sp;
}
-
bool
-Disassembler::Disassemble
-(
- Debugger &debugger,
- const ArchSpec &arch,
- const char *plugin_name,
- const char *flavor,
- const ExecutionContext &exe_ctx,
- const AddressRange &disasm_range,
- uint32_t num_instructions,
- uint32_t num_mixed_context_lines,
- uint32_t options,
- Stream &strm
-)
+Disassembler::Disassemble(Debugger &debugger,
+ const ArchSpec &arch,
+ const char *plugin_name,
+ const char *flavor,
+ const ExecutionContext &exe_ctx,
+ const AddressRange &disasm_range,
+ uint32_t num_instructions,
+ uint32_t num_mixed_context_lines,
+ uint32_t options,
+ Stream &strm)
{
if (disasm_range.GetByteSize())
{
lldb::DisassemblerSP disasm_sp (Disassembler::FindPluginForTarget(exe_ctx.GetTargetSP(), arch, flavor, plugin_name));
- if (disasm_sp.get())
+ if (disasm_sp)
{
AddressRange range;
ResolveAddress (exe_ctx, disasm_range.GetBaseAddress(), range.GetBaseAddress());
@@ -314,38 +302,24 @@ Disassembler::Disassemble
if (bytes_disassembled == 0)
return false;
- bool result = PrintInstructions (disasm_sp.get(),
- debugger,
- arch,
- exe_ctx,
- num_instructions,
- num_mixed_context_lines,
- options,
- strm);
-
- // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
- // I'll fix that but for now, just clear the list and it will go away nicely.
- disasm_sp->GetInstructionList().Clear();
- return result;
+ return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx, num_instructions,
+ num_mixed_context_lines, options, strm);
}
}
return false;
}
bool
-Disassembler::Disassemble
-(
- Debugger &debugger,
- const ArchSpec &arch,
- const char *plugin_name,
- const char *flavor,
- const ExecutionContext &exe_ctx,
- const Address &start_address,
- uint32_t num_instructions,
- uint32_t num_mixed_context_lines,
- uint32_t options,
- Stream &strm
-)
+Disassembler::Disassemble(Debugger &debugger,
+ const ArchSpec &arch,
+ const char *plugin_name,
+ const char *flavor,
+ const ExecutionContext &exe_ctx,
+ const Address &start_address,
+ uint32_t num_instructions,
+ uint32_t num_mixed_context_lines,
+ uint32_t options,
+ Stream &strm)
{
if (num_instructions > 0)
{
@@ -353,7 +327,7 @@ Disassembler::Disassemble
arch,
flavor,
plugin_name));
- if (disasm_sp.get())
+ if (disasm_sp)
{
Address addr;
ResolveAddress (exe_ctx, start_address, addr);
@@ -364,36 +338,17 @@ Disassembler::Disassemble
prefer_file_cache);
if (bytes_disassembled == 0)
return false;
- bool result = PrintInstructions (disasm_sp.get(),
- debugger,
- arch,
- exe_ctx,
- num_instructions,
- num_mixed_context_lines,
- options,
- strm);
-
- // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
- // I'll fix that but for now, just clear the list and it will go away nicely.
- disasm_sp->GetInstructionList().Clear();
- return result;
+ return PrintInstructions(disasm_sp.get(), debugger, arch, exe_ctx, num_instructions,
+ num_mixed_context_lines, options, strm);
}
}
return false;
}
-
-bool
-Disassembler::PrintInstructions
-(
- Disassembler *disasm_ptr,
- Debugger &debugger,
- const ArchSpec &arch,
- const ExecutionContext &exe_ctx,
- uint32_t num_instructions,
- uint32_t num_mixed_context_lines,
- uint32_t options,
- Stream &strm
-)
+
+bool
+Disassembler::PrintInstructions(Disassembler *disasm_ptr, Debugger &debugger, const ArchSpec &arch,
+ const ExecutionContext &exe_ctx, uint32_t num_instructions,
+ uint32_t num_mixed_context_lines, uint32_t options, Stream &strm)
{
// We got some things disassembled...
size_t num_instructions_found = disasm_ptr->GetInstructionList().GetSize();
@@ -406,7 +361,7 @@ Disassembler::PrintInstructions
SymbolContext sc;
SymbolContext prev_sc;
AddressRange sc_range;
- const Address *pc_addr_ptr = NULL;
+ const Address *pc_addr_ptr = nullptr;
StackFrame *frame = exe_ctx.GetFramePtr();
TargetSP target_sp (exe_ctx.GetTargetSP());
@@ -419,7 +374,7 @@ Disassembler::PrintInstructions
const uint32_t scope = eSymbolContextLineEntry | eSymbolContextFunction | eSymbolContextSymbol;
const bool use_inline_block_range = false;
- const FormatEntity::Entry *disassembly_format = NULL;
+ const FormatEntity::Entry *disassembly_format = nullptr;
FormatEntity::Entry format;
if (exe_ctx.HasTargetScope())
{
@@ -449,7 +404,7 @@ Disassembler::PrintInstructions
if (resolved_mask)
{
StreamString strmstr;
- Debugger::FormatDisassemblerAddress (disassembly_format, &sc, NULL, &exe_ctx, &addr, strmstr);
+ Debugger::FormatDisassemblerAddress(disassembly_format, &sc, nullptr, &exe_ctx, &addr, strmstr);
size_t cur_line = strmstr.GetSizeOfLastLine();
if (cur_line > address_text_size)
address_text_size = cur_line;
@@ -509,7 +464,7 @@ Disassembler::PrintInstructions
}
const bool show_bytes = (options & eOptionShowBytes) != 0;
- inst->Dump (&strm, max_opcode_byte_size, true, show_bytes, &exe_ctx, &sc, &prev_sc, NULL, address_text_size);
+ inst->Dump(&strm, max_opcode_byte_size, true, show_bytes, &exe_ctx, &sc, &prev_sc, nullptr, address_text_size);
strm.EOL();
}
else
@@ -521,20 +476,16 @@ Disassembler::PrintInstructions
return true;
}
-
bool
-Disassembler::Disassemble
-(
- Debugger &debugger,
- const ArchSpec &arch,
- const char *plugin_name,
- const char *flavor,
- const ExecutionContext &exe_ctx,
- uint32_t num_instructions,
- uint32_t num_mixed_context_lines,
- uint32_t options,
- Stream &strm
-)
+Disassembler::Disassemble(Debugger &debugger,
+ const ArchSpec &arch,
+ const char *plugin_name,
+ const char *flavor,
+ const ExecutionContext &exe_ctx,
+ uint32_t num_instructions,
+ uint32_t num_mixed_context_lines,
+ uint32_t options,
+ Stream &strm)
{
AddressRange range;
StackFrame *frame = exe_ctx.GetFramePtr();
@@ -579,9 +530,7 @@ Instruction::Instruction(const Address &address, AddressClass addr_class) :
{
}
-Instruction::~Instruction()
-{
-}
+Instruction::~Instruction() = default;
AddressClass
Instruction::GetAddressClass ()
@@ -664,12 +613,12 @@ Instruction::Dump (lldb_private::Stream *s,
bool
Instruction::DumpEmulation (const ArchSpec &arch)
{
- std::unique_ptr<EmulateInstruction> insn_emulator_ap (EmulateInstruction::FindPlugin (arch, eInstructionTypeAny, NULL));
- if (insn_emulator_ap.get())
- {
- insn_emulator_ap->SetInstruction (GetOpcode(), GetAddress(), NULL);
+ std::unique_ptr<EmulateInstruction> insn_emulator_ap(EmulateInstruction::FindPlugin(arch, eInstructionTypeAny, nullptr));
+ if (insn_emulator_ap)
+ {
+ insn_emulator_ap->SetInstruction(GetOpcode(), GetAddress(), nullptr);
return insn_emulator_ap->EvaluateInstruction (0);
- }
+ }
return false;
}
@@ -714,7 +663,7 @@ Instruction::ReadArray (FILE *in_file, Stream *out_stream, OptionValue::Type dat
line.clear();
}
- if (line.size() > 0)
+ if (!line.empty())
{
std::string value;
static RegularExpression g_reg_exp ("^[ \t]*([^ \t]+)[ \t]*$");
@@ -784,7 +733,7 @@ Instruction::ReadDictionary (FILE *in_file, Stream *out_stream)
}
// Try to find a key-value pair in the current line and add it to the dictionary.
- if (line.size() > 0)
+ if (!line.empty())
{
static RegularExpression g_reg_exp ("^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)[ \t]*$");
RegularExpression::Match regex_match(2);
@@ -816,7 +765,7 @@ Instruction::ReadDictionary (FILE *in_file, Stream *out_stream)
assert (value.size() == 1);
// value is a dictionary
value_sp = ReadDictionary (in_file, out_stream);
- if (value_sp.get() == NULL)
+ if (!value_sp)
{
option_value_sp.reset ();
return option_value_sp;
@@ -827,7 +776,7 @@ Instruction::ReadDictionary (FILE *in_file, Stream *out_stream)
assert (value.size() == 1);
// value is an array
value_sp = ReadArray (in_file, out_stream, data_type);
- if (value_sp.get() == NULL)
+ if (!value_sp)
{
option_value_sp.reset ();
return option_value_sp;
@@ -848,8 +797,6 @@ Instruction::ReadDictionary (FILE *in_file, Stream *out_stream)
value_sp.reset (new OptionValueString (value.c_str(), ""));
}
-
-
if (const_key == encoding_key)
{
// A 'data_encoding=..." is NOT a normal key-value pair; it is meta-data indicating the
@@ -876,8 +823,7 @@ Instruction::TestEmulation (Stream *out_stream, const char *file_name)
out_stream->Printf ("Instruction::TestEmulation: Missing file_name.");
return false;
}
-
- FILE *test_file = fopen (file_name, "r");
+ FILE *test_file = FileSystem::Fopen(file_name, "r");
if (!test_file)
{
out_stream->Printf ("Instruction::TestEmulation: Attempt to open test file failed.");
@@ -902,7 +848,7 @@ Instruction::TestEmulation (Stream *out_stream, const char *file_name)
// Read all the test information from the test file into an OptionValueDictionary.
OptionValueSP data_dictionary_sp (ReadDictionary (test_file, out_stream));
- if (data_dictionary_sp.get() == NULL)
+ if (!data_dictionary_sp)
{
out_stream->Printf ("Instruction::TestEmulation: Error reading Dictionary Object.\n");
fclose (test_file);
@@ -917,17 +863,16 @@ Instruction::TestEmulation (Stream *out_stream, const char *file_name)
OptionValueSP value_sp = data_dictionary->GetValueForKey (description_key);
- if (value_sp.get() == NULL)
+ if (!value_sp)
{
out_stream->Printf ("Instruction::TestEmulation: Test file does not contain description string.\n");
return false;
}
SetDescription (value_sp->GetStringValue());
-
-
+
value_sp = data_dictionary->GetValueForKey (triple_key);
- if (value_sp.get() == NULL)
+ if (!value_sp)
{
out_stream->Printf ("Instruction::TestEmulation: Test file does not contain triple.\n");
return false;
@@ -937,8 +882,8 @@ Instruction::TestEmulation (Stream *out_stream, const char *file_name)
arch.SetTriple (llvm::Triple (value_sp->GetStringValue()));
bool success = false;
- std::unique_ptr<EmulateInstruction> insn_emulator_ap (EmulateInstruction::FindPlugin (arch, eInstructionTypeAny, NULL));
- if (insn_emulator_ap.get())
+ std::unique_ptr<EmulateInstruction> insn_emulator_ap(EmulateInstruction::FindPlugin(arch, eInstructionTypeAny, nullptr));
+ if (insn_emulator_ap)
success = insn_emulator_ap->TestEmulation (out_stream, arch, data_dictionary);
if (success)
@@ -958,19 +903,18 @@ Instruction::Emulate (const ArchSpec &arch,
EmulateInstruction::ReadRegisterCallback read_reg_callback,
EmulateInstruction::WriteRegisterCallback write_reg_callback)
{
- std::unique_ptr<EmulateInstruction> insn_emulator_ap (EmulateInstruction::FindPlugin (arch, eInstructionTypeAny, NULL));
- if (insn_emulator_ap.get())
- {
- insn_emulator_ap->SetBaton (baton);
- insn_emulator_ap->SetCallbacks (read_mem_callback, write_mem_callback, read_reg_callback, write_reg_callback);
- insn_emulator_ap->SetInstruction (GetOpcode(), GetAddress(), NULL);
- return insn_emulator_ap->EvaluateInstruction (evaluate_options);
- }
+ std::unique_ptr<EmulateInstruction> insn_emulator_ap(EmulateInstruction::FindPlugin(arch, eInstructionTypeAny, nullptr));
+ if (insn_emulator_ap)
+ {
+ insn_emulator_ap->SetBaton(baton);
+ insn_emulator_ap->SetCallbacks(read_mem_callback, write_mem_callback, read_reg_callback, write_reg_callback);
+ insn_emulator_ap->SetInstruction(GetOpcode(), GetAddress(), nullptr);
+ return insn_emulator_ap->EvaluateInstruction(evaluate_options);
+ }
return false;
}
-
uint32_t
Instruction::GetData (DataExtractor &data)
{
@@ -982,9 +926,7 @@ InstructionList::InstructionList() :
{
}
-InstructionList::~InstructionList()
-{
-}
+InstructionList::~InstructionList() = default;
size_t
InstructionList::GetSize() const
@@ -1008,8 +950,6 @@ InstructionList::GetMaxOpcocdeByteSize () const
return max_inst_size;
}
-
-
InstructionSP
InstructionList::GetInstructionAtIndex (size_t idx) const
{
@@ -1028,7 +968,7 @@ InstructionList::Dump (Stream *s,
const uint32_t max_opcode_byte_size = GetMaxOpcocdeByteSize();
collection::const_iterator pos, begin, end;
- const FormatEntity::Entry *disassembly_format = NULL;
+ const FormatEntity::Entry *disassembly_format = nullptr;
FormatEntity::Entry format;
if (exe_ctx && exe_ctx->HasTargetScope())
{
@@ -1046,15 +986,14 @@ InstructionList::Dump (Stream *s,
{
if (pos != begin)
s->EOL();
- (*pos)->Dump(s, max_opcode_byte_size, show_address, show_bytes, exe_ctx, NULL, NULL, disassembly_format, 0);
+ (*pos)->Dump(s, max_opcode_byte_size, show_address, show_bytes, exe_ctx, nullptr, nullptr, disassembly_format, 0);
}
}
-
void
InstructionList::Clear()
{
- m_instructions.clear();
+ m_instructions.clear();
}
void
@@ -1144,7 +1083,6 @@ InstructionList::GetIndexOfInstructionAtAddress (const Address &address)
return index;
}
-
uint32_t
InstructionList::GetIndexOfInstructionAtLoadAddress (lldb::addr_t load_addr, Target &target)
{
@@ -1163,7 +1101,7 @@ Disassembler::ParseInstructions (const ExecutionContext *exe_ctx,
{
Target *target = exe_ctx->GetTargetPtr();
const addr_t byte_size = range.GetByteSize();
- if (target == NULL || byte_size == 0 || !range.GetBaseAddress().IsValid())
+ if (target == nullptr || byte_size == 0 || !range.GetBaseAddress().IsValid())
return 0;
DataBufferHeap *heap_buffer = new DataBufferHeap (byte_size, '\0');
@@ -1186,7 +1124,8 @@ Disassembler::ParseInstructions (const ExecutionContext *exe_ctx,
m_arch.GetByteOrder(),
m_arch.GetAddressByteSize());
const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
- return DecodeInstructions (range.GetBaseAddress(), data, 0, UINT32_MAX, false, data_from_file);
+ return DecodeInstructions(range.GetBaseAddress(), data, 0, UINT32_MAX, false,
+ data_from_file);
}
else if (error_strm_ptr)
{
@@ -1212,14 +1151,14 @@ Disassembler::ParseInstructions (const ExecutionContext *exe_ctx,
{
m_instruction_list.Clear();
- if (exe_ctx == NULL || num_instructions == 0 || !start.IsValid())
+ if (exe_ctx == nullptr || num_instructions == 0 || !start.IsValid())
return 0;
Target *target = exe_ctx->GetTargetPtr();
// Calculate the max buffer size we will need in order to disassemble
const addr_t byte_size = num_instructions * m_arch.GetMaximumOpcodeByteSize();
- if (target == NULL || byte_size == 0)
+ if (target == nullptr || byte_size == 0)
return 0;
DataBufferHeap *heap_buffer = new DataBufferHeap (byte_size, '\0');
@@ -1262,7 +1201,7 @@ Disassembler::Disassembler(const ArchSpec& arch, const char *flavor) :
m_base_addr(LLDB_INVALID_ADDRESS),
m_flavor ()
{
- if (flavor == NULL)
+ if (flavor == nullptr)
m_flavor.assign("default");
else
m_flavor.assign(flavor);
@@ -1270,10 +1209,7 @@ Disassembler::Disassembler(const ArchSpec& arch, const char *flavor) :
// If this is an arm variant that can only include thumb (T16, T32)
// instructions, force the arch triple to be "thumbv.." instead of
// "armv..."
- if ((arch.GetTriple().getArch() == llvm::Triple::arm || arch.GetTriple().getArch() == llvm::Triple::thumb)
- && (arch.GetCore() == ArchSpec::Core::eCore_arm_armv7m
- || arch.GetCore() == ArchSpec::Core::eCore_arm_armv7em
- || arch.GetCore() == ArchSpec::Core::eCore_arm_armv6m))
+ if (arch.IsAlwaysThumbInstructions())
{
std::string thumb_arch_name (arch.GetTriple().getArchName().str());
// Replace "arm" with "thumb" so we get all thumb variants correct
@@ -1286,12 +1222,7 @@ Disassembler::Disassembler(const ArchSpec& arch, const char *flavor) :
}
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-Disassembler::~Disassembler()
-{
-}
+Disassembler::~Disassembler() = default;
InstructionList &
Disassembler::GetInstructionList ()
@@ -1308,15 +1239,14 @@ Disassembler::GetInstructionList () const
//----------------------------------------------------------------------
// Class PseudoInstruction
//----------------------------------------------------------------------
+
PseudoInstruction::PseudoInstruction () :
Instruction (Address(), eAddressClassUnknown),
m_description ()
{
}
-PseudoInstruction::~PseudoInstruction ()
-{
-}
+PseudoInstruction::~PseudoInstruction() = default;
bool
PseudoInstruction::DoesBranch ()
@@ -1340,7 +1270,6 @@ PseudoInstruction::Decode (const lldb_private::Disassembler &disassembler,
return m_opcode.GetByteSize();
}
-
void
PseudoInstruction::SetOpcode (size_t opcode_size, void *opcode_data)
{
diff --git a/source/Core/DynamicLoader.cpp b/source/Core/DynamicLoader.cpp
index 4d2824c5f334..f41ff4a80c83 100644
--- a/source/Core/DynamicLoader.cpp
+++ b/source/Core/DynamicLoader.cpp
@@ -7,6 +7,10 @@
//
//===----------------------------------------------------------------------===//
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
#include "lldb/lldb-private.h"
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Process.h"
@@ -22,7 +26,7 @@ using namespace lldb_private;
DynamicLoader*
DynamicLoader::FindPlugin (Process *process, const char *plugin_name)
{
- DynamicLoaderCreateInstance create_callback = NULL;
+ DynamicLoaderCreateInstance create_callback = nullptr;
if (plugin_name)
{
ConstString const_plugin_name(plugin_name);
@@ -30,42 +34,34 @@ DynamicLoader::FindPlugin (Process *process, const char *plugin_name)
if (create_callback)
{
std::unique_ptr<DynamicLoader> instance_ap(create_callback(process, true));
- if (instance_ap.get())
+ if (instance_ap)
return instance_ap.release();
}
}
else
{
- for (uint32_t idx = 0; (create_callback = PluginManager::GetDynamicLoaderCreateCallbackAtIndex(idx)) != NULL; ++idx)
+ for (uint32_t idx = 0; (create_callback = PluginManager::GetDynamicLoaderCreateCallbackAtIndex(idx)) != nullptr; ++idx)
{
std::unique_ptr<DynamicLoader> instance_ap(create_callback(process, false));
- if (instance_ap.get())
+ if (instance_ap)
return instance_ap.release();
}
}
- return NULL;
+ return nullptr;
}
-
-//----------------------------------------------------------------------
-// DynamicLoader constructor
-//----------------------------------------------------------------------
DynamicLoader::DynamicLoader(Process *process) :
m_process (process)
{
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-DynamicLoader::~DynamicLoader()
-{
-}
+DynamicLoader::~DynamicLoader() = default;
//----------------------------------------------------------------------
// Accessosors to the global setting as to whether to stop at image
// (shared library) loading/unloading.
//----------------------------------------------------------------------
+
bool
DynamicLoader::GetStopWhenImagesChange () const
{
@@ -84,7 +80,7 @@ DynamicLoader::GetTargetExecutable()
Target &target = m_process->GetTarget();
ModuleSP executable = target.GetExecutableModule();
- if (executable.get())
+ if (executable)
{
if (executable->GetFileSpec().Exists())
{
@@ -92,7 +88,7 @@ DynamicLoader::GetTargetExecutable()
ModuleSP module_sp (new Module (module_spec));
// Check if the executable has changed and set it to the target executable if they differ.
- if (module_sp.get() && module_sp->GetUUID().IsValid() && executable->GetUUID().IsValid())
+ if (module_sp && module_sp->GetUUID().IsValid() && executable->GetUUID().IsValid())
{
if (module_sp->GetUUID() != executable->GetUUID())
executable.reset();
@@ -102,7 +98,7 @@ DynamicLoader::GetTargetExecutable()
executable.reset();
}
- if (!executable.get())
+ if (!executable)
{
executable = target.GetSharedModule(module_spec);
if (executable.get() != target.GetExecutableModulePointer())
@@ -158,15 +154,14 @@ DynamicLoader::UnloadSectionsCommon(const ModuleSP module)
}
}
-
const SectionList *
DynamicLoader::GetSectionListFromModule(const ModuleSP module) const
{
SectionList *sections = nullptr;
- if (module.get())
+ if (module)
{
ObjectFile *obj_file = module->GetObjectFile();
- if (obj_file)
+ if (obj_file != nullptr)
{
sections = obj_file->GetSectionList();
}
@@ -199,7 +194,7 @@ DynamicLoader::LoadModuleAtAddress(const FileSpec &file,
{
// Try to fetch the load address of the file from the process as we need absolute load
// address to read the file out of the memory instead of a load bias.
- bool is_loaded;
+ bool is_loaded = false;
lldb::addr_t load_addr;
Error error = m_process->GetFileLoadAddress(file, is_loaded, load_addr);
if (error.Success() && is_loaded)
@@ -220,7 +215,6 @@ int64_t
DynamicLoader::ReadUnsignedIntWithSizeInBytes(addr_t addr, int size_in_bytes)
{
Error error;
-
uint64_t value = m_process->ReadUnsignedIntegerFromMemory(addr, size_in_bytes, 0, error);
if (error.Fail())
return -1;
diff --git a/source/Core/EmulateInstruction.cpp b/source/Core/EmulateInstruction.cpp
index 9b6beeb8299a..e46cfb2d8945 100644
--- a/source/Core/EmulateInstruction.cpp
+++ b/source/Core/EmulateInstruction.cpp
@@ -9,6 +9,12 @@
#include "lldb/Core/EmulateInstruction.h"
+// C Includes
+// C++ Includes
+#include <cstring>
+
+// Other libraries and framework includes
+// Project includes
#include "lldb/Core/Address.h"
#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Error.h"
@@ -29,7 +35,7 @@ using namespace lldb_private;
EmulateInstruction*
EmulateInstruction::FindPlugin (const ArchSpec &arch, InstructionType supported_inst_type, const char *plugin_name)
{
- EmulateInstructionCreateInstance create_callback = NULL;
+ EmulateInstructionCreateInstance create_callback = nullptr;
if (plugin_name)
{
ConstString const_plugin_name (plugin_name);
@@ -43,33 +49,32 @@ EmulateInstruction::FindPlugin (const ArchSpec &arch, InstructionType supported_
}
else
{
- for (uint32_t idx = 0; (create_callback = PluginManager::GetEmulateInstructionCreateCallbackAtIndex(idx)) != NULL; ++idx)
+ for (uint32_t idx = 0; (create_callback = PluginManager::GetEmulateInstructionCreateCallbackAtIndex(idx)) != nullptr; ++idx)
{
EmulateInstruction *emulate_insn_ptr = create_callback(arch, supported_inst_type);
if (emulate_insn_ptr)
return emulate_insn_ptr;
}
}
- return NULL;
+ return nullptr;
}
EmulateInstruction::EmulateInstruction (const ArchSpec &arch) :
- m_arch (arch),
- m_baton (NULL),
- m_read_mem_callback (&ReadMemoryDefault),
- m_write_mem_callback (&WriteMemoryDefault),
- m_read_reg_callback (&ReadRegisterDefault),
- m_write_reg_callback (&WriteRegisterDefault),
- m_addr (LLDB_INVALID_ADDRESS)
+ m_arch(arch),
+ m_baton(nullptr),
+ m_read_mem_callback(&ReadMemoryDefault),
+ m_write_mem_callback(&WriteMemoryDefault),
+ m_read_reg_callback(&ReadRegisterDefault),
+ m_write_reg_callback(&WriteRegisterDefault),
+ m_addr(LLDB_INVALID_ADDRESS)
{
::memset (&m_opcode, 0, sizeof (m_opcode));
}
-
bool
EmulateInstruction::ReadRegister (const RegisterInfo *reg_info, RegisterValue& reg_value)
{
- if (m_read_reg_callback)
+ if (m_read_reg_callback != nullptr)
return m_read_reg_callback (this, m_baton, reg_info, reg_value);
return false;
}
@@ -115,7 +120,7 @@ EmulateInstruction::WriteRegister (const Context &context,
const RegisterInfo *reg_info,
const RegisterValue& reg_value)
{
- if (m_write_reg_callback)
+ if (m_write_reg_callback != nullptr)
return m_write_reg_callback (this, m_baton, context, reg_info, reg_value);
return false;
}
@@ -132,14 +137,12 @@ EmulateInstruction::WriteRegister (const Context &context,
return false;
}
-
bool
EmulateInstruction::WriteRegisterUnsigned (const Context &context,
lldb::RegisterKind reg_kind,
uint32_t reg_num,
uint64_t uint_value)
{
-
RegisterInfo reg_info;
if (GetRegisterInfo(reg_kind, reg_num, reg_info))
{
@@ -155,8 +158,7 @@ EmulateInstruction::WriteRegisterUnsigned (const Context &context,
const RegisterInfo *reg_info,
uint64_t uint_value)
{
-
- if (reg_info)
+ if (reg_info != nullptr)
{
RegisterValue reg_value;
if (reg_value.SetUInt(uint_value, reg_info->byte_size))
@@ -171,7 +173,7 @@ EmulateInstruction::ReadMemory (const Context &context,
void *dst,
size_t dst_len)
{
- if (m_read_mem_callback)
+ if (m_read_mem_callback != nullptr)
return m_read_mem_callback (this, m_baton, context, addr, dst, dst_len) == dst_len;
return false;
}
@@ -202,7 +204,6 @@ EmulateInstruction::ReadMemoryUnsigned (const Context &context, lldb::addr_t add
return uval64;
}
-
bool
EmulateInstruction::WriteMemoryUnsigned (const Context &context,
lldb::addr_t addr,
@@ -213,9 +214,7 @@ EmulateInstruction::WriteMemoryUnsigned (const Context &context,
strm.PutMaxHex64 (uval, uval_byte_size);
size_t bytes_written = m_write_mem_callback (this, m_baton, context, addr, strm.GetData(), uval_byte_size);
- if (bytes_written == uval_byte_size)
- return true;
- return false;
+ return (bytes_written == uval_byte_size);
}
bool
@@ -224,12 +223,11 @@ EmulateInstruction::WriteMemory (const Context &context,
const void *src,
size_t src_len)
{
- if (m_write_mem_callback)
+ if (m_write_mem_callback != nullptr)
return m_write_mem_callback (this, m_baton, context, addr, src, src_len) == src_len;
return false;
}
-
void
EmulateInstruction::SetBaton (void *baton)
{
@@ -254,29 +252,24 @@ EmulateInstruction::SetReadMemCallback (ReadMemoryCallback read_mem_callback)
m_read_mem_callback = read_mem_callback;
}
-
void
EmulateInstruction::SetWriteMemCallback (WriteMemoryCallback write_mem_callback)
{
m_write_mem_callback = write_mem_callback;
}
-
void
EmulateInstruction::SetReadRegCallback (ReadRegisterCallback read_reg_callback)
{
m_read_reg_callback = read_reg_callback;
}
-
void
EmulateInstruction::SetWriteRegCallback (WriteRegisterCallback write_reg_callback)
{
m_write_reg_callback = write_reg_callback;
}
-
-
//
// Read & Write Memory and Registers callback functions.
//
@@ -289,7 +282,7 @@ EmulateInstruction::ReadMemoryFrame (EmulateInstruction *instruction,
void *dst,
size_t dst_len)
{
- if (!baton || dst == NULL || dst_len == 0)
+ if (baton == nullptr || dst == nullptr || dst_len == 0)
return 0;
StackFrame *frame = (StackFrame *) baton;
@@ -311,7 +304,7 @@ EmulateInstruction::WriteMemoryFrame (EmulateInstruction *instruction,
const void *src,
size_t src_len)
{
- if (!baton || src == NULL || src_len == 0)
+ if (baton == nullptr || src == nullptr || src_len == 0)
return 0;
StackFrame *frame = (StackFrame *) baton;
@@ -332,7 +325,7 @@ EmulateInstruction::ReadRegisterFrame (EmulateInstruction *instruction,
const RegisterInfo *reg_info,
RegisterValue &reg_value)
{
- if (!baton)
+ if (baton == nullptr)
return false;
StackFrame *frame = (StackFrame *) baton;
@@ -346,7 +339,7 @@ EmulateInstruction::WriteRegisterFrame (EmulateInstruction *instruction,
const RegisterInfo *reg_info,
const RegisterValue &reg_value)
{
- if (!baton)
+ if (baton == nullptr)
return false;
StackFrame *frame = (StackFrame *) baton;
@@ -504,45 +497,35 @@ EmulateInstruction::Context::Dump (Stream &strm,
switch (info_type)
{
case eInfoTypeRegisterPlusOffset:
- {
- strm.Printf (" (reg_plus_offset = %s%+" PRId64 ")",
- info.RegisterPlusOffset.reg.name,
- info.RegisterPlusOffset.signed_offset);
- }
+ strm.Printf(" (reg_plus_offset = %s%+" PRId64 ")",
+ info.RegisterPlusOffset.reg.name,
+ info.RegisterPlusOffset.signed_offset);
break;
case eInfoTypeRegisterPlusIndirectOffset:
- {
- strm.Printf (" (reg_plus_reg = %s + %s)",
- info.RegisterPlusIndirectOffset.base_reg.name,
- info.RegisterPlusIndirectOffset.offset_reg.name);
- }
+ strm.Printf(" (reg_plus_reg = %s + %s)",
+ info.RegisterPlusIndirectOffset.base_reg.name,
+ info.RegisterPlusIndirectOffset.offset_reg.name);
break;
case eInfoTypeRegisterToRegisterPlusOffset:
- {
- strm.Printf (" (base_and_imm_offset = %s%+" PRId64 ", data_reg = %s)",
- info.RegisterToRegisterPlusOffset.base_reg.name,
- info.RegisterToRegisterPlusOffset.offset,
- info.RegisterToRegisterPlusOffset.data_reg.name);
- }
+ strm.Printf(" (base_and_imm_offset = %s%+" PRId64 ", data_reg = %s)",
+ info.RegisterToRegisterPlusOffset.base_reg.name,
+ info.RegisterToRegisterPlusOffset.offset,
+ info.RegisterToRegisterPlusOffset.data_reg.name);
break;
case eInfoTypeRegisterToRegisterPlusIndirectOffset:
- {
- strm.Printf (" (base_and_reg_offset = %s + %s, data_reg = %s)",
- info.RegisterToRegisterPlusIndirectOffset.base_reg.name,
- info.RegisterToRegisterPlusIndirectOffset.offset_reg.name,
- info.RegisterToRegisterPlusIndirectOffset.data_reg.name);
- }
+ strm.Printf(" (base_and_reg_offset = %s + %s, data_reg = %s)",
+ info.RegisterToRegisterPlusIndirectOffset.base_reg.name,
+ info.RegisterToRegisterPlusIndirectOffset.offset_reg.name,
+ info.RegisterToRegisterPlusIndirectOffset.data_reg.name);
break;
case eInfoTypeRegisterRegisterOperands:
- {
- strm.Printf (" (register to register binary op: %s and %s)",
- info.RegisterRegisterOperands.operand1.name,
- info.RegisterRegisterOperands.operand2.name);
- }
+ strm.Printf(" (register to register binary op: %s and %s)",
+ info.RegisterRegisterOperands.operand1.name,
+ info.RegisterRegisterOperands.operand2.name);
break;
case eInfoTypeOffset:
@@ -599,7 +582,7 @@ EmulateInstruction::SetInstruction (const Opcode &opcode, const Address &inst_ad
m_addr = LLDB_INVALID_ADDRESS;
if (inst_addr.IsValid())
{
- if (target)
+ if (target != nullptr)
m_addr = inst_addr.GetLoadAddress (target);
if (m_addr == LLDB_INVALID_ADDRESS)
m_addr = inst_addr.GetFileAddress ();
@@ -661,12 +644,9 @@ EmulateInstruction::GetInternalRegisterNumber (RegisterContext *reg_ctx, const R
return LLDB_INVALID_REGNUM;
}
-
bool
EmulateInstruction::CreateFunctionEntryUnwind (UnwindPlan &unwind_plan)
{
unwind_plan.Clear();
return false;
}
-
-
diff --git a/source/Core/Error.cpp b/source/Core/Error.cpp
index ce055826af2c..97c2c4cc5b67 100644
--- a/source/Core/Error.cpp
+++ b/source/Core/Error.cpp
@@ -13,13 +13,15 @@
#endif
// C++ Includes
+#include <cerrno>
+#include <cstdarg>
+
// Other libraries and framework includes
+#include "llvm/ADT/SmallVector.h"
+
// Project includes
#include "lldb/Core/Error.h"
#include "lldb/Core/Log.h"
-#include "llvm/ADT/SmallVector.h"
-#include <cerrno>
-#include <cstdarg>
using namespace lldb;
using namespace lldb_private;
@@ -31,9 +33,6 @@ Error::Error ():
{
}
-//----------------------------------------------------------------------
-// Default constructor
-//----------------------------------------------------------------------
Error::Error(ValueType err, ErrorType type) :
m_code (err),
m_type (type),
@@ -41,12 +40,7 @@ Error::Error(ValueType err, ErrorType type) :
{
}
-Error::Error (const Error &rhs) :
- m_code (rhs.m_code),
- m_type (rhs.m_type),
- m_string (rhs.m_string)
-{
-}
+Error::Error(const Error &rhs) = default;
Error::Error (const char* format, ...):
m_code (0),
@@ -75,7 +69,6 @@ Error::operator = (const Error& rhs)
return *this;
}
-
//----------------------------------------------------------------------
// Assignment operator
//----------------------------------------------------------------------
@@ -88,9 +81,7 @@ Error::operator = (uint32_t err)
return *this;
}
-Error::~Error()
-{
-}
+Error::~Error() = default;
//----------------------------------------------------------------------
// Get the error value as a NULL C string. The error string will be
@@ -101,11 +92,11 @@ const char *
Error::AsCString(const char *default_error_str) const
{
if (Success())
- return NULL;
+ return nullptr;
if (m_string.empty())
{
- const char *s = NULL;
+ const char *s = nullptr;
switch (m_type)
{
case eErrorTypeMachKernel:
@@ -121,7 +112,7 @@ Error::AsCString(const char *default_error_str) const
default:
break;
}
- if (s)
+ if (s != nullptr)
m_string.assign(s);
}
if (m_string.empty())
@@ -129,12 +120,11 @@ Error::AsCString(const char *default_error_str) const
if (default_error_str)
m_string.assign(default_error_str);
else
- return NULL; // User wanted a NULL string back...
+ return nullptr; // User wanted a nullptr string back...
}
return m_string.c_str();
}
-
//----------------------------------------------------------------------
// Clear the error and any cached error string that it might contain.
//----------------------------------------------------------------------
@@ -186,27 +176,27 @@ Error::Fail () const
void
Error::PutToLog (Log *log, const char *format, ...)
{
- char *arg_msg = NULL;
+ char *arg_msg = nullptr;
va_list args;
va_start (args, format);
::vasprintf (&arg_msg, format, args);
va_end (args);
- if (arg_msg != NULL)
+ if (arg_msg != nullptr)
{
if (Fail())
{
const char *err_str = AsCString();
- if (err_str == NULL)
+ if (err_str == nullptr)
err_str = "???";
SetErrorStringWithFormat("error: %s err = %s (0x%8.8x)", arg_msg, err_str, m_code);
- if (log)
+ if (log != nullptr)
log->Error("%s", m_string.c_str());
}
else
{
- if (log)
+ if (log != nullptr)
log->Printf("%s err = 0x%8.8x", arg_msg, m_code);
}
::free (arg_msg);
@@ -227,20 +217,20 @@ Error::LogIfError (Log *log, const char *format, ...)
{
if (Fail())
{
- char *arg_msg = NULL;
+ char *arg_msg = nullptr;
va_list args;
va_start (args, format);
::vasprintf (&arg_msg, format, args);
va_end (args);
- if (arg_msg != NULL)
+ if (arg_msg != nullptr)
{
const char *err_str = AsCString();
- if (err_str == NULL)
+ if (err_str == nullptr)
err_str = "???";
SetErrorStringWithFormat("%s err = %s (0x%8.8x)", arg_msg, err_str, m_code);
- if (log)
+ if (log != nullptr)
log->Error("%s", m_string.c_str());
::free (arg_msg);
@@ -273,7 +263,7 @@ Error::SetExpressionErrorWithFormat (lldb::ExpressionResults result, const char
{
int length = 0;
- if (format && format[0])
+ if (format != nullptr && format[0])
{
va_list args;
va_start (args, format);
@@ -333,7 +323,7 @@ Error::SetErrorToGenericError ()
void
Error::SetErrorString (const char *err_str)
{
- if (err_str && err_str[0])
+ if (err_str != nullptr && err_str[0])
{
// If we have an error string, we should always at least have
// an error set to a generic value.
@@ -354,7 +344,7 @@ Error::SetErrorString (const char *err_str)
int
Error::SetErrorStringWithFormat (const char *format, ...)
{
- if (format && format[0])
+ if (format != nullptr && format[0])
{
va_list args;
va_start (args, format);
@@ -372,7 +362,7 @@ Error::SetErrorStringWithFormat (const char *format, ...)
int
Error::SetErrorStringWithVarArg (const char *format, va_list args)
{
- if (format && format[0])
+ if (format != nullptr && format[0])
{
// If we have an error string, we should always at least have
// an error set to a generic value.
@@ -407,7 +397,6 @@ Error::SetErrorStringWithVarArg (const char *format, va_list args)
return 0;
}
-
//----------------------------------------------------------------------
// Returns true if the error code in this object is considered a
// successful return value.
@@ -421,9 +410,5 @@ Error::Success() const
bool
Error::WasInterrupted() const
{
- if (m_type == eErrorTypePOSIX && m_code == EINTR)
- return true;
- else
- return false;
+ return (m_type == eErrorTypePOSIX && m_code == EINTR);
}
-
diff --git a/source/Core/Event.cpp b/source/Core/Event.cpp
index 293a322257ef..6b07e4d91987 100644
--- a/source/Core/Event.cpp
+++ b/source/Core/Event.cpp
@@ -9,6 +9,8 @@
// C Includes
// C++ Includes
+#include <algorithm>
+
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Event.h"
@@ -19,82 +21,89 @@
#include "lldb/Core/Stream.h"
#include "lldb/Host/Endian.h"
#include "lldb/Target/Process.h"
-#include <algorithm>
using namespace lldb;
using namespace lldb_private;
-//----------------------------------------------------------------------
-// Event constructor
-//----------------------------------------------------------------------
Event::Event (Broadcaster *broadcaster, uint32_t event_type, EventData *data) :
- m_broadcaster (broadcaster),
- m_type (event_type),
- m_data_ap (data)
+ m_broadcaster_wp(broadcaster->GetBroadcasterImpl()),
+ m_type(event_type),
+ m_data_sp(data)
{
}
-Event::Event(uint32_t event_type, EventData *data) :
- m_broadcaster (NULL), // Set by the broadcaster when this event gets broadcast
- m_type (event_type),
- m_data_ap (data)
+Event::Event (Broadcaster *broadcaster, uint32_t event_type, const EventDataSP &event_data_sp) :
+ m_broadcaster_wp(broadcaster->GetBroadcasterImpl()),
+ m_type(event_type),
+ m_data_sp(event_data_sp)
{
}
+Event::Event(uint32_t event_type, EventData *data) :
+ m_broadcaster_wp(),
+ m_type(event_type),
+ m_data_sp(data)
+{
+}
-//----------------------------------------------------------------------
-// Event destructor
-//----------------------------------------------------------------------
-Event::~Event ()
+Event::Event(uint32_t event_type, const EventDataSP &event_data_sp) :
+ m_broadcaster_wp(),
+ m_type(event_type),
+ m_data_sp(event_data_sp)
{
}
+Event::~Event() = default;
+
void
Event::Dump (Stream *s) const
{
- if (m_broadcaster)
+ Broadcaster *broadcaster;
+ Broadcaster::BroadcasterImplSP broadcaster_impl_sp(m_broadcaster_wp.lock());
+ if (broadcaster_impl_sp)
+ broadcaster = broadcaster_impl_sp->GetBroadcaster();
+ else
+ broadcaster = nullptr;
+
+ if (broadcaster)
{
StreamString event_name;
- if (m_broadcaster->GetEventNames (event_name, m_type, false))
+ if (broadcaster->GetEventNames (event_name, m_type, false))
s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x (%s), data = ",
static_cast<const void*>(this),
- static_cast<void*>(m_broadcaster),
- m_broadcaster->GetBroadcasterName().GetCString(),
+ static_cast<void*>(broadcaster),
+ broadcaster->GetBroadcasterName().GetCString(),
m_type, event_name.GetString().c_str());
else
s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x, data = ",
static_cast<const void*>(this),
- static_cast<void*>(m_broadcaster),
- m_broadcaster->GetBroadcasterName().GetCString(), m_type);
+ static_cast<void*>(broadcaster),
+ broadcaster->GetBroadcasterName().GetCString(), m_type);
}
else
s->Printf("%p Event: broadcaster = NULL, type = 0x%8.8x, data = ",
static_cast<const void*>(this), m_type);
- if (m_data_ap.get() == NULL)
- s->Printf ("<NULL>");
- else
+ if (m_data_sp)
{
s->PutChar('{');
- m_data_ap->Dump (s);
+ m_data_sp->Dump (s);
s->PutChar('}');
}
+ else
+ s->Printf ("<NULL>");
}
void
Event::DoOnRemoval ()
{
- if (m_data_ap.get())
- m_data_ap->DoOnRemoval (this);
+ if (m_data_sp)
+ m_data_sp->DoOnRemoval (this);
}
-EventData::EventData()
-{
-}
+EventData::EventData() = default;
-EventData::~EventData()
-{
-}
+EventData::~EventData() = default;
void
EventData::Dump (Stream *s) const
@@ -119,9 +128,7 @@ EventDataBytes::EventDataBytes (const void *src, size_t src_len) :
SetBytes (src, src_len);
}
-EventDataBytes::~EventDataBytes()
-{
-}
+EventDataBytes::~EventDataBytes() = default;
const ConstString &
EventDataBytes::GetFlavorString ()
@@ -144,10 +151,10 @@ EventDataBytes::Dump (Stream *s) const
{
s->Printf("\"%s\"", m_bytes.c_str());
}
- else if (m_bytes.size() > 0)
+ else if (!m_bytes.empty())
{
DataExtractor data;
- data.SetData(&m_bytes[0], m_bytes.size(), endian::InlHostByteOrder());
+ data.SetData(m_bytes.data(), m_bytes.size(), endian::InlHostByteOrder());
data.Dump(s, 0, eFormatBytes, 1, m_bytes.size(), 32, LLDB_INVALID_ADDRESS, 0, 0);
}
}
@@ -155,9 +162,7 @@ EventDataBytes::Dump (Stream *s) const
const void *
EventDataBytes::GetBytes() const
{
- if (m_bytes.empty())
- return NULL;
- return &m_bytes[0];
+ return (m_bytes.empty() ? nullptr : m_bytes.data());
}
size_t
@@ -169,7 +174,7 @@ EventDataBytes::GetByteSize() const
void
EventDataBytes::SetBytes (const void *src, size_t src_len)
{
- if (src && src_len > 0)
+ if (src != nullptr && src_len > 0)
m_bytes.assign ((const char *)src, src_len);
else
m_bytes.clear();
@@ -178,27 +183,26 @@ EventDataBytes::SetBytes (const void *src, size_t src_len)
void
EventDataBytes::SetBytesFromCString (const char *cstr)
{
- if (cstr && cstr[0])
+ if (cstr != nullptr && cstr[0])
m_bytes.assign (cstr);
else
m_bytes.clear();
}
-
const void *
EventDataBytes::GetBytesFromEvent (const Event *event_ptr)
{
const EventDataBytes *e = GetEventDataFromEvent (event_ptr);
- if (e)
+ if (e != nullptr)
return e->GetBytes();
- return NULL;
+ return nullptr;
}
size_t
EventDataBytes::GetByteSizeFromEvent (const Event *event_ptr)
{
const EventDataBytes *e = GetEventDataFromEvent (event_ptr);
- if (e)
+ if (e != nullptr)
return e->GetByteSize();
return 0;
}
@@ -206,13 +210,13 @@ EventDataBytes::GetByteSizeFromEvent (const Event *event_ptr)
const EventDataBytes *
EventDataBytes::GetEventDataFromEvent (const Event *event_ptr)
{
- if (event_ptr)
+ if (event_ptr != nullptr)
{
const EventData *event_data = event_ptr->GetData();
if (event_data && event_data->GetFlavor() == EventDataBytes::GetFlavorString())
return static_cast <const EventDataBytes *> (event_data);
}
- return NULL;
+ return nullptr;
}
void
@@ -220,5 +224,3 @@ EventDataBytes::SwapBytes (std::string &new_bytes)
{
m_bytes.swap (new_bytes);
}
-
-
diff --git a/source/Core/FastDemangle.cpp b/source/Core/FastDemangle.cpp
index a27a2f1dbff1..528f7f6bd88d 100644
--- a/source/Core/FastDemangle.cpp
+++ b/source/Core/FastDemangle.cpp
@@ -11,6 +11,8 @@
#include <string.h>
#include <stdlib.h>
+#include "lldb/lldb-private.h"
+
//#define DEBUG_FAILURES 1
//#define DEBUG_SUBSTITUTIONS 1
//#define DEBUG_TEMPLATE_ARGS 1
@@ -1627,7 +1629,7 @@ private:
return Parse('E');
}
--m_read_ptr;
- // fallthrough
+ LLVM_FALLTHROUGH;
case 'w':
case 'c':
case 'a':
@@ -1827,7 +1829,7 @@ private:
if (*m_read_ptr++ == 'r')
return ParseUnresolvedName();
--m_read_ptr;
- // fallthrough
+ LLVM_FALLTHROUGH;
default:
return ParseExpressionPrimary();
}
@@ -2099,7 +2101,7 @@ private:
}
case 'L':
++m_read_ptr;
- // fallthrough
+ LLVM_FALLTHROUGH;
default:
{
if (!ParseUnscopedName(name_state))
@@ -2293,7 +2295,7 @@ private:
m_read_ptr += strlen(m_read_ptr);
break;
}
- // fallthrough
+ LLVM_FALLTHROUGH;
default:
if (first_param)
first_param = false;
@@ -2363,6 +2365,7 @@ private:
Write('(');
Write(m_read_ptr, m_read_end - m_read_ptr);
Write(')');
+ LLVM_FALLTHROUGH;
case '\0':
return true;
default:
diff --git a/source/Core/FileSpecList.cpp b/source/Core/FileSpecList.cpp
index 4b1c991c6be4..cef1bfba41b0 100644
--- a/source/Core/FileSpecList.cpp
+++ b/source/Core/FileSpecList.cpp
@@ -6,35 +6,28 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+
#include "lldb/Core/FileSpecList.h"
-#include "lldb/Core/Stream.h"
+
+// C Includes
+// C++ Includes
#include <algorithm>
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Stream.h"
+
using namespace lldb_private;
using namespace std;
-//------------------------------------------------------------------
-// Default constructor
-//------------------------------------------------------------------
FileSpecList::FileSpecList() :
m_files()
{
}
-//------------------------------------------------------------------
-// Copy constructor
-//------------------------------------------------------------------
-FileSpecList::FileSpecList(const FileSpecList& rhs) :
- m_files(rhs.m_files)
-{
-}
+FileSpecList::FileSpecList(const FileSpecList& rhs) = default;
-//------------------------------------------------------------------
-// Destructor
-//------------------------------------------------------------------
-FileSpecList::~FileSpecList()
-{
-}
+FileSpecList::~FileSpecList() = default;
//------------------------------------------------------------------
// Assignment operator
@@ -104,7 +97,7 @@ FileSpecList::Dump(Stream *s, const char *separator_cstr) const
// "file_spec" starting "start_idx" entries into the file spec list.
//
// Returns the valid index of the file that matches "file_spec" if
-// it is found, else UINT32_MAX is returned.
+// it is found, else std::numeric_limits<uint32_t>::max() is returned.
//------------------------------------------------------------------
size_t
FileSpecList::FindFileIndex (size_t start_idx, const FileSpec &file_spec, bool full, bool remove_dots) const
@@ -119,7 +112,8 @@ FileSpecList::FindFileIndex (size_t start_idx, const FileSpec &file_spec, bool f
{
if (compare_filename_only)
{
- if (m_files[idx].GetFilename() == file_spec.GetFilename())
+ if (ConstString::Equals(m_files[idx].GetFilename(), file_spec.GetFilename(),
+ file_spec.IsCaseSensitive() || m_files[idx].IsCaseSensitive()))
return idx;
}
else
@@ -140,7 +134,6 @@ FileSpecList::FindFileIndex (size_t start_idx, const FileSpec &file_spec, bool f
const FileSpec &
FileSpecList::GetFileSpecAtIndex(size_t idx) const
{
-
if (idx < m_files.size())
return m_files[idx];
static FileSpec g_empty_file_spec;
@@ -152,7 +145,7 @@ FileSpecList::GetFileSpecPointerAtIndex(size_t idx) const
{
if (idx < m_files.size())
return &m_files[idx];
- return NULL;
+ return nullptr;
}
//------------------------------------------------------------------
@@ -207,26 +200,23 @@ FileSpecList::GetFilesMatchingPartialPath (const char *path, bool dir_okay, File
else if (type == FileSpec::eFileTypeDirectory)
{
// Fill the match list with all the files in the directory:
-
}
else
{
return 0;
}
-
}
else
{
ConstString dir_name = path_spec.GetDirectory();
- Constring file_name = GetFilename();
- if (dir_name == NULL)
+ ConstString file_name = GetFilename();
+ if (dir_name == nullptr)
{
// Match files in the CWD.
}
else
{
// Match files in the given directory:
-
}
}
#endif
diff --git a/source/Core/FormatEntity.cpp b/source/Core/FormatEntity.cpp
index 804682f64bd3..e2097cc72b85 100644
--- a/source/Core/FormatEntity.cpp
+++ b/source/Core/FormatEntity.cpp
@@ -9,9 +9,13 @@
#include "lldb/Core/FormatEntity.h"
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
+// Project includes
#include "lldb/Core/Address.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
@@ -45,7 +49,6 @@
using namespace lldb;
using namespace lldb_private;
-
enum FileKind
{
FileError = 0,
@@ -54,11 +57,11 @@ enum FileKind
Fullpath
};
-#define ENTRY(n,t,f) { n, NULL, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0,0,NULL, false}
-#define ENTRY_VALUE(n,t,f,v) { n, NULL, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, v,0,NULL, false}
-#define ENTRY_CHILDREN(n,t,f,c) { n, NULL, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0,llvm::array_lengthof(c),c, false}
-#define ENTRY_CHILDREN_KEEP_SEP(n,t,f,c) { n, NULL, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0,llvm::array_lengthof(c),c, true}
-#define ENTRY_STRING(n,s) { n, s, FormatEntity::Entry::Type::InsertString, FormatEntity::Entry::FormatType::None, 0,0, NULL, false}
+#define ENTRY(n,t,f) { n, nullptr, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0, 0, nullptr, false}
+#define ENTRY_VALUE(n,t,f,v) { n, nullptr, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, v, 0, nullptr, false}
+#define ENTRY_CHILDREN(n,t,f,c) { n, nullptr, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0, llvm::array_lengthof(c), c, false}
+#define ENTRY_CHILDREN_KEEP_SEP(n,t,f,c) { n, nullptr, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0, llvm::array_lengthof(c), c, true}
+#define ENTRY_STRING(n,s) { n, s, FormatEntity::Entry::Type::InsertString, FormatEntity::Entry::FormatType::None, 0, 0, nullptr, false}
static FormatEntity::Entry::Definition g_string_entry[] =
{
ENTRY("*", ParentString, None)
@@ -80,7 +83,6 @@ static FormatEntity::Entry::Definition g_file_child_entries[] =
static FormatEntity::Entry::Definition g_frame_child_entries[] =
{
-
ENTRY ("index", FrameIndex , UInt32),
ENTRY ("pc" , FrameRegisterPC , UInt64),
ENTRY ("fp" , FrameRegisterFP , UInt64),
@@ -193,7 +195,6 @@ static FormatEntity::Entry::Definition g_ansi_entries[] =
ENTRY_STRING ( "negative" , ANSI_ESC_START _TO_STR(ANSI_CTRL_IMAGE_NEGATIVE) ANSI_ESC_END),
ENTRY_STRING ( "conceal" , ANSI_ESC_START _TO_STR(ANSI_CTRL_CONCEAL) ANSI_ESC_END),
ENTRY_STRING ( "crossed-out" , ANSI_ESC_START _TO_STR(ANSI_CTRL_CROSSED_OUT) ANSI_ESC_END),
-
};
static FormatEntity::Entry::Definition g_script_child_entries[] =
@@ -229,12 +230,11 @@ static FormatEntity::Entry::Definition g_top_level_entries[] =
static FormatEntity::Entry::Definition g_root = ENTRY_CHILDREN ("<root>", Root, None, g_top_level_entries);
-
FormatEntity::Entry::Entry (llvm::StringRef s) :
string (s.data(), s.size()),
printf_format (),
children (),
- definition (NULL),
+ definition(nullptr),
type (Type::String),
fmt (lldb::eFormatDefault),
number (0),
@@ -246,7 +246,7 @@ FormatEntity::Entry::Entry (char ch) :
string (1, ch),
printf_format (),
children (),
- definition (NULL),
+ definition(nullptr),
type (Type::String),
fmt (lldb::eFormatDefault),
number (0),
@@ -278,7 +278,6 @@ FormatEntity::Entry::AppendText (const char *cstr)
return AppendText (llvm::StringRef(cstr));
}
-
Error
FormatEntity::Parse (const llvm::StringRef &format_str, Entry &entry)
{
@@ -379,7 +378,6 @@ FormatEntity::Entry::Dump (Stream &s, int depth) const
}
}
-
template <typename T>
static bool RunScriptFormatKeyword(Stream &s,
const SymbolContext *sc,
@@ -436,7 +434,7 @@ DumpAddress (Stream &s,
addr_width = 16;
if (print_file_addr_or_load_addr)
{
- ExecutionContextScope *exe_scope = NULL;
+ ExecutionContextScope *exe_scope = nullptr;
if (exe_ctx)
exe_scope = exe_ctx->GetBestExecutionContextScope();
addr.Dump (&s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, 0);
@@ -569,7 +567,7 @@ ScanBracketedRange (llvm::StringRef subpath,
if (separator_index == llvm::StringRef::npos)
{
const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
- index_lower = ::strtoul (index_lower_cstr, NULL, 0);
+ index_lower = ::strtoul(index_lower_cstr, nullptr, 0);
index_higher = index_lower;
if (log)
log->Printf("[ScanBracketedRange] [%" PRId64 "] detected, high index is same", index_lower);
@@ -578,8 +576,8 @@ ScanBracketedRange (llvm::StringRef subpath,
{
const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
const char *index_higher_cstr = subpath.data() + separator_index + 1;
- index_lower = ::strtoul (index_lower_cstr, NULL, 0);
- index_higher = ::strtoul (index_higher_cstr, NULL, 0);
+ index_lower = ::strtoul(index_lower_cstr, nullptr, 0);
+ index_higher = ::strtoul(index_higher_cstr, nullptr, 0);
if (log)
log->Printf("[ScanBracketedRange] [%" PRId64 "-%" PRId64 "] detected", index_lower, index_higher);
}
@@ -664,7 +662,6 @@ DumpRegister (Stream &s,
return false;
}
-
static ValueObjectSP
ExpandIndexedExpression (ValueObject* valobj,
size_t index,
@@ -729,7 +726,7 @@ DumpValue (Stream &s,
const FormatEntity::Entry &entry,
ValueObject *valobj)
{
- if (valobj == NULL)
+ if (valobj == nullptr)
return false;
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
@@ -751,7 +748,7 @@ DumpValue (Stream &s,
case FormatEntity::Entry::Type::ScriptVariableSynthetic:
is_script = true;
- // Fall through
+ LLVM_FALLTHROUGH;
case FormatEntity::Entry::Type::VariableSynthetic:
custom_format = entry.fmt;
val_obj_display = (ValueObject::ValueObjectRepresentationStyle)entry.number;
@@ -767,15 +764,15 @@ DumpValue (Stream &s,
return false;
}
- if (valobj == NULL)
+ if (valobj == nullptr)
return false;
ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
ValueObject::GetValueForExpressionPathOptions options;
options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().SetSyntheticChildrenTraversal(ValueObject::GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both);
- ValueObject* target = NULL;
- const char* var_name_final_if_array_range = NULL;
+ ValueObject* target = nullptr;
+ const char* var_name_final_if_array_range = nullptr;
size_t close_bracket_index = llvm::StringRef::npos;
int64_t index_lower = -1;
int64_t index_higher = -1;
@@ -844,7 +841,6 @@ DumpValue (Stream &s,
}
}
-
is_array_range = (final_value_type == ValueObject::eExpressionPathEndResultTypeBoundedRange ||
final_value_type == ValueObject::eExpressionPathEndResultTypeUnboundedRange);
@@ -887,7 +883,7 @@ DumpValue (Stream &s,
}
// TODO use flags for these
- const uint32_t type_info_flags = target->GetCompilerType().GetTypeInfo(NULL);
+ const uint32_t type_info_flags = target->GetCompilerType().GetTypeInfo(nullptr);
bool is_array = (type_info_flags & eTypeIsArray) != 0;
bool is_pointer = (type_info_flags & eTypeIsPointer) != 0;
bool is_aggregate = target->GetCompilerType().IsAggregateType();
@@ -1021,7 +1017,7 @@ DumpValue (Stream &s,
}
else
{
- success &= FormatEntity::FormatStringRef(special_directions, s, sc, exe_ctx, NULL, item, false, false);
+ success &= FormatEntity::FormatStringRef(special_directions, s, sc, exe_ctx, nullptr, item, false, false);
}
if (--max_num_children == 0)
@@ -1036,7 +1032,6 @@ DumpValue (Stream &s,
s.PutChar(']');
return success;
}
-
}
static bool
@@ -1044,7 +1039,6 @@ DumpRegister (Stream &s,
StackFrame *frame,
const char *reg_name,
Format format)
-
{
if (frame)
{
@@ -1078,7 +1072,7 @@ FormatThreadExtendedInfoRecurse(const FormatEntity::Entry &entry,
StructuredData::ObjectSP value = thread_info_dictionary->GetObjectForDotSeparatedPath (path);
- if (value.get())
+ if (value)
{
if (value->GetType() == StructuredData::Type::eTypeInteger)
{
@@ -1116,7 +1110,6 @@ FormatThreadExtendedInfoRecurse(const FormatEntity::Entry &entry,
return false;
}
-
static inline bool
IsToken(const char *var_name_begin, const char *var)
{
@@ -1150,8 +1143,8 @@ FormatEntity::FormatStringRef (const llvm::StringRef &format_str,
}
}
return false;
-
}
+
bool
FormatEntity::FormatCString (const char *format,
Stream &s,
@@ -1203,14 +1196,14 @@ FormatEntity::Format (const Entry &entry,
case Entry::Type::Root:
for (const auto &child : entry.children)
{
- if (Format (child,
+ if (!Format(child,
s,
sc,
exe_ctx,
addr,
valobj,
function_changed,
- initial_function) == false)
+ initial_function))
{
return false; // If any item of root fails, then the formatting fails
}
@@ -1242,16 +1235,13 @@ FormatEntity::Format (const Entry &entry,
case Entry::Type::VariableSynthetic:
case Entry::Type::ScriptVariable:
case Entry::Type::ScriptVariableSynthetic:
- if (DumpValue(s, sc, exe_ctx, entry, valobj))
- return true;
- return false;
+ return DumpValue(s, sc, exe_ctx, entry, valobj);
case Entry::Type::AddressFile:
case Entry::Type::AddressLoad:
case Entry::Type::AddressLoadOrFile:
- if (addr && addr->IsValid() && DumpAddress(s, sc, exe_ctx, *addr, entry.type == Entry::Type::AddressLoadOrFile))
- return true;
- return false;
+ return (addr != nullptr && addr->IsValid() &&
+ DumpAddress(s, sc, exe_ctx, *addr, entry.type == Entry::Type::AddressLoadOrFile));
case Entry::Type::ProcessID:
if (exe_ctx)
@@ -1293,7 +1283,6 @@ FormatEntity::Format (const Entry &entry,
}
return false;
-
case Entry::Type::ThreadID:
if (exe_ctx)
{
@@ -1607,7 +1596,6 @@ FormatEntity::Format (const Entry &entry,
}
return false;
-
case Entry::Type::FrameRegisterByName:
if (exe_ctx)
{
@@ -1674,11 +1662,11 @@ FormatEntity::Format (const Entry &entry,
}
else
{
- const char *name = NULL;
+ const char *name = nullptr;
if (sc->function)
- name = sc->function->GetName().AsCString (NULL);
+ name = sc->function->GetName().AsCString(nullptr);
else if (sc->symbol)
- name = sc->symbol->GetName().AsCString (NULL);
+ name = sc->symbol->GetName().AsCString(nullptr);
if (name)
{
s.PutCString(name);
@@ -1765,11 +1753,11 @@ FormatEntity::Format (const Entry &entry,
// Print the function name with arguments in it
if (sc->function)
{
- ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
- const char *cstr = sc->function->GetName().AsCString (NULL);
+ ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
+ const char *cstr = sc->function->GetName().AsCString(nullptr);
if (cstr)
{
- const InlineFunctionInfo *inline_info = NULL;
+ const InlineFunctionInfo *inline_info = nullptr;
VariableListSP variable_list_sp;
bool get_function_vars = true;
if (sc->block)
@@ -1861,7 +1849,7 @@ FormatEntity::Format (const Entry &entry,
var_value_sp = var_value_sp->GetQualifiedRepresentationIfAvailable(exe_scope->CalculateTarget()->TargetProperties::GetPreferDynamicValue(),
exe_scope->CalculateTarget()->TargetProperties::GetEnableSyntheticValue());
if (var_value_sp->GetCompilerType().IsAggregateType() &&
- DataVisualization::ShouldPrintAsOneLiner(*var_value_sp.get()))
+ DataVisualization::ShouldPrintAsOneLiner(*var_value_sp))
{
static StringSummaryFormat format(TypeSummaryImpl::Flags()
.SetHideItemNames(false)
@@ -1908,7 +1896,7 @@ FormatEntity::Format (const Entry &entry,
}
else if (sc->symbol)
{
- const char *cstr = sc->symbol->GetName().AsCString (NULL);
+ const char *cstr = sc->symbol->GetName().AsCString(nullptr);
if (cstr)
{
s.PutCString(cstr);
@@ -1936,9 +1924,7 @@ FormatEntity::Format (const Entry &entry,
return false;
case Entry::Type::FunctionLineOffset:
- if (DumpAddressOffsetFromFunction (s, sc, exe_ctx, sc->line_entry.range.GetBaseAddress(), false, false, false))
- return true;
- return false;
+ return (DumpAddressOffsetFromFunction (s, sc, exe_ctx, sc->line_entry.range.GetBaseAddress(), false, false, false));
case Entry::Type::FunctionPCOffset:
if (exe_ctx)
@@ -1953,7 +1939,7 @@ FormatEntity::Format (const Entry &entry,
return false;
case Entry::Type::FunctionChanged:
- return function_changed == true;
+ return function_changed;
case Entry::Type::FunctionIsOptimized:
{
@@ -1966,7 +1952,7 @@ FormatEntity::Format (const Entry &entry,
}
case Entry::Type::FunctionInitial:
- return initial_function == true;
+ return initial_function;
case Entry::Type::LineEntryFile:
if (sc && sc->line_entry.IsValid())
@@ -2008,7 +1994,7 @@ FormatEntity::Format (const Entry &entry,
if (addr && exe_ctx && exe_ctx->GetFramePtr())
{
RegisterContextSP reg_ctx = exe_ctx->GetFramePtr()->GetRegisterContextSP();
- if (reg_ctx.get())
+ if (reg_ctx)
{
addr_t pc_loadaddr = reg_ctx->GetPC();
if (pc_loadaddr != LLDB_INVALID_ADDRESS)
@@ -2036,7 +2022,7 @@ DumpCommaSeparatedChildEntryNames (Stream &s, const FormatEntity::Entry::Definit
if (parent->children)
{
const size_t n = parent->num_children;
- for (size_t i=0; i<n; ++i)
+ for (size_t i = 0; i < n; ++i)
{
if (i > 0)
s.PutCString(", ");
@@ -2047,7 +2033,6 @@ DumpCommaSeparatedChildEntryNames (Stream &s, const FormatEntity::Entry::Definit
return false;
}
-
static Error
ParseEntry (const llvm::StringRef &format_str,
const FormatEntity::Entry::Definition *parent,
@@ -2060,7 +2045,7 @@ ParseEntry (const llvm::StringRef &format_str,
llvm::StringRef key = format_str.substr(0, sep_pos);
const size_t n = parent->num_children;
- for (size_t i=0; i<n; ++i)
+ for (size_t i = 0; i < n; ++i)
{
const FormatEntity::Entry::Definition *entry_def = parent->children + i;
if (key.equals(entry_def->name) || entry_def->name[0] == '*')
@@ -2143,7 +2128,6 @@ ParseEntry (const llvm::StringRef &format_str,
return error;
}
-
static const FormatEntity::Entry::Definition *
FindEntry (const llvm::StringRef &format_str, const FormatEntity::Entry::Definition *parent, llvm::StringRef &remainder)
{
@@ -2151,7 +2135,7 @@ FindEntry (const llvm::StringRef &format_str, const FormatEntity::Entry::Definit
std::pair<llvm::StringRef, llvm::StringRef> p = format_str.split('.');
const size_t n = parent->num_children;
- for (size_t i=0; i<n; ++i)
+ for (size_t i = 0; i < n; ++i)
{
const FormatEntity::Entry::Definition *entry_def = parent->children + i;
if (p.first.equals(entry_def->name) || entry_def->name[0] == '*')
@@ -2257,14 +2241,14 @@ FormatEntity::ParseInternal (llvm::StringRef &format, Entry &parent_entry, uint3
char oct_str[5] = { 0, 0, 0, 0, 0 };
int i;
- for (i=0; (format[i] >= '0' && format[i] <= '7') && i<4; ++i)
+ for (i = 0; (format[i] >= '0' && format[i] <= '7') && i < 4; ++i)
oct_str[i] = format[i];
// We don't want to consume the last octal character since
// the main for loop will do this for us, so we advance p by
// one less than i (even if i is zero)
format = format.drop_front(i);
- unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
+ unsigned long octal_value = ::strtoul(oct_str, nullptr, 8);
if (octal_value <= UINT8_MAX)
{
parent_entry.AppendChar((char)octal_value);
@@ -2294,7 +2278,7 @@ FormatEntity::ParseInternal (llvm::StringRef &format, Entry &parent_entry, uint3
format = format.drop_front();
}
- unsigned long hex_value = strtoul (hex_str, NULL, 16);
+ unsigned long hex_value = strtoul(hex_str, nullptr, 16);
if (hex_value <= UINT8_MAX)
{
parent_entry.AppendChar((char)hex_value);
@@ -2483,7 +2467,6 @@ FormatEntity::ParseInternal (llvm::StringRef &format, Entry &parent_entry, uint3
return error;
}
-
Error
FormatEntity::ExtractVariableInfo (llvm::StringRef &format_str, llvm::StringRef &variable_name, llvm::StringRef &variable_format)
{
@@ -2556,7 +2539,7 @@ AddMatches (const FormatEntity::Entry::Definition *def,
const size_t n = def->num_children;
if (n > 0)
{
- for (size_t i=0; i<n; ++i)
+ for (size_t i = 0; i < n; ++i)
{
std::string match = prefix.str();
if (match_prefix.empty())
@@ -2566,6 +2549,7 @@ AddMatches (const FormatEntity::Entry::Definition *def,
}
}
}
+
size_t
FormatEntity::AutoComplete (const char *s,
int match_start_point,
diff --git a/source/Core/IOHandler.cpp b/source/Core/IOHandler.cpp
index 47d00e9184cf..bab0263a0c6e 100644
--- a/source/Core/IOHandler.cpp
+++ b/source/Core/IOHandler.cpp
@@ -38,8 +38,18 @@
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/ThreadPlan.h"
+#ifndef LLDB_DISABLE_CURSES
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/StackFrame.h"
+#endif
-
+#ifdef _MSC_VER
+#include <Windows.h>
+#endif
using namespace lldb;
using namespace lldb_private;
@@ -67,7 +77,7 @@ IOHandler::IOHandler (Debugger &debugger,
m_popped (false),
m_flags (flags),
m_type (type),
- m_user_data (NULL),
+ m_user_data(nullptr),
m_done (false),
m_active (false)
{
@@ -83,49 +93,37 @@ IOHandler::~IOHandler() = default;
int
IOHandler::GetInputFD()
{
- if (m_input_sp)
- return m_input_sp->GetFile().GetDescriptor();
- return -1;
+ return (m_input_sp ? m_input_sp->GetFile().GetDescriptor() : -1);
}
int
IOHandler::GetOutputFD()
{
- if (m_output_sp)
- return m_output_sp->GetFile().GetDescriptor();
- return -1;
+ return (m_output_sp ? m_output_sp->GetFile().GetDescriptor() : -1);
}
int
IOHandler::GetErrorFD()
{
- if (m_error_sp)
- return m_error_sp->GetFile().GetDescriptor();
- return -1;
+ return (m_error_sp ? m_error_sp->GetFile().GetDescriptor() : -1);
}
FILE *
IOHandler::GetInputFILE()
{
- if (m_input_sp)
- return m_input_sp->GetFile().GetStream();
- return NULL;
+ return (m_input_sp ? m_input_sp->GetFile().GetStream() : nullptr);
}
FILE *
IOHandler::GetOutputFILE()
{
- if (m_output_sp)
- return m_output_sp->GetFile().GetStream();
- return NULL;
+ return (m_output_sp ? m_output_sp->GetFile().GetStream() : nullptr);
}
FILE *
IOHandler::GetErrorFILE()
{
- if (m_error_sp)
- return m_error_sp->GetFile().GetStream();
- return NULL;
+ return (m_error_sp ? m_error_sp->GetFile().GetStream() : nullptr);
}
StreamFileSP &
@@ -171,13 +169,13 @@ IOHandler::WaitForPop ()
}
void
-IOHandlerStack::PrintAsync (Stream *stream, const char *s, size_t len)
+IOHandlerStack::PrintAsync(Stream *stream, const char *s, size_t len)
{
if (stream)
{
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (m_top)
- m_top->PrintAsync (stream, s, len);
+ m_top->PrintAsync(stream, s, len);
}
}
@@ -186,9 +184,9 @@ IOHandlerConfirm::IOHandlerConfirm (Debugger &debugger,
bool default_response) :
IOHandlerEditline(debugger,
IOHandler::Type::Confirm,
- NULL, // NULL editline_name means no history loaded/saved
- NULL, // No prompt
- NULL, // No continuation prompt
+ nullptr, // nullptr editline_name means no history loaded/saved
+ nullptr, // No prompt
+ nullptr, // No continuation prompt
false, // Multi-line
false, // Don't colorize the prompt (i.e. the confirm message.)
0,
@@ -204,7 +202,6 @@ IOHandlerConfirm::IOHandlerConfirm (Debugger &debugger,
prompt_stream.Printf(": [y/N] ");
SetPrompt (prompt_stream.GetString().c_str());
-
}
IOHandlerConfirm::~IOHandlerConfirm() = default;
@@ -304,14 +301,14 @@ IOHandlerDelegate::IOHandlerComplete (IOHandler &io_handler,
--word_start;
while (word_start > current_line && !isspace(*word_start))
--word_start;
- CommandCompletions::InvokeCommonCompletionCallbacks (io_handler.GetDebugger().GetCommandInterpreter(),
- CommandCompletions::eVariablePathCompletion,
- word_start,
- skip_first_n_matches,
- max_matches,
- NULL,
- word_complete,
- matches);
+ CommandCompletions::InvokeCommonCompletionCallbacks(io_handler.GetDebugger().GetCommandInterpreter(),
+ CommandCompletions::eVariablePathCompletion,
+ word_start,
+ skip_first_n_matches,
+ max_matches,
+ nullptr,
+ word_complete,
+ matches);
size_t num_matches = matches.GetSize();
if (num_matches > 0)
@@ -382,7 +379,7 @@ IOHandlerEditline::IOHandlerEditline (Debugger &debugger,
m_delegate (delegate),
m_prompt (),
m_continuation_prompt(),
- m_current_lines_ptr (NULL),
+ m_current_lines_ptr(nullptr),
m_base_line_number (line_number_start),
m_curr_line_idx (UINT32_MAX),
m_multi_line (multi_line),
@@ -460,12 +457,12 @@ IOHandlerEditline::GetLine (std::string &line, bool &interrupted)
{
if (GetIsInteractive())
{
- const char *prompt = NULL;
+ const char *prompt = nullptr;
if (m_multi_line && m_curr_line_idx > 0)
prompt = GetContinuationPrompt();
- if (prompt == NULL)
+ if (prompt == nullptr)
prompt = GetPrompt();
if (prompt && prompt[0])
@@ -484,7 +481,7 @@ IOHandlerEditline::GetLine (std::string &line, bool &interrupted)
m_editing = true;
while (!done)
{
- if (fgets(buffer, sizeof(buffer), in) == NULL)
+ if (fgets(buffer, sizeof(buffer), in) == nullptr)
{
const int saved_errno = errno;
if (feof(in))
@@ -532,7 +529,6 @@ IOHandlerEditline::GetLine (std::string &line, bool &interrupted)
#endif
}
-
#ifndef LLDB_DISABLE_LIBEDIT
bool
IOHandlerEditline::IsInputCompleteCallback (Editline *editline,
@@ -587,7 +583,7 @@ IOHandlerEditline::GetPrompt ()
{
#endif
if (m_prompt.empty())
- return NULL;
+ return nullptr;
#ifndef LLDB_DISABLE_LIBEDIT
}
#endif
@@ -603,7 +599,7 @@ IOHandlerEditline::SetPrompt (const char *p)
m_prompt.clear();
#ifndef LLDB_DISABLE_LIBEDIT
if (m_editline_ap)
- m_editline_ap->SetPrompt (m_prompt.empty() ? NULL : m_prompt.c_str());
+ m_editline_ap->SetPrompt(m_prompt.empty() ? nullptr : m_prompt.c_str());
#endif
return true;
}
@@ -611,9 +607,7 @@ IOHandlerEditline::SetPrompt (const char *p)
const char *
IOHandlerEditline::GetContinuationPrompt ()
{
- if (m_continuation_prompt.empty())
- return NULL;
- return m_continuation_prompt.c_str();
+ return (m_continuation_prompt.empty() ? nullptr : m_continuation_prompt.c_str());
}
void
@@ -626,7 +620,7 @@ IOHandlerEditline::SetContinuationPrompt (const char *p)
#ifndef LLDB_DISABLE_LIBEDIT
if (m_editline_ap)
- m_editline_ap->SetContinuationPrompt (m_continuation_prompt.empty() ? NULL : m_continuation_prompt.c_str());
+ m_editline_ap->SetContinuationPrompt(m_continuation_prompt.empty() ? nullptr : m_continuation_prompt.c_str());
#endif
}
@@ -671,7 +665,7 @@ IOHandlerEditline::GetLines (StringList &lines, bool &interrupted)
{
FILE *out = GetOutputFILE();
if (out)
- ::fprintf(out, "%u%s", m_base_line_number + (uint32_t)lines.GetSize(), GetPrompt() == NULL ? " " : "");
+ ::fprintf(out, "%u%s", m_base_line_number + (uint32_t)lines.GetSize(), GetPrompt() == nullptr ? " " : "");
}
m_curr_line_idx = lines.GetSize();
@@ -783,20 +777,32 @@ IOHandlerEditline::PrintAsync (Stream *stream, const char *s, size_t len)
m_editline_ap->PrintAsync(stream, s, len);
else
#endif
+ {
+ const char *prompt = GetPrompt();
+#ifdef _MSC_VER
+ if (prompt)
+ {
+ // Back up over previous prompt using Windows API
+ CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
+ HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
+ GetConsoleScreenBufferInfo(console_handle, &screen_buffer_info);
+ COORD coord = screen_buffer_info.dwCursorPosition;
+ coord.X -= strlen(prompt);
+ if (coord.X < 0)
+ coord.X = 0;
+ SetConsoleCursorPosition(console_handle, coord);
+ }
+#endif
IOHandler::PrintAsync(stream, s, len);
+ if (prompt)
+ IOHandler::PrintAsync(GetOutputStreamFile().get(), prompt, strlen(prompt));
+ }
}
// we may want curses to be disabled for some builds
// for instance, windows
#ifndef LLDB_DISABLE_CURSES
-#include "lldb/Core/ValueObject.h"
-#include "lldb/Symbol/VariableList.h"
-#include "lldb/Target/Target.h"
-#include "lldb/Target/Process.h"
-#include "lldb/Target/Thread.h"
-#include "lldb/Target/StackFrame.h"
-
#define KEY_RETURN 10
#define KEY_ESCAPE 27
@@ -1078,13 +1084,13 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
virtual const char *
WindowDelegateGetHelpText ()
{
- return NULL;
+ return nullptr;
}
virtual KeyHelp *
WindowDelegateGetKeyHelp ()
{
- return NULL;
+ return nullptr;
}
};
@@ -1124,9 +1130,9 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
public:
Window (const char *name) :
m_name (name),
- m_window (NULL),
- m_panel (NULL),
- m_parent (NULL),
+ m_window(nullptr),
+ m_panel(nullptr),
+ m_parent(nullptr),
m_subwindows (),
m_delegate_sp (),
m_curr_active_window_idx (UINT32_MAX),
@@ -1140,9 +1146,9 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
Window (const char *name, WINDOW *w, bool del = true) :
m_name (name),
- m_window (NULL),
- m_panel (NULL),
- m_parent (NULL),
+ m_window(nullptr),
+ m_panel(nullptr),
+ m_parent(nullptr),
m_subwindows (),
m_delegate_sp (),
m_curr_active_window_idx (UINT32_MAX),
@@ -1158,8 +1164,8 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
Window (const char *name, const Rect &bounds) :
m_name (name),
- m_window (NULL),
- m_parent (NULL),
+ m_window(nullptr),
+ m_parent(nullptr),
m_subwindows (),
m_delegate_sp (),
m_curr_active_window_idx (UINT32_MAX),
@@ -1180,7 +1186,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
}
void
- Reset (WINDOW *w = NULL, bool del = true)
+ Reset(WINDOW *w = nullptr, bool del = true)
{
if (m_window == w)
return;
@@ -1188,12 +1194,12 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
if (m_panel)
{
::del_panel (m_panel);
- m_panel = NULL;
+ m_panel = nullptr;
}
if (m_window && m_delete)
{
::delwin (m_window);
- m_window = NULL;
+ m_window = nullptr;
m_delete = false;
}
if (w)
@@ -1415,7 +1421,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
// Window drawing utilities
//----------------------------------------------------------------------
void
- DrawTitleBox (const char *title, const char *bottom_message = NULL)
+ DrawTitleBox(const char *title, const char *bottom_message = nullptr)
{
attr_t attr = 0;
if (IsActive())
@@ -1456,7 +1462,6 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
}
if (attr)
AttributeOff(attr);
-
}
virtual void
@@ -1554,7 +1559,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
Windows subwindows (m_subwindows);
for (auto subwindow_sp : subwindows)
{
- if (subwindow_sp->m_can_activate == false)
+ if (!subwindow_sp->m_can_activate)
{
HandleCharResult result = subwindow_sp->HandleChar(key);
if (result != eKeyNotHandled)
@@ -1569,7 +1574,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
SetActiveWindow (Window *window)
{
const size_t num_subwindows = m_subwindows.size();
- for (size_t i=0; i<num_subwindows; ++i)
+ for (size_t i = 0; i < num_subwindows; ++i)
{
if (m_subwindows[i].get() == window)
{
@@ -1601,7 +1606,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
// Find first window that wants to be active if this window is active
const size_t num_subwindows = m_subwindows.size();
- for (size_t i=0; i<num_subwindows; ++i)
+ for (size_t i = 0; i < num_subwindows; ++i)
{
if (m_subwindows[i]->GetCanBeActive())
{
@@ -1944,7 +1949,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
m_max_submenu_name_length (0),
m_max_submenu_key_name_length (0),
m_selected (0),
- m_parent (NULL),
+ m_parent(nullptr),
m_submenus (),
m_canned_result (MenuActionResult::NotHandled),
m_delegate_sp()
@@ -1965,7 +1970,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
m_max_submenu_name_length (0),
m_max_submenu_key_name_length (0),
m_selected (0),
- m_parent (NULL),
+ m_parent(nullptr),
m_submenus (),
m_canned_result (MenuActionResult::NotHandled),
m_delegate_sp()
@@ -1990,7 +1995,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
m_max_submenu_key_name_length = 0;
Menus &submenus = GetSubmenus();
const size_t num_submenus = submenus.size();
- for (size_t i=0; i<num_submenus; ++i)
+ for (size_t i = 0; i < num_submenus; ++i)
{
Menu *submenu = submenus[i].get();
if (static_cast<size_t>(m_max_submenu_name_length) < submenu->m_name.size())
@@ -2022,7 +2027,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
if (width > 2)
{
width -= 2;
- for (int i=0; i< width; ++i)
+ for (int i = 0; i < width; ++i)
window.PutChar(ACS_HLINE);
}
window.PutChar(ACS_RTEE);
@@ -2097,7 +2102,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
{
window.SetBackground(2);
window.MoveCursor(0, 0);
- for (size_t i=0; i<num_submenus; ++i)
+ for (size_t i = 0; i < num_submenus; ++i)
{
Menu *menu = submenus[i].get();
if (i > 0)
@@ -2121,7 +2126,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
window.Erase();
window.SetBackground(2);
window.Box();
- for (size_t i=0; i<num_submenus; ++i)
+ for (size_t i = 0; i < num_submenus; ++i)
{
const bool is_selected =
(i == static_cast<size_t>(selected_idx));
@@ -2171,7 +2176,6 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
break;
case KEY_RIGHT:
- {
++m_selected;
if (m_selected >= static_cast<int>(num_submenus))
m_selected = 0;
@@ -2180,11 +2184,9 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
else if (!submenus.empty())
run_menu_sp = submenus.front();
result = eKeyHandled;
- }
break;
case KEY_LEFT:
- {
--m_selected;
if (m_selected < 0)
m_selected = num_submenus - 1;
@@ -2193,11 +2195,10 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
else if (!submenus.empty())
run_menu_sp = submenus.front();
result = eKeyHandled;
- }
break;
default:
- for (size_t i=0; i<num_submenus; ++i)
+ for (size_t i = 0; i < num_submenus; ++i)
{
if (submenus[i]->GetKeyValue() == key)
{
@@ -2285,8 +2286,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
return eKeyHandled;
default:
- {
- for (size_t i=0; i<num_submenus; ++i)
+ for (size_t i = 0; i < num_submenus; ++i)
{
Menu *menu = submenus[i].get();
if (menu->GetKeyValue() == key)
@@ -2298,9 +2298,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
return eKeyHandled;
}
}
- }
break;
-
}
}
else if (menu_type == Menu::Type::Separator)
@@ -2314,11 +2312,10 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
public:
Application (FILE *in, FILE *out) :
m_window_sp(),
- m_screen (NULL),
+ m_screen(nullptr),
m_in (in),
m_out (out)
{
-
}
~Application ()
@@ -2328,7 +2325,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
if (m_screen)
{
::delscreen(m_screen);
- m_screen = NULL;
+ m_screen = nullptr;
}
}
@@ -2340,7 +2337,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
#if 0
::initscr();
#else
- m_screen = ::newterm(NULL, m_out, m_in);
+ m_screen = ::newterm(nullptr, m_out, m_in);
#endif
::start_color();
::curs_set(0);
@@ -2369,7 +2366,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
halfdelay(delay_in_tenths_of_a_second); // Poll using some number of tenths of seconds seconds when calling Window::GetChar()
- ListenerSP listener_sp (new Listener ("lldb.IOHandler.curses.Application"));
+ ListenerSP listener_sp (Listener::MakeListener("lldb.IOHandler.curses.Application"));
ConstString broadcaster_class_target(Target::GetStaticBroadcasterClass());
ConstString broadcaster_class_process(Process::GetStaticBroadcasterClass());
ConstString broadcaster_class_thread(Thread::GetStaticBroadcasterClass());
@@ -2457,7 +2454,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
ConstString broadcaster_class (broadcaster->GetBroadcasterClass());
if (broadcaster_class == broadcaster_class_process)
{
- debugger.GetCommandInterpreter().UpdateExecutionContext(NULL);
+ debugger.GetCommandInterpreter().UpdateExecutionContext(nullptr);
update = true;
continue; // Don't get any key, just update our view
}
@@ -2472,7 +2469,7 @@ type summary add -s "${var.origin%S} ${var.size%S}" curses::Rect
switch (key_result)
{
case eKeyHandled:
- debugger.GetCommandInterpreter().UpdateExecutionContext(NULL);
+ debugger.GetCommandInterpreter().UpdateExecutionContext(nullptr);
update = true;
break;
case eKeyNotHandled:
@@ -2556,7 +2553,7 @@ struct Row
if (valobj)
{
const size_t num_children = valobj->GetNumChildren();
- for (size_t i=0; i<num_children; ++i)
+ for (size_t i = 0; i < num_children; ++i)
{
children.push_back(Row (valobj->GetChildAtIndex(i, true), this));
}
@@ -2646,7 +2643,7 @@ class TreeItem;
class TreeDelegate
{
public:
- TreeDelegate() {}
+ TreeDelegate() = default;
virtual ~TreeDelegate() = default;
virtual void TreeDelegateDrawTreeItem (TreeItem &item, Window &window) = 0;
@@ -2659,11 +2656,10 @@ typedef std::shared_ptr<TreeDelegate> TreeDelegateSP;
class TreeItem
{
public:
-
TreeItem (TreeItem *parent, TreeDelegate &delegate, bool might_have_children) :
m_parent (parent),
m_delegate (delegate),
- m_user_data (NULL),
+ m_user_data(nullptr),
m_identifier (0),
m_row_idx (-1),
m_children (),
@@ -2751,7 +2747,7 @@ public:
// The root item must calculate its children,
// or we must calculate the number of children
// if the item is expanded
- if (m_parent == NULL || expanded)
+ if (m_parent == nullptr || expanded)
GetNumChildren();
for (auto &item : m_children)
@@ -2849,7 +2845,7 @@ public:
{
// If we displayed all the rows and item.Draw() returns
// false we are done drawing and can exit this for loop
- if (item.Draw(window, first_visible_row, selected_row_idx, row_idx, num_rows_left) == false)
+ if (!item.Draw(window, first_visible_row, selected_row_idx, row_idx, num_rows_left))
break;
}
}
@@ -2897,7 +2893,7 @@ public:
if (static_cast<uint32_t>(m_row_idx) == row_idx)
return this;
if (m_children.empty())
- return NULL;
+ return nullptr;
if (IsExpanded())
{
for (auto &item : m_children)
@@ -2907,7 +2903,7 @@ public:
return selected_item_ptr;
}
}
- return NULL;
+ return nullptr;
}
void *
@@ -2957,8 +2953,8 @@ public:
TreeWindowDelegate (Debugger &debugger, const TreeDelegateSP &delegate_sp) :
m_debugger (debugger),
m_delegate_sp (delegate_sp),
- m_root (NULL, *delegate_sp, true),
- m_selected_item (NULL),
+ m_root(nullptr, *delegate_sp, true),
+ m_selected_item(nullptr),
m_num_rows (0),
m_selected_row_idx (0),
m_first_visible_row (0),
@@ -3031,12 +3027,11 @@ public:
}
else
{
- m_selected_item = NULL;
+ m_selected_item = nullptr;
}
window.DeferredRefresh();
-
-
+
return true; // Drawing handled
}
@@ -3060,7 +3055,7 @@ public:
{ ' ', "Toggle item expansion" },
{ ',', "Page up" },
{ '.', "Page down" },
- { '\0', NULL }
+ { '\0', nullptr }
};
return g_source_view_key_help;
}
@@ -3205,7 +3200,7 @@ public:
StreamString strm;
const SymbolContext &sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
ExecutionContext exe_ctx (frame_sp);
- if (FormatEntity::Format(m_format, strm, &sc, &exe_ctx, NULL, NULL, false, false))
+ if (FormatEntity::Format(m_format, strm, &sc, &exe_ctx, nullptr, nullptr, false, false))
{
int right_pad = 1;
window.PutCStringTruncated(strm.GetString().c_str(), right_pad);
@@ -3276,7 +3271,7 @@ public:
{
StreamString strm;
ExecutionContext exe_ctx (thread_sp);
- if (FormatEntity::Format (m_format, strm, NULL, &exe_ctx, NULL, NULL, false, false))
+ if (FormatEntity::Format(m_format, strm, nullptr, &exe_ctx, nullptr, nullptr, false, false))
{
int right_pad = 1;
window.PutCStringTruncated(strm.GetString().c_str(), right_pad);
@@ -3310,7 +3305,7 @@ public:
TreeItem t (&item, *m_frame_delegate_sp, false);
size_t num_frames = thread_sp->GetStackFrameCount();
item.Resize (num_frames, t);
- for (size_t i=0; i<num_frames; ++i)
+ for (size_t i = 0; i < num_frames; ++i)
{
item[i].SetUserData(thread_sp.get());
item[i].SetIdentifier(i);
@@ -3335,7 +3330,7 @@ public:
if (thread_sp)
{
ThreadList &thread_list = thread_sp->GetProcess()->GetThreadList();
- Mutex::Locker locker (thread_list.GetMutex());
+ std::lock_guard<std::recursive_mutex> guard(thread_list.GetMutex());
ThreadSP selected_thread_sp = thread_list.GetSelectedThread();
if (selected_thread_sp->GetID() != thread_sp->GetID())
{
@@ -3385,7 +3380,7 @@ public:
{
StreamString strm;
ExecutionContext exe_ctx (process_sp);
- if (FormatEntity::Format (m_format, strm, NULL, &exe_ctx, NULL, NULL, false, false))
+ if (FormatEntity::Format(m_format, strm, nullptr, &exe_ctx, nullptr, nullptr, false, false))
{
int right_pad = 1;
window.PutCStringTruncated(strm.GetString().c_str(), right_pad);
@@ -3417,10 +3412,10 @@ public:
TreeItem t (&item, *m_thread_delegate_sp, false);
ThreadList &threads = process_sp->GetThreadList();
- Mutex::Locker locker (threads.GetMutex());
+ std::lock_guard<std::recursive_mutex> guard(threads.GetMutex());
size_t num_threads = threads.GetSize();
item.Resize (num_threads, t);
- for (size_t i=0; i<num_threads; ++i)
+ for (size_t i = 0; i < num_threads; ++i)
{
item[i].SetIdentifier(threads.GetThreadAtIndex(i)->GetID());
item[i].SetMightHaveChildren(true);
@@ -3450,7 +3445,7 @@ public:
ValueObjectListDelegate () :
m_valobj_list (),
m_rows (),
- m_selected_row (NULL),
+ m_selected_row(nullptr),
m_selected_row_idx (0),
m_first_visible_row (0),
m_num_rows (0),
@@ -3462,7 +3457,7 @@ public:
ValueObjectListDelegate (ValueObjectList &valobj_list) :
m_valobj_list (valobj_list),
m_rows (),
- m_selected_row (NULL),
+ m_selected_row(nullptr),
m_selected_row_idx (0),
m_first_visible_row (0),
m_num_rows (0),
@@ -3477,15 +3472,15 @@ public:
void
SetValues (ValueObjectList &valobj_list)
{
- m_selected_row = NULL;
+ m_selected_row = nullptr;
m_selected_row_idx = 0;
m_first_visible_row = 0;
m_num_rows = 0;
m_rows.clear();
m_valobj_list = valobj_list;
const size_t num_values = m_valobj_list.GetSize();
- for (size_t i=0; i<num_values; ++i)
- m_rows.push_back(Row(m_valobj_list.GetValueObjectAtIndex(i), NULL));
+ for (size_t i = 0; i < num_values; ++i)
+ m_rows.push_back(Row(m_valobj_list.GetValueObjectAtIndex(i), nullptr));
}
bool
@@ -3560,7 +3555,7 @@ public:
{ ' ', "Toggle item expansion" },
{ ',', "Page up" },
{ '.', "Page down" },
- { '\0', NULL }
+ { '\0', nullptr }
};
return g_source_view_key_help;
}
@@ -3713,10 +3708,10 @@ protected:
{
ValueObject *valobj = row.valobj.get();
- if (valobj == NULL)
+ if (valobj == nullptr)
return false;
- const char *type_name = options.show_types ? valobj->GetTypeName().GetCString() : NULL;
+ const char *type_name = options.show_types ? valobj->GetTypeName().GetCString() : nullptr;
const char *name = valobj->GetName().GetCString();
const char *value = valobj->GetValueAsCString ();
const char *summary = valobj->GetSummaryAsCString ();
@@ -3844,7 +3839,7 @@ protected:
}
}
}
- return NULL;
+ return nullptr;
}
Row *
@@ -3868,7 +3863,7 @@ public:
FrameVariablesWindowDelegate (Debugger &debugger) :
ValueObjectListDelegate (),
m_debugger (debugger),
- m_frame_block (NULL)
+ m_frame_block(nullptr)
{
}
@@ -3885,8 +3880,8 @@ public:
{
ExecutionContext exe_ctx (m_debugger.GetCommandInterpreter().GetExecutionContext());
Process *process = exe_ctx.GetProcessPtr();
- Block *frame_block = NULL;
- StackFrame *frame = NULL;
+ Block *frame_block = nullptr;
+ StackFrame *frame = nullptr;
if (process)
{
@@ -3916,7 +3911,7 @@ public:
{
const DynamicValueType use_dynamic = eDynamicDontRunTarget;
const size_t num_locals = locals->GetSize();
- for (size_t i=0; i<num_locals; ++i)
+ for (size_t i = 0; i < num_locals; ++i)
{
ValueObjectSP value_sp = frame->GetValueObjectForFrameVariable (locals->GetVariableAtIndex(i), use_dynamic);
if (value_sp)
@@ -3926,7 +3921,6 @@ public:
local_values.Append(synthetic_value_sp);
else
local_values.Append(value_sp);
-
}
}
// Update the values
@@ -3936,7 +3930,7 @@ public:
}
else
{
- m_frame_block = NULL;
+ m_frame_block = nullptr;
// Update the values with an empty list if there is no frame
SetValues(local_values);
}
@@ -4121,7 +4115,7 @@ CursesKeyToCString (int ch)
snprintf(g_desc, sizeof(g_desc), "\\x%2.2x", ch);
return g_desc;
}
- return NULL;
+ return nullptr;
}
HelpDialogDelegate::HelpDialogDelegate (const char *text, KeyHelp *key_help_array) :
@@ -4328,7 +4322,7 @@ public:
{ KEY_RIGHT, "Expand" },
{ KEY_PPAGE, "Page up" },
{ KEY_NPAGE, "Page down" },
- { '\0', NULL }
+ { '\0', nullptr }
};
return g_source_view_key_help;
}
@@ -4437,9 +4431,9 @@ public:
submenus.erase (submenus.begin() + 8, submenus.end());
ThreadList &threads = process->GetThreadList();
- Mutex::Locker locker (threads.GetMutex());
+ std::lock_guard<std::recursive_mutex> guard(threads.GetMutex());
size_t num_threads = threads.GetSize();
- for (size_t i=0; i<num_threads; ++i)
+ for (size_t i = 0; i < num_threads; ++i)
{
ThreadSP thread_sp = threads.GetThreadAtIndex(i);
char menu_char = '\0';
@@ -4456,7 +4450,7 @@ public:
if (queue_name && queue_name[0])
thread_menu_title.Printf (" %s", queue_name);
}
- menu.AddSubmenu (MenuSP (new Menu(thread_menu_title.GetString().c_str(), NULL, menu_char, thread_sp->GetID())));
+ menu.AddSubmenu(MenuSP(new Menu(thread_menu_title.GetString().c_str(), nullptr, menu_char, thread_sp->GetID())));
}
}
else if (submenus.size() > 7)
@@ -4629,7 +4623,7 @@ public:
if (StateIsStoppedState(state, true))
{
StreamString strm;
- if (thread && FormatEntity::Format (m_format, strm, NULL, &exe_ctx, NULL, NULL, false, false))
+ if (thread && FormatEntity::Format(m_format, strm, nullptr, &exe_ctx, nullptr, nullptr, false, false))
{
window.MoveCursor (40, 0);
window.PutCStringTruncated(strm.GetString().c_str(), 1);
@@ -4666,7 +4660,7 @@ public:
m_debugger (debugger),
m_sc (),
m_file_sp (),
- m_disassembly_scope (NULL),
+ m_disassembly_scope(nullptr),
m_disassembly_sp (),
m_disassembly_range (),
m_title (),
@@ -4725,7 +4719,7 @@ public:
{ 'S', "Step in (single instruction)" },
{ ',', "Page up" },
{ '.', "Page down" },
- { '\0', NULL }
+ { '\0', nullptr }
};
return g_source_view_key_help;
}
@@ -4735,7 +4729,7 @@ public:
{
ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
Process *process = exe_ctx.GetProcessPtr();
- Thread *thread = NULL;
+ Thread *thread = nullptr;
bool update_location = false;
if (process)
@@ -4870,7 +4864,7 @@ public:
if (m_disassembly_scope != m_sc.function)
{
m_disassembly_scope = m_sc.function;
- m_disassembly_sp = m_sc.function->GetInstructions (exe_ctx, NULL, prefer_file_cache);
+ m_disassembly_sp = m_sc.function->GetInstructions(exe_ctx, nullptr, prefer_file_cache);
if (m_disassembly_sp)
{
set_selected_line_to_pc = true;
@@ -4891,7 +4885,7 @@ public:
if (m_disassembly_scope != m_sc.symbol)
{
m_disassembly_scope = m_sc.symbol;
- m_disassembly_sp = m_sc.symbol->GetInstructions (exe_ctx, NULL, prefer_file_cache);
+ m_disassembly_sp = m_sc.symbol->GetInstructions(exe_ctx, nullptr, prefer_file_cache);
if (m_disassembly_sp)
{
set_selected_line_to_pc = true;
@@ -4965,7 +4959,7 @@ public:
const attr_t selected_highlight_attr = A_REVERSE;
const attr_t pc_highlight_attr = COLOR_PAIR(1);
- for (size_t i=0; i<num_visible_lines; ++i)
+ for (size_t i = 0; i < num_visible_lines; ++i)
{
const uint32_t curr_line = m_first_visible_line + i;
if (curr_line < num_source_lines)
@@ -5095,7 +5089,7 @@ public:
m_first_visible_line = pc_idx - non_visible_pc_offset;
}
- for (size_t i=0; i<num_visible_lines; ++i)
+ for (size_t i = 0; i < num_visible_lines; ++i)
{
const uint32_t inst_idx = m_first_visible_line + i;
Instruction *inst = insts.GetInstructionAtIndex(inst_idx).get();
@@ -5141,20 +5135,20 @@ public:
const char *operands = inst->GetOperands(&exe_ctx);
const char *comment = inst->GetComment(&exe_ctx);
- if (mnemonic && mnemonic[0] == '\0')
- mnemonic = NULL;
- if (operands && operands[0] == '\0')
- operands = NULL;
- if (comment && comment[0] == '\0')
- comment = NULL;
+ if (mnemonic != nullptr && mnemonic[0] == '\0')
+ mnemonic = nullptr;
+ if (operands != nullptr && operands[0] == '\0')
+ operands = nullptr;
+ if (comment != nullptr && comment[0] == '\0')
+ comment = nullptr;
strm.Clear();
- if (mnemonic && operands && comment)
+ if (mnemonic != nullptr && operands != nullptr && comment != nullptr)
strm.Printf ("%-8s %-25s ; %s", mnemonic, operands, comment);
- else if (mnemonic && operands)
+ else if (mnemonic != nullptr && operands != nullptr)
strm.Printf ("%-8s %s", mnemonic, operands);
- else if (mnemonic)
+ else if (mnemonic != nullptr)
strm.Printf ("%s", mnemonic);
int right_pad = 1;
@@ -5275,14 +5269,15 @@ public:
ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
if (exe_ctx.HasProcessScope() && exe_ctx.GetProcessRef().IsAlive())
{
- BreakpointSP bp_sp = exe_ctx.GetTargetRef().CreateBreakpoint (NULL, // Don't limit the breakpoint to certain modules
- m_file_sp->GetFileSpec(), // Source file
- m_selected_line + 1, // Source line number (m_selected_line is zero based)
- eLazyBoolCalculate, // Check inlines using global setting
- eLazyBoolCalculate, // Skip prologue using global setting,
- false, // internal
- false, // request_hardware
- eLazyBoolCalculate); // move_to_nearest_code
+ BreakpointSP bp_sp = exe_ctx.GetTargetRef().CreateBreakpoint(nullptr, // Don't limit the breakpoint to certain modules
+ m_file_sp->GetFileSpec(), // Source file
+ m_selected_line + 1, // Source line number (m_selected_line is zero based)
+ 0, // No offset
+ eLazyBoolCalculate, // Check inlines using global setting
+ eLazyBoolCalculate, // Skip prologue using global setting,
+ false, // internal
+ false, // request_hardware
+ eLazyBoolCalculate); // move_to_nearest_code
// Make breakpoint one shot
bp_sp->GetOptions()->SetOneShot(true);
exe_ctx.GetProcessRef().Resume();
@@ -5311,14 +5306,15 @@ public:
ExecutionContext exe_ctx = m_debugger.GetCommandInterpreter().GetExecutionContext();
if (exe_ctx.HasTargetScope())
{
- BreakpointSP bp_sp = exe_ctx.GetTargetRef().CreateBreakpoint (NULL, // Don't limit the breakpoint to certain modules
- m_file_sp->GetFileSpec(), // Source file
- m_selected_line + 1, // Source line number (m_selected_line is zero based)
- eLazyBoolCalculate, // Check inlines using global setting
- eLazyBoolCalculate, // Skip prologue using global setting,
- false, // internal
- false, // request_hardware
- eLazyBoolCalculate); // move_to_nearest_code
+ BreakpointSP bp_sp = exe_ctx.GetTargetRef().CreateBreakpoint(nullptr, // Don't limit the breakpoint to certain modules
+ m_file_sp->GetFileSpec(), // Source file
+ m_selected_line + 1, // Source line number (m_selected_line is zero based)
+ 0, // No offset
+ eLazyBoolCalculate, // Check inlines using global setting
+ eLazyBoolCalculate, // Skip prologue using global setting,
+ false, // internal
+ false, // request_hardware
+ eLazyBoolCalculate); // move_to_nearest_code
}
}
else if (m_selected_line < GetNumDisassemblyLines())
@@ -5452,38 +5448,38 @@ IOHandlerCursesGUI::Activate ()
MenuDelegateSP app_menu_delegate_sp = std::static_pointer_cast<MenuDelegate>(app_delegate_sp);
MenuSP lldb_menu_sp(new Menu("LLDB" , "F1", KEY_F(1), ApplicationDelegate::eMenuID_LLDB));
- MenuSP exit_menuitem_sp(new Menu("Exit", NULL, 'x', ApplicationDelegate::eMenuID_LLDBExit));
+ MenuSP exit_menuitem_sp(new Menu("Exit", nullptr, 'x', ApplicationDelegate::eMenuID_LLDBExit));
exit_menuitem_sp->SetCannedResult(MenuActionResult::Quit);
- lldb_menu_sp->AddSubmenu (MenuSP (new Menu("About LLDB", NULL, 'a', ApplicationDelegate::eMenuID_LLDBAbout)));
+ lldb_menu_sp->AddSubmenu (MenuSP (new Menu("About LLDB", nullptr, 'a', ApplicationDelegate::eMenuID_LLDBAbout)));
lldb_menu_sp->AddSubmenu (MenuSP (new Menu(Menu::Type::Separator)));
lldb_menu_sp->AddSubmenu (exit_menuitem_sp);
MenuSP target_menu_sp(new Menu("Target" ,"F2", KEY_F(2), ApplicationDelegate::eMenuID_Target));
- target_menu_sp->AddSubmenu (MenuSP (new Menu("Create", NULL, 'c', ApplicationDelegate::eMenuID_TargetCreate)));
- target_menu_sp->AddSubmenu (MenuSP (new Menu("Delete", NULL, 'd', ApplicationDelegate::eMenuID_TargetDelete)));
+ target_menu_sp->AddSubmenu (MenuSP (new Menu("Create", nullptr, 'c', ApplicationDelegate::eMenuID_TargetCreate)));
+ target_menu_sp->AddSubmenu (MenuSP (new Menu("Delete", nullptr, 'd', ApplicationDelegate::eMenuID_TargetDelete)));
MenuSP process_menu_sp(new Menu("Process", "F3", KEY_F(3), ApplicationDelegate::eMenuID_Process));
- process_menu_sp->AddSubmenu (MenuSP (new Menu("Attach" , NULL, 'a', ApplicationDelegate::eMenuID_ProcessAttach)));
- process_menu_sp->AddSubmenu (MenuSP (new Menu("Detach" , NULL, 'd', ApplicationDelegate::eMenuID_ProcessDetach)));
- process_menu_sp->AddSubmenu (MenuSP (new Menu("Launch" , NULL, 'l', ApplicationDelegate::eMenuID_ProcessLaunch)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Attach" , nullptr, 'a', ApplicationDelegate::eMenuID_ProcessAttach)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Detach" , nullptr, 'd', ApplicationDelegate::eMenuID_ProcessDetach)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Launch" , nullptr, 'l', ApplicationDelegate::eMenuID_ProcessLaunch)));
process_menu_sp->AddSubmenu (MenuSP (new Menu(Menu::Type::Separator)));
- process_menu_sp->AddSubmenu (MenuSP (new Menu("Continue", NULL, 'c', ApplicationDelegate::eMenuID_ProcessContinue)));
- process_menu_sp->AddSubmenu (MenuSP (new Menu("Halt" , NULL, 'h', ApplicationDelegate::eMenuID_ProcessHalt)));
- process_menu_sp->AddSubmenu (MenuSP (new Menu("Kill" , NULL, 'k', ApplicationDelegate::eMenuID_ProcessKill)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Continue", nullptr, 'c', ApplicationDelegate::eMenuID_ProcessContinue)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Halt" , nullptr, 'h', ApplicationDelegate::eMenuID_ProcessHalt)));
+ process_menu_sp->AddSubmenu (MenuSP (new Menu("Kill" , nullptr, 'k', ApplicationDelegate::eMenuID_ProcessKill)));
MenuSP thread_menu_sp(new Menu("Thread", "F4", KEY_F(4), ApplicationDelegate::eMenuID_Thread));
- thread_menu_sp->AddSubmenu (MenuSP (new Menu("Step In" , NULL, 'i', ApplicationDelegate::eMenuID_ThreadStepIn)));
- thread_menu_sp->AddSubmenu (MenuSP (new Menu("Step Over", NULL, 'v', ApplicationDelegate::eMenuID_ThreadStepOver)));
- thread_menu_sp->AddSubmenu (MenuSP (new Menu("Step Out" , NULL, 'o', ApplicationDelegate::eMenuID_ThreadStepOut)));
+ thread_menu_sp->AddSubmenu (MenuSP (new Menu("Step In" , nullptr, 'i', ApplicationDelegate::eMenuID_ThreadStepIn)));
+ thread_menu_sp->AddSubmenu (MenuSP (new Menu("Step Over", nullptr, 'v', ApplicationDelegate::eMenuID_ThreadStepOver)));
+ thread_menu_sp->AddSubmenu (MenuSP (new Menu("Step Out" , nullptr, 'o', ApplicationDelegate::eMenuID_ThreadStepOut)));
MenuSP view_menu_sp(new Menu("View", "F5", KEY_F(5), ApplicationDelegate::eMenuID_View));
- view_menu_sp->AddSubmenu (MenuSP (new Menu("Backtrace", NULL, 'b', ApplicationDelegate::eMenuID_ViewBacktrace)));
- view_menu_sp->AddSubmenu (MenuSP (new Menu("Registers", NULL, 'r', ApplicationDelegate::eMenuID_ViewRegisters)));
- view_menu_sp->AddSubmenu (MenuSP (new Menu("Source" , NULL, 's', ApplicationDelegate::eMenuID_ViewSource)));
- view_menu_sp->AddSubmenu (MenuSP (new Menu("Variables", NULL, 'v', ApplicationDelegate::eMenuID_ViewVariables)));
+ view_menu_sp->AddSubmenu (MenuSP (new Menu("Backtrace", nullptr, 'b', ApplicationDelegate::eMenuID_ViewBacktrace)));
+ view_menu_sp->AddSubmenu (MenuSP (new Menu("Registers", nullptr, 'r', ApplicationDelegate::eMenuID_ViewRegisters)));
+ view_menu_sp->AddSubmenu (MenuSP (new Menu("Source" , nullptr, 's', ApplicationDelegate::eMenuID_ViewSource)));
+ view_menu_sp->AddSubmenu (MenuSP (new Menu("Variables", nullptr, 'v', ApplicationDelegate::eMenuID_ViewVariables)));
MenuSP help_menu_sp(new Menu("Help", "F6", KEY_F(6), ApplicationDelegate::eMenuID_Help));
- help_menu_sp->AddSubmenu (MenuSP (new Menu("GUI Help", NULL, 'g', ApplicationDelegate::eMenuID_HelpGUIHelp)));
+ help_menu_sp->AddSubmenu (MenuSP (new Menu("GUI Help", nullptr, 'g', ApplicationDelegate::eMenuID_HelpGUIHelp)));
m_app_ap->Initialize();
WindowSP &main_window_sp = m_app_ap->GetMainWindow();
diff --git a/source/Core/Listener.cpp b/source/Core/Listener.cpp
index 34475498d48e..15a698784681 100644
--- a/source/Core/Listener.cpp
+++ b/source/Core/Listener.cpp
@@ -11,6 +11,8 @@
// C Includes
// C++ Includes
+#include <algorithm>
+
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Broadcaster.h"
@@ -18,53 +20,72 @@
#include "lldb/Core/StreamString.h"
#include "lldb/Core/Event.h"
#include "lldb/Host/TimeValue.h"
-#include <algorithm>
using namespace lldb;
using namespace lldb_private;
-Listener::Listener(const char *name) :
- m_name (name),
- m_broadcasters(),
- m_broadcasters_mutex (Mutex::eMutexTypeRecursive),
- m_events (),
- m_events_mutex (Mutex::eMutexTypeRecursive),
- m_cond_wait()
+namespace
+{
+ class BroadcasterManagerWPMatcher
+ {
+ public:
+ BroadcasterManagerWPMatcher (BroadcasterManagerSP manager_sp) : m_manager_sp(manager_sp) {}
+ bool operator() (const BroadcasterManagerWP input_wp) const
+ {
+ BroadcasterManagerSP input_sp = input_wp.lock();
+ return (input_sp && input_sp == m_manager_sp);
+ }
+
+ BroadcasterManagerSP m_manager_sp;
+ };
+} // anonymous namespace
+
+Listener::Listener(const char *name)
+ : m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(), m_events_mutex(Mutex::eMutexTypeNormal)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
- if (log)
+ if (log != nullptr)
log->Printf ("%p Listener::Listener('%s')",
static_cast<void*>(this), m_name.c_str());
}
Listener::~Listener()
{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
- Mutex::Locker locker (m_broadcasters_mutex);
-
- size_t num_managers = m_broadcaster_managers.size();
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
- for (size_t i = 0; i < num_managers; i++)
- m_broadcaster_managers[i]->RemoveListener(*this);
+ Clear();
if (log)
- log->Printf ("%p Listener::~Listener('%s')",
- static_cast<void*>(this), m_name.c_str());
- Clear();
+ log->Printf("%p Listener::%s('%s')", static_cast<void *>(this), __FUNCTION__, m_name.c_str());
}
void
Listener::Clear()
{
- Mutex::Locker locker(m_broadcasters_mutex);
+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
+ std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
broadcaster_collection::iterator pos, end = m_broadcasters.end();
for (pos = m_broadcasters.begin(); pos != end; ++pos)
- pos->first->RemoveListener (this, pos->second.event_mask);
- m_broadcasters.clear();
- m_cond_wait.SetValue (false, eBroadcastNever);
+ {
+ Broadcaster::BroadcasterImplSP broadcaster_sp(pos->first.lock());
+ if (broadcaster_sp)
+ broadcaster_sp->RemoveListener (this, pos->second.event_mask);
+ }
m_broadcasters.clear();
+
Mutex::Locker event_locker(m_events_mutex);
m_events.clear();
+ size_t num_managers = m_broadcaster_managers.size();
+
+ for (size_t i = 0; i < num_managers; i++)
+ {
+ BroadcasterManagerSP manager_sp(m_broadcaster_managers[i].lock());
+ if (manager_sp)
+ manager_sp->RemoveListener(this);
+ }
+
+ if (log)
+ log->Printf("%p Listener::%s('%s')", static_cast<void *>(this), __FUNCTION__, m_name.c_str());
}
uint32_t
@@ -75,25 +96,21 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask
// Scope for "locker"
// Tell the broadcaster to add this object as a listener
{
- Mutex::Locker locker(m_broadcasters_mutex);
- m_broadcasters.insert(std::make_pair(broadcaster, BroadcasterInfo(event_mask)));
+ std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ Broadcaster::BroadcasterImplWP impl_wp(broadcaster->GetBroadcasterImpl());
+ m_broadcasters.insert(std::make_pair(impl_wp, BroadcasterInfo(event_mask)));
}
- uint32_t acquired_mask = broadcaster->AddListener (this, event_mask);
-
- if (event_mask != acquired_mask)
- {
+ uint32_t acquired_mask = broadcaster->AddListener (this->shared_from_this(), event_mask);
- }
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS));
- if (log)
+ if (log != nullptr)
log->Printf ("%p Listener::StartListeningForEvents (broadcaster = %p, mask = 0x%8.8x) acquired_mask = 0x%8.8x for %s",
static_cast<void*>(this),
static_cast<void*>(broadcaster), event_mask,
acquired_mask, m_name.c_str());
return acquired_mask;
-
}
return 0;
}
@@ -106,14 +123,16 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask
// Scope for "locker"
// Tell the broadcaster to add this object as a listener
{
- Mutex::Locker locker(m_broadcasters_mutex);
- m_broadcasters.insert(std::make_pair(broadcaster, BroadcasterInfo(event_mask, callback, callback_user_data)));
+ std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ Broadcaster::BroadcasterImplWP impl_wp(broadcaster->GetBroadcasterImpl());
+ m_broadcasters.insert(std::make_pair(impl_wp,
+ BroadcasterInfo(event_mask, callback, callback_user_data)));
}
- uint32_t acquired_mask = broadcaster->AddListener (this, event_mask);
+ uint32_t acquired_mask = broadcaster->AddListener (this->shared_from_this(), event_mask);
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS));
- if (log)
+ if (log != nullptr)
{
void **pointer = reinterpret_cast<void**>(&callback);
log->Printf ("%p Listener::StartListeningForEvents (broadcaster = %p, mask = 0x%8.8x, callback = %p, user_data = %p) acquired_mask = 0x%8.8x for %s",
@@ -135,11 +154,11 @@ Listener::StopListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask)
{
// Scope for "locker"
{
- Mutex::Locker locker(m_broadcasters_mutex);
- m_broadcasters.erase (broadcaster);
+ std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ m_broadcasters.erase (broadcaster->GetBroadcasterImpl());
}
// Remove the broadcaster from our set of broadcasters
- return broadcaster->RemoveListener (this, event_mask);
+ return broadcaster->RemoveListener (this->shared_from_this(), event_mask);
}
return false;
@@ -152,8 +171,8 @@ Listener::BroadcasterWillDestruct (Broadcaster *broadcaster)
{
// Scope for "broadcasters_locker"
{
- Mutex::Locker broadcasters_locker(m_broadcasters_mutex);
- m_broadcasters.erase (broadcaster);
+ std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ m_broadcasters.erase (broadcaster->GetBroadcasterImpl());
}
// Scope for "event_locker"
@@ -168,19 +187,18 @@ Listener::BroadcasterWillDestruct (Broadcaster *broadcaster)
else
++pos;
}
-
- if (m_events.empty())
- m_cond_wait.SetValue (false, eBroadcastNever);
-
}
}
void
-Listener::BroadcasterManagerWillDestruct (BroadcasterManager *manager)
+Listener::BroadcasterManagerWillDestruct (BroadcasterManagerSP manager_sp)
{
// Just need to remove this broadcast manager from the list of managers:
broadcaster_manager_collection::iterator iter, end_iter = m_broadcaster_managers.end();
- iter = find(m_broadcaster_managers.begin(), end_iter, manager);
+ BroadcasterManagerWP manager_wp;
+
+ BroadcasterManagerWPMatcher matcher(manager_sp);
+ iter = std::find_if<broadcaster_manager_collection::iterator, BroadcasterManagerWPMatcher>(m_broadcaster_managers.begin(), end_iter, matcher);
if (iter != end_iter)
m_broadcaster_managers.erase (iter);
}
@@ -189,37 +207,31 @@ void
Listener::AddEvent (EventSP &event_sp)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS));
- if (log)
+ if (log != nullptr)
log->Printf ("%p Listener('%s')::AddEvent (event_sp = {%p})",
static_cast<void*>(this), m_name.c_str(),
static_cast<void*>(event_sp.get()));
- // Scope for "locker"
- {
- Mutex::Locker locker(m_events_mutex);
- m_events.push_back (event_sp);
- }
- m_cond_wait.SetValue (true, eBroadcastAlways);
+ Mutex::Locker locker(m_events_mutex);
+ m_events.push_back (event_sp);
+ m_events_condition.Broadcast();
}
class EventBroadcasterMatches
{
public:
EventBroadcasterMatches (Broadcaster *broadcaster) :
- m_broadcaster (broadcaster) {
+ m_broadcaster (broadcaster)
+ {
}
bool operator() (const EventSP &event_sp) const
{
- if (event_sp->BroadcasterIs(m_broadcaster))
- return true;
- else
- return false;
+ return event_sp->BroadcasterIs(m_broadcaster);
}
private:
Broadcaster *m_broadcaster;
-
};
class EventMatcher
@@ -242,7 +254,7 @@ public:
{
bool found_source = false;
const ConstString &event_broadcaster_name = event_sp->GetBroadcaster()->GetBroadcasterName();
- for (uint32_t i=0; i<m_num_broadcaster_names; ++i)
+ for (uint32_t i = 0; i < m_num_broadcaster_names; ++i)
{
if (m_broadcaster_names[i] == event_broadcaster_name)
{
@@ -266,28 +278,27 @@ private:
const uint32_t m_event_type_mask;
};
-
bool
Listener::FindNextEventInternal
(
- Broadcaster *broadcaster, // NULL for any broadcaster
- const ConstString *broadcaster_names, // NULL for any event
+ Mutex::Locker& lock,
+ Broadcaster *broadcaster, // nullptr for any broadcaster
+ const ConstString *broadcaster_names, // nullptr for any event
uint32_t num_broadcaster_names,
uint32_t event_type_mask,
EventSP &event_sp,
bool remove)
{
+ // NOTE: callers of this function must lock m_events_mutex using a Mutex::Locker
+ // and pass the locker as the first argument. m_events_mutex is no longer recursive.
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS));
- Mutex::Locker lock(m_events_mutex);
-
if (m_events.empty())
return false;
-
Listener::event_collection::iterator pos = m_events.end();
- if (broadcaster == NULL && broadcaster_names == NULL && event_type_mask == 0)
+ if (broadcaster == nullptr && broadcaster_names == nullptr && event_type_mask == 0)
{
pos = m_events.begin();
}
@@ -300,7 +311,7 @@ Listener::FindNextEventInternal
{
event_sp = *pos;
- if (log)
+ if (log != nullptr)
log->Printf ("%p '%s' Listener::FindNextEventInternal(broadcaster=%p, broadcaster_names=%p[%u], event_type_mask=0x%8.8x, remove=%i) event %p",
static_cast<void*>(this), GetName(),
static_cast<void*>(broadcaster),
@@ -311,20 +322,12 @@ Listener::FindNextEventInternal
if (remove)
{
m_events.erase(pos);
-
- if (m_events.empty())
- m_cond_wait.SetValue (false, eBroadcastNever);
- }
-
- // Unlock the event queue here. We've removed this event and are about to return
- // it so it should be okay to get the next event off the queue here - and it might
- // be useful to do that in the "DoOnRemoval".
- lock.Unlock();
-
- // Don't call DoOnRemoval if you aren't removing the event...
- if (remove)
+ // Unlock the event queue here. We've removed this event and are about to return
+ // it so it should be okay to get the next event off the queue here - and it might
+ // be useful to do that in the "DoOnRemoval".
+ lock.Unlock();
event_sp->DoOnRemoval();
-
+ }
return true;
}
@@ -335,122 +338,105 @@ Listener::FindNextEventInternal
Event *
Listener::PeekAtNextEvent ()
{
+ Mutex::Locker lock(m_events_mutex);
EventSP event_sp;
- if (FindNextEventInternal (NULL, NULL, 0, 0, event_sp, false))
+ if (FindNextEventInternal(lock, nullptr, nullptr, 0, 0, event_sp, false))
return event_sp.get();
- return NULL;
+ return nullptr;
}
Event *
Listener::PeekAtNextEventForBroadcaster (Broadcaster *broadcaster)
{
+ Mutex::Locker lock(m_events_mutex);
EventSP event_sp;
- if (FindNextEventInternal (broadcaster, NULL, 0, 0, event_sp, false))
+ if (FindNextEventInternal(lock, broadcaster, nullptr, 0, 0, event_sp, false))
return event_sp.get();
- return NULL;
+ return nullptr;
}
Event *
Listener::PeekAtNextEventForBroadcasterWithType (Broadcaster *broadcaster, uint32_t event_type_mask)
{
+ Mutex::Locker lock(m_events_mutex);
EventSP event_sp;
- if (FindNextEventInternal (broadcaster, NULL, 0, event_type_mask, event_sp, false))
+ if (FindNextEventInternal(lock, broadcaster, nullptr, 0, event_type_mask, event_sp, false))
return event_sp.get();
- return NULL;
+ return nullptr;
}
-
bool
-Listener::GetNextEventInternal
-(
- Broadcaster *broadcaster, // NULL for any broadcaster
- const ConstString *broadcaster_names, // NULL for any event
- uint32_t num_broadcaster_names,
- uint32_t event_type_mask,
- EventSP &event_sp
-)
+Listener::GetNextEventInternal(Broadcaster *broadcaster, // nullptr for any broadcaster
+ const ConstString *broadcaster_names, // nullptr for any event
+ uint32_t num_broadcaster_names,
+ uint32_t event_type_mask,
+ EventSP &event_sp)
{
- return FindNextEventInternal (broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, event_sp, true);
+ Mutex::Locker lock(m_events_mutex);
+ return FindNextEventInternal (lock, broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, event_sp, true);
}
bool
Listener::GetNextEvent (EventSP &event_sp)
{
- return GetNextEventInternal (NULL, NULL, 0, 0, event_sp);
+ return GetNextEventInternal(nullptr, nullptr, 0, 0, event_sp);
}
-
bool
Listener::GetNextEventForBroadcaster (Broadcaster *broadcaster, EventSP &event_sp)
{
- return GetNextEventInternal (broadcaster, NULL, 0, 0, event_sp);
+ return GetNextEventInternal(broadcaster, nullptr, 0, 0, event_sp);
}
bool
Listener::GetNextEventForBroadcasterWithType (Broadcaster *broadcaster, uint32_t event_type_mask, EventSP &event_sp)
{
- return GetNextEventInternal (broadcaster, NULL, 0, event_type_mask, event_sp);
+ return GetNextEventInternal(broadcaster, nullptr, 0, event_type_mask, event_sp);
}
-
bool
-Listener::WaitForEventsInternal
-(
- const TimeValue *timeout,
- Broadcaster *broadcaster, // NULL for any broadcaster
- const ConstString *broadcaster_names, // NULL for any event
- uint32_t num_broadcaster_names,
- uint32_t event_type_mask,
- EventSP &event_sp
-)
+Listener::WaitForEventsInternal(const TimeValue *timeout,
+ Broadcaster *broadcaster, // nullptr for any broadcaster
+ const ConstString *broadcaster_names, // nullptr for any event
+ uint32_t num_broadcaster_names,
+ uint32_t event_type_mask,
+ EventSP &event_sp)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS));
- bool timed_out = false;
-
- if (log)
+ if (log != nullptr)
log->Printf ("%p Listener::WaitForEventsInternal (timeout = { %p }) for %s",
static_cast<void*>(this), static_cast<const void*>(timeout),
m_name.c_str());
- while (1)
- {
- // Note, we don't want to lock the m_events_mutex in the call to GetNextEventInternal, since the DoOnRemoval
- // code might require that new events be serviced. For instance, the Breakpoint Command's
- if (GetNextEventInternal (broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, event_sp))
- return true;
-
- {
- // Reset condition value to false, so we can wait for new events to be
- // added that might meet our current filter
- // But first poll for any new event that might satisfy our condition, and if so consume it,
- // otherwise wait.
-
- Mutex::Locker event_locker(m_events_mutex);
- const bool remove = false;
- if (FindNextEventInternal (broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, event_sp, remove))
- continue;
- else
- m_cond_wait.SetValue (false, eBroadcastNever);
- }
-
- if (m_cond_wait.WaitForValueEqualTo (true, timeout, &timed_out))
- continue;
+ Mutex::Locker lock(m_events_mutex);
- else if (timed_out)
+ while (true)
+ {
+ if (FindNextEventInternal (lock, broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, event_sp, true))
{
- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
- if (log)
- log->Printf ("%p Listener::WaitForEventsInternal() timed out for %s",
- static_cast<void*>(this), m_name.c_str());
- break;
+ return true;
}
else
{
- log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
- if (log)
- log->Printf ("%p Listener::WaitForEventsInternal() unknown error for %s",
- static_cast<void*>(this), m_name.c_str());
- break;
+ bool timed_out = false;
+ if (m_events_condition.Wait(m_events_mutex, timeout, &timed_out) != 0)
+ {
+ if (timed_out)
+ {
+ log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
+ if (log != nullptr)
+ log->Printf ("%p Listener::WaitForEventsInternal() timed out for %s",
+ static_cast<void*>(this), m_name.c_str());
+ }
+ else
+ {
+ log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS);
+ if (log != nullptr)
+ log->Printf ("%p Listener::WaitForEventsInternal() unknown error for %s",
+ static_cast<void*>(this), m_name.c_str());
+ }
+ return false;
+ }
}
}
@@ -458,73 +444,47 @@ Listener::WaitForEventsInternal
}
bool
-Listener::WaitForEventForBroadcasterWithType
-(
- const TimeValue *timeout,
- Broadcaster *broadcaster,
- uint32_t event_type_mask,
- EventSP &event_sp
-)
+Listener::WaitForEventForBroadcasterWithType(const TimeValue *timeout,
+ Broadcaster *broadcaster,
+ uint32_t event_type_mask,
+ EventSP &event_sp)
{
- return WaitForEventsInternal (timeout, broadcaster, NULL, 0, event_type_mask, event_sp);
+ return WaitForEventsInternal(timeout, broadcaster, nullptr, 0, event_type_mask, event_sp);
}
bool
-Listener::WaitForEventForBroadcaster
-(
- const TimeValue *timeout,
- Broadcaster *broadcaster,
- EventSP &event_sp
-)
+Listener::WaitForEventForBroadcaster(const TimeValue *timeout,
+ Broadcaster *broadcaster,
+ EventSP &event_sp)
{
- return WaitForEventsInternal (timeout, broadcaster, NULL, 0, 0, event_sp);
+ return WaitForEventsInternal(timeout, broadcaster, nullptr, 0, 0, event_sp);
}
bool
Listener::WaitForEvent (const TimeValue *timeout, EventSP &event_sp)
{
- return WaitForEventsInternal (timeout, NULL, NULL, 0, 0, event_sp);
+ return WaitForEventsInternal(timeout, nullptr, nullptr, 0, 0, event_sp);
}
-//Listener::broadcaster_collection::iterator
-//Listener::FindBroadcasterWithMask (Broadcaster *broadcaster, uint32_t event_mask, bool exact)
-//{
-// broadcaster_collection::iterator pos;
-// broadcaster_collection::iterator end = m_broadcasters.end();
-// for (pos = m_broadcasters.find (broadcaster);
-// pos != end && pos->first == broadcaster;
-// ++pos)
-// {
-// if (exact)
-// {
-// if ((event_mask & pos->second.event_mask) == event_mask)
-// return pos;
-// }
-// else
-// {
-// if (event_mask & pos->second.event_mask)
-// return pos;
-// }
-// }
-// return end;
-//}
-
size_t
Listener::HandleBroadcastEvent (EventSP &event_sp)
{
size_t num_handled = 0;
- Mutex::Locker locker(m_broadcasters_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
Broadcaster *broadcaster = event_sp->GetBroadcaster();
+ if (!broadcaster)
+ return 0;
broadcaster_collection::iterator pos;
broadcaster_collection::iterator end = m_broadcasters.end();
- for (pos = m_broadcasters.find (broadcaster);
- pos != end && pos->first == broadcaster;
+ Broadcaster::BroadcasterImplSP broadcaster_impl_sp(broadcaster->GetBroadcasterImpl());
+ for (pos = m_broadcasters.find (broadcaster_impl_sp);
+ pos != end && pos->first.lock() == broadcaster_impl_sp;
++pos)
{
BroadcasterInfo info = pos->second;
if (event_sp->GetType () & info.event_mask)
{
- if (info.callback != NULL)
+ if (info.callback != nullptr)
{
info.callback (event_sp, info.callback_user_data);
++num_handled;
@@ -535,28 +495,44 @@ Listener::HandleBroadcastEvent (EventSP &event_sp)
}
uint32_t
-Listener::StartListeningForEventSpec (BroadcasterManager &manager,
+Listener::StartListeningForEventSpec (BroadcasterManagerSP manager_sp,
const BroadcastEventSpec &event_spec)
{
+ if (!manager_sp)
+ return 0;
+
// The BroadcasterManager mutex must be locked before m_broadcasters_mutex
// to avoid violating the lock hierarchy (manager before broadcasters).
- Mutex::Locker manager_locker(manager.m_manager_mutex);
- Mutex::Locker locker(m_broadcasters_mutex);
+ std::lock_guard<std::recursive_mutex> manager_guard(manager_sp->m_manager_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
- uint32_t bits_acquired = manager.RegisterListenerForEvents(*this, event_spec);
+ uint32_t bits_acquired = manager_sp->RegisterListenerForEvents(this->shared_from_this(), event_spec);
if (bits_acquired)
- m_broadcaster_managers.push_back(&manager);
-
+ {
+ broadcaster_manager_collection::iterator iter, end_iter = m_broadcaster_managers.end();
+ BroadcasterManagerWP manager_wp(manager_sp);
+ BroadcasterManagerWPMatcher matcher(manager_sp);
+ iter = std::find_if<broadcaster_manager_collection::iterator, BroadcasterManagerWPMatcher>(m_broadcaster_managers.begin(), end_iter, matcher);
+ if (iter == end_iter)
+ m_broadcaster_managers.push_back(manager_wp);
+ }
+
return bits_acquired;
}
bool
-Listener::StopListeningForEventSpec (BroadcasterManager &manager,
+Listener::StopListeningForEventSpec (BroadcasterManagerSP manager_sp,
const BroadcastEventSpec &event_spec)
{
- Mutex::Locker locker(m_broadcasters_mutex);
- return manager.UnregisterListenerForEvents (*this, event_spec);
+ if (!manager_sp)
+ return false;
+ std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ return manager_sp->UnregisterListenerForEvents (this->shared_from_this(), event_spec);
}
-
+ListenerSP
+Listener::MakeListener(const char *name)
+{
+ return ListenerSP(new Listener(name));
+}
diff --git a/source/Core/Log.cpp b/source/Core/Log.cpp
index 8d415bdc0e77..a292df3ed525 100644
--- a/source/Core/Log.cpp
+++ b/source/Core/Log.cpp
@@ -8,30 +8,30 @@
//===----------------------------------------------------------------------===//
// C Includes
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-
// C++ Includes
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
#include <map>
+#include <mutex>
#include <string>
// Other libraries and framework includes
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Signals.h"
+
// Project includes
#include "lldb/Core/Log.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Host/Host.h"
-#include "lldb/Host/Mutex.h"
#include "lldb/Host/ThisThread.h"
#include "lldb/Host/TimeValue.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Utility/NameMatches.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Signals.h"
using namespace lldb;
using namespace lldb_private;
@@ -49,9 +49,7 @@ Log::Log (const StreamSP &stream_sp) :
{
}
-Log::~Log ()
-{
-}
+Log::~Log() = default;
Flags &
Log::GetOptions()
@@ -149,8 +147,8 @@ Log::VAPrintf(const char *format, va_list args)
if (m_options.Test(LLDB_LOG_OPTION_THREADSAFE))
{
- static Mutex g_LogThreadedMutex(Mutex::eMutexTypeRecursive);
- Mutex::Locker locker(g_LogThreadedMutex);
+ static std::recursive_mutex g_LogThreadedMutex;
+ std::lock_guard<std::recursive_mutex> guard(g_LogThreadedMutex);
stream_sp->PutCString(header.GetString().c_str());
stream_sp->Flush();
}
@@ -178,7 +176,6 @@ Log::Debug(const char *format, ...)
va_end(args);
}
-
//----------------------------------------------------------------------
// Print debug strings if and only if the global debug option is set to
// a non-zero value.
@@ -195,7 +192,6 @@ Log::DebugVerbose(const char *format, ...)
va_end(args);
}
-
//----------------------------------------------------------------------
// Log only if all of the bits are set
//----------------------------------------------------------------------
@@ -223,7 +219,6 @@ Log::Error(const char *format, ...)
va_end(args);
}
-
void
Log::VAError(const char *format, va_list args)
{
@@ -237,7 +232,6 @@ Log::VAError(const char *format, va_list args)
free(arg_msg);
}
-
//----------------------------------------------------------------------
// Printing of errors that ARE fatal. Exit with ERR exit code
// immediately.
@@ -259,7 +253,6 @@ Log::FatalError(int err, const char *format, ...)
::exit(err);
}
-
//----------------------------------------------------------------------
// Printing of warnings that are not fatal only if verbose mode is
// enabled.
@@ -298,6 +291,7 @@ Log::WarningVerbose(const char *format, ...)
Printf("warning: %s", arg_msg);
free(arg_msg);
}
+
//----------------------------------------------------------------------
// Printing of warnings that are not fatal.
//----------------------------------------------------------------------
@@ -323,7 +317,6 @@ typedef CallbackMap::iterator CallbackMapIter;
typedef std::map <ConstString, LogChannelSP> LogChannelMap;
typedef LogChannelMap::iterator LogChannelMapIter;
-
// Surround our callback map with a singleton function so we don't have any
// global initializers.
static CallbackMap &
@@ -401,13 +394,10 @@ Log::EnableLogChannel(lldb::StreamSP &log_stream_sp,
}
void
-Log::EnableAllLogChannels
-(
- StreamSP &log_stream_sp,
- uint32_t log_options,
- const char **categories,
- Stream *feedback_strm
-)
+Log::EnableAllLogChannels(StreamSP &log_stream_sp,
+ uint32_t log_options,
+ const char **categories,
+ Stream *feedback_strm)
{
CallbackMap &callback_map = GetCallbackMap ();
CallbackMapIter pos, end = callback_map.end();
@@ -421,7 +411,6 @@ Log::EnableAllLogChannels
{
channel_pos->second->Enable (log_stream_sp, log_options, feedback_strm, categories);
}
-
}
void
@@ -441,7 +430,6 @@ Log::AutoCompleteChannelName (const char *channel_name, StringList &matches)
}
else
matches.AppendString(pos_channel_name);
-
}
}
@@ -471,7 +459,7 @@ Log::Initialize()
void
Log::Terminate ()
{
- DisableAllLogChannels (NULL);
+ DisableAllLogChannels(nullptr);
}
void
@@ -492,7 +480,7 @@ Log::ListAllLogChannels (Stream *strm)
uint32_t idx = 0;
const char *name;
- for (idx = 0; (name = PluginManager::GetLogChannelCreateNameAtIndex (idx)) != NULL; ++idx)
+ for (idx = 0; (name = PluginManager::GetLogChannelCreateNameAtIndex (idx)) != nullptr; ++idx)
{
LogChannelSP log_channel_sp(LogChannel::FindPlugin (name));
if (log_channel_sp)
@@ -529,7 +517,6 @@ Log::GetDebug() const
return false;
}
-
LogChannelSP
LogChannel::FindPlugin (const char *plugin_name)
{
@@ -566,8 +553,4 @@ LogChannel::LogChannel () :
{
}
-LogChannel::~LogChannel ()
-{
-}
-
-
+LogChannel::~LogChannel() = default;
diff --git a/source/Core/Logging.cpp b/source/Core/Logging.cpp
index d08d833ee469..9eb4f6676a4d 100644
--- a/source/Core/Logging.cpp
+++ b/source/Core/Logging.cpp
@@ -11,30 +11,31 @@
// C Includes
// C++ Includes
+#include <cstring>
#include <atomic>
+
// Other libraries and framework includes
// Project includes
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamFile.h"
-#include <string.h>
using namespace lldb;
using namespace lldb_private;
-
// We want to avoid global constructors where code needs to be run so here we
// control access to our static g_log_sp by hiding it in a singleton function
// that will construct the static g_lob_sp the first time this function is
// called.
static std::atomic<bool> g_log_enabled {false};
-static Log * g_log = NULL;
+static Log * g_log = nullptr;
+
static Log *
GetLog ()
{
if (!g_log_enabled)
- return NULL;
+ return nullptr;
return g_log;
}
@@ -62,7 +63,7 @@ lldb_private::GetLogIfAllCategoriesSet (uint32_t mask)
{
uint32_t log_mask = log->GetMask().Get();
if ((log_mask & mask) != mask)
- return NULL;
+ return nullptr;
}
return log;
}
@@ -84,7 +85,7 @@ void
lldb_private::LogIfAnyCategoriesSet (uint32_t mask, const char *format, ...)
{
Log *log(GetLogIfAnyCategoriesSet (mask));
- if (log)
+ if (log != nullptr)
{
va_list args;
va_start (args, format);
@@ -97,9 +98,9 @@ Log *
lldb_private::GetLogIfAnyCategoriesSet (uint32_t mask)
{
Log *log(GetLog ());
- if (log && mask && (mask & log->GetMask().Get()))
+ if (log != nullptr && mask && (mask & log->GetMask().Get()))
return log;
- return NULL;
+ return nullptr;
}
void
@@ -107,13 +108,13 @@ lldb_private::DisableLog (const char **categories, Stream *feedback_strm)
{
Log *log(GetLog ());
- if (log)
+ if (log != nullptr)
{
uint32_t flag_bits = 0;
- if (categories[0] != NULL)
+ if (categories[0] != nullptr)
{
flag_bits = log->GetMask().Get();
- for (size_t i = 0; categories[i] != NULL; ++i)
+ for (size_t i = 0; categories[i] != nullptr; ++i)
{
const char *arg = categories[i];
@@ -149,6 +150,7 @@ lldb_private::DisableLog (const char **categories, Stream *feedback_strm)
else if (0 == ::strcasecmp(arg, "jit")) flag_bits &= ~LIBLLDB_LOG_JIT_LOADER;
else if (0 == ::strcasecmp(arg, "language")) flag_bits &= ~LIBLLDB_LOG_LANGUAGE;
else if (0 == ::strncasecmp(arg, "formatters", 10)) flag_bits &= ~LIBLLDB_LOG_DATAFORMATTERS;
+ else if (0 == ::strncasecmp(arg, "demangle", 8)) flag_bits &= ~LIBLLDB_LOG_DEMANGLE;
else
{
feedback_strm->Printf ("error: unrecognized log category '%s'\n", arg);
@@ -164,8 +166,6 @@ lldb_private::DisableLog (const char **categories, Stream *feedback_strm)
g_log_enabled = false;
}
}
-
- return;
}
Log *
@@ -174,7 +174,7 @@ lldb_private::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, const ch
// Try see if there already is a log - that way we can reuse its settings.
// We could reuse the log in toto, but we don't know that the stream is the same.
uint32_t flag_bits;
- if (g_log)
+ if (g_log != nullptr)
flag_bits = g_log->GetMask().Get();
else
flag_bits = 0;
@@ -182,15 +182,15 @@ lldb_private::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, const ch
// Now make a new log with this stream if one was provided
if (log_stream_sp)
{
- if (g_log)
+ if (g_log != nullptr)
g_log->SetStream(log_stream_sp);
else
g_log = new Log(log_stream_sp);
}
- if (g_log)
+ if (g_log != nullptr)
{
- for (size_t i=0; categories[i] != NULL; ++i)
+ for (size_t i = 0; categories[i] != nullptr; ++i)
{
const char *arg = categories[i];
@@ -226,6 +226,7 @@ lldb_private::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, const ch
else if (0 == ::strcasecmp(arg, "jit")) flag_bits |= LIBLLDB_LOG_JIT_LOADER;
else if (0 == ::strcasecmp(arg, "language")) flag_bits |= LIBLLDB_LOG_LANGUAGE;
else if (0 == ::strncasecmp(arg, "formatters", 10)) flag_bits |= LIBLLDB_LOG_DATAFORMATTERS;
+ else if (0 == ::strncasecmp(arg, "demangle", 8)) flag_bits |= LIBLLDB_LOG_DEMANGLE;
else
{
feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
@@ -241,7 +242,6 @@ lldb_private::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, const ch
return g_log;
}
-
void
lldb_private::ListLogCategories (Stream *strm)
{
@@ -253,6 +253,7 @@ lldb_private::ListLogCategories (Stream *strm)
" communication - log communication activities\n"
" connection - log connection details\n"
" default - enable the default set of logging categories for liblldb\n"
+ " demangle - log mangled names to catch demangler crashes\n"
" dyld - log shared library related activities\n"
" events - log broadcaster, listener and event queue activities\n"
" expr - log expressions\n"
diff --git a/source/Core/Makefile b/source/Core/Makefile
deleted file mode 100644
index b7773e3f571d..000000000000
--- a/source/Core/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-##===- source/Core/Makefile --------------------------------*- Makefile -*-===##
-#
-# The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LLDB_LEVEL := ../..
-LIBRARYNAME := lldbCore
-BUILD_ARCHIVE = 1
-
-include $(LLDB_LEVEL)/Makefile
diff --git a/source/Core/Mangled.cpp b/source/Core/Mangled.cpp
index bdc710c8f8e1..543b34e337a2 100644
--- a/source/Core/Mangled.cpp
+++ b/source/Core/Mangled.cpp
@@ -34,6 +34,8 @@
#include "llvm/ADT/DenseMap.h"
#include "lldb/Core/ConstString.h"
+#include "lldb/Core/Log.h"
+#include "lldb/Core/Logging.h"
#include "lldb/Core/Mangled.h"
#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/Stream.h"
@@ -271,6 +273,8 @@ Mangled::GetDemangledName (lldb::LanguageType language) const
"Mangled::GetDemangledName (m_mangled = %s)",
m_mangled.GetCString());
+ Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DEMANGLE);
+
// Don't bother running anything that isn't mangled
const char *mangled_name = m_mangled.GetCString();
ManglingScheme mangling_scheme{cstring_mangling_scheme(mangled_name)};
@@ -285,6 +289,8 @@ Mangled::GetDemangledName (lldb::LanguageType language) const
case eManglingSchemeMSVC:
{
#if defined(_MSC_VER)
+ if (log)
+ log->Printf("demangle msvc: %s", mangled_name);
const size_t demangled_length = 2048;
demangled_name = static_cast<char *>(::malloc(demangled_length));
::ZeroMemory(demangled_name, demangled_length);
@@ -295,6 +301,14 @@ Mangled::GetDemangledName (lldb::LanguageType language) const
UNDNAME_NO_MEMBER_TYPE | // Strip virtual, static, etc specifiers
UNDNAME_NO_MS_KEYWORDS // Strip all MS extension keywords
);
+ if (log)
+ {
+ if (demangled_name && demangled_name[0])
+ log->Printf("demangled msvc: %s -> \"%s\"", mangled_name, demangled_name);
+ else
+ log->Printf("demangled msvc: %s -> error: 0x%" PRIx64, mangled_name, result);
+ }
+
if (result == 0)
{
free(demangled_name);
@@ -306,6 +320,8 @@ Mangled::GetDemangledName (lldb::LanguageType language) const
case eManglingSchemeItanium:
{
#ifdef LLDB_USE_BUILTIN_DEMANGLER
+ if (log)
+ log->Printf("demangle itanium: %s", mangled_name);
// Try to use the fast-path demangler first for the
// performance win, falling back to the full demangler only
// when necessary
@@ -315,6 +331,13 @@ Mangled::GetDemangledName (lldb::LanguageType language) const
#else
demangled_name = abi::__cxa_demangle(mangled_name, NULL, NULL, NULL);
#endif
+ if (log)
+ {
+ if (demangled_name)
+ log->Printf("demangled itanium: %s -> \"%s\"", mangled_name, demangled_name);
+ else
+ log->Printf("demangled itanium: %s -> error: failed to demangle", mangled_name);
+ }
break;
}
case eManglingSchemeNone:
diff --git a/source/Core/Module.cpp b/source/Core/Module.cpp
index a29456f5b5a5..5fe39abda183 100644
--- a/source/Core/Module.cpp
+++ b/source/Core/Module.cpp
@@ -7,9 +7,17 @@
//
//===----------------------------------------------------------------------===//
+#include "lldb/Core/Module.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+#include "llvm/Support/raw_os_ostream.h"
+#include "llvm/Support/Signals.h"
+
+// Project includes
#include "lldb/Core/AddressResolverFileLine.h"
#include "lldb/Core/Error.h"
-#include "lldb/Core/Module.h"
#include "lldb/Core/DataBuffer.h"
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Log.h"
@@ -40,9 +48,6 @@
#include "Plugins/ObjectFile/JIT/ObjectFileJIT.h"
-#include "llvm/Support/raw_os_ostream.h"
-#include "llvm/Support/Signals.h"
-
using namespace lldb;
using namespace lldb_private;
@@ -60,14 +65,14 @@ GetModuleCollection()
// is a big problem we can introduce a Finalize method that will tear everything down in
// a predictable order.
- static ModuleCollection *g_module_collection = NULL;
- if (g_module_collection == NULL)
+ static ModuleCollection *g_module_collection = nullptr;
+ if (g_module_collection == nullptr)
g_module_collection = new ModuleCollection();
return *g_module_collection;
}
-Mutex *
+std::recursive_mutex &
Module::GetAllocationModuleCollectionMutex()
{
// NOTE: The mutex below must be leaked since the global module list in
@@ -75,30 +80,30 @@ Module::GetAllocationModuleCollectionMutex()
// 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 Mutex *g_module_collection_mutex = NULL;
- if (g_module_collection_mutex == NULL)
- g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak
- return g_module_collection_mutex;
+ 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 ()
{
- Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
return GetModuleCollection().size();
}
Module *
Module::GetAllocatedModuleAtIndex (size_t idx)
{
- Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
ModuleCollection &modules = GetModuleCollection();
if (idx < modules.size())
return modules[idx];
- return NULL;
+ return nullptr;
}
-#if 0
+#if 0
// These functions help us to determine if modules are still loaded, yet don't require that
// you have a command interpreter and can easily be called from an external debugger.
namespace lldb {
@@ -117,7 +122,7 @@ namespace lldb {
ModuleCollection &modules = GetModuleCollection();
const size_t count = modules.size();
printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count);
- for (size_t i=0; i<count; ++i)
+ for (size_t i = 0; i < count; ++i)
{
StreamString strm;
@@ -135,44 +140,42 @@ namespace lldb {
#endif
-Module::Module (const ModuleSpec &module_spec) :
- m_mutex (Mutex::eMutexTypeRecursive),
- 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)
+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...
{
- Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ 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)
- 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() ? "" : ")");
+ 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
@@ -189,18 +192,18 @@ Module::Module (const ModuleSpec &module_spec) :
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())
@@ -213,57 +216,53 @@ Module::Module (const ModuleSpec &module_spec) :
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 (Mutex::eMutexTypeRecursive),
- 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)
+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...
{
- Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetAllocationModuleCollectionMutex());
GetModuleCollection().push_back(this);
}
@@ -273,40 +272,37 @@ Module::Module(const FileSpec& file_spec,
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)
- 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 (Mutex::eMutexTypeRecursive),
- 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)
-{
- Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ 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);
}
@@ -314,10 +310,10 @@ 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
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
// Scope for locker below...
{
- Mutex::Locker locker (GetAllocationModuleCollectionMutex());
+ 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);
@@ -325,7 +321,7 @@ Module::~Module()
modules.erase(pos);
}
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
- if (log)
+ if (log != nullptr)
log->Printf ("%p Module::~Module((%s) '%s%s%s%s')",
static_cast<void*>(this),
m_arch.GetArchitectureName(),
@@ -352,7 +348,7 @@ Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t hea
}
else
{
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (process_sp)
{
m_did_load_objfile = true;
@@ -395,18 +391,17 @@ Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t hea
return m_objfile_sp.get();
}
-
const lldb_private::UUID&
Module::GetUUID()
{
- if (m_did_parse_uuid.load() == false)
+ if (!m_did_parse_uuid.load())
{
- Mutex::Locker locker (m_mutex);
- if (m_did_parse_uuid.load() == false)
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ if (!m_did_parse_uuid.load())
{
ObjectFile * obj_file = GetObjectFile ();
- if (obj_file != NULL)
+ if (obj_file != nullptr)
{
obj_file->GetUUID(&m_uuid);
m_did_parse_uuid = true;
@@ -425,7 +420,7 @@ Module::GetTypeSystemForLanguage (LanguageType language)
void
Module::ParseAllDebugSymbols()
{
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
size_t num_comp_units = GetNumCompileUnits();
if (num_comp_units == 0)
return;
@@ -439,12 +434,12 @@ Module::ParseAllDebugSymbols()
sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
if (sc.comp_unit)
{
- sc.function = NULL;
+ sc.function = nullptr;
symbols->ParseVariablesForContext(sc);
symbols->ParseCompileUnitFunctions(sc);
- for (size_t func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx)
+ for (size_t func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != nullptr; ++func_idx)
{
symbols->ParseFunctionBlocks(sc);
@@ -452,9 +447,8 @@ Module::ParseAllDebugSymbols()
symbols->ParseVariablesForContext(sc);
}
-
// Parse all types for this compile unit
- sc.function = NULL;
+ sc.function = nullptr;
symbols->ParseTypes(sc);
}
}
@@ -481,7 +475,7 @@ Module::DumpSymbolContext(Stream *s)
size_t
Module::GetNumCompileUnits()
{
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
Timer scoped_timer(__PRETTY_FUNCTION__,
"Module::GetNumCompileUnits (module = %p)",
static_cast<void*>(this));
@@ -494,7 +488,7 @@ Module::GetNumCompileUnits()
CompUnitSP
Module::GetCompileUnitAtIndex (size_t index)
{
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
size_t num_comp_units = GetNumCompileUnits ();
CompUnitSP cu_sp;
@@ -510,7 +504,7 @@ Module::GetCompileUnitAtIndex (size_t index)
bool
Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
{
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr);
SectionList *section_list = GetSectionList();
if (section_list)
@@ -522,7 +516,7 @@ uint32_t
Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc,
bool resolve_tail_call_address)
{
- Mutex::Locker locker (m_mutex);
+ 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
@@ -548,7 +542,8 @@ Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve
if (resolve_scope & eSymbolContextCompUnit ||
resolve_scope & eSymbolContextFunction ||
resolve_scope & eSymbolContextBlock ||
- resolve_scope & eSymbolContextLineEntry )
+ resolve_scope & eSymbolContextLineEntry ||
+ resolve_scope & eSymbolContextVariable )
{
resolved_flags |= sym_vendor->ResolveSymbolContext (so_addr, resolve_scope, sc);
}
@@ -672,7 +667,7 @@ Module::ResolveSymbolContextForFilePath
uint32_t
Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
{
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
Timer scoped_timer(__PRETTY_FUNCTION__,
"Module::ResolveSymbolContextForFilePath (%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
file_spec.GetPath().c_str(),
@@ -689,7 +684,6 @@ Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t li
return sc_list.GetSize() - initial_count;
}
-
size_t
Module::FindGlobalVariables (const ConstString &name,
const CompilerDeclContext *parent_decl_ctx,
@@ -728,7 +722,7 @@ Module::FindCompileUnits (const FileSpec &path,
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)
+ for (size_t i = 0; i < num_compile_units; ++i)
{
sc.comp_unit = GetCompileUnitAtIndex(i).get();
if (sc.comp_unit)
@@ -740,6 +734,186 @@ Module::FindCompileUnits (const FileSpec &path,
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
+ 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())
+ 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;
+ }
+ }
+}
+
+
size_t
Module::FindFunctions (const ConstString &name,
const CompilerDeclContext *parent_decl_ctx,
@@ -759,21 +933,13 @@ Module::FindFunctions (const ConstString &name,
if (name_type_mask & eFunctionNameTypeAuto)
{
- ConstString lookup_name;
- uint32_t lookup_name_type_mask = 0;
- bool match_name_after_lookup = false;
- Module::PrepareForFunctionNameLookup (name,
- name_type_mask,
- eLanguageTypeUnknown, // TODO: add support
- lookup_name,
- lookup_name_type_mask,
- match_name_after_lookup);
-
+ LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
+
if (symbols)
{
- symbols->FindFunctions(lookup_name,
+ symbols->FindFunctions(lookup_info.GetLookupName(),
parent_decl_ctx,
- lookup_name_type_mask,
+ lookup_info.GetNameTypeMask(),
include_inlines,
append,
sc_list);
@@ -783,30 +949,14 @@ Module::FindFunctions (const ConstString &name,
{
Symtab *symtab = symbols->GetSymtab();
if (symtab)
- symtab->FindFunctionSymbols(lookup_name, lookup_name_type_mask, sc_list);
+ symtab->FindFunctionSymbols(lookup_info.GetLookupName(), lookup_info.GetNameTypeMask(), sc_list);
}
}
- if (match_name_after_lookup)
- {
- SymbolContext sc;
- size_t i = old_size;
- while (i<sc_list.GetSize())
- {
- if (sc_list.GetContextAtIndex(i, sc))
- {
- const char *func_name = sc.GetFunctionName().GetCString();
- if (func_name && strstr (func_name, name.GetCString()) == NULL)
- {
- // Remove the current context
- sc_list.RemoveContextAtIndex(i);
- // Don't increment i and continue in the loop
- continue;
- }
- }
- ++i;
- }
- }
+ const size_t new_size = sc_list.GetSize();
+
+ if (old_size < new_size)
+ lookup_info.Prune (sc_list, old_size);
}
else
{
@@ -861,7 +1011,7 @@ Module::FindFunctions (const RegularExpression& regex,
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)
+ for (size_t i = 0; i < num_matches; ++i)
{
sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
SymbolType sym_type = sc.symbol->GetType();
@@ -874,7 +1024,7 @@ Module::FindFunctions (const RegularExpression& regex,
{
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)
+ for (size_t i = start_size; i < end_functions_added_index; ++i)
{
const SymbolContext &sc = sc_list[i];
if (sc.block)
@@ -885,7 +1035,7 @@ Module::FindFunctions (const RegularExpression& regex,
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)
+ for (size_t i = start_size; i < num_matches; ++i)
{
sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
SymbolType sym_type = sc.symbol->GetType();
@@ -916,7 +1066,7 @@ Module::FindAddressesForLine (const lldb::TargetSP target_sp,
AddressResolverFileLine resolver(file, line, true);
resolver.ResolveAddress (filter);
- for (size_t n=0;n<resolver.GetNumberOfAddresses();n++)
+ for (size_t n = 0; n < resolver.GetNumberOfAddresses(); n++)
{
Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
Function *f = addr.CalculateSymbolContextFunction();
@@ -933,14 +1083,15 @@ Module::FindTypes_Impl (const SymbolContext& sc,
const CompilerDeclContext *parent_decl_ctx,
bool append,
size_t max_matches,
+ llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap& types)
{
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
- if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
+ 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, types);
+ return symbols->FindTypes(sc, name, parent_decl_ctx, append, max_matches, searched_symbol_files, types);
}
return 0;
}
@@ -954,7 +1105,8 @@ Module::FindTypesInNamespace (const SymbolContext& sc,
{
const bool append = true;
TypeMap types_map;
- size_t num_types = FindTypes_Impl(sc, type_name, parent_decl_ctx, append, max_matches, 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;
@@ -966,18 +1118,19 @@ Module::FindFirstType (const SymbolContext& sc,
bool exact_match)
{
TypeList type_list;
- const size_t num_matches = FindTypes (sc, name, exact_match, 1, 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;
@@ -1000,7 +1153,7 @@ Module::FindTypes (const SymbolContext& sc,
exact_match = true;
}
ConstString type_basename_const_str (type_basename.c_str());
- if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, typesmap))
+ 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();
@@ -1013,13 +1166,13 @@ Module::FindTypes (const SymbolContext& sc,
{
// 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), NULL, append, max_matches, typesmap);
+ 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, NULL, append, max_matches, typesmap);
+ num_matches = FindTypes_Impl(sc, name, nullptr, append, max_matches, searched_symbol_files, typesmap);
}
}
if (num_matches > 0)
@@ -1030,13 +1183,13 @@ Module::FindTypes (const SymbolContext& sc,
SymbolVendor*
Module::GetSymbolVendor (bool can_create, lldb_private::Stream *feedback_strm)
{
- if (m_did_load_symbol_vendor.load() == false)
+ if (!m_did_load_symbol_vendor.load())
{
- Mutex::Locker locker (m_mutex);
- if (m_did_load_symbol_vendor.load() == false && can_create)
+ 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 != NULL)
+ if (obj_file != nullptr)
{
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
@@ -1079,7 +1232,7 @@ Module::GetSpecificationDescription () const
void
Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
{
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (level >= eDescriptionLevelFull)
{
@@ -1127,14 +1280,13 @@ Module::ReportError (const char *format, ...)
strm.EOL();
}
Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
-
}
}
bool
Module::FileHasChanged () const
{
- if (m_file_has_changed == false)
+ if (!m_file_has_changed)
m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
return m_file_has_changed;
}
@@ -1142,7 +1294,7 @@ Module::FileHasChanged () const
void
Module::ReportErrorIfModifyDetected (const char *format, ...)
{
- if (m_first_file_changed_log == false)
+ if (!m_first_file_changed_log)
{
if (FileHasChanged ())
{
@@ -1202,7 +1354,7 @@ Module::ReportWarning (const char *format, ...)
void
Module::LogMessage (Log *log, const char *format, ...)
{
- if (log)
+ if (log != nullptr)
{
StreamString log_message;
GetDescription(&log_message, lldb::eDescriptionLevelFull);
@@ -1218,7 +1370,7 @@ Module::LogMessage (Log *log, const char *format, ...)
void
Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
{
- if (log)
+ if (log != nullptr)
{
StreamString log_message;
GetDescription(&log_message, lldb::eDescriptionLevelFull);
@@ -1241,7 +1393,7 @@ Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
void
Module::Dump(Stream *s)
{
- Mutex::Locker locker (m_mutex);
+ 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",
@@ -1263,14 +1415,13 @@ Module::Dump(Stream *s)
s->IndentLess();
}
-
TypeList*
Module::GetTypeList ()
{
SymbolVendor *symbols = GetSymbolVendor ();
if (symbols)
return &symbols->GetTypeList();
- return NULL;
+ return nullptr;
}
const ConstString &
@@ -1282,10 +1433,10 @@ Module::GetObjectName() const
ObjectFile *
Module::GetObjectFile()
{
- if (m_did_load_objfile.load() == false)
+ if (!m_did_load_objfile.load())
{
- Mutex::Locker locker (m_mutex);
- if (m_did_load_objfile.load() == false)
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ if (!m_did_load_objfile.load())
{
Timer scoped_timer(__PRETTY_FUNCTION__,
"Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
@@ -1326,10 +1477,10 @@ SectionList *
Module::GetSectionList()
{
// Populate m_unified_sections_ap with sections from objfile.
- if (m_sections_ap.get() == NULL)
+ if (!m_sections_ap)
{
ObjectFile *obj_file = GetObjectFile();
- if (obj_file)
+ if (obj_file != nullptr)
obj_file->CreateSections(*GetUnifiedSectionList());
}
return m_sections_ap.get();
@@ -1342,7 +1493,7 @@ Module::SectionFileAddressesChanged ()
if (obj_file)
obj_file->SectionFileAddressesChanged ();
SymbolVendor* sym_vendor = GetSymbolVendor();
- if (sym_vendor)
+ if (sym_vendor != nullptr)
sym_vendor->SectionFileAddressesChanged ();
}
@@ -1350,7 +1501,7 @@ SectionList *
Module::GetUnifiedSectionList()
{
// Populate m_unified_sections_ap with sections from objfile.
- if (m_sections_ap.get() == NULL)
+ if (!m_sections_ap)
m_sections_ap.reset(new SectionList());
return m_sections_ap.get();
}
@@ -1369,7 +1520,7 @@ Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symb
if (symtab)
return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
}
- return NULL;
+ return nullptr;
}
void
Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
@@ -1416,7 +1567,6 @@ Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_t
// No need to protect this call using m_mutex all other method calls are
// already thread safe.
-
Timer scoped_timer(__PRETTY_FUNCTION__,
"Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
name.AsCString(),
@@ -1530,7 +1680,7 @@ Module::SetSymbolFileFileSpec (const FileSpec &file)
bool
Module::IsExecutable ()
{
- if (GetObjectFile() == NULL)
+ if (GetObjectFile() == nullptr)
return false;
else
return GetObjectFile()->IsExecutable();
@@ -1543,7 +1693,7 @@ Module::IsLoadedInTarget (Target *target)
if (obj_file)
{
SectionList *sections = GetSectionList();
- if (sections != NULL)
+ if (sections != nullptr)
{
size_t num_sections = sections->GetSize();
for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
@@ -1589,15 +1739,14 @@ Module::LoadScriptingResourceInTarget (Target *target, Error& error, Stream* fee
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)
+ for (uint32_t i = 0; i < num_specs; ++i)
{
FileSpec scripting_fspec (file_specs.GetFileSpecAtIndex(i));
if (scripting_fspec && scripting_fspec.Exists())
@@ -1651,7 +1800,7 @@ bool
Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
{
ObjectFile *object_file = GetObjectFile();
- if (object_file)
+ if (object_file != nullptr)
{
changed = object_file->SetLoadAddress(target, value, value_is_offset);
return true;
@@ -1672,10 +1821,7 @@ Module::MatchesModuleSpec (const ModuleSpec &module_ref)
if (uuid.IsValid())
{
// If the UUID matches, then nothing more needs to match...
- if (uuid == GetUUID())
- return true;
- else
- return false;
+ return (uuid == GetUUID());
}
const FileSpec &file_spec = module_ref.GetFileSpec();
@@ -1712,14 +1858,14 @@ Module::MatchesModuleSpec (const ModuleSpec &module_ref)
bool
Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
{
- Mutex::Locker locker (m_mutex);
+ 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
{
- Mutex::Locker locker (m_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
return m_source_mappings.RemapPath(path, new_path);
}
@@ -1730,121 +1876,14 @@ Module::GetVersion (uint32_t *versions, uint32_t num_versions)
if (obj_file)
return obj_file->GetVersion (versions, num_versions);
- if (versions && num_versions)
+ if (versions != nullptr && num_versions != 0)
{
- for (uint32_t i=0; i<num_versions; ++i)
+ for (uint32_t i = 0; i < num_versions; ++i)
versions[i] = LLDB_INVALID_MODULE_VERSION;
}
return 0;
}
-void
-Module::PrepareForFunctionNameLookup (const ConstString &name,
- uint32_t name_type_mask,
- LanguageType language,
- ConstString &lookup_name,
- uint32_t &lookup_name_type_mask,
- bool &match_name_after_lookup)
-{
- const char *name_cstr = name.GetCString();
- lookup_name_type_mask = eFunctionNameTypeNone;
- match_name_after_lookup = false;
-
- llvm::StringRef basename;
- llvm::StringRef context;
-
- if (name_type_mask & eFunctionNameTypeAuto)
- {
- if (CPlusPlusLanguage::IsCPPMangledName (name_cstr))
- lookup_name_type_mask = eFunctionNameTypeFull;
- else if ((language == eLanguageTypeUnknown ||
- Language::LanguageIsObjC(language)) &&
- ObjCLanguage::IsPossibleObjCMethodName (name_cstr))
- lookup_name_type_mask = eFunctionNameTypeFull;
- else if (Language::LanguageIsC(language))
- {
- lookup_name_type_mask = eFunctionNameTypeFull;
- }
- else
- {
- if ((language == eLanguageTypeUnknown ||
- Language::LanguageIsObjC(language)) &&
- ObjCLanguage::IsPossibleObjCSelector(name_cstr))
- lookup_name_type_mask |= eFunctionNameTypeSelector;
-
- CPlusPlusLanguage::MethodName cpp_method (name);
- basename = cpp_method.GetBasename();
- if (basename.empty())
- {
- if (CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context, basename))
- lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
- else
- lookup_name_type_mask |= eFunctionNameTypeFull;
- }
- else
- {
- lookup_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
- }
- }
- }
- else
- {
- lookup_name_type_mask = name_type_mask;
- if (lookup_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
- lookup_name_type_mask &= ~(eFunctionNameTypeBase);
- if (lookup_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 (lookup_name_type_mask & eFunctionNameTypeSelector)
- {
- if (!ObjCLanguage::IsPossibleObjCSelector(name_cstr))
- {
- lookup_name_type_mask &= ~(eFunctionNameTypeSelector);
- if (lookup_name_type_mask == eFunctionNameTypeNone)
- return;
- }
- }
- }
-
- 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
- lookup_name.SetString(basename);
- 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"
- lookup_name = name;
- match_name_after_lookup = false;
- }
-}
-
ModuleSP
Module::CreateJITModule (const lldb::ObjectFileJITDelegateSP &delegate_sp)
{
diff --git a/source/Core/ModuleList.cpp b/source/Core/ModuleList.cpp
index 75b2ca11103a..bfd53e7d1c2c 100644
--- a/source/Core/ModuleList.cpp
+++ b/source/Core/ModuleList.cpp
@@ -10,10 +10,9 @@
#include "lldb/Core/ModuleList.h"
// C Includes
-#include <stdint.h>
-
// C++ Includes
-#include <mutex> // std::once
+#include <cstdint>
+#include <mutex>
// Other libraries and framework includes
// Project includes
@@ -23,44 +22,27 @@
#include "lldb/Host/Host.h"
#include "lldb/Host/Symbols.h"
#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/VariableList.h"
using namespace lldb;
using namespace lldb_private;
-//----------------------------------------------------------------------
-// ModuleList constructor
-//----------------------------------------------------------------------
-ModuleList::ModuleList() :
- m_modules(),
- m_modules_mutex (Mutex::eMutexTypeRecursive),
- m_notifier(NULL)
+ModuleList::ModuleList() : m_modules(), m_modules_mutex(), m_notifier(nullptr)
{
}
-//----------------------------------------------------------------------
-// Copy constructor
-//----------------------------------------------------------------------
-ModuleList::ModuleList(const ModuleList& rhs) :
- m_modules(),
- m_modules_mutex (Mutex::eMutexTypeRecursive),
- m_notifier(NULL)
+ModuleList::ModuleList(const ModuleList &rhs) : m_modules(), m_modules_mutex(), m_notifier(nullptr)
{
- Mutex::Locker lhs_locker(m_modules_mutex);
- Mutex::Locker rhs_locker(rhs.m_modules_mutex);
+ 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 (Mutex::eMutexTypeRecursive),
- m_notifier(notifier)
+ModuleList::ModuleList(ModuleList::Notifier *notifier) : m_modules(), m_modules_mutex(), m_notifier(notifier)
{
}
-//----------------------------------------------------------------------
-// Assignment operator
-//----------------------------------------------------------------------
const ModuleList&
ModuleList::operator= (const ModuleList& rhs)
{
@@ -78,33 +60,28 @@ ModuleList::operator= (const ModuleList& rhs)
// avoids priority inversion.
if (uintptr_t(this) > uintptr_t(&rhs))
{
- Mutex::Locker lhs_locker(m_modules_mutex);
- Mutex::Locker rhs_locker(rhs.m_modules_mutex);
+ 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
{
- Mutex::Locker rhs_locker(rhs.m_modules_mutex);
- Mutex::Locker lhs_locker(m_modules_mutex);
+ 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;
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-ModuleList::~ModuleList()
-{
-}
+ModuleList::~ModuleList() = default;
void
ModuleList::AppendImpl (const ModuleSP &module_sp, bool use_notifier)
{
if (module_sp)
{
- Mutex::Locker locker(m_modules_mutex);
+ 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);
@@ -122,7 +99,7 @@ ModuleList::ReplaceEquivalent (const ModuleSP &module_sp)
{
if (module_sp)
{
- Mutex::Locker locker(m_modules_mutex);
+ 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.
@@ -148,7 +125,7 @@ ModuleList::AppendIfNeeded (const ModuleSP &module_sp)
{
if (module_sp)
{
- Mutex::Locker locker(m_modules_mutex);
+ 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)
{
@@ -186,7 +163,7 @@ ModuleList::RemoveImpl (const ModuleSP &module_sp, bool use_notifier)
{
if (module_sp)
{
- Mutex::Locker locker(m_modules_mutex);
+ 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)
{
@@ -234,7 +211,7 @@ ModuleList::RemoveIfOrphaned (const Module *module_ptr)
{
if (module_ptr)
{
- Mutex::Locker locker(m_modules_mutex);
+ 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)
{
@@ -256,16 +233,16 @@ ModuleList::RemoveIfOrphaned (const Module *module_ptr)
size_t
ModuleList::RemoveOrphans (bool mandatory)
{
- Mutex::Locker locker;
-
+ std::unique_lock<std::recursive_mutex> lock(m_modules_mutex, std::defer_lock);
+
if (mandatory)
{
- locker.Lock (m_modules_mutex);
+ lock.lock();
}
else
{
// Not mandatory, remove orphans if we can get the mutex
- if (!locker.TryLock(m_modules_mutex))
+ if (!lock.try_lock())
return 0;
}
collection::iterator pos = m_modules.begin();
@@ -288,7 +265,7 @@ ModuleList::RemoveOrphans (bool mandatory)
size_t
ModuleList::Remove (ModuleList &module_list)
{
- Mutex::Locker locker(m_modules_mutex);
+ 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)
@@ -315,7 +292,7 @@ ModuleList::Destroy()
void
ModuleList::ClearImpl (bool use_notifier)
{
- Mutex::Locker locker(m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
if (use_notifier && m_notifier)
m_notifier->WillClearList(*this);
m_modules.clear();
@@ -324,7 +301,7 @@ ModuleList::ClearImpl (bool use_notifier)
Module*
ModuleList::GetModulePointerAtIndex (size_t idx) const
{
- Mutex::Locker locker(m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
return GetModulePointerAtIndexUnlocked(idx);
}
@@ -333,13 +310,13 @@ ModuleList::GetModulePointerAtIndexUnlocked (size_t idx) const
{
if (idx < m_modules.size())
return m_modules[idx].get();
- return NULL;
+ return nullptr;
}
ModuleSP
ModuleList::GetModuleAtIndex(size_t idx) const
{
- Mutex::Locker locker(m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
return GetModuleAtIndexUnlocked(idx);
}
@@ -367,57 +344,33 @@ ModuleList::FindFunctions (const ConstString &name,
if (name_type_mask & eFunctionNameTypeAuto)
{
- ConstString lookup_name;
- uint32_t lookup_name_type_mask = 0;
- bool match_name_after_lookup = false;
- Module::PrepareForFunctionNameLookup (name, name_type_mask,
- eLanguageTypeUnknown, // TODO: add support
- lookup_name,
- lookup_name_type_mask,
- match_name_after_lookup);
-
- Mutex::Locker locker(m_modules_mutex);
+ 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_name,
- NULL,
- lookup_name_type_mask,
- include_symbols,
- include_inlines,
- true,
- sc_list);
+ (*pos)->FindFunctions(lookup_info.GetLookupName(),
+ nullptr,
+ lookup_info.GetNameTypeMask(),
+ include_symbols,
+ include_inlines,
+ true,
+ sc_list);
}
- if (match_name_after_lookup)
- {
- SymbolContext sc;
- size_t i = old_size;
- while (i<sc_list.GetSize())
- {
- if (sc_list.GetContextAtIndex(i, sc))
- {
- const char *func_name = sc.GetFunctionName().GetCString();
- if (func_name && strstr (func_name, name.GetCString()) == NULL)
- {
- // Remove the current context
- sc_list.RemoveContextAtIndex(i);
- // Don't increment i and continue in the loop
- continue;
- }
- }
- ++i;
- }
- }
+ const size_t new_size = sc_list.GetSize();
+ if (old_size < new_size)
+ lookup_info.Prune (sc_list, old_size);
}
else
{
- Mutex::Locker locker(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)->FindFunctions (name, NULL, name_type_mask, include_symbols, include_inlines, true, sc_list);
+ (*pos)->FindFunctions(name, nullptr, name_type_mask, include_symbols, include_inlines, true, sc_list);
}
}
return sc_list.GetSize() - old_size;
@@ -432,49 +385,26 @@ ModuleList::FindFunctionSymbols (const ConstString &name,
if (name_type_mask & eFunctionNameTypeAuto)
{
- ConstString lookup_name;
- uint32_t lookup_name_type_mask = 0;
- bool match_name_after_lookup = false;
- Module::PrepareForFunctionNameLookup (name, name_type_mask,
- eLanguageTypeUnknown, // TODO: add support
- lookup_name,
- lookup_name_type_mask,
- match_name_after_lookup);
-
- Mutex::Locker locker(m_modules_mutex);
+ 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_name,
- lookup_name_type_mask,
- sc_list);
- }
-
- if (match_name_after_lookup)
- {
- SymbolContext sc;
- size_t i = old_size;
- while (i<sc_list.GetSize())
- {
- if (sc_list.GetContextAtIndex(i, sc))
- {
- const char *func_name = sc.GetFunctionName().GetCString();
- if (func_name && strstr (func_name, name.GetCString()) == NULL)
- {
- // Remove the current context
- sc_list.RemoveContextAtIndex(i);
- // Don't increment i and continue in the loop
- continue;
- }
- }
- ++i;
- }
+ (*pos)->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
{
- Mutex::Locker locker(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)
{
@@ -485,7 +415,6 @@ ModuleList::FindFunctionSymbols (const ConstString &name,
return sc_list.GetSize() - old_size;
}
-
size_t
ModuleList::FindFunctions(const RegularExpression &name,
bool include_symbols,
@@ -495,7 +424,7 @@ ModuleList::FindFunctions(const RegularExpression &name,
{
const size_t old_size = sc_list.GetSize();
- Mutex::Locker locker(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)
{
@@ -512,8 +441,8 @@ ModuleList::FindCompileUnits (const FileSpec &path,
{
if (!append)
sc_list.Clear();
-
- Mutex::Locker locker(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)
{
@@ -530,16 +459,15 @@ ModuleList::FindGlobalVariables (const ConstString &name,
VariableList& variable_list) const
{
size_t initial_size = variable_list.GetSize();
- Mutex::Locker locker(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)->FindGlobalVariables (name, NULL, append, max_matches, variable_list);
+ (*pos)->FindGlobalVariables(name, nullptr, append, max_matches, variable_list);
}
return variable_list.GetSize() - initial_size;
}
-
size_t
ModuleList::FindGlobalVariables (const RegularExpression& regex,
bool append,
@@ -547,7 +475,7 @@ ModuleList::FindGlobalVariables (const RegularExpression& regex,
VariableList& variable_list) const
{
size_t initial_size = variable_list.GetSize();
- Mutex::Locker locker(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)
{
@@ -556,14 +484,13 @@ ModuleList::FindGlobalVariables (const RegularExpression& regex,
return variable_list.GetSize() - initial_size;
}
-
size_t
ModuleList::FindSymbolsWithNameAndType (const ConstString &name,
SymbolType symbol_type,
SymbolContextList &sc_list,
bool append) const
{
- Mutex::Locker locker(m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
if (!append)
sc_list.Clear();
size_t initial_size = sc_list.GetSize();
@@ -580,7 +507,7 @@ ModuleList::FindSymbolsMatchingRegExAndType (const RegularExpression &regex,
SymbolContextList &sc_list,
bool append) const
{
- Mutex::Locker locker(m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
if (!append)
sc_list.Clear();
size_t initial_size = sc_list.GetSize();
@@ -596,7 +523,7 @@ ModuleList::FindModules (const ModuleSpec &module_spec, ModuleList& matching_mod
{
size_t existing_matches = matching_module_list.GetSize();
- Mutex::Locker locker(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)
{
@@ -614,7 +541,7 @@ ModuleList::FindModule (const Module *module_ptr) const
// Scope for "locker"
{
- Mutex::Locker locker(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)
@@ -627,7 +554,6 @@ ModuleList::FindModule (const Module *module_ptr) const
}
}
return module_sp;
-
}
ModuleSP
@@ -637,7 +563,7 @@ ModuleList::FindModule (const UUID &uuid) const
if (uuid.IsValid())
{
- Mutex::Locker locker(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)
@@ -652,11 +578,10 @@ ModuleList::FindModule (const UUID &uuid) const
return module_sp;
}
-
size_t
-ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool name_is_fully_qualified, size_t max_matches, TypeList& types) const
+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
{
- Mutex::Locker locker(m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
size_t total_matches = 0;
collection::const_iterator pos, end = m_modules.end();
@@ -668,7 +593,7 @@ ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool na
{
if (sc.module_sp.get() == (*pos).get())
{
- total_matches += (*pos)->FindTypes (sc, name, name_is_fully_qualified, max_matches, types);
+ total_matches += (*pos)->FindTypes (sc, name, name_is_fully_qualified, max_matches, searched_symbol_files, types);
if (total_matches >= max_matches)
break;
@@ -683,9 +608,9 @@ ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool na
{
// 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 != NULL).
+ // 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, types);
+ total_matches += (*pos)->FindTypes (world_sc, name, name_is_fully_qualified, max_matches, searched_symbol_files, types);
if (total_matches >= max_matches)
break;
@@ -698,7 +623,7 @@ ModuleList::FindTypes (const SymbolContext& sc, const ConstString &name, bool na
bool
ModuleList::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
{
- Mutex::Locker locker(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)
{
@@ -714,7 +639,7 @@ ModuleList::FindAddressesForLine (const lldb::TargetSP target_sp,
Function *function,
std::vector<Address> &output_local, std::vector<Address> &output_extern)
{
- Mutex::Locker locker(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)
{
@@ -726,7 +651,7 @@ ModuleSP
ModuleList::FindFirstModule (const ModuleSpec &module_spec) const
{
ModuleSP module_sp;
- Mutex::Locker locker(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)
{
@@ -743,21 +668,20 @@ ModuleList::GetSize() const
{
size_t size = 0;
{
- Mutex::Locker locker(m_modules_mutex);
+ 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";
+ // s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
+ // s.Indent();
+ // s << "ModuleList\n";
- Mutex::Locker locker(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)
{
@@ -768,9 +692,9 @@ ModuleList::Dump(Stream *s) const
void
ModuleList::LogUUIDAndPaths (Log *log, const char *prefix_cstr)
{
- if (log)
- {
- Mutex::Locker locker(m_modules_mutex);
+ 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)
{
@@ -789,7 +713,7 @@ ModuleList::LogUUIDAndPaths (Log *log, const char *prefix_cstr)
bool
ModuleList::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr) const
{
- Mutex::Locker locker(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)
{
@@ -814,7 +738,7 @@ ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t res
}
else
{
- Mutex::Locker locker(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)
{
@@ -830,14 +754,11 @@ ModuleList::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t res
}
uint32_t
-ModuleList::ResolveSymbolContextForFilePath
-(
- const char *file_path,
- uint32_t line,
- bool check_inlines,
- uint32_t resolve_scope,
- SymbolContextList& sc_list
-) const
+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);
@@ -846,7 +767,7 @@ ModuleList::ResolveSymbolContextForFilePath
uint32_t
ModuleList::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) const
{
- Mutex::Locker locker(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)
{
@@ -861,7 +782,7 @@ ModuleList::GetIndexForModule (const Module *module) const
{
if (module)
{
- Mutex::Locker locker(m_modules_mutex);
+ 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();
@@ -877,13 +798,13 @@ ModuleList::GetIndexForModule (const Module *module) const
static ModuleList &
GetSharedModuleList ()
{
- static ModuleList *g_shared_module_list = NULL;
+ 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 == NULL)
+ if (g_shared_module_list == nullptr)
g_shared_module_list = new ModuleList(); // <--- Intentional leak!!!
});
return *g_shared_module_list;
@@ -895,7 +816,7 @@ ModuleList::ModuleIsInCache (const Module *module_ptr)
if (module_ptr)
{
ModuleList &shared_module_list = GetSharedModuleList ();
- return shared_module_list.FindModule (module_ptr).get() != NULL;
+ return shared_module_list.FindModule(module_ptr).get() != nullptr;
}
return false;
}
@@ -913,18 +834,15 @@ ModuleList::RemoveOrphanSharedModules (bool 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::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 ();
- Mutex::Locker locker(shared_module_list.m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> guard(shared_module_list.m_modules_mutex);
char path[PATH_MAX];
Error error;
@@ -943,7 +861,7 @@ ModuleList::GetSharedModule
// 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 == false)
+ if (!always_create)
{
ModuleList matching_module_list;
const size_t num_matching_modules = shared_module_list.FindModules (module_spec, matching_module_list);
@@ -956,11 +874,11 @@ ModuleList::GetSharedModule
// Make sure the file for the module hasn't been modified
if (module_sp->FileHasChanged())
{
- if (old_module_sp_ptr && !old_module_sp_ptr->get())
+ 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)
+ if (log != nullptr)
log->Printf("module changed: %p, removing from global module list",
static_cast<void*>(module_sp.get()));
@@ -1104,7 +1022,6 @@ ModuleList::GetSharedModule
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.
@@ -1119,7 +1036,7 @@ ModuleList::GetSharedModule
// 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() == NULL)
+ if (platform_module_spec.GetUUIDPtr() == nullptr)
{
TimeValue file_spec_mod_time(located_binary_modulespec.GetFileSpec().GetModificationTime());
if (file_spec_mod_time.IsValid())
@@ -1135,7 +1052,7 @@ ModuleList::GetSharedModule
}
}
- if (module_sp.get() == NULL)
+ 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
@@ -1204,7 +1121,7 @@ ModuleList::LoadScriptingResourcesInTarget (Target *target,
{
if (!target)
return false;
- Mutex::Locker locker(m_modules_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
for (auto module : m_modules)
{
Error error;
@@ -1225,13 +1142,13 @@ ModuleList::LoadScriptingResourcesInTarget (Target *target,
}
}
}
- return errors.size() == 0;
+ return errors.empty();
}
void
ModuleList::ForEach (std::function <bool (const ModuleSP &module_sp)> const &callback) const
{
- Mutex::Locker locker(m_modules_mutex);
+ 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
diff --git a/source/Core/Opcode.cpp b/source/Core/Opcode.cpp
index 89eea2624cec..e36727eaa313 100644
--- a/source/Core/Opcode.cpp
+++ b/source/Core/Opcode.cpp
@@ -13,6 +13,7 @@
// C++ Includes
// Other libraries and framework includes
#include "llvm/ADT/Triple.h"
+
// Project includes
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/DataBufferHeap.h"
@@ -20,11 +21,9 @@
#include "lldb/Core/Stream.h"
#include "lldb/Host/Endian.h"
-
using namespace lldb;
using namespace lldb_private;
-
int
Opcode::Dump (Stream *s, uint32_t min_byte_width)
{
@@ -50,13 +49,11 @@ Opcode::Dump (Stream *s, uint32_t min_byte_width)
break;
case Opcode::eTypeBytes:
+ for (uint32_t i = 0; i < m_data.inst.length; ++i)
{
- 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]);
- }
+ if (i > 0)
+ bytes_written += s->PutChar (' ');
+ bytes_written += s->Printf ("%2.2x", m_data.inst.bytes[i]);
}
break;
}
@@ -94,7 +91,7 @@ Opcode::GetData (DataExtractor &data) const
{
uint32_t byte_size = GetByteSize ();
uint8_t swap_buf[8];
- const void *buf = NULL;
+ const void *buf = nullptr;
if (byte_size > 0)
{
@@ -148,7 +145,7 @@ Opcode::GetData (DataExtractor &data) const
}
}
}
- if (buf)
+ if (buf != nullptr)
{
DataBufferSP buffer_sp;
@@ -160,6 +157,3 @@ Opcode::GetData (DataExtractor &data) const
data.Clear();
return 0;
}
-
-
-
diff --git a/source/Core/PluginManager.cpp b/source/Core/PluginManager.cpp
index a90b57678b7a..500b08b73e9e 100644
--- a/source/Core/PluginManager.cpp
+++ b/source/Core/PluginManager.cpp
@@ -9,22 +9,25 @@
#include "lldb/Core/PluginManager.h"
-#include <limits.h>
-
+// C Includes
+// C++ Includes
+#include <climits>
+#include <mutex>
#include <string>
#include <vector>
+// Other libraries and framework includes
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/DynamicLibrary.h"
+
+// Project includes
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Error.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Host/Mutex.h"
#include "lldb/Interpreter/OptionValueProperties.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/DynamicLibrary.h"
-
using namespace lldb;
using namespace lldb_private;
@@ -35,9 +38,8 @@ enum PluginAction
ePluginGetInstanceAtIndex
};
-
-typedef bool (*PluginInitCallback) (void);
-typedef void (*PluginTermCallback) (void);
+typedef bool (*PluginInitCallback)();
+typedef void (*PluginTermCallback)();
struct PluginInfo
{
@@ -53,10 +55,10 @@ struct PluginInfo
typedef std::map<FileSpec, PluginInfo> PluginTerminateMap;
-static Mutex &
-GetPluginMapMutex ()
+static std::recursive_mutex &
+GetPluginMapMutex()
{
- static Mutex g_plugin_map_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_plugin_map_mutex;
return g_plugin_map_mutex;
}
@@ -70,7 +72,7 @@ GetPluginMap ()
static bool
PluginIsLoaded (const FileSpec &plugin_file_spec)
{
- Mutex::Locker locker (GetPluginMapMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetPluginMapMutex());
PluginTerminateMap &plugin_map = GetPluginMap ();
return plugin_map.find (plugin_file_spec) != plugin_map.end();
}
@@ -78,7 +80,7 @@ PluginIsLoaded (const FileSpec &plugin_file_spec)
static void
SetPluginInfo (const FileSpec &plugin_file_spec, const PluginInfo &plugin_info)
{
- Mutex::Locker locker (GetPluginMapMutex ());
+ 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;
@@ -92,12 +94,9 @@ CastToFPtr (void *VPtr)
}
static FileSpec::EnumerateDirectoryResult
-LoadPluginCallback
-(
- void *baton,
- FileSpec::FileType file_type,
- const FileSpec &file_spec
-)
+LoadPluginCallback(void *baton,
+ FileSpec::FileType file_type,
+ const FileSpec &file_spec)
{
// PluginManager *plugin_manager = (PluginManager *)baton;
Error error;
@@ -134,7 +133,7 @@ LoadPluginCallback
if (success)
{
- // It is ok for the "LLDBPluginTerminate" symbol to be NULL
+ // It is ok for the "LLDBPluginTerminate" symbol to be nullptr
plugin_info.plugin_term_callback =
CastToFPtr<PluginTermCallback>(plugin_info.library.getAddressOfSymbol("LLDBPluginTerminate"));
}
@@ -170,7 +169,6 @@ LoadPluginCallback
return FileSpec::eEnumerateDirectoryResultNext;
}
-
void
PluginManager::Initialize ()
{
@@ -184,12 +182,12 @@ PluginManager::Initialize ()
{
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
{
- FileSpec::EnumerateDirectory (dir_path,
- find_directories,
- find_files,
- find_other,
- LoadPluginCallback,
- NULL);
+ FileSpec::EnumerateDirectory(dir_path,
+ find_directories,
+ find_files,
+ find_other,
+ LoadPluginCallback,
+ nullptr);
}
}
@@ -197,12 +195,12 @@ PluginManager::Initialize ()
{
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path)))
{
- FileSpec::EnumerateDirectory (dir_path,
- find_directories,
- find_files,
- find_other,
- LoadPluginCallback,
- NULL);
+ FileSpec::EnumerateDirectory(dir_path,
+ find_directories,
+ find_files,
+ find_other,
+ LoadPluginCallback,
+ nullptr);
}
}
#endif
@@ -211,14 +209,14 @@ PluginManager::Initialize ()
void
PluginManager::Terminate ()
{
- Mutex::Locker locker (GetPluginMapMutex ());
+ 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 NULL).
+ // is one (if the symbol was not nullptr).
if (pos->second.library.isValid())
{
if (pos->second.plugin_term_callback)
@@ -228,16 +226,14 @@ PluginManager::Terminate ()
plugin_map.clear();
}
-
#pragma mark ABI
-
struct ABIInstance
{
ABIInstance() :
name(),
description(),
- create_callback(NULL)
+ create_callback(nullptr)
{
}
@@ -248,10 +244,10 @@ struct ABIInstance
typedef std::vector<ABIInstance> ABIInstances;
-static Mutex &
-GetABIInstancesMutex ()
+static std::recursive_mutex &
+GetABIInstancesMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -263,12 +259,9 @@ GetABIInstances ()
}
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- ABICreateInstance create_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ ABICreateInstance create_callback)
{
if (create_callback)
{
@@ -278,7 +271,7 @@ PluginManager::RegisterPlugin
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- Mutex::Locker locker (GetABIInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
GetABIInstances ().push_back (instance);
return true;
}
@@ -290,7 +283,7 @@ PluginManager::UnregisterPlugin (ABICreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetABIInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
ABIInstances &instances = GetABIInstances ();
ABIInstances::iterator pos, end = instances.end();
@@ -309,11 +302,11 @@ PluginManager::UnregisterPlugin (ABICreateInstance create_callback)
ABICreateInstance
PluginManager::GetABICreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetABIInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
ABIInstances &instances = GetABIInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
ABICreateInstance
@@ -321,7 +314,7 @@ PluginManager::GetABICreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetABIInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetABIInstancesMutex());
ABIInstances &instances = GetABIInstances ();
ABIInstances::iterator pos, end = instances.end();
@@ -331,19 +324,17 @@ PluginManager::GetABICreateCallbackForPluginName (const ConstString &name)
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
-
#pragma mark Disassembler
-
struct DisassemblerInstance
{
DisassemblerInstance() :
name(),
description(),
- create_callback(NULL)
+ create_callback(nullptr)
{
}
@@ -354,10 +345,10 @@ struct DisassemblerInstance
typedef std::vector<DisassemblerInstance> DisassemblerInstances;
-static Mutex &
-GetDisassemblerMutex ()
+static std::recursive_mutex &
+GetDisassemblerMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -369,12 +360,9 @@ GetDisassemblerInstances ()
}
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- DisassemblerCreateInstance create_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ DisassemblerCreateInstance create_callback)
{
if (create_callback)
{
@@ -384,7 +372,7 @@ PluginManager::RegisterPlugin
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- Mutex::Locker locker (GetDisassemblerMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
GetDisassemblerInstances ().push_back (instance);
return true;
}
@@ -396,7 +384,7 @@ PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetDisassemblerMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
DisassemblerInstances &instances = GetDisassemblerInstances ();
DisassemblerInstances::iterator pos, end = instances.end();
@@ -415,11 +403,11 @@ PluginManager::UnregisterPlugin (DisassemblerCreateInstance create_callback)
DisassemblerCreateInstance
PluginManager::GetDisassemblerCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetDisassemblerMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
DisassemblerInstances &instances = GetDisassemblerInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
DisassemblerCreateInstance
@@ -427,7 +415,7 @@ PluginManager::GetDisassemblerCreateCallbackForPluginName (const ConstString &na
{
if (name)
{
- Mutex::Locker locker (GetDisassemblerMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetDisassemblerMutex());
DisassemblerInstances &instances = GetDisassemblerInstances ();
DisassemblerInstances::iterator pos, end = instances.end();
@@ -437,21 +425,18 @@ PluginManager::GetDisassemblerCreateCallbackForPluginName (const ConstString &na
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
-
-
#pragma mark DynamicLoader
-
struct DynamicLoaderInstance
{
DynamicLoaderInstance() :
name(),
description(),
- create_callback(NULL),
- debugger_init_callback (NULL)
+ create_callback(nullptr),
+ debugger_init_callback(nullptr)
{
}
@@ -463,11 +448,10 @@ struct DynamicLoaderInstance
typedef std::vector<DynamicLoaderInstance> DynamicLoaderInstances;
-
-static Mutex &
-GetDynamicLoaderMutex ()
+static std::recursive_mutex &
+GetDynamicLoaderMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -478,15 +462,11 @@ GetDynamicLoaderInstances ()
return g_instances;
}
-
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- DynamicLoaderCreateInstance create_callback,
- DebuggerInitializeCallback debugger_init_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ DynamicLoaderCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback)
{
if (create_callback)
{
@@ -497,7 +477,7 @@ PluginManager::RegisterPlugin
instance.description = description;
instance.create_callback = create_callback;
instance.debugger_init_callback = debugger_init_callback;
- Mutex::Locker locker (GetDynamicLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
GetDynamicLoaderInstances ().push_back (instance);
}
return false;
@@ -508,7 +488,7 @@ PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetDynamicLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
DynamicLoaderInstances::iterator pos, end = instances.end();
@@ -527,11 +507,11 @@ PluginManager::UnregisterPlugin (DynamicLoaderCreateInstance create_callback)
DynamicLoaderCreateInstance
PluginManager::GetDynamicLoaderCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetDynamicLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
DynamicLoaderCreateInstance
@@ -539,7 +519,7 @@ PluginManager::GetDynamicLoaderCreateCallbackForPluginName (const ConstString &n
{
if (name)
{
- Mutex::Locker locker (GetDynamicLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
DynamicLoaderInstances::iterator pos, end = instances.end();
@@ -549,19 +529,18 @@ PluginManager::GetDynamicLoaderCreateCallbackForPluginName (const ConstString &n
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark JITLoader
-
struct JITLoaderInstance
{
JITLoaderInstance() :
name(),
description(),
- create_callback(NULL),
- debugger_init_callback (NULL)
+ create_callback(nullptr),
+ debugger_init_callback(nullptr)
{
}
@@ -573,11 +552,10 @@ struct JITLoaderInstance
typedef std::vector<JITLoaderInstance> JITLoaderInstances;
-
-static Mutex &
-GetJITLoaderMutex ()
+static std::recursive_mutex &
+GetJITLoaderMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -588,15 +566,11 @@ GetJITLoaderInstances ()
return g_instances;
}
-
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- JITLoaderCreateInstance create_callback,
- DebuggerInitializeCallback debugger_init_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ JITLoaderCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback)
{
if (create_callback)
{
@@ -607,7 +581,7 @@ PluginManager::RegisterPlugin
instance.description = description;
instance.create_callback = create_callback;
instance.debugger_init_callback = debugger_init_callback;
- Mutex::Locker locker (GetJITLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
GetJITLoaderInstances ().push_back (instance);
}
return false;
@@ -618,7 +592,7 @@ PluginManager::UnregisterPlugin (JITLoaderCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetJITLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
JITLoaderInstances &instances = GetJITLoaderInstances ();
JITLoaderInstances::iterator pos, end = instances.end();
@@ -637,11 +611,11 @@ PluginManager::UnregisterPlugin (JITLoaderCreateInstance create_callback)
JITLoaderCreateInstance
PluginManager::GetJITLoaderCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetJITLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
JITLoaderInstances &instances = GetJITLoaderInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
JITLoaderCreateInstance
@@ -649,7 +623,7 @@ PluginManager::GetJITLoaderCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetJITLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
JITLoaderInstances &instances = GetJITLoaderInstances ();
JITLoaderInstances::iterator pos, end = instances.end();
@@ -659,18 +633,17 @@ PluginManager::GetJITLoaderCreateCallbackForPluginName (const ConstString &name)
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark EmulateInstruction
-
struct EmulateInstructionInstance
{
EmulateInstructionInstance() :
- name(),
- description(),
- create_callback(NULL)
+ name(),
+ description(),
+ create_callback(nullptr)
{
}
@@ -681,10 +654,10 @@ struct EmulateInstructionInstance
typedef std::vector<EmulateInstructionInstance> EmulateInstructionInstances;
-static Mutex &
-GetEmulateInstructionMutex ()
+static std::recursive_mutex &
+GetEmulateInstructionMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -695,14 +668,10 @@ GetEmulateInstructionInstances ()
return g_instances;
}
-
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- EmulateInstructionCreateInstance create_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ EmulateInstructionCreateInstance create_callback)
{
if (create_callback)
{
@@ -712,7 +681,7 @@ PluginManager::RegisterPlugin
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- Mutex::Locker locker (GetEmulateInstructionMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
GetEmulateInstructionInstances ().push_back (instance);
}
return false;
@@ -723,7 +692,7 @@ PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callbac
{
if (create_callback)
{
- Mutex::Locker locker (GetEmulateInstructionMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
EmulateInstructionInstances::iterator pos, end = instances.end();
@@ -742,11 +711,11 @@ PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callbac
EmulateInstructionCreateInstance
PluginManager::GetEmulateInstructionCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetEmulateInstructionMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
EmulateInstructionCreateInstance
@@ -754,7 +723,7 @@ PluginManager::GetEmulateInstructionCreateCallbackForPluginName (const ConstStri
{
if (name)
{
- Mutex::Locker locker (GetEmulateInstructionMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetEmulateInstructionMutex());
EmulateInstructionInstances &instances = GetEmulateInstructionInstances ();
EmulateInstructionInstances::iterator pos, end = instances.end();
@@ -764,10 +733,10 @@ PluginManager::GetEmulateInstructionCreateCallbackForPluginName (const ConstStri
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
-#pragma mark OperatingSystem
+#pragma mark OperatingSystem
struct OperatingSystemInstance
{
@@ -787,10 +756,10 @@ struct OperatingSystemInstance
typedef std::vector<OperatingSystemInstance> OperatingSystemInstances;
-static Mutex &
-GetOperatingSystemMutex ()
+static std::recursive_mutex &
+GetOperatingSystemMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -815,7 +784,7 @@ PluginManager::RegisterPlugin(const ConstString &name, const char *description,
instance.description = description;
instance.create_callback = create_callback;
instance.debugger_init_callback = debugger_init_callback;
- Mutex::Locker locker (GetOperatingSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
GetOperatingSystemInstances ().push_back (instance);
}
return false;
@@ -826,7 +795,7 @@ PluginManager::UnregisterPlugin (OperatingSystemCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetOperatingSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
OperatingSystemInstances &instances = GetOperatingSystemInstances ();
OperatingSystemInstances::iterator pos, end = instances.end();
@@ -845,11 +814,11 @@ PluginManager::UnregisterPlugin (OperatingSystemCreateInstance create_callback)
OperatingSystemCreateInstance
PluginManager::GetOperatingSystemCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetOperatingSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
OperatingSystemInstances &instances = GetOperatingSystemInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
OperatingSystemCreateInstance
@@ -857,7 +826,7 @@ PluginManager::GetOperatingSystemCreateCallbackForPluginName (const ConstString
{
if (name)
{
- Mutex::Locker locker (GetOperatingSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
OperatingSystemInstances &instances = GetOperatingSystemInstances ();
OperatingSystemInstances::iterator pos, end = instances.end();
@@ -867,19 +836,17 @@ PluginManager::GetOperatingSystemCreateCallbackForPluginName (const ConstString
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
-
#pragma mark Language
-
struct LanguageInstance
{
LanguageInstance() :
name(),
description(),
- create_callback(NULL)
+ create_callback(nullptr)
{
}
@@ -890,10 +857,10 @@ struct LanguageInstance
typedef std::vector<LanguageInstance> LanguageInstances;
-static Mutex &
-GetLanguageMutex ()
+static std::recursive_mutex &
+GetLanguageMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -905,12 +872,9 @@ GetLanguageInstances ()
}
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- LanguageCreateInstance create_callback
- )
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ LanguageCreateInstance create_callback)
{
if (create_callback)
{
@@ -920,7 +884,7 @@ PluginManager::RegisterPlugin
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- Mutex::Locker locker (GetLanguageMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
GetLanguageInstances ().push_back (instance);
}
return false;
@@ -931,7 +895,7 @@ PluginManager::UnregisterPlugin (LanguageCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetLanguageMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
LanguageInstances &instances = GetLanguageInstances ();
LanguageInstances::iterator pos, end = instances.end();
@@ -950,11 +914,11 @@ PluginManager::UnregisterPlugin (LanguageCreateInstance create_callback)
LanguageCreateInstance
PluginManager::GetLanguageCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetLanguageMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
LanguageInstances &instances = GetLanguageInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
LanguageCreateInstance
@@ -962,7 +926,7 @@ PluginManager::GetLanguageCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetLanguageMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageMutex());
LanguageInstances &instances = GetLanguageInstances ();
LanguageInstances::iterator pos, end = instances.end();
@@ -972,19 +936,17 @@ PluginManager::GetLanguageCreateCallbackForPluginName (const ConstString &name)
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
-
#pragma mark LanguageRuntime
-
struct LanguageRuntimeInstance
{
LanguageRuntimeInstance() :
name(),
description(),
- create_callback(NULL)
+ create_callback(nullptr)
{
}
@@ -996,10 +958,10 @@ struct LanguageRuntimeInstance
typedef std::vector<LanguageRuntimeInstance> LanguageRuntimeInstances;
-static Mutex &
-GetLanguageRuntimeMutex ()
+static std::recursive_mutex &
+GetLanguageRuntimeMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -1011,13 +973,10 @@ GetLanguageRuntimeInstances ()
}
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- LanguageRuntimeCreateInstance create_callback,
- LanguageRuntimeGetCommandObject command_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ LanguageRuntimeCreateInstance create_callback,
+ LanguageRuntimeGetCommandObject command_callback)
{
if (create_callback)
{
@@ -1028,7 +987,7 @@ PluginManager::RegisterPlugin
instance.description = description;
instance.create_callback = create_callback;
instance.command_callback = command_callback;
- Mutex::Locker locker (GetLanguageRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
GetLanguageRuntimeInstances ().push_back (instance);
}
return false;
@@ -1039,7 +998,7 @@ PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetLanguageRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
LanguageRuntimeInstances::iterator pos, end = instances.end();
@@ -1058,21 +1017,21 @@ PluginManager::UnregisterPlugin (LanguageRuntimeCreateInstance create_callback)
LanguageRuntimeCreateInstance
PluginManager::GetLanguageRuntimeCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetLanguageRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
LanguageRuntimeGetCommandObject
PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetLanguageRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
if (idx < instances.size())
return instances[idx].command_callback;
- return NULL;
+ return nullptr;
}
LanguageRuntimeCreateInstance
@@ -1080,7 +1039,7 @@ PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const ConstString
{
if (name)
{
- Mutex::Locker locker (GetLanguageRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetLanguageRuntimeMutex());
LanguageRuntimeInstances &instances = GetLanguageRuntimeInstances ();
LanguageRuntimeInstances::iterator pos, end = instances.end();
@@ -1090,18 +1049,17 @@ PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const ConstString
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark SystemRuntime
-
struct SystemRuntimeInstance
{
SystemRuntimeInstance() :
name(),
description(),
- create_callback(NULL)
+ create_callback(nullptr)
{
}
@@ -1112,10 +1070,10 @@ struct SystemRuntimeInstance
typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances;
-static Mutex &
-GetSystemRuntimeMutex ()
+static std::recursive_mutex &
+GetSystemRuntimeMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -1127,12 +1085,9 @@ GetSystemRuntimeInstances ()
}
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- SystemRuntimeCreateInstance create_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ SystemRuntimeCreateInstance create_callback)
{
if (create_callback)
{
@@ -1142,7 +1097,7 @@ PluginManager::RegisterPlugin
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- Mutex::Locker locker (GetSystemRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
GetSystemRuntimeInstances ().push_back (instance);
}
return false;
@@ -1153,7 +1108,7 @@ PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetSystemRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
SystemRuntimeInstances::iterator pos, end = instances.end();
@@ -1172,11 +1127,11 @@ PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback)
SystemRuntimeCreateInstance
PluginManager::GetSystemRuntimeCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetSystemRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
SystemRuntimeCreateInstance
@@ -1184,7 +1139,7 @@ PluginManager::GetSystemRuntimeCreateCallbackForPluginName (const ConstString &n
{
if (name)
{
- Mutex::Locker locker (GetSystemRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSystemRuntimeMutex());
SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
SystemRuntimeInstances::iterator pos, end = instances.end();
@@ -1194,10 +1149,9 @@ PluginManager::GetSystemRuntimeCreateCallbackForPluginName (const ConstString &n
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
-
#pragma mark ObjectFile
struct ObjectFileInstance
@@ -1205,10 +1159,10 @@ struct ObjectFileInstance
ObjectFileInstance() :
name(),
description(),
- create_callback(NULL),
- create_memory_callback (NULL),
- get_module_specifications (NULL),
- save_core (NULL)
+ create_callback(nullptr),
+ create_memory_callback(nullptr),
+ get_module_specifications(nullptr),
+ save_core(nullptr)
{
}
@@ -1222,10 +1176,10 @@ struct ObjectFileInstance
typedef std::vector<ObjectFileInstance> ObjectFileInstances;
-static Mutex &
-GetObjectFileMutex ()
+static std::recursive_mutex &
+GetObjectFileMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -1236,7 +1190,6 @@ GetObjectFileInstances ()
return g_instances;
}
-
bool
PluginManager::RegisterPlugin (const ConstString &name,
const char *description,
@@ -1256,7 +1209,7 @@ PluginManager::RegisterPlugin (const ConstString &name,
instance.create_memory_callback = create_memory_callback;
instance.save_core = save_core;
instance.get_module_specifications = get_module_specifications;
- Mutex::Locker locker (GetObjectFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
GetObjectFileInstances ().push_back (instance);
}
return false;
@@ -1267,7 +1220,7 @@ PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetObjectFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
ObjectFileInstances &instances = GetObjectFileInstances ();
ObjectFileInstances::iterator pos, end = instances.end();
@@ -1286,32 +1239,31 @@ PluginManager::UnregisterPlugin (ObjectFileCreateInstance create_callback)
ObjectFileCreateInstance
PluginManager::GetObjectFileCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetObjectFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
ObjectFileInstances &instances = GetObjectFileInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
-
ObjectFileCreateMemoryInstance
PluginManager::GetObjectFileCreateMemoryCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetObjectFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
ObjectFileInstances &instances = GetObjectFileInstances ();
if (idx < instances.size())
return instances[idx].create_memory_callback;
- return NULL;
+ return nullptr;
}
ObjectFileGetModuleSpecifications
PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetObjectFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
ObjectFileInstances &instances = GetObjectFileInstances ();
if (idx < instances.size())
return instances[idx].get_module_specifications;
- return NULL;
+ return nullptr;
}
ObjectFileCreateInstance
@@ -1319,7 +1271,7 @@ PluginManager::GetObjectFileCreateCallbackForPluginName (const ConstString &name
{
if (name)
{
- Mutex::Locker locker (GetObjectFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
ObjectFileInstances &instances = GetObjectFileInstances ();
ObjectFileInstances::iterator pos, end = instances.end();
@@ -1329,16 +1281,15 @@ PluginManager::GetObjectFileCreateCallbackForPluginName (const ConstString &name
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
-
ObjectFileCreateMemoryInstance
PluginManager::GetObjectFileCreateMemoryCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetObjectFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
ObjectFileInstances &instances = GetObjectFileInstances ();
ObjectFileInstances::iterator pos, end = instances.end();
@@ -1348,14 +1299,14 @@ PluginManager::GetObjectFileCreateMemoryCallbackForPluginName (const ConstString
return pos->create_memory_callback;
}
}
- return NULL;
+ return nullptr;
}
Error
PluginManager::SaveCore (const lldb::ProcessSP &process_sp, const FileSpec &outfile)
{
Error error;
- Mutex::Locker locker (GetObjectFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectFileMutex());
ObjectFileInstances &instances = GetObjectFileInstances ();
ObjectFileInstances::iterator pos, end = instances.end();
@@ -1375,8 +1326,8 @@ struct ObjectContainerInstance
ObjectContainerInstance() :
name(),
description(),
- create_callback (NULL),
- get_module_specifications (NULL)
+ create_callback(nullptr),
+ get_module_specifications(nullptr)
{
}
@@ -1384,15 +1335,14 @@ struct ObjectContainerInstance
std::string description;
ObjectContainerCreateInstance create_callback;
ObjectFileGetModuleSpecifications get_module_specifications;
-
};
typedef std::vector<ObjectContainerInstance> ObjectContainerInstances;
-static Mutex &
-GetObjectContainerMutex ()
+static std::recursive_mutex &
+GetObjectContainerMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -1418,7 +1368,7 @@ PluginManager::RegisterPlugin (const ConstString &name,
instance.description = description;
instance.create_callback = create_callback;
instance.get_module_specifications = get_module_specifications;
- Mutex::Locker locker (GetObjectContainerMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
GetObjectContainerInstances ().push_back (instance);
}
return false;
@@ -1429,7 +1379,7 @@ PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetObjectContainerMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
ObjectContainerInstances &instances = GetObjectContainerInstances ();
ObjectContainerInstances::iterator pos, end = instances.end();
@@ -1448,11 +1398,11 @@ PluginManager::UnregisterPlugin (ObjectContainerCreateInstance create_callback)
ObjectContainerCreateInstance
PluginManager::GetObjectContainerCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetObjectContainerMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
ObjectContainerInstances &instances = GetObjectContainerInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
ObjectContainerCreateInstance
@@ -1460,7 +1410,7 @@ PluginManager::GetObjectContainerCreateCallbackForPluginName (const ConstString
{
if (name)
{
- Mutex::Locker locker (GetObjectContainerMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
ObjectContainerInstances &instances = GetObjectContainerInstances ();
ObjectContainerInstances::iterator pos, end = instances.end();
@@ -1470,17 +1420,17 @@ PluginManager::GetObjectContainerCreateCallbackForPluginName (const ConstString
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
ObjectFileGetModuleSpecifications
PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetObjectContainerMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetObjectContainerMutex());
ObjectContainerInstances &instances = GetObjectContainerInstances ();
if (idx < instances.size())
return instances[idx].get_module_specifications;
- return NULL;
+ return nullptr;
}
#pragma mark LogChannel
@@ -1490,7 +1440,7 @@ struct LogInstance
LogInstance() :
name(),
description(),
- create_callback(NULL)
+ create_callback(nullptr)
{
}
@@ -1501,10 +1451,10 @@ struct LogInstance
typedef std::vector<LogInstance> LogInstances;
-static Mutex &
-GetLogMutex ()
+static std::recursive_mutex &
+GetLogMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -1515,15 +1465,10 @@ GetLogInstances ()
return g_instances;
}
-
-
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- LogChannelCreateInstance create_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ LogChannelCreateInstance create_callback)
{
if (create_callback)
{
@@ -1533,7 +1478,7 @@ PluginManager::RegisterPlugin
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- Mutex::Locker locker (GetLogMutex ());
+ std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
GetLogInstances ().push_back (instance);
}
return false;
@@ -1544,7 +1489,7 @@ PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetLogMutex ());
+ std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
LogInstances &instances = GetLogInstances ();
LogInstances::iterator pos, end = instances.end();
@@ -1563,22 +1508,21 @@ PluginManager::UnregisterPlugin (LogChannelCreateInstance create_callback)
const char *
PluginManager::GetLogChannelCreateNameAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetLogMutex ());
+ std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
LogInstances &instances = GetLogInstances ();
if (idx < instances.size())
return instances[idx].name.GetCString();
- return NULL;
+ return nullptr;
}
-
LogChannelCreateInstance
PluginManager::GetLogChannelCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetLogMutex ());
+ std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
LogInstances &instances = GetLogInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
LogChannelCreateInstance
@@ -1586,7 +1530,7 @@ PluginManager::GetLogChannelCreateCallbackForPluginName (const ConstString &name
{
if (name)
{
- Mutex::Locker locker (GetLogMutex ());
+ std::lock_guard<std::recursive_mutex> gard(GetLogMutex());
LogInstances &instances = GetLogInstances ();
LogInstances::iterator pos, end = instances.end();
@@ -1596,7 +1540,7 @@ PluginManager::GetLogChannelCreateCallbackForPluginName (const ConstString &name
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark Platform
@@ -1606,8 +1550,8 @@ struct PlatformInstance
PlatformInstance() :
name(),
description(),
- create_callback(NULL),
- debugger_init_callback (NULL)
+ create_callback(nullptr),
+ debugger_init_callback(nullptr)
{
}
@@ -1619,10 +1563,10 @@ struct PlatformInstance
typedef std::vector<PlatformInstance> PlatformInstances;
-static Mutex &
-GetPlatformInstancesMutex ()
+static std::recursive_mutex &
+GetPlatformInstancesMutex()
{
- static Mutex g_platform_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_platform_instances_mutex;
return g_platform_instances_mutex;
}
@@ -1633,7 +1577,6 @@ GetPlatformInstances ()
return g_platform_instances;
}
-
bool
PluginManager::RegisterPlugin (const ConstString &name,
const char *description,
@@ -1642,8 +1585,8 @@ PluginManager::RegisterPlugin (const ConstString &name,
{
if (create_callback)
{
- Mutex::Locker locker (GetPlatformInstancesMutex ());
-
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
+
PlatformInstance instance;
assert ((bool)name);
instance.name = name;
@@ -1657,25 +1600,24 @@ PluginManager::RegisterPlugin (const ConstString &name,
return false;
}
-
const char *
PluginManager::GetPlatformPluginNameAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetPlatformInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
PlatformInstances &instances = GetPlatformInstances ();
if (idx < instances.size())
return instances[idx].name.GetCString();
- return NULL;
+ return nullptr;
}
const char *
PluginManager::GetPlatformPluginDescriptionAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetPlatformInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
PlatformInstances &instances = GetPlatformInstances ();
if (idx < instances.size())
return instances[idx].description.c_str();
- return NULL;
+ return nullptr;
}
bool
@@ -1683,7 +1625,7 @@ PluginManager::UnregisterPlugin (PlatformCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetPlatformInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
PlatformInstances &instances = GetPlatformInstances ();
PlatformInstances::iterator pos, end = instances.end();
@@ -1702,11 +1644,11 @@ PluginManager::UnregisterPlugin (PlatformCreateInstance create_callback)
PlatformCreateInstance
PluginManager::GetPlatformCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetPlatformInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
PlatformInstances &instances = GetPlatformInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
PlatformCreateInstance
@@ -1714,7 +1656,7 @@ PluginManager::GetPlatformCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetPlatformInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
PlatformInstances &instances = GetPlatformInstances ();
PlatformInstances::iterator pos, end = instances.end();
@@ -1724,7 +1666,7 @@ PluginManager::GetPlatformCreateCallbackForPluginName (const ConstString &name)
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
size_t
@@ -1732,7 +1674,7 @@ PluginManager::AutoCompletePlatformName (const char *name, StringList &matches)
{
if (name)
{
- Mutex::Locker locker (GetPlatformInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
PlatformInstances &instances = GetPlatformInstances ();
llvm::StringRef name_sref(name);
@@ -1746,6 +1688,7 @@ PluginManager::AutoCompletePlatformName (const char *name, StringList &matches)
}
return matches.GetSize();
}
+
#pragma mark Process
struct ProcessInstance
@@ -1753,8 +1696,8 @@ struct ProcessInstance
ProcessInstance() :
name(),
description(),
- create_callback(NULL),
- debugger_init_callback(NULL)
+ create_callback(nullptr),
+ debugger_init_callback(nullptr)
{
}
@@ -1766,10 +1709,10 @@ struct ProcessInstance
typedef std::vector<ProcessInstance> ProcessInstances;
-static Mutex &
-GetProcessMutex ()
+static std::recursive_mutex &
+GetProcessMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -1780,7 +1723,6 @@ GetProcessInstances ()
return g_instances;
}
-
bool
PluginManager::RegisterPlugin (const ConstString &name,
const char *description,
@@ -1796,7 +1738,7 @@ PluginManager::RegisterPlugin (const ConstString &name,
instance.description = description;
instance.create_callback = create_callback;
instance.debugger_init_callback = debugger_init_callback;
- Mutex::Locker locker (GetProcessMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
GetProcessInstances ().push_back (instance);
}
return false;
@@ -1805,21 +1747,21 @@ PluginManager::RegisterPlugin (const ConstString &name,
const char *
PluginManager::GetProcessPluginNameAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetProcessMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
ProcessInstances &instances = GetProcessInstances ();
if (idx < instances.size())
return instances[idx].name.GetCString();
- return NULL;
+ return nullptr;
}
const char *
PluginManager::GetProcessPluginDescriptionAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetProcessMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
ProcessInstances &instances = GetProcessInstances ();
if (idx < instances.size())
return instances[idx].description.c_str();
- return NULL;
+ return nullptr;
}
bool
@@ -1827,7 +1769,7 @@ PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetProcessMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
ProcessInstances &instances = GetProcessInstances ();
ProcessInstances::iterator pos, end = instances.end();
@@ -1846,20 +1788,19 @@ PluginManager::UnregisterPlugin (ProcessCreateInstance create_callback)
ProcessCreateInstance
PluginManager::GetProcessCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetProcessMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
ProcessInstances &instances = GetProcessInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
-
ProcessCreateInstance
PluginManager::GetProcessCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetProcessMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
ProcessInstances &instances = GetProcessInstances ();
ProcessInstances::iterator pos, end = instances.end();
@@ -1869,7 +1810,7 @@ PluginManager::GetProcessCreateCallbackForPluginName (const ConstString &name)
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark ScriptInterpreter
@@ -1880,7 +1821,7 @@ struct ScriptInterpreterInstance
: name()
, language(lldb::eScriptLanguageNone)
, description()
- , create_callback(NULL)
+ , create_callback(nullptr)
{
}
@@ -1892,10 +1833,10 @@ struct ScriptInterpreterInstance
typedef std::vector<ScriptInterpreterInstance> ScriptInterpreterInstances;
-static Mutex &
+static std::recursive_mutex &
GetScriptInterpreterMutex()
{
- static Mutex g_instances_mutex(Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -1919,7 +1860,7 @@ PluginManager::RegisterPlugin(const ConstString &name, const char *description,
instance.description = description;
instance.create_callback = create_callback;
instance.language = script_language;
- Mutex::Locker locker(GetScriptInterpreterMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
GetScriptInterpreterInstances().push_back(instance);
return false;
}
@@ -1929,7 +1870,7 @@ PluginManager::UnregisterPlugin(ScriptInterpreterCreateInstance create_callback)
{
if (!create_callback)
return false;
- Mutex::Locker locker(GetScriptInterpreterMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
ScriptInterpreterInstances::iterator pos, end = instances.end();
@@ -1947,7 +1888,7 @@ PluginManager::UnregisterPlugin(ScriptInterpreterCreateInstance create_callback)
ScriptInterpreterCreateInstance
PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx)
{
- Mutex::Locker locker(GetScriptInterpreterMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
if (idx < instances.size())
return instances[idx].create_callback;
@@ -1957,7 +1898,7 @@ PluginManager::GetScriptInterpreterCreateCallbackAtIndex(uint32_t idx)
lldb::ScriptInterpreterSP
PluginManager::GetScriptInterpreterForLanguage(lldb::ScriptLanguage script_lang, CommandInterpreter &interpreter)
{
- Mutex::Locker locker(GetScriptInterpreterMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetScriptInterpreterMutex());
ScriptInterpreterInstances &instances = GetScriptInterpreterInstances();
ScriptInterpreterInstances::iterator pos, end = instances.end();
@@ -1996,10 +1937,10 @@ struct SymbolFileInstance
typedef std::vector<SymbolFileInstance> SymbolFileInstances;
-static Mutex &
-GetSymbolFileMutex ()
+static std::recursive_mutex &
+GetSymbolFileMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -2010,15 +1951,11 @@ GetSymbolFileInstances ()
return g_instances;
}
-
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- SymbolFileCreateInstance create_callback,
- DebuggerInitializeCallback debugger_init_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ SymbolFileCreateInstance create_callback,
+ DebuggerInitializeCallback debugger_init_callback)
{
if (create_callback)
{
@@ -2029,7 +1966,7 @@ PluginManager::RegisterPlugin
instance.description = description;
instance.create_callback = create_callback;
instance.debugger_init_callback = debugger_init_callback;
- Mutex::Locker locker (GetSymbolFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
GetSymbolFileInstances ().push_back (instance);
}
return false;
@@ -2040,7 +1977,7 @@ PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetSymbolFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
SymbolFileInstances &instances = GetSymbolFileInstances ();
SymbolFileInstances::iterator pos, end = instances.end();
@@ -2059,11 +1996,11 @@ PluginManager::UnregisterPlugin (SymbolFileCreateInstance create_callback)
SymbolFileCreateInstance
PluginManager::GetSymbolFileCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetSymbolFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
SymbolFileInstances &instances = GetSymbolFileInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
SymbolFileCreateInstance
@@ -2071,7 +2008,7 @@ PluginManager::GetSymbolFileCreateCallbackForPluginName (const ConstString &name
{
if (name)
{
- Mutex::Locker locker (GetSymbolFileMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
SymbolFileInstances &instances = GetSymbolFileInstances ();
SymbolFileInstances::iterator pos, end = instances.end();
@@ -2081,11 +2018,9 @@ PluginManager::GetSymbolFileCreateCallbackForPluginName (const ConstString &name
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
-
-
#pragma mark SymbolVendor
struct SymbolVendorInstance
@@ -2093,7 +2028,7 @@ struct SymbolVendorInstance
SymbolVendorInstance() :
name(),
description(),
- create_callback(NULL)
+ create_callback(nullptr)
{
}
@@ -2104,10 +2039,10 @@ struct SymbolVendorInstance
typedef std::vector<SymbolVendorInstance> SymbolVendorInstances;
-static Mutex &
-GetSymbolVendorMutex ()
+static std::recursive_mutex &
+GetSymbolVendorMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -2119,12 +2054,9 @@ GetSymbolVendorInstances ()
}
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- SymbolVendorCreateInstance create_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ SymbolVendorCreateInstance create_callback)
{
if (create_callback)
{
@@ -2134,7 +2066,7 @@ PluginManager::RegisterPlugin
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- Mutex::Locker locker (GetSymbolVendorMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
GetSymbolVendorInstances ().push_back (instance);
}
return false;
@@ -2145,7 +2077,7 @@ PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetSymbolVendorMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
SymbolVendorInstances &instances = GetSymbolVendorInstances ();
SymbolVendorInstances::iterator pos, end = instances.end();
@@ -2164,20 +2096,19 @@ PluginManager::UnregisterPlugin (SymbolVendorCreateInstance create_callback)
SymbolVendorCreateInstance
PluginManager::GetSymbolVendorCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetSymbolVendorMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
SymbolVendorInstances &instances = GetSymbolVendorInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
-
SymbolVendorCreateInstance
PluginManager::GetSymbolVendorCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetSymbolVendorMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolVendorMutex());
SymbolVendorInstances &instances = GetSymbolVendorInstances ();
SymbolVendorInstances::iterator pos, end = instances.end();
@@ -2187,10 +2118,9 @@ PluginManager::GetSymbolVendorCreateCallbackForPluginName (const ConstString &na
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
-
#pragma mark UnwindAssembly
struct UnwindAssemblyInstance
@@ -2198,7 +2128,7 @@ struct UnwindAssemblyInstance
UnwindAssemblyInstance() :
name(),
description(),
- create_callback(NULL)
+ create_callback(nullptr)
{
}
@@ -2209,10 +2139,10 @@ struct UnwindAssemblyInstance
typedef std::vector<UnwindAssemblyInstance> UnwindAssemblyInstances;
-static Mutex &
-GetUnwindAssemblyMutex ()
+static std::recursive_mutex &
+GetUnwindAssemblyMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -2224,12 +2154,9 @@ GetUnwindAssemblyInstances ()
}
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- UnwindAssemblyCreateInstance create_callback
-)
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ UnwindAssemblyCreateInstance create_callback)
{
if (create_callback)
{
@@ -2239,7 +2166,7 @@ PluginManager::RegisterPlugin
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- Mutex::Locker locker (GetUnwindAssemblyMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
GetUnwindAssemblyInstances ().push_back (instance);
}
return false;
@@ -2250,7 +2177,7 @@ PluginManager::UnregisterPlugin (UnwindAssemblyCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetUnwindAssemblyMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
UnwindAssemblyInstances::iterator pos, end = instances.end();
@@ -2269,20 +2196,19 @@ PluginManager::UnregisterPlugin (UnwindAssemblyCreateInstance create_callback)
UnwindAssemblyCreateInstance
PluginManager::GetUnwindAssemblyCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetUnwindAssemblyMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
-
UnwindAssemblyCreateInstance
PluginManager::GetUnwindAssemblyCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetUnwindAssemblyMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetUnwindAssemblyMutex());
UnwindAssemblyInstances &instances = GetUnwindAssemblyInstances ();
UnwindAssemblyInstances::iterator pos, end = instances.end();
@@ -2292,7 +2218,7 @@ PluginManager::GetUnwindAssemblyCreateCallbackForPluginName (const ConstString &
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark MemoryHistory
@@ -2300,9 +2226,9 @@ PluginManager::GetUnwindAssemblyCreateCallbackForPluginName (const ConstString &
struct MemoryHistoryInstance
{
MemoryHistoryInstance() :
- name(),
- description(),
- create_callback(NULL)
+ name(),
+ description(),
+ create_callback(nullptr)
{
}
@@ -2313,10 +2239,10 @@ struct MemoryHistoryInstance
typedef std::vector<MemoryHistoryInstance> MemoryHistoryInstances;
-static Mutex &
-GetMemoryHistoryMutex ()
+static std::recursive_mutex &
+GetMemoryHistoryMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -2328,12 +2254,9 @@ GetMemoryHistoryInstances ()
}
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- MemoryHistoryCreateInstance create_callback
- )
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ MemoryHistoryCreateInstance create_callback)
{
if (create_callback)
{
@@ -2343,7 +2266,7 @@ PluginManager::RegisterPlugin
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- Mutex::Locker locker (GetMemoryHistoryMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
GetMemoryHistoryInstances ().push_back (instance);
}
return false;
@@ -2354,7 +2277,7 @@ PluginManager::UnregisterPlugin (MemoryHistoryCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetMemoryHistoryMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
MemoryHistoryInstances &instances = GetMemoryHistoryInstances ();
MemoryHistoryInstances::iterator pos, end = instances.end();
@@ -2373,20 +2296,19 @@ PluginManager::UnregisterPlugin (MemoryHistoryCreateInstance create_callback)
MemoryHistoryCreateInstance
PluginManager::GetMemoryHistoryCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetMemoryHistoryMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
MemoryHistoryInstances &instances = GetMemoryHistoryInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
-
MemoryHistoryCreateInstance
PluginManager::GetMemoryHistoryCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetMemoryHistoryMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetMemoryHistoryMutex());
MemoryHistoryInstances &instances = GetMemoryHistoryInstances ();
MemoryHistoryInstances::iterator pos, end = instances.end();
@@ -2396,7 +2318,7 @@ PluginManager::GetMemoryHistoryCreateCallbackForPluginName (const ConstString &n
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark InstrumentationRuntime
@@ -2404,9 +2326,9 @@ PluginManager::GetMemoryHistoryCreateCallbackForPluginName (const ConstString &n
struct InstrumentationRuntimeInstance
{
InstrumentationRuntimeInstance() :
- name(),
- description(),
- create_callback(NULL)
+ name(),
+ description(),
+ create_callback(nullptr)
{
}
@@ -2418,10 +2340,10 @@ struct InstrumentationRuntimeInstance
typedef std::vector<InstrumentationRuntimeInstance> InstrumentationRuntimeInstances;
-static Mutex &
-GetInstrumentationRuntimeMutex ()
+static std::recursive_mutex &
+GetInstrumentationRuntimeMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -2433,13 +2355,10 @@ GetInstrumentationRuntimeInstances ()
}
bool
-PluginManager::RegisterPlugin
-(
- const ConstString &name,
- const char *description,
- InstrumentationRuntimeCreateInstance create_callback,
- InstrumentationRuntimeGetType get_type_callback
- )
+PluginManager::RegisterPlugin(const ConstString &name,
+ const char *description,
+ InstrumentationRuntimeCreateInstance create_callback,
+ InstrumentationRuntimeGetType get_type_callback)
{
if (create_callback)
{
@@ -2450,7 +2369,7 @@ PluginManager::RegisterPlugin
instance.description = description;
instance.create_callback = create_callback;
instance.get_type_callback = get_type_callback;
- Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
GetInstrumentationRuntimeInstances ().push_back (instance);
}
return false;
@@ -2461,7 +2380,7 @@ PluginManager::UnregisterPlugin (InstrumentationRuntimeCreateInstance create_cal
{
if (create_callback)
{
- Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
InstrumentationRuntimeInstances::iterator pos, end = instances.end();
@@ -2480,30 +2399,29 @@ PluginManager::UnregisterPlugin (InstrumentationRuntimeCreateInstance create_cal
InstrumentationRuntimeGetType
PluginManager::GetInstrumentationRuntimeGetTypeCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
if (idx < instances.size())
return instances[idx].get_type_callback;
- return NULL;
+ return nullptr;
}
InstrumentationRuntimeCreateInstance
PluginManager::GetInstrumentationRuntimeCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
-
InstrumentationRuntimeCreateInstance
PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetInstrumentationRuntimeMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetInstrumentationRuntimeMutex());
InstrumentationRuntimeInstances &instances = GetInstrumentationRuntimeInstances ();
InstrumentationRuntimeInstances::iterator pos, end = instances.end();
@@ -2513,18 +2431,17 @@ PluginManager::GetInstrumentationRuntimeCreateCallbackForPluginName (const Const
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark TypeSystem
-
struct TypeSystemInstance
{
TypeSystemInstance() :
- name(),
- description(),
- create_callback(NULL)
+ name(),
+ description(),
+ create_callback(nullptr)
{
}
@@ -2536,10 +2453,10 @@ struct TypeSystemInstance
typedef std::vector<TypeSystemInstance> TypeSystemInstances;
-static Mutex &
-GetTypeSystemMutex ()
+static std::recursive_mutex &
+GetTypeSystemMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -2565,7 +2482,7 @@ PluginManager::RegisterPlugin (const ConstString &name,
instance.description = description;
instance.create_callback = create_callback;
instance.enumerate_callback = enumerate_supported_languages_callback;
- Mutex::Locker locker (GetTypeSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
GetTypeSystemInstances ().push_back (instance);
}
return false;
@@ -2576,7 +2493,7 @@ PluginManager::UnregisterPlugin (TypeSystemCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetTypeSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
TypeSystemInstances &instances = GetTypeSystemInstances ();
TypeSystemInstances::iterator pos, end = instances.end();
@@ -2595,11 +2512,11 @@ PluginManager::UnregisterPlugin (TypeSystemCreateInstance create_callback)
TypeSystemCreateInstance
PluginManager::GetTypeSystemCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetTypeSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
TypeSystemInstances &instances = GetTypeSystemInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
TypeSystemCreateInstance
@@ -2607,7 +2524,7 @@ PluginManager::GetTypeSystemCreateCallbackForPluginName (const ConstString &name
{
if (name)
{
- Mutex::Locker locker (GetTypeSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
TypeSystemInstances &instances = GetTypeSystemInstances ();
TypeSystemInstances::iterator pos, end = instances.end();
@@ -2617,17 +2534,17 @@ PluginManager::GetTypeSystemCreateCallbackForPluginName (const ConstString &name
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
TypeSystemEnumerateSupportedLanguages
PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetTypeSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
TypeSystemInstances &instances = GetTypeSystemInstances ();
if (idx < instances.size())
return instances[idx].enumerate_callback;
- return NULL;
+ return nullptr;
}
TypeSystemEnumerateSupportedLanguages
@@ -2635,7 +2552,7 @@ PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName (co
{
if (name)
{
- Mutex::Locker locker (GetTypeSystemMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
TypeSystemInstances &instances = GetTypeSystemInstances ();
TypeSystemInstances::iterator pos, end = instances.end();
@@ -2645,7 +2562,7 @@ PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName (co
return pos->enumerate_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark REPL
@@ -2653,9 +2570,9 @@ PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName (co
struct REPLInstance
{
REPLInstance() :
- name(),
- description(),
- create_callback(NULL)
+ name(),
+ description(),
+ create_callback(nullptr)
{
}
@@ -2667,10 +2584,10 @@ struct REPLInstance
typedef std::vector<REPLInstance> REPLInstances;
-static Mutex &
-GetREPLMutex ()
+static std::recursive_mutex &
+GetREPLMutex()
{
- static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
+ static std::recursive_mutex g_instances_mutex;
return g_instances_mutex;
}
@@ -2696,7 +2613,7 @@ PluginManager::RegisterPlugin (const ConstString &name,
instance.description = description;
instance.create_callback = create_callback;
instance.enumerate_languages_callback = enumerate_languages_callback;
- Mutex::Locker locker (GetREPLMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
GetREPLInstances ().push_back (instance);
}
return false;
@@ -2707,7 +2624,7 @@ PluginManager::UnregisterPlugin (REPLCreateInstance create_callback)
{
if (create_callback)
{
- Mutex::Locker locker (GetREPLMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
REPLInstances &instances = GetREPLInstances ();
REPLInstances::iterator pos, end = instances.end();
@@ -2726,11 +2643,11 @@ PluginManager::UnregisterPlugin (REPLCreateInstance create_callback)
REPLCreateInstance
PluginManager::GetREPLCreateCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetREPLMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
REPLInstances &instances = GetREPLInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
- return NULL;
+ return nullptr;
}
REPLCreateInstance
@@ -2738,7 +2655,7 @@ PluginManager::GetREPLCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetREPLMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
REPLInstances &instances = GetREPLInstances ();
REPLInstances::iterator pos, end = instances.end();
@@ -2748,26 +2665,25 @@ PluginManager::GetREPLCreateCallbackForPluginName (const ConstString &name)
return pos->create_callback;
}
}
- return NULL;
+ return nullptr;
}
REPLEnumerateSupportedLanguages
PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx)
{
- Mutex::Locker locker (GetREPLMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
REPLInstances &instances = GetREPLInstances ();
if (idx < instances.size())
return instances[idx].enumerate_languages_callback;
- return NULL;
+ return nullptr;
}
-
REPLEnumerateSupportedLanguages
PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName (const ConstString &name)
{
if (name)
{
- Mutex::Locker locker (GetREPLMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
REPLInstances &instances = GetREPLInstances ();
REPLInstances::iterator pos, end = instances.end();
@@ -2777,7 +2693,7 @@ PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName (co
return pos->enumerate_languages_callback;
}
}
- return NULL;
+ return nullptr;
}
#pragma mark PluginManager
@@ -2787,7 +2703,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger)
{
// Initialize the DynamicLoader plugins
{
- Mutex::Locker locker (GetDynamicLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetDynamicLoaderMutex());
DynamicLoaderInstances &instances = GetDynamicLoaderInstances ();
DynamicLoaderInstances::iterator pos, end = instances.end();
@@ -2800,7 +2716,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger)
// Initialize the JITLoader plugins
{
- Mutex::Locker locker (GetJITLoaderMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetJITLoaderMutex());
JITLoaderInstances &instances = GetJITLoaderInstances ();
JITLoaderInstances::iterator pos, end = instances.end();
@@ -2813,7 +2729,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger)
// Initialize the Platform plugins
{
- Mutex::Locker locker (GetPlatformInstancesMutex ());
+ std::lock_guard<std::recursive_mutex> guard(GetPlatformInstancesMutex());
PlatformInstances &instances = GetPlatformInstances ();
PlatformInstances::iterator pos, end = instances.end();
@@ -2826,7 +2742,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger)
// Initialize the Process plugins
{
- Mutex::Locker locker (GetProcessMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetProcessMutex());
ProcessInstances &instances = GetProcessInstances();
ProcessInstances::iterator pos, end = instances.end();
@@ -2839,7 +2755,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger)
// Initialize the SymbolFile plugins
{
- Mutex::Locker locker (GetSymbolFileMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetSymbolFileMutex());
for (auto& sym_file: GetSymbolFileInstances())
{
if (sym_file.debugger_init_callback)
@@ -2849,7 +2765,7 @@ PluginManager::DebuggerInitialize (Debugger &debugger)
// Initialize the OperatingSystem plugins
{
- Mutex::Locker locker(GetOperatingSystemMutex());
+ std::lock_guard<std::recursive_mutex> guard(GetOperatingSystemMutex());
for (auto &os : GetOperatingSystemInstances())
{
if (os.debugger_init_callback)
@@ -2871,7 +2787,7 @@ GetDebuggerPropertyForPlugins (Debugger &debugger,
{
static ConstString g_property_name("plugin");
- OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty (NULL, g_property_name);
+ 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));
@@ -2883,7 +2799,7 @@ GetDebuggerPropertyForPlugins (Debugger &debugger,
if (plugin_properties_sp)
{
- lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty (NULL, plugin_type_name);
+ 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));
@@ -2911,7 +2827,7 @@ GetDebuggerPropertyForPluginsOldStyle (Debugger &debugger,
lldb::OptionValuePropertiesSP parent_properties_sp (debugger.GetValueProperties());
if (parent_properties_sp)
{
- OptionValuePropertiesSP plugin_properties_sp = parent_properties_sp->GetSubProperty (NULL, plugin_type_name);
+ 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));
@@ -2923,7 +2839,7 @@ GetDebuggerPropertyForPluginsOldStyle (Debugger &debugger,
if (plugin_properties_sp)
{
- lldb::OptionValuePropertiesSP plugin_type_properties_sp = plugin_properties_sp->GetSubProperty (NULL, g_property_name);
+ 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));
@@ -2990,7 +2906,7 @@ const char* kProcessPluginName("process");
const char* kSymbolFilePluginName("symbol-file");
const char* kJITLoaderPluginName("jit-loader");
-}
+} // anonymous namespace
lldb::OptionValuePropertiesSP
PluginManager::GetSettingForDynamicLoaderPlugin (Debugger &debugger,
@@ -3013,7 +2929,6 @@ PluginManager::CreateSettingForDynamicLoaderPlugin (Debugger &debugger,
is_global_property);
}
-
lldb::OptionValuePropertiesSP
PluginManager::GetSettingForPlatformPlugin (Debugger &debugger, const ConstString &setting_name)
{
@@ -3038,7 +2953,6 @@ PluginManager::CreateSettingForPlatformPlugin (Debugger &debugger,
GetDebuggerPropertyForPluginsOldStyle);
}
-
lldb::OptionValuePropertiesSP
PluginManager::GetSettingForProcessPlugin (Debugger &debugger, const ConstString &setting_name)
{
diff --git a/source/Core/RegisterValue.cpp b/source/Core/RegisterValue.cpp
index d4ba9989c6a9..d9085d7f0bae 100644
--- a/source/Core/RegisterValue.cpp
+++ b/source/Core/RegisterValue.cpp
@@ -1,4 +1,4 @@
-//===-- RegisterValue.cpp ----------------------------------------*- C++ -*-===//
+//===-- RegisterValue.cpp ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -11,7 +11,12 @@
// C Includes
// C++ Includes
+#include <vector>
+
// Other libraries and framework includes
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+
// Project includes
#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Error.h"
@@ -24,7 +29,6 @@
using namespace lldb;
using namespace lldb_private;
-
bool
RegisterValue::Dump (Stream *s,
const RegisterInfo *reg_info,
@@ -98,14 +102,12 @@ RegisterValue::Dump (Stream *s,
return false;
}
-
bool
RegisterValue::GetData (DataExtractor &data) const
{
return data.SetData(GetBytes(), GetByteSize(), GetByteOrder()) > 0;
}
-
uint32_t
RegisterValue::GetAsMemoryData (const RegisterInfo *reg_info,
void *dst,
@@ -113,7 +115,7 @@ RegisterValue::GetAsMemoryData (const RegisterInfo *reg_info,
lldb::ByteOrder dst_byte_order,
Error &error) const
{
- if (reg_info == NULL)
+ if (reg_info == nullptr)
{
error.SetErrorString ("invalid register info argument.");
return 0;
@@ -163,7 +165,7 @@ RegisterValue::SetFromMemoryData (const RegisterInfo *reg_info,
lldb::ByteOrder src_byte_order,
Error &error)
{
- if (reg_info == NULL)
+ if (reg_info == nullptr)
{
error.SetErrorString ("invalid register info argument.");
return 0;
@@ -202,34 +204,13 @@ RegisterValue::SetFromMemoryData (const RegisterInfo *reg_info,
// 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);
-
- // Given the register info, set the value type of this RegisterValue object
- SetType (reg_info);
- // And make sure we were able to figure out what that register value was
- RegisterValue::Type value_type = GetType();
- if (value_type == eTypeInvalid)
- {
- // No value has been read into this object...
- error.SetErrorStringWithFormat("invalid register value type for register %s", reg_info->name);
- return 0;
- }
- else if (value_type == eTypeBytes)
- {
- buffer.byte_order = src_byte_order;
- // Make sure to set the buffer length of the destination buffer to avoid
- // problems due to uninitialized variables.
- buffer.length = src_len;
- }
- const uint32_t bytes_copied = src_data.CopyByteOrderedData (0, // src offset
- src_len, // src length
- GetBytes(), // dst buffer
- GetByteSize(), // dst length
- GetByteOrder()); // dst byte order
- if (bytes_copied == 0)
- error.SetErrorStringWithFormat("failed to copy data for register write of %s", reg_info->name);
+ error = SetValueFromData(reg_info, src_data, 0, true);
+ if (error.Fail())
+ return 0;
- return bytes_copied;
+ // If SetValueFromData succeeded, we must have copied all of src_len
+ return src_len;
}
bool
@@ -239,16 +220,27 @@ RegisterValue::GetScalarValue (Scalar &scalar) const
{
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;
+ 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:
@@ -270,41 +262,12 @@ RegisterValue::Clear()
RegisterValue::Type
RegisterValue::SetType (const RegisterInfo *reg_info)
{
- m_type = eTypeInvalid;
- const uint32_t byte_size = reg_info->byte_size;
- switch (reg_info->encoding)
- {
- case eEncodingInvalid:
- break;
-
- case eEncodingUint:
- case eEncodingSint:
- if (byte_size == 1)
- m_type = eTypeUInt8;
- else if (byte_size <= 2)
- m_type = eTypeUInt16;
- else if (byte_size <= 4)
- m_type = eTypeUInt32;
- else if (byte_size <= 8)
- m_type = eTypeUInt64;
- else if (byte_size <= 16)
- m_type = eTypeUInt128;
- break;
-
- case eEncodingIEEE754:
- if (byte_size == sizeof(float))
- m_type = eTypeFloat;
- else if (byte_size == sizeof(double))
- m_type = eTypeDouble;
- else if (byte_size == sizeof(long double))
- m_type = eTypeLongDouble;
- break;
+ // 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);
- case eEncodingVector:
- m_type = eTypeBytes;
- break;
- }
- m_scalar.SetType(reg_info);
return m_type;
}
@@ -342,16 +305,23 @@ RegisterValue::SetValueFromData (const RegisterInfo *reg_info, DataExtractor &sr
memset (buffer.bytes, 0, sizeof (buffer.bytes));
type128 int128;
- switch (SetType (reg_info))
+
+ m_type = eTypeInvalid;
+ switch (reg_info->encoding)
{
- case eTypeInvalid:
- error.SetErrorString("");
+ case eEncodingInvalid:
break;
- case eTypeUInt8: SetUInt8 (src.GetMaxU32 (&src_offset, src_len)); break;
- case eTypeUInt16: SetUInt16 (src.GetMaxU32 (&src_offset, src_len)); break;
- case eTypeUInt32: SetUInt32 (src.GetMaxU32 (&src_offset, src_len)); break;
- case eTypeUInt64: SetUInt64 (src.GetMaxU64 (&src_offset, src_len)); break;
- case eTypeUInt128:
+ 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);
@@ -368,11 +338,17 @@ RegisterValue::SetValueFromData (const RegisterInfo *reg_info, DataExtractor &sr
SetUInt128 (llvm::APInt(128, 2, int128.x));
}
break;
- case eTypeFloat: SetFloat (src.GetFloat (&src_offset)); break;
- case eTypeDouble: SetDouble(src.GetDouble (&src_offset)); break;
- case eTypeLongDouble: SetFloat (src.GetLongDouble (&src_offset)); break;
- case eTypeBytes:
+ 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);
@@ -384,17 +360,17 @@ RegisterValue::SetValueFromData (const RegisterInfo *reg_info, DataExtractor &sr
buffer.length, // dst length
buffer.byte_order) == 0)// dst byte order
{
- error.SetErrorString ("data copy failed data.");
+ 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;
}
-#include "llvm/ADT/StringRef.h"
-#include <vector>
static inline void StripSpaces(llvm::StringRef &Str)
{
while (!Str.empty() && isspace(Str[0]))
@@ -402,16 +378,19 @@ static inline void StripSpaces(llvm::StringRef &Str)
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);
}
+
// Helper function for RegisterValue::SetValueFromCString()
static bool
ParseVectorEncoding(const RegisterInfo *reg_info, const char *vector_str, const uint32_t byte_size, RegisterValue *reg_value)
@@ -445,17 +424,18 @@ ParseVectorEncoding(const RegisterInfo *reg_info, const char *vector_str, const
reg_value->SetBytes(&(bytes.front()), byte_size, eByteOrderLittle);
return true;
}
+
Error
RegisterValue::SetValueFromCString (const RegisterInfo *reg_info, const char *value_str)
{
Error error;
- if (reg_info == NULL)
+ if (reg_info == nullptr)
{
error.SetErrorString ("Invalid register info argument.");
return error;
}
- if (value_str == NULL || value_str[0] == '\0')
+ if (value_str == nullptr || value_str[0] == '\0')
{
error.SetErrorString ("Invalid c-string value string.");
return error;
@@ -562,7 +542,6 @@ RegisterValue::SetValueFromCString (const RegisterInfo *reg_info, const char *va
return error;
}
-
bool
RegisterValue::SignExtend (uint32_t sign_bitpos)
{
@@ -730,9 +709,7 @@ RegisterValue::GetAsUInt128 (const llvm::APInt& fail_value, bool *success_ptr) c
case 4:
case 8:
case 16:
- {
return llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)buffer.bytes)->x);
- }
}
}
break;
@@ -825,26 +802,7 @@ RegisterValue::GetBytes () const
case eTypeLongDouble: return m_scalar.GetBytes();
case eTypeBytes: return buffer.bytes;
}
- return NULL;
-}
-
-void *
-RegisterValue::GetBytes ()
-{
- 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 NULL;
+ return nullptr;
}
uint32_t
@@ -866,7 +824,6 @@ RegisterValue::GetByteSize () const
return 0;
}
-
bool
RegisterValue::SetUInt (uint64_t uint, uint32_t byte_size)
{
@@ -921,7 +878,6 @@ RegisterValue::SetBytes (const void *bytes, size_t length, lldb::ByteOrder byte_
}
}
-
bool
RegisterValue::operator == (const RegisterValue &rhs) const
{
@@ -1032,7 +988,6 @@ RegisterValue::ClearBit (uint32_t bit)
return false;
}
-
bool
RegisterValue::SetBit (uint32_t bit)
{
@@ -1077,4 +1032,3 @@ RegisterValue::SetBit (uint32_t bit)
}
return false;
}
-
diff --git a/source/Core/RegularExpression.cpp b/source/Core/RegularExpression.cpp
index 767521500af8..bdef3ced94d4 100644
--- a/source/Core/RegularExpression.cpp
+++ b/source/Core/RegularExpression.cpp
@@ -7,11 +7,17 @@
//
//===----------------------------------------------------------------------===//
-#include <string.h>
#include "lldb/Core/RegularExpression.h"
+
+// C Includes
+// C++ Includes
+#include <cstring>
+
+// Other libraries and framework includes
#include "llvm/ADT/StringRef.h"
-#include "lldb/Core/Error.h"
+// Project includes
+#include "lldb/Core/Error.h"
//----------------------------------------------------------------------
// Enable enhanced mode if it is available. This allows for things like
@@ -26,15 +32,12 @@
using namespace lldb_private;
-//----------------------------------------------------------------------
-// Default constructor
-//----------------------------------------------------------------------
RegularExpression::RegularExpression() :
m_re(),
m_comp_err (1),
m_preg()
{
- memset(&m_preg,0,sizeof(m_preg));
+ memset(&m_preg, 0, sizeof(m_preg));
}
//----------------------------------------------------------------------
@@ -63,6 +66,7 @@ RegularExpression::operator= (const RegularExpression &rhs)
Compile (rhs.GetText());
return *this;
}
+
//----------------------------------------------------------------------
// Destructor
//
@@ -117,7 +121,7 @@ bool
RegularExpression::Execute (const char* s, Match *match) const
{
int err = 1;
- if (s != NULL && m_comp_err == 0)
+ if (s != nullptr && m_comp_err == 0)
{
if (match)
{
@@ -129,11 +133,11 @@ RegularExpression::Execute (const char* s, Match *match) const
}
else
{
- err = ::regexec (&m_preg,
- s,
- 0,
- NULL,
- 0);
+ err = ::regexec(&m_preg,
+ s,
+ 0,
+ nullptr,
+ 0);
}
}
@@ -202,7 +206,6 @@ RegularExpression::Match::GetMatchSpanningIndices (const char* s, uint32_t idx1,
return false;
}
-
//----------------------------------------------------------------------
// Returns true if the regular expression compiled and is ready
// for execution.
@@ -220,9 +223,7 @@ RegularExpression::IsValid () const
const char*
RegularExpression::GetText () const
{
- if (m_re.empty())
- return NULL;
- return m_re.c_str();
+ return (m_re.empty() ? nullptr : m_re.c_str());
}
//----------------------------------------------------------------------
diff --git a/source/Core/Scalar.cpp b/source/Core/Scalar.cpp
index 586969b2d50a..d3e9a7565046 100644
--- a/source/Core/Scalar.cpp
+++ b/source/Core/Scalar.cpp
@@ -9,10 +9,16 @@
#include "lldb/Core/Scalar.h"
-#include <math.h>
-#include <inttypes.h>
-#include <stdio.h>
+// C Includes
+// C++ Includes
+#include <cinttypes>
+#include <cmath>
+#include <cstdio>
+// Other libraries and framework includes
+#include "llvm/ADT/SmallString.h"
+
+// Project includes
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/Error.h"
#include "lldb/Core/Stream.h"
@@ -72,19 +78,12 @@ PromoteToMaxType
return Scalar::e_void;
}
-
-//----------------------------------------------------------------------
-// Scalar constructor
-//----------------------------------------------------------------------
Scalar::Scalar() :
m_type(e_void),
m_float((float)0)
{
}
-//----------------------------------------------------------------------
-// Scalar copy constructor
-//----------------------------------------------------------------------
Scalar::Scalar(const Scalar& rhs) :
m_type(rhs.m_type),
m_integer(rhs.m_integer),
@@ -137,10 +136,10 @@ bool
Scalar::GetData (DataExtractor &data, size_t limit_byte_size) const
{
size_t byte_size = GetByteSize();
- static float f_val;
- static double d_val;
if (byte_size > 0)
{
+ const uint8_t *bytes = reinterpret_cast<const uint8_t *>(GetBytes());
+
if (limit_byte_size < byte_size)
{
if (endian::InlHostByteOrder() == eByteOrderLittle)
@@ -148,110 +147,33 @@ Scalar::GetData (DataExtractor &data, size_t limit_byte_size) const
// On little endian systems if we want fewer bytes from the
// current type we just specify fewer bytes since the LSByte
// is first...
- 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:
- data.SetData((const uint8_t *)m_integer.getRawData(), limit_byte_size, endian::InlHostByteOrder());
- return true;
- case e_float:
- f_val = m_float.convertToFloat();
- data.SetData((uint8_t *)&f_val, limit_byte_size, endian::InlHostByteOrder());
- return true;
- case e_double:
- d_val = m_float.convertToDouble();
- data.SetData((uint8_t *)&d_val, limit_byte_size, endian::InlHostByteOrder());
- return true;
- case e_long_double:
- static llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- data.SetData((const uint8_t *)ldbl_val.getRawData(), limit_byte_size, endian::InlHostByteOrder());
- return true;
- }
+ 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
- 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:
- data.SetData((const uint8_t *)m_integer.getRawData() + byte_size - limit_byte_size, limit_byte_size, endian::InlHostByteOrder());
- return true;
- case e_float:
- f_val = m_float.convertToFloat();
- data.SetData((uint8_t *)&f_val + byte_size - limit_byte_size, limit_byte_size, endian::InlHostByteOrder());
- return true;
- case e_double:
- d_val = m_float.convertToDouble();
- data.SetData((uint8_t *)&d_val + byte_size - limit_byte_size, limit_byte_size, endian::InlHostByteOrder());
- return true;
- case e_long_double:
- static llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- data.SetData((const uint8_t *)ldbl_val.getRawData() + byte_size - limit_byte_size, limit_byte_size, endian::InlHostByteOrder());
- return true;
- }
- }
- }
- else
- {
- // We want all of the data
- 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:
- data.SetData((const uint8_t *)m_integer.getRawData(), byte_size, endian::InlHostByteOrder());
- return true;
- case e_float:
- f_val = m_float.convertToFloat();
- data.SetData((uint8_t *)&f_val, byte_size, endian::InlHostByteOrder());
- return true;
- case e_double:
- d_val = m_float.convertToDouble();
- data.SetData((uint8_t *)&d_val, byte_size, endian::InlHostByteOrder());
- return true;
- case e_long_double:
- static llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- data.SetData((const uint8_t *)ldbl_val.getRawData(), byte_size, endian::InlHostByteOrder());
- return true;
+ bytes += byte_size - limit_byte_size;
+ byte_size = limit_byte_size;
}
}
+
+ data.SetData(bytes, byte_size, endian::InlHostByteOrder());
return true;
}
data.Clear();
return false;
}
-void *
+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:
@@ -262,20 +184,65 @@ Scalar::GetBytes() const
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:
- return const_cast<void *>(reinterpret_cast<const void *>(m_integer.getRawData()));
+ 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 (void *)&flt_val;
+ return reinterpret_cast<const void *>(&flt_val);
case e_double:
dbl_val = m_float.convertToDouble();
- return (void *)&dbl_val;
+ return reinterpret_cast<const void *>(&dbl_val);
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return const_cast<void *>(reinterpret_cast<const void *>(ldbl_val.getRawData()));
+ 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 NULL;
+ return nullptr;
}
size_t
@@ -292,7 +259,10 @@ Scalar::GetByteSize() const
case e_slonglong:
case e_ulonglong:
case e_sint128:
- case e_uint128: return (m_integer.getBitWidth() / 8);
+ 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);
@@ -316,6 +286,8 @@ Scalar::IsZero() const
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:
@@ -328,7 +300,6 @@ Scalar::IsZero() const
void
Scalar::GetValue (Stream *s, bool show_type) const
{
- const uint64_t *src;
if (show_type)
s->Printf("(%s) ", GetTypeAsCString());
@@ -336,25 +307,26 @@ Scalar::GetValue (Stream *s, bool show_type) const
{
case e_void:
break;
- case e_sint: s->Printf("%i", *(const sint_t *) m_integer.getRawData()); break;
- case e_uint: s->Printf("0x%8.8x", *(const uint_t *) m_integer.getRawData()); break;
- case e_slong: s->Printf("%li", *(const slong_t *) m_integer.getRawData()); break;
- case e_ulong: s->Printf("0x%8.8lx", *(const ulong_t *) m_integer.getRawData()); break;
- case e_slonglong: s->Printf("%lli", *(const slonglong_t *) m_integer.getRawData()); break;
- case e_ulonglong: s->Printf("0x%16.16llx", *(const ulonglong_t *) m_integer.getRawData()); break;
+ case e_sint:
+ case e_ulong:
+ case e_slonglong:
case e_sint128:
- src = m_integer.getRawData();
- s->Printf("%lli%lli", *(const slonglong_t *)src, *(const slonglong_t *)(src + 1));
+ case e_sint256:
+ s->Printf("%s",m_integer.toString(10,true).c_str());
break;
+ case e_uint:
+ case e_slong:
+ case e_ulonglong:
case e_uint128:
- src = m_integer.getRawData();
- s->Printf("0x%16.16llx%16.16llx", *(const ulonglong_t *)src, *(const ulonglong_t *)(src + 1));
+ case e_uint256:
+ s->Printf("%s",m_integer.toString(16,false).c_str());
break;
- case e_float: s->Printf("%f", m_float.convertToFloat()); break;
- case e_double: s->Printf("%g", m_float.convertToDouble()); break;
+ case e_float:
+ case e_double:
case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- s->Printf("%Lg", *(const long_double_t *)ldbl_val.getRawData());
+ llvm::SmallString<24> string;
+ m_float.toString(string);
+ s->Printf("%s", string.c_str());
break;
}
}
@@ -373,6 +345,8 @@ Scalar::GetTypeAsCString() const
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";
@@ -380,11 +354,6 @@ Scalar::GetTypeAsCString() const
return "<invalid Scalar type>";
}
-
-
-//----------------------------------------------------------------------
-// Scalar copy constructor
-//----------------------------------------------------------------------
Scalar&
Scalar::operator=(const Scalar& rhs)
{
@@ -405,7 +374,6 @@ Scalar::operator= (const int v)
return *this;
}
-
Scalar&
Scalar::operator= (unsigned int v)
{
@@ -499,16 +467,17 @@ Scalar::operator= (llvm::APInt rhs)
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;
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-Scalar::~Scalar()
-{
-}
+Scalar::~Scalar() = default;
bool
Scalar::Promote(Scalar::Type type)
@@ -525,63 +494,59 @@ Scalar::Promote(Scalar::Type type)
case e_void: break;
case e_sint: success = true; break;
case e_uint:
- {
- m_integer = llvm::APInt(sizeof(uint_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
+ m_integer = m_integer.sextOrTrunc(sizeof(uint_t) * 8);
success = true;
break;
- }
+
case e_slong:
- {
- m_integer = llvm::APInt(sizeof(slong_t) * 8, *(const uint64_t *)m_integer.getRawData(), true);
+ m_integer = m_integer.sextOrTrunc(sizeof(slong_t) * 8);
success = true;
break;
- }
+
case e_ulong:
- {
- m_integer = llvm::APInt(sizeof(ulong_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
+ m_integer = m_integer.sextOrTrunc(sizeof(ulong_t) * 8);
success = true;
break;
- }
+
case e_slonglong:
- {
- m_integer = llvm::APInt(sizeof(slonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), true);
+ m_integer = m_integer.sextOrTrunc(sizeof(slonglong_t) * 8);
success = true;
break;
- }
+
case e_ulonglong:
- {
- m_integer = llvm::APInt(sizeof(ulonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
+ m_integer = m_integer.sextOrTrunc(sizeof(ulonglong_t) * 8);
success = true;
break;
- }
+
case e_sint128:
case e_uint128:
- {
- m_integer = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)m_integer.getRawData()));
+ 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;
@@ -592,57 +557,54 @@ Scalar::Promote(Scalar::Type type)
case e_sint: break;
case e_uint: success = true; break;
case e_slong:
- {
- m_integer = llvm::APInt(sizeof(slong_t) * 8, *(const uint64_t *)m_integer.getRawData(), true);
+ m_integer = m_integer.zextOrTrunc(sizeof(slong_t) * 8);
success = true;
break;
- }
+
case e_ulong:
- {
- m_integer = llvm::APInt(sizeof(ulong_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
+ m_integer = m_integer.zextOrTrunc(sizeof(ulong_t) * 8);
success = true;
break;
- }
+
case e_slonglong:
- {
- m_integer = llvm::APInt(sizeof(slonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), true);
+ m_integer = m_integer.zextOrTrunc(sizeof(slonglong_t) * 8);
success = true;
break;
- }
+
case e_ulonglong:
- {
- m_integer = llvm::APInt(sizeof(ulonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
+ m_integer = m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8);
success = true;
break;
- }
+
case e_sint128:
case e_uint128:
- {
- m_integer = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)m_integer.getRawData()));
+ m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128);
success = true;
break;
- }
- case e_float:
- {
+
+ 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;
@@ -654,51 +616,49 @@ Scalar::Promote(Scalar::Type type)
case e_uint: break;
case e_slong: success = true; break;
case e_ulong:
- {
- m_integer = llvm::APInt(sizeof(ulong_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
+ m_integer = m_integer.sextOrTrunc(sizeof(ulong_t) * 8);
success = true;
break;
- }
+
case e_slonglong:
- {
- m_integer = llvm::APInt(sizeof(slonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), true);
+ m_integer = m_integer.sextOrTrunc(sizeof(slonglong_t) * 8);
success = true;
break;
- }
+
case e_ulonglong:
- {
- m_integer = llvm::APInt(sizeof(ulonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
+ m_integer = m_integer.sextOrTrunc(sizeof(ulonglong_t) * 8);
success = true;
break;
- }
+
case e_sint128:
case e_uint128:
- {
- m_integer = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)m_integer.getRawData()));
+ 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;
@@ -711,45 +671,44 @@ Scalar::Promote(Scalar::Type type)
case e_slong: break;
case e_ulong: success = true; break;
case e_slonglong:
- {
- m_integer = llvm::APInt(sizeof(slonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), true);
+ m_integer = m_integer.zextOrTrunc(sizeof(slonglong_t) * 8);
success = true;
break;
- }
+
case e_ulonglong:
- {
- m_integer = llvm::APInt(sizeof(ulonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
+ m_integer = m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8);
success = true;
break;
- }
+
case e_sint128:
case e_uint128:
- {
- m_integer = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)m_integer.getRawData()));
+ 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;
@@ -763,39 +722,39 @@ Scalar::Promote(Scalar::Type type)
case e_ulong: break;
case e_slonglong: success = true; break;
case e_ulonglong:
- {
- m_integer = llvm::APInt(sizeof(ulonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
+ m_integer = m_integer.sextOrTrunc(sizeof(ulonglong_t) * 8);
success = true;
break;
- }
+
case e_sint128:
case e_uint128:
- {
- m_integer = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)m_integer.getRawData()));
+ 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;
@@ -811,32 +770,33 @@ Scalar::Promote(Scalar::Type type)
case e_ulonglong: success = true; break;
case e_sint128:
case e_uint128:
- {
- m_integer = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)m_integer.getRawData()));
+ 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;
@@ -852,32 +812,33 @@ Scalar::Promote(Scalar::Type type)
case e_ulonglong: break;
case e_sint128: success = true; break;
case e_uint128:
- {
- m_integer = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)m_integer.getRawData()));
+ 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;
@@ -893,30 +854,104 @@ Scalar::Promote(Scalar::Type type)
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;
+ 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;
+
case e_float:
switch (type)
{
@@ -928,23 +963,22 @@ Scalar::Promote(Scalar::Type type)
case e_slonglong:
case e_ulonglong:
case e_sint128:
- case e_uint128: break;
+ 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;
@@ -960,17 +994,17 @@ Scalar::Promote(Scalar::Type type)
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;
@@ -986,6 +1020,8 @@ Scalar::Promote(Scalar::Type type)
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;
@@ -1015,11 +1051,12 @@ Scalar::GetValueTypeAsCString (Scalar::Type type)
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)
{
@@ -1073,78 +1110,78 @@ Scalar::Cast(Scalar::Type type)
case e_ulonglong:
case e_sint128:
case e_uint128:
+ case e_sint256:
+ case e_uint256:
switch (type)
{
case e_void: break;
case e_sint:
- {
m_integer = m_integer.sextOrTrunc(sizeof(sint_t) * 8);
success = true;
break;
- }
+
case e_uint:
- {
m_integer = m_integer.zextOrTrunc(sizeof(sint_t) * 8);
success = true;
break;
- }
+
case e_slong:
- {
m_integer = m_integer.sextOrTrunc(sizeof(slong_t) * 8);
success = true;
break;
- }
+
case e_ulong:
- {
m_integer = m_integer.zextOrTrunc(sizeof(slong_t) * 8);
success = true;
break;
- }
+
case e_slonglong:
- {
m_integer = m_integer.sextOrTrunc(sizeof(slonglong_t) * 8);
success = true;
break;
- }
+
case e_ulonglong:
- {
m_integer = m_integer.zextOrTrunc(sizeof(slonglong_t) * 8);
success = true;
break;
- }
+
case e_sint128:
- {
m_integer = m_integer.sextOrTrunc(BITWIDTH_INT128);
success = true;
break;
- }
+
case e_uint128:
- {
m_integer = m_integer.zextOrTrunc(BITWIDTH_INT128);
success = true;
break;
- }
+
+ case e_sint256:
+ m_integer = m_integer.sextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ break;
+
+ case e_uint256:
+ m_integer = m_integer.zextOrTrunc(BITWIDTH_INT256);
+ success = true;
+ break;
+
case e_float:
- {
m_float = llvm::APFloat(m_integer.bitsToFloat());
success = true;
break;
- }
+
case e_double:
- {
m_float = llvm::APFloat(m_integer.bitsToDouble());
success = true;
break;
- }
+
case e_long_double:
- {
if(m_ieee_quad)
m_float = llvm::APFloat(llvm::APFloat::IEEEquad, m_integer);
else
m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended, m_integer);
success = true;
break;
- }
}
break;
@@ -1159,7 +1196,9 @@ Scalar::Cast(Scalar::Type type)
case e_slonglong:
case e_ulonglong:
case e_sint128:
- case e_uint128: m_integer = m_float.bitcastToAPInt(); success = true; break;
+ 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:
@@ -1183,7 +1222,9 @@ Scalar::Cast(Scalar::Type type)
case e_slonglong:
case e_ulonglong:
case e_sint128:
- case e_uint128: m_integer = m_float.bitcastToAPInt(); success = true; break;
+ 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:
@@ -1201,61 +1242,65 @@ Scalar::Cast(Scalar::Type 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;
@@ -1283,7 +1328,9 @@ Scalar::MakeSigned ()
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_sint; 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;
@@ -1292,7 +1339,33 @@ Scalar::MakeSigned ()
return success;
}
-char
+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)
@@ -1306,14 +1379,16 @@ Scalar::SChar(char fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const schar_t *)(m_integer.sextOrTrunc(sizeof(schar_t) * 8)).getRawData();
+ 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.getRawData();
+ return (schar_t)(ldbl_val.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue();
}
return fail_value;
}
@@ -1332,14 +1407,16 @@ Scalar::UChar(unsigned char fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const uchar_t *)m_integer.getRawData();
+ 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.getRawData();
+ return (uchar_t)(ldbl_val.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue();
}
return fail_value;
}
@@ -1358,14 +1435,16 @@ Scalar::SShort(short fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const sshort_t *)(m_integer.sextOrTrunc(sizeof(sshort_t) * 8)).getRawData();
+ 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 *(const sshort_t *)ldbl_val.getRawData();
+ return (sshort_t)(ldbl_val.sextOrTrunc(sizeof(sshort_t) * 8)).getSExtValue();
}
return fail_value;
}
@@ -1384,14 +1463,16 @@ Scalar::UShort(unsigned short fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const ushort_t *)m_integer.getRawData();
+ 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 *(const ushort_t *)ldbl_val.getRawData();;
+ return (ushort_t)(ldbl_val.zextOrTrunc(sizeof(ushort_t) * 8)).getZExtValue();
}
return fail_value;
}
@@ -1410,14 +1491,16 @@ Scalar::SInt(int fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const sint_t *)(m_integer.sextOrTrunc(sizeof(sint_t) * 8)).getRawData();
+ 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 *(const sint_t *)ldbl_val.getRawData();
+ return (sint_t)(ldbl_val.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue();
}
return fail_value;
}
@@ -1436,19 +1519,20 @@ Scalar::UInt(unsigned int fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const uint_t *)m_integer.getRawData();
+ 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 *(const uint_t *)ldbl_val.getRawData();
+ return (uint_t)(ldbl_val.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue();
}
return fail_value;
}
-
long
Scalar::SLong(long fail_value) const
{
@@ -1463,20 +1547,20 @@ Scalar::SLong(long fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const slong_t *)(m_integer.sextOrTrunc(sizeof(slong_t) * 8)).getRawData();
+ 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 *(const slong_t *)ldbl_val.getRawData();
+ return (slong_t)(ldbl_val.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue();
}
return fail_value;
}
-
-
unsigned long
Scalar::ULong(unsigned long fail_value) const
{
@@ -1491,48 +1575,20 @@ Scalar::ULong(unsigned long fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const ulong_t *)m_integer.getRawData();
+ 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 *(const ulong_t *)ldbl_val.getRawData();
+ return (ulong_t)(ldbl_val.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue();
}
return fail_value;
}
-uint64_t
-Scalar::GetRawBits64(uint64_t 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:
- return *m_integer.getRawData();
- case e_float:
- return (uint64_t)m_float.convertToFloat();
- case e_double:
- return (uint64_t)m_float.convertToDouble();
- case e_long_double:
- llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return *ldbl_val.getRawData();
- }
- return fail_value;
-}
-
-
-
long long
Scalar::SLongLong(long long fail_value) const
{
@@ -1547,19 +1603,20 @@ Scalar::SLongLong(long long fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const slonglong_t *)(m_integer.sextOrTrunc(sizeof(slonglong_t) * 8)).getRawData();
+ 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 *(const slonglong_t *)ldbl_val.getRawData();
+ 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
{
@@ -1574,14 +1631,41 @@ Scalar::ULongLong(unsigned long long fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
- return *(const ulonglong_t *)m_integer.getRawData();
+ 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 *(const ulonglong_t *)ldbl_val.getRawData();
+ 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;
}
@@ -1600,6 +1684,8 @@ Scalar::UInt128(const llvm::APInt& fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
+ case e_sint256:
+ case e_uint256:
return m_integer;
case e_float:
case e_double:
@@ -1610,7 +1696,7 @@ Scalar::UInt128(const llvm::APInt& fail_value) const
}
llvm::APInt
-Scalar::SInt128(llvm::APInt& fail_value) const
+Scalar::SInt256(llvm::APInt& fail_value) const
{
switch (m_type)
{
@@ -1623,6 +1709,8 @@ Scalar::SInt128(llvm::APInt& fail_value) const
case e_ulonglong:
case e_sint128:
case e_uint128:
+ case e_sint256:
+ case e_uint256:
return m_integer;
case e_float:
case e_double:
@@ -1632,6 +1720,31 @@ Scalar::SInt128(llvm::APInt& fail_value) const
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
{
@@ -1646,6 +1759,8 @@ Scalar::Float(float fail_value) const
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();
@@ -1658,7 +1773,6 @@ Scalar::Float(float fail_value) const
return fail_value;
}
-
double
Scalar::Double(double fail_value) const
{
@@ -1673,6 +1787,8 @@ Scalar::Double(double fail_value) const
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();
@@ -1685,7 +1801,6 @@ Scalar::Double(double fail_value) const
return fail_value;
}
-
long double
Scalar::LongDouble(long double fail_value) const
{
@@ -1700,6 +1815,8 @@ Scalar::LongDouble(long double fail_value) const
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();
@@ -1712,7 +1829,6 @@ Scalar::LongDouble(long double fail_value) const
return fail_value;
}
-
Scalar&
Scalar::operator+= (const Scalar& rhs)
{
@@ -1732,17 +1848,16 @@ Scalar::operator+= (const Scalar& rhs)
case e_ulonglong:
case e_sint128:
case e_uint128:
- {
+ case e_sint256:
+ case e_uint256:
m_integer = a->m_integer + b->m_integer;
break;
- }
+
case e_float:
case e_double:
case e_long_double:
- {
m_float = a->m_float + b->m_float;
break;
- }
}
}
return *this;
@@ -1768,6 +1883,8 @@ Scalar::operator<<= (const Scalar& rhs)
case e_ulonglong:
case e_sint128:
case e_uint128:
+ case e_sint256:
+ case e_uint256:
switch (rhs.m_type)
{
case e_void:
@@ -1784,10 +1901,10 @@ Scalar::operator<<= (const Scalar& rhs)
case e_ulonglong:
case e_sint128:
case e_uint128:
- {
- m_integer <<= *rhs.m_integer.getRawData();
+ case e_sint256:
+ case e_uint256:
+ m_integer = m_integer << rhs.m_integer;
break;
- }
}
break;
}
@@ -1814,6 +1931,8 @@ Scalar::ShiftRightLogical(const Scalar& rhs)
case e_ulonglong:
case e_sint128:
case e_uint128:
+ case e_sint256:
+ case e_uint256:
switch (rhs.m_type)
{
case e_void:
@@ -1830,14 +1949,16 @@ Scalar::ShiftRightLogical(const Scalar& rhs)
case e_ulonglong:
case e_sint128:
case e_uint128:
- m_integer = m_integer.lshr(*(const uint_t *) rhs.m_integer.getRawData()); break;
+ 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)
{
@@ -1858,6 +1979,8 @@ Scalar::operator>>= (const Scalar& rhs)
case e_ulonglong:
case e_sint128:
case e_uint128:
+ case e_sint256:
+ case e_uint256:
switch (rhs.m_type)
{
case e_void:
@@ -1872,19 +1995,18 @@ Scalar::operator>>= (const Scalar& rhs)
case e_ulong:
case e_slonglong:
case e_ulonglong:
- case e_sint128:
- case e_uint128:
- {
- m_integer >> *rhs.m_integer.getRawData();
- break;
- }
+ case e_sint128:
+ case e_uint128:
+ case e_sint256:
+ case e_uint256:
+ m_integer = m_integer.ashr(rhs.m_integer);
+ break;
}
break;
}
return *this;
}
-
Scalar&
Scalar::operator&= (const Scalar& rhs)
{
@@ -1905,6 +2027,8 @@ Scalar::operator&= (const Scalar& rhs)
case e_ulonglong:
case e_sint128:
case e_uint128:
+ case e_sint256:
+ case e_uint256:
switch (rhs.m_type)
{
case e_void:
@@ -1919,20 +2043,18 @@ Scalar::operator&= (const Scalar& rhs)
case e_ulong:
case e_slonglong:
case e_ulonglong:
- case e_sint128:
- case e_uint128:
- {
- m_integer &= rhs.m_integer;
- break;
- }
+ case e_sint128:
+ case e_uint128:
+ case e_sint256:
+ case e_uint256:
+ m_integer &= rhs.m_integer;
+ break;
}
break;
}
return *this;
}
-
-
bool
Scalar::AbsoluteValue()
{
@@ -1945,6 +2067,7 @@ Scalar::AbsoluteValue()
case e_slong:
case e_slonglong:
case e_sint128:
+ case e_sint256:
if (m_integer.isNegative())
m_integer = -m_integer;
return true;
@@ -1953,6 +2076,7 @@ Scalar::AbsoluteValue()
case e_ulong:
case e_ulonglong: return true;
case e_uint128:
+ case e_uint256:
case e_float:
case e_double:
case e_long_double:
@@ -1962,7 +2086,6 @@ Scalar::AbsoluteValue()
return false;
}
-
bool
Scalar::UnaryNegate()
{
@@ -1977,6 +2100,8 @@ Scalar::UnaryNegate()
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:
@@ -1999,6 +2124,8 @@ Scalar::OnesComplement()
case e_ulonglong:
case e_sint128:
case e_uint128:
+ case e_sint256:
+ case e_uint256:
m_integer = ~m_integer; return true;
case e_void:
@@ -2010,7 +2137,6 @@ Scalar::OnesComplement()
return false;
}
-
const Scalar
lldb_private::operator+ (const Scalar& lhs, const Scalar& rhs)
{
@@ -2031,6 +2157,8 @@ lldb_private::operator+ (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2041,7 +2169,6 @@ lldb_private::operator+ (const Scalar& lhs, const Scalar& rhs)
return result;
}
-
const Scalar
lldb_private::operator- (const Scalar& lhs, const Scalar& rhs)
{
@@ -2062,6 +2189,8 @@ lldb_private::operator- (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2085,21 +2214,27 @@ lldb_private::operator/ (const Scalar& lhs, const Scalar& rhs)
{
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_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.getRawData() / *b->m_integer.getRawData();
+ 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:
@@ -2137,6 +2272,8 @@ lldb_private::operator* (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2166,6 +2303,8 @@ lldb_private::operator& (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2198,6 +2337,8 @@ lldb_private::operator| (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2224,23 +2365,29 @@ lldb_private::operator% (const Scalar& lhs, const Scalar& rhs)
switch (result.m_type)
{
default: break;
- 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:
- {
- if (b->m_integer != 0)
- {
- result.m_integer = *a->m_integer.getRawData() % *b->m_integer.getRawData();
- return result;
- }
- 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;
@@ -2266,6 +2413,8 @@ lldb_private::operator^ (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2296,33 +2445,11 @@ lldb_private::operator>> (const Scalar& lhs, const Scalar &rhs)
return result;
}
-// Return the raw unsigned integer without any casting or conversion
-unsigned int
-Scalar::RawUInt () const
-{
- return *(const uint_t *) m_integer.getRawData();
-}
-
-// Return the raw unsigned long without any casting or conversion
-unsigned long
-Scalar::RawULong () const
-{
- return *(const ulong_t *) m_integer.getRawData();
-}
-
-// Return the raw unsigned long long without any casting or conversion
-unsigned long long
-Scalar::RawULongLong () const
-{
- return *(const ulonglong_t *) m_integer.getRawData();
-}
-
-
Error
Scalar::SetValueFromCString (const char *value_str, Encoding encoding, size_t byte_size)
{
Error error;
- if (value_str == NULL || value_str[0] == '\0')
+ if (value_str == nullptr || value_str[0] == '\0')
{
error.SetErrorString ("Invalid c-string value string.");
return error;
@@ -2449,6 +2576,7 @@ Scalar::SetValueFromData (DataExtractor &data, lldb::Encoding encoding, size_t b
Error error;
type128 int128;
+ type256 int256;
switch (encoding)
{
case lldb::eEncodingInvalid:
@@ -2468,20 +2596,35 @@ Scalar::SetValueFromData (DataExtractor &data, lldb::Encoding encoding, size_t b
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 + 1);
+ 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 + 1);
+ 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;
@@ -2499,20 +2642,35 @@ Scalar::SetValueFromData (DataExtractor &data, lldb::Encoding encoding, size_t b
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 + 1);
+ 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 + 1);
+ 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;
@@ -2561,6 +2719,8 @@ Scalar::SignExtend (uint32_t sign_bit_pos)
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))
@@ -2615,51 +2775,33 @@ Scalar::ExtractBitfield (uint32_t bit_size,
if (bit_size == 0)
return true;
- uint32_t msbit = bit_offset + bit_size - 1;
- uint32_t lsbit = bit_offset;
- uint64_t result;
switch (m_type)
{
case Scalar::e_void:
+ case Scalar::e_float:
+ case Scalar::e_double:
+ case Scalar::e_long_double:
break;
- case e_float:
- result = SignedBits ((uint64_t )m_float.convertToFloat(), msbit, lsbit);
- m_float = llvm::APFloat((float_t)result);
- return true;
- case e_double:
- result = SignedBits ((uint64_t )m_float.convertToDouble(), msbit, lsbit);
- m_float = llvm::APFloat((double_t)result);
- case e_long_double:
- m_integer = m_float.bitcastToAPInt();
- result = SignedBits (*m_integer.getRawData(), msbit, lsbit);
- if(m_ieee_quad)
- m_float = llvm::APFloat(llvm::APFloat::IEEEquad, llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&result)->x));
- else
- m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended, llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&result)->x));
- return true;
-
case Scalar::e_sint:
case Scalar::e_slong:
case Scalar::e_slonglong:
case Scalar::e_sint128:
- m_integer = SignedBits (*m_integer.getRawData(), msbit, lsbit);
+ 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:
- m_integer = UnsignedBits (*m_integer.getRawData(), msbit, lsbit);
+ 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)
{
@@ -2682,6 +2824,8 @@ lldb_private::operator== (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2715,6 +2859,8 @@ lldb_private::operator!= (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2743,11 +2889,13 @@ lldb_private::operator< (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2776,11 +2924,13 @@ lldb_private::operator<= (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2792,7 +2942,6 @@ lldb_private::operator<= (const Scalar& lhs, const Scalar& rhs)
return false;
}
-
bool
lldb_private::operator> (const Scalar& lhs, const Scalar& rhs)
{
@@ -2810,11 +2959,13 @@ lldb_private::operator> (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2843,11 +2994,13 @@ lldb_private::operator>= (const Scalar& lhs, const Scalar& rhs)
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:
@@ -2873,7 +3026,9 @@ Scalar::ClearBit (uint32_t bit)
case e_slonglong:
case e_ulonglong:
case e_sint128:
- case e_uint128: m_integer.clearBit(bit); return true;
+ 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;
@@ -2895,7 +3050,9 @@ Scalar::SetBit (uint32_t bit)
case e_slonglong:
case e_ulonglong:
case e_sint128:
- case e_uint128: m_integer.setBit(bit); return true;
+ 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;
@@ -2903,72 +3060,3 @@ Scalar::SetBit (uint32_t bit)
return false;
}
-void
-Scalar::SetType (const RegisterInfo *reg_info)
-{
- const uint32_t byte_size = reg_info->byte_size;
- switch (reg_info->encoding)
- {
- case eEncodingInvalid:
- break;
- case eEncodingUint:
- if (byte_size == 1 || byte_size == 2 || byte_size == 4)
- {
- m_integer = llvm::APInt(sizeof(uint_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
- m_type = e_uint;
- }
- if (byte_size == 8)
- {
- m_integer = llvm::APInt(sizeof(ulonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), false);
- m_type = e_ulonglong;
- }
- if (byte_size == 16)
- {
- m_integer = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)m_integer.getRawData())->x);
- m_type = e_uint128;
- }
- break;
- case eEncodingSint:
- if (byte_size == 1 || byte_size == 2 || byte_size == 4)
- {
- m_integer = llvm::APInt(sizeof(sint_t) * 8, *(const uint64_t *)m_integer.getRawData(), true);
- m_type = e_sint;
- }
- if (byte_size == 8)
- {
- m_integer = llvm::APInt(sizeof(slonglong_t) * 8, *(const uint64_t *)m_integer.getRawData(), true);
- m_type = e_slonglong;
- }
- if (byte_size == 16)
- {
- m_integer = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((const type128 *)m_integer.getRawData())->x);
- m_type = e_sint128;
- }
- break;
- case eEncodingIEEE754:
- if (byte_size == sizeof(float))
- {
- bool losesInfo = false;
- m_float.convert(llvm::APFloat::IEEEsingle, llvm::APFloat::rmTowardZero, &losesInfo);
- m_type = e_float;
- }
- else if (byte_size == sizeof(double))
- {
- bool losesInfo = false;
- m_float.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmTowardZero, &losesInfo);
- m_type = e_double;
- }
- else if (byte_size == sizeof(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());
- m_type = e_long_double;
- }
- break;
- case eEncodingVector:
- m_type = e_void;
- break;
- }
-}
diff --git a/source/Core/SearchFilter.cpp b/source/Core/SearchFilter.cpp
index f54bbe8d4adf..202a40ff414d 100644
--- a/source/Core/SearchFilter.cpp
+++ b/source/Core/SearchFilter.cpp
@@ -9,9 +9,9 @@
// C Includes
// C++ Includes
+
// Other libraries and framework includes
// Project includes
-
#include "lldb/lldb-private.h"
#include "lldb/Core/SearchFilter.h"
#include "lldb/Core/Module.h"
@@ -21,56 +21,26 @@
using namespace lldb;
using namespace lldb_private;
-//----------------------------------------------------------------------
-// SearchFilter constructor
-//----------------------------------------------------------------------
-Searcher::Searcher ()
-{
+Searcher::Searcher() = default;
-}
-
-Searcher::~Searcher ()
-{
-
-}
+Searcher::~Searcher() = default;
void
Searcher::GetDescription (Stream *s)
{
}
-//----------------------------------------------------------------------
-// SearchFilter constructor
-//----------------------------------------------------------------------
SearchFilter::SearchFilter(const TargetSP &target_sp) :
m_target_sp (target_sp)
{
}
-//----------------------------------------------------------------------
-// SearchFilter copy constructor
-//----------------------------------------------------------------------
-SearchFilter::SearchFilter(const SearchFilter& rhs) :
- m_target_sp (rhs.m_target_sp)
-{
-}
+SearchFilter::SearchFilter(const SearchFilter& rhs) = default;
-//----------------------------------------------------------------------
-// SearchFilter assignment operator
-//----------------------------------------------------------------------
-const SearchFilter&
-SearchFilter::operator=(const SearchFilter& rhs)
-{
- m_target_sp = rhs.m_target_sp;
- return *this;
-}
+SearchFilter&
+SearchFilter::operator=(const SearchFilter& rhs) = default;
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-SearchFilter::~SearchFilter()
-{
-}
+SearchFilter::~SearchFilter() = default;
bool
SearchFilter::ModulePasses (const FileSpec &spec)
@@ -116,7 +86,6 @@ SearchFilter::GetDescription (Stream *s)
void
SearchFilter::Dump (Stream *s) const
{
-
}
lldb::SearchFilterSP
@@ -143,7 +112,7 @@ SearchFilter::Search (Searcher &searcher)
empty_sc.target_sp = m_target_sp;
if (searcher.GetDepth() == Searcher::eDepthTarget)
- searcher.SearchCallback (*this, empty_sc, NULL, false);
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
else
DoModuleIteration(empty_sc, searcher);
}
@@ -158,10 +127,10 @@ SearchFilter::SearchInModuleList (Searcher &searcher, ModuleList &modules)
empty_sc.target_sp = m_target_sp;
if (searcher.GetDepth() == Searcher::eDepthTarget)
- searcher.SearchCallback (*this, empty_sc, NULL, false);
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
else
{
- Mutex::Locker modules_locker(modules.GetMutex());
+ std::lock_guard<std::recursive_mutex> guard(modules.GetMutex());
const size_t numModules = modules.GetSize();
for (size_t i = 0; i < numModules; i++)
@@ -176,7 +145,6 @@ SearchFilter::SearchInModuleList (Searcher &searcher, ModuleList &modules)
}
}
-
Searcher::CallbackReturn
SearchFilter::DoModuleIteration (const lldb::ModuleSP& module_sp, Searcher &searcher)
{
@@ -194,7 +162,7 @@ SearchFilter::DoModuleIteration (const SymbolContext &context, Searcher &searche
if (searcher.GetDepth () == Searcher::eDepthModule)
{
SymbolContext matchingContext(context.module_sp.get());
- searcher.SearchCallback (*this, matchingContext, NULL, false);
+ searcher.SearchCallback(*this, matchingContext, nullptr, false);
}
else
{
@@ -204,8 +172,8 @@ SearchFilter::DoModuleIteration (const SymbolContext &context, Searcher &searche
else
{
const ModuleList &target_images = m_target_sp->GetImages();
- Mutex::Locker modules_locker(target_images.GetMutex());
-
+ 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++)
{
@@ -219,7 +187,7 @@ SearchFilter::DoModuleIteration (const SymbolContext &context, Searcher &searche
{
SymbolContext matchingContext(m_target_sp, module_sp);
- Searcher::CallbackReturn shouldContinue = searcher.SearchCallback (*this, matchingContext, NULL, false);
+ Searcher::CallbackReturn shouldContinue = searcher.SearchCallback(*this, matchingContext, nullptr, false);
if (shouldContinue == Searcher::eCallbackReturnStop
|| shouldContinue == Searcher::eCallbackReturnPop)
return shouldContinue;
@@ -242,7 +210,7 @@ Searcher::CallbackReturn
SearchFilter::DoCUIteration (const ModuleSP &module_sp, const SymbolContext &context, Searcher &searcher)
{
Searcher::CallbackReturn shouldContinue;
- if (context.comp_unit == NULL)
+ if (context.comp_unit == nullptr)
{
const size_t num_comp_units = module_sp->GetNumCompileUnits();
for (size_t i = 0; i < num_comp_units; i++)
@@ -257,7 +225,7 @@ SearchFilter::DoCUIteration (const ModuleSP &module_sp, const SymbolContext &con
{
SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get());
- shouldContinue = searcher.SearchCallback (*this, matchingContext, NULL, false);
+ shouldContinue = searcher.SearchCallback(*this, matchingContext, nullptr, false);
if (shouldContinue == Searcher::eCallbackReturnPop)
return Searcher::eCallbackReturnContinue;
@@ -276,7 +244,7 @@ SearchFilter::DoCUIteration (const ModuleSP &module_sp, const SymbolContext &con
if (CompUnitPasses(*context.comp_unit))
{
SymbolContext matchingContext (m_target_sp, module_sp, context.comp_unit);
- return searcher.SearchCallback (*this, matchingContext, NULL, false);
+ return searcher.SearchCallback(*this, matchingContext, nullptr, false);
}
}
return Searcher::eCallbackReturnContinue;
@@ -326,30 +294,15 @@ SearchFilterForUnconstrainedSearches::DoCopyForBreakpoint (Breakpoint &breakpoin
// Selects a shared library matching a given file spec
//----------------------------------------------------------------------
-//----------------------------------------------------------------------
-// SearchFilterByModule constructors
-//----------------------------------------------------------------------
-
SearchFilterByModule::SearchFilterByModule (const lldb::TargetSP &target_sp, const FileSpec &module) :
SearchFilter (target_sp),
m_module_spec (module)
{
}
+SearchFilterByModule::SearchFilterByModule(const SearchFilterByModule& rhs) = default;
-//----------------------------------------------------------------------
-// SearchFilterByModule copy constructor
-//----------------------------------------------------------------------
-SearchFilterByModule::SearchFilterByModule(const SearchFilterByModule& rhs) :
- SearchFilter (rhs),
- m_module_spec (rhs.m_module_spec)
-{
-}
-
-//----------------------------------------------------------------------
-// SearchFilterByModule assignment operator
-//----------------------------------------------------------------------
-const SearchFilterByModule&
+SearchFilterByModule&
SearchFilterByModule::operator=(const SearchFilterByModule& rhs)
{
m_target_sp = rhs.m_target_sp;
@@ -357,20 +310,12 @@ SearchFilterByModule::operator=(const SearchFilterByModule& rhs)
return *this;
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-SearchFilterByModule::~SearchFilterByModule()
-{
-}
+SearchFilterByModule::~SearchFilterByModule() = default;
bool
SearchFilterByModule::ModulePasses (const ModuleSP &module_sp)
{
- if (module_sp && FileSpec::Equal(module_sp->GetFileSpec(), m_module_spec, false))
- return true;
- else
- return false;
+ return (module_sp && FileSpec::Equal(module_sp->GetFileSpec(), m_module_spec, false));
}
bool
@@ -388,7 +333,6 @@ SearchFilterByModule::AddressPasses (Address &address)
return true;
}
-
bool
SearchFilterByModule::CompUnitPasses (FileSpec &fileSpec)
{
@@ -411,7 +355,7 @@ SearchFilterByModule::Search (Searcher &searcher)
{
SymbolContext empty_sc;
empty_sc.target_sp = m_target_sp;
- searcher.SearchCallback (*this, empty_sc, NULL, false);
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
}
// If the module file spec is a full path, then we can just find the one
@@ -419,8 +363,8 @@ SearchFilterByModule::Search (Searcher &searcher)
// find the ones that match the file name.
const ModuleList &target_modules = m_target_sp->GetImages();
- Mutex::Locker modules_locker (target_modules.GetMutex());
-
+ 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++)
{
@@ -463,7 +407,6 @@ SearchFilterByModule::GetFilterRequiredItems()
void
SearchFilterByModule::Dump (Stream *s) const
{
-
}
lldb::SearchFilterSP
@@ -478,10 +421,6 @@ SearchFilterByModule::DoCopyForBreakpoint (Breakpoint &breakpoint)
// Selects a shared library matching a given file spec
//----------------------------------------------------------------------
-//----------------------------------------------------------------------
-// SearchFilterByModuleList constructors
-//----------------------------------------------------------------------
-
SearchFilterByModuleList::SearchFilterByModuleList (const lldb::TargetSP &target_sp,
const FileSpecList &module_list) :
SearchFilter (target_sp),
@@ -489,20 +428,9 @@ SearchFilterByModuleList::SearchFilterByModuleList (const lldb::TargetSP &target
{
}
+SearchFilterByModuleList::SearchFilterByModuleList(const SearchFilterByModuleList& rhs) = default;
-//----------------------------------------------------------------------
-// SearchFilterByModuleList copy constructor
-//----------------------------------------------------------------------
-SearchFilterByModuleList::SearchFilterByModuleList(const SearchFilterByModuleList& rhs) :
- SearchFilter (rhs),
- m_module_spec_list (rhs.m_module_spec_list)
-{
-}
-
-//----------------------------------------------------------------------
-// SearchFilterByModuleList assignment operator
-//----------------------------------------------------------------------
-const SearchFilterByModuleList&
+SearchFilterByModuleList&
SearchFilterByModuleList::operator=(const SearchFilterByModuleList& rhs)
{
m_target_sp = rhs.m_target_sp;
@@ -510,12 +438,7 @@ SearchFilterByModuleList::operator=(const SearchFilterByModuleList& rhs)
return *this;
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-SearchFilterByModuleList::~SearchFilterByModuleList()
-{
-}
+SearchFilterByModuleList::~SearchFilterByModuleList() = default;
bool
SearchFilterByModuleList::ModulePasses (const ModuleSP &module_sp)
@@ -523,7 +446,8 @@ 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)
+ if (module_sp &&
+ m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) != UINT32_MAX)
return true;
else
return false;
@@ -548,7 +472,6 @@ SearchFilterByModuleList::AddressPasses (Address &address)
return true;
}
-
bool
SearchFilterByModuleList::CompUnitPasses (FileSpec &fileSpec)
{
@@ -571,7 +494,7 @@ SearchFilterByModuleList::Search (Searcher &searcher)
{
SymbolContext empty_sc;
empty_sc.target_sp = m_target_sp;
- searcher.SearchCallback (*this, empty_sc, NULL, false);
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
}
// If the module file spec is a full path, then we can just find the one
@@ -579,8 +502,8 @@ SearchFilterByModuleList::Search (Searcher &searcher)
// find the ones that match the file name.
const ModuleList &target_modules = m_target_sp->GetImages();
- Mutex::Locker modules_locker (target_modules.GetMutex());
-
+ 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++)
{
@@ -645,7 +568,6 @@ SearchFilterByModuleList::GetFilterRequiredItems()
void
SearchFilterByModuleList::Dump (Stream *s) const
{
-
}
lldb::SearchFilterSP
@@ -655,16 +577,11 @@ SearchFilterByModuleList::DoCopyForBreakpoint (Breakpoint &breakpoint)
return ret_sp;
}
-
//----------------------------------------------------------------------
// SearchFilterByModuleListAndCU:
// Selects a shared library matching a given file spec
//----------------------------------------------------------------------
-//----------------------------------------------------------------------
-// SearchFilterByModuleListAndCU constructors
-//----------------------------------------------------------------------
-
SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU (const lldb::TargetSP &target_sp,
const FileSpecList &module_list,
const FileSpecList &cu_list) :
@@ -673,20 +590,9 @@ SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU (const lldb::Target
{
}
+SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU(const SearchFilterByModuleListAndCU& rhs) = default;
-//----------------------------------------------------------------------
-// SearchFilterByModuleListAndCU copy constructor
-//----------------------------------------------------------------------
-SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU(const SearchFilterByModuleListAndCU& rhs) :
- SearchFilterByModuleList (rhs),
- m_cu_spec_list (rhs.m_cu_spec_list)
-{
-}
-
-//----------------------------------------------------------------------
-// SearchFilterByModuleListAndCU assignment operator
-//----------------------------------------------------------------------
-const SearchFilterByModuleListAndCU&
+SearchFilterByModuleListAndCU&
SearchFilterByModuleListAndCU::operator=(const SearchFilterByModuleListAndCU& rhs)
{
if (&rhs != this)
@@ -698,12 +604,7 @@ SearchFilterByModuleListAndCU::operator=(const SearchFilterByModuleListAndCU& rh
return *this;
}
-//----------------------------------------------------------------------
-// Destructor
-//----------------------------------------------------------------------
-SearchFilterByModuleListAndCU::~SearchFilterByModuleListAndCU()
-{
-}
+SearchFilterByModuleListAndCU::~SearchFilterByModuleListAndCU() = default;
bool
SearchFilterByModuleListAndCU::AddressPasses (Address &address)
@@ -711,7 +612,6 @@ SearchFilterByModuleListAndCU::AddressPasses (Address &address)
return true;
}
-
bool
SearchFilterByModuleListAndCU::CompUnitPasses (FileSpec &fileSpec)
{
@@ -747,7 +647,7 @@ SearchFilterByModuleListAndCU::Search (Searcher &searcher)
{
SymbolContext empty_sc;
empty_sc.target_sp = m_target_sp;
- searcher.SearchCallback (*this, empty_sc, NULL, false);
+ searcher.SearchCallback(*this, empty_sc, nullptr, false);
}
// If the module file spec is a full path, then we can just find the one
@@ -756,14 +656,15 @@ SearchFilterByModuleListAndCU::Search (Searcher &searcher)
ModuleList matching_modules;
const ModuleList &target_images = m_target_sp->GetImages();
- Mutex::Locker modules_locker(target_images.GetMutex());
-
+ 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)
+ 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;
@@ -844,7 +745,6 @@ SearchFilterByModuleListAndCU::GetFilterRequiredItems()
void
SearchFilterByModuleListAndCU::Dump (Stream *s) const
{
-
}
lldb::SearchFilterSP
@@ -853,4 +753,3 @@ SearchFilterByModuleListAndCU::DoCopyForBreakpoint (Breakpoint &breakpoint)
SearchFilterSP ret_sp(new SearchFilterByModuleListAndCU(*this));
return ret_sp;
}
-
diff --git a/source/Core/Section.cpp b/source/Core/Section.cpp
index cf1cbac8fd7c..9622cb78970c 100644
--- a/source/Core/Section.cpp
+++ b/source/Core/Section.cpp
@@ -14,75 +14,61 @@
#include "lldb/Target/Target.h"
#include "lldb/Utility/ConvertEnum.h"
-#include <limits>
-
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_target_byte_size(target_byte_size)
+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,
- 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_target_byte_size(target_byte_size)
+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());
@@ -254,7 +240,8 @@ Section::Dump (Stream *s, Target *target, uint32_t depth) const
range.Dump (s, 0);
}
- s->Printf("%c 0x%8.8" PRIx64 " 0x%8.8" PRIx64 " 0x%8.8x ", resolved ? ' ' : '*', m_file_offset, m_file_size, Get());
+ 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);
@@ -319,6 +306,33 @@ Section::Slide (addr_t slide_amount, bool slide_children)
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;
+}
+
+//------------------------------------------------------------------
+/// 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)
{
@@ -567,9 +581,12 @@ SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth)
if (show_header && !m_sections.empty())
{
s->Indent();
- s->Printf( "SectID Type %s Address File Off. File Size Flags Section Name\n", target_has_loaded_sections ? "Load" : "File");
+ 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");
+ s->PutCString("---------- ---------------- --------------------------------------- ---- ---------- ---------- "
+ "---------- ----------------------------\n");
}
diff --git a/source/Core/StreamCallback.cpp b/source/Core/StreamCallback.cpp
index d144b16755e7..9f0adee2a159 100644
--- a/source/Core/StreamCallback.cpp
+++ b/source/Core/StreamCallback.cpp
@@ -18,13 +18,8 @@
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 ()
+StreamCallback::StreamCallback(lldb::LogOutputCallback callback, void *baton)
+ : Stream(0, 4, eByteOrderBig), m_callback(callback), m_baton(baton), m_accumulated_data(), m_collection_mutex()
{
}
@@ -35,7 +30,7 @@ StreamCallback::~StreamCallback ()
StreamString &
StreamCallback::FindStreamForThread(lldb::tid_t cur_tid)
{
- Mutex::Locker locker(m_collection_mutex);
+ std::lock_guard<std::mutex> guard(m_collection_mutex);
collection::iterator iter = m_accumulated_data.find (cur_tid);
if (iter == m_accumulated_data.end())
{
diff --git a/source/Core/Timer.cpp b/source/Core/Timer.cpp
index e53ce2ec453d..f4cd33fc3cb5 100644
--- a/source/Core/Timer.cpp
+++ b/source/Core/Timer.cpp
@@ -8,12 +8,12 @@
//===----------------------------------------------------------------------===//
#include "lldb/Core/Timer.h"
+#include <algorithm>
#include <map>
+#include <mutex>
#include <vector>
-#include <algorithm>
#include "lldb/Core/Stream.h"
-#include "lldb/Host/Mutex.h"
#include "lldb/Host/Host.h"
#include <stdio.h>
@@ -39,15 +39,23 @@ namespace
std::atomic<bool> Timer::g_quiet(true);
std::atomic<unsigned> Timer::g_display_depth(0);
-std::mutex Timer::g_file_mutex;
-FILE* Timer::g_file = nullptr;
-
-static lldb::thread_key_t g_key;
+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 Mutex &
+static std::mutex &
GetCategoryMutex()
{
- static Mutex g_category_mutex(Mutex::eMutexTypeNormal);
+ static std::mutex g_category_mutex;
return g_category_mutex;
}
@@ -58,10 +66,17 @@ GetCategoryMap()
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)
{
@@ -72,24 +87,11 @@ GetTimerStackForCurrentThread ()
}
void
-ThreadSpecificCleanup (void *p)
-{
- delete (TimerStack *)p;
-}
-
-void
Timer::SetQuiet (bool value)
{
g_quiet = value;
}
-void
-Timer::Initialize ()
-{
- Timer::g_file = stdout;
- g_key = Host::ThreadLocalStorageCreate(ThreadSpecificCleanup);
-}
-
Timer::Timer (const char *category, const char *format, ...) :
m_category (category),
m_total_start (),
@@ -105,18 +107,18 @@ Timer::Timer (const char *category, const char *format, ...) :
{
if (g_quiet == false)
{
- std::lock_guard<std::mutex> lock(g_file_mutex);
+ std::lock_guard<std::mutex> lock(GetFileMutex());
// Indent
- ::fprintf (g_file, "%*s", stack->m_depth * TIMER_INDENT_AMOUNT, "");
+ ::fprintf(stdout, "%*s", stack->m_depth * TIMER_INDENT_AMOUNT, "");
// Print formatted string
va_list args;
va_start (args, format);
- ::vfprintf (g_file, format, args);
+ ::vfprintf(stdout, format, args);
va_end (args);
// Newline
- ::fprintf (g_file, "\n");
+ ::fprintf(stdout, "\n");
}
TimeValue start_time(TimeValue::Now());
m_total_start = start_time;
@@ -160,16 +162,13 @@ Timer::~Timer()
if (g_quiet == false)
{
- std::lock_guard<std::mutex> lock(g_file_mutex);
- ::fprintf (g_file,
- "%*s%.9f sec (%.9f sec)\n",
- (stack->m_depth - 1) *TIMER_INDENT_AMOUNT, "",
- total_nsec / 1000000000.0,
- timer_nsec / 1000000000.0);
+ 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.
- Mutex::Locker locker (GetCategoryMutex());
+ std::lock_guard<std::mutex> guard(GetCategoryMutex());
TimerCategoryMap &category_map = GetCategoryMap();
category_map[m_category] += timer_nsec_uint;
}
@@ -240,7 +239,7 @@ CategoryMapIteratorSortCriterion (const TimerCategoryMap::const_iterator& lhs, c
void
Timer::ResetCategoryTimes ()
{
- Mutex::Locker locker (GetCategoryMutex());
+ std::lock_guard<std::mutex> guard(GetCategoryMutex());
TimerCategoryMap &category_map = GetCategoryMap();
category_map.clear();
}
@@ -248,7 +247,7 @@ Timer::ResetCategoryTimes ()
void
Timer::DumpCategoryTimes (Stream *s)
{
- Mutex::Locker locker (GetCategoryMutex());
+ 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();
diff --git a/source/Core/UserSettingsController.cpp b/source/Core/UserSettingsController.cpp
index 837ff18721e2..6313fa1eb13a 100644
--- a/source/Core/UserSettingsController.cpp
+++ b/source/Core/UserSettingsController.cpp
@@ -108,3 +108,27 @@ Properties::GetSubProperty (const ExecutionContext *exe_ctx,
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;
+ }
+
+}
+
diff --git a/source/Core/Value.cpp b/source/Core/Value.cpp
index a5c48e823ace..eb250eb77e46 100644
--- a/source/Core/Value.cpp
+++ b/source/Core/Value.cpp
@@ -428,17 +428,16 @@ Value::GetValueAsData (ExecutionContext *exe_ctx,
uint32_t limit_byte_size = UINT32_MAX;
- if (ast_type.IsValid() && ast_type.IsScalarType())
+ if (ast_type.IsValid())
{
- uint64_t type_encoding_count = 0;
- lldb::Encoding type_encoding = ast_type.GetEncoding(type_encoding_count);
-
- if (type_encoding == eEncodingUint || type_encoding == eEncodingSint)
- limit_byte_size = ast_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
+ limit_byte_size = ast_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
}
- if (m_value.GetData (data, limit_byte_size))
- return error; // Success;
+ 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;
diff --git a/source/Core/ValueObject.cpp b/source/Core/ValueObject.cpp
index 6b1a6c590631..3e0a31833ef6 100644
--- a/source/Core/ValueObject.cpp
+++ b/source/Core/ValueObject.cpp
@@ -834,20 +834,20 @@ ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_
ExecutionContext exe_ctx (GetExecutionContextRef());
- child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
- idx,
- transparent_pointers,
- omit_empty_base_classes,
- ignore_array_bounds,
- child_name_str,
- child_byte_size,
- child_byte_offset,
- child_bitfield_bit_size,
- child_bitfield_bit_offset,
- child_is_base_class,
- child_is_deref_of_parent,
- this,
- language_flags);
+ child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex(&exe_ctx,
+ idx,
+ transparent_pointers,
+ omit_empty_base_classes,
+ ignore_array_bounds,
+ child_name_str,
+ child_byte_size,
+ child_byte_offset,
+ child_bitfield_bit_size,
+ child_bitfield_bit_offset,
+ child_is_base_class,
+ child_is_deref_of_parent,
+ this,
+ language_flags);
if (child_compiler_type)
{
if (synthetic_index)
@@ -1789,6 +1789,10 @@ ValueObject::DumpPrintableRepresentation(Stream& s,
addr_t
ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
{
+ // Can't take address of a bitfield
+ if (IsBitfield())
+ return LLDB_INVALID_ADDRESS;
+
if (!UpdateValueIfNeeded(false))
return LLDB_INVALID_ADDRESS;
@@ -2146,6 +2150,10 @@ ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_cre
synthetic_child_sp = GetSyntheticChild (index_const_str);
if (!synthetic_child_sp)
{
+ uint32_t bit_field_size = to - from + 1;
+ uint32_t bit_field_offset = from;
+ if (GetDataExtractor().GetByteOrder() == eByteOrderBig)
+ bit_field_offset = GetByteSize() * 8 - bit_field_size - bit_field_offset;
// We haven't made a synthetic array member for INDEX yet, so
// lets make one and cache it for any future reference.
ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
@@ -2153,8 +2161,8 @@ ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_cre
index_const_str,
GetByteSize(),
0,
- to-from+1,
- from,
+ bit_field_size,
+ bit_field_offset,
false,
false,
eAddressTypeInvalid,
@@ -2174,14 +2182,20 @@ ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_cre
}
ValueObjectSP
-ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
+ValueObject::GetSyntheticChildAtOffset(uint32_t offset,
+ const CompilerType& type,
+ bool can_create,
+ ConstString name_const_str)
{
ValueObjectSP synthetic_child_sp;
- char name_str[64];
- snprintf(name_str, sizeof(name_str), "@%i", offset);
- ConstString name_const_str(name_str);
+ if (name_const_str.IsEmpty())
+ {
+ char name_str[64];
+ snprintf(name_str, sizeof(name_str), "@%i", offset);
+ name_const_str.SetCString(name_str);
+ }
// Check if we have already created a synthetic array member in this
// valid object. If we have we will re-use it.
@@ -2217,13 +2231,19 @@ ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type
}
ValueObjectSP
-ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
+ValueObject::GetSyntheticBase (uint32_t offset,
+ const CompilerType& type,
+ bool can_create,
+ ConstString name_const_str)
{
ValueObjectSP synthetic_child_sp;
- char name_str[64];
- snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
- ConstString name_const_str(name_str);
+ if (name_const_str.IsEmpty())
+ {
+ char name_str[128];
+ snprintf(name_str, sizeof(name_str), "base%s@%i", type.GetTypeName().AsCString("<unknown>"), offset);
+ name_const_str.SetCString(name_str);
+ }
// Check if we have already created a synthetic array member in this
// valid object. If we have we will re-use it.
@@ -2530,7 +2550,7 @@ ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExp
if (!is_deref_of_parent)
{
ValueObject *non_base_class_parent = GetNonBaseClassParent();
- if (non_base_class_parent)
+ if (non_base_class_parent && !non_base_class_parent->GetName().IsEmpty())
{
CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
if (non_base_class_parent_compiler_type)
@@ -2797,6 +2817,7 @@ ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
}
expression_cstr++; // skip the -
}
+ LLVM_FALLTHROUGH;
case '.': // or fallthrough from ->
{
if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
diff --git a/source/Core/ValueObjectConstResult.cpp b/source/Core/ValueObjectConstResult.cpp
index a0f1737a861c..441cee540f7c 100644
--- a/source/Core/ValueObjectConstResult.cpp
+++ b/source/Core/ValueObjectConstResult.cpp
@@ -314,9 +314,12 @@ ValueObjectConstResult::Dereference (Error &error)
}
lldb::ValueObjectSP
-ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
+ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset,
+ const CompilerType& type,
+ bool can_create,
+ ConstString name_const_str)
{
- return m_impl.GetSyntheticChildAtOffset(offset, type, can_create);
+ return m_impl.GetSyntheticChildAtOffset(offset, type, can_create, name_const_str);
}
lldb::ValueObjectSP
diff --git a/source/Core/ValueObjectConstResultCast.cpp b/source/Core/ValueObjectConstResultCast.cpp
index 8f0c0f1522f2..1611503c4bf1 100644
--- a/source/Core/ValueObjectConstResultCast.cpp
+++ b/source/Core/ValueObjectConstResultCast.cpp
@@ -40,9 +40,10 @@ ValueObjectConstResultCast::Dereference (Error &error)
lldb::ValueObjectSP
ValueObjectConstResultCast::GetSyntheticChildAtOffset(uint32_t offset,
const CompilerType& type,
- bool can_create)
+ bool can_create,
+ ConstString name_const_str)
{
- return m_impl.GetSyntheticChildAtOffset(offset, type, can_create);
+ return m_impl.GetSyntheticChildAtOffset(offset, type, can_create, name_const_str);
}
lldb::ValueObjectSP
diff --git a/source/Core/ValueObjectConstResultChild.cpp b/source/Core/ValueObjectConstResultChild.cpp
index c93aedc22603..e3afa36351a8 100644
--- a/source/Core/ValueObjectConstResultChild.cpp
+++ b/source/Core/ValueObjectConstResultChild.cpp
@@ -57,9 +57,15 @@ ValueObjectConstResultChild::Dereference (Error &error)
}
lldb::ValueObjectSP
-ValueObjectConstResultChild::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
+ValueObjectConstResultChild::GetSyntheticChildAtOffset(uint32_t offset,
+ const CompilerType& type,
+ bool can_create,
+ ConstString name_const_str)
{
- return m_impl.GetSyntheticChildAtOffset(offset, type, can_create);
+ return m_impl.GetSyntheticChildAtOffset(offset,
+ type,
+ can_create,
+ name_const_str);
}
lldb::ValueObjectSP
diff --git a/source/Core/ValueObjectConstResultImpl.cpp b/source/Core/ValueObjectConstResultImpl.cpp
index 85ac3f2c5fe5..6db7f184da8f 100644
--- a/source/Core/ValueObjectConstResultImpl.cpp
+++ b/source/Core/ValueObjectConstResultImpl.cpp
@@ -117,12 +117,18 @@ ValueObjectConstResultImpl::CreateChildAtIndex (size_t idx, bool synthetic_array
}
lldb::ValueObjectSP
-ValueObjectConstResultImpl::GetSyntheticChildAtOffset (uint32_t offset, const CompilerType& type, bool can_create)
+ValueObjectConstResultImpl::GetSyntheticChildAtOffset (uint32_t offset,
+ const CompilerType& type,
+ bool can_create,
+ ConstString name_const_str)
{
if (m_impl_backend == NULL)
return lldb::ValueObjectSP();
- return m_impl_backend->ValueObject::GetSyntheticChildAtOffset(offset, type, can_create);
+ return m_impl_backend->ValueObject::GetSyntheticChildAtOffset(offset,
+ type,
+ can_create,
+ name_const_str);
}
lldb::ValueObjectSP
diff --git a/source/Core/ValueObjectDynamicValue.cpp b/source/Core/ValueObjectDynamicValue.cpp
index 0ac86a68f19f..65deba096d82 100644
--- a/source/Core/ValueObjectDynamicValue.cpp
+++ b/source/Core/ValueObjectDynamicValue.cpp
@@ -419,6 +419,22 @@ ValueObjectDynamicValue::GetPreferredDisplayLanguage ()
}
bool
+ValueObjectDynamicValue::IsSyntheticChildrenGenerated ()
+{
+ if (m_parent)
+ return m_parent->IsSyntheticChildrenGenerated();
+ return false;
+}
+
+void
+ValueObjectDynamicValue::SetSyntheticChildrenGenerated (bool b)
+{
+ if (m_parent)
+ m_parent->SetSyntheticChildrenGenerated(b);
+ this->ValueObject::SetSyntheticChildrenGenerated(b);
+}
+
+bool
ValueObjectDynamicValue::GetDeclaration (Declaration &decl)
{
if (m_parent)
diff --git a/source/Core/ValueObjectSyntheticFilter.cpp b/source/Core/ValueObjectSyntheticFilter.cpp
index 0ccc4385e3cc..f2f233711b9c 100644
--- a/source/Core/ValueObjectSyntheticFilter.cpp
+++ b/source/Core/ValueObjectSyntheticFilter.cpp
@@ -12,6 +12,8 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/ValueObjectSyntheticFilter.h"
+
+#include "lldb/Core/Log.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/TypeSynthetic.h"
@@ -61,17 +63,12 @@ ValueObjectSynthetic::ValueObjectSynthetic (ValueObject &parent, lldb::Synthetic
m_children_byindex(),
m_name_toindex(),
m_synthetic_children_count(UINT32_MAX),
+ m_synthetic_children_cache(),
m_parent_type_name(parent.GetTypeName()),
m_might_have_children(eLazyBoolCalculate),
m_provides_value(eLazyBoolCalculate)
{
-#ifdef FOOBAR
- std::string new_name(parent.GetName().AsCString());
- new_name += "$$__synth__";
- SetName (ConstString(new_name.c_str()));
-#else
SetName(parent.GetName());
-#endif
CopyValueData(m_parent);
CreateSynthFilter();
}
@@ -99,20 +96,41 @@ ValueObjectSynthetic::GetQualifiedTypeName()
ConstString
ValueObjectSynthetic::GetDisplayTypeName()
{
+ if (ConstString synth_name = m_synth_filter_ap->GetSyntheticTypeName())
+ return synth_name;
+
return m_parent->GetDisplayTypeName();
}
size_t
ValueObjectSynthetic::CalculateNumChildren(uint32_t max)
{
+ Log* log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS);
+
UpdateValueIfNeeded();
if (m_synthetic_children_count < UINT32_MAX)
return m_synthetic_children_count <= max ? m_synthetic_children_count : max;
if (max < UINT32_MAX)
- return m_synth_filter_ap->CalculateNumChildren(max);
+ {
+ size_t num_children = m_synth_filter_ap->CalculateNumChildren(max);
+ if (log)
+ log->Printf("[ValueObjectSynthetic::CalculateNumChildren] for VO of name %s and type %s, the filter returned %zu child values",
+ GetName().AsCString(),
+ GetTypeName().AsCString(),
+ num_children);
+ return num_children;
+ }
else
- return (m_synthetic_children_count = m_synth_filter_ap->CalculateNumChildren(max));
+ {
+ size_t num_children = (m_synthetic_children_count = m_synth_filter_ap->CalculateNumChildren(max));
+ if (log)
+ log->Printf("[ValueObjectSynthetic::CalculateNumChildren] for VO of name %s and type %s, the filter returned %zu child values",
+ GetName().AsCString(),
+ GetTypeName().AsCString(),
+ num_children);
+ return num_children;
+ }
}
lldb::ValueObjectSP
@@ -156,6 +174,8 @@ ValueObjectSynthetic::CreateSynthFilter ()
bool
ValueObjectSynthetic::UpdateValue ()
{
+ Log* log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS);
+
SetValueIsValid (false);
m_error.Clear();
@@ -172,6 +192,11 @@ ValueObjectSynthetic::UpdateValue ()
ConstString new_parent_type_name = m_parent->GetTypeName();
if (new_parent_type_name != m_parent_type_name)
{
+ if (log)
+ log->Printf("[ValueObjectSynthetic::UpdateValue] name=%s, type changed from %s to %s, recomputing synthetic filter",
+ GetName().AsCString(),
+ m_parent_type_name.AsCString(),
+ new_parent_type_name.AsCString());
m_parent_type_name = new_parent_type_name;
CreateSynthFilter();
}
@@ -179,6 +204,8 @@ ValueObjectSynthetic::UpdateValue ()
// let our backend do its update
if (m_synth_filter_ap->Update() == false)
{
+ if (log)
+ log->Printf("[ValueObjectSynthetic::UpdateValue] name=%s, synthetic filter said caches are stale - clearing", GetName().AsCString());
// filter said that cached values are stale
m_children_byindex.Clear();
m_name_toindex.Clear();
@@ -186,9 +213,15 @@ ValueObjectSynthetic::UpdateValue ()
// for a synthetic VO that might indeed happen, so we need to tell the upper echelons
// that they need to come back to us asking for children
m_children_count_valid = false;
+ m_synthetic_children_cache.Clear();
m_synthetic_children_count = UINT32_MAX;
m_might_have_children = eLazyBoolCalculate;
}
+ else
+ {
+ if (log)
+ log->Printf("[ValueObjectSynthetic::UpdateValue] name=%s, synthetic filter said caches are still valid", GetName().AsCString());
+ }
m_provides_value = eLazyBoolCalculate;
@@ -196,11 +229,17 @@ ValueObjectSynthetic::UpdateValue ()
if (synth_val && synth_val->CanProvideValue())
{
+ if (log)
+ log->Printf("[ValueObjectSynthetic::UpdateValue] name=%s, synthetic filter said it can provide a value", GetName().AsCString());
+
m_provides_value = eLazyBoolYes;
CopyValueData(synth_val.get());
}
else
{
+ if (log)
+ log->Printf("[ValueObjectSynthetic::UpdateValue] name=%s, synthetic filter said it will not provide a value", GetName().AsCString());
+
m_provides_value = eLazyBoolNo;
CopyValueData(m_parent);
}
@@ -212,6 +251,13 @@ ValueObjectSynthetic::UpdateValue ()
lldb::ValueObjectSP
ValueObjectSynthetic::GetChildAtIndex (size_t idx, bool can_create)
{
+ Log* log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS);
+
+ if (log)
+ log->Printf("[ValueObjectSynthetic::GetChildAtIndex] name=%s, retrieving child at index %zu",
+ GetName().AsCString(),
+ idx);
+
UpdateValueIfNeeded();
ValueObject *valobj;
@@ -219,18 +265,51 @@ ValueObjectSynthetic::GetChildAtIndex (size_t idx, bool can_create)
{
if (can_create && m_synth_filter_ap.get() != nullptr)
{
+ if (log)
+ log->Printf("[ValueObjectSynthetic::GetChildAtIndex] name=%s, child at index %zu not cached and will be created",
+ GetName().AsCString(),
+ idx);
+
lldb::ValueObjectSP synth_guy = m_synth_filter_ap->GetChildAtIndex (idx);
+
+ if (log)
+ log->Printf("[ValueObjectSynthetic::GetChildAtIndex] name=%s, child at index %zu created as %p (is synthetic: %s)",
+ GetName().AsCString(),
+ idx,
+ synth_guy.get(),
+ synth_guy.get() ? (synth_guy->IsSyntheticChildrenGenerated() ? "yes" : "no") : "no");
+
if (!synth_guy)
return synth_guy;
+
+ if (synth_guy->IsSyntheticChildrenGenerated())
+ m_synthetic_children_cache.AppendObject(synth_guy);
m_children_byindex.SetValueForKey(idx, synth_guy.get());
synth_guy->SetPreferredDisplayLanguageIfNeeded(GetPreferredDisplayLanguage());
return synth_guy;
}
else
+ {
+ if (log)
+ log->Printf("[ValueObjectSynthetic::GetChildAtIndex] name=%s, child at index %zu not cached and cannot be created (can_create = %s, synth_filter = %p)",
+ GetName().AsCString(),
+ idx,
+ can_create ? "yes" : "no",
+ m_synth_filter_ap.get());
+
return lldb::ValueObjectSP();
+ }
}
else
+ {
+ if (log)
+ log->Printf("[ValueObjectSynthetic::GetChildAtIndex] name=%s, child at index %zu cached as %p",
+ GetName().AsCString(),
+ idx,
+ valobj);
+
return valobj->GetSP();
+ }
}
lldb::ValueObjectSP
@@ -338,6 +417,22 @@ ValueObjectSynthetic::GetPreferredDisplayLanguage ()
}
bool
+ValueObjectSynthetic::IsSyntheticChildrenGenerated ()
+{
+ if (m_parent)
+ return m_parent->IsSyntheticChildrenGenerated();
+ return false;
+}
+
+void
+ValueObjectSynthetic::SetSyntheticChildrenGenerated (bool b)
+{
+ if (m_parent)
+ m_parent->SetSyntheticChildrenGenerated(b);
+ this->ValueObject::SetSyntheticChildrenGenerated(b);
+}
+
+bool
ValueObjectSynthetic::GetDeclaration (Declaration &decl)
{
if (m_parent)
diff --git a/source/Core/ValueObjectVariable.cpp b/source/Core/ValueObjectVariable.cpp
index 389b7c54243d..a29d858d169f 100644
--- a/source/Core/ValueObjectVariable.cpp
+++ b/source/Core/ValueObjectVariable.cpp
@@ -164,7 +164,15 @@ ValueObjectVariable::UpdateValue ()
loclist_base_load_addr = sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (target);
}
Value old_value(m_value);
- if (expr.Evaluate (&exe_ctx, NULL, NULL, NULL, loclist_base_load_addr, NULL, m_value, &m_error))
+ if (expr.Evaluate (&exe_ctx,
+ nullptr,
+ nullptr,
+ nullptr,
+ loclist_base_load_addr,
+ nullptr,
+ nullptr,
+ m_value,
+ &m_error))
{
m_resolved_value = m_value;
m_value.SetContext(Value::eContextTypeVariable, variable);