Fix Clang-tidy modernize-use-nullptr warnings in some files in source/Core; other minor fixes.

llvm-svn: 262441
This commit is contained in:
Eugene Zelenko 2016-03-02 01:09:03 +00:00
parent 5e4c46de6d
commit 896ddd03e9
8 changed files with 232 additions and 287 deletions

View File

@ -75,7 +75,7 @@ public:
}
bool operator< (const BroadcastEventSpec &rhs) const;
const BroadcastEventSpec &operator= (const BroadcastEventSpec &rhs);
BroadcastEventSpec &operator=(const BroadcastEventSpec &rhs);
private:
ConstString m_broadcaster_class;
@ -194,15 +194,11 @@ private:
bool operator () (const event_listener_key input) const
{
if (input.second == m_listener)
return true;
else
return false;
return (input.second == m_listener);
}
private:
const Listener *m_listener;
};
};
@ -463,4 +459,4 @@ private:
} // namespace lldb_private
#endif // liblldb_Broadcaster_h_
#endif // liblldb_Broadcaster_h_

View File

@ -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)
@ -545,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;
#if VERBOSE_OUTPUT
s->PutCString ("(objc_msgref *) -> { (func*)");
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
#else
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))
{
showed_info = true;
#if VERBOSE_OUTPUT
s->PutCString ("(objc_msgref *) -> { (func*)");
s->PutCString("), (char *)");
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
s->PutCString(" (");
#else
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))
{
#if VERBOSE_OUTPUT
s->PutCString("), (char *)");
so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
s->PutCString(" (");
#else
s->PutCString(", ");
#endif
ReadCStringFromMemory (exe_scope, so_addr, s);
}
#if VERBOSE_OUTPUT
s->PutCString(") }");
#else
s->PutCString(" }");
s->PutCString(", ");
#endif
ReadCStringFromMemory (exe_scope, so_addr, s);
}
#if VERBOSE_OUTPUT
s->PutCString(") }");
#else
s->PutCString(" }");
#endif
}
}
}
@ -645,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);
}
}
}
@ -690,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())
@ -749,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);
@ -797,6 +794,7 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
return false;
}
break;
case DumpStyleResolvedPointerDescription:
{
Process *process = exe_ctx.GetProcessPtr();
@ -897,7 +895,7 @@ Address::CalculateSymbolContextCompileUnit () const
return sc.comp_unit;
}
}
return NULL;
return nullptr;
}
Function *
@ -914,7 +912,7 @@ Address::CalculateSymbolContextFunction () const
return sc.function;
}
}
return NULL;
return nullptr;
}
Block *
@ -931,7 +929,7 @@ Address::CalculateSymbolContextBlock () const
return sc.block;
}
}
return NULL;
return nullptr;
}
Symbol *
@ -948,7 +946,7 @@ Address::CalculateSymbolContextSymbol () const
return sc.symbol;
}
}
return NULL;
return nullptr;
}
bool
@ -985,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)
@ -1021,7 +1018,6 @@ Address::CompareModulePointerAndOffset (const Address& a, const Address& b)
return 0;
}
size_t
Address::MemorySize () const
{
@ -1030,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
@ -1086,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)
@ -1094,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
@ -1129,4 +1124,3 @@ Address::SetLoadAddress (lldb::addr_t load_addr, Target *target)
m_offset = load_addr;
return false;
}

View File

@ -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());
}

View File

@ -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[] =
@ -156,7 +156,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 +173,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 +186,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 +200,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 +263,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),
@ -346,7 +343,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 +353,7 @@ FindArchDefinition (ArchitectureType arch_type)
if (def->type == arch_type)
return def;
}
return NULL;
return nullptr;
}
// Get an architecture definition by name.
@ -369,7 +365,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 +373,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 +390,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 +405,7 @@ FindArchDefinitionEntry (const ArchDefinition *def, ArchSpec::Core core)
if (entries[i].core == core)
return &entries[i];
}
return NULL;
return nullptr;
}
//===----------------------------------------------------------------------===//
@ -467,9 +463,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 +495,6 @@ ArchSpec::Clear()
//===----------------------------------------------------------------------===//
// Predicates.
const char *
ArchSpec::GetArchitectureName () const
{
@ -730,7 +723,6 @@ ArchSpec::SetTriple (const llvm::Triple &triple)
Clear();
}
return IsValid();
}
@ -740,7 +732,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 == '.')))
@ -779,6 +771,7 @@ ParseMachCPUDashSubtypeTriple (const char *triple_cstr, ArchSpec &arch)
}
return false;
}
bool
ArchSpec::SetTriple (const char *triple_cstr)
{
@ -1446,7 +1439,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.
@ -1463,7 +1456,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.
@ -1482,7 +1475,7 @@ ArchSpec::GetStopInfoOverrideCallback () const
const llvm::Triple::ArchType machine = GetMachine();
if (machine == llvm::Triple::arm)
return StopInfoOverrideCallbackTypeARM;
return NULL;
return nullptr;
}
bool

View File

@ -47,7 +47,7 @@ Broadcaster::~Broadcaster()
void
Broadcaster::CheckInWithManager ()
{
if (m_manager != NULL)
if (m_manager != nullptr)
{
m_manager->SignUpListenersForBroadcaster(*this);
}
@ -68,6 +68,7 @@ Broadcaster::Clear()
m_listeners.clear();
}
const ConstString &
Broadcaster::GetBroadcasterName ()
{
@ -108,13 +109,12 @@ Broadcaster::GetEventNames (Stream &s, uint32_t event_mask, bool prefix_with_bro
void
Broadcaster::AddInitialEventsToListener (Listener *listener, uint32_t requested_events)
{
}
uint32_t
Broadcaster::AddListener (Listener* listener, uint32_t event_mask)
{
if (listener == NULL)
if (listener == nullptr)
return 0;
Mutex::Locker locker(m_listeners_mutex);
@ -165,7 +165,7 @@ Broadcaster::EventTypeHasListeners (uint32_t event_type)
{
Mutex::Locker locker (m_listeners_mutex);
if (m_hijacking_listeners.size() > 0 && event_type & m_hijacking_masks.back())
if (!m_hijacking_listeners.empty() && event_type & m_hijacking_masks.back())
return true;
if (m_listeners.empty())
@ -216,8 +216,8 @@ Broadcaster::BroadcastEventIfUnique (EventSP &event_sp)
void
Broadcaster::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
@ -227,13 +227,13 @@ Broadcaster::PrivateBroadcastEvent (EventSP &event_sp, bool unique)
Mutex::Locker event_types_locker(m_listeners_mutex);
Listener *hijacking_listener = NULL;
Listener *hijacking_listener = nullptr;
if (!m_hijacking_listeners.empty())
{
assert (!m_hijacking_masks.empty());
hijacking_listener = m_hijacking_listeners.back();
if ((event_type & m_hijacking_masks.back()) == 0)
hijacking_listener = NULL;
hijacking_listener = nullptr;
}
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS));
@ -257,7 +257,6 @@ Broadcaster::PrivateBroadcastEvent (EventSP &event_sp, bool unique)
{
collection::iterator pos, end = m_listeners.end();
// Iterate through all listener/mask pairs
for (pos = m_listeners.begin(); pos != end; ++pos)
{
@ -341,11 +340,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,18 +355,12 @@ BroadcastEventSpec::operator< (const BroadcastEventSpec &rhs) const
}
}
const BroadcastEventSpec &
BroadcastEventSpec::operator= (const BroadcastEventSpec &rhs)
{
m_broadcaster_class = rhs.m_broadcaster_class;
m_event_bits = rhs.m_event_bits;
return *this;
}
BroadcastEventSpec &
BroadcastEventSpec::operator=(const BroadcastEventSpec &rhs) = default;
BroadcasterManager::BroadcasterManager() :
m_manager_mutex(Mutex::eMutexTypeRecursive)
{
}
uint32_t
@ -412,7 +401,7 @@ BroadcasterManager::UnregisterListenerForEvents (Listener &listener, BroadcastEv
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);
@ -453,7 +442,7 @@ BroadcasterManager::GetListenerForEventSpec (BroadcastEventSpec event_spec) cons
if (iter != end_iter)
return (*iter).second;
else
return NULL;
return nullptr;
}
void
@ -462,11 +451,10 @@ BroadcasterManager::RemoveListener (Listener &listener)
Mutex::Locker locker(m_manager_mutex);
ListenerMatches predicate (listener);
if (m_listeners.erase (&listener) == 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);
@ -502,5 +490,4 @@ BroadcasterManager::Clear ()
(*iter)->BroadcasterManagerWillDestruct(this);
m_listeners.clear();
m_event_map.clear();
}

View File

@ -9,6 +9,8 @@
// C Includes
// C++ Includes
#include <cstring>
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Communication.h"
@ -19,7 +21,6 @@
#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,21 +32,18 @@ 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),
Broadcaster(nullptr, 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)
m_bytes_mutex(Mutex::eMutexTypeRecursive),
m_write_mutex(Mutex::eMutexTypeNormal),
m_synchronize_mutex(Mutex::eMutexTypeNormal),
m_callback(nullptr),
m_callback_baton(nullptr),
m_close_on_eof(true)
{
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
@ -62,9 +60,6 @@ Communication::Communication(const char *name) :
CheckInWithManager();
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
Communication::~Communication()
{
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
@ -76,9 +71,9 @@ Communication::~Communication()
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.");
@ -174,7 +167,7 @@ Communication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, Connectio
Listener listener ("Communication::Read");
listener.StartListeningForEvents (this, eBroadcastBitReadThreadGotBytes | eBroadcastBitReadThreadDidExit);
EventSP event_sp;
while (listener.WaitForEvent (timeout_time.IsValid() ? &timeout_time : NULL, event_sp))
while (listener.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,7 +199,6 @@ 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)
{
@ -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,7 +233,6 @@ 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());
@ -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();
@ -287,11 +277,11 @@ size_t
Communication::GetCachedBytes (void *dst, size_t dst_len)
{
Mutex::Locker locker(m_bytes_mutex);
if (m_bytes.size() > 0)
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,7 +308,7 @@ 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);
m_bytes.append ((const char *)bytes, len);
@ -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
@ -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;
@ -454,14 +439,14 @@ Communication::SynchronizeWithReadThread ()
// Wait for the synchronization event.
EventSP event_sp;
listener.WaitForEvent(NULL, event_sp);
listener.WaitForEvent(nullptr, event_sp);
}
void
Communication::SetConnection (Connection *connection)
{
Disconnect (NULL);
StopReadThread(NULL);
Disconnect(nullptr);
StopReadThread(nullptr);
m_connection_sp.reset(connection);
}

View File

@ -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,9 +22,13 @@
#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"
@ -42,7 +45,7 @@ ConnectionSharedMemory::ConnectionSharedMemory () :
ConnectionSharedMemory::~ConnectionSharedMemory ()
{
Disconnect (NULL);
Disconnect(nullptr);
}
bool
@ -136,7 +139,7 @@ ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error
if (create) {
handle = CreateFileMapping(
INVALID_HANDLE_VALUE,
NULL,
nullptr,
PAGE_READWRITE,
llvm::Hi_32(size),
llvm::Lo_32(size),
@ -159,7 +162,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;
}

View File

@ -1,4 +1,4 @@
//===-- DataEncoder.cpp ---------------------------------------*- C++ -*-===//
//===-- DataEncoder.cpp -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -9,11 +9,16 @@
#include "lldb/Core/DataEncoder.h"
#include <assert.h>
#include <stddef.h>
// C Includes
// C++ Includes
#include <cassert>
#include <cstddef>
#include <limits>
// Other libraries and framework includes
#include "llvm/Support/MathExtras.h"
// Project includes
#include "lldb/Core/DataBuffer.h"
#include "lldb/Host/Endian.h"
@ -25,6 +30,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 +65,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 +94,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 +113,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 +127,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 +158,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 +188,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)
@ -232,7 +233,7 @@ DataEncoder::PutU8 (uint32_t offset, uint8_t value)
m_start[offset] = value;
return offset + 1;
}
return UINT32_MAX;
return std::numeric_limits<uint32_t>::max();
}
uint32_t
@ -247,7 +248,7 @@ DataEncoder::PutU16 (uint32_t offset, uint16_t value)
return offset + sizeof (value);
}
return UINT32_MAX;
return std::numeric_limits<uint32_t>::max();
}
uint32_t
@ -262,7 +263,7 @@ DataEncoder::PutU32 (uint32_t offset, uint32_t value)
return offset + sizeof (value);
}
return UINT32_MAX;
return std::numeric_limits<uint32_t>::max();
}
uint32_t
@ -277,7 +278,7 @@ DataEncoder::PutU64 (uint32_t offset, uint64_t value)
return offset + sizeof (value);
}
return UINT32_MAX;
return std::numeric_limits<uint32_t>::max();
}
//----------------------------------------------------------------------
@ -303,13 +304,13 @@ DataEncoder::PutMaxU64 (uint32_t offset, uint32_t byte_size, uint64_t value)
assert(!"GetMax64 unhandled case!");
break;
}
return UINT32_MAX;
return std::numeric_limits<uint32_t>::max();
}
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))
@ -317,7 +318,7 @@ DataEncoder::PutData (uint32_t offset, const void *src, uint32_t src_len)
memcpy (m_start + offset, src, src_len);
return offset + src_len;
}
return UINT32_MAX;
return std::numeric_limits<uint32_t>::max();
}
uint32_t
@ -329,7 +330,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;
return std::numeric_limits<uint32_t>::max();
}