Reputation: 2398
I wrote a simple assembler using flex and bison . It worked perfectly until I made a small change . Was a harmless additional rule in the lex and yacc specifications . After that it throws a segmentation fault each time I run it . I tried to trace the source of this seg fault but it turns out it occurs before the main in the lex file is executed . Then I removed the addition I made and recompiled it , It still shows the same error.
What's wrong???
I did something like this
Thanks in Advance
Upvotes: 0
Views: 1243
Reputation: 2513
Please provide more information such as GDB backtrace and the code of the corresponding flex and bison rules.
One debugging tip I have is to put printf()
statements inside your flex rules. For example, suppose you wanted your new rule to match something like THISLOOP: LWU R2, 0(R3)
. Then in flex, you would put printf() inside any rules matching anything from that bison rule. But again, without any code it's impossible to debug.
Upvotes: 1
Reputation: 146261
$ cc -g whatever...
$ gdb a.out
(gdb) run
<boom>
(gdb)bt
And if the answer isn't at that point obvious, select the entire above sequence and update your question above.
BTW, my guess is that you have changed the way you are building it. Perhaps you should just just cut your program back to hello, world, and then start adding in the other components one by one.
Upvotes: 3