| | 1 | 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. |
| | 2 | |
| | 3 | Put 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 |
| | 19 | set history save |
| | 20 | set history size 1000 |
| | 21 | set lang c |
| | 22 | set print null-stop |
| | 23 | set print pretty off |
| | 24 | set print symbol-filename on |
| | 25 | |
| | 26 | def consts |
| | 27 | set $pi=3.141592654 |
| | 28 | set $SH_SUCCESS = 0x8001c009 |
| | 29 | set $SH_GENERIC_ERROR = 16384 |
| | 30 | end |
| | 31 | document 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 |
| | 35 | end |
| | 36 | |
| | 37 | # Often finds what we need, and does no harm |
| | 38 | dir src |
| | 39 | |
| | 40 | ############################################################################################################# |
| | 41 | # Macros --- making life simple |
| | 42 | ############################################################################################################# |
| | 43 | |
| | 44 | define bell |
| | 45 | printf "\a" |
| | 46 | end |
| | 47 | document bell |
| | 48 | Ring the bell |
| | 49 | end |
| | 50 | |
| | 51 | define cc |
| | 52 | signal 2 |
| | 53 | end |
| | 54 | document cc |
| | 55 | Send CTRL-C signal |
| | 56 | end |
| | 57 | |
| | 58 | define dl |
| | 59 | delete $bpnum |
| | 60 | printf "Deleting breakpoint %d\n", $bpnum-- |
| | 61 | end |
| | 62 | document dl |
| | 63 | Delete the most recent breakpoint |
| | 64 | end |
| | 65 | |
| | 66 | define f0 |
| | 67 | frame 0 |
| | 68 | list |
| | 69 | end |
| | 70 | document f0 |
| | 71 | List frame 0 |
| | 72 | end |
| | 73 | |
| | 74 | define ni |
| | 75 | nexti |
| | 76 | x/i $pc |
| | 77 | end |
| | 78 | document ni |
| | 79 | Go to next instruction, and print it |
| | 80 | end |
| | 81 | |
| | 82 | define si |
| | 83 | stepi |
| | 84 | x/i $pc |
| | 85 | end |
| | 86 | document si |
| | 87 | Step to next instruction, and print it |
| | 88 | end |
| | 89 | |
| | 90 | define pdeg |
| | 91 | print ($arg0)*180/3.1415926536 |
| | 92 | end |
| | 93 | document pdeg |
| | 94 | Print a value given in radians in degrees |
| | 95 | end |
| | 96 | |
| | 97 | define pdeg2 |
| | 98 | output ($arg0)*180/3.1415926536 |
| | 99 | printf " " |
| | 100 | output ($arg1)*180/3.1415926536 |
| | 101 | printf "\n" |
| | 102 | end |
| | 103 | document pdeg2 |
| | 104 | Print two numbers, converting from radians to degrees |
| | 105 | end |
| | 106 | |
| | 107 | define p2 |
| | 108 | output $arg0 |
| | 109 | printf " " |
| | 110 | output $arg1 |
| | 111 | printf "\n" |
| | 112 | end |
| | 113 | document p2 |
| | 114 | Print two numbers |
| | 115 | end |
| | 116 | |
| | 117 | define p3 |
| | 118 | output $arg0 |
| | 119 | printf " " |
| | 120 | output $arg1 |
| | 121 | printf " " |
| | 122 | output $arg2 |
| | 123 | printf "\n" |
| | 124 | end |
| | 125 | document p3 |
| | 126 | Print three numbers |
| | 127 | end |
| | 128 | |
| | 129 | define p4 |
| | 130 | output $arg0 |
| | 131 | printf " " |
| | 132 | output $arg1 |
| | 133 | printf " " |
| | 134 | output $arg2 |
| | 135 | printf " " |
| | 136 | output $arg3 |
| | 137 | printf "\n" |
| | 138 | end |
| | 139 | document p4 |
| | 140 | Print four numbers |
| | 141 | end |
| | 142 | |
| | 143 | def pp |
| | 144 | set print pretty on |
| | 145 | print $arg0 |
| | 146 | set print pretty off |
| | 147 | end |
| | 148 | document pp |
| | 149 | Print an expression with pretty print on |
| | 150 | end |
| | 151 | |
| | 152 | define ret |
| | 153 | return |
| | 154 | continue |
| | 155 | end |
| | 156 | |
| | 157 | define rr |
| | 158 | dont-repeat |
| | 159 | run |
| | 160 | end |
| | 161 | document rr |
| | 162 | Run with no confirmation required |
| | 163 | end |
| | 164 | |
| | 165 | def rn |
| | 166 | run null - |
| | 167 | end |
| | 168 | document rn |
| | 169 | Run with null arguments |
| | 170 | end |
| | 171 | |
| | 172 | define w |
| | 173 | where 7 |
| | 174 | echo \t...\n |
| | 175 | end |
| | 176 | document w |
| | 177 | Where am I? Print a backtrace of 7 lines max |
| | 178 | end |
| | 179 | |
| | 180 | |
| | 181 | ############################################################################################################# |
| | 182 | # Loops |
| | 183 | ############################################################################################################# |
| | 184 | |
| | 185 | define loop |
| | 186 | set $i=$arg0 |
| | 187 | while $i < $arg1 |
| | 188 | output $i |
| | 189 | echo \t |
| | 190 | $arg2 $arg3 |
| | 191 | set $i++ |
| | 192 | end |
| | 193 | end |
| | 194 | document 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 | \ |
| | 206 | See also sloop, which doesn't print the loop counter |
| | 207 | end |
| | 208 | |
| | 209 | define loop2 |
| | 210 | set $i=$arg0 |
| | 211 | while $i < $arg1 |
| | 212 | output $i |
| | 213 | echo \t |
| | 214 | $arg2 $arg3 $arg4 |
| | 215 | set $i++ |
| | 216 | end |
| | 217 | end |
| | 218 | document loop2 |
| | 219 | Repeat the command "$arg2 $arg3 $arg4" for $i = $arg0 .. $arg1-1 |
| | 220 | See also sloop2, which doesn't print the loop counter |
| | 221 | end |
| | 222 | |
| | 223 | define 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 |
| | 231 | end |
| | 232 | document loop3 |
| | 233 | Repeat the command "$arg2 $arg3 $arg4 $arg5" for $i = $arg0 .. $arg1-1 |
| | 234 | end |
| | 235 | |
| | 236 | define sloop |
| | 237 | set $i=$arg0 |
| | 238 | while $i < $arg1 |
| | 239 | $arg2 $arg3 |
| | 240 | set $i++ |
| | 241 | end |
| | 242 | end |
| | 243 | document sloop |
| | 244 | Identical to loop, but don't print the loop counter |
| | 245 | end |
| | 246 | |
| | 247 | define sloop2 |
| | 248 | set $i=$arg0 |
| | 249 | while $i < $arg1 |
| | 250 | $arg2 $arg3 $arg4 |
| | 251 | set $i++ |
| | 252 | end |
| | 253 | end |
| | 254 | document sloop2 |
| | 255 | Like loop2, but don't print the loop counter |
| | 256 | end |
| | 257 | |
| | 258 | define sloop3 |
| | 259 | set $i=$arg0 |
| | 260 | while $i < $arg1 |
| | 261 | $arg2 $arg3 $arg4 $arg5 |
| | 262 | set $i++ |
| | 263 | end |
| | 264 | end |
| | 265 | document sloop3 |
| | 266 | Like loop3, but don't print the loop counter |
| | 267 | end |
| | 268 | |
| | 269 | define 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 |
| | 277 | end |
| | 278 | document iloop |
| | 279 | Identical to loop (except that the variable's called $i_i), |
| | 280 | but used internally in e.g. pmask |
| | 281 | end |
| | 282 | |
| | 283 | define 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 |
| | 294 | end |
| | 295 | document 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. |
| | 304 | end |
| | 305 | |
| | 306 | define 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 |
| | 317 | end |
| | 318 | document 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 |
| | 327 | end |
| | 328 | |
| | 329 | define 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" |
| | 340 | end |
| | 341 | document sum |
| | 342 | Evaluate sum_{$i = $arg0}^{$i = $arg1-1} $arg2 |
| | 343 | |
| | 344 | e.g. sum 0 10 foo[$i].n |
| | 345 | end |
| | 346 | |
| | 347 | ############################################################################################################# |
| | 348 | # Pan-STARRS pslib setup for gdb |
| | 349 | # |
| | 350 | # Provided by Robert Lupton, some changes 30 Jan 2006 |
| | 351 | ############################################################################################################# |
| | 352 | |
| | 353 | define pserror |
| | 354 | break p_psError |
| | 355 | end |
| | 356 | document pserror |
| | 357 | Set a break point on calls to psError() |
| | 358 | end |
| | 359 | |
| | 360 | define pswarn |
| | 361 | break p_psWarning |
| | 362 | end |
| | 363 | document pswarn |
| | 364 | Set a break point on warnings |
| | 365 | end |
| | 366 | |
| | 367 | set $p_psMemAllocID = -1 |
| | 368 | define 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 |
| | 385 | end |
| | 386 | document 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| |
| | 389 | end |
| | 390 | |
| | 391 | set $p_psMemFreeID = -1 |
| | 392 | define 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 |
| | 406 | end |
| | 407 | document psfreeid |
| | 408 | Break when memory ID $p_psMemFreeID == $ARG0 is freed |
| | 409 | end |
| | 410 | |
| | 411 | def psmemid |
| | 412 | psallocid $arg0 |
| | 413 | psfreeid $arg0 |
| | 414 | end |
| | 415 | document psmemid |
| | 416 | Set both alloc and free callbacks to arg0 |
| | 417 | end |
| | 418 | |
| | 419 | define psmem |
| | 420 | set $psmem = ((psMemBlock*)$arg0 - 1) |
| | 421 | print $psmem->id |
| | 422 | end |
| | 423 | document 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 |
| | 430 | end |
| | 431 | |
| | 432 | define psmemprint |
| | 433 | set $psmem = ((psMemBlock*)$arg0 - 1) |
| | 434 | psmemblock $psmem |
| | 435 | end |
| | 436 | document psmemprint |
| | 437 | Use psmemblock to print the psMemBlock associated with $arg0 (use print *$psmem for full details) |
| | 438 | end |
| | 439 | |
| | 440 | define 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" |
| | 448 | end |
| | 449 | document psmemblock |
| | 450 | Pretty-print the interesting bits of a psMemBlock $arg0 |
| | 451 | end |
| | 452 | |
| | 453 | define psmembreak |
| | 454 | cond $arg0 $arg1 != 0 && ((psMemBlock*)$arg1 - 1)->id == $arg2 |
| | 455 | end |
| | 456 | document psmembreak |
| | 457 | Make breakpoint $arg0 conditional on $arg1's memory serial number being $arg2 |
| | 458 | end |
| | 459 | |
| | 460 | define 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) |
| | 465 | end |
| | 466 | document psimagewrite |
| | 467 | Write a psImage ($arg1) to a FITS file ($arg0). |
| | 468 | end |
| | 469 | |
| | 470 | define psmetadataitem |
| | 471 | break psMetadataItemAllocV if metadataId + 1 == $arg0 |
| | 472 | end |
| | 473 | document psmetadataitem |
| | 474 | Break on allocating item with id number ($arg0). |
| | 475 | end |
| | 476 | |
| | 477 | define pscheckcorruption |
| | 478 | call p_psMemCheckCorruption("gdb", 0, "gdb", stderr, 0) |
| | 479 | end |
| | 480 | document pscheckcorruption |
| | 481 | Check for memory corruption. |
| | 482 | end |
| | 483 | |
| | 484 | define 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 |
| | 493 | end |
| | 494 | document psmetadatalist |
| | 495 | List all the elements of a psMetadata ($arg0) |
| | 496 | end |
| | 497 | |
| | 498 | define 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 |
| | 507 | end |
| | 508 | document psmetadataget |
| | 509 | Get the nominated element ($arg1) of a psMetadata ($arg0) |
| | 510 | end |
| | 511 | </pre> |