Remote debugging GRUB over a serial line
Hi!
For those who are interested, here's gdb remote stub for debugging over serial line.
http://netbsd.sk/~lkundrak/misc/grub2-gdb/grub2-gdb-stub.diff
This week I'll try to clean up the code, so don't
expect it to be particularly good yet.
I also added a paragraph on remote debugging to the howto
http://netbsd.sk/~lkundrak/misc/grub2-gdb/howto.html
Signature · 3 lines
o Lubomir Kundrak *O* <[email protected]>, http://skosi.org/~lkundrak/ (_) SKOSI -- Slovak OpenSource Initiative
Lubomir Kundrak <[email protected]> writes:
Hi Lubomir,
Quoted 7 lines
For those who are interested, here's gdb remote stub for debugging over serial line.
http://netbsd.sk/~lkundrak/misc/grub2-gdb/grub2-gdb-stub.diff
This week I'll try to clean up the code, so don't
expect it to be particularly good yet.
When it is finished, could you please send the patch to the list (inline) and can you include a changelog entry? That will make it easier to get the patch applied.
Thanks,
Marco
Quoted 19 lines · Marco Gerards
From: Marco Gerards <[email protected]>
Date: Mon, 22 May 2006 16:00:01 +0200
In-Reply-To: <[email protected]> (Lubomir Kundrak's messageof "Mon, 22 May 2006 10:51:46 +0200")Message-ID: <[email protected]>
Subject: Re: Remote debugging GRUB over a serial lineLubomir Kundrak <[email protected]> writes:
Hi Lubomir,
Quoted 7 lines
For those who are interested, here's gdb remote stub for debugging over serial line.
http://netbsd.sk/~lkundrak/misc/grub2-gdb/grub2-gdb-stub.diff
This week I'll try to clean up the code, so don't
expect it to be particularly good yet.
Quoted 6 lines
When it is finished, could you please send the patch to the list (inline) and can you include a changelog entry? That will make it easier to get the patch applied.
Thanks,
Marco
So okay, I have tidied the code up a little, trying to comply with GNU coding standards & wrote a changelog entry. Here is it:
2006-05-23: Lubomir Kundrak <[email protected]>
* conf/i386-pc.rmk: Add serial and gdb modules to the list of modules to be built.
* term/i386/pc/serial.c (serial_hw_put): Let some useful serial driver functions be exported.
(grub_serial_getkey): Likewise
* kern/dl.c (grub_dl_resolve_symbols): Let the trapvec symbol be resolved correctly (instead of 0).
* gdb/cstub.c: New file.
* gdb/gdb.c: New file.
* gdb/i386/idt.c: New file.
* gdb/i386/signal.c: New file.
* gdb/i386/machdep.S: New file.
* include/grub/gdb.h: New file.
* include/grub/i386/gdb.h: New file.
* include/grub/i386/pc/kernel.h: New file.
* kern/i386/pc/startup.S: New file.
conf/i386-pc.rmk +8 -1
@@ -116,7 +116,14 @@ pkgdata_MODULES = _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ - videotest.mod play.mod + videotest.mod play.mod serial.mod gdb.mod + +# For gdb.mod. +gdb_mod_SOURCES = gdb/cstub.c gdb/gdb.c gdb/i386/idt.c \ + gdb/i386/machdep.S gdb/i386/signal.c +gdb_mod_CFLAGS = $(COMMON_CFLAGS) +gdb_mod_LDFLAGS = $(COMMON_LDFLAGS) +gdb_mod_ASFLAGS = $(COMMON_ASFLAGS) # For _chain.mod. _chain_mod_SOURCES = loader/i386/pc/chainloader.c
gdb/cstub.c +362 -0
362 lines not on this page · raw message
gdb/gdb.c +61 -0
61 lines not on this page · raw message
gdb/i386/idt.c +61 -0
61 lines not on this page · raw message
gdb/i386/machdep.S +193 -0
193 lines not on this page · raw message
gdb/i386/signal.c +53 -0
53 lines not on this page · raw message
include/grub/gdb.h +38 -0
@@ -0,0 +1,38 @@ +/* gdb.h - Various definitions for the remote GDB stub */ +/* +* Copyright (C) 2006 Lubomir Kundrak +* +* This program 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 2 of the License, or +* (at your option) any later version. +* +* This program 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 this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef GRUB_GDB_HEADER +#define GRUB_GDB_HEADER 1 + +#define SIGFPE 8 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGSEGV 11 +#define SIGILL 4 +#define SIGUSR1 30 +/* We probably don't need other ones. */ + +extern int (*grub_gdb_getchar) (); +extern void (*grub_gdb_putchar) (int ); + +void grub_gdb_breakpoint (); +int grub_gdb_trap2sig (int ); + +#endif /* ! GRUB_GDB_HEADER */ +
include/grub/i386/gdb.h +80 -0
80 lines not on this page · raw message
include/grub/i386/pc/kernel.h +1 -1
@@ -39,7 +39,7 @@#define GRUB_KERNEL_MACHINE_PREFIX 0x1c/* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_MACHINE_RAW_SIZE 0x4A0 +#define GRUB_KERNEL_MACHINE_RAW_SIZE 0x4BC#ifndef ASM_FILE
kern/dl.c +6 -4
@@ -353,16 +353,18 @@ {case STT_NOTYPE :/* Resolve a global symbol. */ -if (sym->st_name !=0 && sym->st_shndx ==0 ) +if (sym->st_name ==0 ) +break ; + +if (sym->st_shndx ==0 )/* external */ { sym->st_value = (Elf_Addr )grub_dl_resolve_symbol (name);if (! sym->st_value)return grub_error (GRUB_ERR_BAD_MODULE ,"the symbol `%s' not found" , name); - } -else - sym->st_value =0 ;break ; + } +/* nonexternal, same as STT_OBJECT */ case STT_OBJECT : sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod,
kern/i386/pc/startup.S +13 -0
@@ -332,6 +332,14 @@ .word 0x27 /* limit */ .long gdt /* addr */ +/* IDT region descriptors */ +prot_idt: + .word 0xffff /* limit */ + .long 0x0 /* addr */ + +real_idt: + .word 0xffff /* limit */ + .long 0x0 /* addr */ /* * These next two routines, "real_to_prot" and "prot_to_real" are structured
@@ -381,6 +389,8 @@ /* zero %eax */ xorl %eax, %eax + lidt prot_idt + /* return on the old (or initialized) stack! */ ret
@@ -389,6 +399,9 @@ /* just in case, set GDT */ lgdt gdtdesc + sidt prot_idt + lidt real_idt + /* save the protected mode stack */ movl %esp, %eax movl %eax, protstack
term/i386/pc/serial.c +3 -3
@@ -93,7 +93,7 @@ }/* Fetch a key. */ -static int +int serial_hw_fetch (void ) {if (inb (serial_settings.port +UART_LSR ) &UART_DATA_READY )
@@ -103,7 +103,7 @@ }/* Put a chararacter. */ -static void +void serial_hw_put (const int c) {unsigned int timeout =100000 ;
@@ -261,7 +261,7 @@ }/* The serial version of getkey. */ -static int +int grub_serial_getkey (void ) {int c;
Signature · 3 lines
o Lubomir Kundrak *O* <[email protected]>, http://skosi.org/~lkundrak/ (_) SKOSI -- Slovak OpenSource Initiative
Uff, I made a mistake -- of course following two files were wrongly described as newly added in the changelog. I am sorry for that:
* include/grub/i386/pc/kernel.h:
(GRUB_KERNEL_MACHINE_RAW_SIZE): Portion of uncopressible code grew a bit.
* kern/i386/pc/startup.S: (real_idt, prot_idt) (real_to_prot, prot_to_real): Preservation of protected mode IDT in real mode calls
Signature · 3 lines
o Lubomir Kundrak *O* <[email protected]>, http://skosi.org/~lkundrak/ (_) SKOSI -- Slovak OpenSource Initiative