Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't debug lex.yy.cc file

Tags:

c

lex

I have created a lex file test.l and create lex.yy.c from it, which I then compile with gcc -g flags

I am linking it and I dont have a problem compiling the rest of my code which makes the call to yylex(), however, in GDB i dont seem to be able to dive on the call to yylex().

What am I doing wrong? I put breakpoints in the yylex() method itself, and this causes gdb to stop on my call to yylex() but never inside the function.

Do I need to compile the -l library with debug symbols or something?

I know it is running because i created my lex.yy.c file with -d, so I see the output of accepting tokens and whatnot.

Thanks

like image 353
Derek Avatar asked Nov 29 '25 20:11

Derek


1 Answers

I think you are falling foul of the fact that lex, or at least flex, uses the #line directive to set the file that is used for errors, and symbolic debugging, to the .l file that the .c file was created from. You'll need to set the breakpoints in the .l file or use the -L option to instruct flex not to use the #line directive.

GDB requires the file name that appeared in the #line directive when setting breakpoints. If you manually converted the .l file to a .c file then this is probably what you used on the command line. If the conversion was done implicitly by make then it's just the basename of the .l file (without the folders).

like image 96
Will Avatar answered Dec 02 '25 13:12

Will



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!