Difference between revisions of "VPI DEBUG"

From Vlsiwiki
Jump to: navigation, search
(Created page with '==Retrieved on 11/25/09 from http://bbs.dicder.com/archiver/index.php?tid-499.html== <strong>5life</strong> 发表于 2006-3-13 04:41 PM</p> <h3>How to Debug PLI, DPI, and Dire…')
(No difference)

Revision as of 22:58, 25 November 2009

Retrieved on 11/25/09 from http://bbs.dicder.com/archiver/index.php?tid-499.html

5life 发表于 2006-3-13 04:41 PM</p>

How to Debug PLI, DPI, and DirectC applications using gdb

  NTRODUCTION:�Z*u�C�p

A L!K�^*k
3N:l�|#^�t'w#m�r4j
You can add new functionality to a Verilog simulator such as VCS by
*c�N:z5|�K�h�A�^ linking in your C code.  You can also call C code from OpenVera
�|�q%R�e7u�Q'Q!o6N b�a testbenches.  Perhaps you have a C model, made of routines in the file
6o�J z�N(\;b�a�f!{ w,k

model.c, and invoked with the Verilog system task $model. The C code
�U�s�x�y�h9o is known as the application, and will consist of one or more routines.:T�['R!{�d)m
The connection between the application and the simulator is the PLI,
9^�U�b�j*a�j#y�k the Programming Language Interface.  The application will be called
0E�a�x�f�u during simulation either directly, when VCS executes the system task�E�G:w�K�}-J�`(j8y X.z
for the application ($model), or asynchronously when VCS is doing an%g�D&Q�e�c*h5{3O

activity such as initialization or shutdown.
(p�A�]/d){�n7~!E
�P3`2L3n�a4S�_�X�] Alternately, you want to call a C routine such as log2() directly @*q8o1J�A�P�D%H
using VCS&#39;s DirectC interface, or the new DPI (Direct Procedural
�]�F7a�`�o�z"O Interface) that is part of SystemVerilog.  Only the linking differs.
�a�q&G�A2B&w


+O�|4@�N0f�A s$E.\�h �q�h�j d%B!}*d
COMPILING:
�B�F;Q�D.Z.|�P&p
�@:}"M�S-M ?,w You must do several steps to debug the C application.  The C code must
�D�w:h�x�Z be compiled for debug, linked with the Verilog code, the simulator ?�~�g�p�A�Q)Z9q3o9s

must be started with the debugger, and a breakpoint needs to be added�M,W3E/C�K%e5L
in the application.  This guide only covers using the GNU gcc compiler�P�s�z�]�s:i:[4F/q9P3R�|
and the matching gdb debugger.  Other tools will have a similar flow.�N�|$q�R#b�y

�J"M�z�t c�]6m First, the C code must be compiled with -g so that its debug symbols, such%N�o;m7S#x�P�I�|�e2W
as variables and routine names, will be visible at run-time.
�l�y(K,?0N&Q�`

�E/g.|2?/A�o

&nbsp; &nbsp;&gt; gcc -g -o model.c -I${VCS_HOME}/include�B6p!V-}�~�y%}


�z�b�n�e8[!t The -o switch tells gcc to create object code (model.o) and not an;_!`�h�A.V O�i
executable.  The -I switch points to the VCS include files that define
�K�c+~�c.?9H�K6{%r-e

constants and the PLI routine names.(s�U6\�v�^�|3q�W v�I&F8I B-l
�?9U�Z-w C'I�I!k"u�P
Next link the C code into your simulation:
0l�K�L,j�e�I/n x�H
�M!l�U/r�O%b3j

&nbsp; &nbsp;&gt; vcs design.v -P model.tab model.o9e�P5j�h�W'C�x


�p+u#S-@�~�| The Verilog code is in design.v, your C code is in model.o, and
*N7L�E.B0y'b�{ model.tab tells VCS which C routines to call when $model is used in)X�F6{ e:J)e'm&d9`�~
the Verilog.  This produces the executable simv.
*S�N�K�Z�G�@ �h�l�?3P�j#V�Q$T
Alternately, you can compile the Verilog and C code together.  Use the
�}�p�Z�?�|�W

VCS -CFLAGS option to pass flags to the C compiler: &gt; vcs design.v -P
�~4Q0n:^*p�i�l model.tab model.c \ -CFLAGS &quot;-g -I${VCS_HOME}/include&quot;
#P�A0U�}+r @ ] ~-I7f�j 'N�{-`,^/u�g9b�]
If you are using DirectC, you don&#39;t need a table file:1C�f&W�w�z,C O�r

$Q�h:X8_2U�O9[

&nbsp; &nbsp;&gt; vcs +dc design.v model.o	A:S3z"r�Y+c


(g�n E S [2T/Z,_6d �p!^�t7h R:B�X R

Z/O�P�_�M6K RUNNING THE DEBUGGER8u�w)f*b5p+n*N8\
:Z�z!m7h�_)Z

Now you are ready to roll!  Start the debugger and tell it which
�r�M�j�_�M"A I/a%a executable to use:�W"`�I�R�?.y�E#Q�Y�\
7f�f�s O�h�S

&nbsp; &nbsp;&gt; gdb simv
r�~�d3r,n�~9R &nbsp; &nbsp;�k%N�R�B�N
&nbsp; &nbsp;(gdb)
,m"E2`�F�i�u%D*g s


�R+H-_�q�c t Here you can set a breakpoint on a C routine: z3{!d�r�H�V�L�w�B�}#q
�y�v�b�t,E$Q�]6d,|

&nbsp; &nbsp;(gdb) br model_call
$F�b$o�|�D
&nbsp; &nbsp;Breakpoint 1 at 0x8050ba6: file model.c, line 12.
�Q�}�Q+P4J

'D�q$y'A�\�H�u1e�X
Now run the simulation, specifying the command line switches to use with simv:
*i"H�G-I1h�t
(~9g3X�w�}�Q�r$^

&nbsp; &nbsp;(gdb) run -l simv.log�o*c6r @6V&w�M�o�E�]:K
&nbsp; &nbsp;Starting program: /disk/user/simv2q3F$I�c+c�c-^�K�`
&nbsp; &nbsp;Chronologic VCS Simulator copyright 1991-20049@�^8^$R�G�P

N�X

&nbsp; &nbsp;...6M�V�f5K$u�B�X�i4c
&nbsp; &nbsp;Breakpoint 1, model_call() at model.c:12�{3?�V$b�Z

B�t

&nbsp; &nbsp;(gdb)�n-L�@�^�q�o4l

'q�j8L�{�b)m�O)V
Now you can step through the code (step and next), print variable*}�m9x:|�E)z�_(\�_
values (print and x), look at the call stack (bt) and other debugger
�z�X�R)~ B�E�S%v4A(R�g�@ tricks.  If you run gdb inside Emacs (M-X gdb) you can see the source
'k%Y1[�}�`�i�{&w&H

code in one window while the debugger runs in the other.:r�k�h�Y�^�p�D

�{�x�`�G8_1_�L8\&p This guide only shows how to debug code linked directly with VCS, not�P�c�F�h�O/@�Y�O
shareable code.  Shareable code is only loaded into memory when&q4^4W N�b g�o
needed, not at the start of execution.  So you can not set a�D1L$P1C ]�h

breakpoint on your code when gdb loads the executable as your code is4V-c�_!x�L�{6s�x)Q5}
not in memory yet.