调试解析器生成的代码
我使用 Lemon Parser 生成了一个解析器代码。我无法调试生成的代码。控件显示除当前正在执行的语句之外的其他源代码。断点已移位。我尝试过 gdb 和 Visual C++。两者都有同样的问题。请告诉我调试的方法。
I have generated a parser code using Lemon Parser. I am not able to debug the generated code. Control shows some other source code than the currently executing statement. Breakpoints are displaced. I tried on gdb and Visual C++. Both have the same problem. Please tell me the way to debug it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您的输入文件名为 mylexer.y,在这种情况下,Lemon 将生成 myparser.c 和 myparser.h
在 myparser.c 内部您将看到诸如此类的行
这些是 行指令。它们非常适合将语法错误追溯到用于生成代码的文件。它们不利于调试。
要抑制它们,请使用 -l 选项调用 Lemon 。
要查看文档中未提及的其他选项,请使用 -?
Let's say your input file is named mylexer.y in which case Lemon will generate myparser.c and myparser.h
Inside of myparser.c you will see lines such as this
These are line directives. They are good for tracing syntax errors back to the file that was used to generate the code. They are not good for debugging.
To suppress them invoke Lemon with the -l option.
To see other options not mentioned in the documentation use -?
以下是经过认证的 WAG(Wild Ass Guess):
我建议查看解析器生成器使用的所有宏,看看是否有任何转义换行符他们。如果有,请尝试删除所有它们(通过将行连接在一起),然后重新编译文件。然后查看调试器中的代码——事情可能突然回到了应有的位置。
背景故事:早在 80 年代,我就开发并销售了一款名为 CDB 的调试器。当我将它移植到名称中包含 U*NX 的任何东西时,我开始非常熟悉各种编译器的特性以及它们在某些情况下如何发出调试信息。
一个普遍存在的问题与转义换行符的宏有关。例如
,如果
y = 2;
的行号应该为 5,则许多符号表最终会将其显示为 6,并且其后的每一行都会被关闭-一。每次使用这样的宏都会使行号越来越远。The following is a certified WAG (Wild Ass Guess):
I would recommend looking at all of the macros being used by the parser generator and see if there are any escaped newlines in them. If there are, try removing all of them (by joining the lines together) and then recompile the file. Then looked at the code in the debugger -- things suddenly may be back to where they should be.
Backstory: Back in the 80's I developed and marketed a debugger called CDB. As I ported it to anything that had U*NX in it's name I became intimately familiar with the idiosyncrasies of the various compilers and how they emitted debug info in certain situations.
One widespread problem had to do with macros that had escaped newlines them. E.g.
If the line number for
y = 2;
should have been 5, many symbol tables would end up showing it as 6, and every line after it would be off-by-one. And each use of such a macro would throw the line numbers farther and farther off.如果将它们构建为 lib/dll,请检查优化、调试信息选项。
Check optimization, debug information options if you are building them as lib/dll.