Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

Dealing with C++ in gdb

To print instance variables of a C++ class in gdb, it is sometimes necessary to include an explicit object pointer. For example, after setting a breakpoint in the tick method of the class Guitar and continuing to the breakpoint, gdb prints something like

Breakpoint 2, Guitar::tick (this=0x805cde8) at Guitar.cpp:100
(gdb)
The this variable points to the current instance of the Guitar object. If an instance variable, say pluckAmp, cannot be found when you try to print it, try instead
(gdb) p this->pluckAmp
$1 = 0.296875
Also, this can be dereferenced to list all instance variables, e.g.,
(gdb) p *this
$2 = {<Plucked3> = {<Instrmnt> = {<Stk> = {static STK_SINT8 = 1, 
        static STK_SINT16 = 2, static STK_SINT32 = 8, 
        static STK_FLOAT32 = 16, static STK_FLOAT64 = 32, 
        static srate = 22050, _vptr.Stk = 0x8059020}, 
      lastOutput = 0}, delayLine = 0x805ce70, delayLine2 = 0x8064f18, 
    combDelay = 0x806cfb0, filter = 0x8075040, filter2 = 0x80750f8, 
    resonator = 0x80751a0, length = 442, loopGain = 0.99999000000000005, 
    baseLoopGain = 0.995, lastFreq = 2637.0204553029598, 
    lastLength = 8.36170988194581, detuning = 0.996, pluckAmp = 0.296875, 
    pluckPos = 0.234567}, soundfile = 0x8075248, dampTime = 8, 
  waveDone = 0, feedback = 0, noise = 0x8075088, 
  excitationFilter = 0x8075398, 
  excitationCoeffs = 0x0}
Suppose we're interested in filter2 above:
(gdb) p filter2
$3 = (BiQuad *) 0x80750f8
(gdb) p *filter2
$4 = {<Filter> = {<Stk> = {static STK_SINT8 = 1, 
      static STK_SINT16 = 2, static STK_SINT32 = 8, 
      static STK_FLOAT32 = 16, static STK_FLOAT64 = 32, 
      static srate = 22050, _vptr.Stk = 0x80590e0}, 
    gain = 0.60459499999999999, nB = 3, nA = 3, 
    b = 0x8075140,  a = 0x8075120, 
    outputs = 0x8075180, inputs = 0x8075160}, <No data fields>}
(gdb)
We see that filter2 is an instance of the BiQuad class. Note that the superclass instance variables are enclosed in curly brackets (the leaf class instance variables begin with gain in this example). We are omitting this here, since doing it once seems to make gdb know about it thereafter. Suppose we want to see the filter coefficients:
(gdb) p filter2->b[0] @ 3
$5 = {1, -1.03, 0.21540000000000001}
(gdb) p filter2->a[0] @ 3
$6 = {1, -1.3337300000000001, 0.446191}
(gdb)
and so on.


Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite and copy this work] 
``Physical Audio Signal Processing for Virtual Musical Instruments and Digital Audio Effects'', by Julius O. Smith III, (December 2005 Edition).
Copyright © 2006-07-01 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA  [Automatic-links disclaimer]