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