Skip to content

Commit

Permalink
Add the ability to tag one or more breakpoints with a name. These
Browse files Browse the repository at this point in the history
names can then be used in place of breakpoint id's or breakpoint id 
ranges in all the commands that operate on breakpoints.

<rdar://problem/10103959>

llvm-svn: 224392
  • Loading branch information
jimingham committed Dec 16, 2014
1 parent aa1bade commit 5e09c8c
Show file tree
Hide file tree
Showing 16 changed files with 713 additions and 20 deletions.
12 changes: 12 additions & 0 deletions lldb/include/lldb/API/SBBreakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ class SBBreakpoint

SBError
SetScriptCallbackBody (const char *script_body_text);

bool
AddName (const char *new_name);

void
RemoveName (const char *name_to_remove);

bool
MatchesName (const char *name);

void
GetNames (SBStringList &names);

size_t
GetNumResolvedLocations() const;
Expand Down
30 changes: 30 additions & 0 deletions lldb/include/lldb/Breakpoint/Breakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

// C Includes
// C++ Includes
#include <unordered_set>

// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/BreakpointID.h"
#include "lldb/Breakpoint/BreakpointLocationList.h"
#include "lldb/Breakpoint/BreakpointOptions.h"
#include "lldb/Breakpoint/BreakpointLocationCollection.h"
Expand Down Expand Up @@ -636,6 +639,32 @@ class Breakpoint:
return m_filter_sp;
}

bool
AddName (const char *new_name, Error &error);

void
RemoveName (const char *name_to_remove)
{
if (name_to_remove)
m_name_list.erase(name_to_remove);
}

bool
MatchesName (const char *name)
{
return m_name_list.find(name) != m_name_list.end();
}

void
GetNames (std::vector<std::string> &names)
{
names.clear();
for (auto name : m_name_list)
{
names.push_back(name);
}
}

protected:
friend class Target;
//------------------------------------------------------------------
Expand Down Expand Up @@ -697,6 +726,7 @@ class Breakpoint:
bool m_being_created;
bool m_hardware; // If this breakpoint is required to use a hardware breakpoint
Target &m_target; // The target that holds this breakpoint.
std::unordered_set<std::string> m_name_list; // If not empty, this is the name of this breakpoint (many breakpoints can share the same name.)
lldb::SearchFilterSP m_filter_sp; // The filter that constrains the breakpoint's domain.
lldb::BreakpointResolverSP m_resolver_sp; // The resolver that defines this breakpoint.
BreakpointOptions m_options; // Settable breakpoint options
Expand Down
15 changes: 15 additions & 0 deletions lldb/include/lldb/Breakpoint/BreakpointID.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ class BreakpointID
ParseCanonicalReference (const char *input, lldb::break_id_t *break_id, lldb::break_id_t *break_loc_id);


//------------------------------------------------------------------
/// Takes an input string and checks to see whether it is a breakpoint name.
/// If it is a mal-formed breakpoint name, error will be set to an appropriate
/// error string.
///
/// @param[in] input
/// A string containing JUST the breakpoint description.
/// @param[out] error
/// If the name is a well-formed breakpoint name, set to success, otherwise set to an error.
/// @return
/// \b true if the name is a breakpoint name (as opposed to an ID or range) false otherwise.
//------------------------------------------------------------------
static bool
StringIsBreakpointName (const char *name, Error &error);

//------------------------------------------------------------------
/// Takes a breakpoint ID and the breakpoint location id and returns
/// a string containing the canonical description for the breakpoint
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Breakpoint/BreakpointIDList.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BreakpointIDList
StringContainsIDRangeExpression (const char *in_string, size_t *range_start_len, size_t *range_end_pos);

static void
FindAndReplaceIDRanges (Args &old_args, Target *target, CommandReturnObject &result, Args &new_args);
FindAndReplaceIDRanges (Args &old_args, Target *target, bool allow_locations, CommandReturnObject &result, Args &new_args);

private:
BreakpointIDArray m_breakpoint_ids;
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ namespace lldb {
eArgTypeBoolean,
eArgTypeBreakpointID,
eArgTypeBreakpointIDRange,
eArgTypeBreakpointName,
eArgTypeByteSize,
eArgTypeClassName,
eArgTypeCommandName,
Expand Down
9 changes: 6 additions & 3 deletions lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "1"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
customWorkingDirectory = "/Volumes/work/gclayton/Documents/devb/attach"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "YES"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "26F5C26910F3D9A4009D5894"
Expand Down Expand Up @@ -147,7 +149,8 @@
buildConfiguration = "Release"
ignoresPersistentStateOnLaunch = "YES"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "26F5C26910F3D9A4009D5894"
Expand Down
12 changes: 12 additions & 0 deletions lldb/scripts/Python/interface/SBBreakpoint.i
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ public:
SBError
SetScriptCallbackBody (const char *script_body_text);

bool
AddName (const char *new_name);

void
RemoveName (const char *name_to_remove);

bool
MatchesName (const char *name);

void
GetNames (SBStringList &names);

size_t
GetNumResolvedLocations() const;

Expand Down
78 changes: 78 additions & 0 deletions lldb/source/API/SBBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
#include "lldb/API/SBThread.h"

#include "lldb/Breakpoint/Breakpoint.h"
Expand Down Expand Up @@ -653,6 +654,83 @@ SBBreakpoint::SetScriptCallbackBody (const char *callback_body_text)
return sb_error;
}

bool
SBBreakpoint::AddName (const char *new_name)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));

if (log)
log->Printf ("SBBreakpoint(%p)::AddName (name=%s)",
static_cast<void*>(m_opaque_sp.get()),
new_name);

if (m_opaque_sp)
{
Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
Error error; // Think I'm just going to swallow the error here, it's probably more annoying to have to provide it.
return m_opaque_sp->AddName(new_name, error);
}

return false;
}

void
SBBreakpoint::RemoveName (const char *name_to_remove)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));

if (log)
log->Printf ("SBBreakpoint(%p)::RemoveName (name=%s)",
static_cast<void*>(m_opaque_sp.get()),
name_to_remove);

if (m_opaque_sp)
{
Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
m_opaque_sp->RemoveName(name_to_remove);
}
}

bool
SBBreakpoint::MatchesName (const char *name)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));

if (log)
log->Printf ("SBBreakpoint(%p)::MatchesName (name=%s)",
static_cast<void*>(m_opaque_sp.get()),
name);

if (m_opaque_sp)
{
Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
return m_opaque_sp->MatchesName(name);
}

return false;
}

void
SBBreakpoint::GetNames (SBStringList &names)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));

if (log)
log->Printf ("SBBreakpoint(%p)::GetNames ()",
static_cast<void*>(m_opaque_sp.get()));

if (m_opaque_sp)
{
Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
std::vector<std::string> names_vec;
m_opaque_sp->GetNames(names_vec);
for (std::string name : names_vec)
{
names.AppendString (name.c_str());
}
}
}

lldb_private::Breakpoint *
SBBreakpoint::operator->() const
{
Expand Down
34 changes: 33 additions & 1 deletion lldb/source/Breakpoint/Breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ Breakpoint::Breakpoint (Target &new_target, Breakpoint &source_bp) :
m_target(new_target),
m_options (source_bp.m_options),
m_locations(*this),
m_resolve_indirect_symbols(source_bp.m_resolve_indirect_symbols)
m_resolve_indirect_symbols(source_bp.m_resolve_indirect_symbols),
m_name_list (source_bp.m_name_list)
{
// Now go through and copy the filter & resolver:
m_resolver_sp = source_bp.m_resolver_sp->CopyForBreakpoint(*this);
Expand Down Expand Up @@ -782,6 +783,23 @@ Breakpoint::GetNumLocations() const
return m_locations.GetSize();
}

bool
Breakpoint::AddName (const char *new_name, Error &error)
{
if (!new_name)
return false;
if (!BreakpointID::StringIsBreakpointName(new_name, error))
{
error.SetErrorStringWithFormat("input name \"%s\" not a breakpoint name.", new_name);
return false;
}
if (!error.Success())
return false;

m_name_list.insert(new_name);
return true;
}

void
Breakpoint::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_locations)
{
Expand Down Expand Up @@ -832,6 +850,20 @@ Breakpoint::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_l

if (level == lldb::eDescriptionLevelFull)
{
if (!m_name_list.empty())
{
s->EOL();
s->Indent();
s->Printf ("Names:");
s->EOL();
s->IndentMore();
for (std::string name : m_name_list)
{
s->Indent();
s->Printf("%s\n", name.c_str());
}
s->IndentLess();
}
s->IndentLess();
s->EOL();
}
Expand Down
17 changes: 17 additions & 0 deletions lldb/source/Breakpoint/BreakpointID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "lldb/Breakpoint/BreakpointID.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/Error.h"

using namespace lldb;
using namespace lldb_private;
Expand Down Expand Up @@ -121,3 +122,19 @@ BreakpointID::ParseCanonicalReference (const char *input, break_id_t *break_id_p
return false;
}

bool
BreakpointID::StringIsBreakpointName(const char *name, Error &error)
{
error.Clear();

if (name && (name[0] >= 'A' && name[0] <= 'z'))
{
if (strcspn(name, ".- ") != strlen(name))
{
error.SetErrorStringWithFormat("invalid breakpoint name: \"%s\"", name);
}
return true;
}
else
return false;
}
Loading

0 comments on commit 5e09c8c

Please sign in to comment.