GRMON is currently provided for platforms: Linux (GLIBC >2.10), Windows 7 and Windows 10. To run the
GUI Java 8 is required. Both 32-bit and 64-bit versions are supported.
The available debug communication links for each platform vary and they may have additional third-party dependencies that have additional system requirements. See Chapter 5, Debug link for more information.
1.3. Obtaining GRMON
The primary site for GRMON is Cobham Gaisler website [http://www.gaisler.com/], where the latest version of
GRMON can be ordered and evaluation versions downloaded.
1.4. Installation
Follow these steps to install GRMON. Detailed information can be found futher down.
1. Extract the archive
2. Install the Sentinel LDK Runtime (GRMON Pro version only)
3. Optionally install third-party drivers for the debug interfaces.
4. Optionally setup the path for shared libraries (Linux only)
5. Optionally add GRMON to the environment variable PATH
To install GRMON, extract the archive anywhere on the host computer. The archive contains a directory for each
OS that GRMON supports. Each OS-folder contains additional directories as described in the list below. The 32bit and 64-bit version of each OS can be installed in parallel by extracting the archive to the same location.
The professional version use a Sentinel LDK license key. See Appendix E, License key installation for installation
of the Sentinel LDK runtime.
Some debug interfaces requires installation of third-party drivers, see Chapter 5, Debug link for more information.
The bin<BITS> directory contains the executable. For convenience it is recommended to add the bin<BITS>
directory of the host OS to the environment variable PATH. See Appendix F, Appending environment variables
for instructions on how to append environment variables.
To be able to run the GUI, it is required to install the same bitness version of GRMON as the Java installation.
It is still possible to run both bit-versions of GRMON with the GUI. I.e to run GRMON 32-bit with a Java 64bit, install both bit-versions of GRMON.
GRMON3-UM
June 2019, Version 3.1.0
5www.cobham.com/gaisler
The lib<BITS> directory contains some additional libraries that GRMON requires. On the Windows platform
the lib<BITS> directory is not available. On the Linux platform, if GRMON fails to start because of some missing libraries that are located in this directory, then add this path to the environment variable LD_LIBRARY_PATH
or add it the ld.so.cache (see man pages about ldconfig for more information).
GRMON must find the share directory to work properly. GRMON will try to automatically detect the location
of the folder. A warning will be printed when starting GRMON if it fails to find the share folder. If it fails to
automatically detect the folder, then the environment variable GRMON_SHARE can be set to point the share/grmon folder. For example on Windows it could be set to c:\opt\grmon-pro\windows\share\grmon
or on Linux it could be set to /opt/grmon-pro/linux/share/grmon.
1.5. License
The GRMON license file can be found in the share folder of the installation. For example on Windows it can
be found in c:\opt\grmon-pro\windows\share\grmon or on Linux it could be found in /opt/gr-mon-pro/linux/share/grmon.
1.6. GRMON Evaluation version
The evaluation version of GRMON can be downloaded from Cobham Gaisler website [http://www.gaisler.com/].
The evaluation version may be used during a period of 21 days without purchasing a license. After this period,
any commercial use of GRMON is not permitted without a valid license. The following features are not available
in the evaluation version:
• GUI
• Support for LEON2, LEON3-FT, LEON4
• FT memory controllers
• SpaceWire drivers
• Custom JTAG configuration
• Profiling
• TCL API (drivers, init scripts, hooks, I/O forward to TCL channel etc)
1.7. Problem reports
Please send bug reports or comments to support@gaisler.com.
Customers with a valid support agreement may send questions to support@gaisler.com. Include a GRMON log
when sending questions, please. A log can be obtained by starting GRMON with the command line switch -log
filename.
The leon_sparc community at Yahoo may also be a source to find solutions to problems.
GRMON3-UM
June 2019, Version 3.1.0
6www.cobham.com/gaisler
2. Debugging concept
2.1. Overview
The GRMON debug monitor is intended to debug system-on-chip (SOC) designs based on the LEON processor.
The monitor connects to a dedicated debug interface on the target hardware, through which it can perform read
and write cycles on the on-chip bus (AHB). The debug interface can be of various types: the LEON3/4 processor
supports debugging over a serial UART, 32-bit PCI, JTAG, Ethernet and SpaceWire (using the GRESB Ethernet
to SpaceWire bridge) debug interfaces. On the target system, all debug interfaces are realized as AHB masters
with the Debug protocol implemented in hardware. There is thus no software support necessary to debug a LEON
system, and a target system does in fact not even need to have a processor present.
Figure 2.1. GRMON concept overview
GRMON can operate in two modes: command-line mode and GDB mode. In command-line mode, GRMON
commands are entered manually through a terminal window. In GDB mode, GRMON acts as a GDB gateway and
translates the GDB extended-remote protocol to debug commands on the target system.
GRMON is implemented using three functional layers: command layer, debug driver layer, and debug interface
layer. The command layer takes input from the user and parses it in a Tcl Shell. It is also possible to start a GDB
server service, which has its own shell, that takes input from GDB. Each shell has it own set of commands and
variables. Many commands depends on drivers and will fail if the core is note present in the target system. More
information about Tcl integration can be found in the Section 3.5, “Tcl integration”.
The debug driver layer implements drivers that probes and initializes the cores. GRMON will scan the target system
at start-up and detect which IP cores are present. The drivers may also provides information to the commands.
The debug interface layer implements the debug link protocol for each supported debug interface. Which interface
to use for a debug session is specified through command line options during the start of GRMON. Only interfaces
based on JTAG supports 8-/16-bit accesses, all other interfaces access subwords using read-modify-write. 32-bit
accesses are supported by all interfaces. More information can be found in Chapter 5, Debug link.
2.2. Target initialization
When GRMON first connects to the target system, it scans the system to detect which IP cores are present. This is
done by reading the plug and play information which is normally located at address 0xfffff000 on the AHB bus. A
GRMON3-UM
June 2019, Version 3.1.0
7www.cobham.com/gaisler
debug driver for each recognized IP core is then initialized, and performs a core-specific initialization sequence if
required. For a memory controller, the initialization sequence would typically consist of a memory probe operation
to detect the amount of attached RAM. For a UART, it could consist of initializing the baud rate generator and
flushing the FIFOs. After the initialization is complete, the system configuration is printed:
GRMON3 LEON debug monitor v3.0.0 32-bit professional version
Copyright (C) 2018 Cobham Gaisler - All rights reserved.
For latest updates, go to http://www.gaisler.com/
Comments or bug-reports to support@gaisler.com
Component Vendor
LEON3 SPARC V8 Processor Cobham Gaisler
AHB Debug UART Cobham Gaisler
JTAG Debug Link Cobham Gaisler
GRSPW2 SpaceWire Serial Link Cobham Gaisler
LEON2 Memory Controller European Space Agency
AHB/APB Bridge Cobham Gaisler
LEON3 Debug Support Unit Cobham Gaisler
Generic UART Cobham Gaisler
Multi-processor Interrupt Ctrl. Cobham Gaisler
Modular Timer Unit Cobham Gaisler
General Purpose I/O port Cobham Gaisler
Use command 'info sys' to print a detailed report of attached cores
grmon3>
More detailed system information can be printed using the ‘info sys’ command as listed below. The detailed system
view also provides information about address mapping, interrupt allocation and IP core configuration. Information
about which AMBA AHB and APB buses a core is connected to can be seen by adding the -v option. GRMON
assigns a unique name to all cores, the core name is printed to the left. See Appendix C, Tcl API for information
about Tcl variables and device names.
grgpio0 Cobham Gaisler General Purpose I/O port
APB: 80000800 - 80000900
2.2.1. LEON2 target initialization
The plug and play information was introduced in the LEON3 processor (GRLIB), and is not available for LEON2
systems. LEON2 is supported by starting GRMON with the -sys leon2 switch or one of the switches that
correspond to a known LEON2 device, see Section 6.12, “LEON2 support”.
A LEON2 system has a fixed set of IP cores and address mapping. GRMON will use an internal plug and play table
that describes this configuration. The plug and play table used for LEON2 is fixed, and no automatic detection of
present cores is attempted. Only those cores that need to be initialized by GRMON are included in the table, so
the listing might not correspond to the actual target. It is however possible to load a custom configuration file that
describes the target system configuration using see Section 2.2.2, “Configuration file target initialization”
2.2.2. Configuration file target initialization
It is possible to provide GRMON with a configuration file that describes a static configuration by starting GRMON
with the switch -cfgfilename.
The format of the plug and play configuration file is described in section Appendix D, Fixed target configurationfile format. It can be used for both LEON3 and LEON2 systems. An example configuration file is also supplied
with the GRMON professional distribution in share/src/cfg/leon3.xml.
2.3. Memory register reset values
To ensure that the memory registers has sane values, GRMON will reset the registers when commands that access
the memories are issued, for example run, load commands and similar commands. To modify the reset values,
use the commands listed in Section 6.14.2, “Commands”.
GRMON3-UM
June 2019, Version 3.1.0
9www.cobham.com/gaisler
3. Operation
This chapter describes how GRMON can be controlled by the user in a terminal based interactive debug session
and how it can be automated with scripts for batch execution. The first sections describe and exemplifies typical
operations for interactive use. The later sections describe automation concepts. Most interactive commands are
applicable also for automated use.
GRMON graphical user interface is described in Chapter 4, Graphical user interface.
3.1. Overview
An interactive GRMON debug session typically consists of the following steps:
1. Starting GRMON and attaching to the target system
2. Examining the hardware configuration
3. Uploading application program
4. Setup debugging, for example insert breakpoints and watchpoints
5. Executing the application
6. Debugging the application and examining the CPU and hardware state
Step 2 though 6 is performed using the GRMON terminal interface or by attaching GDB and use the standard
GDB interface. The GDB section describes how GRMON specific commands are accessed from GDB.
The following sections will give an overview how the various steps are performed.
3.2. Starting GRMON
On a Linux host, GRMON is started by giving the grmon command together with command line options in a
terminal window. It can run either the GUI or a commandline interface depending on if a debug link option is
provided or not.
On Windows hosts, there are two executable provided. The file grmon.exe is intended to be started in a Windows
command prompt (cmd.exe). It can run either the GUI or a commandline interface depending on if a debug link
option is provided or not. The executable grmon-gui.exe will always spawn a gui.
Command line options are grouped by function as indicated below.
• The debug link options: setting up a connection to GRLIB target
• General options: debug session behavior options
• Debug driver options: configure the hardware, skip core auto-probing etc.
NOTE: If any debug-link option is given to grmon or grmon.exe, then the GRMON command line interface
will be started.
If no debug-link option is given to grmon or grmon.exe, then the GRMON graphical user interface will be started.
For more information, see Chapter 4, Graphical user interface.
Below is an example of GRMON connecting to a GR712 evaluation board using the FTDI USB serial interface,
tunneling the UART output of APBUART0 to GRMON and specifying three RAM wait states on read and write:
$ grmon -ftdi -u -ramws 3
To connect to a target using the AHBUART debug link, the following example can be used:
$ grmon -uart -u
The -uart option uses the first UART of the host (ttyS0 or COM1) with a baud rate of 115200 baud by default.
3.2.1. Debug link options
GRMON connects to a GRLIB target using one debug link interface, the command line options selects which
interface the PC uses to connect to the target and optionally how the debug link is configured. All options are
described in Chapter 5, Debug link.
GRMON3-UM
June 2019, Version 3.1.0
10www.cobham.com/gaisler
3.2.2. Debug driver options
The debug drivers provide an interface to view and access AMBA devices during debugging and they offer device
specific ways to configure the hardware when connecting and before running the executable. Drivers usually auto-probe their devices for optimal configuration values, however sometimes it is useful to override the auto-probed
values. Some options affects multiple drivers. The debug driver options are described in Chapter 6, Debug drivers.
3.2.3. General options
The general options are mostly target independent options configuring the behavior of GRMON. Some of them
affects how the target system is accessed both during connection and during the whole debugging session. All
general options are described below.
grmon [options]
Options:
-abaudbaudrate
Set baud-rate for all UARTs in the system, (except the debug-link UART). By default, 38400 baud is used.
-ambamb[maxbuses]
Enable auto-detection of AHBCTRL_MB system and (optionally) specifies the maximum number of buses
in the system if an argument is given. The optional argument to -ambamb is decoded as below:
0, 1: No Multi-bus (MB) (max one bus)
2..3: Limit MB support to 2 or 3 AMBA PnP buses
4 or no argument: Selects Full MB support
-cfilename
Run the commands in the batch file at start-up.
-cfgfilename
Load fixed PnP configuration from a xml-file.
-echo
Echo all the commands in the batch file at start-up. Has no effect unless -c is also set.
-edac
Enable EDAC operation in memory controllers that support it.
-freqsysclk
Overrides the detected system frequency. The frequency is specified in MHz.
-gdb[port]
Listen for GDB connection directly at start-up. Optionally specify the port number for GDB communications. Default port number is 2222.
-gui
Start the GRMON graphical user interface. This option must be combined with an option which specifies
the debug-link to use. See Chapter 4, Graphical user interface for more information.
-ioareaaddress
Specify the location of the I/O area. (Default is 0xfff00000).
-logfilename
Log session to the specified file. If the file already exists the new session is appended. This should be used
when requesting support.
-ni
Read plug n' play and detect all system device, but don't do any target initialization. See Section 3.4.11,
“Attaching to a target system without initialization” for more information.
-nopnp
Disable the plug n' play scanning. GRMON won't detect any hardware and any hardware dependent functionality won't work.
-u[device]
Put UART 1 in FIFO debug mode if hardware supports it, else put it in loop-back mode. Debug mode will
enable both reading and writing to the UART from the monitor console. Loop-back mode will only enable
reading. See Section 3.9, “Forwarding application console I/O”. The optional device parameter is used to
select a specific UART to be put in debug mode. The device parameter is an index starting with 0 for the
first UART and then increasing with one in the order they are found in the bus scan. If the device parameter
is not used the first UART is selected.
GRMON3-UM
June 2019, Version 3.1.0
11www.cobham.com/gaisler
-udm[device]
Put UART 1 in FIFO debug mode if hardware supports it. Debug mode will enable both reading and writing
to the UART from the monitor console. See Section 3.9, “Forwarding application console I/O”. The optional
device parameter is used to select a specific UART to be put in debug mode. The device parameter is an
index starting with 0 for the first UART and then increasing with one in the order they are found in the bus
scan. If the device parameter is not used the first UART is selected.
-ulb[device]
Put UART 1 in loop-back mode. Loop-back mode will only enable reading from the UART to the monitor
console. See Section 3.9, “Forwarding application console I/O”. The optional device parameter is used to
select a specific UART to be put in debug mode. The device parameter is an index starting with 0 for the
first UART and then increasing with one in the order they are found in the bus scan. If the device parameter
is not used the first UART is selected.
-ucmdfilename
Load script specified by filename into all shells, including the system shell.
-udrvfilename
Load script specified by filename into system shell.
3.3. GRMON command-line interface (CLI)
The GRMON3 command-line interface features a Tcl 8.6 interpreter which will interpret all entered commands
substituting variables etc. before GRMON is actually called. Variables exported by GRMON can also be used
to access internal states and hardware registers without going through commands. The GRMON Tcl interface is
described in Section 3.5, “Tcl integration”.
GRMON dynamically loads libreadline.so if available on your host system, and uses the readline library to
enter and edit commands. Short forms of the commands are allowed, e.g lo, loa, or load, are all interpreted as load.
Tab completion is available for commands, Tcl variables, text-symbols, file names, etc. If libreadline.so
is not found, the standard input/output routines are used instead (no history, poor editing capabilities and no tabcompletion).
The commands can be separated in to three categories:
• Tcl internal commands and reserved key words
• GRMON built-in commands always available regardless of target
• GRMON commands accessing debug drivers
Tcl internal and GRMON built-in commands are available regardless of target hardware present whereas debug
driver commands may only be present on supported systems. The Tcl and driver commands are described in
Section 3.5, “Tcl integration” and Chapter 6, Debug drivers respectively. In Table 3.1 is a summary of all GRMON
built-in commands. For the full list of commands, see Appendix A, Command index.
Table 3.1. BUILT-IN commands
amemAsynchronous bus read
batchExecute batch script
bdumpDump memory to a file
bloadLoad a binary file
disassembleDisassemble memory
dumpDump memory to a file
dwarfprint or lookup dwarf information
eeloadLoad a file into an EEPROM
execshRun commands in the execution shell
exitExit GRMON
gdbControll the builtin GDB remote server
guiControl the graphical user interface
helpPrint all commands or detailed help for a specific command
GRMON3-UM
June 2019, Version 3.1.0
12www.cobham.com/gaisler
infoShow information
loadLoad a file or print filenames of uploaded files
membAMBA bus 8-bit memory read access, list a range of addresses
memhAMBA bus 16-bit memory read access, list a range of addresses
memAMBA bus 32-bit memory read access, list a range of addresses
nologSuppress stdout of a command
quitQuit the GRMON console
resetReset drivers
rtg4fddrPrint initialization sequence
rtg4serdesPrint initialization sequence
sf2mddrPrint initialization sequence
sf2serdesPrint initialization sequence
shellExecute shell process
silentSuppress stdout of a command
symbolsLoad, print or lookup symbols
usrshRun commands in threaded user shell
verifyVerify that a file has been uploaded correctly
washClear or set memory areas
wmembAMBA bus 8-bit memory write access
wmemhAMBA bus 16-bit memory write access
wmemsWrite a string to an AMBA bus memory address
wmemAMBA bus 32-bit memory write access
3.4. Common debug operations
This section describes and gives some examples of how GRMON is typically used, the full command reference
can be found in Appendix A, Command index.
3.4.1. Examining the hardware configuration
When connecting for the first time it is essential to verify that GRMON has auto-detected all devices and their
configuration correctly. At start-up GRMON will print the cores and the frequency detected. From the command
line one can examine the system by executing info sys as below:
grmon3> info sys
cpu0 Cobham Gaisler LEON3-FT SPARC V8 Processor
AHB Master 0
cpu1 Cobham Gaisler LEON3-FT SPARC V8 Processor
AHB Master 1
greth0 Cobham Gaisler GR Ethernet MAC
AHB Master 3
APB: 80000E00 - 80000F00
IRQ: 14
grspw0 Cobham Gaisler GRSPW2 SpaceWire Serial Link
AHB Master 5
APB: 80100800 - 80100900
IRQ: 22
Number of ports: 1
grspw1 Cobham Gaisler GRSPW2 SpaceWire Serial Link
AHB Master 6
APB: 80100900 - 80100A00
IRQ: 23
Number of ports: 1
mctrl0 Cobham Gaisler Memory controller with EDAC
AHB: 00000000 - 20000000
AHB: 20000000 - 40000000
AHB: 40000000 - 80000000
APB: 80000000 - 80000100
8-bit prom @ 0x00000000
32-bit static ram: 1 * 8192 kbyte @ 0x40000000
The memory section for example tells us that GRMON are using the correct amount of memory and memory
type. The parameters can be tweaked by passing memory driver specific options on start-up, see Section 3.2,
“Starting GRMON”. The current memory settings can be viewed in detail by listing the registers with info reg or
by accessing the registers by the Tcl variables exported by GRMON:
The supported file formats are SPARC ELF-32, ELF-64 (MSB truncated to 32-bit addresses), srecord and a.out
binaries. Each section is loaded to its link address. The program entry point of the file is used to set the %PC,
%NPC when the application is later started with run. It is also possible to load binary data by specifying file and
target address using the bload command.
One can use the verify command to make sure that the file has been loaded correctly to memory as below. Any
discrepancies will be reported in the GRMON console.
grmon3> verify v8/stanford.exe
40000000 .text 54.8kB / 54.8kB [===============>] 100%
4000DB30 .data 2.9kB / 2.9kB [===============>] 100%
Total size: 57.66kB (726.74kbit/s)
Entry point 0x40000000
Image of /home/daniel/examples/v8/stanford.exe verified without errors
NOTE: On-going DMA can be turned off to avoid that hardware overwrites the loaded image by issuing the reset
command prior to load. This is important after the CPU has been executing using DMA in for example Ethernet
network traffic.
3.4.3. Running applications
After the application has been uploaded to the target with load the run command can be used to start execution.
The entry-point taken from the ELF-file during loading will serve as the starting address, the first instruction
executed. The run command issues a driver reset, however it may be necessary to perform a reset prior to loading
the image to avoid that DMA overwrites the image. See the reset command for details. Applications already
located in FLASH can be started by specifying an absolute address. The cont command resumes execution after
a temporary stop, e.g. a breakpoint hit. go also affects the CPU execution, the difference compared to run is that
the target device hardware is not initialized before starting execution.
grmon3> run
Starting
Perm Towers Queens Intmm Mm Puzzle Quick Bubble Tree FFT
34 67 33 117 1117 367 50 50 250 1133
Nonfloating point composite is 144
Floating point composite is 973
CPU 0: Program exited normally.
CPU 1: Power down mode
The output from the application normally appears on the LEON UARTs and thus not in the GRMON console.
However, if GRMON is started with the -u switch, the UART is put into debug mode and the output is tunneled
over the debug-link and finally printed on the console by GRMON. See Section 3.9, “Forwarding application
console I/O”. Note that older hardware (GRLIB 1.0.17-b2710 and older) has only partial support for -u, it will not
work when the APBUART software driver uses interrupt driven I/O, thus Linux and vxWorks are not supported
on older hardware. Instead, a terminal emulator should be connected to UART 1 of the target system.
Since the application changes (at least) the .data segment during run-time the application must be reloaded before
it can be executed again. If the application uses the MMU (e.g. Linux) or installs data exception handlers (e.g.
eCos), GRMON should be started with -nb to avoid going into break mode on a page-fault or data exception.
Likewise, when a software debugger is running on the target (e.g. GDB natively in Linux user-space or WindRiver
Workbench debugging a task) soft breakpoints ("TA 0x01" instruction) will result in traps that the OS will handle
GRMON3-UM
15www.cobham.com/gaisler
June 2019, Version 3.1.0
and tell the native debugger. To prevent GRMON from interpreting it as its own breakpoints and stop the CPU
one must use the -nswb switch.
3.4.4. Inserting breakpoints and watchpoints
All breakpoints are inserted with the bp command. The subcommand (soft, hard, watch, bus, data, delete) given to
bp determine which type of breakpoint is inserted, if no subcommand is given bp defaults to a software breakpoint.
Instruction breakpoints are inserted using bp soft or bp hard commands. Inserting a software breakpoint will add
a (TA 0x1) instruction by modifying the target's memory before starting the CPU, while bp hard will insert a
hardware breakpoint using one of the IU watchpoint registers. To debug instruction code in read-only memories
or memories which are self-modifying the only option is hardware breakpoints. Note that it's possible to debug
any RAM-based code using software breakpoints, even where traps are disabled such as in trap handlers. Since
hardware breakpoints triggers on the CPU instruction address one must be aware that when the MMU is turned
on, virtual addresses are triggered upon.
CPU data address watchpoints (read-only, write-only or read-write) are inserted using the bp watch command.
Watchpoints can be setup to trigger within a range determined by a bit-mask where a one means that the address
must match the address pattern and a zero mask indicate don't care. The lowest 2-bits are not available, meaning
that 32-bit words are the smallest address that can be watched. Byte accesses can still be watched but accesses to
the neighboring three bytes will also be watched.
AMBA-bus watchpoints can be inserted using bp bus or bp data. When a bus watchpoint is hit the trace buffer
will freeze. The processor can optionally be put in debug mode when the bus watchpoint is hit. This is controlled
by the tmode command:
grmon3> tmode break N
If N = 0, the processor will not be halted when the watchpoint is hit. A value > 0 will break the processor and set
the AHB trace buffer delay counter to the same value.
NOTE: For hardware supported break/watchpoints the target must have been configured accordingly, otherwise
a failure will be reported. Note also that the number of watchpoints implemented varies between designs.
3.4.5. Displaying processor registers
The current register window of a LEON processor can be displayed using the reg command or by accessing the Tcl
cpu namespace that GRMON provides. GRMON exports cpu and cpuN where N selects which CPU's registers
are accessed, the cpu namespace points to the active CPU selected by the cpu command.
Other register windows can be displayed using reg wN, when N denotes the window number. Use the float command to show the FPU registers (if present).
3.4.6. Backtracing function calls
When debugging an application it is often most useful to view how the CPU entered the current function. The bt
command analyze the previous stack frames to determine the backtrace. GRMON reads the register windows and
then switches to read from the stack depending on the %WIM and %PSR register.
GRMON3-UM
June 2019, Version 3.1.0
16www.cobham.com/gaisler
The backtrace is presented with the caller's program counter (%PC) to return to (below where the CALL instruction
was issued) and the stack pointer (%SP) at that time. The first entry (frame #0) indicates the current location of
the CPU and the current stack pointer. The right most column print out the %PC address relative the function
symbol, i.e. if symbols are present.
NOTE: In order to display a correct backtrace for optimized code where optimized leaf functions are present a
symbol table must exist.
In a MP system the backtrace of a specific CPU can be printed, either by changing the active CPU with the cpu
command or by passing the CPU index to bt.
3.4.7. Displaying memory contents
Any memory location can be displayed and written using the commands listed in the table below. Memory commands that are prefixed with a v access the virtual address space seen by doing MMU address lookups for active
CPU.
Table 3.2. Memory access commands
Command
Description
Name
memAMBA bus 32-bit memory read access, list a range of addresses
wmemAMBA bus 32-bit memory write access
vmemAMBA bus 32-bit virtual memory read access, list a range of addresses
membAMBA bus 8-bit memory read access, list a range of addresses
memhAMBA bus 16-bit memory read access, list a range of addresses
vmembAMBA bus 8-bit virtual memory read access, list a range of addresses
vmemhAMBA bus 16-bit virtual memory read access, list a range of addresses
vwmembAMBA bus 8-bit virtual memory write access
vwmemhAMBA bus 16-bit virtual memory write access
vwmemsWrite a string to an AMBA bus virtual memory address
vwmemAMBA bus 32-bit virtual memory write access
wmembAMBA bus 8-bit memory write access
wmemhAMBA bus 16-bit memory write access
wmemsWrite a string to an AMBA bus memory address
amemAMBA bus 32-bit asynchronous memory read access
NOTE: Most debug links only support 32-bit accesses, only JTAG links support unaligned access. An unaligned
access is when the address or number of bytes are not evenly divided by four. When an unaligned data read request
is issued, then GRMON will read some extra bytes to align the data, but only return the requested data. If a write
request is issued, then an aligned read-modify-write sequence will occur.
The mem command requires an address and an optional length, if the length is left out 64 bytes are displayed. If a
program has been loaded, text symbols can be used instead of a numeric address. The memory content is displayed
in hexadecimal-decimal format, grouped in 32-bit words. The ASCII equivalent is printed at the end of the line.
The memory access commands listed in Table 3.2 are not restricted to memory: they can be used on any bus
address accessible by the debug link. However, for access to peripheral control registers, the command info reg
can provide a more user-friendly output.
All commands in Table 3.2, , except for amem, return to the caller when the bus access has completed, which
means that a sequence of these commands generates a sequence of bus accesses with the same ordering. In situations where the bus accesses order is not critical, the command amem can be used to schedule multiple concurrent
read accesses whose results can be retrieved at a later time. This is useful when GRMON is automated using Tcl
scripts.
3.4.8. Instruction disassembly
If the memory contents is SPARC machine code, the contents can be displayed in assembly code using the disassemble command:
The LEON processor and associated debug support unit (DSU) can be configured with trace buffers to store both
the latest executed instructions and the latest AHB bus transfers. The trace buffers are automatically enabled by
GRMON during start-up , but can also be individually enabled and disabled using tmode command. The command
ahb is used to show the AMBA buffer. The command inst is used to show the instruction buffer. The command
hist is used to display the contents of the instruction and the AMBA buffers mixed together. Below is an example
debug session that shows the usage of breakpoints, watchpoints and the trace buffer:
grmon3> lo v8/stanford.exe
40000000 .text 54.8kB / 54.8kB [===============>] 100%
4000DB30 .data 2.9kB / 2.9kB [===============>] 100%
Total size: 57.66kB (786.00kbit/s)
Entry point 0x40000000
Image /home/daniel/examples/v8/stanford.exe loaded
GRMON3-UM
June 2019, Version 3.1.0
18www.cobham.com/gaisler
grmon3> bp Fft
Software breakpoint 1 at <Fft>
grmon3> bp watch 0x4000eae0
Hardware watchpoint 2 at 0x4000eae0
grmon3> bp
NUM ADRESS MASK TYPE SYMBOL
1 : 0x40003e20 (soft) Fft+0
2 : 0x4000eae0 0xfffffffc (watch rw) floated+0
grmon3> run
CPU 0: watchpoint 2 hit
0x40001024: c0388003 std %g0, [%g2 + %g3] <_start+36>
CPU 1: Power down mode
grmon3> cont
Towers Queens Intmm Mm Puzzle Quick Bubble Tree FFT
CPU 0: breakpoint 1 hit
0x40003e24: a0100018 mov %i0, %l0 <Fft+4>
CPU 1: Power down mode
When printing executed instructions, the value within brackets denotes the instruction result, or in the case of
store instructions the store address and store data. The value in the first column displays the relative time, equal
GRMON3-UM
19www.cobham.com/gaisler
June 2019, Version 3.1.0
to the DSU timer. The time is taken when the instruction completes in the last pipeline stage (write-back) of the
processor. In a mixed instruction/AHB display, AHB address and read or write value appears within brackets. The
time indicates when the transfer completed, i.e. when HREADY was asserted.
NOTE: As the AHB trace is disabled when a breakpoint is hit, AHB accesses related to instruction cache fetches
after the time of break can be missed. The command ahb force can be used enable AHB tracing even when the
processor is in debug mode.
NOTE: When switching between tracing modes with tmode the contents of the trace buffer will not be valid until
execution has been resumed and the buffer refilled.
3.4.10. Profiling
GRMON supports profiling of LEON applications when run on real hardware. The profiling function collects
(statistical) information on the amount of execution time spent in each function. Due to its non-intrusive nature,
the profiling data does not take into consideration if the current function is called from within another procedure.
Even so, it still provides useful information and can be used for application tuning.
NOTE: To increase the number of samples, use the fastest debug link available on the target system. I.a. do not
use I/O forwarding (start GRMON without the -u commandline option)
grmon3> lo v8/stanford.exe
40000000 .text 54.8kB / 54.8kB [===============>] 100%
4000DB30 .data 2.9kB / 2.9kB [===============>] 100%
Total size: 57.66kB (786.00kbit/s)
Entry point 0x40000000
Image /home/daniel/examples/v8/stanford.exe loaded
grmon3> profile on
grmon3> run
Starting
Perm Towers Queens Intmm Mm Puzzle Quick Bubble Tree FFT
CPU 0: Interrupted!
0x40003ee4: 95a0c8a4 fsubs %f3, %f4, %f10 <Fft+196>
CPU 1: Interrupted!
0x40000000: 88100000 clr %g4 <start+0>
3.4.11. Attaching to a target system without initialization
When GRMON connects to a target system, it probes the configuration and initializes memory and registers. To
determine why a target has crashed, or resume debugging without reloading the application, it might be desirable
to connect to the target without performing a (destructive) initialization. This can be done by specifying the ni switch during the start-up of GRMON. The system information print-out (info sys) will then however not be
able to display the correct memory settings. The use of the -stack option and the go command might also be
GRMON3-UM
June 2019, Version 3.1.0
20www.cobham.com/gaisler
necessary in case the application is later restarted. The run command may not have the intended effect since the
debug drivers have not been initialized during start-up.
3.4.12. Multi-processor support
In systems with more than one LEON processor, the cpu command can be used to control the state and debugging
focus of the processors. In MP systems, the processors are enumerated with 0..N-1, where N is the number of
processors. Each processor can be in two states; enabled or disabled. When enabled, a processor can be started by
LEON software or by GRMON. When disabled, the processor will remain halted regardless. One can pause a MP
operating system and disable a CPU to debug a hanged CPU for example.
Most per-CPU (DSU) debugging commands such as displaying registers, backtrace or adding breakpoints will be
directed to the active processor only. Switching active processor can be done using the 'cpu active N' command,
see example below. The Tcl cpu namespace exported by GRMON is also changed to point to the active CPU's
namespace, thus accessing cpu will be the same as accessing cpu1 if CPU1 is the currently active CPU.
grmon3> cpu
cpu 0: enabled active
cpu 1: enabled
grmon3> cpu act 1
grmon3> cpu
cpu 0: enabled
cpu 1: enabled active
grmon3> cpu act 0
grmon3> cpu dis 1
grmon3> cpu
cpu 0: enabled active
cpu 1: disabled
grmon3> puts $cpu::fpu::f1
-1.984328031539917
grmon3> puts $cpu0::fpu::f1
-1.984328031539917
grmon3> puts $cpu1::fpu::f1
2.3017966689845248e+18
NOTE: Non-MP software can still run on the first CPU unaffected of the additional CPUs since it is the target
software that is responsible for waking other CPUs. All processors are enabled by default.
Note that it is possible to debug MP systems using GDB, but the user are required to change CPU itself. GRMON
specific commands can be entered from GDB using the monitor command.
3.4.13. Stack and entry point
The stack pointer is located in %O6 (%SP) register of SPARC CPUs. GRMON sets the stack pointer before starting
the CPU with the run command. The address is auto-detected to end of main memory, however it is overridable
using the -stack when starting GRMON or by issuing the stack command. Thus stack pointer can be used by
software to detect end of main memory.
The entry point (EP) determines at which address the CPU start its first instruction execution. The EP defaults to
main memory start and normally overridden by the load command when loading the application. ELF-files has
support for storing entry point. The entry point can manually be set with the ep command.
In a MP systems if may be required to set EP and stack pointer individual per CPU, one can use the cpu command
in conjunction with ep and stack.
3.4.14. Memory Management Unit (MMU) support
The LEON optionally implements the reference MMU (SRMMU) described in the SPARCv8 specification. GRMON support viewing and changing the MMU registers through the DSU, using the mmu command. GRMON
also supports address translation by reading the MMU table from memory similar to the MMU. The walk com-
GRMON3-UM
June 2019, Version 3.1.0
21www.cobham.com/gaisler
mand looks up one address by walking the MMU table printing out every step taken and the result. To simply
print out the result of such a translation, use the va command.
The memory commands that are prefixed with a v work with virtual addresses, the addresses given are translated
before listing or writing physical memory. If the MMU is not enabled, the vmem command for example is an alias
for mem. See Section 3.4.7, “Displaying memory contents” for more information.
NOTE: Many commands are affected by that the MMU is turned on, such as the disassemble command.
3.4.15. CPU cache support
The LEON optionally implements Level-1 instruction-cache and data-cache. GRMON supports the CPU's cache
by adopting certain operations depending on if the cache is activated or not. The user may also be able to access
the cache directly. This is however not normally needed, but may be useful when debugging or analyzing different
cache aspects. By default the L1-cache is turned on by GRMON , the cctrl command can be used to change the
cache control register. The commandline switches -nic and -ndc disables instruction and data cache respectively.
With the icache and dcache commands it is possible to view and modify the current content of the cache or check
if the cache is consistent with the memory. Both caches can be flushed instantly using the commands cctrl flush.
The data cache can be flushed instantly using the commands dcache flush. The instruction cache can be flushed
instantly using the commands icache flush.
The GRLIB Level-2 cache is supported using the l2cache command.
3.5. Tcl integration
GRMON has built-in support for Tcl 8.6. All commands lines entered in the terminal will pass through a Tclinterpreter. This enables loops, variables, procedures, scripts, arithmetics and more for the user. I.a. it also provides
an API for the user to extend GRMON.
3.5.1. Shells
GRMON creates several independent TCL shells, each with its own set of commands and variables. I.e. changing
active CPU in one shell does not affect any other shell. In the commandline version there one shell available for
the user by default, the CLI shell, which is accessed from the terminal. In the GUI is possible to create and view
multiple shells.
Additional custom user shells for the commandline interface can be created with the command usrsh. Each custom
user shell has an associated Tcl interpreter running in a separate execution thread.
When the GDB service is running, a GDB shell is also available from GDB by using the command mon.
There is also a system shell and an execution shell running in the background that GRMON uses internally. Some
hooks must be loaded into these shells to work, see Appendix C, Tcl API for more information.
3.5.2. Commands
There are two groups of commands, the native Tcl commands and GRMON's commands. Information about the
native Tcl commands and their syntax can be found at the Tcl website [http://www.tcl.tk/]. The GRMON commands' syntax documentation can be found in Appendix B, Command syntax.
The commands have three types of output:
1. Standard output. GRMON's commands prints information to standard output. This information is often
structured in a human readable way and cannot be used by other commands. Most of the GRMON commands
print some kind of information to the standard output, while very few of the Tcl commands does that.
Setting the variable ::grmon::settings:suppress_output to 1 will stop GRMON commands
from printing to the standard output, i.e. the TCL command puts will still print it's output. It is also possible to
put the command silent in front of another GRMON command to suppress the output of a single command,
e.g. grmon3> puts [expr [silent mem 0x40000000 4] + 4]
GRMON3-UM
June 2019, Version 3.1.0
22www.cobham.com/gaisler
2. Return values. The return value from GRMON is seldom the same as the information that is printed to
standard output, it's often the important data in a raw format. Return values can be used as input to other
commands or to be saved in variables. All TCL commands and many GRMON commands have return
values. The return values from commands are normally not printed. To print the return value to standard
output one can use the Tcl command puts. I.a. if the variable ::grmon::settings:echo_result
to 1, then GRMON will always print the result to stdout.
3. Return code. The return code from a command can be accessed by reading the variable errorCode or
by using the Tcl command catch. Both Tcl and GRMON commands will have an error message as return
value if it fails, which is also printed to standard output. More about error codes can be read about in the
Tcl tutorial or on the Tcler's Wiki [http://wiki.tcl.tk/].
For some of the GRMON commands it is possible to specify which core the commands is operation on. This is
implemented differently depending for each command, see the commands' syntax documentation in Appendix B,
Command syntax for more details. Some of these commands use a device name to specify which core to interact
with, see Appendix C, Tcl API for more information about device names.
3.5.3. API
It is possible to extend GRMON using Tcl. GRMON provides an API that makes it possible do write own device
drivers, implement hooks and to write advanced commands. See Appendix C, Tcl API for a detailed description
of the API.
3.6. Symbolic debug information
GRMON will automatically extract the symbol information from ELF-files, debug information is never read from
ELF-files. The symbols can be used to GRMON commands where an address is expected as below. Symbols are
tab completed.
The symbols command can be used to display all symbols, lookup the address of a symbol, or to read in symbols
from an alternate (ELF) file:
grmon3> symbols load v8/stanford.exe
grmon3> symbols lookup main
Found address 0x40004070
grmon3> symbols list
0x40005ab8 GLOBAL FUNC putchar
0x4000b6ac GLOBAL FUNC _mprec_log10
0x4000d9d0 GLOBAL OBJECT __mprec_tinytens
0x4000bbe8 GLOBAL FUNC cleanup_glue
0x4000abfc GLOBAL FUNC _hi0bits
0x40005ad4 GLOBAL FUNC _puts_r
0x4000c310 GLOBAL FUNC _lseek_r
0x4000eaac GLOBAL OBJECT piecemax
0x40001aac GLOBAL FUNC Try
0x40003c6c GLOBAL FUNC Uniform11
0x400059e8 GLOBAL FUNC printf
...
Reading symbols from alternate files is necessary when debugging self-extracting applications (MKPROM), when
switching between virtual and physical address space (Linux) or when debugging a multi-core ASMP system
where each CPU has its own symbol table. It is recommended to clear old symbols with symbols clear before
switching symbol table, otherwise the new symbols will be added to the old table.
GRMON3-UM
23www.cobham.com/gaisler
June 2019, Version 3.1.0
3.6.1. Multi-processor symbolic debug information
When loading symbols into GRMON it is possible to associate them with a CPU. When all symbols/images are
associated with CPU index 0, then GRMON will assume its a single-core or SMP application and lookup all
symbols from the symbols table associated with CPU index 0.
If different CPU indexes are specified (by setting active CPU or adding cpu# argument to the commands) when
loading symbols/images, then GRMON will assume its an AMP application that has been loaded. GRMON will
use the current active CPU (or cpu# argument) to determine which CPU index to lookup symbols from.
grmon3> bp _Thread_Handler cpu0
Software breakpoint 2 at <_Thread_Handler>
grmon3> bp
NUM ADRESS MASK TYPE CPU SYMBOL
1 : 0x40418408 (soft) 1 _Thread_Handler+0
2 : 0x40019408 (soft) 0 _Thread_Handler+0
3.7. GDB interface
This section describes the GDB interface support available in GRMON. GRMON supports GDB version 6.3, 6.4,
6.8 and 8.2. Other tools that communicate over the GDB protocol may also attach to GRMON, some tools such
as Eclipse Workbench and DDD communicate with GRMON via GDB.
GDB must be built for the SPARC architecture, a native PC GDB does not work together with GRMON. The
toolchains that Cobham Gaisler distributes comes with a patched and tested version of GDB targeting all SPARC
LEON development tools.
Please see the GDB documentation available from the official GDB homepage [http://www.gnu.org/software/gdb/].
3.7.1. Connecting GDB to GRMON
GRMON can act as a remote target for GDB, allowing symbolic debugging of target applications. To initiate GDB
communications, start the monitor with the -gdb switch or use the GRMON gdb start command:
$ grmon -gdb
...
Started GDB service on port 2222.
...
grmon3> gdb status
GDB Service is waiting for incoming connection
Port: 2222
Then, start GDB in a different window and connect to GRMON using the extended-remote protocol. By default,
GRMON listens on port 2222 for the GDB connection:
$ sparc-gaisler-elf-gdb /opt/bcc-2.0.7-rc.1-gcc/src/examples/stanford/stanford
GNU gdb (GDB) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=sparc-gaisler-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
GRMON3-UM
June 2019, Version 3.1.0
24www.cobham.com/gaisler
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /opt/bcc-2.0.7-rc.1-gcc/src/examples/stanford/stanford...done.
(gdb) target extended-remote :2222
Remote debugging using :2222
__bcc_entry_point () at /opt/bcc-2.0.7-rc.1-gcc/src/libbcc/shared/trap/trap_table_mvt.S:81
81 RESET_TRAP(__bcc_trap_reset_mvt); ! 00 reset
(gdb)
3.7.2. Executing GRMON commands from GDB
While GDB is attached to GRMON, most GRMON commands can be executed using the GDB monitor command.
Output from the GRMON commands is then displayed in the GDB console like below. Some DSU commands are
naturally not available since they would conflict with GDB. All commands executed from GDB are executed in a
separate Tcl interpreter, thus variables created from GDB will not be available from the GRMON terminal.
To load and start an application, use the GDB load and run command.
$ sparc-rtems-gdb v8/stanford.exe
(gdb) target extended-remote :2222
Remote debugging using :2222
main () at stanford.c:1033
1033 {
(gdb) load
Loading section .text, size 0xdb30 lma 0x40000000
Loading section .data, size 0xb78 lma 0x4000db30
Start address 0x40000000, load size 59048
Transfer rate: 18 KB/sec, 757 bytes/write.
(gdb) b main
Breakpoint 1 at 0x40004074: file stanford.c, line 1033.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/daniel/examples/v8/stanford.exe
Breakpoint 1, main () at stanford.c:1033
1033 {
(gdb) list
1028 /* Printcomplex( 6, 99, z, 1, 256, 17 ); */
1029 };
1030 } /* oscar */ ;
1031
1032 main ()
1033 {
1034 int i;
1035 fixed = 0.0;
1036 floated = 0.0;
1037 printf ("Starting \n");
(gdb)
To interrupt execution, Ctrl-C can be typed in GDB terminal (similar to GRMON). The program can be restarted
using the GDB run command but the program image needs to be reloaded first using the load command. Software
trap 1 (TA 0x1) is used by GDB to insert breakpoints and should not be used by the application.
GRMON translates SPARC traps into (UNIX) signals which are properly communicated to GDB. If the application
encounters a fatal trap, execution will be stopped exactly before the failing instruction. The target memory and
register values can then be examined in GDB to determine the error cause.
GRMON implements the GDB breakpoint and watchpoint interface and makes sure that memory and cache are
synchronized.
GRMON3-UM
25www.cobham.com/gaisler
June 2019, Version 3.1.0
3.7.4. Running SMP applications from GDB
If GRMON is running on the same computer as GDB, or if the executable is available on the remote computer that is
running GRMON, it is recommended to issue the GDB command set remote exec-file <remote-file-path>. After
this has been set, GRMON will automatically load the file, and symbols if available, when the GDB command
run is issued.
$ sparc-rtems-gdb /opt/rtems-4.11/src/rtems-4.11/testsuites/libtests/ticker/ticker.exe
GNU gdb 6.8.0.20090916-cvs
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=sparc-rtems"...
(gdb) target extended-remote :2222
Remote debugging using :2222
0x00000000 in ?? ()
(gdb) set remote exec-file /opt/rtems-4.11/src/rtems-4.11/testsuites/libtests/ticker/ticker.exe
(gdb) break Init
Breakpoint 1 at 0x40001318: file ../../../../../leon3smp/lib/include/rtems/score/thread.h, line 627.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /opt/rtems-4.11/src/rtems-4.11/testsuites/libtests/ticker/ticker.exe
If the executable is not available on the remote computer where GRMON is running, then the GDB command
load can be used to load the software to the target system. In addition the entry points for all CPU's, except the
first, must be set manually using the GRMON ep before starting the application.
$ sparc-rtems-gdb /opt/rtems-4.11/src/rtems-4.11/testsuites/libtests/ticker/ticker.exe
GNU gdb 6.8.0.20090916-cvs
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=sparc-rtems"...
(gdb) target extended-remote :2222
Remote debugging using :2222
trap_table () at /opt/rtems-4.11/src/rtems-4.11/c/src/lib/libbsp/sparc/leon3/../../sparc/shared/start
/start.S:69
69 /opt/rtems-4.11/src/rtems-4.11/c/src/lib/libbsp/sparc/leon3/../../sparc/shared/start/start.S: No
such file or directory.
in /opt/rtems-4.11/src/rtems-4.11/c/src/lib/libbsp/sparc/leon3/../../sparc/shared/start/start.S
Current language: auto; currently asm
(gdb) load
Loading section .text, size 0x1aed0 lma 0x40000000
Loading section .data, size 0x5b0 lma 0x4001aed0
Start address 0x40000000, load size 111744
Transfer rate: 138 KB/sec, 765 bytes/write.
(gdb) mon ep $cpu::iu::pc cpu1
(gdb) mon ep $cpu::iu::pc cpu2
(gdb) mon ep $cpu::iu::pc cpu3
Cpu 1 entry point: 0x40000000
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /opt/rtems-4.11/src/rtems-4.11/testsuites/libtests/ticker/ticker.exe
3.7.5. Running AMP applications from GDB
If GRMON is running on the same computer as GDB, or if the executables are available on the remote computer
that is running GRMON, it is recommended to issue the GDB command set remote exec-file <remote-file-path>.
When this is set, GRMON will automatically load the file,and symbols if available, when the GDB command run is
issued. The second application needs to be loaded into GRMON using the GRMON command load <remote-file-
path> cpu1. In addition the stacks must also be set manually in GRMON using the command stack <address>
cpu# for both CPUs.
$ sparc-rtems-gdb /opt/rtems-4.10/src/samples/rtems-mp1
GNU gdb 6.8.0.20090916-cvs
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=sparc-rtems"...
GRMON3-UM
June 2019, Version 3.1.0
26www.cobham.com/gaisler
(gdb) target extended-remote :2222
Remote debugging using :2222
(gdb) set remote exec-file /opt/rtems-4.10/src/samples/rtems-mp1
(gdb) mon stack 0x403fff00 cpu0
CPU 0 stack pointer: 0x403fff00
(gdb) mon load /opt/rtems-4.10/src/samples/rtems-mp2 cpu1
Total size: 177.33kB (1.17Mbit/s)
Entry point 0x40400000
Image /opt/rtems-4.10/src/samples/rtems-mp2 loaded
(gdb) mon stack 0x407fff00 cpu1
CPU 1 stack pointer: 0x407fff00
(gdb) run
Starting program: /opt/rtems-4.10/src/samples/rtems-mp1
NODE[0]: is Up!
NODE[0]: Waiting for Semaphore A to be created (0x53454d41)
NODE[0]: Waiting for Semaphore B to be created (0x53454d42)
NODE[0]: Waiting for Task A to be created (0x54534b41)
^C[New Thread 151060481]
Program received signal SIGINT, Interrupt.
[Switching to Thread 151060481]
pwdloop () at /opt/rtems-4.10/src/rtems-4.10/c/src/lib/libbsp/sparc/leon3/startup/bspidle.S:26
warning: Source file is more recent than executable.
26 retl
Current language: auto; currently asm
(gdb)
If the executable is not available on the remote computer where GRMON is running, then the GDB command file
and load can be used to load the software to the target system. Use the GRMON command cpu act <num> before
issuing the GDB command load to specify which CPU is the target for the software being loaded. In addition the
stacks must also be set manually in GRMON using the command stack <address> cpu# for both CPUs.
$ sparc-rtems-gdb
GNU gdb 6.8.0.20090916-cvs
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=sparc-rtems".
(gdb) target extended-remote :2222
Remote debugging using :2222
0x40000000 in ?? ()
(gdb) file /opt/rtems-4.10/src/samples/rtems-mp2
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /opt/rtems-4.10/src/samples/rtems-mp2...done.
(gdb) mon cpu act 1
(gdb) load
Loading section .text, size 0x2b3e0 lma 0x40400000
Loading section .data, size 0x1170 lma 0x4042b3e0
Loading section .jcr, size 0x4 lma 0x4042c550
Start address 0x40400000, load size 181588
Transfer rate: 115 KB/sec, 759 bytes/write.
(gdb) file /opt/rtems-4.10/src/samples/rtems-mp1
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Load new symbol table from "/opt/rtems-4.10/src/samples/rtems-mp1"? (y or n) y
Reading symbols from /opt/rtems-4.10/src/samples/rtems-mp1...done.
(gdb) mon cpu act 0
(gdb) load
Loading section .text, size 0x2b3e0 lma 0x40001000
Loading section .data, size 0x1170 lma 0x4002c3e0
Loading section .jcr, size 0x4 lma 0x4002d550
Start address 0x40001000, load size 181588
Transfer rate: 117 KB/sec, 759 bytes/write.
(gdb) mon stack 0x407fff00 cpu1
CPU 1 stack pointer: 0x407fff00
(gdb) mon stack 0x403fff00 cpu0
CPU 0 stack pointer: 0x403fff00
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /opt/rtems-4.10/src/samples/samples/rtems-mp1
3.7.6. GDB Thread support
GDB is capable of listing a operating system's threads, however it relies on GRMON to implement low-level
thread access. GDB normally fetches the threading information on every stop, for example after a breakpoint is
GRMON3-UM
June 2019, Version 3.1.0
27www.cobham.com/gaisler
reached or between single-stepping stops. GRMON have to access the memory rather many times to retrieve the
information, GRMON. See Section 3.8, “Thread support” for more information.
Start GRMON with the -nothreads switch to disable threads in GRMON and thus in GDB too.
Note that GRMON must have access to the symbol table of the operating system so that the thread structures of
the target OS can be found. The symbol table can be loaded from GDB by one must bear in mind that the path is
relative to where GRMON has been started. If GDB is connected to GRMON over the network one must make
the symbol file available on the remote computer running GRMON.
(gdb) mon puts [pwd]
/home/daniel
(gdb) pwd
Working directory /home/daniel.
(gdb) mon sym load /opt/rtems-4.10/src/samples/rtems-hello
(gdb) mon sym
0x00016910 GLOBAL FUNC imfs_dir_lseek
0x00021f00 GLOBAL OBJECT Device_drivers
0x0001c6b4 GLOBAL FUNC _mprec_log10
...
When a program running in GDB stops GRMON reports which thread it is in. The command info threads can be
used in GDB to list all known threads, thread N to switch to thread N and bt to list the backtrace of the selected
thread.
Program received signal SIGINT, Interrupt.
[Switching to Thread 167837703]
0x40001b5c in console_outbyte_polled (port=0, ch=113 `q`) at rtems/.../leon3/console/debugputs.c:38
38 while ((LEON3_Console_Uart[LEON3_Cpu_Index+port]->status & LEON_REG_UART_STATUS_THE) == 0);
(gdb) info threads
8 Thread 167837702 (FTPD Wevnt) 0x4002f760 in _Thread_Dispatch () at rtems/.../threaddispatch.c:109
7 Thread 167837701 (FTPa Wevnt) 0x4002f760 in _Thread_Dispatch () at rtems/.../threaddispatch.c:109
6 Thread 167837700 (DCtx Wevnt) 0x4002f760 in _Thread_Dispatch () at rtems/.../threaddispatch.c:109
5 Thread 167837699 (DCrx Wevnt) 0x4002f760 in _Thread_Dispatch () at rtems/.../threaddispatch.c:109
4 Thread 167837698 (ntwk ready) 0x4002f760 in _Thread_Dispatch () at rtems/.../threaddispatch.c:109
3 Thread 167837697 (UI1 ready) 0x4002f760 in _Thread_Dispatch () at rtems/.../threaddispatch.c:109
2 Thread 151060481 (Int. ready) 0x4002f760 in _Thread_Dispatch () at rtems/.../threaddispatch.c:109
* 1 Thread 167837703 (HTPD ready ) 0x40001b5c in console_outbyte_polled (port=0, ch=113 `q`)
at ../../../rtems/c/src/lib/libbsp/sparc/leon3/console/debugputs.c:38
(gdb) thread 8
[Switching to thread 8 (Thread 167837702)]#0 0x4002f760 in _Thread_Dispatch ()
at rtems/.../threaddispatch.c:109
109 _Context_Switch( &executing->Registers, &heir->Registers );
(gdb) bt
#0 0x4002f760 in _Thread_Dispatch () at rtems/cpukit/score/src/threaddispatch.c:109
#1 0x40013ee0 in rtems_event_receive(event_in=33554432, option_set=0, ticks=0, event_out=0x43fecc14)
at ../../../../leon3/lib/include/rtems/score/thread.inl:205
#2 0x4002782c in rtems_bsdnet_event_receive (event_in=33554432, option_set=2, ticks=0,
event_out=0x43fecc14) at rtems/cpukit/libnetworking/rtems/rtems_glue.c:641
#3 0x40027548 in soconnsleep (so=0x43f0cd70) at rtems/cpukit/libnetworking/rtems/rtems_glue.c:465
#4 0x40029118 in accept (s=3, name=0x43feccf0, namelen=0x43feccec) at rtems/.../rtems_syscall.c:215
#5 0x40004028 in daemon () at rtems/c/src/libnetworking/rtems_servers/ftpd.c:1925
#6 0x40053388 in _Thread_Handler () at rtems/cpukit/score/src/threadhandler.c:123
#7 0x40053270 in __res_mkquery (op=0, dname=0x0, class=0, type=0, data=0x0, datalen=0, newrr_in=0x0,
buf=0x0, buflen=0)
at ../rtems/cpukit/libnetworking/libc/res_mkquery.c:199
#8 0x00000008 in ?? ()
#9 0x00000008 in ?? ()
Previous frame identical to this frame (corrupt stack?)
In comparison to GRMON the frame command in GDB can be used to select a individual stack frame. One can
also step between frames by issuing the up or down commands. The CPU registers can be listed using the inforegisters command. Note that the info registers command only can see the following registers for an inactive
task: g0-g7, l0-l7, i0-i7, o0-o7, PC and PSR. The other registers will be displayed as 0:
gdb) frame 5
#5 0x40004028 in daemon () at rtems/.../rtems_servers/ftpd.c:1925
1925 ss = accept(s, (struct sockaddr *)&addr, &addrLen);
NOTE: It is not supported to set thread specific breakpoints. All breakpoints are global and stops the execution
of all threads. It is not possible to change the value of registers other than those of the current thread.
3.7.7. Virtual memory
There is no way for GRMON to determine if an address sent from GDB is physical or virtual. If an MMU unit is
present in the system and it is enabled, then GRMON will assume that all addresses are virtual and try to translate
them. When debugging an application that uses the MMU one typically have an image with physical addresses
used to load data into the memory and a second image with debug-symbols of virtual addresses. It is therefore
important to make sure that the MMU is enabled/disabled when each image is used.
The example below will show a typical case on how to handle virtual and physical addresses when debugging with
GDB. The application being debugged is Linux and it consists of two different images created with Linuxbuild.
The file image.ram contains physical addresses and a small loader, that among others configures the MMU,
while the file image contains all the debug-symbols in virtual address-space.
First start GRMON and start the GDB server.
$ grmon -nb -gdb
Then start GDB in a second shell, load both files into GDB, connect to GRMON and then upload the application
into the system. The addresses will be interpreted as physical since the MMU is disabled when GRMON starts.
$ sparc-linux-gdb
GNU gdb 6.8.0.20090916-cvs
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=sparc-linux".
(gdb) file output/images/image.ram
Reading symbols from /home/user/linuxbuild-1.0.2/output/images/image.ram...(no d
ebugging symbols found)...done.
The program must reach a state where the MMU is enabled before any virtual address can be translated. Software
breakpoints cannot be used since the MMU is still disabled and GRMON won't translate them into a physical.
Hardware breakpoints don't need to be translated into physical addresses, therefore set a hardware assisted breakpoint at 0xf0004000, which is the virtual start address for the Linux kernel.
(gdb) hbreak *0xf0004000
Hardware assisted breakpoint 1 at 0xf0004000: file /home/user/linuxbuild-1.0.2/l
inux/linux-2.6-git/arch/sparc/kernel/head_32.S, line 87.
(gdb) cont
Continuing.
Breakpoint 1, trapbase_cpu0 () at /home/user/linuxbuild-1.0.2/linux/linux-2.6-gi
t/arch/sparc/kernel/head_32.S:87
87 t_zero: b gokernel; nop; nop; nop;
At this point the loader has enabled the MMU and both software breakpoints and symbols can be used.
(gdb) break leon_init_timers
Breakpoint 2 at 0xf03cff14: file /home/user/linuxbuild-1.0.2/linux/linux-2.6-git
/arch/sparc/kernel/leon_kernel.c, line 116.
(gdb) cont
Continuing.
Breakpoint 2, leon_init_timers (counter_fn=0xf00180c8 <timer_interrupt>)
at /home/user/linuxbuild-1.0.2/linux/linux-2.6-git/arch/sparc/kernel/leon_ke
rnel.c:116
116 leondebug_irq_disable = 0;
Current language: auto; currently c
(gdb) bt
#0 leon_init_timers (counter_fn=0xf00180c8 <timer_interrupt>)
at /home/user/linuxbuild-1.0.2/linux/linux-2.6-git/arch/sparc/kernel/leon_ke
rnel.c:116
#1 0xf03ce944 in time_init () at /home/user/linuxbuild-1.0.2/linux/linux-2.6-gi
t/arch/sparc/kernel/time_32.c:227
#2 0xf03cc13c in start_kernel () at /home/user/linuxbuild-1.0.2/linux/linux-2.6
-git/init/main.c:619
#3 0xf03cb804 in sun4c_continue_boot ()
#4 0xf03cb804 in sun4c_continue_boot ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) info locals
eirq = <value optimized out>
rootnp = <value optimized out>
np = <value optimized out>
pp = <value optimized out>
len = 13
ampopts = <value optimized out>
(gdb) print len
$2 = 13
If the application for some reason need to be reloaded, then the MMU must first be disabled via GRMON. In
addition all software breakpoints should be deleted before the application is restarted since the MMU has been
disabled and GRMON won't translate virtual addresses anymore.