agra-uni-bremen / riscv-vp

RISC-V Virtual Prototype
MIT License
139 stars 49 forks source link

--debug-mode requires IPv6 and does not work in Docker by default #5

Closed U2654 closed 3 years ago

U2654 commented 3 years ago

Using riscv-vp or hifive-vp with --debug-mode in the current master throws:

_Error: (E549) uncaught exception: Cannot assign requested address In file: ../../../src/sysc/kernel/scexcept.cpp:101

To reproduce, try riscv-vp --debug-mode main in sw/simple-sensor

The problem wasn't in earlier versions.

Cirromulus commented 3 years ago

It works on our computers. Could you post more information about your system, and especially where the exception was thrown (maybe with gdb catch throw).

U2654 commented 3 years ago

Thanks. I set up new installations and can confirm that the problem does not appear on a Linux native machine and a Linux VM. I have the problem within a Linux Docker container. I guess it might be some port/socket issue if I understand the gdb output. It is strange that the problem did not appear with the same container and a former risc-vp version. Maybe we can close this issue?

`Catchpoint 1 (exception thrown), 0x00007f4c368b4d1d in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (gdb) bt

0 0x00007f4c368b4d1d in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6

1 0x000056188727151f in GDBServer::create_sock (this=0x5618887caaf0, port=5005)

at /home/risc-v/riscv-vp/vp/src/core/common/gdb-mc/gdb_server.cpp:94

2 0x000056188727100b in GDBServer::GDBServer (this=0x5618887caaf0, name=..., targets=std::vector of length 1, capacity 1 = {...},

mm=0x7ffec7a05210, port=5005, mmus=std::vector of length 0, capacity 0)
at /home/risc-v/riscv-vp/vp/src/core/common/gdb-mc/gdb_server.cpp:49

3 0x00005618871defa7 in sc_main (argc=4, argv=0x5618887b7690) at /home/risc-v/riscv-vp/vp/src/platform/basic/main.cpp:206

4 0x0000561887287858 in sc_elab_and_sim ()

5 0x00007f4c35e9cb97 in __libc_start_main (main=0x5618871dd2d0
, argc=4, argv=0x7ffec7a0e9a8, init=,

fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffec7a0e998) at ../csu/libc-start.c:310

6 0x00005618871ddb3a in _start ()

`

nmeum commented 3 years ago

Looking at the backtrace, this seems to be a problem with GDBServer::create_sock():

https://github.com/agra-uni-bremen/riscv-vp/blob/8c6ebca26b199dff82a3ebe61d82adc130ca74a4/vp/src/core/common/gdb-mc/gdb_server.cpp#L69-L89

This code binds to the IPv6 loopback address (i.e. ::1) and uses the IPV6_V6ONLY socket option to make sure that the socket also works with IPv4. The old GDB setup only created an IPv4 socket (that's likely why you didn't encounter this before). Maybe your Docker setup does not allow binding to the loopback interface? Or it doesn't support IPv6 and/or the IPV6_V6ONLY socket option? Unfortunately, I am not familiar with Docker. You could set a breakpoint in the create_sock function to check which specific function fails and check the errno to figure out why it fails.

Maybe we can close this issue?

Would be nice to figure out what's causing this. How do I reproduce this?

nmeum commented 3 years ago

It seems to me that IPv6 is disabled in Docker by default. That would explain why you didn't encounter this issue previously. Enabling IPv6 support in the Docker Daemon should fix this https://docs.docker.com/config/daemon/ipv6/

Maybe we can adjust this function to fallback to v4-only if binding to IPv6 fails.

U2654 commented 3 years ago

I enabled IPv6 in Docker. It works now. Thanks.