@@ -49,14 +49,16 @@ static constexpr int StackPageSize = 20;
49
49
//
50
50
// s=3,l=3 = [th0->s3, label1, th1->s0]
51
51
static bool FillStackFrames (DAP &dap, lldb::SBThread &thread,
52
+ lldb::SBFormat &frame_format,
52
53
llvm::json::Array &stack_frames, int64_t &offset,
53
- const int64_t start_frame, const int64_t levels) {
54
+ const int64_t start_frame, const int64_t levels,
55
+ const bool include_all) {
54
56
bool reached_end_of_stack = false ;
55
57
for (int64_t i = start_frame;
56
58
static_cast <int64_t >(stack_frames.size ()) < levels; i++) {
57
59
if (i == -1 ) {
58
60
stack_frames.emplace_back (
59
- CreateExtendedStackFrameLabel (thread, dap. frame_format ));
61
+ CreateExtendedStackFrameLabel (thread, frame_format));
60
62
continue ;
61
63
}
62
64
@@ -67,10 +69,10 @@ static bool FillStackFrames(DAP &dap, lldb::SBThread &thread,
67
69
break ;
68
70
}
69
71
70
- stack_frames.emplace_back (CreateStackFrame (frame, dap. frame_format ));
72
+ stack_frames.emplace_back (CreateStackFrame (frame, frame_format));
71
73
}
72
74
73
- if (dap. configuration . displayExtendedBacktrace && reached_end_of_stack) {
75
+ if (include_all && reached_end_of_stack) {
74
76
// Check for any extended backtraces.
75
77
for (uint32_t bt = 0 ;
76
78
bt < thread.GetProcess ().GetNumExtendedBacktraceTypes (); bt++) {
@@ -80,8 +82,9 @@ static bool FillStackFrames(DAP &dap, lldb::SBThread &thread,
80
82
continue ;
81
83
82
84
reached_end_of_stack = FillStackFrames (
83
- dap, backtrace, stack_frames, offset,
84
- (start_frame - offset) > 0 ? start_frame - offset : -1 , levels);
85
+ dap, backtrace, frame_format, stack_frames, offset,
86
+ (start_frame - offset) > 0 ? start_frame - offset : -1 , levels,
87
+ include_all);
85
88
if (static_cast <int64_t >(stack_frames.size ()) >= levels)
86
89
break ;
87
90
}
@@ -178,14 +181,54 @@ void StackTraceRequestHandler::operator()(
178
181
llvm::json::Array stack_frames;
179
182
llvm::json::Object body;
180
183
184
+ lldb::SBFormat frame_format = dap.frame_format ;
185
+ bool include_all = dap.configuration .displayExtendedBacktrace ;
186
+
187
+ if (const auto *format = arguments->getObject (" format" )) {
188
+ // Indicates that all stack frames should be included, even those the debug
189
+ // adapter might otherwise hide.
190
+ include_all = GetBoolean (format, " includeAll" ).value_or (false );
191
+
192
+ // Parse the properties that have a corresponding format string.
193
+ // FIXME: Support "parameterTypes" and "hex".
194
+ const bool module = GetBoolean (format, " module" ).value_or (false );
195
+ const bool line = GetBoolean (format, " line" ).value_or (false );
196
+ const bool parameters = GetBoolean (format, " parameters" ).value_or (false );
197
+ const bool parameter_names =
198
+ GetBoolean (format, " parameterNames" ).value_or (false );
199
+ const bool parameter_values =
200
+ GetBoolean (format, " parameterValues" ).value_or (false );
201
+
202
+ // Only change the format string if we have to.
203
+ if (module || line || parameters || parameter_names || parameter_values) {
204
+ std::string format_str;
205
+ llvm::raw_string_ostream os (format_str);
206
+
207
+ if (module)
208
+ os << " {${module.file.basename} }" ;
209
+
210
+ if (line)
211
+ os << " {${line.file.basename}:${line.number}:${line.column} }" ;
212
+
213
+ if (parameters || parameter_names || parameter_values)
214
+ os << " {${function.name-with-args}}" ;
215
+ else
216
+ os << " {${function.name-without-args}}" ;
217
+
218
+ lldb::SBError error;
219
+ frame_format = lldb::SBFormat (format_str.c_str (), error);
220
+ assert (error.Success ());
221
+ }
222
+ }
223
+
181
224
if (thread.IsValid ()) {
182
225
const auto start_frame =
183
226
GetInteger<uint64_t >(arguments, " startFrame" ).value_or (0 );
184
227
const auto levels = GetInteger<uint64_t >(arguments, " levels" ).value_or (0 );
185
228
int64_t offset = 0 ;
186
- bool reached_end_of_stack =
187
- FillStackFrames ( dap, thread, stack_frames, offset, start_frame,
188
- levels == 0 ? INT64_MAX : levels);
229
+ bool reached_end_of_stack = FillStackFrames (
230
+ dap, thread, frame_format , stack_frames, offset, start_frame,
231
+ levels == 0 ? INT64_MAX : levels, include_all );
189
232
body.try_emplace (" totalFrames" ,
190
233
start_frame + stack_frames.size () +
191
234
(reached_end_of_stack ? 0 : StackPageSize));
0 commit comments