Paul Bolle a écrit :
Add support for the qAttached packet. Main benefit is that if gdb was attached to a debuggee and it quits it will now ask if it should detach from the debuggee instead of asking whether the debuggee should be killed. (It still will ask whether the debuggee should be killed if it launched the debuggee itself).
Signed-off-by: Paul Bolle pebolle@tiscali.nl
Would it be better to add a new member to gdbctx instead of using a separate variable (qAttached_reply)?
yes, inclusion in gdbctx is preferred (and storage should rather be an integer rather than a string pointer) A+
Add support for the qAttached packet. Main benefit is that gdb now will ask if it should detach from the debuggee if it was attached to a debuggee instead of asking whether the debuggee should be killed. (It still will ask whether the debuggee should be killed if it launched the debuggee itself).
Signed-off-by: Paul Bolle pebolle@tiscali.nl --- On Wed, 2009-11-04 at 21:42 +0100, Eric Pouech wrote:
[...] inclusion in gdbctx is preferred (and storage should rather be an integer rather than a string pointer)
programs/winedbg/gdbproxy.c | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index 4f12481..0f5088c 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -109,6 +109,8 @@ struct gdb_context struct gdb_ctx_Xpoint Xpoints[NUM_XPOINT]; /* Unix environment */ unsigned long wine_segs[3]; /* load addresses of the ELF wine exec segments (text, bss and data) */ + /* attached or launched? */ + int attached; };
static BOOL tgt_process_gdbproxy_read(HANDLE hProcess, const void* addr, @@ -1794,6 +1796,15 @@ static enum packet_return packet_query(struct gdb_context* gdbctx) return packet_done; } break; + case 'A': + /* Since gdb's multiprocess protocol extensions aren't supported, this + * shouldn't be "qAttached:PID", just "qAttached", but check anyway. */ + if (gdbctx->in_packet_len == 8 && strncmp(gdbctx->in_packet, "Attached", 8) == 0) + { + packet_reply(gdbctx, gdbctx->attached ? "1": "0", 1); + return packet_done; + } + break; case 'C': if (gdbctx->in_packet_len == 1) { @@ -2179,6 +2190,7 @@ static int fetch_data(struct gdb_context* gdbctx)
#define FLAG_NO_START 1 #define FLAG_WITH_XTERM 2 +#define FLAG_ATTACHED 4
static BOOL gdb_exec(const char* wine_path, unsigned port, unsigned flags) { @@ -2318,6 +2330,7 @@ static BOOL gdb_init_context(struct gdb_context* gdbctx, unsigned flags) gdbctx->in_trap = FALSE; gdbctx->trace = /*GDBPXY_TRC_PACKET | GDBPXY_TRC_COMMAND |*/ GDBPXY_TRC_COMMAND_ERROR | GDBPXY_TRC_COMMAND_FIXME | GDBPXY_TRC_WIN32_EVENT; gdbctx->process = NULL; + gdbctx->attached = (flags & FLAG_ATTACHED) ? 1 : 0; for (i = 0; i < NUM_XPOINT; i++) gdbctx->Xpoints[i].type = -1; for (i = 0; i < sizeof(gdbctx->wine_segs) / sizeof(gdbctx->wine_segs[0]); i++) @@ -2350,6 +2363,7 @@ static int gdb_remote(unsigned flags) struct pollfd pollfd; struct gdb_context gdbctx; BOOL doLoop; + BOOL kill;
for (doLoop = gdb_init_context(&gdbctx, flags); doLoop;) { @@ -2365,8 +2379,8 @@ static int gdb_remote(unsigned flags) { if (gdbctx.trace & GDBPXY_TRC_LOWLEVEL) fprintf(stderr, "Gdb hung up\n"); - /* kill also debuggee process - questionnable - */ - detach_debuggee(&gdbctx, TRUE); + kill = (flags & FLAG_ATTACHED) ? FALSE : TRUE; + detach_debuggee(&gdbctx, kill); doLoop = FALSE; break; } @@ -2412,8 +2426,11 @@ int gdb_main(int argc, char* argv[]) } return -1; } - if (dbg_active_attach(argc, argv) == start_ok || - dbg_active_launch(argc, argv) == start_ok) + if (dbg_active_attach(argc, argv) == start_ok) { + gdb_flags |= FLAG_ATTACHED; + return gdb_remote(gdb_flags); + } + else if (dbg_active_launch(argc, argv) == start_ok) return gdb_remote(gdb_flags); #else fprintf(stderr, "GdbProxy mode not supported on this platform\n");