pgubook-readers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pgubook-readers] toupper and command line args


From: Emmet Ford
Subject: Re: [Pgubook-readers] toupper and command line args
Date: Sun, 22 Feb 2004 23:31:33 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040119

Well, when a program begins, aren't the stack pointer and the base pointer
the same?

Yes, ebp gets set to the value in esp at the top of the program, setting up the 
initial stack frame. So, when I break at the second instruction and do an 'info 
registers', it shows esp and ebp holding the same value:


esp            0xbffffa70       0xbffffa70
ebp            0xbffffa70       0xbffffa70

argc is at %esp (same as %ebp at this point), argv[0] is at 4(%esp), arg[1] at 8(%esp) and so on...


You are correct. Examining the address stored in ebp (or esp, at this point) shows the address count. ebp + 4 contains the starting address of the arg0 string (the program name), ebp + 8 contains the starting address of the arg1 string, etc:

(gdb) x/1xw 0xbffffa70
0xbffffa70:     0x00000003
(gdb)
0xbffffa74:     0xbffffba4
(gdb)
0xbffffa78:     0xbffffbbb
(gdb)
0xbffffa7c:     0xbffffbc7

Examining the addresses of the argv strings reveals them to be where they should be, followed by the environmental variables:

(gdb) x/1sb 0xbffffba4
0xbffffba4:      "/home/eford/as/toupper"
(gdb)
0xbffffbbb:      "./toupper.s"
(gdb)
0xbffffbc7:      "./toupper.out"
(gdb)
0xbffffbd5:      "CPLUS_INCLUDE_PATH=/usr/lib/qt-3.2.1/include"

But I keep thinking I'm missing something, because page 91 makes it clear
that the first arg should be at 16(%esp), not 8(%esp).

Yes, it is curious. I suspect that you have happened upon a documentational 
anomaly. Time to hit the bug tracking database!

--Emmet Ford




reply via email to

[Prev in Thread] Current Thread [Next in Thread]