Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[lldb-mi] Add possibility to set breakpoints without selecting a target.
Browse files Browse the repository at this point in the history
Now it's possible to set breakpoints before selecting a target, they
will be set to the dummy target and then copied to an each added one.

Patch by Alexander Polyakov!

Differential Revision: https://reviews.llvm.org/D46588

git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@333205 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
adrian-prantl committed May 24, 2018
1 parent 784251f commit 26acfa3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lit/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ debugserver = lit.util.which('debugserver', lldb_tools_dir)
lldb = "%s -S %s/lit-lldb-init" % (lit.util.which('lldb', lldb_tools_dir),
config.test_source_root)

lldbmi = lit.util.which('lldb-mi', lldb_tools_dir)

if not os.path.exists(config.cc):
config.cc = lit.util.which(config.cc, config.environment['PATH'])

Expand All @@ -79,6 +81,7 @@ if platform.system() in ['Darwin']:
config.substitutions.append(('%cc', config.cc))
config.substitutions.append(('%cxx', config.cxx))

config.substitutions.append(('%lldbmi', lldbmi + " --synchronous"))
config.substitutions.append(('%lldb', lldb))

if debugserver is not None:
Expand Down
15 changes: 15 additions & 0 deletions lit/tools/lldb-mi/breakpoint/break-insert.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# RUN: %cc %p/inputs/break-insert.c -g
# RUN: %lldbmi < %s | FileCheck %s

# Test that a breakpoint can be inserted before creating a target.

-break-insert breakpoint
# CHECK: ^done,bkpt={number="1"

-file-exec-and-symbols a.out
# CHECK: ^done

-exec-run
# CHECK: ^running
# CHECK: *stopped,reason="breakpoint-hit"

7 changes: 7 additions & 0 deletions lit/tools/lldb-mi/breakpoint/inputs/break-insert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int breakpoint() { // Breakpoint will be set here.
return 0;
}

int main() {
return breakpoint();
}
1 change: 1 addition & 0 deletions lit/tools/lldb-mi/breakpoint/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.suffixes = ['.test']
15 changes: 11 additions & 4 deletions tools/lldb-mi/MICmdCmdBreak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ bool CMICmdCmdBreakInsert::Execute() {
CMICMDBASE_GETOPTION(pArgRestrictBrkPtToThreadId, OptionShort,
m_constStrArgNamedRestrictBrkPtToThreadId);

// Ask LLDB for the target to check if we have valid or dummy one.
CMICmnLLDBDebugSessionInfo &rSessionInfo(
CMICmnLLDBDebugSessionInfo::Instance());
lldb::SBTarget sbTarget = rSessionInfo.GetTarget();

m_bBrkPtEnabled = !pArgDisableBrkPt->GetFound();
m_bBrkPtIsTemp = pArgTempBrkPt->GetFound();
m_bHaveArgOptionThreadGrp = pArgThreadGroup->GetFound();
Expand All @@ -157,7 +162,12 @@ bool CMICmdCmdBreakInsert::Execute() {
nThreadGrp);
m_strArgOptionThreadGrp = CMIUtilString::Format("i%d", nThreadGrp);
}
m_bBrkPtIsPending = pArgPendingBrkPt->GetFound();

if (sbTarget == rSessionInfo.GetDebugger().GetDummyTarget())
m_bBrkPtIsPending = true;
else
m_bBrkPtIsPending = pArgPendingBrkPt->GetFound();

if (pArgLocation->GetFound())
m_brkName = pArgLocation->GetValue();
else if (m_bBrkPtIsPending) {
Expand Down Expand Up @@ -225,9 +235,6 @@ bool CMICmdCmdBreakInsert::Execute() {

// Ask LLDB to create a breakpoint
bool bOk = MIstatus::success;
CMICmnLLDBDebugSessionInfo &rSessionInfo(
CMICmnLLDBDebugSessionInfo::Instance());
lldb::SBTarget sbTarget = rSessionInfo.GetTarget();
switch (eBrkPtType) {
case eBreakPoint_ByAddress:
m_brkPt = sbTarget.BreakpointCreateByAddress(nAddress);
Expand Down
5 changes: 4 additions & 1 deletion tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,10 @@ lldb::SBListener &CMICmnLLDBDebugSessionInfo::GetListener() const {
// Throws: None.
//--
lldb::SBTarget CMICmnLLDBDebugSessionInfo::GetTarget() const {
return GetDebugger().GetSelectedTarget();
auto target = GetDebugger().GetSelectedTarget();
if (target.IsValid())
return target;
return GetDebugger().GetDummyTarget();
}

//++
Expand Down

0 comments on commit 26acfa3

Please sign in to comment.