From ff2294bec1e2d5cc2510914edae1bf7576ee5bf8 Mon Sep 17 00:00:00 2001 From: midipix Date: Sun, 8 Sep 2019 15:56:05 +0000 Subject: mgdb: struct winnt_process: added and integrated struct __dbg_event member. --- overlay/mgdb/gdb/winnt-nat.c | 68 ++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/overlay/mgdb/gdb/winnt-nat.c b/overlay/mgdb/gdb/winnt-nat.c index 449b740..5e7dc22 100644 --- a/overlay/mgdb/gdb/winnt-nat.c +++ b/overlay/mgdb/gdb/winnt-nat.c @@ -33,11 +33,12 @@ struct regcache; struct winnt_process { - int pfd; - pid_t pid; - pid_t syspid; - pid_t systid; - pid_t flags; + int pfd; + pid_t pid; + pid_t syspid; + pid_t systid; + pid_t flags; + struct __dbg_event event; }; static size_t pcnt; @@ -278,13 +279,16 @@ static void winnt_respond (int pfd, struct __dbg_event * event, int response) if (__dbg_event_respond(pfd,event) < 0) winnt_perror("failed to respond to debug event",pfd); + + event->syspid = 0; + event->systid = 0; } 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 __dbg_event * event; struct winnt_process * pidinfo; if (!target_is_pushed(t)) @@ -299,6 +303,7 @@ static void winnt_prepare (struct target_ops * t, pid_t pid, int pfd, int attach if (!(pidinfo = winnt_process_record(pid))) winnt_perror("internal error: record not found",pid); + event = &pidinfo->event; inferior_ptid = pid_to_ptid (pid); cinf->attach_flag = attached; @@ -310,25 +315,25 @@ static void winnt_prepare (struct target_ops * t, pid_t pid, int pfd, int attach while (1) { do { - ret = __dbg_event_acquire(pfd,&event); + ret = __dbg_event_acquire(pfd,event); } while ((ret < 0) && (errno == EAGAIN)); if (ret < 0) winnt_perror("failed to acquire preliminary debug event",pid); - if ((event.evttype == __DBG_STATE_CREATE_PROCESS) && !attached) - if (__dbg_resume_thread(pfd,event.systid) < 0) + if ((event->evttype == __DBG_STATE_CREATE_PROCESS) && !attached) + if (__dbg_resume_thread(pfd,event->systid) < 0) winnt_perror("failed to resume first thread",pid); - inferior_ptid.pid = event.syspid; - inferior_ptid.tid = event.systid; + inferior_ptid.pid = event->syspid; + inferior_ptid.tid = event->systid; - switch (event.evttype) { + switch (event->evttype) { case __DBG_STATE_EXCEPTION: case __DBG_STATE_BREAKPOINT: case __DBG_STATE_SINGLE_STEP: - pidinfo->syspid = event.syspid; - pidinfo->systid = event.systid; + pidinfo->syspid = event->syspid; + pidinfo->systid = event->systid; target_terminal_ours(); return; @@ -340,7 +345,7 @@ static void winnt_prepare (struct target_ops * t, pid_t pid, int pfd, int attach case __DBG_STATE_DLL_UNLOAD: case __DBG_STATE_EXIT_THREAD: case __DBG_STATE_EXIT_PROCESS: - winnt_respond(pfd,&event,__DBG_RESPONSE_CONTINUE); + winnt_respond(pfd,event,__DBG_RESPONSE_CONTINUE); } } } @@ -419,12 +424,32 @@ static ptid_t winnt_wait( struct target_waitstatus * waitstatus, int target_options) { - struct __dbg_event dbgevent; + struct __dbg_event event; + struct winnt_process * pdbg; + struct winnt_process * pcap; + struct winnt_process * pidinfo; struct pollfd pollfdbuf[512]; struct pollfd * pfds; struct pollfd * pfd; nfds_t nfds,i; + if (ptid.pid < 0) + for (pdbg=plist, pcap=&plist[pcnt]; pdbgevent.systid) + return ptid_build( + pdbg->event.syspid,0, + pdbg->event.systid); + + if (ptid.pid > 0) { + if (!(pidinfo = winnt_process_record(event.syspid))) + winnt_perror("internal error: record not found",event.syspid); + + if (pidinfo->event.systid) + return ptid_build( + pidinfo->event.syspid,0, + pidinfo->event.systid); + } + if (pcnt*sizeof(*pfds) < sizeof(pollfdbuf)) pfds = pollfdbuf; else if (!(pfds = (struct pollfd *)calloc(pcnt,sizeof(*pfds)))) @@ -444,10 +469,17 @@ static ptid_t winnt_wait( if (!pfd) return null_ptid; - if (__dbg_event_query_one(pfd->fd,&dbgevent) < 0) + if (__dbg_event_query_one(pfd->fd,&event) < 0) return null_ptid; - return ptid_build(dbgevent.syspid,0,dbgevent.systid); + if (!(pidinfo = winnt_process_record(event.syspid))) + winnt_perror("internal error: record not found",event.syspid); + + memcpy(&pidinfo->event,&event,sizeof(event)); + + return ptid_build( + event.syspid,0, + event.systid); } static void winnt_resume ( -- cgit v1.2.3