Skip to content

[lldb] Add a test for lea_rsp_pattern_p to x86 unwinder (NFC) #94852

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
Jun 11, 2024

Conversation

xgupta
Copy link
Contributor

@xgupta xgupta commented Jun 8, 2024

This commit adds a test for lea_rsp_pattern_p which was previously due as FIXME.

This commit adds a test for lea_rsp_pattern_p which was previously due as FIXME.
@xgupta xgupta requested a review from JDevlieghere as a code owner June 8, 2024 12:16
@llvmbot llvmbot added the lldb label Jun 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 8, 2024

@llvm/pr-subscribers-lldb

Author: Shivam Gupta (xgupta)

Changes

This commit adds a test for lea_rsp_pattern_p which was previously due as FIXME.


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

1 Files Affected:

  • (modified) lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp (+23-1)
diff --git a/lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp b/lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp
index 277cc14ce50c9..597e5b2e40d5e 100644
--- a/lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp
+++ b/lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp
@@ -1731,7 +1731,29 @@ TEST_F(Testx86AssemblyInspectionEngine, TestAddESP) {
   EXPECT_EQ(4 - 16, row_sp->GetCFAValue().GetOffset());
 }
 
-// FIXME add test for lea_rsp_pattern_p
+TEST_F(Testx86AssemblyInspectionEngine, TestLEA_RSP_Pattern) {
+  UnwindPlan::Row::RegisterLocation regloc;
+  UnwindPlan::RowSP row_sp;
+  AddressRange sample_range;
+  UnwindPlan unwind_plan(eRegisterKindLLDB);
+  std::unique_ptr<x86AssemblyInspectionEngine> engine = Getx86_64Inspector();
+
+  uint8_t data[] = {
+      0x8d, 0x64, 0x24, 0x10, // lea rsp, [rsp + 0x10]
+      0x90                    // nop
+  };
+
+  sample_range = AddressRange(0x1000, sizeof(data));
+
+  EXPECT_TRUE(engine->GetNonCallSiteUnwindPlanFromAssembly(
+      data, sizeof(data), sample_range, unwind_plan));
+
+  row_sp = unwind_plan.GetRowForFunctionOffset(0);
+  EXPECT_EQ(0ull, row_sp->GetOffset());
+  EXPECT_TRUE(row_sp->GetCFAValue().GetRegisterNumber() == k_rsp);
+  EXPECT_TRUE(row_sp->GetCFAValue().IsRegisterPlusOffset() == true);
+  EXPECT_EQ(8, row_sp->GetCFAValue().GetOffset());
+}
 
 TEST_F(Testx86AssemblyInspectionEngine, TestPopRBX) {
   UnwindPlan::Row::RegisterLocation regloc;

@jasonmolenda
Copy link
Collaborator

Hi, thanks for the PR. I wrote the x86 unwinder but I don't work with the ISA very often any more, I'm a little confused. Shouldn't the sp offset after this instruction executes be 16? The test is testing for 8. I'm sure I've misunderstood the effects of the instruction.

@jasonmolenda jasonmolenda self-requested a review June 10, 2024 23:49
Copy link
Collaborator

@jasonmolenda jasonmolenda left a comment

Choose a reason for hiding this comment

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

Ah wait, it's because x86_64 functions on entry have the CFA == $rsp+8, right. So you add 16 to rsp and now the CFA is $rsp-8. This is good to merge. Do you have access to do that yourself?

@xgupta
Copy link
Contributor Author

xgupta commented Jun 11, 2024

Thanks @jasonmolenda for the review. I do have commit access to merge it.

@xgupta xgupta merged commit baad1b8 into llvm:main Jun 11, 2024
7 checks passed
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Jun 12, 2024
…4852)

This commit adds a test for lea_rsp_pattern_p which was previously due
as FIXME.
@xgupta xgupta deleted the lea_rsp_pattern_p_test branch June 12, 2024 16:21
@HerrCai0907 HerrCai0907 mentioned this pull request Jun 13, 2024
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