Module 5: Configuration and Extension | Intermediate UVM

Factory Debugging

Diagnose unexpected factory behavior by tracing registration, creation, override matching, hierarchy, and the actual type constructed.

Learning objectives

  • Explain what the UVM factory is actually deciding during object and component creation.
  • Distinguish factory registration, factory creation, type overrides, and instance overrides.
  • Use uvm_factory::get().print() to inspect factory configuration.
  • Use component topology and full hierarchical names to debug instance override matching.
  • Verify the actual constructed type rather than inferring it from source code.
  • Diagnose common reasons an override does not take effect.
  • Diagnose the opposite failure: an override affects an instance that should have remained unchanged.
  • Understand why new() bypasses factory substitution.
  • Develop a repeatable workflow for resolving conflicts between type and instance overrides.
  • Recognize when the problem is factory configuration versus component configuration or implementation logic.

Step 1: Start with the symptom

Lessons 44 and 45 showed how the factory can replace implementations:

Lesson 44


type override
protocol_driver
|
+----> debug_driver

Lesson 45
instance override
protocol_driver
|
+----> command_agent.driver
error_injecting_driver

In a real verification environment, the difficult part is often not writing the override. It is answering:

  • Was the override registered?
  • Did the component actually use the factory?
  • Did the instance path match?
  • Was another override also applicable?
  • Was the override installed before construction?
  • What class was actually constructed?
Factory debugging principle: Debug the factory as a resolution process. Do not start by modifying the component that appears to have the wrong type.

Step 2: Understand what the factory controls

The factory does not magically replace every object in the testbench. A component or object must be created through a factory-aware API.

Factory-aware construction:

driver = protocol_driver::type_id::create(
"driver",
this


);

Direct construction:

driver = new("driver", this);

The second form does not ask the factory to resolve a replacement.

Factory-aware path:


requested type
|
v
UVM factory
|
+---- matching override?
|          |
|       yes/no
|          |
v          v
replacement   requested type
|
v
constructed object

This gives us the first debugging question:

Is the object actually being created through the factory?

Step 3: Verify type registration

Factory registration allows UVM to associate a SystemVerilog type with its factory representation.

For a component:

class protocol_driver extends uvm_driver #(protocol_item);


`uvm_component_utils(protocol_driver)

function new(
string name = "protocol_driver",
uvm_component parent = null
);
super.new(name, parent);
endfunction

endclass

And for the replacement:

class error_injecting_driver extends protocol_driver;


`uvm_component_utils(error_injecting_driver)

function new(
string name = "error_injecting_driver",
uvm_component parent = null
);
super.new(name, parent);
endfunction

endclass

If the requested type or replacement type is not correctly registered, factory-based construction cannot behave as intended.

Step 4: Verify the component uses type_id::create()

Consider this reusable agent:

class protocol_agent extends uvm_agent;


`uvm_component_utils(protocol_agent)

protocol_driver driver;

function new(
string name = "protocol_agent",
uvm_component parent = null
);
super.new(name, parent);
endfunction

function void build_phase(uvm_phase phase);
super.build_phase(phase);


if (is_active == UVM_ACTIVE) begin
  driver = protocol_driver::type_id::create(
    "driver",
    this
  );
end


endfunction

endclass

The important line is:

protocol_driver::type_id::create("driver", this)

The agent requests a protocol_driver. The factory is then allowed to determine the concrete implementation.

Step 5: Verify the actual type

Never assume that the type named in the source code is the type that was constructed.

UVM components provide:

get_type_name()

For example:

`uvm_info(


"FACTORY_TYPE",
$sformatf(
"Component=%s ActualType=%s",
driver.get_full_name(),
driver.get_type_name()
),
UVM_MEDIUM
)

Suppose the output is:

Component=uvm_test_top.env.command_agent.driver


ActualType=protocol_driver

Then the instance override did not produce the intended replacement.

If the output is:

Component=uvm_test_top.env.command_agent.driver


ActualType=error_injecting_driver

the factory substitution did occur, and the debugging problem has moved elsewhere.

Evidence first: The actual constructed type is stronger evidence than the intended factory configuration written in the test.

Step 6: Inspect the factory

UVM provides a factory diagnostic facility:

uvm_factory::get().print();

Use this when you need to understand what registrations and overrides are currently known to the factory.

A useful debugging sequence is:

Factory problem
  |
  v


uvm_factory::get().print()
|
+-- Is the replacement registered?
|
+-- Is a type override present?
|
+-- Is an instance override present?
|
+-- What target pattern does it use?
|
v
Compare with actual hierarchy
|
v
Verify actual constructed type

The factory printout is particularly valuable when multiple tests, base classes, or helper utilities can install overrides.

Step 7: Verify the actual UVM hierarchy

Instance overrides depend on hierarchy, so hierarchy errors are one of the most common causes of unexpected behavior.

Print the component topology:

uvm_top.print_topology();

Suppose the actual environment is:

uvm_test_top


|
+-- env
|
+-- command_agent
|    |
|    +-- driver
|
+-- response_agent
|
+-- driver

The command driver's full name is:

uvm_test_top.env.command_agent.driver

Compare this actual path with the path used by the override:

uvm_factory::get().set_inst_override_by_type(
protocol_driver::get_type(),
error_injecting_driver::get_type(),
"uvm_test_top.env.command_agent.driver"


);

A small naming difference can cause the intended instance override not to match.

Step 8: Debug an instance override that does not work

Suppose the test contains:

uvm_factory::get().set_inst_override_by_type(
protocol_driver::get_type(),
error_injecting_driver::get_type(),
"uvm_test_top.env.command_agent.driver"


);

But the actual driver remains protocol_driver.

Work through the following chain:

1. Is protocol_driver registered?
          |
          v


2. Is error_injecting_driver registered?
|
v
3. Does the agent call type_id::create()?
|
v
4. Is the override installed before driver creation?
|
v
5. Is the target path correct?
|
v
6. Does the path match the actual hierarchy?
|
v
7. Is another factory rule involved?
|
v
8. What type was actually constructed?

This prevents random changes to the environment.

Step 9: Debug an override that is too broad

The opposite problem is equally important: a test intended to change one component changes several.

For example, the test may accidentally contain:

uvm_factory::get().set_type_override_by_type(
protocol_driver::get_type(),
error_injecting_driver::get_type()


);

That is a type override, not an instance override.

If the environment creates:

command_agent.driver


response_agent.driver
monitor_agent.driver

all matching factory requests may now receive the replacement.

If the requirement is:

command_agent.driver
-> error_injecting_driver


response_agent.driver
-> protocol_driver

monitor_agent.driver
-> protocol_driver

the test needs selective instance-level substitution rather than a broad type override.

Step 10: Check override timing

Factory overrides affect factory resolution when construction occurs. They do not change an object that has already been constructed.

Install override
   |
   v


Factory-aware create()
|
v
Factory resolves request
|
v
Concrete object constructed

Therefore, this sequence is too late:

build environment
  |
  +-- driver already created
  |
  v


install factory override

Installing the override before the affected construction is the safe rule.

Step 11: Check for multiple matching overrides

Factory debugging becomes more important when a testbench contains both type-level and instance-level substitutions.

Type override:


protocol_driver
|
+----> debug_driver

Instance override:
uvm_test_top.env.command_agent.driver
|
+----> error_injecting_driver

Now there are two different kinds of factory information:

  • a broad substitution for requests of protocol_driver, and
  • a more selective substitution associated with a particular instance scope.

Do not diagnose such situations by assuming that the last line of test code automatically wins. Factory matching and override precedence determine the result.

Use:

uvm_factory::get().print();

and verify the actual constructed type.

Practical rule: When several factory rules could apply, inspect the factory's registered rules and the actual hierarchy instead of reasoning from source-code order alone.

Step 12: Understand the complete factory-debugging workflow

A reliable debugging workflow is:

Unexpected implementation
      |
      v


1. Identify requested type
   |
   v

2. Identify actual hierarchy instance
   |
   v

3. Check factory-aware construction
   |
   v

4. Check type registration
   |
   v

5. Print factory configuration
   |
   v

6. Inspect type and instance overrides
   |
   v

7. Verify override target/path
   |
   v

8. Check when override was installed
   |
   v

9. Check for competing matching rules
   |
   v

10. Verify actual constructed type
    |
    v

11. Only then inspect replacement behavior

This workflow separates factory resolution problems from bugs in the replacement component itself.

Step 13: Distinguish factory problems from configuration problems

Not every unexpected behavior is a factory problem.

Symptom Likely area
Wrong class was constructed Factory registration, override, path, or creation
Correct class, wrong timeout Configuration
Correct class, wrong virtual interface Configuration / interface binding
Correct class, incorrect protocol behavior Component implementation or stimulus
One instance unexpectedly replaced Instance override matching
All instances unexpectedly replaced Possibly a type override or broad instance pattern

This distinction prevents the factory from becoming a universal explanation for testbench failures.

Step 14: Build a small factory-debugging example

Assume the environment contains two agents:

uvm_test_top.env
    

    |
    +-- agent_a.driver
    |
    +-- agent_b.driver

The reusable agent creates:

driver = protocol_driver::type_id::create(
    

    "driver",
    this
    );

The test wants only agent B to use:

debug_driver extends protocol_driver

The override is:

uvm_factory::get().set_inst_override_by_type(
    

    protocol_driver::get_type(),
    debug_driver::get_type(),
    "uvm_test_top.env.agent_b.driver"
    );

Now verify three independent facts:

1. Factory rule exists.
    

12. Actual hierarchy contains:
    uvm_test_top.env.agent_b.driver

13. Actual types are:

    agent_a.driver -> protocol_driver
    agent_b.driver -> debug_driver

Step 15: Add useful diagnostics to reusable components

Factory debugging becomes much easier when reusable components report their actual type and hierarchy during development.

function void end_of_elaboration_phase(uvm_phase phase);
    

super.end_of_elaboration_phase(phase);

`uvm_info(
"FACTORY_TYPE",
$sformatf(
"%s constructed as %s",
get_full_name(),
get_type_name()
),
UVM_LOW
)
endfunction

This does not change factory behavior. It simply exposes useful evidence at a stable point in the UVM lifecycle.

For a reusable environment, these diagnostics can be especially useful when multiple agents use the same base class.

Step 16: Avoid hiding factory behavior

Factory overrides are powerful because reusable components do not need to know which implementation a particular test wants.

That same flexibility can make a test difficult to understand if overrides are scattered throughout helper code.

Prefer a clear ownership model:

Reusable environment
|
+-- requests base types through factory


Test
|
+-- chooses intentional substitutions

Factory
|
+-- resolves construction

Diagnostics
|
+-- verify actual result

Avoid silently installing overrides from unrelated utility code unless that behavior is explicitly part of the verification architecture.

Common mistakes

Try it yourself: factory detective

Create an environment with two agents, each containing a factory-created protocol_driver.

Create:

debug_driver extends protocol_driver

Then intentionally create three versions of the test:

  1. No override.
  2. A type override.
  3. An instance override targeting only agent_b.driver.

For every run, collect:

uvm_top.print_topology();


uvm_factory::get().print();
actual get_type_name() for both drivers

Explain why the observed types differ between the three tests.

Debugging exercise: the override did nothing

You are told that the following override is active:

uvm_factory::get().set_inst_override_by_type(
protocol_driver::get_type(),
debug_driver::get_type(),
"uvm_test_top.env.agent_b.driver"


);

But the actual type remains protocol_driver.

Investigate these possibilities in order:

  1. The driver is constructed with new().
  2. The override is installed after driver creation.
  3. The instance path is wrong.
  4. The replacement type is not registered.
  5. The actual component name differs from the assumed name.
  6. Another factory rule is affecting resolution.

Do not change the driver implementation until you have eliminated these factory-resolution causes.

Debugging exercise: the wrong instances changed

The requirement is:

agent_a.driver -> protocol_driver


agent_b.driver -> debug_driver
agent_c.driver -> protocol_driver

Instead, all three drivers become debug_driver.

Determine whether the test accidentally installed a type override, used an overly broad instance pattern, or inherited another factory rule.

Use factory diagnostics and actual type reporting to prove the cause.

Challenge: build a factory-resolution test

Create a reusable environment containing three instances of the same agent class.

Implement:

protocol_driver


debug_driver
error_injecting_driver

Create separate tests demonstrating:

  1. the default factory behavior;
  2. a type override;
  3. an instance override;
  4. an intentionally conflicting type and instance override;
  5. a broken instance path that fails to produce the expected replacement.

For every case, produce a small diagnostic table:

Instance Requested type Expected concrete type Actual concrete type Why?
agent_a.driver protocol_driver ... ... ...
agent_b.driver protocol_driver ... ... ...
agent_c.driver protocol_driver ... ... ...

Advanced extension: Move the factory override into a base test and create a derived test that adds another override. Determine which factory rules are applicable to each instance and document the resulting behavior from the factory diagnostics.

Practical debugging checklist

  1. What type was requested? Identify the base type passed to type_id::create().
  2. Where was it created? Identify the component's full hierarchical name.
  3. Was the factory used? Look for type_id::create() rather than new().
  4. Are both types registered? Check the factory registration macros.
  5. Was the override installed early enough? It must affect construction before that request is resolved.
  6. What overrides exist? Inspect uvm_factory::get().print().
  7. Does the instance path match? Compare it with the actual topology.
  8. Could another rule match? Check type and instance overrides together.
  9. What was actually constructed? Use get_type_name().
  10. Only after that: debug the behavior of the concrete implementation itself.

Knowledge check

  1. Why can an override have no effect?

    Common causes include direct construction with new(), late installation, incorrect registration, or an instance path that does not match.

  2. How do you determine the actual class that was constructed?

    Use get_type_name() on the constructed UVM object or component.

  3. What does uvm_top.print_topology() help you determine?

    It exposes the actual UVM component hierarchy and names needed when reasoning about instance-specific matching.

  4. What does uvm_factory::get().print() help you investigate?

    It provides factory information such as registered types and configured override rules.

  5. Why is new() important during factory debugging?

    Direct construction bypasses factory substitution.

  6. Why should actual type be checked before debugging driver behavior?

    Because a behavioral failure may be caused by the wrong implementation being constructed rather than by a bug in the implementation you expected to run.

  7. What is the difference between a type override and an instance override?

    A type override provides broad substitution for matching factory requests, while an instance override targets a particular hierarchy scope or instance pattern.

  8. Should factory debugging rely only on source-code order?

    No. When multiple factory rules can match, inspect the factory configuration and verify the actual constructed result.

Key takeaways

  • The factory resolves factory-aware creation requests; it does not retroactively replace existing objects.
  • type_id::create() is essential when a component is intended to be factory-overridable.
  • Registration, creation, override matching, hierarchy, and timing are separate things to verify.
  • uvm_factory::get().print() is a primary diagnostic tool for inspecting factory state.
  • uvm_top.print_topology() helps establish the real component hierarchy used by instance-specific matching.
  • get_full_name() and get_type_name() provide concrete evidence about where an object exists and what was constructed.
  • An override that does not work and an override that is too broad are different debugging problems.
  • When multiple factory rules exist, inspect the applicable rules and their matching scope rather than guessing from source-code order.
  • Factory problems should be separated from configuration problems and from bugs in the concrete implementation.
  • A good factory-debugging workflow proves the construction path and actual type before changing reusable environment code.

What comes next?

The factory sequence is now complete:

Lesson 43


Configuration Scope and Precedence
|
v
Lesson 44
Factory Type Overrides
|
v
Lesson 45
Factory Instance Overrides
|
v
Lesson 46
Factory Debugging
|
v
Lesson 47
UVM Callbacks

Lesson 44 introduced broad implementation substitution. Lesson 45 narrowed that substitution to selected hierarchy instances. Lesson 46 completes the factory topic by teaching you how to determine why the factory selected the implementation it did.

Next, Lesson 47 introduces UVM Callbacks as a different extension mechanism. Instead of replacing a component's class through the factory, callbacks allow reusable components to expose controlled extension points while keeping the original component implementation in place.