From: Eugene Zelenko Date: Thu, 10 Mar 2016 23:57:12 +0000 (+0000) Subject: Fix Clang-tidy modernize-use-nullptr warnings in some files in source/Core; other... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a74f37a5996e301dfc9ce749d4be59b8ea5c776f;p=platform%2Fupstream%2Fllvm.git Fix Clang-tidy modernize-use-nullptr warnings in some files in source/Core; other minor fixes. llvm-svn: 263174 --- diff --git a/lldb/source/Core/ConstString.cpp b/lldb/source/Core/ConstString.cpp index b2f61dd..f983f14 100644 --- a/lldb/source/Core/ConstString.cpp +++ b/lldb/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 +#include + +// Other libraries and framework includes #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/RWMutex.h" -#include -#include +// 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 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 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 (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; @@ -306,18 +313,18 @@ ConstString::Compare(const ConstString &lhs, const ConstString &rhs, const bool } 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); } } @@ -327,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(sizeof(void*) * 2), diff --git a/lldb/source/Core/Error.cpp b/lldb/source/Core/Error.cpp index ce05582..97c2c4c 100644 --- a/lldb/source/Core/Error.cpp +++ b/lldb/source/Core/Error.cpp @@ -13,13 +13,15 @@ #endif // C++ Includes +#include +#include + // 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 -#include 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/lldb/source/Core/Event.cpp b/lldb/source/Core/Event.cpp index 8e20063..a8063bf 100644 --- a/lldb/source/Core/Event.cpp +++ b/lldb/source/Core/Event.cpp @@ -9,6 +9,8 @@ // C Includes // C++ Includes +#include + // Other libraries and framework includes // Project includes #include "lldb/Core/Event.h" @@ -19,14 +21,10 @@ #include "lldb/Core/Stream.h" #include "lldb/Host/Endian.h" #include "lldb/Target/Process.h" -#include using namespace lldb; using namespace lldb_private; -//---------------------------------------------------------------------- -// Event constructor -//---------------------------------------------------------------------- Event::Event (Broadcaster *broadcaster, uint32_t event_type, EventData *data) : m_broadcaster_wp (broadcaster->GetBroadcasterImpl()), m_type (event_type), @@ -40,13 +38,7 @@ Event::Event(uint32_t event_type, EventData *data) : { } - -//---------------------------------------------------------------------- -// Event destructor -//---------------------------------------------------------------------- -Event::~Event () -{ -} +Event::~Event() = default; void Event::Dump (Stream *s) const @@ -77,30 +69,26 @@ Event::Dump (Stream *s) const s->Printf("%p Event: broadcaster = NULL, type = 0x%8.8x, data = ", static_cast(this), m_type); - if (m_data_ap.get() == NULL) - s->Printf (""); - else + if (m_data_ap) { s->PutChar('{'); m_data_ap->Dump (s); s->PutChar('}'); } + else + s->Printf (""); } void Event::DoOnRemoval () { - if (m_data_ap.get()) + if (m_data_ap) m_data_ap->DoOnRemoval (this); } -EventData::EventData() -{ -} +EventData::EventData() = default; -EventData::~EventData() -{ -} +EventData::~EventData() = default; void EventData::Dump (Stream *s) const @@ -125,9 +113,7 @@ EventDataBytes::EventDataBytes (const void *src, size_t src_len) : SetBytes (src, src_len); } -EventDataBytes::~EventDataBytes() -{ -} +EventDataBytes::~EventDataBytes() = default; const ConstString & EventDataBytes::GetFlavorString () @@ -150,10 +136,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); } } @@ -161,9 +147,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 @@ -175,7 +159,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(); @@ -184,27 +168,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; } @@ -212,13 +195,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 (event_data); } - return NULL; + return nullptr; } void @@ -226,5 +209,3 @@ EventDataBytes::SwapBytes (std::string &new_bytes) { m_bytes.swap (new_bytes); } - - diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp index 7226a4f..e2097cc 100644 --- a/lldb/source/Core/FormatEntity.cpp +++ b/lldb/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, 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 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)); @@ -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 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; ichildren + 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 p = format_str.split('.'); const size_t n = parent->num_children; - for (size_t i=0; ichildren + 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 + // Other libraries and framework includes // Project includes #include "lldb/Core/Broadcaster.h" @@ -18,7 +20,6 @@ #include "lldb/Core/StreamString.h" #include "lldb/Core/Event.h" #include "lldb/Host/TimeValue.h" -#include using namespace lldb; using namespace lldb_private; @@ -32,14 +33,12 @@ namespace bool operator() (const BroadcasterManagerWP input_wp) const { BroadcasterManagerSP input_sp = input_wp.lock(); - if (input_sp && input_sp == m_manager_sp) - return true; - else - return false; + return (input_sp && input_sp == m_manager_sp); } + BroadcasterManagerSP m_manager_sp; }; -} +} // anonymous namespace Listener::Listener(const char *name) : m_name (name), @@ -50,7 +49,7 @@ Listener::Listener(const char *name) : m_cond_wait() { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); - if (log) + if (log != nullptr) log->Printf ("%p Listener::Listener('%s')", static_cast(this), m_name.c_str()); } @@ -88,7 +87,7 @@ Listener::Clear() manager_sp->RemoveListener(this); } - if (log) + if (log != nullptr) log->Printf ("%p Listener::~Listener('%s')", static_cast(this), m_name.c_str()); } @@ -108,19 +107,14 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t event_mask uint32_t acquired_mask = broadcaster->AddListener (this->shared_from_this(), event_mask); - if (event_mask != acquired_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(this), static_cast(broadcaster), event_mask, acquired_mask, m_name.c_str()); return acquired_mask; - } return 0; } @@ -142,7 +136,7 @@ Listener::StartListeningForEvents (Broadcaster* broadcaster, uint32_t 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(&callback); log->Printf ("%p Listener::StartListeningForEvents (broadcaster = %p, mask = 0x%8.8x, callback = %p, user_data = %p) acquired_mask = 0x%8.8x for %s", @@ -200,7 +194,6 @@ Listener::BroadcasterWillDestruct (Broadcaster *broadcaster) if (m_events.empty()) m_cond_wait.SetValue (false, eBroadcastNever); - } } @@ -221,7 +214,7 @@ 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(this), m_name.c_str(), static_cast(event_sp.get())); @@ -244,15 +237,11 @@ public: 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 @@ -275,7 +264,7 @@ public: { bool found_source = false; const ConstString &event_broadcaster_name = event_sp->GetBroadcaster()->GetBroadcasterName(); - for (uint32_t i=0; iPrintf ("%p '%s' Listener::FindNextEventInternal(broadcaster=%p, broadcaster_names=%p[%u], event_type_mask=0x%8.8x, remove=%i) event %p", static_cast(this), GetName(), static_cast(broadcaster), @@ -369,39 +356,35 @@ Event * Listener::PeekAtNextEvent () { EventSP event_sp; - if (FindNextEventInternal (NULL, NULL, 0, 0, event_sp, false)) + if (FindNextEventInternal(nullptr, nullptr, 0, 0, event_sp, false)) return event_sp.get(); - return NULL; + return nullptr; } Event * Listener::PeekAtNextEventForBroadcaster (Broadcaster *broadcaster) { EventSP event_sp; - if (FindNextEventInternal (broadcaster, NULL, 0, 0, event_sp, false)) + if (FindNextEventInternal(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) { EventSP event_sp; - if (FindNextEventInternal (broadcaster, NULL, 0, event_type_mask, event_sp, false)) + if (FindNextEventInternal(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); } @@ -409,43 +392,38 @@ Listener::GetNextEventInternal 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(this), static_cast(timeout), m_name.c_str()); - while (1) + while (true) { // 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 @@ -472,7 +450,7 @@ Listener::WaitForEventsInternal else if (timed_out) { log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS); - if (log) + if (log != nullptr) log->Printf ("%p Listener::WaitForEventsInternal() timed out for %s", static_cast(this), m_name.c_str()); break; @@ -480,7 +458,7 @@ Listener::WaitForEventsInternal else { log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS); - if (log) + if (log != nullptr) log->Printf ("%p Listener::WaitForEventsInternal() unknown error for %s", static_cast(this), m_name.c_str()); break; @@ -491,32 +469,26 @@ 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); } size_t @@ -537,7 +509,7 @@ Listener::HandleBroadcastEvent (EventSP &event_sp) 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; @@ -582,7 +554,6 @@ Listener::StopListeningForEventSpec (BroadcasterManagerSP manager_sp, Mutex::Locker locker(m_broadcasters_mutex); return manager_sp->UnregisterListenerForEvents (this->shared_from_this(), event_spec); - } ListenerSP diff --git a/lldb/source/Core/Log.cpp b/lldb/source/Core/Log.cpp index 8d415bd..9a356e6 100644 --- a/lldb/source/Core/Log.cpp +++ b/lldb/source/Core/Log.cpp @@ -8,15 +8,18 @@ //===----------------------------------------------------------------------===// // C Includes -#include -#include -#include - // C++ Includes +#include +#include +#include #include #include // 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" @@ -29,9 +32,6 @@ #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() @@ -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 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;