map2dbg: Implemented

Signed-off-by: Max Logaev <maxlogaev@proton.me>
This commit is contained in:
2026-01-13 18:00:02 +03:00
parent e41f3ad2a7
commit e2729157e4

47
tools/map2dbg.py Normal file
View File

@@ -0,0 +1,47 @@
#!/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()