[Lldb-commits] [lldb] 701030c - In InitializeZerothFrame check for a CFA/AFA or error out

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 6 14:55:17 PST 2023


Author: Jason Molenda
Date: 2023-02-06T14:53:50-08:00
New Revision: 701030c3ecba0621ce5d325667fb75b73cf1532b

URL: https://github.com/llvm/llvm-project/commit/701030c3ecba0621ce5d325667fb75b73cf1532b
DIFF: https://github.com/llvm/llvm-project/commit/701030c3ecba0621ce5d325667fb75b73cf1532b.diff

LOG: In InitializeZerothFrame check for a CFA/AFA or error out

There is a failure where we somehow get an invalid register
number being used to calculate the canonical frame address,
and this ends up with lldb crashing with a null deref because it
assumes that it is always able to find information about that
register.

This patch adds a check for a failure to get a register, and
declares the frame invalid in that case, with some additional
logging or an assert for debug builds.

Differential Revision: https://reviews.llvm.org/D143232
rdar://104428038

Added: 
    

Modified: 
    lldb/source/Target/RegisterContextUnwind.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/RegisterContextUnwind.cpp b/lldb/source/Target/RegisterContextUnwind.cpp
index 2da40ba2bf61e..bf31ebbd858ae 100644
--- a/lldb/source/Target/RegisterContextUnwind.cpp
+++ b/lldb/source/Target/RegisterContextUnwind.cpp
@@ -37,6 +37,8 @@
 #include "lldb/Utility/RegisterValue.h"
 #include "lldb/Utility/VASPrintf.h"
 #include "lldb/lldb-private.h"
+
+#include <cassert>
 #include <memory>
 
 using namespace lldb;
@@ -289,6 +291,13 @@ void RegisterContextUnwind::InitializeZerothFrame() {
   } else
     ReadFrameAddress(row_register_kind, active_row->GetAFAValue(), m_afa);
 
+  if (m_cfa == LLDB_INVALID_ADDRESS && m_afa == LLDB_INVALID_ADDRESS) {
+    UnwindLogMsg(
+        "could not read CFA or AFA values for first frame, not valid.");
+    m_frame_type = eNotAValidFrame;
+    return;
+  }
+
   UnwindLogMsg("initialized frame current pc is 0x%" PRIx64 " cfa is 0x%" PRIx64
                " afa is 0x%" PRIx64 " using %s UnwindPlan",
                (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
@@ -2116,6 +2125,14 @@ bool RegisterContextUnwind::ReadGPRValue(lldb::RegisterKind register_kind,
   }
 
   const RegisterInfo *reg_info = GetRegisterInfoAtIndex(lldb_regnum);
+  assert(reg_info);
+  if (!reg_info) {
+    UnwindLogMsg(
+        "Could not find RegisterInfo definition for lldb register number %d",
+        lldb_regnum);
+    return false;
+  }
+
   RegisterValue reg_value;
   // if this is frame 0 (currently executing frame), get the requested reg
   // contents from the actual thread registers


        


More information about the lldb-commits mailing list