"null pointer dereference "error

Hi ALL,

I have written one scoreboard code with analysis ports in it.

here is my function to write analysis port:

function void write_phy(input phy_reg_map_tr packet);
         phy_reg_map_tr p_mon;
         $cast(p_mon,packet.clone());
         //`uvm_info("SPI_SCOREABOARD", $sformatf("\nPHY transaction:\n  %S", p_mon.sprint() ) , UVM_LOW)
          phy_dataQ.push_back(p_mon);
    endfunction

In task i am writing one loop for comparison as below:

for(int i=0;i<phy_dataQ.size();i++)begin
    for(int j=1;j<phy_dataQ.size();j++)begin
    //phy_reg_map_tr pt1,pt2;
    pt1 = phy_dataQ[i];
    pt2 = phy_dataQ[j];
    if(pt1.addr_b == pt2.addr_b && pt1.reg_map_tr_mode_t == REG_MAP_READ && pt2.reg_map_tr_mode_t == REG_MAP_READ)begin
        phy_dataQ.delete(j);
    end
end
end

But it is showing the null pointer reference error in if statement. i have tried to create object handle with type_id but still it’s the same.
Please help me to debug or anything i am missing here.

Thanks in advance

In reply to chandnidodiya:

Would you please provide the complete code.

for(int i=0;i<phy_dataQ.size();i++)begin
    for(int j=1;j<phy_dataQ.size();j++)begin
    //phy_reg_map_tr pt1,pt2;
    pt1 = phy_dataQ[i];
    pt2 = phy_dataQ[j];
    if(pt1.addr_b == pt2.addr_b && pt1.reg_map_tr_mode_t == REG_MAP_READ && pt2.reg_map_tr_mode_t == REG_MAP_READ)begin
        phy_dataQ.delete(j);
    end end 

But it is showing the null pointer reference error in if statement. i have tried to create object handle with type_id but still it’s the same.
Please help me to debug or anything i am missing here.

Thanks in advance

In reply to chandnidodiya:

Its still incomplete information provided by you.
What is pt1 and pt2 here, if these are handle of a class.Then create them using new and rerun the code.

In reply to pk_94:

yes pt1 and pt2 are handles of class.
phy_reg_map_tr pt1,pt2;

I have created them using new still the same error persist!!!

In reply to chandnidodiya:

Are you sure pt1/pt2 are cvlass objects?
See

    pt1 = phy_dataQ[i];
    pt2 = phy_dataQ[j];

All what you are doing with

phy_dataQ

looks like a queue.

In reply to chandnidodiya:

Can you define the class phy_reg_map_tr ,so that it will be helpful to debug your case.
There may be two possible issues :-

  1. constructor being not called
  2. the data item being accessed is not available inside the class definition.

In reply to chandnidodiya:

for(int i=0;i<phy_dataQ.size();i++)begin
for(int j=1;j<phy_dataQ.size();j++)begin
//phy_reg_map_tr pt1,pt2;
pt1 = phy_dataQ[i];
pt2 = phy_dataQ[j];
if(pt1.addr_b == pt2.addr_b && pt1.reg_map_tr_mode_t == REG_MAP_READ && pt2.reg_map_tr_mode_t == REG_MAP_READ)begin
phy_dataQ.delete(j);
end end 

But it is showing the null pointer reference error in if statement. i have tried to create object handle with type_id but still it’s the same.
Please help me to debug or anything i am missing here.
Thanks in advance

You are deleting queue index and in next for loop again you are comparing that index which does not exist(deleted in previous for loop run)

phy_dataQ.delete(j);

That’s why you are getting null object access error in if statement.

Regards,
Supal

In reply to MayurKubavat:

I have tried to check with fatals if the objects are null or not and it’s showing pt2 as nul object.

In reply to chr_sue:

Yes, it’s queue in which i have pushed all the packets from the analysis port.