* Fix some warnings in r_debug_native for mingw64

This commit is contained in:
pancake 2011-09-19 21:08:26 +02:00
parent b00ccc9e18
commit 8933c45e0d
5 changed files with 1315 additions and 37 deletions

View File

@ -178,9 +178,9 @@ static int r_debug_native_step(RDebug *dbg) {
int ret = R_FALSE;
int pid = dbg->pid;
#if __WINDOWS__
CONTEXT regs __attribute__ ((aligned (16)));
/* set TRAP flag */
/*
CONTEXT regs __attribute__ ((aligned (16)));
r_debug_native_reg_read (dbg, R_REG_TYPE_GPR, &regs, sizeof (regs));
regs.EFlags |= 0x100;
r_debug_native_reg_write (pid, dbg->tid, R_REG_TYPE_GPR, &regs, sizeof (regs));
@ -319,6 +319,7 @@ static int r_debug_native_wait(RDebug *dbg, int pid) {
// TODO: why strdup here?
static const char *r_debug_native_reg_profile(RDebug *dbg) {
#if __WINDOWS__
if (dbg->bits == 32) {
return strdup (
"=pc eip\n"
"=sp esp\n"
@ -355,6 +356,45 @@ static const char *r_debug_native_reg_profile(RDebug *dbg) {
"seg ss .32 200 0\n"
/* +512 bytes for maximum supoprted extension extended registers */
);
} else {
// XXX. this is wrong
return strdup (
"=pc rip\n"
"=sp rsp\n"
"=bp rbp\n"
"=a0 rax\n"
"=a1 rbx\n"
"=a2 rcx\n"
"=a3 rdi\n"
"drx dr0 .32 4 0\n"
"drx dr1 .32 8 0\n"
"drx dr2 .32 12 0\n"
"drx dr3 .32 16 0\n"
"drx dr6 .32 20 0\n"
"drx dr7 .32 24 0\n"
/* floating save area 4+4+4+4+4+4+4+80+4 = 112 */
"seg gs .32 132 0\n"
"seg fs .32 136 0\n"
"seg es .32 140 0\n"
"seg ds .32 144 0\n"
"gpr rdi .32 156 0\n"
"gpr rsi .32 160 0\n"
"gpr rbx .32 164 0\n"
"gpr rdx .32 168 0\n"
"gpr rcx .32 172 0\n"
"gpr rax .32 176 0\n"
"gpr rbp .32 180 0\n"
"gpr rsp .32 196 0\n"
"gpr rip .32 184 0\n"
"seg cs .32 184 0\n"
"seg ds .32 152 0\n"
"seg gs .32 140 0\n"
"seg fs .32 144 0\n"
"gpr rflags .32 192 0 c1p.a.zstido.n.rv\n" // XXX must be flg
"seg ss .32 200 0\n"
/* +512 bytes for maximum supoprted extension extended registers */
);
}
#elif __linux__ && __MIPS__
return strdup (
"=pc r0\n"
@ -1702,17 +1742,18 @@ static RList *r_debug_native_frames(RDebug *dbg) {
static int r_debug_native_kill(RDebug *dbg, boolt thread, int sig) {
#if __WINDOWS__
// TODO: implement thread support signaling here
HANDLE hProcess; // XXX
eprintf ("TODO: r_debug_native_kill\n");
#if 0
static uint WM_CLOSE = 0x10;
static bool CloseWindow(IntPtr hWnd) {
hWnd = FindWindowByCaption (0, "explorer");
SendMessage(hWnd, WM_CLOSE, NULL, NULL);
CloseWindow(hWnd);
return true;
}
#endif
HANDLE hProcess; // XXX
static uint WM_CLOSE = 0x10;
static bool CloseWindow(IntPtr hWnd) {
hWnd = FindWindowByCaption (0, "explorer");
SendMessage(hWnd, WM_CLOSE, NULL, NULL);
CloseWindow(hWnd);
return true;
}
TerminateProcess (hProcess, 1);
#endif
return R_FALSE;
#else
int ret = R_FALSE;
@ -1809,9 +1850,10 @@ static void addr_to_string(struct sockaddr_storage *ss, char *buffer, int buflen
#endif
static RList *r_debug_desc_native_list (int pid) {
RList *ret;
RList *ret = NULL;
RDebugDesc *desc;
int perm, type;
// TODO: windows
#if __KFBSD__
int mib[4];
size_t len;

View File

@ -90,7 +90,7 @@ return (0);
1897 } CONTEXT;
#endif
BOOL WINAPI DebugActiveProcessStop(DWORD dwProcessId);
//BOOL WINAPI DebugActiveProcessStop(DWORD dwProcessId);
static void (*gmbn)(HANDLE, HMODULE, LPTSTR, int) = NULL;
static int (*gmi)(HANDLE, HMODULE, LPMODULEINFO, int) = NULL;
static BOOL WINAPI (*w32_detach)(DWORD) = NULL;
@ -99,27 +99,37 @@ static HANDLE WINAPI (*w32_dbgbreak)(HANDLE) = NULL;
static DWORD WINAPI (*w32_getthreadid)(HANDLE) = NULL; // Vista
static DWORD WINAPI (*w32_getprocessid)(HANDLE) = NULL; // XP
static void r_str_wtoc(char* d, const WCHAR* s) {
int i = 0;
while (s[i] != '\0') {
d[i] = (char)s[i];
++i;
}
d[i] = 0;
}
static void print_lasterr(const char *str) {
/* code from MSDN, :? */
LPWSTR pMessage = L"%1!*.*s! %4 %5!*s!";
DWORD_PTR pArgs[] = { (DWORD_PTR)4, (DWORD_PTR)2, (DWORD_PTR)L"Bill", // %1!*.*s!
(DWORD_PTR)L"Bob", // %4
(DWORD_PTR)6, (DWORD_PTR)L"Bill" }; // %5!*s!
const DWORD size = 100+1;
WCHAR buffer[size];
WCHAR buffer[200];
char cbuffer[100];
if (!FormatMessage (FORMAT_MESSAGE_FROM_STRING |
FORMAT_MESSAGE_ARGUMENT_ARRAY,
pMessage,
0, // ignored
0, // ignored
(LPTSTR)&buffer,
size-1,
sizeof (buffer)-1,
(va_list*)pArgs)) {
eprintf ("(%s): Format message failed with 0x%x\n",
r_str_get (str), GetLastError());
r_str_get (str), (ut32)GetLastError ());
return;
}
eprintf ("print_lasterr: %s ::: %s\n", r_str_get (str), r_str_get (buffer));
r_str_wtoc (cbuffer, buffer);
eprintf ("print_lasterr: %s ::: %s\n", r_str_get (str), r_str_get (cbuffer));
}
@ -151,14 +161,14 @@ static int w32_dbg_init() {
gmi = (int (*)(HANDLE, HMODULE, LPMODULEINFO, int))
GetProcAddress (lib, "GetModuleInformation");
if(w32_detach == NULL || w32_openthread == NULL || w32_dbgbreak == NULL ||
if (w32_detach == NULL || w32_openthread == NULL || w32_dbgbreak == NULL ||
gmbn == NULL || gmi == NULL) {
// OOPS!
eprintf("debug_init_calls:\n"
"DebugActiveProcessStop: 0x%x\n"
"OpenThread: 0x%x\n"
"DebugBreakProcess: 0x%x\n"
"GetThreadId: 0x%x\n",
eprintf ("debug_init_calls:\n"
"DebugActiveProcessStop: 0x%p\n"
"OpenThread: 0x%p\n"
"DebugBreakProcess: 0x%p\n"
"GetThreadId: 0x%p\n",
w32_detach, w32_openthread, w32_dbgbreak, w32_getthreadid);
return R_FALSE;
}
@ -186,7 +196,7 @@ inline static int w32_h2t(HANDLE h) {
return w32_getthreadid (h);
if (w32_getprocessid != NULL) // >= Windows XP1
return w32_getprocessid (h);
return (int)h; // XXX broken
return (int)(size_t)h; // XXX broken
}
static inline int w32_h2p(HANDLE h) {
@ -283,7 +293,7 @@ static int w32_dbg_wait(RDebug *dbg, int pid) {
/* get kind of event */
switch (code) {
case CREATE_PROCESS_DEBUG_EVENT:
eprintf ("(%d) created process (%d:0x%x)\n",
eprintf ("(%d) created process (%d:%p)\n",
pid, w32_h2t (de.u.CreateProcessInfo.
hProcess),
de.u.CreateProcessInfo.lpStartAddress);
@ -298,20 +308,19 @@ static int w32_dbg_wait(RDebug *dbg, int pid) {
ret = R_DBG_REASON_EXIT_PID;
break;
case CREATE_THREAD_DEBUG_EVENT:
eprintf ("(%d) created thread (0x%x)\n",
pid, de.u.CreateThread.lpStartAddress);
eprintf ("(%d) created thread (%p)\n", pid, de.u.CreateThread.lpStartAddress);
r_debug_native_continue (dbg, pid, tid, -1);
ret = R_DBG_REASON_NEW_TID;
next_event = 1;
break;
case EXIT_THREAD_DEBUG_EVENT:
eprintf("EXIT_THREAD\n");
eprintf ("EXIT_THREAD\n");
r_debug_native_continue (dbg, pid, tid, -1);
next_event = 1;
ret = R_DBG_REASON_EXIT_TID;
break;
case LOAD_DLL_DEBUG_EVENT:
eprintf("(%d) Loading %s library at 0x%x\n",
eprintf ("(%d) Loading %s library at %p\n",
pid, "", de.u.LoadDll.lpBaseOfDll);
r_debug_native_continue (dbg, pid, tid, -1);
next_event = 1;
@ -367,13 +376,13 @@ static RList *w32_dbg_maps() {
LPBYTE page;
char *mapname = NULL;
/* DEPRECATED */
char PeHeader[1024];
ut8 PeHeader[1024];
MODULEINFO ModInfo;
IMAGE_DOS_HEADER *dos_header;
IMAGE_NT_HEADERS *nt_headers;
IMAGE_SECTION_HEADER *SectionHeader;
int NumSections, i;
DWORD ret_len;
SIZE_T ret_len;
RDebugMap *mr;
RList *list = r_list_new ();
@ -424,9 +433,8 @@ static RList *w32_dbg_maps() {
for (i=0; i<NumSections; i++) {
mr = r_debug_map_new (mapname,
SectionHeader->VirtualAddress + page,
SectionHeader->VirtualAddress + page
+ SectionHeader->Misc.VirtualSize,
(ut64)(size_t) (SectionHeader->VirtualAddress + page),
(ut64)(size_t) (SectionHeader->VirtualAddress + page + SectionHeader->Misc.VirtualSize),
SectionHeader->Characteristics, // XXX?
0);
if (mr == NULL)
@ -456,7 +464,8 @@ static RList *w32_dbg_maps() {
#endif
page += mbi.RegionSize;
} else {
mr = r_debug_map_new ("unk", page, page+mbi.RegionSize, mbi.Protect, 0);
mr = r_debug_map_new ("unk", (ut64)(size_t)(page),
(ut64)(size_t)(page+mbi.RegionSize), mbi.Protect, 0);
if (mr == NULL) {
eprintf ("Cannot create r_debug_map_new\n");
// XXX leak
@ -545,7 +554,6 @@ err_load_th:
// XXX hacky
RList *w32_pids (int pid, RList *list) {
HANDLE th;
HANDLE thid;
THREADENTRY32 te32;
int ret = -1;
te32.dwSize = sizeof (THREADENTRY32);

View File

@ -11,6 +11,7 @@ F+= freebsd-x86-32
F+= openbsd-x86-32
F+= openbsd-x86-64
F+= windows-x86-32
F+= windows-x86-64
include ../../../config-user.mk

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,9 @@
cd `dirname $PWD/$0` ; cd ..
export PATH=${PWD}/sys/_work/mingw64/bin:${PATH}
# TODO: add support for ccache
make clean
./configure --without-gmp --with-compiler=x86_64-w64-mingw32-gcc --with-ostype=windows --host=x86_64-unknown-windows --without-ssl
make
make -j 4
make w32dist