rtems提供了trace的基本功能,如下演示此功能情况
对于rtems的trace功能,可以通过官方提供的fileio-trace.ini示例文件配置,如下
; ; RTEMS Trace Linker FileIO Trace Configuration ; ; Copyright 2015 Chris Johns <chrisj@rtems.org> ; ;-------------------------------------------------------------------------- [tracer] name = File IO tracer ; ; The configuration ; options = fileio-options traces = fileio defines = fileio enables = fileio triggers = fileio functions = fileio-funcs, rtems-api, rtems-posix, libc-heap include = rtems.ini, rtld-base.ini, rtld-trace-buffer.ini, libc-heap.ini ;-------------------------------------------------------------------------- [fileio-options] dump-on-error = true ; ; Tools ; prefix = /opt/rtems/4.11 rtems-path = /opt/rtems/kernel/4.11 rtems-bsp = sparc/sis ; ; Generator options. ; gen-enables = enable gen-triggers = enable ;-------------------------------------------------------------------------- [fileio] generator = trace-buffer-generator define = '#define RTLD_TRACE_BUFFER_SIZE (1UL * 1024 * 1024)' trace = rtems_shell_init trace = malloc, calloc, realloc, free traces = rtems-api-semaphore, rtems-posix-mutex enable = rtems_shell_init enable = malloc, calloc, realloc, free enables = rtems-api-semaphore, rtems-posix-mutex trigger = rtems_shell_init ;-------------------------------------------------------------------------- [fileio-funcs] headers = fileio-headers signatures = fileio-signatures [fileio-headers] header = '#include <rtems/shell.h>"' [fileio-signatures] rtems_shell_init = rtems_status_code, const char*, size_t, rtems_task_priority, const char*, bool, bool, rtems_shell_login_check_t
这里关于rtems-path和rtems-bsp主要配置为当前rtems的安装路径和bsp路径,如下
prefix = /root/work/rtems/out rtems-path = /root/work/rtems/out rtems-bsp = aarch64/zynqmp_qemu
这里以fileio为例,我们需要先将init.c编译成.o文件,如下
# /root/work/rtems/out/bin/aarch64-rtems6-gcc -MMD -Wall -Wmissing-prototypes -Wimplicit-function-declaration -Wstrict-prototypes -Wnested-externs -mno-outline-atomics -mcpu=cortex-a53 -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 -O2 -g -fdata-sections -ffunction-sections -Icpukit/include -I../../../cpukit/include -Icpukit/score/cpu/aarch64/include -I../../../cpukit/score/cpu/aarch64/include -Ibsps/include -I../../../bsps/include -Ibsps/aarch64/include -I../../../bsps/aarch64/include -Ibsps/aarch64/xilinx-zynqmp/include -I../../../bsps/aarch64/xilinx-zynqmp/include -Itestsuites/support/include -I../../../testsuites/support/include ../../../testsuites/samples/fileio/init.c -c -o/root/work/rtems/rtems/build/aarch64/zynqmp_qemu/testsuites/samples/fileio/fileio-init.o -DHAVE_CONFIG_H=1 -DTEST_STATE_USER_INPUT=1
此命令来源于构建是waf的verbose参数,如下可以看到waf verbose参数. 值得注意的是,我将原来构建的init.c.672.o名字重写成了fileio-init.o
# rm -rf build/aarch64/zynqmp_qemu/testsuites/samples/fileio # ./waf -v Waf: Entering directory `/root/work/rtems/rtems/build' Waf: Leaving directory `/root/work/rtems/rtems/build' 'build' finished successfully (0.045s) Waf: Entering directory `/root/work/rtems/rtems/build/aarch64/zynqmp_qemu' 08:11:11 runner 'git ls-files --modified' 08:11:11 runner 'git rev-parse HEAD' [3710/4847] Compiling testsuites/samples/fileio/init.c 08:11:13 runner ['/root/work/rtems/out/bin/aarch64-rtems6-gcc', '-MMD', '-Wall', '-Wmissing-prototypes', '-Wimplicit-function- declaration', '-Wstrict-prototypes', '-Wnested-externs', '-mno-outline-atomics', '-mcpu=cortex-a53', '-mfix-cortex-a53-835769' , '-mfix-cortex-a53-843419', '-O2', '-g', '-fdata-sections', '-ffunction-sections', '-Icpukit/include', '-I../../../cpukit/inc lude', '-Icpukit/score/cpu/aarch64/include', '-I../../../cpukit/score/cpu/aarch64/include', '-Ibsps/include', '-I../../../bsps /include', '-Ibsps/aarch64/include', '-I../../../bsps/aarch64/include', '-Ibsps/aarch64/xilinx-zynqmp/include', '-I../../../bs ps/aarch64/xilinx-zynqmp/include', '-Itestsuites/support/include', '-I../../../testsuites/support/include', '../../../testsuit es/samples/fileio/init.c', '-c', '-o/root/work/rtems/rtems/build/aarch64/zynqmp_qemu/testsuites/samples/fileio/init.c.672.o', '-DHAVE_CONFIG_H=1', '-DTEST_STATE_USER_INPUT=1'] [4847/4847] Linking build/aarch64/zynqmp_qemu/testsuites/samples/fileio.exe 08:11:14 runner ['/root/work/rtems/out/bin/aarch64-rtems6-gcc', 'testsuites/samples/fileio/init.c.672.o', '-o/root/work/rtems/ rtems/build/aarch64/zynqmp_qemu/testsuites/samples/fileio.exe', '-Wl,-Bstatic', '-L.', '-lrtemscpu', '-lrtemsbsp', '-lrtemstes t', '-Wl,-Bdynamic', '-qrtems', '-mno-outline-atomics', '-mcpu=cortex-a53', '-mfix-cortex-a53-835769', '-mfix-cortex-a53-84341 9', '-Wl,--gc-sections', '-L/root/work/rtems/rtems/bsps/aarch64/shared/start', '-L/root/work/rtems/rtems/bsps/aarch64/xilinx-z ynqmp/start', '-Wl,--wrap=printf', '-Wl,--wrap=puts', '-Wl,--wrap=putchar'] Waf: Leaving directory `/root/work/rtems/rtems/build/aarch64/zynqmp_qemu' 'build_aarch64/zynqmp_qemu' finished successfully (2.606s)
根据抓到的日志信息,我们可以拿到ld的命令如下:
# /root/work/rtems/out/bin/aarch64-rtems6-gcc testsuites/samples/fileio/init.c.672.o -o/root/work/rtems/rtems/build/aarch64/zynqmp_qemu/testsuites/samples/fileio.exe -Wl,-Bstatic -L. -lrtemscpu -lrtemsbsp -lrtemstest -Wl,-Bdynamic -qrtems -mno-outline-atomics -mcpu=cortex-a53 -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 -Wl,--gc-sections -L/root/work/rtems/rtems/bsps/aarch64/shared/start -L/root/work/rtems/rtems/bsps/aarch64/xilinx-zynqmp/start -Wl,--wrap=printf -Wl,--wrap=puts -Wl,--wrap=putchar
此时我们根据gcc的verbose参数,可以得到ld的调用参数如下
# aarch64-rtems6-ld -plugin /root/work/rtems/out/libexec/gcc/aarch64-rtems6/13.3.0/liblto_plugin.so -plugin-opt=/root/work/rtems/out/libexec/gcc/aarch64-rtems6/13.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccBjkjvt.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lrtemsbsp -plugin-opt=-pass-through=-lrtemscpu -plugin-opt=-pass-through=-latomic -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc -EL -X -maarch64elf --fix-cortex-a53-835769 --fix-cortex-a53-843419 -o /root/work/rtems/rtems/build/aarch64/zynqmp_qemu/testsuites/samples/fileio.exe /root/work/rtems/out/lib/gcc/aarch64-rtems6/13.3.0/nooa/a53/fix835769/fix843419/crti.o /root/work/rtems/out/lib/gcc/aarch64-rtems6/13.3.0/nooa/a53/fix835769/fix843419/crtbegin.o -L. -L/root/work/rtems/rtems/bsps/aarch64/shared/start -L/root/work/rtems/rtems/bsps/aarch64/xilinx-zynqmp/start -L/root/work/rtems/out/lib/gcc/aarch64-rtems6/13.3.0/nooa/a53/fix835769/fix843419 -L/root/work/rtems/out/lib/gcc/aarch64-rtems6/13.3.0/../../../../aarch64-rtems6/lib/nooa/a53/fix835769/fix843419 -L/root/work/rtems/out/lib/gcc/aarch64-rtems6/13.3.0 -L/root/work/rtems/out/lib/gcc/aarch64-rtems6/13.3.0/../../../../aarch64-rtems6/lib testsuites/samples/fileio/init.c.672.o -Bstatic -lrtemscpu -lrtemsbsp -lrtemstest -Bdynamic --gc-sections --wrap=printf --wrap=puts --wrap=putchar -lgcc --start-group -lrtemsbsp -lrtemscpu -latomic -lc -lgcc --end-group -lgcc /root/work/rtems/out/lib/gcc/aarch64-rtems6/13.3.0/nooa/a53/fix835769/fix843419/crtend.o /root/work/rtems/out/lib/gcc/aarch64-rtems6/13.3.0/nooa/a53/fix835769/fix843419/crtn.o -T linkcmds
这里清晰的描述了fileio.exe的ld过程,我们将其替换成rtems-tld的调用方式如下
# rtems-tld -C build/aarch64/zynqmp_qemu/fileio-trace.ini -- -B/root/work/rtems/out/aarch64-rtems6/zynqmp_qemu/lib -qrtems -mcpu=cortex-a53 -O2 -g -ffunction-sections -fdata-sections -Wall -Wmissing-prototypes -Wimplicit-function-declaration -Wstrict-prototypes -Wnested-externs -Wl,--gc-sections -mcpu=cortex-a53 -o /root/work/rtems/rtems/build/aarch64/zynqmp_qemu/testsuites/samples/fileio.exe /root/work/rtems/rtems/build/aarch64/zynqmp_qemu/testsuites/samples/fileio/fileio-init.o -lrtemstest
这里如果是通过ld链接,则系统无法进行trace,如果通过rtems-tld链接,则系统可被trace。效果如下
如果通过标准ld,如下验证
# qemu-system-aarch64 -no-reboot -nographic -s -serial mon:stdio -machine xlnx-zcu102 -m 4096 -kernel build/aarch64/zynqmp_qemu/testsuites/samples/fileio.exe *** BEGIN OF TEST FILE I/O *** *** TEST VERSION: 6.0.0.87bf49b7156b9ddf45c218e5d4fa01f27b283db7 *** TEST STATE: USER_INPUT *** TEST BUILD: RTEMS_POSIX_API RTEMS_SMP *** TEST TOOLS: 13.3.0 20240521 (RTEMS 6, RSB b1aec32059aa0e86385ff75ec01daf93713fa382-modified, Newlib 1b3dcfd) Press any key to start file I/O sample (20s remaining) ========================= RTEMS FILE I/O Test Menu ========================= p -> part_table_initialize f -> mount all disks in fs_table l -> list file r -> read file w -> write file s -> start shell Enter your selection ==>s Creating /etc/passwd and group with four useable accounts: root/pwd test/pwd rtems/NO PASSWORD chroot/NO PASSWORD Only the root user has access to all available commands. ========================= starting shell ========================= Welcome to rtems-6.0.0 (AArch64/AArch64-LP64/zynqmp_qemu) Copyright (C) 1989, 2021 RTEMS Project and contributors Login into RTEMS /dev/foobar login: root Password: RTEMS Shell on /dev/foobar. Use 'help' to list commands. SHLL [/] # rtrace status No trace buffer generated code in the application; see rtems-tld
此时我们rtrace status无法看到trace buffer,故此系统无法trace
我们通过rtems-tld链接的系统,如下现象
# qemu-system-aarch64 -no-reboot -nographic -s -serial mon:stdio -machine xlnx-zcu102 -m 4096 -kernel build/aarch64/zynqmp_qemu/testsuites/samples/fileio.exe *** BEGIN OF TEST FILE I/O *** *** TEST VERSION: 6.0.0.87bf49b7156b9ddf45c218e5d4fa01f27b283db7 *** TEST STATE: USER_INPUT *** TEST BUILD: RTEMS_POSIX_API RTEMS_SMP *** TEST TOOLS: 13.3.0 20240521 (RTEMS 6, RSB b1aec32059aa0e86385ff75ec01daf93713fa382-modified, Newlib 1b3dcfd) Press any key to start file I/O sample (20s remaining) Press any key to start file I/O sample (19s remaining) ========================= RTEMS FILE I/O Test Menu ========================= p -> part_table_initialize f -> mount all disks in fs_table l -> list file r -> read file w -> write file s -> start shell Enter your selection ==>s Creating /etc/passwd and group with four useable accounts: root/pwd test/pwd rtems/NO PASSWORD chroot/NO PASSWORD Only the root user has access to all available commands. ========================= starting shell ========================= Welcome to rtems-6.0.0 (AArch64/AArch64-LP64/zynqmp_qemu) Copyright (C) 1989, 2021 RTEMS Project and contributors Login into RTEMS /dev/foobar login: root Password: RTEMS Shell on /dev/foobar. Use 'help' to list commands. SHLL [/] # rtrace status RTEMS Trace Bufferring: status Running: yes Triggered: yes Level: 0% Traces: 24 SHLL [/] #
此时我们可以看到rtrace的状态
至此,我们开启了rtems的trace系统。需要备注的是rtems的默认账号密码是root/pwd