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 :p
Printable View
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 :p
IMO it is definetely your findfirst function that is crashing. Can you provide the input you are passing to this function again please?
Well from what I can tell (his driver is the one making the calls to my functions) it should be as follows:
Given the sourcelineMy breakup function should be getting called to create the tokensCode:EXAMPLE +LDA STUFF,X
From there my findfirst function should be getting called to return the index in the codetable of where the symbol residesCode:void breakup(char sourceline[], struct toklist components);
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 sourcelineCode:int findfirst(tabletype tabl[], int n, char x[]);
And then once that has occurred my opcodeincr function can perform it's calculations to decide how much the program counter needs to be incrementedCode:int opcodeincr(int tablindx, int ni, int xbpe);
Upon further discussion with my professor this is what I have to offer:
I'm going to give that a shot and see what I can find outQuote:
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
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
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!
You are very welcome. Glad you sorted it out!