diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index a244b9e48..a08dea624 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -2059,7 +2059,10 @@ vpiHandle vpi_handle_by_name(PLI_BYTE8* namep, vpiHandle scope) { const VerilatedScope* scopep; const VerilatedVpioScope* const voScopep = VerilatedVpioScope::castp(scope); std::string scopeAndName = namep; - if (voScopep) { + if (0 == std::strncmp(namep, "$root.", std::strlen("$root."))) { + namep += std::strlen("$root."); + scopeAndName = namep; + } else if (voScopep) { const bool scopeIsPackage = VerilatedVpioPackage::castp(scope) != nullptr; scopeAndName = std::string{voScopep->fullname()} + (scopeIsPackage ? "" : ".") + namep; namep = const_cast(scopeAndName.c_str()); diff --git a/test_regress/t/t_vpi_package.cpp b/test_regress/t/t_vpi_package.cpp index c2ba1eb52..c36b28f1e 100644 --- a/test_regress/t/t_vpi_package.cpp +++ b/test_regress/t/t_vpi_package.cpp @@ -120,6 +120,7 @@ int mon_check() { CHECK_RESULT_Z(check_handle(const_cast("someOtherInt"), tHandle)) CHECK_RESULT_Z(check_handle(const_cast("t.someOtherInt"), NULL)) + CHECK_RESULT_Z(check_handle(const_cast("$root.t.someOtherInt"), NULL)) CHECK_RESULT_Z(check_handle(const_cast("someString"), tHandle)) CHECK_RESULT_Z(check_handle(const_cast("t.someString"), NULL)) CHECK_RESULT_Z(check_handle(const_cast("someInt"), pkgHandle))