Skip to content

Enable debugging with LLDB (Xcode, Qt Creator, etc) #744

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

Merged
merged 2 commits into from
Oct 19, 2023
Merged

Enable debugging with LLDB (Xcode, Qt Creator, etc) #744

merged 2 commits into from
Oct 19, 2023

Conversation

bluetarpmedia
Copy link
Contributor

Some changes are needed in order to enable debugging with LLDB (used by Xcode and Qt Creator):

  • print line directives before each function definition
  • filenames in line directives now have absolute paths

I also tested these changes with Visual Studio and the debugging experience continues to work as before.

Line directive filenames now have absolute paths.
These changes are required to enable debugging with LLDB.
@gregmarr
Copy link
Contributor

filenames in line directives now have absolute paths

This is going to break the line directives in reflect.h. It also means that the builds are not reproducible from different directories. I'm surprised that any debugger at this point would be unable to understand relative #line directives. I suspect that this would need to be a switch, like this: https://github.com/hsutter/cppfront/blob/main/source/cppfront.cpp#L139

// Don't print duplicate line directives on subsequent lines
if (
prev_line_directive.out_pos_line == curr_pos.lineno
&& prev_line_directive.line == line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example of what was being output that is being suppressed? I know that there are some places where we need to output the same directive multiple times due to intermediate code. It's not 100% clear to me that this will only eliminate truly duplicate line numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That code prevents duplicate line directives like this:

#line 11 "C:\\path\\main.cpp2"
#line 11 "C:\\path\\main.cpp2"
auto main() -> int{
 print_menu(2023);
}

But it still allows the same line directive line number to be reused elsewhere, just not immediately on subsequent lines.

This is still allowed:

#line 11 "C:\\path\\main.cpp2"
auto main() -> int;

//=== Cpp2 function definitions =================================================

#line 11 "C:\\path\\main.cpp2"
auto main() -> int{
 print_menu(2023);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for the confirmation.

@bluetarpmedia
Copy link
Contributor Author

bluetarpmedia commented Oct 11, 2023

This is going to break the line directives in reflect.h.

I hadn't noticed that, thanks. Fortunately, in this case, the impact will be for cppfront developers themselves using lldb if lldb can't find the reflect.h file. End-users of cppfront won't be affected.

It also means that the builds are not reproducible from different directories. I'm surprised that any debugger at this point would be unable to understand relative #line directives.

Yes, I found that surprising too. Based on my tests (on macOS), lldb uses the current working directory when trying to find a relative filename in a line directive. So if you run your binary from a different working directory then suddenly the debugging experience will fail. Whereas with MSVC I suspect the path to the original source code directory is included in the PDB file, so relative filenames work correctly since the debugger can reconstruct it with the directory from the PDB.

I suspect that this would need to be a switch, like this: https://github.com/hsutter/cppfront/blob/main/source/cppfront.cpp#L139

Good thinking, I'll add that to my PR.

EDIT - Done, see below.

@hsutter
Copy link
Owner

hsutter commented Oct 19, 2023

Looks good, thanks!

@hsutter hsutter merged commit 12793b0 into hsutter:main Oct 19, 2023
hsutter added a commit that referenced this pull request Oct 20, 2023
@hsutter
Copy link
Owner

hsutter commented Oct 20, 2023

After merging this I re-ran regression tests, and it made incorrect changes... in the first couple of test files I looked at, the #line that used to exist on the function definition was removed (which I think is the opposite of what you wanted, and made the line information incorrect).

So I've reverted this merge... please create a new PR and try running it against all regression tests? Thanks!

zaucy pushed a commit to zaucy/cppfront that referenced this pull request Dec 5, 2023
* Print line directives before function definitions

Line directive filenames now have absolute paths.
These changes are required to enable debugging with LLDB.

* Add command line option to enable absolute paths in line directives (defaults to off)
zaucy pushed a commit to zaucy/cppfront that referenced this pull request Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants