| 64 | |
| 65 | |
| 66 | def format_thread(thread: PyThread, native_mode: NativeReportingMode) -> Iterable[str]: |
| 67 | native = native_mode != NativeReportingMode.OFF |
| 68 | current_frame: Optional[PyFrame] = thread.first_frame |
| 69 | if current_frame is None and not native: |
| 70 | yield f"The frame stack for thread {thread.tid} is empty" |
| 71 | return |
| 72 | |
| 73 | thread_name = f" ({thread.name}) " if thread.name else " " |
| 74 | yield ( |
| 75 | f"Traceback for thread {thread.tid}{thread_name}{thread.status} " |
| 76 | "(most recent call last):" |
| 77 | ) |
| 78 | |
| 79 | if not (native and _are_the_stacks_mergeable(thread)): |
| 80 | if native: |
| 81 | yield "* - Unable to merge native stack due to insufficient native information - *" |
| 82 | while current_frame is not None: |
| 83 | if not current_frame.is_shim: |
| 84 | yield from format_frame(current_frame) |
| 85 | current_frame = current_frame.next |
| 86 | else: |
| 87 | yield from _format_merged_stacks( |
| 88 | thread, current_frame, native_mode == NativeReportingMode.LAST |
| 89 | ) |
| 90 | yield "" |
| 91 | |
| 92 | |
| 93 | def _format_merged_stacks( |