Skip to content

[lldb/DWARF] Downgrade the "parent of variable is not CU" error #108806

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

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

labath
Copy link
Collaborator

@labath labath commented Sep 16, 2024

This can legitimately happen for static function-local variables with a non-manual dwarf index. According to the DWARF spec, these variables should be (and are) included in the compiler generated indexes, but they are ignored by our manual index. Encountering them does not indicate any sort of error.

The error message is particularly annoying due to a combination of the fact that we don't cache negative hits (so we print it every time we encounter it), VSCode's aggresive tab completion (which attempts a lookup after every keypress) and the fact that some low-level libraries (e.g. tcmalloc) have several local variables called "v". The result is a console full of error messages everytime you type "v ".

We already have tests (e.g. find-basic-variable.cpp), which check that these variables are not included in the result (and by extension, that their presence does not crash lldb). It would be possible to extend it to make sure it does not print this error message, but it doesn't seem like it would be particularly useful.

@labath labath requested a review from Michael137 September 16, 2024 09:33
@llvmbot llvmbot added the lldb label Sep 16, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 16, 2024

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

This can legitimately happen for static function-local variables with a non-manual dwarf index. According to the DWARF spec, these variables should be (and are) included in the compiler generated indexes, but they are ignored by our manual index. Encountering them does not indicate any sort of error.

The error message is particularly annoying due to a combination of the fact that we don't cache negative hits (so we print it every time we encounter it), VSCode's aggresive tab completion (which attempts a lookup after every keypress) and the fact that some low-level libraries (e.g. tcmalloc) have several local variables called "v". The result is a console full of error messages everytime you type "v ".

We already have tests (e.g. find-basic-variable.cpp), which check that these variables are not included in the result (and by extension, that their presence does not crash lldb). It would be possible to extend it to make sure it does not print this error message, but it doesn't seem like it would be particularly useful.


Full diff: https://github.com/llvm/llvm-project/pull/108806.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+2-4)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index f721ca00fd3559..082c437321e38b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3828,10 +3828,8 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
     break;
 
   default:
-    GetObjectFile()->GetModule()->ReportError(
-        "didn't find appropriate parent DIE for variable list for {0:x8} "
-        "{1} ({2}).\n",
-        die.GetID(), DW_TAG_value_to_name(die.Tag()), die.Tag());
+    LLDB_LOG(GetLog(DWARFLog::Lookups),
+             "DIE {0:x8} is not a global variable - ignoring", die.GetID());
     return;
   }
 

labath added a commit to labath/llvm-project that referenced this pull request Sep 16, 2024
Use a `nullptr` map entry to mean "variable parse was attempted and it
failed" an the absence of an entry to mean "parsing hasn't been
attempted yet".

I ran into this because parsing of function-static variables was
generating a lot of errors (see llvm#108806), but this seems like a good
idea in general.

In theory this should be NFC, except for possibly reducing some amount
of work.
Copy link
Member

@Michael137 Michael137 left a comment

Choose a reason for hiding this comment

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

Seems reasonable to make this less spammy. Though is there a reason why we're not adding them to the manual index? Is this just something we didn't implement (yet)?

@labath
Copy link
Collaborator Author

labath commented Sep 16, 2024

Adding these to the manual index is very easy -- there just isn't a point in doing it (except maybe for consistency).

In case I wasn't clear: this warning/error appears in the compiler-generated indexes, because we find the variable in the name lookup -- and then ignore it.
For the manual index, the variable is simply not found, so there's nothing to ignore or warn about.

@labath
Copy link
Collaborator Author

labath commented Sep 16, 2024

One more clarification :P

I think it would be reasonable for something like target variable foo()::v to return the static variable v in function foo(), and to make that work we might (depending on how exactly this is implemented) need to insert the variable into the manual index as well. However, we don't support such queries right now.

@Michael137
Copy link
Member

Ahh thanks for the clarification. Makes sense.

Sounds like a situation where this would arise is:

struct Foo {
  static int bar;
};

int Foo::bar = 5;

int main() {
  static bool bar = false
  __builtin_debugtrap();
}

Doing (lldb) target var bar would produce this error. Which I agree doesn't seem right.

I guess the alternative would be to suppress the error message only if the parent is a DW_TAG_subprogram. But that wouldn't really be a complete check either since local variables wouldn't be distinguishable.

So LGTM.

"{1} ({2}).\n",
die.GetID(), DW_TAG_value_to_name(die.Tag()), die.Tag());
LLDB_LOG(GetLog(DWARFLog::Lookups),
"DIE {0:x8} is not a global variable - ignoring", die.GetID());
Copy link
Member

Choose a reason for hiding this comment

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

Nit: should we include the name/tag too? I could see it being useful

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, why not.

This can legitimately happen for static function-local variables with a
non-manual dwarf index. According to the DWARF spec, these variables
should be (and are) included in the compiler generated indexes, but they
are ignored by our manual index. Encountering them does not indicate any
sort of error.

The error message is particularly annoying due to a combination of the
fact that we don't cache negative hits (so we print it every time we
encounter it), VSCode's aggresive tab completion (which attempts a
lookup after every keypress) and the fact that some low-level libraries
(e.g. tcmalloc) have several local variables called "v". The result is a
console full of error messages everytime you type "v ".

We already have tests (e.g. find-basic-variable.cpp), which check that
these variables are not included in the result (and by extension, that
their presence does not crash lldb). It would be possible to extend it
to make sure it does *not* print this error message, but it doesn't seem
like it would be particularly useful.
@labath labath merged commit 1f8e662 into llvm:main Sep 19, 2024
7 checks passed
@labath labath deleted the local branch September 19, 2024 13:08
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
…#108806)

This can legitimately happen for static function-local variables with a
non-manual dwarf index. According to the DWARF spec, these variables
should be (and are) included in the compiler generated indexes, but they
are ignored by our manual index. Encountering them does not indicate any
sort of error.

The error message is particularly annoying due to a combination of the
fact that we don't cache negative hits (so we print it every time we
encounter it), VSCode's aggresive tab completion (which attempts a
lookup after every keypress) and the fact that some low-level libraries
(e.g. tcmalloc) have several local variables called "v". The result is a
console full of error messages everytime you type "v ".

We already have tests (e.g. find-basic-variable.cpp), which check that
these variables are not included in the result (and by extension, that
their presence does not crash lldb). It would be possible to extend it
to make sure it does *not* print this error message, but it doesn't seem
like it would be particularly useful.
Michael137 pushed a commit to swiftlang/llvm-project that referenced this pull request May 6, 2025
…#108806)

This can legitimately happen for static function-local variables with a
non-manual dwarf index. According to the DWARF spec, these variables
should be (and are) included in the compiler generated indexes, but they
are ignored by our manual index. Encountering them does not indicate any
sort of error.

The error message is particularly annoying due to a combination of the
fact that we don't cache negative hits (so we print it every time we
encounter it), VSCode's aggresive tab completion (which attempts a
lookup after every keypress) and the fact that some low-level libraries
(e.g. tcmalloc) have several local variables called "v". The result is a
console full of error messages everytime you type "v ".

We already have tests (e.g. find-basic-variable.cpp), which check that
these variables are not included in the result (and by extension, that
their presence does not crash lldb). It would be possible to extend it
to make sure it does *not* print this error message, but it doesn't seem
like it would be particularly useful.

(cherry picked from commit 1f8e662)
Michael137 pushed a commit to swiftlang/llvm-project that referenced this pull request May 6, 2025
…#108806)

This can legitimately happen for static function-local variables with a
non-manual dwarf index. According to the DWARF spec, these variables
should be (and are) included in the compiler generated indexes, but they
are ignored by our manual index. Encountering them does not indicate any
sort of error.

The error message is particularly annoying due to a combination of the
fact that we don't cache negative hits (so we print it every time we
encounter it), VSCode's aggresive tab completion (which attempts a
lookup after every keypress) and the fact that some low-level libraries
(e.g. tcmalloc) have several local variables called "v". The result is a
console full of error messages everytime you type "v ".

We already have tests (e.g. find-basic-variable.cpp), which check that
these variables are not included in the result (and by extension, that
their presence does not crash lldb). It would be possible to extend it
to make sure it does *not* print this error message, but it doesn't seem
like it would be particularly useful.

(cherry picked from commit 1f8e662)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants