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

推荐订阅源

The Last Watchdog
The Last Watchdog
S
Securelist
T
Threat Research - Cisco Blogs
Forbes - Security
Forbes - Security
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Attack and Defense Labs
Attack and Defense Labs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
W
WeLiveSecurity
P
Palo Alto Networks Blog
O
OpenAI News
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
L
Lohrmann on Cybersecurity
NISL@THU
NISL@THU
T
Tor Project blog
T
Threatpost
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
A
Arctic Wolf
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Latest news
Latest news
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tenable Blog
量子位
L
LINUX DO - 最新话题
Webroot Blog
Webroot Blog
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
Hacker News: Ask HN
Hacker News: Ask HN
U
Unit 42
T
Tailwind CSS Blog
WordPress大学
WordPress大学
N
News | PayPal Newsroom
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Stack Overflow Blog
Stack Overflow Blog
Cloudbric
Cloudbric
C
Check Point Blog
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Hacker News
The Hacker News
B
Blog

博客园 - yooooooo

ftraceoption irq-info MPAM BE/ FE 的区别及功能 IPI与CPU唤醒机制 【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函数代码详解 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