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

[GR-34179] Upgrade CE debug info feature to provide information about Java types for Windows/PECOFF #3732

Merged
merged 1 commit into from Dec 16, 2022

Conversation

stooke
Copy link
Contributor

@stooke stooke commented Aug 27, 2021

This PR adds type information to the CodeView 4 debug information (See PR #2396). It is related to issue #2986, but is targeted to Windows and Visual Studio.

This PR is based off (and highly dependant on) the work in PR #3046.

With this patch, memory can be examined from the Visual Studio or WinDbg command line and cast to Java types as laid out by the Graal compiler. Static member variables can be referenced directly.

Caveats:

  • Pointer types for instance members in the presence of isolates are not yet implemented, as there appears to be no way to express a pointer that is an offset from r14 in CodeView. I will continue to research this, but at this time, this implementation works best if isolates are disabled.
  • As there is no local variable information added by this PR, users must manually cast registers to pointers; for example (java_lang_String*)(rdx).

I recommend @adinn as a first reviewer for this PR, as it is based on his debug type PR.

@oubidar-Abderrahim oubidar-Abderrahim self-assigned this Aug 31, 2021
@olpaw olpaw added this to To do in Native Image via automation Aug 31, 2021
@olpaw olpaw assigned olpaw and unassigned oubidar-Abderrahim Aug 31, 2021
@olpaw
Copy link
Member

olpaw commented Aug 31, 2021

@adinn looks like github does not allow me to put you on this one as reviewer 😞

@adinn
Copy link
Collaborator

adinn commented Aug 31, 2021

@olpaw No worry. I'll review it anyway :-)

Copy link
Collaborator

@adinn adinn left a comment

Choose a reason for hiding this comment

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

This looks ok to me modulo the 3 inline comments I made. Not that I can really comment on the intricacies of the PeCOFF records and their detailed layout.

I believe this is going to need to be modified slightly when rebased over head in order to take account of the changes made to support inline info. Specifically PrimaryEntry.getSubranges() is still being called from CVLinerecordBuilder. That has been dropped in head in favour of calling leafRangeIterator(). I don't think there us anything else needs changing though.

@adinn
Copy link
Collaborator

adinn commented Sep 14, 2021

I believe this is going to need to be modified slightly when rebased over head in order to take account of the changes made to support inline info. Specifically PrimaryEntry.getSubranges() is still being called from CVLinerecordBuilder. That has been dropped in head in favour of calling leafRangeIterator(). I don't think there us anything else needs changing though.

@stooke The above tweak turns out to be unneeded. The upstream code was updated to use the correct iterator when the gdb inline methods patch went in. Once this PR is rebased it all fits together without any conflict. So, it appears to be ready for Oracle review and merging.

@pejovica Could you please review this and help get it through the Oracle gate?

@pejovica
Copy link
Member

@adinn Sure, I should be able to start with that after next week.

@adinn
Copy link
Collaborator

adinn commented Oct 4, 2021

@pejovica This PR is still waiting to be reviewed. will you be able to do that soon or do we need to find someone else to review it?

@olpaw olpaw self-requested a review October 4, 2021 12:00
Copy link
Member

@olpaw olpaw left a comment

Choose a reason for hiding this comment

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

Hi @stooke
Great to see progress on the Windows side of CE debuginfo generation!

Please consolidate the commits. E.g. combine subsequent style related commits into one (or even better, fold them into the commit that is the origin of the style issue). Also start commit messages with uppercase. A more thorough review from @pejovica will follow.

Native Image automation moved this from To do to In progress Oct 4, 2021
@olpaw
Copy link
Member

olpaw commented Oct 4, 2021

  • Please consolidate the commits. E.g. combine subsequent style related commits into one (or even better, fold them into the commit that is the origin of the style issue). Also start commit messages with uppercase.

@stooke
Copy link
Contributor Author

stooke commented Oct 4, 2021

  • Please consolidate the commits. E.g. combine subsequent style related commits into one (or even better, fold them into the commit that is the origin of the style issue). Also start commit messages with uppercase.

Hello @olpaw , and thank you for your review! I've started to address your concerns, and squashed many of the commits, changing the messages to start with uppercase. Please let me know if I should squash further.

@olpaw
Copy link
Member

olpaw commented Oct 4, 2021

I've started to address your concerns, and squashed many of the commits, changing the messages to start with uppercase. Please let me know if I should squash further.

Looks much better now. Thanks!

@adinn
Copy link
Collaborator

adinn commented Oct 7, 2021

@olpaw is this still waiting on a review from @pejovica or is it ok for it to be pushed through the gate?

@olpaw
Copy link
Member

olpaw commented Oct 7, 2021

@olpaw is this still waiting on a review from @pejovica or is it ok for it to be pushed through the gate?

@pejovica is currently reviewing the PR (and testing it thoroughly on his Windows machine). Since the PR is quite big this might take some more time. Sorry for the inconvenience.

@adinn
Copy link
Collaborator

adinn commented Oct 7, 2021

@olpaw Sure, thanks for the update and no inconvenience or problem about @pejovica taking his time. I'm very glad to hear he is giving it a proper workout.

Copy link
Member

@pejovica pejovica left a comment

Choose a reason for hiding this comment

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

@stooke Thanks for working on this!

Overall, the PR looks good, but there are a few more things to do. Apart from what is stated in the comments, my main concern is the design of CVTypeSectionBuilder. In particular, I think there is no need to replace forwarding records with complete records on the fly as it only makes things harder to reason about.

Instead, I suggest establishing a few invariants that we can easily check:

  1. Type records should only use forwarding records for cross-referencing.
  2. Symbol records should only use complete records for cross-referencing (e.g., for S_UDT records).

This would mean that CVTypeSectionBuilder.buildClass will still make a complete record, but while doing so it will only be able to reference forwarding records. As a result, there will be no need to track whether the construction of a complete record is in progress -- it will no longer matter as only forwarding records will be referenced, and we can make them as needed.

String externName = memberNameToCodeViewName(classEntry, f);
if (cvDebugInfo.useHeapBase()) {
/* REL32 offset from heap base register. */
addToSymbolSubsection(new CVSymbolSubrecord.CVSymbolRegRel32Record(cvDebugInfo, externName, typeIndex, f.getOffset(), cvDebugInfo.getHeapbaseRegister()));
Copy link
Member

Choose a reason for hiding this comment

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

Well, I don't think this can work... So I'd suggest that we drop this for now and document that we only support debugging with -H:-SpawnIsolates.

Also note that the register must be specified using the appropriate CV constant, such as CV_AMD64_R14.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I propose we definitely say we don't support debugging with isolates (should we emit a warning?), but I'd like to keep this code in; using pointer arithmetic (and a notepad) it is possible to make your way around even with isolates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the register constants properly.

@stooke
Copy link
Contributor Author

stooke commented Jul 26, 2022

Feel free to ping me here or on Slack if any public gates need to be restarted. If you add new commits, I need to sync them with the internal PR and that means I need to re-run all internal gates, too.

Sorry, I just added a dummy commit to restart the public gates; should I squash that and push again? Next time I'll ping you instead.

@fniephaus
Copy link
Member

It's all good... just wanted you to be aware that I need to sync all commits and that there are other ways to restart gates. :)

@stooke
Copy link
Contributor Author

stooke commented Jul 26, 2022

It's all good... just wanted you to be aware that I need to sync all commits and that there are other ways to restart gates. :)

Duly noted. :) Should I squash my dummy commit? The PR is good ether way.

@fniephaus
Copy link
Member

Good! :) No need to do anything, I'll just drop the dummy commit so I don't need to restart the internal gates.

Comment on lines 1063 to 1064
/* Add in size of record type and length fields. */
return estimatedSize + Short.BYTES * 2;
Copy link
Member

Choose a reason for hiding this comment

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

Well, this is not entirely true. The record size does not include the length field, only the type field. However, we really do lose 4 bytes due to the alignment requirement.

I think this could be better expressed using availableSize (instead of estimatedSize) as the initial value can be clearly defined

    int availableSize = MAX_LF_FIELDLIST_RECORD_SIZE - CVUtil.align4(Short.BYTES) - CVUtil.align4(LF_INDEX_RECORD_SIZE);

and the rest of the code would only require a slight adjustment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pejovica, I've refactored this to correct the calculation and alignment calculations, but I haven't moved to using 'availableSize' as I think the concept of limits is best kept to the FieldListBuilder.
If this is a showstopper, please let me know and we can discuss it.

@stooke
Copy link
Contributor Author

stooke commented Aug 18, 2022

@pejovica, thank you again for your comments. I have posted a set of changes to address them (but haven't adopted 'availableSize' for reasons given above).

Copy link
Member

@pejovica pejovica left a comment

Choose a reason for hiding this comment

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

@stooke I left you a few more comments, but other than that the PR looks good.

@stooke
Copy link
Contributor Author

stooke commented Oct 26, 2022

@pejovica thank you for your review, and I'm sorry circumstances forced me to take this long to get back to this PR. I've incorporated your suggestions. Should I rebase on head?

@pejovica
Copy link
Member

pejovica commented Nov 3, 2022

@stooke No worries, glad you're back!

Should I rebase on head?

Yes, that would be great.

@stooke
Copy link
Contributor Author

stooke commented Nov 7, 2022

@stooke No worries, glad you're back!

Should I rebase on head?

Yes, that would be great.

@pejovica , I've rebased the PR. Thank you for your patience.

Copy link
Member

@pejovica pejovica left a comment

Choose a reason for hiding this comment

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

@stooke One last thing, can you please squash everything into one commit before I proceed with the integration.

@stooke
Copy link
Contributor Author

stooke commented Dec 12, 2022

@stooke One last thing, can you please squash everything into one commit before I proceed with the integration.

@pejovica I have pushed the PR as a single commit.

@pejovica
Copy link
Member

Excellent, thanks!

@pejovica pejovica changed the title [GR-39210] Upgrade CE debug info feature to provide information about Java types for Windows/PECOFF [GR-34179] Upgrade CE debug info feature to provide information about Java types for Windows/PECOFF Dec 13, 2022
@graalvmbot graalvmbot merged commit 77e3a74 into oracle:master Dec 16, 2022
Native Image automation moved this from In progress to Done Dec 16, 2022
Native Image Debugging automation moved this from In progress to Done Dec 16, 2022
sophie-kaleba pushed a commit to sophie-kaleba/truffle that referenced this pull request Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
native-image-debuginfo OCA Verified All contributors have signed the Oracle Contributor Agreement. oca-signed redhat-interest
Projects
Native Image
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

8 participants