]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Add facility to debug GRUB with gdb under qemu.
authorLubomir Kundrak <lkundrak@redhat.com>
Sun, 13 Nov 2011 21:59:46 +0000 (22:59 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 13 Nov 2011 21:59:46 +0000 (22:59 +0100)
* grub-core/gdb_grub.in: New file.
* grub-core/gmodule.pl.in: Likewise.
* grub-core/Makefile.core.def (gmodule.pl): New script.
(gdb_grub): Likewise.

ChangeLog
grub-core/Makefile.core.def
grub-core/gdb_grub.in [new file with mode: 0644]
grub-core/gmodule.pl.in [new file with mode: 0644]

index d3c48339ea5a15c7979420ed7a504b004cdded80..22421a7152dbdccc2a90e685fce17c9c64a8e241 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-11-13  Lubomir Kundrak  <lkundrak@redhat.com>
+
+       Add facility to debug GRUB with gdb under qemu.
+
+       * grub-core/gdb_grub.in: New file.
+       * grub-core/gmodule.pl.in: Likewise.
+       * grub-core/Makefile.core.def (gmodule.pl): New script.
+       (gdb_grub): Likewise.
+
 2011-11-13  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * util/grub-mount.c (argp_parser): Accept relative pathes.
index fc0472d32c363e73a9c128c786f16ae68a9fa923..cae79b381f881de5cdfc9696a1171f1c77c308a0 100644 (file)
@@ -18,6 +18,18 @@ script = {
   common = modinfo.sh.in;
 };
 
+script = {
+  installdir = noinst;
+  name = gmodule.pl;
+  common = gmodule.pl.in;
+};
+
+script = {
+  installdir = noinst;
+  name = gdb_grub;
+  common = gdb_grub.in;
+};
+
 kernel = {
   name = kernel;
 
diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in
new file mode 100644 (file)
index 0000000..4a55233
--- /dev/null
@@ -0,0 +1,82 @@
+###
+### Load debuging information about GNU GRUB 2 modules into GDB
+### automatically. Needs readelf, Perl and gmodule.pl script
+###
+### $Id: .gdbinit,v 1.1 2006/05/14 11:38:08 lkundrak Exp $
+### Lubomir Kundrak <lkudrak@skosi.org>
+###
+
+# Add section numbers and addresses to .segments.tmp
+define dump_module_sections
+       set $mod = $arg0
+
+       # FIXME: save logging status
+       set logging file .segments.tmp
+       set logging redirect on
+       set logging overwrite off
+       set logging on
+
+       printf "%s", $mod->name
+       set $segment = $mod->segment
+       while ($segment)
+               printf " %i 0x%x", $segment->section, $segment->addr
+               set $segment = $segment->next
+       end
+       printf "\n"
+
+       set logging off
+       # FIXME: restore logging status
+end
+document dump_module_sections
+       Gather information about module whose mod structure was
+       given for use with match_and_load_symbols
+end
+
+# Generate and execute GDB commands and delete temporary files
+# afterwards
+define match_and_load_symbols
+       shell perl gmodule.pl <.segments.tmp >.loadsym.gdb
+       source .loadsym.gdb
+       shell rm -f .segments.tmp .loadsym.gdb
+end
+document match_and_load_symbols
+       Launch script, that matches section names with information
+       generated by dump_module_sections and load debugging info
+       apropriately
+end
+
+###
+
+define load_module
+       dump_module_sections $arg0
+       match_and_load_symbols
+end
+document load_module
+       Load debugging information for module given as argument.
+end
+
+define load_all_modules
+       set $this = grub_dl_head
+       while ($this != 0)
+               dump_module_sections $this->mod
+               set $this = $this->next
+       end
+       match_and_load_symbols
+end
+document load_all_modules
+       Load debugging information for all loaded modules.
+end
+
+###
+
+set confirm off
+file kernel.exec
+target remote :1234
+
+# inform when module is loaded
+break grub_dl_add
+commands
+       silent
+       load_module mod
+       cont
+end
diff --git a/grub-core/gmodule.pl.in b/grub-core/gmodule.pl.in
new file mode 100644 (file)
index 0000000..6739a6f
--- /dev/null
@@ -0,0 +1,30 @@
+###
+### Generate GDB commands, that load symbols for specified module,
+### with proper section relocations. See .gdbinit
+###
+### $Id: gmodule.pl,v 1.2 2006/05/14 11:38:42 lkundrak Exp lkundrak $
+### Lubomir Kundrak <lkudrak@skosi.org>
+###
+
+use strict;
+
+while (<>) {
+       my ($name, %sections) = split;
+
+       print "add-symbol-file $name.module";
+
+       open (READELF, "readelf -S $name.mod |") or die;
+       while (<READELF>) {
+               /\[\s*(\d+)\]\s+(\.\S+)/ or next;
+
+               if ($2 eq '.text') {
+                       print " $sections{$1}";
+                       next;
+               }
+
+               print " -s $2 $sections{$1}"
+                       if ($sections{$1} ne '0x0');
+       };
+       close (READELF);
+       print "\n";
+}