lldb - detect retguard prologue

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

lldb - detect retguard prologue

Todd Mortimer
The diff below teaches the lldb assembly inspector to skip over the
retguard instrumentation when traversing function prologues.

ok?


diff --git a/gnu/llvm/tools/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp b/gnu/llvm/tools/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
index 10a56980594..251635c7e6f 100644
--- a/gnu/llvm/tools/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
+++ b/gnu/llvm/tools/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
@@ -593,6 +593,18 @@ bool x86AssemblyInspectionEngine::ret_pattern_p() {
   return false;
 }

+// movq $0x????????(%rip), $reg [(0x4c || 0x48) 0x8b ?? ?? ?? ?? ??]
+// xorq $off(%rsp), $reg        [(0x4c || 0x48) 0x33 ?? 0x24]
+bool x86AssemblyInspectionEngine::retguard_prologue_p(size_t offset, int insn_len) {
+  uint8_t *p = m_cur_insn;
+  if (offset == 0 && insn_len == 7)
+    return (*p == 0x48 || *p == 0x4c) && (*(p + 1) == 0x8b);
+  else if (offset == 7 && insn_len == 4)
+    return (*p == 0x48 || *p == 0x4c) && (*(p + 1) == 0x33) && (*(p + 3) == 0x24);
+
+  return false;
+}
+
 uint32_t x86AssemblyInspectionEngine::extract_4(uint8_t *b) {
   uint32_t v = 0;
   for (int i = 3; i >= 0; i--)
@@ -1214,6 +1226,7 @@ bool x86AssemblyInspectionEngine::FindFirstNonPrologueInstruction(
     if (push_rbp_pattern_p() || mov_rsp_rbp_pattern_p() ||
         sub_rsp_pattern_p(scratch) || push_reg_p(regno) ||
         mov_reg_to_local_stack_frame_p(regno, scratch) ||
+        retguard_prologue_p(offset, insn_len) ||
         (lea_rsp_pattern_p(scratch) && offset == 0)) {
       offset += insn_len;
       continue;
diff --git a/gnu/llvm/tools/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.h b/gnu/llvm/tools/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.h
index cec9803c8a4..8ef4ab59c63 100644
--- a/gnu/llvm/tools/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.h
+++ b/gnu/llvm/tools/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.h
@@ -110,6 +110,7 @@ private:
   bool call_next_insn_pattern_p();
   bool mov_reg_to_local_stack_frame_p(int &regno, int &rbp_offset);
   bool ret_pattern_p();
+  bool retguard_prologue_p(size_t offset, int insn_len);
   uint32_t extract_4(uint8_t *b);

   bool instruction_length(uint8_t *insn, int &length, uint32_t buffer_remaining_bytes);