Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Feb 1999 13:29:52 +1030
From:      Greg Lehey <grog@lemis.com>
To:        Chuck Robey <chuckr@mat.net>, Eivind Eklund <eivind@FreeBSD.ORG>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: gdb sucks - and I need to get around it.  help?
Message-ID:  <19990217132952.Z515@lemis.com>
In-Reply-To: <Pine.BSF.4.05.9902161238390.327-100000@picnic.mat.net>; from Chuck Robey on Tue, Feb 16, 1999 at 12:41:34PM -0500
References:  <19990216170310.C60651@bitbox.follo.net> <Pine.BSF.4.05.9902161238390.327-100000@picnic.mat.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday, 16 February 1999 at 12:41:34 -0500, Chuck Robey wrote:
> On Tue, 16 Feb 1999, Eivind Eklund wrote:
>
>> Anybody know of any way of getting gdb to step from the start of the
>> program?
>>
>> I have an executable with absolutely no symbol data (symbol data is
>> absolutely non-available) which I *have* to get to step through, if
>> necessary by re-implementing gdb.
>
> You can tell the absolute address of main(), right?  Can't you just set
> a breakpoint of the program to the address of main() directly (not
> symbolically) then start the program.  It should stop immediately, then
> you can single step until you fall asleep, right?
>
> That's all if this is a C program.  If it's C++, where there is stuff
> active even before main(), then I'm not sure the address you'd want, but
> it'd NOT be main().  I think I'd get it via objdump.  It could read the
> elf headers and get it.

There's stuff before main in C programs as well.  The entry point of
all C and C++ programs is start, which is in crt0.o or crt1.o.  In
a.out files, it used to be directly after the header at 0x1020.  I'm
not sure where the start address is in an ELF file.  The clue should
be here somewhere, but I can't see it:

$ objdump   --section-headers /bin/sh

/bin/sh:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .init         00000006  08048074  08048074  00000074  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text         00042c50  0804807c  0804807c  0000007c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .fini         00000006  0808accc  0808accc  00042ccc  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  3 .rodata       0000706d  0808acd4  0808acd4  00042cd4  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .data         00002758  08092d44  08092d44  00049d44  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  5 .ctors        00000008  0809549c  0809549c  0004c49c  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  6 .dtors        00000008  080954a4  080954a4  0004c4a4  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  7 .bss          00008eec  080954b0  080954b0  0004c4b0  2**4
                  ALLOC
  8 .comment      00000fdc  00000000  00000000  0004c4b0  2**0
                  CONTENTS, READONLY
  9 .note         00000fdc  00000fdc  00000fdc  0004d48c  2**0
                  CONTENTS, READONLY
 10 .gnu.warning.f_prealloc 0000003a  00001fb8  00001fb8  0004e468  2**0
                  CONTENTS, READONLY


I set a breakpoint on the base address of the text segment, but it
didn't hit:

$ gdb /bin/sh
GDB is free software and you are welcome to 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.
GDB 4.16 (i386-unknown-freebsd), 
Copyright 1996 Free Software Foundation, Inc...(no debugging symbols found)...
(gdb) b *0x0804807c
Breakpoint 1 at 0x804807c
(gdb) r
Starting program: /bin/sh 
warning: shared library handler failed to enable breakpoint
# ^C
Program received signal SIGINT, Interrupt.
0x806b234 in ?? ()
(gdb) bt
#0  0x806b234 in ?? ()
#1  0x804f34a in ?? ()
#2  0x8054399 in ?? ()
#3  0x80541f5 in ?? ()
#4  0x80535e9 in ?? ()
#5  0x80511fb in ?? ()
#6  0x805118b in ?? ()
#7  0x80480e9 in ?? ()
(gdb) 

The backtrace looks like it's coming from that address, so I'd guess
that the address is correct, and the "failed to enable breakpoint"
warning is the problem.  Is this a bug or a feature?

Greg
--
See complete headers for address, home page and phone numbers
finger grog@lemis.com for PGP public key


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990217132952.Z515>