diff mbox

core file support for AIX

Message ID OF8F4A8FA0.A9E5B5DA-ON65257EE3.003F3BB0-65257EE3.003F6161@in.ibm.com
State New
Headers show

Commit Message

Sangamesh Mallayya Oct. 19, 2015, 11:32 a.m. UTC
Hi All,
 
Below patches adds support for debugging core file's in AIX.
Right now gdb doesn't recognise the AIX core file and doesn't have method 
to identify if we are using old format or new core format.
These patch adds support for debugging both 32-bit & 64-bit core file in 
case of both 32-bit and 64-bit gdb.
 
1) With the first patch (core_patch.txt) we resolve these errors
 
    is not a core dump: File format not recognized 
 
    And also the compilation error like this after adding powerpc64 entry 
in configuration file.
 
    rs6000-core.c:112: error: field 'old' has incomplete type 
    rs6000-core.c:125: error: field 'old' has incomplete type 
    rs6000-core.c: In function 'read_hdr': 
    rs6000-core.c:286: error: dereferencing pointer to incomplete type 
    rs6000-core.c:286: error: dereferencing pointer to incomplete type 
 
    Here is sample example to test this.
 
   # cat test.c
   int foo(char **p)
   {
      strcpy(*p, "Hello");
   }
   int main()
   {

      char *p;
      foo(&p);
   }


   # file test_32 core 
   test_32: executable (RISC System/6000 V3.1) or obj module not stripped
   core:    AIX core file 32-bit, test_32


   Program terminated with signal 11, Segmentation fault.
   #0  0x0000f014 in ?? ()
   (gdb) bt 
   #0  0x0000f014 in ?? ()
   #1  0x10000390 in foo (p=0x2ff22bf8) at test.c:3
   #2  0x100003e4 in main () at test.c:9
   (gdb) frame 1 
   #1  0x10000390 in foo (p=0x2ff22bf8) at test.c:3
    3          strcpy(*p, "Hello");


    # file test_64 core
    test_64: 64-bit XCOFF executable or object module
    core:    AIX core file 64-bit, test_64

    Program terminated with signal 11, Segmentation fault.
    #0  0x000000000000f414 in ?? ()
    (gdb) bt
    #0  0x000000000000f414 in ?? ()
    #1  0x0000000100000490 in foo (p=0xffffffffffffb00) at test.c:3
    #2  0x00000001000004e4 in main () at test.c:9
    (gdb) frame 1
    #1  0x0000000100000490 in foo (p=0xffffffffffffb00) at test.c:3
    3          strcpy(*p, "Hello");
    (gdb) 

 
2) Second patch(core_bmax_patch.txt) adds the support for debugging core 
file generated by binaries in case of the large memory model.
If a binary has been compiled with -bmaxdata option then we can't be able 
access the value stored in .data section 

    xlc -g -o test test.c -bmaxdata:0x80000000

    (gdb) bt
    #0  0xd013a820 in raise () from /usr/lib/libc.a(shr.o)
    #1  0xd01b3088 in abort () from /usr/lib/libc.a(shr.o)
    #2  0x100003b8 in main () at test.c:7
    (gdb) frame 2
    #2  0x100003b8 in main () at test.c:7
    7       test.c: A file or directory in the path name does not exist..
    (gdb) info locals
    c = 0x30000a68 <error: Cannot access memory at address 0x30000a68>
    __func__ = "main"
    (gdb) 


    with fix

    (gdb) bt
    #0  0xd013a820 in raise () from /usr/lib/libc.a(shr.o)
    #1  0xd01b3088 in abort () from /usr/lib/libc.a(shr.o)
    #2  0x100003b8 in main () at test.c:7
    (gdb) frame 2
    #2  0x100003b8 in main () at test.c:7
    7       test.c: A file or directory in the path name does not exist..
    (gdb) info locals
    c = 0x30000a68 "Hello"
    __func__ = "main"
    (gdb) 



Thanks & Regards,
-Sangamesh
AIX BOS Development
Bangalore, EGL D Block, 6th floor

Phone: +91 (80) 417-76965

--- bfd/configure_orig	2015-10-16 10:03:17.000000000 -0500
+++ bfd/configure	2015-10-16 10:12:51.000000000 -0500
@@ -14056,7 +14056,7 @@ if test "${target}" = "${host}"; then
   rs6000-*-lynx*)
 	COREFILE=lynx-core.lo
 	;;
-  rs6000-*-aix[5-9].* | powerpc-*-aix[5-9].*)
+  rs6000-*-aix[5-9].* | powerpc-*-aix[5-9].* | powerpc64-*-aix[5-9].*)
         COREFILE=rs6000-core.lo
 	COREFLAG="$COREFLAG -DAIX_5_CORE -DAIX_CORE_DUMPX_CORE"
 	;;
@@ -14094,6 +14094,7 @@ rm -f core conftest.err conftest.$ac_obj
   rs6000-*-*)		COREFILE=rs6000-core.lo ;;
   powerpc-*-aix4*)	COREFILE=rs6000-core.lo ;;
   powerpc-*-aix*)	COREFILE=rs6000-core.lo ;;
+  powerpc64-*-aix*)	COREFILE=rs6000-core.lo ;;
   powerpc-*-beos*)	;;
   powerpc-*-freebsd* | powerpc-*-kfreebsd*-gnu)
 		        COREFILE='' ;;
--- bfd/rs6000-core.c_orig	2015-10-16 13:07:20.000000000 -0500
+++ bfd/rs6000-core.c	2015-10-19 04:23:26.000000000 -0500
@@ -92,7 +92,7 @@ typedef unsigned long ptr_to_uint;
 /* Union of 32-bit and 64-bit versions of ld_info.  */
 
 typedef union {
-#ifdef __ld_info32
+#if defined (__ld_info32) || defined (__ld_info64)
   struct __ld_info32 l32;
   struct __ld_info64 l64;
 #else
@@ -109,8 +109,10 @@ typedef union {
 #else
   struct core_dump new_dump;		/* for simpler coding */
 #endif
+#ifndef BFD64                   /* use old only if gdb is 32-bit */
   struct core_dump old;		/* old AIX 4.2- core dump, still used on
 				   4.3+ with appropriate SMIT config */
+#endif
 } CoreHdr;
 
 /* Union of old and new vm_info structures.  */
@@ -122,14 +124,20 @@ typedef union {
 #else
   struct vm_info new_dump;
 #endif
+#ifndef BFD64
   struct vm_info old;
+#endif
 } VmInfo;
 #endif
 
 /* Return whether CoreHdr C is in new or old format.  */
 
 #ifdef AIX_CORE_DUMPX_CORE
-# define CORE_NEW(c)	(!(c).old.c_entries)
+ #ifndef BFD64
+   # define CORE_NEW(c)        (!(c).old.c_entries)
+ #else
+   # define CORE_NEW(c)   (!(c).new_dump.c_entries)
+ #endif
 #else
 # define CORE_NEW(c)	0
 #endif
@@ -258,9 +266,13 @@ typedef union {
 
 /* Size of the leading portion that old and new core dump structures have in
    common.  */
-#define CORE_COMMONSZ	((int) &((struct core_dump *) 0)->c_entries \
-			 + sizeof (((struct core_dump *) 0)->c_entries))
-
+#ifdef AIX_CORE_DUMPX_CORE
+#define CORE_COMMONSZ  ((long) &((struct core_dumpx *) 0)->c_entries \
+                        + sizeof (((struct core_dumpx *) 0)->c_entries))
+#else
+#define CORE_COMMONSZ   ((int) &((struct core_dump *) 0)->c_entries \
+                       + sizeof (((struct core_dump *) 0)->c_entries)
+#endif
 /* Define prototypes for certain functions, to avoid a compiler warning
    saying that they are missing.  */
 
@@ -290,8 +302,10 @@ read_hdr (bfd *abfd, CoreHdr *core)
   /* Read the trailing portion of the structure.  */
   if (CORE_NEW (*core))
     size = sizeof (core->new_dump);
+  #ifndef BFD64
   else
     size = sizeof (core->old);
+  #endif
   size -= CORE_COMMONSZ;
   return bfd_bread ((char *) core + CORE_COMMONSZ, size, abfd) == size;
 }
@@ -356,6 +370,7 @@ rs6000coff_core_p (bfd *abfd)
       c_stackend = CNEW_STACKORG (core.new_dump) + c_size;
       c_lsize = CNEW_LSIZE (core.new_dump);
       c_loader = CNEW_LOADER (core.new_dump);
+  #ifndef BFD64
       proc64 = CNEW_PROC64 (core.new_dump);
     }
   else
@@ -366,6 +381,7 @@ rs6000coff_core_p (bfd *abfd)
       c_stackend = COLD_STACKEND;
       c_lsize = 0x7ffffff;
       c_loader = (file_ptr) (ptr_to_uint) COLD_LOADER (core.old);
+   #endif
       proc64 = 0;
     }
 
@@ -379,11 +395,13 @@ rs6000coff_core_p (bfd *abfd)
       c_regsize = sizeof (CNEW_MSTSAVE (core.new_dump));
       c_regptr = &CNEW_MSTSAVE (core.new_dump);
     }
+  #ifndef BFD64
   else
     {
       c_regsize = sizeof (COLD_MSTSAVE (core.old));
       c_regptr = &COLD_MSTSAVE (core.old);
     }
+  #endif
   c_regoff = (char *) c_regptr - (char *) &core;
 
   if (bfd_stat (abfd, &statbuf) < 0)
@@ -433,7 +451,11 @@ rs6000coff_core_p (bfd *abfd)
     }
 
   /* Sanity check on the c_tab field.  */
+  #ifndef BFD64
   if (!CORE_NEW (core) && (c_loader < (file_ptr) sizeof core.old ||
+  #else
+  if (!CORE_NEW (core) && (c_loader < (file_ptr) sizeof core.new_dump ||
+  #endif
 			   c_loader >= statbuf.st_size ||
 			   c_loader >= c_stack))
     {
@@ -447,7 +469,11 @@ rs6000coff_core_p (bfd *abfd)
 			   bfd_get_filename (abfd));
 
   /* Allocate core file header.  */
+  #ifndef BFD64
   size = CORE_NEW (core) ? sizeof (core.new_dump) : sizeof (core.old);
+  #else
+  size =  sizeof (core.new_dump);
+  #endif
   tmpptr = (char *) bfd_zalloc (abfd, (bfd_size_type) size);
   if (!tmpptr)
     return NULL;
@@ -540,6 +566,7 @@ rs6000coff_core_p (bfd *abfd)
 	c_vmregions = core.new_dump.c_vmregions;
 	c_vmm = (file_ptr) core.new_dump.c_vmm;
       }
+    #ifndef BFD64
     else
       {
 	c_datasize = core.old.c_datasize;
@@ -547,6 +574,7 @@ rs6000coff_core_p (bfd *abfd)
 	c_vmregions = core.old.c_vmregions;
 	c_vmm = (file_ptr) (ptr_to_uint) core.old.c_vmm;
       }
+    #endif
 
     /* .data section from executable.  */
     if (c_datasize)
@@ -613,7 +641,11 @@ rs6000coff_core_p (bfd *abfd)
 	    file_ptr vminfo_offset;
 	    bfd_vma vminfo_addr;
 
+            #ifndef BFD64
 	    size = CORE_NEW (core) ? sizeof (vminfo.new_dump) : sizeof (vminfo.old);
+            #else
+            size = sizeof (vminfo.new_dump);
+            #endif
 	    if (bfd_bread (&vminfo, size, abfd) != size)
 	      goto fail;
 
@@ -623,12 +655,14 @@ rs6000coff_core_p (bfd *abfd)
 		vminfo_size = vminfo.new_dump.vminfo_size;
 		vminfo_offset = vminfo.new_dump.vminfo_offset;
 	      }
+            #ifndef BFD64
 	    else
 	      {
 		vminfo_addr = (bfd_vma) (ptr_to_uint) vminfo.old.vminfo_addr;
 		vminfo_size = vminfo.old.vminfo_size;
 		vminfo_offset = vminfo.old.vminfo_offset;
 	      }
+            #endif
 
 	    if (vminfo_offset)
 	      if (!make_bfd_asection (abfd, ".vmdata",
@@ -668,8 +702,10 @@ rs6000coff_core_file_matches_executable_
 
   if (CORE_NEW (core))
     c_loader = CNEW_LOADER (core.new_dump);
+  #ifndef BFD64
   else
     c_loader = (file_ptr) (ptr_to_uint) COLD_LOADER (core.old);
+  #endif
 
   if (CORE_NEW (core) && CNEW_PROC64 (core.new_dump))
     size = (int) ((LdInfo *) 0)->l64.ldinfo_filename;
@@ -732,8 +768,12 @@ char *
 rs6000coff_core_file_failing_command (bfd *abfd)
 {
   CoreHdr *core = core_hdr (abfd);
+  #ifndef BFD64
   char *com = CORE_NEW (*core) ?
     CNEW_COMM (core->new_dump) : COLD_COMM (core->old);
+  #else
+  char *com = CNEW_COMM (core->new_dump);
+  #endif
 
   if (*com)
     return com;
@@ -745,7 +785,11 @@ int
 rs6000coff_core_file_failing_signal (bfd *abfd)
 {
   CoreHdr *core = core_hdr (abfd);
+  #ifndef BFD64
   return CORE_NEW (*core) ? core->new_dump.c_signo : core->old.c_signo;
+  #else
+  return  core->new_dump.c_signo;
+  #endif
 }
 
 #endif /* AIX_CORE */

Comments

Pedro Alves Oct. 20, 2015, 11:56 a.m. UTC | #1
Hi Sangamesh,

On 10/19/2015 12:32 PM, Sangamesh Mallayya wrote:
> Hi All,
>  
> Below patches adds support for debugging core file's in AIX.
> Right now gdb doesn't recognise the AIX core file and doesn't have method 
> to identify if we are using old format or new core format.
> These patch adds support for debugging both 32-bit & 64-bit core file in 
> case of both 32-bit and 64-bit gdb.

The bfd/ directory is owned by the binutils folks.  You need to
send these patches to the binutils list.

Thanks,
Pedro Alves
diff mbox

Patch

--- bfd/rs6000-core.c_orig	2015-10-16 13:07:20.000000000 -0500
+++ bfd/rs6000-core.c	2015-10-19 04:26:17.000000000 -0500
@@ -528,6 +528,7 @@  rs6000coff_core_p (bfd *abfd)
     file_ptr ldi_core;
     uint ldi_next;
     bfd_vma ldi_dataorg;
+    bfd_vma core_dataorg;
 
     /* Fields from new and old core structures.  */
     bfd_size_type c_datasize, c_vmregions;
@@ -551,19 +552,27 @@  rs6000coff_core_p (bfd *abfd)
     /* .data section from executable.  */
     if (c_datasize)
       {
+	/* If Large Memory Model is used, then the .data segment should start from
+	   BDATAORG which has been defined in the system header files. */
+
+        if (c_flag & CORE_BIGDATA)
+          core_dataorg = BDATAORG;
+        else
+          core_dataorg = CDATA_ADDR (c_datasize);
+
 	if (!make_bfd_asection (abfd, ".data",
 				SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
 				c_datasize,
-				(bfd_vma) CDATA_ADDR (c_datasize),
+				(bfd_vma) core_dataorg,
 				c_data))
 	  goto fail;
       }
 
     /* .data sections from loaded objects.  */
     if (proc64)
-      size = (int) ((LdInfo *) 0)->l64.ldinfo_filename;
+      size = (unsigned long) ((LdInfo *) 0)->l64.ldinfo_filename;
     else
-      size = (int) ((LdInfo *) 0)->l32.ldinfo_filename;
+      size = (unsigned long) ((LdInfo *) 0)->l32.ldinfo_filename;
 
     while (1)
       {