This is an archive of the discontinued LLVM Phabricator instance.

Filter non-external static members from SBType::GetFieldAtIndex.
ClosedPublic

Authored by siggi-alpheus on Apr 25 2022, 11:03 AM.

Details

Summary

See issue 55040 where static members of classes declared in the anonymous namespace are incorrectly returned as member fields from lldb::SBType::GetFieldAtIndex(). It appears that attrs.member_byte_offset contains a sentinel value for members that don't have a DW_AT_data_member_location.

Diff Detail

Event Timeline

siggi-alpheus created this revision.Apr 25 2022, 11:03 AM
Herald added a project: Restricted Project. · View Herald Transcript
siggi-alpheus requested review of this revision.Apr 25 2022, 11:03 AM

For future reference, it's better to generate a full diff when uploading a patch manually. Here are some ways to do that.

Apart from the inline comment this patch seems fine. We should also add a test case with the non-external static member. I think the test case could be as simple as declaring a global variable of the given type, printing it, and making sure the output is correct. You can use one of the assembly tests in test/Shell/SymbolFile/DWARF/x86/ for inspiration. Or you can wait until I get a bit of time to create one...

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
2672

Have you run the test suite? I'd guess that you'd need to check for DW_AT_data_bit_offset here as well.

Thanks for taking a look. Let me see about fixing the test failures and writing that test.

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
2672

Yeah, I ran the tests overnight and I see a couple of tests failing. Will see about fixing and writing a test for the case.

Now passes all tests, still needs a test.

siggi-alpheus marked an inline comment as done.Apr 27 2022, 11:40 AM

Now passes all tests - but I still need to write a test for the problem.

Add a test that fails against the ToT lldb.

Please take a look. This now passes all tests locally, and adds a test that fails against the current ToT lldb.

A full diff from origin/main - I hope.

Fix awkwardly named variable in the test.

This is passing lldb-checks locally. Is there anything else I need to add or tweak, or is this ready for review?

labath accepted this revision.May 4 2022, 8:26 AM

Looks good. Thanks for the patch. Do you need me to commit this for you?

Left two comments inline, but I can also fix that when I'm pushing it.

lldb/test/Shell/SymbolFile/DWARF/x86/debug_static-member-anonymous-namespace.s
6

Better use some other number here, as it's fairly easy for a value to accidentally come out as zero.

23–26

We're not going to be running this, so you don't really need the main function.

This revision is now accepted and ready to land.May 4 2022, 8:26 AM

Thanks!

lldb/test/Shell/SymbolFile/DWARF/x86/debug_static-member-anonymous-namespace.s
18

I wonder why I couldn't get the query to work against an initialized global without the main function. Is the assembly directly out of gcc, or did you need to tweak it?
PS: Now I fancy some pie.

labath added inline comments.May 10 2022, 5:53 AM
lldb/test/Shell/SymbolFile/DWARF/x86/debug_static-member-anonymous-namespace.s
18

I produced this by modifying/reducing the input you provided (with looking at some gcc output as reference).

Without more details, I can only guess what was the problem for you, but one of issue that comes up in tests like this is that lldb does not like to display variables whose "file address" is zero -- it mistakes them for a null pointer (one day I'll have to fix that). I work around that here, by adding some padding so that the variable does not end up at the address zero.