From owner-freebsd-hackers Sat Jul 7 17:18: 6 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from alpo.whistle.com (s206m1.whistle.com [207.76.206.1]) by hub.freebsd.org (Postfix) with ESMTP id 4C8D637B403 for ; Sat, 7 Jul 2001 17:18:03 -0700 (PDT) (envelope-from mark-ml@whistle.com) Received: from [207.76.207.129] ([10.1.10.118]) by alpo.whistle.com (8.9.1a/8.9.1) with ESMTP id RAA97242; Sat, 7 Jul 2001 17:17:15 -0700 (PDT) Mime-Version: 1.0 X-Sender: mark-ml@207.76.206.1 Message-Id: In-Reply-To: <20010706232729.J93367@bsd.havk.org> References: <20010706232729.J93367@bsd.havk.org> Date: Sat, 7 Jul 2001 17:17:23 -0700 To: Steve Price , hackers@FreeBSD.ORG From: Mark Peek Subject: Re: FW: gdb debugging tips Content-Type: text/plain; charset="us-ascii" ; format="flowed" Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG At 11:27 PM -0500 7/6/01, Steve Price wrote: >Not sure if this is hackers@ material but since it is FreeBSD- >related and is probably something people on this can do in their >sleep I'm forwarding this here after no response on chat. > >----- Forwarded message from Steve Price ----- > >I've been having problems with a software package for which I >only have a binary with no debugging symbols. In talking to >the folks that wrote the software I know what arguments the >routine takes I just need to be able to see them in the debugger. >Here's what I've done: > >Fire up the program. Attach to the pid of the running process >with 'gdb lsv 10336'. I've set the breakpoint at the routine >that I'm interested in 'break LH2P' and I've coerced the program >to run to the breakpoint. > >Here's where I'm lost. I'm back in gdb and it is waiting for >me to tell it what to do. I know the function LH2P takes one >argument a 'char *'. How do I view a function's arguments? With >debugging symbols this is as easy as 'where'. I figured >'info args' would be the ticket but all it says is 'No symbol >table info avialable'. Now I'm betting the information from >'info frame' is the key but how to decipher it. Assuming ordinary i386 calling conventions... Usually gdb will stop in a function after it has adjusted the stack frame. You should be able to dump the strings (assuming it is null terminated) with: print *(char **)($ebp+8) In other words, ebp is pointing to the call stack frame. The +8 is needed to skip over the saved registers (ebp and eip which you will see listed in 'info frame') and get to the first argument which you can then dereference. So, for example: # cat > xx.c void func(char *sarg) { } main() { func("hello world\n"); } # cc -O -o xx xx.c # gdb xx GNU gdb 4.18 Copyright 1998 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 "i386-unknown-freebsd"... (no debugging symbols found)... (gdb) b func Breakpoint 1 at 0x804848f (gdb) run Starting program: xx (no debugging symbols found)...(no debugging symbols found)... Breakpoint 1, 0x804848f in func () (gdb) print *(char **)($ebp+8) $1 = 0x80484e3 "hello world\n" (gdb) Mark To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message