惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - yooooooo

【ARM CoreLink 系列 5 -- CI-700 控制器介绍 】 ARM CoreLink 系列 4.3 -- NI-700 Component and interface identifiers ARM CCI-500 与 NI0700 的关系. ARM NIC-400 与 NI-700 的区别 claude code命令使用 【ARM Trace32(劳特巴赫) 使用介绍 2.2 -- TRACE32 进阶命令之 DIAG 弹框命令】 trace32 .cmm脚本和.t32文件的区别 【ARM Trace32(劳特巴赫) 使用介绍 1.1 - Veloce 环境中使用trace32 连接 Cortex-M33】 PCIe 总线的 ASPM 和 链路状态机制总结 fw_devlink 功能 I3C协议详解 UART 协议规范 BPF 调度器 sched_ext 实现机制、调度流程及样例 Android Camera性能分析 录像Buffer Path详解 【UEFI基础】Protocol介绍 【UEFI实战】在库中使用全局变量 sched feature TTWU_QUEUE 【ARM CoreLink 系列 4.2 -- NI-700 Function units 详细介绍】 edk2构建编译流程 UEFI:FDF文件及FD、FV、FFS EDK II PCD的概念、类型、使用 PELT算法浅析 load_balance函数代码详解 - yooooooo UEFI Boot Manager Linux misfit task Linux 内核中sched_prio_to_weight转换关系 CFS任务放置代码详解 CFS任务的负载均衡(load balance)
【ARM Trace32(劳特巴赫) 使用介绍 2.1 -- TRACE32 Practice 脚本 cmm 脚本学习】
yooooooo · 2026-04-19 · via 博客园 - yooooooo

1. TRACE32 Practice 语法

Practice脚本是Lauterbach公司提供的一种脚本语言,运用于其TRACE32软件当中,非常容易上手、并且功能强大。其运用的主要领域包含:

  • 自动化测试
  • 创建图形化界面的工具
  • 初始化和配置TRACE32软件
  • 控制Lauterbach硬件

1.1 脚本变量申明

Practice脚本中的变量(Variable)被称为宏(Marco),其本质就是存储于内存中的字符串,与C语言中的宏Q不同,Practice脚本中的宏随时可以被创建和修改。且根据作用域的不同,其又被进一步分为三类:本地宏,私有宏,全局宏:

  • 本地宏(Local Marco)

在代码块(block)中存在,离开代码块时被擦除。本地宏在它的代码块、子代码块、子函数、子脚本中可见。

  • 私有宏

仅在声明它的代码块和子代码块中可见。

  • 全局宏

全局可见,并且声明它的代码块终止后也不会被擦除。

1.1.1 本地变量申明:

 LOCAL &a &b &c //关健字为LOCAL, 变量以 “&” 开头
 ENTRY &a &b
 &c=&a*&b
 RETURN &c

1.1.2 全局变量申明:

 LOCAL &a &b &c //关健字为LOCAL, 变量以 “&” 开头
 ENTRY &a &b
 &c=&a*&b
 RETURN &c

1.1.3 常量

Practice脚本中支持多种常量类型:

十进制128.

浮点型128.0或369.36

十六进制0xA5A5

二进制0b0010

比特掩码0y10xx0

布尔型TRUE()或FALSE()

字符串"hello world"

字符‘z’

地址P:0x100

带段信息的地址P:0x02:0x100

地址范围P:0x100-0x1ff 或P:0x100++0x0f

高级语言的符号表main

声明、初始化宏都很简单,下面是个简单的例子,先声明,再初始化。注意在初始化宏的时候,宏名称和等号之间不能有空格,等号后面允许有空格。

GLOBAL  &ChipVersion
LOCAL  &msg1
PRIVATE &val1 &val2

&ChipVersion= "ES1"
&msg1=  "Hello World!"
&val1=  0xAA55
&val2=  128.

1.2 Trace32

在 practice 脚本中,常见的循环有while,repeat,以及这两种的组合。

1.2.1 While

在限定条件下,重复执行一个代码段

GLOBAL  &ChipVersion
LOCAL  &msg1
PRIVATE &val1 &val2

&ChipVersion= "ES1"
&msg1=  "Hello World!"
&val1=  0xAA55
&val2=  128.
AREA.view
PRIVATE &i
&i=0.
WHILE &i<10. ;Loop while &i is smaller 10
(
    PRINT "Count: " &i
    &i=&i+1.
)
ENDDO

注意语法之间不要加空格,比如&1+1,&i=&i+1.类似这种,不要丢掉谁后的.。

执行结果:
image

1.2.2 Repeat

按照给定的次数,重复执行一个代码段。

语法1:

RePeaT <count> <command> 		Repeat <command> <count>-times.

示例1:

;Example 1
;Print the character X 5 times
AREA.view
RePeaT 5. PRINT "hello world"

执行结果:
image

语法2

RePeaT <count>					Repeat <block> <count>-times.
(
	<block>
)

示例1:

每200ms打印一个“*”

;Example 2
AREA.view
RePeaT 10.
(
	PRINT %CONTinue "*"
	WAIT 200.ms
)

结果如下:

image

示例2:

;Example 2
Var.Break.Set flags /Write 		//Set a Write breakpoint to array
								//flags
;Repeat the following 10 times
;Start the program and wait until the target halts at the breakpoint.
;Then export the contents of array flags to file flags_export.csv in CSV
;format.
RePeaT 10.
(
	Go
	WAIT !STATE.RUN()
	Var.EXPORT "flags_export.csv" flags /Append
)

1.2.3 Repeat While

类似C语言中的 do-while循环

;Example 3
;Read a line from my_strings.txt
;Write not-empty lines to file my_strings_noempty.txt

PRIVATE &CurrentLine &RightLine
OPEN #1 my_strings.txt /Read
OPEN #2 my_strings_noempty.txt /Create
AREA.view
RePeaT
(
	READ #1 %LINE &CurrentLine
	IF (!FILE.EOFLASTREAD()&&("&CurrentLine"!=””))
	WRITE #2 "&CurrentLine"
)
WHILE !FILE.EOFLASTREAD()
CLOSE #1
CLOSE #2

1.3 Trace32条件判断

1.3.1 IF ELSE条件判断

Practice 脚本中的条件判断是依赖 IF ELSE 语句来完成的。

  • IF ELSE和其后的条件语句间要有至少一个空格;

  • 条件语句本身可以用圆括号包裹,也可不用;

  • IF ELSE所条件执行的代码段必须使用圆括号包裹,注意这时圆括号必须位于独立的一行。

语法如下

IF <condition>
(
	<if_block>
)
ELSE
(
	<else_block>
)

示例1:

Trace32关健字不区分大小写,也可以是if else

AREA.view
PRINT "IF ELSE Ttest"

IF "a"=="a"
(
  PRINT "true"
)
ELSE IF "a"=="b"
(
  PRINT "false"
)
ELSE
(
  PRINT "这里不会运行(test)"
)

运行结果:

image

示例2:

// Script double_if.cmm
PRIVATE &testfunc &correct_result
OPEN #1 "func_test.txt" /READ

WHILE TRUE()
(
	READ #1 &testfunc &correct_result
	IF "&testfunc"!=""
	(
		IF Var.VALUE(&testfunc)==&correct_result
		(
			APPEND "test_protocol.txt"\
			FORMAT.STRing("&testfunc=&correct_result",50.,' ')\
			FORMAT.UnixTime("c",DATE.UnixTime(),DATE.utcOffSet())
		)
		ELSE
		(
			PRIVATE &result
			&result=CONVert.HEXTOINT(Var.VALUE(&testfunc))
			APPEND "test_protocol.txt"\
			FORMAT.STRing("&testfunc failed with &result (&correct_result)",50.,' ')\
			FORMAT.UnixTime("c",DATE.UnixTime(),DATE.utcOffSet())
		)
	)
	ELSE
	(
		CLOSE #1
		ENDDO
	)
)
ENDDO

如果一行字符太长可以使用换行符“\”。

1.4 Trace32跳转语句

利用GOSUB,GOTOQ和JUMPTO指令可以完成脚本内的跳转。

1.4.1 GOTO语法:

语法:

GOTO <label> 					Continue PRACTICE script at <label>.
								<label> must be part of the currently executing script.

示例:

GOTO 88. 				 ;跳转至当前脚本文件第88行
AREA.view
GOTO print_hello

print_hello:
	PRINT "hello world !"
ENDDO

运行结果:

image

1.4.2 JUMPTO

JUMPTO <label> 			Continue PRACTICE script at <label>.
						<label> must be part of a script that is currently located on the
						PRACTICE stack. <label> must not be located in a block.

示例:

AREA.view

PRINT "test start..."
GOTO jumpto_test

PRINT "jumpto test failed!"

jumpto_test:
	PRINT "jumpto test success!"
ENDDO

运行结果:

image