2004-04-05 22:21:27 +00:00
|
|
|
/*
|
|
|
|
* Stack walking
|
|
|
|
*
|
|
|
|
* Copyright 1995 Alexandre Julliard
|
|
|
|
* Copyright 1996 Eric Youngdale
|
2008-10-18 17:23:08 +00:00
|
|
|
* Copyright 1999 Ove Kåven
|
2004-04-05 22:21:27 +00:00
|
|
|
* Copyright 2004 Eric Pouech
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-04-05 22:21:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2005-11-28 16:32:54 +00:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2004-04-05 22:21:27 +00:00
|
|
|
#include "dbghelp_private.h"
|
|
|
|
#include "winternl.h"
|
2005-05-16 14:20:16 +00:00
|
|
|
#include "wine/winbase16.h"
|
2004-04-05 22:21:27 +00:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
|
|
|
|
|
|
|
|
enum st_mode {stm_start, stm_32bit, stm_16bit, stm_done};
|
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
static DWORD64 WINAPI addr_to_linear(HANDLE hProcess, HANDLE hThread, ADDRESS64* addr)
|
2009-12-10 14:29:20 +00:00
|
|
|
{
|
|
|
|
LDT_ENTRY le;
|
|
|
|
|
|
|
|
switch (addr->Mode)
|
|
|
|
{
|
|
|
|
case AddrMode1616:
|
|
|
|
if (GetThreadSelectorEntry(hThread, addr->Segment, &le))
|
|
|
|
return (le.HighWord.Bits.BaseHi << 24) +
|
|
|
|
(le.HighWord.Bits.BaseMid << 16) + le.BaseLow + LOWORD(addr->Offset);
|
|
|
|
break;
|
|
|
|
case AddrMode1632:
|
|
|
|
if (GetThreadSelectorEntry(hThread, addr->Segment, &le))
|
|
|
|
return (le.HighWord.Bits.BaseHi << 24) +
|
|
|
|
(le.HighWord.Bits.BaseMid << 16) + le.BaseLow + addr->Offset;
|
|
|
|
break;
|
|
|
|
case AddrModeReal:
|
|
|
|
return (DWORD)(LOWORD(addr->Segment) << 4) + addr->Offset;
|
|
|
|
case AddrModeFlat:
|
|
|
|
return addr->Offset;
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported (yet) mode (%x)\n", addr->Mode);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-12-22 13:20:49 +00:00
|
|
|
FIXME("Failed to linearize address %04x:%s (mode %x)\n",
|
|
|
|
addr->Segment, wine_dbgstr_longlong(addr->Offset), addr->Mode);
|
2009-12-10 14:29:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-23 11:43:44 +00:00
|
|
|
static BOOL CALLBACK read_mem(HANDLE hProcess, DWORD addr, void* buffer,
|
|
|
|
DWORD size, LPDWORD nread)
|
|
|
|
{
|
2006-11-29 21:04:27 +00:00
|
|
|
SIZE_T r;
|
|
|
|
if (!ReadProcessMemory(hProcess, (void*)addr, buffer, size, &r)) return FALSE;
|
2007-02-15 16:24:39 +00:00
|
|
|
if (nread) *nread = r;
|
2006-11-29 21:04:27 +00:00
|
|
|
return TRUE;
|
2005-05-23 11:43:44 +00:00
|
|
|
}
|
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
static BOOL CALLBACK read_mem64(HANDLE hProcess, DWORD64 addr, void* buffer,
|
|
|
|
DWORD size, LPDWORD nread)
|
|
|
|
{
|
2006-11-29 21:04:27 +00:00
|
|
|
SIZE_T r;
|
|
|
|
if (!ReadProcessMemory(hProcess, (void*)(DWORD_PTR)addr, buffer, size, &r)) return FALSE;
|
2007-02-15 16:24:39 +00:00
|
|
|
if (nread) *nread = r;
|
2006-11-29 21:04:27 +00:00
|
|
|
return TRUE;
|
2005-12-05 11:50:10 +00:00
|
|
|
}
|
|
|
|
|
2004-04-05 22:21:27 +00:00
|
|
|
/* indexes in Reserved array */
|
|
|
|
#define __CurrentMode 0
|
|
|
|
#define __CurrentSwitch 1
|
|
|
|
#define __NextSwitch 2
|
|
|
|
|
|
|
|
#define curr_mode (frame->Reserved[__CurrentMode])
|
|
|
|
#define curr_switch (frame->Reserved[__CurrentSwitch])
|
|
|
|
#define next_switch (frame->Reserved[__NextSwitch])
|
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
struct stack_walk_callback
|
|
|
|
{
|
|
|
|
HANDLE hProcess;
|
|
|
|
HANDLE hThread;
|
|
|
|
BOOL is32;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
PREAD_PROCESS_MEMORY_ROUTINE f_read_mem;
|
|
|
|
PTRANSLATE_ADDRESS_ROUTINE f_xlat_adr;
|
2006-01-05 12:41:25 +00:00
|
|
|
PFUNCTION_TABLE_ACCESS_ROUTINE f_tabl_acs;
|
|
|
|
PGET_MODULE_BASE_ROUTINE f_modl_bas;
|
2005-12-05 11:50:10 +00:00
|
|
|
} s32;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
PREAD_PROCESS_MEMORY_ROUTINE64 f_read_mem;
|
|
|
|
PTRANSLATE_ADDRESS_ROUTINE64 f_xlat_adr;
|
2006-01-05 12:41:25 +00:00
|
|
|
PFUNCTION_TABLE_ACCESS_ROUTINE64 f_tabl_acs;
|
|
|
|
PGET_MODULE_BASE_ROUTINE64 f_modl_bas;
|
2005-12-05 11:50:10 +00:00
|
|
|
} s64;
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void addr_32to64(const ADDRESS* addr32, ADDRESS64* addr64)
|
|
|
|
{
|
|
|
|
addr64->Offset = (ULONG64)addr32->Offset;
|
|
|
|
addr64->Segment = addr32->Segment;
|
|
|
|
addr64->Mode = addr32->Mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void addr_64to32(const ADDRESS64* addr64, ADDRESS* addr32)
|
|
|
|
{
|
|
|
|
addr32->Offset = (ULONG)addr64->Offset;
|
|
|
|
addr32->Segment = addr64->Segment;
|
|
|
|
addr32->Mode = addr64->Mode;
|
|
|
|
}
|
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
static inline BOOL sw_read_mem(struct stack_walk_callback* cb, DWORD64 addr, void* ptr, DWORD sz)
|
2005-12-05 11:50:10 +00:00
|
|
|
{
|
|
|
|
if (cb->is32)
|
|
|
|
return cb->u.s32.f_read_mem(cb->hProcess, addr, ptr, sz, NULL);
|
|
|
|
else
|
|
|
|
return cb->u.s64.f_read_mem(cb->hProcess, addr, ptr, sz, NULL);
|
|
|
|
}
|
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
static inline DWORD64 sw_xlat_addr(struct stack_walk_callback* cb, ADDRESS64* addr)
|
2005-12-05 11:50:10 +00:00
|
|
|
{
|
2006-01-05 12:41:25 +00:00
|
|
|
if (addr->Mode == AddrModeFlat) return addr->Offset;
|
2009-12-22 13:20:49 +00:00
|
|
|
if (cb->is32)
|
2005-12-05 11:50:10 +00:00
|
|
|
{
|
2009-12-22 13:20:49 +00:00
|
|
|
ADDRESS addr32;
|
2005-12-05 11:50:10 +00:00
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
addr_64to32(addr, &addr32);
|
|
|
|
return cb->u.s32.f_xlat_adr(cb->hProcess, cb->hThread, &addr32);
|
2005-12-05 11:50:10 +00:00
|
|
|
}
|
2009-12-22 13:20:49 +00:00
|
|
|
else if (cb->u.s64.f_xlat_adr)
|
|
|
|
return cb->u.s64.f_xlat_adr(cb->hProcess, cb->hThread, addr);
|
2006-01-05 12:41:25 +00:00
|
|
|
return addr_to_linear(cb->hProcess, cb->hThread, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void* sw_tabl_acs(struct stack_walk_callback* cb, DWORD addr)
|
|
|
|
{
|
|
|
|
if (cb->is32)
|
|
|
|
return cb->u.s32.f_tabl_acs(cb->hProcess, addr);
|
2005-12-05 11:50:10 +00:00
|
|
|
else
|
2006-01-05 12:41:25 +00:00
|
|
|
return cb->u.s64.f_tabl_acs(cb->hProcess, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD sw_modl_bas(struct stack_walk_callback* cb, DWORD addr)
|
|
|
|
{
|
|
|
|
if (cb->is32)
|
|
|
|
return cb->u.s32.f_modl_bas(cb->hProcess, addr);
|
|
|
|
else
|
|
|
|
return cb->u.s64.f_modl_bas(cb->hProcess, addr);
|
2005-12-05 11:50:10 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
static BOOL stack_walk(struct stack_walk_callback* cb, LPSTACKFRAME64 frame)
|
2004-04-05 22:21:27 +00:00
|
|
|
{
|
|
|
|
STACK32FRAME frame32;
|
|
|
|
STACK16FRAME frame16;
|
|
|
|
char ch;
|
2009-12-22 13:20:49 +00:00
|
|
|
ADDRESS64 tmp;
|
2004-04-05 22:21:27 +00:00
|
|
|
DWORD p;
|
|
|
|
WORD val;
|
|
|
|
BOOL do_switch;
|
2009-12-22 13:20:49 +00:00
|
|
|
unsigned int i;
|
2004-04-05 22:21:27 +00:00
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (curr_mode >= stm_done) return FALSE;
|
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s cSwitch=%p nSwitch=%p\n",
|
2006-11-29 21:04:27 +00:00
|
|
|
wine_dbgstr_addr(&frame->AddrPC),
|
2004-04-05 22:21:27 +00:00
|
|
|
wine_dbgstr_addr(&frame->AddrFrame),
|
|
|
|
wine_dbgstr_addr(&frame->AddrReturn),
|
2009-12-22 13:20:49 +00:00
|
|
|
wine_dbgstr_addr(&frame->AddrStack),
|
2004-04-05 22:21:27 +00:00
|
|
|
curr_mode == stm_start ? "start" : (curr_mode == stm_16bit ? "16bit" : "32bit"),
|
2009-12-22 13:20:49 +00:00
|
|
|
(void*)(DWORD_PTR)curr_switch, (void*)(DWORD_PTR)next_switch);
|
2004-04-05 22:21:27 +00:00
|
|
|
|
|
|
|
if (curr_mode == stm_start)
|
|
|
|
{
|
|
|
|
THREAD_BASIC_INFORMATION info;
|
|
|
|
|
2004-09-23 04:27:46 +00:00
|
|
|
if ((frame->AddrPC.Mode == AddrModeFlat) &&
|
|
|
|
(frame->AddrFrame.Mode != AddrModeFlat))
|
|
|
|
{
|
|
|
|
WARN("Bad AddrPC.Mode / AddrFrame.Mode combination\n");
|
|
|
|
goto done_err;
|
|
|
|
}
|
|
|
|
|
2004-04-05 22:21:27 +00:00
|
|
|
/* Init done */
|
|
|
|
curr_mode = (frame->AddrPC.Mode == AddrModeFlat) ?
|
|
|
|
stm_32bit : stm_16bit;
|
|
|
|
|
2005-05-23 11:43:44 +00:00
|
|
|
/* cur_switch holds address of WOW32Reserved field in TEB in debuggee
|
2004-04-05 22:21:27 +00:00
|
|
|
* address space
|
|
|
|
*/
|
2005-12-05 11:50:10 +00:00
|
|
|
if (NtQueryInformationThread(cb->hThread, ThreadBasicInformation, &info,
|
2005-05-23 11:43:44 +00:00
|
|
|
sizeof(info), NULL) == STATUS_SUCCESS)
|
2004-04-05 22:21:27 +00:00
|
|
|
{
|
2005-05-23 11:43:44 +00:00
|
|
|
curr_switch = (unsigned long)info.TebBaseAddress + FIELD_OFFSET(TEB, WOW32Reserved);
|
2009-12-22 13:20:49 +00:00
|
|
|
if (!sw_read_mem(cb, curr_switch, &p, sizeof(p)))
|
2004-04-05 22:21:27 +00:00
|
|
|
{
|
2005-05-23 11:43:44 +00:00
|
|
|
WARN("Can't read TEB:WOW32Reserved\n");
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
|
|
|
}
|
2009-12-22 13:20:49 +00:00
|
|
|
next_switch = p;
|
2005-05-23 11:43:44 +00:00
|
|
|
if (curr_mode == stm_16bit)
|
2004-04-05 22:21:27 +00:00
|
|
|
{
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, next_switch, &frame32, sizeof(frame32)))
|
2005-05-23 11:43:44 +00:00
|
|
|
{
|
2009-12-22 13:20:49 +00:00
|
|
|
WARN("Bad stack frame %p\n", (void*)(DWORD_PTR)next_switch);
|
2005-05-23 11:43:44 +00:00
|
|
|
goto done_err;
|
|
|
|
}
|
|
|
|
curr_switch = (DWORD)frame32.frame16;
|
|
|
|
tmp.Mode = AddrMode1616;
|
|
|
|
tmp.Segment = SELECTOROF(curr_switch);
|
|
|
|
tmp.Offset = OFFSETOF(curr_switch);
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, sw_xlat_addr(cb, &tmp), &ch, sizeof(ch)))
|
2005-05-23 11:43:44 +00:00
|
|
|
curr_switch = 0xFFFFFFFF;
|
2004-04-05 22:21:27 +00:00
|
|
|
}
|
2005-05-23 11:43:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp.Mode = AddrMode1616;
|
|
|
|
tmp.Segment = SELECTOROF(next_switch);
|
|
|
|
tmp.Offset = OFFSETOF(next_switch);
|
2005-12-05 11:50:10 +00:00
|
|
|
p = sw_xlat_addr(cb, &tmp);
|
|
|
|
if (!sw_read_mem(cb, p, &frame16, sizeof(frame16)))
|
2005-05-23 11:43:44 +00:00
|
|
|
{
|
2006-11-29 21:04:27 +00:00
|
|
|
WARN("Bad stack frame 0x%08x\n", p);
|
2005-05-23 11:43:44 +00:00
|
|
|
goto done_err;
|
|
|
|
}
|
2009-12-12 11:18:28 +00:00
|
|
|
curr_switch = (DWORD_PTR)frame16.frame32;
|
2004-04-05 22:21:27 +00:00
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, curr_switch, &ch, sizeof(ch)))
|
2005-05-23 11:43:44 +00:00
|
|
|
curr_switch = 0xFFFFFFFF;
|
|
|
|
}
|
2004-04-05 22:21:27 +00:00
|
|
|
}
|
2005-05-23 11:43:44 +00:00
|
|
|
else
|
|
|
|
/* FIXME: this will allow to work when we're not attached to a live target,
|
|
|
|
* but the 16 <=> 32 switch facility won't be available.
|
|
|
|
*/
|
|
|
|
curr_switch = 0;
|
|
|
|
frame->AddrReturn.Mode = frame->AddrStack.Mode = (curr_mode == stm_16bit) ? AddrMode1616 : AddrModeFlat;
|
2004-04-30 04:15:41 +00:00
|
|
|
/* don't set up AddrStack on first call. Either the caller has set it up, or
|
|
|
|
* we will get it in the next frame
|
|
|
|
*/
|
2006-01-05 12:41:25 +00:00
|
|
|
memset(&frame->AddrBStore, 0, sizeof(frame->AddrBStore));
|
2004-04-05 22:21:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (frame->AddrFrame.Offset == 0) goto done_err;
|
|
|
|
if (frame->AddrFrame.Mode == AddrModeFlat)
|
|
|
|
{
|
|
|
|
assert(curr_mode == stm_32bit);
|
|
|
|
do_switch = curr_switch && frame->AddrFrame.Offset >= curr_switch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert(curr_mode == stm_16bit);
|
2005-05-23 11:43:44 +00:00
|
|
|
do_switch = curr_switch &&
|
2004-04-05 22:21:27 +00:00
|
|
|
frame->AddrFrame.Segment == SELECTOROF(curr_switch) &&
|
|
|
|
frame->AddrFrame.Offset >= OFFSETOF(curr_switch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_switch)
|
|
|
|
{
|
|
|
|
if (curr_mode == stm_16bit)
|
|
|
|
{
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, next_switch, &frame32, sizeof(frame32)))
|
2004-04-05 22:21:27 +00:00
|
|
|
{
|
2009-12-22 13:20:49 +00:00
|
|
|
WARN("Bad stack frame %p\n", (void*)(DWORD_PTR)next_switch);
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->AddrPC.Mode = AddrModeFlat;
|
|
|
|
frame->AddrPC.Segment = 0;
|
|
|
|
frame->AddrPC.Offset = frame32.retaddr;
|
|
|
|
frame->AddrFrame.Mode = AddrModeFlat;
|
|
|
|
frame->AddrFrame.Segment = 0;
|
|
|
|
frame->AddrFrame.Offset = frame32.ebp;
|
|
|
|
|
|
|
|
frame->AddrStack.Mode = AddrModeFlat;
|
|
|
|
frame->AddrStack.Segment = 0;
|
|
|
|
frame->AddrReturn.Mode = AddrModeFlat;
|
|
|
|
frame->AddrReturn.Segment = 0;
|
|
|
|
|
|
|
|
next_switch = curr_switch;
|
|
|
|
tmp.Mode = AddrMode1616;
|
|
|
|
tmp.Segment = SELECTOROF(next_switch);
|
|
|
|
tmp.Offset = OFFSETOF(next_switch);
|
2005-12-05 11:50:10 +00:00
|
|
|
p = sw_xlat_addr(cb, &tmp);
|
2004-04-05 22:21:27 +00:00
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, p, &frame16, sizeof(frame16)))
|
2004-04-05 22:21:27 +00:00
|
|
|
{
|
2006-11-29 21:04:27 +00:00
|
|
|
WARN("Bad stack frame 0x%08x\n", p);
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
|
|
|
}
|
2009-12-12 11:18:28 +00:00
|
|
|
curr_switch = (DWORD_PTR)frame16.frame32;
|
2004-04-05 22:21:27 +00:00
|
|
|
curr_mode = stm_32bit;
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, curr_switch, &ch, sizeof(ch)))
|
2005-05-23 11:43:44 +00:00
|
|
|
curr_switch = 0;
|
2004-04-05 22:21:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp.Mode = AddrMode1616;
|
|
|
|
tmp.Segment = SELECTOROF(next_switch);
|
|
|
|
tmp.Offset = OFFSETOF(next_switch);
|
2005-12-05 11:50:10 +00:00
|
|
|
p = sw_xlat_addr(cb, &tmp);
|
2004-04-05 22:21:27 +00:00
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, p, &frame16, sizeof(frame16)))
|
2004-04-05 22:21:27 +00:00
|
|
|
{
|
2006-11-29 21:04:27 +00:00
|
|
|
WARN("Bad stack frame 0x%08x\n", p);
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Got a 16 bit stack switch:"
|
|
|
|
"\n\tframe32: %08lx"
|
2006-11-29 21:04:27 +00:00
|
|
|
"\n\tedx:%08x ecx:%08x ebp:%08x"
|
2004-04-05 22:21:27 +00:00
|
|
|
"\n\tds:%04x es:%04x fs:%04x gs:%04x"
|
2006-11-29 21:04:27 +00:00
|
|
|
"\n\tcall_from_ip:%08x module_cs:%04x relay=%08x"
|
|
|
|
"\n\tentry_ip:%04x entry_point:%08x"
|
2004-04-05 22:21:27 +00:00
|
|
|
"\n\tbp:%04x ip:%04x cs:%04x\n",
|
|
|
|
(unsigned long)frame16.frame32,
|
|
|
|
frame16.edx, frame16.ecx, frame16.ebp,
|
|
|
|
frame16.ds, frame16.es, frame16.fs, frame16.gs,
|
|
|
|
frame16.callfrom_ip, frame16.module_cs, frame16.relay,
|
|
|
|
frame16.entry_ip, frame16.entry_point,
|
|
|
|
frame16.bp, frame16.ip, frame16.cs);
|
|
|
|
|
|
|
|
|
|
|
|
frame->AddrPC.Mode = AddrMode1616;
|
|
|
|
frame->AddrPC.Segment = frame16.cs;
|
|
|
|
frame->AddrPC.Offset = frame16.ip;
|
|
|
|
|
|
|
|
frame->AddrFrame.Mode = AddrMode1616;
|
|
|
|
frame->AddrFrame.Segment = SELECTOROF(next_switch);
|
|
|
|
frame->AddrFrame.Offset = frame16.bp;
|
|
|
|
|
|
|
|
frame->AddrStack.Mode = AddrMode1616;
|
|
|
|
frame->AddrStack.Segment = SELECTOROF(next_switch);
|
|
|
|
|
|
|
|
frame->AddrReturn.Mode = AddrMode1616;
|
|
|
|
frame->AddrReturn.Segment = frame16.cs;
|
|
|
|
|
|
|
|
next_switch = curr_switch;
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, next_switch, &frame32, sizeof(frame32)))
|
2004-04-05 22:21:27 +00:00
|
|
|
{
|
2009-12-22 13:20:49 +00:00
|
|
|
WARN("Bad stack frame %p\n", (void*)(DWORD_PTR)next_switch);
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
|
|
|
}
|
|
|
|
curr_switch = (DWORD)frame32.frame16;
|
|
|
|
tmp.Mode = AddrMode1616;
|
|
|
|
tmp.Segment = SELECTOROF(curr_switch);
|
|
|
|
tmp.Offset = OFFSETOF(curr_switch);
|
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, sw_xlat_addr(cb, &tmp), &ch, sizeof(ch)))
|
2005-05-23 11:43:44 +00:00
|
|
|
curr_switch = 0;
|
2004-04-05 22:21:27 +00:00
|
|
|
curr_mode = stm_16bit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame->AddrPC = frame->AddrReturn;
|
|
|
|
if (curr_mode == stm_16bit)
|
|
|
|
{
|
|
|
|
frame->AddrStack.Offset = frame->AddrFrame.Offset + 2 * sizeof(WORD);
|
|
|
|
/* "pop up" previous BP value */
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, sw_xlat_addr(cb, &frame->AddrFrame),
|
|
|
|
&val, sizeof(WORD)))
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
|
|
|
frame->AddrFrame.Offset = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame->AddrStack.Offset = frame->AddrFrame.Offset + 2 * sizeof(DWORD);
|
|
|
|
/* "pop up" previous EBP value */
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, frame->AddrFrame.Offset,
|
|
|
|
&frame->AddrFrame.Offset, sizeof(DWORD)))
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curr_mode == stm_16bit)
|
|
|
|
{
|
2005-12-05 11:50:10 +00:00
|
|
|
p = sw_xlat_addr(cb, &frame->AddrFrame);
|
|
|
|
if (!sw_read_mem(cb, p + sizeof(WORD), &val, sizeof(WORD)))
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
|
|
|
frame->AddrReturn.Offset = val;
|
|
|
|
/* get potential cs if a far call was used */
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, p + 2 * sizeof(WORD), &val, sizeof(WORD)))
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
|
|
|
if (frame->AddrFrame.Offset & 1)
|
|
|
|
frame->AddrReturn.Segment = val; /* far call assumed */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* not explicitly marked as far call,
|
|
|
|
* but check whether it could be anyway
|
|
|
|
*/
|
|
|
|
if ((val & 7) == 7 && val != frame->AddrReturn.Segment)
|
|
|
|
{
|
|
|
|
LDT_ENTRY le;
|
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
if (GetThreadSelectorEntry(cb->hThread, val, &le) &&
|
2004-04-05 22:21:27 +00:00
|
|
|
(le.HighWord.Bits.Type & 0x08)) /* code segment */
|
|
|
|
{
|
|
|
|
/* it is very uncommon to push a code segment cs as
|
|
|
|
* a parameter, so this should work in most cases
|
|
|
|
*/
|
|
|
|
frame->AddrReturn.Segment = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frame->AddrFrame.Offset &= ~1;
|
2004-04-20 04:03:42 +00:00
|
|
|
/* we "pop" parameters as 16 bit entities... of course, this won't
|
2004-04-05 22:21:27 +00:00
|
|
|
* work if the parameter is in fact bigger than 16bit, but
|
|
|
|
* there's no way to know that here
|
|
|
|
*/
|
|
|
|
for (i = 0; i < sizeof(frame->Params) / sizeof(frame->Params[0]); i++)
|
|
|
|
{
|
2005-12-05 11:50:10 +00:00
|
|
|
sw_read_mem(cb, p + (2 + i) * sizeof(WORD), &val, sizeof(val));
|
2004-04-05 22:21:27 +00:00
|
|
|
frame->Params[i] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-05 11:50:10 +00:00
|
|
|
if (!sw_read_mem(cb, frame->AddrFrame.Offset + sizeof(DWORD),
|
|
|
|
&frame->AddrReturn.Offset, sizeof(DWORD)))
|
2005-05-23 11:43:44 +00:00
|
|
|
{
|
2009-12-22 13:20:49 +00:00
|
|
|
WARN("Cannot read new frame offset %p\n",
|
|
|
|
(void*)(DWORD_PTR)(frame->AddrFrame.Offset + (int)sizeof(DWORD)));
|
2004-04-05 22:21:27 +00:00
|
|
|
goto done_err;
|
2005-05-23 11:43:44 +00:00
|
|
|
}
|
2009-12-22 13:20:49 +00:00
|
|
|
for (i = 0; i < sizeof(frame->Params) / sizeof(frame->Params[0]); i++)
|
|
|
|
{
|
|
|
|
sw_read_mem(cb, frame->AddrFrame.Offset + 2 * sizeof(DWORD), &p, sizeof(p));
|
|
|
|
frame->Params[i] = p;
|
|
|
|
}
|
2004-04-05 22:21:27 +00:00
|
|
|
}
|
|
|
|
|
2006-01-05 12:41:25 +00:00
|
|
|
frame->Far = TRUE;
|
|
|
|
frame->Virtual = TRUE;
|
|
|
|
p = sw_xlat_addr(cb, &frame->AddrPC);
|
|
|
|
if (p && sw_modl_bas(cb, p))
|
|
|
|
frame->FuncTableEntry = sw_tabl_acs(cb, p);
|
|
|
|
else
|
|
|
|
frame->FuncTableEntry = NULL;
|
2004-04-05 22:21:27 +00:00
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s cSwitch=%p nSwitch=%p FuncTable=%p\n",
|
2006-11-29 21:04:27 +00:00
|
|
|
wine_dbgstr_addr(&frame->AddrPC),
|
2004-04-05 22:21:27 +00:00
|
|
|
wine_dbgstr_addr(&frame->AddrFrame),
|
|
|
|
wine_dbgstr_addr(&frame->AddrReturn),
|
|
|
|
wine_dbgstr_addr(&frame->AddrStack),
|
|
|
|
curr_mode == stm_start ? "start" : (curr_mode == stm_16bit ? "16bit" : "32bit"),
|
2009-12-22 13:20:49 +00:00
|
|
|
(void*)(DWORD_PTR)curr_switch, (void*)(DWORD_PTR)next_switch, frame->FuncTableEntry);
|
2004-04-05 22:21:27 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
done_err:
|
|
|
|
curr_mode = stm_done;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-11-28 09:40:02 +00:00
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* StackWalk (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI StackWalk(DWORD MachineType, HANDLE hProcess, HANDLE hThread,
|
2009-12-22 13:20:49 +00:00
|
|
|
LPSTACKFRAME frame32, PVOID ctx,
|
2005-12-05 11:50:10 +00:00
|
|
|
PREAD_PROCESS_MEMORY_ROUTINE f_read_mem,
|
|
|
|
PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
|
|
|
|
PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
|
|
|
|
PTRANSLATE_ADDRESS_ROUTINE f_xlat_adr)
|
|
|
|
{
|
|
|
|
struct stack_walk_callback swcb;
|
2009-12-22 13:20:49 +00:00
|
|
|
STACKFRAME64 frame64;
|
|
|
|
BOOL ret;
|
2005-12-05 11:50:10 +00:00
|
|
|
|
2006-11-29 21:04:27 +00:00
|
|
|
TRACE("(%d, %p, %p, %p, %p, %p, %p, %p, %p)\n",
|
2009-12-22 13:20:49 +00:00
|
|
|
MachineType, hProcess, hThread, frame32, ctx,
|
2005-12-05 11:50:10 +00:00
|
|
|
f_read_mem, FunctionTableAccessRoutine,
|
|
|
|
GetModuleBaseRoutine, f_xlat_adr);
|
|
|
|
|
|
|
|
if (MachineType != IMAGE_FILE_MACHINE_I386)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
addr_32to64(&frame32->AddrPC, &frame64.AddrPC);
|
|
|
|
addr_32to64(&frame32->AddrReturn, &frame64.AddrReturn);
|
|
|
|
addr_32to64(&frame32->AddrFrame, &frame64.AddrFrame);
|
|
|
|
addr_32to64(&frame32->AddrStack, &frame64.AddrStack);
|
|
|
|
addr_32to64(&frame32->AddrBStore, &frame64.AddrBStore);
|
|
|
|
frame64.FuncTableEntry = frame32->FuncTableEntry; /* FIXME */
|
|
|
|
frame64.Far = frame32->Far;
|
|
|
|
frame64.Virtual = frame32->Virtual;
|
|
|
|
frame64.Reserved[0] = frame32->Reserved[0];
|
|
|
|
frame64.Reserved[1] = frame32->Reserved[1];
|
|
|
|
frame64.Reserved[2] = frame32->Reserved[2];
|
|
|
|
/* we don't handle KdHelp */
|
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
swcb.hProcess = hProcess;
|
|
|
|
swcb.hThread = hThread;
|
|
|
|
swcb.is32 = TRUE;
|
|
|
|
/* sigh... MS isn't even consistent in the func prototypes */
|
|
|
|
swcb.u.s32.f_read_mem = (f_read_mem) ? f_read_mem : read_mem;
|
2009-12-22 13:20:49 +00:00
|
|
|
swcb.u.s32.f_xlat_adr = f_xlat_adr;
|
2006-01-05 12:41:25 +00:00
|
|
|
swcb.u.s32.f_tabl_acs = (FunctionTableAccessRoutine) ? FunctionTableAccessRoutine : SymFunctionTableAccess;
|
|
|
|
swcb.u.s32.f_modl_bas = (GetModuleBaseRoutine) ? GetModuleBaseRoutine : SymGetModuleBase;
|
2005-12-05 11:50:10 +00:00
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
ret = stack_walk(&swcb, &frame64);
|
|
|
|
|
|
|
|
addr_64to32(&frame64.AddrPC, &frame32->AddrPC);
|
|
|
|
addr_64to32(&frame64.AddrReturn, &frame32->AddrReturn);
|
|
|
|
addr_64to32(&frame64.AddrFrame, &frame32->AddrFrame);
|
|
|
|
addr_64to32(&frame64.AddrStack, &frame32->AddrStack);
|
|
|
|
addr_64to32(&frame64.AddrBStore, &frame32->AddrBStore);
|
|
|
|
frame32->FuncTableEntry = frame64.FuncTableEntry; /* FIXME */
|
|
|
|
frame32->Params[0] = frame64.Params[0];
|
|
|
|
frame32->Params[1] = frame64.Params[1];
|
|
|
|
frame32->Params[2] = frame64.Params[2];
|
|
|
|
frame32->Params[3] = frame64.Params[3];
|
|
|
|
frame32->Far = frame64.Far;
|
|
|
|
frame32->Virtual = frame64.Virtual;
|
|
|
|
frame32->Reserved[0] = frame64.Reserved[0];
|
|
|
|
frame32->Reserved[1] = frame64.Reserved[1];
|
|
|
|
frame32->Reserved[2] = frame64.Reserved[2];
|
|
|
|
|
|
|
|
return ret;
|
2005-12-05 11:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-29 10:48:57 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* StackWalk64 (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI StackWalk64(DWORD MachineType, HANDLE hProcess, HANDLE hThread,
|
2009-12-22 13:20:49 +00:00
|
|
|
LPSTACKFRAME64 frame, PVOID ctx,
|
2005-11-29 10:48:57 +00:00
|
|
|
PREAD_PROCESS_MEMORY_ROUTINE64 f_read_mem,
|
|
|
|
PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
|
|
|
|
PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
|
|
|
|
PTRANSLATE_ADDRESS_ROUTINE64 f_xlat_adr)
|
|
|
|
{
|
2005-12-05 11:50:10 +00:00
|
|
|
struct stack_walk_callback swcb;
|
|
|
|
|
2006-11-29 21:04:27 +00:00
|
|
|
TRACE("(%d, %p, %p, %p, %p, %p, %p, %p, %p)\n",
|
2009-12-22 13:20:49 +00:00
|
|
|
MachineType, hProcess, hThread, frame, ctx,
|
2005-11-29 10:48:57 +00:00
|
|
|
f_read_mem, FunctionTableAccessRoutine,
|
|
|
|
GetModuleBaseRoutine, f_xlat_adr);
|
2005-12-05 11:50:10 +00:00
|
|
|
|
|
|
|
if (MachineType != IMAGE_FILE_MACHINE_I386)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
swcb.hProcess = hProcess;
|
|
|
|
swcb.hThread = hThread;
|
|
|
|
swcb.is32 = FALSE;
|
|
|
|
/* sigh... MS isn't even consistent in the func prototypes */
|
|
|
|
swcb.u.s64.f_read_mem = (f_read_mem) ? f_read_mem : read_mem64;
|
2009-12-22 13:20:49 +00:00
|
|
|
swcb.u.s64.f_xlat_adr = (f_xlat_adr) ? f_xlat_adr : addr_to_linear;
|
2006-01-05 12:41:25 +00:00
|
|
|
swcb.u.s64.f_tabl_acs = (FunctionTableAccessRoutine) ? FunctionTableAccessRoutine : SymFunctionTableAccess64;
|
|
|
|
swcb.u.s64.f_modl_bas = (GetModuleBaseRoutine) ? GetModuleBaseRoutine : SymGetModuleBase64;
|
2005-12-05 11:50:10 +00:00
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
if (!stack_walk(&swcb, frame)) return FALSE;
|
|
|
|
|
2005-12-05 11:50:10 +00:00
|
|
|
/* we don't handle KdHelp */
|
2009-12-22 13:20:49 +00:00
|
|
|
frame->KdHelp.Thread = 0xC000FADE;
|
|
|
|
frame->KdHelp.ThCallbackStack = 0x10;
|
|
|
|
frame->KdHelp.ThCallbackBStore = 0;
|
|
|
|
frame->KdHelp.NextCallback = 0;
|
|
|
|
frame->KdHelp.FramePointer = 0;
|
|
|
|
frame->KdHelp.KiCallUserMode = 0xD000DAFE;
|
|
|
|
frame->KdHelp.KeUserCallbackDispatcher = 0xE000F000;
|
|
|
|
frame->KdHelp.SystemRangeStart = 0xC0000000;
|
|
|
|
frame->KdHelp.Reserved[0] /* KiUserExceptionDispatcher */ = 0xE0005000;
|
2005-12-05 11:50:10 +00:00
|
|
|
|
2009-12-22 13:20:49 +00:00
|
|
|
return TRUE;
|
2005-11-29 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2005-11-28 09:40:02 +00:00
|
|
|
/******************************************************************
|
|
|
|
* SymRegisterFunctionEntryCallback (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymRegisterFunctionEntryCallback(HANDLE hProc,
|
|
|
|
PSYMBOL_FUNCENTRY_CALLBACK cb, PVOID user)
|
|
|
|
{
|
|
|
|
FIXME("(%p %p %p): stub!\n", hProc, cb, user);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymRegisterFunctionEntryCallback64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymRegisterFunctionEntryCallback64(HANDLE hProc,
|
|
|
|
PSYMBOL_FUNCENTRY_CALLBACK64 cb,
|
|
|
|
ULONG64 user)
|
|
|
|
{
|
|
|
|
FIXME("(%p %p %s): stub!\n", hProc, cb, wine_dbgstr_longlong(user));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|