Segmentation fault

This is a discussion on Segmentation fault within the C Programming forums, part of the General Programming Boards category; Haha, yea like I said the guy is a genius and actually does a lot of work in robotics currently ...

  1. #31
    Registered User
    Join Date
    Mar 2010
    Posts
    61
    Haha, yea like I said the guy is a genius and actually does a lot of work in robotics currently but it just feels like he doesn't care enough about us as students to do a well enough job, but we'll see how it all turns out in a few years I guess

  2. #32
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    IMO it is definetely your findfirst function that is crashing. Can you provide the input you are passing to this function again please?

  3. #33
    Registered User
    Join Date
    Mar 2010
    Posts
    61
    Well from what I can tell (his driver is the one making the calls to my functions) it should be as follows:

    Given the sourceline
    Code:
    EXAMPLE +LDA STUFF,X
    My breakup function should be getting called to create the tokens
    Code:
    void breakup(char sourceline[], struct toklist components);
    From there my findfirst function should be getting called to return the index in the codetable of where the symbol resides
    Code:
    int findfirst(tabletype tabl[], int n, char x[]);
    Once I know where the symbol is located in the codetable I can set the components to their values based on the info in the codetable and the provided information in the sourceline

    And then once that has occurred my opcodeincr function can perform it's calculations to decide how much the program counter needs to be incremented
    Code:
    int opcodeincr(int tablindx, int ni, int xbpe);

  4. #34
    Registered User
    Join Date
    Mar 2010
    Posts
    61
    Upon further discussion with my professor this is what I have to offer:
    Good question. If findfirst is compiled with the –g option as well, you can probe it using gdb.

    After starting gdb
    (gdb) break findfirst [stop on first line of findfirst]
    (gdb) run [run to breakpoint]
    (gdb) list [list findfirst]
    (gdb) break 11 [or whatever line in findfirst you want to stop at]
    (gdb) cont [continue to break point]
    (gdb) print <var name>
    (gdb) next [single step]
    (gdb) next 10 [run next 10 lines]
    Etc
    I'm going to give that a shot and see what I can find out

  5. #35
    Registered User
    Join Date
    Mar 2010
    Posts
    61
    Ok, from that test here's what I got, no clue really what this means lol

    Code:
    (gdb) break findfirst
    Breakpoint 1 at 0x400cdb: file findfirst.c, line 20.
    (gdb) run
    Starting program: /home/37/n00449937/cop3601/n00449937-5
    
    Enter:
    
        1. To test opcodeincr
        2. To test storageincr
        3. To quit
    
    >>>1
    
    **********************
    * TESTING opcodeincr *
    **********************
    COP 3601: Spring, 2010 -
    
    
    Enter breakup line (enter done to exit test) : EXAMPLE +LDA TEST,X
    
    
    ptr after getting "opcode":LDA
    
    
    
    ptr after "removing white space":TEST,X
    
    
    Breakpoint 1, findfirst (tabl=0x5042e0, n=57, x=0x7fbffff7b0 "LDA")
        at findfirst.c:20
    20         int index = -1;
    (gdb) list
    15      * Finds the first occurrence of a symbol from the table using a binary search
    16      * and returns its index, otherwise returns -1 if not found.
    17      */
    18      int findfirst(tabletype tabl[], int n, char x[])
    19      {
    20         int index = -1;
    21
    22         int min = 0;
    23         int max = n;
    24         int mid = n/2;
    (gdb) break 24
    Breakpoint 2 at 0x400cef: file findfirst.c, line 24.
    (gdb) cont
    Continuing.
    
    Breakpoint 2, findfirst (tabl=0x5042e0, n=57, x=0x7fbffff7b0 "LDA")
        at findfirst.c:24
    24         int mid = n/2;
    (gdb) print x
    $1 = 0x7fbffff7b0 "LDA"
    (gdb) next
    
    
    char x:LDA
    
    26         while(min <= max)
    (gdb) next 10
    26         while(min <= max)
    (gdb) cont
    Continuing.
    
    Program received signal SIGINT, Interrupt.
    0x0000000000400d83 in findfirst (tabl=0x5042e0, n=57, x=0x7fbffff7b0 "LDA")
        at findfirst.c:35
    35            if(strcmp(tabl[mid].symbol, x) == 0)
    (gdb) list
    30            if(strcmp(tabl[mid].symbol, x) < 0)
    31               min = mid + 1;
    32            else
    33               max = mid;
    34
    35            if(strcmp(tabl[mid].symbol, x) == 0)
    36               index = mid;
    37         }
    38
    39         return index;
    (gdb) quit

  6. #36
    Registered User
    Join Date
    Mar 2010
    Posts
    61
    Hey thanks for all the help, I figured it out, my binary search was going while min <= max instead of min < max, I know I had changed it for a reason, just can't remember why. Thanks for helping me get to the right direction. I would've been looking in the wrong place for a week!

  7. #37
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    You are very welcome. Glad you sorted it out!

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why am I getting segmentation fault on this?
    By arya6000 in forum C++ Programming
    Replies: 6
    Last Post: 10-12-2008, 07:32 AM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 06:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 01:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21