2002-07-20 22:29:09 +02:00
|
|
|
/*
|
2012-05-15 10:15:32 +02:00
|
|
|
* A Win32 based proxy implementing the GBD remote protocol.
|
|
|
|
* This makes it possible to debug Wine (and any "emulated"
|
|
|
|
* program) under Linux using GDB.
|
2002-07-20 22:29:09 +02:00
|
|
|
*
|
2004-06-04 02:59:16 +02:00
|
|
|
* Copyright (c) Eric Pouech 2002-2004
|
2002-07-20 22:29:09 +02:00
|
|
|
*
|
|
|
|
* 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 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-20 22:29:09 +02:00
|
|
|
*/
|
|
|
|
|
2003-01-07 20:45:40 +01:00
|
|
|
/* Protocol specification can be found here:
|
2010-01-05 20:42:19 +01:00
|
|
|
* http://sources.redhat.com/gdb/onlinedocs/gdb/Maintenance-Commands.html
|
2003-01-07 20:45:40 +01:00
|
|
|
*/
|
|
|
|
|
2021-10-04 11:27:43 +02:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
2003-09-07 07:08:14 +02:00
|
|
|
#include <stdarg.h>
|
2002-07-20 22:29:09 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "debugger.h"
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2021-10-04 15:19:20 +02:00
|
|
|
#include "winsock2.h"
|
2002-07-20 22:29:09 +02:00
|
|
|
#include "tlhelp32.h"
|
2018-07-30 21:47:53 +02:00
|
|
|
#include "wine/debug.h"
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2018-07-30 21:47:53 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-04 11:30:14 +02:00
|
|
|
struct gdb_xpoint
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
int pid;
|
|
|
|
int tid;
|
|
|
|
enum be_xpoint_type type;
|
|
|
|
void *addr;
|
|
|
|
int size;
|
2021-10-04 14:16:23 +02:00
|
|
|
unsigned int value;
|
2020-04-04 11:30:14 +02:00
|
|
|
};
|
|
|
|
|
2021-11-23 16:09:48 +01:00
|
|
|
struct reply_buffer
|
|
|
|
{
|
|
|
|
unsigned char* base;
|
|
|
|
size_t len;
|
|
|
|
size_t alloc;
|
|
|
|
};
|
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
#define QX_NAME_SIZE 32
|
|
|
|
#define QX_ANNEX_SIZE MAX_PATH
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
struct gdb_context
|
|
|
|
{
|
|
|
|
/* gdb information */
|
2021-10-04 11:27:43 +02:00
|
|
|
SOCKET sock;
|
2002-07-20 22:29:09 +02:00
|
|
|
/* incoming buffer */
|
|
|
|
char* in_buf;
|
|
|
|
int in_buf_alloc;
|
|
|
|
int in_len;
|
|
|
|
/* split into individual packet */
|
|
|
|
char* in_packet;
|
|
|
|
int in_packet_len;
|
|
|
|
/* outgoing buffer */
|
2021-11-23 16:09:48 +01:00
|
|
|
struct reply_buffer out_buf;
|
2002-07-20 22:29:09 +02:00
|
|
|
int out_curr_packet;
|
|
|
|
/* generic GDB thread information */
|
2020-04-01 17:03:25 +02:00
|
|
|
int exec_tid; /* tid used in step & continue */
|
|
|
|
int other_tid; /* tid to be used in any other operation */
|
2020-04-04 11:30:14 +02:00
|
|
|
struct list xpoint_list;
|
2002-07-20 22:29:09 +02:00
|
|
|
/* current Win32 trap env */
|
2020-04-01 17:03:26 +02:00
|
|
|
DEBUG_EVENT de;
|
2020-04-01 17:03:27 +02:00
|
|
|
DWORD de_reply;
|
2002-07-20 22:29:09 +02:00
|
|
|
/* Win32 information */
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_process* process;
|
2002-07-20 22:29:09 +02:00
|
|
|
/* Unix environment */
|
2021-10-04 14:16:23 +02:00
|
|
|
ULONG_PTR wine_segs[3]; /* load addresses of the ELF wine exec segments (text, bss and data) */
|
2020-03-31 15:12:29 +02:00
|
|
|
BOOL no_ack_mode;
|
2021-11-23 16:11:00 +01:00
|
|
|
int qxfer_object_idx;
|
|
|
|
char qxfer_object_annex[QX_ANNEX_SIZE];
|
2021-11-23 16:10:01 +01:00
|
|
|
struct reply_buffer qxfer_buffer;
|
2002-07-20 22:29:09 +02:00
|
|
|
};
|
|
|
|
|
2021-10-04 11:27:43 +02:00
|
|
|
/* assume standard signal and errno values */
|
|
|
|
enum host_error
|
|
|
|
{
|
2021-11-23 16:11:15 +01:00
|
|
|
HOST_EPERM = 1,
|
|
|
|
HOST_ENOENT = 2,
|
2021-10-04 11:27:43 +02:00
|
|
|
HOST_ESRCH = 3,
|
2021-11-23 16:11:15 +01:00
|
|
|
HOST_ENOMEM = 12,
|
2021-10-04 11:27:43 +02:00
|
|
|
HOST_EFAULT = 14,
|
|
|
|
HOST_EINVAL = 22,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum host_signal
|
|
|
|
{
|
|
|
|
HOST_SIGINT = 2,
|
|
|
|
HOST_SIGILL = 4,
|
|
|
|
HOST_SIGTRAP = 5,
|
|
|
|
HOST_SIGABRT = 6,
|
|
|
|
HOST_SIGFPE = 8,
|
|
|
|
HOST_SIGBUS = 10,
|
|
|
|
HOST_SIGSEGV = 11,
|
|
|
|
HOST_SIGALRM = 14,
|
|
|
|
HOST_SIGTERM = 15,
|
|
|
|
};
|
|
|
|
|
2020-04-04 11:30:14 +02:00
|
|
|
static void gdbctx_delete_xpoint(struct gdb_context *gdbctx, struct dbg_thread *thread,
|
|
|
|
dbg_ctx_t *ctx, struct gdb_xpoint *x)
|
|
|
|
{
|
2021-03-09 22:54:55 +01:00
|
|
|
struct dbg_process *process = gdbctx->process;
|
2020-04-04 11:30:14 +02:00
|
|
|
struct backend_cpu *cpu = process->be_cpu;
|
|
|
|
|
|
|
|
if (!cpu->remove_Xpoint(process->handle, process->process_io, ctx, x->type, x->addr, x->value, x->size))
|
2022-02-07 08:40:49 +01:00
|
|
|
ERR("%04lx:%04lx: Couldn't remove breakpoint at:%p/%x type:%d\n", process->pid, thread ? thread->tid : ~0, x->addr, x->size, x->type);
|
2020-04-04 11:30:14 +02:00
|
|
|
|
|
|
|
list_remove(&x->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gdbctx_insert_xpoint(struct gdb_context *gdbctx, struct dbg_thread *thread,
|
|
|
|
dbg_ctx_t *ctx, enum be_xpoint_type type, void *addr, int size)
|
|
|
|
{
|
|
|
|
struct dbg_process *process = thread->process;
|
|
|
|
struct backend_cpu *cpu = process->be_cpu;
|
|
|
|
struct gdb_xpoint *x;
|
2021-10-04 14:16:23 +02:00
|
|
|
unsigned int value;
|
2020-04-04 11:30:14 +02:00
|
|
|
|
|
|
|
if (!cpu->insert_Xpoint(process->handle, process->process_io, ctx, type, addr, &value, size))
|
|
|
|
{
|
2022-02-07 08:40:49 +01:00
|
|
|
ERR("%04lx:%04lx: Couldn't insert breakpoint at:%p/%x type:%d\n", process->pid, thread->tid, addr, size, type);
|
2020-04-04 11:30:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(x = HeapAlloc(GetProcessHeap(), 0, sizeof(struct gdb_xpoint))))
|
|
|
|
{
|
2022-02-07 08:40:49 +01:00
|
|
|
ERR("%04lx:%04lx: Couldn't allocate memory for breakpoint at:%p/%x type:%d\n", process->pid, thread->tid, addr, size, type);
|
2020-04-04 11:30:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
x->pid = process->pid;
|
|
|
|
x->tid = thread->tid;
|
|
|
|
x->type = type;
|
|
|
|
x->addr = addr;
|
|
|
|
x->size = size;
|
|
|
|
x->value = value;
|
|
|
|
list_add_head(&gdbctx->xpoint_list, &x->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct gdb_xpoint *gdb_find_xpoint(struct gdb_context *gdbctx, struct dbg_thread *thread,
|
|
|
|
enum be_xpoint_type type, void *addr, int size)
|
|
|
|
{
|
|
|
|
struct gdb_xpoint *x;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(x, &gdbctx->xpoint_list, struct gdb_xpoint, entry)
|
|
|
|
{
|
|
|
|
if (thread && (x->pid != thread->process->pid || x->tid != thread->tid))
|
|
|
|
continue;
|
|
|
|
if (x->type == type && x->addr == addr && x->size == size)
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-05 15:16:14 +02:00
|
|
|
static BOOL tgt_process_gdbproxy_read(HANDLE hProcess, const void* addr,
|
|
|
|
void* buffer, SIZE_T len, SIZE_T* rlen)
|
|
|
|
{
|
|
|
|
return ReadProcessMemory( hProcess, addr, buffer, len, rlen );
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL tgt_process_gdbproxy_write(HANDLE hProcess, void* addr,
|
|
|
|
const void* buffer, SIZE_T len, SIZE_T* wlen)
|
|
|
|
{
|
|
|
|
return WriteProcessMemory( hProcess, addr, buffer, len, wlen );
|
|
|
|
}
|
|
|
|
|
2008-05-26 19:25:04 +02:00
|
|
|
static struct be_process_io be_process_gdbproxy_io =
|
|
|
|
{
|
|
|
|
NULL, /* we shouldn't use close_process() in gdbproxy */
|
2009-06-05 15:16:14 +02:00
|
|
|
tgt_process_gdbproxy_read,
|
|
|
|
tgt_process_gdbproxy_write
|
2008-05-26 19:25:04 +02:00
|
|
|
};
|
2006-03-01 21:05:31 +01:00
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
/* =============================================== *
|
|
|
|
* B A S I C M A N I P U L A T I O N S *
|
|
|
|
* =============================================== *
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline int hex_from0(char ch)
|
|
|
|
{
|
|
|
|
if (ch >= '0' && ch <= '9') return ch - '0';
|
|
|
|
if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10;
|
|
|
|
if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10;
|
2002-10-15 04:19:06 +02:00
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
assert(0);
|
2002-10-15 04:19:06 +02:00
|
|
|
return 0;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned char hex_to0(int x)
|
|
|
|
{
|
|
|
|
assert(x >= 0 && x < 16);
|
|
|
|
return "0123456789abcdef"[x];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hex_from(void* dst, const char* src, size_t len)
|
|
|
|
{
|
2003-01-23 22:32:35 +01:00
|
|
|
unsigned char *p = dst;
|
2002-07-20 22:29:09 +02:00
|
|
|
while (len--)
|
|
|
|
{
|
2003-01-23 22:32:35 +01:00
|
|
|
*p++ = (hex_from0(src[0]) << 4) | hex_from0(src[1]);
|
2002-07-20 22:29:09 +02:00
|
|
|
src += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hex_to(char* dst, const void* src, size_t len)
|
|
|
|
{
|
2003-01-23 22:32:35 +01:00
|
|
|
const unsigned char *p = src;
|
2002-07-20 22:29:09 +02:00
|
|
|
while (len--)
|
|
|
|
{
|
2003-01-23 22:32:35 +01:00
|
|
|
*dst++ = hex_to0(*p >> 4);
|
|
|
|
*dst++ = hex_to0(*p & 0x0F);
|
|
|
|
p++;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:09:48 +01:00
|
|
|
static void reply_buffer_clear(struct reply_buffer* reply)
|
|
|
|
{
|
|
|
|
reply->len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reply_buffer_grow(struct reply_buffer* reply, size_t size)
|
|
|
|
{
|
2021-11-23 16:09:53 +01:00
|
|
|
size_t required_alloc = reply->len + size;
|
|
|
|
|
|
|
|
if (reply->alloc < required_alloc)
|
2021-11-23 16:09:48 +01:00
|
|
|
{
|
2021-11-23 16:09:53 +01:00
|
|
|
reply->alloc = reply->alloc * 3 / 2;
|
|
|
|
if (reply->alloc < required_alloc)
|
|
|
|
reply->alloc = required_alloc;
|
|
|
|
|
2021-11-23 16:09:48 +01:00
|
|
|
reply->base = realloc(reply->base, reply->alloc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reply_buffer_append(struct reply_buffer* reply, const void* data, size_t size)
|
|
|
|
{
|
|
|
|
reply_buffer_grow(reply, size);
|
|
|
|
memcpy(reply->base + reply->len, data, size);
|
|
|
|
reply->len += size;
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
static inline void reply_buffer_append_str(struct reply_buffer* reply, const char* str)
|
|
|
|
{
|
|
|
|
reply_buffer_append(reply, str, strlen(str));
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:09:48 +01:00
|
|
|
static inline void reply_buffer_append_hex(struct reply_buffer* reply, const void* src, size_t len)
|
|
|
|
{
|
|
|
|
reply_buffer_grow(reply, len * 2);
|
|
|
|
hex_to((char *)reply->base + reply->len, src, len);
|
|
|
|
reply->len += len * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void reply_buffer_append_uinthex(struct reply_buffer* reply, ULONG_PTR val, int len)
|
|
|
|
{
|
|
|
|
char buf[sizeof(ULONG_PTR) * 2], *ptr;
|
|
|
|
|
|
|
|
assert(len <= sizeof(ULONG_PTR));
|
|
|
|
|
|
|
|
ptr = buf + len * 2;
|
|
|
|
while (ptr != buf)
|
|
|
|
{
|
|
|
|
*--ptr = hex_to0(val & 0x0F);
|
|
|
|
val >>= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
reply_buffer_append(reply, ptr, len * 2);
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:10:49 +01:00
|
|
|
static const unsigned char xml_special_chars_lookup_table[16] = {
|
|
|
|
/* The characters should be sorted by its value modulo table length. */
|
|
|
|
|
|
|
|
0x00, /* NUL */
|
|
|
|
0,
|
|
|
|
0x22, /* ": 0010|0010 */
|
|
|
|
0, 0, 0,
|
|
|
|
0x26, /* &: 0010|0110 */
|
|
|
|
0x27, /* ': 0010|0111 */
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0x3C, /* <: 0011|1100 */
|
|
|
|
0,
|
|
|
|
0x3E, /* >: 0011|1110 */
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline BOOL is_nul_or_xml_special_char(unsigned char val)
|
|
|
|
{
|
|
|
|
const size_t length = ARRAY_SIZE(xml_special_chars_lookup_table);
|
|
|
|
return xml_special_chars_lookup_table[val % length] == val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reply_buffer_append_xmlstr(struct reply_buffer* reply, const char* str)
|
|
|
|
{
|
|
|
|
const char *ptr = str, *curr;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
curr = ptr;
|
|
|
|
|
|
|
|
while (!is_nul_or_xml_special_char((unsigned char)*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
reply_buffer_append(reply, curr, ptr - curr);
|
|
|
|
|
|
|
|
switch (*ptr++)
|
|
|
|
{
|
|
|
|
case '"': reply_buffer_append_str(reply, """); break;
|
|
|
|
case '&': reply_buffer_append_str(reply, "&"); break;
|
|
|
|
case '\'': reply_buffer_append_str(reply, "'"); break;
|
|
|
|
case '<': reply_buffer_append_str(reply, "<"); break;
|
|
|
|
case '>': reply_buffer_append_str(reply, ">"); break;
|
|
|
|
case '\0':
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:09:48 +01:00
|
|
|
static unsigned char checksum(const void* data, int len)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
unsigned cksum = 0;
|
2021-11-23 16:09:48 +01:00
|
|
|
const unsigned char* ptr = data;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
while (len-- > 0)
|
2021-11-23 16:09:48 +01:00
|
|
|
cksum += *ptr++;
|
2002-07-20 22:29:09 +02:00
|
|
|
return cksum;
|
|
|
|
}
|
|
|
|
|
2018-06-13 23:34:01 +02:00
|
|
|
static inline void* cpu_register_ptr(struct gdb_context *gdbctx,
|
|
|
|
dbg_ctx_t *ctx, unsigned idx)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2018-06-13 23:34:01 +02:00
|
|
|
assert(idx < gdbctx->process->be_cpu->gdb_num_regs);
|
2020-04-03 15:35:51 +02:00
|
|
|
return (char*)ctx + gdbctx->process->be_cpu->gdb_register_map[idx].offset;
|
2012-05-20 09:45:26 +02:00
|
|
|
}
|
|
|
|
|
2018-06-13 23:34:01 +02:00
|
|
|
static inline DWORD64 cpu_register(struct gdb_context *gdbctx,
|
|
|
|
dbg_ctx_t *ctx, unsigned idx)
|
2012-05-20 09:45:26 +02:00
|
|
|
{
|
2020-04-03 15:35:51 +02:00
|
|
|
switch (gdbctx->process->be_cpu->gdb_register_map[idx].length)
|
2012-05-20 09:45:26 +02:00
|
|
|
{
|
2018-06-13 23:34:01 +02:00
|
|
|
case 1: return *(BYTE*)cpu_register_ptr(gdbctx, ctx, idx);
|
|
|
|
case 2: return *(WORD*)cpu_register_ptr(gdbctx, ctx, idx);
|
|
|
|
case 4: return *(DWORD*)cpu_register_ptr(gdbctx, ctx, idx);
|
|
|
|
case 8: return *(DWORD64*)cpu_register_ptr(gdbctx, ctx, idx);
|
2012-05-20 09:45:26 +02:00
|
|
|
default:
|
2018-07-30 21:47:53 +02:00
|
|
|
ERR("got unexpected size: %u\n",
|
2020-04-03 15:35:51 +02:00
|
|
|
(unsigned)gdbctx->process->be_cpu->gdb_register_map[idx].length);
|
2012-05-20 09:45:26 +02:00
|
|
|
assert(0);
|
2013-03-06 14:09:24 +01:00
|
|
|
return 0;
|
2012-05-20 09:45:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 23:34:01 +02:00
|
|
|
static inline void cpu_register_hex_from(struct gdb_context *gdbctx,
|
|
|
|
dbg_ctx_t* ctx, unsigned idx, const char **phex)
|
2012-05-20 09:45:26 +02:00
|
|
|
{
|
2018-06-13 23:34:01 +02:00
|
|
|
const struct gdb_register *cpu_register_map = gdbctx->process->be_cpu->gdb_register_map;
|
2020-04-03 15:35:51 +02:00
|
|
|
hex_from(cpu_register_ptr(gdbctx, ctx, idx), *phex, cpu_register_map[idx].length);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* =============================================== *
|
|
|
|
* W I N 3 2 D E B U G I N T E R F A C E *
|
|
|
|
* =============================================== *
|
|
|
|
*/
|
|
|
|
|
2020-04-01 17:03:25 +02:00
|
|
|
static struct dbg_thread* dbg_thread_from_tid(struct gdb_context* gdbctx, int tid)
|
|
|
|
{
|
|
|
|
struct dbg_process *process = gdbctx->process;
|
|
|
|
struct dbg_thread *thread;
|
|
|
|
|
|
|
|
if (!process) return NULL;
|
|
|
|
|
2020-04-01 17:03:28 +02:00
|
|
|
if (tid == 0) tid = gdbctx->de.dwThreadId;
|
2020-04-01 17:03:25 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(thread, &process->threads, struct dbg_thread, entry)
|
|
|
|
{
|
|
|
|
if (tid > 0 && thread->tid != tid) continue;
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
2020-04-01 17:03:28 +02:00
|
|
|
return NULL;
|
2020-04-01 17:03:25 +02:00
|
|
|
}
|
|
|
|
|
2020-04-01 17:03:24 +02:00
|
|
|
static void dbg_thread_set_single_step(struct dbg_thread *thread, BOOL enable)
|
2003-04-19 23:27:47 +02:00
|
|
|
{
|
2020-04-01 17:03:24 +02:00
|
|
|
struct backend_cpu *backend;
|
|
|
|
dbg_ctx_t ctx;
|
|
|
|
|
|
|
|
if (!thread) return;
|
|
|
|
if (!thread->process) return;
|
|
|
|
if (!(backend = thread->process->be_cpu)) return;
|
|
|
|
|
|
|
|
if (!backend->get_context(thread->handle, &ctx))
|
2003-04-19 23:27:47 +02:00
|
|
|
{
|
2022-02-07 08:40:49 +01:00
|
|
|
ERR("get_context failed for thread %04lx:%04lx\n", thread->process->pid, thread->tid);
|
2020-04-01 17:03:24 +02:00
|
|
|
return;
|
2003-04-19 23:27:47 +02:00
|
|
|
}
|
2020-04-01 17:03:24 +02:00
|
|
|
backend->single_step(&ctx, enable);
|
|
|
|
if (!backend->set_context(thread->handle, &ctx))
|
2022-02-07 08:40:49 +01:00
|
|
|
ERR("set_context failed for thread %04lx:%04lx\n", thread->process->pid, thread->tid);
|
2003-04-19 23:27:47 +02:00
|
|
|
}
|
|
|
|
|
2020-04-04 11:30:17 +02:00
|
|
|
static unsigned char signal_from_debug_event(DEBUG_EVENT* de)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-04-04 11:30:17 +02:00
|
|
|
DWORD ec;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-04 11:30:17 +02:00
|
|
|
if (de->dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT)
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGTERM;
|
2020-04-04 11:30:17 +02:00
|
|
|
if (de->dwDebugEventCode != EXCEPTION_DEBUG_EVENT)
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGTRAP;
|
2020-04-04 11:30:17 +02:00
|
|
|
|
|
|
|
ec = de->u.Exception.ExceptionRecord.ExceptionCode;
|
|
|
|
switch (ec)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
case EXCEPTION_ACCESS_VIOLATION:
|
|
|
|
case EXCEPTION_PRIV_INSTRUCTION:
|
|
|
|
case EXCEPTION_STACK_OVERFLOW:
|
|
|
|
case EXCEPTION_GUARD_PAGE:
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGSEGV;
|
2002-07-20 22:29:09 +02:00
|
|
|
case EXCEPTION_DATATYPE_MISALIGNMENT:
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGBUS;
|
2002-07-20 22:29:09 +02:00
|
|
|
case EXCEPTION_SINGLE_STEP:
|
|
|
|
case EXCEPTION_BREAKPOINT:
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGTRAP;
|
2002-07-20 22:29:09 +02:00
|
|
|
case EXCEPTION_FLT_DENORMAL_OPERAND:
|
|
|
|
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
|
|
|
|
case EXCEPTION_FLT_INEXACT_RESULT:
|
|
|
|
case EXCEPTION_FLT_INVALID_OPERATION:
|
|
|
|
case EXCEPTION_FLT_OVERFLOW:
|
|
|
|
case EXCEPTION_FLT_STACK_CHECK:
|
|
|
|
case EXCEPTION_FLT_UNDERFLOW:
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGFPE;
|
2002-07-20 22:29:09 +02:00
|
|
|
case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
|
|
|
case EXCEPTION_INT_OVERFLOW:
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGFPE;
|
2002-07-20 22:29:09 +02:00
|
|
|
case EXCEPTION_ILLEGAL_INSTRUCTION:
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGILL;
|
2002-07-20 22:29:09 +02:00
|
|
|
case CONTROL_C_EXIT:
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGINT;
|
2003-04-04 21:41:31 +02:00
|
|
|
case STATUS_POSSIBLE_DEADLOCK:
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGALRM;
|
2020-04-04 11:30:17 +02:00
|
|
|
/* should not be here */
|
|
|
|
case EXCEPTION_INVALID_HANDLE:
|
2021-02-05 10:21:28 +01:00
|
|
|
case EXCEPTION_WINE_NAME_THREAD:
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGTRAP;
|
2020-04-04 11:30:17 +02:00
|
|
|
default:
|
2022-02-07 08:40:49 +01:00
|
|
|
ERR("Unknown exception code 0x%08lx\n", ec);
|
2021-10-04 11:27:43 +02:00
|
|
|
return HOST_SIGABRT;
|
2020-04-04 11:30:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL handle_exception(struct gdb_context* gdbctx, EXCEPTION_DEBUG_INFO* exc)
|
|
|
|
{
|
|
|
|
EXCEPTION_RECORD* rec = &exc->ExceptionRecord;
|
|
|
|
|
|
|
|
switch (rec->ExceptionCode)
|
|
|
|
{
|
2021-02-05 10:21:28 +01:00
|
|
|
case EXCEPTION_WINE_NAME_THREAD:
|
2018-06-14 23:58:49 +02:00
|
|
|
{
|
|
|
|
const THREADNAME_INFO *threadname = (const THREADNAME_INFO *)rec->ExceptionInformation;
|
|
|
|
struct dbg_thread *thread;
|
|
|
|
char name[9];
|
|
|
|
SIZE_T read;
|
|
|
|
|
2022-02-24 19:34:02 +01:00
|
|
|
if (threadname->dwType != 0x1000)
|
|
|
|
return FALSE;
|
2018-06-14 23:58:49 +02:00
|
|
|
if (threadname->dwThreadID == -1)
|
2020-04-01 17:03:28 +02:00
|
|
|
thread = dbg_get_thread(gdbctx->process, gdbctx->de.dwThreadId);
|
2018-06-14 23:58:49 +02:00
|
|
|
else
|
|
|
|
thread = dbg_get_thread(gdbctx->process, threadname->dwThreadID);
|
|
|
|
if (thread)
|
|
|
|
{
|
|
|
|
if (gdbctx->process->process_io->read( gdbctx->process->handle,
|
|
|
|
threadname->szName, name, sizeof(name), &read) && read == sizeof(name))
|
|
|
|
{
|
2022-02-07 08:40:49 +01:00
|
|
|
fprintf(stderr, "Thread ID=%04lx renamed to \"%.9s\"\n",
|
2018-06-14 23:58:49 +02:00
|
|
|
threadname->dwThreadID, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2022-02-07 08:40:49 +01:00
|
|
|
ERR("Cannot set name of thread %04lx\n", threadname->dwThreadID);
|
2020-04-04 11:30:15 +02:00
|
|
|
return TRUE;
|
2018-06-14 23:58:49 +02:00
|
|
|
}
|
2018-07-30 21:47:56 +02:00
|
|
|
case EXCEPTION_INVALID_HANDLE:
|
2020-04-04 11:30:15 +02:00
|
|
|
return TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
default:
|
2020-04-04 11:30:15 +02:00
|
|
|
return FALSE;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 06:36:34 +02:00
|
|
|
static BOOL handle_debug_event(struct gdb_context* gdbctx, BOOL stop_on_dll_load_unload)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-04-01 17:03:26 +02:00
|
|
|
DEBUG_EVENT *de = &gdbctx->de;
|
2020-04-01 17:03:27 +02:00
|
|
|
struct dbg_thread *thread;
|
2020-04-01 17:03:26 +02:00
|
|
|
|
2008-10-18 09:15:10 +02:00
|
|
|
union {
|
|
|
|
char bufferA[256];
|
|
|
|
WCHAR buffer[256];
|
|
|
|
} u;
|
2021-04-13 12:14:15 +02:00
|
|
|
DWORD size;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-01 17:03:25 +02:00
|
|
|
gdbctx->exec_tid = de->dwThreadId;
|
|
|
|
gdbctx->other_tid = de->dwThreadId;
|
2020-04-01 17:03:27 +02:00
|
|
|
gdbctx->de_reply = DBG_REPLY_LATER;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
switch (de->dwDebugEventCode)
|
|
|
|
{
|
|
|
|
case CREATE_PROCESS_DEBUG_EVENT:
|
2006-03-01 21:05:31 +01:00
|
|
|
gdbctx->process = dbg_add_process(&be_process_gdbproxy_io, de->dwProcessId,
|
2005-05-24 13:46:25 +02:00
|
|
|
de->u.CreateProcessInfo.hProcess);
|
2020-04-04 11:30:16 +02:00
|
|
|
if (!gdbctx->process)
|
|
|
|
return TRUE;
|
|
|
|
|
2021-04-13 12:14:15 +02:00
|
|
|
size = ARRAY_SIZE(u.buffer);
|
|
|
|
QueryFullProcessImageNameW( gdbctx->process->handle, 0, u.buffer, &size );
|
2008-10-18 09:15:10 +02:00
|
|
|
dbg_set_process_name(gdbctx->process, u.buffer);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2022-03-18 17:25:36 +01:00
|
|
|
fprintf(stderr, "%04lx:%04lx: create process '%ls'/%p @%p (%lu<%lu>)\n",
|
2002-07-20 22:29:09 +02:00
|
|
|
de->dwProcessId, de->dwThreadId,
|
2022-03-18 17:25:36 +01:00
|
|
|
u.buffer,
|
2008-10-18 09:15:10 +02:00
|
|
|
de->u.CreateProcessInfo.lpImageName,
|
2006-12-20 14:17:27 +01:00
|
|
|
de->u.CreateProcessInfo.lpStartAddress,
|
2002-07-20 22:29:09 +02:00
|
|
|
de->u.CreateProcessInfo.dwDebugInfoFileOffset,
|
|
|
|
de->u.CreateProcessInfo.nDebugInfoSize);
|
|
|
|
|
|
|
|
/* de->u.CreateProcessInfo.lpStartAddress; */
|
2008-10-18 09:15:10 +02:00
|
|
|
if (!dbg_init(gdbctx->process->handle, u.buffer, TRUE))
|
2018-07-30 21:47:53 +02:00
|
|
|
ERR("Couldn't initiate DbgHelp\n");
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2022-02-07 08:40:49 +01:00
|
|
|
fprintf(stderr, "%04lx:%04lx: create thread I @%p\n", de->dwProcessId,
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwThreadId, de->u.CreateProcessInfo.lpStartAddress);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2021-06-25 17:19:33 +02:00
|
|
|
dbg_load_module(gdbctx->process->handle, de->u.CreateProcessInfo.hFile, u.buffer,
|
|
|
|
(DWORD_PTR)de->u.CreateProcessInfo.lpBaseOfImage, 0);
|
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_add_thread(gdbctx->process, de->dwThreadId,
|
|
|
|
de->u.CreateProcessInfo.hThread,
|
|
|
|
de->u.CreateProcessInfo.lpThreadLocalBase);
|
2020-04-04 11:30:16 +02:00
|
|
|
return TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
case LOAD_DLL_DEBUG_EVENT:
|
2021-04-13 12:29:38 +02:00
|
|
|
fetch_module_name( de->u.LoadDll.lpImageName, de->u.LoadDll.lpBaseOfDll,
|
|
|
|
u.buffer, ARRAY_SIZE(u.buffer) );
|
2022-03-18 17:25:36 +01:00
|
|
|
fprintf(stderr, "%04lx:%04lx: loads DLL %ls @%p (%lu<%lu>)\n",
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwProcessId, de->dwThreadId,
|
2022-03-18 17:25:36 +01:00
|
|
|
u.buffer,
|
2018-07-30 21:47:53 +02:00
|
|
|
de->u.LoadDll.lpBaseOfDll,
|
|
|
|
de->u.LoadDll.dwDebugInfoFileOffset,
|
|
|
|
de->u.LoadDll.nDebugInfoSize);
|
2008-10-18 09:15:19 +02:00
|
|
|
dbg_load_module(gdbctx->process->handle, de->u.LoadDll.hFile, u.buffer,
|
|
|
|
(DWORD_PTR)de->u.LoadDll.lpBaseOfDll, 0);
|
2021-07-13 06:36:34 +02:00
|
|
|
if (stop_on_dll_load_unload)
|
|
|
|
break;
|
2020-04-04 11:30:16 +02:00
|
|
|
return TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
case UNLOAD_DLL_DEBUG_EVENT:
|
2022-02-07 08:40:49 +01:00
|
|
|
fprintf(stderr, "%08lx:%08lx: unload DLL @%p\n",
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwProcessId, de->dwThreadId, de->u.UnloadDll.lpBaseOfDll);
|
2008-10-18 09:15:19 +02:00
|
|
|
SymUnloadModule(gdbctx->process->handle,
|
|
|
|
(DWORD_PTR)de->u.UnloadDll.lpBaseOfDll);
|
2021-07-13 06:36:34 +02:00
|
|
|
if (stop_on_dll_load_unload)
|
|
|
|
break;
|
2020-04-04 11:30:16 +02:00
|
|
|
return TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
case EXCEPTION_DEBUG_EVENT:
|
2022-02-07 08:40:49 +01:00
|
|
|
TRACE("%08lx:%08lx: exception code=0x%08lx\n", de->dwProcessId,
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwThreadId, de->u.Exception.ExceptionRecord.ExceptionCode);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-04 11:30:16 +02:00
|
|
|
if (handle_exception(gdbctx, &de->u.Exception))
|
|
|
|
return TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CREATE_THREAD_DEBUG_EVENT:
|
2022-02-07 08:40:49 +01:00
|
|
|
fprintf(stderr, "%08lx:%08lx: create thread D @%p\n", de->dwProcessId,
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwThreadId, de->u.CreateThread.lpStartAddress);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_add_thread(gdbctx->process,
|
|
|
|
de->dwThreadId,
|
|
|
|
de->u.CreateThread.hThread,
|
|
|
|
de->u.CreateThread.lpThreadLocalBase);
|
2020-04-04 11:30:16 +02:00
|
|
|
return TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
case EXIT_THREAD_DEBUG_EVENT:
|
2022-02-07 08:40:49 +01:00
|
|
|
fprintf(stderr, "%08lx:%08lx: exit thread (%lu)\n",
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwProcessId, de->dwThreadId, de->u.ExitThread.dwExitCode);
|
2020-04-01 17:03:28 +02:00
|
|
|
if ((thread = dbg_get_thread(gdbctx->process, de->dwThreadId)))
|
|
|
|
dbg_del_thread(thread);
|
2020-04-04 11:30:16 +02:00
|
|
|
return TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
case EXIT_PROCESS_DEBUG_EVENT:
|
2022-02-07 08:40:49 +01:00
|
|
|
fprintf(stderr, "%08lx:%08lx: exit process (%lu)\n",
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwProcessId, de->dwThreadId, de->u.ExitProcess.dwExitCode);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_del_process(gdbctx->process);
|
2002-07-20 22:29:09 +02:00
|
|
|
gdbctx->process = NULL;
|
2020-04-04 11:30:16 +02:00
|
|
|
return FALSE;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
case OUTPUT_DEBUG_STRING_EVENT:
|
2005-05-24 13:46:25 +02:00
|
|
|
memory_get_string(gdbctx->process,
|
2004-08-23 00:35:36 +02:00
|
|
|
de->u.DebugString.lpDebugStringData, TRUE,
|
2008-10-18 09:15:10 +02:00
|
|
|
de->u.DebugString.fUnicode, u.bufferA, sizeof(u.bufferA));
|
2022-02-07 08:40:49 +01:00
|
|
|
fprintf(stderr, "%08lx:%08lx: output debug string (%s)\n",
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwProcessId, de->dwThreadId, debugstr_a(u.bufferA));
|
2020-04-04 11:30:16 +02:00
|
|
|
return TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
case RIP_EVENT:
|
2022-02-07 08:40:49 +01:00
|
|
|
fprintf(stderr, "%08lx:%08lx: rip error=%lu type=%lu\n", de->dwProcessId,
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwThreadId, de->u.RipInfo.dwError, de->u.RipInfo.dwType);
|
2020-04-04 11:30:16 +02:00
|
|
|
return TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
default:
|
2022-02-07 08:40:49 +01:00
|
|
|
FIXME("%08lx:%08lx: unknown event (%lu)\n",
|
2018-07-30 21:47:53 +02:00
|
|
|
de->dwProcessId, de->dwThreadId, de->dwDebugEventCode);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
2020-04-01 17:03:27 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(thread, &gdbctx->process->threads, struct dbg_thread, entry)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
if (!thread->suspended) SuspendThread(thread->handle);
|
|
|
|
thread->suspended = TRUE;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
2020-04-04 11:30:16 +02:00
|
|
|
|
|
|
|
return FALSE;
|
2005-02-10 22:18:12 +01:00
|
|
|
}
|
|
|
|
|
2020-04-01 17:03:27 +02:00
|
|
|
static void handle_step_or_continue(struct gdb_context* gdbctx, int tid, BOOL step, int sig)
|
2005-02-10 22:18:12 +01:00
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
struct dbg_process *process = gdbctx->process;
|
|
|
|
struct dbg_thread *thread;
|
2005-02-10 22:18:12 +01:00
|
|
|
|
2020-04-01 17:03:28 +02:00
|
|
|
if (tid == 0) tid = gdbctx->de.dwThreadId;
|
2020-04-01 17:03:27 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(thread, &process->threads, struct dbg_thread, entry)
|
2005-02-10 22:18:12 +01:00
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
if (tid != -1 && thread->tid != tid) continue;
|
|
|
|
if (!thread->suspended) continue;
|
|
|
|
thread->suspended = FALSE;
|
|
|
|
|
|
|
|
if (process->pid == gdbctx->de.dwProcessId && thread->tid == gdbctx->de.dwThreadId)
|
|
|
|
gdbctx->de_reply = (sig == -1 ? DBG_CONTINUE : DBG_EXCEPTION_NOT_HANDLED);
|
|
|
|
|
|
|
|
dbg_thread_set_single_step(thread, step);
|
|
|
|
ResumeThread(thread->handle);
|
2005-02-10 22:18:12 +01:00
|
|
|
}
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
2005-05-24 12:11:37 +02:00
|
|
|
static BOOL check_for_interrupt(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
char pkt;
|
2021-10-04 11:27:43 +02:00
|
|
|
fd_set read_fds;
|
|
|
|
struct timeval tv = { 0, 0 };
|
|
|
|
|
|
|
|
FD_ZERO( &read_fds );
|
|
|
|
FD_SET( gdbctx->sock, &read_fds );
|
|
|
|
|
|
|
|
if (select( 0, &read_fds, NULL, NULL, &tv ) > 0)
|
|
|
|
{
|
|
|
|
if (recv(gdbctx->sock, &pkt, 1, 0) != 1) {
|
|
|
|
ERR("read failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (pkt != '\003') {
|
|
|
|
ERR("Unexpected break packet %#02x\n", pkt);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2005-05-24 12:11:37 +02:00
|
|
|
}
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
static void wait_for_debuggee(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
if (gdbctx->de.dwDebugEventCode)
|
|
|
|
ContinueDebugEvent(gdbctx->de.dwProcessId, gdbctx->de.dwThreadId, gdbctx->de_reply);
|
|
|
|
|
2005-05-24 12:11:37 +02:00
|
|
|
for (;;)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-04-01 17:03:26 +02:00
|
|
|
if (!WaitForDebugEvent(&gdbctx->de, 10))
|
2005-05-24 12:11:37 +02:00
|
|
|
{
|
|
|
|
if (GetLastError() == ERROR_SEM_TIMEOUT)
|
|
|
|
{
|
|
|
|
if (check_for_interrupt(gdbctx)) {
|
|
|
|
if (!DebugBreakProcess(gdbctx->process->handle)) {
|
2019-12-10 09:29:40 +01:00
|
|
|
ERR("Failed to break into debuggee\n");
|
2005-05-24 12:11:37 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-04-01 17:03:26 +02:00
|
|
|
WaitForDebugEvent(&gdbctx->de, INFINITE);
|
2005-05-24 12:11:37 +02:00
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 06:36:34 +02:00
|
|
|
if (!handle_debug_event(gdbctx, TRUE))
|
2020-04-04 11:30:16 +02:00
|
|
|
break;
|
2020-04-01 17:03:26 +02:00
|
|
|
ContinueDebugEvent(gdbctx->de.dwProcessId, gdbctx->de.dwThreadId, DBG_CONTINUE);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void detach_debuggee(struct gdb_context* gdbctx, BOOL kill)
|
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
handle_step_or_continue(gdbctx, -1, FALSE, -1);
|
|
|
|
|
|
|
|
if (gdbctx->de.dwDebugEventCode)
|
|
|
|
ContinueDebugEvent(gdbctx->de.dwProcessId, gdbctx->de.dwThreadId, DBG_CONTINUE);
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
if (!kill)
|
|
|
|
DebugActiveProcessStop(gdbctx->process->pid);
|
2004-06-04 02:59:16 +02:00
|
|
|
dbg_del_process(gdbctx->process);
|
2002-07-20 22:29:09 +02:00
|
|
|
gdbctx->process = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_process_info(struct gdb_context* gdbctx, char* buffer, size_t len)
|
|
|
|
{
|
2006-12-20 14:10:47 +01:00
|
|
|
DWORD status;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
if (!GetExitCodeProcess(gdbctx->process->handle, &status))
|
|
|
|
{
|
|
|
|
strcpy(buffer, "Unknown process");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (status == STILL_ACTIVE)
|
|
|
|
{
|
|
|
|
strcpy(buffer, "Running");
|
|
|
|
}
|
|
|
|
else
|
2022-02-07 08:40:49 +01:00
|
|
|
snprintf(buffer, len, "Terminated (%lu)", status);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
switch (GetPriorityClass(gdbctx->process->handle))
|
|
|
|
{
|
|
|
|
case 0: break;
|
|
|
|
case ABOVE_NORMAL_PRIORITY_CLASS: strcat(buffer, ", above normal priority"); break;
|
2019-12-10 09:29:40 +01:00
|
|
|
case BELOW_NORMAL_PRIORITY_CLASS: strcat(buffer, ", below normal priority"); break;
|
2002-07-20 22:29:09 +02:00
|
|
|
case HIGH_PRIORITY_CLASS: strcat(buffer, ", high priority"); break;
|
|
|
|
case IDLE_PRIORITY_CLASS: strcat(buffer, ", idle priority"); break;
|
|
|
|
case NORMAL_PRIORITY_CLASS: strcat(buffer, ", normal priority"); break;
|
|
|
|
case REALTIME_PRIORITY_CLASS: strcat(buffer, ", realtime priority"); break;
|
|
|
|
}
|
|
|
|
strcat(buffer, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_thread_info(struct gdb_context* gdbctx, unsigned tid,
|
|
|
|
char* buffer, size_t len)
|
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_thread* thd;
|
2006-12-20 14:10:47 +01:00
|
|
|
DWORD status;
|
2002-07-20 22:29:09 +02:00
|
|
|
int prio;
|
|
|
|
|
|
|
|
/* FIXME: use the size of buffer */
|
2004-06-04 02:59:16 +02:00
|
|
|
thd = dbg_get_thread(gdbctx->process, tid);
|
2002-07-20 22:29:09 +02:00
|
|
|
if (thd == NULL)
|
|
|
|
{
|
|
|
|
strcpy(buffer, "No information");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (GetExitCodeThread(thd->handle, &status))
|
|
|
|
{
|
|
|
|
if (status == STILL_ACTIVE)
|
|
|
|
{
|
|
|
|
/* FIXME: this is a bit brutal... some nicer way shall be found */
|
|
|
|
switch (status = SuspendThread(thd->handle))
|
|
|
|
{
|
|
|
|
case -1: break;
|
|
|
|
case 0: strcpy(buffer, "Running"); break;
|
2022-02-07 08:40:49 +01:00
|
|
|
default: snprintf(buffer, len, "Suspended (%lu)", status - 1);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
ResumeThread(thd->handle);
|
|
|
|
}
|
|
|
|
else
|
2022-02-07 08:40:49 +01:00
|
|
|
snprintf(buffer, len, "Terminated (exit code = %lu)", status);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(buffer, "Unknown threadID");
|
|
|
|
}
|
|
|
|
switch (prio = GetThreadPriority(thd->handle))
|
|
|
|
{
|
|
|
|
case THREAD_PRIORITY_ERROR_RETURN: break;
|
|
|
|
case THREAD_PRIORITY_ABOVE_NORMAL: strcat(buffer, ", priority +1 above normal"); break;
|
|
|
|
case THREAD_PRIORITY_BELOW_NORMAL: strcat(buffer, ", priority -1 below normal"); break;
|
|
|
|
case THREAD_PRIORITY_HIGHEST: strcat(buffer, ", priority +2 above normal"); break;
|
|
|
|
case THREAD_PRIORITY_LOWEST: strcat(buffer, ", priority -2 below normal"); break;
|
|
|
|
case THREAD_PRIORITY_IDLE: strcat(buffer, ", priority idle"); break;
|
|
|
|
case THREAD_PRIORITY_NORMAL: strcat(buffer, ", priority normal"); break;
|
|
|
|
case THREAD_PRIORITY_TIME_CRITICAL: strcat(buffer, ", priority time-critical"); break;
|
2003-02-11 23:06:19 +01:00
|
|
|
default: snprintf(buffer + strlen(buffer), len - strlen(buffer), ", priority = %d", prio);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
assert(strlen(buffer) < len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* =============================================== *
|
|
|
|
* P A C K E T U T I L S *
|
|
|
|
* =============================================== *
|
|
|
|
*/
|
|
|
|
|
2021-07-02 10:14:41 +02:00
|
|
|
static int addr_width(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
int sz = (gdbctx && gdbctx->process && gdbctx->process->be_cpu) ?
|
|
|
|
gdbctx->process->be_cpu->pointer_size : (int)sizeof(void*);
|
|
|
|
return sz * 2;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
enum packet_return {packet_error = 0x00, packet_ok = 0x01, packet_done = 0x02,
|
2021-11-23 16:11:00 +01:00
|
|
|
packet_send_buffer = 0x03, packet_last_f = 0x80};
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
static void packet_reply_hex_to(struct gdb_context* gdbctx, const void* src, int len)
|
|
|
|
{
|
2021-11-23 16:09:48 +01:00
|
|
|
reply_buffer_append_hex(&gdbctx->out_buf, src, len);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
2003-02-11 23:06:19 +01:00
|
|
|
static inline void packet_reply_hex_to_str(struct gdb_context* gdbctx, const char* src)
|
|
|
|
{
|
|
|
|
packet_reply_hex_to(gdbctx, src, strlen(src));
|
|
|
|
}
|
|
|
|
|
2021-10-04 14:16:23 +02:00
|
|
|
static void packet_reply_val(struct gdb_context* gdbctx, ULONG_PTR val, int len)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2021-11-23 16:09:48 +01:00
|
|
|
reply_buffer_append_uinthex(&gdbctx->out_buf, val, len);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
2021-11-19 14:41:24 +01:00
|
|
|
static const unsigned char gdb_special_chars_lookup_table[4] = {
|
|
|
|
/* The characters should be indexed by its value modulo table length. */
|
|
|
|
|
|
|
|
0x24, /* $: 001001|00 */
|
|
|
|
0x7D, /* }: 011111|01 */
|
|
|
|
0x2A, /* *: 001010|10 */
|
|
|
|
0x23 /* #: 001000|11 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline BOOL is_gdb_special_char(unsigned char val)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2021-11-19 14:41:24 +01:00
|
|
|
/* A note on the GDB special character scanning code:
|
|
|
|
*
|
|
|
|
* We cannot use strcspn() since we plan to transmit binary data in
|
|
|
|
* packet reply, which can contain NULL (0x00) bytes. We also don't want
|
|
|
|
* to slow down memory dump transfers. Therefore, we use a tiny lookup
|
|
|
|
* table that contains all the four special characters to speed up scanning.
|
|
|
|
*/
|
|
|
|
const size_t length = ARRAY_SIZE(gdb_special_chars_lookup_table);
|
|
|
|
return gdb_special_chars_lookup_table[val % length] == val;
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
static void packet_reply_add_data(struct gdb_context* gdbctx, const void* data, size_t len)
|
2021-11-19 14:41:24 +01:00
|
|
|
{
|
2021-11-23 16:10:01 +01:00
|
|
|
const unsigned char *ptr = data, *end = ptr + len, *curr;
|
2021-11-23 16:09:48 +01:00
|
|
|
unsigned char esc_seq[2];
|
2021-11-19 14:41:24 +01:00
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
while (ptr != end)
|
2021-11-19 14:41:24 +01:00
|
|
|
{
|
|
|
|
curr = ptr;
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
while (ptr != end && !is_gdb_special_char(*ptr))
|
2021-11-19 14:41:24 +01:00
|
|
|
ptr++;
|
|
|
|
|
2021-11-23 16:09:48 +01:00
|
|
|
reply_buffer_append(&gdbctx->out_buf, curr, ptr - curr);
|
2021-11-23 16:10:01 +01:00
|
|
|
if (ptr == end) break;
|
2021-11-19 14:41:24 +01:00
|
|
|
|
2021-11-23 16:09:48 +01:00
|
|
|
esc_seq[0] = 0x7D;
|
|
|
|
esc_seq[1] = 0x20 ^ *ptr++;
|
|
|
|
reply_buffer_append(&gdbctx->out_buf, esc_seq, 2);
|
2021-11-19 14:41:24 +01:00
|
|
|
}
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
static inline void packet_reply_add(struct gdb_context* gdbctx, const char* str)
|
|
|
|
{
|
|
|
|
packet_reply_add_data(gdbctx, str, strlen(str));
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
static void packet_reply_open(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
assert(gdbctx->out_curr_packet == -1);
|
2021-11-23 16:09:48 +01:00
|
|
|
reply_buffer_append(&gdbctx->out_buf, "$", 1);
|
|
|
|
gdbctx->out_curr_packet = gdbctx->out_buf.len;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void packet_reply_close(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
unsigned char cksum;
|
|
|
|
int plen;
|
|
|
|
|
2021-11-23 16:09:48 +01:00
|
|
|
plen = gdbctx->out_buf.len - gdbctx->out_curr_packet;
|
|
|
|
reply_buffer_append(&gdbctx->out_buf, "#", 1);
|
|
|
|
cksum = checksum(gdbctx->out_buf.base + gdbctx->out_curr_packet, plen);
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_hex_to(gdbctx, &cksum, 1);
|
|
|
|
gdbctx->out_curr_packet = -1;
|
|
|
|
}
|
|
|
|
|
2018-11-19 15:24:10 +01:00
|
|
|
static enum packet_return packet_reply(struct gdb_context* gdbctx, const char* packet)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
packet_reply_open(gdbctx);
|
|
|
|
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, packet);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
|
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_reply_error(struct gdb_context* gdbctx, int error)
|
|
|
|
{
|
|
|
|
packet_reply_open(gdbctx);
|
|
|
|
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "E");
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_val(gdbctx, error, 1);
|
|
|
|
|
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
|
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
|
2020-04-01 17:03:23 +02:00
|
|
|
static inline void packet_reply_register_hex_to(struct gdb_context* gdbctx, dbg_ctx_t* ctx, unsigned idx)
|
2012-05-20 09:45:26 +02:00
|
|
|
{
|
2018-06-13 23:34:01 +02:00
|
|
|
const struct gdb_register *cpu_register_map = gdbctx->process->be_cpu->gdb_register_map;
|
2020-04-03 15:35:51 +02:00
|
|
|
packet_reply_hex_to(gdbctx, cpu_register_ptr(gdbctx, ctx, idx), cpu_register_map[idx].length);
|
2012-05-20 09:45:26 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 16:11:08 +01:00
|
|
|
static void packet_reply_xfer(struct gdb_context* gdbctx, size_t off, size_t len, BOOL* more_p)
|
2021-11-23 16:10:01 +01:00
|
|
|
{
|
2021-11-23 16:11:08 +01:00
|
|
|
BOOL more;
|
2021-11-23 16:10:01 +01:00
|
|
|
size_t data_len, trunc_len;
|
|
|
|
|
|
|
|
packet_reply_open(gdbctx);
|
|
|
|
data_len = gdbctx->qxfer_buffer.len;
|
|
|
|
|
|
|
|
/* check if off + len would overflow */
|
2021-11-23 16:11:08 +01:00
|
|
|
more = off < data_len && off + len < data_len;
|
|
|
|
if (more)
|
2021-11-23 16:10:01 +01:00
|
|
|
packet_reply_add(gdbctx, "m");
|
|
|
|
else
|
|
|
|
packet_reply_add(gdbctx, "l");
|
|
|
|
|
|
|
|
if (off < data_len)
|
|
|
|
{
|
|
|
|
trunc_len = min(len, data_len - off);
|
|
|
|
packet_reply_add_data(gdbctx, gdbctx->qxfer_buffer.base + off, trunc_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
packet_reply_close(gdbctx);
|
2021-11-23 16:11:08 +01:00
|
|
|
|
|
|
|
*more_p = more;
|
2021-11-23 16:10:01 +01:00
|
|
|
}
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
/* =============================================== *
|
|
|
|
* P A C K E T H A N D L E R S *
|
|
|
|
* =============================================== *
|
|
|
|
*/
|
|
|
|
|
2020-04-04 11:30:14 +02:00
|
|
|
static void packet_reply_status_xpoints(struct gdb_context* gdbctx, struct dbg_thread *thread,
|
|
|
|
dbg_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
struct dbg_process *process = thread->process;
|
|
|
|
struct backend_cpu *cpu = process->be_cpu;
|
|
|
|
struct gdb_xpoint *x;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(x, &gdbctx->xpoint_list, struct gdb_xpoint, entry)
|
|
|
|
{
|
|
|
|
if (x->pid != process->pid || x->tid != thread->tid)
|
|
|
|
continue;
|
|
|
|
if (!cpu->is_watchpoint_set(ctx, x->value))
|
|
|
|
continue;
|
|
|
|
if (x->type == be_xpoint_watch_write)
|
|
|
|
{
|
|
|
|
packet_reply_add(gdbctx, "watch:");
|
2021-10-04 14:16:23 +02:00
|
|
|
packet_reply_val(gdbctx, (ULONG_PTR)x->addr, sizeof(x->addr));
|
2020-04-04 11:30:14 +02:00
|
|
|
packet_reply_add(gdbctx, ";");
|
|
|
|
}
|
|
|
|
if (x->type == be_xpoint_watch_read)
|
|
|
|
{
|
|
|
|
packet_reply_add(gdbctx, "rwatch:");
|
2021-10-04 14:16:23 +02:00
|
|
|
packet_reply_val(gdbctx, (ULONG_PTR)x->addr, sizeof(x->addr));
|
2020-04-04 11:30:14 +02:00
|
|
|
packet_reply_add(gdbctx, ";");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 17:37:42 +01:00
|
|
|
static void packet_reply_begin_stop_reply(struct gdb_context* gdbctx, unsigned char signal)
|
|
|
|
{
|
|
|
|
packet_reply_add(gdbctx, "T");
|
|
|
|
packet_reply_val(gdbctx, signal, 1);
|
|
|
|
|
|
|
|
/* We should always report the current thread ID for all stop replies.
|
|
|
|
* Otherwise, GDB complains with the following message:
|
|
|
|
*
|
|
|
|
* Warning: multi-threaded target stopped without sending a thread-id,
|
|
|
|
* using first non-exited thread
|
|
|
|
*/
|
|
|
|
packet_reply_add(gdbctx, "thread:");
|
|
|
|
packet_reply_val(gdbctx, gdbctx->de.dwThreadId, 4);
|
|
|
|
packet_reply_add(gdbctx, ";");
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
static enum packet_return packet_reply_status(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-04-01 17:03:24 +02:00
|
|
|
struct dbg_process *process = gdbctx->process;
|
2020-04-01 17:03:28 +02:00
|
|
|
struct dbg_thread *thread;
|
2020-04-01 17:03:24 +02:00
|
|
|
struct backend_cpu *backend;
|
|
|
|
dbg_ctx_t ctx;
|
|
|
|
size_t i;
|
|
|
|
|
2020-04-07 19:34:17 +02:00
|
|
|
switch (gdbctx->de.dwDebugEventCode)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-04-07 19:34:17 +02:00
|
|
|
default:
|
|
|
|
if (!process) return packet_error;
|
2020-04-01 17:03:24 +02:00
|
|
|
if (!(backend = process->be_cpu)) return packet_error;
|
2020-04-01 17:03:28 +02:00
|
|
|
if (!(thread = dbg_get_thread(process, gdbctx->de.dwThreadId)) ||
|
|
|
|
!backend->get_context(thread->handle, &ctx))
|
2020-04-01 17:03:24 +02:00
|
|
|
return packet_error;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-03-31 15:12:31 +02:00
|
|
|
packet_reply_open(gdbctx);
|
2021-11-16 17:37:42 +01:00
|
|
|
packet_reply_begin_stop_reply(gdbctx, signal_from_debug_event(&gdbctx->de));
|
2020-04-04 11:30:14 +02:00
|
|
|
packet_reply_status_xpoints(gdbctx, thread, &ctx);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-01 17:03:24 +02:00
|
|
|
for (i = 0; i < backend->gdb_num_regs; i++)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
packet_reply_val(gdbctx, i, 1);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, ":");
|
2020-04-01 17:03:24 +02:00
|
|
|
packet_reply_register_hex_to(gdbctx, &ctx, i);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, ";");
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
2020-03-31 15:12:31 +02:00
|
|
|
|
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
2020-04-07 19:34:17 +02:00
|
|
|
|
|
|
|
case EXIT_PROCESS_DEBUG_EVENT:
|
|
|
|
packet_reply_open(gdbctx);
|
|
|
|
packet_reply_add(gdbctx, "W");
|
|
|
|
packet_reply_val(gdbctx, gdbctx->de.u.ExitProcess.dwExitCode, 4);
|
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done | packet_last_f;
|
2021-07-13 06:36:34 +02:00
|
|
|
|
|
|
|
case LOAD_DLL_DEBUG_EVENT:
|
|
|
|
case UNLOAD_DLL_DEBUG_EVENT:
|
|
|
|
packet_reply_open(gdbctx);
|
2021-11-16 17:37:42 +01:00
|
|
|
packet_reply_begin_stop_reply(gdbctx, HOST_SIGTRAP);
|
2021-07-13 06:36:34 +02:00
|
|
|
packet_reply_add(gdbctx, "library:;");
|
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_last_signal(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
assert(gdbctx->in_packet_len == 0);
|
|
|
|
return packet_reply_status(gdbctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_continue(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
void *addr;
|
|
|
|
|
|
|
|
if (sscanf(gdbctx->in_packet, "%p", &addr) == 1)
|
|
|
|
FIXME("Continue at address %p not supported\n", addr);
|
|
|
|
|
|
|
|
handle_step_or_continue(gdbctx, gdbctx->exec_tid, FALSE, -1);
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
wait_for_debuggee(gdbctx);
|
|
|
|
return packet_reply_status(gdbctx);
|
|
|
|
}
|
|
|
|
|
2011-10-05 22:41:10 +02:00
|
|
|
static enum packet_return packet_verbose_cont(struct gdb_context* gdbctx)
|
2005-02-10 22:18:12 +01:00
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
char *buf = gdbctx->in_packet, *end = gdbctx->in_packet + gdbctx->in_packet_len;
|
2005-02-10 22:18:12 +01:00
|
|
|
|
2005-05-29 22:04:28 +02:00
|
|
|
if (gdbctx->in_packet[4] == '?')
|
|
|
|
{
|
2005-02-10 22:18:12 +01:00
|
|
|
packet_reply_open(gdbctx);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "vCont");
|
|
|
|
packet_reply_add(gdbctx, ";c");
|
|
|
|
packet_reply_add(gdbctx, ";C");
|
|
|
|
packet_reply_add(gdbctx, ";s");
|
|
|
|
packet_reply_add(gdbctx, ";S");
|
2005-02-10 22:18:12 +01:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
|
2020-04-01 17:03:27 +02:00
|
|
|
while (buf < end && (buf = memchr(buf + 1, ';', end - buf - 1)))
|
2005-05-29 22:04:28 +02:00
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
int tid = -1, sig = -1;
|
|
|
|
int action, n;
|
2005-02-10 22:18:12 +01:00
|
|
|
|
2020-04-01 17:03:27 +02:00
|
|
|
switch ((action = buf[1]))
|
2005-05-29 22:04:28 +02:00
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
default:
|
|
|
|
return packet_error;
|
|
|
|
case 'c':
|
|
|
|
case 's':
|
|
|
|
buf += 2;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
case 'S':
|
|
|
|
if (sscanf(buf, ";%*c%2x", &sig) <= 0 ||
|
2020-04-04 11:30:17 +02:00
|
|
|
sig != signal_from_debug_event(&gdbctx->de))
|
2005-05-29 22:04:28 +02:00
|
|
|
return packet_error;
|
2020-04-01 17:03:27 +02:00
|
|
|
buf += 4;
|
2005-02-10 22:18:12 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-04-01 17:03:27 +02:00
|
|
|
if (buf > end)
|
|
|
|
return packet_error;
|
|
|
|
if (buf < end && *buf == ':' && (n = sscanf(buf, ":%x", &tid)) <= 0)
|
|
|
|
return packet_error;
|
2005-02-10 22:18:12 +01:00
|
|
|
|
2020-04-01 17:03:27 +02:00
|
|
|
handle_step_or_continue(gdbctx, tid, action == 's' || action == 'S', sig);
|
|
|
|
}
|
2005-02-10 22:18:12 +01:00
|
|
|
|
|
|
|
wait_for_debuggee(gdbctx);
|
|
|
|
return packet_reply_status(gdbctx);
|
|
|
|
}
|
|
|
|
|
2011-10-05 22:41:10 +02:00
|
|
|
static enum packet_return packet_verbose(struct gdb_context* gdbctx)
|
|
|
|
{
|
2018-07-30 21:47:55 +02:00
|
|
|
if (gdbctx->in_packet_len >= 4 && !memcmp(gdbctx->in_packet, "Cont", 4))
|
2011-10-05 22:41:10 +02:00
|
|
|
{
|
2018-07-30 21:47:55 +02:00
|
|
|
return packet_verbose_cont(gdbctx);
|
2011-10-05 22:41:10 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 15:12:30 +02:00
|
|
|
if (gdbctx->in_packet_len == 14 && !memcmp(gdbctx->in_packet, "MustReplyEmpty", 14))
|
|
|
|
return packet_reply(gdbctx, "");
|
|
|
|
|
2011-10-05 22:41:10 +02:00
|
|
|
return packet_error;
|
2018-07-30 21:47:55 +02:00
|
|
|
}
|
2011-10-05 22:41:10 +02:00
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
static enum packet_return packet_continue_signal(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
void *addr;
|
|
|
|
int sig, n;
|
|
|
|
|
|
|
|
if ((n = sscanf(gdbctx->in_packet, "%x;%p", &sig, &addr)) == 2)
|
|
|
|
FIXME("Continue at address %p not supported\n", addr);
|
|
|
|
if (n < 1) return packet_error;
|
|
|
|
|
2020-04-04 11:30:17 +02:00
|
|
|
if (sig != signal_from_debug_event(&gdbctx->de))
|
2020-04-01 17:03:27 +02:00
|
|
|
{
|
|
|
|
ERR("Changing signals is not supported.\n");
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_error;
|
2020-04-01 17:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handle_step_or_continue(gdbctx, gdbctx->exec_tid, FALSE, sig);
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
wait_for_debuggee(gdbctx);
|
|
|
|
return packet_reply_status(gdbctx);
|
|
|
|
}
|
|
|
|
|
2020-04-04 11:30:14 +02:00
|
|
|
static enum packet_return packet_delete_breakpoint(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
struct dbg_process *process = gdbctx->process;
|
|
|
|
struct dbg_thread *thread;
|
|
|
|
struct backend_cpu *cpu;
|
|
|
|
struct gdb_xpoint *x;
|
|
|
|
dbg_ctx_t ctx;
|
|
|
|
char type;
|
|
|
|
void *addr;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (!process) return packet_error;
|
|
|
|
if (!(cpu = process->be_cpu)) return packet_error;
|
|
|
|
|
|
|
|
if (sscanf(gdbctx->in_packet, "%c,%p,%x", &type, &addr, &size) < 3)
|
|
|
|
return packet_error;
|
|
|
|
|
|
|
|
if (type == '0')
|
|
|
|
return packet_error;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(thread, &process->threads, struct dbg_thread, entry)
|
|
|
|
{
|
|
|
|
if (!cpu->get_context(thread->handle, &ctx))
|
|
|
|
continue;
|
|
|
|
if ((type == '1') && (x = gdb_find_xpoint(gdbctx, thread, be_xpoint_watch_exec, addr, size)))
|
|
|
|
gdbctx_delete_xpoint(gdbctx, thread, &ctx, x);
|
|
|
|
if ((type == '2' || type == '4') && (x = gdb_find_xpoint(gdbctx, thread, be_xpoint_watch_read, addr, size)))
|
|
|
|
gdbctx_delete_xpoint(gdbctx, thread, &ctx, x);
|
|
|
|
if ((type == '3' || type == '4') && (x = gdb_find_xpoint(gdbctx, thread, be_xpoint_watch_write, addr, size)))
|
|
|
|
gdbctx_delete_xpoint(gdbctx, thread, &ctx, x);
|
|
|
|
cpu->set_context(thread->handle, &ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((type == '1') && (x = gdb_find_xpoint(gdbctx, NULL, be_xpoint_watch_exec, addr, size)))
|
|
|
|
gdbctx_delete_xpoint(gdbctx, NULL, NULL, x);
|
|
|
|
while ((type == '2' || type == '4') && (x = gdb_find_xpoint(gdbctx, NULL, be_xpoint_watch_read, addr, size)))
|
|
|
|
gdbctx_delete_xpoint(gdbctx, NULL, NULL, x);
|
|
|
|
while ((type == '3' || type == '4') && (x = gdb_find_xpoint(gdbctx, NULL, be_xpoint_watch_write, addr, size)))
|
|
|
|
gdbctx_delete_xpoint(gdbctx, NULL, NULL, x);
|
|
|
|
|
|
|
|
return packet_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_insert_breakpoint(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
struct dbg_process *process = gdbctx->process;
|
|
|
|
struct dbg_thread *thread;
|
|
|
|
struct backend_cpu *cpu;
|
|
|
|
dbg_ctx_t ctx;
|
|
|
|
char type;
|
|
|
|
void *addr;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (!process) return packet_error;
|
|
|
|
if (!(cpu = process->be_cpu)) return packet_error;
|
|
|
|
|
|
|
|
if (memchr(gdbctx->in_packet, ';', gdbctx->in_packet_len))
|
|
|
|
{
|
|
|
|
FIXME("breakpoint commands not supported\n");
|
|
|
|
return packet_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(gdbctx->in_packet, "%c,%p,%x", &type, &addr, &size) < 3)
|
|
|
|
return packet_error;
|
|
|
|
|
|
|
|
if (type == '0')
|
|
|
|
return packet_error;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(thread, &process->threads, struct dbg_thread, entry)
|
|
|
|
{
|
|
|
|
if (!cpu->get_context(thread->handle, &ctx))
|
|
|
|
continue;
|
|
|
|
if (type == '1')
|
|
|
|
gdbctx_insert_xpoint(gdbctx, thread, &ctx, be_xpoint_watch_exec, addr, size);
|
|
|
|
if (type == '2' || type == '4')
|
|
|
|
gdbctx_insert_xpoint(gdbctx, thread, &ctx, be_xpoint_watch_read, addr, size);
|
|
|
|
if (type == '3' || type == '4')
|
|
|
|
gdbctx_insert_xpoint(gdbctx, thread, &ctx, be_xpoint_watch_write, addr, size);
|
|
|
|
cpu->set_context(thread->handle, &ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return packet_ok;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
static enum packet_return packet_detach(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
detach_debuggee(gdbctx, FALSE);
|
|
|
|
return packet_ok | packet_last_f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_read_registers(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-04-01 17:03:25 +02:00
|
|
|
struct dbg_thread *thread = dbg_thread_from_tid(gdbctx, gdbctx->other_tid);
|
2020-04-01 17:03:23 +02:00
|
|
|
struct backend_cpu *backend;
|
2018-06-13 00:53:18 +02:00
|
|
|
dbg_ctx_t ctx;
|
2020-04-01 17:03:23 +02:00
|
|
|
size_t i;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-01 17:03:23 +02:00
|
|
|
if (!thread) return packet_error;
|
|
|
|
if (!thread->process) return packet_error;
|
|
|
|
if (!(backend = thread->process->be_cpu)) return packet_error;
|
|
|
|
|
|
|
|
if (!backend->get_context(thread->handle, &ctx))
|
|
|
|
return packet_error;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2003-04-19 23:27:47 +02:00
|
|
|
packet_reply_open(gdbctx);
|
2020-04-01 17:03:23 +02:00
|
|
|
for (i = 0; i < backend->gdb_num_regs; i++)
|
|
|
|
packet_reply_register_hex_to(gdbctx, &ctx, i);
|
2018-06-13 23:34:01 +02:00
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_write_registers(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-04-01 17:03:25 +02:00
|
|
|
struct dbg_thread *thread = dbg_thread_from_tid(gdbctx, gdbctx->other_tid);
|
2020-04-01 17:03:23 +02:00
|
|
|
struct backend_cpu *backend;
|
2018-06-13 00:53:18 +02:00
|
|
|
dbg_ctx_t ctx;
|
2020-04-01 17:03:23 +02:00
|
|
|
const char *ptr;
|
|
|
|
size_t i;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-01 17:03:23 +02:00
|
|
|
if (!thread) return packet_error;
|
|
|
|
if (!thread->process) return packet_error;
|
|
|
|
if (!(backend = thread->process->be_cpu)) return packet_error;
|
|
|
|
|
|
|
|
if (!backend->get_context(thread->handle, &ctx))
|
|
|
|
return packet_error;
|
|
|
|
|
|
|
|
if (gdbctx->in_packet_len < backend->gdb_num_regs * 2)
|
|
|
|
return packet_error;
|
2003-04-19 23:27:47 +02:00
|
|
|
|
2012-05-20 09:45:26 +02:00
|
|
|
ptr = gdbctx->in_packet;
|
2020-04-01 17:03:23 +02:00
|
|
|
for (i = 0; i < backend->gdb_num_regs; i++)
|
|
|
|
cpu_register_hex_from(gdbctx, &ctx, i, &ptr);
|
2018-06-13 00:53:17 +02:00
|
|
|
|
2020-04-01 17:03:23 +02:00
|
|
|
if (!backend->set_context(thread->handle, &ctx))
|
2003-04-19 23:27:47 +02:00
|
|
|
{
|
2022-02-07 08:40:49 +01:00
|
|
|
ERR("Failed to set context for tid %04lx, error %lu\n", thread->tid, GetLastError());
|
2003-04-19 23:27:47 +02:00
|
|
|
return packet_error;
|
|
|
|
}
|
2020-04-01 17:03:23 +02:00
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_kill(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
detach_debuggee(gdbctx, TRUE);
|
2020-03-31 15:12:31 +02:00
|
|
|
return packet_ok | packet_last_f;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_thread(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
switch (gdbctx->in_packet[0])
|
|
|
|
{
|
|
|
|
case 'c':
|
2020-04-01 17:03:25 +02:00
|
|
|
if (sscanf(gdbctx->in_packet, "c%x", &gdbctx->exec_tid) == 1)
|
|
|
|
return packet_ok;
|
|
|
|
return packet_error;
|
2002-07-20 22:29:09 +02:00
|
|
|
case 'g':
|
2020-04-01 17:03:25 +02:00
|
|
|
if (sscanf(gdbctx->in_packet, "g%x", &gdbctx->other_tid) == 1)
|
|
|
|
return packet_ok;
|
|
|
|
return packet_error;
|
2002-07-20 22:29:09 +02:00
|
|
|
default:
|
2018-07-30 21:47:53 +02:00
|
|
|
FIXME("Unknown thread sub-command %c\n", gdbctx->in_packet[0]);
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_read_memory(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
char *addr;
|
2006-06-13 14:16:06 +02:00
|
|
|
unsigned int len, blk_len, nread;
|
2002-07-20 22:29:09 +02:00
|
|
|
char buffer[32];
|
2006-06-30 21:37:38 +02:00
|
|
|
SIZE_T r = 0;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
if (sscanf(gdbctx->in_packet, "%p,%x", &addr, &len) != 2) return packet_error;
|
2004-08-02 20:25:58 +02:00
|
|
|
if (len <= 0) return packet_error;
|
2018-07-30 21:47:53 +02:00
|
|
|
TRACE("Read %u bytes at %p\n", len, addr);
|
2004-08-02 20:25:58 +02:00
|
|
|
for (nread = 0; nread < len; nread += r, addr += r)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
blk_len = min(sizeof(buffer), len - nread);
|
2018-05-18 15:51:22 +02:00
|
|
|
if (!gdbctx->process->process_io->read(gdbctx->process->handle, addr,
|
|
|
|
buffer, blk_len, &r) || r == 0)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
/* fail at first address, return error */
|
2021-10-04 11:27:43 +02:00
|
|
|
if (nread == 0) return packet_reply_error(gdbctx, HOST_EFAULT );
|
2002-07-20 22:29:09 +02:00
|
|
|
/* something has already been read, return partial information */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nread == 0) packet_reply_open(gdbctx);
|
|
|
|
packet_reply_hex_to(gdbctx, buffer, r);
|
|
|
|
}
|
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_write_memory(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
char* addr;
|
2006-06-13 14:16:06 +02:00
|
|
|
unsigned int len, blk_len;
|
2002-07-20 22:29:09 +02:00
|
|
|
char* ptr;
|
|
|
|
char buffer[32];
|
2006-06-30 21:37:38 +02:00
|
|
|
SIZE_T w;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
ptr = memchr(gdbctx->in_packet, ':', gdbctx->in_packet_len);
|
|
|
|
if (ptr == NULL)
|
|
|
|
{
|
2018-07-30 21:47:53 +02:00
|
|
|
ERR("Cannot find ':' in %s\n", debugstr_an(gdbctx->in_packet, gdbctx->in_packet_len));
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_error;
|
|
|
|
}
|
|
|
|
*ptr++ = '\0';
|
|
|
|
|
|
|
|
if (sscanf(gdbctx->in_packet, "%p,%x", &addr, &len) != 2)
|
|
|
|
{
|
2018-07-30 21:47:53 +02:00
|
|
|
ERR("Failed to parse %s\n", debugstr_a(gdbctx->in_packet));
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_error;
|
|
|
|
}
|
|
|
|
if (ptr - gdbctx->in_packet + len * 2 != gdbctx->in_packet_len)
|
|
|
|
{
|
2018-07-30 21:47:53 +02:00
|
|
|
ERR("Length %u does not match packet length %u\n",
|
|
|
|
(int)(ptr - gdbctx->in_packet) + len * 2, gdbctx->in_packet_len);
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_error;
|
|
|
|
}
|
2018-07-30 21:47:53 +02:00
|
|
|
TRACE("Write %u bytes at %p\n", len, addr);
|
2002-07-20 22:29:09 +02:00
|
|
|
while (len > 0)
|
|
|
|
{
|
|
|
|
blk_len = min(sizeof(buffer), len);
|
|
|
|
hex_from(buffer, ptr, blk_len);
|
2005-05-24 13:46:25 +02:00
|
|
|
if (!gdbctx->process->process_io->write(gdbctx->process->handle, addr, buffer, blk_len, &w) ||
|
|
|
|
w != blk_len)
|
|
|
|
break;
|
|
|
|
addr += blk_len;
|
|
|
|
len -= blk_len;
|
|
|
|
ptr += blk_len;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
return packet_ok; /* FIXME: error while writing ? */
|
|
|
|
}
|
|
|
|
|
2008-02-01 21:26:47 +01:00
|
|
|
static enum packet_return packet_read_register(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-04-01 17:03:25 +02:00
|
|
|
struct dbg_thread *thread = dbg_thread_from_tid(gdbctx, gdbctx->other_tid);
|
2020-04-01 17:03:23 +02:00
|
|
|
struct backend_cpu *backend;
|
2018-06-13 00:53:18 +02:00
|
|
|
dbg_ctx_t ctx;
|
2020-04-01 17:03:23 +02:00
|
|
|
size_t reg;
|
2008-02-01 21:26:47 +01:00
|
|
|
|
2020-04-01 17:03:23 +02:00
|
|
|
if (!thread) return packet_error;
|
|
|
|
if (!thread->process) return packet_error;
|
|
|
|
if (!(backend = thread->process->be_cpu)) return packet_error;
|
|
|
|
|
|
|
|
if (!backend->get_context(thread->handle, &ctx))
|
2008-02-01 21:26:47 +01:00
|
|
|
return packet_error;
|
2020-04-01 17:03:23 +02:00
|
|
|
|
2021-10-04 15:19:20 +02:00
|
|
|
if (sscanf(gdbctx->in_packet, "%Ix", ®) != 1)
|
2020-04-01 17:03:23 +02:00
|
|
|
return packet_error;
|
|
|
|
if (reg >= backend->gdb_num_regs)
|
2008-02-01 21:26:47 +01:00
|
|
|
{
|
2021-10-04 15:19:20 +02:00
|
|
|
WARN("Unhandled register %Iu\n", reg);
|
2020-04-01 17:03:23 +02:00
|
|
|
return packet_error;
|
2008-02-01 21:26:47 +01:00
|
|
|
}
|
2018-07-30 21:47:53 +02:00
|
|
|
|
2021-11-26 17:30:28 +01:00
|
|
|
TRACE("%Iu => %I64x\n", reg, cpu_register(gdbctx, &ctx, reg));
|
2018-07-30 21:47:53 +02:00
|
|
|
|
2012-05-22 21:52:03 +02:00
|
|
|
packet_reply_open(gdbctx);
|
2020-04-01 17:03:23 +02:00
|
|
|
packet_reply_register_hex_to(gdbctx, &ctx, reg);
|
2008-02-01 21:26:47 +01:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
static enum packet_return packet_write_register(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-04-01 17:03:25 +02:00
|
|
|
struct dbg_thread *thread = dbg_thread_from_tid(gdbctx, gdbctx->other_tid);
|
2020-04-01 17:03:23 +02:00
|
|
|
struct backend_cpu *backend;
|
2018-06-13 00:53:18 +02:00
|
|
|
dbg_ctx_t ctx;
|
2020-04-01 17:03:23 +02:00
|
|
|
size_t reg;
|
|
|
|
char *ptr;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-01 17:03:23 +02:00
|
|
|
if (!thread) return packet_error;
|
|
|
|
if (!thread->process) return packet_error;
|
|
|
|
if (!(backend = thread->process->be_cpu)) return packet_error;
|
|
|
|
|
|
|
|
if (!backend->get_context(thread->handle, &ctx))
|
|
|
|
return packet_error;
|
|
|
|
|
|
|
|
if (!(ptr = strchr(gdbctx->in_packet, '=')))
|
|
|
|
return packet_error;
|
|
|
|
*ptr++ = '\0';
|
|
|
|
|
2021-10-04 15:19:20 +02:00
|
|
|
if (sscanf(gdbctx->in_packet, "%Ix", ®) != 1)
|
2020-04-01 17:03:23 +02:00
|
|
|
return packet_error;
|
|
|
|
if (reg >= backend->gdb_num_regs)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
/* FIXME: if just the reg is above cpu_num_regs, don't tell gdb
|
|
|
|
* it wouldn't matter too much, and it fakes our support for all regs
|
|
|
|
*/
|
2021-10-04 15:19:20 +02:00
|
|
|
WARN("Unhandled register %Iu\n", reg);
|
2020-04-01 17:03:23 +02:00
|
|
|
return packet_ok;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
2018-07-30 21:47:53 +02:00
|
|
|
|
2021-10-04 15:19:20 +02:00
|
|
|
TRACE("%Iu <= %s\n", reg, debugstr_an(ptr, (int)(gdbctx->in_packet_len - (ptr - gdbctx->in_packet))));
|
2003-04-19 23:27:47 +02:00
|
|
|
|
2020-04-01 17:03:23 +02:00
|
|
|
cpu_register_hex_from(gdbctx, &ctx, reg, (const char**)&ptr);
|
|
|
|
if (!backend->set_context(thread->handle, &ctx))
|
2003-04-19 23:27:47 +02:00
|
|
|
{
|
2022-02-07 08:40:49 +01:00
|
|
|
ERR("Failed to set context for tid %04lx, error %lu\n", thread->tid, GetLastError());
|
2003-04-19 23:27:47 +02:00
|
|
|
return packet_error;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void packet_query_monitor_wnd_helper(struct gdb_context* gdbctx, HWND hWnd, int indent)
|
|
|
|
{
|
|
|
|
char buffer[128];
|
|
|
|
char clsName[128];
|
|
|
|
char wndName[128];
|
|
|
|
HWND child;
|
|
|
|
|
|
|
|
do {
|
2009-12-09 18:14:07 +01:00
|
|
|
if (!GetClassNameA(hWnd, clsName, sizeof(clsName)))
|
2002-07-20 22:29:09 +02:00
|
|
|
strcpy(clsName, "-- Unknown --");
|
2009-12-09 18:14:07 +01:00
|
|
|
if (!GetWindowTextA(hWnd, wndName, sizeof(wndName)))
|
2002-07-20 22:29:09 +02:00
|
|
|
strcpy(wndName, "-- Empty --");
|
|
|
|
|
|
|
|
packet_reply_open(gdbctx);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "O");
|
2006-12-20 14:17:27 +01:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
2022-02-07 08:40:49 +01:00
|
|
|
"%*s%04Ix%*s%-17.17s %08lx %0*Ix %.14s\n",
|
2006-12-20 14:17:27 +01:00
|
|
|
indent, "", (ULONG_PTR)hWnd, 13 - indent, "",
|
2009-12-09 18:14:07 +01:00
|
|
|
clsName, GetWindowLongW(hWnd, GWL_STYLE),
|
2021-07-02 10:14:41 +02:00
|
|
|
addr_width(gdbctx), (ULONG_PTR)GetWindowLongPtrW(hWnd, GWLP_WNDPROC),
|
2009-12-12 12:19:29 +01:00
|
|
|
wndName);
|
2003-02-11 23:06:19 +01:00
|
|
|
packet_reply_hex_to_str(gdbctx, buffer);
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
|
|
|
|
if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
|
|
|
|
packet_query_monitor_wnd_helper(gdbctx, child, indent + 1);
|
|
|
|
} while ((hWnd = GetWindow(hWnd, GW_HWNDNEXT)) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void packet_query_monitor_wnd(struct gdb_context* gdbctx, int len, const char* str)
|
|
|
|
{
|
|
|
|
char buffer[128];
|
|
|
|
|
|
|
|
/* we do the output in several 'O' packets, with the last one being just OK for
|
|
|
|
* marking the end of the output */
|
|
|
|
packet_reply_open(gdbctx);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "O");
|
2003-02-11 23:06:19 +01:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"%-16.16s %-17.17s %-8.8s %s\n",
|
|
|
|
"hwnd", "Class Name", " Style", " WndProc Text");
|
|
|
|
packet_reply_hex_to_str(gdbctx, buffer);
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
|
|
|
|
/* FIXME: could also add a pmt to this command in str... */
|
|
|
|
packet_query_monitor_wnd_helper(gdbctx, GetDesktopWindow(), 0);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply(gdbctx, "OK");
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void packet_query_monitor_process(struct gdb_context* gdbctx, int len, const char* str)
|
|
|
|
{
|
|
|
|
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
2016-10-02 07:40:36 +02:00
|
|
|
char buffer[31+MAX_PATH];
|
2002-07-20 22:29:09 +02:00
|
|
|
char deco;
|
|
|
|
PROCESSENTRY32 entry;
|
|
|
|
BOOL ok;
|
|
|
|
|
|
|
|
if (snap == INVALID_HANDLE_VALUE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry.dwSize = sizeof(entry);
|
2004-06-04 02:59:16 +02:00
|
|
|
ok = Process32First(snap, &entry);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
/* we do the output in several 'O' packets, with the last one being just OK for
|
|
|
|
* marking the end of the output */
|
|
|
|
|
|
|
|
packet_reply_open(gdbctx);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "O");
|
2003-02-11 23:06:19 +01:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
" %-8.8s %-8.8s %-8.8s %s\n",
|
2004-06-04 02:59:16 +02:00
|
|
|
"pid", "threads", "parent", "executable");
|
2003-02-11 23:06:19 +01:00
|
|
|
packet_reply_hex_to_str(gdbctx, buffer);
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
|
|
|
|
while (ok)
|
|
|
|
{
|
|
|
|
deco = ' ';
|
|
|
|
if (entry.th32ProcessID == gdbctx->process->pid) deco = '>';
|
|
|
|
packet_reply_open(gdbctx);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "O");
|
2003-02-11 23:06:19 +01:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
2022-02-07 08:40:49 +01:00
|
|
|
"%c%08lx %-8ld %08lx '%s'\n",
|
2003-02-11 23:06:19 +01:00
|
|
|
deco, entry.th32ProcessID, entry.cntThreads,
|
|
|
|
entry.th32ParentProcessID, entry.szExeFile);
|
|
|
|
packet_reply_hex_to_str(gdbctx, buffer);
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
ok = Process32Next(snap, &entry);
|
|
|
|
}
|
|
|
|
CloseHandle(snap);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply(gdbctx, "OK");
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void packet_query_monitor_mem(struct gdb_context* gdbctx, int len, const char* str)
|
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
char* addr = 0;
|
2003-10-09 06:39:01 +02:00
|
|
|
const char* state;
|
|
|
|
const char* type;
|
2002-07-20 22:29:09 +02:00
|
|
|
char prot[3+1];
|
|
|
|
char buffer[128];
|
|
|
|
|
|
|
|
/* we do the output in several 'O' packets, with the last one being just OK for
|
|
|
|
* marking the end of the output */
|
|
|
|
packet_reply_open(gdbctx);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "O");
|
2003-02-11 23:06:19 +01:00
|
|
|
packet_reply_hex_to_str(gdbctx, "Address Size State Type RWX\n");
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
|
|
|
|
while (VirtualQueryEx(gdbctx->process->handle, addr, &mbi, sizeof(mbi)) >= sizeof(mbi))
|
|
|
|
{
|
|
|
|
switch (mbi.State)
|
|
|
|
{
|
|
|
|
case MEM_COMMIT: state = "commit "; break;
|
|
|
|
case MEM_FREE: state = "free "; break;
|
|
|
|
case MEM_RESERVE: state = "reserve"; break;
|
|
|
|
default: state = "??? "; break;
|
|
|
|
}
|
|
|
|
if (mbi.State != MEM_FREE)
|
|
|
|
{
|
|
|
|
switch (mbi.Type)
|
|
|
|
{
|
|
|
|
case MEM_IMAGE: type = "image "; break;
|
|
|
|
case MEM_MAPPED: type = "mapped "; break;
|
|
|
|
case MEM_PRIVATE: type = "private"; break;
|
|
|
|
case 0: type = " "; break;
|
|
|
|
default: type = "??? "; break;
|
|
|
|
}
|
|
|
|
memset(prot, ' ' , sizeof(prot)-1);
|
|
|
|
prot[sizeof(prot)-1] = '\0';
|
2021-07-02 09:49:25 +02:00
|
|
|
if (mbi.AllocationProtect & (PAGE_READONLY|PAGE_READWRITE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_WRITECOPY))
|
2002-07-20 22:29:09 +02:00
|
|
|
prot[0] = 'R';
|
|
|
|
if (mbi.AllocationProtect & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE))
|
|
|
|
prot[1] = 'W';
|
|
|
|
if (mbi.AllocationProtect & (PAGE_WRITECOPY|PAGE_EXECUTE_WRITECOPY))
|
|
|
|
prot[1] = 'C';
|
2021-07-02 09:49:25 +02:00
|
|
|
if (mbi.AllocationProtect & (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY))
|
2002-07-20 22:29:09 +02:00
|
|
|
prot[2] = 'X';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = "";
|
|
|
|
prot[0] = '\0';
|
|
|
|
}
|
|
|
|
packet_reply_open(gdbctx);
|
2021-11-26 17:30:16 +01:00
|
|
|
snprintf(buffer, sizeof(buffer), "%0*Ix %0*Ix %s %s %s\n",
|
2021-07-02 10:14:41 +02:00
|
|
|
addr_width(gdbctx), (DWORD_PTR)addr,
|
|
|
|
addr_width(gdbctx), mbi.RegionSize, state, type, prot);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "O");
|
2003-02-11 23:06:19 +01:00
|
|
|
packet_reply_hex_to_str(gdbctx, buffer);
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
|
|
|
|
if (addr + mbi.RegionSize < addr) /* wrap around ? */
|
|
|
|
break;
|
|
|
|
addr += mbi.RegionSize;
|
|
|
|
}
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply(gdbctx, "OK");
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct query_detail
|
|
|
|
{
|
|
|
|
int with_arg;
|
|
|
|
const char* name;
|
|
|
|
size_t len;
|
|
|
|
void (*handler)(struct gdb_context*, int, const char*);
|
|
|
|
} query_details[] =
|
|
|
|
{
|
|
|
|
{0, "wnd", 3, packet_query_monitor_wnd},
|
|
|
|
{0, "window", 6, packet_query_monitor_wnd},
|
|
|
|
{0, "proc", 4, packet_query_monitor_process},
|
|
|
|
{0, "process", 7, packet_query_monitor_process},
|
|
|
|
{0, "mem", 3, packet_query_monitor_mem},
|
|
|
|
{0, NULL, 0, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum packet_return packet_query_remote_command(struct gdb_context* gdbctx,
|
|
|
|
const char* hxcmd, size_t len)
|
|
|
|
{
|
|
|
|
char buffer[128];
|
|
|
|
struct query_detail* qd;
|
|
|
|
|
|
|
|
assert((len & 1) == 0 && len < 2 * sizeof(buffer));
|
|
|
|
len /= 2;
|
|
|
|
hex_from(buffer, hxcmd, len);
|
|
|
|
|
2012-07-27 14:09:40 +02:00
|
|
|
for (qd = query_details; qd->name != NULL; qd++)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
if (len < qd->len || strncmp(buffer, qd->name, qd->len) != 0) continue;
|
|
|
|
if (!qd->with_arg && len != qd->len) continue;
|
|
|
|
|
|
|
|
(qd->handler)(gdbctx, len - qd->len, buffer + qd->len);
|
|
|
|
return packet_done;
|
|
|
|
}
|
2021-10-04 11:27:43 +02:00
|
|
|
return packet_reply_error(gdbctx, HOST_EINVAL );
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
2020-04-03 15:35:45 +02:00
|
|
|
static BOOL CALLBACK packet_query_libraries_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
|
|
|
|
{
|
|
|
|
struct gdb_context* gdbctx = ctx;
|
2021-11-23 16:10:01 +01:00
|
|
|
struct reply_buffer* reply = &gdbctx->qxfer_buffer;
|
2020-04-03 15:35:45 +02:00
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
IMAGE_SECTION_HEADER *sec;
|
|
|
|
IMAGE_DOS_HEADER *dos = NULL;
|
|
|
|
IMAGE_NT_HEADERS *nth = NULL;
|
|
|
|
IMAGEHLP_MODULE64 mod;
|
|
|
|
SIZE_T size, i;
|
|
|
|
BOOL is_wow64;
|
|
|
|
char buffer[0x400];
|
|
|
|
|
|
|
|
mod.SizeOfStruct = sizeof(mod);
|
|
|
|
SymGetModuleInfo64(gdbctx->process->handle, base, &mod);
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<library name=\"");
|
2020-04-03 15:35:45 +02:00
|
|
|
if (strcmp(mod.LoadedImageName, "[vdso].so") == 0)
|
2021-11-23 16:10:49 +01:00
|
|
|
reply_buffer_append_xmlstr(reply, "linux-vdso.so.1");
|
2020-04-03 15:35:45 +02:00
|
|
|
else if (mod.LoadedImageName[0] == '/')
|
2021-11-23 16:10:49 +01:00
|
|
|
reply_buffer_append_xmlstr(reply, mod.LoadedImageName);
|
2020-04-03 15:35:45 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
ANSI_STRING ansi_name;
|
|
|
|
char *unix_path, *tmp;
|
|
|
|
|
|
|
|
RtlInitAnsiString(&ansi_name, mod.LoadedImageName);
|
|
|
|
RtlAnsiStringToUnicodeString(&nt_name, &ansi_name, TRUE);
|
|
|
|
|
|
|
|
if ((unix_path = wine_get_unix_file_name(nt_name.Buffer)))
|
|
|
|
{
|
|
|
|
if (IsWow64Process(gdbctx->process->handle, &is_wow64) &&
|
|
|
|
is_wow64 && (tmp = strstr(unix_path, "system32")))
|
|
|
|
memcpy(tmp, "syswow64", 8);
|
2021-11-23 16:10:49 +01:00
|
|
|
reply_buffer_append_xmlstr(reply, unix_path);
|
2020-04-03 15:35:45 +02:00
|
|
|
}
|
|
|
|
else
|
2021-11-23 16:10:49 +01:00
|
|
|
reply_buffer_append_xmlstr(reply, mod.LoadedImageName);
|
2020-04-03 15:35:45 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_path);
|
|
|
|
RtlFreeUnicodeString(&nt_name);
|
|
|
|
}
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "\">");
|
2020-04-03 15:35:45 +02:00
|
|
|
|
|
|
|
size = sizeof(buffer);
|
|
|
|
if (VirtualQueryEx(gdbctx->process->handle, (void *)(UINT_PTR)mod.BaseOfImage, &mbi, sizeof(mbi)) >= sizeof(mbi) &&
|
|
|
|
mbi.Type == MEM_IMAGE && mbi.State != MEM_FREE)
|
|
|
|
{
|
|
|
|
if (ReadProcessMemory(gdbctx->process->handle, (void *)(UINT_PTR)mod.BaseOfImage, buffer, size, &size) &&
|
|
|
|
size >= sizeof(IMAGE_DOS_HEADER))
|
|
|
|
dos = (IMAGE_DOS_HEADER *)buffer;
|
|
|
|
|
|
|
|
if (dos && dos->e_magic == IMAGE_DOS_SIGNATURE && dos->e_lfanew < size)
|
|
|
|
nth = (IMAGE_NT_HEADERS *)(buffer + dos->e_lfanew);
|
|
|
|
|
|
|
|
if (nth && memcmp(&nth->Signature, "PE\0\0", 4))
|
|
|
|
nth = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nth) memset(buffer, 0, sizeof(buffer));
|
|
|
|
|
|
|
|
/* if the module is not PE we have cleared buffer with 0, this makes
|
|
|
|
* the following computation valid in all cases. */
|
|
|
|
dos = (IMAGE_DOS_HEADER *)buffer;
|
|
|
|
nth = (IMAGE_NT_HEADERS *)(buffer + dos->e_lfanew);
|
|
|
|
if (IsWow64Process(gdbctx->process->handle, &is_wow64) && is_wow64)
|
|
|
|
sec = IMAGE_FIRST_SECTION((IMAGE_NT_HEADERS32 *)nth);
|
|
|
|
else
|
|
|
|
sec = IMAGE_FIRST_SECTION((IMAGE_NT_HEADERS64 *)nth);
|
|
|
|
|
|
|
|
for (i = 0; i < max(nth->FileHeader.NumberOfSections, 1); ++i)
|
|
|
|
{
|
|
|
|
if ((char *)(sec + i) >= buffer + size) break;
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<segment address=\"0x");
|
|
|
|
reply_buffer_append_uinthex(reply, mod.BaseOfImage + sec[i].VirtualAddress, sizeof(ULONG_PTR));
|
|
|
|
reply_buffer_append_str(reply, "\"/>");
|
2020-04-03 15:35:45 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "</library>");
|
2020-04-03 15:35:45 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
static enum packet_return packet_query_libraries(struct gdb_context* gdbctx)
|
2020-04-03 15:35:45 +02:00
|
|
|
{
|
2021-11-23 16:10:01 +01:00
|
|
|
struct reply_buffer* reply = &gdbctx->qxfer_buffer;
|
2020-04-03 15:35:45 +02:00
|
|
|
BOOL opt;
|
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
if (!gdbctx->process) return packet_error;
|
|
|
|
|
|
|
|
if (gdbctx->qxfer_object_annex[0])
|
|
|
|
return packet_reply_error(gdbctx, 0);
|
|
|
|
|
2020-04-03 15:35:45 +02:00
|
|
|
/* this will resynchronize builtin dbghelp's internal ELF module list */
|
|
|
|
SymLoadModule(gdbctx->process->handle, 0, 0, 0, 0, 0);
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<library-list>");
|
2020-04-03 15:35:45 +02:00
|
|
|
opt = SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
|
|
|
|
SymEnumerateModules64(gdbctx->process->handle, packet_query_libraries_cb, gdbctx);
|
|
|
|
SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, opt);
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "</library-list>");
|
2021-11-23 16:11:00 +01:00
|
|
|
|
|
|
|
return packet_send_buffer;
|
2020-04-03 15:35:45 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
static enum packet_return packet_query_threads(struct gdb_context* gdbctx)
|
2020-04-03 15:35:46 +02:00
|
|
|
{
|
2021-11-23 16:10:01 +01:00
|
|
|
struct reply_buffer* reply = &gdbctx->qxfer_buffer;
|
2020-04-03 15:35:46 +02:00
|
|
|
struct dbg_process* process = gdbctx->process;
|
|
|
|
struct dbg_thread* thread;
|
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
if (!process) return packet_error;
|
|
|
|
|
|
|
|
if (gdbctx->qxfer_object_annex[0])
|
|
|
|
return packet_reply_error(gdbctx, 0);
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<threads>");
|
2020-04-03 15:35:46 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(thread, &process->threads, struct dbg_thread, entry)
|
|
|
|
{
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<thread ");
|
|
|
|
reply_buffer_append_str(reply, "id=\"");
|
|
|
|
reply_buffer_append_uinthex(reply, thread->tid, 4);
|
|
|
|
reply_buffer_append_str(reply, "\" name=\"");
|
2022-02-24 19:34:04 +01:00
|
|
|
if (strlen(thread->name))
|
|
|
|
{
|
|
|
|
reply_buffer_append_str(reply, thread->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char tid[5];
|
|
|
|
snprintf(tid, sizeof(tid), "%04lx", thread->tid);
|
|
|
|
reply_buffer_append_str(reply, tid);
|
|
|
|
}
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "\"/>");
|
2020-04-03 15:35:46 +02:00
|
|
|
}
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "</threads>");
|
2021-11-23 16:11:00 +01:00
|
|
|
|
|
|
|
return packet_send_buffer;
|
2020-04-03 15:35:46 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
static void packet_query_target_xml(struct gdb_context* gdbctx, struct reply_buffer* reply, struct backend_cpu* cpu)
|
2020-04-03 15:35:50 +02:00
|
|
|
{
|
|
|
|
const char* feature_prefix = NULL;
|
|
|
|
const char* feature = NULL;
|
|
|
|
char buffer[256];
|
|
|
|
int i;
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<target>");
|
2020-04-03 15:35:50 +02:00
|
|
|
switch (cpu->machine)
|
|
|
|
{
|
|
|
|
case IMAGE_FILE_MACHINE_AMD64:
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<architecture>i386:x86-64</architecture>");
|
2020-04-03 15:35:50 +02:00
|
|
|
feature_prefix = "org.gnu.gdb.i386.";
|
|
|
|
break;
|
|
|
|
case IMAGE_FILE_MACHINE_I386:
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<architecture>i386</architecture>");
|
2020-04-03 15:35:50 +02:00
|
|
|
feature_prefix = "org.gnu.gdb.i386.";
|
|
|
|
break;
|
|
|
|
case IMAGE_FILE_MACHINE_ARMNT:
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<architecture>arm</architecture>");
|
2020-04-03 15:35:50 +02:00
|
|
|
feature_prefix = "org.gnu.gdb.arm.";
|
|
|
|
break;
|
|
|
|
case IMAGE_FILE_MACHINE_ARM64:
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<architecture>aarch64</architecture>");
|
2020-04-03 15:35:50 +02:00
|
|
|
feature_prefix = "org.gnu.gdb.aarch64.";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < cpu->gdb_num_regs; ++i)
|
|
|
|
{
|
|
|
|
if (cpu->gdb_register_map[i].feature)
|
|
|
|
{
|
2021-11-23 16:10:01 +01:00
|
|
|
if (feature) reply_buffer_append_str(reply, "</feature>");
|
2020-04-03 15:35:50 +02:00
|
|
|
feature = cpu->gdb_register_map[i].feature;
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<feature name=\"");
|
2021-11-23 16:10:49 +01:00
|
|
|
if (feature_prefix) reply_buffer_append_xmlstr(reply, feature_prefix);
|
|
|
|
reply_buffer_append_xmlstr(reply, feature);
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "\">");
|
2020-04-03 15:35:50 +02:00
|
|
|
|
|
|
|
if (strcmp(feature_prefix, "org.gnu.gdb.i386.") == 0 &&
|
|
|
|
strcmp(feature, "core") == 0)
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<flags id=\"i386_eflags\" size=\"4\">"
|
|
|
|
"<field name=\"CF\" start=\"0\" end=\"0\"/>"
|
|
|
|
"<field name=\"\" start=\"1\" end=\"1\"/>"
|
|
|
|
"<field name=\"PF\" start=\"2\" end=\"2\"/>"
|
|
|
|
"<field name=\"AF\" start=\"4\" end=\"4\"/>"
|
|
|
|
"<field name=\"ZF\" start=\"6\" end=\"6\"/>"
|
|
|
|
"<field name=\"SF\" start=\"7\" end=\"7\"/>"
|
|
|
|
"<field name=\"TF\" start=\"8\" end=\"8\"/>"
|
|
|
|
"<field name=\"IF\" start=\"9\" end=\"9\"/>"
|
|
|
|
"<field name=\"DF\" start=\"10\" end=\"10\"/>"
|
|
|
|
"<field name=\"OF\" start=\"11\" end=\"11\"/>"
|
|
|
|
"<field name=\"NT\" start=\"14\" end=\"14\"/>"
|
|
|
|
"<field name=\"RF\" start=\"16\" end=\"16\"/>"
|
|
|
|
"<field name=\"VM\" start=\"17\" end=\"17\"/>"
|
|
|
|
"<field name=\"AC\" start=\"18\" end=\"18\"/>"
|
|
|
|
"<field name=\"VIF\" start=\"19\" end=\"19\"/>"
|
|
|
|
"<field name=\"VIP\" start=\"20\" end=\"20\"/>"
|
|
|
|
"<field name=\"ID\" start=\"21\" end=\"21\"/>"
|
|
|
|
"</flags>");
|
2020-04-03 15:35:50 +02:00
|
|
|
|
|
|
|
if (strcmp(feature_prefix, "org.gnu.gdb.i386.") == 0 &&
|
|
|
|
strcmp(feature, "sse") == 0)
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "<vector id=\"v4f\" type=\"ieee_single\" count=\"4\"/>"
|
|
|
|
"<vector id=\"v2d\" type=\"ieee_double\" count=\"2\"/>"
|
|
|
|
"<vector id=\"v16i8\" type=\"int8\" count=\"16\"/>"
|
|
|
|
"<vector id=\"v8i16\" type=\"int16\" count=\"8\"/>"
|
|
|
|
"<vector id=\"v4i32\" type=\"int32\" count=\"4\"/>"
|
|
|
|
"<vector id=\"v2i64\" type=\"int64\" count=\"2\"/>"
|
|
|
|
"<union id=\"vec128\">"
|
|
|
|
"<field name=\"v4_float\" type=\"v4f\"/>"
|
|
|
|
"<field name=\"v2_double\" type=\"v2d\"/>"
|
|
|
|
"<field name=\"v16_int8\" type=\"v16i8\"/>"
|
|
|
|
"<field name=\"v8_int16\" type=\"v8i16\"/>"
|
|
|
|
"<field name=\"v4_int32\" type=\"v4i32\"/>"
|
|
|
|
"<field name=\"v2_int64\" type=\"v2i64\"/>"
|
|
|
|
"<field name=\"uint128\" type=\"uint128\"/>"
|
|
|
|
"</union>"
|
|
|
|
"<flags id=\"i386_mxcsr\" size=\"4\">"
|
|
|
|
"<field name=\"IE\" start=\"0\" end=\"0\"/>"
|
|
|
|
"<field name=\"DE\" start=\"1\" end=\"1\"/>"
|
|
|
|
"<field name=\"ZE\" start=\"2\" end=\"2\"/>"
|
|
|
|
"<field name=\"OE\" start=\"3\" end=\"3\"/>"
|
|
|
|
"<field name=\"UE\" start=\"4\" end=\"4\"/>"
|
|
|
|
"<field name=\"PE\" start=\"5\" end=\"5\"/>"
|
|
|
|
"<field name=\"DAZ\" start=\"6\" end=\"6\"/>"
|
|
|
|
"<field name=\"IM\" start=\"7\" end=\"7\"/>"
|
|
|
|
"<field name=\"DM\" start=\"8\" end=\"8\"/>"
|
|
|
|
"<field name=\"ZM\" start=\"9\" end=\"9\"/>"
|
|
|
|
"<field name=\"OM\" start=\"10\" end=\"10\"/>"
|
|
|
|
"<field name=\"UM\" start=\"11\" end=\"11\"/>"
|
|
|
|
"<field name=\"PM\" start=\"12\" end=\"12\"/>"
|
|
|
|
"<field name=\"FZ\" start=\"15\" end=\"15\"/>"
|
|
|
|
"</flags>");
|
2020-04-03 15:35:50 +02:00
|
|
|
}
|
|
|
|
|
2021-10-04 15:19:20 +02:00
|
|
|
snprintf(buffer, ARRAY_SIZE(buffer), "<reg name=\"%s\" bitsize=\"%Iu\"",
|
2020-04-03 15:35:51 +02:00
|
|
|
cpu->gdb_register_map[i].name, 8 * cpu->gdb_register_map[i].length);
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, buffer);
|
2020-04-03 15:35:50 +02:00
|
|
|
|
|
|
|
if (cpu->gdb_register_map[i].type)
|
|
|
|
{
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, " type=\"");
|
2021-11-23 16:10:49 +01:00
|
|
|
reply_buffer_append_xmlstr(reply, cpu->gdb_register_map[i].type);
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "\"");
|
2020-04-03 15:35:50 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
reply_buffer_append_str(reply, "/>");
|
2020-04-03 15:35:50 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 16:10:01 +01:00
|
|
|
if (feature) reply_buffer_append_str(reply, "</feature>");
|
|
|
|
reply_buffer_append_str(reply, "</target>");
|
2020-04-03 15:35:50 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
static enum packet_return packet_query_features(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
struct reply_buffer* reply = &gdbctx->qxfer_buffer;
|
|
|
|
struct dbg_process* process = gdbctx->process;
|
|
|
|
|
|
|
|
if (!process) return packet_error;
|
|
|
|
|
|
|
|
if (strncmp(gdbctx->qxfer_object_annex, "target.xml", QX_ANNEX_SIZE) == 0)
|
|
|
|
{
|
|
|
|
struct backend_cpu *cpu = process->be_cpu;
|
|
|
|
if (!cpu) return packet_error;
|
|
|
|
|
|
|
|
packet_query_target_xml(gdbctx, reply, cpu);
|
|
|
|
|
|
|
|
return packet_send_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return packet_reply_error(gdbctx, 0);
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:11:15 +01:00
|
|
|
static enum packet_return packet_query_exec_file(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
struct reply_buffer* reply = &gdbctx->qxfer_buffer;
|
|
|
|
struct dbg_process* process = gdbctx->process;
|
|
|
|
char *unix_path;
|
|
|
|
BOOL is_wow64;
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (!process) return packet_error;
|
|
|
|
|
|
|
|
if (gdbctx->qxfer_object_annex[0] || !process->imageName)
|
|
|
|
return packet_reply_error(gdbctx, HOST_EPERM);
|
|
|
|
|
|
|
|
if (!(unix_path = wine_get_unix_file_name(process->imageName)))
|
|
|
|
return packet_reply_error(gdbctx, GetLastError() == ERROR_NOT_ENOUGH_MEMORY ? HOST_ENOMEM : HOST_ENOENT);
|
|
|
|
|
|
|
|
if (IsWow64Process(process->handle, &is_wow64) &&
|
|
|
|
is_wow64 && (tmp = strstr(unix_path, "system32")))
|
|
|
|
memcpy(tmp, "syswow64", 8);
|
|
|
|
|
|
|
|
reply_buffer_append_str(reply, unix_path);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_path);
|
|
|
|
|
|
|
|
return packet_send_buffer;
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
struct qxfer
|
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
enum packet_return (*handler)(struct gdb_context* gdbctx);
|
|
|
|
} qxfer_handlers[] =
|
|
|
|
{
|
|
|
|
{"libraries", packet_query_libraries},
|
|
|
|
{"threads" , packet_query_threads },
|
|
|
|
{"features" , packet_query_features },
|
2021-11-23 16:11:15 +01:00
|
|
|
{"exec-file", packet_query_exec_file},
|
2021-11-23 16:11:00 +01:00
|
|
|
};
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
static enum packet_return packet_query(struct gdb_context* gdbctx)
|
|
|
|
{
|
2021-11-23 16:11:00 +01:00
|
|
|
char object_name[QX_NAME_SIZE], annex[QX_ANNEX_SIZE];
|
2021-11-19 14:41:12 +01:00
|
|
|
unsigned int off, len;
|
2020-04-03 15:35:45 +02:00
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
switch (gdbctx->in_packet[0])
|
|
|
|
{
|
|
|
|
case 'f':
|
|
|
|
if (strncmp(gdbctx->in_packet + 1, "ThreadInfo", gdbctx->in_packet_len - 1) == 0)
|
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_thread* thd;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
|
|
|
packet_reply_open(gdbctx);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "m");
|
2010-04-12 21:18:37 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(thd, &gdbctx->process->threads, struct dbg_thread, entry)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
packet_reply_val(gdbctx, thd->tid, 4);
|
2010-04-12 21:18:37 +02:00
|
|
|
if (list_next(&gdbctx->process->threads, &thd->entry) != NULL)
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, ",");
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
else if (strncmp(gdbctx->in_packet + 1, "ProcessInfo", gdbctx->in_packet_len - 1) == 0)
|
|
|
|
{
|
|
|
|
char result[128];
|
|
|
|
|
|
|
|
packet_reply_open(gdbctx);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "O");
|
2002-07-20 22:29:09 +02:00
|
|
|
get_process_info(gdbctx, result, sizeof(result));
|
2003-02-11 23:06:19 +01:00
|
|
|
packet_reply_hex_to_str(gdbctx, result);
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (strncmp(gdbctx->in_packet + 1, "ThreadInfo", gdbctx->in_packet_len - 1) == 0)
|
|
|
|
{
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply(gdbctx, "l");
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
else if (strncmp(gdbctx->in_packet + 1, "ProcessInfo", gdbctx->in_packet_len - 1) == 0)
|
|
|
|
{
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply(gdbctx, "l");
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
break;
|
2012-01-03 21:37:59 +01:00
|
|
|
case 'A':
|
|
|
|
if (strncmp(gdbctx->in_packet, "Attached", gdbctx->in_packet_len) == 0)
|
2018-11-19 15:24:10 +01:00
|
|
|
return packet_reply(gdbctx, "1");
|
2012-01-03 21:37:59 +01:00
|
|
|
break;
|
2002-07-20 22:29:09 +02:00
|
|
|
case 'C':
|
|
|
|
if (gdbctx->in_packet_len == 1)
|
|
|
|
{
|
2004-06-04 02:59:16 +02:00
|
|
|
struct dbg_thread* thd;
|
2002-07-20 22:29:09 +02:00
|
|
|
/* FIXME: doc says 16 bit val ??? */
|
|
|
|
/* grab first created thread, aka last in list */
|
2010-04-12 21:18:37 +02:00
|
|
|
assert(gdbctx->process && !list_empty(&gdbctx->process->threads));
|
|
|
|
thd = LIST_ENTRY(list_tail(&gdbctx->process->threads), struct dbg_thread, entry);
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_open(gdbctx);
|
2018-11-19 15:24:10 +01:00
|
|
|
packet_reply_add(gdbctx, "QC");
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_val(gdbctx, thd->tid, 4);
|
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
if (strncmp(gdbctx->in_packet, "Offsets", gdbctx->in_packet_len) == 0)
|
|
|
|
{
|
|
|
|
char buf[64];
|
|
|
|
|
2009-11-08 15:08:11 +01:00
|
|
|
snprintf(buf, sizeof(buf),
|
2021-11-26 17:30:16 +01:00
|
|
|
"Text=%08Ix;Data=%08Ix;Bss=%08Ix",
|
2003-02-11 23:06:19 +01:00
|
|
|
gdbctx->wine_segs[0], gdbctx->wine_segs[1],
|
|
|
|
gdbctx->wine_segs[2]);
|
2018-11-19 15:24:10 +01:00
|
|
|
return packet_reply(gdbctx, buf);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
if (gdbctx->in_packet_len > 5 && strncmp(gdbctx->in_packet, "Rcmd,", 5) == 0)
|
|
|
|
{
|
|
|
|
return packet_query_remote_command(gdbctx, gdbctx->in_packet + 5,
|
|
|
|
gdbctx->in_packet_len - 5);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
if (strncmp(gdbctx->in_packet, "Symbol::", gdbctx->in_packet_len) == 0)
|
|
|
|
return packet_ok;
|
2010-08-30 13:34:37 +02:00
|
|
|
if (strncmp(gdbctx->in_packet, "Supported", 9) == 0)
|
2008-04-30 21:28:13 +02:00
|
|
|
{
|
2021-11-23 16:11:00 +01:00
|
|
|
size_t i;
|
|
|
|
|
2020-03-31 15:12:29 +02:00
|
|
|
packet_reply_open(gdbctx);
|
|
|
|
packet_reply_add(gdbctx, "QStartNoAckMode+;");
|
2021-11-23 16:11:00 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(qxfer_handlers); i++)
|
|
|
|
{
|
|
|
|
packet_reply_add(gdbctx, "qXfer:");
|
|
|
|
packet_reply_add(gdbctx, qxfer_handlers[i].name);
|
|
|
|
packet_reply_add(gdbctx, ":read+;");
|
|
|
|
}
|
2020-03-31 15:12:29 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
2008-04-30 21:28:13 +02:00
|
|
|
}
|
2002-07-20 22:29:09 +02:00
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
if (gdbctx->in_packet_len > 15 &&
|
|
|
|
strncmp(gdbctx->in_packet, "ThreadExtraInfo", 15) == 0 &&
|
|
|
|
gdbctx->in_packet[15] == ',')
|
|
|
|
{
|
|
|
|
unsigned tid;
|
|
|
|
char* end;
|
|
|
|
char result[128];
|
|
|
|
|
|
|
|
tid = strtol(gdbctx->in_packet + 16, &end, 16);
|
|
|
|
if (end == NULL) break;
|
|
|
|
get_thread_info(gdbctx, tid, result, sizeof(result));
|
|
|
|
packet_reply_open(gdbctx);
|
2003-02-11 23:06:19 +01:00
|
|
|
packet_reply_hex_to_str(gdbctx, result);
|
2002-07-20 22:29:09 +02:00
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
|
|
|
}
|
2010-08-30 13:34:37 +02:00
|
|
|
if (strncmp(gdbctx->in_packet, "TStatus", 7) == 0)
|
|
|
|
{
|
|
|
|
/* Tracepoints not supported */
|
|
|
|
packet_reply_open(gdbctx);
|
|
|
|
packet_reply_close(gdbctx);
|
|
|
|
return packet_done;
|
|
|
|
}
|
2002-07-20 22:29:09 +02:00
|
|
|
break;
|
2013-02-25 21:45:56 +01:00
|
|
|
case 'X':
|
2021-11-23 16:11:00 +01:00
|
|
|
annex[0] = '\0';
|
|
|
|
if (sscanf(gdbctx->in_packet, "Xfer:%31[^:]:read::%x,%x", object_name, &off, &len) == 3 ||
|
|
|
|
sscanf(gdbctx->in_packet, "Xfer:%31[^:]:read:%255[^:]:%x,%x", object_name, annex, &off, &len) == 4)
|
2020-04-03 15:35:45 +02:00
|
|
|
{
|
2021-11-23 16:11:00 +01:00
|
|
|
enum packet_return result;
|
|
|
|
int i;
|
2021-11-23 16:11:08 +01:00
|
|
|
BOOL more;
|
2020-04-03 15:35:45 +02:00
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(qxfer_handlers); i++)
|
|
|
|
{
|
|
|
|
if (strcmp(qxfer_handlers[i].name, object_name) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2020-04-03 15:35:45 +02:00
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
if (i >= ARRAY_SIZE(qxfer_handlers))
|
|
|
|
{
|
|
|
|
ERR("unhandled qXfer %s read %s %u,%u\n", debugstr_a(object_name), debugstr_a(annex), off, len);
|
|
|
|
return packet_error;
|
|
|
|
}
|
2020-04-03 15:35:46 +02:00
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
TRACE("qXfer %s read %s %u,%u\n", debugstr_a(object_name), debugstr_a(annex), off, len);
|
2020-04-03 15:35:46 +02:00
|
|
|
|
2021-11-23 16:11:08 +01:00
|
|
|
if (off > 0 &&
|
|
|
|
gdbctx->qxfer_buffer.len > 0 &&
|
|
|
|
gdbctx->qxfer_object_idx == i &&
|
|
|
|
strcmp(gdbctx->qxfer_object_annex, annex) == 0)
|
|
|
|
{
|
|
|
|
result = packet_send_buffer;
|
|
|
|
TRACE("qXfer read result = %d (cached)\n", result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reply_buffer_clear(&gdbctx->qxfer_buffer);
|
|
|
|
|
|
|
|
gdbctx->qxfer_object_idx = i;
|
|
|
|
strcpy(gdbctx->qxfer_object_annex, annex);
|
2020-04-03 15:35:50 +02:00
|
|
|
|
2021-11-23 16:11:08 +01:00
|
|
|
result = (*qxfer_handlers[i].handler)(gdbctx);
|
|
|
|
TRACE("qXfer read result = %d\n", result);
|
|
|
|
}
|
2021-11-23 16:11:00 +01:00
|
|
|
|
2021-11-23 16:11:08 +01:00
|
|
|
more = FALSE;
|
2021-11-23 16:11:00 +01:00
|
|
|
if ((result & ~packet_last_f) == packet_send_buffer)
|
|
|
|
{
|
2021-11-23 16:11:08 +01:00
|
|
|
packet_reply_xfer(gdbctx, off, len, &more);
|
2021-11-23 16:11:00 +01:00
|
|
|
result = (result & packet_last_f) | packet_done;
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:11:08 +01:00
|
|
|
if (!more)
|
|
|
|
{
|
|
|
|
gdbctx->qxfer_object_idx = -1;
|
|
|
|
gdbctx->qxfer_object_annex[0] = '\0';
|
|
|
|
reply_buffer_clear(&gdbctx->qxfer_buffer);
|
|
|
|
}
|
2021-11-23 16:11:00 +01:00
|
|
|
|
|
|
|
return result;
|
2020-04-03 15:35:50 +02:00
|
|
|
}
|
2013-02-25 21:45:56 +01:00
|
|
|
break;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
2018-07-30 21:47:53 +02:00
|
|
|
ERR("Unhandled query %s\n", debugstr_an(gdbctx->in_packet, gdbctx->in_packet_len));
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_error;
|
|
|
|
}
|
|
|
|
|
2020-03-31 15:12:29 +02:00
|
|
|
static enum packet_return packet_set(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
if (strncmp(gdbctx->in_packet, "StartNoAckMode", 14) == 0)
|
|
|
|
{
|
|
|
|
gdbctx->no_ack_mode = TRUE;
|
|
|
|
return packet_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
return packet_error;
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
static enum packet_return packet_step(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-04-01 17:03:27 +02:00
|
|
|
void *addr;
|
|
|
|
|
|
|
|
if (sscanf(gdbctx->in_packet, "%p", &addr) == 1)
|
|
|
|
FIXME("Continue at address %p not supported\n", addr);
|
|
|
|
|
|
|
|
handle_step_or_continue(gdbctx, gdbctx->exec_tid, TRUE, -1);
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
wait_for_debuggee(gdbctx);
|
|
|
|
return packet_reply_status(gdbctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum packet_return packet_thread_alive(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
char* end;
|
|
|
|
unsigned tid;
|
|
|
|
|
|
|
|
tid = strtol(gdbctx->in_packet, &end, 16);
|
|
|
|
if (tid == -1 || tid == 0)
|
2021-10-04 11:27:43 +02:00
|
|
|
return packet_reply_error(gdbctx, HOST_EINVAL );
|
2004-06-04 02:59:16 +02:00
|
|
|
if (dbg_get_thread(gdbctx->process, tid) != NULL)
|
2002-07-20 22:29:09 +02:00
|
|
|
return packet_ok;
|
2021-10-04 11:27:43 +02:00
|
|
|
return packet_reply_error(gdbctx, HOST_ESRCH );
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* =============================================== *
|
|
|
|
* P A C K E T I N F R A S T R U C T U R E *
|
|
|
|
* =============================================== *
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct packet_entry
|
|
|
|
{
|
|
|
|
char key;
|
|
|
|
enum packet_return (*handler)(struct gdb_context* gdbctx);
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct packet_entry packet_entries[] =
|
|
|
|
{
|
|
|
|
{'?', packet_last_signal},
|
|
|
|
{'c', packet_continue},
|
|
|
|
{'C', packet_continue_signal},
|
|
|
|
{'D', packet_detach},
|
|
|
|
{'g', packet_read_registers},
|
|
|
|
{'G', packet_write_registers},
|
|
|
|
{'k', packet_kill},
|
|
|
|
{'H', packet_thread},
|
|
|
|
{'m', packet_read_memory},
|
|
|
|
{'M', packet_write_memory},
|
2008-02-01 21:26:47 +01:00
|
|
|
{'p', packet_read_register},
|
2002-07-20 22:29:09 +02:00
|
|
|
{'P', packet_write_register},
|
|
|
|
{'q', packet_query},
|
2020-03-31 15:12:29 +02:00
|
|
|
{'Q', packet_set},
|
2005-02-10 22:18:12 +01:00
|
|
|
{'s', packet_step},
|
2002-07-20 22:29:09 +02:00
|
|
|
{'T', packet_thread_alive},
|
2005-02-10 22:18:12 +01:00
|
|
|
{'v', packet_verbose},
|
2020-04-04 11:30:14 +02:00
|
|
|
{'z', packet_delete_breakpoint},
|
|
|
|
{'Z', packet_insert_breakpoint},
|
2002-07-20 22:29:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL extract_packets(struct gdb_context* gdbctx)
|
|
|
|
{
|
2020-03-31 15:12:28 +02:00
|
|
|
char *ptr, *sum = gdbctx->in_buf, *end = gdbctx->in_buf + gdbctx->in_len;
|
|
|
|
enum packet_return ret = packet_error;
|
|
|
|
unsigned int cksum;
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
/* ptr points to the beginning ('$') of the current packet
|
|
|
|
* sum points to the beginning ('#') of the current packet checksum ("#xx")
|
|
|
|
* len is the length of the current packet data (sum - ptr - 1)
|
|
|
|
* end points to the end of the received data buffer
|
|
|
|
*/
|
|
|
|
|
2020-03-31 15:12:29 +02:00
|
|
|
while (!gdbctx->no_ack_mode &&
|
|
|
|
(ptr = memchr(sum, '$', end - sum)) &&
|
2020-03-31 15:12:28 +02:00
|
|
|
(sum = memchr(ptr, '#', end - ptr)) &&
|
|
|
|
(end - sum >= 3) && sscanf(sum, "#%02x", &cksum) == 1)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-03-31 15:12:28 +02:00
|
|
|
len = sum - ptr - 1;
|
|
|
|
sum += 3;
|
|
|
|
|
|
|
|
if (cksum == checksum(ptr + 1, len))
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-03-31 15:12:28 +02:00
|
|
|
TRACE("Acking: %s\n", debugstr_an(ptr, sum - ptr));
|
2021-10-04 11:27:43 +02:00
|
|
|
send(gdbctx->sock, "+", 1, 0);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
2020-03-31 15:12:28 +02:00
|
|
|
else
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-03-31 15:12:28 +02:00
|
|
|
ERR("Nacking: %s (checksum: %d != %d)\n", debugstr_an(ptr, sum - ptr),
|
|
|
|
cksum, checksum(ptr + 1, len));
|
2021-10-04 11:27:43 +02:00
|
|
|
send(gdbctx->sock, "-", 1, 0);
|
2020-03-31 15:12:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((ret & packet_last_f) == 0 &&
|
|
|
|
(ptr = memchr(gdbctx->in_buf, '$', gdbctx->in_len)) &&
|
|
|
|
(sum = memchr(ptr, '#', end - ptr)) &&
|
|
|
|
(end - sum >= 3) && sscanf(sum, "#%02x", &cksum) == 1)
|
|
|
|
{
|
|
|
|
if (ptr != gdbctx->in_buf)
|
|
|
|
WARN("Ignoring: %s\n", debugstr_an(gdbctx->in_buf, ptr - gdbctx->in_buf));
|
|
|
|
|
|
|
|
len = sum - ptr - 1;
|
|
|
|
sum += 3;
|
|
|
|
|
|
|
|
if (cksum == checksum(ptr + 1, len))
|
|
|
|
{
|
|
|
|
TRACE("Handling: %s\n", debugstr_an(ptr, sum - ptr));
|
|
|
|
|
|
|
|
ret = packet_error;
|
|
|
|
gdbctx->in_packet = ptr + 2;
|
|
|
|
gdbctx->in_packet_len = len - 1;
|
|
|
|
gdbctx->in_packet[gdbctx->in_packet_len] = '\0';
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(packet_entries); i++)
|
|
|
|
if (packet_entries[i].key == ptr[1])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == ARRAY_SIZE(packet_entries))
|
|
|
|
WARN("Unhandled: %s\n", debugstr_an(ptr + 1, len));
|
|
|
|
else if (((ret = (packet_entries[i].handler)(gdbctx)) & ~packet_last_f) == packet_error)
|
|
|
|
WARN("Failed: %s\n", debugstr_an(ptr + 1, len));
|
|
|
|
|
|
|
|
switch (ret & ~packet_last_f)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-03-31 15:12:28 +02:00
|
|
|
case packet_error: packet_reply(gdbctx, ""); break;
|
|
|
|
case packet_ok: packet_reply(gdbctx, "OK"); break;
|
|
|
|
case packet_done: break;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
2020-03-31 15:12:28 +02:00
|
|
|
|
2021-11-23 16:09:48 +01:00
|
|
|
TRACE("Reply: %s\n", debugstr_an((char *)gdbctx->out_buf.base, gdbctx->out_buf.len));
|
|
|
|
i = send(gdbctx->sock, (char *)gdbctx->out_buf.base, gdbctx->out_buf.len, 0);
|
|
|
|
assert(i == gdbctx->out_buf.len);
|
|
|
|
reply_buffer_clear(&gdbctx->out_buf);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
2002-12-16 23:10:34 +01:00
|
|
|
else
|
2020-03-31 15:12:28 +02:00
|
|
|
WARN("Ignoring: %s (checksum: %d != %d)\n", debugstr_an(ptr, sum - ptr),
|
|
|
|
cksum, checksum(ptr + 1, len));
|
|
|
|
|
|
|
|
gdbctx->in_len = end - sum;
|
|
|
|
memmove(gdbctx->in_buf, sum, end - sum);
|
|
|
|
end = gdbctx->in_buf + gdbctx->in_len;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
2020-03-31 15:12:28 +02:00
|
|
|
|
|
|
|
return (ret & packet_last_f);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int fetch_data(struct gdb_context* gdbctx)
|
|
|
|
{
|
|
|
|
int len, in_len = gdbctx->in_len;
|
|
|
|
|
|
|
|
assert(gdbctx->in_len <= gdbctx->in_buf_alloc);
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
#define STEP 128
|
|
|
|
if (gdbctx->in_len + STEP > gdbctx->in_buf_alloc)
|
2021-11-19 14:41:05 +01:00
|
|
|
gdbctx->in_buf = realloc(gdbctx->in_buf, gdbctx->in_buf_alloc += STEP);
|
2002-07-20 22:29:09 +02:00
|
|
|
#undef STEP
|
2021-10-04 11:27:43 +02:00
|
|
|
len = recv(gdbctx->sock, gdbctx->in_buf + gdbctx->in_len, gdbctx->in_buf_alloc - gdbctx->in_len - 1, 0);
|
2002-07-20 22:29:09 +02:00
|
|
|
if (len <= 0) break;
|
|
|
|
gdbctx->in_len += len;
|
|
|
|
assert(gdbctx->in_len <= gdbctx->in_buf_alloc);
|
|
|
|
if (len < gdbctx->in_buf_alloc - gdbctx->in_len) break;
|
|
|
|
}
|
2020-03-31 15:12:26 +02:00
|
|
|
|
|
|
|
gdbctx->in_buf[gdbctx->in_len] = '\0';
|
2002-07-20 22:29:09 +02:00
|
|
|
return gdbctx->in_len - in_len;
|
|
|
|
}
|
|
|
|
|
2006-02-24 22:14:36 +01:00
|
|
|
#define FLAG_NO_START 1
|
|
|
|
#define FLAG_WITH_XTERM 2
|
|
|
|
|
2020-04-07 19:34:16 +02:00
|
|
|
static BOOL gdb_exec(unsigned port, unsigned flags)
|
2004-06-04 02:59:16 +02:00
|
|
|
{
|
2021-10-04 15:19:20 +02:00
|
|
|
WCHAR tmp[MAX_PATH], buf[MAX_PATH];
|
2021-10-04 11:27:43 +02:00
|
|
|
const char *argv[6];
|
2021-10-04 15:19:20 +02:00
|
|
|
char *unix_tmp;
|
|
|
|
const char *gdb_path;
|
|
|
|
FILE* f;
|
2004-06-04 02:59:16 +02:00
|
|
|
|
|
|
|
if (!(gdb_path = getenv("WINE_GDB"))) gdb_path = "gdb";
|
2021-10-04 15:19:20 +02:00
|
|
|
GetTempPathW( MAX_PATH, buf );
|
|
|
|
GetTempFileNameW( buf, L"gdb", 0, tmp );
|
|
|
|
if ((f = _wfopen( tmp, L"w+" )) == NULL) return FALSE;
|
|
|
|
unix_tmp = wine_get_unix_file_name( tmp );
|
2004-06-04 02:59:16 +02:00
|
|
|
fprintf(f, "target remote localhost:%d\n", ntohs(port));
|
|
|
|
fprintf(f, "set prompt Wine-gdb>\\ \n");
|
|
|
|
/* gdb 5.1 seems to require it, won't hurt anyway */
|
|
|
|
fprintf(f, "sharedlibrary\n");
|
|
|
|
/* This is needed (but not a decent & final fix)
|
|
|
|
* Without this, gdb would skip our inter-DLL relay code (because
|
|
|
|
* we don't have any line number information for the relay code)
|
|
|
|
* With this, we will stop on first instruction of the stub, and
|
|
|
|
* reusing step, will get us through the relay stub at the actual
|
|
|
|
* function we're looking at.
|
|
|
|
*/
|
|
|
|
fprintf(f, "set step-mode on\n");
|
|
|
|
/* tell gdb to delete this file when done handling it... */
|
2021-10-04 15:19:20 +02:00
|
|
|
fprintf(f, "shell rm -f \"%s\"\n", unix_tmp);
|
2004-06-04 02:59:16 +02:00
|
|
|
fclose(f);
|
2021-10-04 11:27:43 +02:00
|
|
|
argv[0] = "xterm";
|
|
|
|
argv[1] = "-e";
|
|
|
|
argv[2] = gdb_path;
|
|
|
|
argv[3] = "-x";
|
2021-10-04 15:19:20 +02:00
|
|
|
argv[4] = unix_tmp;
|
2021-10-04 11:27:43 +02:00
|
|
|
argv[5] = NULL;
|
2006-02-24 22:14:36 +01:00
|
|
|
if (flags & FLAG_WITH_XTERM)
|
2021-10-04 11:27:43 +02:00
|
|
|
__wine_unix_spawnvp( (char **)argv, FALSE );
|
2004-06-04 02:59:16 +02:00
|
|
|
else
|
2021-10-04 11:27:43 +02:00
|
|
|
__wine_unix_spawnvp( (char **)argv + 2, FALSE );
|
2021-10-04 15:19:20 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, unix_tmp );
|
2004-06-04 02:59:16 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-04-01 17:03:26 +02:00
|
|
|
static BOOL gdb_startup(struct gdb_context* gdbctx, unsigned flags, unsigned port)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2021-10-04 11:27:43 +02:00
|
|
|
SOCKET sock;
|
2021-11-16 17:38:17 +01:00
|
|
|
BOOL reuseaddr = TRUE;
|
2021-10-04 11:27:43 +02:00
|
|
|
struct sockaddr_in s_addrs = {0};
|
|
|
|
int s_len = sizeof(s_addrs);
|
|
|
|
fd_set read_fds;
|
|
|
|
WSADATA data;
|
2012-10-25 21:29:10 +02:00
|
|
|
BOOL ret = FALSE;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2021-10-04 11:27:43 +02:00
|
|
|
WSAStartup( MAKEWORD(2, 2), &data );
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
/* step 1: create socket for gdb connection request */
|
2021-10-04 11:27:43 +02:00
|
|
|
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2021-10-04 11:27:43 +02:00
|
|
|
ERR("Failed to create socket: %u\n", WSAGetLastError());
|
2002-07-20 22:29:09 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-11-16 17:38:17 +01:00
|
|
|
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&reuseaddr, sizeof(reuseaddr));
|
|
|
|
|
2018-05-03 02:32:50 +02:00
|
|
|
s_addrs.sin_family = AF_INET;
|
2021-10-04 11:27:43 +02:00
|
|
|
s_addrs.sin_addr.S_un.S_addr = INADDR_ANY;
|
2018-05-03 02:32:50 +02:00
|
|
|
s_addrs.sin_port = htons(port);
|
|
|
|
if (bind(sock, (struct sockaddr *)&s_addrs, sizeof(s_addrs)) == -1)
|
|
|
|
goto cleanup;
|
|
|
|
|
2021-10-04 11:27:43 +02:00
|
|
|
if (listen(sock, 1) == -1 || getsockname(sock, (struct sockaddr *)&s_addrs, &s_len) == -1)
|
2012-10-25 21:29:10 +02:00
|
|
|
goto cleanup;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2004-06-04 02:59:16 +02:00
|
|
|
/* step 2: do the process internal creation */
|
2021-07-13 06:36:34 +02:00
|
|
|
handle_debug_event(gdbctx, FALSE);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-07 19:34:16 +02:00
|
|
|
/* step 3: fire up gdb (if requested) */
|
2006-02-24 22:14:36 +01:00
|
|
|
if (flags & FLAG_NO_START)
|
2002-08-20 01:58:03 +02:00
|
|
|
fprintf(stderr, "target remote localhost:%d\n", ntohs(s_addrs.sin_port));
|
2002-07-20 22:29:09 +02:00
|
|
|
else
|
2021-10-04 11:27:43 +02:00
|
|
|
gdb_exec(s_addrs.sin_port, flags);
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2020-04-07 19:34:16 +02:00
|
|
|
/* step 4: wait for gdb to connect actually */
|
2021-10-04 11:27:43 +02:00
|
|
|
FD_ZERO( &read_fds );
|
|
|
|
FD_SET( sock, &read_fds );
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2021-10-04 11:27:43 +02:00
|
|
|
if (select( 0, &read_fds, NULL, NULL, NULL ) > 0)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2021-10-04 11:27:43 +02:00
|
|
|
int dummy = 1;
|
|
|
|
|
|
|
|
gdbctx->sock = accept(sock, (struct sockaddr *)&s_addrs, &s_len);
|
|
|
|
if (gdbctx->sock != INVALID_SOCKET)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2012-10-25 21:29:10 +02:00
|
|
|
ret = TRUE;
|
2021-11-26 17:30:16 +01:00
|
|
|
TRACE("connected on %Iu\n", gdbctx->sock);
|
2002-07-20 22:29:09 +02:00
|
|
|
/* don't keep our small packets too long: send them ASAP back to GDB
|
|
|
|
* without this, GDB really crawls
|
|
|
|
*/
|
|
|
|
setsockopt(gdbctx->sock, IPPROTO_TCP, TCP_NODELAY, (char*)&dummy, sizeof(dummy));
|
|
|
|
}
|
|
|
|
}
|
2021-10-04 11:27:43 +02:00
|
|
|
else ERR("Failed to connect to gdb: %u\n", WSAGetLastError());
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2012-10-25 21:29:10 +02:00
|
|
|
cleanup:
|
2021-10-04 11:27:43 +02:00
|
|
|
closesocket(sock);
|
2012-10-25 21:29:10 +02:00
|
|
|
return ret;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
|
2018-05-03 02:32:50 +02:00
|
|
|
static BOOL gdb_init_context(struct gdb_context* gdbctx, unsigned flags, unsigned port)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2021-10-04 11:27:43 +02:00
|
|
|
gdbctx->sock = INVALID_SOCKET;
|
2002-07-20 22:29:09 +02:00
|
|
|
gdbctx->in_buf = NULL;
|
|
|
|
gdbctx->in_buf_alloc = 0;
|
|
|
|
gdbctx->in_len = 0;
|
2021-11-23 16:09:48 +01:00
|
|
|
memset(&gdbctx->out_buf, 0, sizeof(gdbctx->out_buf));
|
2002-07-20 22:29:09 +02:00
|
|
|
gdbctx->out_curr_packet = -1;
|
|
|
|
|
2020-04-01 17:03:25 +02:00
|
|
|
gdbctx->exec_tid = -1;
|
|
|
|
gdbctx->other_tid = -1;
|
2020-04-04 11:30:14 +02:00
|
|
|
list_init(&gdbctx->xpoint_list);
|
2002-07-20 22:29:09 +02:00
|
|
|
gdbctx->process = NULL;
|
2020-03-31 15:12:29 +02:00
|
|
|
gdbctx->no_ack_mode = FALSE;
|
2018-06-18 00:09:29 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(gdbctx->wine_segs); i++)
|
2009-11-08 15:08:11 +01:00
|
|
|
gdbctx->wine_segs[i] = 0;
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2021-11-23 16:11:00 +01:00
|
|
|
gdbctx->qxfer_object_idx = -1;
|
|
|
|
memset(gdbctx->qxfer_object_annex, 0, sizeof(gdbctx->qxfer_object_annex));
|
2021-11-23 16:10:01 +01:00
|
|
|
memset(&gdbctx->qxfer_buffer, 0, sizeof(gdbctx->qxfer_buffer));
|
|
|
|
|
2002-07-20 22:29:09 +02:00
|
|
|
/* wait for first trap */
|
2020-04-01 17:03:26 +02:00
|
|
|
while (WaitForDebugEvent(&gdbctx->de, INFINITE))
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2020-04-01 17:03:26 +02:00
|
|
|
if (gdbctx->de.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
/* this should be the first event we get,
|
|
|
|
* and the only one of this type */
|
2020-04-01 17:03:26 +02:00
|
|
|
assert(gdbctx->process == NULL && gdbctx->de.dwProcessId == dbg_curr_pid);
|
2004-06-04 02:59:16 +02:00
|
|
|
/* gdbctx->dwProcessId = pid; */
|
2020-04-01 17:03:26 +02:00
|
|
|
if (!gdb_startup(gdbctx, flags, port)) return FALSE;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
2021-07-13 06:36:34 +02:00
|
|
|
else if (!handle_debug_event(gdbctx, FALSE))
|
2020-04-04 11:30:16 +02:00
|
|
|
break;
|
2020-04-01 17:03:26 +02:00
|
|
|
ContinueDebugEvent(gdbctx->de.dwProcessId, gdbctx->de.dwThreadId, DBG_CONTINUE);
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-05-03 02:32:50 +02:00
|
|
|
static int gdb_remote(unsigned flags, unsigned port)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
|
|
|
struct gdb_context gdbctx;
|
|
|
|
|
2021-10-04 11:27:43 +02:00
|
|
|
if (!gdb_init_context(&gdbctx, flags, port)) return 0;
|
2021-12-15 16:52:52 +01:00
|
|
|
/* don't handle ctrl-c, but let gdb do the job */
|
|
|
|
SetConsoleCtrlHandler(NULL, TRUE);
|
2021-10-04 11:27:43 +02:00
|
|
|
for (;;)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2021-10-04 11:27:43 +02:00
|
|
|
fd_set read_fds, err_fds;
|
|
|
|
|
|
|
|
FD_ZERO( &read_fds );
|
|
|
|
FD_ZERO( &err_fds );
|
|
|
|
FD_SET( gdbctx.sock, &read_fds );
|
|
|
|
FD_SET( gdbctx.sock, &err_fds );
|
2002-07-20 22:29:09 +02:00
|
|
|
|
2021-10-04 11:27:43 +02:00
|
|
|
if (select( 0, &read_fds, NULL, &err_fds, NULL ) == -1) break;
|
|
|
|
|
|
|
|
if (FD_ISSET( gdbctx.sock, &err_fds ))
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2021-10-04 11:27:43 +02:00
|
|
|
ERR("gdb hung up\n");
|
|
|
|
/* kill also debuggee process - questionnable - */
|
|
|
|
detach_debuggee(&gdbctx, TRUE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (FD_ISSET( gdbctx.sock, &read_fds ))
|
|
|
|
{
|
|
|
|
if (fetch_data(&gdbctx) > 0)
|
2002-07-20 22:29:09 +02:00
|
|
|
{
|
2021-10-04 11:27:43 +02:00
|
|
|
if (extract_packets(&gdbctx)) break;
|
2002-07-20 22:29:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-24 22:14:36 +01:00
|
|
|
|
|
|
|
int gdb_main(int argc, char* argv[])
|
|
|
|
{
|
2018-05-03 02:32:50 +02:00
|
|
|
unsigned gdb_flags = 0, port = 0;
|
|
|
|
char *port_end;
|
2006-02-24 22:14:36 +01:00
|
|
|
|
|
|
|
argc--; argv++;
|
|
|
|
while (argc > 0 && argv[0][0] == '-')
|
|
|
|
{
|
|
|
|
if (strcmp(argv[0], "--no-start") == 0)
|
|
|
|
{
|
|
|
|
gdb_flags |= FLAG_NO_START;
|
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(argv[0], "--with-xterm") == 0)
|
|
|
|
{
|
|
|
|
gdb_flags |= FLAG_WITH_XTERM;
|
|
|
|
argc--; argv++;
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-03 02:32:50 +02:00
|
|
|
if (strcmp(argv[0], "--port") == 0 && argc > 1)
|
|
|
|
{
|
|
|
|
port = strtoul(argv[1], &port_end, 10);
|
|
|
|
if (*port_end)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Invalid port: %s\n", argv[1]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
argc -= 2; argv += 2;
|
|
|
|
continue;
|
|
|
|
}
|
2006-02-24 22:14:36 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2006-02-27 21:50:33 +01:00
|
|
|
if (dbg_active_attach(argc, argv) == start_ok ||
|
|
|
|
dbg_active_launch(argc, argv) == start_ok)
|
2018-05-03 02:32:50 +02:00
|
|
|
return gdb_remote(gdb_flags, port);
|
2021-10-04 11:27:43 +02:00
|
|
|
|
2006-02-24 22:14:36 +01:00
|
|
|
return -1;
|
|
|
|
}
|