Hi, So these files are meant to be in conjunction with either QEMU or GDB. They provide macros that will help mapping symbol files to appropriate addresses. The grub.gdb file contains inline documentation, I plan on either updating wiki documentation [1] or texinfo documentation in case anyone's already working on it.
[1] http://grub.enbug.org/DebuggingWithGDB For now, given the GDB's way of to looking up symbol files and ability I am aware of and missing abilities to pass the resolved paths to the program that's exec'd, gmodule.pl has to reside at the same directory as symbol files and that should be GDB's working directory as well. That directory is the build directory, which is often the source directory. Needless to say, this needs preservance of unstripped elf files, which means these [2] modifications to genmk.rb. [2] http://lists.gnu.org/archive/html/grub-devel/2008-04/msg00080.html 2008-05-06: Lubomir Rintel <[EMAIL PROTECTED]> * .gdbinit: New file. * grub.gdb: New file. * gmodule.pl: New file. -- Lubomir Rintel (Was: Kundrak) http://v3.sk/~lkundrak/
2008-05-06: Lubomir Rintel <[EMAIL PROTECTED]> * .gdbinit: New file. * grub.gdb: New file. * gmodule.pl: New file. --- /dev/null 2008-05-02 09:18:25.380014078 +0200 +++ .gdbinit 2008-05-06 12:51:12.000000000 +0200 @@ -0,0 +1,2 @@ +# Put your GDB initialization commands here +source grub.gdb --- /dev/null 2008-05-02 09:18:25.380014078 +0200 +++ grub.gdb 2008-05-06 12:51:33.000000000 +0200 @@ -0,0 +1,109 @@ +# grub.gdb - Macros to ease debugging of GRUB and its modules with GDB + +# GRUB -- GRand Unified Bootloader +# Copyright (C) 2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +# +# Load debuging information about GNU GRUB 2 modules into GDB +# automatically. Needs readelf, Perl and gmodule.pl script +# +# Note: break_load command won't work with GDB up to 6.6 due to +# bug in processing breakpoint command hooks. GDB 6.8 works fine. +# + +define _cleanup + shell rm -f .segments.tmp .loadsym.gdb +end + +# 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.elf", $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 + _cleanup +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 + _cleanup + _dump_module_sections $arg0 + _match_and_load_symbols +end +document load_module + Load debugging information for module given as argument. +end + +define load_modules + _cleanup + 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_modules + Load debugging information for all loaded modules. +end + +define load_kernel + file kernel.exec +end +document load_kernel + Load debugging information for kernel. +end + +define break_load + # Load debugging symbols for module when it's loaded + break grub_dl_ref + commands + load_module mod + cont + end +end +document break_load + Make modules load automatically. +end --- /dev/null 2008-05-02 09:18:25.380014078 +0200 +++ gmodule.pl 2008-05-06 12:52:02.000000000 +0200 @@ -0,0 +1,52 @@ +# gmodule.pl - Generate GDB commands to load symbols to right addresses + +# GRUB -- GRand Unified Bootloader +# Copyright (C) 2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +use strict; +use warnings; + +while (<>) { + # Line we get contains section number - load address pairs + # prepended by module name + my ($file, %load_addr) = split; + + my $text = ''; # This one needs not be prepended by -s + my $sections = ''; # All but .text + + print "add-symbol-file $file"; + + open (READELF, "readelf -S $file |") + or die $!; + + while (<READELF>) { + + /\[\s*(\d+)\]\s+(\.\S+)/ or next; + my $sec_num = $1; + my $sec_name = $2; + + # .text section doesn't have to be prepended by -s .text + if ($sec_name eq '.text') { + $text = $load_addr{$sec_num}; + next; + } + + $sections .= " -s $sec_name $load_addr{$sec_num}" + if ($load_addr{$sec_num} and $load_addr{$sec_num} ne '0x0'); + }; + close (READELF); + print " $text $sections\n"; +}
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel