Skip to main content
Department of Information Technology

gdb Introduction Lab

Since you have the source code for the example_timer program, you can use gdb to debug your program with full C-source code support and full gdb-functionality. For more information, see the debug tips page.

You will need two shell windows to use gdb with Simics. Both started in the place where you build your code.

  • Start Simics loading the example_timer program you built in the compilation introduction lab (with a shell pointing at the example code you copied from the course directory):

host$ cd example_files
host$ export SIMICS=~/simics
host$ ./run.sh example_timer
Checking out a license... done: academic license.
Looking for additional Simics modules in /home/jakob/simics/v9-sol8-64/lib
                         
  +----------------+    Copyright 1998-2004 by Virtutech, All Rights Reserved
  |   Virtutech    |    Version: simics-2.0.16
  |     Simics     |    Compiled: Sun Jul 11 01:54:46 MEST 2004
  +----------------+
    www.simics.com      "Virtutech" and "Simics" are trademarks of Virtutech AB

Type 'copyright' for details on copyright.
Type 'license' for details on warranty, copying, etc.
Type 'readme' for further information about this version.
Type 'help help' for info on the on-line documentation.

/home/jakob/temp/example_files/example_timer
Loading binary: '/home/jakob/temp/example_files/example_timer' 
  PC set to: 8002029c 
  Loading OK.

Welcome to Simics for the computer systems course!

simics> 

  • Run Simics for a few cycles.

simics> c 10
[cpu0] v:0x800202c4 p:0x000202c4  addiu t1,t1,4
simics>

  • Follow the instructions at the debug tips page to start the gdb server in Simics (and please use some other random port than we do below to avoid collisions with your fellow students):

simics> gdb-remote port=56713
[gdb_central info] delaying central thread start
[gdb_central info] adding new connection with id 0
[gdb_central info] starting new simulation with 1 simics process
[gdb_central info] starting central thread
[gdb_remote_56713 info] Awaiting GDB connections to cpu 'cpu0' on port 56713.
simics> 

  • Move over to the other shell, and start gdb in remote mode:

host$ cd example_files
host$ /it/kurs/compsys/mips-devel/bin/mips-idt-elf-gdb example_timer
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=sparc-sun-solaris2.7 --target=mips-idt-elf"...
(gdb) 

  • Connect to the Simics gdb server using the target command. We assume that this shell is running on the same machine as the Simics session, so we do not need to give a host name, just the port to use (same as we specified when we started the gdb server in Simics above):

(gdb) target remote :56713
Remote debugging using :56713
copyloop () at asm.S:16
16              .data
Current language:  auto; currently asm
(gdb) 

  • In the Simics window, you should see a confirmation that a connection has occured:

simics>
[gdb_remote_56713 info] New GDB connection established
[gdb_remote_56713 info] Attached to cpu0
simics>

  • To start execution, give a c command at the Simics prompt, which will give gdb control over the execution. Note that if either gdb or Simics considers execution to be stopped, it is stopped. So you have to make sure that both consider the program to be running.

simics> c   
[gdb_remote_56713 info] waiting for controlling gdb
[cpu0] v:0x800202c4 p:0x000202c4  addiu t1,t1,4

  • Move over to gdb, and start debugging!

(gdb)

  • Try single-stepping, looking at stacks, variables, etc. as usual with gdb. Note that gdb is smart enough to give you source lines even in assembly files. Some examples to get you started:
    • b kload_timer to break on the function kload_timer
    • c to continue execution until a breakpoint hits
    • bt to show a stack backtrace of a function
    • s to step source-line by source-line
    • l to list the source code where we are currently executing
  • Note that you can always inspect the state of the machine from the Simics command-line when execution is stopped.

Updated  2004-10-22 14:51:03 by Dan Wallin.