IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changes between Initial Version and Version 1 of Dotgdbinit


Ignore:
Timestamp:
Feb 24, 2009, 4:23:54 PM (18 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Dotgdbinit

    v1 v1  
     1Most of this has been contributed by Robert Lupton, edited and supplemented by Paul Price. The more Pan-STARRS-centric definitions are towards the end.
     2
     3Put this in your <tt>~/.gdbinit</tt> file:
     4
     5<pre>
     6#############################################################################################################
     7# .gdbinit file
     8#
     9# Mostly copied from Robert Lupton, 30 Jan 2006
     10#############################################################################################################
     11
     12#############################################################################################################
     13# Setups
     14#############################################################################################################
     15
     16#set confirm off
     17#set heuristic-fence-post 10000
     18#show follow-fork-mode
     19set history save
     20set history size 1000
     21set lang c
     22set print null-stop
     23set print pretty off
     24set print symbol-filename on
     25
     26def consts
     27        set $pi=3.141592654
     28        set $SH_SUCCESS = 0x8001c009
     29        set $SH_GENERIC_ERROR = 16384
     30end
     31document consts
     32        Set various interesting values.
     33        Gdb clears them everytime it loads an image, as it thinks that the meaning
     34        of "float" or "int" may have changed
     35end
     36
     37# Often finds what we need, and does no harm
     38dir src
     39
     40#############################################################################################################
     41# Macros --- making life simple
     42#############################################################################################################
     43
     44define bell
     45        printf "\a"
     46end
     47document bell
     48        Ring the bell
     49end
     50
     51define cc
     52        signal 2
     53end
     54document cc
     55        Send CTRL-C signal
     56end
     57
     58define dl
     59        delete $bpnum 
     60        printf "Deleting breakpoint %d\n", $bpnum--
     61end
     62document dl
     63        Delete the most recent breakpoint
     64end
     65
     66define f0
     67        frame 0
     68        list
     69end
     70document f0
     71        List frame 0
     72end
     73
     74define ni
     75        nexti
     76        x/i $pc
     77end
     78document ni
     79        Go to next instruction, and print it
     80end
     81
     82define si
     83        stepi
     84        x/i $pc
     85end
     86document si
     87        Step to next instruction, and print it
     88end
     89
     90define pdeg
     91        print ($arg0)*180/3.1415926536
     92end
     93document pdeg
     94        Print a value given in radians in degrees
     95end
     96
     97define pdeg2
     98        output ($arg0)*180/3.1415926536
     99        printf " "
     100        output ($arg1)*180/3.1415926536
     101        printf "\n"
     102end
     103document pdeg2
     104        Print two numbers, converting from radians to degrees
     105end
     106
     107define p2
     108        output $arg0
     109        printf " "
     110        output $arg1
     111        printf "\n"
     112end
     113document p2
     114        Print two numbers
     115end
     116
     117define p3
     118        output $arg0
     119        printf " "
     120        output $arg1
     121        printf " "
     122        output $arg2
     123        printf "\n"
     124end
     125document p3
     126        Print three numbers
     127end
     128
     129define p4
     130        output $arg0
     131        printf " "
     132        output $arg1
     133        printf " "
     134        output $arg2
     135        printf " "
     136        output $arg3
     137        printf "\n"
     138end
     139document p4
     140        Print four numbers
     141end
     142
     143def pp
     144        set print pretty on
     145        print $arg0
     146        set print pretty off
     147end
     148document pp
     149        Print an expression with pretty print on
     150end
     151
     152define ret
     153        return
     154        continue
     155end
     156
     157define rr
     158        dont-repeat
     159        run
     160end
     161document rr
     162        Run with no confirmation required
     163end
     164
     165def rn
     166        run null -
     167end
     168document rn
     169        Run with null arguments
     170end
     171
     172define w
     173        where 7
     174        echo \t...\n
     175end
     176document w
     177        Where am I?  Print a backtrace of 7 lines max
     178end
     179
     180
     181#############################################################################################################
     182# Loops
     183#############################################################################################################
     184
     185define loop
     186   set $i=$arg0
     187   while $i < $arg1
     188      output $i
     189      echo \t           
     190      $arg2 $arg3
     191      set $i++         
     192   end
     193end
     194document loop
     195    Repeat the command "$arg2 $arg3" for $i = $arg0 .. $arg1-1
     196
     197\    e.g.
     198\       loop 0 5 p objc->color[$i]->id
     199\       loop 0 5 ppeak objc->color[$i]->peaks->peak[0]
     200\
     201\       if foo is:
     202\           follow2 $arg0 ->next 10 ppeak
     203\
     204\       loop 0 5 foo objc->color[$i]->peaks->peak
     205\
     206See also sloop, which doesn't print the loop counter
     207end
     208
     209define loop2
     210   set $i=$arg0
     211   while $i < $arg1
     212      output $i
     213      echo \t           
     214      $arg2 $arg3 $arg4
     215      set $i++         
     216   end
     217end
     218document loop2
     219    Repeat the command "$arg2 $arg3 $arg4" for $i = $arg0 .. $arg1-1
     220    See also sloop2, which doesn't print the loop counter
     221end
     222
     223define loop3
     224   set $i=$arg0
     225   while $i < $arg1
     226      output $i
     227      echo \t           
     228      $arg2 $arg3 $arg4 $arg5
     229      set $i++         
     230   end
     231end
     232document loop3
     233        Repeat the command "$arg2 $arg3 $arg4 $arg5" for $i = $arg0 .. $arg1-1
     234end
     235
     236define sloop
     237   set $i=$arg0
     238   while $i < $arg1
     239      $arg2 $arg3
     240      set $i++         
     241   end
     242end
     243document sloop
     244        Identical to loop, but don't print the loop counter
     245end
     246
     247define sloop2
     248   set $i=$arg0
     249   while $i < $arg1
     250      $arg2 $arg3 $arg4
     251      set $i++         
     252   end
     253end
     254document sloop2
     255        Like loop2, but don't print the loop counter
     256end
     257
     258define sloop3
     259   set $i=$arg0
     260   while $i < $arg1
     261      $arg2 $arg3 $arg4 $arg5
     262      set $i++         
     263   end
     264end
     265document sloop3
     266        Like loop3, but don't print the loop counter
     267end
     268
     269define iloop
     270   set $i_i=$arg0
     271   while $i_i < $arg1
     272      output $i_i
     273      echo \t           
     274      $arg2 $arg3
     275      set $i_i++               
     276   end
     277end
     278document iloop
     279        Identical to loop (except that the variable's called $i_i),
     280        but used internally in e.g. pmask
     281end
     282
     283define follow
     284   set $follow = 0
     285   set $next = $arg0
     286   while $follow < $arg2 && $next != 0
     287      output $follow
     288      echo \t           
     289      output ($next $arg3)
     290      echo \n           
     291      set $follow++
     292      set $next = $next $arg1
     293   end
     294end
     295document follow
     296        Follow a chain of $arg1 pointers from $arg0, until they reach a NULL
     297        (max: $arg2 elements). For each element "ptr", execute
     298                output ptr $arg3
     299        E.g.
     300                follow peaks->peaks ->next 10 ->colc
     301                follow peaks->peaks ->next 10 [0]
     302        where the latter prints the entire element. See also follow2 to apply
     303        a specified command to each element.
     304end
     305
     306define follow2
     307   set $follow = 0
     308   set $next = $arg0
     309   while $follow < $arg2 && $next != 0
     310      output $follow
     311      echo \t           
     312      $arg3 $next
     313
     314      set $follow++
     315      set $next = $next $arg1
     316   end
     317end
     318document follow2
     319        Follow a chain of $arg1 pointers from $arg0, until they reach a NULL
     320        (max: $arg2 elements). For each element "ptr", execute
     321                $arg3 ptr
     322
     323        E.g.
     324                follow2 peaks->peaks ->next 10 ppeak
     325        to print the centres of a set of peaks.
     326        See also follow to print a given element
     327end
     328
     329define sum
     330   set $iSAVED=$i
     331   set $i=$arg0
     332   set $sum = 0
     333   while $i < $arg1
     334      set $sum += $arg2
     335      set $i++         
     336   end
     337   set $i=$iSAVED
     338   output $sum
     339   printf "\n"
     340end
     341document sum
     342    Evaluate sum_{$i = $arg0}^{$i = $arg1-1} $arg2
     343
     344    e.g. sum 0 10 foo[$i].n                     
     345end
     346
     347#############################################################################################################
     348# Pan-STARRS pslib setup for gdb
     349#
     350# Provided by Robert Lupton, some changes 30 Jan 2006
     351#############################################################################################################
     352
     353define pserror
     354        break p_psError
     355end
     356document pserror
     357        Set a break point on calls to psError()
     358end
     359
     360define pswarn
     361        break p_psWarning
     362end
     363document pswarn
     364        Set a break point on warnings
     365end
     366
     367set $p_psMemAllocID = -1
     368define psallocid
     369        if $arg0 < 0
     370                set $p_psMemAllocID = -1
     371                set $i = 0 - $arg0
     372                psallocid $i
     373        else
     374                if $p_psMemAllocID == -1
     375                        b memAllocCallbackDefault
     376                        set $p_psMemAllocID = $arg0
     377                        #b main if p_psMemAllocID = $p_psMemAllocID, 0
     378                        #b main if p_psMemAllocID == 0 && psMemAllocCallbackSetID((psMemId)$p_psMemAllocID), 0
     379                end
     380
     381                set $p_psMemAllocID = $arg0
     382                #set p_psMemAllocID = $p_psMemAllocID
     383                call psMemAllocCallbackSetID((psMemId)$p_psMemAllocID)
     384        end
     385end
     386document psallocid
     387        Break when memory ID $p_psMemAllocID == $ARG0 is allocated. N.b. if $ARG0
     388        is negative, set the breakpoints, and set the threshold at |$ARG0|
     389end
     390
     391set $p_psMemFreeID = -1
     392define psfreeid
     393        if $arg0 < 0
     394                set $p_psMemFreeID = -1
     395                set $i = 0 - $arg0
     396                psfreeid $i
     397        else
     398                if $p_psMemFreeID == -1
     399                        b memFreeCallbackDefault
     400                        #b main if p_psMemFreeID == 0 && psMemFreeCallbackSetID($p_psMemFreeID), 0
     401                end
     402
     403                set $p_psMemFreeID = $arg0
     404                call psMemFreeCallbackSetID($p_psMemFreeID)
     405        end
     406end
     407document psfreeid
     408        Break when memory ID $p_psMemFreeID == $ARG0 is freed
     409end
     410
     411def psmemid
     412    psallocid $arg0
     413    psfreeid $arg0
     414end
     415document psmemid
     416        Set both alloc and free callbacks to arg0
     417end
     418
     419define psmem
     420        set $psmem = ((psMemBlock*)$arg0 - 1)
     421        print $psmem->id
     422end
     423document psmem
     424        Set $psmem to $arg0's psMemBlock, and print $psmem->id. This is
     425        equivalent to saying:
     426                ((psMemBlock *)ptr - 1)->id
     427        an expression which can be useful in setting break points. You can set
     428        such a condition on breakpoint 123 by saying
     429                psmemb 123 ptr 1069669
     430end
     431
     432define psmemprint
     433        set $psmem = ((psMemBlock*)$arg0 - 1)
     434        psmemblock $psmem
     435end
     436document psmemprint
     437        Use psmemblock to print the psMemBlock associated with $arg0 (use print *$psmem for full details)
     438end
     439
     440define psmemblock
     441        set $_arg0 = (psMemBlock *)$arg0
     442        printf "ID: %d  (%s:%d)  refCntr: %d  persistent: %d  corrupt: %d  freeFunc: ", \
     443               $_arg0->id, $_arg0->file, $_arg0->lineno, $_arg0->refCounter, $_arg0->persistent, \
     444               ($_arg0->startblock != 0xdeadbeef || $_arg0->endblock != 0xdeadbeef || \
     445                (void*)((char *)($_arg0 + 1) + $_arg0->userMemorySize) != 0xdeadbeef ? 1 : 0)
     446        output $_arg0->freeFunc
     447        printf "\n"
     448end
     449document psmemblock
     450    Pretty-print the interesting bits of a psMemBlock $arg0
     451end
     452
     453define psmembreak
     454        cond $arg0 $arg1 != 0 && ((psMemBlock*)$arg1 - 1)->id == $arg2
     455end
     456document psmembreak
     457        Make breakpoint $arg0 conditional on $arg1's memory serial number being $arg2
     458end
     459
     460define psimagewrite
     461        printf "Writing to %s\n", $arg0
     462        set $fits = psFitsOpen($arg0, "w")
     463        call psFitsWriteImage($fits, 0, $arg1, 0, 0)
     464        call psFitsClose($fits)
     465end
     466document psimagewrite
     467        Write a psImage ($arg1) to a FITS file ($arg0).
     468end
     469
     470define psmetadataitem
     471        break psMetadataItemAllocV if metadataId + 1 == $arg0
     472end
     473document psmetadataitem
     474        Break on allocating item with id number ($arg0).
     475end
     476
     477define pscheckcorruption
     478        call p_psMemCheckCorruption("gdb", 0, "gdb", stderr, 0)
     479end
     480document pscheckcorruption
     481        Check for memory corruption.
     482end
     483
     484define psmetadatalist
     485        set $listptr = $arg0->list->head
     486        set $listindex = 0
     487        while ($listptr != 0)
     488                set $listitem = (psMetadataItem*)$listptr->data
     489                printf "%d: %s (%s)\n", $listindex, $listitem->name, $listitem->comment
     490                set $listptr = $listptr->next
     491                set $listindex++
     492        end
     493end
     494document psmetadatalist
     495        List all the elements of a psMetadata ($arg0)
     496end
     497
     498define psmetadataget
     499        set $listptr = $arg0->list->head
     500        set $listindex = 0
     501        while ($listptr != 0 && $listindex != $arg1)
     502                set $listptr = $listptr->next
     503                set $listindex++
     504        end
     505        set $listitem = (psMetadataItem*)$listptr->data
     506        print *$listitem
     507end
     508document psmetadataget
     509        Get the nominated element ($arg1) of a psMetadata ($arg0)
     510end
     511</pre>