From 222ac4f0570e7620e50c498ddecd56d0d2e9bbdb Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 2 Sep 2019 04:13:11 +0000 Subject: mgdb: winnt_prepare(), winnt_respond(): initial implementation and integration. --- overlay/mgdb/gdb/winnt-nat.c | 112 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/overlay/mgdb/gdb/winnt-nat.c b/overlay/mgdb/gdb/winnt-nat.c index cdfa210..5d2d309 100644 --- a/overlay/mgdb/gdb/winnt-nat.c +++ b/overlay/mgdb/gdb/winnt-nat.c @@ -10,6 +10,7 @@ #include "target.h" #include "utils.h" #include "inferior.h" +#include "gdbthread.h" #include "inf-child.h" #include "x86-nat.h" @@ -29,10 +30,14 @@ struct winnt_process { int pfd; pid_t pid; + pid_t syspid; + pid_t systid; + pid_t flags; }; static size_t pcnt; static winnt_process * plist; +static char outbuf[256]; static winnt_process * winnt_plist_expand (void) { @@ -99,6 +104,18 @@ static int winnt_pfd_from_pid (pid_t pid) return -1; } +static struct winnt_process * winnt_process_record(pid_t pid) +{ + winnt_process * pdbg; + winnt_process * pcap; + + for (pdbg=plist, pcap=&plist[pcnt]; pdbgpid == pid) + return pdbg; + + return 0; +} + static nfds_t winnt_poll_one_init (struct pollfd * pfds, pid_t pid) { winnt_process * pdbg; @@ -141,6 +158,87 @@ static void winnt_xclose (struct target_ops * t) { } +static void winnt_respond (int pfd, struct __dbg_event * event, int response) +{ + ptid_t ptid; + + event->eresponse = response; + + switch (event->evttype) { + case __DBG_STATE_CREATE_PROCESS: + ptid = ptid_build(event->syspid,0,0); + add_thread(ptid); + ptid = ptid_build(event->syspid,0,event->systid); + add_thread(ptid); + break; + + case __DBG_STATE_CREATE_THREAD: + ptid = ptid_build(event->syspid,0,event->systid); + add_thread(ptid); + break; + + default: + break; + } + + if (__dbg_event_respond(pfd,event) < 0) + winnt_perror("failed to respond to debug event",pfd); +} + +static void winnt_prepare (struct target_ops * t, pid_t pid, int pfd, int attached) +{ + int ret; + struct inferior * cinf; + struct __dbg_event event; + struct winnt_process * pidinfo; + + if (!target_is_pushed(t)) + push_target(t); + + clear_proceed_status(0); + init_wait_for_inferior(); + + if (!(cinf = current_inferior())) + winnt_error("failed to obtain current inferior"); + + if (!(pidinfo = winnt_process_record(pid))) + winnt_perror("internal error: record not found",pid); + + inferior_ptid = pid_to_ptid (pid); + cinf->attach_flag = attached; + + inferior_appeared(cinf,pid); + init_thread_list(); + + while (1) { + do { + ret = __dbg_event_acquire(pfd,&event); + } while ((ret < 0) && (errno == EAGAIN)); + + if (ret < 0) + winnt_perror("failed to acquire preliminary debug event",pid); + + switch (event.evttype) { + case __DBG_STATE_EXCEPTION: + case __DBG_STATE_BREAKPOINT: + case __DBG_STATE_SINGLE_STEP: + pidinfo->syspid = event.syspid; + pidinfo->systid = event.systid; + return; + + case __DBG_STATE_CREATE_THREAD: + case __DBG_STATE_IDLE: + case __DBG_STATE_REPLY_PENDING: + case __DBG_STATE_CREATE_PROCESS: + case __DBG_STATE_DLL_LOAD: + case __DBG_STATE_DLL_UNLOAD: + case __DBG_STATE_EXIT_THREAD: + case __DBG_STATE_EXIT_PROCESS: + winnt_respond(pfd,&event,__DBG_RESPONSE_CONTINUE); + } + } +} + static void winnt_attach (struct target_ops * t, const char * args, int from_tty) { pid_t pid; @@ -168,6 +266,8 @@ static void winnt_attach (struct target_ops * t, const char * args, int from_tty close(pfd); winnt_error ("could not expand debuggee list"); } + + winnt_prepare(t,pid,pfd,from_tty); } static void winnt_detach (struct target_ops * t, const char * args, int from_tty) @@ -259,6 +359,16 @@ static void winnt_create_inferior( winnt_error("Not implemented"); } +static char * winnt_pid_to_str (struct target_ops * t, ptid_t ptid) +{ + if (ptid.tid) + sprintf(outbuf,"Thread %d:%d",ptid.pid,ptid.tid); + else + sprintf(outbuf,"Process %d",ptid.pid); + + return outbuf; +} + static target_ops * winnt_target_alloc (void) { target_ops * t = inf_child_target(); @@ -279,6 +389,8 @@ static target_ops * winnt_target_alloc (void) t->to_mourn_inferior = winnt_mourn_inferior; t->to_create_inferior = winnt_create_inferior; + t->to_pid_to_str = winnt_pid_to_str; + x86_use_watchpoints(t); return t; -- cgit v1.2.3