From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28054 invoked by alias); 12 Jan 2009 15:08:48 -0000 Received: (qmail 28045 invoked by uid 22791); 12 Jan 2009 15:08:47 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=BAYES_00,J_CHICKENPOX_22,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from rn-out-0910.google.com (HELO rn-out-0910.google.com) (64.233.170.186) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 12 Jan 2009 15:08:16 +0000 Received: by rn-out-0910.google.com with SMTP id k40so7273918rnd.0 for ; Mon, 12 Jan 2009 07:08:14 -0800 (PST) Received: by 10.142.141.21 with SMTP id o21mr7518576wfd.308.1231772893698; Mon, 12 Jan 2009 07:08:13 -0800 (PST) Received: by 10.143.16.7 with HTTP; Mon, 12 Jan 2009 07:08:13 -0800 (PST) Message-ID: <74fef6df0901120708u3dab58eo462d8dae3e9d9ccb@mail.gmail.com> Date: Mon, 12 Jan 2009 15:08:00 -0000 From: "Mathieu Lacage" To: gdb@sourceware.org Subject: Re: how to make gdb happy with my linkmap In-Reply-To: <74fef6df0901050658g6c279a3ah321c7c6e30630475@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_256429_22060604.1231772893699" References: <74fef6df0812181341x8ecdd31me028bd4d658384b1@mail.gmail.com> <20081218214854.GA7706@caradoc.them.org> <74fef6df0812181402n1debced5xbe3f402a3a34ecf2@mail.gmail.com> <20081218221005.GA9012@caradoc.them.org> <74fef6df0812260239o1f21e833t6464c9d41bedcdd1@mail.gmail.com> <20081226125329.GA12783@caradoc.them.org> <74fef6df0901050658g6c279a3ah321c7c6e30630475@mail.gmail.com> X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-01/txt/msg00056.txt.bz2 ------=_Part_256429_22060604.1231772893699 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 2219 Just in case it helps anyone, since I did not really have time to investigate the gdb issues, I came up with the attached elf editor which replaces the content of PT_INTERP. Eventually, I will have to deal with gdb but, not now :) Mathieu On Mon, Jan 5, 2009 at 3:58 PM, Mathieu Lacage wrote: >> Does it work any better with ld.so? I doubt it - GDB doesn't do > > It does not seem to work any better with ld-linux.so.2. I tried to > look into this a bit more but I did not make much progress. Here is > what I get: > > mathieu@mathieu-boulot:~/code/elf-loader$ gdb ./ldso > GNU gdb 6.8-debian > Copyright (C) 2008 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. Type "show copying" > and "show warranty" for details. > This GDB was configured as "i486-linux-gnu"... > (gdb) b stage1 > Breakpoint 1 at 0x944: file ldso.c, line 304. > (gdb) r ./hello > Starting program: /home/mathieu/code/elf-loader/ldso ./hello > hello > > Program exited normally. > (gdb) > > What I find weird is: > 1) mathieu@mathieu-boulot:~/code/elf-loader$ readelf -s ./ldso |grep stage1 > 225: 00000932 135 FUNC GLOBAL HIDDEN 6 stage1 > mathieu@mathieu-boulot:~/code/elf-loader$ readelf -l ./ldso > > Elf file type is DYN (Shared object file) > Entry point 0x932 > There are 6 program headers, starting at offset 52 > [...] > > i.e., stage1 is located at offset 0x932, and not 0x944 so, I can't > figure out where the 0x944 displayed by gdb is coming from. I also > find it surprising that gdb is actually trying to set a breakpoint at > address 0x944: this is a pie binary so, gdb should know that the > address will be known only once the program is run.... > > To summarize, 2 questions: > 1) what do I need to do to make gdb _not_ attempt to really set the > breakpoint before the program is run ? > > 2) why is gdb using 0x944 and not 0x932 ? > > I am shooting a bit in the dark here, obviously. > > Mathieu > -- > Mathieu Lacage > -- Mathieu Lacage ------=_Part_256429_22060604.1231772893699 Content-Type: text/x-csrc; name=elfedit.c Content-Transfer-Encoding: base64 X-Attachment-Id: f_fpv9r1600 Content-Disposition: attachment; filename=elfedit.c Content-length: 2384 I2luY2x1ZGUgPHN5cy90eXBlcy5oPgojaW5jbHVkZSA8c3lzL3N0YXQuaD4K I2luY2x1ZGUgPGZjbnRsLmg+CiNpbmNsdWRlIDxlbGYuaD4KI2luY2x1ZGUg PGxpbmsuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgojaW5jbHVkZSA8c3RkbGli Lmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCgppbnQgbWFpbiAoaW50IGFyZ2Ms IGNoYXIgKmFyZ3ZbXSkKewogIGNvbnN0IGNoYXIgKmZpbGVuYW1lID0gYXJn dlsxXTsKICBFbGZXKEVoZHIpIGhlYWRlcjsKICBpbnQgZmQgPSBvcGVuIChm aWxlbmFtZSwgT19SRFdSKTsKCiAgc3NpemVfdCBieXRlc19yZWFkID0gcmVh ZCAoZmQsICZoZWFkZXIsIHNpemVvZiAoaGVhZGVyKSk7CiAgaWYgKGJ5dGVz X3JlYWQgIT0gc2l6ZW9mIChoZWFkZXIpKQogICAgewogICAgICByZXR1cm4g LTE7CiAgICB9CgogIEVsZlcoUGhkcikgKnBoID0gbWFsbG9jIChoZWFkZXIu ZV9waG51bSAqIGhlYWRlci5lX3BoZW50c2l6ZSk7CiAgaWYgKHBoID09IDAp CiAgICB7CiAgICAgIHJldHVybiAtMjsKICAgIH0KICBpZiAobHNlZWsgKGZk LCBoZWFkZXIuZV9waG9mZiwgU0VFS19TRVQpID09IC0xKQogICAgewogICAg ICByZXR1cm4gLTM7CiAgICB9CiAgaWYgKHJlYWQgKGZkLCBwaCwgaGVhZGVy LmVfcGhudW0gKiBoZWFkZXIuZV9waGVudHNpemUpICE9IGhlYWRlci5lX3Bo bnVtICogaGVhZGVyLmVfcGhlbnRzaXplKQogICAgewogICAgICByZXR1cm4g LTQ7CiAgICB9CiAgaW50IGk7CiAgZm9yIChpID0gMDsgaSA8IGhlYWRlci5l X3BobnVtOyBpKyspCi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ZW1zeiA9IHN0cmxlbiAoYXJndlsy XSkrMTsKCSAgaWYgKHdyaXRlIChmZCwgJm1lbXN6LCBzaXplb2YobWVtc3op KSAhPSBzaXplb2YobWVtc3opKQoJICAgIHsKCSAgICAgIHJldHVybiAtMTE7 CgkgICAgfQoJICByZXR1cm4gMDsKCX0KICAgIH0KICAKCiAgcmV0dXJuIDA7 Cn0K ------=_Part_256429_22060604.1231772893699--