大家帮忙看看这个Segmentation fault是什么情况

tfssm 2012-07-17 10:35:09
if ((fd = open (videodevice, O_RDWR)) == -1) {
perror ("ERROR opening V4L interface \n");
exit (1);
}
.....
videochan.norm = norme;
videochan.channel = channel;
if (ioctl (fd, VIDIOCSCHAN, &videochan) == -1) {
printf ("ERROR setting channel and norme \n");
exit (1);
运行发生Segmentation fault
另一个程序也发生了类似的Segmentation fault:在ioctl赋值的时候
...全文
495 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
tfssm 2012-07-24
  • 打赏
  • 举报
回复
重新编译了内核 support能加的都加了 还是不行
tfssm 2012-07-21
  • 打赏
  • 举报
回复
printf("**************** PROBING CAMERA *********************\n");
if (ioctl (fd, VIDIOCGCAP, &videocap) == -1) {
printf ("wrong device\n");
exit (1);
}

printf("Camera found: %s \n",videocap.name);

if (ioctl (fd, VIDIOCGCHAN, &videochan) == -1) {
printf ("Hmm did not support Video_channel\n");
isVideoChannel = 0;
}
if (isVideoChannel){
videochan.norm = norme;
videochan.channel = channel;
if (ioctl (fd, VIDIOCSCHAN, &videochan) == -1) {
printf ("ERROR setting channel and norme \n");
exit (1);
}
看来不是对齐的问题 对齐以后段错误反倒提前发生了
tfssm 2012-07-21
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]
x86不怕内存不对齐,arm必须对齐,这个要考虑

比如在arm中类似
char *p = 。。。
int i = *(int*)p
就有可能出问题
[/Quote]
arm对齐以后出了新段错误
**************** PROBING CAMERA *********************
Camera found: PC Camera
Hmm did not support Video_channel
*****************************************************
grabbing method default MMAP asked
VIDIOCGMBUF size 475136 frames 4 offets[0]=0 offsets[1]=118784
VIDIOCGPICT
brightnes=32896 hue=0 color=0 contrast=32768 whiteness=39321
depth=8 palette=0
VIDIOCSPICT
brightness=32896 hue=0 color=0 contrast=32768 whiteness=39321
depth=24 palette=15

: Invalid argument
cmcapture: Invalid argument
>>cmcapture err -1
cvsync err
: Invalid argument
cmcapture: Invalid argument
>>cmcapture err -1
Segmentation fault
dongjiawei316 2012-07-20
  • 打赏
  • 举报
回复
你看谁调的这个函数啊!应该不用什么工具,你看代码也能看出来吧!
jackyjkchen 2012-07-20
  • 打赏
  • 举报
回复
x86不怕内存不对齐,arm必须对齐,这个要考虑

比如在arm中类似
char *p = 。。。
int i = *(int*)p
就有可能出问题
tfssm 2012-07-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
运行报Some problem with the ioctl SET_VS_INFO!!! Segmentation fault
从上面得打印看,你的ioctl并没有Segmentation fault,因为既然有打印Some problem with the ioctl SET_VS_INFO,就说明ioctl已经返回。

你注意下你这个函数如果返回-1,会发生什么情况吧!
[/Quote]
报Some problem with the ioctl SET_VS_INFO!!! Segmentation fault,说明ioctl已经返回-1,返回-1程序报段错误退出。段错误不在这里,段错误在别的地方,如何定位?用什么工具定位?
dongjiawei316 2012-07-20
  • 打赏
  • 举报
回复
运行报Some problem with the ioctl SET_VS_INFO!!! Segmentation fault
从上面得打印看,你的ioctl并没有Segmentation fault,因为既然有打印Some problem with the ioctl SET_VS_INFO,就说明ioctl已经返回。

你注意下你这个函数如果返回-1,会发生什么情况吧!
tfssm 2012-07-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
越界,某个变量未申请空间就赋值的可能性比较大。

不过你这点信息无法判断具体是什么问题。
[/Quote]
找了一天 没发现有变量未申请空间就赋值 求良策
tfssm 2012-07-18
  • 打赏
  • 举报
回复
请问如何得到Segmentation fault
的更多信息,我dbg了也产生了core文件,但都不能精确定位
[Quote=引用 3 楼 的回复:]
越界,某个变量未申请空间就赋值的可能性比较大。

不过你这点信息无法判断具体是什么问题。
[/Quote]
tfssm 2012-07-18
  • 打赏
  • 举报
回复
我用gdb远程调试确定问题是在那里
同样的程序在PC上可以正常运行,移植到开发板上就有了问题
我用了arm-linux-gcc 4 和3 编译都有问题
有趣的是相同的问题又发生在另一个程序里
fb_info_to_driver.Bpp = vinfo.bits_per_pixel ;
fb_info_to_driver.LeftTop_x = 0;
fb_info_to_driver.LeftTop_y = 0;
fb_info_to_driver.Width = destWidth;
fb_info_to_driver.Height = destHeight;

if (ioctl(dev_fb0, SET_OSD_INFO, &fb_info_to_driver)) {
printf("Some problem with the ioctl SET_VS_INFO!!!\n");
return -1;
}
运行报Some problem with the ioctl SET_VS_INFO!!! Segmentation fault
几乎一模一样的问题
帅得不敢出门 2012-07-18
  • 打赏
  • 举报
回复
越界,某个变量未申请空间就赋值的可能性比较大。

不过你这点信息无法判断具体是什么问题。


louyong0571 2012-07-18
  • 打赏
  • 举报
回复
gdb跟踪!
wqkjj 2012-07-18
  • 打赏
  • 举报
回复
如果你确定是在这一部分代码出现这个错误,则可能:
(1)videochan的参数没有填写正确 或者 驱动程序存在bug
如果不是
(1)比较担心实际出现的代码问题在你的.....中。
(2)不妨用gdb/dbx/adb/sdb之类的调试工具跟踪一下。

23,114

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧