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

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

Closed
wants to merge 3 commits into from

Conversation

bluetarpmedia
Copy link
Contributor

@bluetarpmedia bluetarpmedia commented Oct 27, 2023

Debugging with LLDB (used by Xcode and Qt Creator) requires the following:

  • Print line directives before each function definition
  • Use absolute paths for filenames in line directives

Changes in this PR

  1. Print line directives before each function definition
  2. Add a new command line option to use absolute paths in line directives (defaults to off). LLDB users will have to turn this on.
  3. Update the test-results with the new line directives preceding function definitions

I manually verified the line numbers in the test-results. I also tested these changes with Visual Studio and the debugging experience continues to work as before, as well as with Xcode/Qt Creator after the changes.

Changes to test-results

New line directives have been inserted before function definitions.

EDIT: The following no longer applies (see comment history)

Bugfix?

There's one change that appears to be a bug fix.

See pure2-bugfix-for-memberwise-base-assignment.cpp:

Before this PR:

#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
auto Base::operator=([[maybe_unused]] Base const& that) -> Base&  { std::cout << "(out this, that)\n";
                                      return *this;
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"    <---- bug?
                                     }

That second #line 3 appears to be a bug.

After this PR:

#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
auto Base::operator=([[maybe_unused]] Base const& that) -> Base&  { std::cout << "(out this, that)\n";
                                      return *this; }

* Print line directives before function definitions
* Add command line option to enable absolute paths in line directives (defaults to off)

These changes are required to enable debugging with LLDB (turn on absolute paths).
@gregmarr
Copy link
Contributor

Why do you think it's a bug? The } on that line is generated from the code on line 3 of the cpp2 source file. I think the actual bug here is that there isn't a #line 3 before the return *this;.

It should either be this:

#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
  auto Base::operator=([[maybe_unused]] Base const& that) -> Base&  { std::cout << "(out this, that)\n";
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
                                      return *this;
#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
                                     }

or this:

#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
  auto Base::operator=([[maybe_unused]] Base const& that) -> Base&  { std::cout << "(out this, that)\n"; return *this; }

@bluetarpmedia
Copy link
Contributor Author

Why do you think it's a bug? The } on that line is generated from the code on line 3 of the cpp2 source file. I think the actual bug here is that there isn't a #line 3 before the return *this;.

If I put a breakpoint on line 3 in the Cpp2 file:

1 Base: type = {
2   operator=: (out this) = { }
3   operator=: (out this, that)       = std::cout << "(out this, that)\n";
4   operator=: (implicit out this, _) = std::cout << "(implicit out this, _)\n";
5 }
...

then I want the debugger to break at the beginning of the function. So if there are multiple #line 3 directives in the PDB (for example) pointing at different Cpp1 lines then I was concerned it may choose one of the other directives instead of the one preceding the function.

But your example here:

#line 3 "pure2-bugfix-for-memberwise-base-assignment.cpp2"
  auto Base::operator=([[maybe_unused]] Base const& that) -> Base&  { std::cout << "(out this, that)\n"; return *this; }

seems ideal to me and would remove all ambiguity. I'm not sure which part of cppfront puts a newline before the generated return but I think it's separate to the line directive changes I made.

@gregmarr
Copy link
Contributor

If it can't handle multiple line directives pointing at the same line, then it has no hope of properly debugging this, as those end up all over the place.

I'm not sure which part of cppfront puts a newline before the generated return but I think it's separate to the line directive changes I made.

That may be true, but it would be good to know exactly why this PR removes an existing correct line number, so it doesn't cause another issue later.

Restores the original behaviour in the `pure2-bugfix-for-memberwise-base-assignment` regression test where a line directive is emitted after the return statement and before the closing brace.
@bluetarpmedia
Copy link
Contributor Author

That may be true, but it would be good to know exactly why this PR removes an existing correct line number, so it doesn't cause another issue later.

I've updated the PR to restore the original behaviour of inserting the line directive prior to the closing brace in these emitted assignment operators.

As a result, the changes to the regression tests in this PR only involve inserting new line directives prior to function definitions.

@bluetarpmedia
Copy link
Contributor Author

This PR has been replaced by PR #932.
It was easier to start again based on the new to_cpp1.h code rather than updating this version.

@bluetarpmedia bluetarpmedia deleted the linedirs branch January 12, 2024 01:33
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.

2 participants