C 使用GDB更改for循环条件?
我正在调试一个程序,对(int I=0;I)的行很感兴趣C 使用GDB更改for循环条件?,c,loops,debugging,gdb,C,Loops,Debugging,Gdb,我正在调试一个程序,对(int I=0;I)的行很感兴趣 想要更改我gdb无法更改您的代码,它设置为只读…我同意:我认为有一些工具允许您在调试器(Visual Studio?)中实际替换代码…但我怀疑gdb能做到这一点。我想,你可以改变寄存器来翻转跳转条件…嗯,这有点可疑。在这种情况下,可能只有跳转条件被改变,也许..通过编辑代码将10移动到一个变量中,然后通过gdb将变量编辑为11。 #include <stdio.h> int main() { for (int i = 0;
想要更改我gdb无法更改您的代码,它设置为只读…我同意:我认为有一些工具允许您在调试器(Visual Studio?)中实际替换代码…但我怀疑gdb能做到这一点。我想,你可以改变寄存器来翻转跳转条件…嗯,这有点可疑。在这种情况下,可能只有跳转条件被改变,也许..通过编辑代码将
10
移动到一个变量中,然后通过gdb将变量编辑为11
。
#include <stdio.h>
int main()
{
for (int i = 0; i < 10; i++)
printf("%d\n", i);
return 0;
}
gcc -g -std=c99 t.c && gdb -q ./a.out
gdb) disas main
Dump of assembler code for function main:
0x000000000040052d <+0>: push %rbp
0x000000000040052e <+1>: mov %rsp,%rbp
0x0000000000400531 <+4>: sub $0x10,%rsp
0x0000000000400535 <+8>: movl $0x0,-0x4(%rbp)
0x000000000040053c <+15>: jmp 0x400556 <main+41>
0x000000000040053e <+17>: mov -0x4(%rbp),%eax
0x0000000000400541 <+20>: mov %eax,%esi
0x0000000000400543 <+22>: mov $0x4005f4,%edi
0x0000000000400548 <+27>: mov $0x0,%eax
0x000000000040054d <+32>: callq 0x400410 <printf@plt>
0x0000000000400552 <+37>: addl $0x1,-0x4(%rbp)
0x0000000000400556 <+41>: cmpl $0x9,-0x4(%rbp)
0x000000000040055a <+45>: jle 0x40053e <main+17>
0x000000000040055c <+47>: mov $0x0,%eax
0x0000000000400561 <+52>: leaveq
0x0000000000400562 <+53>: retq
End of assembler dump.
(gdb) b *0x40055a if i == 10
Breakpoint 1 at 0x40055a: file t.c, line 4.
(gdb) run
Starting program: /tmp/a.out
0
1
2
3
4
5
6
7
8
9
Breakpoint 1, 0x000000000040055a in main () at t.c:4
4 for (int i = 0; i < 10; i++)
(gdb) p i
$1 = 10
(gdb) jump *0x40053e
Continuing at 0x40053e.
10
[Inferior 1 (process 22210) exited normally]
(gdb) disas/r 0x400556,0x400557
Dump of assembler code from 0x400556 to 0x400557:
0x0000000000400556 <main+41>: 83 7d fc 09 cmpl $0x9,-0x4(%rbp)
End of assembler dump.
(gdb) start
Starting program: /tmp/a.out
Temporary breakpoint 1, main () at t.c:4
4 for (int i = 0; i < 10; i++)
(gdb) set *(char*)0x400559 = 10
(gdb) disas/r 0x400556,0x400557
Dump of assembler code from 0x400556 to 0x400557:
0x0000000000400556 <main+41>: 83 7d fc 0a cmpl $0xa,-0x4(%rbp)
End of assembler dump.
(gdb) c
Continuing.
0
1
2
3
4
5
6
7
8
9
10
[Inferior 1 (process 23131) exited normally]