I assume its running linux and you have root access or executable and file change permissions. We are gonna crosscompile the gdb server (and possibly other small stuff).
gmp was included with the Knulli SDK i think: https://github.com/knulli-cfw/buildroot Ow yeah.
We be asuming to be running KNULLI, and thus use their SDK?buildroot. adapt if running others.
Steps to Cross-Compile gdbserver:
export PATH=/home/codeasm/games/anbernic/SDK/knulli-sdk/build/aarch64-buildroot-linux-gnu_sdk-buildroot/bin:$PATH
export SYSROOT=$(aarch64-buildroot-linux-gnu-gcc --print-sysroot)gmp and mpfr (knulli came with gmp, so I skipped that):
wget https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz
wget https://www.mpfr.org/mpfr-current/mpfr-4.2.2.tar.xz
tar -xf gmp-6.2.1.tar.xz
cd gmp-6.2.1
./configure --host=aarch64-buildroot-linux-gnu --prefix=$SYSROOT/usr
make
make install
cd ..
tar -xf mpfr-4.2.2.tar.xz
cd mpfr-4.2.2
./configure --host=aarch64-buildroot-linux-gnu --prefix=$SYSROOT/usr --with-gmp=$SYSROOT/usr
make
make install
cd ..Download GDB Source Code:
wget http://ftp.gnu.org/gnu/gdb/gdb-16.3.tar.gz
cd gdb-16.3/
mkdir build-gdbserver
cd build-gdbserverConfigure for Cross-Compilation: Use the provided toolchain and sysroot:
../configure --host=aarch64-buildroot-linux-gnu --with-sysroot=$SYSROOT \
--with-gmp=$SYSROOT/usr \
--with-mpfr=$SYSROOT/usr \
--disable-binutils --disable-ld --disable-gas --disable-sim
Build gdbserver:
makeTransfer to Target: Use scp or adb as described in the README to copy the compiled gdbserver binary to the target device.
for example:
adb push gdbserver/gdbserver /userdata/roms/tools/gdbservernow you can:
adb shell /userdata/roms/tools/gdbserver :1235 ./mainand on the host:
aarch64-linux-gnu-gdb TestApp
set sysroot /home/codeasm/games/anbernic/SDK/knulli-sdk/build/aarch64-buildroot-linux-gnu_sdk-buildroot/aarch64-buildroot-linux-gnu/sysroot
target remote 192.168.2.19:1235
(./gdbserver :1235 ./main)
If no network, but you do have adb:
on the client/target: start as usual, but add a forward
gdbserver :1235 ./mainnow on the host, where you also have adb access:
adb forward tcp:1235 tcp:1235it will say the port number you forwarded. now from HOST gdb, you can connect: after setting the right sysroot maybe.
target remote :1235and presto, you have gdb running over adb.
Getting stacks:
gdb -ex "set pagination 0" -ex "thread apply all bt"
--batch -p $(pidof mysqld)
Or for version-impaired (gdb 6.3 and older):
(echo "set pagination 0"; echo "thread apply all bt"; echo "quit"; cat /dev/zero ) | gdb -p $(pidof mysqld)
Collapsing traces (awk!):
BEGIN { s = ""; } /Thread/ { print s; s = ""; } /^#/ { if ($3 != "in") { $4 = $2 } } /^#/ { if (s != "" ) { s = s "," $4} else { s = $4 } } END { print s }
Full technology demonstration:
#!/bin/bash nsamples=1 sleeptime=0 pid=$(pidof mysqld)
for x in $(seq 1 $nsamples)
do
gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid
sleep $sleeptime
done |
awk '
BEGIN { s = ""; }
/^Thread/ { print s; s = ""; }
/^#/ { if (s != "" ) { s = s "," $4} else { s = $4 } }
END { print s }' |
sort | uniq -c | sort -r -n -k 1,1
aarch64-linux-gnu-gdb -ex "set sysroot /home/codeasm/games/anbernic/SDK/knulli-sdk/build/aarch64-buildroot-linux-gnu_sdk-buildroot/aarch64-buildroot-linux-gnu/sysroot" \
-ex "target remote :1235" \
-ex "set debuginfod enabled off" \
-ex "set pagination 0" \
-ex "continue" \
-ex "thread apply all bt" \
--batch main