winedbg: Added a close_process method to process_io.

- added a close_process method to process_io
- made use of it to get rid of dbg_detach
This commit is contained in:
Eric Pouech 2006-02-27 21:50:43 +01:00 committed by Alexandre Julliard
parent 4202c752d3
commit 5ca519705d
5 changed files with 41 additions and 37 deletions

View File

@ -139,7 +139,7 @@ command:
| tSYMBOLFILE pathname expr_rvalue { symbol_read_symtable($2, $3); }
| tWHATIS expr_lvalue { dbg_printf("type = "); types_print_type(&$2.type, FALSE); dbg_printf("\n"); }
| tATTACH tNUM { dbg_attach_debuggee($2, FALSE, TRUE); }
| tDETACH { dbg_detach_debuggee(); }
| tDETACH { dbg_curr_process->process_io->close_process(dbg_curr_process, FALSE); }
| tMINIDUMP pathname { minidump_write($2, (dbg_curr_thread && dbg_curr_thread->in_exception) ? &dbg_curr_thread->excpt_record : NULL);}
| tECHO tSTRING { dbg_printf("%s\n", $2); }
| run_command

View File

@ -216,6 +216,7 @@ struct dbg_process
/* describes the way the debugger interacts with a given process */
struct be_process_io
{
BOOL (*close_process)(struct dbg_process*, BOOL);
BOOL (WINAPI *read)(HANDLE, const void*, void*, DWORD, DWORD*);
BOOL (WINAPI *write)(HANDLE, void*, const void*, DWORD, DWORD*);
};
@ -403,7 +404,6 @@ extern int dbg_printf(const char* format, ...);
#endif
extern const struct dbg_internal_var* dbg_get_internal_var(const char*);
extern BOOL dbg_attach_debuggee(DWORD pid, BOOL cofe, BOOL wfe);
extern BOOL dbg_detach_debuggee(void);
extern BOOL dbg_interrupt_debuggee(void);
extern struct dbg_process* dbg_add_process(DWORD pid, HANDLE h);
extern void dbg_set_process_name(struct dbg_process* p, const char* name);

View File

@ -338,7 +338,7 @@ static void backtrace_all(void)
{
if (entry.th32OwnerProcessID == GetCurrentProcessId()) continue;
if (dbg_curr_process && dbg_curr_pid != entry.th32OwnerProcessID)
dbg_detach_debuggee();
dbg_curr_process->process_io->close_process(dbg_curr_process, FALSE);
if (entry.th32OwnerProcessID != dbg_curr_pid)
{
@ -358,7 +358,7 @@ static void backtrace_all(void)
while (Thread32Next(snapshot, &entry));
if (dbg_curr_process)
dbg_detach_debuggee();
dbg_curr_process->process_io->close_process(dbg_curr_process, FALSE);
}
CloseHandle(snapshot);
}

View File

@ -34,12 +34,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
static char* dbg_last_cmd_line;
struct be_process_io be_process_active_io =
{
ReadProcessMemory,
WriteProcessMemory,
};
static void dbg_init_current_process(void)
{
}
@ -100,23 +94,6 @@ BOOL dbg_attach_debuggee(DWORD pid, BOOL cofe, BOOL wfe)
return TRUE;
}
BOOL dbg_detach_debuggee(void)
{
/* remove all set breakpoints in debuggee code */
break_set_xpoints(FALSE);
/* needed for single stepping (ugly).
* should this be handled inside the server ???
*/
be_cpu->single_step(&dbg_context, FALSE);
SetThreadContext(dbg_curr_thread->handle, &dbg_context);
if (dbg_curr_thread->in_exception)
ContinueDebugEvent(dbg_curr_pid, dbg_curr_tid, DBG_CONTINUE);
if (!DebugActiveProcessStop(dbg_curr_pid)) return FALSE;
dbg_del_process(dbg_curr_process);
return TRUE;
}
static unsigned dbg_fetch_context(void)
{
dbg_context.ContextFlags = CONTEXT_CONTROL
@ -413,6 +390,8 @@ static DWORD dbg_handle_exception(const EXCEPTION_RECORD* rec, BOOL first_chance
return DBG_CONTINUE;
}
static BOOL tgt_process_active_close_process(struct dbg_process* pcs, BOOL kill);
static unsigned dbg_handle_debug_event(DEBUG_EVENT* de)
{
char buffer[256];
@ -507,15 +486,7 @@ static unsigned dbg_handle_debug_event(DEBUG_EVENT* de)
WINE_ERR("Unknown process\n");
break;
}
if (!SymCleanup(dbg_curr_process->handle))
dbg_printf("Couldn't initiate DbgHelp\n");
/* just in case */
break_set_xpoints(FALSE);
/* kill last thread */
dbg_del_thread(dbg_curr_process->threads);
dbg_del_process(dbg_curr_process);
dbg_printf("Process of pid=0x%08lx has terminated\n", dbg_curr_pid);
tgt_process_active_close_process(dbg_curr_process, FALSE);
break;
case CREATE_THREAD_DEBUG_EVENT:
@ -687,7 +658,6 @@ void dbg_wait_next_exception(DWORD cont, int count, int mode)
}
dbg_interactiveP = TRUE;
parser_handle(hFile);
dbg_printf("WineDbg terminated on pid 0x%lx\n", dbg_curr_pid);
return 0;
}
@ -928,3 +898,34 @@ enum dbg_start dbg_active_auto(int argc, char* argv[])
dbg_main_loop(hFile);
return start_ok;
}
static BOOL tgt_process_active_close_process(struct dbg_process* pcs, BOOL kill)
{
if (pcs == dbg_curr_process)
{
/* remove all set breakpoints in debuggee code */
break_set_xpoints(FALSE);
/* needed for single stepping (ugly).
* should this be handled inside the server ???
*/
be_cpu->single_step(&dbg_context, FALSE);
if (dbg_curr_thread->in_exception)
{
SetThreadContext(dbg_curr_thread->handle, &dbg_context);
ContinueDebugEvent(dbg_curr_pid, dbg_curr_tid, DBG_CONTINUE);
}
if (!kill && !DebugActiveProcessStop(dbg_curr_pid)) return FALSE;
}
SymCleanup(pcs->handle);
dbg_printf("Process of pid=0x%08lx has terminated\n", pcs->pid);
dbg_del_process(pcs);
return TRUE;
}
struct be_process_io be_process_active_io =
{
tgt_process_active_close_process,
ReadProcessMemory,
WriteProcessMemory,
};

View File

@ -551,6 +551,9 @@ int main(int argc, char** argv)
}
retv = dbg_main_loop(hFile);
while (dbg_process_list)
dbg_process_list->process_io->close_process(dbg_process_list, TRUE);
dbg_save_internal_vars();
return retv;