I want to determine the cause of a sigsegv

谁说我不能喝 提交于 2019-12-11 12:37:41

问题


I'm writing an applicaiton for gentoo linux and redhat linux, one of the funciton always crashes on the redhat machine

usleep(100000);
    Display *display;
    display = XOpenDisplay(NULL);
    Window w;
    int x,y,i;
    unsigned m;
    Window root = XDefaultRootWindow(display);
    XQueryPointer(display,root,&root,&w,&x,&y,&i,&i,&m);
    XImage *image;
    sleep(1);
    image = XGetImage(display,root,0,0,1366,768,AllPlanes,XYPixmap);
    int pixel = XGetPixel(image,x,y);
    printf("\\clr(%i,%i,%i){}\n",x,y,pixel);
    XCloseDisplay(display);

This function always crashes with a segmentation fault on the rhel machine

running the progrma in gdb: Program received signal SIGSEGV, Segmentation fault. 0x000000369942cb48 in ?? () from /usr/lib64/libX11.so.6 Missing separate debuginfos, use: debuginfo-install atk-1.30.0-1.el6.x86_64 cairo-1.8.8-6.el6_6.x86_64 expat-2.0.1-11.el6_2.x86_64 fontconfig-2.8.0-5.el6.x86_64 freetype-2.3.11-15.el6_6.1.x86_64 gdk-pixbuf2-2.24.1-6.el6_7.x86_64 glib2-2.28.8-4.el6.x86_64 glibc-2.12-1.166.el6_7.1.x86_64 gtk2-2.24.23-6.el6.x86_64 libX11-1.6.0-6.el6.x86_64 libXau-1.0.6-4.el6.x86_64 libXcomposite-0.4.3-4.el6.x86_64 libXcursor-1.1.14-2.1.el6.x86_64 libXdamage-1.1.3-4.el6.x86_64 libXext-1.3.2-2.1.el6.x86_64 libXfixes-5.0.1-2.1.el6.x86_64 libXi-1.7.2-2.2.el6.x86_64 libXinerama-1.1.3-2.1.el6.x86_64 libXrandr-1.4.1-2.1.el6.x86_64 libXrender-0.9.8-2.1.el6.x86_64 libXtst-1.2.2-2.1.el6.x86_64 libpng-1.2.49-2.el6_7.x86_64 libselinux-2.0.94-5.8.el6.x86_64 libxcb-1.9.1-3.el6.x86_64 pango-1.28.1-10.el6.x86_64 pixman-0.32.4-4.el6.x86_64 zlib-1.2.3-29.el6.x86_64

unfortunately I cannot install any additional packages(or install from 3rd party repos) for the rhel machines

backtrace: (gdb) bt

0 0x000000369942cb48 in ?? () from /usr/lib64/libX11.so.6

1 0x00000000004048ce in main (argc=2, argv=0x7fffffffe148) at tat.c:92

line 92 is : int pixel = XGetPixel(image,x,y);

the application works fine if that line is removed

thanks


回答1:


Use XGetWindowAttributes to find the real width/heitgh of the screen. Do not use the hardcoded values.




回答2:


Most likely it is this line returning NULL:

image = XGetImage(display,root,0,0,1366,768,AllPlanes,XYPixmap);

Manual Page says: If a problem occurs, XGetImage returns NULL.

However, this error might be triggered by a previous line's error -- as is mentioned in the comments, you should be checking the return values of all these calls for success/failure.



来源:https://stackoverflow.com/questions/34661001/i-want-to-determine-the-cause-of-a-sigsegv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!