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.

llvm-svn: 282043
This commit is contained in:
Jim Ingham 2016-09-21 01:21:19 +00:00
parent 09aa01a6f8
commit ff9a91ea98
6 changed files with 66 additions and 4 deletions

View File

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

View File

@ -102,6 +102,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.
///

View File

@ -708,6 +708,9 @@ public:
lldb::SBBreakpoint
FindBreakpointByID (break_id_t break_id);
bool FindBreakpointsByName(const char *name, SBBreakpointList &bkpt_list);
bool
EnableAllBreakpoints ();

View File

@ -1079,6 +1079,23 @@ SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
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) {

View File

@ -137,6 +137,23 @@ BreakpointList::FindBreakpointByID(break_id_t break_id) const {
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));

View File

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