This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][NativePDB] Global ctor and dtor should be global decls.
ClosedPublic

Authored by zequanwu on Sep 7 2022, 12:35 PM.

Details

Summary

This fixes a crash that mistaken global ctor/dtor as funciton methods.

Diff Detail

Event Timeline

zequanwu created this revision.Sep 7 2022, 12:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 7 2022, 12:35 PM
zequanwu requested review of this revision.Sep 7 2022, 12:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 7 2022, 12:35 PM
rnk added inline comments.Sep 7 2022, 1:00 PM
lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
1198

Should the check be done before GetParentDeclContext or be done inside GetParentDeclContext so that we don't do wasted work computing a parent that won't be used for dynamic initializers?

zequanwu updated this revision to Diff 458583.Sep 7 2022, 3:23 PM
zequanwu marked an inline comment as done.

Address comment.

labath added a comment.Sep 9 2022, 2:32 AM

I believe that this fixes the crash, but the names of generated functions still look fairly weird. Could we create them using their mangled name instead? That way, someone might actually call them, if he was so inclined.

zequanwu updated this revision to Diff 459145.Sep 9 2022, 11:41 AM

Update test case after moving the check into CreateDeclInfoForUndecoratedName.

I believe that this fixes the crash, but the names of generated functions still look fairly weird. Could we create them using their mangled name instead? That way, someone might actually call them, if he was so inclined.

It looks like they don't have mangled name stored in pdb.

I believe that this fixes the crash, but the names of generated functions still look fairly weird. Could we create them using their mangled name instead? That way, someone might actually call them, if he was so inclined.

It looks like they don't have mangled name stored in pdb.

Hmm.. That's unfortunate. In that case, I'm wondering if this shouldn't be handled somehow directly inside MSVCUndecoratedNameParser. What does the function return right now? Do you think that result is going to be useful for other users of that class?

Also, I'm still continuing to be amazed (and scared) by the amount of name parsing that is going on here. Have you checked that there's no better way to associate an entity with its enclosing context?

I believe that this fixes the crash, but the names of generated functions still look fairly weird. Could we create them using their mangled name instead? That way, someone might actually call them, if he was so inclined.

It looks like they don't have mangled name stored in pdb.

Hmm.. That's unfortunate. In that case, I'm wondering if this shouldn't be handled somehow directly inside MSVCUndecoratedNameParser. What does the function return right now? Do you think that result is going to be useful for other users of that class?

MSVCUndecoratedNameParser expects a undercoated name of a entity(class, function, variable, etc) and returns the a pair of {pointer to parent decl context, base name of the entity}. This is the only way we use to get enclosing context for a given entity.

Also, I'm still continuing to be amazed (and scared) by the amount of name parsing that is going on here. Have you checked that there's no better way to associate an entity with its enclosing context?

If the entity is a global variable, we don't have any other ways to know if its enclosing context is record or namespace. If the entity is record or function, then we can know if its enclosing context is a record by looking at its type info but need to fall back to parse name again if it's inside a namespace. The issue is there isn't a way to represent namespaces in PDB, and they are just embedded into the name strings.

I believe that this fixes the crash, but the names of generated functions still look fairly weird. Could we create them using their mangled name instead? That way, someone might actually call them, if he was so inclined.

It looks like they don't have mangled name stored in pdb.

Hmm.. That's unfortunate. In that case, I'm wondering if this shouldn't be handled somehow directly inside MSVCUndecoratedNameParser. What does the function return right now? Do you think that result is going to be useful for other users of that class?

MSVCUndecoratedNameParser expects a undercoated name of a entity(class, function, variable, etc) and returns the a pair of {pointer to parent decl context, base name of the entity}.

Hmm... are you sure about that? CreateDeclInfoForUndecoratedName returns a {decl ctx, base name} pair. MSVCUndecoratedNameParser returns (creates) an array of MSVCUndecoratedNameSpecifiers. My question was about what those specifiers are specifically for the inputs we're talking about here (static void B::dynamic atexit destructor for 'glob'() or such), and whether those outputs "make sense" for some user of that class (it's clear that they don't make sense here).

Basically, I'm trying to see whether it's possible (desirable?) to move this logic into the parser class. The parser already does a lot of string manipulation, so checking for these strings there would make more sense to me than doing some sort of a pre-parse from the outside.

Also, I'm still continuing to be amazed (and scared) by the amount of name parsing that is going on here. Have you checked that there's no better way to associate an entity with its enclosing context?

If the entity is a global variable, we don't have any other ways to know if its enclosing context is record or namespace. If the entity is record or function, then we can know if its enclosing context is a record by looking at its type info but need to fall back to parse name again if it's inside a namespace. The issue is there isn't a way to represent namespaces in PDB, and they are just embedded into the name strings.

Hmm.. well, that's unfortunate, but I guess we'll have to live with it.

I believe that this fixes the crash, but the names of generated functions still look fairly weird. Could we create them using their mangled name instead? That way, someone might actually call them, if he was so inclined.

It looks like they don't have mangled name stored in pdb.

Hmm.. That's unfortunate. In that case, I'm wondering if this shouldn't be handled somehow directly inside MSVCUndecoratedNameParser. What does the function return right now? Do you think that result is going to be useful for other users of that class?

MSVCUndecoratedNameParser expects a undercoated name of a entity(class, function, variable, etc) and returns the a pair of {pointer to parent decl context, base name of the entity}.

Hmm... are you sure about that? CreateDeclInfoForUndecoratedName returns a {decl ctx, base name} pair. MSVCUndecoratedNameParser returns (creates) an array of MSVCUndecoratedNameSpecifiers. My question was about what those specifiers are specifically for the inputs we're talking about here (static void B::dynamic atexit destructor for 'glob'() or such), and whether those outputs "make sense" for some user of that class (it's clear that they don't make sense here).

Basically, I'm trying to see whether it's possible (desirable?) to move this logic into the parser class. The parser already does a lot of string manipulation, so checking for these strings there would make more sense to me than doing some sort of a pre-parse from the outside.

Sorry, I misunderstood you and copied the wrong function name there. And yeah, I think the logic should be moved into MSVCUndecoratedNameParser.

zequanwu updated this revision to Diff 460152.Sep 14 2022, 10:43 AM

Move the logic into MSVCUndecoratedNameParser.

labath accepted this revision.Sep 15 2022, 6:16 AM
This revision is now accepted and ready to land.Sep 15 2022, 6:16 AM