Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdb debugging #320

Closed
yli147 opened this issue May 5, 2023 · 9 comments
Closed

gdb debugging #320

yli147 opened this issue May 5, 2023 · 9 comments

Comments

@yli147
Copy link

yli147 commented May 5, 2023

I'm trying to use gdb to debug with the bazel-bin/salus, some steps are as below, but it looks like the gdb can't find the the source code for example main.rs based on symbol file bazel-bin/salus. Has anyone one worked with gdb ? Thanks

$ gdb-multiarch bazel-bin/salus
$ set architecture riscv:rv64
$ target remote localhost:1234
$ set directories ./src/
$ add-symbol-file ./bazel-bin/test-workloads/guestvm
$ add-symbol-file ./bazel-bin/test-workloads/tellus

@rajnesh-kanwal
Copy link
Contributor

Here are the steps which seem to work fine for me. Looks like gdb-multiarch isn't reading debug info from provided executable for some reason, strange. With your instructions I have to do add-symbol-file ./bazel-bin/salus to get it working. set directories ./src/ is not needed. Also we don't support guest debugging as of right now.

$ gdb-multiarch --symbols=bazel-bin/salus
$ set architecture riscv:rv64
$ target remote localhost:1234
$ b primary_init
$ c

After the breakpoint if I go to the TUI mode (Ctrl-x + a) I can see main.rs.

@yli147
Copy link
Author

yli147 commented May 5, 2023

Hi Rajnesh, Thanks for your response, still not working even by using "gdb-multiarch --symbols=bazel-bin/salus", what's the version of your rust toolchain and gdb ? did you add some speicfic rust build option ? or anything other ?

image

@yli147
Copy link
Author

yli147 commented May 5, 2023

And Yes, guest application debugging is not available right after the sret instruction

image

@rajnesh-kanwal
Copy link
Contributor

rajnesh-kanwal commented May 5, 2023

gdb-multiarch -v
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2

Strange. These steps seem to work fine for me.

image

@yli147
Copy link
Author

yli147 commented May 6, 2023

I'm using the below commands to build salus and debug, is there anything wrong ? By the way I can debug one riscv hello world application written by rust. so now I guess it should not the gdb issue. Are there any build options to force to build a debug version of salus ? or somthing related to rust toolchain ? Thanks

$ git clone https://github.com/rivosinc/salus.git
$ cd salus/
$ git submodule update --init
$ wget -c https://github.com/bazelbuild/bazelisk/releases/download/v1.16.0/bazelisk-linux-amd64
chmod a+x bazelisk-linux-amd64
$ ./bazelisk-linux-amd64 build //:salus-all
$ {QEMU}/build/riscv64-softmmu/qemu-system-riscv64
-M virt,aia=aplic-imsic,aia-guests=4 -cpu rv64,v=on,vlen=256,elen=64,x-smaia=true,x-ssaia=true,sscofpmf=true -smp 1 -m 2048 -nographic
-kernel bazel-bin/salus
-device guest-loader,kernel=bazel-bin/test-workloads/tellus_guestvm,addr=0xc0200000 -s -S

@yli147
Copy link
Author

yli147 commented May 6, 2023

Oh, it is caused by the --compilation_mode, with the below change, I can debug the salus now ! Thanks

$ vim ./.bazelrc
Change the line
build --compilation_mode=opt
=>
build --compilation_mode=dbg

@yli147
Copy link
Author

yli147 commented May 6, 2023

By the way, I can also debug the guest application by using the following steps:

$ gdb-multiarch --symbols=bazel-bin/salus
$ set architecture riscv:rv64
$ target remote localhost:1234
$ b _run_guest
$ b _guest_exit
$ c
It will stop in _run_guest, then step to the sret instruction
$ b *0x80200000
$ c
it will stop at 0x80200000 which is of the guest application
$ remove-symbol-file -a 0x80200000
$ add-symbol-file ./bazel-bin/test-workloads/tellus
$ b tellus.rs:464
$ c

image

@rajnesh-kanwal
Copy link
Contributor

Oh, it is caused by the --compilation_mode, with the below change, I can debug the salus now ! Thanks

$ vim ./.bazelrc Change the line build --compilation_mode=opt => build --compilation_mode=dbg

You can avoid all this by using make run_tellus_gdb, it takes care of everything, including invoking qemu with -s -S options.

@yli147
Copy link
Author

yli147 commented May 8, 2023

ok, thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants