Most of this has been contributed by Robert Lupton, edited and supplemented by Paul Price. The more Pan-STARRS-centric definitions are towards the end. Put this in your ~/.gdbinit file:
#############################################################################################################
# .gdbinit file
#
# Mostly copied from Robert Lupton, 30 Jan 2006
#############################################################################################################
#############################################################################################################
# Setups
#############################################################################################################
#set confirm off
#set heuristic-fence-post 10000
#show follow-fork-mode
set history save
set history size 1000
set lang c
set print null-stop
set print pretty off
set print symbol-filename on
def consts
set $pi=3.141592654
set $SH_SUCCESS = 0x8001c009
set $SH_GENERIC_ERROR = 16384
end
document consts
Set various interesting values.
Gdb clears them everytime it loads an image, as it thinks that the meaning
of "float" or "int" may have changed
end
# Often finds what we need, and does no harm
dir src
#############################################################################################################
# Macros --- making life simple
#############################################################################################################
define bell
printf "\a"
end
document bell
Ring the bell
end
define cc
signal 2
end
document cc
Send CTRL-C signal
end
define dl
delete $bpnum
printf "Deleting breakpoint %d\n", $bpnum--
end
document dl
Delete the most recent breakpoint
end
define f0
frame 0
list
end
document f0
List frame 0
end
define ni
nexti
x/i $pc
end
document ni
Go to next instruction, and print it
end
define si
stepi
x/i $pc
end
document si
Step to next instruction, and print it
end
define pdeg
print ($arg0)*180/3.1415926536
end
document pdeg
Print a value given in radians in degrees
end
define pdeg2
output ($arg0)*180/3.1415926536
printf " "
output ($arg1)*180/3.1415926536
printf "\n"
end
document pdeg2
Print two numbers, converting from radians to degrees
end
define p2
output $arg0
printf " "
output $arg1
printf "\n"
end
document p2
Print two numbers
end
define p3
output $arg0
printf " "
output $arg1
printf " "
output $arg2
printf "\n"
end
document p3
Print three numbers
end
define p4
output $arg0
printf " "
output $arg1
printf " "
output $arg2
printf " "
output $arg3
printf "\n"
end
document p4
Print four numbers
end
def pp
set print pretty on
print $arg0
set print pretty off
end
document pp
Print an expression with pretty print on
end
define ret
return
continue
end
define rr
dont-repeat
run
end
document rr
Run with no confirmation required
end
def rn
run null -
end
document rn
Run with null arguments
end
define w
where 7
echo \t...\n
end
document w
Where am I? Print a backtrace of 7 lines max
end
#############################################################################################################
# Loops
#############################################################################################################
define loop
set $i=$arg0
while $i < $arg1
output $i
echo \t
$arg2 $arg3
set $i++
end
end
document loop
Repeat the command "$arg2 $arg3" for $i = $arg0 .. $arg1-1
\ e.g.
\ loop 0 5 p objc->color[$i]->id
\ loop 0 5 ppeak objc->color[$i]->peaks->peak[0]
\
\ if foo is:
\ follow2 $arg0 ->next 10 ppeak
\
\ loop 0 5 foo objc->color[$i]->peaks->peak
\
See also sloop, which doesn't print the loop counter
end
define loop2
set $i=$arg0
while $i < $arg1
output $i
echo \t
$arg2 $arg3 $arg4
set $i++
end
end
document loop2
Repeat the command "$arg2 $arg3 $arg4" for $i = $arg0 .. $arg1-1
See also sloop2, which doesn't print the loop counter
end
define loop3
set $i=$arg0
while $i < $arg1
output $i
echo \t
$arg2 $arg3 $arg4 $arg5
set $i++
end
end
document loop3
Repeat the command "$arg2 $arg3 $arg4 $arg5" for $i = $arg0 .. $arg1-1
end
define sloop
set $i=$arg0
while $i < $arg1
$arg2 $arg3
set $i++
end
end
document sloop
Identical to loop, but don't print the loop counter
end
define sloop2
set $i=$arg0
while $i < $arg1
$arg2 $arg3 $arg4
set $i++
end
end
document sloop2
Like loop2, but don't print the loop counter
end
define sloop3
set $i=$arg0
while $i < $arg1
$arg2 $arg3 $arg4 $arg5
set $i++
end
end
document sloop3
Like loop3, but don't print the loop counter
end
define iloop
set $i_i=$arg0
while $i_i < $arg1
output $i_i
echo \t
$arg2 $arg3
set $i_i++
end
end
document iloop
Identical to loop (except that the variable's called $i_i),
but used internally in e.g. pmask
end
define follow
set $follow = 0
set $next = $arg0
while $follow < $arg2 && $next != 0
output $follow
echo \t
output ($next $arg3)
echo \n
set $follow++
set $next = $next $arg1
end
end
document follow
Follow a chain of $arg1 pointers from $arg0, until they reach a NULL
(max: $arg2 elements). For each element "ptr", execute
output ptr $arg3
E.g.
follow peaks->peaks ->next 10 ->colc
follow peaks->peaks ->next 10 [0]
where the latter prints the entire element. See also follow2 to apply
a specified command to each element.
end
define follow2
set $follow = 0
set $next = $arg0
while $follow < $arg2 && $next != 0
output $follow
echo \t
$arg3 $next
set $follow++
set $next = $next $arg1
end
end
document follow2
Follow a chain of $arg1 pointers from $arg0, until they reach a NULL
(max: $arg2 elements). For each element "ptr", execute
$arg3 ptr
E.g.
follow2 peaks->peaks ->next 10 ppeak
to print the centres of a set of peaks.
See also follow to print a given element
end
define sum
set $iSAVED=$i
set $i=$arg0
set $sum = 0
while $i < $arg1
set $sum += $arg2
set $i++
end
set $i=$iSAVED
output $sum
printf "\n"
end
document sum
Evaluate sum_{$i = $arg0}^{$i = $arg1-1} $arg2
e.g. sum 0 10 foo[$i].n
end
#############################################################################################################
# Pan-STARRS pslib setup for gdb
#
# Provided by Robert Lupton, some changes 30 Jan 2006
#############################################################################################################
define pserror
break p_psError
end
document pserror
Set a break point on calls to psError()
end
define pswarn
break p_psWarning
end
document pswarn
Set a break point on warnings
end
set $p_psMemAllocID = -1
define psallocid
if $arg0 < 0
set $p_psMemAllocID = -1
set $i = 0 - $arg0
psallocid $i
else
if $p_psMemAllocID == -1
b memAllocCallbackDefault
set $p_psMemAllocID = $arg0
#b main if p_psMemAllocID = $p_psMemAllocID, 0
#b main if p_psMemAllocID == 0 && psMemAllocCallbackSetID((psMemId)$p_psMemAllocID), 0
end
set $p_psMemAllocID = $arg0
#set p_psMemAllocID = $p_psMemAllocID
call psMemAllocCallbackSetID((psMemId)$p_psMemAllocID)
end
end
document psallocid
Break when memory ID $p_psMemAllocID == $ARG0 is allocated. N.b. if $ARG0
is negative, set the breakpoints, and set the threshold at |$ARG0|
end
set $p_psMemFreeID = -1
define psfreeid
if $arg0 < 0
set $p_psMemFreeID = -1
set $i = 0 - $arg0
psfreeid $i
else
if $p_psMemFreeID == -1
b memFreeCallbackDefault
#b main if p_psMemFreeID == 0 && psMemFreeCallbackSetID($p_psMemFreeID), 0
end
set $p_psMemFreeID = $arg0
call psMemFreeCallbackSetID($p_psMemFreeID)
end
end
document psfreeid
Break when memory ID $p_psMemFreeID == $ARG0 is freed
end
def psmemid
psallocid $arg0
psfreeid $arg0
end
document psmemid
Set both alloc and free callbacks to arg0
end
define psmem
set $psmem = ((psMemBlock*)$arg0 - 1)
print $psmem->id
end
document psmem
Set $psmem to $arg0's psMemBlock, and print $psmem->id. This is
equivalent to saying:
((psMemBlock *)ptr - 1)->id
an expression which can be useful in setting break points. You can set
such a condition on breakpoint 123 by saying
psmemb 123 ptr 1069669
end
define psmemprint
set $psmem = ((psMemBlock*)$arg0 - 1)
psmemblock $psmem
end
document psmemprint
Use psmemblock to print the psMemBlock associated with $arg0 (use print *$psmem for full details)
end
define psmemblock
set $_arg0 = (psMemBlock *)$arg0
printf "ID: %d (%s:%d) refCntr: %d persistent: %d corrupt: %d freeFunc: ", \
$_arg0->id, $_arg0->file, $_arg0->lineno, $_arg0->refCounter, $_arg0->persistent, \
($_arg0->startblock != 0xdeadbeef || $_arg0->endblock != 0xdeadbeef || \
(void*)((char *)($_arg0 + 1) + $_arg0->userMemorySize) != 0xdeadbeef ? 1 : 0)
output $_arg0->freeFunc
printf "\n"
end
document psmemblock
Pretty-print the interesting bits of a psMemBlock $arg0
end
define psmembreak
cond $arg0 $arg1 != 0 && ((psMemBlock*)$arg1 - 1)->id == $arg2
end
document psmembreak
Make breakpoint $arg0 conditional on $arg1's memory serial number being $arg2
end
define psimagewrite
printf "Writing to %s\n", $arg0
set $fits = psFitsOpen($arg0, "w")
call psFitsWriteImage($fits, 0, $arg1, 0, 0)
call psFitsClose($fits)
end
document psimagewrite
Write a psImage ($arg1) to a FITS file ($arg0).
end
define psmetadataitem
break psMetadataItemAllocV if metadataId + 1 == $arg0
end
document psmetadataitem
Break on allocating item with id number ($arg0).
end
define pscheckcorruption
call p_psMemCheckCorruption("gdb", 0, "gdb", stderr, 0)
end
document pscheckcorruption
Check for memory corruption.
end
define psmetadatalist
set $listptr = $arg0->list->head
set $listindex = 0
while ($listptr != 0)
set $listitem = (psMetadataItem*)$listptr->data
printf "%d: %s (%s)\n", $listindex, $listitem->name, $listitem->comment
set $listptr = $listptr->next
set $listindex++
end
end
document psmetadatalist
List all the elements of a psMetadata ($arg0)
end
define psmetadataget
set $listptr = $arg0->list->head
set $listindex = 0
while ($listptr != 0 && $listindex != $arg1)
set $listptr = $listptr->next
set $listindex++
end
set $listitem = (psMetadataItem*)$listptr->data
print *$listitem
end
document psmetadataget
Get the nominated element ($arg1) of a psMetadata ($arg0)
end