Skip to content

[lldb] Fix TestDiagnoseDereferenceFunctionReturn on linux #128512

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 2 commits into from
Feb 25, 2025

Conversation

labath
Copy link
Collaborator

@labath labath commented Feb 24, 2025

The test was failing because it was looking up the immediate value from the call instruction as a load address, whereas in fact it was a file address. This worked on darwin because (with ASLR disabled) the two addresses are generally the same. On linux, this depends on the build mode, but with the default (PIE) build type, the two are never the same. The test also fails on a mac with ASLR enabled.

This path fixes the code to look up the value as a file address.

The test was failing because it was looking up the immediate value from
the call instruction as a load address, whereas in fact it was a file
address. This worked on darwin because (with ASLR disabled) the two
addresses are generally the same. On linux, this depends on the build
mode, but with the default (PIE) build type, the two are never the same.
The test also fails on a mac with ASLR enabled.

This path fixes the code to look up the value as a file address.
@llvmbot
Copy link
Member

llvmbot commented Feb 24, 2025

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

The test was failing because it was looking up the immediate value from the call instruction as a load address, whereas in fact it was a file address. This worked on darwin because (with ASLR disabled) the two addresses are generally the same. On linux, this depends on the build mode, but with the default (PIE) build type, the two are never the same. The test also fails on a mac with ASLR enabled.

This path fixes the code to look up the value as a file address.


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

2 Files Affected:

  • (modified) lldb/source/Target/StackFrame.cpp (+6-5)
  • (modified) lldb/test/API/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py (+1-1)
diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp
index 4d068638f42b6..f8061ffad1466 100644
--- a/lldb/source/Target/StackFrame.cpp
+++ b/lldb/source/Target/StackFrame.cpp
@@ -1670,13 +1670,14 @@ lldb::ValueObjectSP DoGuessValueAt(StackFrame &frame, ConstString reg,
         break;
       case Instruction::Operand::Type::Immediate: {
         SymbolContext sc;
-        Address load_address;
-        if (!frame.CalculateTarget()->ResolveLoadAddress(
-                operands[0].m_immediate, load_address)) {
+        if (!pc.GetModule())
+          break;
+        Address address(operands[0].m_immediate,
+                        pc.GetModule()->GetSectionList());
+        if (!address.IsValid())
           break;
-        }
         frame.CalculateTarget()->GetImages().ResolveSymbolContextForAddress(
-            load_address, eSymbolContextFunction, sc);
+            address, eSymbolContextFunction, sc);
         if (!sc.function) {
           break;
         }
diff --git a/lldb/test/API/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py b/lldb/test/API/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py
index d0f6ebefa334a..8ada9a2369602 100644
--- a/lldb/test/API/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py
+++ b/lldb/test/API/commands/frame/diagnose/dereference-function-return/TestDiagnoseDereferenceFunctionReturn.py
@@ -10,7 +10,7 @@
 
 
 class TestDiagnoseDereferenceFunctionReturn(TestBase):
-    @expectedFailureAll(oslist=no_match(lldbplatformutil.getDarwinOSTriples()))
+    @expectedFailureAll(oslist=["windows"])
     @skipIf(
         archs=no_match(["x86_64"])
     )  # <rdar://problem/33842388> frame diagnose doesn't work for armv7 or arm64

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

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

LGTM.

As usual with Windows, I am a bit curious whether this works there, but not enough to check myself or demand that you do :)

@DavidSpickett
Copy link
Collaborator

Also we have no Windows x86 bot right now so you'd never know if it was right outside your own machine.

@labath
Copy link
Collaborator Author

labath commented Feb 25, 2025

Thanks.

As we've learned in #123217, all of this relies on parsing the stop reason strings, and I think the windows strings just don't have the expected format.

@labath labath merged commit 6c17380 into llvm:main Feb 25, 2025
10 checks passed
@labath labath deleted the diagnose branch February 25, 2025 08:03
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