gdb support in GRUB build system
RFC PATCH 1/1 gdb support in GRUB build system
I following the GRUB 2 gdb debugging instructions this week and I was successful in using QEMU and gdb to debug GRUB. I wondered if we could make this a bit easier -- primarily by making GRUB's build system generate the '.elf' files with full symbol info without requiring a patch. Attached is a patch against GRUB 2 trunk (this is the one from the GRUB 2 debugging guide, just fixed to apply on the latest GRUB sources).
We could make it a 'configure' option like '--enable-debug' or something, but it seems like minimal overhead to generate the .elf files for gdb in addition to "real" GRUB files.
Let me know what you all think. Thanks!
Regards,
Colin
=== modified file 'genmk.rb'
genmk.rb +7 -3
@@ -101,10 +101,11 @@ mod_obj = mod_src.suffix('o') defsym = 'def-' + @name.suffix('lst') undsym = 'und-' + @name.suffix('lst') + exec = @name.suffix('elf') mod_name = File.basename(@name, '.mod') symbolic_name = mod_name.sub(/\.[^\.]*$/, '') - "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{undsym} + "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{undsym} #{exec} ifneq ($(#{prefix}_EXPORTS),no) CLEANFILES += #{defsym} DEFSYMFILES += #{defsym}
@@ -112,11 +113,14 @@ MOSTLYCLEANFILES += #{deps_str} UNDSYMFILES += #{undsym} -#{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) +#{@name}: #{exec} + -rm -f $@ + $(OBJCOPY) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $^ $@ + +#{exec}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) -rm -f $@ $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) $(MODULE_LDFLAGS) -Wl,-r,-d -o $@ #{pre_obj} #{mod_obj} if test ! -z $(TARGET_OBJ2ELF); then ./$(TARGET_OBJ2ELF) $@ || (rm -f $@; exit 1); fi - $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment $@ #{pre_obj}: $(#{prefix}_DEPENDENCIES) #{objs_str} -rm -f $@
=== modified file 'kern/main.c'
main.c +3 -0
@@ -122,6 +122,9 @@grub_print_error (); } +void +main (void ) __attribute__ ((alias ("grub_main" ))); +/* The main routine. */ void grub_main (void )
Am Dienstag, den 05.08.2008, 07:42 -0700 schrieb Colin D Bennett:
Quoted 8 lines
I following the GRUB 2 gdb debugging instructions this week and I was successful in using QEMU and gdb to debug GRUB. I wondered if we could make this a bit easier -- primarily by making GRUB's build system generate the '.elf' files with full symbol info without requiring a patch. Attached is a patch against GRUB 2 trunk (this is the one from the GRUB 2 debugging guide, just fixed to apply on the latest GRUB sources).
Well I already brought this wiki page up on here, but nobody really cared about updating this.
I even did the same as you updateing that patch to current SVN ;)
See here:
http://lists.gnu.org/archive/html/grub-devel/2008-07/msg00585.html
http://lists.gnu.org/archive/html/grub-devel/2008-08/msg00037.html
Quoted 1 line
Let me know what you all think. Thanks!
Thanks that at least you try to that GDB + Qemu stuff easier.
Even with the patches from Lubomir from May I wasn't able to get the symbols of the loaded modules.
I have used that load_modules function which is in the new gdb-macro patch but it didn't work.
And the gdb-stub didn't apply and I was unsure if it was safe to just adjust the values in the header file which was changed.
I think I'm not that good in this stuff to get it working, so it's very nice that you want to do it now :)
Quoted 28 lines · On Tue, 05 Aug 2008 17:05:57 +0200 Felix Zielcke <[email protected]> wrote:
Am Dienstag, den 05.08.2008, 07:42 -0700 schrieb Colin D Bennett:
Quoted 8 lines
I following the GRUB 2 gdb debugging instructions this week and I was successful in using QEMU and gdb to debug GRUB. I wondered if we could make this a bit easier -- primarily by making GRUB's build system generate the '.elf' files with full symbol info without requiring a patch. Attached is a patch against GRUB 2 trunk (this is the one from the GRUB 2 debugging guide, just fixed to apply on the latest GRUB sources).
Well I already brought this wiki page up on here, but nobody really cared about updating this.
I even did the same as you updateing that patch to current SVN ;)See here:
http://lists.gnu.org/archive/html/grub-devel/2008-07/msg00585.html
http://lists.gnu.org/archive/html/grub-devel/2008-08/msg00037.htmlQuoted 1 line
Let me know what you all think. Thanks!
Thanks that at least you try to that GDB + Qemu stuff easier.
Even with the patches from Lubomir from May I wasn't able to get the symbols of the loaded modules.
I have used thatload_modulesfunction which is in the new gdb-macro patch but it didn't work.
And the gdb-stub didn't apply and I was unsure if it was safe to just adjust the values in the header file which was changed.
Quoted 2 lines
I think I'm not that good in this stuff to get it working, so it's very nice that you want to do it now :)
Interesting. Well, I think I used the 'load_all_modules' function instead of just 'load_modules'. And IIRC, I first used the GRUB legacy floppy image that was provided to chainload GRUB 2 over QEMU's built-in tftp, but I think that directly booting GRUB 2 in QEMU for debugging did not work... I'll have to try it again to verify that.
Cheers,
Colin
Am Dienstag, den 05.08.2008, 08:11 -0700 schrieb Colin D Bennett:
Quoted 7 lines
Interesting. Well, I think I used the '
load_all_modules' function instead of just 'load_modules'. And IIRC, I first used the GRUB legacy floppy image that was provided to chainload GRUB 2 over QEMU's built-in tftp, but I think that directly booting GRUB 2 in QEMU for debugging did not work... I'll have to try it again to verify that.
The gdb-macros patch on his fedora page[0] has only load_modules where the help text of it says it loads all symbols.
I didn't try the chainload grub2 with tftp way.
I have used directly a grub2 floppy img for that and it did work for the functions not in a module.
I didn't make anything special, just recompiled grub2 with that page, we both updated, and CFLAGS="-O0 -g3"
and then created the grub2_floppy.img
Quoted 4 lines · Colin D Bennett
We could make it a 'configure' option like '--enable-debug' or something, but it seems like minimal overhead to generate the .elf files for gdb in addition to "real" GRUB files.
I'd favour the --enable-debug. Even if it's a small overhead, it becomes a big problem when you are out of space and need to start looking around to see what can be shaved off.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 9 lines · On Tue, 5 Aug 2008 22:14:03 +0200 Robert Millan <[email protected]> wrote:
Quoted 4 lines · Colin D Bennett
We could make it a 'configure' option like '--enable-debug' or something, but it seems like minimal overhead to generate the .elf files for gdb in addition to "real" GRUB files.
I'd favour the --enable-debug. Even if it's a small overhead, it becomes a big problem when you are out of space and need to start looking around to see what can be shaved off.
In that case, should --enable-debug be the default, or --disable-debug?
Colin
Quoted 9 lines · Colin D Bennett
Quoted 6 lines · On Tue, 5 Aug 2008 22:14:03 +0200 Robert Millan <[email protected]> wrote:
Quoted 4 lines · Colin D Bennett
We could make it a 'configure' option like '--enable-debug' or something, but it seems like minimal overhead to generate the .elf files for gdb in addition to "real" GRUB files.
Quoted 5 lines
Quoted 3 lines
I'd favour the --enable-debug. Even if it's a small overhead, it becomes a big problem when you are out of space and need to start looking around to see what can be shaved off.
In that case, should --enable-debug be the default, or --disable-debug?
I'd prefer to disable debug as default. What do others think?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 3 lines
Quoted 1 line
In that case, should --enable-debug be the default, or --disable-debug?
I'd prefer to disable debug as default. What do others think?
It only creates extra files in the build, unless something is done with them? It's not the /boot or core.img getting expanded here. Also, if users need debugging info, it's much more reliable to fall back on files of debugging symbols that are already generated and match the installed grub binary compile. Or did I get confused? I didn't think they were incredibly huge size files either, so I'd say enable them by default.
-Isaac
Am Dienstag, den 05.08.2008, 23:54 +0200 schrieb Robert Millan:
Quoted 5 lines · Colin D Bennett
Quoted 1 line
In that case, should --enable-debug be the default, or --disable-debug?
I'd prefer to disable debug as default. What do others think?
Have it disabled by default.
I don't think it's useful to have them for everyone i.e. the average user.
What do they gain with it?
If you want to debug real grub you need qemu/bochs and gdb isn't that easy (for the avera users)
Ok maybe I think still more like a Windows guy and not a Linux one, but with Opensuse and Ubuntu I think Linux gets more attractive to people who aren't that experts as we are here on the list :)
Why should we waste a bit of space by default for every Linux distribution?
I doubt they all figure out that they can just disable it on creating there .rpm etc.
And I doubt Robert is disabling this for the Debian build if it's by default enabled on upstream ;)
For debugging it's always the best if you compile with -O0 too and this shouldn't really be the default.
For the few people who need to debug real grub it shouldn't be too hard to just recompile it with `CFLAGS="-g3 -O0" ./configure --enable-debug'
Having debug symbols in the userland tools could be maybe a bit useful for example in the case of the grub-probe segfault I experienced on my mdraid experiments.
Quoted 10 lines · On Thu, 07 Aug 2008 09:37:22 +0200 Felix Zielcke <[email protected]> wrote:
Am Dienstag, den 05.08.2008, 23:54 +0200 schrieb Robert Millan:
Quoted 6 lines · Colin D Bennett
Quoted 2 lines
In that case, should --enable-debug be the default, or --disable-debug?
I'd prefer to disable debug as default. What do others think?
Have it disabled by default.
I don't think it's useful to have them for everyone i.e. the average user.
I agree that having debug info for the installed GRUB is not helpful, especially for the general end-user. So files installed by the GRUB install process certainly don't need debugging symbols.
My concern was only to generate the required symbol information at build time, not to install it for a real GRUB install, or to package these files for distribution in .rpm, .deb, etc.
I don't really care if it's the default or not since I can simply choose my configure options as necessary for the task at hand. If I have a debugging situation, then I can rebuild with debug info, since I'd have to re-start the GRUB/QEMU session anyway to begin debugging. (And I don't use the ridiculously slow QEMU for most stuff anyway.)
Quoted 3 lines
Having debug symbols in the userland tools could be maybe a bit useful for example in the case of the grub-probe segfault I experienced on my mdraid experiments.
True, in that case it makes sense to include debug info (if a distro's other packages include it), since a core dump could be used to debug, or if core dumps aren't enabled, then you could simply re-run it with 'gdb grub-probe' to try to recreate the problem. This doesn't require the whole QEMU virtual machine situation that debugging the GRUB boot loader itself requires.
Regards,
Colin
Quoted 5 lines · Colin D Bennett
Quoted 3 lines
Having debug symbols in the userland tools could be maybe a bit useful for example in the case of the grub-probe segfault I experienced on my mdraid experiments.
True, in that case it makes sense to include debug info
Agreed. Furthermore, Debian packaging environment _expects_ packages to include debug info by default; this allows us (Debian) to define a common variable interface to enable/disable debug symbols by toggling the scripts that run strip after the build.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 11 lines · On Thu, 7 Aug 2008 18:07:43 +0200 Robert Millan <[email protected]> wrote:
Quoted 5 lines · Colin D Bennett
Quoted 3 lines
Having debug symbols in the userland tools could be maybe a bit useful for example in the case of the grub-probe segfault I experienced on my mdraid experiments.
True, in that case it makes sense to include debug info
Agreed. Furthermore, Debian packaging environment _expects_ packages to include debug info by default; this allows us (Debian) to define a common variable interface to enable/disable debug symbols by toggling the scripts that run strip after the build.
Also, also Gentoo does the same thing -- the Gentoo ebuild system does the stripping based on certain flags are set in the FEATURES variable ('nostrip' or 'splitdebug').
Regards,
Colin