[Lldb-commits] [lldb] r282043 - Adds tests for breakpoint names, and a FindBreakpointsByName.
Jim Ingham via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 20 18:21:19 PDT 2016
Author: jingham
Date: Tue Sep 20 20:21:19 2016
New Revision: 282043
URL: http://llvm.org/viewvc/llvm-project?rev=282043&view=rev
Log:
Adds tests for breakpoint names, and a FindBreakpointsByName.
Also if you set a breakpoint with an invalid name, we'll
refuse to set the breakpoint rather than silently ignoring
the name.
Modified:
lldb/trunk/include/lldb/API/SBTarget.h
lldb/trunk/include/lldb/Breakpoint/BreakpointList.h
lldb/trunk/scripts/interface/SBTarget.i
lldb/trunk/source/API/SBTarget.cpp
lldb/trunk/source/Breakpoint/BreakpointList.cpp
lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=282043&r1=282042&r2=282043&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Tue Sep 20 20:21:19 2016
@@ -666,6 +666,10 @@ public:
lldb::SBBreakpoint FindBreakpointByID(break_id_t break_id);
+ // Finds all breakpoints by name, returning the list in bkpt_list. Returns
+ // false if the name is not a valid breakpoint name, true otherwise.
+ bool FindBreakpointsByName(const char *name, SBBreakpointList &bkpt_list);
+
bool EnableAllBreakpoints();
bool DisableAllBreakpoints();
Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointList.h?rev=282043&r1=282042&r2=282043&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointList.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointList.h Tue Sep 20 20:21:19 2016
@@ -103,6 +103,17 @@ public:
const lldb::BreakpointSP GetBreakpointAtIndex(size_t i) const;
//------------------------------------------------------------------
+ /// Find all the breakpoints with a given name
+ ///
+ /// @param[in] name
+ /// The breakpoint name for which to search.
+ ///
+ /// @result
+ /// \bfalse if the input name was not a legal breakpoint name.
+ //------------------------------------------------------------------
+ bool FindBreakpointsByName(const char *name, BreakpointList &matching_bps);
+
+ //------------------------------------------------------------------
/// Returns the number of elements in this breakpoint list.
///
/// @result
Modified: lldb/trunk/scripts/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBTarget.i?rev=282043&r1=282042&r2=282043&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/interface/SBTarget.i Tue Sep 20 20:21:19 2016
@@ -708,6 +708,9 @@ public:
lldb::SBBreakpoint
FindBreakpointByID (break_id_t break_id);
+
+ bool FindBreakpointsByName(const char *name, SBBreakpointList &bkpt_list);
+
bool
EnableAllBreakpoints ();
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=282043&r1=282042&r2=282043&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Tue Sep 20 20:21:19 2016
@@ -1079,6 +1079,23 @@ SBBreakpoint SBTarget::FindBreakpointByI
return sb_breakpoint;
}
+bool SBTarget::FindBreakpointsByName(const char *name,
+ SBBreakpointList &bkpts) {
+ TargetSP target_sp(GetSP());
+ if (target_sp) {
+ std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
+ BreakpointList bkpt_list(false);
+ bool is_valid =
+ target_sp->GetBreakpointList().FindBreakpointsByName(name, bkpt_list);
+ if (!is_valid)
+ return false;
+ for (BreakpointSP bkpt_sp : bkpt_list.Breakpoints()) {
+ bkpts.AppendByID(bkpt_sp->GetID());
+ }
+ }
+ return true;
+}
+
bool SBTarget::EnableAllBreakpoints() {
TargetSP target_sp(GetSP());
if (target_sp) {
Modified: lldb/trunk/source/Breakpoint/BreakpointList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointList.cpp?rev=282043&r1=282042&r2=282043&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointList.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointList.cpp Tue Sep 20 20:21:19 2016
@@ -137,6 +137,23 @@ BreakpointList::FindBreakpointByID(break
return stop_sp;
}
+bool BreakpointList::FindBreakpointsByName(const char *name,
+ BreakpointList &matching_bps) {
+ Error error;
+ if (!name)
+ return false;
+
+ if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(name), error))
+ return false;
+
+ for (BreakpointSP bkpt_sp : Breakpoints()) {
+ if (bkpt_sp->MatchesName(name)) {
+ matching_bps.Add(bkpt_sp, false);
+ }
+ }
+ return true;
+}
+
void BreakpointList::Dump(Stream *s) const {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
s->Printf("%p: ", static_cast<const void *>(this));
Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp?rev=282043&r1=282042&r2=282043&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp Tue Sep 20 20:21:19 2016
@@ -249,6 +249,9 @@ public:
case 'N': {
if (BreakpointID::StringIsBreakpointName(option_strref, error))
m_breakpoint_names.push_back(option_arg);
+ else
+ error.SetErrorStringWithFormat("Invalid breakpoint name: %s",
+ option_arg);
break;
}
@@ -622,10 +625,17 @@ protected:
bp->GetOptions()->SetCondition(m_options.m_condition.c_str());
if (!m_options.m_breakpoint_names.empty()) {
- Error error; // We don't need to check the error here, since the option
- // parser checked it...
- for (auto name : m_options.m_breakpoint_names)
- bp->AddName(name.c_str(), error);
+ Error name_error;
+ for (auto name : m_options.m_breakpoint_names) {
+ bp->AddName(name.c_str(), name_error);
+ if (name_error.Fail()) {
+ result.AppendErrorWithFormat("Invalid breakpoint name: %s",
+ name.c_str());
+ target->RemoveBreakpointByID(bp->GetID());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
}
bp->SetOneShot(m_options.m_one_shot);
More information about the lldb-commits
mailing list