strace输出问题解决

时间:2013-10-30 19:09:52

标签: linux strace

我尝试在linux中为我的程序运行strace

以下是输出示例:

brk(0)                                  = 0x804b000
brk(0x806c000)                          = 0x806c000
open("test.txt", O_RDONLY)              = 3
fstat64(3, {st_mode=S_IFREG|0600, st_size=216, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7728000
read(3, "10\n10\n2\t3\t3\t5\t4\t7\t7\t2\t2\t7\t\n8\t3\t1"..., 4096) = 216
read(3, "", 4096)                       = 0
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0xb7728000, 4096)                = 0
**open(NULL, O_RDONLY)                    = -1 EFAULT (Bad address)**
dup(2)                                  = 3
fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)
fstat64(3, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7728000
**_llseek(3, 0, 0xbfc97a44, SEEK_CUR)     = -1 ESPIPE (Illegal seek)**
write(3, "Can't open file!: Bad address\n", 30Can't open file!: Bad address

为什么我在这两行中遇到一些错误。 **open(NULL, O_RDONLY)**是什么意思?

1 个答案:

答案 0 :(得分:3)

**open(NULL, O_RDONLY)  

您传递的是NULL字符串作为文件名。根据{{​​3}},当路径名指向可访问的地址空间之外时,会生成EFAULT

_llseek(3, 0, 0xbfc97a44, SEEK_CUR)

您正在尝试设置不支持此功能的文件描述符的偏移量。

实际上,你试图移动STANDARD ERROR的偏移量(3是dup(2)的结果),这没有意义,因为它不是真正的文件。根据{{​​3}},当文件描述符与管道,套接字或FIFO相关联时,会生成ESPIPE