In a GDB session, I am using trace
to define trace points to collect some variables. The following is my C code:
#include <stdio.h>
int main() {
// Define variables for square, cube, and the sums
int square, cube;
int sum_of_squares = 0, sum_of_cubes = 0;
int i;
// Loop from 1 to 10
for (i = 1; i <= 10; i++) {
// Calculate square and cube of the current number
square = i * i;
cube = i * i * i;
// Accumulate the sums
sum_of_squares += square;
sum_of_cubes += cube;
}
// After the loop, print the accumulated sums
printf("Sum of squares: %d\n", sum_of_squares);
printf("Sum of cubes: %d\n", sum_of_cubes);
// Wait for the user to press any key before exiting
printf("Press any key to exit...\n");
getchar(); // Wait for user input
return 0;
}
I use the following command to compile:
gcc -g -O0 main.c -o test
In one terminal I run the gdbserver:
gdbserver :0 ./test
# Process ./test created; pid = 70878
# Listening on port 43457
In another terminal I run gdb:
gdb -q ./test
In my gdb session execute the following gdb instructions:
(gdb) target remote :43457
(gdb) break main
(gdb) continue
(gdb) trace main.c:17
(gdb) actions
# Enter actions for tracepoint 2, one per line.
# End with a line saying just "end".
# >collect square,cube
# >end
(gdb) tstart
(gdb) continue
^C
(gdb) tstop
(gdb) tfind 0
(gdb) tdump
# Data collected at tracepoint 2, trace frame 0:
# square = <unavailable>
# cube = <unavailable>
(gdb) tfind
# Found trace frame 1, tracepoint 2
# 17 sum_of_cubes += cube;
(gdb) tdump
# Data collected at tracepoint 2, trace frame 1:
# square = <unavailable>
# cube = <unavailable>
In all frames I get the same <unavailable>
for collected variables.
The following describes my system:
mohammad@ubuntu:~$ uname -a
Linux ubuntu 6.8.0-35-generic #35-Ubuntu SMP PREEMPT_DYNAMIC Tue May 21 07:52:29 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux
mohammad@ubuntu:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="/"
SUPPORT_URL="/"
BUG_REPORT_URL="/"
PRIVACY_POLICY_URL=";
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
mohammad@ubuntu:~$ gdb --version
GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
mohammad@ubuntu:~$ gcc --version
gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
mohammad@ubuntu:~$ gdbserver --version
GNU gdbserver (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
Copyright (C) 2024 Free Software Foundation, Inc.
gdbserver is free software, covered by the GNU General Public License.
This gdbserver was configured as "aarch64-linux-gnu"
mohammad@ubuntu:~$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-6.8.0-35-generic root=UUID=974aad07-eefd-4d23-a2c7-3c132d00c155 ro
mohammad@ubuntu:~$
Why am I unable to collect any data?