Sunday, May 13, 2012

Line Debugging in Simulation



There was time when during my functional simulation, the simulator hangs at one point and does't advance. I have seen times during simulations when the time advances but nothing comes up or changes in the waveform. That happens because your design (or processor in my case) is stuck at some point like a WFI or bus-hang kind of situations but this was different. This was the time when the time in the simulation didn't advance at all.This was something new for me. I didnt know how to debug the situation or to know what part of verilog code was causing the issue.After spending some time with the issue, i came across the term "line debugging". I had heard the term with respect to C/C++ where GDB serves the same purpose just didnt know it existed for verilog simulation too. So here is how it is done for ncsim simulation(i am sure similar options exists for all other simulators):


1.Compile your code with -LINEDEBUG option in both ncverilg and ncvhdl command lines.
2.Then when the simulator hangs,hit CTRL-C on the console window
3.Type "run -step" on console and open source browser.
4.Continue running "run -step " . You see a yellow line moves on the source code indicating what part of RTL is being executed.
5.Continue running until you figure out you have been here before :-)

This way you can easily find the piece of code which may cause a loop back. In my case that piece of code looked something like this:

always @* begin
a <= a|b;
end

With the presence of * for sensitivity list, both a and b comes under it. so whenever there is an event on a or b, the block gets executed which might cause a change in a again. This is a combinational loop in the design and is forbidden.

-linedebug option i found out later causes to slow down the simulation time a lot and hence should not be used unless you are line debugging.


Happy debugging!!!



5 comments:

  1. Thanks a bundle.. this helped me figure out the problematic signal in my design causing comb. loop.
    Much appreciated !!

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. You save my day ! Thanks a million !!!

    ReplyDelete