Index: packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/TestMiBreak.py =================================================================== --- packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/TestMiBreak.py +++ packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/TestMiBreak.py @@ -143,6 +143,32 @@ self.expect("\^running") self.expect("\*stopped,reason=\"breakpoint-hit\"") + @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows. + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races. + @skipIfRemote # We do not currently support remote debugging via the MI. + def test_lldbmi_break_insert_without_target(self): + """Test that 'lldb-mi --interpreter' can set breakpoints without + selecting a valid target.""" + + self.spawnLldbMi(args=None) + + # This command have to insert breakpoint to the dummy target. + self.runCmd("-break-insert main") + # FIXME function name is unknown on Darwin, fullname should be ??, line is -1 + self.expect( + "\^done,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\"," + "addr=\"0xffffffffffffffff\",func=\"\?\?\",file=\"\?\?\",fullname=\"\?\?/\?\?\"," + "line=\"0\",pending=\[\"main\"\],times=\"0\",original-location=\"main\"}" + ) + + # Add a valid target. + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + self.runCmd("-exec-run") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races @skipIfRemote # We do not currently support remote debugging via the MI. Index: tools/lldb-mi/MICmdCmdBreak.cpp =================================================================== --- tools/lldb-mi/MICmdCmdBreak.cpp +++ tools/lldb-mi/MICmdCmdBreak.cpp @@ -148,6 +148,11 @@ 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(); @@ -157,7 +162,12 @@ 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) { @@ -225,9 +235,6 @@ // 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); Index: tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp =================================================================== --- tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp +++ tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp @@ -871,7 +871,10 @@ // Throws: None. //-- lldb::SBTarget CMICmnLLDBDebugSessionInfo::GetTarget() const { - return GetDebugger().GetSelectedTarget(); + auto target = GetDebugger().GetSelectedTarget(); + if (target.IsValid()) + return target; + return GetDebugger().GetDummyTarget(); } //++