Demangle Rust symbols using rustfilt.
(entries)
| 324 | |
| 325 | |
| 326 | def demangle_symbols(entries): |
| 327 | """Demangle Rust symbols using rustfilt.""" |
| 328 | symbols = [e[2] for e in entries if e[2]] |
| 329 | if not symbols: |
| 330 | return entries |
| 331 | |
| 332 | try: |
| 333 | demangled = run(["rustfilt"], input="\n".join(symbols)) |
| 334 | demangled_list = demangled.strip().split("\n") |
| 335 | except Exception: |
| 336 | return entries |
| 337 | |
| 338 | result = [] |
| 339 | demangle_idx = 0 |
| 340 | for section, crate, symbol, size in entries: |
| 341 | if symbol: |
| 342 | if demangle_idx < len(demangled_list): |
| 343 | symbol = demangled_list[demangle_idx] |
| 344 | demangle_idx += 1 |
| 345 | # With LTO, all code is merged into one object file, so the |
| 346 | # object-based crate is just the top-level crate. Recover the |
| 347 | # real originating crate from the demangled symbol path. |
| 348 | sym_crate = crate_from_symbol(symbol) |
| 349 | if sym_crate: |
| 350 | crate = sym_crate |
| 351 | result.append((section, crate, symbol, size)) |
| 352 | return result |
| 353 | |
| 354 | |
| 355 | def crate_from_symbol(symbol): |