20from typing
import Optional
22from .frames
import dap_frame_generator
23from .modules
import module_id
24from .scopes
import symbol_value
25from .server
import request, capability
26from .sources
import make_source
27from .startup
import in_gdb_thread
28from .state
import set_thread
29from .typecheck
import type_check
30from .varref
import apply_format
35def _compute_parameters(frame, stack_format):
36 arg_iter = frame.frame_args()
42 name, val = symbol_value(arg, frame)
45 if stack_format[
"parameterTypes"]:
46 desc.append(
"[" + str(val.type) +
"]")
47 if stack_format[
"parameterNames"]:
51 if stack_format[
"parameterValues"]:
53 if stack_format[
"parameterValues"]:
54 desc.append(val.format_string(summary=
True))
55 result.append(
" ".join(desc))
56 return ", ".join(result)
61def _backtrace(thread_id, levels, startFrame, stack_format):
62 with apply_format(stack_format):
65 frame_iter = dap_frame_generator(startFrame, levels, stack_format[
"includeAll"])
66 for frame_id, current_frame
in frame_iter:
67 pc = current_frame.address()
70 name = current_frame.function()
73 if stack_format[
"parameters"]
and (
74 stack_format[
"parameterTypes"]
75 or stack_format[
"parameterNames"]
76 or stack_format[
"parameterValues"]
78 name +=
"(" + _compute_parameters(current_frame, stack_format) +
")"
86 "instructionPointerReference": hex(pc),
88 line = current_frame.line()
90 newframe[
"line"] = line
91 if stack_format[
"line"]:
92 name +=
", line " + str(line)
94 if objfile
is not None:
95 newframe[
"moduleId"] = module_id(objfile)
96 if stack_format[
"module"]:
97 name +=
", module " + objfile.username
98 filename = current_frame.filename()
99 if filename
is not None:
100 newframe[
"source"] = make_source(filename, os.path.basename(filename))
101 newframe[
"name"] = name
102 frames.append(newframe)
107 "stackFrames": frames,
115def check_stack_frame(
119 hex: Optional[bool] =
False,
120 parameters: Optional[bool] =
False,
121 parameterTypes: Optional[bool] =
False,
122 parameterNames: Optional[bool] =
False,
123 parameterValues: Optional[bool] =
False,
124 line: Optional[bool] =
False,
125 module: Optional[bool] =
False,
126 includeAll: Optional[bool] =
False,
131 "parameters": parameters,
132 "parameterTypes": parameterTypes,
133 "parameterNames": parameterNames,
134 "parameterValues": parameterValues,
137 "includeAll": includeAll,
141@request("stackTrace")
142@capability("supportsDelayedStackTraceLoading")
144 *, levels: int = 0, startFrame: int = 0, threadId: int, format=
None, **extra
149 format = check_stack_frame(**format)
150 return _backtrace(threadId, levels, startFrame, format)