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

[DebugInfo]Fix for redundant lexical block in debug info #895

Merged
merged 1 commit into from
Aug 28, 2020

Conversation

SouraVX
Copy link
Collaborator

@SouraVX SouraVX commented May 16, 2020

Flang was creating a redundant lexical block at the beginning of of every subroutine debug info. This was causing debuggers to incorrectly assume the scope of a variable to be this lexical block.

This patch fixes this incorrect behavior by replacing all the debug info references of this redundant lexical block to the actual subroutine.

Brief explanation and correct behavior can be found here:
http://lists.llvm.org/pipermail/flang-dev/2020-April/000277.html
https://patchwork.ozlabs.org/patch/436971/

After this, GDB is correctly able to show formal arguments for the case of pass by value parameters.

@gklimowicz gklimowicz requested a review from jieljiel May 22, 2020 18:56
@SouraVX
Copy link
Collaborator Author

SouraVX commented Jun 1, 2020

Gentle Ping @Jiel-nv!

Copy link

@jieljiel jieljiel left a comment

Choose a reason for hiding this comment

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

This change works, the scope changes of the metadata look like shortcuts are made which bypassed the DILexicalBlock and subsequent DILocation mdnodes. However, isn't it better to avoid emitting those mdnodes because they are no longer referenced anywhere, in other words, those are unnecessary.

Actually, instead of checking STYPE on each cur_line_mdnode, it could be easier to set the root block mdnode to be the subprogram itself. Fortran doesn't have lexical block and nested lexical block. So it seems to me, a simple one line change might do the trick.

How about just use the the "parent_blk_mdnode" to replace the call to "lldbg_create_block_mdnode()".
I think this simple change works the same, i.e. redundant DWARF layer of lexical block will be removed. But a better looking debug metadata will be produced.

@SouraVX
Copy link
Collaborator Author

SouraVX commented Jun 2, 2020

Thank you for your reviewing this!

Actually, instead of checking STYPE on each cur_line_mdnode, it could be easier to set the root block mdnode to be the subprogram itself. Fortran doesn't have lexical block and nested lexical block. So it seems to me, a simple one line change might do the trick.

With Fortran 2008 we can have lexical blocks with BLOCK statement:
BLOCK
REAL BLOCK_LOCAL
....
END BLOCK

Anyways I've flipped the approach similar to what you mentioned and fortunately this covers this above test scenarios also.
So we're all set to no redundant block in LLVM IR and the resultant DWARF. And correct Lexical Block debug info(From IR to DWARF) for the BLOCK statement💯

@SouraVX SouraVX changed the title Fix for redundant lexical block in debug info [DebugInfo]Fix for redundant lexical block in debug info Jun 2, 2020
@SouraVX SouraVX requested a review from jieljiel June 2, 2020 07:14
@SouraVX
Copy link
Collaborator Author

SouraVX commented Jul 25, 2020

Rebased on top of master, added test case.
@kiranchandramohan , @gklimowicz, please have a look!
Thanks!

Copy link
Collaborator

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

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

One minor formatting comment.
I am running some internal tests and will get back to you in a couple of days.

@@ -1810,7 +1810,9 @@ lldbg_emit_lexical_block(LL_DebugInfo *db, int sptr, int lineno, int findex,
NEEDB((db->blk_idx + 1), db->blk_tab, BLKINFO, db->blk_tab_size,
(db->blk_tab_size + 64));
db->blk_tab[db->blk_idx].mdnode =
lldbg_create_block_mdnode(db, parent_blk_mdnode, lineno, 1, findex, ID++);
STYPEG(sptr) == ST_BLOCK ? lldbg_create_block_mdnode(db,
parent_blk_mdnode, lineno, 1, findex, ID++)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are tabs here I think. Could you check and remove?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not visible from diff, but after setting list there is some special character "^I". Thanks for mentioning this!
Anyway should I squash(all the commits) it or do an extra commit for this formatting correction ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please go ahead and squash.

Flang was creating a redundant lexical block at the beginning of
of every subroutine. This was causing debuggers to incorrectly
assume the scope of a variable to be this lexical block.

This patch fixes this incorrect behavior by creating a lexical
block iff there is actually present in source code.
Copy link
Collaborator

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

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

LGTM. Internal tests passed.

@SouraVX
Copy link
Collaborator Author

SouraVX commented Aug 25, 2020

Although this PR is already approved by @jiel-nv . @gklimowicz could you please run internal tests ? so that we can move ahead.

@gklimowicz
Copy link
Contributor

Testing today...

@gklimowicz gklimowicz self-requested a review August 27, 2020 18:36
Copy link
Contributor

@gklimowicz gklimowicz left a comment

Choose a reason for hiding this comment

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

This passes our internal tests on OpenPower on LLVM 9, so I approve it.

@shivaramaarao shivaramaarao merged commit 18a9be2 into flang-compiler:master Aug 28, 2020
SouraVX added a commit to SouraVX/flang that referenced this pull request Apr 8, 2021
pawosm-arm pushed a commit that referenced this pull request Apr 8, 2021
@SouraVX SouraVX deleted the lex-block branch July 7, 2021 06:19
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.

5 participants