|
10 | 10 |
|
11 | 11 | from esp_idf_monitor.base.key_config import MENU_KEY, TOGGLE_OUTPUT_KEY
|
12 | 12 |
|
13 |
| -from .output_helpers import error_print, note_print |
| 13 | +from .output_helpers import (COMMON_PREFIX, error_print, green_print, |
| 14 | + normal_print, note_print, red_print, yellow_print) |
14 | 15 |
|
15 | 16 | key_description = miniterm.key_description
|
16 | 17 |
|
@@ -141,9 +142,40 @@ def output_toggle(self): # type: () -> None
|
141 | 142 | def handle_possible_pc_address_in_line(self, line: bytes, insert_new_line: bool = False) -> None:
|
142 | 143 | if not self.pc_address_decoder:
|
143 | 144 | return
|
144 |
| - translation = self.pc_address_decoder.decode_address(line) |
145 |
| - if translation: |
146 |
| - if insert_new_line: |
147 |
| - # insert a new line in case address translation is printed in the middle of a line |
148 |
| - self.print(b'\n') |
149 |
| - self.print(translation, console_printer=note_print) |
| 145 | + |
| 146 | + # Find any executable addresses in the line and translate them to source locations. |
| 147 | + translated = self.pc_address_decoder.translate_addresses(line.decode(errors='ignore')) |
| 148 | + if not translated: |
| 149 | + return |
| 150 | + |
| 151 | + if insert_new_line: |
| 152 | + # insert a new line in case address translation is printed in the middle of a line |
| 153 | + self.print(b'\n') |
| 154 | + |
| 155 | + # For each address and its corresponding trace |
| 156 | + for address, trace in translated: |
| 157 | + # Print the address (start of line, white) |
| 158 | + self.print(f'{COMMON_PREFIX} {address}: ', console_printer=normal_print) |
| 159 | + if not trace: |
| 160 | + # No trace entries (this should not happen, but just in case, red) |
| 161 | + self.print('(unknown)', console_printer=red_print) |
| 162 | + continue |
| 163 | + |
| 164 | + # For each source location in the trace |
| 165 | + for idx, entry in enumerate(trace): |
| 166 | + if idx > 0: |
| 167 | + # More than 1 entry indicates inlined functions (white). |
| 168 | + self.print(f'{COMMON_PREFIX} (inlined by) ', console_printer=normal_print) |
| 169 | + |
| 170 | + # Print the function name (yellow) |
| 171 | + self.print(entry.func, console_printer=lambda msg: yellow_print(msg, newline='')) |
| 172 | + if entry.path == 'ROM': |
| 173 | + # Special case for ROM paths (green) |
| 174 | + self.print(' in ', console_printer=normal_print) |
| 175 | + self.print('ROM', console_printer=green_print) |
| 176 | + else: |
| 177 | + # Print the file path and line number (green:red) |
| 178 | + self.print(' at ', console_printer=normal_print) |
| 179 | + self.print(entry.path, console_printer=lambda msg: green_print(msg, newline='')) |
| 180 | + self.print(':', console_printer=normal_print) |
| 181 | + self.print(entry.line, console_printer=red_print) |
0 commit comments