chisel2-deprecated icon indicating copy to clipboard operation
chisel2-deprecated copied to clipboard

Segmentation fault crashing tester

Open da-steve101 opened this issue 9 years ago • 3 comments

The tester crashed with a segmentation fault

Chisel trace is

[info]   Chisel.TestApplicationException: test application exit - exit code 139
[info]   at Chisel.Tester.throwExceptionIfDead(Tester.scala:128)
[info]   at Chisel.Tester.Chisel$Tester$$mwhile(Tester.scala:138)
[info]   at Chisel.Tester.start(Tester.scala:763)
[info]   at Chisel.Tester.<init>(Tester.scala:795)

Valgrind output running the simulator is

==22869== Invalid write of size 8
==22869==    at 0x7A8482: dat_api<17>::get_value(unsigned long*) (emul_api.h:38)
==22869==    by 0x7AA7CB: emul_api_t::get_value(dat_api_base*&, unsigned long*) (emul_api.h:110)
==22869==    by 0x7F25AF: sim_api_t<dat_api_base*>::send_tokens() (sim_api.h:333)
==22869==    by 0x7F21B0: sim_api_t<dat_api_base*>::tick() (sim_api.h:142)

From gdb looking at sim_api.h (send_tokens, 325) at the iteration of loop at 331 before the crash

sim_data.outputs.size() = 5367
off = 2047

It appears that the out channel is not big enough for all the values. The channel appears to allocate one page (pgsize = 4096) to store values (sim_api.h, 55).

    channel = (char*)mmap(NULL, pgsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 

Perhaps the channel size should be determined using the number of inputs and outputs the design has?

da-steve101 avatar Feb 26 '16 01:02 da-steve101

On Feb 25, 2016, at 5:48 PM, da-steve101 [email protected] wrote:

The tester crashed with a segmentation fault

Chisel trace is

[info] Chisel.TestApplicationException: test application exit - exit code 139 [info] at Chisel.Tester.throwExceptionIfDead(Tester.scala:128) [info] at Chisel.Tester.Chisel $Tester$$ mwhile(Tester.scala:138) [info] at Chisel.Tester.start(Tester.scala:763) [info] at Chisel.Tester. (Tester.scala:795) Valgrind output running the simulator is

==22869== Invalid write of size 8 ==22869== at 0x7A8482: dat_api <17>::get_value(unsigned long* ) (emul_api.h:38) ==22869== by 0x7AA7CB: emul_api_t::get_value(dat_api_base &, unsigned long ) (emul_api.h:110) ==22869== by 0x7F25AF: sim_api_t<dat_api_base*>::send_tokens () (sim_api.h:333) ==22869== by 0x7F21B0: sim_api_t<dat_api_base*>::tick() (sim_api.h:142) From gdb looking at sim_api.h (send_tokens, 325) at the iteration of loop at 331 before the crash

sim_data.outputs.size () = 5367 off = 2047

It appears that the out channel is not big enough for all the values. The channel appears to allocate one page (pgsize = 4096) to store values (sim_api.h, 55).

channel = (char*)mmap(NULL, pgsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 

Perhaps the channel size should be determined using the number of inputs and outputs the design has?

Excellent analysis. We'll submit a fix.

ucbjrl avatar Feb 26 '16 16:02 ucbjrl

Can someone comment on how to run valgrind or gdb with the C++ generated code? Normally I use sbt to run the binary file under the Chisel tester so I am not how to run both under valgrind/gdb in order to debug a segmentation fault. Thanks!

swamy-t avatar Nov 25 '16 08:11 swamy-t

When you run with sbt, chisel prints out the gcc commands it is running. All you have to do is run those commands with '-g' to put in debugging symbols. Can then run the compiled binary with gdb/valgrind

da-steve101 avatar Nov 30 '16 01:11 da-steve101