Skip to content

Commit

Permalink
Improve Nim remote GDB debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Feb 11, 2022
1 parent 1c311cc commit 710071f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 6 additions & 2 deletions binaries/nim/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
### Nim RISC-V program example
## Nim RISC-V program example

The program is designed to print a JSON structure and then crash.
The signal handlers will show the backtrace as long as debug info is added.

## Requirements
### Requirements

You will need to have Nim in your PATH.

Install gcc-10-riscv64-linux-gnu to be able build the Nim program for RISC-V.

### Debugging

Run `bash debug.sh` to start remotely debugging with GDB. You will need to build the RISC-V GDB from the RISC-V GNU toolchain, as it is not provided by any distro that I know of.
13 changes: 10 additions & 3 deletions binaries/nim/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ NIM_LIBS=`whereis nim`
NIM_LIBS="${NIM_LIBS##*: }"
NIM_LIBS="${NIM_LIBS/bin*/lib}"

nim c --nimcache:$NIMCACHE $NIMCPU --colors:on --os:linux --gc:arc -d:useMalloc=true -d:debug -c ${NIMFILE}
jq '.compile[] [0]' $NIMCACHE/*.json > buildfiles.txt
if [[ -z "${DEBUG}" ]]; then
nim c --nimcache:$NIMCACHE $NIMCPU --colors:on --os:linux --gc:arc -d:useMalloc=true -d:release -c ${NIMFILE}
jq '.compile[] [0]' $NIMCACHE/*.json > buildfiles.txt

cmake .. -DGCC_TRIPLE=$GCC_TRIPLE -DNIM_LIBS=$NIM_LIBS -DCMAKE_BUILD_TYPE=Release
cmake .. -DGCC_TRIPLE=$GCC_TRIPLE -DNIM_LIBS=$NIM_LIBS -DCMAKE_BUILD_TYPE=Release -DDEBUGGING=OFF
else
nim c --nimcache:$NIMCACHE $NIMCPU --colors:on --os:linux --gc:arc -d:useMalloc=true --debugger=native -c ${NIMFILE}
jq '.compile[] [0]' $NIMCACHE/*.json > buildfiles.txt

cmake .. -DGCC_TRIPLE=$GCC_TRIPLE -DNIM_LIBS=$NIM_LIBS -DCMAKE_BUILD_TYPE=Debug -DDEBUGGING=ON
fi
make -j4
popd

Expand Down
2 changes: 2 additions & 0 deletions binaries/nim/debug.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
file riscv64-linux-gnu/hello
target remote localhost:2159
6 changes: 6 additions & 0 deletions binaries/nim/debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export DEBUG=1
source build.sh
echo "=================================="
echo " Start emulator with DEBUG=1 now. "
echo "=================================="
riscv64-unknown-linux-gnu-gdb -x debug.gdb

0 comments on commit 710071f

Please sign in to comment.