@@ -7,7 +7,7 @@ module StackTraces
77
88
99import Base: hash, == , show
10- import Core: CodeInfo, MethodInstance
10+ import Core: CodeInfo, MethodInstance, CodeInstance
1111using Base. IRShow: normalize_method_name, append_scopes!, LineInfoNode
1212
1313export StackTrace, StackFrame, stacktrace
@@ -21,9 +21,9 @@ Stack information representing execution context, with the following fields:
2121
2222 The name of the function containing the execution context.
2323
24- - `linfo::Union{Method, Core.MethodInstance, Core.CodeInfo, Nothing}`
24+ - `linfo::Union{Method, Core.MethodInstance, Core.CodeInstance, Core. CodeInfo, Nothing}`
2525
26- The Method, MethodInstance, or CodeInfo containing the execution context (if it could be found), \
26+ The Method, MethodInstance, CodeInstance, or CodeInfo containing the execution context (if it could be found), \
2727 or nothing (for example, if the inlining was a result of macro expansion).
2828
2929- `file::Symbol`
@@ -54,9 +54,9 @@ struct StackFrame # this type should be kept platform-agnostic so that profiles
5454 file:: Symbol
5555 " the line number in the file containing the execution context"
5656 line:: Int
57- " the MethodInstance or CodeInfo containing the execution context (if it could be found), \
57+ " the CodeInstance or CodeInfo containing the execution context (if it could be found), \
5858 or nothing (for example, if the inlining was a result of macro expansion)."
59- linfo:: Union{MethodInstance, Method, CodeInfo, Nothing}
59+ linfo:: Union{Core. MethodInstance, Core.CodeInstance , Method, CodeInfo, Nothing}
6060 " true if the code is from C"
6161 from_c:: Bool
6262 " true if the code is from an inlined frame"
@@ -137,16 +137,26 @@ function lookup(ip::Base.InterpreterIP)
137137 line = meth. line
138138 codeinfo = meth. source
139139 else
140+ func = top_level_scope_sym
141+ file = empty_sym
142+ line = Int32 (0 )
140143 if code isa Core. CodeInstance
141144 codeinfo = code. inferred:: CodeInfo
145+ def = code. def
146+ if isa (def, Core. ABIOverride)
147+ def = def. def
148+ end
149+ if isa (def, MethodInstance) && isa (def. def, Method)
150+ meth = def. def
151+ func = meth. name
152+ file = meth. file
153+ line = meth. line
154+ end
142155 else
143156 codeinfo = code:: CodeInfo
144157 end
145- func = top_level_scope_sym
146- file = empty_sym
147- line = Int32 (0 )
148158 end
149- def = (code isa MethodInstance ? code : StackTraces ) # Module just used as a token for top-level code
159+ def = (code isa CodeInfo ? StackTraces : code ) # Module just used as a token for top-level code
150160 pc:: Int = max (ip. stmt + 1 , 0 ) # n.b. ip.stmt is 0-indexed
151161 scopes = LineInfoNode[]
152162 append_scopes! (scopes, pc, codeinfo. debuginfo, def)
@@ -157,7 +167,7 @@ function lookup(ip::Base.InterpreterIP)
157167 scopes = map (scopes) do lno
158168 if inlined
159169 def = lno. method
160- def isa Union{Method,MethodInstance} || (def = nothing )
170+ def isa Union{Method,Core . CodeInstance, MethodInstance} || (def = nothing )
161171 else
162172 def = codeinfo
163173 end
227237
228238is_top_level_frame (f:: StackFrame ) = f. linfo isa CodeInfo || (f. linfo === nothing && f. func === top_level_scope_sym)
229239
240+ function frame_method_or_module (lkup:: StackFrame )
241+ code = lkup. linfo
242+ code isa Method && return code
243+ code isa Module && return code
244+ mi = frame_mi (lkup)
245+ mi isa MethodInstance || return nothing
246+ return mi. def
247+ end
248+
249+ function frame_mi (lkup:: StackFrame )
250+ code = lkup. linfo
251+ code isa Core. CodeInstance && (code = code. def)
252+ code isa Core. ABIOverride && (code = code. def)
253+ code isa MethodInstance || return nothing
254+ return code
255+ end
256+
230257function show_spec_linfo (io:: IO , frame:: StackFrame )
231258 linfo = frame. linfo
232259 if linfo === nothing
@@ -241,16 +268,18 @@ function show_spec_linfo(io::IO, frame::StackFrame)
241268 print (io, " top-level scope" )
242269 elseif linfo isa Module
243270 Base. print_within_stacktrace (io, Base. demangle_function_name (string (frame. func)), bold= true )
244- elseif linfo isa MethodInstance
245- def = linfo. def
246- if def isa Module
247- Base. show_mi (io, linfo, #= from_stackframe=# true )
271+ else
272+ if linfo isa Union{MethodInstance, CodeInstance}
273+ def = frame_method_or_module (frame)
274+ if def isa Module
275+ Base. show_mi (io, linfo, #= from_stackframe=# true )
276+ else
277+ show_spec_sig (io, def, frame_mi (frame). specTypes)
278+ end
248279 else
249- show_spec_sig (io, def, linfo. specTypes)
280+ m = linfo:: Method
281+ show_spec_sig (io, m, m. sig)
250282 end
251- else
252- m = linfo:: Method
253- show_spec_sig (io, m, m. sig)
254283 end
255284end
256285
302331
303332function Base. parentmodule (frame:: StackFrame )
304333 linfo = frame. linfo
334+ if linfo isa CodeInstance
335+ linfo = linfo. def
336+ if isa (linfo, Core. ABIOverride)
337+ linfo = linfo. def
338+ end
339+ end
305340 if linfo isa MethodInstance
306341 def = linfo. def
307342 if def isa Module
0 commit comments