File: ThreadPlanStepThroughGenericTrampoline.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (137 lines) | stat: -rw-r--r-- 4,178 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//===-- ThreadPlanStepThroughGenericTrampoline.cpp
//-----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/Target/ThreadPlanStepThroughGenericTrampoline.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Stream.h"

using namespace lldb;
using namespace lldb_private;

uint32_t ThreadPlanStepThroughGenericTrampoline::s_default_flag_values =
    ThreadPlanShouldStopHere::eStepInAvoidNoDebug;

ThreadPlanStepThroughGenericTrampoline::ThreadPlanStepThroughGenericTrampoline(
    Thread &thread, lldb::RunMode stop_others)
    : ThreadPlanStepRange(ThreadPlan::eKindStepThroughGenericTrampoline,
                          "Step through generic trampoline", thread, {}, {},
                          stop_others),
      ThreadPlanShouldStopHere(this) {

  SetFlagsToDefault();
  auto frame = GetThread().GetFrameWithStackID(m_stack_id);
  if (!frame)
    return;
  SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction);

  if (!sc.function)
    return;
  AddRange(sc.function->GetAddressRange());
}

ThreadPlanStepThroughGenericTrampoline::
    ~ThreadPlanStepThroughGenericTrampoline() = default;

void ThreadPlanStepThroughGenericTrampoline::GetDescription(
    Stream *s, lldb::DescriptionLevel level) {

  auto PrintFailureIfAny = [&]() {
    if (m_status.Success())
      return;
    s->Printf(" failed (%s)", m_status.AsCString());
  };

  if (level == lldb::eDescriptionLevelBrief) {
    s->Printf("step through generic trampoline");
    PrintFailureIfAny();
    return;
  }

  auto frame = GetThread().GetFrameWithStackID(m_stack_id);
  if (!frame) {
    s->Printf("<error, frame not available>");
    return;
  }

  SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction);
  if (!sc.function) {
    s->Printf("<error, function not available>");
    return;
  }

  s->Printf("Stepping through generic trampoline %s",
            sc.function->GetName().AsCString());

  lldb::StackFrameSP curr_frame = GetThread().GetStackFrameAtIndex(0);
  if (!curr_frame)
    return;

  SymbolContext curr_frame_sc =
      curr_frame->GetSymbolContext(eSymbolContextFunction);
  if (!curr_frame_sc.function)
    return;
  s->Printf(", current function: %s",
            curr_frame_sc.function->GetName().GetCString());

  PrintFailureIfAny();

  s->PutChar('.');
}

bool ThreadPlanStepThroughGenericTrampoline::ShouldStop(Event *event_ptr) {
  Log *log = GetLog(LLDBLog::Step);

  if (log) {
    StreamString s;
    DumpAddress(s.AsRawOstream(), GetThread().GetRegisterContext()->GetPC(),
                GetTarget().GetArchitecture().GetAddressByteSize());
    LLDB_LOGF(log, "ThreadPlanStepThroughGenericTrampoline reached %s.",
              s.GetData());
  }

  if (IsPlanComplete())
    return true;

  m_no_more_plans = false;

  Thread &thread = GetThread();
  lldb::StackFrameSP curr_frame = thread.GetStackFrameAtIndex(0);
  if (!curr_frame)
    return false;

  SymbolContext sc = curr_frame->GetSymbolContext(eSymbolContextFunction);

  if (sc.function && sc.function->IsGenericTrampoline() &&
      SetNextBranchBreakpoint()) {
    // While whatever frame we're in is a generic trampoline,
    // continue stepping to the next branch, until we
    // end up in a function which isn't a trampoline.
    return false;
  }

  m_no_more_plans = true;
  SetPlanComplete();
  return true;
}

bool ThreadPlanStepThroughGenericTrampoline::ValidatePlan(Stream *error) {
  // If trampoline support is disabled, there's nothing for us to do.
  if (!Target::GetGlobalProperties().GetEnableTrampolineSupport())
    return false;

  auto frame = GetThread().GetFrameWithStackID(m_stack_id);
  if (!frame)
    return false;

  SymbolContext sc = frame->GetSymbolContext(eSymbolContextFunction);
  return sc.function && sc.function->IsGenericTrampoline();
}