gdb和strncmp,是否存储了寄存器值?

gdb和strncmp,是否存储了寄存器值?,gdb,Gdb,下面是我的代码(test.c): #包括 #包括 int main(int argc,字符**argv){ char passwd[]=“pass”; 如果(argc

下面是我的代码(test.c):

#包括
#包括
int main(int argc,字符**argv){
char passwd[]=“pass”;
如果(argc<2){
printf(“用法:%s\n”,argv[0]);
返回0;
}
如果(!strncmp(passwd,argv[1],4)){
printf(“绿灯!\n”);
返回1;
}
printf(“红灯!\n”);
返回0;
}
我使用以下方法编译:

  gcc -o test test.c

    And I started debugger: `gdb ./test`
    (gdb) disassemble main
    Dump of assembler code for function main:
    0x08048404 <main+0>:    lea    0x4(%esp),%ecx
    ......
    0x08048456 <main+82>:   mov    0x4(%edx),%eax
    0x08048459 <main+85>:   add    $0x4,%eax
    0x0804845c <main+88>:   mov    (%eax),%eax
    0x0804845e <main+90>:   movl   $0x4,0x8(%esp)
    0x08048466 <main+98>:   mov    %eax,0x4(%esp)
    0x0804846a <main+102>:  lea    -0x9(%ebp),%eax
    0x0804846d <main+105>:  mov    %eax,(%esp)
    0x08048470 <main+108>:  call   0x8048318 <strncmp@plt>
    0x08048475 <main+113>:  test   %eax,%eax
    0x08048477 <main+115>:  jne    0x804848e <main+138>
    0x08048479 <main+117>:  movl   $0x804859c,(%esp)
    0x08048480 <main+124>:  call   0x8048308 <puts@plt>
    0x08048485 <main+129>:  movl   $0x1,-0x18(%ebp)
 ...........
    0x080484a8 <main+164>:  pop    %ebp
    0x080484a9 <main+165>:  lea    -0x4(%ecx),%esp
    0x080484ac <main+168>:  ret
    End of assembler dump.
gcc-o test.c
我启动了调试器:`gdb./test`
(gdb)拆卸主管道
主功能的汇编程序代码转储:
0x08048404:lea 0x4(%esp),%ecx
......
0x08048456:mov 0x4(%edx),%eax
0x08048459:添加$0x4,%eax
0x0804845c:mov(%eax),%eax
0x0804845e:movl$0x4,0x8(%esp)
0x08048466:mov%eax,0x4(%esp)
0x0804846a:lea-0x9(%ebp),%eax
0x0804846d:mov%eax,(%esp)
0x08048470:呼叫0x8048318
0x08048475:测试%eax,%eax
0x08048477:jne 0x804848e
0x08048479:movl$0x804859c,(%esp)
0x08048480:调用0x8048308
0x08048485:movl$0x1,-0x18(%ebp)
...........
0x080484a8:弹出%ebp
0x080484a9:lea-0x4(%ecx),%esp
0x080484ac:ret
汇编程序转储结束。
我将断点设置在main+108并运行prog

    (gdb) break *main+108
    Breakpoint 1 at 0x8048470
    (gdb) run p@ss
    Starting program: /etc/hien/test p@ss

    Breakpoint 1, 0x08048470 in main ()
    eax            0xbfffe9ff       -1073747457
    ecx            0xbfffea20       -1073747424
    edx            0xbfffea20       -1073747424
    ebx            0xaebff4 11452404
    esp            0xbfffe9e0       0xbfffe9e0
    ebp            0xbfffea08       0xbfffea08
    esi            0x994ca0 10046624
    edi            0x0      0
    eip            0x8048470        0x8048470 <main+108>
    eflags         0x282    [ SF IF ]
    cs             0x73     115
    ss             0x7b     123
    ds             0x7b     123
    es             0x7b     123
    fs             0x0      0
    gs             0x33     51
    (gdb) x/s $eax
    0xbfffe9ff:      "pass"
    (gdb) x/s $ecx
    0xbfffea20:      "\002"
    (gdb)
(gdb)断开*main+108
断点1位于0x8048470
(gdb)运行p@ss
启动程序:/etc/hien/testp@ss
主()中的断点1,0x08048470
eax 0xbfffe9ff-1073747457
ecx 0xbfffea20-1073747424
edx 0xbfffea20-1073747424
ebx 0xaebff4 11452404
esp 0xbfffe9e0 0xbfffe9e0
ebp 0xbfffea08 0xbfffea08
esi 0x994ca0 10046624
电子数据交换0x0
eip 0x8048470 0x8048470
eflags 0x282[SF IF]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb)x/s$eax
0xbfffe9ff:“通过”
(gdb)x/s$ecx
0xbfffea20:“\002”
(gdb)
哪个寄存器可以显示“argv[1]”的值?
请帮帮我!谢谢

调用约定应该是将所有参数推送到堆栈中。所以试试看

(gdb) x/s *(0 + (void**)$esp)
# should show "pass"
(gdb) x/s *(1 + (void**)$esp)
# should show argv[1]
(gdb) x/d *(2 + (void**)$esp)
# should show 4

调用约定应该是将所有参数推送到堆栈。所以试试看

(gdb) x/s *(0 + (void**)$esp)
# should show "pass"
(gdb) x/s *(1 + (void**)$esp)
# should show argv[1]
(gdb) x/d *(2 + (void**)$esp)
# should show 4

您需要注册表(可能不在注册表中)有什么原因吗?只需使用
-g
选项编译并发出“在gdb中打印argv[1]`是不够的”?如果不使用-g选项,argv[1]的值存储在哪里?是否有某些原因需要寄存器(它可能不在寄存器中)?只需使用
-g
选项编译并发出“在gdb中打印argv[1]`是不够的)?argv[1]的值在哪里存储如果不使用-g选项?非常好的答案!非常感谢你!回答得很好!非常感谢你!