| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3755 人关注过本帖
标题:write()后直接退出程序,怎么查错?
只看楼主 加入收藏
飞跃的乌龟
Rank: 2
等 级:论坛游民
帖 子:96
专家分:18
注 册:2012-10-20
结帖率:90.32%
收藏
已结贴  问题点数:20 回复次数:17 
write()后直接退出程序,怎么查错?
各位有没有见过这种错误,或者有没有其他方法可以查错的dmesg显示
bug unable to handle kernel paging request at 00007ffda441a050
int ret,fd;
char toSend[LENGTH]={0};
fd=open("/dev/charMsgDriver",O_RDWR);
scanf("%[^\n]%*c",toSend);
ret=write(fd,toSend,strlen(toSend));//fd,toSend,strlen(toSend)都是有值,到这句的时候就不会执行,直接退出,后面不会执行了也查不了错。
charMsgDriver应该是一个内核的字符驱动模块在root下执行该程序,执行到write时显示“已杀死”



[此贴子已经被作者于2018-6-27 17:20编辑过]

搜索更多相关主题的帖子: write 退出 显示 ret 执行 
2018-06-27 16:54
烟雨晨曦
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:7
帖 子:150
专家分:599
注 册:2017-3-5
收藏
得分:20 
strace ./程序 或者生成core文件gdb调试一下 你这样能看得到什么
2018-06-27 18:45
lin5161678
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:45
帖 子:1136
专家分:3729
注 册:2011-12-3
收藏
得分:0 
LENGTH 多大
你读取了多少个字符?

https://zh.
2018-06-27 19:00
飞跃的乌龟
Rank: 2
等 级:论坛游民
帖 子:96
专家分:18
注 册:2012-10-20
收藏
得分:0 
回复 3楼 lin5161678
length大小是1024,测试的是输四个字符abcd
2018-06-27 22:52
飞跃的乌龟
Rank: 2
等 级:论坛游民
帖 子:96
专家分:18
注 册:2012-10-20
收藏
得分:0 
回复 2楼 烟雨晨曦
程序代码:
execve("./test", ["./test"], [/* 83 vars */]) = 0
brk(0)                                  = 0x66f000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd0a490e000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/home/qianyang/catkin_ws/devel/lib/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/qianyang/catkin_ws/devel/lib/tls/x86_64", 0x7ffd1bd47ce0) = -1 ENOENT (No such file or directory)
open("/home/qianyang/catkin_ws/devel/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/qianyang/catkin_ws/devel/lib/tls", 0x7ffd1bd47ce0) = -1 ENOENT (No such file or directory)
open("/home/qianyang/catkin_ws/devel/lib/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/qianyang/catkin_ws/devel/lib/x86_64", 0x7ffd1bd47ce0) = -1 ENOENT (No such file or directory)
open("/home/qianyang/catkin_ws/devel/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/qianyang/catkin_ws/devel/lib", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
open("/opt/ros/indigo/lib/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/opt/ros/indigo/lib/tls/x86_64", 0x7ffd1bd47ce0) = -1 ENOENT (No such file or directory)
open("/opt/ros/indigo/lib/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/opt/ros/indigo/lib/tls", 0x7ffd1bd47ce0) = -1 ENOENT (No such file or directory)
open("/opt/ros/indigo/lib/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/opt/ros/indigo/lib/x86_64", 0x7ffd1bd47ce0) = -1 ENOENT (No such file or directory)
open("/opt/ros/indigo/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/opt/ros/indigo/lib", {st_mode=S_IFDIR|0755, st_size=20480, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=164111, ...}) = 0
mmap(NULL, 164111, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd0a48e5000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P \2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1853216, ...}) = 0
mmap(NULL, 3961536, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd0a4326000
mprotect(0x7fd0a44e4000, 2093056, PROT_NONE) = 0
mmap(0x7fd0a46e3000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7fd0a46e3000
mmap(0x7fd0a46e9000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fd0a46e9000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd0a48e4000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd0a48e2000
arch_prctl(ARCH_SET_FS, 0x7fd0a48e2740) = 0
mprotect(0x7fd0a46e3000, 16384, PROT_READ) = 0
mprotect(0x600000, 4096, PROT_READ)     = 0
mprotect(0x7fd0a4910000, 4096, PROT_READ) = 0
munmap(0x7fd0a48e5000, 164111)          = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd0a490d000
write(1, "\n", 1
)                       = 1
open("/dev/charMsgDriver", O_RDWR)      = -1 ENOENT (No such file or directory)
dup(2)                                  = 3
fcntl(3, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
brk(0)                                  = 0x66f000
brk(0x690000)                           = 0x690000
fstat(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd0a490c000
lseek(3, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
write(3, "failed to open charMsgDriver dev"..., 37failed to open charMsgDriver device.
) = 37
write(3, ": No such file or directory\n", 28: No such file or directory
) = 28
close(3)                                = 0
munmap(0x7fd0a490c000, 4096)            = 0
exit_group(2)                           = ?
+++ exited with 2 +++
2018-06-27 23:05
烟雨晨曦
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:7
帖 子:150
专家分:599
注 册:2017-3-5
收藏
得分:0 
回复 5楼 飞跃的乌龟
图片附件: 游客没有浏览图片的权限,请 登录注册

这不是都有了么

[此贴子已经被作者于2018-6-28 11:16编辑过]

2018-06-28 11:14
飞跃的乌龟
Rank: 2
等 级:论坛游民
帖 子:96
专家分:18
注 册:2012-10-20
收藏
得分:0 
回复 6楼 烟雨晨曦
是的,很奇怪,我看过那个目录下那个文件是在的


[此贴子已经被作者于2018-6-28 12:47编辑过]

2018-06-28 12:44
飞跃的乌龟
Rank: 2
等 级:论坛游民
帖 子:96
专家分:18
注 册:2012-10-20
收藏
得分:0 
回复 6楼 烟雨晨曦
不好意思,上面那个strace执行的时候好像因为重启,把那个文件给删了,所以找不到,我把文件又加进去再strace一下结果是
程序代码:
qianyang@qianyang-Lenovo-XiaoXin-700-15ISK:~/embed/4/userApp$ sudo strace ./test

execve("./test", ["./test"], [/* 18 vars */]) = 0
brk(0)                                  = 0x12ed000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5087bd3000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=164111, ...}) = 0
mmap(NULL, 164111, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f5087baa000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P \2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1853216, ...}) = 0
mmap(NULL, 3961536, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f50875eb000
mprotect(0x7f50877a9000, 2093056, PROT_NONE) = 0
mmap(0x7f50879a8000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f50879a8000
mmap(0x7f50879ae000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f50879ae000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5087ba9000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5087ba7000
arch_prctl(ARCH_SET_FS, 0x7f5087ba7740) = 0
mprotect(0x7f50879a8000, 16384, PROT_READ) = 0
mprotect(0x600000, 4096, PROT_READ)     = 0
mprotect(0x7f5087bd5000, 4096, PROT_READ) = 0
munmap(0x7f5087baa000, 164111)          = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 5), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5087bd2000
write(1, "\n", 1
)                       = 1
open("/dev/charMsgDriver", O_RDWR)      = 3
write(1, "type something to the kernel mod"..., 37type something to the kernel module:
) = 37
fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 5), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f5087bd1000
read(0, 0x7f5087bd1000, 1024)           = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
read(0, 0x7f5087bd1000, 1024)           = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
read(0,       

2018-06-28 12:56
星泪成寒
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:6
帖 子:77
专家分:549
注 册:2013-5-19
收藏
得分:0 
最后 read(0), 是在等标准输入吧
2018-06-28 13:33
烟雨晨曦
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:7
帖 子:150
专家分:599
注 册:2017-3-5
收藏
得分:0 
回复 8楼 飞跃的乌龟
图片附件: 游客没有浏览图片的权限,请 登录注册
scanf 读取输入报错了
2018-06-28 14:09
快速回复:write()后直接退出程序,怎么查错?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023649 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved