public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] scox/dyninst: Share an already attached process
@ 2015-02-13 22:07 scox
0 siblings, 0 replies; only message in thread
From: scox @ 2015-02-13 22:07 UTC (permalink / raw)
To: archer-commits
The branch, scox/dyninst has been updated
via c1019e06804801746b14fdc62e2b06f3a2a7e01d (commit)
from 9bd9119042646a9f974898ae4ef7a92b074268fd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit c1019e06804801746b14fdc62e2b06f3a2a7e01d
Author: Stan Cox <scox@redhat.com>
Date: Fri Feb 13 17:05:40 2015 -0500
Share an already attached process
* server.c (set_client_state): Clear process specific members.
(match_client_state): Determine if this is an already attached process.
(handle_v_run): Determine if trying to run an already attached process.
(handle_status): ...and if so then treat vRun as a ? status request.
* server.h (client_state): Add executable.
* (dyninst-low.cc, event-loop.c): Debug message cleanup
* remote-utils.c: Add fd to getpkt/putpkt messages
-----------------------------------------------------------------------
Summary of changes:
gdb/gdbserver/dyninst-low.cc | 21 ++++++--
gdb/gdbserver/event-loop.c | 5 --
gdb/gdbserver/remote-utils.c | 20 ++------
gdb/gdbserver/server.c | 104 ++++++++++++++++++++++++++++++++++++++++-
gdb/gdbserver/server.h | 16 ++++---
5 files changed, 130 insertions(+), 36 deletions(-)
First 500 lines of diff:
diff --git a/gdb/gdbserver/dyninst-low.cc b/gdb/gdbserver/dyninst-low.cc
index be4d6ef..195f664 100644
--- a/gdb/gdbserver/dyninst-low.cc
+++ b/gdb/gdbserver/dyninst-low.cc
@@ -222,17 +222,19 @@ public:
{
Thread::const_ptr thr;
if (event != NULL)
- DEBUG(event->getEventType().code() << " " << EventType::LWPCreate);
- if (event != NULL)
{
if (event->getEventType().code() == EventType::LWPCreate)
{
EventNewLWP::const_ptr newlwp_ev = event->getEventNewLWP();
+ if (event != NULL)
+ DEBUG(event->getEventType().code() << " LWPCreate");
return newlwp_ev->getNewThread();
}
else if (event->getEventType().code() == EventType::UserThreadCreate)
{
EventNewUserThread::const_ptr newlwp_ev = event->getEventNewUserThread();
+ if (event != NULL)
+ DEBUG(event->getEventType().code() << " UserThreadCreate");
return newlwp_ev->getNewThread();
}
}
@@ -513,6 +515,9 @@ dyninst_create_inferior (char *program, char **allargs)
static int
dyninst_attach (unsigned long pid)
{
+ ProcessSet::iterator procset_it = dyninst_procset->find(pid);
+ if (procset_it != dyninst_procset->end())
+ DEBUG("already attached to pid " << pid);
Process::ptr dyninst_proc = Process::attachProcess(pid);
if (dyninst_proc == Process::ptr())
error ("Cannot attach to process %ld: %s",
@@ -622,7 +627,9 @@ dyninst_resume (struct thread_resume *resume_info, size_t n)
switch (resume_info[i].kind)
{
case resume_step:
- DEBUG("in step mode", pid_to_string (th));
+ MachRegisterVal result;
+ th->getRegister(MachRegister(x86_64::rip), result);
+ DEBUG("in step mode @" << result, pid_to_string (th));
if (! th->setSingleStepMode(true))
DYNERR("Unable to setSingleStepMode");
case resume_continue:
@@ -964,7 +971,9 @@ dyninst_read_pc (struct regcache *regcache)
if (the_low_target.get_pc == NULL)
return 0;
- return (*the_low_target.get_pc) (regcache);
+ CORE_ADDR pc = (*the_low_target.get_pc) (regcache);
+ DEBUG("pc is " << pc);
+ return pc;
}
static void
@@ -1106,8 +1115,8 @@ dyninst_insert_point (enum raw_bkpt_type type, CORE_ADDR addr, int len,
Process::const_ptr dyninst_process = th->getProcess();
bool result;
- DEBUG(" addr=" << addr, pid_to_string(th));
Breakpoint::ptr brp = Breakpoint::newBreakpoint();
+ DEBUG(" addr=" << addr << " " << brp->getToAddress(), pid_to_string(th));
brp->setData(bp);
if (! (result = dyninst_process->addBreakpoint(addr, brp)))
DYNERR ("Unable insert breakpoint at %#lx", (long)addr);
@@ -1123,7 +1132,6 @@ dyninst_remove_point (enum raw_bkpt_type type, CORE_ADDR addr, int len,
struct raw_breakpoint *rbp)
{
Thread::const_ptr th = dyninst_get_inferior_thread();
- DEBUG(" addr=" << addr, pid_to_string (th) );
Process::const_ptr dyninst_process = th->getProcess();
std::vector<Breakpoint::ptr>::iterator it;
@@ -1133,6 +1141,7 @@ dyninst_remove_point (enum raw_bkpt_type type, CORE_ADDR addr, int len,
Breakpoint::ptr bp = *it;
if ((struct raw_breakpoint*)bp->getData() == rbp)
{
+ DEBUG(" addr=" << addr << " " << bp->getToAddress(), pid_to_string(th));
if (! (result = dyninst_process->rmBreakpoint(addr, bp)))
DYNERR ("Unable remove breakpoint at %#lx", (long)addr);
break;
diff --git a/gdb/gdbserver/event-loop.c b/gdb/gdbserver/event-loop.c
index 7185c02..70413dd 100644
--- a/gdb/gdbserver/event-loop.c
+++ b/gdb/gdbserver/event-loop.c
@@ -543,7 +543,6 @@ wait_for_event (void)
}
/* Enqueue all detected file events. */
- fprintf (stderr,"%s 1 #fds=%d\n",__FUNCTION__,gdb_notifier.num_fds);
for (file_ptr = gdb_notifier.first_file_handler;
file_ptr != NULL && num_found > 0;
file_ptr = file_ptr->next_file)
@@ -595,8 +594,6 @@ start_event_loop (void)
{
/* Any events already waiting in the queue? */
int res = process_event ();
- if (debug_threads)
- fprintf (stderr, "COX After process_event\n");
/* Did the event handler want the event loop to stop? */
if (res == -1)
@@ -620,8 +617,6 @@ start_event_loop (void)
sources left. This will make the event loop stop, and the
application exit. */
- if (debug_threads)
- fprintf (stderr, "COX Before start_event_loop return\n");
if (wait_for_event () < 0)
return;
}
diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index d7973d2..2e5c20b 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -607,11 +607,6 @@ read_ptid (char *buf, char **obuf)
static int
write_prim (gdb_fildes_t fd, const void *buf, int count)
{
- if (debug_threads)
- {
- client_state *cs = get_client_state(0);
- printf ("%s %d %.*s\n", __FUNCTION__,cs->file_desc, count, (char*)buf);
- }
if (remote_connection_is_stdio ())
return write (fileno (stdout), buf, count);
else
@@ -625,11 +620,6 @@ write_prim (gdb_fildes_t fd, const void *buf, int count)
static int
read_prim (gdb_fildes_t fd, void *buf, int count)
{
- if (debug_threads)
- {
- client_state *cs = get_client_state(0);
- printf ("%s %d %.*s\n", __FUNCTION__,cs->file_desc, count, (char*)buf);
- }
if (remote_connection_is_stdio ())
return read (fileno (stdin), buf, count);
else
@@ -688,9 +678,9 @@ putpkt_binary_1 (char *buf, int cnt, int is_notif)
if (remote_debug)
{
if (is_notif)
- fprintf (stderr, "putpkt (\"%s\"); [notif]\n", buf2);
+ fprintf (stderr, "putpkt/%d (\"%s\"); [notif]\n", cs->file_desc, buf2);
else
- fprintf (stderr, "putpkt (\"%s\"); [noack mode]\n", buf2);
+ fprintf (stderr, "putpkt/%d (\"%s\"); [noack mode]\n", cs->file_desc, buf2);
fflush (stderr);
}
break;
@@ -698,7 +688,7 @@ putpkt_binary_1 (char *buf, int cnt, int is_notif)
if (remote_debug)
{
- fprintf (stderr, "putpkt (\"%s\"); [looking for ack]\n", buf2);
+ fprintf (stderr, "putpkt/%d (\"%s\"); [looking for ack]\n", cs->file_desc, buf2);
fflush (stderr);
}
@@ -1035,7 +1025,7 @@ getpkt (gdb_fildes_t fd, char *buf)
{
if (remote_debug)
{
- fprintf (stderr, "getpkt (\"%s\"); [sending ack] \n", buf);
+ fprintf (stderr, "getpkt/%d(\"%s\"); [sending ack] \n", fd, buf);
fflush (stderr);
}
@@ -1052,7 +1042,7 @@ getpkt (gdb_fildes_t fd, char *buf)
{
if (remote_debug)
{
- fprintf (stderr, "getpkt (\"%s\"); [no ack sent] \n", buf);
+ fprintf (stderr, "getpkt/%d (\"%s\"); [no ack sent] \n", fd, buf);
fflush (stderr);
}
}
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 03edb13..3db0661 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -89,6 +89,18 @@ new_client_state ()
}
+void
+dump_client_state ()
+{
+ client_state *cs;
+ for (cs = set_client_state (-1); cs != NULL; cs = cs->next)
+ if (debug_threads)
+ {
+ debug_printf ("%s %s %d cont_thr %#lx gen thr %#lx\n", __FUNCTION__,cs->executable, cs->file_desc, (long unsigned)cs->cont_thread.pid, (long unsigned)cs->general_thread.pid);
+ debug_printf ("%s %d all procs %#lx all thrs %#lx curr thr %#lx\n", __FUNCTION__,(int)cs->last_ptid.pid, (unsigned long)cs->all_processes.head, (unsigned long)cs->all_threads.head, (unsigned long)cs->current_thread);
+ }
+}
+
client_state *
set_client_state (gdb_fildes_t fd)
{
@@ -130,8 +142,6 @@ set_client_state (gdb_fildes_t fd)
current_fd = fd;
return csidx;
}
- else if (csidx->file_desc > fd)
- break;
else if (csidx->next == NULL)
break;
}
@@ -140,8 +150,23 @@ set_client_state (gdb_fildes_t fd)
new_csidx = new_client_state ();
*new_csidx = *csidx;
new_csidx->file_desc = fd;
+ new_csidx->executable = NULL;
+#if 1
+ new_csidx->cont_thread = null_ptid;
+ new_csidx->general_thread = null_ptid;
+ new_csidx->wrapper_argv = NULL;
+ new_csidx->signal_pid = 0;
+ new_csidx->last_ptid = null_ptid;
+ new_csidx->current_thread = 0;
+ new_csidx->all_processes.head = NULL;
+ new_csidx->all_processes.tail = NULL;
+ new_csidx->all_threads.head = NULL;
+ new_csidx->all_threads.tail = NULL;
+#endif
current_fd = fd;
csidx->next = new_csidx;
+ if (debug_threads)
+ debug_printf ("%s Called returned fd=%d current=%d\n", __FUNCTION__, fd, current_fd);
return new_csidx;
}
@@ -153,6 +178,63 @@ get_client_state (void)
return set_client_state (0);
}
+client_state *
+match_client_state (char *executable)
+{
+ client_state *cs;
+ char *new_executable;
+ int entry = 0;
+ client_state *matched_cs = NULL;
+ dump_client_state();
+ for (cs = set_client_state (-1); cs != NULL; cs = cs->next)
+ {
+ if (debug_threads)
+ debug_printf ("%s %s looking for %s entry %d for fd %d\n", __FUNCTION__, cs->executable, executable, entry++, cs->file_desc);
+ }
+
+ for (cs = set_client_state (-1); cs != NULL; cs = cs->next)
+ {
+ if (cs->executable && strcmp (cs->executable, executable) == 0)
+ {
+ matched_cs = cs;
+ break;
+ }
+ }
+
+ cs = set_client_state (0);
+ if (matched_cs && cs != matched_cs)
+ {
+ client_state *tcs = get_client_state();
+ client_state *next_cs = cs->next;
+ gdb_fildes_t file_desc = cs->file_desc;
+ *cs = *matched_cs;
+ cs->next = next_cs;
+ cs->file_desc = file_desc;
+#if 0
+ cs->executable = matched_cs->executable;
+ cs->cont_thread = matched_cs->cont_thread;
+ cs->general_thread = matched_cs->general_thread;
+ cs->wrapper_argv = matched_cs->wrapper_argv;
+ cs->signal_pid = matched_cs->signal_pid;
+ cs->last_ptid = matched_cs->last_ptid;
+ cs->all_processes.head = matched_cs->all_processes.head;
+ cs->all_threads.head = matched_cs->all_threads.head;
+ cs->current_thread = matched_cs->current_thread;
+#endif
+ debug_printf ("%s current=%d returning %d\n", __FUNCTION__,tcs->file_desc,cs->file_desc);
+ return cs;
+ }
+ else
+ {
+ new_executable = xmalloc (strlen (executable) + 1);
+ strcpy (new_executable, executable);
+ cs->executable = new_executable;
+ if (debug_threads)
+ debug_printf ("%s %s %d returning null\n", __FUNCTION__, cs->executable, cs->file_desc);
+ }
+
+ return NULL;
+}
/* Post a stop reply to the stop reply queue. */
@@ -247,6 +329,8 @@ start_inferior (char **argv)
debug_flush ();
}
+ match_client_state (new_argv[0]);
+
#ifdef SIGTTOU
signal (SIGTTOU, SIG_DFL);
signal (SIGTTIN, SIG_DFL);
@@ -2438,6 +2522,8 @@ handle_v_attach (char *own_buf)
int pid;
pid = strtol (own_buf + 8, NULL, 16);
+ if (debug_threads)
+ debug_printf ("%s %d %d\n", __FUNCTION__, cs->file_desc,pid);
if (pid != 0 && attach_inferior (pid) == 0)
{
/* Don't report shared library events after attaching, even if
@@ -2535,7 +2621,14 @@ handle_v_run (char *own_buf)
freeargv (cs->program_argv);
cs->program_argv = new_argv;
+ if (match_client_state (new_argv[0]))
+ {
+ if (debug_threads)
+ debug_printf ("%s returning 0\n",__FUNCTION__);
+ return 0;
+ }
start_inferior (cs->program_argv);
+
if (cs->last_status.kind == TARGET_WAITKIND_STOPPED)
{
prepare_resume_reply (own_buf, cs->last_ptid, &cs->last_status);
@@ -2583,6 +2676,7 @@ handle_v_kill (char *own_buf)
}
}
+static void handle_status (char *);
/* Handle all of the extended 'v' packets. */
void
handle_v_requests (char *own_buf, int packet_len, int *new_packet_len, gdb_client_data client_data)
@@ -2635,7 +2729,11 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len, gdb_clien
write_enn (own_buf);
return;
}
- handle_v_run (own_buf);
+ if (! handle_v_run (own_buf))
+ {
+ strcpy (own_buf, "?");
+ handle_status (own_buf);
+ }
return;
}
diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h
index 034205d..6a55a7b 100644
--- a/gdb/gdbserver/server.h
+++ b/gdb/gdbserver/server.h
@@ -117,15 +117,17 @@ extern int handle_target_event (int err, gdb_client_data client_data);
struct client_state
{
+ char *executable;
// file descriptor corresponding to this client
gdb_fildes_t file_desc;
- /* --once: Exit after the first connection has closed. */
+ // following were in server.c
+ // --once: Exit after the first connection has closed.
int run_once;
- /* --multi */
+ // --multi
int multi_process;
- /* QNonStop packet */
+ // QNonStop packet
int non_stop;
- /* QDisableRandomization packet */
+ // QDisableRandomization packet
int disable_randomization;
/* The thread set with an `Hc' packet. `Hc' is deprecated in favor of
`vCont'. Note the multi-process extensions made `vCont' a
@@ -138,7 +140,7 @@ struct client_state
some places in the backends check it to know when (and for which
thread) single-thread scheduler-locking is in effect. */
ptid_t cont_thread;
- /* The thread set with an `Hg' packet. */
+ // The thread set with an `Hg' packet.
ptid_t general_thread;
int server_waiting;
int extended_protocol;
@@ -156,10 +158,10 @@ struct client_state
unsigned char readchar_buf[BUFSIZ];
int readchar_bufcnt;
unsigned char *readchar_bufp;
- // was in server.h
+ // following were in mem-break.c
const unsigned char *breakpoint_data;
int breakpoint_len;
- // was in inferior.c
+ // following were in inferior.c
struct inferior_list all_processes;
struct inferior_list all_threads;
struct thread_info *current_thread;
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-02-13 22:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-13 22:07 [SCM] scox/dyninst: Share an already attached process scox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).