Part 2 · Phases & Lifecycle · Intermediate
config_db Gets in build_phase
Canonical config_db set/get patterns during build — paths, types, virtual interfaces, and fail-fast diagnostics.
The config_db contract at build time
config_db is the only supported way to pass virtual interfaces, config objects, and scalar knobs into components during build_phase. Gets must match prior sets on path, name, and type.
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(apb_cfg)::get(this, "", "cfg", cfg))
`uvm_fatal("NOCFG", $sformatf("apb_cfg missing at %s", get_full_name()))
if (!uvm_config_db#(virtual apb_if)::get(this, "", "vif", vif))
`uvm_fatal("NOVIF", $sformatf("apb_if missing at %s", get_full_name()))
endfunction[PHASE][UVM] config_db triple match
SET side: uvm_config_db#(T)::set(cntxt, inst_path, field_name, value)
GET side: uvm_config_db#(T)::get(cntxt, inst_path, field_name, value)
All three must align:
1) type T
2) inst_path ("" = this component)
3) field_name stringKey takeaways
Fail fast with uvm_fatal on missing mandatory config — silent defaults hide integration bugs.
Set from test/top with broad paths; get locally with inst_path "".
Virtual interface type in get must match set exactly (including virtual keyword).
Common pitfalls
Set at "env.agt" but get at "" — path mismatch, get fails.
Set virtual apb_if but get apb_if — type parameter mismatch.
Using uvm_config_db::set without context — wrong propagation scope.
Hierarchical set patterns
Env-level components push config down to children using scoped instance paths.
Env pushes, agent pulls
class my_env extends uvm_env;
env_cfg cfg;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
void'(uvm_config_db#(env_cfg)::get(this, "", "cfg", cfg));
uvm_config_db#(env_cfg)::set(this, "*", "cfg", cfg);
agt = my_agent::type_id::create("agt", this);
endfunction
endclass[PHASE] path patterns
top → all: set(null, "*", "vif", vif)
test → env: set(this, "env", "cfg", cfg)
env → agents: set(this, "agt*", "cfg", agt_cfg)
agent local: get(this, "", "cfg", cfg)Debug helper
function void debug_config_db(string field);
uvm_config_db#(int)::dump();
if (!uvm_config_db#(apb_cfg)::get(this, "", field, cfg))
`uvm_warning("CFG",
$sformatf("get failed: comp=%s field=%s", get_full_name(), field))
endfunctionCall dump() once when a get fails — shows all entries and types.
Log get_full_name() in fatal messages for instant path triage.
Prefer one cfg object over dozens of scalar config_db fields.
[PHASE][UVM] config triage matrix
get returns 0:
→ type mismatch? check #(T) on both sides
→ path mismatch? compare set inst_path vs get context
→ set too late? setter must run before getter's build_phase
→ wrong field name? typo in "cfg" vs "config"Common pitfalls
Storing config only in plusargs without pushing to config_db before build.
Multiple competing sets with different types on the same field name.
Using get without checking return value — null cfg used silently.