GDB server instance to give the possibility to debug target by debugger. More...
#include <gdb.h>
Public Member Functions | |
int | Step (bool &trueHwStep, SystemClockOffset *timeToNextStepIn_ns=0) |
Return nonzero if a breakpoint was hit. | |
int | InternalStep (bool &trueHwStep, SystemClockOffset *timeToNextStepIn_ns=0) |
void | TryConnectGdb () |
try to accept a new connection from gdb | |
void | SendPosition (int signal) |
int | SleepStep () |
GdbServer (AvrDevice *, int port, int debugOn, int WaitForGdbConnection=true) | |
virtual | ~GdbServer () |
void | Run () |
Start interacting with gdb. | |
Protected Member Functions | |
word | avr_core_flash_read (int addr) |
void | avr_core_flash_write (int addr, word val) |
void | avr_core_flash_write_hi8 (int addr, byte val) |
void | avr_core_flash_write_lo8 (int addr, byte val) |
void | avr_core_remove_breakpoint (dword pc) |
void | avr_core_insert_breakpoint (dword pc) |
int | signal_has_occurred (int signo) |
void | signal_watch_start (int signo) |
void | signal_watch_stop (int signo) |
int | avr_core_step () |
int | hex2nib (char hex) |
Convert a hexidecimal digit to a 4 bit nibble. | |
const char * | gdb_last_reply (const char *reply) |
void | gdb_send_ack () |
Acknowledge a packet from GDB. | |
void | gdb_send_reply (const char *reply) |
Send a reply to GDB. | |
void | gdb_send_hex_reply (const char *reply, const char *reply_to_encode) |
void | gdb_read_registers () |
void | gdb_write_registers (const char *pkt) |
int | gdb_extract_hex_num (const char **pkt, char stop) |
void | gdb_read_register (const char *pkt) |
void | gdb_write_register (const char *pkt) |
int | gdb_get_addr_len (const char *pkt, char a_end, char l_end, unsigned int *addr, int *len) |
void | gdb_read_memory (const char *pkt) |
void | gdb_write_memory (const char *pkt) |
void | gdb_break_point (const char *pkt) |
void | gdb_select_thread (const char *pkt) |
void | gdb_is_thread_alive (const char *pkt) |
void | gdb_get_thread_list (const char *pkt) |
int | gdb_get_signal (const char *pkt) |
int | gdb_parse_packet (const char *pkt) |
int | gdb_receive_and_process_packet (int blocking) |
void | gdb_main_loop () |
void | gdb_interact (int port, int debug_on) |
void | IdleStep () |
Protected Attributes | |
AvrDevice * | core |
GdbServerSocket * | server |
the server socket wrapper | |
bool | connState |
result of server->Connect() | |
time_t | oldTime |
int | global_debug_on |
debugging the debugger interface | |
int | waitForGdbConnection |
bool | exitOnKillRequest |
flag for regression test to shutdown simulator on kill request from gdb | |
int | runMode |
bool | lastCoreStepFinished |
char * | last_reply |
char | buf [MAX_BUF] |
int | m_gdb_thread_id |
For queries by GDB. First thread ID is 1. See http://sources.redhat.com/gdb/current/onlinedocs/gdb/Packets.html#thread-id. | |
Static Protected Attributes | |
static std::vector< GdbServer * > | allGdbServers |
GDB server instance to give the possibility to debug target by debugger.
Definition at line 116 of file gdb.h.
GdbServer::GdbServer | ( | AvrDevice * | c, | |
int | port, | |||
int | debugOn, | |||
int | WaitForGdbConnection = true | |||
) |
Definition at line 290 of file gdbserver.cpp.
References connState, GDB_RET_NOTHING_RECEIVED, last_reply, lastCoreStepFinished, m_gdb_thread_id, runMode, and server.
GdbServer::~GdbServer | ( | ) | [virtual] |
Definition at line 315 of file gdbserver.cpp.
References avr_free(), GdbServerSocket::Close(), last_reply, and server.
word GdbServer::avr_core_flash_read | ( | int | addr | ) | [protected] |
Definition at line 321 of file gdbserver.cpp.
References core, AvrDevice::Flash, Memory::GetSize(), and AvrFlash::ReadMemRawWord().
Referenced by gdb_read_memory().
void GdbServer::avr_core_flash_write | ( | int | addr, | |
word | val | |||
) | [protected] |
Definition at line 326 of file gdbserver.cpp.
References avr_error, core, AvrFlash::Decode(), AvrDevice::Flash, Memory::GetSize(), and AvrFlash::WriteMemByte().
Referenced by gdb_write_memory().
void GdbServer::avr_core_flash_write_hi8 | ( | int | addr, | |
byte | val | |||
) | [protected] |
Definition at line 334 of file gdbserver.cpp.
References avr_error, core, AvrFlash::Decode(), AvrDevice::Flash, Memory::GetSize(), and AvrFlash::WriteMemByte().
Referenced by gdb_write_memory().
void GdbServer::avr_core_flash_write_lo8 | ( | int | addr, | |
byte | val | |||
) | [protected] |
Definition at line 341 of file gdbserver.cpp.
References avr_error, core, AvrFlash::Decode(), AvrDevice::Flash, Memory::GetSize(), and AvrFlash::WriteMemByte().
Referenced by gdb_write_memory().
void GdbServer::avr_core_insert_breakpoint | ( | dword | pc | ) | [protected] |
Definition at line 353 of file gdbserver.cpp.
References AvrDevice::BP, and core.
Referenced by gdb_break_point().
void GdbServer::avr_core_remove_breakpoint | ( | dword | pc | ) | [protected] |
Definition at line 348 of file gdbserver.cpp.
References AvrDevice::BP, and core.
Referenced by gdb_break_point().
int GdbServer::avr_core_step | ( | ) | [protected] |
void GdbServer::gdb_break_point | ( | const char * | pkt | ) | [protected] |
Format of breakpoint commands (both insert and remove):
"z<t>,<addr>,<length>" - remove break/watch point "Z<t>,<add>r,<length>" - insert break/watch point
In both cases t can be the following: t = '0' - software breakpoint t = '1' - hardware breakpoint t = '2' - write watch point t = '3' - read watch point t = '4' - access watch point
addr is address. length is in bytes
For a software breakpoint, length specifies the size of the instruction to be patched. For hardware breakpoints and watchpoints, length specifies the memory region to be monitored. To avoid potential problems, the operations should be implemented in an idempotent way. -- GDB 5.0 manual.
Definition at line 989 of file gdbserver.cpp.
References avr_core_insert_breakpoint(), avr_core_remove_breakpoint(), avr_warning, core, AvrDevice::Flash, gdb_get_addr_len(), gdb_send_reply(), and Memory::GetSize().
Referenced by gdb_parse_packet().
int GdbServer::gdb_extract_hex_num | ( | const char ** | pkt, | |
char | stop | |||
) | [protected] |
Extract a hexadecimal number from the pkt. Keep scanning pkt until stop char is reached or size of int is exceeded or a '' is reached. pkt is modified to point to stop char when done.
Use this function to extract a num with an arbitrary num of hex digits. This should _not_ be used to extract n digits from a m len string of digits (n <= m).
Definition at line 603 of file gdbserver.cpp.
References avr_error, and hex2nib().
Referenced by gdb_read_register(), and gdb_write_register().
int GdbServer::gdb_get_addr_len | ( | const char * | pkt, | |
char | a_end, | |||
char | l_end, | |||
unsigned int * | addr, | |||
int * | len | |||
) | [protected] |
Parse the pkt string for the addr and length. a_end is first char after addr. l_end is first char after len. Returns number of characters to advance pkt.
Definition at line 736 of file gdbserver.cpp.
References hex2nib().
Referenced by gdb_break_point(), gdb_read_memory(), and gdb_write_memory().
int GdbServer::gdb_get_signal | ( | const char * | pkt | ) | [protected] |
Continue command format: "c<addr>" or "s<addr>"
If addr is given, resume at that address, otherwise, resume at current address.
Continue with signal command format: "C<sig>;<addr>" or "S<sig>;<addr>" "<sig>" should always be 2 hex digits, possibly zero padded. ";<addr>" part is optional.
If addr is given, resume at that address, otherwise, resume at current address.
Definition at line 1132 of file gdbserver.cpp.
References core, gdb_send_reply(), GDB_SIGHUP, global_debug_on, hex2nib(), and AvrDevice::Reset().
Referenced by gdb_parse_packet().
void GdbServer::gdb_get_thread_list | ( | const char * | pkt | ) | [protected] |
Definition at line 1101 of file gdbserver.cpp.
References core, gdb_send_reply(), ThreadList::GetCount(), global_debug_on, HWStack::m_ThreadList, and AvrDevice::stack.
Referenced by gdb_parse_packet().
void GdbServer::gdb_interact | ( | int | port, | |
int | debug_on | |||
) | [protected] |
void GdbServer::gdb_is_thread_alive | ( | const char * | pkt | ) | [protected] |
Definition at line 1084 of file gdbserver.cpp.
References core, gdb_send_reply(), global_debug_on, hex2nib(), ThreadList::IsGDBThreadAlive(), HWStack::m_ThreadList, and AvrDevice::stack.
Referenced by gdb_parse_packet().
const char * GdbServer::gdb_last_reply | ( | const char * | reply | ) | [protected] |
Use a single function for storing/getting the last reply message. If reply is NULL, return pointer to the last reply saved. Otherwise, make a copy of the buffer pointed to by reply.
Definition at line 384 of file gdbserver.cpp.
References avr_free(), avr_strdup(), and last_reply.
Referenced by gdb_receive_and_process_packet(), and gdb_send_reply().
void GdbServer::gdb_main_loop | ( | ) | [protected] |
int GdbServer::gdb_parse_packet | ( | const char * | pkt | ) | [protected] |
Parse the packet. Assumes that packet is null terminated. Return GDB_RET_KILL_REQUEST if packet is 'kill' command, GDB_RET_OK otherwise.
Definition at line 1165 of file gdbserver.cpp.
References core, exitOnKillRequest, AvrDevice::Flash, gdb_break_point(), gdb_get_signal(), gdb_get_thread_list(), gdb_is_thread_alive(), gdb_read_memory(), gdb_read_register(), gdb_read_registers(), GDB_RET_CONTINUE, GDB_RET_KILL_REQUEST, GDB_RET_OK, GDB_RET_SINGLE_STEP, gdb_select_thread(), gdb_send_hex_reply(), gdb_send_reply(), GDB_SIGHUP, gdb_write_memory(), gdb_write_register(), gdb_write_registers(), ThreadList::GetCurrentThreadForGDB(), global_debug_on, AvrFlash::IsProgramLoaded(), HWStack::m_ThreadList, SendPosition(), and AvrDevice::stack.
Referenced by gdb_receive_and_process_packet().
void GdbServer::gdb_read_memory | ( | const char * | pkt | ) | [protected] |
Definition at line 758 of file gdbserver.cpp.
References avr_core_flash_read(), avr_free(), avr_new0, avr_warning, core, AvrDevice::eeprom, EEPROM_OFFSET, FLASH_OFFSET, gdb_get_addr_len(), gdb_send_reply(), AvrDevice::GetRWMem(), MEM_SPACE_MASK, HWEeprom::ReadFromAddress(), and SRAM_OFFSET.
Referenced by gdb_parse_packet().
void GdbServer::gdb_read_register | ( | const char * | pkt | ) | [protected] |
Read a single register. Packet form: 'pn' where n is a hex number with no zero padding.
Definition at line 625 of file gdbserver.cpp.
References avr_warning, core, gdb_extract_hex_num(), gdb_send_reply(), AvrDevice::GetCoreReg(), HWStack::GetStackPointer(), MAX_BUF, AvrDevice::PC, AvrDevice::stack, and AvrDevice::status.
Referenced by gdb_parse_packet().
void GdbServer::gdb_read_registers | ( | ) | [protected] |
GDB needs the 32 8-bit, gpw registers (r00 - r31), the 8-bit SREG, the 16-bit SP (stack pointer) and the 32-bit PC (program counter). Thus need to send a reply with r00, r01, ..., r31, SREG, SPL, SPH, PCL, PCH Low bytes before High since AVR is little endian.
Definition at line 481 of file gdbserver.cpp.
References avr_free(), avr_new0, core, gdb_send_reply(), AvrDevice::GetCoreReg(), ThreadList::GetCurrentThreadForGDB(), HWStack::GetStackPointer(), ThreadList::GetThreadFromGDB(), m_gdb_thread_id, Thread::m_ip, Thread::m_sp, HWStack::m_ThreadList, AvrDevice::PC, Thread::registers, AvrDevice::stack, and AvrDevice::status.
Referenced by gdb_parse_packet().
int GdbServer::gdb_receive_and_process_packet | ( | int | blocking | ) | [protected] |
Perform pre-packet parsing. This will handle messages from gdb which are outside the realm of packets or prepare a packet for parsing.
Use the static block_on flag to reduce the over head of turning blocking on and off every time this function is called.
Definition at line 1297 of file gdbserver.cpp.
References avr_error, avr_warning, GDB_BLOCKING_ON, gdb_last_reply(), gdb_parse_packet(), GDB_RET_CTRL_C, GDB_RET_NOTHING_RECEIVED, GDB_RET_OK, gdb_send_ack(), gdb_send_reply(), global_debug_on, hex2nib(), GdbServerSocket::ReadByte(), server, and GdbServerSocket::SetBlockingMode().
Referenced by IdleStep(), InternalStep(), and Run().
void GdbServer::gdb_select_thread | ( | const char * | pkt | ) | [protected] |
Definition at line 1055 of file gdbserver.cpp.
References gdb_send_reply(), global_debug_on, hex2nib(), and m_gdb_thread_id.
Referenced by gdb_parse_packet().
void GdbServer::gdb_send_ack | ( | ) | [protected] |
Acknowledge a packet from GDB.
Definition at line 404 of file gdbserver.cpp.
References global_debug_on, server, and GdbServerSocket::Write().
Referenced by gdb_receive_and_process_packet(), and Run().
void GdbServer::gdb_send_hex_reply | ( | const char * | reply, | |
const char * | reply_to_encode | |||
) | [protected] |
Definition at line 464 of file gdbserver.cpp.
References gdb_send_reply().
Referenced by gdb_parse_packet().
void GdbServer::gdb_send_reply | ( | const char * | reply | ) | [protected] |
Send a reply to GDB.
Definition at line 413 of file gdbserver.cpp.
References avr_error, gdb_last_reply(), global_debug_on, server, and GdbServerSocket::Write().
Referenced by gdb_break_point(), gdb_get_signal(), gdb_get_thread_list(), gdb_is_thread_alive(), gdb_parse_packet(), gdb_read_memory(), gdb_read_register(), gdb_read_registers(), gdb_receive_and_process_packet(), gdb_select_thread(), gdb_send_hex_reply(), gdb_write_memory(), gdb_write_register(), gdb_write_registers(), InternalStep(), Run(), and SendPosition().
void GdbServer::gdb_write_memory | ( | const char * | pkt | ) | [protected] |
Definition at line 866 of file gdbserver.cpp.
References avr_core_flash_write(), avr_core_flash_write_hi8(), avr_core_flash_write_lo8(), avr_warning, core, AvrDevice::eeprom, EEPROM_OFFSET, FLASH_OFFSET, gdb_get_addr_len(), gdb_send_reply(), global_debug_on, hex2nib(), MEM_SPACE_MASK, AvrDevice::SetRWMem(), SIGNATURE_OFFSET, SRAM_OFFSET, and HWEeprom::WriteAtAddress().
Referenced by gdb_parse_packet().
void GdbServer::gdb_write_register | ( | const char * | pkt | ) | [protected] |
Write a single register. Packet form: 'Pn=r' where n is a hex number with no zero padding and r is two hex digits for each byte in register (target byte order).
Definition at line 672 of file gdbserver.cpp.
References avr_warning, core, gdb_extract_hex_num(), gdb_send_reply(), hex2nib(), AvrDevice::PC, AvrDevice::SetCoreReg(), HWStack::SetStackPointer(), AvrDevice::stack, and AvrDevice::status.
Referenced by gdb_parse_packet().
void GdbServer::gdb_write_registers | ( | const char * | pkt | ) | [protected] |
GDB is sending values to be written to the registers. Registers are the same and in the same order as described in gdb_read_registers() above.
Definition at line 546 of file gdbserver.cpp.
References core, gdb_send_reply(), hex2nib(), AvrDevice::PC, AvrDevice::SetCoreReg(), HWStack::SetStackPointer(), AvrDevice::stack, and AvrDevice::status.
Referenced by gdb_parse_packet().
int GdbServer::hex2nib | ( | char | hex | ) | [protected] |
Convert a hexidecimal digit to a 4 bit nibble.
Definition at line 364 of file gdbserver.cpp.
References avr_error.
Referenced by gdb_extract_hex_num(), gdb_get_addr_len(), gdb_get_signal(), gdb_is_thread_alive(), gdb_receive_and_process_packet(), gdb_select_thread(), gdb_write_memory(), gdb_write_register(), and gdb_write_registers().
void GdbServer::IdleStep | ( | ) | [protected] |
Definition at line 1440 of file gdbserver.cpp.
References GDB_BLOCKING_OFF, gdb_receive_and_process_packet(), GDB_RET_CONTINUE, GDB_RET_CTRL_C, GDB_RET_NOTHING_RECEIVED, GDB_RET_OK, GDB_SIGINT, lastCoreStepFinished, runMode, and SendPosition().
int GdbServer::InternalStep | ( | bool & | trueHwStep, | |
SystemClockOffset * | timeToNextStepIn_ns = 0 | |||
) |
Definition at line 1467 of file gdbserver.cpp.
References allGdbServers, BREAK_POINT, GdbServerSocket::CloseConnection(), connState, core, AvrDevice::DeleteAllBreakpoints(), GDB_BLOCKING_OFF, GDB_BLOCKING_ON, gdb_receive_and_process_packet(), GDB_RET_CONTINUE, GDB_RET_CTRL_C, GDB_RET_KILL_REQUEST, GDB_RET_NOTHING_RECEIVED, GDB_RET_OK, GDB_RET_SINGLE_STEP, gdb_send_reply(), GDB_SIGILL, GDB_SIGINT, GDB_SIGTRAP, INVALID_OPCODE, lastCoreStepFinished, MAX_BUF, AvrDevice::Reset(), runMode, SendPosition(), server, and AvrDevice::Step().
Referenced by Step().
void GdbServer::Run | ( | ) |
Start interacting with gdb.
core | A previously initialized simulator core | |
port | Port which server will listen for connections on. | |
debug_on | Turn on gdb debug diagnostic messages. |
Start a tcp server socket on localhost listening for connections on the given port. Once a connection is established, enter an infinite loop and process command requests from gdb using the remote serial protocol. Only a single connection is allowed at a time.
Definition at line 1389 of file gdbserver.cpp.
References GDB_BLOCKING_ON, gdb_receive_and_process_packet(), GDB_RET_CTRL_C, GDB_RET_KILL_REQUEST, gdb_send_ack(), gdb_send_reply(), GDB_SIGINT, and MAX_BUF.
void GdbServer::SendPosition | ( | int | signal | ) |
Definition at line 1557 of file gdbserver.cpp.
References core, gdb_send_reply(), ThreadList::GetCurrentThreadForGDB(), HWStack::GetStackPointer(), m_gdb_thread_id, HWStack::m_ThreadList, MAX_BUF, AvrDevice::PC, AvrDevice::stack, and AvrDevice::status.
Referenced by gdb_parse_packet(), IdleStep(), and InternalStep().
int GdbServer::signal_has_occurred | ( | int | signo | ) | [protected] |
Definition at line 357 of file gdbserver.cpp.
void GdbServer::signal_watch_start | ( | int | signo | ) | [protected] |
Definition at line 358 of file gdbserver.cpp.
void GdbServer::signal_watch_stop | ( | int | signo | ) | [protected] |
Definition at line 359 of file gdbserver.cpp.
int GdbServer::SleepStep | ( | ) |
Definition at line 1582 of file gdbserver.cpp.
int GdbServer::Step | ( | bool & | trueHwStep, | |
SystemClockOffset * | timeToNextStepIn_ns = 0 | |||
) | [virtual] |
Return nonzero if a breakpoint was hit.
Implements SimulationMember.
Definition at line 1426 of file gdbserver.cpp.
References connState, core, AvrDevice::GetClockFreq(), InternalStep(), AvrDevice::Step(), TryConnectGdb(), and waitForGdbConnection.
void GdbServer::TryConnectGdb | ( | ) |
try to accept a new connection from gdb
Definition at line 1415 of file gdbserver.cpp.
References allGdbServers, GdbServerSocket::Connect(), connState, oldTime, and server.
Referenced by Step().
vector< GdbServer * > GdbServer::allGdbServers [static, protected] |
Definition at line 119 of file gdb.h.
Referenced by InternalStep(), and TryConnectGdb().
char GdbServer::buf[MAX_BUF] [protected] |
bool GdbServer::connState [protected] |
result of server->Connect()
Definition at line 122 of file gdb.h.
Referenced by GdbServer(), InternalStep(), Step(), and TryConnectGdb().
AvrDevice* GdbServer::core [protected] |
Definition at line 120 of file gdb.h.
Referenced by avr_core_flash_read(), avr_core_flash_write(), avr_core_flash_write_hi8(), avr_core_flash_write_lo8(), avr_core_insert_breakpoint(), avr_core_remove_breakpoint(), gdb_break_point(), gdb_get_signal(), gdb_get_thread_list(), gdb_is_thread_alive(), gdb_parse_packet(), gdb_read_memory(), gdb_read_register(), gdb_read_registers(), gdb_write_memory(), gdb_write_register(), gdb_write_registers(), InternalStep(), SendPosition(), and Step().
bool GdbServer::exitOnKillRequest [protected] |
flag for regression test to shutdown simulator on kill request from gdb
Definition at line 130 of file gdb.h.
Referenced by gdb_parse_packet().
int GdbServer::global_debug_on [protected] |
debugging the debugger interface
Definition at line 128 of file gdb.h.
Referenced by gdb_get_signal(), gdb_get_thread_list(), gdb_is_thread_alive(), gdb_parse_packet(), gdb_receive_and_process_packet(), gdb_select_thread(), gdb_send_ack(), gdb_send_reply(), and gdb_write_memory().
char* GdbServer::last_reply [protected] |
Definition at line 136 of file gdb.h.
Referenced by gdb_last_reply(), GdbServer(), and ~GdbServer().
bool GdbServer::lastCoreStepFinished [protected] |
Definition at line 132 of file gdb.h.
Referenced by GdbServer(), IdleStep(), and InternalStep().
int GdbServer::m_gdb_thread_id [protected] |
For queries by GDB. First thread ID is 1. See http://sources.redhat.com/gdb/current/onlinedocs/gdb/Packets.html#thread-id.
Definition at line 138 of file gdb.h.
Referenced by gdb_read_registers(), gdb_select_thread(), GdbServer(), and SendPosition().
time_t GdbServer::oldTime [protected] |
remember when we have tried to open a tcp connection last time. Only one try per second
Definition at line 126 of file gdb.h.
Referenced by TryConnectGdb().
int GdbServer::runMode [protected] |
Definition at line 131 of file gdb.h.
Referenced by GdbServer(), IdleStep(), and InternalStep().
GdbServerSocket* GdbServer::server [protected] |
the server socket wrapper
Definition at line 121 of file gdb.h.
Referenced by gdb_receive_and_process_packet(), gdb_send_ack(), gdb_send_reply(), GdbServer(), InternalStep(), TryConnectGdb(), and ~GdbServer().
int GdbServer::waitForGdbConnection [protected] |