From 3706a51c6b010f4cd8d754dd45c979137de1f72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=20=E6=B3=BD=E9=9A=86?= Date: Fri, 4 Oct 2024 21:21:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0AI=E7=94=9F=E6=88=90=E5=87=BD?= =?UTF-8?q?=E6=95=B0,=20=E5=87=86=E5=A4=87=E5=88=B6=E4=BD=9Cmap=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=A7=A3=E6=9E=90=E5=8A=9F=E8=83=BD;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/func_upgrade_1727523631782.py | 65 ++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 source/func_upgrade_1727523631782.py diff --git a/source/func_upgrade_1727523631782.py b/source/func_upgrade_1727523631782.py new file mode 100644 index 0000000..1ef8f3e --- /dev/null +++ b/source/func_upgrade_1727523631782.py @@ -0,0 +1,65 @@ +import re +from pathlib import Path + +def parse_map_file(map_file_path): + # 定义正则表达式模式 + section_pattern = re.compile(r'^\s*(\w+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+(.*)$') + symbol_pattern = re.compile(r'^\s*([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+(\w+)\s+(.*)$') + + sections = {} + symbols = {} + + with open(map_file_path, 'r') as file: + for line in file: + # 匹配section行 + match = section_pattern.match(line) + if match: + section_name = match.group(1) + start_address = int(match.group(2), 16) + end_address = int(match.group(3), 16) + size = int(match.group(4), 16) + sections[section_name] = { + 'start_address': start_address, + 'end_address': end_address, + 'size': size + } + continue + + # 匹配symbol行 + match = symbol_pattern.match(line) + if match: + address = int(match.group(1), 16) + size = int(match.group(2), 16) + type_ = match.group(3) + name = match.group(4) + definition = match.group(5) + symbols[name] = { + 'address': address, + 'size': size, + 'type': type_, + 'definition': definition + } + + return sections, symbols + +# 使用示例 +map_file_path = 'D:\WorkingProject\LightStackOptimizer\software\lamina_controller_dsp\lamina_controller_dsp\DEBUG\lamina_controller_dsp.map' +path_map = Path(map_file_path) +sections, symbols = parse_map_file(map_file_path) + +print("Sections:") +for section_name, section_info in sections.items(): + print(f"Section: {section_name}") + print(f" Start Address: {section_info['start_address']:X}") + print(f" End Address: {section_info['end_address']:X}") + print(f" Size: {section_info['size']:X}") + print() + +print("Symbols:") +for symbol_name, symbol_info in symbols.items(): + print(f"Symbol: {symbol_name}") + print(f" Address: {symbol_info['address']:X}") + print(f" Size: {symbol_info['size']:X}") + print(f" Type: {symbol_info['type']}") + print(f" Definition: {symbol_info['definition']}") + print() \ No newline at end of file