Find addr2line tool from build_info.json. Args: build_info_path: Path to build_info.json file Returns: Path to addr2line tool or None if not found
(build_info_path: Path)
| 30 | |
| 31 | |
| 32 | def find_addr2line_from_build_info(build_info_path: Path) -> Optional[Path]: |
| 33 | """Find addr2line tool from build_info.json. |
| 34 | |
| 35 | Args: |
| 36 | build_info_path: Path to build_info.json file |
| 37 | |
| 38 | Returns: |
| 39 | Path to addr2line tool or None if not found |
| 40 | """ |
| 41 | try: |
| 42 | with open(build_info_path, "r") as f: |
| 43 | build_info: dict[str, Any] = json.load(f) |
| 44 | |
| 45 | # Build info has structure: { "board_name": { "aliases": { "addr2line": "path" } } } |
| 46 | # Get the first (and usually only) board entry |
| 47 | for board_name, board_data in build_info.items(): |
| 48 | if not isinstance(board_data, dict): |
| 49 | continue |
| 50 | if "aliases" not in board_data: |
| 51 | continue |
| 52 | aliases = cast(dict[str, Any], board_data["aliases"]) |
| 53 | if not isinstance(aliases, dict): |
| 54 | continue |
| 55 | addr2line_path = cast(Optional[str], aliases.get("addr2line")) |
| 56 | if addr2line_path and isinstance(addr2line_path, str): |
| 57 | path = Path(addr2line_path) |
| 58 | if path.exists(): |
| 59 | print( |
| 60 | f"Using addr2line from build_info.json: {path}", |
| 61 | file=sys.stderr, |
| 62 | ) |
| 63 | return path |
| 64 | else: |
| 65 | print( |
| 66 | f"Warning: addr2line path from build_info.json does not exist: {path}", |
| 67 | file=sys.stderr, |
| 68 | ) |
| 69 | |
| 70 | print("Warning: No addr2line path found in build_info.json", file=sys.stderr) |
| 71 | return None |
| 72 | |
| 73 | except KeyboardInterrupt as ki: |
| 74 | handle_keyboard_interrupt(ki) |
| 75 | raise |
| 76 | except Exception as e: |
| 77 | print( |
| 78 | f"Warning: Failed to load addr2line from build_info.json: {e}", |
| 79 | file=sys.stderr, |
| 80 | ) |
| 81 | return None |
| 82 | |
| 83 | |
| 84 | def find_addr2line() -> Optional[Path]: |
no test coverage detected