From b6d2555ec500494d531e94001c723cbc4c06225c Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 12 Oct 2005 13:45:21 -0400 Subject: Make it easier to attach the remote debugger. base/remote_gdb.cc: Keep track of a vector of all of the usable debuggers and provide a current_debugger variable that can be set from gdb to specify which remote debugger is desired. If debugger() is called and the current_debugger is not attached, call accept on its listener so we can still attach a remote debugger from the gdb prompt if we had forgotten to before. Print out more information when the simulator starts so we can distinguish debuggers more easily. base/remote_gdb.hh: Have a remote debugger instance keep track of its listener. Number the remote debuggers so it's easier to figure out which is which. --HG-- extra : convert_revision : 97119597ac3772ea4df6da3b3a4827f50253a51f --- base/remote_gdb.cc | 37 ++++++++++++++++++++++++++++--------- base/remote_gdb.hh | 7 +++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/base/remote_gdb.cc b/base/remote_gdb.cc index 3af73179a..1f3a60bbf 100644 --- a/base/remote_gdb.cc +++ b/base/remote_gdb.cc @@ -134,13 +134,19 @@ using namespace std; #ifdef DEBUG -RemoteGDB *theDebugger = NULL; +vector debuggers; +int current_debugger = -1; void debugger() { - if (theDebugger) - theDebugger->trap(ALPHA_KENTRY_IF); + if (current_debugger >= 0 && current_debugger < debuggers.size()) { + RemoteGDB *gdb = debuggers[current_debugger]; + if (!gdb->isattached()) + gdb->listener->accept(); + if (gdb->isattached()) + gdb->trap(ALPHA_KENTRY_IF); + } } #endif @@ -161,7 +167,10 @@ GDBListener::Event::process(int revent) GDBListener::GDBListener(RemoteGDB *g, int p) : event(NULL), gdb(g), port(p) -{} +{ + assert(!gdb->listener); + gdb->listener = this; +} GDBListener::~GDBListener() { @@ -183,9 +192,21 @@ GDBListener::listen() port++; } - cerr << "Listening for remote gdb connection on port " << port << endl; event = new Event(this, listener.getfd(), POLLIN); pollQueue.schedule(event); + +#ifdef DEBUG + gdb->number = debuggers.size(); + debuggers.push_back(gdb); +#endif + +#ifdef DEBUG + ccprintf(cerr, "%d: %s: listening for remote gdb #%d on port %d\n", + curTick, name(), gdb->number, port); +#else + ccprintf(cerr, "%d: %s: listening for remote gdb on port %d\n", + curTick, name(), port); +#endif } void @@ -228,7 +249,8 @@ RemoteGDB::Event::process(int revent) } RemoteGDB::RemoteGDB(System *_system, ExecContext *c) - : event(NULL), fd(-1), active(false), attached(false), + : event(NULL), listener(NULL), number(-1), fd(-1), + active(false), attached(false), system(_system), pmem(_system->physmem), context(c) { memset(gdbregs, 0, sizeof(gdbregs)); @@ -260,9 +282,6 @@ RemoteGDB::attach(int f) attached = true; DPRINTFN("remote gdb attached\n"); -#ifdef DEBUG - theDebugger = this; -#endif } void diff --git a/base/remote_gdb.hh b/base/remote_gdb.hh index f9a220a5d..652a58317 100644 --- a/base/remote_gdb.hh +++ b/base/remote_gdb.hh @@ -40,8 +40,13 @@ class System; class ExecContext; class PhysicalMemory; +class GDBListener; class RemoteGDB { + private: + friend void debugger(); + friend class GDBListener; + protected: class Event : public PollEvent { @@ -55,6 +60,8 @@ class RemoteGDB friend class Event; Event *event; + GDBListener *listener; + int number; protected: int fd; -- cgit v1.2.3