diff options
Diffstat (limited to 'source/Breakpoint')
-rw-r--r-- | source/Breakpoint/Breakpoint.cpp | 55 | ||||
-rw-r--r-- | source/Breakpoint/BreakpointID.cpp | 17 | ||||
-rw-r--r-- | source/Breakpoint/BreakpointIDList.cpp | 20 | ||||
-rw-r--r-- | source/Breakpoint/BreakpointLocation.cpp | 105 | ||||
-rw-r--r-- | source/Breakpoint/BreakpointLocationList.cpp | 16 | ||||
-rw-r--r-- | source/Breakpoint/BreakpointOptions.cpp | 29 | ||||
-rw-r--r-- | source/Breakpoint/BreakpointResolverAddress.cpp | 90 | ||||
-rw-r--r-- | source/Breakpoint/BreakpointResolverName.cpp | 103 | ||||
-rw-r--r-- | source/Breakpoint/BreakpointSite.cpp | 29 | ||||
-rw-r--r-- | source/Breakpoint/StoppointCallbackContext.cpp | 7 | ||||
-rw-r--r-- | source/Breakpoint/Watchpoint.cpp | 83 | ||||
-rw-r--r-- | source/Breakpoint/WatchpointList.cpp | 7 | ||||
-rw-r--r-- | source/Breakpoint/WatchpointOptions.cpp | 26 |
13 files changed, 339 insertions, 248 deletions
diff --git a/source/Breakpoint/Breakpoint.cpp b/source/Breakpoint/Breakpoint.cpp index 23d484f0f68a3..54f67b90220a3 100644 --- a/source/Breakpoint/Breakpoint.cpp +++ b/source/Breakpoint/Breakpoint.cpp @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// - // C Includes // C++ Includes // Other libraries and framework includes -// Project includes +#include "llvm/Support/Casting.h" +// Project includes #include "lldb/Core/Address.h" #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Breakpoint/BreakpointLocation.h" @@ -31,7 +31,6 @@ #include "lldb/Symbol/SymbolContext.h" #include "lldb/Target/Target.h" #include "lldb/Target/ThreadSpec.h" -#include "llvm/Support/Casting.h" using namespace lldb; using namespace lldb_private; @@ -83,9 +82,7 @@ Breakpoint::Breakpoint (Target &new_target, Breakpoint &source_bp) : //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- -Breakpoint::~Breakpoint() -{ -} +Breakpoint::~Breakpoint() = default; const lldb::TargetSP Breakpoint::GetTargetSP () @@ -236,7 +233,7 @@ Breakpoint::SetThreadID (lldb::tid_t thread_id) lldb::tid_t Breakpoint::GetThreadID () const { - if (m_options.GetThreadSpecNoCreate() == NULL) + if (m_options.GetThreadSpecNoCreate() == nullptr) return LLDB_INVALID_THREAD_ID; else return m_options.GetThreadSpecNoCreate()->GetTID(); @@ -255,7 +252,7 @@ Breakpoint::SetThreadIndex (uint32_t index) uint32_t Breakpoint::GetThreadIndex() const { - if (m_options.GetThreadSpecNoCreate() == NULL) + if (m_options.GetThreadSpecNoCreate() == nullptr) return 0; else return m_options.GetThreadSpecNoCreate()->GetIndex(); @@ -264,7 +261,7 @@ Breakpoint::GetThreadIndex() const void Breakpoint::SetThreadName (const char *thread_name) { - if (m_options.GetThreadSpec()->GetName() != NULL + if (m_options.GetThreadSpec()->GetName() != nullptr && ::strcmp (m_options.GetThreadSpec()->GetName(), thread_name) == 0) return; @@ -275,8 +272,8 @@ Breakpoint::SetThreadName (const char *thread_name) const char * Breakpoint::GetThreadName () const { - if (m_options.GetThreadSpecNoCreate() == NULL) - return NULL; + if (m_options.GetThreadSpecNoCreate() == nullptr) + return nullptr; else return m_options.GetThreadSpecNoCreate()->GetName(); } @@ -284,7 +281,7 @@ Breakpoint::GetThreadName () const void Breakpoint::SetQueueName (const char *queue_name) { - if (m_options.GetThreadSpec()->GetQueueName() != NULL + if (m_options.GetThreadSpec()->GetQueueName() != nullptr && ::strcmp (m_options.GetThreadSpec()->GetQueueName(), queue_name) == 0) return; @@ -295,8 +292,8 @@ Breakpoint::SetQueueName (const char *queue_name) const char * Breakpoint::GetQueueName () const { - if (m_options.GetThreadSpecNoCreate() == NULL) - return NULL; + if (m_options.GetThreadSpecNoCreate() == nullptr) + return nullptr; else return m_options.GetThreadSpecNoCreate()->GetQueueName(); } @@ -456,7 +453,6 @@ Breakpoint::ModulesChanged (ModuleList &module_list, bool load, bool delete_loca if (!seen) new_modules.AppendIfNeeded (module_sp); - } if (new_modules.GetSize() > 0) @@ -474,7 +470,7 @@ Breakpoint::ModulesChanged (ModuleList &module_list, bool load, bool delete_loca removed_locations_event = new BreakpointEventData (eBreakpointEventTypeLocationsRemoved, shared_from_this()); else - removed_locations_event = NULL; + removed_locations_event = nullptr; size_t num_modules = module_list.GetSize(); for (size_t i = 0; i < num_modules; i++) @@ -502,7 +498,6 @@ Breakpoint::ModulesChanged (ModuleList &module_list, bool load, bool delete_loca } if (delete_locations) locations_to_remove.Add (break_loc_sp); - } } @@ -568,7 +563,7 @@ SymbolContextsMightBeEquivalent(SymbolContext &old_sc, SymbolContext &new_sc) } return equivalent_scs; } -} +} // anonymous namespace void Breakpoint::ModuleReplaced (ModuleSP old_module_sp, ModuleSP new_module_sp) @@ -740,7 +735,7 @@ Breakpoint::ModuleReplaced (ModuleSP old_module_sp, ModuleSP new_module_sp) locations_event = new BreakpointEventData (eBreakpointEventTypeLocationsRemoved, shared_from_this()); else - locations_event = NULL; + locations_event = nullptr; for (BreakpointLocationSP loc_sp : locations_to_remove.BreakpointLocations()) { @@ -804,7 +799,7 @@ Breakpoint::AddName (const char *new_name, Error &error) void Breakpoint::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_locations) { - assert (s != NULL); + assert (s != nullptr); if (!m_kind_description.empty()) { @@ -849,6 +844,9 @@ Breakpoint::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_l GetOptions()->GetDescription(s, level); + if (m_precondition_sp) + m_precondition_sp->GetDescription(*s, level); + if (level == lldb::eDescriptionLevelFull) { if (!m_name_list.empty()) @@ -876,7 +874,7 @@ Breakpoint::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_l { s->Printf ("no locations (pending)."); } - else if (num_locations == 1 && show_locations == false) + else if (num_locations == 1 && !show_locations) { // There is only one location, so we'll just print that location information. GetLocationAtIndex(0)->GetDescription(s, level); @@ -922,7 +920,6 @@ Breakpoint::GetResolverDescription (Stream *s) m_resolver_sp->GetDescription (s); } - bool Breakpoint::GetMatchingFileLine (const ConstString &filename, uint32_t line_number, BreakpointLocationCollection &loc_coll) { @@ -965,7 +962,7 @@ Breakpoint::BreakpointPrecondition::EvaluatePrecondition(StoppointCallbackContex } void -Breakpoint::BreakpointPrecondition::DescribePrecondition(Stream &stream, lldb::DescriptionLevel level) +Breakpoint::BreakpointPrecondition::GetDescription(Stream &stream, lldb::DescriptionLevel level) { } @@ -993,8 +990,7 @@ Breakpoint::SendBreakpointChangedEvent (lldb::BreakpointEventType eventKind) void Breakpoint::SendBreakpointChangedEvent (BreakpointEventData *data) { - - if (data == NULL) + if (data == nullptr) return; if (!m_being_created @@ -1013,9 +1009,7 @@ Breakpoint::BreakpointEventData::BreakpointEventData (BreakpointEventType sub_ty { } -Breakpoint::BreakpointEventData::~BreakpointEventData () -{ -} +Breakpoint::BreakpointEventData::~BreakpointEventData() = default; const ConstString & Breakpoint::BreakpointEventData::GetFlavorString () @@ -1030,7 +1024,6 @@ Breakpoint::BreakpointEventData::GetFlavor () const return BreakpointEventData::GetFlavorString (); } - BreakpointSP & Breakpoint::BreakpointEventData::GetBreakpoint () { @@ -1057,7 +1050,7 @@ Breakpoint::BreakpointEventData::GetEventDataFromEvent (const Event *event) if (event_data && event_data->GetFlavor() == BreakpointEventData::GetFlavorString()) return static_cast <const BreakpointEventData *> (event->GetData()); } - return NULL; + return nullptr; } BreakpointEventType @@ -1065,7 +1058,7 @@ Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (const EventSP { const BreakpointEventData *data = GetEventDataFromEvent (event_sp.get()); - if (data == NULL) + if (data == nullptr) return eBreakpointEventTypeInvalidType; else return data->GetBreakpointEventType(); diff --git a/source/Breakpoint/BreakpointID.cpp b/source/Breakpoint/BreakpointID.cpp index 31823886dd9fb..81a3dfe50d9b8 100644 --- a/source/Breakpoint/BreakpointID.cpp +++ b/source/Breakpoint/BreakpointID.cpp @@ -7,14 +7,12 @@ // //===----------------------------------------------------------------------===// - // C Includes #include <stdio.h> // C++ Includes // Other libraries and framework includes // Project includes - #include "lldb/Breakpoint/BreakpointID.h" #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Core/Stream.h" @@ -29,11 +27,9 @@ BreakpointID::BreakpointID (break_id_t bp_id, break_id_t loc_id) : { } -BreakpointID::~BreakpointID () -{ -} +BreakpointID::~BreakpointID() = default; -const char *BreakpointID::g_range_specifiers[] = { "-", "to", "To", "TO", NULL }; +const char *BreakpointID::g_range_specifiers[] = { "-", "to", "To", "TO", nullptr }; // Tells whether or not STR is valid to use between two strings representing breakpoint IDs, to // indicate a range of breakpoint IDs. This is broken out into a separate function so that we can @@ -43,7 +39,7 @@ bool BreakpointID::IsRangeIdentifier (const char *str) { int specifier_count = 0; - for (int i = 0; g_range_specifiers[i] != NULL; ++i) + for (int i = 0; g_range_specifiers[i] != nullptr; ++i) ++specifier_count; for (int i = 0; i < specifier_count; ++i) @@ -62,10 +58,7 @@ BreakpointID::IsValidIDExpression (const char *str) break_id_t loc_id; BreakpointID::ParseCanonicalReference (str, &bp_id, &loc_id); - if (bp_id == LLDB_INVALID_BREAK_ID) - return false; - else - return true; + return (bp_id != LLDB_INVALID_BREAK_ID); } void @@ -99,7 +92,7 @@ BreakpointID::ParseCanonicalReference (const char *input, break_id_t *break_id_p *break_id_ptr = LLDB_INVALID_BREAK_ID; *break_loc_id_ptr = LLDB_INVALID_BREAK_ID; - if (input == NULL || *input == '\0') + if (input == nullptr || *input == '\0') return false; const char *format = "%i%n.%i%n"; diff --git a/source/Breakpoint/BreakpointIDList.cpp b/source/Breakpoint/BreakpointIDList.cpp index b8b506750b348..ebf0697c271ba 100644 --- a/source/Breakpoint/BreakpointIDList.cpp +++ b/source/Breakpoint/BreakpointIDList.cpp @@ -7,6 +7,10 @@ // //===----------------------------------------------------------------------===// +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes #include "lldb/Breakpoint/BreakpointIDList.h" #include "lldb/Breakpoint/Breakpoint.h" @@ -27,9 +31,7 @@ m_invalid_id (LLDB_INVALID_BREAK_ID, LLDB_INVALID_BREAK_ID) { } -BreakpointIDList::~BreakpointIDList () -{ -} +BreakpointIDList::~BreakpointIDList() = default; size_t BreakpointIDList::GetSize() @@ -38,12 +40,9 @@ BreakpointIDList::GetSize() } BreakpointID & -BreakpointIDList::GetBreakpointIDAtIndex (size_t index) +BreakpointIDList::GetBreakpointIDAtIndex(size_t index) { - if (index < m_breakpoint_ids.size()) - return m_breakpoint_ids[index]; - else - return m_invalid_id; + return ((index < m_breakpoint_ids.size()) ? m_breakpoint_ids[index] : m_invalid_id); } bool @@ -124,7 +123,7 @@ BreakpointIDList::FindBreakpointID (const char *bp_id_str, size_t *position) void BreakpointIDList::InsertStringArray (const char **string_array, size_t array_size, CommandReturnObject &result) { - if (string_array == NULL) + if (string_array == nullptr) return; for (uint32_t i = 0; i < array_size; ++i) @@ -385,7 +384,6 @@ BreakpointIDList::FindAndReplaceIDRanges (Args &old_args, } result.SetStatus (eReturnStatusSuccessFinishNoResult); - return; } bool @@ -402,7 +400,7 @@ BreakpointIDList::StringContainsIDRangeExpression (const char *in_string, *range_end_pos = 0; int specifiers_size = 0; - for (int i = 0; BreakpointID::g_range_specifiers[i] != NULL; ++i) + for (int i = 0; BreakpointID::g_range_specifiers[i] != nullptr; ++i) ++specifiers_size; for (int i = 0; i < specifiers_size && !is_range_expression; ++i) diff --git a/source/Breakpoint/BreakpointLocation.cpp b/source/Breakpoint/BreakpointLocation.cpp index a199d390803b0..5ff91102aadda 100644 --- a/source/Breakpoint/BreakpointLocation.cpp +++ b/source/Breakpoint/BreakpointLocation.cpp @@ -9,8 +9,6 @@ // C Includes // C++ Includes -#include <string> - // Other libraries and framework includes // Project includes #include "lldb/Breakpoint/BreakpointLocation.h" @@ -21,9 +19,11 @@ #include "lldb/Core/Module.h" #include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObject.h" -#include "lldb/Expression/ClangUserExpression.h" +#include "lldb/Expression/ExpressionVariable.h" +#include "lldb/Expression/UserExpression.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Symbol.h" +#include "lldb/Symbol/TypeSystem.h" #include "lldb/Target/Target.h" #include "lldb/Target/Process.h" #include "lldb/Target/Thread.h" @@ -88,12 +88,18 @@ BreakpointLocation::GetBreakpoint () return m_owner; } +Target & +BreakpointLocation::GetTarget() +{ + return m_owner.GetTarget(); +} + bool BreakpointLocation::IsEnabled () const { if (!m_owner.IsEnabled()) return false; - else if (m_options_ap.get() != NULL) + else if (m_options_ap.get() != nullptr) return m_options_ap->IsEnabled(); else return true; @@ -123,7 +129,7 @@ BreakpointLocation::SetThreadID (lldb::tid_t thread_id) { // If we're resetting this to an invalid thread id, then // don't make an options pointer just to do that. - if (m_options_ap.get() != NULL) + if (m_options_ap.get() != nullptr) m_options_ap->SetThreadID (thread_id); } SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); @@ -147,11 +153,10 @@ BreakpointLocation::SetThreadIndex (uint32_t index) { // If we're resetting this to an invalid thread id, then // don't make an options pointer just to do that. - if (m_options_ap.get() != NULL) + if (m_options_ap.get() != nullptr) m_options_ap->GetThreadSpec()->SetIndex(index); } SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); - } uint32_t @@ -166,13 +171,13 @@ BreakpointLocation::GetThreadIndex() const void BreakpointLocation::SetThreadName (const char *thread_name) { - if (thread_name != NULL) + if (thread_name != nullptr) GetLocationOptions()->GetThreadSpec()->SetName(thread_name); else { // If we're resetting this to an invalid thread id, then // don't make an options pointer just to do that. - if (m_options_ap.get() != NULL) + if (m_options_ap.get() != nullptr) m_options_ap->GetThreadSpec()->SetName(thread_name); } SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); @@ -184,19 +189,19 @@ BreakpointLocation::GetThreadName () const if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetName(); else - return NULL; + return nullptr; } void BreakpointLocation::SetQueueName (const char *queue_name) { - if (queue_name != NULL) + if (queue_name != nullptr) GetLocationOptions()->GetThreadSpec()->SetQueueName(queue_name); else { // If we're resetting this to an invalid thread id, then // don't make an options pointer just to do that. - if (m_options_ap.get() != NULL) + if (m_options_ap.get() != nullptr) m_options_ap->GetThreadSpec()->SetQueueName(queue_name); } SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); @@ -208,13 +213,13 @@ BreakpointLocation::GetQueueName () const if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetQueueName(); else - return NULL; + return nullptr; } bool BreakpointLocation::InvokeCallback (StoppointCallbackContext *context) { - if (m_options_ap.get() != NULL && m_options_ap->HasCallback()) + if (m_options_ap.get() != nullptr && m_options_ap->HasCallback()) return m_options_ap->InvokeCallback (context, m_owner.GetID(), GetID()); else return m_owner.InvokeCallback (context, GetID()); @@ -238,7 +243,6 @@ BreakpointLocation::SetCallback (BreakpointHitCallback callback, const BatonSP & SendBreakpointLocationChangedEvent (eBreakpointEventTypeCommandChanged); } - void BreakpointLocation::ClearCallback () { @@ -278,11 +282,27 @@ BreakpointLocation::ConditionSaysStop (ExecutionContext &exe_ctx, Error &error) !m_user_expression_sp || !m_user_expression_sp->MatchesContext(exe_ctx)) { - m_user_expression_sp.reset(new ClangUserExpression(condition_text, - NULL, - lldb::eLanguageTypeUnknown, - ClangUserExpression::eResultTypeAny)); + LanguageType language = eLanguageTypeUnknown; + // See if we can figure out the language from the frame, otherwise use the default language: + CompileUnit *comp_unit = m_address.CalculateSymbolContextCompileUnit(); + if (comp_unit) + language = comp_unit->GetLanguage(); + Error error; + m_user_expression_sp.reset(GetTarget().GetUserExpressionForLanguage(condition_text, + nullptr, + language, + Expression::eResultTypeAny, + EvaluateExpressionOptions(), + error)); + if (error.Fail()) + { + if (log) + log->Printf("Error getting condition expression: %s.", error.AsCString()); + m_user_expression_sp.reset(); + return true; + } + StreamString errors; if (!m_user_expression_sp->Parse(errors, @@ -314,7 +334,7 @@ BreakpointLocation::ConditionSaysStop (ExecutionContext &exe_ctx, Error &error) StreamString execution_errors; - ClangExpressionVariableSP result_variable_sp; + ExpressionVariableSP result_variable_sp; ExpressionResults result_code = m_user_expression_sp->Execute(execution_errors, @@ -337,21 +357,20 @@ BreakpointLocation::ConditionSaysStop (ExecutionContext &exe_ctx, Error &error) if (result_value_sp) { - Scalar scalar_value; - if (result_value_sp->ResolveValue (scalar_value)) + ret = result_value_sp->IsLogicalTrue(error); + if (log) { - if (scalar_value.ULongLong(1) == 0) - ret = false; - else - ret = true; - if (log) + if (error.Success()) + { log->Printf("Condition successfully evaluated, result is %s.\n", ret ? "true" : "false"); - } - else - { - ret = false; - error.SetErrorString("Failed to get an integer result from the expression"); + } + else + { + error.SetErrorString("Failed to get an integer result from the expression"); + ret = false; + } + } } else @@ -385,7 +404,7 @@ BreakpointLocation::SetIgnoreCount (uint32_t n) void BreakpointLocation::DecrementIgnoreCount() { - if (m_options_ap.get() != NULL) + if (m_options_ap.get() != nullptr) { uint32_t loc_ignore = m_options_ap->GetIgnoreCount(); if (loc_ignore != 0) @@ -396,7 +415,7 @@ BreakpointLocation::DecrementIgnoreCount() bool BreakpointLocation::IgnoreCountShouldStop() { - if (m_options_ap.get() != NULL) + if (m_options_ap.get() != nullptr) { uint32_t loc_ignore = m_options_ap->GetIgnoreCount(); if (loc_ignore != 0) @@ -413,7 +432,7 @@ BreakpointLocation::IgnoreCountShouldStop() const BreakpointOptions * BreakpointLocation::GetOptionsNoCreate () const { - if (m_options_ap.get() != NULL) + if (m_options_ap.get() != nullptr) return m_options_ap.get(); else return m_owner.GetOptions (); @@ -425,7 +444,7 @@ BreakpointLocation::GetLocationOptions () // If we make the copy we don't copy the callbacks because that is potentially // expensive and we don't want to do that for the simple case where someone is // just disabling the location. - if (m_options_ap.get() == NULL) + if (m_options_ap.get() == nullptr) m_options_ap.reset(BreakpointOptions::CopyOptionsNoCallback(*m_owner.GetOptions ())); return m_options_ap.get(); @@ -497,7 +516,7 @@ BreakpointLocation::UndoBumpHitCount() bool BreakpointLocation::IsResolved () const { - return m_bp_site_sp.get() != NULL; + return m_bp_site_sp.get() != nullptr; } lldb::BreakpointSiteSP @@ -513,7 +532,7 @@ BreakpointLocation::ResolveBreakpointSite () return true; Process *process = m_owner.GetTarget().GetProcessSP().get(); - if (process == NULL) + if (process == nullptr) return false; lldb::break_id_t new_id = process->CreateBreakpointSite (shared_from_this(), m_owner.IsHardware()); @@ -601,13 +620,13 @@ BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) sc.module_sp->GetFileSpec().Dump (s); } - if (sc.comp_unit != NULL) + if (sc.comp_unit != nullptr) { s->EOL(); s->Indent("compile unit = "); static_cast<FileSpec*>(sc.comp_unit)->GetFilename().Dump (s); - if (sc.function != NULL) + if (sc.function != nullptr) { s->EOL(); s->Indent("function = "); @@ -648,11 +667,11 @@ BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) s->Printf (", "); s->Printf ("address = "); - ExecutionContextScope *exe_scope = NULL; + ExecutionContextScope *exe_scope = nullptr; Target *target = &m_owner.GetTarget(); if (target) exe_scope = target->GetProcessSP().get(); - if (exe_scope == NULL) + if (exe_scope == nullptr) exe_scope = target; if (level == eDescriptionLevelInitial) @@ -710,7 +729,7 @@ BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) void BreakpointLocation::Dump(Stream *s) const { - if (s == NULL) + if (s == nullptr) return; s->Printf("BreakpointLocation %u: tid = %4.4" PRIx64 " load addr = 0x%8.8" PRIx64 " state = %s type = %s breakpoint " diff --git a/source/Breakpoint/BreakpointLocationList.cpp b/source/Breakpoint/BreakpointLocationList.cpp index 06b270a08ce94..d57cfa68fb80c 100644 --- a/source/Breakpoint/BreakpointLocationList.cpp +++ b/source/Breakpoint/BreakpointLocationList.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// - // C Includes // C++ Includes // Other libraries and framework includes @@ -22,7 +21,6 @@ #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Target.h" - using namespace lldb; using namespace lldb_private; @@ -32,13 +30,11 @@ BreakpointLocationList::BreakpointLocationList(Breakpoint &owner) : m_address_to_location (), m_mutex (Mutex::eMutexTypeRecursive), m_next_id (0), - m_new_location_recorder (NULL) + m_new_location_recorder (nullptr) { } -BreakpointLocationList::~BreakpointLocationList() -{ -} +BreakpointLocationList::~BreakpointLocationList() = default; BreakpointLocationSP BreakpointLocationList::Create (const Address &addr, bool resolve_indirect_symbols) @@ -163,7 +159,6 @@ BreakpointLocationList::Dump (Stream *s) const s->IndentLess(); } - BreakpointLocationSP BreakpointLocationList::GetByIndex (size_t i) { @@ -285,7 +280,6 @@ BreakpointLocationList::SwapLocation (BreakpointLocationSP to_location_sp, Break to_location_sp->ResolveBreakpointSite(); } - bool BreakpointLocationList::RemoveLocation (const lldb::BreakpointLocationSP &bp_loc_sp) { @@ -304,7 +298,7 @@ BreakpointLocationList::RemoveLocation (const lldb::BreakpointLocationSP &bp_loc return true; } } - } + } return false; } @@ -348,7 +342,7 @@ void BreakpointLocationList::StartRecordingNewLocations (BreakpointLocationCollection &new_locations) { Mutex::Locker locker (m_mutex); - assert (m_new_location_recorder == NULL); + assert(m_new_location_recorder == nullptr); m_new_location_recorder = &new_locations; } @@ -356,7 +350,7 @@ void BreakpointLocationList::StopRecordingNewLocations () { Mutex::Locker locker (m_mutex); - m_new_location_recorder = NULL; + m_new_location_recorder = nullptr; } void diff --git a/source/Breakpoint/BreakpointOptions.cpp b/source/Breakpoint/BreakpointOptions.cpp index db76ffb8685ca..d2a919756857c 100644 --- a/source/Breakpoint/BreakpointOptions.cpp +++ b/source/Breakpoint/BreakpointOptions.cpp @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Breakpoint/BreakpointOptions.h" - // C Includes // C++ Includes // Other libraries and framework includes // Project includes +#include "lldb/Breakpoint/BreakpointOptions.h" + #include "lldb/Core/Stream.h" #include "lldb/Core/StringList.h" #include "lldb/Core/Value.h" @@ -20,7 +20,6 @@ #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Target/ThreadSpec.h" -#include "lldb/Expression/ClangUserExpression.h" using namespace lldb; using namespace lldb_private; @@ -59,7 +58,7 @@ BreakpointOptions::BreakpointOptions(const BreakpointOptions& rhs) : m_ignore_count (rhs.m_ignore_count), m_thread_spec_ap () { - if (rhs.m_thread_spec_ap.get() != NULL) + if (rhs.m_thread_spec_ap.get() != nullptr) m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get())); m_condition_text = rhs.m_condition_text; m_condition_text_hash = rhs.m_condition_text_hash; @@ -77,7 +76,7 @@ BreakpointOptions::operator=(const BreakpointOptions& rhs) m_enabled = rhs.m_enabled; m_one_shot = rhs.m_one_shot; m_ignore_count = rhs.m_ignore_count; - if (rhs.m_thread_spec_ap.get() != NULL) + if (rhs.m_thread_spec_ap.get() != nullptr) m_thread_spec_ap.reset(new ThreadSpec(*rhs.m_thread_spec_ap.get())); m_condition_text = rhs.m_condition_text; m_condition_text_hash = rhs.m_condition_text_hash; @@ -102,9 +101,7 @@ BreakpointOptions::CopyOptionsNoCallback (BreakpointOptions &orig) //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- -BreakpointOptions::~BreakpointOptions() -{ -} +BreakpointOptions::~BreakpointOptions() = default; //------------------------------------------------------------------ // Callbacks @@ -144,10 +141,10 @@ BreakpointOptions::InvokeCallback (StoppointCallbackContext *context, { if (m_callback && context->is_synchronous == IsCallbackSynchronous()) { - return m_callback (m_callback_baton_sp ? m_callback_baton_sp->m_data : NULL, - context, - break_id, - break_loc_id); + return m_callback(m_callback_baton_sp ? m_callback_baton_sp->m_data : nullptr, + context, + break_id, + break_loc_id); } else return true; @@ -182,7 +179,7 @@ BreakpointOptions::GetConditionText (size_t *hash) const } else { - return NULL; + return nullptr; } } @@ -195,7 +192,7 @@ BreakpointOptions::GetThreadSpecNoCreate () const ThreadSpec * BreakpointOptions::GetThreadSpec () { - if (m_thread_spec_ap.get() == NULL) + if (m_thread_spec_ap.get() == nullptr) m_thread_spec_ap.reset (new ThreadSpec()); return m_thread_spec_ap.get(); @@ -210,11 +207,10 @@ BreakpointOptions::SetThreadID (lldb::tid_t thread_id) void BreakpointOptions::GetDescription (Stream *s, lldb::DescriptionLevel level) const { - // Figure out if there are any options not at their default value, and only print // anything if there are: - if (m_ignore_count != 0 || !m_enabled || m_one_shot || (GetThreadSpecNoCreate() != NULL && GetThreadSpecNoCreate()->HasSpecification ())) + if (m_ignore_count != 0 || !m_enabled || m_one_shot || (GetThreadSpecNoCreate() != nullptr && GetThreadSpecNoCreate()->HasSpecification ())) { if (level == lldb::eDescriptionLevelVerbose) { @@ -294,4 +290,3 @@ BreakpointOptions::CommandBaton::GetDescription (Stream *s, lldb::DescriptionLev s->IndentLess (); s->IndentLess (); } - diff --git a/source/Breakpoint/BreakpointResolverAddress.cpp b/source/Breakpoint/BreakpointResolverAddress.cpp index 193bc413af051..8a0469a07e466 100644 --- a/source/Breakpoint/BreakpointResolverAddress.cpp +++ b/source/Breakpoint/BreakpointResolverAddress.cpp @@ -16,6 +16,7 @@ #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Log.h" +#include "lldb/Core/Module.h" #include "lldb/Core/StreamString.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" @@ -29,10 +30,25 @@ using namespace lldb_private; BreakpointResolverAddress::BreakpointResolverAddress ( Breakpoint *bkpt, + const Address &addr, + const FileSpec &module_spec +) : + BreakpointResolver (bkpt, BreakpointResolver::AddressResolver), + m_addr (addr), + m_resolved_addr(LLDB_INVALID_ADDRESS), + m_module_filespec(module_spec) +{ +} + +BreakpointResolverAddress::BreakpointResolverAddress +( + Breakpoint *bkpt, const Address &addr ) : BreakpointResolver (bkpt, BreakpointResolver::AddressResolver), - m_addr (addr) + m_addr (addr), + m_resolved_addr(LLDB_INVALID_ADDRESS), + m_module_filespec() { } @@ -44,10 +60,16 @@ BreakpointResolverAddress::~BreakpointResolverAddress () void BreakpointResolverAddress::ResolveBreakpoint (SearchFilter &filter) { - // The address breakpoint only takes once, so if we've already set it we're done. - if (m_breakpoint->GetNumLocations() > 0) - return; - else + // If the address is not section relative, then we should not try to re-resolve it, it is just some + // random address and we wouldn't know what to do on reload. But if it is section relative, we need to + // re-resolve it since the section it's in may have shifted on re-run. + bool re_resolve = false; + if (m_addr.GetSection() || m_module_filespec) + re_resolve = true; + else if (m_breakpoint->GetNumLocations() == 0) + re_resolve = true; + + if (re_resolve) BreakpointResolver::ResolveBreakpoint(filter); } @@ -58,10 +80,14 @@ BreakpointResolverAddress::ResolveBreakpointInModules ModuleList &modules ) { - // The address breakpoint only takes once, so if we've already set it we're done. - if (m_breakpoint->GetNumLocations() > 0) - return; - else + // See comment in ResolveBreakpoint. + bool re_resolve = false; + if (m_addr.GetSection()) + re_resolve = true; + else if (m_breakpoint->GetNumLocations() == 0) + re_resolve = true; + + if (re_resolve) BreakpointResolver::ResolveBreakpointInModules (filter, modules); } @@ -78,14 +104,44 @@ BreakpointResolverAddress::SearchCallback if (filter.AddressPasses (m_addr)) { - BreakpointLocationSP bp_loc_sp(m_breakpoint->AddLocation(m_addr)); - if (bp_loc_sp && !m_breakpoint->IsInternal()) + if (m_breakpoint->GetNumLocations() == 0) + { + // If the address is just an offset, and we're given a module, see if we can find the appropriate module + // loaded in the binary, and fix up m_addr to use that. + if (!m_addr.IsSectionOffset() && m_module_filespec) + { + Target &target = m_breakpoint->GetTarget(); + ModuleSpec module_spec(m_module_filespec); + ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec); + if (module_sp) + { + Address tmp_address; + if (module_sp->ResolveFileAddress(m_addr.GetOffset(), tmp_address)) + m_addr = tmp_address; + } + } + + BreakpointLocationSP bp_loc_sp(m_breakpoint->AddLocation(m_addr)); + m_resolved_addr = m_addr.GetLoadAddress(&m_breakpoint->GetTarget()); + if (bp_loc_sp && !m_breakpoint->IsInternal()) + { + StreamString s; + bp_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); + if (log) + log->Printf ("Added location: %s\n", s.GetData()); + } + } + else { - StreamString s; - bp_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); - if (log) - log->Printf ("Added location: %s\n", s.GetData()); + BreakpointLocationSP loc_sp = m_breakpoint->GetLocationAtIndex(0); + lldb::addr_t cur_load_location = m_addr.GetLoadAddress(&m_breakpoint->GetTarget()); + if (cur_load_location != m_resolved_addr) + { + m_resolved_addr = cur_load_location; + loc_sp->ClearBreakpointSite(); + loc_sp->ResolveBreakpointSite(); + } } } return Searcher::eCallbackReturnStop; @@ -101,7 +157,7 @@ void BreakpointResolverAddress::GetDescription (Stream *s) { s->PutCString ("address = "); - m_addr.Dump(s, m_breakpoint->GetTarget().GetProcessSP().get(), Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); + m_addr.Dump(s, m_breakpoint->GetTarget().GetProcessSP().get(), Address::DumpStyleModuleWithFileAddress, Address::DumpStyleLoadAddress); } void diff --git a/source/Breakpoint/BreakpointResolverName.cpp b/source/Breakpoint/BreakpointResolverName.cpp index 581f7b0161734..9ae3fe5256d4d 100644 --- a/source/Breakpoint/BreakpointResolverName.cpp +++ b/source/Breakpoint/BreakpointResolverName.cpp @@ -7,22 +7,21 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Breakpoint/BreakpointResolverName.h" - // C Includes // C++ Includes // Other libraries and framework includes // Project includes +#include "lldb/Breakpoint/BreakpointResolverName.h" + #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/StreamString.h" -#include "lldb/Symbol/ClangNamespaceDecl.h" #include "lldb/Symbol/Block.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/SymbolContext.h" -#include "lldb/Target/ObjCLanguageRuntime.h" +#include "Plugins/Language/ObjC/ObjCLanguage.h" using namespace lldb; using namespace lldb_private; @@ -30,15 +29,16 @@ using namespace lldb_private; BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt, const char *name_cstr, uint32_t name_type_mask, + LanguageType language, Breakpoint::MatchType type, bool skip_prologue) : BreakpointResolver (bkpt, BreakpointResolver::NameResolver), m_class_name (), m_regex (), m_match_type (type), + m_language (language), m_skip_prologue (skip_prologue) { - if (m_match_type == Breakpoint::Regexp) { if (!m_regex.Compile (name_cstr)) @@ -59,9 +59,11 @@ BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt, const char *names[], size_t num_names, uint32_t name_type_mask, + LanguageType language, bool skip_prologue) : BreakpointResolver (bkpt, BreakpointResolver::NameResolver), m_match_type (Breakpoint::Exact), + m_language (language), m_skip_prologue (skip_prologue) { for (size_t i = 0; i < num_names; i++) @@ -73,9 +75,11 @@ BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt, BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt, std::vector<std::string> names, uint32_t name_type_mask, + LanguageType language, bool skip_prologue) : BreakpointResolver (bkpt, BreakpointResolver::NameResolver), m_match_type (Breakpoint::Exact), + m_language (language), m_skip_prologue (skip_prologue) { for (const std::string& name : names) @@ -86,27 +90,27 @@ BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt, BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt, RegularExpression &func_regex, + lldb::LanguageType language, bool skip_prologue) : BreakpointResolver (bkpt, BreakpointResolver::NameResolver), - m_class_name (NULL), + m_class_name (nullptr), m_regex (func_regex), m_match_type (Breakpoint::Regexp), + m_language (language), m_skip_prologue (skip_prologue) { } -BreakpointResolverName::BreakpointResolverName -( - Breakpoint *bkpt, - const char *class_name, - const char *method, - Breakpoint::MatchType type, - bool skip_prologue -) : +BreakpointResolverName::BreakpointResolverName(Breakpoint *bkpt, + const char *class_name, + const char *method, + Breakpoint::MatchType type, + bool skip_prologue ) : BreakpointResolver (bkpt, BreakpointResolver::NameResolver), m_class_name (class_name), m_regex (), m_match_type (type), + m_language (eLanguageTypeUnknown), m_skip_prologue (skip_prologue) { LookupInfo lookup; @@ -117,9 +121,7 @@ BreakpointResolverName::BreakpointResolverName m_lookups.push_back (lookup); } -BreakpointResolverName::~BreakpointResolverName () -{ -} +BreakpointResolverName::~BreakpointResolverName() = default; BreakpointResolverName::BreakpointResolverName(const BreakpointResolverName &rhs) : BreakpointResolver(rhs.m_breakpoint, BreakpointResolver::NameResolver), @@ -127,15 +129,15 @@ BreakpointResolverName::BreakpointResolverName(const BreakpointResolverName &rhs m_class_name(rhs.m_class_name), m_regex(rhs.m_regex), m_match_type (rhs.m_match_type), + m_language (rhs.m_language), m_skip_prologue (rhs.m_skip_prologue) { - } void BreakpointResolverName::AddNameLookup (const ConstString &name, uint32_t name_type_mask) { - ObjCLanguageRuntime::MethodName objc_method(name.GetCString(), false); + ObjCLanguage::MethodName objc_method(name.GetCString(), false); if (objc_method.IsValid(false)) { std::vector<ConstString> objc_names; @@ -154,12 +156,11 @@ BreakpointResolverName::AddNameLookup (const ConstString &name, uint32_t name_ty { LookupInfo lookup; lookup.name = name; - Module::PrepareForFunctionNameLookup(lookup.name, name_type_mask, lookup.lookup_name, lookup.name_type_mask, lookup.match_name_after_lookup); + Module::PrepareForFunctionNameLookup(lookup.name, name_type_mask, m_language, lookup.lookup_name, lookup.name_type_mask, lookup.match_name_after_lookup); m_lookups.push_back (lookup); } } - void BreakpointResolverName::LookupInfo::Prune (SymbolContextList &sc_list, size_t start_idx) const { @@ -172,7 +173,7 @@ BreakpointResolverName::LookupInfo::Prune (SymbolContextList &sc_list, size_t st if (!sc_list.GetContextAtIndex(i, sc)) break; ConstString full_name (sc.GetFunctionName()); - if (full_name && ::strstr(full_name.GetCString(), name.GetCString()) == NULL) + if (full_name && ::strstr(full_name.GetCString(), name.GetCString()) == nullptr) { sc_list.RemoveContextAtIndex(i); } @@ -184,19 +185,15 @@ BreakpointResolverName::LookupInfo::Prune (SymbolContextList &sc_list, size_t st } } - // 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 -BreakpointResolverName::SearchCallback -( - SearchFilter &filter, - SymbolContext &context, - Address *addr, - bool containing -) +BreakpointResolverName::SearchCallback(SearchFilter &filter, + SymbolContext &context, + Address *addr, + bool containing) { SymbolContextList func_list; //SymbolContextList sym_list; @@ -204,7 +201,7 @@ BreakpointResolverName::SearchCallback uint32_t i; bool new_location; Address break_addr; - assert (m_breakpoint != NULL); + assert (m_breakpoint != nullptr); Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); @@ -215,7 +212,8 @@ BreakpointResolverName::SearchCallback return Searcher::eCallbackReturnStop; } bool filter_by_cu = (filter.GetFilterRequiredItems() & eSymbolContextCompUnit) != 0; - const bool include_symbols = filter_by_cu == false; + bool filter_by_language = (m_language != eLanguageTypeUnknown); + const bool include_symbols = !filter_by_cu; const bool include_inlines = true; const bool append = true; @@ -227,13 +225,13 @@ BreakpointResolverName::SearchCallback for (const LookupInfo &lookup : m_lookups) { const size_t start_func_idx = func_list.GetSize(); - context.module_sp->FindFunctions (lookup.lookup_name, - NULL, - lookup.name_type_mask, - include_symbols, - include_inlines, - append, - func_list); + context.module_sp->FindFunctions(lookup.lookup_name, + nullptr, + lookup.name_type_mask, + include_symbols, + include_inlines, + append, + func_list); const size_t end_func_idx = func_list.GetSize(); if (start_func_idx < end_func_idx) @@ -258,15 +256,33 @@ BreakpointResolverName::SearchCallback } // If the filter specifies a Compilation Unit, remove the ones that don't pass at this point. - if (filter_by_cu) + if (filter_by_cu || filter_by_language) { uint32_t num_functions = func_list.GetSize(); for (size_t idx = 0; idx < num_functions; idx++) { + bool remove_it = false; SymbolContext sc; func_list.GetContextAtIndex(idx, sc); - if (!sc.comp_unit || !filter.CompUnitPasses(*sc.comp_unit)) + if (filter_by_cu) + { + if (!sc.comp_unit || !filter.CompUnitPasses(*sc.comp_unit)) + remove_it = true; + } + + if (filter_by_language) + { + LanguageType sym_language = sc.GetLanguage(); + if ((Language::GetPrimaryLanguage(sym_language) != + Language::GetPrimaryLanguage(m_language)) && + (sym_language != eLanguageTypeUnknown)) + { + remove_it = true; + } + } + + if (remove_it) { func_list.RemoveContextAtIndex(idx); num_functions--; @@ -374,12 +390,15 @@ BreakpointResolverName::GetDescription (Stream *s) s->Printf ("'%s'}", m_lookups[num_names - 1].name.GetCString()); } } + if (m_language != eLanguageTypeUnknown) + { + s->Printf (", language = %s", Language::GetNameForLanguageType(m_language)); + } } void BreakpointResolverName::Dump (Stream *s) const { - } lldb::BreakpointResolverSP diff --git a/source/Breakpoint/BreakpointSite.cpp b/source/Breakpoint/BreakpointSite.cpp index e9ce812e7732a..d2aaea098cdb9 100644 --- a/source/Breakpoint/BreakpointSite.cpp +++ b/source/Breakpoint/BreakpointSite.cpp @@ -7,14 +7,14 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Breakpoint/BreakpointSite.h" - // C Includes // C++ Includes #include <inttypes.h> // Other libraries and framework includes // Project includes +#include "lldb/Breakpoint/BreakpointSite.h" + #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Breakpoint/BreakpointSiteList.h" @@ -23,13 +23,10 @@ using namespace lldb; using namespace lldb_private; -BreakpointSite::BreakpointSite -( - BreakpointSiteList *list, - const BreakpointLocationSP& owner, - lldb::addr_t addr, - bool use_hardware -) : +BreakpointSite::BreakpointSite(BreakpointSiteList *list, + const BreakpointLocationSP& owner, + lldb::addr_t addr, + bool use_hardware) : StoppointLocation(GetNextID(), addr, 0, use_hardware), m_type (eSoftware), // Process subclasses need to set this correctly using SetType() m_saved_opcode(), @@ -85,7 +82,7 @@ BreakpointSite::IsBreakpointAtThisSite (lldb::break_id_t bp_id) void BreakpointSite::Dump(Stream *s) const { - if (s == NULL) + if (s == nullptr) return; s->Printf("BreakpointSite %u: addr = 0x%8.8" PRIx64 " type = %s breakpoint hw_index = %i hit_count = %-4u", @@ -205,6 +202,7 @@ BreakpointSite::ValidForThisThread (Thread *thread) void BreakpointSite::BumpHitCounts() { + Mutex::Locker locker(m_owners_mutex); for (BreakpointLocationSP loc_sp : m_owners.BreakpointLocations()) { loc_sp->BumpHitCount(); @@ -253,3 +251,14 @@ BreakpointSite::IntersectsRange(lldb::addr_t addr, size_t size, lldb::addr_t *in } return false; } + +size_t +BreakpointSite::CopyOwnersList (BreakpointLocationCollection &out_collection) +{ + Mutex::Locker locker(m_owners_mutex); + for (BreakpointLocationSP loc_sp : m_owners.BreakpointLocations()) + { + out_collection.Add(loc_sp); + } + return out_collection.GetSize(); +} diff --git a/source/Breakpoint/StoppointCallbackContext.cpp b/source/Breakpoint/StoppointCallbackContext.cpp index 2266c3e429c65..9932843714f8a 100644 --- a/source/Breakpoint/StoppointCallbackContext.cpp +++ b/source/Breakpoint/StoppointCallbackContext.cpp @@ -7,17 +7,16 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Breakpoint/StoppointCallbackContext.h" - // C Includes // C++ Includes // Other libraries and framework includes // Project includes +#include "lldb/Breakpoint/StoppointCallbackContext.h" using namespace lldb_private; StoppointCallbackContext::StoppointCallbackContext() : - event (NULL), + event (nullptr), exe_ctx_ref (), is_synchronous (false) { @@ -33,7 +32,7 @@ StoppointCallbackContext::StoppointCallbackContext(Event *e, const ExecutionCont void StoppointCallbackContext::Clear() { - event = NULL; + event = nullptr; exe_ctx_ref.Clear(); is_synchronous = false; } diff --git a/source/Breakpoint/Watchpoint.cpp b/source/Breakpoint/Watchpoint.cpp index 45559b1901add..00a328e3039fc 100644 --- a/source/Breakpoint/Watchpoint.cpp +++ b/source/Breakpoint/Watchpoint.cpp @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Breakpoint/Watchpoint.h" - // C Includes // C++ Includes // Other libraries and framework includes // Project includes +#include "lldb/Breakpoint/Watchpoint.h" + #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/Stream.h" #include "lldb/Core/Value.h" @@ -22,12 +22,12 @@ #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Target/ThreadSpec.h" -#include "lldb/Expression/ClangUserExpression.h" +#include "lldb/Expression/UserExpression.h" using namespace lldb; using namespace lldb_private; -Watchpoint::Watchpoint (Target& target, lldb::addr_t addr, uint32_t size, const ClangASTType *type, bool hardware) : +Watchpoint::Watchpoint (Target& target, lldb::addr_t addr, uint32_t size, const CompilerType *type, bool hardware) : StoppointLocation (0, addr, size, hardware), m_target(target), m_enabled(false), @@ -67,9 +67,7 @@ Watchpoint::Watchpoint (Target& target, lldb::addr_t addr, uint32_t size, const m_being_created = false; } -Watchpoint::~Watchpoint() -{ -} +Watchpoint::~Watchpoint() = default; // This function is used when "baton" doesn't need to be freed void @@ -102,7 +100,6 @@ void Watchpoint::SetDeclInfo (const std::string &str) { m_decl_str = str; - return; } std::string @@ -115,7 +112,6 @@ void Watchpoint::SetWatchSpec (const std::string &str) { m_watch_spec_str = str; - return; } // Override default impl of StoppointLocation::IsHardware() since m_is_hardware @@ -154,10 +150,7 @@ Watchpoint::CaptureWatchedValue (const ExecutionContext &exe_ctx) } m_new_value_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), watch_name.AsCString(), watch_address, m_type); m_new_value_sp = m_new_value_sp->CreateConstantValue(watch_name); - if (m_new_value_sp && m_new_value_sp->GetError().Success()) - return true; - else - return false; + return (m_new_value_sp && m_new_value_sp->GetError().Success()); } void @@ -190,9 +183,6 @@ Watchpoint::ShouldStop (StoppointCallbackContext *context) if (!IsEnabled()) return false; - if (GetHitCount() <= GetIgnoreCount()) - return false; - return true; } @@ -200,7 +190,6 @@ void Watchpoint::GetDescription (Stream *s, lldb::DescriptionLevel level) { DumpWithLevel(s, level); - return; } void @@ -209,7 +198,7 @@ Watchpoint::Dump(Stream *s) const DumpWithLevel(s, lldb::eDescriptionLevelBrief); } -// If prefix is NULL, we display the watch id and ignore the prefix altogether. +// If prefix is nullptr, we display the watch id and ignore the prefix altogether. void Watchpoint::DumpSnapshots(Stream *s, const char *prefix) const { @@ -218,21 +207,38 @@ Watchpoint::DumpSnapshots(Stream *s, const char *prefix) const s->Printf("\nWatchpoint %u hit:", GetID()); prefix = ""; } - + if (m_old_value_sp) { - s->Printf("\n%sold value: %s", prefix, m_old_value_sp->GetValueAsCString()); + const char *old_value_cstr = m_old_value_sp->GetValueAsCString(); + if (old_value_cstr && old_value_cstr[0]) + s->Printf("\n%sold value: %s", prefix, old_value_cstr); + else + { + const char *old_summary_cstr = m_old_value_sp-> GetSummaryAsCString(); + if (old_summary_cstr && old_summary_cstr[0]) + s->Printf("\n%sold value: %s", prefix, old_summary_cstr); + } } + if (m_new_value_sp) { - s->Printf("\n%snew value: %s", prefix, m_new_value_sp->GetValueAsCString()); + const char *new_value_cstr = m_new_value_sp->GetValueAsCString(); + if (new_value_cstr && new_value_cstr[0]) + s->Printf("\n%snew value: %s", prefix, new_value_cstr); + else + { + const char *new_summary_cstr = m_new_value_sp-> GetSummaryAsCString(); + if (new_summary_cstr && new_summary_cstr[0]) + s->Printf("\n%snew value: %s", prefix, new_summary_cstr); + } } } void Watchpoint::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const { - if (s == NULL) + if (s == nullptr) return; assert(description_level >= lldb::eDescriptionLevelBrief && @@ -334,11 +340,13 @@ Watchpoint::WatchpointRead () const { return m_watch_read != 0; } + bool Watchpoint::WatchpointWrite () const { return m_watch_write != 0; } + uint32_t Watchpoint::GetIgnoreCount () const { @@ -363,15 +371,26 @@ Watchpoint::InvokeCallback (StoppointCallbackContext *context) void Watchpoint::SetCondition (const char *condition) { - if (condition == NULL || condition[0] == '\0') + if (condition == nullptr || condition[0] == '\0') { if (m_condition_ap.get()) m_condition_ap.reset(); } else { - // Pass NULL for expr_prefix (no translation-unit level definitions). - m_condition_ap.reset(new ClangUserExpression (condition, NULL, lldb::eLanguageTypeUnknown, ClangUserExpression::eResultTypeAny)); + // Pass nullptr for expr_prefix (no translation-unit level definitions). + Error error; + m_condition_ap.reset(m_target.GetUserExpressionForLanguage(condition, + nullptr, + lldb::eLanguageTypeUnknown, + UserExpression::eResultTypeAny, + EvaluateExpressionOptions(), + error)); + if (error.Fail()) + { + // FIXME: Log something... + m_condition_ap.reset(); + } } SendWatchpointChangedEvent (eWatchpointEventTypeConditionChanged); } @@ -382,7 +401,7 @@ Watchpoint::GetConditionText () const if (m_condition_ap.get()) return m_condition_ap->GetUserText(); else - return NULL; + return nullptr; } void @@ -399,8 +418,7 @@ Watchpoint::SendWatchpointChangedEvent (lldb::WatchpointEventType eventKind) void Watchpoint::SendWatchpointChangedEvent (WatchpointEventData *data) { - - if (data == NULL) + if (data == nullptr) return; if (!m_being_created @@ -418,9 +436,7 @@ Watchpoint::WatchpointEventData::WatchpointEventData (WatchpointEventType sub_ty { } -Watchpoint::WatchpointEventData::~WatchpointEventData () -{ -} +Watchpoint::WatchpointEventData::~WatchpointEventData() = default; const ConstString & Watchpoint::WatchpointEventData::GetFlavorString () @@ -435,7 +451,6 @@ Watchpoint::WatchpointEventData::GetFlavor () const return WatchpointEventData::GetFlavorString (); } - WatchpointSP & Watchpoint::WatchpointEventData::GetWatchpoint () { @@ -462,7 +477,7 @@ Watchpoint::WatchpointEventData::GetEventDataFromEvent (const Event *event) if (event_data && event_data->GetFlavor() == WatchpointEventData::GetFlavorString()) return static_cast <const WatchpointEventData *> (event->GetData()); } - return NULL; + return nullptr; } WatchpointEventType @@ -470,7 +485,7 @@ Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent (const EventSP { const WatchpointEventData *data = GetEventDataFromEvent (event_sp.get()); - if (data == NULL) + if (data == nullptr) return eWatchpointEventTypeInvalidType; else return data->GetWatchpointEventType(); diff --git a/source/Breakpoint/WatchpointList.cpp b/source/Breakpoint/WatchpointList.cpp index 472bae06b441c..64bf5cd63ed0d 100644 --- a/source/Breakpoint/WatchpointList.cpp +++ b/source/Breakpoint/WatchpointList.cpp @@ -75,10 +75,15 @@ WatchpointList::FindByAddress (lldb::addr_t addr) const { wp_collection::const_iterator pos, end = m_watchpoints.end(); for (pos = m_watchpoints.begin(); pos != end; ++pos) - if ((*pos)->GetLoadAddress() == addr) { + { + lldb::addr_t wp_addr = (*pos)->GetLoadAddress(); + uint32_t wp_bytesize = (*pos)->GetByteSize(); + if ((wp_addr <= addr) && ((wp_addr + wp_bytesize) > addr)) + { wp_sp = *pos; break; } + } } return wp_sp; diff --git a/source/Breakpoint/WatchpointOptions.cpp b/source/Breakpoint/WatchpointOptions.cpp index c2c9696c4ce74..365d884691ef5 100644 --- a/source/Breakpoint/WatchpointOptions.cpp +++ b/source/Breakpoint/WatchpointOptions.cpp @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Breakpoint/WatchpointOptions.h" - // C Includes // C++ Includes // Other libraries and framework includes // Project includes +#include "lldb/Breakpoint/WatchpointOptions.h" + #include "lldb/Core/Stream.h" #include "lldb/Core/StringList.h" #include "lldb/Core/Value.h" @@ -20,7 +20,6 @@ #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Target/ThreadSpec.h" -#include "lldb/Expression/ClangUserExpression.h" using namespace lldb; using namespace lldb_private; @@ -51,7 +50,7 @@ WatchpointOptions::WatchpointOptions(const WatchpointOptions& rhs) : m_callback_is_synchronous (rhs.m_callback_is_synchronous), m_thread_spec_ap () { - if (rhs.m_thread_spec_ap.get() != NULL) + if (rhs.m_thread_spec_ap.get() != nullptr) m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get())); } @@ -64,7 +63,7 @@ WatchpointOptions::operator=(const WatchpointOptions& rhs) m_callback = rhs.m_callback; m_callback_baton_sp = rhs.m_callback_baton_sp; m_callback_is_synchronous = rhs.m_callback_is_synchronous; - if (rhs.m_thread_spec_ap.get() != NULL) + if (rhs.m_thread_spec_ap.get() != nullptr) m_thread_spec_ap.reset(new ThreadSpec(*rhs.m_thread_spec_ap.get())); return *this; } @@ -87,9 +86,7 @@ WatchpointOptions::CopyOptionsNoCallback (WatchpointOptions &orig) //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- -WatchpointOptions::~WatchpointOptions() -{ -} +WatchpointOptions::~WatchpointOptions() = default; //------------------------------------------------------------------ // Callbacks @@ -128,9 +125,9 @@ WatchpointOptions::InvokeCallback (StoppointCallbackContext *context, { if (m_callback && context->is_synchronous == IsCallbackSynchronous()) { - return m_callback (m_callback_baton_sp ? m_callback_baton_sp->m_data : NULL, - context, - watch_id); + return m_callback(m_callback_baton_sp ? m_callback_baton_sp->m_data : nullptr, + context, + watch_id); } else return true; @@ -151,7 +148,7 @@ WatchpointOptions::GetThreadSpecNoCreate () const ThreadSpec * WatchpointOptions::GetThreadSpec () { - if (m_thread_spec_ap.get() == NULL) + if (m_thread_spec_ap.get() == nullptr) m_thread_spec_ap.reset (new ThreadSpec()); return m_thread_spec_ap.get(); @@ -172,14 +169,14 @@ WatchpointOptions::GetCallbackDescription (Stream *s, lldb::DescriptionLevel lev m_callback_baton_sp->GetDescription (s, level); } } + void WatchpointOptions::GetDescription (Stream *s, lldb::DescriptionLevel level) const { - // Figure out if there are any options not at their default value, and only print // anything if there are: - if ((GetThreadSpecNoCreate() != NULL && GetThreadSpecNoCreate()->HasSpecification ())) + if ((GetThreadSpecNoCreate() != nullptr && GetThreadSpecNoCreate()->HasSpecification ())) { if (level == lldb::eDescriptionLevelVerbose) { @@ -238,4 +235,3 @@ WatchpointOptions::CommandBaton::GetDescription (Stream *s, lldb::DescriptionLev s->IndentLess (); s->IndentLess (); } - |