Suche Hilfe zum Finden eines segmention fault fehlers (Bin Anfänger)



  • Ich muss mich gestern vertippt haben! (da hatte ich den Fehler in eine Datei kopiert)
    mit

    gcc sendtest.c -o send -W -Wall -L /usr/X11/lib -lX11
    

    kommt der gcc error nicht mehr!

    Aber das Programm mach bei der Ausführung

    Segmentation fault
    

    Wie finde ich den Fehler?



  • Indem Du mit -g kompilierst und dann mal den gdb anwirfst. (Optional mit ddd oä als Interface.)



  • also bei mir tuts auch mitm kompilieren - wie rufe ich das programm auf, was muss ich für parameter übergeben, dann kann ichs ma testen... ?

    edit: wieso muss ichn als parameter immer -L/usr/X11R6/lib machen? ohne kommt immer der fehler cannot find -lX11 - aber in meiner ld.so.conf steht /usr/X11R6/lib drin 😮

    mfg blan



  • 3 getrennte Buachstaben also z.b. 3 2 1
    ./send 3 2 1



  • Mein gdb sagt, dass der Fehler in dieser Zeile auftaucht:

    XGetInputFocus(display, focus_return,revert_to_return);
    

    Und wenn Du Dir genau anschaust, was Du da übergibst, dann sollte Dich das auch nicht wundern. 😉



  • blan schrieb:

    edit: wieso muss ichn als parameter immer -L/usr/X11R6/lib machen? ohne kommt immer der fehler cannot find -lX11 - aber in meiner ld.so.conf steht /usr/X11R6/lib drin 😮

    Die ld.so.conf ist ja nur für ldconfig gut, nicht damit Du beim Linken keinen -Librarysuchpfad angeben musst.



  • okay gut und wie behebe ich dann das problem? ^^

    mfg blan



  • gdb --exec send
    

    bringt

    GNU gdb 6.3
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i486-slackware-linux".
    (gdb) run 1 2 3
    Starting program: /home/poison/joy2key-1.6/send 1 2 3
    (no debugging symbols found)
    Using host libthread_db library "/lib/tls/libthread_db.so.1".
    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)
    
    Program received signal SIGSEGV, Segmentation fault.
    0xb7f2b656 in XGetInputFocus () from /usr/X11R6/lib/libX11.so.6
    

    Also habe ich bei XGetImputFocus etwas falsch gemacht? Aber was? Was bedeutet 0xb7f2b656?
    Danke für den Tipp mit gdb :)!



  • blan schrieb:

    okay gut und wie behebe ich dann das problem? ^^

    Das ist kein Problem. Du kannst ja auch make oä verwenden, dann sparst Du Dir die Schreibarbeit.



  • Naja, schau Dir die ganzen Parameter mal genau an. Du übergibst lauter Pointer ins Daten-Nirvana...



  • Bekomme ich die Werte denn nicht erst von XGetImputFocus()?



  • schau dir doch mal die x11 referenz an 😃

    http://tronche.com/gui/x/xlib/input/XGetInputFocus.html

    mfg blan



  • 😃
    Danke!
    nun klappt's

    #include <stdio.h>
    #include <stdlib.h>
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    #include <string.h>
    
    int main (int argc, char *argv[]) {
          Display *display;
          Window focus_return;
          int revert_to_return;
      int i;
    
      if (argc<3) {
        printf("usage: ./sendkey key1 key2 key3 etc.\n\n");
        return(1);
      }
    
    if ((display = XOpenDisplay(NULL)) == NULL)
    {
            printf("Unable to open display\n");
            return 1;
    }
    
    XGetInputFocus(display, &focus_return,&revert_to_return);
    
      for (i=3; i<argc; ++i) {
        XEvent ev;
        KeySym key;
        ev.xkey.type=KeyPress;
        ev.xkey.window=focus_return;
        ev.xkey.root=ev.xkey.subwindow=None;
        ev.xkey.time=0;
        ev.xkey.x=ev.xkey.y=ev.xkey.x_root=ev.xkey.y_root=0;
        ev.xkey.state=0;
        key=XStringToKeysym(argv[i]);
        ev.xkey.keycode=XKeysymToKeycode(display, key);
        ev.xkey.same_screen=True;
        XSendEvent(display, focus_return, True, KeyPressMask, &ev);
        ev.type=KeyRelease;
        XSendEvent(display, focus_return, True, KeyReleaseMask, &ev);
      }
    
      XCloseDisplay(display);
    
      return(0);
    }
    

Anmelden zum Antworten