Jump to content
AmeyaVS

Possible Bug in VCD tracing

Recommended Posts

Hi,

It seems I have hit a bug in VCD tracing implementation in SystemC release 2.3.2.

Here is the bracktrace captured in GDB: (minimal example available here: https://github.com/AmeyaVS/SystemC_ramblings/tree/dev)

as one can observe the exception: SIGFPE in systemc-2.3.2/src/sysc/tracing/sc_trace_file_base.cpp:268 due to divide by zero error.

GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/ameya/Documents/demo/SystemC_ramblings/src/02_adder/build/tests/AdderTest/AdderTest.run...done.
(gdb) r
Starting program: /home/ameya/Documents/demo/SystemC_ramblings/src/02_adder/build/tests/AdderTest/AdderTest.run 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

        SystemC 2.3.2-Accellera --- May  1 2018 16:30:17
        Copyright (c) 1996-2017 by all Contributors,
        ALL RIGHTS RESERVED
At time 0 s :: (a, b, cin): 100 (sum, carry_out): 00
At time 0 s :: (a, b, cin): 010 (sum, carry_out): 00
At time 0 s :: (a, b, cin): 110 (sum, carry_out): 10
At time 0 s :: (a, b, cin): 001 (sum, carry_out): 10
At time 0 s :: (a, b, cin): 101 (sum, carry_out): 11
At time 0 s :: (a, b, cin): 011 (sum, carry_out): 10
At time 0 s :: (a, b, cin): 111 (sum, carry_out): 00
At time 0 s :: (a, b, cin): 111 (sum, carry_out): 01

Info: /OSCI/SystemC: Simulation stopped by user.

Program received signal SIGFPE, Arithmetic exception.
0x00007ffff7b57799 in sc_core::sc_trace_file_base::timestamp_in_trace_units (this=this@entry=0x5555557a3730, high=@0x7fffffffc658: 93824994651128, low=@0x7fffffffc660: 140737488346560)
    at /home/ameya/apps/src/systemc/systemc-2.3.2/src/sysc/tracing/sc_trace_file_base.cpp:268
268	        unit_type unit_divisor = trace_unit_fs / kernel_unit_fs;
(gdb) bt
#0  0x00007ffff7b57799 in sc_core::sc_trace_file_base::timestamp_in_trace_units (this=this@entry=0x5555557a3730, high=@0x7fffffffc658: 93824994651128, low=@0x7fffffffc660: 140737488346560)
    at /home/ameya/apps/src/systemc/systemc-2.3.2/src/sysc/tracing/sc_trace_file_base.cpp:268
#1  0x00007ffff7b5d8a2 in sc_core::vcd_trace_file::get_time_stamp (this=this@entry=0x5555557a3730, now_units_high=@0x7fffffffc658: 93824994651128, now_units_low=@0x7fffffffc660: 140737488346560)
    at /home/ameya/apps/src/systemc/systemc-2.3.2/src/sysc/tracing/sc_vcd_trace.cpp:2086
#2  0x00007ffff7b5e242 in sc_core::vcd_trace_file::~vcd_trace_file (this=0x5555557a3730, __in_chrg=<optimized out>) at /home/ameya/apps/src/systemc/systemc-2.3.2/src/sysc/tracing/sc_vcd_trace.cpp:2145
#3  0x00007ffff7b5e319 in sc_core::vcd_trace_file::~vcd_trace_file (this=0x5555557a3730, __in_chrg=<optimized out>) at /home/ameya/apps/src/systemc/systemc-2.3.2/src/sysc/tracing/sc_vcd_trace.cpp:2153
#4  0x000055555555cfc1 in sc_main (argc=1, argv=0x5555557a2bf0) at /home/ameya/Documents/demo/SystemC_ramblings/src/02_adder/tests/AdderTest/src/full_adder_main.cpp:37
#5  0x00007ffff7b32e24 in sc_core::sc_elab_and_sim (argc=1, argv=<optimized out>) at /home/ameya/apps/src/systemc/systemc-2.3.2/src/sysc/kernel/sc_main_main.cpp:87
#6  0x00007ffff7097b97 in __libc_start_main (main=0x7ffff7aa1fa0 <main(int, char**)>, argc=1, argv=0x7fffffffddb8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffffffdda8) at ../csu/libc-start.c:310
#7  0x000055555555c08a in _start ()
(gdb) 

I seems to happen only when the simulation time is not progressing.

One can apply the below patch to branch (dev) available under here for the following sub-directory: https://github.com/AmeyaVS/SystemC_ramblings/tree/dev/src/02_adder

diff --git a/src/02_adder/tests/AdderTest/src/driver.cpp b/src/02_adder/tests/AdderTest/src/driver.cpp
index e70aea1..26169b7 100644
--- a/src/02_adder/tests/AdderTest/src/driver.cpp
+++ b/src/02_adder/tests/AdderTest/src/driver.cpp
@@ -7,8 +7,14 @@ void driver::prc_driver() {
     d_a = pattern[0];
     d_b = pattern[1];
     d_cin = pattern[2];
-    wait(5, sc_core::SC_NS);
+    //wait(5, sc_core::SC_NS);
+    wait(sc_core::SC_ZERO_TIME);
     pattern++;
+    if (pattern == 0) {
+      break;
+    }
   }
+  wait(sc_core::SC_ZERO_TIME);
+  sc_core::sc_stop();
 }
 

This behavior is not reproduced in SystemC release 2.3.1a.

I will try to debug further and hopefully with probable fix.

Regards,

Ameya Vikram Singh

Share this post


Link to post
Share on other sites

Thanks for reporting!

Here is a small reproducer for this bug:

#include <systemc>

int sc_main(int argc, char ** argv ) {
    sc_core::sc_trace_file *tf = sc_core::sc_create_vcd_trace_file("vcdtrace");
    sc_core::sc_close_vcd_trace_file(tf);
    return 0;
}

 

Probably the easiest way to fix is to do zero check before printing last time stamp.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×