Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

GDB Support for Simulators

Simulators built with ArchC can use the GDB protocol very easy, just implement few processor dependent methods for the interface and the simulator will be able to respond to GDB, allowing users to debug software inside the simulator.

Developer should implement methods to interface architecture and GDB, mapping registers and memory to desired GDB format. These methods, explained in detail below, should be implemented in a file named after your processor: <PROCESSOR_NAME>_gdb_funcs.cpp, given your processor is implemented in <PROCESSOR_NAME>.ac. Then "make distclean" your simulator, run acsim with -gdb, and make it again. Acsim with -gdb will make your simulator class inherit from AC_GDB_Interface and include your <PROCESSOR_NAME>_gdb_funcs.cpp, so using those functions.

When built, the simulator will handle the --gdb, waiting for the GDB to connect at port 5000 (port defined in compile time, changeable with -DPORT_NUM=<YOUR_PORT>, or defined in run time, using --gdb=<YOUR_PORT>).

Register Support

You must implement AC_GDB_Interface::nRegs(), AC_GDB_Interface::reg_read() and AC_GDB_Interface::reg_write(), so the simulator can send the read and write register packets to GDB. You must check GDB doc to know the order the registers should be sent and map them in reg_read() and reg_write(), then define the number of registers GDB expect to receive/send in nRegs(). The order is defined in REGISTER_RAW_SIZE and REGISTER_NAME macros. Please read "info gdb", section "Remote Protocol", nodes "Packets" and "Register Packet Format" before continue.
Example:
If you have one bank with general purpose registers (RB_GP), one with floating point registers (RB_FP) and one with status register (RB_S). If GDB expect the packets in order: 32 general purpose registers, 32 floating point registers and 8 status register and PC, your functions should be like:
      int YOUR_CLASS::nRegs( void ) {
           return 73;
      }

        ac_word YOUR_CLASS::reg_read( int reg ) {
         // General Purpose
         if ( ( reg >= 0 ) && ( reg < 32 ) )
            return RB_GP.read( reg );

         // Floating Point
           else if ( ( reg >= 32 ) && ( reg < 64 ) )
            return RB_FP.read( reg - 32 );

         // Status
         else if ( ( reg >= 64 ) && ( reg < 72 ) )
            return RB_SR.read( reg - 64 );

         // Program Counter
         else if ( reg == 72 )
            return ac_resources::ac_pc;

         return 0; // unmaped register? return 0
        }

      void YOUR_CLASS::reg_write( int reg, ac_word value ) {
         // General Purpose
         if ( ( reg >= 0 ) && ( reg < 32 ) )
            RB_GP.write( reg, value );

         // Floating Point
         else if ( ( reg >= 32 ) && ( reg < 64 ) )
            RB_FP.write( reg - 32, value );

         // Status
         else if ( ( reg >= 64 ) && ( reg < 72 ) )
            RB_SR.write( reg - 64, value );

         // Program Counter
         else if ( reg == 72 )
            ac_resources::ac_pc = value;
      }

Memory Support

You must implement AC_GDB_Interface::mem_read() and AC_GDB_Interface::mem_write() to read and write memory regions.
Example:
If you use just one memory bank (no separated data and instruction memory), it's easy as follow:
      unsigned char YOUR_CLASS::mem_read( unsigned int address ) {
         return ac_resources::IM->read_byte( address );
      }

      void YOUR_CLASS::mem_write( unsigned int address,
                                  unsigned char byte) {
         ac_resources::IM->write_byte( address, byte );
      }

See also:
AC_GDB_Interface

mips1_gdb_funcs::cpp

sparcv8_gdb_funcs::cpp

Gdb info page, section "Remote Protocol", node "Register Packet Format".

Gdb source package, file gdb/remote-mips.c, mips_map_regno(). (http://sources.redhat.com/cgi-bin/cvsweb.cgi/~checkout~/src/gdb/remote-mips.c?&cvsroot=src)

Gdb source package, file gdb/sparc-stub.c, regnames enumerate. (http://sources.redhat.com/cgi-bin/cvsweb.cgi/~checkout~/src/gdb/sparc-stub.c?&cvsroot=src)


Generated on Thu Jun 24 08:30:09 2004 for ArchC by doxygen 1.3.4