Bug Summary

File:tools/lldb/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
Warning:line 1420, column 5
Value stored to 'bOk' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name MICmnLLDBDebuggerHandleEvents.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D HAVE_ROUND -D LLDB_CONFIGURATION_RELEASE -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lldb/tools/lldb-mi -I /build/llvm-toolchain-snapshot-7~svn338205/tools/lldb/tools/lldb-mi -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn338205/tools/lldb/include -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn338205/include -I /usr/include/python2.7 -I /build/llvm-toolchain-snapshot-7~svn338205/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lldb/../clang/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/lib/gcc/x86_64-linux-gnu/8/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-comment -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/tools/lldb/tools/lldb-mi -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-07-29-043837-17923-1 -x c++ /build/llvm-toolchain-snapshot-7~svn338205/tools/lldb/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp -faddrsig
1//===-- MICmnLLDBDebuggerHandleEvents.cpp -----------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// Third party headers:
11#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBBreakpoint.h"
13#include "lldb/API/SBCommandInterpreter.h"
14#include "lldb/API/SBCommandReturnObject.h"
15#include "lldb/API/SBEvent.h"
16#include "lldb/API/SBProcess.h"
17#include "lldb/API/SBStream.h"
18#include "lldb/API/SBTarget.h"
19#include "lldb/API/SBThread.h"
20#include "lldb/API/SBUnixSignals.h"
21#include "llvm/Support/Compiler.h"
22#ifdef _WIN32
23#include <io.h> // For the ::_access()
24#else
25#include <unistd.h> // For the ::access()
26#endif // _WIN32
27
28// In-house headers:
29#include "MICmnLLDBDebugSessionInfo.h"
30#include "MICmnLLDBDebugger.h"
31#include "MICmnLLDBDebuggerHandleEvents.h"
32#include "MICmnLog.h"
33#include "MICmnMIOutOfBandRecord.h"
34#include "MICmnMIResultRecord.h"
35#include "MICmnMIValueConst.h"
36#include "MICmnMIValueList.h"
37#include "MICmnResources.h"
38#include "MICmnStreamStderr.h"
39#include "MICmnStreamStdout.h"
40#include "MIDriver.h"
41#include "MIUtilDebug.h"
42#include "Platform.h" // for PATH_MAX
43
44#include <algorithm>
45
46//++
47//------------------------------------------------------------------------------------
48// Details: CMICmnLLDBDebuggerHandleEvents constructor.
49// Type: Method.
50// Args: None.
51// Return: None.
52// Throws: None.
53//--
54CMICmnLLDBDebuggerHandleEvents::CMICmnLLDBDebuggerHandleEvents() {}
55
56//++
57//------------------------------------------------------------------------------------
58// Details: CMICmnLLDBDebuggerHandleEvents destructor.
59// Type: Overridable.
60// Args: None.
61// Return: None.
62// Throws: None.
63//--
64CMICmnLLDBDebuggerHandleEvents::~CMICmnLLDBDebuggerHandleEvents() {
65 Shutdown();
66}
67
68//++
69//------------------------------------------------------------------------------------
70// Details: Initialize resources for *this broadcaster object.
71// Type: Method.
72// Args: None.
73// Return: MIstatus::success - Functionality succeeded.
74// MIstatus::failure - Functionality failed.
75// Throws: None.
76//--
77bool CMICmnLLDBDebuggerHandleEvents::Initialize() {
78 m_clientUsageRefCnt++;
79
80 if (m_bInitialized)
81 return MIstatus::success;
82
83 m_bInitialized = MIstatus::success;
84 m_bSignalsInitialized = false;
85 m_SIGINT = 0;
86 m_SIGSTOP = 0;
87 m_SIGSEGV = 0;
88 m_SIGTRAP = 0;
89
90 return m_bInitialized;
91}
92
93//++
94//------------------------------------------------------------------------------------
95// Details: Release resources for *this broadcaster object.
96// Type: Method.
97// Args: None.
98// Return: MIstatus::success - Functionality succeeded.
99// MIstatus::failure - Functionality failed.
100// Throws: None.
101//--
102bool CMICmnLLDBDebuggerHandleEvents::Shutdown() {
103 if (--m_clientUsageRefCnt > 0)
104 return MIstatus::success;
105
106 if (!m_bInitialized)
107 return MIstatus::success;
108
109 m_bInitialized = false;
110
111 return MIstatus::success;
112}
113
114//++
115//------------------------------------------------------------------------------------
116// Details: Interpret the event object to ascertain the action to take or
117// information to
118// to form and put in a MI Out-of-band record object which is given to
119// stdout.
120// Type: Method.
121// Args: vEvent - (R) An LLDB broadcast event.
122// vrbHandledEvent - (W) True - event handled, false = not handled.
123// Return: MIstatus::success - Functionality succeeded.
124// MIstatus::failure - Functionality failed.
125// Throws: None.
126//--
127bool CMICmnLLDBDebuggerHandleEvents::HandleEvent(const lldb::SBEvent &vEvent,
128 bool &vrbHandledEvent) {
129 bool bOk = MIstatus::success;
130 vrbHandledEvent = false;
131
132 if (lldb::SBProcess::EventIsProcessEvent(vEvent)) {
133 vrbHandledEvent = true;
134 bOk = HandleEventSBProcess(vEvent);
135 } else if (lldb::SBBreakpoint::EventIsBreakpointEvent(vEvent)) {
136 vrbHandledEvent = true;
137 bOk = HandleEventSBBreakPoint(vEvent);
138 } else if (lldb::SBThread::EventIsThreadEvent(vEvent)) {
139 vrbHandledEvent = true;
140 bOk = HandleEventSBThread(vEvent);
141 } else if (lldb::SBTarget::EventIsTargetEvent(vEvent)) {
142 vrbHandledEvent = true;
143 bOk = HandleEventSBTarget(vEvent);
144 } else if (lldb::SBCommandInterpreter::EventIsCommandInterpreterEvent(
145 vEvent)) {
146 vrbHandledEvent = true;
147 bOk = HandleEventSBCommandInterpreter(vEvent);
148 }
149
150 return bOk;
151}
152
153//++
154//------------------------------------------------------------------------------------
155// Details: Handle a LLDB SBProcess event.
156// Type: Method.
157// Args: vEvent - (R) An LLDB broadcast event.
158// Return: MIstatus::success - Functionality succeeded.
159// MIstatus::failure - Functionality failed.
160// Throws: None.
161//--
162bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBProcess(
163 const lldb::SBEvent &vEvent) {
164 bool bOk = MIstatus::success;
165
166 const char *pEventType = "";
167 const MIuint nEventType = vEvent.GetType();
168 switch (nEventType) {
169 case lldb::SBProcess::eBroadcastBitInterrupt:
170 pEventType = "eBroadcastBitInterrupt";
171 break;
172 case lldb::SBProcess::eBroadcastBitProfileData:
173 pEventType = "eBroadcastBitProfileData";
174 break;
175 case lldb::SBProcess::eBroadcastBitStructuredData:
176 pEventType = "eBroadcastBitStructuredData";
177 break;
178 case lldb::SBProcess::eBroadcastBitStateChanged:
179 pEventType = "eBroadcastBitStateChanged";
180 bOk = HandleProcessEventBroadcastBitStateChanged(vEvent);
181 break;
182 case lldb::SBProcess::eBroadcastBitSTDERR:
183 pEventType = "eBroadcastBitSTDERR";
184 bOk = GetProcessStderr();
185 break;
186 case lldb::SBProcess::eBroadcastBitSTDOUT:
187 pEventType = "eBroadcastBitSTDOUT";
188 bOk = GetProcessStdout();
189 break;
190 default: {
191 const CMIUtilString msg(
192 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT
).c_str()
,
193 "SBProcess", (MIuint)nEventType));
194 SetErrorDescription(msg);
195 return MIstatus::failure;
196 }
197 }
198 m_pLog->WriteLog(CMIUtilString::Format(
199 "##### An SB Process event occurred: %s", pEventType));
200
201 return bOk;
202}
203
204//++
205//------------------------------------------------------------------------------------
206// Details: Handle a LLDB SBBreakpoint event.
207// Type: Method.
208// Args: vEvent - (R) An LLDB broadcast event.
209// Return: MIstatus::success - Functionality succeeded.
210// MIstatus::failure - Functionality failed.
211// Throws: None.
212//--
213bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBBreakPoint(
214 const lldb::SBEvent &vEvent) {
215 bool bOk = MIstatus::success;
216
217 const char *pEventType = "";
218 const lldb::BreakpointEventType eEvent =
219 lldb::SBBreakpoint::GetBreakpointEventTypeFromEvent(vEvent);
220 switch (eEvent) {
221 case lldb::eBreakpointEventTypeThreadChanged:
222 pEventType = "eBreakpointEventTypeThreadChanged";
223 break;
224 case lldb::eBreakpointEventTypeLocationsRemoved:
225 pEventType = "eBreakpointEventTypeLocationsRemoved";
226 break;
227 case lldb::eBreakpointEventTypeInvalidType:
228 pEventType = "eBreakpointEventTypeInvalidType";
229 break;
230 case lldb::eBreakpointEventTypeLocationsAdded:
231 pEventType = "eBreakpointEventTypeLocationsAdded";
232 bOk = HandleEventSBBreakpointLocationsAdded(vEvent);
233 break;
234 case lldb::eBreakpointEventTypeAdded:
235 pEventType = "eBreakpointEventTypeAdded";
236 bOk = HandleEventSBBreakpointAdded(vEvent);
237 break;
238 case lldb::eBreakpointEventTypeRemoved:
239 pEventType = "eBreakpointEventTypeRemoved";
240 bOk = HandleEventSBBreakpointCmn(vEvent);
241 break;
242 case lldb::eBreakpointEventTypeLocationsResolved:
243 pEventType = "eBreakpointEventTypeLocationsResolved";
244 bOk = HandleEventSBBreakpointCmn(vEvent);
245 break;
246 case lldb::eBreakpointEventTypeEnabled:
247 pEventType = "eBreakpointEventTypeEnabled";
248 bOk = HandleEventSBBreakpointCmn(vEvent);
249 break;
250 case lldb::eBreakpointEventTypeDisabled:
251 pEventType = "eBreakpointEventTypeDisabled";
252 bOk = HandleEventSBBreakpointCmn(vEvent);
253 break;
254 case lldb::eBreakpointEventTypeCommandChanged:
255 pEventType = "eBreakpointEventTypeCommandChanged";
256 bOk = HandleEventSBBreakpointCmn(vEvent);
257 break;
258 case lldb::eBreakpointEventTypeConditionChanged:
259 pEventType = "eBreakpointEventTypeConditionChanged";
260 bOk = HandleEventSBBreakpointCmn(vEvent);
261 break;
262 case lldb::eBreakpointEventTypeIgnoreChanged:
263 pEventType = "eBreakpointEventTypeIgnoreChanged";
264 bOk = HandleEventSBBreakpointCmn(vEvent);
265 break;
266 case lldb::eBreakpointEventTypeAutoContinueChanged:
267 pEventType = "eBreakpointEventTypeAutoContinueChanged";
268 bOk = HandleEventSBBreakpointCmn(vEvent);
269 break;
270 }
271 m_pLog->WriteLog(CMIUtilString::Format(
272 "##### An SB Breakpoint event occurred: %s", pEventType));
273
274 return bOk;
275}
276
277//++
278//------------------------------------------------------------------------------------
279// Details: Handle a LLDB SBBreakpoint event.
280// Type: Method.
281// Args: vEvent - (R) An LLDB broadcast event.
282// Return: MIstatus::success - Functionality succeeded.
283// MIstatus::failure - Functionality failed.
284// Throws: None.
285//--
286bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBBreakpointLocationsAdded(
287 const lldb::SBEvent &vEvent) {
288 const MIuint nLoc =
289 lldb::SBBreakpoint::GetNumBreakpointLocationsFromEvent(vEvent);
290 if (nLoc == 0)
291 return MIstatus::success;
292
293 lldb::SBBreakpoint brkPt = lldb::SBBreakpoint::GetBreakpointFromEvent(vEvent);
294 const CMIUtilString plural((nLoc == 1) ? "" : "s");
295 const CMIUtilString msg(
296 CMIUtilString::Format("%d location%s added to breakpoint %d", nLoc,
297 plural.c_str(), brkPt.GetID()));
298
299 return TextToStdout(msg);
300}
301
302//++
303//------------------------------------------------------------------------------------
304// Details: Handle a LLDB SBBreakpoint event.
305// Type: Method.
306// Args: vEvent - (R) An LLDB broadcast event.
307// Return: MIstatus::success - Functionality succeeded.
308// MIstatus::failure - Functionality failed.
309// Throws: None.
310//--
311bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBBreakpointCmn(
312 const lldb::SBEvent &vEvent) {
313 lldb::SBBreakpoint brkPt = lldb::SBBreakpoint::GetBreakpointFromEvent(vEvent);
314 if (!brkPt.IsValid())
315 return MIstatus::success;
316
317 CMICmnLLDBDebugSessionInfo &rSessionInfo(
318 CMICmnLLDBDebugSessionInfo::Instance());
319 CMICmnLLDBDebugSessionInfo::SBrkPtInfo sBrkPtInfo;
320 if (!rSessionInfo.GetBrkPtInfo(brkPt, sBrkPtInfo)) {
321 SetErrorDescription(
322 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_BRKPT_INFO_GET)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_BRKPT_INFO_GET
).c_str()
,
323 "HandleEventSBBreakpointCmn()", brkPt.GetID()));
324 return MIstatus::failure;
325 }
326
327 // CODETAG_LLDB_BREAKPOINT_CREATION
328 // This is in a worker thread
329 // Add more breakpoint information or overwrite existing information
330 CMICmnLLDBDebugSessionInfo::SBrkPtInfo sBrkPtInfoRec;
331 if (!rSessionInfo.RecordBrkPtInfoGet(brkPt.GetID(), sBrkPtInfoRec)) {
332 SetErrorDescription(
333 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_BRKPT_NOTFOUND)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_BRKPT_NOTFOUND
).c_str()
,
334 "HandleEventSBBreakpointCmn()", brkPt.GetID()));
335 return MIstatus::failure;
336 }
337 sBrkPtInfo.m_bDisp = sBrkPtInfoRec.m_bDisp;
338 sBrkPtInfo.m_bEnabled = brkPt.IsEnabled();
339 sBrkPtInfo.m_bHaveArgOptionThreadGrp = false;
340 sBrkPtInfo.m_strOptThrdGrp = "";
341 sBrkPtInfo.m_nTimes = brkPt.GetHitCount();
342 sBrkPtInfo.m_strOrigLoc = sBrkPtInfoRec.m_strOrigLoc;
343 sBrkPtInfo.m_nIgnore = sBrkPtInfoRec.m_nIgnore;
344 sBrkPtInfo.m_bPending = sBrkPtInfoRec.m_bPending;
345 sBrkPtInfo.m_bCondition = sBrkPtInfoRec.m_bCondition;
346 sBrkPtInfo.m_strCondition = sBrkPtInfoRec.m_strCondition;
347 sBrkPtInfo.m_bBrkPtThreadId = sBrkPtInfoRec.m_bBrkPtThreadId;
348 sBrkPtInfo.m_nBrkPtThreadId = sBrkPtInfoRec.m_nBrkPtThreadId;
349
350 // MI print
351 // "=breakpoint-modified,bkpt={number=\"%d\",type=\"breakpoint\",disp=\"%s\",enabled=\"%c\",addr=\"0x%016"
352 // PRIx64 "\",
353 // func=\"%s\",file=\"%s\",fullname=\"%s/%s\",line=\"%d\",times=\"%d\",original-location=\"%s\"}"
354 CMICmnMIValueTuple miValueTuple;
355 if (!rSessionInfo.MIResponseFormBrkPtInfo(sBrkPtInfo, miValueTuple)) {
356 SetErrorDescription(
357 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_FORM_MI_RESPONSE)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_FORM_MI_RESPONSE
).c_str()
,
358 "HandleEventSBBreakpointCmn()"));
359 return MIstatus::failure;
360 }
361
362 const CMICmnMIValueResult miValueResultC("bkpt", miValueTuple);
363 const CMICmnMIOutOfBandRecord miOutOfBandRecord(
364 CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified, miValueResultC);
365 bool bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
366 bOk = bOk && CMICmnStreamStdout::WritePrompt();
367
368 return bOk;
369}
370
371//++
372//------------------------------------------------------------------------------------
373// Details: Handle a LLDB SBBreakpoint added event.
374// Add more breakpoint information or overwrite existing information.
375// Normally a break point session info objects exists by now when an MI
376// command
377// was issued to insert a break so the retrieval would normally always
378// succeed
379// however should a user type "b main" into a console then LLDB will
380// create a
381// breakpoint directly, hence no MI command, hence no previous record
382// of the
383// breakpoint so RecordBrkPtInfoGet() will fail. We still get the event
384// though
385// so need to create a breakpoint info object here and send appropriate
386// MI
387// response.
388// Type: Method.
389// Args: vEvent - (R) An LLDB broadcast event.
390// Return: MIstatus::success - Functionality succeeded.
391// MIstatus::failure - Functionality failed.
392// Throws: None.
393//--
394bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBBreakpointAdded(
395 const lldb::SBEvent &vEvent) {
396 lldb::SBBreakpoint brkPt = lldb::SBBreakpoint::GetBreakpointFromEvent(vEvent);
397 if (!brkPt.IsValid())
398 return MIstatus::success;
399
400 CMICmnLLDBDebugSessionInfo &rSessionInfo(
401 CMICmnLLDBDebugSessionInfo::Instance());
402 CMICmnLLDBDebugSessionInfo::SBrkPtInfo sBrkPtInfo;
403 if (!rSessionInfo.GetBrkPtInfo(brkPt, sBrkPtInfo)) {
404 SetErrorDescription(
405 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_BRKPT_INFO_GET)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_BRKPT_INFO_GET
).c_str()
,
406 "HandleEventSBBreakpointAdded()", brkPt.GetID()));
407 return MIstatus::failure;
408 }
409
410 // CODETAG_LLDB_BREAKPOINT_CREATION
411 // This is in a worker thread
412 CMICmnLLDBDebugSessionInfo::SBrkPtInfo sBrkPtInfoRec;
413 const bool bBrkPtExistAlready =
414 rSessionInfo.RecordBrkPtInfoGet(brkPt.GetID(), sBrkPtInfoRec);
415 if (bBrkPtExistAlready) {
416 // Update breakpoint information object
417 sBrkPtInfo.m_bDisp = sBrkPtInfoRec.m_bDisp;
418 sBrkPtInfo.m_bEnabled = brkPt.IsEnabled();
419 sBrkPtInfo.m_bHaveArgOptionThreadGrp = false;
420 sBrkPtInfo.m_strOptThrdGrp.clear();
421 sBrkPtInfo.m_nTimes = brkPt.GetHitCount();
422 sBrkPtInfo.m_strOrigLoc = sBrkPtInfoRec.m_strOrigLoc;
423 sBrkPtInfo.m_nIgnore = sBrkPtInfoRec.m_nIgnore;
424 sBrkPtInfo.m_bPending = sBrkPtInfoRec.m_bPending;
425 sBrkPtInfo.m_bCondition = sBrkPtInfoRec.m_bCondition;
426 sBrkPtInfo.m_strCondition = sBrkPtInfoRec.m_strCondition;
427 sBrkPtInfo.m_bBrkPtThreadId = sBrkPtInfoRec.m_bBrkPtThreadId;
428 sBrkPtInfo.m_nBrkPtThreadId = sBrkPtInfoRec.m_nBrkPtThreadId;
429 } else {
430 // Create a breakpoint information object
431 sBrkPtInfo.m_bDisp = brkPt.IsOneShot();
432 sBrkPtInfo.m_bEnabled = brkPt.IsEnabled();
433 sBrkPtInfo.m_bHaveArgOptionThreadGrp = false;
434 sBrkPtInfo.m_strOptThrdGrp.clear();
435 sBrkPtInfo.m_strOrigLoc = CMIUtilString::Format(
436 "%s:%d", sBrkPtInfo.m_fileName.c_str(), sBrkPtInfo.m_nLine);
437 sBrkPtInfo.m_nIgnore = brkPt.GetIgnoreCount();
438 sBrkPtInfo.m_bPending = false;
439 const char *pStrCondition = brkPt.GetCondition();
440 sBrkPtInfo.m_bCondition = (pStrCondition != nullptr) ? true : false;
441 sBrkPtInfo.m_strCondition =
442 (pStrCondition != nullptr) ? pStrCondition : "??";
443 sBrkPtInfo.m_bBrkPtThreadId = (brkPt.GetThreadID() != 0) ? true : false;
444 sBrkPtInfo.m_nBrkPtThreadId = brkPt.GetThreadID();
445 }
446
447 CMICmnMIValueTuple miValueTuple;
448 if (!rSessionInfo.MIResponseFormBrkPtInfo(sBrkPtInfo, miValueTuple)) {
449 SetErrorDescription(
450 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_FORM_MI_RESPONSE)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_FORM_MI_RESPONSE
).c_str()
,
451 "HandleEventSBBreakpointAdded()"));
452 return MIstatus::failure;
453 }
454
455 bool bOk = MIstatus::success;
456 if (bBrkPtExistAlready) {
457 // MI print
458 // "=breakpoint-modified,bkpt={number=\"%d\",type=\"breakpoint\",disp=\"%s\",enabled=\"%c\",addr=\"0x%016"
459 // PRIx64
460 // "\",func=\"%s\",file=\"%s\",fullname=\"%s/%s\",line=\"%d\",times=\"%d\",original-location=\"%s\"}"
461 const CMICmnMIValueResult miValueResult("bkpt", miValueTuple);
462 const CMICmnMIOutOfBandRecord miOutOfBandRecord(
463 CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointModified, miValueResult);
464 bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
465 bOk = bOk && CMICmnStreamStdout::WritePrompt();
466 } else {
467 // CODETAG_LLDB_BRKPT_ID_MAX
468 if (brkPt.GetID() > (lldb::break_id_t)rSessionInfo.m_nBrkPointCntMax) {
469 SetErrorDescription(CMIUtilString::Format(
470 MIRSRC(IDS_CMD_ERR_BRKPT_CNT_EXCEEDED)CMICmnResources::Instance().GetString(IDS_CMD_ERR_BRKPT_CNT_EXCEEDED
).c_str()
,
471 "HandleEventSBBreakpointAdded()", rSessionInfo.m_nBrkPointCntMax,
472 sBrkPtInfo.m_id));
473 return MIstatus::failure;
474 }
475 if (!rSessionInfo.RecordBrkPtInfo(brkPt.GetID(), sBrkPtInfo)) {
476 SetErrorDescription(CMIUtilString::Format(
477 MIRSRC(IDS_LLDBOUTOFBAND_ERR_BRKPT_INFO_SET)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_BRKPT_INFO_SET
).c_str()
,
478 "HandleEventSBBreakpointAdded()", sBrkPtInfo.m_id));
479 return MIstatus::failure;
480 }
481
482 // MI print
483 // "=breakpoint-created,bkpt={number=\"%d\",type=\"breakpoint\",disp=\"%s\",enabled=\"%c\",addr=\"0x%016"
484 // PRIx64
485 // "\",func=\"%s\",file=\"%s\",fullname=\"%s/%s\",line=\"%d\",times=\"%d\",original-location=\"%s\"}"
486 const CMICmnMIValueResult miValueResult("bkpt", miValueTuple);
487 const CMICmnMIOutOfBandRecord miOutOfBandRecord(
488 CMICmnMIOutOfBandRecord::eOutOfBand_BreakPointCreated, miValueResult);
489 bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
490 bOk = bOk && CMICmnStreamStdout::WritePrompt();
491 }
492
493 return bOk;
494}
495
496//++
497//------------------------------------------------------------------------------------
498// Details: Handle a LLDB SBThread event.
499// Type: Method.
500// Args: vEvent - (R) An LLDB broadcast event.
501// Return: MIstatus::success - Functionality succeeded.
502// MIstatus::failure - Functionality failed.
503// Throws: None.
504//--
505bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBThread(
506 const lldb::SBEvent &vEvent) {
507 if (!ChkForStateChanges())
508 return MIstatus::failure;
509
510 bool bOk = MIstatus::success;
511 const char *pEventType = "";
512 const MIuint nEventType = vEvent.GetType();
513 switch (nEventType) {
514 case lldb::SBThread::eBroadcastBitStackChanged:
515 pEventType = "eBroadcastBitStackChanged";
516 bOk = HandleEventSBThreadBitStackChanged(vEvent);
517 break;
518 case lldb::SBThread::eBroadcastBitThreadSuspended:
519 pEventType = "eBroadcastBitThreadSuspended";
520 bOk = HandleEventSBThreadSuspended(vEvent);
521 break;
522 case lldb::SBThread::eBroadcastBitThreadResumed:
523 pEventType = "eBroadcastBitThreadResumed";
524 break;
525 case lldb::SBThread::eBroadcastBitSelectedFrameChanged:
526 pEventType = "eBroadcastBitSelectedFrameChanged";
527 break;
528 case lldb::SBThread::eBroadcastBitThreadSelected:
529 pEventType = "eBroadcastBitThreadSelected";
530 break;
531 default: {
532 const CMIUtilString msg(
533 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT
).c_str()
,
534 "SBThread", (MIuint)nEventType));
535 SetErrorDescription(msg);
536 return MIstatus::failure;
537 }
538 }
539 m_pLog->WriteLog(CMIUtilString::Format("##### An SBThread event occurred: %s",
540 pEventType));
541
542 return bOk;
543}
544
545//++
546//------------------------------------------------------------------------------------
547// Details: Handle a LLDB SBThread event.
548// Type: Method.
549// Args: vEvent - (R) An LLDB broadcast event.
550// Return: MIstatus::success - Functionality succeeded.
551// MIstatus::failure - Functionality failed.
552// Throws: None.
553//--
554bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBThreadSuspended(
555 const lldb::SBEvent &vEvent) {
556 lldb::SBThread thread = lldb::SBThread::GetThreadFromEvent(vEvent);
557 if (!thread.IsValid())
558 return MIstatus::success;
559
560 const lldb::StopReason eStopReason = thread.GetStopReason();
561 if (eStopReason != lldb::eStopReasonSignal)
562 return MIstatus::success;
563
564 // MI print "@thread=%d,signal=%lld"
565 const MIuint64 nId = thread.GetStopReasonDataAtIndex(0);
566 const CMIUtilString strThread(
567 CMIUtilString::Format("%d", thread.GetThreadID()));
568 const CMICmnMIValueConst miValueConst(strThread);
569 const CMICmnMIValueResult miValueResult("thread", miValueConst);
570 CMICmnMIOutOfBandRecord miOutOfBandRecord(
571 CMICmnMIOutOfBandRecord::eOutOfBand_Thread, miValueResult);
572 const CMIUtilString strSignal(CMIUtilString::Format("%lld", nId));
573 const CMICmnMIValueConst miValueConst2(strSignal);
574 const CMICmnMIValueResult miValueResult2("signal", miValueConst2);
575 miOutOfBandRecord.Add(miValueResult2);
576 return MiOutOfBandRecordToStdout(miOutOfBandRecord);
577}
578
579//++
580//------------------------------------------------------------------------------------
581// Details: Handle a LLDB SBThread event.
582// Type: Method.
583// Args: vEvent - (R) An LLDB broadcast event.
584// Return: MIstatus::success - Functionality succeeded.
585// MIstatus::failure - Functionality failed.
586// Throws: None.
587//--
588bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBThreadBitStackChanged(
589 const lldb::SBEvent &vEvent) {
590 lldb::SBThread thread = lldb::SBThread::GetThreadFromEvent(vEvent);
591 if (!thread.IsValid())
592 return MIstatus::success;
593
594 lldb::SBStream streamOut;
595 const bool bOk = thread.GetStatus(streamOut);
596 return bOk && TextToStdout(streamOut.GetData());
597}
598
599//++
600//------------------------------------------------------------------------------------
601// Details: Handle a LLDB SBTarget event.
602// Type: Method.
603// Args: vEvent - (R) An LLDB broadcast event.
604// Return: MIstatus::success - Functional succeeded.
605// MIstatus::failure - Functional failed.
606// Throws: None.
607//--
608bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBTarget(
609 const lldb::SBEvent &vEvent) {
610 if (!ChkForStateChanges())
611 return MIstatus::failure;
612
613 bool bOk = MIstatus::success;
614 const char *pEventType = "";
615 const MIuint nEventType = vEvent.GetType();
616 switch (nEventType) {
617 case lldb::SBTarget::eBroadcastBitBreakpointChanged:
618 pEventType = "eBroadcastBitBreakpointChanged";
619 break;
620 case lldb::SBTarget::eBroadcastBitModulesLoaded:
621 pEventType = "eBroadcastBitModulesLoaded";
622 bOk = HandleTargetEventBroadcastBitModulesLoaded(vEvent);
623 break;
624 case lldb::SBTarget::eBroadcastBitModulesUnloaded:
625 pEventType = "eBroadcastBitModulesUnloaded";
626 bOk = HandleTargetEventBroadcastBitModulesUnloaded(vEvent);
627 break;
628 case lldb::SBTarget::eBroadcastBitWatchpointChanged:
629 pEventType = "eBroadcastBitWatchpointChanged";
630 break;
631 case lldb::SBTarget::eBroadcastBitSymbolsLoaded:
632 pEventType = "eBroadcastBitSymbolsLoaded";
633 break;
634 default: {
635 const CMIUtilString msg(
636 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT
).c_str()
,
637 "SBTarget", (MIuint)nEventType));
638 SetErrorDescription(msg);
639 return MIstatus::failure;
640 }
641 }
642 m_pLog->WriteLog(CMIUtilString::Format("##### An SBTarget event occurred: %s",
643 pEventType));
644
645 return bOk;
646}
647
648//++
649//------------------------------------------------------------------------------------
650// Details: Print to stdout
651// "=library-loaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\",symbols-loaded="%d"[,symbols-path=\"%s\"],loaded_addr=\"0x%016"
652// PRIx64"\""
653// Type: Method.
654// Args: None.
655// Return: MIstatus::success - Function succeeded.
656// MIstatus::failure - Function failed.
657// Throws: None.
658//--
659bool CMICmnLLDBDebuggerHandleEvents::HandleTargetEventBroadcastBitModulesLoaded(
660 const lldb::SBEvent &vEvent) {
661 bool bOk = MIstatus::failure;
662 const MIuint nSize = lldb::SBTarget::GetNumModulesFromEvent(vEvent);
663 for (MIuint nIndex = 0; nIndex < nSize; ++nIndex) {
664 const lldb::SBModule sbModule =
665 lldb::SBTarget::GetModuleAtIndexFromEvent(nIndex, vEvent);
666 CMICmnMIOutOfBandRecord miOutOfBandRecord(
667 CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleLoaded);
668 const bool bWithExtraFields = true;
669 bOk = MiHelpGetModuleInfo(sbModule, bWithExtraFields, miOutOfBandRecord);
670 bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
671 if (!bOk)
672 break;
673 }
674
675 return bOk;
676}
677
678//++
679//------------------------------------------------------------------------------------
680// Details: Print to stdout
681// "=library-unloaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\",symbols-loaded="%d"[,symbols-path=\"%s\"],loaded_addr=\"0x%016"
682// PRIx64"\""
683// Type: Method.
684// Args: None.
685// Return: MIstatus::success - Function succeeded.
686// MIstatus::failure - Function failed.
687// Throws: None.
688//--
689bool CMICmnLLDBDebuggerHandleEvents::
690 HandleTargetEventBroadcastBitModulesUnloaded(const lldb::SBEvent &vEvent) {
691 bool bOk = MIstatus::failure;
692 const MIuint nSize = lldb::SBTarget::GetNumModulesFromEvent(vEvent);
693 for (MIuint nIndex = 0; nIndex < nSize; ++nIndex) {
694 const lldb::SBModule sbModule =
695 lldb::SBTarget::GetModuleAtIndexFromEvent(nIndex, vEvent);
696 CMICmnMIOutOfBandRecord miOutOfBandRecord(
697 CMICmnMIOutOfBandRecord::eOutOfBand_TargetModuleUnloaded);
698 const bool bWithExtraFields = false;
699 bOk = MiHelpGetModuleInfo(sbModule, bWithExtraFields, miOutOfBandRecord);
700 bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
701 if (!bOk)
702 break;
703 }
704
705 return bOk;
706}
707
708//++
709//------------------------------------------------------------------------------------
710// Details: Build module information for =library-loaded/=library-unloaded:
711// "id=\"%s\",target-name=\"%s\",host-name=\"%s\",symbols-loaded="%d"[,symbols-path=\"%s\"],loaded_addr=\"0x%016"
712// PRIx64"\""
713// Type: Method.
714// Args: vwrMiValueList - (W) MI value list object.
715// Return: MIstatus::success - Function succeeded.
716// MIstatus::failure - Function failed.
717// Throws: None.
718//--
719bool CMICmnLLDBDebuggerHandleEvents::MiHelpGetModuleInfo(
720 const lldb::SBModule &vModule, const bool vbWithExtraFields,
721 CMICmnMIOutOfBandRecord &vwrMiOutOfBandRecord) {
722 bool bOk = MIstatus::success;
723
724 // First, build standard fields:
725 // Build "id" field
726 std::unique_ptr<char[]> apPath(new char[PATH_MAX4096]);
727 vModule.GetFileSpec().GetPath(apPath.get(), PATH_MAX4096);
728 const CMIUtilString strTargetPath(apPath.get());
729 const CMICmnMIValueConst miValueConst(strTargetPath.AddSlashes());
730 const CMICmnMIValueResult miValueResult("id", miValueConst);
731 vwrMiOutOfBandRecord.Add(miValueResult);
732 // Build "target-name" field
733 const CMICmnMIValueConst miValueConst2(strTargetPath.AddSlashes());
734 const CMICmnMIValueResult miValueResult2("target-name", miValueConst2);
735 vwrMiOutOfBandRecord.Add(miValueResult2);
736 // Build "host-name" field
737 vModule.GetPlatformFileSpec().GetPath(apPath.get(), PATH_MAX4096);
738 const CMIUtilString strHostPath(apPath.get());
739 const CMICmnMIValueConst miValueConst3(strHostPath.AddSlashes());
740 const CMICmnMIValueResult miValueResult3("host-name", miValueConst3);
741 vwrMiOutOfBandRecord.Add(miValueResult3);
742
743 // Then build extra fields if needed:
744 if (vbWithExtraFields) {
745 // Build "symbols-loaded" field
746 vModule.GetSymbolFileSpec().GetPath(apPath.get(), PATH_MAX4096);
747 const CMIUtilString strSymbolsPath(apPath.get());
748 const bool bSymbolsLoaded =
749 !CMIUtilString::Compare(strHostPath, strSymbolsPath);
750 const CMICmnMIValueConst miValueConst4(
751 CMIUtilString::Format("%d", bSymbolsLoaded));
752 const CMICmnMIValueResult miValueResult4("symbols-loaded", miValueConst4);
753 vwrMiOutOfBandRecord.Add(miValueResult4);
754 // Build "symbols-path" field
755 if (bSymbolsLoaded) {
756 const CMICmnMIValueConst miValueConst5(strSymbolsPath.AddSlashes());
757 const CMICmnMIValueResult miValueResult5("symbols-path", miValueConst5);
758 vwrMiOutOfBandRecord.Add(miValueResult5);
759 }
760 // Build "loaded_addr" field
761 lldb::SBAddress sbAddress(vModule.GetObjectFileHeaderAddress());
762 CMICmnLLDBDebugSessionInfo &rSessionInfo(
763 CMICmnLLDBDebugSessionInfo::Instance());
764 const lldb::addr_t nLoadAddress(
765 sbAddress.GetLoadAddress(rSessionInfo.GetTarget()));
766 const CMIUtilString strLoadedAddr(
767 nLoadAddress != LLDB_INVALID_ADDRESS(18446744073709551615UL)
768 ? CMIUtilString::Format("0x%016" PRIx64"l" "x", nLoadAddress)
769 : "-");
770 const CMICmnMIValueConst miValueConst6(strLoadedAddr);
771 const CMICmnMIValueResult miValueResult6("loaded_addr", miValueConst6);
772 vwrMiOutOfBandRecord.Add(miValueResult6);
773
774 // Build "size" field
775 lldb::SBSection sbSection = sbAddress.GetSection();
776 const CMIUtilString strSize(
777 CMIUtilString::Format("%" PRIu64"l" "u", sbSection.GetByteSize()));
778 const CMICmnMIValueConst miValueConst7(strSize);
779 const CMICmnMIValueResult miValueResult7("size", miValueConst7);
780 vwrMiOutOfBandRecord.Add(miValueResult7);
781 }
782
783 return bOk;
784}
785
786//++
787//------------------------------------------------------------------------------------
788// Details: Handle a LLDB SBCommandInterpreter event.
789// Type: Method.
790// Args: vEvent - (R) An LLDB command interpreter event.
791// Return: MIstatus::success - Functionality succeeded.
792// MIstatus::failure - Functionality failed.
793// Throws: None.
794//--
795bool CMICmnLLDBDebuggerHandleEvents::HandleEventSBCommandInterpreter(
796 const lldb::SBEvent &vEvent) {
797 // This function is not used
798 // *** This function is under development
799
800 const char *pEventType = "";
801 const MIuint nEventType = vEvent.GetType();
802 switch (nEventType) {
803 case lldb::SBCommandInterpreter::eBroadcastBitThreadShouldExit:
804 pEventType = "eBroadcastBitThreadShouldExit";
805 // ToDo: IOR: Reminder to maybe handle this here
806 // const MIuint nEventType = event.GetType();
807 // if (nEventType &
808 // lldb::SBCommandInterpreter::eBroadcastBitThreadShouldExit)
809 //{
810 // m_pClientDriver->SetExitApplicationFlag();
811 // vrbYesExit = true;
812 // return MIstatus::success;
813 //}
814 break;
815 case lldb::SBCommandInterpreter::eBroadcastBitResetPrompt:
816 pEventType = "eBroadcastBitResetPrompt";
817 break;
818 case lldb::SBCommandInterpreter::eBroadcastBitQuitCommandReceived: {
819 pEventType = "eBroadcastBitQuitCommandReceived";
820 const bool bForceExit = true;
821 CMICmnLLDBDebugger::Instance().GetDriver().SetExitApplicationFlag(
822 bForceExit);
823 break;
824 }
825 case lldb::SBCommandInterpreter::eBroadcastBitAsynchronousOutputData:
826 pEventType = "eBroadcastBitAsynchronousOutputData";
827 break;
828 case lldb::SBCommandInterpreter::eBroadcastBitAsynchronousErrorData:
829 pEventType = "eBroadcastBitAsynchronousErrorData";
830 break;
831 default: {
832 const CMIUtilString msg(
833 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT
).c_str()
,
834 "SBCommandInterpreter", (MIuint)nEventType));
835 SetErrorDescription(msg);
836 return MIstatus::failure;
837 }
838 }
839 m_pLog->WriteLog(CMIUtilString::Format(
840 "##### An SBCommandInterpreter event occurred: %s", pEventType));
841
842 return MIstatus::success;
843}
844
845//++
846//------------------------------------------------------------------------------------
847// Details: Handle SBProcess event eBroadcastBitStateChanged.
848// Type: Method.
849// Args: vEvent - (R) An LLDB event object.
850// Return: MIstatus::success - Functionality succeeded.
851// MIstatus::failure - Functionality failed.
852// Throws: None.
853//--
854bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventBroadcastBitStateChanged(
855 const lldb::SBEvent &vEvent) {
856 // Make sure the program hasn't been auto-restarted:
857 if (lldb::SBProcess::GetRestartedFromEvent(vEvent))
858 return MIstatus::success;
859
860 bool bOk = ChkForStateChanges();
861 bOk = bOk && GetProcessStdout();
862 bOk = bOk && GetProcessStderr();
863 if (!bOk)
864 return MIstatus::failure;
865
866 // Something changed in the process; get the event and report the process's
867 // current
868 // status and location
869 const lldb::StateType eEventState =
870 lldb::SBProcess::GetStateFromEvent(vEvent);
871 if (eEventState == lldb::eStateInvalid)
872 return MIstatus::success;
873
874 lldb::SBProcess process = lldb::SBProcess::GetProcessFromEvent(vEvent);
875 if (!process.IsValid()) {
876 const CMIUtilString msg(CMIUtilString::Format(
877 MIRSRC(IDS_LLDBOUTOFBAND_ERR_PROCESS_INVALID)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_PROCESS_INVALID
).c_str()
, "SBProcess",
878 "HandleProcessEventBroadcastBitStateChanged()"));
879 SetErrorDescription(msg);
880 return MIstatus::failure;
881 }
882
883 bool bShouldBrk = true;
884 const char *pEventType = "";
885 switch (eEventState) {
886 case lldb::eStateUnloaded:
887 pEventType = "eStateUnloaded";
888 break;
889 case lldb::eStateConnected:
890 pEventType = "eStateConnected";
891 break;
892 case lldb::eStateAttaching:
893 pEventType = "eStateAttaching";
894 break;
895 case lldb::eStateLaunching:
896 pEventType = "eStateLaunching";
897 break;
898 case lldb::eStateStopped:
899 pEventType = "eStateStopped";
900 bOk = HandleProcessEventStateStopped(vEvent, bShouldBrk);
901 if (bShouldBrk)
902 break;
903 LLVM_FALLTHROUGH[[clang::fallthrough]];
904 case lldb::eStateCrashed:
905 case lldb::eStateSuspended:
906 pEventType = "eStateSuspended";
907 bOk = HandleProcessEventStateSuspended(vEvent);
908 break;
909 case lldb::eStateRunning:
910 pEventType = "eStateRunning";
911 bOk = HandleProcessEventStateRunning();
912 break;
913 case lldb::eStateStepping:
914 pEventType = "eStateStepping";
915 break;
916 case lldb::eStateDetached:
917 pEventType = "eStateDetached";
918 break;
919 case lldb::eStateExited:
920 // Don't exit from lldb-mi here. We should be able to re-run target.
921 pEventType = "eStateExited";
922 bOk = HandleProcessEventStateExited();
923 break;
924 default: {
925 const CMIUtilString msg(CMIUtilString::Format(
926 MIRSRC(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_UNKNOWN_EVENT
).c_str()
,
927 "SBProcess BroadcastBitStateChanged", (MIuint)eEventState));
928 SetErrorDescription(msg);
929 return MIstatus::failure;
930 }
931 }
932
933 // ToDo: Remove when finished coding application
934 m_pLog->WriteLog(CMIUtilString::Format(
935 "##### An SB Process event BroadcastBitStateChanged occurred: %s",
936 pEventType));
937
938 return bOk;
939}
940
941//++
942//------------------------------------------------------------------------------------
943// Details: Asynchronous event handler for LLDB Process state suspended.
944// Type: Method.
945// Args: vEvent - (R) An LLDB event object.
946// Return: MIstatus::success - Functionality succeeded.
947// MIstatus::failure - Functionality failed.
948// Throws: None.
949//--
950bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStateSuspended(
951 const lldb::SBEvent &vEvent) {
952 bool bOk = MIstatus::success;
953 lldb::SBDebugger &rDebugger =
954 CMICmnLLDBDebugSessionInfo::Instance().GetDebugger();
955 lldb::SBProcess sbProcess =
956 CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
957 lldb::SBTarget target = sbProcess.GetTarget();
958 if (rDebugger.GetSelectedTarget() == target) {
959 if (!UpdateSelectedThread())
960 return MIstatus::failure;
961
962 lldb::SBCommandReturnObject result;
963 const lldb::ReturnStatus status =
964 rDebugger.GetCommandInterpreter().HandleCommand("process status",
965 result, false);
966 MIunused(status)(void)status;;
967 bOk = TextToStderr(result.GetError());
968 bOk = bOk && TextToStdout(result.GetOutput());
969 } else {
970 lldb::SBStream streamOut;
971 const MIuint nTargetIndex = rDebugger.GetIndexOfTarget(target);
972 if (nTargetIndex != UINT_MAX(2147483647 *2U +1U))
973 streamOut.Printf("Target %d: (", nTargetIndex);
974 else
975 streamOut.Printf("Target <unknown index>: (");
976 target.GetDescription(streamOut, lldb::eDescriptionLevelBrief);
977 streamOut.Printf(") stopped.\n");
978 bOk = TextToStdout(streamOut.GetData());
979 }
980
981 return bOk;
982}
983
984//++
985//------------------------------------------------------------------------------------
986// Details: Print to stdout MI formatted text to indicate process stopped.
987// Type: Method.
988// Args: vwrbShouldBrk - (W) True = Yes break, false = do not.
989// Return: MIstatus::success - Functionality succeeded.
990// MIstatus::failure - Functionality failed.
991// Throws: None.
992//--
993bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStateStopped(
994 const lldb::SBEvent &vrEvent, bool &vwrbShouldBrk) {
995 if (!UpdateSelectedThread())
996 return MIstatus::failure;
997
998 const char *pEventType = "";
999 bool bOk = MIstatus::success;
1000 lldb::SBProcess sbProcess =
1001 CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
1002 const lldb::StopReason eStoppedReason =
1003 sbProcess.GetSelectedThread().GetStopReason();
1004 switch (eStoppedReason) {
1005 case lldb::eStopReasonInvalid:
1006 pEventType = "eStopReasonInvalid";
1007 vwrbShouldBrk = false;
1008 break;
1009 case lldb::eStopReasonNone:
1010 pEventType = "eStopReasonNone";
1011 break;
1012 case lldb::eStopReasonTrace:
1013 pEventType = "eStopReasonTrace";
1014 bOk = HandleProcessEventStopReasonTrace();
1015 break;
1016 case lldb::eStopReasonBreakpoint:
1017 pEventType = "eStopReasonBreakpoint";
1018 bOk = HandleProcessEventStopReasonBreakpoint();
1019 break;
1020 case lldb::eStopReasonWatchpoint:
1021 pEventType = "eStopReasonWatchpoint";
1022 break;
1023 case lldb::eStopReasonSignal:
1024 pEventType = "eStopReasonSignal";
1025 bOk = HandleProcessEventStopSignal(vrEvent);
1026 break;
1027 case lldb::eStopReasonException:
1028 pEventType = "eStopReasonException";
1029 bOk = HandleProcessEventStopException();
1030 break;
1031 case lldb::eStopReasonExec:
1032 pEventType = "eStopReasonExec";
1033 break;
1034 case lldb::eStopReasonPlanComplete:
1035 pEventType = "eStopReasonPlanComplete";
1036 bOk = HandleProcessEventStopReasonTrace();
1037 break;
1038 case lldb::eStopReasonThreadExiting:
1039 pEventType = "eStopReasonThreadExiting";
1040 break;
1041 case lldb::eStopReasonInstrumentation:
1042 pEventType = "eStopReasonInstrumentation";
1043 break;
1044 }
1045
1046 // ToDo: Remove when finished coding application
1047 m_pLog->WriteLog(CMIUtilString::Format(
1048 "##### An SB Process event stop state occurred: %s", pEventType));
1049
1050 return bOk;
1051}
1052
1053//++
1054//------------------------------------------------------------------------------------
1055// Details: Asynchronous event handler for LLDB Process stop signal.
1056// Type: Method.
1057// Args: vrEvent - (R) An LLDB broadcast event.
1058// Return: MIstatus::success - Functionality succeeded.
1059// MIstatus::failure - Functionality failed.
1060// Throws: None.
1061//--
1062bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopSignal(
1063 const lldb::SBEvent &vrEvent) {
1064 bool bOk = MIstatus::success;
1065
1066 InitializeSignals();
1067 lldb::SBProcess sbProcess =
1068 CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
1069 const MIuint64 nStopReason =
1070 sbProcess.GetSelectedThread().GetStopReasonDataAtIndex(0);
1071 const bool bInterrupted = lldb::SBProcess::GetInterruptedFromEvent(vrEvent);
1072 if (nStopReason == m_SIGINT || (nStopReason == m_SIGSTOP && bInterrupted)) {
1073 // MI print
1074 // "*stopped,reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\",frame={%s},thread-id=\"%d\",stopped-threads=\"all\""
1075 const CMICmnMIValueConst miValueConst("signal-received");
1076 const CMICmnMIValueResult miValueResult("reason", miValueConst);
1077 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1078 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult);
1079 const CMICmnMIValueConst miValueConst2("SIGINT");
1080 const CMICmnMIValueResult miValueResult2("signal-name", miValueConst2);
1081 miOutOfBandRecord.Add(miValueResult2);
1082 const CMICmnMIValueConst miValueConst3("Interrupt");
1083 const CMICmnMIValueResult miValueResult3("signal-meaning", miValueConst3);
1084 miOutOfBandRecord.Add(miValueResult3);
1085 CMICmnMIValueTuple miValueTuple;
1086 bOk = bOk && MiHelpGetCurrentThreadFrame(miValueTuple);
1087 const CMICmnMIValueResult miValueResult4("frame", miValueTuple);
1088 miOutOfBandRecord.Add(miValueResult4);
1089 const CMIUtilString strThreadId(CMIUtilString::Format(
1090 "%" PRIu32"u", sbProcess.GetSelectedThread().GetIndexID()));
1091 const CMICmnMIValueConst miValueConst5(strThreadId);
1092 const CMICmnMIValueResult miValueResult5("thread-id", miValueConst5);
1093 miOutOfBandRecord.Add(miValueResult5);
1094 const CMICmnMIValueConst miValueConst6("all");
1095 const CMICmnMIValueResult miValueResult6("stopped-threads", miValueConst6);
1096 miOutOfBandRecord.Add(miValueResult6);
1097 bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
1098 bOk = bOk && CMICmnStreamStdout::WritePrompt();
1099 } else if (nStopReason == m_SIGSTOP) {
1100 // MI print
1101 // "*stopped,reason=\"signal-received\",signal-name=\"SIGSTOP\",signal-meaning=\"Stop\",frame={%s},thread-id=\"%d\",stopped-threads=\"all\""
1102 const CMICmnMIValueConst miValueConst("signal-received");
1103 const CMICmnMIValueResult miValueResult("reason", miValueConst);
1104 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1105 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult);
1106 const CMICmnMIValueConst miValueConst2("SIGSTOP");
1107 const CMICmnMIValueResult miValueResult2("signal-name", miValueConst2);
1108 miOutOfBandRecord.Add(miValueResult2);
1109 const CMICmnMIValueConst miValueConst3("Stop");
1110 const CMICmnMIValueResult miValueResult3("signal-meaning", miValueConst3);
1111 miOutOfBandRecord.Add(miValueResult3);
1112 CMICmnMIValueTuple miValueTuple;
1113 bOk = bOk && MiHelpGetCurrentThreadFrame(miValueTuple);
1114 const CMICmnMIValueResult miValueResult4("frame", miValueTuple);
1115 miOutOfBandRecord.Add(miValueResult4);
1116 const CMIUtilString strThreadId(CMIUtilString::Format(
1117 "%" PRIu32"u", sbProcess.GetSelectedThread().GetIndexID()));
1118 const CMICmnMIValueConst miValueConst5(strThreadId);
1119 const CMICmnMIValueResult miValueResult5("thread-id", miValueConst5);
1120 miOutOfBandRecord.Add(miValueResult5);
1121 const CMICmnMIValueConst miValueConst6("all");
1122 const CMICmnMIValueResult miValueResult6("stopped-threads", miValueConst6);
1123 miOutOfBandRecord.Add(miValueResult6);
1124 bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
1125 bOk = bOk && CMICmnStreamStdout::WritePrompt();
1126 } else if (nStopReason == m_SIGSEGV) {
1127 // MI print
1128 // "*stopped,reason=\"signal-received\",signal-name=\"SIGSEGV\",signal-meaning=\"Segmentation
1129 // fault\",thread-id=\"%d\",frame={%s}"
1130 const CMICmnMIValueConst miValueConst("signal-received");
1131 const CMICmnMIValueResult miValueResult("reason", miValueConst);
1132 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1133 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult);
1134 const CMICmnMIValueConst miValueConst2("SIGSEGV");
1135 const CMICmnMIValueResult miValueResult2("signal-name", miValueConst2);
1136 miOutOfBandRecord.Add(miValueResult2);
1137 const CMICmnMIValueConst miValueConst3("Segmentation fault");
1138 const CMICmnMIValueResult miValueResult3("signal-meaning", miValueConst3);
1139 miOutOfBandRecord.Add(miValueResult3);
1140 CMICmnMIValueTuple miValueTuple;
1141 bOk = bOk && MiHelpGetCurrentThreadFrame(miValueTuple);
1142 const CMICmnMIValueResult miValueResult4("frame", miValueTuple);
1143 miOutOfBandRecord.Add(miValueResult4);
1144 const CMIUtilString strThreadId(CMIUtilString::Format(
1145 "%d", sbProcess.GetSelectedThread().GetIndexID()));
1146 const CMICmnMIValueConst miValueConst5(strThreadId);
1147 const CMICmnMIValueResult miValueResult5("thread-id", miValueConst5);
1148 miOutOfBandRecord.Add(miValueResult5);
1149 bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
1150 // Note no "(gdb)" output here
1151 } else if (nStopReason == m_SIGTRAP) {
1152 lldb::SBThread thread = sbProcess.GetSelectedThread();
1153 const MIuint nFrames = thread.GetNumFrames();
1154 if (nFrames > 0) {
1155 lldb::SBFrame frame = thread.GetFrameAtIndex(0);
1156 const char *pFnName = frame.GetFunctionName();
1157 if (pFnName != nullptr) {
1158 const CMIUtilString fnName = CMIUtilString(pFnName);
1159 static const CMIUtilString threadCloneFn =
1160 CMIUtilString("__pthread_clone");
1161
1162 if (CMIUtilString::Compare(threadCloneFn, fnName)) {
1163 if (sbProcess.IsValid())
1164 sbProcess.Continue();
1165 }
1166 }
1167 }
1168 } else {
1169 // MI print
1170 // "*stopped,reason=\"signal-received\",signal-name=\"%s\",thread-id=\"%d\",stopped-threads=\"all\""
1171 // MI print
1172 // "*stopped,reason=\"signal-received\",signal=\"%d\",thread-id=\"%d\",stopped-threads=\"all\""
1173 const CMICmnMIValueConst miValueConst("signal-received");
1174 const CMICmnMIValueResult miValueResult("reason", miValueConst);
1175 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1176 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult);
1177 lldb::SBUnixSignals sbUnixSignals = sbProcess.GetUnixSignals();
1178 const char *pSignal = sbUnixSignals.GetSignalAsCString(nStopReason);
1179 if (pSignal) {
1180 const CMICmnMIValueConst miValueConst2(pSignal);
1181 const CMICmnMIValueResult miValueResult2("signal-name", miValueConst2);
1182 miOutOfBandRecord.Add(miValueResult2);
1183 } else {
1184 const CMIUtilString strSignal(
1185 CMIUtilString::Format("%" PRIu64"l" "u", nStopReason));
1186 const CMICmnMIValueConst miValueConst2(strSignal);
1187 const CMICmnMIValueResult miValueResult2("signal", miValueConst2);
1188 miOutOfBandRecord.Add(miValueResult2);
1189 }
1190 const CMIUtilString strThreadId(CMIUtilString::Format(
1191 "%d", sbProcess.GetSelectedThread().GetIndexID()));
1192 const CMICmnMIValueConst miValueConst3(strThreadId);
1193 const CMICmnMIValueResult miValueResult3("thread-id", miValueConst3);
1194 miOutOfBandRecord.Add(miValueResult3);
1195 const CMICmnMIValueConst miValueConst4("all");
1196 const CMICmnMIValueResult miValueResult4("stopped-threads", miValueConst4);
1197 miOutOfBandRecord.Add(miValueResult4);
1198 bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
1199 bOk = bOk && CMICmnStreamStdout::WritePrompt();
1200 }
1201 return bOk;
1202}
1203
1204//++
1205//------------------------------------------------------------------------------------
1206// Details: Asynchronous event handler for LLDB Process stop exception.
1207// Type: Method.
1208// Args: None.
1209// Return: MIstatus::success - Functional succeeded.
1210// MIstatus::failure - Functional failed.
1211// Throws: None.
1212//--
1213bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopException() {
1214 const lldb::SBProcess sbProcess =
1215 CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
1216 lldb::SBThread sbThread = sbProcess.GetSelectedThread();
1217 const size_t nStopDescriptionLen = sbThread.GetStopDescription(nullptr, 0);
1218 std::unique_ptr<char[]> apStopDescription(new char[nStopDescriptionLen]);
1219 sbThread.GetStopDescription(apStopDescription.get(), nStopDescriptionLen);
1220
1221 // MI print
1222 // "*stopped,reason=\"exception-received\",exception=\"%s\",thread-id=\"%d\",stopped-threads=\"all\""
1223 const CMICmnMIValueConst miValueConst("exception-received");
1224 const CMICmnMIValueResult miValueResult("reason", miValueConst);
1225 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1226 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult);
1227 const CMIUtilString strReason(apStopDescription.get());
1228 const CMICmnMIValueConst miValueConst2(strReason);
1229 const CMICmnMIValueResult miValueResult2("exception", miValueConst2);
1230 miOutOfBandRecord.Add(miValueResult2);
1231 const CMIUtilString strThreadId(
1232 CMIUtilString::Format("%d", sbThread.GetIndexID()));
1233 const CMICmnMIValueConst miValueConst3(strThreadId);
1234 const CMICmnMIValueResult miValueResult3("thread-id", miValueConst3);
1235 miOutOfBandRecord.Add(miValueResult3);
1236 const CMICmnMIValueConst miValueConst4("all");
1237 const CMICmnMIValueResult miValueResult4("stopped-threads", miValueConst4);
1238 miOutOfBandRecord.Add(miValueResult4);
1239 bool bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
1240 bOk = bOk && CMICmnStreamStdout::WritePrompt();
1241
1242 return bOk;
1243}
1244
1245//++
1246//------------------------------------------------------------------------------------
1247// Details: Form partial MI response in a MI value tuple object.
1248// Type: Method.
1249// Args: vwrMiValueTuple - (W) MI value tuple object.
1250// Return: MIstatus::success - Functionality succeeded.
1251// MIstatus::failure - Functionality failed.
1252// Throws: None.
1253//--
1254bool CMICmnLLDBDebuggerHandleEvents::MiHelpGetCurrentThreadFrame(
1255 CMICmnMIValueTuple &vwrMiValueTuple) {
1256 CMIUtilString strThreadFrame;
1257 lldb::SBProcess sbProcess =
1258 CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
1259 lldb::SBThread thread = sbProcess.GetSelectedThread();
1260 const MIuint nFrame = thread.GetNumFrames();
1261 if (nFrame == 0) {
1262 // MI print
1263 // "addr=\"??\",func=\"??\",file=\"??\",fullname=\"??\",line=\"??\""
1264 const CMICmnMIValueConst miValueConst("??");
1265 const CMICmnMIValueResult miValueResult("addr", miValueConst);
1266 CMICmnMIValueTuple miValueTuple(miValueResult);
1267 const CMICmnMIValueResult miValueResult2("func", miValueConst);
1268 miValueTuple.Add(miValueResult2);
1269 const CMICmnMIValueResult miValueResult4("file", miValueConst);
1270 miValueTuple.Add(miValueResult4);
1271 const CMICmnMIValueResult miValueResult5("fullname", miValueConst);
1272 miValueTuple.Add(miValueResult5);
1273 const CMICmnMIValueResult miValueResult6("line", miValueConst);
1274 miValueTuple.Add(miValueResult6);
1275
1276 vwrMiValueTuple = miValueTuple;
1277
1278 return MIstatus::success;
1279 }
1280
1281 CMICmnMIValueTuple miValueTuple;
1282 if (!CMICmnLLDBDebugSessionInfo::Instance().MIResponseFormFrameInfo(
1283 thread, 0, CMICmnLLDBDebugSessionInfo::eFrameInfoFormat_NoArguments,
1284 miValueTuple)) {
1285 SetErrorDescription(
1286 CMIUtilString::Format(MIRSRC(IDS_LLDBOUTOFBAND_ERR_FORM_MI_RESPONSE)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_FORM_MI_RESPONSE
).c_str()
,
1287 "MiHelpGetCurrentThreadFrame()"));
1288 return MIstatus::failure;
1289 }
1290
1291 vwrMiValueTuple = miValueTuple;
1292
1293 return MIstatus::success;
1294}
1295
1296//++
1297//------------------------------------------------------------------------------------
1298// Details: Asynchronous event handler for LLDB Process stop reason breakpoint.
1299// Type: Method.
1300// Args: None.
1301// Return: MIstatus::success - Functionality succeeded.
1302// MIstatus::failure - Functionality failed.
1303// Throws: None.
1304//--
1305bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopReasonBreakpoint() {
1306 // CODETAG_DEBUG_SESSION_RUNNING_PROG_RECEIVED_SIGINT_PAUSE_PROGRAM
1307 if (!CMIDriver::Instance().SetDriverStateRunningNotDebugging()) {
1308 const CMIUtilString &rErrMsg(CMIDriver::Instance().GetErrorDescription());
1309 SetErrorDescription(CMIUtilString::Format(
1310 MIRSRC(IDS_LLDBOUTOFBAND_ERR_SETNEWDRIVERSTATE)CMICmnResources::Instance().GetString(IDS_LLDBOUTOFBAND_ERR_SETNEWDRIVERSTATE
).c_str()
,
1311 "HandleProcessEventStopReasonBreakpoint()", rErrMsg.c_str()));
1312 return MIstatus::failure;
1313 }
1314
1315 lldb::SBProcess sbProcess =
1316 CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
1317 const MIuint64 brkPtId =
1318 sbProcess.GetSelectedThread().GetStopReasonDataAtIndex(0);
1319 lldb::SBBreakpoint brkPt =
1320 CMICmnLLDBDebugSessionInfo::Instance().GetTarget().GetBreakpointAtIndex(
1321 (MIuint)brkPtId);
1322
1323 return MiStoppedAtBreakPoint(brkPtId, brkPt);
1324}
1325
1326//++
1327//------------------------------------------------------------------------------------
1328// Details: Form the MI Out-of-band response for stopped reason on hitting a
1329// break point.
1330// Type: Method.
1331// Args: vBrkPtId - (R) The LLDB break point's ID
1332// vBrkPt - (R) THe LLDB break point object.
1333// Return: MIstatus::success - Functionality succeeded.
1334// MIstatus::failure - Functionality failed.
1335// Throws: None.
1336//--
1337bool CMICmnLLDBDebuggerHandleEvents::MiStoppedAtBreakPoint(
1338 const MIuint64 vBrkPtId, const lldb::SBBreakpoint &vBrkPt) {
1339 bool bOk = MIstatus::success;
1340
1341 lldb::SBProcess sbProcess =
1342 CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
1343 lldb::SBThread thread = sbProcess.GetSelectedThread();
1344 const MIuint nFrame = thread.GetNumFrames();
1345 if (nFrame == 0) {
1346 // MI print
1347 // "*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"%d\",frame={},thread-id=\"%d\",stopped-threads=\"all\""
1348 const CMICmnMIValueConst miValueConst("breakpoint-hit");
1349 const CMICmnMIValueResult miValueResult("reason", miValueConst);
1350 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1351 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult);
1352 const CMICmnMIValueConst miValueConst2("del");
1353 const CMICmnMIValueResult miValueResult2("disp", miValueConst2);
1354 miOutOfBandRecord.Add(miValueResult2);
1355 const CMIUtilString strBkp(CMIUtilString::Format("%d", vBrkPtId));
1356 const CMICmnMIValueConst miValueConst3(strBkp);
1357 CMICmnMIValueResult miValueResult3("bkptno", miValueConst3);
1358 miOutOfBandRecord.Add(miValueResult3);
1359 const CMICmnMIValueConst miValueConst4("{}");
1360 const CMICmnMIValueResult miValueResult4("frame", miValueConst4);
1361 miOutOfBandRecord.Add(miValueResult4);
1362 const CMIUtilString strThreadId(
1363 CMIUtilString::Format("%d", vBrkPt.GetThreadIndex()));
1364 const CMICmnMIValueConst miValueConst5(strThreadId);
1365 const CMICmnMIValueResult miValueResult5("thread-id", miValueConst5);
1366 miOutOfBandRecord.Add(miValueResult5);
1367 const CMICmnMIValueConst miValueConst6("all");
1368 const CMICmnMIValueResult miValueResult6("stopped-threads", miValueConst6);
1369 miOutOfBandRecord.Add(miValueResult6);
1370 bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
1371 bOk = bOk && CMICmnStreamStdout::WritePrompt();
1372 return bOk;
1373 }
1374
1375 CMICmnLLDBDebugSessionInfo &rSessionInfo(
1376 CMICmnLLDBDebugSessionInfo::Instance());
1377
1378 // MI print
1379 // "*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"%d\",frame={addr=\"0x%016"
1380 // PRIx64
1381 // "\",func=\"%s\",args=[],file=\"%s\",fullname=\"%s\",line=\"%d\"},thread-id=\"%d\",stopped-threads=\"all\""
1382 const CMICmnMIValueConst miValueConst("breakpoint-hit");
1383 const CMICmnMIValueResult miValueResult("reason", miValueConst);
1384 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1385 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult);
1386 const CMICmnMIValueConst miValueConstA("del");
1387 const CMICmnMIValueResult miValueResultA("disp", miValueConstA);
1388 miOutOfBandRecord.Add(miValueResultA);
1389 const CMIUtilString strBkp(CMIUtilString::Format("%d", vBrkPtId));
1390 const CMICmnMIValueConst miValueConstB(strBkp);
1391 CMICmnMIValueResult miValueResultB("bkptno", miValueConstB);
1392 miOutOfBandRecord.Add(miValueResultB);
1393
1394 // frame={addr=\"0x%016" PRIx64
1395 // "\",func=\"%s\",args=[],file=\"%s\",fullname=\"%s\",line=\"%d\"}
1396 if (bOk) {
1397 CMICmnMIValueTuple miValueTuple;
1398 bOk = bOk &&
1399 rSessionInfo.MIResponseFormFrameInfo(
1400 thread, 0,
1401 CMICmnLLDBDebugSessionInfo::eFrameInfoFormat_AllArguments,
1402 miValueTuple);
1403 const CMICmnMIValueResult miValueResult8("frame", miValueTuple);
1404 miOutOfBandRecord.Add(miValueResult8);
1405 }
1406
1407 // Add to MI thread-id=\"%d\",stopped-threads=\"all\"
1408 if (bOk) {
1409 const CMIUtilString strThreadId(
1410 CMIUtilString::Format("%d", thread.GetIndexID()));
1411 const CMICmnMIValueConst miValueConst8(strThreadId);
1412 const CMICmnMIValueResult miValueResult8("thread-id", miValueConst8);
1413 miOutOfBandRecord.Add(miValueResult8);
1414 }
1415 if (bOk) {
1416 const CMICmnMIValueConst miValueConst9("all");
1417 const CMICmnMIValueResult miValueResult9("stopped-threads", miValueConst9);
1418 miOutOfBandRecord.Add(miValueResult9);
1419 bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
1420 bOk = bOk && CMICmnStreamStdout::WritePrompt();
Value stored to 'bOk' is never read
1421 }
1422
1423 return MIstatus::success;
1424}
1425
1426//++
1427//------------------------------------------------------------------------------------
1428// Details: Asynchronous event handler for LLDB Process stop reason trace.
1429// Type: Method.
1430// Args: None.
1431// Return: MIstatus::success - Functionality succeeded.
1432// MIstatus::failure - Functionality failed.
1433// Throws: None.
1434//--
1435bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopReasonTrace() {
1436 bool bOk = true;
1437 lldb::SBProcess sbProcess =
1438 CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
1439 lldb::SBThread thread = sbProcess.GetSelectedThread();
1440 const MIuint nFrame = thread.GetNumFrames();
1441 if (nFrame == 0) {
1442 // MI print "*stopped,reason=\"trace\",stopped-threads=\"all\""
1443 const CMICmnMIValueConst miValueConst("trace");
1444 const CMICmnMIValueResult miValueResult("reason", miValueConst);
1445 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1446 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult);
1447 const CMICmnMIValueConst miValueConst2("all");
1448 const CMICmnMIValueResult miValueResult2("stopped-threads", miValueConst2);
1449 miOutOfBandRecord.Add(miValueResult2);
1450 bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
1451 bOk = bOk && CMICmnStreamStdout::WritePrompt();
1452 return bOk;
1453 }
1454
1455 CMICmnLLDBDebugSessionInfo &rSessionInfo(
1456 CMICmnLLDBDebugSessionInfo::Instance());
1457
1458 // MI print
1459 // "*stopped,reason=\"end-stepping-range\",frame={addr=\"0x%016" PRIx64
1460 // "\",func=\"%s\",args=[\"%s\"],file=\"%s\",fullname=\"%s\",line=\"%d\"},thread-id=\"%d\",stopped-threads=\"all\""
1461
1462 // Function args
1463 CMICmnMIValueTuple miValueTuple;
1464 if (!rSessionInfo.MIResponseFormFrameInfo(
1465 thread, 0, CMICmnLLDBDebugSessionInfo::eFrameInfoFormat_AllArguments,
1466 miValueTuple))
1467 return MIstatus::failure;
1468
1469 const CMICmnMIValueConst miValueConst("end-stepping-range");
1470 const CMICmnMIValueResult miValueResult("reason", miValueConst);
1471 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1472 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult);
1473 const CMICmnMIValueResult miValueResult2("frame", miValueTuple);
1474 miOutOfBandRecord.Add(miValueResult2);
1475
1476 // Add to MI thread-id=\"%d\",stopped-threads=\"all\"
1477 const CMIUtilString strThreadId(
1478 CMIUtilString::Format("%d", thread.GetIndexID()));
1479 const CMICmnMIValueConst miValueConst8(strThreadId);
1480 const CMICmnMIValueResult miValueResult8("thread-id", miValueConst8);
1481 miOutOfBandRecord.Add(miValueResult8);
1482
1483 const CMICmnMIValueConst miValueConst9("all");
1484 const CMICmnMIValueResult miValueResult9("stopped-threads", miValueConst9);
1485 miOutOfBandRecord.Add(miValueResult9);
1486 bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
1487 bOk = bOk && CMICmnStreamStdout::WritePrompt();
1488
1489 return bOk;
1490}
1491
1492//++
1493//------------------------------------------------------------------------------------
1494// Details: Asynchronous function update selected thread.
1495// Type: Method.
1496// Args: None.
1497// Return: MIstatus::success - Functionality succeeded.
1498// MIstatus::failure - Functionality failed.
1499// Throws: None.
1500//--
1501bool CMICmnLLDBDebuggerHandleEvents::UpdateSelectedThread() {
1502 lldb::SBProcess process = CMICmnLLDBDebugSessionInfo::Instance()
1503 .GetDebugger()
1504 .GetSelectedTarget()
1505 .GetProcess();
1506 if (!process.IsValid())
1507 return MIstatus::success;
1508
1509 lldb::SBThread currentThread = process.GetSelectedThread();
1510 lldb::SBThread thread;
1511 const lldb::StopReason eCurrentThreadStoppedReason =
1512 currentThread.GetStopReason();
1513 if (!currentThread.IsValid() ||
1514 (eCurrentThreadStoppedReason == lldb::eStopReasonInvalid) ||
1515 (eCurrentThreadStoppedReason == lldb::eStopReasonNone)) {
1516 // Prefer a thread that has just completed its plan over another thread as
1517 // current thread
1518 lldb::SBThread planThread;
1519 lldb::SBThread otherThread;
1520 const size_t nThread = process.GetNumThreads();
1521 for (MIuint i = 0; i < nThread; i++) {
1522 // GetThreadAtIndex() uses a base 0 index
1523 // GetThreadByIndexID() uses a base 1 index
1524 thread = process.GetThreadAtIndex(i);
1525 const lldb::StopReason eThreadStopReason = thread.GetStopReason();
1526 switch (eThreadStopReason) {
1527 case lldb::eStopReasonTrace:
1528 case lldb::eStopReasonBreakpoint:
1529 case lldb::eStopReasonWatchpoint:
1530 case lldb::eStopReasonSignal:
1531 case lldb::eStopReasonException:
1532 if (!otherThread.IsValid())
1533 otherThread = thread;
1534 break;
1535 case lldb::eStopReasonPlanComplete:
1536 if (!planThread.IsValid())
1537 planThread = thread;
1538 break;
1539 case lldb::eStopReasonInvalid:
1540 case lldb::eStopReasonNone:
1541 default:
1542 break;
1543 }
1544 }
1545 if (planThread.IsValid())
1546 process.SetSelectedThread(planThread);
1547 else if (otherThread.IsValid())
1548 process.SetSelectedThread(otherThread);
1549 else {
1550 if (currentThread.IsValid())
1551 thread = currentThread;
1552 else
1553 thread = process.GetThreadAtIndex(0);
1554
1555 if (thread.IsValid())
1556 process.SetSelectedThread(thread);
1557 }
1558 } // if( !currentThread.IsValid() || (eCurrentThreadStoppedReason ==
1559 // lldb::eStopReasonInvalid) || (eCurrentThreadStoppedReason ==
1560 // lldb::eStopReasonNone) )
1561
1562 return MIstatus::success;
1563}
1564
1565//++
1566//------------------------------------------------------------------------------------
1567// Details: Print to stdout "*running,thread-id=\"all\"", "(gdb)".
1568// Type: Method.
1569// Args: None.
1570// Return: MIstatus::success - Functionality succeeded.
1571// MIstatus::failure - Functionality failed.
1572// Throws: None.
1573//--
1574bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStateRunning() {
1575 CMICmnMIValueConst miValueConst("all");
1576 CMICmnMIValueResult miValueResult("thread-id", miValueConst);
1577 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1578 CMICmnMIOutOfBandRecord::eOutOfBand_Running, miValueResult);
1579 bool bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
1580 bOk = bOk && CMICmnStreamStdout::WritePrompt();
1581
1582 return bOk;
1583}
1584
1585//++
1586//------------------------------------------------------------------------------------
1587// Details: Print to stdout "=thread-exited,id=\"%ld\",group-id=\"i1\"",
1588// "=thread-group-exited,id=\"i1\",exit-code=\"0\""),
1589// "*stopped,reason=\"exited-normally\"",
1590// "(gdb)"
1591// Type: Method.
1592// Args: None.
1593// Return: MIstatus::success - Functionality succeeded.
1594// MIstatus::failure - Functionality failed.
1595// Throws: None.
1596//--
1597bool CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStateExited() {
1598 const CMIUtilString strId(CMIUtilString::Format("%ld", 1));
1599 CMICmnMIValueConst miValueConst(strId);
1600 CMICmnMIValueResult miValueResult("id", miValueConst);
1601 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1602 CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited, miValueResult);
1603 CMICmnMIValueConst miValueConst2("i1");
1604 CMICmnMIValueResult miValueResult2("group-id", miValueConst2);
1605 miOutOfBandRecord.Add(miValueResult2);
1606 bool bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
1607 if (bOk) {
1608 CMICmnMIValueConst miValueConst3("i1");
1609 CMICmnMIValueResult miValueResult3("id", miValueConst3);
1610 CMICmnMIOutOfBandRecord miOutOfBandRecord2(
1611 CMICmnMIOutOfBandRecord::eOutOfBand_ThreadGroupExited, miValueResult3);
1612 CMICmnMIValueConst miValueConst2("0");
1613 CMICmnMIValueResult miValueResult2("exit-code", miValueConst2);
1614 miOutOfBandRecord2.Add(miValueResult2);
1615 bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord2);
1616 }
1617 if (bOk) {
1618 CMICmnMIValueConst miValueConst4("exited-normally");
1619 CMICmnMIValueResult miValueResult4("reason", miValueConst4);
1620 CMICmnMIOutOfBandRecord miOutOfBandRecord3(
1621 CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult4);
1622 bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord3);
1623 }
1624 bOk = bOk && CMICmnStreamStdout::WritePrompt();
1625
1626 return bOk;
1627}
1628
1629//++
1630//------------------------------------------------------------------------------------
1631// Details: Drain all stdout so we don't see any output come after we print our
1632// prompts.
1633// The process has stuff waiting for stdout; get it and write it out to
1634// the
1635// appropriate place.
1636// Type: Method.
1637// Args: None.
1638// Return: MIstatus::success - Functionality succeeded.
1639// MIstatus::failure - Functionality failed.
1640// Throws: None.
1641//--
1642bool CMICmnLLDBDebuggerHandleEvents::GetProcessStdout() {
1643 CMIUtilString text;
1644 std::unique_ptr<char[]> apStdoutBuffer(new char[1024]);
1645 lldb::SBProcess process = CMICmnLLDBDebugSessionInfo::Instance()
1646 .GetDebugger()
1647 .GetSelectedTarget()
1648 .GetProcess();
1649 while (1) {
1650 const size_t nBytes = process.GetSTDOUT(apStdoutBuffer.get(), 1024);
1651 text.append(apStdoutBuffer.get(), nBytes);
1652
1653 while (1) {
1654 const size_t nNewLine = text.find('\n');
1655 if (nNewLine == std::string::npos)
1656 break;
1657
1658 const CMIUtilString line(text.substr(0, nNewLine + 1));
1659 text.erase(0, nNewLine + 1);
1660 const bool bEscapeQuotes(true);
1661 CMICmnMIValueConst miValueConst(line.Escape(bEscapeQuotes));
1662 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1663 CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);
1664 const bool bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
1665 if (!bOk)
1666 return MIstatus::failure;
1667 }
1668
1669 if (nBytes == 0) {
1670 if (!text.empty()) {
1671 const bool bEscapeQuotes(true);
1672 CMICmnMIValueConst miValueConst(text.Escape(bEscapeQuotes));
1673 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1674 CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput,
1675 miValueConst);
1676 return MiOutOfBandRecordToStdout(miOutOfBandRecord);
1677 }
1678 break;
1679 }
1680 }
1681
1682 return MIstatus::success;
1683}
1684
1685//++
1686//------------------------------------------------------------------------------------
1687// Details: Drain all stderr so we don't see any output come after we print our
1688// prompts.
1689// The process has stuff waiting for stderr; get it and write it out to
1690// the
1691// appropriate place.
1692// Type: Method.
1693// Args: None.
1694// Return: MIstatus::success - Functionality succeeded.
1695// MIstatus::failure - Functionality failed.
1696// Throws: None.
1697//--
1698bool CMICmnLLDBDebuggerHandleEvents::GetProcessStderr() {
1699 CMIUtilString text;
1700 std::unique_ptr<char[]> apStderrBuffer(new char[1024]);
1701 lldb::SBProcess process = CMICmnLLDBDebugSessionInfo::Instance()
1702 .GetDebugger()
1703 .GetSelectedTarget()
1704 .GetProcess();
1705 while (1) {
1706 const size_t nBytes = process.GetSTDERR(apStderrBuffer.get(), 1024);
1707 text.append(apStderrBuffer.get(), nBytes);
1708
1709 while (1) {
1710 const size_t nNewLine = text.find('\n');
1711 if (nNewLine == std::string::npos)
1712 break;
1713
1714 const CMIUtilString line(text.substr(0, nNewLine + 1));
1715 const bool bEscapeQuotes(true);
1716 CMICmnMIValueConst miValueConst(line.Escape(bEscapeQuotes));
1717 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1718 CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);
1719 const bool bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
1720 if (!bOk)
1721 return MIstatus::failure;
1722 }
1723
1724 if (nBytes == 0) {
1725 if (!text.empty()) {
1726 const bool bEscapeQuotes(true);
1727 CMICmnMIValueConst miValueConst(text.Escape(bEscapeQuotes));
1728 CMICmnMIOutOfBandRecord miOutOfBandRecord(
1729 CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput,
1730 miValueConst);
1731 return MiOutOfBandRecordToStdout(miOutOfBandRecord);
1732 }
1733 break;
1734 }
1735 }
1736
1737 return MIstatus::success;
1738}
1739
1740//++
1741//------------------------------------------------------------------------------------
1742// Details: Asynchronous event function check for state changes.
1743// Type: Method.
1744// Args: None.
1745// Return: MIstatus::success - Functionality succeeded.
1746// MIstatus::failure - Functionality failed.
1747// Throws: None.
1748//--
1749bool CMICmnLLDBDebuggerHandleEvents::ChkForStateChanges() {
1750 CMICmnLLDBDebugSessionInfo &rSessionInfo(
1751 CMICmnLLDBDebugSessionInfo::Instance());
1752 lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
1753 if (!sbProcess.IsValid())
1754 return MIstatus::success;
1755
1756 // Check for created threads
1757 const MIuint nThread = sbProcess.GetNumThreads();
1758 for (MIuint i = 0; i < nThread; i++) {
1759 // GetThreadAtIndex() uses a base 0 index
1760 // GetThreadByIndexID() uses a base 1 index
1761 lldb::SBThread thread = sbProcess.GetThreadAtIndex(i);
1762 if (!thread.IsValid())
1763 continue;
1764
1765 const MIuint threadIndexID = thread.GetIndexID();
1766 const bool bFound =
1767 std::find(rSessionInfo.m_vecActiveThreadId.cbegin(),
1768 rSessionInfo.m_vecActiveThreadId.cend(),
1769 threadIndexID) != rSessionInfo.m_vecActiveThreadId.end();
1770 if (!bFound) {
1771 rSessionInfo.m_vecActiveThreadId.push_back(threadIndexID);
1772
1773 // Form MI "=thread-created,id=\"%d\",group-id=\"i1\""
1774 const CMIUtilString strValue(CMIUtilString::Format("%d", threadIndexID));
1775 const CMICmnMIValueConst miValueConst(strValue);
1776 const CMICmnMIValueResult miValueResult("id", miValueConst);
1777 CMICmnMIOutOfBandRecord miOutOfBand(
1778 CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated, miValueResult);
1779 const CMICmnMIValueConst miValueConst2("i1");
1780 const CMICmnMIValueResult miValueResult2("group-id", miValueConst2);
1781 miOutOfBand.Add(miValueResult2);
1782 bool bOk = MiOutOfBandRecordToStdout(miOutOfBand);
1783 if (!bOk)
1784 return MIstatus::failure;
1785 }
1786 }
1787
1788 lldb::SBThread currentThread = sbProcess.GetSelectedThread();
1789 if (currentThread.IsValid()) {
1790 const MIuint currentThreadIndexID = currentThread.GetIndexID();
1791 if (rSessionInfo.m_currentSelectedThread != currentThreadIndexID) {
1792 rSessionInfo.m_currentSelectedThread = currentThreadIndexID;
1793
1794 // Form MI "=thread-selected,id=\"%d\""
1795 const CMIUtilString strValue(
1796 CMIUtilString::Format("%d", currentThreadIndexID));
1797 const CMICmnMIValueConst miValueConst(strValue);
1798 const CMICmnMIValueResult miValueResult("id", miValueConst);
1799 CMICmnMIOutOfBandRecord miOutOfBand(
1800 CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected, miValueResult);
1801 if (!MiOutOfBandRecordToStdout(miOutOfBand))
1802 return MIstatus::failure;
1803 }
1804 }
1805
1806 // Check for invalid (removed) threads
1807 CMICmnLLDBDebugSessionInfo::VecActiveThreadId_t::iterator it =
1808 rSessionInfo.m_vecActiveThreadId.begin();
1809 while (it != rSessionInfo.m_vecActiveThreadId.end()) {
1810 const MIuint threadIndexID = *it;
1811 lldb::SBThread thread = sbProcess.GetThreadByIndexID(threadIndexID);
1812 if (!thread.IsValid()) {
1813 // Form MI "=thread-exited,id=\"%ld\",group-id=\"i1\""
1814 const CMIUtilString strValue(CMIUtilString::Format("%ld", threadIndexID));
1815 const CMICmnMIValueConst miValueConst(strValue);
1816 const CMICmnMIValueResult miValueResult("id", miValueConst);
1817 CMICmnMIOutOfBandRecord miOutOfBand(
1818 CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited, miValueResult);
1819 const CMICmnMIValueConst miValueConst2("i1");
1820 const CMICmnMIValueResult miValueResult2("group-id", miValueConst2);
1821 miOutOfBand.Add(miValueResult2);
1822 bool bOk = MiOutOfBandRecordToStdout(miOutOfBand);
1823 if (!bOk)
1824 return MIstatus::failure;
1825
1826 // Remove current thread from cache and get next
1827 it = rSessionInfo.m_vecActiveThreadId.erase(it);
1828 } else
1829 // Next
1830 ++it;
1831 }
1832
1833 return CMICmnStreamStdout::WritePrompt();
1834}
1835
1836//++
1837//------------------------------------------------------------------------------------
1838// Details: Take a fully formed MI result record and send to the stdout stream.
1839// Also output to the MI Log file.
1840// Type: Method.
1841// Args: vrMiResultRecord - (R) MI result record object.
1842// Return: MIstatus::success - Functionality succeeded.
1843// MIstatus::failure - Functionality failed.
1844// Throws: None.
1845//--
1846bool CMICmnLLDBDebuggerHandleEvents::MiResultRecordToStdout(
1847 const CMICmnMIResultRecord &vrMiResultRecord) {
1848 return TextToStdout(vrMiResultRecord.GetString());
1849}
1850
1851//++
1852//------------------------------------------------------------------------------------
1853// Details: Take a fully formed MI Out-of-band record and send to the stdout
1854// stream.
1855// Also output to the MI Log file.
1856// Type: Method.
1857// Args: vrMiOutOfBandRecord - (R) MI Out-of-band record object.
1858// Return: MIstatus::success - Functionality succeeded.
1859// MIstatus::failure - Functionality failed.
1860// Throws: None.
1861//--
1862bool CMICmnLLDBDebuggerHandleEvents::MiOutOfBandRecordToStdout(
1863 const CMICmnMIOutOfBandRecord &vrMiOutOfBandRecord) {
1864 return TextToStdout(vrMiOutOfBandRecord.GetString());
1865}
1866
1867//++
1868//------------------------------------------------------------------------------------
1869// Details: Take a text data and send to the stdout stream. Also output to the
1870// MI Log
1871// file.
1872// Type: Method.
1873// Args: vrTxt - (R) Text.
1874// Return: MIstatus::success - Functionality succeeded.
1875// MIstatus::failure - Functionality failed.
1876// Throws: None.
1877//--
1878bool CMICmnLLDBDebuggerHandleEvents::TextToStdout(const CMIUtilString &vrTxt) {
1879 return CMICmnStreamStdout::TextToStdout(vrTxt);
1880}
1881
1882//++
1883//------------------------------------------------------------------------------------
1884// Details: Take a text data and send to the stderr stream. Also output to the
1885// MI Log
1886// file.
1887// Type: Method.
1888// Args: vrTxt - (R) Text.
1889// Return: MIstatus::success - Functionality succeeded.
1890// MIstatus::failure - Functionality failed.
1891// Throws: None.
1892//--
1893bool CMICmnLLDBDebuggerHandleEvents::TextToStderr(const CMIUtilString &vrTxt) {
1894 return CMICmnStreamStderr::TextToStderr(vrTxt);
1895}
1896
1897//++
1898//------------------------------------------------------------------------------------
1899// Details: Initialize the member variables with the signal values in this
1900// process
1901// file.
1902// Type: Method.
1903// Args: None
1904// Return: Noen
1905// Throws: None.
1906//--
1907void CMICmnLLDBDebuggerHandleEvents::InitializeSignals() {
1908 if (!m_bSignalsInitialized) {
1909 lldb::SBProcess sbProcess =
1910 CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
1911 if (sbProcess.IsValid()) {
1912 lldb::SBUnixSignals unix_signals = sbProcess.GetUnixSignals();
1913 m_SIGINT = unix_signals.GetSignalNumberFromName("SIGINT");
1914 m_SIGSTOP = unix_signals.GetSignalNumberFromName("SIGSTOP");
1915 m_SIGSEGV = unix_signals.GetSignalNumberFromName("SIGSEGV");
1916 m_SIGTRAP = unix_signals.GetSignalNumberFromName("SIGTRAP");
1917 m_bSignalsInitialized = true;
1918 }
1919 }
1920}