LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2008, 11:43 PM   #1
valpa
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Rep: Reputation: 15
breakpoint address different with symbol address??


I have compiled a very simple test.c to test

Quote:
xiaodwan@xd-linuxServer:~/test$ ls -l
total 536
-rwxr-xr-x 1 xiaodwan xiaodwan 536205 2008-08-18 21:23 test1
-rw-r--r-- 1 xiaodwan xiaodwan 49 2008-08-18 21:23 test1.c
-rw-r--r-- 1 xiaodwan xiaodwan 694 2008-08-18 21:23 test1.o
The symbol *main* address is 0804cf54.
Quote:
0804cf54 <main>:
804cf54: 8d 4c 24 04 lea 0x4(%esp),%ecx
804cf58: 83 e4 f0 and $0xfffffff0,%esp
804cf5b: ff 71 fc pushl 0xfffffffc(%ecx)
804cf5e: 55 push %ebp
804cf5f: 89 e5 mov %esp,%ebp
804cf61: 51 push %ecx
804cf62: b8 00 00 00 00 mov $0x0,%eax
804cf67: 59 pop %ecx
804cf68: 5d pop %ebp
804cf69: 8d 61 fc lea 0xfffffffc(%ecx),%esp
804cf6c: c3 ret
804cf6d: 90 nop
804cf6e: 90 nop
804cf6f: 90 nop
But GDB set break at 0x804cf62, not 0804cf54, why???

Quote:
xiaodwan@xd-linuxServer:~/test$ gdb test1
GNU gdb 6.6-debian
Copyright (C) 2006 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 "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main
Breakpoint 1 at 0x804cf62
(gdb) b _start
Breakpoint 2 at 0x804ceb0
(gdb) info main
Undefined info command: "main". Try "help info".
(gdb) info symbol main
main in section .text
(gdb) info address main
Symbol "main" is at 0x804cf54 in a file compiled without debugging.
(gdb)
 
Old 08-19-2008, 07:06 AM   #2
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
Maybe because between 0x804cf54 and 0x804cf62, the heap of the function is created...
When you need to branch to main, you call 0x804cf54, but when you need to debug, you want to stop at 0x804cf62 so the registers and the adresses that refer to the heap make sense.
 
Old 08-20-2008, 01:47 AM   #3
valpa
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Agrouf View Post
Maybe because between 0x804cf54 and 0x804cf62, the heap of the function is created...
When you need to branch to main, you call 0x804cf54, but when you need to debug, you want to stop at 0x804cf62 so the registers and the adresses that refer to the heap make sense.
I don't know much about the *function heap*. Could you give some explain or reference?
 
Old 08-20-2008, 04:04 AM   #4
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
Sorry I meant the call stack of the function.
http://en.wikipedia.org/wiki/Call_stack

Last edited by Agrouf; 08-20-2008 at 04:05 AM.
 
Old 08-21-2008, 01:58 AM   #5
valpa
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Agrouf View Post
Sorry I meant the call stack of the function.
http://en.wikipedia.org/wiki/Call_stack

Are you sure it is because call stack?
I think 0x804cf54 and 0x804cf62 both in .text segment. These two address do nothing about stack region of a running program.
 
Old 08-21-2008, 02:20 AM   #6
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
Well maybe you could list the instructions between 0x804cf54 and 0x804cf62 to see what's in there...
 
Old 08-21-2008, 11:36 PM   #7
valpa
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Agrouf View Post
Well maybe you could list the instructions between 0x804cf54 and 0x804cf62 to see what's in there...

Here is the output, I changed a machine, so it is not 0x804cf62 & 0x804cf54 anymore, but same question exist. Now it's 0x8048382 and 0x8048374

Code:
[xiaodwan@xd-Arch test]$ objdump -d -j .text test1

test1:     file format elf32-i386

Disassembly of section .text:

...
08048374 <main>:
 8048374:	8d 4c 24 04          	lea    0x4(%esp),%ecx
 8048378:	83 e4 f0             	and    $0xfffffff0,%esp
 804837b:	ff 71 fc             	pushl  -0x4(%ecx)
 804837e:	55                   	push   %ebp
 804837f:	89 e5                	mov    %esp,%ebp
 8048381:	51                   	push   %ecx
 8048382:	83 ec 04             	sub    $0x4,%esp
 8048385:	83 c4 04             	add    $0x4,%esp
 8048388:	59                   	pop    %ecx
 8048389:	5d                   	pop    %ebp
 804838a:	8d 61 fc             	lea    -0x4(%ecx),%esp
 804838d:	c3                   	ret    
 804838e:	90                   	nop    
 804838f:	90                   	nop    
...

[xiaodwan@xd-Arch test]$ gdb test1
GNU gdb 6.7.1
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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 "i686-pc-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) b main
Breakpoint 1 at 0x8048382
(gdb) info main
Undefined info command: "main".  Try "help info".
(gdb) help info
Generic command for showing things about the program being debugged.

List of info subcommands:

info address -- Describe where symbol SYM is stored
info all-registers -- List of all registers and their contents
info args -- Argument variables of current stack frame
info auxv -- Display the inferior's auxiliary vector
info breakpoints -- Status of user-settable breakpoints
info catch -- Exceptions that can be caught in the current stack frame
info checkpoints -- IDs of currently known forks/checkpoints
info classes -- All Objective-C classes
info common -- Print out the values contained in a Fortran COMMON block
info copying -- Conditions for redistributing copies of GDB
info dcache -- Print information on the dcache performance
info display -- Expressions to display when program stops
info extensions -- All filename extensions associated with a source language
info files -- Names of targets and files being debugged
info float -- Print the status of the floating point unit
info forks -- IDs of currently known forks/checkpoints
info frame -- All about selected stack frame
info functions -- All function names
info handle -- What debugger does when program gets various signals
---Type <return> to continue, or q <return> to quit---q
Quit
(gdb) info address main
Symbol "main" is at 0x8048374 in a file compiled without debugging.
(gdb)
 
Old 08-22-2008, 12:44 AM   #8
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
Actually, the esp register is the pointer to the top of the stack.
So you see it is preparing the stack register between 0x8048374 and 0x8048382
Quote:
8048374: 8d 4c 24 04 lea 0x4(%esp),%ecx
8048378: 83 e4 f0 and $0xfffffff0,%esp
804837b: ff 71 fc pushl -0x4(%ecx)
804837e: 55 push %ebp
804837f: 89 e5 mov %esp,%ebp
8048381: 51 push %ecx
 
Old 08-23-2008, 12:46 AM   #9
valpa
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Original Poster
Rep: Reputation: 15
OK, I know that.

Code:
 8048374:	8d 4c 24 04          	lea    0x4(%esp),%ecx
 8048378:	83 e4 f0             	and    $0xfffffff0,%esp
 804837b:	ff 71 fc             	pushl  -0x4(%ecx)
 804837e:	55                   	push   %ebp
 804837f:	89 e5                	mov    %esp,%ebp
 8048381:	51                   	push   %ecx
Above is the Call stack preparation.


then, call stack roll back from 8048382 to 804838a
Code:
 
 8048382:	83 ec 04             	sub    $0x4,%esp
 8048385:	83 c4 04             	add    $0x4,%esp
 8048388:	59                   	pop    %ecx
 8048389:	5d                   	pop    %ebp
 804838a:	8d 61 fc             	lea    -0x4(%ecx),%esp
 804838d:	c3                   	ret
GDB always know the code length of function call stack operation, right?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Router gateway address being picked up as primary DNS address under SuSe Hubmasterflex Linux - Networking 13 10-18-2008 01:40 PM
WARNING: IP: Hardware address '***' trying to be our address 172.016.104.065 sunram Solaris / OpenSolaris 1 05-30-2008 08:51 AM
Find real ip address using link local address, mdns/zeroconf dannemanare Linux - Networking 0 01-17-2008 04:31 AM
Single DHCP server ,to provide the ip address to a MAC address in two different subne alix123 Linux - Software 5 05-08-2007 11:16 PM
how to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 04:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration