Debugging in verification, the art and the science: symptom, clues, checkpoints, root cause, The Art of Verification
| | |

Debugging in Verification: The Art and Science of Finding the Real Bug

In short: A failing test shows you a symptom, not a cause. Finding the cause takes two things. The science is a method you can repeat: reproduce, start from the first error, split the problem in half, change one thing at a time. The art is judgment: noticing what the failures have in common, guessing where to look first, and knowing when a clue is pointing at the wrong place. In this lesson a 3-stage UVM pipeline has three bugs that look the same at the output. Clues narrow each one down, and checkpoints between the stages show exactly where each one lives.

Why is debugging both an art and a science?

Because the scoreboard only tells you where the bug was noticed, and that is almost never where it was made.

A wrong value at the output of a chip has travelled. It was created in one stage, carried through the next ones, maybe mixed with good data, and only then compared with a model. By the time the test fails, the bug is many cycles and several blocks away from the line that reports it.

The science gets you closer step by step. Start from the first error. Make the failure happen again. Cut the path in half and check which half is wrong. That works every time, but it can be slow.

The art makes it fast. An experienced engineer looks at a list of failures and says: they all happen when one packet follows another with no gap. That guess is often right, and it saves hours. But a guess is a hypothesis, not a proof. Sometimes two different bugs share the same clue, and only the method can tell them apart.

You need both. This lesson shows each one on a real bench.

The picture: a stain on the ceiling

You see a brown stain on your living room ceiling. The stain is the symptom.

A beginner paints over it, or tears open the ceiling right there. The water is coming from somewhere else: it ran along a beam from the bathroom next door.

A good plumber does two things.

  • Judgment. In a house this age, leaks usually start at the shower seal. Check there first.
  • Method. Close the valves one section at a time and watch which one stops the drip.

The guess is quick and often right. The valves are slower, but they never lie. A testbench needs both: clues to guess where to look, and checkpoints that work like the valves.

What will you learn in this lesson?

By the end of this lesson you will be able to:

  • Tell a symptom from a cause, and explain why they are usually far apart.
  • Use the scientific loop: reproduce, start from the first error, one hypothesis, one change.
  • Read the failures as clues: find what the failing transactions have in common.
  • Know when a clue is misleading, and when to switch from guessing to checking.
  • Add checkpoints between stages in a UVM bench so the bench tells you where a bug lives.

What is the science side of debugging?

It is a loop you can run on any failure, even one you do not understand yet:

  1. Reproduce it. Same test, same seed, same options. A failure you cannot repeat cannot be fixed with confidence.
  2. Start from the first error. One bug often causes a flood of later errors. The first one is closest to the cause.
  3. Form one hypothesis. Write it as a sentence you can prove wrong: the length is wrong because the counter is too narrow.
  4. Test it with one change. Add one check, one print or one directed test. Change two things at once and you learn nothing.
  5. Split the path. Check the data halfway along. If it is already wrong there, the bug is in the first half. If not, the second.
  6. Repeat until one place is left. Then shrink it to the shortest test that still fails, and keep that test.

The Practical Verification Debug Guide walks through this method in detail, with a UVM bench built to explain its own failures. This lesson is about the other half: the judgment that tells you where to point the method first.

Diagram: the science of debugging is a six-step loop (reproduce, start from the first error, one hypothesis, one change, split the path, repeat), and the art is judgment (read failures as a list, know where bugs live, doubt your favourite theory, talk it through, know when to stop guessing). Both lead to a proven root cause.
Judgment tells the method where to look; the method proves the judgment right or wrong.

What is the art side of debugging?

It is everything the method cannot give you on its own:

  • Seeing patterns. What do the failing transactions have in common? Same length? Same address? Same gap before them? A list of failures is full of clues if you read it as a list, not one by one.
  • Knowing where bugs live. Bugs gather at edges: back-to-back traffic, the first and last beat, counters that wrap, resets, the moment a buffer fills. Experience is mostly knowing these places.
  • Doubting your favourite theory. A clue narrows the search. It does not prove anything. Two different bugs can leave the same clue.
  • Talking it through. Explaining the failure to a colleague, out loud, often shows you the gap in your own story before they say a word.
  • Knowing when to stop guessing. If three guesses in a row are wrong, go back to the method and split the path.

Why is the symptom so far from the cause?

SymptomCause
WhereThe checker that noticed, often at the outputThe block that made the wrong value
WhenWhen the result was comparedCycles or packets earlier
What it tells youSomething is wrongWhat to fix

In a pipeline, a value made wrong in the first stage can travel through every stage after it before anyone compares it. The more stages, the further apart the two are.

Diagram: a 3-stage pipeline (S1 framer, S2 accumulator, OUT formatter) with checkpoints after S1 and S2 and an end-to-end check at the output. For BUG=1 the cause is in S1 when packet B starts, but the end-to-end check only fires when packet B ends at the output.
The output tells you something is wrong; a checkpoint tells you where.

How do checkpoints split the problem for you?

A checkpoint compares the data at a stage boundary with the same reference model the scoreboard uses. Put one after each stage. Now the first checkpoint that disagrees, with all the ones before it still agreeing, owns the bug.

In a block-level bench you can probe internal signals directly. In a subsystem bench you put passive monitors on the internal interfaces between blocks. Either way it is the valves in the picture: each one tells you which side of it the leak is on.

How do you find three bugs that look the same?

Let’s debug a small IP on a real UVM bench, the way you would on a project: symptom first, then clues, then proof.

The IP: a 3-stage packet pipeline

  • Packets come in one byte per cycle, with in_sop on the first byte and in_eop on the last. A 1-byte packet has both on the same cycle. Packets are 1 to 40 bytes long.
  • S1, the framer, registers each byte and its flags.
  • S2, the accumulator, adds up the length and the sum of the bytes, and produces one result per packet.
  • OUT, the formatter, drives out_valid for one cycle with out_len and out_sum.
  • Results come out in packet order, and out_len is never 0.

This shape, a few registered stages that each do one job, is how most datapaths are built, so the debug habits here carry over to real blocks.

The three bugs

  • +BUG=1, in S1: when a packet starts on the cycle right after the previous one ended, S1 drops the start-of-packet flag. S2 then adds the new packet onto the old one.
  • +BUG=2, in S2: the length counter is 5 bits wide, so packets longer than 31 bytes report the wrong length.
  • +BUG=3, in OUT: when two packets finish on back-to-back cycles, OUT keeps its old value for the second one.

All three show up the same way at the output: a packet with the wrong length or sum. That is the point. The symptom does not tell you which bug you have.

How does the bench report a failure?

The test sends 300 random packets, 1 to 40 bytes, with 0 to 3 idle cycles between them. A reference model written from the spec predicts the length and sum of every packet. At the end, the scoreboard prints three views of the same run:

LineWhat it showsWhich side of debugging
E2EMismatches at the output, with the first two failing packetsThe symptom
CLUESWhat the failing packets have in common: no gap before them, 1 byte long, longer than 31 bytesThe art: patterns
LOCATEHow many times each checkpoint (after S1, after S2, at OUT) disagreed with the model, and which one disagreed firstThe science: splitting the path

An assertion in the interface, A_LEN_NONZERO, checks the one rule that must hold every cycle: a result never has length 0.

Diagram: UVM testbench architecture for the debug pipeline. tav_debug_test sends 300 random packets. The agent drives the packet pins and samples the outputs plus probes on the S1 and S2 boundaries through tav_pipe_if, which carries the A_LEN_NONZERO and A_NO_X assertions. The scoreboard holds the reference model, checkpoints S1 and S2, the end-to-end check, and the CLUES and LOCATE reports.
A normal UVM bench plus two checkpoints on the stage boundaries.

The code

This file, with its expected output, is also on GitHub in the course repo: tav-verification-basics, 06-debugging.

One file, UVM 1.2, every name starting with tav_. Paste it into EDA Playground, pick Synopsys VCS with UVM 1.2, set the top module to tav_top, and run. Add +BUG=1, +BUG=2 or +BUG=3 to switch a bug on.

// tav_debug_pipe_uvm.sv : three bugs, one symptom; clues and checkpoints find where each one lives (UVM 1.2)
// Run on Synopsys VCS X-2025.06-SP1 with UVM 1.2 (EDA Playground), 24 Nov 2026.
// The Art of Verification | theartofverification.com
//
// EDA Playground: Synopsys VCS, UVM 1.2, top module "tav_top".
// Paste this whole file into testbench.sv and leave design.sv empty.
//
// The design is a 3-stage packet pipeline: S1 framer, S2 accumulator, OUT formatter.
// For every packet it reports the length and the sum of its bytes.
// The test sends 300 random packets (1 to 40 bytes, 0 to 3 idle cycles between them).
// At the end the scoreboard prints three views of the same run:
//   E2E     the end-to-end check at the output: the symptom
//   CLUES   what the failing packets have in common: the detective's view
//   LOCATE  checkpoints between stages: which stage went wrong first
//
// Run options (one per run):
//   (none)    the clean design
//   +BUG=1    S1 drops the start-of-packet flag when a packet follows the previous one with no gap
//   +BUG=2    S2 counts length with 5 bits, so packets longer than 31 bytes report the wrong length
//   +BUG=3    OUT keeps its old value when two packets finish on back-to-back cycles
//
// Spec:
//   A packet is a run of beats with in_valid = 1, the first with in_sop = 1, the last with in_eop = 1.
//   A 1-byte packet has in_sop = in_eop = 1 on the same beat. Packets are 1 to 40 bytes.
//   For each packet, out_valid pulses once with out_len = number of bytes and out_sum = sum of bytes.
//   Results come out in packet order. out_len is never 0.
//   rst_n (async, active low) clears the pipeline.

`timescale 1ns/1ns
`include "uvm_macros.svh"
import uvm_pkg::*;

// ---------------------------------------------------------------------------
// The design
// ---------------------------------------------------------------------------
module tav_pkt_pipe (input  logic        clk, rst_n,
                     input  logic        in_valid, in_sop, in_eop,
                     input  logic [7:0]  in_data,
                     output logic        out_valid,
                     output logic [5:0]  out_len,
                     output logic [15:0] out_sum,
                     input  int          bug);
  // S1 framer: registers each beat
  logic       s1_valid, s1_sop, s1_eop, last_eop;
  logic [7:0] s1_data;
  // S2 accumulator: running length and sum, one result per packet
  logic [5:0]  acc_len, s2_len, nl;
  logic [15:0] acc_sum, s2_sum, ns;
  logic        s2_done;
  // OUT formatter
  logic        busy;

  always_ff @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      s1_valid <= 0; s1_sop <= 0; s1_eop <= 0; s1_data <= 0; last_eop <= 0;
    end else begin
      s1_valid <= in_valid;
      s1_sop   <= in_sop && !(bug == 1 && last_eop);                 // BUG=1
      s1_eop   <= in_eop;
      s1_data  <= in_data;
      last_eop <= in_valid && in_eop;
    end
  end

  always_comb begin
    nl = s1_sop ? 6'd1 : acc_len + 6'd1;
    if (bug == 2) nl = {1'b0, nl[4:0]};                               // BUG=2
    ns = s1_sop ? {8'd0, s1_data} : acc_sum + s1_data;
  end

  always_ff @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      acc_len <= 0; acc_sum <= 0; s2_done <= 0; s2_len <= 0; s2_sum <= 0;
    end else begin
      s2_done <= 0;
      if (s1_valid) begin
        acc_len <= nl; acc_sum <= ns;
        if (s1_eop) begin
          s2_done <= 1; s2_len <= nl; s2_sum <= ns;
        end
      end
    end
  end

  always_ff @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      out_valid <= 0; out_len <= 0; out_sum <= 0; busy <= 0;
    end else begin
      out_valid <= s2_done;
      busy      <= s2_done;
      if (s2_done && !(bug == 3 && busy)) begin                       // BUG=3
        out_len <= s2_len; out_sum <= s2_sum;
      end
    end
  end
endmodule

// ---------------------------------------------------------------------------
// Interface: pins plus probes on the stage boundaries; the monitor samples before each edge
// ---------------------------------------------------------------------------
interface tav_pipe_if (input logic clk);
  logic        rst_n, in_valid, in_sop, in_eop, out_valid;
  logic [7:0]  in_data;
  logic [5:0]  out_len;
  logic [15:0] out_sum;
  // probes (driven from tav_top)
  logic        s1_valid, s1_sop, s1_eop, s2_done;
  logic [7:0]  s1_data;
  logic [5:0]  s2_len;
  logic [15:0] s2_sum;
  clocking mon_cb @(posedge clk);
    default input #1step;
    input rst_n, in_valid, in_sop, in_eop, in_data, out_valid, out_len, out_sum,
          s1_valid, s1_sop, s1_eop, s1_data, s2_done, s2_len, s2_sum;
  endclocking

  A_LEN_NONZERO: assert property (@(posedge clk) disable iff (!rst_n) out_valid |-> out_len != 0)
    else `uvm_error("SVA", $sformatf("A_LEN_NONZERO: out_valid with out_len=0 (out_sum=%0d)", $sampled(out_sum)))
  A_NO_X:        assert property (@(posedge clk) disable iff (!rst_n) !$isunknown(out_valid))
    else `uvm_error("SVA", "A_NO_X: out_valid is X")
endinterface

// ---------------------------------------------------------------------------
// Transactions: a packet for the driver, a cycle snapshot from the monitor
// ---------------------------------------------------------------------------
class tav_pkt_item extends uvm_sequence_item;
  rand int unsigned len, gap;
  rand bit [7:0]    data[];
  bit               rst;
  constraint c_len  { len dist {1 := 10, [2:31] :/ 60, [32:40] :/ 30}; }
  constraint c_gap  { gap dist {0 := 30, [1:3] :/ 70}; }
  constraint c_data { data.size() == len; }
  `uvm_object_utils(tav_pkt_item)
  function new(string name = "tav_pkt_item");
    super.new(name);
  endfunction
endclass

class tav_cycle_item extends uvm_object;
  bit          rst, in_valid, in_sop, in_eop, out_valid, s1_valid, s1_sop, s1_eop, s2_done;
  bit   [7:0]  in_data, s1_data;
  logic [5:0]  out_len, s2_len;
  logic [15:0] out_sum, s2_sum;
  `uvm_object_utils(tav_cycle_item)
  function new(string name = "tav_cycle_item");
    super.new(name);
  endfunction
endclass

// ---------------------------------------------------------------------------
// Sequences
// ---------------------------------------------------------------------------
class tav_reset_seq extends uvm_sequence #(tav_pkt_item);
  `uvm_object_utils(tav_reset_seq)
  function new(string name = "tav_reset_seq");
    super.new(name);
  endfunction
  task body();
    req = tav_pkt_item::type_id::create("req");
    start_item(req);
    req.rst = 1;
    finish_item(req);
  endtask
endclass

class tav_pkt_seq extends uvm_sequence #(tav_pkt_item);
  `uvm_object_utils(tav_pkt_seq)
  int unsigned n = 300;
  function new(string name = "tav_pkt_seq");
    super.new(name);
  endfunction
  task body();
    repeat (n) begin
      req = tav_pkt_item::type_id::create("req");
      start_item(req);
      if (!req.randomize()) `uvm_fatal("RAND", "randomize failed")
      finish_item(req);
    end
  endtask
endclass

// ---------------------------------------------------------------------------
// Driver: drives on the falling edge; gap idle cycles, then the packet's beats
// ---------------------------------------------------------------------------
class tav_pipe_driver extends uvm_driver #(tav_pkt_item);
  `uvm_component_utils(tav_pipe_driver)
  virtual tav_pipe_if vif;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    if (!uvm_config_db#(virtual tav_pipe_if)::get(this, "", "vif", vif))
      `uvm_fatal("NOVIF", "no virtual interface")
  endfunction
  task idle();
    @(negedge vif.clk);
    vif.in_valid <= 0; vif.in_sop <= 0; vif.in_eop <= 0;
  endtask
  task run_phase(uvm_phase phase);
    vif.rst_n <= 0; vif.in_valid <= 0; vif.in_sop <= 0; vif.in_eop <= 0; vif.in_data <= 0;
    forever begin
      seq_item_port.try_next_item(req);
      if (req == null) idle();
      else begin
        if (req.rst) begin
          @(negedge vif.clk);
          vif.rst_n <= 0; vif.in_valid <= 0; vif.in_sop <= 0; vif.in_eop <= 0;
          @(negedge vif.clk);
          vif.rst_n <= 1;
        end else begin
          repeat (req.gap) idle();
          foreach (req.data[i]) begin
            @(negedge vif.clk);
            vif.in_valid <= 1;
            vif.in_sop   <= (i == 0);
            vif.in_eop   <= (i == req.len - 1);
            vif.in_data  <= req.data[i];
          end
        end
        seq_item_port.item_done();
      end
    end
  endtask
endclass

// ---------------------------------------------------------------------------
// Monitor: one snapshot per clock of the pins and the stage probes
// ---------------------------------------------------------------------------
class tav_pipe_monitor extends uvm_monitor;
  `uvm_component_utils(tav_pipe_monitor)
  virtual tav_pipe_if vif;
  uvm_analysis_port #(tav_cycle_item) ap;
  function new(string name, uvm_component parent);
    super.new(name, parent);
    ap = new("ap", this);
  endfunction
  function void build_phase(uvm_phase phase);
    if (!uvm_config_db#(virtual tav_pipe_if)::get(this, "", "vif", vif))
      `uvm_fatal("NOVIF", "no virtual interface")
  endfunction
  task run_phase(uvm_phase phase);
    forever begin
      tav_cycle_item t;
      @(vif.mon_cb);
      t = tav_cycle_item::type_id::create("t");
      t.rst       = (vif.mon_cb.rst_n !== 1'b1);
      t.in_valid  = vif.mon_cb.in_valid;  t.in_sop = vif.mon_cb.in_sop;  t.in_eop = vif.mon_cb.in_eop;
      t.in_data   = vif.mon_cb.in_data;
      t.s1_valid  = vif.mon_cb.s1_valid;  t.s1_sop = vif.mon_cb.s1_sop;  t.s1_eop = vif.mon_cb.s1_eop;
      t.s1_data   = vif.mon_cb.s1_data;
      t.s2_done   = vif.mon_cb.s2_done;   t.s2_len = vif.mon_cb.s2_len;  t.s2_sum = vif.mon_cb.s2_sum;
      t.out_valid = vif.mon_cb.out_valid; t.out_len = vif.mon_cb.out_len; t.out_sum = vif.mon_cb.out_sum;
      ap.write(t);
    end
  endtask
endclass

// ---------------------------------------------------------------------------
// Scoreboard: reference model from the spec, three views of the result
// ---------------------------------------------------------------------------
typedef struct { int len; int sum; int gap; int num; } tav_pkt_exp_t;

class tav_pipe_scoreboard extends uvm_scoreboard;
  `uvm_component_utils(tav_pipe_scoreboard)
  uvm_analysis_imp #(tav_cycle_item, tav_pipe_scoreboard) imp;

  tav_pkt_exp_t q_s2[$], q_out[$];
  tav_cycle_item prev;
  int  cur_len, cur_sum, cur_gap, idle_run, pkt_num;
  int  packets, e2e_fails, shown;
  int  clue_b2b, clue_len1, clue_long;
  int  s1_fails, s2_fails, out_fails;
  time s1_first, s2_first, out_first;

  function new(string name, uvm_component parent);
    super.new(name, parent);
    imp = new("imp", this);
    idle_run = 99;
  endfunction

  function void note(ref int fails, ref time first);
    if (fails == 0) first = $time;
    fails++;
  endfunction

  function void write(tav_cycle_item t);
    if (t.rst) begin
      q_s2.delete(); q_out.delete(); prev = null; idle_run = 99;
      return;
    end
    // Checkpoint S1: each beat should appear one cycle later, unchanged
    if (prev != null && (t.s1_valid !== prev.in_valid ||
        (prev.in_valid && (t.s1_sop !== prev.in_sop || t.s1_eop !== prev.in_eop || t.s1_data !== prev.in_data))))
      note(s1_fails, s1_first);
    // Checkpoint S2: one result per packet, in order
    if (t.s2_done) begin
      if (q_s2.size() == 0) note(s2_fails, s2_first);
      else begin
        tav_pkt_exp_t e = q_s2.pop_front();
        if (t.s2_len !== e.len[5:0] || t.s2_sum !== e.sum[15:0]) note(s2_fails, s2_first);
      end
    end
    // End to end at the output: this is the symptom a plain scoreboard reports
    if (t.out_valid) begin
      packets++;
      if (q_out.size() == 0) begin
        note(out_fails, out_first); e2e_fails++;
        `uvm_error("E2E", "out_valid with no packet expected")
      end else begin
        tav_pkt_exp_t e = q_out.pop_front();
        if (t.out_len !== e.len[5:0] || t.out_sum !== e.sum[15:0]) begin
          note(out_fails, out_first); e2e_fails++;
          if (e.gap == 0) clue_b2b++;
          if (e.len == 1) clue_len1++;
          if (e.len > 31) clue_long++;
          if (shown < 2) begin
            shown++;
            `uvm_error("E2E", $sformatf("packet %0d: out_len=%0d out_sum=%0d, expected len=%0d sum=%0d",
                       e.num, t.out_len, t.out_sum, e.len, e.sum))
          end
        end
      end
    end
    // Reference model from the spec, fed by the input pins
    if (t.in_valid) begin
      if (t.in_sop) begin cur_len = 1; cur_sum = t.in_data; cur_gap = idle_run; end
      else          begin cur_len++;   cur_sum += t.in_data; end
      if (t.in_eop) begin
        tav_pkt_exp_t e;
        pkt_num++;
        e.len = cur_len; e.sum = cur_sum; e.gap = cur_gap; e.num = pkt_num;
        q_s2.push_back(e); q_out.push_back(e);
        idle_run = 0;
      end
    end else if (idle_run < 99) idle_run++;
    prev = t;
  endfunction

  function void report_phase(uvm_phase phase);
    string where;
    int sva = uvm_report_server::get_server().get_id_count("SVA");
    `uvm_info("E2E", $sformatf("packets=%0d mismatches=%0d assertion_fails=%0d -> %s",
              packets, e2e_fails, sva, (e2e_fails == 0 && sva == 0) ? "PASS" : "FAIL"), UVM_NONE)
    `uvm_info("CLUES", $sformatf("failing packets=%0d: back_to_back=%0d one_byte=%0d longer_than_31=%0d",
              e2e_fails, clue_b2b, clue_len1, clue_long), UVM_NONE)
    if (s1_fails + s2_fails + out_fails == 0) where = "none, every checkpoint agrees with the model";
    else if (s1_fails > 0 && (s2_fails == 0 || s1_first <= s2_first) && (out_fails == 0 || s1_first <= out_first))
      where = $sformatf("S1 framer at %0t", s1_first);
    else if (s2_fails > 0 && (out_fails == 0 || s2_first <= out_first))
      where = $sformatf("S2 accumulator at %0t", s2_first);
    else where = $sformatf("OUT formatter at %0t", out_first);
    `uvm_info("LOCATE", $sformatf("checkpoint fails: S1=%0d S2=%0d OUT=%0d, first divergence: %s",
              s1_fails, s2_fails, out_fails, where), UVM_NONE)
  endfunction
endclass

// ---------------------------------------------------------------------------
// Agent, environment, test
// ---------------------------------------------------------------------------
class tav_pipe_agent extends uvm_agent;
  `uvm_component_utils(tav_pipe_agent)
  uvm_sequencer #(tav_pkt_item) sqr;
  tav_pipe_driver  drv;
  tav_pipe_monitor mon;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    sqr = uvm_sequencer#(tav_pkt_item)::type_id::create("sqr", this);
    drv = tav_pipe_driver::type_id::create("drv", this);
    mon = tav_pipe_monitor::type_id::create("mon", this);
  endfunction
  function void connect_phase(uvm_phase phase);
    drv.seq_item_port.connect(sqr.seq_item_export);
  endfunction
endclass

class tav_pipe_env extends uvm_env;
  `uvm_component_utils(tav_pipe_env)
  tav_pipe_agent      agt;
  tav_pipe_scoreboard scb;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    agt = tav_pipe_agent::type_id::create("agt", this);
    scb = tav_pipe_scoreboard::type_id::create("scb", this);
  endfunction
  function void connect_phase(uvm_phase phase);
    agt.mon.ap.connect(scb.imp);
  endfunction
endclass

class tav_debug_test extends uvm_test;
  `uvm_component_utils(tav_debug_test)
  tav_pipe_env env;
  virtual tav_pipe_if vif;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    env = tav_pipe_env::type_id::create("env", this);
    if (!uvm_config_db#(virtual tav_pipe_if)::get(this, "", "vif", vif))
      `uvm_fatal("NOVIF", "no virtual interface")
  endfunction
  task run_phase(uvm_phase phase);
    tav_reset_seq r = tav_reset_seq::type_id::create("r");
    tav_pkt_seq   s = tav_pkt_seq::type_id::create("s");
    phase.raise_objection(this);
    r.start(env.agt.sqr);
    s.start(env.agt.sqr);
    repeat (6) @(vif.mon_cb);      // let the last packet drain through all three stages
    phase.drop_objection(this);
  endtask
endclass

// ---------------------------------------------------------------------------
// Top
// ---------------------------------------------------------------------------
module tav_top;
  logic clk = 0;
  int   BUG = 0;
  always #5 clk = ~clk;

  tav_pipe_if vif (clk);
  tav_pkt_pipe dut (.clk(clk), .rst_n(vif.rst_n), .in_valid(vif.in_valid), .in_sop(vif.in_sop),
                    .in_eop(vif.in_eop), .in_data(vif.in_data), .out_valid(vif.out_valid),
                    .out_len(vif.out_len), .out_sum(vif.out_sum), .bug(BUG));
  // stage-boundary probes for the checkpoints
  assign vif.s1_valid = dut.s1_valid;
  assign vif.s1_sop   = dut.s1_sop;
  assign vif.s1_eop   = dut.s1_eop;
  assign vif.s1_data  = dut.s1_data;
  assign vif.s2_done  = dut.s2_done;
  assign vif.s2_len   = dut.s2_len;
  assign vif.s2_sum   = dut.s2_sum;

  initial begin
    void'($value$plusargs("BUG=%d", BUG));
    `uvm_info("TOP", $sformatf("Running with BUG=%0d", BUG), UVM_NONE)
    uvm_config_db#(virtual tav_pipe_if)::set(null, "uvm_test_top", "vif", vif);
    uvm_config_db#(virtual tav_pipe_if)::set(null, "uvm_test_top.env.agt.*", "vif", vif);
    run_test("tav_debug_test");
  end
endmodule

What output should you expect?

With no bug switched on, this is the real log from Synopsys VCS X-2025.06-SP1 with UVM 1.2 (trimmed to the report lines):

[E2E] packets=300 mismatches=0 assertion_fails=0 -> PASS
[CLUES] failing packets=0: back_to_back=0 one_byte=0 longer_than_31=0
[LOCATE] checkpoint fails: S1=0 S2=0 OUT=0, first divergence: none, every checkpoint agrees with the model

Three hundred packets, every result right, and every checkpoint agrees with the model. Now the bugs, same bench, same 300 packets, real VCS results:

RunE2E (the symptom)CLUESLOCATE (first divergence)
No bugPASS: 0 mismatches0 failing packetsnone
+BUG=1 (S1 drops sop)FAIL: 95 mismatches, 1 assertion failall 95 back-to-back (13 one byte, 22 longer than 31)S1 framer at 1495 ns (S1=95, S2=95, OUT=95)
+BUG=2 (S2 length 5 bits)FAIL: 79 mismatches, 11 assertion failsall 79 longer than 31 (22 back-to-back)S2 accumulator at 405 ns (S1=0, S2=79, OUT=79)
+BUG=3 (OUT keeps old value)FAIL: 13 mismatchesall 13 back-to-back and all 13 one byteOUT formatter at 5625 ns (S1=0, S2=0, OUT=13)
Results grid: all three bugs fail the end-to-end check. CLUES shows BUG=1 failing only on back-to-back packets, BUG=2 only on packets longer than 31 bytes, BUG=3 only on 1-byte back-to-back packets. LOCATE puts BUG=1 in S1, BUG=2 in S2 and BUG=3 in OUT.
Same symptom for all three. The clues narrow each one down; only the checkpoints split BUG=1 from BUG=3.

Now read the three failing runs the way you would on a project: the first error, then the clues, then the checkpoints.

BUG=1: the clue points the right way

UVM_ERROR @ 1775: uvm_test_top.env.scb [E2E] packet 6: out_len=59 out_sum=7483, expected len=27 sum=3090

Do the subtraction before anything else. 59 minus 27 is 32 and 7483 minus 3090 is 4393. The extra is a whole packet’s worth of bytes, so packet 6 came out with the previous packet’s totals added on. The CLUES line agrees: all 95 failing packets started right after the previous one ended. Hypothesis: when there is no gap, the start of the new packet is lost.

LOCATE confirms it and names the stage: S1, at 1495 ns. The scoreboard only noticed at 1775 ns, when packet 6 ended. The checkpoint found the bug 28 cycles earlier, in the stage that made it.

BUG=2: the clue is most of the story

UVM_ERROR @ 415: uvm_test_top.env.scb [E2E] packet 1: out_len=4 out_sum=4317, expected len=36 sum=4317

The sum is right and the length is short by exactly 32. That smells like a counter that is too narrow. The CLUES line backs it up: all 79 failing packets are longer than 31 bytes, while only 22 of them were back-to-back, so the gap is not the pattern this time. A_LEN_NONZERO fired 11 times too, on packets of exactly 32 bytes, where a 5-bit count wraps to 0.

LOCATE says S2, at 405 ns, just 10 ns before the output. When the bug is near the end of the path, a checkpoint does not save much time. It still tells you which block to open.

BUG=3: the same clue, a different stage

UVM_ERROR @ 5625: uvm_test_top.env.scb [E2E] packet 29: out_len=4 out_sum=185, expected len=1 sum=213

This is where judgment can mislead you. CLUES says all 13 failing packets were back-to-back, the same clue as BUG=1. If you had just fixed BUG=1, your instinct would say: S1 again.

Test that hypothesis against the numbers. If S1 had dropped the start flag, S2 would have added this 1-byte packet onto the previous one, and out_sum would be bigger than 213. It is 185, smaller. The S1 theory is wrong. The output looks like an old result repeated, not a new one built wrong. And CLUES has a second fact: all 13 are also one byte long, so two packets finished on back-to-back cycles.

LOCATE settles it: S1 and S2 never disagreed with the model. S2 made the right result; OUT lost it.

Three bugs, one symptom. The clue was right about the traffic every time, and once it was wrong about the stage. Judgment told you what to look at. The checkpoints told you where.

What are the most common debugging mistakes?

MistakeWhat it looks likeFix
Fixing the symptomA patch at the output that makes the compare passAsk where the wrong value was made, not where it was seen
Starting from the last errorHours spent on error 93, which is an echo of error 1Always open the log at the first error
Trusting one clue too muchAll failures are back-to-back, so the first stage gets the blameA clue narrows the search. Confirm with a checkpoint or a directed test
Changing several things at onceA fix, a new seed and a bench change in the same runOne change per experiment, and write down what it proved
Debugging without the specArguing about what the design should do from the waveformSettle expected behaviour from the spec first, then debug
Blaming the design by defaultA day lost on RTL when the bench drove illegal stimulusCheck the stimulus and the model as suspects too
No checkpointsOnly an end-to-end scoreboard, so every bug looks the sameAdd checks at stage or block boundaries, on the same model
Not keeping the testThe bug is fixed, the short failing test is thrown awayTurn it into a directed regression test

How do you get unstuck?

  • Write the story down. One paragraph: what went in, what came out, what you expected. Gaps in the story are where the bug is.
  • Explain it to someone. You will often find the hole while you are still talking.
  • Go back one step. If three hypotheses failed, the problem is probably earlier than you think. Split the path again.
  • Take a break. A fresh look after a short walk finds things a tired one misses.

Can AI help you debug?

Yes, as a second pair of eyes for hypotheses. It is good at reading a failure report and listing possible causes. It cannot see your RTL, your waveforms or your history with this block, so it can sound sure about a cause that is not there.

Task: give an assistant the spec and the failure report from the +BUG=3 run, without telling it the bug, and ask for ranked hypotheses and the one experiment that would tell them apart.

Tool: Claude, in Anthropic’s Cowork app, 24 Nov 2026, run in a fresh session that had never seen the bench, the RTL or the bug list. It got only the prompt below.

Prompt:

You are a senior design verification engineer. Help me debug this failure.

Design: a 3-stage packet pipeline.
- S1 registers each input beat (valid, sop, eop, data).
- S2 adds up the length and byte sum of each packet and produces one result when eop arrives.
- OUT registers the result and pulses out_valid with out_len and out_sum.
Spec: one result per packet, in order. out_len = number of bytes, out_sum = sum of bytes.
Packets are 1 to 40 bytes, with 0 to 3 idle cycles between packets.

Failure report from 300 random packets:
[E2E] packet 29: out_len=4 out_sum=185, expected len=1 sum=213
[E2E] packet 55: out_len=36 out_sum=4989, expected len=1 sum=37
[E2E] packets=300 mismatches=13 assertion_fails=0 -> FAIL
[CLUES] failing packets=13: back_to_back=13 one_byte=13 longer_than_31=0
(back_to_back = the packet started on the cycle right after the previous packet ended)

1. List your top 3 hypotheses for the root cause, ranked, and the stage each points to.
2. For each, say what evidence would prove it wrong.
3. Name the one experiment that best tells them apart.
Keep it short.

Output (excerpt):

Key clue: every failure is a 1-byte packet that starts right after the previous
packet ended. That is the only way two packets can end on two cycles in a row.
Both bad outputs look like the previous packet's result coming out again.
Packet 29 can't be the old total plus the new byte, because 185 is less than 213.

H1 (OUT): the OUT register doesn't reload when results arrive on back-to-back
    cycles, e.g. it loads only when out_valid was low last cycle. out_valid still
    pulses, but out_len and out_sum keep the previous packet's values.
H2 (S2): when sop and eop arrive on the same beat, S2 picks the held totals
    instead of starting a new packet.
H3 (S1): S1 masks sop, or holds data an extra cycle, on the beat after an eop.

The one experiment: packet A, then a 1-byte packet B the next cycle, plus controls
(one idle cycle between them; a 2-byte packet back to back). Dump the S1 output,
the S2 result and the OUT output. The first stage where B's values go wrong
names the hypothesis: S1 = H3, S2 = H2, OUT = H1.

How I validated it: I checked each hypothesis against the real LOCATE line, which the assistant never saw: S1=0 S2=0 OUT=13, first divergence: OUT formatter at 5625. H1 is right, and ranked first. Its guess at the mechanism is close to the real bug too: in the RTL, OUT skips the load when it had a result on the cycle before. It also used the same arithmetic test as the walkthrough above, 185 is less than 213, to reject the merged-packet theory on its own.

Its one experiment is exactly the checkpoint idea: look at every stage boundary and find the first one that is wrong. The bench in this lesson already does that on every run, which is why the LOCATE line answered in one simulation what the assistant could only propose.

Where it fell short:

  • It could not confirm anything. It reasoned that the outputs look like the previous packet’s result and asked me to check packets 28 and 54 in the log. The log does not print them, because the scoreboard shows only the first two failures. A hypothesis is only as good as the data you can check it against.
  • It never suspected the testbench. All three hypotheses blame the design. A wrong reference model, or a monitor that samples on the wrong edge, can make the same failure report. A real engineer keeps the bench on the suspect list.
  • Some of its reasoning was soft. It called 4989 over 36 bytes “a normal byte value” as support for the stale-result theory. That proves nothing. The 185 versus 213 test was the strong part.

Use an assistant the way this run shows: let it widen your list of hypotheses and suggest the experiment, then let the checkpoints and the logs decide.

Interview questions on debugging

  • What is the difference between a symptom and a root cause? The symptom is where a problem is noticed, usually a checker at the output. The root cause is where the wrong value or behaviour was created, often several stages and many cycles earlier.
  • Why start debugging from the first error? Later errors are often echoes of the first one. The first error is closest in time to the cause.
  • How do you debug a failure in a long pipeline? Check the data at a point halfway along the path. If it is already wrong, the bug is upstream; if not, downstream. Repeat until one stage is left. Checkpoints at stage boundaries do this automatically.
  • All failing packets arrive back-to-back. Is the bug in the input stage? Not necessarily. Back-to-back traffic stresses every stage. The clue says what kind of traffic breaks the design, not which stage is broken. Confirm with checkpoints.
  • How do you know a fix is the right one? The original failing test now passes, a short directed test that hits the exact case passes, related regressions still pass, and you can explain why the fix works.
  • What would you do if a bug only fails on one seed in a thousand? Reproduce it on that seed first, find what is special about the failing traffic, then write a directed or tightly constrained test that hits that case every time.
  • When would you suspect the testbench rather than the design? When the stimulus breaks the spec, when the model disagrees with the spec, or when the failure moves when you change only bench code.

Practice challenge

Try these on the demo bench:

  1. Run +BUG=1 and +BUG=3. Both fail on back-to-back packets. Before you look at LOCATE, write down which stage you think each bug is in, and why.
  2. Remove the S1 and S2 checkpoints, so only the E2E check is left. How would you find BUG=1 now? Write the directed test you would use.
  3. Add a fourth checkpoint inside S2 that checks acc_len after every beat. For BUG=2, how many cycles earlier does it catch the bug than the S2 result check?
  4. Write a directed sequence that reproduces BUG=3 in under 10 cycles.

If your answer to step 1 was the same stage for both, the CLUES line fooled you, and you have just learned why the checkpoints exist.

Frequently asked questions

Is debugging an art or a science?

Both. The science is a repeatable method: reproduce, start from the first error, test one hypothesis at a time, split the path. The art is judgment: spotting patterns in failures and knowing where bugs usually hide. Judgment makes you fast; the method makes you right.

How do you find the root cause of a verification failure?

Reproduce it, start from the first error, and list what the failing transactions have in common. Then check the data at points along its path until you find the first place it goes wrong. That place, not the checker that noticed, holds the root cause.

What is a checkpoint in a testbench?

A check at an internal boundary, such as between two pipeline stages or two blocks, that compares the data there with the reference model. The first checkpoint that disagrees tells you which stage made the error.

Why do some bugs only appear with back-to-back traffic?

Because logic often assumes there is at least one idle cycle between transactions, to clear a flag or update a register. With no gap, that assumption breaks. Back-to-back traffic is one of the first things to test, and one of the first clues to look for.

Can AI find bugs for you?

It can suggest hypotheses from a failure report and help write checks or directed tests. It cannot see your design’s real behaviour unless you give it logs or code, and it can be confidently wrong. Treat every suggestion as a hypothesis and test it.

References and related lessons

References

Related lessons