[Lldb-commits] [PATCH] D143232: Return an error when the CFA resolves to no known register, instead of segfaulting

2023-02-06 Thread Jason Molenda via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG701030c3ecba: In InitializeZerothFrame check for a CFA/AFA 
or error out (authored by jasonmolenda).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143232/new/

https://reviews.llvm.org/D143232

Files:
  lldb/source/Target/RegisterContextUnwind.cpp


Index: lldb/source/Target/RegisterContextUnwind.cpp
===
--- lldb/source/Target/RegisterContextUnwind.cpp
+++ 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 
 #include 
 
 using namespace lldb;
@@ -289,6 +291,13 @@
   } 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 @@
   }
 
   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


Index: lldb/source/Target/RegisterContextUnwind.cpp
===
--- lldb/source/Target/RegisterContextUnwind.cpp
+++ 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 
 #include 
 
 using namespace lldb;
@@ -289,6 +291,13 @@
   } 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 @@
   }
 
   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
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D143232: Return an error when the CFA resolves to no known register, instead of segfaulting

2023-02-06 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

In D143232#4101396 , @bulbazord wrote:

> LGTM. I wonder if there's a good way to exercise this with a test? Like maybe 
> we can create some bogus unwind information and see if LLDB falls over when 
> consuming it?

I'm not sure how we could do that tbh - the currently executing frame uses an 
unwind plan sourced from the assembly instructions, and I can't construct 
assembly language that lldb would parse as using an invalid register number to 
calculate the canonical frame address.  (I genuinely have no idea how we're 
hitting this codepath; it should not be possible.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143232/new/

https://reviews.llvm.org/D143232

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D143232: Return an error when the CFA resolves to no known register, instead of segfaulting

2023-02-02 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

LGTM. I wonder if there's a good way to exercise this with a test? Like maybe 
we can create some bogus unwind information and see if LLDB falls over when 
consuming it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143232/new/

https://reviews.llvm.org/D143232

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D143232: Return an error when the CFA resolves to no known register, instead of segfaulting

2023-02-02 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added a reviewer: bulbazord.
jasonmolenda added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

I'm working on a bug report where lldb crashes while trying to read the 
register that is used to calculate the canonical frame address for the first 
frame in a stack trace.  I haven't figured out how they're getting in this 
state yet, but I want to add a check for a failure to find a register in this 
case, and declare the stack frame as invalid to handle the error.  I also added 
an assert so we can catch it early in debug builds if it ever comes up here.

I think returning no valid stack frame for this thread is going to be a better 
failure mode than having the debugger crash out from under them, ending the 
debug session.  It's still a pretty bad failure, but hopefully we can collect 
some logging with this if it comes up again.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143232

Files:
  lldb/source/Target/RegisterContextUnwind.cpp


Index: lldb/source/Target/RegisterContextUnwind.cpp
===
--- lldb/source/Target/RegisterContextUnwind.cpp
+++ 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 
 #include 
 
 using namespace lldb;
@@ -289,6 +291,13 @@
   } 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 @@
   }
 
   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


Index: lldb/source/Target/RegisterContextUnwind.cpp
===
--- lldb/source/Target/RegisterContextUnwind.cpp
+++ 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 
 #include 
 
 using namespace lldb;
@@ -289,6 +291,13 @@
   } 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 @@
   }
 
   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
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits