some debug statements
PATCH 1/1 some debug statements
This patch adds some useful debug statements I've been accumulating. It uses the following debug categories: disk, mem, loader. I've already found the dprintf infrastructure to be quite useful, albeit a little hard to read with all the file paths and line numbers being output... ;)
I hope that as other people successfully debug other areas (like "partition"), they will add more dprintf statements to facilitate future remote debugging, because you know we're going to have a lot of it. :)
If this is acceptable I will check it in.
-Hollis
2005-06-23 Hollis Blanchard <[email protected]>
* disk/powerpc/ieee1275/ofdisk.c (grub_ofdisk_open): dprintf the device path and resulting ihandle.
(grub_ofdisk_close): dprintf the ihandle being closed. (grub_ofdisk_read): dprintf function parameters.
* kern/mm.c (grub_mm_init_region): Likewise.
* loader/powerpc/ieee1275/linux.c (grub_linux_boot): dprintf the Linux entry point, initrd address and size, and boot arguments. (grub_rescue_cmd_linux): dprintf each ELF segment's address and size before loading into memory.
(grub_rescue_cmd_initrd): dprintf the initrd's address and size before loading into memory.
Index: disk/powerpc/ieee1275/ofdisk.c
===================================================================
RCS file: /cvsroot/grub/grub2/disk/powerpc/ieee1275/ofdisk.c,v retrieving revision 1.9
powerpc/ieee1275/ofdisk.c +10 -0
@@ -63,6 +63,8 @@ grub_ofdisk_open (const char *name, grubif (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0 ))grub_strcat (devpath,":0" ); +grub_dprintf ("disk" ,"Opening `%s'.\n" , devpath); +grub_ieee1275_open (devpath, &dev_ihandle);if (! dev_ihandle) {
@@ -70,6 +72,8 @@ grub_ofdisk_open (const char *name, grub goto fail; } +grub_dprintf ("disk" ,"Opened `%s' as handle 0x%x.\n" , devpath, dev_ihandle); +if (grub_ieee1275_finddevice (devpath, &dev)) {grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"Can't read device properties" );
@@ -112,6 +116,8 @@ grub_ofdisk_open (const char *name, grubstatic void grub_ofdisk_close (grub_disk_t disk) { +grub_dprintf ("disk" ,"Closing handle 0x%x.\n" , + (grub_ieee1275_ihandle_t ) disk->data);grub_ieee1275_close ((grub_ieee1275_ihandle_t ) disk->data); }
@@ -123,6 +129,10 @@ grub_ofdisk_read (grub_disk_t disk, unsiint actual;unsigned long long pos; +grub_dprintf ("disk" , +"Reading handle 0x%x: sector 0x%lx, size 0x%lx, buf %p.\n" , + (grub_ieee1275_ihandle_t ) disk->data, sector, size, buf); + pos = (unsigned long long ) sector *512UL ; grub_ieee1275_seek ((grub_ieee1275_ihandle_t) disk->data, (int) (pos >> 32),
Index: kern/mm.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/mm.c,v
retrieving revision 1.10
mm.c +1 -3
@@ -96,9 +96,7 @@ grub_mm_init_region (void *addr, grub_sigrub_mm_header_t h;grub_mm_region_t r, *p, q; -#if 0 -grub_printf ("%s:%d: addr=%p, size=%u\n" , __FILE__, __LINE__, addr, size); -#endif +grub_dprintf ("mem" ,"addr=%p, size=%u\n" , addr, size);/* If this region is too small, ignore it. */ if (size <GRUB_MM_ALIGN *2 )
Index: loader/powerpc/ieee1275/linux.c
===================================================================
RCS file: /cvsroot/grub/grub2/loader/powerpc/ieee1275/linux.c,v retrieving revision 1.7
powerpc/ieee1275/linux.c +14 -1
@@ -53,6 +53,12 @@ grub_linux_boot (void)grub_ieee1275_set_property (grub_ieee1275_chosen,"bootargs" , linux_args,grub_strlen (linux_args) +1 , &actual); +grub_dprintf ("loader" ,"entry point: 0x%x\n" , linux_addr); +grub_dprintf ("loader" ,"initrd at: 0x%x, size 0x%x\n" , initrd_addr, + initrd_size); +grub_dprintf ("loader" ,"/chosen/bootargs: %s\n" , linux_args); +grub_dprintf ("loader" ,"jumping to Linux...\n" ); +/* Boot the kernel. */ linuxmain = (kernel_entry_t ) linux_addr;linuxmain ((void *) initrd_addr, initrd_size, grub_ieee1275_entry_fn,0 ,0 );
@@ -185,13 +191,18 @@ grub_rescue_cmd_linux (int argc, char *aif (phdr->p_type ==PT_LOAD ) { +void *segment_addr = ((char *) entry) + offset; +if (grub_file_seek (file, phdr->p_offset) ==-1 ) {grub_error (GRUB_ERR_BAD_OS ,"Invalid offset in program header" ); goto fail; } -if (grub_file_read (file, (void *) (((char *) entry) + offset) , phdr->p_filesz) +grub_dprintf ("loader" ,"Loading segment %d at %p, size 0x%x\n" , i, + segment_addr, phdr->p_filesz); + +if (grub_file_read (file, segment_addr, phdr->p_filesz) != (grub_ssize_t ) phdr->p_filesz) goto fail;
@@ -272,6 +283,8 @@ grub_rescue_cmd_initrd (int argc, char * goto fail; } +grub_dprintf ("loader" ,"Loading initrd at 0x%x, size 0x%x\n" , addr, size); +if (grub_file_read (file, (void *) addr, size) != size) {grub_ieee1275_release (addr, size);