LLDB mainline
StopInfo.cpp
Go to the documentation of this file.
1//===-- StopInfo.cpp ------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <string>
10
15#include "lldb/Core/Debugger.h"
18#include "lldb/Target/Process.h"
20#include "lldb/Target/Target.h"
21#include "lldb/Target/Thread.h"
26#include "lldb/Utility/Log.h"
28
29using namespace lldb;
30using namespace lldb_private;
31
32StopInfo::StopInfo(Thread &thread, uint64_t value)
33 : m_thread_wp(thread.shared_from_this()),
34 m_stop_id(thread.GetProcess()->GetStopID()),
35 m_resume_id(thread.GetProcess()->GetResumeID()), m_value(value),
36 m_description(), m_override_should_notify(eLazyBoolCalculate),
37 m_override_should_stop(eLazyBoolCalculate), m_extended_info() {}
38
39bool StopInfo::IsValid() const {
40 ThreadSP thread_sp(m_thread_wp.lock());
41 if (thread_sp)
42 return thread_sp->GetProcess()->GetStopID() == m_stop_id;
43 return false;
44}
45
47 ThreadSP thread_sp(m_thread_wp.lock());
48 if (thread_sp) {
49 m_stop_id = thread_sp->GetProcess()->GetStopID();
50 m_resume_id = thread_sp->GetProcess()->GetResumeID();
51 }
52}
53
55 ThreadSP thread_sp(m_thread_wp.lock());
56
57 if (thread_sp) {
58 lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState();
59 if (ret_type == eStateRunning) {
60 return true;
61 } else if (ret_type == eStateStopped) {
62 // This is a little tricky. We want to count "run and stopped again
63 // before you could ask this question as a "TRUE" answer to
64 // HasTargetRunSinceMe. But we don't want to include any running of the
65 // target done for expressions. So we track both resumes, and resumes
66 // caused by expressions, and check if there are any resumes
67 // NOT caused
68 // by expressions.
69
70 uint32_t curr_resume_id = thread_sp->GetProcess()->GetResumeID();
71 uint32_t last_user_expression_id =
72 thread_sp->GetProcess()->GetLastUserExpressionResumeID();
73 if (curr_resume_id == m_resume_id) {
74 return false;
75 } else if (curr_resume_id > last_user_expression_id) {
76 return true;
77 }
78 }
79 }
80 return false;
81}
82
83// StopInfoBreakpoint
84
85namespace lldb_private {
87public:
89 : StopInfo(thread, break_id), m_should_stop(false),
92 m_was_all_internal(false), m_was_one_shot(false) {
94 }
95
96 StopInfoBreakpoint(Thread &thread, break_id_t break_id, bool should_stop)
97 : StopInfo(thread, break_id), m_should_stop(should_stop),
100 m_was_all_internal(false), m_was_one_shot(false) {
101 StoreBPInfo();
102 }
103
104 ~StopInfoBreakpoint() override = default;
105
106 void StoreBPInfo() {
107 ThreadSP thread_sp(m_thread_wp.lock());
108 if (thread_sp) {
109 BreakpointSiteSP bp_site_sp(
110 thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value));
111 if (bp_site_sp) {
112 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
113 if (num_owners == 1) {
114 BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0);
115 if (bp_loc_sp) {
116 Breakpoint & bkpt = bp_loc_sp->GetBreakpoint();
117 m_break_id = bkpt.GetID();
118 m_was_one_shot = bkpt.IsOneShot();
120 }
121 } else {
122 m_was_all_internal = true;
123 for (uint32_t i = 0; i < num_owners; i++) {
124 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal()) {
125 m_was_all_internal = false;
126 break;
127 }
128 }
129 }
130 m_address = bp_site_sp->GetLoadAddress();
131 }
132 }
133 }
134
136 ProcessSP process_sp(thread.GetProcess());
137 if (process_sp) {
138 BreakpointSiteSP bp_site_sp(
139 process_sp->GetBreakpointSiteList().FindByID(m_value));
140 if (bp_site_sp)
141 return bp_site_sp->ValidForThisThread(thread);
142 }
143 return false;
144 }
145
146 StopReason GetStopReason() const override { return eStopReasonBreakpoint; }
147
148 bool ShouldStopSynchronous(Event *event_ptr) override {
149 ThreadSP thread_sp(m_thread_wp.lock());
150 if (thread_sp) {
152 // Only check once if we should stop at a breakpoint
153 BreakpointSiteSP bp_site_sp(
154 thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value));
155 if (bp_site_sp) {
156 ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
157 StoppointCallbackContext context(event_ptr, exe_ctx, true);
158 bp_site_sp->BumpHitCounts();
159 m_should_stop = bp_site_sp->ShouldStop(&context);
160 } else {
162
163 LLDB_LOGF(log,
164 "Process::%s could not find breakpoint site id: %" PRId64
165 "...",
166 __FUNCTION__, m_value);
167
168 m_should_stop = true;
169 }
171 }
172 return m_should_stop;
173 }
174 return false;
175 }
176
177 bool DoShouldNotify(Event *event_ptr) override {
178 return !m_was_all_internal;
179 }
180
181 const char *GetDescription() override {
182 if (m_description.empty()) {
183 ThreadSP thread_sp(m_thread_wp.lock());
184 if (thread_sp) {
185 BreakpointSiteSP bp_site_sp(
186 thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value));
187 if (bp_site_sp) {
188 StreamString strm;
189 // If we have just hit an internal breakpoint, and it has a kind
190 // description, print that instead of the full breakpoint printing:
191 if (bp_site_sp->IsInternal()) {
192 size_t num_owners = bp_site_sp->GetNumberOfOwners();
193 for (size_t idx = 0; idx < num_owners; idx++) {
194 const char *kind = bp_site_sp->GetOwnerAtIndex(idx)
195 ->GetBreakpoint()
196 .GetBreakpointKind();
197 if (kind != nullptr) {
198 m_description.assign(kind);
199 return kind;
200 }
201 }
202 }
203
204 strm.Printf("breakpoint ");
205 bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief);
206 m_description = std::string(strm.GetString());
207 } else {
208 StreamString strm;
210 BreakpointSP break_sp =
211 thread_sp->GetProcess()->GetTarget().GetBreakpointByID(
212 m_break_id);
213 if (break_sp) {
214 if (break_sp->IsInternal()) {
215 const char *kind = break_sp->GetBreakpointKind();
216 if (kind)
217 strm.Printf("internal %s breakpoint(%d).", kind, m_break_id);
218 else
219 strm.Printf("internal breakpoint(%d).", m_break_id);
220 } else {
221 strm.Printf("breakpoint %d.", m_break_id);
222 }
223 } else {
224 if (m_was_one_shot)
225 strm.Printf("one-shot breakpoint %d", m_break_id);
226 else
227 strm.Printf("breakpoint %d which has been deleted.",
228 m_break_id);
229 }
230 } else if (m_address == LLDB_INVALID_ADDRESS)
231 strm.Printf("breakpoint site %" PRIi64
232 " which has been deleted - unknown address",
233 m_value);
234 else
235 strm.Printf("breakpoint site %" PRIi64
236 " which has been deleted - was at 0x%" PRIx64,
238
239 m_description = std::string(strm.GetString());
240 }
241 }
242 }
243 return m_description.c_str();
244 }
245
246protected:
247 bool ShouldStop(Event *event_ptr) override {
248 // This just reports the work done by PerformAction or the synchronous
249 // stop. It should only ever get called after they have had a chance to
250 // run.
252 return m_should_stop;
253 }
254
255 void PerformAction(Event *event_ptr) override {
257 return;
259 bool all_stopping_locs_internal = true;
260
261 ThreadSP thread_sp(m_thread_wp.lock());
262
263 if (thread_sp) {
265
266 if (!thread_sp->IsValid()) {
267 // This shouldn't ever happen, but just in case, don't do more harm.
268 if (log) {
269 LLDB_LOGF(log, "PerformAction got called with an invalid thread.");
270 }
271 m_should_stop = true;
273 return;
274 }
275
276 BreakpointSiteSP bp_site_sp(
277 thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value));
278 std::unordered_set<break_id_t> precondition_breakpoints;
279 // Breakpoints that fail their condition check are not considered to
280 // have been hit. If the only locations at this site have failed their
281 // conditions, we should change the stop-info to none. Otherwise, if we
282 // hit another breakpoint on a different thread which does stop, users
283 // will see a breakpont hit with a failed condition, which is wrong.
284 // Use this variable to tell us if that is true.
285 bool actually_hit_any_locations = false;
286 if (bp_site_sp) {
287 // Let's copy the owners list out of the site and store them in a local
288 // list. That way if one of the breakpoint actions changes the site,
289 // then we won't be operating on a bad list.
290 BreakpointLocationCollection site_locations;
291 size_t num_owners = bp_site_sp->CopyOwnersList(site_locations);
292
293 if (num_owners == 0) {
294 m_should_stop = true;
295 actually_hit_any_locations = true; // We're going to stop, don't
296 // change the stop info.
297 } else {
298 // We go through each location, and test first its precondition -
299 // this overrides everything. Note, we only do this once per
300 // breakpoint - not once per location... Then check the condition.
301 // If the condition says to stop, then we run the callback for that
302 // location. If that callback says to stop as well, then we set
303 // m_should_stop to true; we are going to stop. But we still want to
304 // give all the breakpoints whose conditions say we are going to stop
305 // a chance to run their callbacks. Of course if any callback
306 // restarts the target by putting "continue" in the callback, then
307 // we're going to restart, without running the rest of the callbacks.
308 // And in this case we will end up not stopping even if another
309 // location said we should stop. But that's better than not running
310 // all the callbacks.
311
312 // There's one other complication here. We may have run an async
313 // breakpoint callback that said we should stop. We only want to
314 // override that if another breakpoint action says we shouldn't
315 // stop. If nobody else has an opinion, then we should stop if the
316 // async callback says we should. An example of this is the async
317 // shared library load notification breakpoint and the setting
318 // stop-on-sharedlibrary-events.
319 // We'll keep the async value in async_should_stop, and track whether
320 // anyone said we should NOT stop in actually_said_continue.
321 bool async_should_stop = false;
323 async_should_stop = m_should_stop;
324 bool actually_said_continue = false;
325
326 m_should_stop = false;
327
328 // We don't select threads as we go through them testing breakpoint
329 // conditions and running commands. So we need to set the thread for
330 // expression evaluation here:
331 ThreadList::ExpressionExecutionThreadPusher thread_pusher(thread_sp);
332
333 ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
334 Process *process = exe_ctx.GetProcessPtr();
336 // If we are in the middle of evaluating an expression, don't run
337 // asynchronous breakpoint commands or expressions. That could
338 // lead to infinite recursion if the command or condition re-calls
339 // the function with this breakpoint.
340 // TODO: We can keep a list of the breakpoints we've seen while
341 // running expressions in the nested
342 // PerformAction calls that can arise when the action runs a
343 // function that hits another breakpoint, and only stop running
344 // commands when we see the same breakpoint hit a second time.
345
347
348 // It is possible that the user has a breakpoint at the same site
349 // as the completed plan had (e.g. user has a breakpoint
350 // on a module entry point, and `ThreadPlanCallFunction` ends
351 // also there). We can't find an internal breakpoint in the loop
352 // later because it was already removed on the plan completion.
353 // So check if the plan was completed, and stop if so.
354 if (thread_sp->CompletedPlanOverridesBreakpoint()) {
355 m_should_stop = true;
356 thread_sp->ResetStopInfo();
357 return;
358 }
359
360 LLDB_LOGF(log, "StopInfoBreakpoint::PerformAction - Hit a "
361 "breakpoint while running an expression,"
362 " not running commands to avoid recursion.");
363 bool ignoring_breakpoints =
365 // Internal breakpoints should be allowed to do their job, we
366 // can make sure they don't do anything that would cause recursive
367 // command execution:
368 if (!m_was_all_internal) {
369 m_should_stop = !ignoring_breakpoints;
370 LLDB_LOGF(log,
371 "StopInfoBreakpoint::PerformAction - in expression, "
372 "continuing: %s.",
373 m_should_stop ? "true" : "false");
375 "hit breakpoint while running function, skipping commands "
376 "and conditions to prevent recursion",
377 process->GetTarget().GetDebugger().GetID());
378 return;
379 }
380 }
381
382 StoppointCallbackContext context(event_ptr, exe_ctx, false);
383
384 // For safety's sake let's also grab an extra reference to the
385 // breakpoint owners of the locations we're going to examine, since
386 // the locations are going to have to get back to their breakpoints,
387 // and the locations don't keep their owners alive. I'm just
388 // sticking the BreakpointSP's in a vector since I'm only using it to
389 // locally increment their retain counts.
390
391 std::vector<lldb::BreakpointSP> location_owners;
392
393 for (size_t j = 0; j < num_owners; j++) {
394 BreakpointLocationSP loc(site_locations.GetByIndex(j));
395 location_owners.push_back(loc->GetBreakpoint().shared_from_this());
396 }
397
398 for (size_t j = 0; j < num_owners; j++) {
399 lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j);
400 StreamString loc_desc;
401 if (log) {
402 bp_loc_sp->GetDescription(&loc_desc, eDescriptionLevelBrief);
403 }
404 // If another action disabled this breakpoint or its location, then
405 // don't run the actions.
406 if (!bp_loc_sp->IsEnabled() ||
407 !bp_loc_sp->GetBreakpoint().IsEnabled())
408 continue;
409
410 // The breakpoint site may have many locations associated with it,
411 // not all of them valid for this thread. Skip the ones that
412 // aren't:
413 if (!bp_loc_sp->ValidForThisThread(*thread_sp)) {
414 if (log) {
415 LLDB_LOGF(log,
416 "Breakpoint %s hit on thread 0x%llx but it was not "
417 "for this thread, continuing.",
418 loc_desc.GetData(),
419 static_cast<unsigned long long>(thread_sp->GetID()));
420 }
421 continue;
422 }
423
424 // First run the precondition, but since the precondition is per
425 // breakpoint, only run it once per breakpoint.
426 std::pair<std::unordered_set<break_id_t>::iterator, bool> result =
427 precondition_breakpoints.insert(
428 bp_loc_sp->GetBreakpoint().GetID());
429 if (!result.second)
430 continue;
431
432 bool precondition_result =
433 bp_loc_sp->GetBreakpoint().EvaluatePrecondition(context);
434 if (!precondition_result) {
435 actually_said_continue = true;
436 continue;
437 }
438 // Next run the condition for the breakpoint. If that says we
439 // should stop, then we'll run the callback for the breakpoint. If
440 // the callback says we shouldn't stop that will win.
441
442 if (bp_loc_sp->GetConditionText() == nullptr)
443 actually_hit_any_locations = true;
444 else {
445 Status condition_error;
446 bool condition_says_stop =
447 bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error);
448
449 if (!condition_error.Success()) {
450 // If the condition fails to evaluate, we are going to stop
451 // at it, so the location was hit.
452 actually_hit_any_locations = true;
453 const char *err_str =
454 condition_error.AsCString("<unknown error>");
455 LLDB_LOGF(log, "Error evaluating condition: \"%s\"\n", err_str);
456
457 StreamString strm;
458 strm << "stopped due to an error evaluating condition of "
459 "breakpoint ";
460 bp_loc_sp->GetDescription(&strm, eDescriptionLevelBrief);
461 strm << ": \"" << bp_loc_sp->GetConditionText() << "\"\n";
462 strm << err_str;
463
465 strm.GetString().str(),
466 exe_ctx.GetTargetRef().GetDebugger().GetID());
467 } else {
468 LLDB_LOGF(log,
469 "Condition evaluated for breakpoint %s on thread "
470 "0x%llx condition_says_stop: %i.",
471 loc_desc.GetData(),
472 static_cast<unsigned long long>(thread_sp->GetID()),
473 condition_says_stop);
474 if (condition_says_stop)
475 actually_hit_any_locations = true;
476 else {
477 // We don't want to increment the hit count of breakpoints if
478 // the condition fails. We've already bumped it by the time
479 // we get here, so undo the bump:
480 bp_loc_sp->UndoBumpHitCount();
481 actually_said_continue = true;
482 continue;
483 }
484 }
485 }
486
487 // We've done all the checks whose failure means "we consider lldb
488 // not to have hit the breakpoint". Now we're going to check for
489 // conditions that might continue after hitting. Start with the
490 // ignore count:
491 if (!bp_loc_sp->IgnoreCountShouldStop()) {
492 actually_said_continue = true;
493 continue;
494 }
495
496 // Check the auto-continue bit on the location, do this before the
497 // callback since it may change this, but that would be for the
498 // NEXT hit. Note, you might think you could check auto-continue
499 // before the condition, and not evaluate the condition if it says
500 // to continue. But failing the condition means the breakpoint was
501 // effectively NOT HIT. So these two states are different.
502 bool auto_continue_says_stop = true;
503 if (bp_loc_sp->IsAutoContinue())
504 {
505 LLDB_LOGF(log,
506 "Continuing breakpoint %s as AutoContinue was set.",
507 loc_desc.GetData());
508 // We want this stop reported, so you will know we auto-continued
509 // but only for external breakpoints:
510 if (!bp_loc_sp->GetBreakpoint().IsInternal())
511 thread_sp->SetShouldReportStop(eVoteYes);
512 auto_continue_says_stop = false;
513 }
514
515 bool callback_says_stop = true;
516
517 // FIXME: For now the callbacks have to run in async mode - the
518 // first time we restart we need
519 // to get out of there. So set it here.
520 // When we figure out how to nest breakpoint hits then this will
521 // change.
522
523 // Don't run async callbacks in PerformAction. They have already
524 // been taken into account with async_should_stop.
525 if (!bp_loc_sp->IsCallbackSynchronous()) {
526 Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger();
527 bool old_async = debugger.GetAsyncExecution();
528 debugger.SetAsyncExecution(true);
529
530 callback_says_stop = bp_loc_sp->InvokeCallback(&context);
531
532 debugger.SetAsyncExecution(old_async);
533
534 if (callback_says_stop && auto_continue_says_stop)
535 m_should_stop = true;
536 else
537 actually_said_continue = true;
538 }
539
540 if (m_should_stop && !bp_loc_sp->GetBreakpoint().IsInternal())
541 all_stopping_locs_internal = false;
542
543 // If we are going to stop for this breakpoint, then remove the
544 // breakpoint.
545 if (callback_says_stop && bp_loc_sp &&
546 bp_loc_sp->GetBreakpoint().IsOneShot()) {
547 thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID(
548 bp_loc_sp->GetBreakpoint().GetID());
549 }
550 // Also make sure that the callback hasn't continued the target. If
551 // it did, when we'll set m_should_start to false and get out of
552 // here.
553 if (HasTargetRunSinceMe()) {
554 m_should_stop = false;
555 actually_said_continue = true;
556 break;
557 }
558 }
559 // At this point if nobody actually told us to continue, we should
560 // give the async breakpoint callback a chance to weigh in:
561 if (!actually_said_continue && !m_should_stop) {
562 m_should_stop = async_should_stop;
563 }
564 }
565 // We've figured out what this stop wants to do, so mark it as valid so
566 // we don't compute it again.
568 } else {
569 m_should_stop = true;
571 actually_hit_any_locations = true;
572 Log *log_process(GetLog(LLDBLog::Process));
573
574 LLDB_LOGF(log_process,
575 "Process::%s could not find breakpoint site id: %" PRId64
576 "...",
577 __FUNCTION__, m_value);
578 }
579
580 if ((!m_should_stop || all_stopping_locs_internal) &&
581 thread_sp->CompletedPlanOverridesBreakpoint()) {
582
583 // Override should_stop decision when we have completed step plan
584 // additionally to the breakpoint
585 m_should_stop = true;
586
587 // We know we're stopping for a completed plan and we don't want to
588 // show the breakpoint stop, so compute the public stop info immediately
589 // here.
590 thread_sp->CalculatePublicStopInfo();
591 } else if (!actually_hit_any_locations) {
592 // In the end, we didn't actually have any locations that passed their
593 // "was I hit" checks. So say we aren't stopped.
594 GetThread()->ResetStopInfo();
595 LLDB_LOGF(log, "Process::%s all locations failed condition checks.",
596 __FUNCTION__);
597 }
598
599 LLDB_LOGF(log,
600 "Process::%s returning from action with m_should_stop: %d.",
601 __FUNCTION__, m_should_stop);
602 }
603 }
604
605private:
608 bool m_should_perform_action; // Since we are trying to preserve the "state"
609 // of the system even if we run functions
610 // etc. behind the users backs, we need to make sure we only REALLY perform
611 // the action once.
612 lldb::addr_t m_address; // We use this to capture the breakpoint site address
613 // when we create the StopInfo,
614 // in case somebody deletes it between the time the StopInfo is made and the
615 // description is asked for.
619};
620
621// StopInfoWatchpoint
622
624public:
625 // Make sure watchpoint is properly disabled and subsequently enabled while
626 // performing watchpoint actions.
628 public:
629 WatchpointSentry(ProcessSP p_sp, WatchpointSP w_sp) : process_sp(p_sp),
630 watchpoint_sp(w_sp) {
631 if (process_sp && watchpoint_sp) {
632 const bool notify = false;
633 watchpoint_sp->TurnOnEphemeralMode();
634 process_sp->DisableWatchpoint(watchpoint_sp.get(), notify);
635 process_sp->AddPreResumeAction(SentryPreResumeAction, this);
636 }
637 }
638
639 void DoReenable() {
640 if (process_sp && watchpoint_sp) {
641 bool was_disabled = watchpoint_sp->IsDisabledDuringEphemeralMode();
642 watchpoint_sp->TurnOffEphemeralMode();
643 const bool notify = false;
644 if (was_disabled) {
645 process_sp->DisableWatchpoint(watchpoint_sp.get(), notify);
646 } else {
647 process_sp->EnableWatchpoint(watchpoint_sp.get(), notify);
648 }
649 }
650 }
651
653 DoReenable();
654 if (process_sp)
655 process_sp->ClearPreResumeAction(SentryPreResumeAction, this);
656 }
657
658 static bool SentryPreResumeAction(void *sentry_void) {
659 WatchpointSentry *sentry = (WatchpointSentry *) sentry_void;
660 sentry->DoReenable();
661 return true;
662 }
663
664 private:
665 ProcessSP process_sp;
666 WatchpointSP watchpoint_sp;
667 };
668
670 lldb::addr_t watch_hit_addr)
671 : StopInfo(thread, watch_id), m_watch_hit_addr(watch_hit_addr) {}
672
673 ~StopInfoWatchpoint() override = default;
674
675 StopReason GetStopReason() const override { return eStopReasonWatchpoint; }
676
677 const char *GetDescription() override {
678 if (m_description.empty()) {
679 StreamString strm;
680 strm.Printf("watchpoint %" PRIi64, m_value);
681 m_description = std::string(strm.GetString());
682 }
683 return m_description.c_str();
684 }
685
686protected:
687 using StopInfoWatchpointSP = std::shared_ptr<StopInfoWatchpoint>;
688 // This plan is used to orchestrate stepping over the watchpoint for
689 // architectures (e.g. ARM) that report the watch before running the watched
690 // access. This is the sort of job you have to defer to the thread plans,
691 // if you try to do it directly in the stop info and there are other threads
692 // that needed to process this stop you will have yanked control away from
693 // them and they won't behave correctly.
695 public:
697 StopInfoWatchpointSP stop_info_sp,
698 WatchpointSP watch_sp)
699 : ThreadPlanStepInstruction(thread, false, true, eVoteNoOpinion,
701 m_stop_info_sp(stop_info_sp), m_watch_sp(watch_sp) {
702 assert(watch_sp);
703 m_watch_index = watch_sp->GetHardwareIndex();
704 }
705
706 bool DoWillResume(lldb::StateType resume_state,
707 bool current_plan) override {
708 if (resume_state == eStateSuspended)
709 return true;
710
711 if (!m_did_disable_wp) {
712 GetThread().GetProcess()->DisableWatchpoint(m_watch_sp.get(), false);
713 m_did_disable_wp = true;
714 }
715 return true;
716 }
717
718 bool DoPlanExplainsStop(Event *event_ptr) override {
720 return true;
721 StopInfoSP stop_info_sp = GetThread().GetPrivateStopInfo();
722 // lldb-server resets the stop info for threads that didn't get to run,
723 // so we might have not gotten to run, but still have a watchpoint stop
724 // reason, in which case this will indeed be for us.
725 if (stop_info_sp
726 && stop_info_sp->GetStopReason() == eStopReasonWatchpoint)
727 return true;
728 return false;
729 }
730
731 void DidPop() override {
732 // Don't artifically keep the watchpoint alive.
733 m_watch_sp.reset();
734 }
735
736 bool ShouldStop(Event *event_ptr) override {
737 bool should_stop = ThreadPlanStepInstruction::ShouldStop(event_ptr);
738 bool plan_done = MischiefManaged();
739 if (plan_done) {
740 m_stop_info_sp->SetStepOverPlanComplete();
743 }
744 return should_stop;
745 }
746
748 return true;
749 }
750
751 protected:
753 if (!m_did_disable_wp)
754 return;
755 m_did_disable_wp = true;
756 GetThread().GetProcess()->EnableWatchpoint(m_watch_sp.get(), true);
757 m_watch_sp->SetHardwareIndex(m_watch_index);
758 }
759
760 private:
762 WatchpointSP m_watch_sp;
764 bool m_did_disable_wp = false;
765 };
766
767 bool ShouldStopSynchronous(Event *event_ptr) override {
768 // If we are running our step-over the watchpoint plan, stop if it's done
769 // and continue if it's not:
771 return m_should_stop;
772
773 // If we are running our step over plan, then stop here and let the regular
774 // ShouldStop figure out what we should do: Otherwise, give our plan
775 // more time to get run:
778
780 ThreadSP thread_sp(m_thread_wp.lock());
781 assert(thread_sp);
782
783 if (thread_sp->GetTemporaryResumeState() == eStateSuspended) {
784 // This is the second firing of a watchpoint so don't process it again.
785 LLDB_LOG(log, "We didn't run but stopped with a StopInfoWatchpoint, we "
786 "have already handled this one, don't do it again.");
787 m_should_stop = false;
789 return m_should_stop;
790 }
791
792 WatchpointSP wp_sp(
793 thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
794 // If we can no longer find the watchpoint, we just have to stop:
795 if (!wp_sp) {
796
797 LLDB_LOGF(log,
798 "Process::%s could not find watchpoint location id: %" PRId64
799 "...",
800 __FUNCTION__, GetValue());
801
802 m_should_stop = true;
804 return true;
805 }
806
807 ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
808 StoppointCallbackContext context(event_ptr, exe_ctx, true);
809 m_should_stop = wp_sp->ShouldStop(&context);
810 if (!m_should_stop) {
811 // This won't happen at present because we only allow one watchpoint per
812 // watched range. So we won't stop at a watched address with a disabled
813 // watchpoint. If we start allowing overlapping watchpoints, then we
814 // will have to make watchpoints be real "WatchpointSite" and delegate to
815 // all the watchpoints sharing the site. In that case, the code below
816 // would be the right thing to do.
818 return m_should_stop;
819 }
820 // If this is a system where we need to execute the watchpoint by hand
821 // after the hit, queue a thread plan to do that, and then say not to stop.
822 // Otherwise, let the async action figure out whether the watchpoint should
823 // stop
824
825 ProcessSP process_sp = exe_ctx.GetProcessSP();
826 bool wp_triggers_after = process_sp->GetWatchpointReportedAfter();
827
828 if (!wp_triggers_after) {
829 // We have to step over the watchpoint before we know what to do:
830 StopInfoWatchpointSP me_as_siwp_sp
831 = std::static_pointer_cast<StopInfoWatchpoint>(shared_from_this());
832 ThreadPlanSP step_over_wp_sp(new ThreadPlanStepOverWatchpoint(
833 *(thread_sp.get()), me_as_siwp_sp, wp_sp));
835 error = thread_sp->QueueThreadPlan(step_over_wp_sp, false);
836 // If we couldn't push the thread plan, just stop here:
837 if (!error.Success()) {
838 LLDB_LOGF(log, "Could not push our step over watchpoint plan: %s",
839 error.AsCString());
840
841 m_should_stop = true;
843 return true;
844 } else {
845 // Otherwise, don't set m_should_stop, we don't know that yet. Just
846 // say we should continue, and tell the thread we really should do so:
847 thread_sp->SetShouldRunBeforePublicStop(true);
849 return false;
850 }
851 } else {
852 // We didn't have to do anything special
854 return m_should_stop;
855 }
856
857 return m_should_stop;
858 }
859
860 bool ShouldStop(Event *event_ptr) override {
861 // This just reports the work done by PerformAction or the synchronous
862 // stop. It should only ever get called after they have had a chance to
863 // run.
865 return m_should_stop;
866 }
867
868 void PerformAction(Event *event_ptr) override {
870 // We're going to calculate if we should stop or not in some way during the
871 // course of this code. Also by default we're going to stop, so set that
872 // here.
873 m_should_stop = true;
874
875
876 ThreadSP thread_sp(m_thread_wp.lock());
877 if (thread_sp) {
878
879 WatchpointSP wp_sp(
880 thread_sp->CalculateTarget()->GetWatchpointList().FindByID(
881 GetValue()));
882 if (wp_sp) {
883 // This sentry object makes sure the current watchpoint is disabled
884 // while performing watchpoint actions, and it is then enabled after we
885 // are finished.
886 ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
887 ProcessSP process_sp = exe_ctx.GetProcessSP();
888
889 WatchpointSentry sentry(process_sp, wp_sp);
890
891 /*
892 * MIPS: Last 3bits of the watchpoint address are masked by the kernel.
893 * For example:
894 * 'n' is at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is
895 * set at 'm', then
896 * watch exception is generated even when 'n' is read/written. To handle
897 * this case,
898 * server emulates the instruction at PC and finds the base address of
899 * the load/store
900 * instruction and appends it in the description of the stop-info
901 * packet. If watchpoint
902 * is not set on this address by user then this do not stop.
903 */
905 WatchpointSP wp_hit_sp =
906 thread_sp->CalculateTarget()->GetWatchpointList().FindByAddress(
908 if (!wp_hit_sp) {
909 m_should_stop = false;
910 wp_sp->IncrementFalseAlarmsAndReviseHitCount();
911 }
912 }
913
914 if (wp_sp->GetHitCount() <= wp_sp->GetIgnoreCount()) {
915 m_should_stop = false;
917 }
918
919 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
920
921 if (m_should_stop && wp_sp->GetConditionText() != nullptr) {
922 // We need to make sure the user sees any parse errors in their
923 // condition, so we'll hook the constructor errors up to the
924 // debugger's Async I/O.
925 ExpressionResults result_code;
926 EvaluateExpressionOptions expr_options;
927 expr_options.SetUnwindOnError(true);
928 expr_options.SetIgnoreBreakpoints(true);
929 ValueObjectSP result_value_sp;
931 result_code = UserExpression::Evaluate(
932 exe_ctx, expr_options, wp_sp->GetConditionText(),
933 llvm::StringRef(), result_value_sp, error);
934
935 if (result_code == eExpressionCompleted) {
936 if (result_value_sp) {
937 Scalar scalar_value;
938 if (result_value_sp->ResolveValue(scalar_value)) {
939 if (scalar_value.ULongLong(1) == 0) {
940 // The condition failed, which we consider "not having hit
941 // the watchpoint" so undo the hit count here.
942 wp_sp->UndoHitCount();
943 m_should_stop = false;
944 } else
945 m_should_stop = true;
946 LLDB_LOGF(log,
947 "Condition successfully evaluated, result is %s.\n",
948 m_should_stop ? "true" : "false");
949 } else {
950 m_should_stop = true;
951 LLDB_LOGF(
952 log,
953 "Failed to get an integer result from the expression.");
954 }
955 }
956 } else {
957 const char *err_str = error.AsCString("<unknown error>");
958 LLDB_LOGF(log, "Error evaluating condition: \"%s\"\n", err_str);
959
960 StreamString strm;
961 strm << "stopped due to an error evaluating condition of "
962 "watchpoint ";
963 wp_sp->GetDescription(&strm, eDescriptionLevelBrief);
964 strm << ": \"" << wp_sp->GetConditionText() << "\"\n";
965 strm << err_str;
966
967 Debugger::ReportError(strm.GetString().str(),
968 exe_ctx.GetTargetRef().GetDebugger().GetID());
969 }
970 }
971
972 // If the condition says to stop, we run the callback to further decide
973 // whether to stop.
974 if (m_should_stop) {
975 // FIXME: For now the callbacks have to run in async mode - the
976 // first time we restart we need
977 // to get out of there. So set it here.
978 // When we figure out how to nest watchpoint hits then this will
979 // change.
980
981 bool old_async = debugger.GetAsyncExecution();
982 debugger.SetAsyncExecution(true);
983
984 StoppointCallbackContext context(event_ptr, exe_ctx, false);
985 bool stop_requested = wp_sp->InvokeCallback(&context);
986
987 debugger.SetAsyncExecution(old_async);
988
989 // Also make sure that the callback hasn't continued the target. If
990 // it did, when we'll set m_should_stop to false and get out of here.
992 m_should_stop = false;
993
994 if (m_should_stop && !stop_requested) {
995 // We have been vetoed by the callback mechanism.
996 m_should_stop = false;
997 }
998 }
999 // Finally, if we are going to stop, print out the new & old values:
1000 if (m_should_stop) {
1001 wp_sp->CaptureWatchedValue(exe_ctx);
1002
1003 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
1004 StreamSP output_sp = debugger.GetAsyncOutputStream();
1005 wp_sp->DumpSnapshots(output_sp.get());
1006 output_sp->EOL();
1007 output_sp->Flush();
1008 }
1009
1010 } else {
1011 Log *log_process(GetLog(LLDBLog::Process));
1012
1013 LLDB_LOGF(log_process,
1014 "Process::%s could not find watchpoint id: %" PRId64 "...",
1015 __FUNCTION__, m_value);
1016 }
1017 LLDB_LOGF(log,
1018 "Process::%s returning from action with m_should_stop: %d.",
1019 __FUNCTION__, m_should_stop);
1020
1022 }
1023 }
1024
1025private:
1027 assert(m_using_step_over_plan);
1029 }
1030
1031 bool m_should_stop = false;
1036};
1037
1038// StopInfoUnixSignal
1039
1041public:
1042 StopInfoUnixSignal(Thread &thread, int signo, const char *description)
1043 : StopInfo(thread, signo) {
1044 SetDescription(description);
1045 }
1046
1047 ~StopInfoUnixSignal() override = default;
1048
1049 StopReason GetStopReason() const override { return eStopReasonSignal; }
1050
1051 bool ShouldStopSynchronous(Event *event_ptr) override {
1052 ThreadSP thread_sp(m_thread_wp.lock());
1053 if (thread_sp)
1054 return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
1055 return false;
1056 }
1057
1058 bool ShouldStop(Event *event_ptr) override {
1059 ThreadSP thread_sp(m_thread_wp.lock());
1060 if (thread_sp)
1061 return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
1062 return false;
1063 }
1064
1065 // If should stop returns false, check if we should notify of this event
1066 bool DoShouldNotify(Event *event_ptr) override {
1067 ThreadSP thread_sp(m_thread_wp.lock());
1068 if (thread_sp) {
1069 bool should_notify =
1070 thread_sp->GetProcess()->GetUnixSignals()->GetShouldNotify(m_value);
1071 if (should_notify) {
1072 StreamString strm;
1073 strm.Printf(
1074 "thread %d received signal: %s", thread_sp->GetIndexID(),
1075 thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(
1076 m_value));
1078 strm.GetData());
1079 }
1080 return should_notify;
1081 }
1082 return true;
1083 }
1084
1085 void WillResume(lldb::StateType resume_state) override {
1086 ThreadSP thread_sp(m_thread_wp.lock());
1087 if (thread_sp) {
1088 if (!thread_sp->GetProcess()->GetUnixSignals()->GetShouldSuppress(
1089 m_value))
1090 thread_sp->SetResumeSignal(m_value);
1091 }
1092 }
1093
1094 const char *GetDescription() override {
1095 if (m_description.empty()) {
1096 ThreadSP thread_sp(m_thread_wp.lock());
1097 if (thread_sp) {
1098 StreamString strm;
1099 const char *signal_name =
1100 thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(
1101 m_value);
1102 if (signal_name)
1103 strm.Printf("signal %s", signal_name);
1104 else
1105 strm.Printf("signal %" PRIi64, m_value);
1106 m_description = std::string(strm.GetString());
1107 }
1108 }
1109 return m_description.c_str();
1110 }
1111};
1112
1113// StopInfoTrace
1114
1115class StopInfoTrace : public StopInfo {
1116public:
1118
1119 ~StopInfoTrace() override = default;
1120
1121 StopReason GetStopReason() const override { return eStopReasonTrace; }
1122
1123 const char *GetDescription() override {
1124 if (m_description.empty())
1125 return "trace";
1126 else
1127 return m_description.c_str();
1128 }
1129};
1130
1131// StopInfoException
1132
1134public:
1135 StopInfoException(Thread &thread, const char *description)
1136 : StopInfo(thread, LLDB_INVALID_UID) {
1137 if (description)
1138 SetDescription(description);
1139 }
1140
1141 ~StopInfoException() override = default;
1142
1143 StopReason GetStopReason() const override { return eStopReasonException; }
1144
1145 const char *GetDescription() override {
1146 if (m_description.empty())
1147 return "exception";
1148 else
1149 return m_description.c_str();
1150 }
1151};
1152
1153// StopInfoProcessorTrace
1154
1156public:
1157 StopInfoProcessorTrace(Thread &thread, const char *description)
1158 : StopInfo(thread, LLDB_INVALID_UID) {
1159 if (description)
1160 SetDescription(description);
1161 }
1162
1163 ~StopInfoProcessorTrace() override = default;
1164
1165 StopReason GetStopReason() const override {
1167 }
1168
1169 const char *GetDescription() override {
1170 if (m_description.empty())
1171 return "processor trace event";
1172 else
1173 return m_description.c_str();
1174 }
1175};
1176
1177// StopInfoThreadPlan
1178
1180public:
1181 StopInfoThreadPlan(ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp,
1182 ExpressionVariableSP &expression_variable_sp)
1183 : StopInfo(plan_sp->GetThread(), LLDB_INVALID_UID), m_plan_sp(plan_sp),
1184 m_return_valobj_sp(return_valobj_sp),
1185 m_expression_variable_sp(expression_variable_sp) {}
1186
1187 ~StopInfoThreadPlan() override = default;
1188
1190
1191 const char *GetDescription() override {
1192 if (m_description.empty()) {
1193 StreamString strm;
1194 m_plan_sp->GetDescription(&strm, eDescriptionLevelBrief);
1195 m_description = std::string(strm.GetString());
1196 }
1197 return m_description.c_str();
1198 }
1199
1200 ValueObjectSP GetReturnValueObject() { return m_return_valobj_sp; }
1201
1202 ExpressionVariableSP GetExpressionVariable() {
1204 }
1205
1206protected:
1207 bool ShouldStop(Event *event_ptr) override {
1208 if (m_plan_sp)
1209 return m_plan_sp->ShouldStop(event_ptr);
1210 else
1211 return StopInfo::ShouldStop(event_ptr);
1212 }
1213
1214private:
1215 ThreadPlanSP m_plan_sp;
1216 ValueObjectSP m_return_valobj_sp;
1217 ExpressionVariableSP m_expression_variable_sp;
1218};
1219
1220// StopInfoExec
1221
1222class StopInfoExec : public StopInfo {
1223public:
1225
1226 ~StopInfoExec() override = default;
1227
1228 bool ShouldStop(Event *event_ptr) override {
1229 ThreadSP thread_sp(m_thread_wp.lock());
1230 if (thread_sp)
1231 return thread_sp->GetProcess()->GetStopOnExec();
1232 return false;
1233 }
1234
1235 StopReason GetStopReason() const override { return eStopReasonExec; }
1236
1237 const char *GetDescription() override { return "exec"; }
1238
1239protected:
1240 void PerformAction(Event *event_ptr) override {
1241 // Only perform the action once
1243 return;
1244 m_performed_action = true;
1245 ThreadSP thread_sp(m_thread_wp.lock());
1246 if (thread_sp)
1247 thread_sp->GetProcess()->DidExec();
1248 }
1249
1251};
1252
1253// StopInfoFork
1254
1255class StopInfoFork : public StopInfo {
1256public:
1257 StopInfoFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
1258 : StopInfo(thread, child_pid), m_child_pid(child_pid),
1259 m_child_tid(child_tid) {}
1260
1261 ~StopInfoFork() override = default;
1262
1263 bool ShouldStop(Event *event_ptr) override { return false; }
1264
1265 StopReason GetStopReason() const override { return eStopReasonFork; }
1266
1267 const char *GetDescription() override { return "fork"; }
1268
1269protected:
1270 void PerformAction(Event *event_ptr) override {
1271 // Only perform the action once
1273 return;
1274 m_performed_action = true;
1275 ThreadSP thread_sp(m_thread_wp.lock());
1276 if (thread_sp)
1277 thread_sp->GetProcess()->DidFork(m_child_pid, m_child_tid);
1278 }
1279
1281
1282private:
1285};
1286
1287// StopInfoVFork
1288
1289class StopInfoVFork : public StopInfo {
1290public:
1291 StopInfoVFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
1292 : StopInfo(thread, child_pid), m_child_pid(child_pid),
1293 m_child_tid(child_tid) {}
1294
1295 ~StopInfoVFork() override = default;
1296
1297 bool ShouldStop(Event *event_ptr) override { return false; }
1298
1299 StopReason GetStopReason() const override { return eStopReasonVFork; }
1300
1301 const char *GetDescription() override { return "vfork"; }
1302
1303protected:
1304 void PerformAction(Event *event_ptr) override {
1305 // Only perform the action once
1307 return;
1308 m_performed_action = true;
1309 ThreadSP thread_sp(m_thread_wp.lock());
1310 if (thread_sp)
1311 thread_sp->GetProcess()->DidVFork(m_child_pid, m_child_tid);
1312 }
1313
1315
1316private:
1319};
1320
1321// StopInfoVForkDone
1322
1324public:
1325 StopInfoVForkDone(Thread &thread) : StopInfo(thread, 0) {}
1326
1327 ~StopInfoVForkDone() override = default;
1328
1329 bool ShouldStop(Event *event_ptr) override { return false; }
1330
1331 StopReason GetStopReason() const override { return eStopReasonVForkDone; }
1332
1333 const char *GetDescription() override { return "vforkdone"; }
1334
1335protected:
1336 void PerformAction(Event *event_ptr) override {
1337 // Only perform the action once
1339 return;
1340 m_performed_action = true;
1341 ThreadSP thread_sp(m_thread_wp.lock());
1342 if (thread_sp)
1343 thread_sp->GetProcess()->DidVForkDone();
1344 }
1345
1347};
1348
1349} // namespace lldb_private
1350
1352 break_id_t break_id) {
1353 return StopInfoSP(new StopInfoBreakpoint(thread, break_id));
1354}
1355
1357 break_id_t break_id,
1358 bool should_stop) {
1359 return StopInfoSP(new StopInfoBreakpoint(thread, break_id, should_stop));
1360}
1361
1362StopInfoSP
1364 lldb::addr_t watch_hit_addr) {
1365 return StopInfoSP(new StopInfoWatchpoint(thread, watch_id, watch_hit_addr));
1366}
1367
1368StopInfoSP StopInfo::CreateStopReasonWithSignal(Thread &thread, int signo,
1369 const char *description) {
1370 thread.GetProcess()->GetUnixSignals()->IncrementSignalHitCount(signo);
1371 return StopInfoSP(new StopInfoUnixSignal(thread, signo, description));
1372}
1373
1375 return StopInfoSP(new StopInfoTrace(thread));
1376}
1377
1379 ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp,
1380 ExpressionVariableSP expression_variable_sp) {
1381 return StopInfoSP(new StopInfoThreadPlan(plan_sp, return_valobj_sp,
1382 expression_variable_sp));
1383}
1384
1386 const char *description) {
1387 return StopInfoSP(new StopInfoException(thread, description));
1388}
1389
1391 const char *description) {
1392 return StopInfoSP(new StopInfoProcessorTrace(thread, description));
1393}
1394
1396 return StopInfoSP(new StopInfoExec(thread));
1397}
1398
1400 lldb::pid_t child_pid,
1401 lldb::tid_t child_tid) {
1402 return StopInfoSP(new StopInfoFork(thread, child_pid, child_tid));
1403}
1404
1405
1407 lldb::pid_t child_pid,
1408 lldb::tid_t child_tid) {
1409 return StopInfoSP(new StopInfoVFork(thread, child_pid, child_tid));
1410}
1411
1413 return StopInfoSP(new StopInfoVForkDone(thread));
1414}
1415
1416ValueObjectSP StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp) {
1417 if (stop_info_sp &&
1418 stop_info_sp->GetStopReason() == eStopReasonPlanComplete) {
1419 StopInfoThreadPlan *plan_stop_info =
1420 static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1421 return plan_stop_info->GetReturnValueObject();
1422 } else
1423 return ValueObjectSP();
1424}
1425
1426ExpressionVariableSP StopInfo::GetExpressionVariable(StopInfoSP &stop_info_sp) {
1427 if (stop_info_sp &&
1428 stop_info_sp->GetStopReason() == eStopReasonPlanComplete) {
1429 StopInfoThreadPlan *plan_stop_info =
1430 static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1431 return plan_stop_info->GetExpressionVariable();
1432 } else
1433 return ExpressionVariableSP();
1434}
1435
1436lldb::ValueObjectSP
1437StopInfo::GetCrashingDereference(StopInfoSP &stop_info_sp,
1438 lldb::addr_t *crashing_address) {
1439 if (!stop_info_sp) {
1440 return ValueObjectSP();
1441 }
1442
1443 const char *description = stop_info_sp->GetDescription();
1444 if (!description) {
1445 return ValueObjectSP();
1446 }
1447
1448 ThreadSP thread_sp = stop_info_sp->GetThread();
1449 if (!thread_sp) {
1450 return ValueObjectSP();
1451 }
1452
1453 StackFrameSP frame_sp = thread_sp->GetSelectedFrame();
1454
1455 if (!frame_sp) {
1456 return ValueObjectSP();
1457 }
1458
1459 const char address_string[] = "address=";
1460
1461 const char *address_loc = strstr(description, address_string);
1462 if (!address_loc) {
1463 return ValueObjectSP();
1464 }
1465
1466 address_loc += (sizeof(address_string) - 1);
1467
1468 uint64_t address = strtoull(address_loc, nullptr, 0);
1469 if (crashing_address) {
1470 *crashing_address = address;
1471 }
1472
1473 return frame_sp->GuessValueForAddress(address);
1474}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:337
#define LLDB_LOGF(log,...)
Definition: Log.h:344
lldb::BreakpointLocationSP GetByIndex(size_t i)
Returns a shared pointer to the breakpoint location with index i.
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition: Breakpoint.h:81
bool IsOneShot() const
Check the OneShot state.
Definition: Breakpoint.cpp:336
bool IsInternal() const
Tell whether this breakpoint is an "internal" breakpoint.
Definition: Breakpoint.cpp:259
A class to manage flag bits.
Definition: Debugger.h:78
lldb::StreamSP GetAsyncOutputStream()
Definition: Debugger.cpp:1225
void SetAsyncExecution(bool async)
Definition: Debugger.cpp:917
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
Definition: Debugger.cpp:1460
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
Definition: Debugger.cpp:1467
void SetUnwindOnError(bool unwind=false)
Definition: Target.h:324
void SetIgnoreBreakpoints(bool ignore=false)
Definition: Target.h:328
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
Target & GetTargetRef() const
Returns a reference to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
bool IsLastResumeForUserExpression() const
Definition: Process.h:278
bool GetIgnoreBreakpointsInExpressions() const
Definition: Process.cpp:235
static void AddRestartedReason(Event *event_ptr, const char *reason)
Definition: Process.cpp:4192
A plug-in interface definition class for debugging a process.
Definition: Process.h:343
const ProcessModID & GetModIDRef() const
Definition: Process.h:1386
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1220
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition: Scalar.cpp:334
An error handling class.
Definition: Status.h:44
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:130
bool Success() const
Test for success condition.
Definition: Status.cpp:287
void PerformAction(Event *event_ptr) override
Definition: StopInfo.cpp:255
const char * GetDescription() override
Definition: StopInfo.cpp:181
bool ShouldStopSynchronous(Event *event_ptr) override
Definition: StopInfo.cpp:148
bool IsValidForOperatingSystemThread(Thread &thread) override
Definition: StopInfo.cpp:135
bool DoShouldNotify(Event *event_ptr) override
Definition: StopInfo.cpp:177
~StopInfoBreakpoint() override=default
StopInfoBreakpoint(Thread &thread, break_id_t break_id, bool should_stop)
Definition: StopInfo.cpp:96
StopInfoBreakpoint(Thread &thread, break_id_t break_id)
Definition: StopInfo.cpp:88
bool ShouldStop(Event *event_ptr) override
Definition: StopInfo.cpp:247
StopReason GetStopReason() const override
Definition: StopInfo.cpp:146
const char * GetDescription() override
Definition: StopInfo.cpp:1145
~StopInfoException() override=default
StopInfoException(Thread &thread, const char *description)
Definition: StopInfo.cpp:1135
StopReason GetStopReason() const override
Definition: StopInfo.cpp:1143
~StopInfoExec() override=default
StopInfoExec(Thread &thread)
Definition: StopInfo.cpp:1224
const char * GetDescription() override
Definition: StopInfo.cpp:1237
StopReason GetStopReason() const override
Definition: StopInfo.cpp:1235
void PerformAction(Event *event_ptr) override
Definition: StopInfo.cpp:1240
bool ShouldStop(Event *event_ptr) override
Definition: StopInfo.cpp:1228
void PerformAction(Event *event_ptr) override
Definition: StopInfo.cpp:1270
bool ShouldStop(Event *event_ptr) override
Definition: StopInfo.cpp:1263
StopReason GetStopReason() const override
Definition: StopInfo.cpp:1265
StopInfoFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
Definition: StopInfo.cpp:1257
~StopInfoFork() override=default
const char * GetDescription() override
Definition: StopInfo.cpp:1267
StopInfoProcessorTrace(Thread &thread, const char *description)
Definition: StopInfo.cpp:1157
~StopInfoProcessorTrace() override=default
const char * GetDescription() override
Definition: StopInfo.cpp:1169
StopReason GetStopReason() const override
Definition: StopInfo.cpp:1165
bool ShouldStop(Event *event_ptr) override
Definition: StopInfo.cpp:1207
~StopInfoThreadPlan() override=default
ExpressionVariableSP m_expression_variable_sp
Definition: StopInfo.cpp:1217
ExpressionVariableSP GetExpressionVariable()
Definition: StopInfo.cpp:1202
const char * GetDescription() override
Definition: StopInfo.cpp:1191
StopReason GetStopReason() const override
Definition: StopInfo.cpp:1189
ValueObjectSP GetReturnValueObject()
Definition: StopInfo.cpp:1200
StopInfoThreadPlan(ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp, ExpressionVariableSP &expression_variable_sp)
Definition: StopInfo.cpp:1181
const char * GetDescription() override
Definition: StopInfo.cpp:1123
~StopInfoTrace() override=default
StopReason GetStopReason() const override
Definition: StopInfo.cpp:1121
StopInfoTrace(Thread &thread)
Definition: StopInfo.cpp:1117
void WillResume(lldb::StateType resume_state) override
Definition: StopInfo.cpp:1085
bool DoShouldNotify(Event *event_ptr) override
Definition: StopInfo.cpp:1066
StopInfoUnixSignal(Thread &thread, int signo, const char *description)
Definition: StopInfo.cpp:1042
~StopInfoUnixSignal() override=default
const char * GetDescription() override
Definition: StopInfo.cpp:1094
bool ShouldStopSynchronous(Event *event_ptr) override
Definition: StopInfo.cpp:1051
bool ShouldStop(Event *event_ptr) override
Definition: StopInfo.cpp:1058
StopReason GetStopReason() const override
Definition: StopInfo.cpp:1049
const char * GetDescription() override
Definition: StopInfo.cpp:1333
~StopInfoVForkDone() override=default
bool ShouldStop(Event *event_ptr) override
Definition: StopInfo.cpp:1329
StopInfoVForkDone(Thread &thread)
Definition: StopInfo.cpp:1325
StopReason GetStopReason() const override
Definition: StopInfo.cpp:1331
void PerformAction(Event *event_ptr) override
Definition: StopInfo.cpp:1336
bool ShouldStop(Event *event_ptr) override
Definition: StopInfo.cpp:1297
StopReason GetStopReason() const override
Definition: StopInfo.cpp:1299
void PerformAction(Event *event_ptr) override
Definition: StopInfo.cpp:1304
~StopInfoVFork() override=default
StopInfoVFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
Definition: StopInfo.cpp:1291
const char * GetDescription() override
Definition: StopInfo.cpp:1301
ThreadPlanStepOverWatchpoint(Thread &thread, StopInfoWatchpointSP stop_info_sp, WatchpointSP watch_sp)
Definition: StopInfo.cpp:696
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override
Definition: StopInfo.cpp:706
WatchpointSentry(ProcessSP p_sp, WatchpointSP w_sp)
Definition: StopInfo.cpp:629
static bool SentryPreResumeAction(void *sentry_void)
Definition: StopInfo.cpp:658
~StopInfoWatchpoint() override=default
std::shared_ptr< StopInfoWatchpoint > StopInfoWatchpointSP
Definition: StopInfo.cpp:687
const char * GetDescription() override
Definition: StopInfo.cpp:677
void PerformAction(Event *event_ptr) override
Definition: StopInfo.cpp:868
bool ShouldStop(Event *event_ptr) override
Definition: StopInfo.cpp:860
StopInfoWatchpoint(Thread &thread, break_id_t watch_id, lldb::addr_t watch_hit_addr)
Definition: StopInfo.cpp:669
bool ShouldStopSynchronous(Event *event_ptr) override
Definition: StopInfo.cpp:767
StopReason GetStopReason() const override
Definition: StopInfo.cpp:675
std::string m_description
Definition: StopInfo.h:179
static lldb::StopInfoSP CreateStopReasonWithPlan(lldb::ThreadPlanSP &plan, lldb::ValueObjectSP return_valobj_sp, lldb::ExpressionVariableSP expression_variable_sp)
Definition: StopInfo.cpp:1378
uint64_t GetValue() const
Definition: StopInfo.h:45
static lldb::ExpressionVariableSP GetExpressionVariable(lldb::StopInfoSP &stop_info_sp)
Definition: StopInfo.cpp:1426
static lldb::StopInfoSP CreateStopReasonWithWatchpointID(Thread &thread, lldb::break_id_t watch_id, lldb::addr_t watch_hit_addr=LLDB_INVALID_ADDRESS)
Definition: StopInfo.cpp:1363
static lldb::ValueObjectSP GetReturnValueObject(lldb::StopInfoSP &stop_info_sp)
Definition: StopInfo.cpp:1416
static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread)
Definition: StopInfo.cpp:1374
static lldb::StopInfoSP CreateStopReasonVFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
Definition: StopInfo.cpp:1406
bool IsValid() const
Definition: StopInfo.cpp:39
lldb::ThreadSP GetThread() const
Definition: StopInfo.h:34
static lldb::StopInfoSP CreateStopReasonFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
Definition: StopInfo.cpp:1399
static lldb::StopInfoSP CreateStopReasonVForkDone(Thread &thread)
Definition: StopInfo.cpp:1412
virtual void SetDescription(const char *desc_cstr)
Definition: StopInfo.h:73
static lldb::StopInfoSP CreateStopReasonWithException(Thread &thread, const char *description)
Definition: StopInfo.cpp:1385
static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id)
static lldb::ValueObjectSP GetCrashingDereference(lldb::StopInfoSP &stop_info_sp, lldb::addr_t *crashing_address=nullptr)
Definition: StopInfo.cpp:1437
static lldb::StopInfoSP CreateStopReasonProcessorTrace(Thread &thread, const char *description)
Definition: StopInfo.cpp:1390
static lldb::StopInfoSP CreateStopReasonWithExec(Thread &thread)
Definition: StopInfo.cpp:1395
static lldb::StopInfoSP CreateStopReasonWithSignal(Thread &thread, int signo, const char *description=nullptr)
Definition: StopInfo.cpp:1368
StopInfo(Thread &thread, uint64_t value)
Definition: StopInfo.cpp:32
lldb::ThreadWP m_thread_wp
Definition: StopInfo.h:174
virtual bool ShouldStop(Event *event_ptr)
Definition: StopInfo.h:171
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
lldb::break_id_t GetID() const
Definition: Stoppoint.cpp:22
const char * GetData() const
Definition: StreamString.h:43
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
Debugger & GetDebugger()
Definition: Target.h:1031
bool DoPlanExplainsStop(Event *event_ptr) override
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:42
virtual lldb::StopInfoSP GetPrivateStopInfo(bool calculate=true)
Definition: Thread.cpp:374
void SetStopInfo(const lldb::StopInfoSP &stop_info_sp)
Definition: Thread.cpp:446
lldb::ProcessSP GetProcess() const
Definition: Thread.h:153
static lldb::ExpressionResults Evaluate(ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, llvm::StringRef expr_cstr, llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp, Status &error, std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
Evaluate one expression in the scratch context of the target passed in the exe_ctx and return its res...
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
#define LLDB_INVALID_INDEX32
Definition: lldb-defines.h:75
#define LLDB_INVALID_UID
Definition: lldb-defines.h:80
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
Definition: SBAddress.h:15
@ eDescriptionLevelBrief
StateType
Process and Thread States.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
@ eStateRunning
Process or thread is running and can't be examined.
ExpressionResults
The results of expression evaluation.
@ eExpressionCompleted
int32_t break_id_t
Definition: lldb-types.h:88
uint64_t pid_t
Definition: lldb-types.h:85
uint64_t addr_t
Definition: lldb-types.h:83
StopReason
Thread stop reasons.
@ eStopReasonPlanComplete
@ eStopReasonTrace
@ eStopReasonBreakpoint
@ eStopReasonExec
Program was re-exec'ed.
@ eStopReasonVForkDone
@ eStopReasonProcessorTrace
@ eStopReasonException
@ eStopReasonWatchpoint
@ eStopReasonVFork
@ eStopReasonSignal
uint64_t tid_t
Definition: lldb-types.h:86
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47