Systemverilog inheritance question

I have below code with some parent/child class definition (all of them are sequences)


class A;
  my_ral_block  my_block;
  task pre_start();
    uvm_config_db#(my_ral_block)::get(null, "*", "my_ral_block", my_block);
  endtask;
  task body();
    ...
  endtask;
endclass

class B extends A;
  task pre_start();
    super.pre_start();
    ...
  endtask;
  task body();
    super.body();
    ...
  endtask;
  taak my_func();
    my_block.my_reg.write();
    ....
  endtask
endclass

class C extends A;
  B my_b;
  task pre_start();
    super.pre_start();
    my_b = new();
  endtask;
  task body();
    super.body();
    my_b.my_func();
    ...
  endtask;
endclass

And I got the error is Error-[NOA] Null object access in the code my_b.my_func() in class C. I don’t know how to fix this. Can anyone help me on this ?

In reply to zz8318:

This likely has nothing to do with inheritance, rather the way sequence C get started without calling pre_start(). If you are going to use pre_body and pre_start (which we recommend you avoid and just use the class constructor new() ) you need to understand the rules about when the do or do not get called.

check → ‘uvm_config_db#(my_ral_block)::get…’ executed after corresponding ‘uvm_config_db…set’ and my_block is not NULL by using +UVM_CONFIG_DB_TRACE.

Better to code it like -


if( !uvm_config_db#(my_ral_block)::get(null, "*", "my_ral_block", my_block) ) begin
    `uvm_fatal(get_name(), "my_block handle is NULL");
end

https://letuslearnsv.com/

In reply to dave_59:

hi Dave, I’m pretty sure the pre_start() of C is executed because I added some print information there.

are you recommending to not use pre_start() ?

In reply to zz8318:

You need to determine which class variable is null when you try to reference it. The way you transcribed the error message is not clear. Try easySV’s suggestion.

We recommend not using pre_start unless you understand and need the functionality of it not being called in certain cases. Otherwise, just put the code in new().