简体   繁体   English

sc_core :: sc_in上的SystemC Seg Fault <bool> ::读()

[英]SystemC Seg Fault on sc_core::sc_in<bool>::read()

I am having a repeating seg fault while using SystemC. 使用SystemC时出现重复的段错误。 During initialization I set a value to 0. During operation of a testbench I am setting this value to 1 in a module (proc). 在初始化期间,我将值设置为0。在测试平台操作期间,我在模块(proc)中将此值设置为1。 This is a sc_signal variable that is attached to a port of another module imem. 这是一个sc_signal变量,附加到另一个模块imem的端口。 The input port is of type sc_in. 输入端口的类型为sc_in。

In theory, this assignment should cause the input port to also be assigned 1, and when I try to access it using the .read() function it should return a 1 and assign it to another internal sc_signal within imem. 从理论上讲,此分配应导致输入端口也被分配为1,当我尝试使用.read()函数访问它时,它应返回1并将其分配给imem中的另一个内部sc_signal。

However, I am instead getting a seg fault. 但是,我却遇到了段错误。

According to gdb, this is occurring during the sc_start(10,SC_NS) call I make, which makes sense since that is when values should be updated. 根据gdb的说法,这是在我进行的sc_start(10,SC_NS)调用期间发生的,这很有意义,因为那是应该更新值的时间。 It traces it specifically to trying to execute the return of the .read(). 它专门追溯到尝试执行.read()的返回的过程。 Here is a quick snippet of the stack return (-O0 and -g3 using g++ and gdb6.6, 64-bit system): 以下是堆栈返回的快速摘要(使用g ++和gdb6.6,64位系统的-O0和-g3):

#0  0x00000000004c79a6 in sc_core::sc_in<bool>::read (this=0x881a38) at <redacted>/systemC/install_x64/include/sysc/communication/sc_signal_ports.h:515
#1  0x00000000004e4b60 in imem::reg_write (this=0x881910) at ../src/abstract_proc/mems/imem.cpp:33
#2  0x000000000050578e in sc_core::sc_simcontext::crunch(bool) ()
#3  0x00000000005042b4 in sc_core::sc_simcontext::simulate(sc_core::sc_time const&) ()
#4  0x00000000004c65b0 in sc_core::sc_start (duration=10, time_unit=sc_core::SC_NS)

The port declaration: 端口声明:

SC_MODULE (imem) {
...
sc_in<bool> en_wr;

The function declaration (occurs in SC_CTOR(imem)): 函数声明(发生在SC_CTOR(imem)中):

SC_METHOD(reg_write);
sensitive << clk.pos();

The function in where it dies: 它死亡的功能:

void imem::reg_write() {
data_wr_d.write(data_wr.read());
wr_addr_d.write(addr_wr.read());
cout << "imem::reg_write()" << std::endl;
en_wr_d.write(en_wr.read());
cout << "imem::reg_write() done" << std::endl;
}

imem::reg_write() gets printed into the console just before the seg fault occurs. imem::reg_write()即将在seg错误发生之前被打印到控制台中。

The declaration and binding of imem's port: imem端口的声明和绑定:

imem_i = new imem("imem");
imem_i->en_wr(imem_wr_en);

The declaration of the driving signal: 行驶信号的声明:

sc_signal<bool> imem_wr_en;

Any ideas? 有任何想法吗? Thoughts? 有什么想法吗? Things I should try? 我应该尝试的事情?

EDIT: Something odd that occurs is sometimes adding or removing lines of code causes the seg fault to go away. 编辑:有时会出现奇怪的事情,有时添加或删除代码行会导致seg错误消失。 One particular instance involved adding a debug cout statement fixed things, but after adding a << std::endl to the end of it the seg fault returned. 一个特定的实例涉及添加一个调试cout语句以修复问题,但是在其末尾添加<< std::endl之后,将返回seg错误。 This implied to some that I have a race condition, but in theory SystemC should be handling all the concurrent threads. 这暗示我有一个竞争条件,但理论上SystemC应该处理所有并发线程。

Could you please tell if you have got solution to your problem. 请问您是否有解决问题的方法。 Actually we are hitting similar issue, seg fault, while reading a boolean sc_signal. 实际上,在读取布尔值sc_signal时,我们遇到了类似的问题,即段错误。 And problem goes away after adding prints in code. 在代码中添加打印后,问题消失了。

Sounds like memory problem. 听起来像是内存问题。 If you over run buffers somewhere, anything can happen - even stuff like you explained : program crashing at random location. 如果您在某个地方运行了缓冲区,则任何事情都可能发生-甚至像您解释的东西:程序在随机位置崩溃。

I really hope you got good unit tests. 我真的希望您获得良好的单元测试。 Try using valgrind to detect memory problems. 尝试使用valgrind检测内存问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM