From: "Raoul Gough" <RaoulGough@yahoo.co.uk>
To: gdb-patches@sources.redhat.com
Subject: Re: coffread.c extension for DLLs without debugging symbols
Date: Tue, 07 Jan 2003 13:11:00 -0000 [thread overview]
Message-ID: <avejk1$lv6$1@main.gmane.org> (raw)
In-Reply-To: <20030104205130.GA9784@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1702 bytes --]
"Christopher Faylor" <cgf@redhat.com> wrote in message
news:20030104205130.GA9784@redhat.com...
> On Sat, Jan 04, 2003 at 04:25:16PM -0000, Raoul Gough wrote:
> >"Christopher Faylor" <cgf@redhat.com> wrote in message
> >news:20030104044408.GA7364@redhat.com...
> >> P.S. Assuming that this works as advertised, I assume that you
will
> >> have no objections to my releasing a new version of gdb for
windows
> >> with this patch in it before the patch makes its way into the
official
> >> gdb repository, right? I think there are a few users in the
cygwin
> >> mailing list that would appreciate this change.
> >
> >By all means - please do. You may as well use the new diff for the
> >comment fixes and the strncmp business.
>
> Ok. Coming soon to a cygwin mirror near you.
Chris, I've done some more testing and discovered a problem with the
virtual memory address determination mechanism. I've been using
bfd_get_section_vma to find out where each section is in memory, but
this is not always correct. BFD returns the DLL's *preferred* load
address, but it may actually have been relocated during loading
because of address space clashes. It seems obvious now, but BFD is not
the right place to get the needed information. I'm looking into the
win32-nat code that handles DLL load events, which *does* know about
the real load address. Unfortunately, this really will make the code
win32 specific. Unless someone else can suggest anything better?
Actually, this seems like a generic bug in GDB's DLL handling - by
compiling with debugging symbols, the problem is even visible without
my patch. Have a look at the attached example, which shows GDB 5.2.1
getting it wrong.
Regards,
Raoul Gough.
[-- Attachment #2: example2.txt --]
[-- Type: text/plain, Size: 2962 bytes --]
$ cat dlleg.c
__attribute((__dllexport__)) void fn () { }
__attribute((__dllexport__)) char hello[] = "Hello world";
__attribute((__dllexport__)) int init_data = 42;
__attribute((__dllexport__)) int uninit_data;
$ cat dlleg2.c
__attribute((__dllexport__)) void fn2 () { }
__attribute((__dllexport__)) char hello2[] = "Hello again";
__attribute((__dllexport__)) int init_data2 = 44;
__attribute((__dllexport__)) int uninit_data2;
$ cat dllegmain.c
__attribute((__dllimport__)) void fn ();
__attribute((__dllimport__)) char hello[];
__attribute((__dllimport__)) int init_data;
__attribute((__dllimport__)) int uninit_data;
__attribute((__dllimport__)) void fn2 ();
__attribute((__dllimport__)) char hello2[];
__attribute((__dllimport__)) int init_data2;
__attribute((__dllimport__)) int uninit_data2;
int main ()
{
fn();
uninit_data = init_data;
fn2();
uninit_data2 = init_data2;
return 0;
}
$ gcc -g -c dlleg.c
$ gcc -g -c dlleg2.c
$ gcc -g -c dllegmain.c
$ #
$ # Note - by omitting the --enable-auto-image-base linker flag, both
$ # DLLs get the same load address by default (0x1000000). At load
$ # time, one of them gets relocated
$ #
$ gcc -shared -o dlleg.dll dlleg.o
$ gcc -shared -o dlleg2.dll dlleg2.o
$ gcc -o dllegmain dllegmain.o dlleg.dll dlleg2.dll
$ gdb dllegmain
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "mingw32"...
(gdb) break main
Breakpoint 1 at 0x401050: file dllegmain.c, line 13.
(gdb) run
Starting program: f:\Users\Raoul\gdb/dllegmain.exe
Breakpoint 1, main () at dllegmain.c:13
13 fn();
(gdb) x/s &hello
0x10002000 <hello2>: "Hello again"
(gdb) #
(gdb) # Uh oh. The symbol "hello" should point to the string
(gdb) # "Hello world", and hello2 should be "Hello again"
(gdb) # (see dlleg.c and dlleg2.c above)
(gdb) #
(gdb) x/s &hello2
0x10002000 <hello2>: "Hello again"
(gdb) #
(gdb) # win32-nat.c knows the real load addresses:
(gdb) #
(gdb) info dll
DLL Name Load Address
F:\cygwin\bin\cygwin1.dll 61001000
F:\WINNT\system32\kernel32.dll 77e81000
f:\Users\Raoul\gdb\dlleg2.dll 10001000
f:\Users\Raoul\gdb\dlleg.dll 00331000
F:\WINNT\system32\advapi32.dll 77db1000
F:\WINNT\system32\rpcrt4.dll 77d41000
F:\WINNT\system32\user32.dll 77e11000
F:\WINNT\system32\gdi32.dll 77f41000
(gdb) #
(gdb) # Using this information, we can find the other string
(gdb) # manually. dlleg2.dll got loaded at it's preferred
(gdb) # address, but dlleg.dll was relocated.
(gdb) #
(gdb) x/s 0x332000
0x332000: "Hello world"
(gdb) quit
The program is running. Exit anyway? (y or n) y
$
next prev parent reply other threads:[~2003-01-07 13:11 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-03 19:41 Raoul Gough
2003-01-04 0:53 ` Michael Snyder
2003-01-04 4:43 ` Christopher Faylor
2003-01-04 16:31 ` Raoul Gough
2003-01-04 17:54 ` Eli Zaretskii
2003-01-04 20:51 ` Christopher Faylor
2003-01-05 14:44 ` Mark Kettenis
2003-01-05 17:18 ` Christopher Faylor
2003-01-05 17:40 ` Daniel Jacobowitz
2003-01-07 1:03 ` Raoul Gough
2003-01-07 1:12 ` Daniel Jacobowitz
2003-01-07 13:11 ` Raoul Gough [this message]
2003-01-07 16:46 ` Christopher Faylor
2003-01-07 2:28 ` Michael Snyder
2003-01-07 2:24 ` Michael Snyder
2003-01-04 11:03 ` Eli Zaretskii
2003-01-04 16:21 ` Raoul Gough
2003-01-06 17:10 ` Elena Zannoni
2003-01-06 17:41 ` Christopher Faylor
2003-01-07 0:46 ` Raoul Gough
2003-01-07 1:53 ` Elena Zannoni
2003-01-10 22:45 ` Raoul Gough
2003-01-07 1:00 ` Andrew Cagney
2003-01-10 22:37 ` Raoul Gough
2003-01-04 16:42 Michael Elizabeth Chastain
2003-01-05 15:40 ` Andrew Cagney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='avejk1$lv6$1@main.gmane.org' \
--to=raoulgough@yahoo.co.uk \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox