Hi all, i’m trying to get array from cpp code to my sv code and get the error:
xmsim: *F,SIGUSR: Unix Signal SIGSEGV raised from user application code. Stack trace information is captured in file sigusrdump.out.
sv code:
function void nmu_sv_get_l_y_msb_array_by_index(int index);
int result[];
result = new [100];
nmu_cpp_get_l_y_msb_array_by_index(index,p_nmu_simulator,result);
endfunction : nmu_sv_get_l_y_msb_array_by_index
import from sv:
import "DPI-C" context function void nmu_cpp_get_l_y_msb_array_by_index(int index,chandle handle, output int result[]);
cpp code:
void nmu_cpp_get_l_y_msb_array_by_index(int index,void* handle ,svOpenArrayHandle result){
myclass* p_cpp_nmu = static_cast<myclass *>(handle);
uint32_t myArray[2]= {8,10};
svPutBitArrElemVecVal(result,myArray, 1); // fail in run time in this line
}
Your issue is the declaration of ‘result’ in the SV code. You are declaring ‘result’ as a dynamic array, where the DPI is expecting a static array. These data types are different and not compatible.
You want:
function void nmu_sv_get_l_y_msb_array_by_index(int index);
int result[100];
nmu_cpp_get_l_y_msb_array_by_index(index,p_nmu_simulator,result);
endfunction : nmu_sv_get_l_y_msb_array_by_index
import "DPI-C" function void nmu_cpp_get_l_y_msb_array_by_index(int index,chandle handle, output int result[]);
module test();
function void nmu_sv_get_l_y_msb_array_by_index(int index);
int result[100];
nmu_cpp_get_l_y_msb_array_by_index(index,null,result);
endfunction : nmu_sv_get_l_y_msb_array_by_index
initial begin
nmu_sv_get_l_y_msb_array_by_index(1);
end
endmodule
I was bogged down by this error for days and finally figured out the solution… I knew I had to create an account just to document it for future travelers
Basically there were discrepancies between the compiler version of xcelium, application code, and the current gcc version in $PATH (to determine your version, just type “which gcc” in the terminal).
Once I made sure they all matched the xcelium version (in my case, gcc/9.5.0), I rebuilt the application code and set my environment variable to point to this version. Once everything was recompiled, it worked.
TL;DR: Make sure your gcc (compiler) versions match what is in your path.