Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';ptrace单步工作正常吗?_C_Ptrace - Fatal编程技术网

为什么';ptrace单步工作正常吗?

为什么';ptrace单步工作正常吗?,c,ptrace,C,Ptrace,我正在尝试使用ptraceapi跟踪一个小程序。我发现每次运行跟踪程序时,都会产生不好的结果。这是我要跟踪的短程序的反汇编: $ objdump -d -M intel inc_reg16 inc_reg16: file format elf32-i386 Disassembly of section .text: 08048060 <.text>: 8048060: b8 00 00 00 00 mov eax,0x0 8048065:

我正在尝试使用ptraceapi跟踪一个小程序。我发现每次运行跟踪程序时,都会产生不好的结果。这是我要跟踪的短程序的反汇编:

$ objdump -d -M intel inc_reg16
inc_reg16:     file format elf32-i386

Disassembly of section .text:

08048060 <.text>:
 8048060:   b8 00 00 00 00          mov    eax,0x0
 8048065:   66 40                   inc    ax
 8048067:   75 fc                   jne    0x8048065
 8048069:   89 c3                   mov    ebx,eax
 804806b:   b8 01 00 00 00          mov    eax,0x1
 8048070:   cd 80                   int    0x80
第二项检查:

$ ./ezptrace > inc_reg16.log
$ grep '8048065' inc_reg16.log | wc -l
65494

问题是上述结果都应该是65536,因为指令inc ax执行了65536次。现在的问题是:我的代码中是否有错误,或者是ptrace中的某个bug造成的?非常感谢您的帮助。

eip是用户空间中“当前指令”的地址。您需要一个ptrace(…PEEKDATA,…),即在ptrace(…GETREGS,…)之后,才能获得实际指令。还请记住,使用ptrace(…PEEKDATA,…)时,您总是获得一个机器字,实际的操作码通常只占用其中较低的16/32位。

我在virtualbox和vmware下尝试了相同的程序,似乎只有vmware有正确的结果,而virtualbox与您有相同的问题。我在我的机器上使用了virtualbox 4.2.1。

/ezptrace | grep8048065 | wc-l给出65536。(顺便说一句,您使用无效参数调用execv,它应该类似于
char*argv[]={“inc_reg16”,NULL};execv(argv[0],argv);
),这非常有趣。有没有可能因为我在虚拟化环境(VirtualBox上的Debian)中运行跟踪程序而收到不好的结果?我刚刚在qemu下运行的32位Ubuntu11.04(托管在Ubuntu11.04 x86_64上,我在那里运行了我的另一个测试)中尝试了它,但我仍然得到了65536。
$ gcc ezptrace.c -Wall -o ezptrace
$ ./ezptrace > inc_reg16.log
$ grep '8048065' inc_reg16.log | wc -l
65498
$ ./ezptrace > inc_reg16.log
$ grep '8048065' inc_reg16.log | wc -l
65494