Null pointer dereference for a register definition

Hi

I have a register definition and using a inbuilt get_n_bytes member function.

Here is the register definition.

function new(name = “REG1_type”);
super.new(.name(name), .n_bits(16), .has_coverage(UVM_CVR_REG_BITS));
void’(build_coverage(UVM_CVR_REG_BITS));
if (has_coverage(UVM_CVR_REG_BITS))
REG_REG1_cov = new();
endfunction

Its a 16 bits wide by definition.

In the checker to update the register model (when I write into this register) I use the following code.

      _register = regs.default_map.get_reg_by_offset(bus_item.cmd);
      bytes_num = _register.get_n_bytes();

Now when I simulate it I get a following error

csim: *E,TRNULLID: NULL pointer dereference.
File: checker.sv, line = 906, pos = 30

the line where the error correspond to is bytes_num = _register.get_n_bytes();

Can I not use get_n_bytes() here. Will it return 2 bytes of the REG1 register.

Any Help.

regards
Avinash

Hi,

have you double checked if the “_register.default_map.get_reg_by_offset” call was
successful?
I would suggest to change the codes as followed:


if(_register = regs.default_map.get_reg_by_offset(bus_item.cmd)) begin
   bytes_num = _register.get_n_bytes();
end else begin
   // Add your error handling here
end

Bye,

Christoph

In reply to frodus:

Hi Christoph

Thanks and you are right . That was the issue.

Seems like if else and display and uvm_info are helpful for debug in uvm. I am new to uvm and finding it difficult when i get stuck.
Debug skills is need of the hour to me.

Thanks a bunch
Avinash

In reply to Avinash:

Hi Avinash,

nice that it is now working.

You should always consider to use the “if … else” inside of a register
implementation this will make debugging of TCs a lot easier :-)

Bye,

Christoph

In reply to frodus:

Hi Christoph

Yes. Thanks for your support.
I used to debug using the waveform and now I think in UVM ,
debug using waveform is limited and lots of if …else and uvm_info
helps in debug.

regards
Avinash