From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Received: (qmail 10471 invoked from network); 10 Jan 2003 22:37:42 -0000 Received: from unknown (HELO main.gmane.org) (80.91.224.249) by 209.249.29.67 with SMTP; 10 Jan 2003 22:37:42 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18X7lD-0006QN-00 for ; Fri, 10 Jan 2003 23:36:19 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: gdb-patches@sources.redhat.com Received: from news by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18X7lA-0006Pv-00 for ; Fri, 10 Jan 2003 23:36:16 +0100 Path: not-for-mail From: "Raoul Gough" Subject: Re: coffread.c extension for DLLs without debugging symbols Date: Fri, 10 Jan 2003 22:37:00 -0000 Message-ID: References: <2110-Sat04Jan2003130101+0200-eliz@is.elta.co.il> <15897.47288.570835.988631@localhost.redhat.com> <3E1A2656.7080906@redhat.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0157_01C2B8F8.ECD5A5E0" X-Complaints-To: usenet@main.gmane.org X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-SW-Source: 2003-01/txt/msg00429.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_0157_01C2B8F8.ECD5A5E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-length: 1034 "Andrew Cagney" wrote in message news:3E1A2656.7080906@redhat.com... > Raoul, looks like a little bit of paper work will be needed. I'll > follow up privatly. The paperwork is reportedly on its way to me now. I've since got a new version of the patch together, which introduces coff-pe-read.c. I'm pretty sure I've got the Makefile right - I added coff-pe-read.o to both SFILES and COMMON_OBS since they already involved coffread.o (anything that needs coffread.o now also needs coff-pe-read.o). I've also fixed the problem with relocated DLLs, and AFAIK all formatting issues. The maintainer will have to add the FSF copyright notices, since I suppose the FSF doesn't acknowledge ownership until the forms go through. I guess you also can't put any of this in CVS until the forms have been processed? BTW, I have some more patches on the way, because I've found what some problems with the general handling of DLL relocation on Windows. I'll post these separately when they're ready. Regards, Raoul Gough. ------=_NextPart_000_0157_01C2B8F8.ECD5A5E0 Content-Type: text/plain; name="ChangeLog_entry.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ChangeLog_entry.txt" Content-length: 506 2003-01-10 Raoul Gough * coff-pe-read.c: New file - support reading of minimal symbols from a portable executable using the export table. * coff-pe-read.h: New file * coffread.c: #include coff-pe-read.h (coff_symtab_read): call read_pe_exported_syms iff no recognized debugging symbols found. * Makefile.in (SFILES): add coff-pe-read.o (coff_pe_read_h): define (COMMON_OBS): add coff-pe-read.o (coffread.o): add coff_pe_read_h dependency (coff-pe-read.o): New target ------=_NextPart_000_0157_01C2B8F8.ECD5A5E0 Content-Type: application/octet-stream; name="coff-pe-read.h" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="coff-pe-read.h" Content-length: 437 /* Interface to coff-pe-read.c (portable-executable-specific symbol reader)= .=0A= =0A= Contributed by Raoul M. Gough (RaoulGough@yahoo.co.uk). */=0A= =0A= #if !defined (COFF_PE_READ_H)=0A= #define COFF_PE_READ_H=0A= =0A= struct objfile;=0A= =0A= /* Read the export table and convert it to minimal symbol table entries */= =0A= void read_pe_exported_syms (struct objfile *objfile);=0A= =0A= #endif /* !defined (COFF_PE_READ_H) */=0A= ------=_NextPart_000_0157_01C2B8F8.ECD5A5E0 Content-Type: application/octet-stream; name="coff-pe-read.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="coff-pe-read.c" Content-length: 10770 /* Read the export table symbols from a portable executable and=0A= convert to internal format, for GDB. Used as a last resort if no=0A= debugging symbols recognized.=0A= =0A= Contributed by Raoul M. Gough (RaoulGough@yahoo.co.uk). */=0A= =0A= #include "coff-pe-read.h"=0A= =0A= #include "bfd.h"=0A= =0A= #include "defs.h"=0A= #include "gdbtypes.h"=0A= =0A= #include "symtab.h"=0A= #include "symfile.h"=0A= #include "objfiles.h"=0A= =0A= /* Internal section information */=0A= =0A= struct read_pe_section_data=0A= {=0A= CORE_ADDR vma_offset; /* Offset to loaded address of sectio= n.*/=0A= unsigned long rva_start; /* Start offset within the pe. */=0A= unsigned long rva_end; /* End offset within the pe. */=0A= enum minimal_symbol_type ms_type; /* Type to assign symbols in section.= */=0A= };=0A= =0A= #define PE_SECTION_INDEX_TEXT 0=0A= #define PE_SECTION_INDEX_DATA 1=0A= #define PE_SECTION_INDEX_BSS 2=0A= #define PE_SECTION_TABLE_SIZE 3=0A= #define PE_SECTION_INDEX_INVALID -1=0A= =0C=0A= /* Get the index of the named section in our own array, which contains=0A= text, data and bss in that order. Return PE_SECTION_INDEX_INVALID=0A= if passed an unrecognised section name. */=0A= =0A= static int=0A= read_pe_section_index (const char *section_name)=0A= {=0A= if (strcmp (section_name, ".text") =3D=3D 0)=0A= {=0A= return PE_SECTION_INDEX_TEXT;=0A= }=0A= =0A= else if (strcmp (section_name, ".data") =3D=3D 0)=0A= {=0A= return PE_SECTION_INDEX_DATA;=0A= }=0A= =0A= else if (strcmp (section_name, ".bss") =3D=3D 0)=0A= {=0A= return PE_SECTION_INDEX_BSS;=0A= }=0A= =0A= else=0A= {=0A= return PE_SECTION_INDEX_INVALID;=0A= }=0A= }=0A= =0A= /* Record the virtual memory address of a section. */=0A= =0A= static void=0A= get_section_vmas (bfd *abfd, asection *sectp, void *context)=0A= {=0A= struct read_pe_section_data *sections =3D context;=0A= int sectix =3D read_pe_section_index (sectp->name);=0A= =0A= if (sectix !=3D PE_SECTION_INDEX_INVALID)=0A= {=0A= /* Data within the section start at rva_start in the pe and at=0A= bfd_get_section_vma() within memory. Store the offset. */=0A= =0A= sections[sectix].vma_offset=0A= =3D bfd_get_section_vma (abfd, sectp) - sections[sectix].rva_start;=0A= }=0A= }=0A= =0C=0A= /* Create a minimal symbol entry for an exported symbol. */=0A= =0A= static void=0A= add_pe_exported_sym (char *sym_name,=0A= unsigned long func_rva,=0A= const struct read_pe_section_data *section_data,=0A= const char *dll_name,=0A= struct objfile *objfile)=0A= {=0A= /* Add the stored offset to get the loaded address of the symbol. */=0A= =0A= CORE_ADDR vma =3D func_rva + section_data->vma_offset;=0A= =0A= char *qualified_name =3D 0;=0A= int dll_name_len =3D strlen (dll_name);=0A= int count;=0A= =0A= /* Generate a (hopefully unique) qualified name using the first part=0A= of the dll name, e.g. KERNEL32!AddAtomA. This matches the style=0A= used by windbg from the "Microsoft Debugging Tools for Windows". */=0A= =0A= qualified_name =3D xmalloc (dll_name_len + strlen (sym_name) + 2);=0A= =0A= strncpy (qualified_name, dll_name, dll_name_len);=0A= qualified_name[dll_name_len] =3D '!';=0A= strcpy (qualified_name + dll_name_len + 1, sym_name);=0A= =0A= prim_record_minimal_symbol (qualified_name,=0A= vma,=0A= section_data->ms_type,=0A= objfile);=0A= =0A= xfree (qualified_name);=0A= =0A= /* Enter the plain name as well, which might not be unique. */=0A= prim_record_minimal_symbol (sym_name,=0A= vma,=0A= section_data->ms_type,=0A= objfile);=0A= }=0A= =0A= /* Truncate a dll_name at the first dot character. */=0A= =0A= static void=0A= read_pe_truncate_name (char *dll_name)=0A= {=0A= while (*dll_name)=0A= {=0A= if ((*dll_name) =3D=3D '.')=0A= {=0A= *dll_name =3D '\0'; /* truncates and causes loop exit. */=0A= }=0A= =0A= else=0A= {=0A= ++dll_name;=0A= }=0A= }=0A= }=0A= =0C=0A= /* Low-level support functions, direct from the ld module pe-dll.c. */=0A= static unsigned int=0A= pe_get16 (bfd *abfd, int where)=0A= {=0A= unsigned char b[2];=0A= =0A= bfd_seek (abfd, (file_ptr) where, SEEK_SET);=0A= bfd_bread (b, (bfd_size_type) 2, abfd);=0A= return b[0] + (b[1] << 8);=0A= }=0A= =0A= static unsigned int=0A= pe_get32 (bfd *abfd, int where)=0A= {=0A= unsigned char b[4];=0A= =0A= bfd_seek (abfd, (file_ptr) where, SEEK_SET);=0A= bfd_bread (b, (bfd_size_type) 4, abfd);=0A= return b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24);=0A= }=0A= =0A= static unsigned int=0A= pe_as32 (void *ptr)=0A= {=0A= unsigned char *b =3D ptr;=0A= =0A= return b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24);=0A= }=0A= =0C=0A= /* Read the (non-debug) export symbol table from a portable=0A= executable. Code originally lifted from the ld function=0A= pe_implied_import_dll in pe-dll.c. */=0A= =0A= void=0A= read_pe_exported_syms (struct objfile *objfile)=0A= {=0A= bfd *dll =3D objfile->obfd;=0A= unsigned long pe_header_offset, opthdr_ofs, num_entries, i;=0A= unsigned long export_rva, export_size, nsections, secptr, expptr;=0A= unsigned long exp_funcbase;=0A= unsigned char *expdata, *erva;=0A= unsigned long name_rvas, ordinals, nexp, ordbase;=0A= char *dll_name;=0A= =0A= /* Array elements are for text, data and bss in that order=0A= Initialization with start_rva > end_rva guarantees that=0A= unused sections won't be matched. */=0A= struct read_pe_section_data section_data[PE_SECTION_TABLE_SIZE]=0A= =3D { {0, 1, 0, mst_text},=0A= {0, 1, 0, mst_data},=0A= {0, 1, 0, mst_bss} };=0A= =0A= struct cleanup *back_to =3D 0;=0A= =0A= char const *target =3D bfd_get_target (objfile->obfd);=0A= =0A= if ((strcmp (target, "pe-i386") !=3D 0) && (strcmp (target, "pei-i386") != =3D 0))=0A= {=0A= /* This is not an i386 format file. Abort now, because the code=0A= is untested on anything else. *FIXME* test on further=0A= architectures and loosen or remove this test. */=0A= return;=0A= }=0A= =0A= /* Get pe_header, optional header and numbers of export entries. */=0A= pe_header_offset =3D pe_get32 (dll, 0x3c);=0A= opthdr_ofs =3D pe_header_offset + 4 + 20;=0A= num_entries =3D pe_get32 (dll, opthdr_ofs + 92);=0A= =0A= if (num_entries < 1) /* No exports. */=0A= {=0A= return;=0A= }=0A= =0A= export_rva =3D pe_get32 (dll, opthdr_ofs + 96);=0A= export_size =3D pe_get32 (dll, opthdr_ofs + 100);=0A= nsections =3D pe_get16 (dll, pe_header_offset + 4 + 2);=0A= secptr =3D (pe_header_offset + 4 + 20 +=0A= pe_get16 (dll, pe_header_offset + 4 + 16));=0A= expptr =3D 0;=0A= =0A= /* Get the rva and size of the export section. */=20=0A= for (i =3D 0; i < nsections; i++)=0A= {=0A= char sname[8];=0A= unsigned long secptr1 =3D secptr + 40 * i;=0A= unsigned long vaddr =3D pe_get32 (dll, secptr1 + 12);=0A= unsigned long vsize =3D pe_get32 (dll, secptr1 + 16);=0A= unsigned long fptr =3D pe_get32 (dll, secptr1 + 20);=0A= =0A= bfd_seek (dll, (file_ptr) secptr1, SEEK_SET);=0A= bfd_bread (sname, (bfd_size_type) 8, dll);=0A= =0A= if (vaddr <=3D export_rva && vaddr + vsize > export_rva)=0A= {=0A= expptr =3D fptr + (export_rva - vaddr);=0A= if (export_rva + export_size > vaddr + vsize)=0A= export_size =3D vsize - (export_rva - vaddr);=0A= break;=0A= }=0A= }=0A= =0A= if (export_size =3D=3D 0)=0A= {=0A= /* Empty export table. */=0A= return;=0A= }=0A= =0A= /* Scan sections and store the base and size of the relevant sections. */= =0A= for (i =3D 0; i < nsections; i++)=0A= {=0A= unsigned long secptr1 =3D secptr + 40 * i;=0A= unsigned long vsize =3D pe_get32 (dll, secptr1 + 8);=0A= unsigned long vaddr =3D pe_get32 (dll, secptr1 + 12);=0A= unsigned long flags =3D pe_get32 (dll, secptr1 + 36);=0A= char sec_name[9];=0A= int sectix;=0A= =0A= sec_name[8] =3D '\0';=0A= bfd_seek (dll, (file_ptr) secptr1 + 0, SEEK_SET);=0A= bfd_bread (sec_name, (bfd_size_type) 8, dll);=0A= =0A= sectix =3D read_pe_section_index (sec_name);=0A= =0A= if (sectix !=3D PE_SECTION_INDEX_INVALID)=0A= {=0A= section_data[sectix].rva_start =3D vaddr;=0A= section_data[sectix].rva_end =3D vaddr + vsize;=0A= }=0A= }=0A= =0A= expdata =3D (unsigned char *) xmalloc (export_size);=0A= back_to =3D make_cleanup (xfree, expdata);=0A= =0A= bfd_seek (dll, (file_ptr) expptr, SEEK_SET);=0A= bfd_bread (expdata, (bfd_size_type) export_size, dll);=0A= erva =3D expdata - export_rva;=0A= =0A= nexp =3D pe_as32 (expdata + 24);=0A= name_rvas =3D pe_as32 (expdata + 32);=0A= ordinals =3D pe_as32 (expdata + 36);=0A= ordbase =3D pe_as32 (expdata + 16);=0A= exp_funcbase =3D pe_as32 (expdata + 28);=0A= =0A= /* Use internal dll name instead of full pathname. */=0A= dll_name =3D pe_as32 (expdata + 12) + erva;=0A= =0A= bfd_map_over_sections (dll, get_section_vmas, section_data);=0A= =0A= /* Adjust the vma_offsets in case this PE got relocated. This=0A= assumes that *all* sections share the same relocation offset=0A= as the text section. */=0A= for (i =3D 0; i < PE_SECTION_TABLE_SIZE; i++)=0A= {=0A= section_data[i].vma_offset=0A= +=3D ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));=0A= }=0A= =0A= printf_filtered ("Minimal symbols from %s...", dll_name);=0A= wrap_here ("");=0A= =0A= /* Truncate name at first dot. Should maybe also convert to all=0A= lower case for convenience on Windows. */=0A= read_pe_truncate_name (dll_name);=0A= =0A= /* Iterate through the list of symbols. */=0A= for (i =3D 0; i < nexp; i++)=0A= {=0A= /* Pointer to the names vector. */=0A= unsigned long name_rva =3D pe_as32 (erva + name_rvas + i * 4);=0A= =0A= /* Pointer to the function address vector. */=20=0A= unsigned long func_rva =3D pe_as32 (erva + exp_funcbase + i * 4);=0A= =0A= /* Find this symbol's section in our own array. */=0A= int sectix =3D 0;=0A= =0A= for (sectix =3D 0; sectix < PE_SECTION_TABLE_SIZE; ++sectix)=0A= {=0A= if ((func_rva >=3D section_data[sectix].rva_start)=0A= && (func_rva < section_data[sectix].rva_end))=0A= {=0A= add_pe_exported_sym (erva + name_rva,=0A= func_rva,=0A= section_data + sectix,=0A= dll_name,=0A= objfile);=0A= break;=0A= }=0A= }=0A= }=0A= =0A= /* discard expdata. */=0A= do_cleanups (back_to);=0A= }=0A= =0A= =0A= =0A= ------=_NextPart_000_0157_01C2B8F8.ECD5A5E0 Content-Type: application/octet-stream; name="Makefile.in.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Makefile.in.diff" Content-length: 3448 Index: Makefile.in=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/Makefile.in,v=0A= retrieving revision 1.310=0A= diff -c -p -r1.310 Makefile.in=0A= *** Makefile.in 6 Jan 2003 20:45:30 -0000 1.310=0A= --- Makefile.in 10 Jan 2003 22:32:08 -0000=0A= *************** SFILES =3D ada-exp.y ada-lang.c ada-typepr=0A= *** 501,507 ****=0A= ax-general.c ax-gdb.c \=0A= bcache.c blockframe.c breakpoint.c buildsym.c builtin-regs.c \=0A= c-exp.y c-lang.c c-typeprint.c c-valprint.c \=0A= ! charset.c cli-out.c coffread.c complaints.c completer.c corefile.c \=0A= cp-abi.c cp-support.c cp-valprint.c \=0A= dbxread.c demangle.c disasm.c doublest.c \=0A= dummy-frame.c dwarfread.c dwarf2read.c \=0A= --- 501,508 ----=0A= ax-general.c ax-gdb.c \=0A= bcache.c blockframe.c breakpoint.c buildsym.c builtin-regs.c \=0A= c-exp.y c-lang.c c-typeprint.c c-valprint.c \=0A= ! charset.c cli-out.c coffread.c coff-pe-read.c \=0A= ! complaints.c completer.c corefile.c \=0A= cp-abi.c cp-support.c cp-valprint.c \=0A= dbxread.c demangle.c disasm.c doublest.c \=0A= dummy-frame.c dwarfread.c dwarf2read.c \=0A= *************** call_cmds_h =3D call-cmds.h=0A= *** 598,603 ****=0A= --- 599,605 ----=0A= ch_lang_h =3D ch-lang.h=0A= cli_out_h =3D cli-out.h=0A= coff_solib_h =3D coff-solib.h=0A= + coff_pe_read_h =3D coff-pe-read.h=0A= command_h =3D command.h=0A= complaints_h =3D complaints.h=0A= completer_h =3D completer.h=0A= *************** COMMON_OBS =3D version.o blockframe.o brea=0A= *** 817,823 ****=0A= kod.o kod-cisco.o \=0A= gdb-events.o \=0A= exec.o bcache.o objfiles.o minsyms.o maint.o demangle.o \=0A= ! dbxread.o coffread.o elfread.o \=0A= dwarfread.o dwarf2read.o mipsread.o stabsread.o corefile.o \=0A= c-lang.o f-lang.o \=0A= ui-out.o cli-out.o \=0A= --- 819,825 ----=0A= kod.o kod-cisco.o \=0A= gdb-events.o \=0A= exec.o bcache.o objfiles.o minsyms.o maint.o demangle.o \=0A= ! dbxread.o coffread.o coff-pe-read.o elfread.o \=0A= dwarfread.o dwarf2read.o mipsread.o stabsread.o corefile.o \=0A= c-lang.o f-lang.o \=0A= ui-out.o cli-out.o \=0A= *************** coffread.o: coffread.c $(defs_h) $(symta=0A= *** 1570,1576 ****=0A= $(breakpoint_h) $(bfd_h) $(gdb_obstack_h) $(gdb_string_h) \=0A= $(coff_internal_h) $(libcoff_h) $(symfile_h) $(objfiles_h) \=0A= $(buildsym_h) $(gdb_stabs_h) $(stabsread_h) $(complaints_h) \=0A= ! $(target_h) $(gdb_assert_h)=0A= complaints.o: complaints.c $(defs_h) $(complaints_h) $(gdb_assert_h) \=0A= $(command_h) $(gdbcmd_h)=0A= completer.o: completer.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression= _h) \=0A= --- 1572,1580 ----=0A= $(breakpoint_h) $(bfd_h) $(gdb_obstack_h) $(gdb_string_h) \=0A= $(coff_internal_h) $(libcoff_h) $(symfile_h) $(objfiles_h) \=0A= $(buildsym_h) $(gdb_stabs_h) $(stabsread_h) $(complaints_h) \=0A= ! $(target_h) $(gdb_assert_h) $(coff_pe_read_h)=0A= ! coff-pe-read.o: coff-pe-read.c $(bfd_h) $(defs_h) $(symtab_h) \=0A= ! $(gdbtypes_h) $(symfile_h) $(objfiles_h) $(coff_pe_read_h)=0A= complaints.o: complaints.c $(defs_h) $(complaints_h) $(gdb_assert_h) \=0A= $(command_h) $(gdbcmd_h)=0A= completer.o: completer.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression= _h) \=0A= ------=_NextPart_000_0157_01C2B8F8.ECD5A5E0 Content-Type: application/octet-stream; name="coffread.c.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="coffread.c.diff" Content-length: 882 Index: coffread.c =================================================================== RCS file: /cvs/src/src/gdb/coffread.c,v retrieving revision 1.32 diff -c -p -r1.32 coffread.c *** coffread.c 17 Dec 2002 00:39:07 -0000 1.32 --- coffread.c 10 Jan 2003 22:33:35 -0000 *************** *** 45,50 **** --- 45,52 ---- #include "target.h" #include "gdb_assert.h" + #include "coff-pe-read.h" + extern void _initialize_coffread (void); struct coff_symfile_info *************** coff_symtab_read (long symtab_offset, un *** 1084,1089 **** --- 1086,1098 ---- process_coff_symbol (cs, &main_aux, objfile); break; } + } + + if ((nsyms == 0) && (pe_file)) + { + /* We've got no debugging symbols, but it's is a portable + executable, so try to read the export table */ + read_pe_exported_syms (objfile); } if (last_source_file) ------=_NextPart_000_0157_01C2B8F8.ECD5A5E0--