Skip to content

Commit ef8b00c

Browse files
committed
[lldb/Target] Add BorrowedStackFrame and make StackFrame methods virtual
This change makes StackFrame methods virtual to enable subclass overrides and introduces BorrowedStackFrame, a wrapper that presents an existing StackFrame with a different frame index. This enables creating synthetic frame views or renumbering frames without copying the underlying frame data, which is useful for frame manipulation scenarios. This also adds a new borrowed-info format entity to show what was the original frame index of the borrowed frame. Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 9324dae commit ef8b00c

File tree

9 files changed

+391
-35
lines changed

9 files changed

+391
-35
lines changed

lldb/include/lldb/Core/FormatEntity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct Entry {
8181
FrameRegisterByName,
8282
FrameIsArtificial,
8383
FrameKind,
84+
FrameBorrowedInfo,
8485
ScriptFrame,
8586
FunctionID,
8687
FunctionDidChange,
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
//===----------------------------------------------------------------------===//
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+
#ifndef LLDB_TARGET_BORROWEDSTACKFRAME_H
10+
#define LLDB_TARGET_BORROWEDSTACKFRAME_H
11+
12+
#include "lldb/Target/StackFrame.h"
13+
14+
namespace lldb_private {
15+
16+
/// \class BorrowedStackFrame BorrowedStackFrame.h
17+
/// "lldb/Target/BorrowedStackFrame.h"
18+
///
19+
/// A wrapper around an existing StackFrame that supersedes its frame index.
20+
///
21+
/// This class is useful when you need to present an existing stack frame
22+
/// with a different index, such as when creating synthetic frame views or
23+
/// renumbering frames without copying all the underlying data.
24+
///
25+
/// All methods delegate to the borrowed frame except for GetFrameIndex()
26+
/// which uses the overridden index.
27+
class BorrowedStackFrame : public StackFrame {
28+
public:
29+
/// Construct a BorrowedStackFrame that wraps an existing frame.
30+
///
31+
/// \param [in] borrowed_frame_sp
32+
/// The existing StackFrame to borrow from. This frame's data will be
33+
/// used for all operations except frame index queries.
34+
///
35+
/// \param [in] override_frame_index
36+
/// The frame index to report instead of the borrowed frame's index.
37+
BorrowedStackFrame(lldb::StackFrameSP borrowed_frame_sp,
38+
uint32_t new_frame_index);
39+
40+
~BorrowedStackFrame() override = default;
41+
42+
uint32_t GetFrameIndex() const override;
43+
void SetFrameIndex(uint32_t index);
44+
45+
uint32_t GetConcreteFrameIndex() const override;
46+
47+
StackID &GetStackID() override;
48+
49+
const Address &GetFrameCodeAddress() override;
50+
51+
Address GetFrameCodeAddressForSymbolication() override;
52+
53+
bool ChangePC(lldb::addr_t pc) override;
54+
55+
const SymbolContext &
56+
GetSymbolContext(lldb::SymbolContextItem resolve_scope) override;
57+
58+
llvm::Error GetFrameBaseValue(Scalar &value) override;
59+
60+
DWARFExpressionList *GetFrameBaseExpression(Status *error_ptr) override;
61+
62+
Block *GetFrameBlock() override;
63+
64+
lldb::RegisterContextSP GetRegisterContext() override;
65+
66+
VariableList *GetVariableList(bool get_file_globals,
67+
Status *error_ptr) override;
68+
69+
lldb::VariableListSP
70+
GetInScopeVariableList(bool get_file_globals,
71+
bool must_have_valid_location = false) override;
72+
73+
lldb::ValueObjectSP GetValueForVariableExpressionPath(
74+
llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic,
75+
uint32_t options, lldb::VariableSP &var_sp, Status &error) override;
76+
77+
bool HasDebugInformation() override;
78+
79+
const char *Disassemble() override;
80+
81+
lldb::ValueObjectSP
82+
GetValueObjectForFrameVariable(const lldb::VariableSP &variable_sp,
83+
lldb::DynamicValueType use_dynamic) override;
84+
85+
bool IsInlined() override;
86+
87+
bool IsSynthetic() const override;
88+
89+
bool IsHistorical() const override;
90+
91+
bool IsArtificial() const override;
92+
93+
bool IsHidden() override;
94+
95+
const char *GetFunctionName() override;
96+
97+
const char *GetDisplayFunctionName() override;
98+
99+
lldb::ValueObjectSP FindVariable(ConstString name) override;
100+
101+
SourceLanguage GetLanguage() override;
102+
103+
SourceLanguage GuessLanguage() override;
104+
105+
lldb::ValueObjectSP GuessValueForAddress(lldb::addr_t addr) override;
106+
107+
lldb::ValueObjectSP GuessValueForRegisterAndOffset(ConstString reg,
108+
int64_t offset) override;
109+
110+
StructuredData::ObjectSP GetLanguageSpecificData() override;
111+
112+
lldb::RecognizedStackFrameSP GetRecognizedFrame() override;
113+
114+
/// Get the underlying borrowed frame.
115+
lldb::StackFrameSP GetBorrowedFrame() const;
116+
117+
bool isA(const void *ClassID) const override;
118+
static bool classof(const StackFrame *obj);
119+
120+
private:
121+
lldb::StackFrameSP m_borrowed_frame_sp;
122+
uint32_t m_new_frame_index;
123+
static char ID;
124+
125+
BorrowedStackFrame(const BorrowedStackFrame &) = delete;
126+
const BorrowedStackFrame &operator=(const BorrowedStackFrame &) = delete;
127+
};
128+
129+
} // namespace lldb_private
130+
131+
#endif // LLDB_TARGET_BORROWEDSTACKFRAME_H

0 commit comments

Comments
 (0)