使用truss调试open()命令调用 [英] Debugging open() command call with truss

查看:179
本文介绍了使用truss调试open()命令调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用truss -t'open' $(program_call)我得到:

open("command.txt", O_RDONLY|O_NONBLOCK)      = 5
response FIFO file descriptor = -1
// Open call was literally sandwiched between print commands, but its not here?
response FIFO file descriptor = 9
open("response.txt", O_WRONLY|O_NONBLOCK)     Err#6 ENXIO
response.txt: No such device or address

问题是,我将文件描述符初始化为-1,所以我知道打开调用必须成功,因为它更改了变量的值.文件描述符从字面上初始化为-1,然后以某种方式在打开命令调用中更改为9(否则程序将在此处结束),但是打开调用未出现在truss调用中,并且计算机没有显示认识到它是开放的.

The thing is, I initialized the file descriptor to -1, so I KNOW that the open call must have succeeded because it changed the value of the variable. The file descriptor is literally initialized to -1, then somehow gets changed to 9 in the open command call (otherwise the program would end there) but yet the open call does NOT show up in the truss call, and the computer does not recognize it as being open.

一些代码:

if ((outfd = open(CMD_FIFO_NAME, O_WRONLY | O_NONBLOCK)) == -1) {
    fprintf(stderr, "Client: Failed to open %s FIFO.\n", CMD_FIFO_NAME);
    exit(1);
}
printf("RESP_FIFO FILE DESCRIPTOR: %d\n", infd);
/* Open the response FIFO for non-blocking reads. */
if ((infd = open(RESP_FIFO_NAME, O_RDONLY | O_NONBLOCK)) == -1) {
    fprintf(stderr, "Client: Failed to open %s FIFO.\n", RESP_FIFO_NAME);
    exit(1);
}
else printf("RESP_FIFO FILE DESCRIPTOR: %d\n", infd);

推荐答案

truss -f -t'open,close,read,write' run.sh足以发现我的错误,其中run.sh是包含正确执行程序的bash文件.

truss -f -t'open,close,read,write' run.sh was useful enough to find my errors, where run.sh was a bash file containing the proper execution of my program.

这篇关于使用truss调试open()命令调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆