gdb_grub.in 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ###
  2. ### Load debuging information about GNU GRUB 2 modules into GDB
  3. ### automatically. Needs readelf, Perl and gmodule.pl script
  4. ###
  5. ### Has to be launched from the writable and trusted
  6. ### directory containing *.image and *.module
  7. ###
  8. ### $Id: .gdbinit,v 1.1 2006/05/14 11:38:08 lkundrak Exp $
  9. ### Lubomir Kundrak <lkudrak@skosi.org>
  10. ###
  11. # Add section numbers and addresses to .segments.tmp
  12. define dump_module_sections
  13. set $mod = $arg0
  14. # FIXME: save logging status
  15. set logging file .segments.tmp
  16. set logging redirect on
  17. set logging overwrite off
  18. set logging on
  19. printf "%s", $mod->name
  20. set $segment = $mod->segment
  21. while ($segment)
  22. printf " %i 0x%lx", $segment->section, $segment->addr
  23. set $segment = $segment->next
  24. end
  25. printf "\n"
  26. set logging off
  27. # FIXME: restore logging status
  28. end
  29. document dump_module_sections
  30. Gather information about module whose mod structure was
  31. given for use with match_and_load_symbols
  32. end
  33. # Generate and execute GDB commands and delete temporary files
  34. # afterwards
  35. define match_and_load_symbols
  36. shell perl gmodule.pl <.segments.tmp >.loadsym.gdb
  37. source .loadsym.gdb
  38. shell rm -f .segments.tmp .loadsym.gdb
  39. end
  40. document match_and_load_symbols
  41. Launch script, that matches section names with information
  42. generated by dump_module_sections and load debugging info
  43. apropriately
  44. end
  45. ###
  46. define load_module
  47. dump_module_sections $arg0
  48. match_and_load_symbols
  49. end
  50. document load_module
  51. Load debugging information for module given as argument.
  52. end
  53. define load_all_modules
  54. set $this = grub_dl_head
  55. while ($this != 0)
  56. dump_module_sections $this
  57. set $this = $this->next
  58. end
  59. match_and_load_symbols
  60. end
  61. document load_all_modules
  62. Load debugging information for all loaded modules.
  63. end
  64. ###
  65. set confirm off
  66. file kernel.exec
  67. target remote :1234
  68. # inform when module is loaded
  69. break grub_dl_add
  70. commands
  71. silent
  72. load_module mod
  73. cont
  74. end