Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace #line directives in the C generator with mappings that use CodeMap.java #84

Open
petervdonovan opened this issue Sep 28, 2022 · 5 comments
Labels
diagnostics Error, warning, and info message reporting refactoring

Comments

@petervdonovan
Copy link
Contributor

In the C generator, we insert #line compiler directives into generated code. This makes generated C programs difficult to debug and confuses tools that measure code coverage. It also is a source of code complexity since the C target is the only target that works that way; if the C generator behaved the same way as the other targets, it would have one line matching system to maintain instead of two.

This change may result in regressions because #line directives allow generated code to be matched to the original code even if they are not copied verbatim from the LF source. However, this is not a fundamental limitation of CodeMap and should be fixed.

@petervdonovan petervdonovan added diagnostics Error, warning, and info message reporting refactoring labels Sep 28, 2022
@lhstrh
Copy link
Member

lhstrh commented Sep 28, 2022

Are you sure we want to do this? Wouldn't this break gdb, among other things?

@petervdonovan
Copy link
Contributor Author

I am not sure if the #line directives ever were useful for debugging (although if they are, then yes, certainly this would break that). Just now I tried to use them with GDB to debug the original LF source, and I got an error:

Line number 15 out of range; file:/home/peter/vscode-lingua-franca/lingua-franca/test/C/src/Minimal.lf has 8 lines.

In my experience, the #line directives only make it more difficult to use GDB because I often want to debug the generated code. For an end user, things might be different, but I'm not sure.

In any case, this will become less important if/when we implement our own debugger on top of GDB. Such a debugger should use CodeMap so that it is compatible with the C++ and Rust targets (Rust does not have #line directives).

@lhstrh
Copy link
Member

lhstrh commented Sep 28, 2022

Perhaps we can disable them by default but have a switch to enable them? Students in the lab are using gdb, which seems to work fine, but is apparently not flawless... Also tagging @lsk567.

@petervdonovan
Copy link
Contributor Author

Okay, no problem -- I simply was not aware of that. This issue should probably wait until we have a good alternative for debugging. It has been on my to-dos for almost a year and it can wait for a year longer.

@lhstrh
Copy link
Member

lhstrh commented Sep 28, 2022

Or perhaps @Aldenysq can sink his teeth into this :-)

petervdonovan added a commit to lf-lang/lingua-franca that referenced this issue Oct 13, 2022
Thanks to @cmnrd and edwardalee for pointing out that this was needed.

Lines are correctly adjusted in VS Code now. Note that this could have
been merged without this fix because I chose to specifically exclude
C from the LSP tests out of reluctance to maintain the #line
directive mechanism; see lf-lang/vscode-lingua-franca#84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics Error, warning, and info message reporting refactoring
Projects
None yet
Development

No branches or pull requests

2 participants