This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix member access in GetExpressionPath
AcceptedPublic

Authored by tonkosi on Aug 26 2022, 5:32 AM.

Details

Summary

This change fixes two issues in ValueObject::GetExpressionPath method:

  1. Accessing members of struct references used to produce expression paths such as "str.&str.member" (instead of the expected "str.member"). This is fixed by assigning the flag tha the child value is a dereference when calling Dereference() on references and adjusting logic in expression path creation.
  2. If the parent of member access is dereference, the produced expression path was "*(ptr).member". This is incorrect, since it dereferences the member instead of the pointer. This is fixed by wrapping dereference expression into parenthesis, resulting with "(*ptr).member".

Diff Detail

Event Timeline

tonkosi created this revision.Aug 26 2022, 5:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2022, 5:32 AM
tonkosi requested review of this revision.Aug 26 2022, 5:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2022, 5:32 AM
werat accepted this revision.Sep 9 2022, 7:35 AM
werat added reviewers: clayborg, granata.enrico.

Nice fix! It would be nice to remove redundant parenthesis, e.g. (*(ptr)).member -> (*ptr).member, but I see this is non-trivial with the current logic.

This revision is now accepted and ready to land.Sep 9 2022, 7:35 AM
tonkosi updated this revision to Diff 463158.Sep 27 2022, 2:36 AM

Forgot to propagate "epformat" when calling GetExpressionPath

clayborg accepted this revision.Sep 28 2022, 3:45 PM

Nice!

JDevlieghere edited reviewers, added: jingham; removed: granata.enrico.Sep 28 2022, 11:25 PM
This revision was automatically updated to reflect the committed changes.
mib added a subscriber: mib.Sep 30 2022, 7:39 AM

Hi @tonkosi! I think your patch broke the macOS bot: https://green.lab.llvm.org/green/job/lldb-cmake/47258/console

Failed Tests (5):
  lldb-api :: commands/frame/diagnose/array/TestArray.py
  lldb-api :: commands/frame/diagnose/bad-reference/TestBadReference.py
  lldb-api :: commands/frame/diagnose/complicated-expression/TestComplicatedExpression.py
  lldb-api :: commands/frame/diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py
  lldb-api :: commands/frame/diagnose/dereference-this/TestDiagnoseDereferenceThis.py

Let me know if you need help reproducing and fixing these issues, otherwise I'll have to revert your patch.

werat reopened this revision.Sep 30 2022, 8:27 AM

Let me know if you need help reproducing and fixing these issues, otherwise I'll have to revert your patch.

Sorry for the breaking the tests. We won't be able to look into this until next week, I've reverted the change for now.

This revision is now accepted and ready to land.Sep 30 2022, 8:27 AM
werat requested changes to this revision.Sep 30 2022, 8:27 AM
This revision now requires changes to proceed.Sep 30 2022, 8:27 AM
mib added a comment.Sep 30 2022, 8:28 AM

Let me know if you need help reproducing and fixing these issues, otherwise I'll have to revert your patch.

Sorry for the breaking the tests. We won't be able to look into this until next week, I've reverted the change for now.

Thank you @werat

tonkosi updated this revision to Diff 466043.Oct 7 2022, 5:02 AM
tonkosi edited the summary of this revision. (Show Details)

Fixed the issue of printing unnecessary parenthesis, which broke API tests on macOS.

Improved use of parenthesis to produce outputs such as (*ptr).member instead of (*(ptr)).member.

Hi, I fixed the issue causing macOS tests to fail, but I don't have a macOS machine to verify it actually works. I'd be grateful if someone could check that part.

I also decided to further reduce number of parenthesis in output (e.g. (*(ptr)).member isn't ideal), but now I realize that the previous *(a.b.c) might be more clear than *a.b.c. Let me know if I should revert that part.

werat accepted this revision.Oct 12 2022, 4:40 AM
This revision is now accepted and ready to land.Oct 12 2022, 4:40 AM
This revision was automatically updated to reflect the committed changes.
JDevlieghere added a comment.EditedOct 20 2022, 9:51 AM

Hey, this patch still breaks TestArray.py. Could you please take another look?

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/47748/testReport/lldb-api/commands_frame_diagnose_array/TestArray_py/

The issue is:

a->c = <parent failed to evaluate: parent is NULL>
hawkinsw added inline comments.
lldb/source/Core/ValueObject.cpp
1947

I am *absolutely* not an expert here but I've spent several hours trying to debug why this incredibly thorough, well-written patch does not handle the case in TestArray.py. It would seem to me that this is the check that we forgot to bring over in to the new logic. I was attempting to be able to have an updated version of the patch by tonight, but didn't get further than just debugging. I will continue to work on it -- I am sure that you gurus have other, more important things to work on.

That said, I am just trying to help so if I am totally off base, please let me know!

Sincerely,
Will

hawkinsw reopened this revision.Oct 24 2022, 3:09 PM

I updated this revision with the following change and I *think* that things are happy again:

diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 226a2c3f690f..1f939c6fa2cd 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -2004,6 +2004,11 @@ void ValueObject::GetExpressionPath(Stream &s,
       s.PutChar(')');
   }
 
+  if (m_flags.m_is_array_item_for_pointer &&
+      epformat == eGetExpressionPathFormatHonorPointers) {
+    s.PutCString(m_name.GetStringRef());
+  }
+
   if (print_obj_access)
     s.PutChar('.');
   if (print_ptr_access)

Let me know if that is helpful.

Sincerely,
Will

This revision is now accepted and ready to land.Oct 24 2022, 3:09 PM

If you would like, I'd be happy to reopen this patch as a separate issue if that's the better way to handle it! Sorry for the SPAM!

Will

Thanks Will, let me apply this locally and see if that addresses the issue for which I reverted the original patch.

Thanks for the fix Will!

Just one question: cpp test file contains the expression a[10].c and the test complains about the expression path a->c.
If I understand correctly, with the latest fix, that would become a[10]->c, which is not the original expression (object access vs pointer access).
Was it like that before or did I mess up something else as well? (the test expects only the substring "a[10]" so I guess it's possible it was like that before)

lldb/source/Core/ValueObject.cpp
1947

Whoops, nice catch. I somehow deleted this part when refactoring the code and forgot about it.

Thanks for looking into this and fixing it, Will :D

Mr. Sabolčec,

Thank you for the kind response -- I hope my work was helpful! It was lots of fun to dig in to this part of the codebase!

Sincerely,
Will

werat added a comment.Nov 9 2023, 7:34 AM

Thanks Will, let me apply this locally and see if that addresses the issue for which I reverted the original patch.

Hy Jonas, sorry for bumping an old thread, but did you manage to check if the latest revision fixes the issue?