[haiku-commits] haiku: hrev44938 - src/apps/debugger/arch/x86

  • From: anevilyak@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 1 Dec 2012 16:07:08 +0100 (CET)

hrev44938 adds 1 changeset to branch 'master'
old head: e66ebcee2798dd25bcc79dd0919d68f255c17060
new head: 1e11702f96520c27ab31e7206922e000e47e8d15
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=1e11702+%5Ee66ebce

----------------------------------------------------------------------------

1e11702: Fix #9247.
  
  - If a program crashed due to an invalid function pointer, the stack
    was being incorrectly unwound such that the top frame would actually
    be skipped, preventing one from seeing the actual line of code that
    invoked said pointer. On x86, we now check if the IP of the top frame
    of the stack lies at a readable location in order to catch this case.

                                      [ Rene Gollent <anevilyak@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev44938
Commit:      1e11702f96520c27ab31e7206922e000e47e8d15
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1e11702
Author:      Rene Gollent <anevilyak@xxxxxxxxx>
Date:        Sat Dec  1 15:04:23 2012 UTC

Ticket:      https://dev.haiku-os.org/ticket/9247

----------------------------------------------------------------------------

1 file changed, 27 insertions(+), 15 deletions(-)
src/apps/debugger/arch/x86/ArchitectureX86.cpp | 42 ++++++++++++++--------

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.cpp 
b/src/apps/debugger/arch/x86/ArchitectureX86.cpp
index bc2e075..5892f2d 100644
--- a/src/apps/debugger/arch/x86/ArchitectureX86.cpp
+++ b/src/apps/debugger/arch/x86/ArchitectureX86.cpp
@@ -309,25 +309,37 @@ ArchitectureX86::CreateStackFrame(Image* image, 
FunctionDebugInfo* function,
                // If the function is not frameless and we're at the top frame 
we need
                // to check whether the prologue has not been executed 
(completely) or
                // we're already after the epilogue.
-               if (hasPrologue && isTopFrame) {
+               if (isTopFrame) {
                        uint32 stack = 0;
-                       if (eip < function->Address() + 3) {
-                               // The prologue has not been executed yet, i.e. 
there's no
-                               // stack frame yet. Get the return address from 
the stack.
-                               stack = 
cpuState->IntRegisterValue(X86_REGISTER_ESP);
-                               if (eip > function->Address()) {
-                                       // The "push %ebp" has already been 
executed.
-                                       stack += 4;
+                       if (hasPrologue) {
+                               if (eip < function->Address() + 3) {
+                                       // The prologue has not been executed 
yet, i.e. there's no
+                                       // stack frame yet. Get the return 
address from the stack.
+                                       stack = 
cpuState->IntRegisterValue(X86_REGISTER_ESP);
+                                       if (eip > function->Address()) {
+                                               // The "push %ebp" has already 
been executed.
+                                               stack += 4;
+                                       }
+                               } else {
+                                       // Not in the function prologue, but 
maybe after the
+                                       // epilogue. The epilogue is a single 
"pop %ebp", so we
+                                       // check whether the current 
instruction is already a
+                                       // "ret".
+                                       uint8 code[1];
+                                       if (fTeamMemory->ReadMemory(eip, &code, 
1) == 1
+                                               && code[0] == 0xc3) {
+                                               stack = 
cpuState->IntRegisterValue(X86_REGISTER_ESP);
+                                       }
                                }
                        } else {
-                               // Not in the function prologue, but maybe 
after the epilogue.
-                               // The epilogue is a single "pop %ebp", so we 
check whether the
-                               // current instruction is already a "ret".
-                               uint8 code[1];
-                               if (fTeamMemory->ReadMemory(eip, &code, 1) == 1
-                                       && code[0] == 0xc3) {
+                               // Check if the instruction pointer is at a 
readable location.
+                               // If it isn't, then chances are we got here 
via a bogus
+                               // function pointer, and the prologue hasn't 
actually been
+                               // executed. In such a case, what we need is 
right at the top
+                               // of the stack.
+                               uint8 data[1];
+                               if (fTeamMemory->ReadMemory(eip, &data, 1) != 1)
                                        stack = 
cpuState->IntRegisterValue(X86_REGISTER_ESP);
-                               }
                        }
 
                        if (stack != 0) {


Other related posts:

  • » [haiku-commits] haiku: hrev44938 - src/apps/debugger/arch/x86 - anevilyak