remote_gdb.cc (10597:bd68c6838b9f) remote_gdb.cc (10598:3d7653a2538b)
1/*
2 * Copyright 2014 Google, Inc.
3 * Copyright (c) 2002-2005 The Regents of The University of Michigan
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright

--- 152 unchanged lines hidden (view full) ---

161}
162#endif
163
164///////////////////////////////////////////////////////////
165//
166//
167//
168
1/*
2 * Copyright 2014 Google, Inc.
3 * Copyright (c) 2002-2005 The Regents of The University of Michigan
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright

--- 152 unchanged lines hidden (view full) ---

161}
162#endif
163
164///////////////////////////////////////////////////////////
165//
166//
167//
168
169GDBListener::Event::Event(GDBListener *l, int fd, int e)
169GDBListener::InputEvent::InputEvent(GDBListener *l, int fd, int e)
170 : PollEvent(fd, e), listener(l)
171{}
172
173void
170 : PollEvent(fd, e), listener(l)
171{}
172
173void
174GDBListener::Event::process(int revent)
174GDBListener::InputEvent::process(int revent)
175{
176 listener->accept();
177}
178
179GDBListener::GDBListener(BaseRemoteGDB *g, int p)
175{
176 listener->accept();
177}
178
179GDBListener::GDBListener(BaseRemoteGDB *g, int p)
180 : event(NULL), gdb(g), port(p)
180 : inputEvent(NULL), gdb(g), port(p)
181{
182 assert(!gdb->listener);
183 gdb->listener = this;
184}
185
186GDBListener::~GDBListener()
187{
181{
182 assert(!gdb->listener);
183 gdb->listener = this;
184}
185
186GDBListener::~GDBListener()
187{
188 if (event)
189 delete event;
188 if (inputEvent)
189 delete inputEvent;
190}
191
192string
193GDBListener::name()
194{
195 return gdb->name() + ".listener";
196}
197

--- 5 unchanged lines hidden (view full) ---

203 return;
204 }
205
206 while (!listener.listen(port, true)) {
207 DPRINTF(GDBMisc, "Can't bind port %d\n", port);
208 port++;
209 }
210
190}
191
192string
193GDBListener::name()
194{
195 return gdb->name() + ".listener";
196}
197

--- 5 unchanged lines hidden (view full) ---

203 return;
204 }
205
206 while (!listener.listen(port, true)) {
207 DPRINTF(GDBMisc, "Can't bind port %d\n", port);
208 port++;
209 }
210
211 event = new Event(this, listener.getfd(), POLLIN);
212 pollQueue.schedule(event);
211 inputEvent = new InputEvent(this, listener.getfd(), POLLIN);
212 pollQueue.schedule(inputEvent);
213
214#ifndef NDEBUG
215 gdb->number = debuggers.size();
216 debuggers.push_back(gdb);
217#endif
218
219#ifndef NDEBUG
220 ccprintf(cerr, "%d: %s: listening for remote gdb #%d on port %d\n",

--- 15 unchanged lines hidden (view full) ---

236 if (sfd != -1) {
237 if (gdb->isattached())
238 close(sfd);
239 else
240 gdb->attach(sfd);
241 }
242}
243
213
214#ifndef NDEBUG
215 gdb->number = debuggers.size();
216 debuggers.push_back(gdb);
217#endif
218
219#ifndef NDEBUG
220 ccprintf(cerr, "%d: %s: listening for remote gdb #%d on port %d\n",

--- 15 unchanged lines hidden (view full) ---

236 if (sfd != -1) {
237 if (gdb->isattached())
238 close(sfd);
239 else
240 gdb->attach(sfd);
241 }
242}
243
244BaseRemoteGDB::Event::Event(BaseRemoteGDB *g, int fd, int e)
244BaseRemoteGDB::InputEvent::InputEvent(BaseRemoteGDB *g, int fd, int e)
245 : PollEvent(fd, e), gdb(g)
246{}
247
248void
245 : PollEvent(fd, e), gdb(g)
246{}
247
248void
249BaseRemoteGDB::Event::process(int revent)
249BaseRemoteGDB::InputEvent::process(int revent)
250{
251 BaseCPU *cpu = gdb->context->getCpuPtr();
252 EventQueue *eq = cpu->comInstEventQueue[gdb->context->threadId()];
253 if (revent & POLLIN) {
254 gdb->trapEvent.type(SIGILL);
255 // Here "ticks" aren't simulator ticks which measure time, they're
256 // instructions committed by the CPU.
257 eq->schedule(&gdb->trapEvent, eq->getCurTick());

--- 6 unchanged lines hidden (view full) ---

264
265void
266BaseRemoteGDB::TrapEvent::process()
267{
268 gdb->trap(_type);
269}
270
271BaseRemoteGDB::BaseRemoteGDB(System *_system, ThreadContext *c, size_t cacheSize)
250{
251 BaseCPU *cpu = gdb->context->getCpuPtr();
252 EventQueue *eq = cpu->comInstEventQueue[gdb->context->threadId()];
253 if (revent & POLLIN) {
254 gdb->trapEvent.type(SIGILL);
255 // Here "ticks" aren't simulator ticks which measure time, they're
256 // instructions committed by the CPU.
257 eq->schedule(&gdb->trapEvent, eq->getCurTick());

--- 6 unchanged lines hidden (view full) ---

264
265void
266BaseRemoteGDB::TrapEvent::process()
267{
268 gdb->trap(_type);
269}
270
271BaseRemoteGDB::BaseRemoteGDB(System *_system, ThreadContext *c, size_t cacheSize)
272 : event(NULL), trapEvent(this), listener(NULL), number(-1), fd(-1),
272 : inputEvent(NULL), trapEvent(this), listener(NULL), number(-1), fd(-1),
273 active(false), attached(false),
274 system(_system), context(c),
275 gdbregs(cacheSize)
276{
277 memset(gdbregs.regs, 0, gdbregs.bytes());
278}
279
280BaseRemoteGDB::~BaseRemoteGDB()
281{
273 active(false), attached(false),
274 system(_system), context(c),
275 gdbregs(cacheSize)
276{
277 memset(gdbregs.regs, 0, gdbregs.bytes());
278}
279
280BaseRemoteGDB::~BaseRemoteGDB()
281{
282 if (event)
283 delete event;
282 if (inputEvent)
283 delete inputEvent;
284}
285
286string
287BaseRemoteGDB::name()
288{
289 return system->name() + ".remote_gdb";
290}
291
292bool
293BaseRemoteGDB::isattached()
294{ return attached; }
295
296void
297BaseRemoteGDB::attach(int f)
298{
299 fd = f;
300
284}
285
286string
287BaseRemoteGDB::name()
288{
289 return system->name() + ".remote_gdb";
290}
291
292bool
293BaseRemoteGDB::isattached()
294{ return attached; }
295
296void
297BaseRemoteGDB::attach(int f)
298{
299 fd = f;
300
301 event = new Event(this, fd, POLLIN);
302 pollQueue.schedule(event);
301 inputEvent = new InputEvent(this, fd, POLLIN);
302 pollQueue.schedule(inputEvent);
303
304 attached = true;
305 DPRINTFN("remote gdb attached\n");
306}
307
308void
309BaseRemoteGDB::detach()
310{
311 attached = false;
312 close(fd);
313 fd = -1;
314
303
304 attached = true;
305 DPRINTFN("remote gdb attached\n");
306}
307
308void
309BaseRemoteGDB::detach()
310{
311 attached = false;
312 close(fd);
313 fd = -1;
314
315 pollQueue.remove(event);
315 pollQueue.remove(inputEvent);
316 DPRINTFN("remote gdb detached\n");
317}
318
319const char *
320BaseRemoteGDB::gdb_command(char cmd)
321{
322 switch (cmd) {
323 case GDBSignal: return "KGDB_SIGNAL";

--- 720 unchanged lines hidden ---
316 DPRINTFN("remote gdb detached\n");
317}
318
319const char *
320BaseRemoteGDB::gdb_command(char cmd)
321{
322 switch (cmd) {
323 case GDBSignal: return "KGDB_SIGNAL";

--- 720 unchanged lines hidden ---