From 5d1280ade1bdab8f4f0754ce1ae9c27a89ee6358 Mon Sep 17 00:00:00 2001 From: midipix Date: Fri, 13 Sep 2019 23:33:44 +0000 Subject: mgdb: winnt_get_modules(): initial implementation and integration. --- overlay/mgdb/gdb/winnt-nat.c | 94 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 6 deletions(-) diff --git a/overlay/mgdb/gdb/winnt-nat.c b/overlay/mgdb/gdb/winnt-nat.c index 564c7f2..2d9999d 100644 --- a/overlay/mgdb/gdb/winnt-nat.c +++ b/overlay/mgdb/gdb/winnt-nat.c @@ -33,12 +33,14 @@ struct regcache; struct winnt_process { - int pfd; - pid_t pid; - pid_t syspid; - pid_t systid; - pid_t flags; - struct __dbg_event event; + int pfd; + pid_t pid; + pid_t syspid; + pid_t systid; + pid_t flags; + int nmodules; + struct __dbg_module_info * modules; + struct __dbg_event event; }; static size_t pcnt; @@ -93,6 +95,28 @@ static int winnt_plist_add (pid_t pid, int pfd) : -1; } +static void winnt_free_modules(struct winnt_process * pidinfo) +{ + struct __dbg_module_info * module; + struct __dbg_module_info * modules_base; + struct __dbg_module_info * modules_cap; + + if (!pidinfo->modules) + return; + + modules_base = pidinfo->modules; + modules_cap = &modules_base[pidinfo->nmodules]; + + for (module=modules_base; modulemodule_name) + free(module->module_name); + + free(pidinfo->modules); + + pidinfo->modules = 0; + pidinfo->nmodules = 0; +} + static void winnt_plist_remove (pid_t pid) { struct winnt_process * pdbg; @@ -100,7 +124,9 @@ static void winnt_plist_remove (pid_t pid) for (pdbg=plist, pcap=&plist[pcnt]; pdbgpid == pid) { + winnt_free_modules(pdbg); pdbg->pid = 0; + pdbg->pfd = 0; return; } } @@ -156,6 +182,60 @@ static char * winnt_pid_to_exec_file (struct target_ops * t, int pid) return outbuf; } +static void winnt_get_modules(struct winnt_process * pidinfo) +{ + void * addr; + struct __dbg_module_info * module; + struct __dbg_module_info * modules; + struct __dbg_module_info * modules_cap; + ssize_t nbytes; + size_t nmodules; + + winnt_free_modules(pidinfo); + + if (!(addr = calloc(2048,sizeof(*modules)))) + return; + + nbytes = __dbg_info_get( + pidinfo->pfd,0, + __DBG_INFO_CACHED_MODULE_LIST, + addr,2048*sizeof(*modules)); + + if (nbytes < 0) { + free(addr); + return; + }; + + nmodules = nbytes / sizeof(*modules); + modules = (struct __dbg_module_info *)calloc(nmodules,sizeof(*modules)); + + if (!modules) { + free(addr); + return; + } + + memcpy(modules,addr,nmodules*sizeof(*modules)); + free(addr); + + module = modules; + modules_cap = &modules[nmodules]; + + for (; modulepfd,module->module_key, + __DBG_INFO_MODULE_RPATH, + outbuf,WINNT_OUTBUF_SIZE); + + if (nbytes > 0) + module->module_name = strdup(outbuf); + + module++; + } + + pidinfo->modules = modules; + pidinfo->nmodules = nmodules; +} + static void winnt_fetch_registers ( struct target_ops * t, struct regcache * rcache, @@ -421,6 +501,7 @@ static void winnt_attach (struct target_ops * t, const char * args, int from_tty } winnt_prepare(t,pid,pfd,from_tty); + winnt_get_modules(winnt_process_record(pid)); } static void winnt_mourn_inferior (struct target_ops * t) @@ -637,6 +718,7 @@ static void winnt_create_inferior( /* init loop */ winnt_prepare(t,pid,pfd,0); + winnt_get_modules(winnt_process_record(pid)); } static char * winnt_pid_to_str (struct target_ops * t, ptid_t ptid) -- cgit v1.2.3