summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2019-09-07 01:20:32 +0000
committermidipix <writeonce@midipix.org>2019-09-07 01:22:51 +0000
commitdb75fad00d1a81b788ce826a448f69e67f9902e5 (patch)
treee90bdb72e42a0e5d73e5863187bc0724267afcdc
parent039cfefbce2b2e6a96a311c30ff1878eac27ac02 (diff)
downloadchainport-db75fad00d1a81b788ce826a448f69e67f9902e5.tar.bz2
chainport-db75fad00d1a81b788ce826a448f69e67f9902e5.tar.xz
mgdb: winnt_create_inferior(): initial implementation and integration.
-rw-r--r--overlay/mgdb/gdb/winnt-nat.c69
1 files changed, 64 insertions, 5 deletions
diff --git a/overlay/mgdb/gdb/winnt-nat.c b/overlay/mgdb/gdb/winnt-nat.c
index 7009df1..0ba63c3 100644
--- a/overlay/mgdb/gdb/winnt-nat.c
+++ b/overlay/mgdb/gdb/winnt-nat.c
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <stddef.h>
#include <pthread.h>
+#include <sys/cmd.h>
#include <sys/debug.h>
#define winnt_error(msg) \
@@ -210,6 +211,9 @@ static void winnt_prepare (struct target_ops * t, pid_t pid, int pfd, int attach
inferior_appeared(cinf,pid);
init_thread_list();
+ target_terminal_init();
+ target_terminal_inferior();
+
while (1) {
do {
ret = __dbg_event_acquire(pfd,&event);
@@ -218,18 +222,23 @@ static void winnt_prepare (struct target_ops * t, pid_t pid, int pfd, int attach
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)
+ winnt_perror("failed to resume first thread",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;
+ target_terminal_ours();
return;
+ case __DBG_STATE_CREATE_PROCESS:
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:
@@ -354,13 +363,63 @@ static void winnt_mourn_inferior (struct target_ops * t)
}
static void winnt_create_inferior(
- struct target_ops * ops,
+ struct target_ops * t,
char * exec_file,
- char * allargs,
- char ** in_env,
+ char * args,
+ char ** envp,
int from_tty)
{
- winnt_error("Not implemented");
+ int pfd;
+ pid_t pid;
+ size_t arglen;
+ char * argbuf;
+ char ** argv;
+
+ /* validate */
+ if (!exec_file)
+ winnt_error("Executable not set; use `target exec'.");
+
+ /* assume no folded white space, add final null termination */
+ arglen = strlen(args);
+ arglen++;
+
+ if (!(argbuf = (char *)calloc(arglen,1)))
+ winnt_error("Failed to allocate argument string buffer.");
+
+ /* extra pointer for exec_file (argv[0]) */
+ arglen++;
+
+ if (!(argv = (char **)calloc(arglen,sizeof(char *))))
+ winnt_error("Failed to allocate argument vector buffer.");
+
+ arglen--;
+
+ /* argv */
+ argv[0] = exec_file;
+
+ if (__cmd_args_to_argv(args,argbuf,arglen,&argv[1],arglen) < 0)
+ winnt_error("Failed to parse command-line arguments.");
+
+ /* spawn */
+ if ((pfd = __dbg_spawn(exec_file,argv,envp,0)) < 0)
+ winnt_error("Failed to spawn executable.");
+
+ /* syspid */
+ if ((pid = __dbg_query_syspid(pfd)) < 0) {
+ __dbg_kill(pfd);
+ close(pfd);
+ winnt_error("Failed to obtain syspid (should never happen).");
+ }
+
+ /* debuggee list */
+ if (winnt_plist_add(pid,pfd) < 0) {
+ __dbg_kill(pfd);
+ close(pfd);
+ winnt_error ("could not expand debuggee list");
+ }
+
+ /* init loop */
+ winnt_prepare(t,pid,pfd,0);
}
static char * winnt_pid_to_str (struct target_ops * t, ptid_t ptid)