利用 XSIM
本节中,我们提供了一系列示例,旨在展示如何借助 XSIM 工具深入探究程序在 XCORE 设备上的运行机制。
代码在哪个 Tile 上执行?
请按照针对多个 Tile 的目标设置中的示例进行构建和执行:
$ xcc -target=XCORE-200-EXPLORER multitile.xc main.c
$ xrun --io a.xe
Hello from tile 0
Hello from tile 1
如何验证这些输出确实是由指定的 Tile 执行的代码生成的呢?我们可以利用 xsim -t 来识别系统调用是由哪个 Tile 产生的。此处,我们用 grep 来过滤并简化跟踪输出, 只捕获与相关输出行相邻的一行:
$ xsim -t a.xe | grep -B 1 "Hello from"
tile[0]@0- -SI A-.----00040264 (_DoSyscall + 0) : nop @11057
Hello from tile 0
tile[1]@0- -SI A-.----00040234 (_DoSyscall + 0) : nop @11061
Hello from tile 1
这证明了系统调用确实是由我们预期的 Tile 产生的。
在模拟中使用 XScope
在模拟器上执行代码时,您可以使用 XScope。尽管它的速度并不比非 XScope 方法快,但它能够帮助调试与 XScope 相关的任何问题。
请根据使用 XSCOPE 进行快速的“printf 调试”中的示例进行构建。如下使用 xsim --xscope 选项执行应用程序:
$ xsim --xscope "-offline xscope.vcd" a.xe
Tile 0: Result 0
Tile 1: Iteration 0 Accumulation: 0
Tile 1: Iteration 1 Accumulation: 1
Tile 1: Iteration 2 Accumulation: 3
Tile 1: Iteration 3 Accumulation: 6
Tile 1: Iteration 4 Accumulation: 10
Tile 1: Iteration 5 Accumulation: 15
Tile 1: Iteration 6 Accumulation: 21
Tile 1: Iteration 7 Accumulation: 28
Tile 1: Iteration 8 Accumulation: 36
Tile 1: Iteration 9 Accumulation: 45
Tile 0: Result 45
XScope 的跟踪输出将被保存到 xscope.vcd 文件中。