- 论坛徽章:
- 11
|
如题,请教各位:
《professional assembly language》中讲到,命令行参数的个数保存在ESP指针之后(向高地址方向)的位置,但小弟通过代码并未验证到这一点:- root@c-dev:/cdev# vi memory_layout.c
复制代码- int main (int argc, char *argv[])
- {
- return 0;
- }
复制代码- root@c-dev:/cdev# gcc -m32 -g memory_layout.c -o memory_layout
复制代码- root@c-dev:/cdev# gdb --args memory_layout a bc def
- GNU gdb (GDB) 7.0.1-debian
- Copyright (C) 2009 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 "x86_64-linux-gnu".
- For bug reporting instructions, please see:
- <http://www.gnu.org/software/gdb/bugs/>...
- Reading symbols from /cdev/memory_layout...done.
- (gdb) break main
- Breakpoint 1 at 0x8048397: file memory_layout.c, line 3.
- (gdb) run
- Starting program: /cdev/memory_layout a bc def
- Breakpoint 1, main (argc=4, argv=0xffffdd54) at memory_layout.c:3
- 3 return 0;
- (gdb) x/x 0xffffdd54
- 0xffffdd54: 0xffffde70
- (gdb) x/s 0xffffde70
- 0xffffde70: "/cdev/memory_layout"
- (gdb) print argv[0]
- $1 = 0xffffde70 "/cdev/memory_layout"
- (gdb) print argv[1]
- $2 = 0xffffde84 "a"
- (gdb) print argv[2]
- $3 = 0xffffde86 "bc"
复制代码 自argv的内存地址开始向高地址方向,依次为各个命令行参数和环境变量,但通过怎样的方法才能找到保存命令行参数个数的内存地址呢?
请各位大神指点一下,小弟菜鸟,不甚感谢。
|
|