48 lines
973 B
Python
48 lines
973 B
Python
#!/usr/bin/env python3
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
# Script for converting GNU LD map file
|
|
# into symbols for KolibriOS debuger (mtdbg),
|
|
|
|
# Copyright (C) 2025 KolibriOS team
|
|
# Author: Maxim Logaev <maxlogaev@proton.me>
|
|
|
|
import sys
|
|
import re
|
|
|
|
if len(sys.argv) < 2:
|
|
print("Usage: python3 map2dbg.py <input.map> <output.dbg>")
|
|
sys.exit(1)
|
|
|
|
map_file = open(sys.argv[1], 'r')
|
|
dbg_file = open(sys.argv[2], 'w')
|
|
|
|
# Find .text section
|
|
line = map_file.readline()
|
|
|
|
while (line):
|
|
if line.startswith(".text"):
|
|
break
|
|
line = map_file.readline()
|
|
|
|
# Extract symbols from .text section
|
|
line = map_file.readline()
|
|
|
|
while (line):
|
|
|
|
# .text section is ended
|
|
if not line.startswith(" "):
|
|
break
|
|
|
|
match = re.search(r'^\s+0x([0-9a-fA-F]+)\s+(\S+)\s*$', line)
|
|
if match:
|
|
addr = match.group(1)
|
|
name = match.group(2)
|
|
dbg_file.write(f"0x{addr} {name}\n")
|
|
|
|
line = map_file.readline()
|
|
|
|
map_file.close()
|
|
dbg_file.close()
|