stm32出现hardfault-自动化分析map文件

可通过如下python脚本进行分析:

import os

import sys

#在此输入HardFault_Handler时打印的PC指针

address = 0x20006980

#以下代码不要要更改

def is_hex(data):

try:

int(data, 16)

return True

except ValueError:

return False

def find_line_number(map_file, address):

line_number = None

linestring = ""

with open(map_file, 'r') as f:

line_num = 0

lines = f.readlines()

for line in lines:

line_num = line_num + 1

line = line.replace('\n', '').strip()

parts = line.split()

if len(parts) >= 3:

if is_hex(parts1) :

func_address = int(parts1, 16)

if func_address >= address:

line_number = str(line_num - 1) if func_address > address else str(line_num)

break

elif is_hex(parts2) :

func_address = int(parts2, 16)

if func_address >= address:

line_number = str(line_num - 1) if func_address > address else str(line_num)

break

linestring = line

return line_number, (linestring if func_address > address else line)

if name == "main":

script_path = os.path.dirname(os.path.realpath(file))

os.chdir(script_path)

map_file = '../Listings/SC_Func.map'

line_number, linestring = find_line_number(map_file, address)

if line_number:

print(f"Function at address: {hex(address)}, LineNumber: {line_number}")

print(f"Content: {linestring}")

else:

print(f"No function found at address {hex(address)}")

相关推荐
Hyyy33 分钟前
理解LLM的基本工作原理:预训练、微调、推理的区别
前端
Gatlin1 小时前
前端逆向与反逆向:一场猫鼠游戏的底层逻辑与实战
前端
代码煮茶1 小时前
React 组件封装方法论 —— 以 Todo App 为例
javascript·react.js
Pedantic1 小时前
本地通知(Local Notifications)学习笔记
前端
任沫1 小时前
Agent之Function Call
javascript·人工智能·go
森蓝情丶2 小时前
我给 AI 搭了个法庭:一个前端仔的 LangGraph 实战全记录
前端·后端
爱勇宝2 小时前
干了近 8 年,一夜之间被裁:AI 时代,程序员最该害怕的不是 AI
前端·后端·程序员
Pedantic2 小时前
Combine 框架学习笔记
前端
runnerdancer2 小时前
Agent如何加载执行Skill的脚本
前端·agent
yingyima3 小时前
VS Code 正则替换技巧:从凌晨3点的服务器报警开始
前端