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.
This commit is contained in:
Lubomir Kundrak 2011-11-13 22:59:46 +01:00 committed by Vladimir 'phcoder' Serbinenko
parent bc108a4a8a
commit 2536cf6463
4 changed files with 133 additions and 0 deletions

View File

@ -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.

View 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;

82
grub-core/gdb_grub.in Normal file
View File

@ -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

30
grub-core/gmodule.pl.in Normal file
View File

@ -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";
}