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 12499 invoked from network); 11 Jan 2003 15:51:51 -0000 Received: from unknown (HELO main.gmane.org) (80.91.224.249) by 209.249.29.67 with SMTP; 11 Jan 2003 15:51:51 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18XNtz-00064l-00 for ; Sat, 11 Jan 2003 16:50:27 +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 18XNtv-00064P-00 for ; Sat, 11 Jan 2003 16:50:23 +0100 Path: not-for-mail From: "Raoul Gough" Subject: [RFC]: win32-nat.c better handling of DLL relocation Date: Sat, 11 Jan 2003 15:51:00 -0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_008E_01C2B989.664A5200" 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/msg00449.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_008E_01C2B989.664A5200 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-length: 643 win32-nat.c currently only passes the loaded address of the .text section into symbol_file_add, which means that any symbols from .data or .bss don't get fixed up properly. This patch fixes the problem by calculating the load addresses of all sections known to bfd. I recently posted a test case which demonstrates the relocation problem in the "coffread.c extension" thread (message ID avejk1$lv6$1@main.gmane.org, posted 7 Jan 2003 13:10:49 -0000). This showed that gdb 5.2.1 didn't handle any DLL symbol relocations. The current CVS version only handles the .text section. With this patch, it handles all sections correctly. Raoul Gough. ------=_NextPart_000_008E_01C2B989.664A5200 Content-Type: text/plain; name="ChangeLog_entry.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ChangeLog_entry.txt" Content-length: 250 2003-01-10 Raoul Gough * win32-nat.c(get_relocated_section_addrs): New function. Find section load addresses for symbol handling in relocated DLLs. (solib_symbols_add): Open a bfd and call get_relocated_section_addrs. ------=_NextPart_000_008E_01C2B989.664A5200 Content-Type: application/octet-stream; name="win32-nat.c.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="win32-nat.c.diff" Content-length: 5127 Index: win32-nat.c=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/win32-nat.c,v=0A= retrieving revision 1.66=0A= diff -c -p -r1.66 win32-nat.c=0A= *** win32-nat.c 23 Nov 2002 02:49:45 -0000 1.66=0A= --- win32-nat.c 11 Jan 2003 15:49:38 -0000=0A= *************** child_clear_solibs (void)=0A= *** 750,761 ****=0A= solib_end =3D &solib_start;=0A= max_dll_name_len =3D sizeof ("DLL Name") - 1;=0A= }=0A= =20=20=0A= /* Add DLL symbol information. */=0A= static struct objfile *=0A= solib_symbols_add (char *name, int from_tty, CORE_ADDR load_addr)=0A= {=0A= ! struct section_addr_info section_addrs;=0A= =20=20=0A= /* The symbols in a dll are offset by 0x1000, which is the=0A= the offset from 0 of the first byte in an image - because=0A= --- 750,816 ----=0A= solib_end =3D &solib_start;=0A= max_dll_name_len =3D sizeof ("DLL Name") - 1;=0A= }=0A= + =0C=0A= + /* Get the loaded address of all sections, given that .text was loaded=0A= + at text_load. Assumes that all sections are subject to the same=0A= + relocation offset. Returns NULL if problems occur or if the=0A= + sections were not relocated. */=0A= =20=20=0A= + static struct section_addr_info *=0A= + get_relocated_section_addrs (bfd *abfd, CORE_ADDR text_load)=0A= + {=0A= + struct section_addr_info *result =3D NULL;=0A= + int section_count =3D bfd_count_sections (abfd);=0A= + asection *text_section =3D bfd_get_section_by_name (abfd, ".text");=0A= + CORE_ADDR text_vma;=0A= +=20=0A= + if (!text_section)=0A= + {=0A= + /* Couldn't get the .text section. Weird. */=0A= + }=0A= +=20=0A= + else if (text_load =3D=3D (text_vma =3D bfd_get_section_vma (abfd, text= _section)))=0A= + {=0A= + /* DLL wasn't relocated. */=0A= + }=0A= +=20=0A= + else=0A= + {=0A= + /* Figure out all sections' loaded addresses. The offset here is=0A= + such that taking a bfd_get_section_vma() result and adding=0A= + offset will give the real load address of the section. */=0A= +=20=0A= + CORE_ADDR offset =3D text_load - text_vma;=0A= +=20=0A= + struct section_table *table_start =3D NULL;=0A= + struct section_table *table_end =3D NULL;=0A= + struct section_table *iter =3D NULL;=0A= +=20=0A= + build_section_table (abfd, &table_start, &table_end);=0A= +=20=0A= + for (iter =3D table_start; iter < table_end; ++iter)=0A= + {=0A= + /* Relocated addresses. */=0A= + iter->addr +=3D offset;=0A= + iter->endaddr +=3D offset;=0A= + }=0A= +=20=0A= + result =3D build_section_addr_info_from_section_table (table_start,= =0A= + table_end);=0A= +=20=0A= + xfree (table_start);=0A= + }=0A= +=20=0A= + return result;=0A= + }=0A= + =0C=0A= /* Add DLL symbol information. */=0A= static struct objfile *=0A= solib_symbols_add (char *name, int from_tty, CORE_ADDR load_addr)=0A= {=0A= ! struct section_addr_info *section_addrs_ptr =3D NULL;=0A= ! static struct objfile *result =3D NULL;=0A= ! bfd *abfd =3D NULL;=0A= =20=20=0A= /* The symbols in a dll are offset by 0x1000, which is the=0A= the offset from 0 of the first byte in an image - because=0A= *************** solib_symbols_add (char *name, int from_=0A= *** 764,773 ****=0A= if (!name || !name[0])=0A= return NULL;=0A= =20=20=0A= ! memset (§ion_addrs, 0, sizeof (section_addrs));=0A= ! section_addrs.other[0].name =3D ".text";=0A= ! section_addrs.other[0].addr =3D load_addr;=0A= ! return safe_symbol_file_add (name, from_tty, §ion_addrs, 0, OBJF_SH= ARED);=0A= }=0A= =20=20=0A= /* Load DLL symbol info. */=0A= --- 819,864 ----=0A= if (!name || !name[0])=0A= return NULL;=0A= =20=20=0A= ! abfd =3D bfd_openr (name, "pei-i386");=0A= !=20=0A= ! if (!abfd)=0A= ! {=0A= ! /* pei failed - try pe */=0A= ! abfd =3D bfd_openr (name, "pe-i386");=0A= ! }=0A= !=20=0A= ! if (abfd)=0A= ! {=0A= ! if (bfd_check_format (abfd, bfd_object))=0A= ! {=0A= ! section_addrs_ptr =3D get_relocated_section_addrs (abfd, load_addr);= =0A= ! }=0A= !=20=0A= ! bfd_close (abfd);=0A= ! }=0A= !=20=0A= ! if (section_addrs_ptr)=0A= ! {=0A= ! result =3D safe_symbol_file_add (name, from_tty, section_addrs_ptr,= =0A= ! 0, OBJF_SHARED);=0A= !=20=0A= ! free_section_addr_info (section_addrs_ptr);=0A= ! }=0A= !=20=0A= ! else=0A= ! {=0A= ! /* Fallback on handling just the .text section. */=0A= ! struct section_addr_info section_addrs;=0A= !=20=0A= ! memset (§ion_addrs, 0, sizeof (section_addrs));=0A= ! section_addrs.other[0].name =3D ".text";=0A= ! section_addrs.other[0].addr =3D load_addr;=0A= !=20=0A= ! result =3D safe_symbol_file_add (name, from_tty, §ion_addrs,=0A= ! 0, OBJF_SHARED);=0A= ! }=0A= !=20=0A= ! return result;=0A= }=0A= =20=20=0A= /* Load DLL symbol info. */=0A= ------=_NextPart_000_008E_01C2B989.664A5200--