diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index ffe1bab79..d5e4f9b66 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -2156,7 +2156,7 @@ void EmitCImp::emitDestructorImp(AstNodeModule* modp) { // Call via function in __Trace.cpp as this .cpp file does not have trace header if (v3Global.needTraceDumper()) { puts("#ifdef VM_TRACE\n"); - puts("if (VL_UNLIKELY(__VlSymsp->__Vm_dumperp)) _traceDumpClose();\n"); + puts("if (VL_UNLIKELY(__VlSymsp->__Vm_dumping)) _traceDumpClose();\n"); puts("#endif // VM_TRACE\n"); } } @@ -2368,7 +2368,7 @@ void EmitCImp::emitWrapEval(AstNodeModule* modp) { putsDecoration("// Tracing\n"); // SystemC's eval loop deals with calling trace, not us if (v3Global.needTraceDumper() && !optSystemC()) { - puts("if (VL_UNLIKELY(vlSymsp->__Vm_dumperp)) _traceDump();\n"); + puts("if (VL_UNLIKELY(vlSymsp->__Vm_dumping)) _traceDump();\n"); } puts("#endif // VM_TRACE\n"); } @@ -2443,7 +2443,7 @@ void EmitCImp::emitWrapEval(AstNodeModule* modp) { puts(EmitCBaseVisitor::symTopAssign()+"\n"); putsDecoration("// Tracing\n"); // SystemC's eval loop deals with calling trace, not us - puts("if (VL_UNLIKELY(vlSymsp->__Vm_dumperp)) _traceDump();\n"); + puts("if (VL_UNLIKELY(vlSymsp->__Vm_dumping)) _traceDump();\n"); puts("#endif // VM_TRACE\n"); puts("}\n"); } @@ -3083,20 +3083,21 @@ class EmitCTrace : EmitCStmts { if (v3Global.needTraceDumper()) { puts("void " + topClassName() + "::_traceDumpOpen() {\n"); + puts( "VerilatedLockGuard lock(__VlSymsp->__Vm_dumperMutex);\n"); puts( "if (VL_UNLIKELY(!__VlSymsp->__Vm_dumperp)) {\n"); - puts( "VerilatedLockGuard lock(__VlSymsp->__Vm_dumperMutex);\n"); puts( "__VlSymsp->__Vm_dumperp = new " + v3Global.opt.traceClassLang() + "();\n"); puts( "const char* cp = vl_dumpctl_filenamep();\n"); puts( "trace(__VlSymsp->__Vm_dumperp, 0, 0);\n"); puts( "__VlSymsp->__Vm_dumperp->open(vl_dumpctl_filenamep());\n"); puts( "__VlSymsp->__Vm_dumperp->changeThread();\n"); + puts( "__VlSymsp->__Vm_dumping = true;\n"); puts( "}\n"); puts("}\n"); splitSizeInc(10); puts("void " + topClassName() + "::_traceDumpClose() {\n"); - // Caller checked for __Vm_dumperp non-NULL puts( "VerilatedLockGuard lock(__VlSymsp->__Vm_dumperMutex);\n"); + puts( "__VlSymsp->__Vm_dumping = false;\n"); puts( "delete __VlSymsp->__Vm_dumperp; __VlSymsp->__Vm_dumperp = NULL;\n"); puts("}\n"); splitSizeInc(10); diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 8533060a2..69dbc8ad4 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -420,6 +420,7 @@ void EmitCSyms::emitSymHdr() { if (v3Global.needTraceDumper()) { // __Vm_dumperp is local, otherwise we wouldn't know what design's eval() // should call a global dumpperp + puts("bool __Vm_dumping; // Dumping is active\n"); puts("VerilatedMutex __Vm_dumperMutex; // Protect __Vm_dumperp\n"); puts(v3Global.opt.traceClassLang() + "* __Vm_dumperp VL_GUARDED_BY(__Vm_dumperMutex); /// Trace class for $dump*\n"); @@ -590,7 +591,10 @@ void EmitCSyms::emitSymImp() { puts(symClassName()+"::"+symClassName()+"("+topClassName()+"* topp, const char* namep)\n"); puts(" // Setup locals\n"); puts(" : __Vm_namep(namep)\n"); // No leak, as gets destroyed when the top is destroyed - if (v3Global.needTraceDumper()) puts(" , __Vm_dumperp(NULL)\n"); + if (v3Global.needTraceDumper()) { + puts(" , __Vm_dumping(false)\n"); + puts(" , __Vm_dumperp(NULL)\n"); + } if (v3Global.opt.trace()) puts(" , __Vm_activity(false)\n"); puts(" , __Vm_didInit(false)\n"); puts(" // Setup submodule names\n");