[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE : Debugging GRUB2 with GDB and QEMU

From: Eric Salomé
Subject: RE : Debugging GRUB2 with GDB and QEMU
Date: Sun, 14 May 2006 00:16:31 +0200

Hi Lubomir,

I've tested your scripts.
They are great.
So I changed my code in kern/dl.c to reflect your .elf convention and I
have all ready to use 

You need to recompile gdb with a modified solib-svr4.c file that allows
an  ELF file to be loaded at different non-contigus memory locations,
one for each section.

All is automatic using interface to gdb and you can set pending
breakpoints waiting for the "shared lib" (the grub module) to be loaded.

( doesn't complain anymore when the program quits, I've added a
grub_unload_all() before exiting grub-emu for modules loaded with the
"insmod" command)

Every thing is setup so that before calling grub_dl_mod_init() there is
a call to grub_gdb_load_mod(mod) and mod->elf contains the string 
Filename.elf -s .text 0x233 -s .rodata 0x236 
Ready to be feed to a .gdbinit script that generates the add-symbol-file
command to be swallowed by any standard gdb.

I've noticed that the attachment files I've sent with my previous emails
were not received on Grub 2 mailing list, so that I can send you (and to
others) my source code if you wish to your personal email address.

Source code is ok, should work on both 32-bits and 64-bits
architectures, though I don't do too many checks to prevent buffer
overflow in grub-emu.

I hope you might find these source extensions to kern/dl.c useful.
It's a great pleasure to be able to dynamically load modules and do the
debugging task at ease.

Thanks again Lubomir. Your scripts have been a great help to finalize
this GRUB / GDB interface.

PS: the following lines in genmk.rb didn't work too well on my pc
(Ubuntu) :
+#{exec}: #{pre_obj} #{mod_obj}
        -rm -f $@
        $(CC) $(#{prefix}_LDFLAGS) $(LDFLAGS) -Wl,-r,-d -o $@ $^

ld (when called by gcc) complains it can't find -lgcc_s, so I changed
back to 
        $(LD) $(#{prefix}_LDFLAGS) $(LDFLAGS) -r -d -o $@ $^

Best Regards,
Eric Salomé - Paris, France

> -----Message d'origine-----
> De : address@hidden [mailto:grub-devel-
> address@hidden De la part de Lubomir Kundrak
> Envoyé : vendredi 12 mai 2006 15:20
> À : address@hidden
> Objet : Debugging GRUB2 with GDB and QEMU
> I wrote some GDB macros that might be helpful for people
> that want to debug GRUB 2 modules with QEMU. [1]
> [1]
> The file genmk.rb.diff is a patch to makefile-generator
> script, that makes the build system leave output files with
> debugging information. Of course, one has have ruby interpreter
> to regenerate the makefiles and compile GRUB with -g
> afterwards.
> Second file is .gdbinit, the GDB initialization file.  It is
> commented, so there is no need to describe it here. It basically
> passes the information extracted from list headed by grub_dl_head to
> the perl script,, and loads its output. It also
> sets a breakpoint whose command list contains macro for loading
> proper symbol file each time a module is loaded. (I know the work
> could be done without the help of a Perl script, but it would
> be far more complicated, I guess)
> Another note worth mentioning is that you'll probably want
> to add aliases for some functions, so that all gdb facilities
> will work correctly. You will at least want to define the symbol
> 'main' for backtraces to stop at the right place. Some facilities
> also want the function 'malloc' to be defined. So, you'll
> probably have to add something like
> .globl main
> main = codestart
> to assembly language sources or
> malloc() __attribute__ ((alias("grub_malloc")));
> to C files.
> I hope this will be useful to at least some of you. Best regards!
> Lubo.
> --
>   o   Lubomir Kundrak
>  *O*  <address@hidden>,
>  (_)  SKOSI -- Slovak OpenSource Initiative
> _______________________________________________
> Grub-devel mailing list
> address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]