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
16#include "lldb/Core/Debugger.h"
18#include "lldb/Symbol/Block.h"
19#include "lldb/Target/Process.h"
21#include "lldb/Target/Target.h"
22#include "lldb/Target/Thread.h"
27#include "lldb/Utility/Log.h"
30
31using namespace lldb;
32using namespace lldb_private;
33
34StopInfo::StopInfo(Thread &thread, uint64_t value)
35 : m_thread_wp(thread.shared_from_this()),
36 m_stop_id(thread.GetProcess()->GetStopID()),
37 m_resume_id(thread.GetProcess()->GetResumeID()), m_value(value),
40
41bool StopInfo::IsValid() const {
42 ThreadSP thread_sp(m_thread_wp.lock());
43 if (thread_sp)
44 return thread_sp->GetProcess()->GetStopID() == m_stop_id;
45 return false;
46}
47
49 ThreadSP thread_sp(m_thread_wp.lock());
50 if (thread_sp) {
51 m_stop_id = thread_sp->GetProcess()->GetStopID();
52 m_resume_id = thread_sp->GetProcess()->GetResumeID();
53 }
54}
55
57 ThreadSP thread_sp(m_thread_wp.lock());
58
59 if (thread_sp) {
60 lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState();
61 if (ret_type == eStateRunning) {
62 return true;
63 } else if (ret_type == eStateStopped) {
64 // This is a little tricky. We want to count "run and stopped again
65 // before you could ask this question as a "TRUE" answer to
66 // HasTargetRunSinceMe. But we don't want to include any running of the
67 // target done for expressions. So we track both resumes, and resumes
68 // caused by expressions, and check if there are any resumes
69 // NOT caused
70 // by expressions.
71
72 uint32_t curr_resume_id = thread_sp->GetProcess()->GetResumeID();
73 uint32_t last_user_expression_id =
74 thread_sp->GetProcess()->GetLastUserExpressionResumeID();
75 if (curr_resume_id == m_resume_id) {
76 return false;
77 } else if (curr_resume_id > last_user_expression_id) {
78 return true;
79 }
80 }
81 }
82 return false;
83}
84
85// StopInfoBreakpoint
86
87namespace lldb_private {
89public:
97
98 StopInfoBreakpoint(Thread &thread, break_id_t break_id, bool should_stop)
99 : StopInfo(thread, break_id), m_should_stop(should_stop),
102 m_was_all_internal(false), m_was_one_shot(false) {
103 StoreBPInfo();
104 }
105
106 ~StopInfoBreakpoint() override = default;
107
108 void StoreBPInfo() {
109 ThreadSP thread_sp(m_thread_wp.lock());
110 if (thread_sp) {
112 if (bp_site_sp) {
113 uint32_t num_constituents = bp_site_sp->GetNumberOfConstituents();
114 if (num_constituents == 1) {
115 BreakpointLocationSP bp_loc_sp = bp_site_sp->GetConstituentAtIndex(0);
116 if (bp_loc_sp) {
117 Breakpoint & bkpt = bp_loc_sp->GetBreakpoint();
118 m_break_id = bkpt.GetID();
119 m_was_one_shot = bkpt.IsOneShot();
121 }
122 } else {
123 m_was_all_internal = true;
124 for (uint32_t i = 0; i < num_constituents; i++) {
125 if (!bp_site_sp->GetConstituentAtIndex(i)
126 ->GetBreakpoint()
127 .IsInternal()) {
128 m_was_all_internal = false;
129 break;
130 }
131 }
132 }
133 m_address = bp_site_sp->GetLoadAddress();
134 }
135 }
136 }
137
139 ProcessSP process_sp(thread.GetProcess());
140 if (process_sp) {
142 if (bp_site_sp)
143 return bp_site_sp->ValidForThisThread(thread);
144 }
145 return false;
146 }
147
148 StopReason GetStopReason() const override { return eStopReasonBreakpoint; }
149
150 bool ShouldStopSynchronous(Event *event_ptr) override {
151 ThreadSP thread_sp(m_thread_wp.lock());
152 if (thread_sp) {
154 // Only check once if we should stop at a breakpoint
156 if (bp_site_sp) {
157 ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
158 StoppointCallbackContext context(event_ptr, exe_ctx, true);
159 bp_site_sp->BumpHitCounts();
160 m_should_stop = bp_site_sp->ShouldStop(&context);
161 } else {
163
164 LLDB_LOGF(log,
165 "Process::%s could not find breakpoint site id: %" PRId64
166 "...",
167 __FUNCTION__, m_value);
168
169 m_should_stop = true;
170 }
172 }
173 return m_should_stop;
174 }
175 return false;
176 }
177
178 bool DoShouldNotify(Event *event_ptr) override {
179 return !m_was_all_internal;
180 }
181
182 const char *GetDescription() override {
183 if (m_description.empty()) {
184 ThreadSP thread_sp(m_thread_wp.lock());
185 if (thread_sp) {
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_constituents = bp_site_sp->GetNumberOfConstituents();
193 for (size_t idx = 0; idx < num_constituents; idx++) {
194 const char *kind = bp_site_sp->GetConstituentAtIndex(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
246 uint32_t GetStopReasonDataCount() const override {
248 if (bp_site_sp)
249 return bp_site_sp->GetNumberOfConstituents() * 2;
250 return 0; // Breakpoint must have cleared itself...
251 }
252
253 uint64_t GetStopReasonDataAtIndex(uint32_t idx) override {
255 if (bp_site_sp) {
256 uint32_t bp_index = idx / 2;
257 BreakpointLocationSP bp_loc_sp(
258 bp_site_sp->GetConstituentAtIndex(bp_index));
259 if (bp_loc_sp) {
260 if (idx & 1) {
261 // FIXME: This might be a Facade breakpoint, so we need to fetch
262 // the one that the thread actually hit, not the native loc ID.
263
264 // Odd idx, return the breakpoint location ID
265 return bp_loc_sp->GetID();
266 } else {
267 // Even idx, return the breakpoint ID
268 return bp_loc_sp->GetBreakpoint().GetID();
269 }
270 }
271 }
273 }
274
275 std::optional<uint32_t>
276 GetSuggestedStackFrameIndex(bool inlined_stack) override {
277 if (!inlined_stack)
278 return {};
279
280 ThreadSP thread_sp(m_thread_wp.lock());
281 if (!thread_sp)
282 return {};
284 if (!bp_site_sp)
285 return {};
286
287 return bp_site_sp->GetSuggestedStackFrameIndex();
288 }
289
290 bool ShouldShow() const override { return !m_was_all_internal; }
291
292 bool ShouldSelect() const override { return !m_was_all_internal; }
293
294protected:
295 bool ShouldStop(Event *event_ptr) override {
296 // This just reports the work done by PerformAction or the synchronous
297 // stop. It should only ever get called after they have had a chance to
298 // run.
300 return m_should_stop;
301 }
302
303 void PerformAction(Event *event_ptr) override {
305 return;
307 bool all_stopping_locs_internal = true;
308
309 ThreadSP thread_sp(m_thread_wp.lock());
310
311 if (thread_sp) {
313
314 if (!thread_sp->IsValid()) {
315 // This shouldn't ever happen, but just in case, don't do more harm.
316 if (log) {
317 LLDB_LOGF(log, "PerformAction got called with an invalid thread.");
318 }
319 m_should_stop = true;
321 return;
322 }
323
325 std::unordered_set<break_id_t> precondition_breakpoints;
326 // Breakpoints that fail their condition check are not considered to
327 // have been hit. If the only locations at this site have failed their
328 // conditions, we should change the stop-info to none. Otherwise, if we
329 // hit another breakpoint on a different thread which does stop, users
330 // will see a breakpont hit with a failed condition, which is wrong.
331 // Use this variable to tell us if that is true.
332 bool actually_hit_any_locations = false;
333 if (bp_site_sp) {
334 // Let's copy the constituents list out of the site and store them in a
335 // local list. That way if one of the breakpoint actions changes the
336 // site, then we won't be operating on a bad list.
337 BreakpointLocationCollection site_locations;
338 size_t num_constituents =
339 bp_site_sp->CopyConstituentsList(site_locations);
340
341 if (num_constituents == 0) {
342 m_should_stop = true;
343 actually_hit_any_locations = true; // We're going to stop, don't
344 // change the stop info.
345 } else {
346 // We go through each location, and test first its precondition -
347 // this overrides everything. Note, we only do this once per
348 // breakpoint - not once per location... Then check the condition.
349 // If the condition says to stop, then we run the callback for that
350 // location. If that callback says to stop as well, then we set
351 // m_should_stop to true; we are going to stop. But we still want to
352 // give all the breakpoints whose conditions say we are going to stop
353 // a chance to run their callbacks. Of course if any callback
354 // restarts the target by putting "continue" in the callback, then
355 // we're going to restart, without running the rest of the callbacks.
356 // And in this case we will end up not stopping even if another
357 // location said we should stop. But that's better than not running
358 // all the callbacks.
359
360 // There's one other complication here. We may have run an async
361 // breakpoint callback that said we should stop. We only want to
362 // override that if another breakpoint action says we shouldn't
363 // stop. If nobody else has an opinion, then we should stop if the
364 // async callback says we should. An example of this is the async
365 // shared library load notification breakpoint and the setting
366 // stop-on-sharedlibrary-events.
367 // We'll keep the async value in async_should_stop, and track whether
368 // anyone said we should NOT stop in actually_said_continue.
369 bool async_should_stop = false;
371 async_should_stop = m_should_stop;
372 bool actually_said_continue = false;
373
374 m_should_stop = false;
375
376 // We don't select threads as we go through them testing breakpoint
377 // conditions and running commands. So we need to set the thread for
378 // expression evaluation here:
379 ThreadList::ExpressionExecutionThreadPusher thread_pusher(thread_sp);
380
381 ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
382 Process *process = exe_ctx.GetProcessPtr();
383 if (process->GetModIDRef().IsRunningExpression()) {
384 // If we are in the middle of evaluating an expression, don't run
385 // asynchronous breakpoint commands or expressions. That could
386 // lead to infinite recursion if the command or condition re-calls
387 // the function with this breakpoint.
388 // TODO: We can keep a list of the breakpoints we've seen while
389 // running expressions in the nested
390 // PerformAction calls that can arise when the action runs a
391 // function that hits another breakpoint, and only stop running
392 // commands when we see the same breakpoint hit a second time.
393
395
396 // It is possible that the user has a breakpoint at the same site
397 // as the completed plan had (e.g. user has a breakpoint
398 // on a module entry point, and `ThreadPlanCallFunction` ends
399 // also there). We can't find an internal breakpoint in the loop
400 // later because it was already removed on the plan completion.
401 // So check if the plan was completed, and stop if so.
402 if (thread_sp->CompletedPlanOverridesBreakpoint()) {
403 m_should_stop = true;
404 thread_sp->ResetStopInfo();
405 return;
406 }
407
408 LLDB_LOGF(log, "StopInfoBreakpoint::PerformAction - Hit a "
409 "breakpoint while running an expression,"
410 " not running commands to avoid recursion.");
411 bool ignoring_breakpoints =
413 // Internal breakpoints should be allowed to do their job, we
414 // can make sure they don't do anything that would cause recursive
415 // command execution:
416 if (!m_was_all_internal) {
417 m_should_stop = !ignoring_breakpoints;
418 LLDB_LOGF(log,
419 "StopInfoBreakpoint::PerformAction - in expression, "
420 "continuing: %s.",
421 m_should_stop ? "true" : "false");
423 "hit breakpoint while running function, skipping commands "
424 "and conditions to prevent recursion",
425 process->GetTarget().GetDebugger().GetID());
426 return;
427 }
428 }
429
430 StoppointCallbackContext context(event_ptr, exe_ctx, false);
431
432 // For safety's sake let's also grab an extra reference to the
433 // breakpoint constituents of the locations we're going to examine,
434 // since the locations are going to have to get back to their
435 // breakpoints, and the locations don't keep their constituents alive.
436 // I'm just sticking the BreakpointSP's in a vector since I'm only
437 // using it to locally increment their retain counts.
438
439 std::vector<lldb::BreakpointSP> location_constituents;
440
441 for (size_t j = 0; j < num_constituents; j++) {
442 BreakpointLocationSP loc(site_locations.GetByIndex(j));
443 location_constituents.push_back(
444 loc->GetBreakpoint().shared_from_this());
445 }
446
447 for (size_t j = 0; j < num_constituents; j++) {
448 lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j);
449 StreamString loc_desc;
450 if (log) {
451 bp_loc_sp->GetDescription(&loc_desc, eDescriptionLevelBrief);
452 }
453 // If another action disabled this breakpoint or its location, then
454 // don't run the actions.
455 if (!bp_loc_sp->IsEnabled() ||
456 !bp_loc_sp->GetBreakpoint().IsEnabled())
457 continue;
458
459 // The breakpoint site may have many locations associated with it,
460 // not all of them valid for this thread. Skip the ones that
461 // aren't:
462 if (!bp_loc_sp->ValidForThisThread(*thread_sp)) {
463 if (log) {
464 LLDB_LOGF(log,
465 "Breakpoint %s hit on thread 0x%llx but it was not "
466 "for this thread, continuing.",
467 loc_desc.GetData(),
468 static_cast<unsigned long long>(thread_sp->GetID()));
469 }
470 continue;
471 }
472
473 // First run the precondition, but since the precondition is per
474 // breakpoint, only run it once per breakpoint.
475 std::pair<std::unordered_set<break_id_t>::iterator, bool> result =
476 precondition_breakpoints.insert(
477 bp_loc_sp->GetBreakpoint().GetID());
478 if (!result.second)
479 continue;
480
481 bool precondition_result =
482 bp_loc_sp->GetBreakpoint().EvaluatePrecondition(context);
483 if (!precondition_result) {
484 actually_said_continue = true;
485 continue;
486 }
487 // Next run the condition for the breakpoint. If that says we
488 // should stop, then we'll run the callback for the breakpoint. If
489 // the callback says we shouldn't stop that will win.
490
491 if (!bp_loc_sp->GetCondition())
492 actually_hit_any_locations = true;
493 else {
494 Status condition_error;
495 bool condition_says_stop =
496 bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error);
497
498 if (!condition_error.Success()) {
499 // If the condition fails to evaluate, we are going to stop
500 // at it, so the location was hit.
501 actually_hit_any_locations = true;
502 const char *err_str =
503 condition_error.AsCString("<unknown error>");
504 LLDB_LOGF(log, "Error evaluating condition: \"%s\"\n", err_str);
505
506 StreamString strm;
507 strm << "stopped due to an error evaluating condition of "
508 "breakpoint ";
509 bp_loc_sp->GetDescription(&strm, eDescriptionLevelBrief);
510 strm << ": \"" << bp_loc_sp->GetCondition().GetText() << "\"\n";
511 strm << err_str;
512
514 strm.GetString().str(),
515 exe_ctx.GetTargetRef().GetDebugger().GetID());
516 } else {
517 LLDB_LOGF(log,
518 "Condition evaluated for breakpoint %s on thread "
519 "0x%llx condition_says_stop: %i.",
520 loc_desc.GetData(),
521 static_cast<unsigned long long>(thread_sp->GetID()),
522 condition_says_stop);
523 if (condition_says_stop)
524 actually_hit_any_locations = true;
525 else {
526 // We don't want to increment the hit count of breakpoints if
527 // the condition fails. We've already bumped it by the time
528 // we get here, so undo the bump:
529 bp_loc_sp->UndoBumpHitCount();
530 actually_said_continue = true;
531 continue;
532 }
533 }
534 }
535
536 // We've done all the checks whose failure means "we consider lldb
537 // not to have hit the breakpoint". Now we're going to check for
538 // conditions that might continue after hitting. Start with the
539 // ignore count:
540 if (!bp_loc_sp->IgnoreCountShouldStop()) {
541 actually_said_continue = true;
542 continue;
543 }
544
545 // Check the auto-continue bit on the location, do this before the
546 // callback since it may change this, but that would be for the
547 // NEXT hit. Note, you might think you could check auto-continue
548 // before the condition, and not evaluate the condition if it says
549 // to continue. But failing the condition means the breakpoint was
550 // effectively NOT HIT. So these two states are different.
551 bool auto_continue_says_stop = true;
552 if (bp_loc_sp->IsAutoContinue())
553 {
554 LLDB_LOGF(log,
555 "Continuing breakpoint %s as AutoContinue was set.",
556 loc_desc.GetData());
557 // We want this stop reported, so you will know we auto-continued
558 // but only for external breakpoints:
559 if (!bp_loc_sp->GetBreakpoint().IsInternal())
560 thread_sp->SetShouldReportStop(eVoteYes);
561 auto_continue_says_stop = false;
562 }
563
564 bool callback_says_stop = true;
565
566 // FIXME: For now the callbacks have to run in async mode - the
567 // first time we restart we need
568 // to get out of there. So set it here.
569 // When we figure out how to nest breakpoint hits then this will
570 // change.
571
572 // Don't run async callbacks in PerformAction. They have already
573 // been taken into account with async_should_stop.
574 if (!bp_loc_sp->IsCallbackSynchronous()) {
575 Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger();
576 bool old_async = debugger.GetAsyncExecution();
577 debugger.SetAsyncExecution(true);
578
579 callback_says_stop = bp_loc_sp->InvokeCallback(&context);
580
581 debugger.SetAsyncExecution(old_async);
582
583 if (callback_says_stop && auto_continue_says_stop)
584 m_should_stop = true;
585 else
586 actually_said_continue = true;
587 }
588
589 if (m_should_stop && !bp_loc_sp->GetBreakpoint().IsInternal())
590 all_stopping_locs_internal = false;
591
592 // If we are going to stop for this breakpoint, then remove the
593 // breakpoint.
594 if (callback_says_stop && bp_loc_sp &&
595 bp_loc_sp->GetBreakpoint().IsOneShot()) {
596 thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID(
597 bp_loc_sp->GetBreakpoint().GetID());
598 }
599 // Also make sure that the callback hasn't continued the target. If
600 // it did, when we'll set m_should_start to false and get out of
601 // here.
602 if (HasTargetRunSinceMe()) {
603 m_should_stop = false;
604 actually_said_continue = true;
605 break;
606 }
607 }
608 // At this point if nobody actually told us to continue, we should
609 // give the async breakpoint callback a chance to weigh in:
610 if (!actually_said_continue && !m_should_stop) {
611 m_should_stop = async_should_stop;
612 }
613 }
614 // We've figured out what this stop wants to do, so mark it as valid so
615 // we don't compute it again.
617 } else {
618 m_should_stop = true;
620 actually_hit_any_locations = true;
621 Log *log_process(GetLog(LLDBLog::Process));
622
623 LLDB_LOGF(log_process,
624 "Process::%s could not find breakpoint site id: %" PRId64
625 "...",
626 __FUNCTION__, m_value);
627 }
628
629 if ((!m_should_stop || all_stopping_locs_internal) &&
630 thread_sp->CompletedPlanOverridesBreakpoint()) {
631
632 // Override should_stop decision when we have completed step plan
633 // additionally to the breakpoint
634 m_should_stop = true;
635
636 // We know we're stopping for a completed plan and we don't want to
637 // show the breakpoint stop, so compute the public stop info immediately
638 // here.
639 thread_sp->CalculatePublicStopInfo();
640 } else if (!actually_hit_any_locations) {
641 // In the end, we didn't actually have any locations that passed their
642 // "was I hit" checks. So say we aren't stopped.
643 GetThread()->ResetStopInfo();
644 LLDB_LOGF(log, "Process::%s all locations failed condition checks.",
645 __FUNCTION__);
646 }
647
648 LLDB_LOGF(log,
649 "Process::%s returning from action with m_should_stop: %d.",
650 __FUNCTION__, m_should_stop);
651 }
652 }
653
654private:
657 return {};
658
659 ThreadSP thread_sp = GetThread();
660 if (!thread_sp)
661 return {};
662 ProcessSP process_sp = thread_sp->GetProcess();
663 if (!process_sp)
664 return {};
665
666 return process_sp->GetBreakpointSiteList().FindByID(m_value);
667 }
668
671 bool m_should_perform_action; // Since we are trying to preserve the "state"
672 // of the system even if we run functions
673 // etc. behind the users backs, we need to make sure we only REALLY perform
674 // the action once.
675 lldb::addr_t m_address; // We use this to capture the breakpoint site address
676 // when we create the StopInfo,
677 // in case somebody deletes it between the time the StopInfo is made and the
678 // description is asked for.
682};
683
684// StopInfoWatchpoint
685
687public:
688 // Make sure watchpoint is properly disabled and subsequently enabled while
689 // performing watchpoint actions.
691 public:
693 watchpoint_sp(w_sp) {
694 if (process_sp && watchpoint_sp) {
695 const bool notify = false;
696 watchpoint_sp->TurnOnEphemeralMode();
697 process_sp->DisableWatchpoint(watchpoint_sp, notify);
698 process_sp->AddPreResumeAction(SentryPreResumeAction, this);
699 }
700 }
701
702 void DoReenable() {
703 if (process_sp && watchpoint_sp) {
704 bool was_disabled = watchpoint_sp->IsDisabledDuringEphemeralMode();
705 watchpoint_sp->TurnOffEphemeralMode();
706 const bool notify = false;
707 if (was_disabled) {
708 process_sp->DisableWatchpoint(watchpoint_sp, notify);
709 } else {
710 process_sp->EnableWatchpoint(watchpoint_sp, notify);
711 }
712 }
713 }
714
716 DoReenable();
717 if (process_sp)
718 process_sp->ClearPreResumeAction(SentryPreResumeAction, this);
719 }
720
721 static bool SentryPreResumeAction(void *sentry_void) {
722 WatchpointSentry *sentry = (WatchpointSentry *) sentry_void;
723 sentry->DoReenable();
724 return true;
725 }
726
727 private:
730 };
731
732 StopInfoWatchpoint(Thread &thread, break_id_t watch_id, bool silently_skip_wp)
733 : StopInfo(thread, watch_id), m_silently_skip_wp(silently_skip_wp) {}
734
735 ~StopInfoWatchpoint() override = default;
736
737 StopReason GetStopReason() const override { return eStopReasonWatchpoint; }
738
739 uint32_t GetStopReasonDataCount() const override { return 1; }
740 uint64_t GetStopReasonDataAtIndex(uint32_t idx) override {
741 if (idx == 0)
742 return GetValue();
743 return 0;
744 }
745
746 const char *GetDescription() override {
747 if (m_description.empty()) {
748 StreamString strm;
749 strm.Printf("watchpoint %" PRIi64, m_value);
750 m_description = std::string(strm.GetString());
751 }
752 return m_description.c_str();
753 }
754
755protected:
756 using StopInfoWatchpointSP = std::shared_ptr<StopInfoWatchpoint>;
757 // This plan is used to orchestrate stepping over the watchpoint for
758 // architectures (e.g. ARM) that report the watch before running the watched
759 // access. This is the sort of job you have to defer to the thread plans,
760 // if you try to do it directly in the stop info and there are other threads
761 // that needed to process this stop you will have yanked control away from
762 // them and they won't behave correctly.
764 public:
766 StopInfoWatchpointSP stop_info_sp,
767 WatchpointSP watch_sp)
768 : ThreadPlanStepInstruction(thread, false, true, eVoteNoOpinion,
770 m_stop_info_sp(stop_info_sp), m_watch_sp(watch_sp) {
771 assert(watch_sp);
772 }
773
774 bool DoWillResume(lldb::StateType resume_state,
775 bool current_plan) override {
776 if (resume_state == eStateSuspended)
777 return true;
778
779 if (!m_did_disable_wp) {
780 GetThread().GetProcess()->DisableWatchpoint(m_watch_sp, false);
781 m_did_disable_wp = true;
782 }
783 return true;
784 }
785
786 bool DoPlanExplainsStop(Event *event_ptr) override {
788 return true;
789 StopInfoSP stop_info_sp = GetThread().GetPrivateStopInfo();
790 // lldb-server resets the stop info for threads that didn't get to run,
791 // so we might have not gotten to run, but still have a watchpoint stop
792 // reason, in which case this will indeed be for us.
793 if (stop_info_sp
794 && stop_info_sp->GetStopReason() == eStopReasonWatchpoint)
795 return true;
796 return false;
797 }
798
799 void DidPop() override {
800 // Don't artifically keep the watchpoint alive.
801 m_watch_sp.reset();
802 }
803
804 bool ShouldStop(Event *event_ptr) override {
805 bool should_stop = ThreadPlanStepInstruction::ShouldStop(event_ptr);
806 bool plan_done = MischiefManaged();
807 if (plan_done) {
808 m_stop_info_sp->SetStepOverPlanComplete();
811 }
812 return should_stop;
813 }
814
816 return true;
817 }
818
819 protected:
821 if (!m_did_disable_wp)
822 return;
823 m_did_disable_wp = true;
824 GetThread().GetProcess()->EnableWatchpoint(m_watch_sp, true);
825 }
826
827 private:
830 bool m_did_disable_wp = false;
831 };
832
833 bool ShouldStopSynchronous(Event *event_ptr) override {
834 // If we are running our step-over the watchpoint plan, stop if it's done
835 // and continue if it's not:
837 return m_should_stop;
838
839 // If we are running our step over plan, then stop here and let the regular
840 // ShouldStop figure out what we should do: Otherwise, give our plan
841 // more time to get run:
844
846 ThreadSP thread_sp(m_thread_wp.lock());
847 assert(thread_sp);
848
849 if (thread_sp->GetTemporaryResumeState() == eStateSuspended) {
850 // This is the second firing of a watchpoint so don't process it again.
851 LLDB_LOG(log, "We didn't run but stopped with a StopInfoWatchpoint, we "
852 "have already handled this one, don't do it again.");
853 m_should_stop = false;
855 return m_should_stop;
856 }
857
858 WatchpointSP wp_sp(
859 thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
860 // If we can no longer find the watchpoint, we just have to stop:
861 if (!wp_sp) {
862
863 LLDB_LOGF(log,
864 "Process::%s could not find watchpoint location id: %" PRId64
865 "...",
866 __FUNCTION__, GetValue());
867
868 m_should_stop = true;
870 return true;
871 }
872
873 ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
874 StoppointCallbackContext context(event_ptr, exe_ctx, true);
875 m_should_stop = wp_sp->ShouldStop(&context);
876 if (!m_should_stop) {
877 // This won't happen at present because we only allow one watchpoint per
878 // watched range. So we won't stop at a watched address with a disabled
879 // watchpoint. If we start allowing overlapping watchpoints, then we
880 // will have to make watchpoints be real "WatchpointSite" and delegate to
881 // all the watchpoints sharing the site. In that case, the code below
882 // would be the right thing to do.
884 return m_should_stop;
885 }
886 // If this is a system where we need to execute the watchpoint by hand
887 // after the hit, queue a thread plan to do that, and then say not to stop.
888 // Otherwise, let the async action figure out whether the watchpoint should
889 // stop
890
891 ProcessSP process_sp = exe_ctx.GetProcessSP();
892 bool wp_triggers_after = process_sp->GetWatchpointReportedAfter();
893
894 if (!wp_triggers_after) {
895 // We have to step over the watchpoint before we know what to do:
896 StopInfoWatchpointSP me_as_siwp_sp
897 = std::static_pointer_cast<StopInfoWatchpoint>(shared_from_this());
898 ThreadPlanSP step_over_wp_sp =
899 std::make_shared<ThreadPlanStepOverWatchpoint>(*(thread_sp.get()),
900 me_as_siwp_sp, wp_sp);
901 // When this plan is done we want to stop, so set this as a Controlling
902 // plan.
903 step_over_wp_sp->SetIsControllingPlan(true);
904 step_over_wp_sp->SetOkayToDiscard(false);
905
907 error = thread_sp->QueueThreadPlan(step_over_wp_sp, false);
908 // If we couldn't push the thread plan, just stop here:
909 if (!error.Success()) {
910 LLDB_LOGF(log, "Could not push our step over watchpoint plan: %s",
911 error.AsCString());
912
913 m_should_stop = true;
915 return true;
916 } else {
917 // Otherwise, don't set m_should_stop, we don't know that yet. Just
918 // say we should continue, and tell the thread we really should do so:
919 thread_sp->SetShouldRunBeforePublicStop(true);
921 return false;
922 }
923 } else {
924 // We didn't have to do anything special
926 return m_should_stop;
927 }
928
929 return m_should_stop;
930 }
931
932 bool ShouldStop(Event *event_ptr) override {
933 // This just reports the work done by PerformAction or the synchronous
934 // stop. It should only ever get called after they have had a chance to
935 // run.
937 return m_should_stop;
938 }
939
940 void PerformAction(Event *event_ptr) override {
942 // We're going to calculate if we should stop or not in some way during the
943 // course of this code. Also by default we're going to stop, so set that
944 // here.
945 m_should_stop = true;
946
947
948 ThreadSP thread_sp(m_thread_wp.lock());
949 if (thread_sp) {
950
951 WatchpointSP wp_sp(
952 thread_sp->CalculateTarget()->GetWatchpointList().FindByID(
953 GetValue()));
954 if (wp_sp) {
955 // This sentry object makes sure the current watchpoint is disabled
956 // while performing watchpoint actions, and it is then enabled after we
957 // are finished.
958 ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
959 ProcessSP process_sp = exe_ctx.GetProcessSP();
960
961 WatchpointSentry sentry(process_sp, wp_sp);
962
963 if (m_silently_skip_wp) {
964 m_should_stop = false;
965 wp_sp->UndoHitCount();
966 }
967
968 if (wp_sp->GetHitCount() <= wp_sp->GetIgnoreCount()) {
969 m_should_stop = false;
971 }
972
973 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
974
975 if (m_should_stop && wp_sp->GetConditionText() != nullptr) {
976 // We need to make sure the user sees any parse errors in their
977 // condition, so we'll hook the constructor errors up to the
978 // debugger's Async I/O.
979 ExpressionResults result_code;
980 EvaluateExpressionOptions expr_options;
981 expr_options.SetUnwindOnError(true);
982 expr_options.SetIgnoreBreakpoints(true);
983 ValueObjectSP result_value_sp;
984 result_code = UserExpression::Evaluate(
985 exe_ctx, expr_options, wp_sp->GetConditionText(),
986 llvm::StringRef(), result_value_sp);
987
988 if (result_code == eExpressionCompleted) {
989 if (result_value_sp) {
990 Scalar scalar_value;
991 if (result_value_sp->ResolveValue(scalar_value)) {
992 if (scalar_value.ULongLong(1) == 0) {
993 // The condition failed, which we consider "not having hit
994 // the watchpoint" so undo the hit count here.
995 wp_sp->UndoHitCount();
996 m_should_stop = false;
997 } else
998 m_should_stop = true;
999 LLDB_LOGF(log,
1000 "Condition successfully evaluated, result is %s.\n",
1001 m_should_stop ? "true" : "false");
1002 } else {
1003 m_should_stop = true;
1004 LLDB_LOGF(
1005 log,
1006 "Failed to get an integer result from the expression.");
1007 }
1008 }
1009 } else {
1010 const char *err_str = "<unknown error>";
1011 if (result_value_sp)
1012 err_str = result_value_sp->GetError().AsCString();
1013
1014 LLDB_LOGF(log, "Error evaluating condition: \"%s\"\n", err_str);
1015
1016 StreamString strm;
1017 strm << "stopped due to an error evaluating condition of "
1018 "watchpoint ";
1019 wp_sp->GetDescription(&strm, eDescriptionLevelBrief);
1020 strm << ": \"" << wp_sp->GetConditionText() << "\"\n";
1021 strm << err_str;
1022
1023 Debugger::ReportError(strm.GetString().str(),
1024 exe_ctx.GetTargetRef().GetDebugger().GetID());
1025 }
1026 }
1027
1028 // If the condition says to stop, we run the callback to further decide
1029 // whether to stop.
1030 if (m_should_stop) {
1031 // FIXME: For now the callbacks have to run in async mode - the
1032 // first time we restart we need
1033 // to get out of there. So set it here.
1034 // When we figure out how to nest watchpoint hits then this will
1035 // change.
1036
1037 bool old_async = debugger.GetAsyncExecution();
1038 debugger.SetAsyncExecution(true);
1039
1040 StoppointCallbackContext context(event_ptr, exe_ctx, false);
1041 bool stop_requested = wp_sp->InvokeCallback(&context);
1042
1043 debugger.SetAsyncExecution(old_async);
1044
1045 // Also make sure that the callback hasn't continued the target. If
1046 // it did, when we'll set m_should_stop to false and get out of here.
1047 if (HasTargetRunSinceMe())
1048 m_should_stop = false;
1049
1050 if (m_should_stop && !stop_requested) {
1051 // We have been vetoed by the callback mechanism.
1052 m_should_stop = false;
1053 }
1054 }
1055
1056 // Don't stop if the watched region value is unmodified, and
1057 // this is a Modify-type watchpoint.
1058 if (m_should_stop && !wp_sp->WatchedValueReportable(exe_ctx)) {
1059 wp_sp->UndoHitCount();
1060 m_should_stop = false;
1061 }
1062
1063 // Finally, if we are going to stop, print out the new & old values:
1064 if (m_should_stop) {
1065 wp_sp->CaptureWatchedValue(exe_ctx);
1066
1067 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
1068 StreamUP output_up = debugger.GetAsyncOutputStream();
1069 if (wp_sp->DumpSnapshots(output_up.get()))
1070 output_up->EOL();
1071 }
1072
1073 } else {
1074 Log *log_process(GetLog(LLDBLog::Process));
1075
1076 LLDB_LOGF(log_process,
1077 "Process::%s could not find watchpoint id: %" PRId64 "...",
1078 __FUNCTION__, m_value);
1079 }
1080 LLDB_LOGF(log,
1081 "Process::%s returning from action with m_should_stop: %d.",
1082 __FUNCTION__, m_should_stop);
1083
1085 }
1086 }
1087
1088private:
1093
1094 bool m_should_stop = false;
1096 // A false watchpoint hit has happened -
1097 // the thread stopped with a watchpoint
1098 // hit notification, but the watched region
1099 // was not actually accessed (as determined
1100 // by the gdb stub we're talking to).
1101 // Continue past this watchpoint without
1102 // notifying the user; on some targets this
1103 // may mean disable wp, instruction step,
1104 // re-enable wp, continue.
1105 // On others, just continue.
1109};
1110
1111// StopInfoUnixSignal
1112
1114public:
1115 StopInfoUnixSignal(Thread &thread, int signo, const char *description,
1116 std::optional<int> code)
1117 : StopInfo(thread, signo), m_code(code) {
1118 SetDescription(description);
1119 }
1120
1121 ~StopInfoUnixSignal() override = default;
1122
1123 StopReason GetStopReason() const override { return eStopReasonSignal; }
1124
1125 bool ShouldStopSynchronous(Event *event_ptr) override {
1126 ThreadSP thread_sp(m_thread_wp.lock());
1127 if (thread_sp)
1128 return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
1129 return false;
1130 }
1131
1132 bool ShouldStop(Event *event_ptr) override { return IsShouldStopSignal(); }
1133
1134 // If should stop returns false, check if we should notify of this event
1135 bool DoShouldNotify(Event *event_ptr) override {
1136 ThreadSP thread_sp(m_thread_wp.lock());
1137 if (thread_sp) {
1138 bool should_notify =
1139 thread_sp->GetProcess()->GetUnixSignals()->GetShouldNotify(m_value);
1140 if (should_notify) {
1141 StreamString strm;
1142 strm.Format(
1143 "thread {0:d} received signal: {1}", thread_sp->GetIndexID(),
1144 thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsStringRef(
1145 m_value));
1147 strm.GetData());
1148 }
1149 return should_notify;
1150 }
1151 return true;
1152 }
1153
1154 void WillResume(lldb::StateType resume_state) override {
1155 ThreadSP thread_sp(m_thread_wp.lock());
1156 if (thread_sp) {
1157 if (!thread_sp->GetProcess()->GetUnixSignals()->GetShouldSuppress(
1158 m_value))
1159 thread_sp->SetResumeSignal(m_value);
1160 }
1161 }
1162
1163 const char *GetDescription() override {
1164 if (m_description.empty()) {
1165 ThreadSP thread_sp(m_thread_wp.lock());
1166 if (thread_sp) {
1167 UnixSignalsSP unix_signals = thread_sp->GetProcess()->GetUnixSignals();
1168 StreamString strm;
1169 strm << "signal ";
1170
1171 std::string signal_name =
1172 unix_signals->GetSignalDescription(m_value, m_code);
1173 if (signal_name.size())
1174 strm << signal_name;
1175 else
1176 strm.Printf("%" PRIi64, m_value);
1177
1178 m_description = std::string(strm.GetString());
1179 }
1180 }
1181 return m_description.c_str();
1182 }
1183
1184 bool ShouldSelect() const override { return IsShouldStopSignal(); }
1185
1186 uint32_t GetStopReasonDataCount() const override { return 1; }
1187 uint64_t GetStopReasonDataAtIndex(uint32_t idx) override {
1188 if (idx == 0)
1189 return GetValue();
1190 return 0;
1191 }
1192
1193private:
1194 // In siginfo_t terms, if m_value is si_signo, m_code is si_code.
1195 std::optional<int> m_code;
1196
1197 bool IsShouldStopSignal() const {
1198 if (ThreadSP thread_sp = m_thread_wp.lock())
1199 return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
1200 return false;
1201 }
1202};
1203
1204// StopInfoInterrupt
1205
1207public:
1208 StopInfoInterrupt(Thread &thread, int signo, const char *description)
1209 : StopInfo(thread, signo) {
1210 SetDescription(description);
1211 }
1212
1213 ~StopInfoInterrupt() override = default;
1214
1215 StopReason GetStopReason() const override {
1217 }
1218
1219 const char *GetDescription() override {
1220 if (m_description.empty()) {
1221 m_description = "async interrupt";
1222 }
1223 return m_description.c_str();
1224 }
1225
1226 uint32_t GetStopReasonDataCount() const override { return 1; }
1227 uint64_t GetStopReasonDataAtIndex(uint32_t idx) override {
1228 if (idx == 0)
1229 return GetValue();
1230 else
1231 return 0;
1232 }
1233};
1234
1235// StopInfoTrace
1236
1237class StopInfoTrace : public StopInfo {
1238public:
1240
1241 ~StopInfoTrace() override = default;
1242
1243 StopReason GetStopReason() const override { return eStopReasonTrace; }
1244
1245 const char *GetDescription() override {
1246 if (m_description.empty())
1247 return "trace";
1248 else
1249 return m_description.c_str();
1250 }
1251
1252 std::optional<uint32_t>
1253 GetSuggestedStackFrameIndex(bool inlined_stack) override {
1254 // Trace only knows how to adjust inlined stacks:
1255 if (!inlined_stack)
1256 return {};
1257
1258 ThreadSP thread_sp = GetThread();
1259 StackFrameSP frame_0_sp = thread_sp->GetStackFrameAtIndex(0);
1260 if (!frame_0_sp)
1261 return {};
1262 if (!frame_0_sp->IsInlined())
1263 return {};
1264 Block *block_ptr = frame_0_sp->GetFrameBlock();
1265 if (!block_ptr)
1266 return {};
1267 Address pc_address = frame_0_sp->GetFrameCodeAddress();
1268 AddressRange containing_range;
1269 if (!block_ptr->GetRangeContainingAddress(pc_address, containing_range) ||
1270 pc_address != containing_range.GetBaseAddress())
1271 return {};
1272
1273 int num_inlined_functions = 0;
1274
1275 for (Block *container_ptr = block_ptr->GetInlinedParent();
1276 container_ptr != nullptr;
1277 container_ptr = container_ptr->GetInlinedParent()) {
1278 if (!container_ptr->GetRangeContainingAddress(pc_address,
1279 containing_range))
1280 break;
1281 if (pc_address != containing_range.GetBaseAddress())
1282 break;
1283
1284 num_inlined_functions++;
1285 }
1286 inlined_stack = true;
1287 return num_inlined_functions + 1;
1288 }
1289};
1290
1291// StopInfoException
1292
1294public:
1295 StopInfoException(Thread &thread, const char *description)
1296 : StopInfo(thread, LLDB_INVALID_UID) {
1297 if (description)
1298 SetDescription(description);
1299 }
1300
1301 ~StopInfoException() override = default;
1302
1303 StopReason GetStopReason() const override { return eStopReasonException; }
1304
1305 const char *GetDescription() override {
1306 if (m_description.empty())
1307 return "exception";
1308 else
1309 return m_description.c_str();
1310 }
1311 uint32_t GetStopReasonDataCount() const override { return 1; }
1312 uint64_t GetStopReasonDataAtIndex(uint32_t idx) override {
1313 if (idx == 0)
1314 return GetValue();
1315 else
1316 return 0;
1317 }
1318};
1319
1320// StopInfoProcessorTrace
1321
1323public:
1324 StopInfoProcessorTrace(Thread &thread, const char *description)
1325 : StopInfo(thread, LLDB_INVALID_UID) {
1326 if (description)
1327 SetDescription(description);
1328 }
1329
1330 ~StopInfoProcessorTrace() override = default;
1331
1332 StopReason GetStopReason() const override {
1334 }
1335
1336 const char *GetDescription() override {
1337 if (m_description.empty())
1338 return "processor trace event";
1339 else
1340 return m_description.c_str();
1341 }
1342};
1343
1344// StopInfoHistoryBoundary
1345
1347public:
1348 StopInfoHistoryBoundary(Thread &thread, const char *description)
1349 : StopInfo(thread, LLDB_INVALID_UID) {
1350 if (description)
1351 SetDescription(description);
1352 }
1353
1354 ~StopInfoHistoryBoundary() override = default;
1355
1356 StopReason GetStopReason() const override {
1358 }
1359
1360 const char *GetDescription() override {
1361 if (m_description.empty())
1362 return "history boundary";
1363 return m_description.c_str();
1364 }
1365};
1366
1367// StopInfoThreadPlan
1368
1370public:
1371 StopInfoThreadPlan(ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp,
1372 ExpressionVariableSP &expression_variable_sp)
1373 : StopInfo(plan_sp->GetThread(), LLDB_INVALID_UID), m_plan_sp(plan_sp),
1374 m_return_valobj_sp(return_valobj_sp),
1375 m_expression_variable_sp(expression_variable_sp) {}
1376
1377 ~StopInfoThreadPlan() override = default;
1378
1380
1381 const char *GetDescription() override {
1382 if (m_description.empty()) {
1383 StreamString strm;
1384 m_plan_sp->GetDescription(&strm, eDescriptionLevelBrief);
1385 m_description = std::string(strm.GetString());
1386 }
1387 return m_description.c_str();
1388 }
1389
1391
1395
1396protected:
1397 bool ShouldStop(Event *event_ptr) override {
1398 if (m_plan_sp)
1399 return m_plan_sp->ShouldStop(event_ptr);
1400 else
1401 return StopInfo::ShouldStop(event_ptr);
1402 }
1403
1404private:
1408};
1409
1410// StopInfoExec
1411
1412class StopInfoExec : public StopInfo {
1413public:
1415
1416 ~StopInfoExec() override = default;
1417
1418 bool ShouldStop(Event *event_ptr) override {
1419 ThreadSP thread_sp(m_thread_wp.lock());
1420 if (thread_sp)
1421 return thread_sp->GetProcess()->GetStopOnExec();
1422 return false;
1423 }
1424
1425 StopReason GetStopReason() const override { return eStopReasonExec; }
1426
1427 const char *GetDescription() override { return "exec"; }
1428
1429protected:
1430 void PerformAction(Event *event_ptr) override {
1431 // Only perform the action once
1433 return;
1434 m_performed_action = true;
1435 ThreadSP thread_sp(m_thread_wp.lock());
1436 if (thread_sp)
1437 thread_sp->GetProcess()->DidExec();
1438 }
1439
1441};
1442
1443// StopInfoFork
1444
1445class StopInfoFork : public StopInfo {
1446public:
1447 StopInfoFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
1448 : StopInfo(thread, child_pid), m_child_pid(child_pid),
1449 m_child_tid(child_tid) {}
1450
1451 ~StopInfoFork() override = default;
1452
1453 bool ShouldStop(Event *event_ptr) override { return false; }
1454
1455 StopReason GetStopReason() const override { return eStopReasonFork; }
1456
1457 const char *GetDescription() override { return "fork"; }
1458
1459 uint32_t GetStopReasonDataCount() const override { return 1; }
1460 uint64_t GetStopReasonDataAtIndex(uint32_t idx) override {
1461 if (idx == 0)
1462 return GetValue();
1463 else
1464 return 0;
1465 }
1466
1467protected:
1468 void PerformAction(Event *event_ptr) override {
1469 // Only perform the action once
1471 return;
1472 m_performed_action = true;
1473 ThreadSP thread_sp(m_thread_wp.lock());
1474 if (thread_sp)
1475 thread_sp->GetProcess()->DidFork(m_child_pid, m_child_tid);
1476 }
1477
1479
1480private:
1483};
1484
1485// StopInfoVFork
1486
1487class StopInfoVFork : public StopInfo {
1488public:
1489 StopInfoVFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
1490 : StopInfo(thread, child_pid), m_child_pid(child_pid),
1491 m_child_tid(child_tid) {}
1492
1493 ~StopInfoVFork() override = default;
1494
1495 bool ShouldStop(Event *event_ptr) override { return false; }
1496
1497 StopReason GetStopReason() const override { return eStopReasonVFork; }
1498
1499 const char *GetDescription() override { return "vfork"; }
1500
1501 uint32_t GetStopReasonDataCount() const override { return 1; }
1502 uint64_t GetStopReasonDataAtIndex(uint32_t idx) override {
1503 if (idx == 0)
1504 return GetValue();
1505 return 0;
1506 }
1507
1508protected:
1509 void PerformAction(Event *event_ptr) override {
1510 // Only perform the action once
1512 return;
1513 m_performed_action = true;
1514 ThreadSP thread_sp(m_thread_wp.lock());
1515 if (thread_sp)
1516 thread_sp->GetProcess()->DidVFork(m_child_pid, m_child_tid);
1517 }
1518
1520
1521private:
1524};
1525
1526// StopInfoVForkDone
1527
1529public:
1530 StopInfoVForkDone(Thread &thread) : StopInfo(thread, 0) {}
1531
1532 ~StopInfoVForkDone() override = default;
1533
1534 bool ShouldStop(Event *event_ptr) override { return false; }
1535
1536 StopReason GetStopReason() const override { return eStopReasonVForkDone; }
1537
1538 const char *GetDescription() override { return "vforkdone"; }
1539
1540protected:
1541 void PerformAction(Event *event_ptr) override {
1542 // Only perform the action once
1544 return;
1545 m_performed_action = true;
1546 ThreadSP thread_sp(m_thread_wp.lock());
1547 if (thread_sp)
1548 thread_sp->GetProcess()->DidVForkDone();
1549 }
1550
1552};
1553
1554} // namespace lldb_private
1555
1557 break_id_t break_id) {
1558 thread.SetThreadHitBreakpointSite();
1559
1560 return std::make_shared<StopInfoBreakpoint>(thread, break_id);
1561}
1562
1564 break_id_t break_id,
1565 bool should_stop) {
1566 return std::make_shared<StopInfoBreakpoint>(thread, break_id, should_stop);
1567}
1568
1569// LWP_TODO: We'll need a CreateStopReasonWithWatchpointResourceID akin
1570// to CreateStopReasonWithBreakpointSiteID
1572 break_id_t watch_id,
1573 bool silently_continue) {
1574 return std::make_shared<StopInfoWatchpoint>(thread, watch_id,
1575 silently_continue);
1576}
1577
1579 const char *description,
1580 std::optional<int> code) {
1581 thread.GetProcess()->GetUnixSignals()->IncrementSignalHitCount(signo);
1582 return std::make_shared<StopInfoUnixSignal>(thread, signo, description, code);
1583}
1584
1586 const char *description) {
1587 return std::make_shared<StopInfoInterrupt>(thread, signo, description);
1588}
1589
1591 return std::make_shared<StopInfoTrace>(thread);
1592}
1593
1595 ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp,
1596 ExpressionVariableSP expression_variable_sp) {
1597 return std::make_shared<StopInfoThreadPlan>(plan_sp, return_valobj_sp,
1598 expression_variable_sp);
1599}
1600
1602 const char *description) {
1603 return std::make_shared<StopInfoException>(thread, description);
1604}
1605
1607 const char *description) {
1608 return std::make_shared<StopInfoProcessorTrace>(thread, description);
1609}
1610
1612 const char *description) {
1613 return std::make_shared<StopInfoHistoryBoundary>(thread, description);
1614}
1615
1617 return std::make_shared<StopInfoExec>(thread);
1618}
1619
1621 lldb::pid_t child_pid,
1622 lldb::tid_t child_tid) {
1623 return std::make_shared<StopInfoFork>(thread, child_pid, child_tid);
1624}
1625
1626
1628 lldb::pid_t child_pid,
1629 lldb::tid_t child_tid) {
1630 return std::make_shared<StopInfoVFork>(thread, child_pid, child_tid);
1631}
1632
1634 return std::make_shared<StopInfoVForkDone>(thread);
1635}
1636
1638 if (stop_info_sp &&
1639 stop_info_sp->GetStopReason() == eStopReasonPlanComplete) {
1640 StopInfoThreadPlan *plan_stop_info =
1641 static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1642 return plan_stop_info->GetReturnValueObject();
1643 } else
1644 return ValueObjectSP();
1645}
1646
1648 if (stop_info_sp &&
1649 stop_info_sp->GetStopReason() == eStopReasonPlanComplete) {
1650 StopInfoThreadPlan *plan_stop_info =
1651 static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1652 return plan_stop_info->GetExpressionVariable();
1653 } else
1654 return ExpressionVariableSP();
1655}
1656
1659 lldb::addr_t *crashing_address) {
1660 if (!stop_info_sp) {
1661 return ValueObjectSP();
1662 }
1663
1664 const char *description = stop_info_sp->GetDescription();
1665 if (!description) {
1666 return ValueObjectSP();
1667 }
1668
1669 ThreadSP thread_sp = stop_info_sp->GetThread();
1670 if (!thread_sp) {
1671 return ValueObjectSP();
1672 }
1673
1674 StackFrameSP frame_sp =
1675 thread_sp->GetSelectedFrame(DoNoSelectMostRelevantFrame);
1676
1677 if (!frame_sp) {
1678 return ValueObjectSP();
1679 }
1680
1681 const char address_string[] = "address=";
1682
1683 const char *address_loc = strstr(description, address_string);
1684 if (!address_loc) {
1685 return ValueObjectSP();
1686 }
1687
1688 address_loc += (sizeof(address_string) - 1);
1689
1690 uint64_t address = strtoull(address_loc, nullptr, 0);
1691 if (crashing_address) {
1692 *crashing_address = address;
1693 }
1694
1695 return frame_sp->GuessValueForAddress(address);
1696}
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:369
#define LLDB_LOGF(log,...)
Definition Log.h:376
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
A section + offset based address class.
Definition Address.h:62
A class that describes a single lexical block.
Definition Block.h:41
bool GetRangeContainingAddress(const Address &addr, AddressRange &range)
Definition Block.cpp:248
Block * GetInlinedParent()
Get the inlined parent block for this block.
Definition Block.cpp:212
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.
bool IsInternal() const
Tell whether this breakpoint is an "internal" breakpoint.
A class to manage flag bits.
Definition Debugger.h:80
void SetAsyncExecution(bool async)
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
lldb::StreamUP GetAsyncOutputStream()
void SetUnwindOnError(bool unwind=false)
Definition Target.h:371
void SetIgnoreBreakpoints(bool ignore=false)
Definition Target.h:375
"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 IsRunningExpression() const
Definition Process.h:282
bool GetIgnoreBreakpointsInExpressions() const
Definition Process.cpp:241
static void AddRestartedReason(Event *event_ptr, const char *reason)
Definition Process.cpp:4457
A plug-in interface definition class for debugging a process.
Definition Process.h:357
const ProcessModID & GetModIDRef() const
Definition Process.h:1473
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1270
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition Scalar.cpp:365
An error handling class.
Definition Status.h:118
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:195
bool Success() const
Test for success condition.
Definition Status.cpp:304
void PerformAction(Event *event_ptr) override
Definition StopInfo.cpp:303
BreakpointSiteSP GetBreakpointSiteSP() const
Definition StopInfo.cpp:655
std::optional< uint32_t > GetSuggestedStackFrameIndex(bool inlined_stack) override
This gives the StopInfo a chance to suggest a stack frame to select.
Definition StopInfo.cpp:276
const char * GetDescription() override
Definition StopInfo.cpp:182
bool ShouldStopSynchronous(Event *event_ptr) override
Definition StopInfo.cpp:150
bool IsValidForOperatingSystemThread(Thread &thread) override
Definition StopInfo.cpp:138
bool DoShouldNotify(Event *event_ptr) override
Definition StopInfo.cpp:178
bool ShouldShow() const override
Returns true if this is a stop reason that should be shown to a user when viewing the thread with thi...
Definition StopInfo.cpp:290
uint32_t GetStopReasonDataCount() const override
Definition StopInfo.cpp:246
~StopInfoBreakpoint() override=default
bool ShouldSelect() const override
Returns true if this is a stop reason that should cause a thread to be selected when stopping.
Definition StopInfo.cpp:292
StopInfoBreakpoint(Thread &thread, break_id_t break_id, bool should_stop)
Definition StopInfo.cpp:98
StopInfoBreakpoint(Thread &thread, break_id_t break_id)
Definition StopInfo.cpp:90
bool ShouldStop(Event *event_ptr) override
Definition StopInfo.cpp:295
uint64_t GetStopReasonDataAtIndex(uint32_t idx) override
Definition StopInfo.cpp:253
StopReason GetStopReason() const override
Definition StopInfo.cpp:148
uint64_t GetStopReasonDataAtIndex(uint32_t idx) override
const char * GetDescription() override
uint32_t GetStopReasonDataCount() const override
~StopInfoException() override=default
StopInfoException(Thread &thread, const char *description)
StopReason GetStopReason() const override
~StopInfoExec() override=default
StopInfoExec(Thread &thread)
const char * GetDescription() override
StopReason GetStopReason() const override
void PerformAction(Event *event_ptr) override
bool ShouldStop(Event *event_ptr) override
uint32_t GetStopReasonDataCount() const override
void PerformAction(Event *event_ptr) override
bool ShouldStop(Event *event_ptr) override
StopReason GetStopReason() const override
uint64_t GetStopReasonDataAtIndex(uint32_t idx) override
StopInfoFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
~StopInfoFork() override=default
const char * GetDescription() override
StopReason GetStopReason() const override
const char * GetDescription() override
~StopInfoHistoryBoundary() override=default
StopInfoHistoryBoundary(Thread &thread, const char *description)
uint32_t GetStopReasonDataCount() const override
StopInfoInterrupt(Thread &thread, int signo, const char *description)
const char * GetDescription() override
StopReason GetStopReason() const override
uint64_t GetStopReasonDataAtIndex(uint32_t idx) override
~StopInfoInterrupt() override=default
StopInfoProcessorTrace(Thread &thread, const char *description)
~StopInfoProcessorTrace() override=default
const char * GetDescription() override
StopReason GetStopReason() const override
bool ShouldStop(Event *event_ptr) override
~StopInfoThreadPlan() override=default
ExpressionVariableSP m_expression_variable_sp
ExpressionVariableSP GetExpressionVariable()
const char * GetDescription() override
StopReason GetStopReason() const override
StopInfoThreadPlan(ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp, ExpressionVariableSP &expression_variable_sp)
const char * GetDescription() override
~StopInfoTrace() override=default
StopReason GetStopReason() const override
StopInfoTrace(Thread &thread)
std::optional< uint32_t > GetSuggestedStackFrameIndex(bool inlined_stack) override
This gives the StopInfo a chance to suggest a stack frame to select.
StopInfoUnixSignal(Thread &thread, int signo, const char *description, std::optional< int > code)
void WillResume(lldb::StateType resume_state) override
bool DoShouldNotify(Event *event_ptr) override
~StopInfoUnixSignal() override=default
const char * GetDescription() override
std::optional< int > m_code
bool ShouldStopSynchronous(Event *event_ptr) override
uint32_t GetStopReasonDataCount() const override
bool ShouldStop(Event *event_ptr) override
StopReason GetStopReason() const override
uint64_t GetStopReasonDataAtIndex(uint32_t idx) override
bool ShouldSelect() const override
Returns true if this is a stop reason that should cause a thread to be selected when stopping.
const char * GetDescription() override
~StopInfoVForkDone() override=default
bool ShouldStop(Event *event_ptr) override
StopReason GetStopReason() const override
void PerformAction(Event *event_ptr) override
bool ShouldStop(Event *event_ptr) override
uint64_t GetStopReasonDataAtIndex(uint32_t idx) override
StopReason GetStopReason() const override
void PerformAction(Event *event_ptr) override
~StopInfoVFork() override=default
StopInfoVFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
const char * GetDescription() override
uint32_t GetStopReasonDataCount() const override
ThreadPlanStepOverWatchpoint(Thread &thread, StopInfoWatchpointSP stop_info_sp, WatchpointSP watch_sp)
Definition StopInfo.cpp:765
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override
Definition StopInfo.cpp:774
WatchpointSentry(ProcessSP p_sp, WatchpointSP w_sp)
Definition StopInfo.cpp:692
static bool SentryPreResumeAction(void *sentry_void)
Definition StopInfo.cpp:721
~StopInfoWatchpoint() override=default
std::shared_ptr< StopInfoWatchpoint > StopInfoWatchpointSP
Definition StopInfo.cpp:756
StopInfoWatchpoint(Thread &thread, break_id_t watch_id, bool silently_skip_wp)
Definition StopInfo.cpp:732
uint32_t GetStopReasonDataCount() const override
Definition StopInfo.cpp:739
const char * GetDescription() override
Definition StopInfo.cpp:746
void PerformAction(Event *event_ptr) override
Definition StopInfo.cpp:940
bool ShouldStop(Event *event_ptr) override
Definition StopInfo.cpp:932
bool ShouldStopSynchronous(Event *event_ptr) override
Definition StopInfo.cpp:833
uint64_t GetStopReasonDataAtIndex(uint32_t idx) override
Definition StopInfo.cpp:740
StopReason GetStopReason() const override
Definition StopInfo.cpp:737
std::string m_description
Definition StopInfo.h:227
static lldb::StopInfoSP CreateStopReasonWithPlan(lldb::ThreadPlanSP &plan, lldb::ValueObjectSP return_valobj_sp, lldb::ExpressionVariableSP expression_variable_sp)
uint64_t GetValue() const
Definition StopInfo.h:46
static lldb::ExpressionVariableSP GetExpressionVariable(lldb::StopInfoSP &stop_info_sp)
static lldb::ValueObjectSP GetReturnValueObject(lldb::StopInfoSP &stop_info_sp)
static lldb::StopInfoSP CreateStopReasonToTrace(Thread &thread)
static lldb::StopInfoSP CreateStopReasonVFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
static lldb::StopInfoSP CreateStopReasonWithInterrupt(Thread &thread, int signo, const char *description)
bool IsValid() const
Definition StopInfo.cpp:41
StructuredData::ObjectSP m_extended_info
Definition StopInfo.h:232
static lldb::StopInfoSP CreateStopReasonWithSignal(Thread &thread, int signo, const char *description=nullptr, std::optional< int > code=std::nullopt)
lldb::ThreadSP GetThread() const
Definition StopInfo.h:35
static lldb::StopInfoSP CreateStopReasonFork(Thread &thread, lldb::pid_t child_pid, lldb::tid_t child_tid)
static lldb::StopInfoSP CreateStopReasonVForkDone(Thread &thread)
static lldb::StopInfoSP CreateStopReasonWithWatchpointID(Thread &thread, lldb::break_id_t watch_id, bool silently_continue=false)
virtual void SetDescription(const char *desc_cstr)
Definition StopInfo.h:74
static lldb::StopInfoSP CreateStopReasonWithException(Thread &thread, const char *description)
static lldb::StopInfoSP CreateStopReasonWithBreakpointSiteID(Thread &thread, lldb::break_id_t break_id)
static lldb::StopInfoSP CreateStopReasonHistoryBoundary(Thread &thread, const char *description)
static lldb::ValueObjectSP GetCrashingDereference(lldb::StopInfoSP &stop_info_sp, lldb::addr_t *crashing_address=nullptr)
LazyBool m_override_should_notify
Definition StopInfo.h:228
static lldb::StopInfoSP CreateStopReasonProcessorTrace(Thread &thread, const char *description)
static lldb::StopInfoSP CreateStopReasonWithExec(Thread &thread)
friend class Thread
Definition StopInfo.h:245
StopInfo(Thread &thread, uint64_t value)
Definition StopInfo.cpp:34
lldb::ThreadWP m_thread_wp
Definition StopInfo.h:222
LazyBool m_override_should_stop
Definition StopInfo.h:229
virtual bool ShouldStop(Event *event_ptr)
Definition StopInfo.h:219
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
llvm::StringRef GetString() const
void Format(const char *format, Args &&... args)
Definition Stream.h:352
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
Debugger & GetDebugger() const
Definition Target.h:1097
bool DoPlanExplainsStop(Event *event_ptr) override
ThreadPlanStepInstruction(Thread &thread, bool step_over, bool stop_others, Vote report_stop_vote, Vote report_run_vote)
Thread & GetThread()
Returns the Thread that is using this thread plan.
virtual lldb::StopInfoSP GetPrivateStopInfo(bool calculate=true)
Definition Thread.cpp:386
void SetStopInfo(const lldb::StopInfoSP &stop_info_sp)
Definition Thread.cpp:464
lldb::ProcessSP GetProcess() const
Definition Thread.h:158
static lldb::ExpressionResults Evaluate(ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, llvm::StringRef expr_cstr, llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp, 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
#define LLDB_INVALID_UID
#define LLDB_INVALID_ADDRESS
@ DoNoSelectMostRelevantFrame
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
@ eDescriptionLevelBrief
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
std::shared_ptr< lldb_private::UnixSignals > UnixSignalsSP
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.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
ExpressionResults
The results of expression evaluation.
@ eExpressionCompleted
int32_t break_id_t
Definition lldb-types.h:86
std::shared_ptr< lldb_private::Process > ProcessSP
uint64_t pid_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
uint64_t addr_t
Definition lldb-types.h:80
StopReason
Thread stop reasons.
@ eStopReasonPlanComplete
@ eStopReasonHistoryBoundary
@ eStopReasonBreakpoint
@ eStopReasonExec
Program was re-exec'ed.
@ eStopReasonVForkDone
@ eStopReasonInterrupt
Thread requested interrupt.
@ eStopReasonProcessorTrace
@ eStopReasonException
@ eStopReasonWatchpoint
std::unique_ptr< lldb_private::Stream > StreamUP
uint64_t tid_t
Definition lldb-types.h:84
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47