@@ -84,16 +84,22 @@ def format_thread(thread: PyThread, native_mode: NativeReportingMode) -> Iterabl
84
84
yield from format_frame (current_frame )
85
85
current_frame = current_frame .next
86
86
else :
87
- yield from _format_merged_stacks (thread , current_frame )
87
+ yield from _format_merged_stacks (
88
+ thread , current_frame , native_mode == NativeReportingMode .LAST
89
+ )
88
90
yield ""
89
91
90
92
91
93
def _format_merged_stacks (
92
- thread : PyThread , current_frame : Optional [PyFrame ]
94
+ thread : PyThread ,
95
+ current_frame : Optional [PyFrame ],
96
+ native_last : bool = False ,
93
97
) -> Iterable [str ]:
98
+ c_frames_list : list [str ] = []
94
99
for frame in thread .native_frames :
95
100
if frame_type (frame , thread .python_version ) == NativeFrame .FrameType .EVAL :
96
101
assert current_frame is not None
102
+ c_frames_list = []
97
103
yield from format_frame (current_frame )
98
104
current_frame = current_frame .next
99
105
while current_frame and not current_frame .is_entry :
@@ -104,12 +110,18 @@ def _format_merged_stacks(
104
110
continue
105
111
elif frame_type (frame , thread .python_version ) == NativeFrame .FrameType .OTHER :
106
112
function = colored (frame .symbol , "yellow" )
107
- yield (
113
+ formatted_c_frame = (
108
114
f' { colored ("(C)" , "blue" )} File "{ frame .path } ",'
109
115
f" line { frame .linenumber } ,"
110
116
f" in { function } ({ colored (frame .library , attrs = ['faint' ])} )"
111
117
)
118
+ if native_last :
119
+ c_frames_list .append (formatted_c_frame )
120
+ else :
121
+ yield formatted_c_frame
112
122
else : # pragma: no cover
113
123
raise ValueError (
114
124
f"Invalid frame type: { frame_type (frame , thread .python_version )} "
115
125
)
126
+ for c_frame in c_frames_list :
127
+ yield c_frame
0 commit comments