utils.gdb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # -*- gdb-script -*-
  2. define load_dump
  3. restore $arg0 binary 0x800000
  4. set $pc = (((unsigned long)$arg1) - 2) << 1
  5. set $sp = $arg2
  6. where
  7. end
  8. document load_dump
  9. Load a crash dump, setup PC/SP and show the current backtrace
  10. Usage: load_dump <file> <PC-addr> <SP-addr>
  11. end
  12. define sp_skip
  13. if $argc == 0
  14. set $shift = 3
  15. else
  16. set $shift = $arg0
  17. end
  18. set $new_pc = ((((unsigned long)*(uint8_t*)($sp+$shift+1)) << 16) + \
  19. (((unsigned long)*(uint8_t*)($sp+$shift+2)) << 8) + \
  20. (((unsigned long)*(uint8_t*)($sp+$shift+3)) << 0)) << 1
  21. set $new_sp = $sp+$shift+3
  22. select-frame 0
  23. set $saved_pc = $pc
  24. set $saved_sp = $sp
  25. set $pc = $new_pc
  26. set $sp = $new_sp
  27. where
  28. end
  29. document sp_skip
  30. Decode the PC address at SP+offset, then show the resulting stack.
  31. The default (and minimum) offset is 3.
  32. Usage: sp_skip [off]
  33. end
  34. define sp_restore
  35. select-frame 0
  36. set $pc = $saved_pc
  37. set $sp = $saved_sp
  38. where
  39. end
  40. document sp_restore
  41. Undo an sp_skip move (restore existing PC/SP positions)
  42. Usage: sp_restore
  43. end
  44. define sp_test
  45. sp_skip $arg0
  46. set $pc = $saved_pc
  47. set $sp = $saved_sp
  48. end
  49. document sp_test
  50. Attempt to decode the PC address at SP+offset, then show the resulting stack.
  51. The default (and minimum) offset is 3.
  52. Usage: sp_test [off]
  53. end
  54. define sp_scan
  55. dont-repeat
  56. if $argc == 0
  57. set $sp_end = 0x802200
  58. else
  59. set $sp_end = $arg0
  60. end
  61. set $sp_pos = $sp
  62. while $sp_pos < ($sp_end-4)
  63. set $sp_off = $sp_pos - $sp
  64. printf "**** scanning %#x (+%u) ****\n", $sp_pos, $sp_off
  65. sp_test $sp_off
  66. set $sp_pos += 1
  67. end
  68. end
  69. document sp_scan
  70. Attempt to decode PC at any location starting from the SP+3 and up to SP-end
  71. (by default the end of the SRAM) and show the resulting stack at all locations.
  72. Usage: sp_scan [SP-end]
  73. end