#coding: utf-8
''' 升级记录
'''
import os
import re
import sys
import ctypes
import subprocess
import collections
import ConfigParser
import sip
sip.setapi('QString', 2)
from PyQt4 import QtCore, QtGui, uic
Function = collections.namedtuple('Function','name address length')
CallerRecord = collections.namedtuple('CallerRecord', 'address callee') # Caller1:
# address1 callee1
# address2 callee2
CalleeRecord = collections.namedtuple('CalleeRecord', 'caller address') # Callee1:
# caller1 address1
# caller2 address2
'''
class HFView(QtGui.QWidget):
def __init__(self, parent=None):
super(HFView, self).__init__(parent)
uic.loadUi('HFView.ui', self)
'''
from HFView_UI import Ui_HFView
class HFView(QtGui.QWidget, Ui_HFView):
def __init__(self, parent=None):
super(HFView, self).__init__(parent)
self.setupUi(self)
self.initSetting()
self.CPURegs = collections.OrderedDict([
('R0', 0), # 0, jlink.JLINKARM_ReadReg index
('R1', 0),
('R2', 0),
('R3', 0),
('R4', 0),
('R5', 0),
('R6', 0),
('R7', 0),
('R8', 0),
('R9', 0),
('R10', 0),
('R11', 0),
('R12', 0),
('R13(SP)', 0),
('R14(LR)', 0),
('R15(PC)', 0),
('XPSR', 0), # 16
('MSP', 0),
('PSP', 0),
('RAZ', 0),
('CFBP', 0),
('APSR', 0),
('EPSR', 0),
('IPSR', 0),
('PRIMASK', 0),
('BASEPRI', 0),
('FAULTMASK', 0),
('CONTROL', 0), # 27
])
def initSetting(self):
if not os.path.exists('setting.ini'):
open('setting.ini', 'w')
self.conf = ConfigParser.ConfigParser()
self.conf.read('setting.ini')
if not self.conf.has_section('globals'):
self.conf.add_section('globals')
self.conf.set('globals', 'dllpath', '')
self.conf.set('globals', 'mappath', '[]')
self.linDLL.setText(self.conf.get('globals', 'dllpath').decode('gbk'))
for path in eval(self.conf.get('globals', 'mappath')): self.cmbMap.insertItem(10, path)
@QtCore.pyqtSlot()
def on_btnDLL_clicked(self):
path = QtGui.QFileDialog.getOpenFileName(caption=u'JLinkARM.dll路径', filter=u'动态链接库文件 (*.dll)', directory=self.linDLL.text())
if path != '':
self.linDLL.setText(path)
@QtCore.pyqtSlot()
def on_btnMap_clicked(self):
path = QtGui.QFileDialog.getOpenFileName(caption=u'项目.map文件路径', filter=u'MDK .map file (*.map)', directory=self.cmbMap.currentText())
if path != '':
self.cmbMap.insertItem(0, path)
self.cmbMap.setCurrentIndex(0)
def parseMapFile(self):
with open(self.cmbMap.currentText(), 'r') as f:
text = f.read()
match = re.search(r'__initial_sp\s+0x([\dabcdef]{8})\s+Data', text)
self.Stack_Top = int(match.group(1), 16)
match = re.search(r'STACK\s+0x([\dabcdef]{8})\s+Section', text)
self.Stack_Limit = int(match.group(1), 16)
self.Functions = {}
self.Program_Start = 0xFFFFFFFF
self.Program_End = 0
for match in re.finditer(r'(\w+)\s+0x([\dabcdef]{8})\s+Thumb Code\s+(\d+)', text):
name, address, length = match.group(1), int(match.group(2), 16)-1, int(match.group(3)) # 函数地址最低位都被置位了,用以进入Thumb状态
self.Functions[name] = Function(name, address, length)
if address < self.Program_Start: self.Program_Start = address
if address > self.Program_End: self.Program_End = address
with open(self.cmbMap.currentText().replace('.map', '.txt')) as f:
text = f.read()
self.FunctionCallers = {}
for match in re.finditer(r'\n ([a-zA-Z0-9_]+)([\s\S]+?)(?=\n \S)', text):
caller = match.group(1)
if caller in self.Functions: # 是个函数
self.FunctionCallers[caller] = []
for line in match.group(2).split('\n'):
match = re.match('[ ]{8}0x([\dabcdef]{8}).+?B[L.W]*\s+([A-Za-z_][A-Za-z0-9_]+) ;', line)
if match:
address, callee = int(match.group(1), 16), match.group(2)
if callee in self.Functions: # 是个函数
self.FunctionCallers[caller].append(CallerRecord(address, callee))
self.FunctionCallees = {}
for func in self.Functions:
self.FunctionCallees[func] = []
for caller in self.FunctionCallers:
for record in self.FunctionCallers[caller]:
if func == record.callee:
self.FunctionCallees[func].append(CalleeRecord(caller, record.address))
'''
for func in self.Functions:
print '%-030s @ 0x%08X len %d' %(self.Functions[func].name, self.Functions[func].address, self.Functions[func].length)
print '\n\n'
for caller in self.FunctionCallers:
print '\n%s Call:' %caller
for record in self.FunctionCallers[caller]:
print '0x%08X %s' %(record.address, record.callee)
print '\n\n'
for callee in self.FunctionCallees:
print '\n%s Called By:' %callee
for record in self.FunctionCallees[callee]:
print '%s @ 0x%08X' %(record.caller, record.address)
'''
@QtCore.pyqtSlot()
def on_btnOper_clicked(self):
self.parseMapFile()
try:
self.jlink = ctypes.cdll.LoadLibrary(self.linDLL.text())
self.jlink.JLINKARM_TIF_Select(1)
self.jlink.JLINKARM_SetSpeed(4000)
self.jlink.JLINKARM_Halt()
for i, reg in enumerate(self.CPURegs):
self.CPURegs[reg] = self.jlink.JLINKARM_ReadReg(i)
if self.CPURegs[reg] < 0: self.CPURegs[reg] += 0x100000000 # 返回值int类型,若大于0x80000000则会变成负数
self.txtMain.append('CPU Registers:')
self.txtMain.append(
'%-07s: 0x%08X %-07s: 0x%08X %-07s: 0x%08X %-07s: 0x%08X\n'
'%-07s: 0x%08X %-07s: 0x%08X %-07s: 0x%08X %-07s: 0x%08X\n'
'%-07s: 0x%08X %-07s: 0x%08X %-07s: 0x%08X %-07s: 0x%08X\n'
'%-07s: 0x%08X\n'
'%-07s: 0x%08X %-07s: 0x%08X %-07s: 0x%08X\n'
'%-07s: 0x%08X\n'
'%-07s: 0x%08X\n'
'%-07s: 0x%08X %-07s: 0x%08X %-07s: 0x%08X %-07s: 0x%08X\n'
'%-07s: 0x%02X\n'
'%-07s: 0x%02X %-07s: %d %-07s: %d\n'
%('R0', self.CPURegs['R0'], 'R1', self.CPURegs['R1'], 'R2', self.CPURegs['R2'], 'R3', self.CPURegs['R3'],
'R4', self.C
Mr显
- 粉丝: 16
- 资源: 30
最新资源
- 数据架构基础知识(35页).pptx
- 数字孪生智慧城市PPT(21页).pptx
- 用户画像解说(16页 ).pptx
- 信捷XDH系列PLC追剪 飞剪 电子凸轮程序模板 包含了定长追剪和飞剪模式 定标飞剪 追剪模式 函数功能块无jia密,是学习信捷追 飞剪的经典模板 适合参考借鉴 包含:PLC程序+信捷触摸屏HMI+软
- 电影票房相关的数据,包括日期、上座率、场均人次、综合票价、综合票房(万元)、综合票房占比、电影片名、大盘退票率、排座占比、场次、排片占比、分账票价和核心票房(万元)等信息 数据提供了每部电影在特定日期
- 基于A* 算法的无人机三维路径规划算法,可以动态避障,自己可以规定设计障碍物位置,MATLAB编程实现
- 视觉显著性驱动的面向机器视频编码框架基于VVC与YOLO的研究及其对物体检测的影响
- node-red创建节点流程
- 机械设计汽车锁零件全自动铆轴设备Creo5.0非常好的设计图纸100%好用.zip
- 基于 yolov8 的航行识别
- 机械设计软管接头压合step非常好的设计图纸100%好用.zip
- 学习threejs,导入AWD格式的模型
- mha5.7、mha5.8的rpm和tar包
- 机械设计全自动卡板拆堆跺滚筒线设备sw21可编辑非常好的设计图纸100%好用.zip
- ESP32-S3-WROOM-1乐鑫WIFI模块原理图和PCB,LCEDA格式
- PEM电解槽二维仿真模型,采用水电解槽,自由与多孔介质流动,固体与流体传热,收敛性良好,适用于探索不同的边界条件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈