remote_gdb.hh revision 77
12SN/A/* 210292SAndreas.Sandberg@ARM.com * Copyright (c) 2003 The Regents of The University of Michigan 310292SAndreas.Sandberg@ARM.com * All rights reserved. 410292SAndreas.Sandberg@ARM.com * 54039Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272SN/A */ 282SN/A 292SN/A#ifndef __REMOTE_GDB_HH__ 302665Ssaidi@eecs.umich.edu#define __REMOTE_GDB_HH__ 312665Ssaidi@eecs.umich.edu 322665Ssaidi@eecs.umich.edu#include <map> 3310475SAndrew.Bardsley@arm.com 342SN/A#include "base/kgdb.h" 352SN/A#include "cpu/pc_event.hh" 361354SN/A#include "base/pollevent.hh" 371354SN/A#include "base/socket.hh" 382SN/A 394046Sbinkertn@umich.educlass System; 402SN/Aclass ExecContext; 4156SN/Aclass PhysicalMemory; 428232Snate@binkert.org 431031SN/Aclass RemoteGDB 446214Snate@binkert.org{ 454167Sbinkertn@umich.edu protected: 462SN/A class Event : public PollEvent 472SN/A { 482SN/A protected: 4910475SAndrew.Bardsley@arm.com RemoteGDB *gdb; 5010475SAndrew.Bardsley@arm.com 5110475SAndrew.Bardsley@arm.com public: 5210475SAndrew.Bardsley@arm.com Event(RemoteGDB *g, int fd, int e); 5310475SAndrew.Bardsley@arm.com void process(int revent); 5410475SAndrew.Bardsley@arm.com }; 5510475SAndrew.Bardsley@arm.com 568232Snate@binkert.org friend class Event; 5710475SAndrew.Bardsley@arm.com Event *event; 5810475SAndrew.Bardsley@arm.com 5910475SAndrew.Bardsley@arm.com protected: 6010475SAndrew.Bardsley@arm.com int fd; 6110475SAndrew.Bardsley@arm.com uint64_t gdbregs[KGDB_NUMREGS]; 6210475SAndrew.Bardsley@arm.com 6310475SAndrew.Bardsley@arm.com protected: 6410475SAndrew.Bardsley@arm.com#ifdef notyet 6510475SAndrew.Bardsley@arm.com label_t recover; 6610475SAndrew.Bardsley@arm.com#endif 6710475SAndrew.Bardsley@arm.com bool active; 6810475SAndrew.Bardsley@arm.com bool attached; 6910475SAndrew.Bardsley@arm.com 7010475SAndrew.Bardsley@arm.com System *system; 7110475SAndrew.Bardsley@arm.com PhysicalMemory *pmem; 7210475SAndrew.Bardsley@arm.com ExecContext *context; 7310475SAndrew.Bardsley@arm.com 7410475SAndrew.Bardsley@arm.com protected: 7510475SAndrew.Bardsley@arm.com uint8_t getbyte(); 7610475SAndrew.Bardsley@arm.com void putbyte(uint8_t b); 7710475SAndrew.Bardsley@arm.com 7810475SAndrew.Bardsley@arm.com int recv(char *data, int len); 7910475SAndrew.Bardsley@arm.com void send(const char *data); 8010475SAndrew.Bardsley@arm.com 8110475SAndrew.Bardsley@arm.com protected: 8210475SAndrew.Bardsley@arm.com // Machine memory 8310475SAndrew.Bardsley@arm.com bool read(Addr addr, size_t size, char *data); 8410475SAndrew.Bardsley@arm.com bool write(Addr addr, size_t size, const char *data); 8510475SAndrew.Bardsley@arm.com 8610475SAndrew.Bardsley@arm.com template <class T> T read(Addr addr); 8710475SAndrew.Bardsley@arm.com template <class T> void write(Addr addr, T data); 8810475SAndrew.Bardsley@arm.com 8910475SAndrew.Bardsley@arm.com public: 9010475SAndrew.Bardsley@arm.com RemoteGDB(System *system, ExecContext *context); 9110475SAndrew.Bardsley@arm.com ~RemoteGDB(); 9210475SAndrew.Bardsley@arm.com 9310475SAndrew.Bardsley@arm.com void attach(int fd); 9410475SAndrew.Bardsley@arm.com void detach(); 9510475SAndrew.Bardsley@arm.com bool isattached(); 9610475SAndrew.Bardsley@arm.com 9710475SAndrew.Bardsley@arm.com bool acc(Addr addr, size_t len); 9810475SAndrew.Bardsley@arm.com static int signal(int type); 9910475SAndrew.Bardsley@arm.com bool trap(int type); 10010475SAndrew.Bardsley@arm.com 10110475SAndrew.Bardsley@arm.com protected: 10210475SAndrew.Bardsley@arm.com void getregs(); 10310475SAndrew.Bardsley@arm.com void setregs(); 10410475SAndrew.Bardsley@arm.com 10510475SAndrew.Bardsley@arm.com void clearSingleStep(); 10610475SAndrew.Bardsley@arm.com void setSingleStep(); 10710475SAndrew.Bardsley@arm.com 10810475SAndrew.Bardsley@arm.com PCEventQueue *getPcEventQueue(); 10910475SAndrew.Bardsley@arm.com 11010475SAndrew.Bardsley@arm.com protected: 11110475SAndrew.Bardsley@arm.com class HardBreakpoint : public PCEvent 11210475SAndrew.Bardsley@arm.com { 11310475SAndrew.Bardsley@arm.com private: 1144046Sbinkertn@umich.edu RemoteGDB *gdb; 1152SN/A 11610475SAndrew.Bardsley@arm.com public: 11710475SAndrew.Bardsley@arm.com HardBreakpoint(RemoteGDB *_gdb, Addr addr); 11810475SAndrew.Bardsley@arm.com 11911153SCurtis.Dunham@arm.com int refcount; 12011153SCurtis.Dunham@arm.com virtual void process(ExecContext *xc); 12111153SCurtis.Dunham@arm.com }; 1222SN/A friend class HardBreakpoint; 1237811Ssteve.reinhardt@amd.com 1244039Sbinkertn@umich.edu typedef std::map<Addr, HardBreakpoint *> break_map_t; 1251070SN/A typedef break_map_t::iterator break_iter_t; 1261070SN/A break_map_t hardBreakMap; 1271070SN/A 1281070SN/A bool insertSoftBreak(Addr addr, size_t len); 1291070SN/A bool removeSoftBreak(Addr addr, size_t len); 1301070SN/A bool insertHardBreak(Addr addr, size_t len); 1311070SN/A bool removeHardBreak(Addr addr, size_t len); 1321070SN/A 1331070SN/A protected: 13410475SAndrew.Bardsley@arm.com struct TempBreakpoint { 13510475SAndrew.Bardsley@arm.com Addr address; // set here 13610475SAndrew.Bardsley@arm.com MachInst bkpt_inst; // saved instruction at bkpt 1372SN/A int init_count; // number of times to skip bkpt 13810259SAndrew.Bardsley@arm.com int count; // current count 13910259SAndrew.Bardsley@arm.com }; 14010259SAndrew.Bardsley@arm.com 14110259SAndrew.Bardsley@arm.com TempBreakpoint notTakenBkpt; 14210259SAndrew.Bardsley@arm.com TempBreakpoint takenBkpt; 14310259SAndrew.Bardsley@arm.com 14410259SAndrew.Bardsley@arm.com void clearTempBreakpoint(TempBreakpoint &bkpt); 14510259SAndrew.Bardsley@arm.com void setTempBreakpoint(TempBreakpoint &bkpt, Addr addr); 14610259SAndrew.Bardsley@arm.com}; 14710259SAndrew.Bardsley@arm.com 14810259SAndrew.Bardsley@arm.comtemplate <class T> 14910259SAndrew.Bardsley@arm.cominline T 15010259SAndrew.Bardsley@arm.comRemoteGDB::read(Addr addr) 15110259SAndrew.Bardsley@arm.com{ 1522SN/A T temp; 1532SN/A read(addr, sizeof(T), (char *)&temp); 1542SN/A return temp; 1552SN/A} 1562SN/A 1572SN/Atemplate <class T> 1582SN/Ainline void 1592SN/ARemoteGDB::write(Addr addr, T data) 1602SN/A{ write(addr, sizeof(T), (const char *)&data); } 1612SN/A 1622SN/Aclass GDBListener 1632SN/A{ 16411153SCurtis.Dunham@arm.com protected: 1652SN/A class Event : public PollEvent 16610475SAndrew.Bardsley@arm.com { 16710475SAndrew.Bardsley@arm.com protected: 16810475SAndrew.Bardsley@arm.com GDBListener *listener; 16910475SAndrew.Bardsley@arm.com 1702SN/A public: 1712SN/A Event(GDBListener *l, int fd, int e); 17210475SAndrew.Bardsley@arm.com void process(int revent); 17310475SAndrew.Bardsley@arm.com }; 17410475SAndrew.Bardsley@arm.com 17510475SAndrew.Bardsley@arm.com friend class Event; 17610475SAndrew.Bardsley@arm.com Event *event; 17710475SAndrew.Bardsley@arm.com 1782SN/A protected: 1792SN/A ListenSocket listener; 18010475SAndrew.Bardsley@arm.com RemoteGDB *gdb; 18110475SAndrew.Bardsley@arm.com int port; 18210475SAndrew.Bardsley@arm.com 18310475SAndrew.Bardsley@arm.com public: 18410475SAndrew.Bardsley@arm.com GDBListener(RemoteGDB *g, int p); 18510475SAndrew.Bardsley@arm.com ~GDBListener(); 1865806Ssaidi@eecs.umich.edu 1875806Ssaidi@eecs.umich.edu void accept(); 18810475SAndrew.Bardsley@arm.com void listen(); 18910475SAndrew.Bardsley@arm.com}; 19010475SAndrew.Bardsley@arm.com 19110475SAndrew.Bardsley@arm.com#endif /* __REMOTE_GDB_H__ */ 19210475SAndrew.Bardsley@arm.com