*E,TRNULLID: NULL pointer dereference

Guys,

I’m getting “NULL pointer dereference” error for the monitor to scoreboard connection…
Help me find the issue…


class mem_1r1w1bw_sb extends uvm_scoreboard;

  `uvm_component_utils(mem_1r1w1bw_sb)
  
  // Configuration object
  agent_config config_obj;
 
  `uvm_analysis_imp_decl(_rd0)
  `uvm_analysis_imp_decl(_wr0)
  `uvm_analysis_imp_decl(_wr1)

  //Analysis Import
  uvm_analysis_imp_rd0#(mem_pkt,mem_1r1w1bw_sb) sb_export_rd0;
  uvm_analysis_imp_wr0#(mem_pkt,mem_1r1w1bw_sb) sb_export_wr0;
  uvm_analysis_imp_wr1#(mem_pkt,mem_1r1w1bw_sb) sb_export_wr1;
  
  //Associative Array
  mem_pkt sb_mem[*];
  
  // Constructor
  function new(string name, uvm_component parent);
  	super.new(name, parent);
  endfunction: new
  
  // Build phase
  virtual function void build_phase(uvm_phase phase);
  	super.build_phase(phase);
  	sb_export_rd0 = new("sb_export_rd0", this);
  	sb_export_wr0 = new("sb_export_wr0", this);
  	sb_export_wr1 = new("sb_export_wr1", this);
  
  	// Propagate the configuration object
  	if(!uvm_config_db#(agent_config)::get(this, "", "config_obj", config_obj))
  		`uvm_fatal("NOCONFIG",{"Config object must be set for: ",get_full_name(),".config_obj"})
  endfunction
  
  virtual function void write_rd0(mem_pkt rcvd_item_rd0);
  	if(!(config_obj.disable_scoreboard)) begin
  		uvm_report_info(get_type_name(), $psprintf(" Read0 COMPARE HERE : ...\n %s", this.sprint()), UVM_HIGH);
  		compare_items (rcvd_item_rd0);
  	end
  endfunction : write_rd0
   virtual function void write_wr0(mem_pkt rcvd_item_wr0);
  	if(!(config_obj.disable_scoreboard)) begin
            if (rcvd_item_wr0.wr0) begin
  		uvm_report_info(get_type_name(), $psprintf(" Write0 store details : ...\n %s", this.sprint()), UVM_HIGH);
  	        sb_mem[rcvd_item_wr0.addr] = rcvd_item_wr0;
  	        uvm_report_info (get_type_name(),$psprintf("Data Write0 @ RAM : ADDR : 0x0%x  DATA : 0x0%x \n", rcvd_item_wr0.addr,rcvd_item_wr0.data),UVM_HIGH);
            end
  	end
  endfunction : write_wr0
    virtual function void write_wr1(mem_pkt rcvd_item_wr1);
  	if(!(config_obj.disable_scoreboard)) begin
            if (rcvd_item_wr1.wr1) begin
                mem_pkt clone_pkt;
                $cast(clone_pkt, rcvd_item_wr1.clone());
  		uvm_report_info(get_type_name(), $psprintf("Write1 Store details : ...\n %s", this.sprint()), UVM_HIGH);
                clone_pkt.data = ((sb_mem[clone_pkt.addr].data & (~clone_pkt.bwe)) | (clone_pkt.data & clone_pkt.bwe));
  	        sb_mem[clone_pkt.addr] = clone_pkt;
  	        uvm_report_info (get_type_name(),$psprintf("Data Write1 @ RAM : ADDR : 0x0%x  DATA : 0x0%x \n", clone_pkt.addr,clone_pkt.data),UVM_HIGH);
            end
  	end
  endfunction : write_wr1
...
endclass

class mem_1r1w1bw_wr1_mon extends uvm_monitor;
...
    virtual protected task collect_transactions();
      trans_collected_w1.wr1 = vif.mem_wr1.wr;
      trans_collected_w1.addr = vif.mem_wr1.waddr;
      trans_collected_w1.data = vif.mem_wr1.wdata;
      trans_collected_w1.bwe = vif.mem_wr1.bwe;
      `uvm_info(get_full_name(),"Transfer collected :\n",UVM_LOW)
      trans_collected_w1.print();

     mon_ap.write(trans_collected_w1);

    endtask : collect_transactions
..
endclass

class mem_1r1w1bw_tb extends uvm_env;
...
    //Connect phase
    virtual function void connect_phase(uvm_phase phase);
       `uvm_info(get_full_name()," @ Connect Phase ",UVM_NONE);
       super.connect_phase(phase);
       //virtual sequencer connection
       memvseqr.memseqr_rd0 = mem_env.rd0_agent.rd0_seqr;
       memvseqr.memseqr_wr0 = mem_env.wr0_agent.wr0_seqr;
       memvseqr.memseqr_wr1 = mem_env.wr1_agent.wr1_seqr;

      //Connect the analysis ports
      mem_env.rd0_agent.rd0_mon.mon_ap.connect(scoreboard.sb_export_rd0);
      mem_env.wr0_agent.wr0_mon.mon_ap.connect(scoreboard.sb_export_wr0);
      mem_env.wr1_agent.wr1_mon.mon_ap.connect(scoreboard.sb_export_wr1);

    endfunction

endclass

You have not indicated which line caused the error so not much to go on.

The process I would follow is:
(1) look at the error message closely. Identify which line of code triggered it. Is it a handle to ‘structure’ or to ‘data’ that is missing?
(2) use your simulator debugger to set a breakpoint on that line and inspect the value of class handles at that time, or edit your code and add assert(xx != null) statements prior to that line to determine WHICH handle is unexpectedly null.

…or…

(1) is this the first time this analysis port hookup has been developed/used? Investigate the ‘usual suspects’:
- do your AP objects exist correctly in the monitors prior to you calling connect() on them - does rd0_mon and wr0_mon etc constructor or build_phase() call new() to create ‘mon_ap’
- are your exports visible? You have invoked macro declarations ‘uvm_analysis_imp_decl’ inside your scoreboard class. Some simulator versions may require these 3 lines to be moved outside the class declaration (although in most cases that would be a compile error not a runtime error)

In general, when you have a line like ‘myenv.myagent.mymon.myap.connect()’ causing a problem, just go through each of those handles in turn and determine which are definitely OK, and which need further investigation. The error message from your simulator should give you sufficient information to get started…

Gordon,

I’m getting error on

virtual function void write_wr1(mem_pkt rcvd_item_wr1);

at scoreboard.

When I comment the

mon_ap.write(trans_collected_w1);

line at monitor, works well and ending properly.

I did this connection as like other analysis port connection, why am I getting “NULL pointer dereference” error for this port only?

John

OK, so it’s data rather than hookup… but the error message indicates a line of code that is not particularly helpful.

Looks like your exports were constructed OK. So…

  1. Is your ‘mon_ap’ constructed with new() in the wr1_mon. Where? (in wr1_mon’s new() or build_phase()?
  2. Try again with the 3 _decl macros invoked outside the class, not inside.
  3. use breakpoints and assert() in your code until you find it.

Good luck!

In reply to John Verif:

John,
Have you created the object trans_collected_w1 (with new method ) or just declared it ?
I don’t see this object being created in the virtual protected task “collect_transaction” or anywhere else in the code.