gdb_grub.in 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. ###
  2. ### Load debuging information about GNU GRUB 2 modules into GDB
  3. ### automatically. Needs readelf, objdump, Python and gdb_helper.py 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. source gdb_helper.py
  12. define dynamic_load_symbols
  13. dynamic_load_kernel_exec_symbols $arg0
  14. run_on_start
  15. # We may have been very late to loading the kernel.exec symbols and
  16. # and modules may already be loaded. So load symbols for any already
  17. # loaded.
  18. load_all_modules
  19. if $is_grub_loaded()
  20. runtime_load_module
  21. end
  22. end
  23. document dynamic_load_symbols
  24. Load debugging symbols from kernel.exec and any loaded modules given
  25. the address of the .text segment of the UEFI binary in memory. Also
  26. setup session to automatically load module symbols for modules loaded
  27. in the future.
  28. end
  29. define load_all_modules
  30. set $this = grub_dl_head
  31. while ($this != 0)
  32. load_module $this
  33. set $this = $this->next
  34. end
  35. end
  36. document load_all_modules
  37. Load debugging information for all loaded modules.
  38. end
  39. define runtime_load_module
  40. break grub_dl_add
  41. commands
  42. silent
  43. load_module mod
  44. cont
  45. end
  46. end
  47. document runtime_load_module
  48. Load module symbols at runtime as they are loaded.
  49. end
  50. define run_on_start
  51. # TODO: Add check to see if _start symbol is defined, if not, then
  52. # the symbols have not yet been loaded and this command will not work.
  53. watch *_start
  54. set $break_efi_start_bpnum = $bpnum
  55. commands
  56. silent
  57. delete $break_efi_start_bpnum
  58. # Save the breakpoints here before the GRUB image is loaded
  59. # into memory, then delete them. Later they will be reloaded
  60. # once the GRUB image has been loaded. This avoids the issue
  61. # where the loading of the GRUB image overwrites the software
  62. # breakpoints, thus confusing GDB and effectively clearing
  63. # those breakpoints.
  64. save breakpoints .early-breakpoints.gdb
  65. delete breakpoints
  66. tbreak _start
  67. commands
  68. silent
  69. # Reload the breakpoints now that the GRUB image has
  70. # finished being loaded into memory.
  71. source .early-breakpoints.gdb
  72. runtime_load_module
  73. if $is_user_command("onstart")
  74. onstart
  75. end
  76. continue
  77. end
  78. continue
  79. end
  80. end
  81. document run_on_start
  82. On some targets, such as x86_64-efi, even if you know where the
  83. firmware will load the GRUB image, you can not simply set a break
  84. point before the image is loaded because loading the image
  85. overwrites the break point in memory. So setup a hardware watch
  86. point, which does not have that problem, and if that gets triggered,
  87. then reset the break point. If a user-defined command named
  88. "onstart" exists it will be run after the start is hit.
  89. NOTE: This assumes symbols have already been correctly loaded for
  90. the EFI application.
  91. end
  92. ###
  93. set confirm off
  94. # Note: On EFI and other platforms that load GRUB to an address that is
  95. # determined at runtime, the symbols in kernel.exec will be wrong.
  96. # However, we must start by loading some executable file or GDB will
  97. # fail.
  98. set $platform_efi = $_streq("@platform@", "efi")
  99. set $target = "@target_cpu@-@platform@"
  100. if ! $runonce
  101. if $platform_efi
  102. # Only load the executable file, not the symbols
  103. exec-file kernel.exec
  104. else
  105. if $_streq($target, "i386-pc")
  106. add-symbol-file boot.image
  107. add-symbol-file diskboot.image
  108. add-symbol-file lzma_decompress.image
  109. end
  110. file kernel.exec
  111. run_on_start
  112. runtime_load_module
  113. end
  114. target remote :1234
  115. set $runonce = 1
  116. end