?? intro.nroff
字號:
.ta 5n 10n 15n 20n 25n 30n 35n 40n 45n 50n 55n 60n.if n .po 1.25i.if t .po 1.0i.hy 14.de hd'sp 3'if \\n%-1 'tl ''- % -'''sp 2.if \\n(vq>0 .xj.nr vq 0'ns...de fo.nr vk 0.nr dn 0.nr wf \\n(.pu-\\n(nlu-\\n(vmu-1v.if \\n(vs>0 .if \\n(wf>0 .xn.if \\n(vs>0 .if \\n(wf<=0 .xo.ch fo -\\n(vmu.nr vs 0.nr vo \\n(vmu'bp...de fe.br.di.ev.if \\n(vs=1 .nr dn +1v.nr vo +\\n(dnu.nr dn 0.if \\n(vou>=\\n(.pu-\\n(nlu-.5v .nr vo \\n(.pu-\\n(nlu-.5v.if \\n(vou<\\n(vmu .nr vo \\n(vmu.ch fo -\\n(vou...de xj.nr vs 1.nr vn 1.di.ev 1.da zb.ns.za.zc.fe.rm za.rm zc...de xn.ev 1'in 0'ti 0.ie \\n(vn \l\|6.0i\(ru\|.el \l\|15\(ru\|.nr vn 0.br.ns.zb.br.di.rm zb.nr vq \\n(dnu.nr dn 0.nr vs 0.ev...de xo.ev 1.di zc.zb.br.di.rm zb.nr vq \\n(dnu.nr dn 0.nr vs 0.nr vn 1.ev...de xp.di za...nr vm 6v.nr vo \n(vmu.wh 0 hd.wh -1.0i fo.ch fo 15i.wh -\n(vmu xp.ch fo -\n(vmu.if n .ll 6.5i.if t .ll 6.0i.if n .lt 6.5i.if t .lt 6.0i.ev 1.if n .ll 6.5i.if t .ll 6.0i.if n .lt 6.5i.if t .lt 6.0i.ev.nr ap 1.af ap A.sp 6.ps +2.ce\fBAn Introduction to Pdx\fP.ps -2.sp 1.ce\fIMark Linton\fR.sp 1.ceSeptember 27, 1981.sp 1.br.nr wg 2v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 6\fBIntroduction\fP.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti +5n\fIPdx\fP is a tool for debugging Pascal programsthat are translated by the Berkeley Pascal translator \fIpi\fP[Joy, Graham, and Haley 80].This tutorial introduces \fIpdx\fP and the basic ways that it can be used.For a complete reference, consult the \fIpdx\fP manual page..br.nr wg 2v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 6\fBGetting Started\fP.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti +5nSuppose the program we are working on is in a file called ``prog.p''.Before using \fIpdx\fP, we must translate it with \fIpi\fP.\fIPdx\fP cannot be used if \fIpi\fP reports any errors during translation.To enter \fIpdx\fP, we type the following: (in examples,the user types is in boldface, what \fIpdx\fP printsis in normal type)..br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in +8n.nf.ne 5% \fBpdx\fP>.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in -8n.fiThe ``>'' is a prompt from \fIpdx\fP.Like the shell or editor, \fIpdx\fP prints the prompt when itis waiting for a command..br.nr wg 2v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 6\fBRunning the Program\fP.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti +5nOnce in \fIpdx\fP, we can begin executing our programby typing the command ``run''.Programs don't usually work the first time;with one of two things happening:.if n .nr In 5.if t .nr In 8.in +\n(Inn.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti -5n\h'1n'1.\h'2n'\cThe program tries to do something that isn'tallowed in Pascal, such as dividing by 0..br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti -5n\h'1n'2.\h'2n'\cThe program runs but produces incorrect results..in -\n(Inn.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.hLet's consider the first case.Suppose ``prog.p'' contains the declarations.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in +8n.nf.ne 5var sum, count : integer; avg : real;.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in -8n.fiand the statement.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in +8n.nf.ne 5 avg := sum / count;.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in -8n.fiat line 15.Suppose further that when the program is run``count'' has the value 0.Running under \fIpdx\fP, the following would be printed:.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in +8n.nf.ne 5> \fBrun\fP.sp 1error at line 15: real divide by zero 15 avg := sum / count;>.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in -8n.fi.br.nr wg 2v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 6\fBPrinting Out Variables\fP.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti +5nWhen a program stops because of an execution error,\fIpdx\fP prints the error and the line in the program wherethe error occurred.We can then examine the program's ``state'', that is,print out the values of any variables that might beof interest.In the above example, we might want to know the valueof \fIsum\fP, so we say.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in +8n.nf.ne 5> \fBprint sum\fP5>.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in -8n.fiThe print command can be given any number of Pascal expressionsseparated by commas..br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 3.ti +5nWe can print the values of all variables by usingthe ``dump'' command.Continuing our example, we might get.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in +8n.nf.ne 5> \fBdump\fPsum = 5count = 0avg = 0.0>.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in -8n.fiFrequently there are many variables activeso that we want to print the list of a file for perusal.This is done by saying.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in +8n.nf.ne 5> \fBdump > out\fP.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in -8n.fiwhere ``out'' is the name of file which does not exist..br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 3.ti +5nThere are two other commands useful for printing informationabout variables.The command ``whatis'' prints out the declaration of a variable.Using the above example,.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in +8n.nf.ne 5> \fBwhatis\fP sumvar sum : integer;.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in -8n.fi.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 3.ti +5nIt is possible for a program to have the same name givento two or more different variables when they are local todifferent procedures.\fIPi\fP distinguishes the variables according to which procedureit is looking at;however, when debugging it is possible that both proceduresare active (for example, one procedure could call the other)..br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 3.ti +5n\fIPdx\fP normally allows printing of any variable declared withinthe most recently called procedure or any variables accessibleto this procedure.A variable in an active procedure that is not normally accessiblecan be printed by preceding its name with the procedure it is inand a ``.''.It can sometimes become difficult to remember the variablethat a given name is currently associated with.The ``which'' command is useful in resolving this confusion.It prints the variable name along with the procedure that it is contained in..br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 3.ti +5nUsually we want to know not only what the values of variablesare, but how the program got to where it is.The ``where'' command lists the procedures that were calledfor the program to reach its current point.It might print, for example,.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in +8n.nf.ne 5> \fBwhere\fPLastCalled(parameters), line 15OneBeforeThat(parameters), line 30MainProgram, line 45>.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.in -8n.fi.br.nr wg 2v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ne 6\fBExecution Tracing\fP.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti +5nNow let's look at the possibility that our program doesn'tget an execution error but doesn't produce the correct results.To figure out what and where something is going wrong, wewish to ``watch'' execution information more closely.The \fBtrace\fP command in \fIpdx\fP allows us to do this.There are five classes of information thatwe can watch:.if n .nr In 5.if t .nr In 8.in +\n(Inn.br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti -3n-\h'2n'\cThe execution of a particular source line..br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti -3n-\h'2n'\cA call to a particular procedure or function..br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti -3n-\h'2n'\cThe value of an expression at a particular source line..br.nr wg 1v.ie \n(.h=\n(vk .nr wg -\n(vhu.el .nr vh 0.if \n(wg>0 \{\.sp \n(wgu.nr vh +\n(wgu \}.nr vk \n(.h.ti -3n-\h'2n'\c
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -