cassanova created this revision.
cassanova added reviewers: JDevlieghere, mib.
cassanova added a project: LLDB.
Herald added a project: All.
cassanova requested review of this revision.
Herald added a subscriber: lldb-commits.

Adds a check to ensure that a process exists before attempting to get its ABI 
to prevent lldb from crash due to trying to read from page zero.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127016

Files:
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/test/Shell/Driver/TestPageZeroRead.test


Index: lldb/test/Shell/Driver/TestPageZeroRead.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Driver/TestPageZeroRead.test
@@ -0,0 +1,3 @@
+# Ensure that the read from memory command doesn't try and read from page zero.
+# RUN: %clang_host %p/Inputs/hello.c -g -o a.out
+# RUN: %lldb -b a.out -o 'x 0'
Index: lldb/source/Commands/CommandObjectMemory.cpp
===================================================================
--- lldb/source/Commands/CommandObjectMemory.cpp
+++ lldb/source/Commands/CommandObjectMemory.cpp
@@ -593,7 +593,10 @@
       return false;
     }
 
-    ABISP abi = m_exe_ctx.GetProcessPtr()->GetABI();
+    ABISP abi;
+    if (Process * proc = m_exe_ctx.GetProcessPtr())
+      abi = proc->GetABI();
+
     if (abi)
       addr = abi->FixDataAddress(addr);
 


Index: lldb/test/Shell/Driver/TestPageZeroRead.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Driver/TestPageZeroRead.test
@@ -0,0 +1,3 @@
+# Ensure that the read from memory command doesn't try and read from page zero.
+# RUN: %clang_host %p/Inputs/hello.c -g -o a.out
+# RUN: %lldb -b a.out -o 'x 0'
Index: lldb/source/Commands/CommandObjectMemory.cpp
===================================================================
--- lldb/source/Commands/CommandObjectMemory.cpp
+++ lldb/source/Commands/CommandObjectMemory.cpp
@@ -593,7 +593,10 @@
       return false;
     }
 
-    ABISP abi = m_exe_ctx.GetProcessPtr()->GetABI();
+    ABISP abi;
+    if (Process * proc = m_exe_ctx.GetProcessPtr())
+      abi = proc->GetABI();
+
     if (abi)
       addr = abi->FixDataAddress(addr);
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to