This chapter describes how to debug ChorusOS systems with the GDB debugger and the Insight GUI. The chapter includes the following:
This section describes the system debugging architecture and illustrates how the various components work together. The system debugging architecture includes:
GDB/Insight debugging tool for ChorusOS
ChorusOS debug server
Debug agent
The first two components run on the host. The debug agent runs on the target and communicates with the ChorusOS debug server through a serial connection. The architecture is illustrated in Figure 3-1.
A debug server can manage several targets (with different architectures) at the same time.
System debugging enables you to debug the microkernel, the system drivers, the BSP, and those supervisor actors that cannot be debugged with application debugging, such as the C_OS.
The following steps guide you through setting up your first system debugging session:
Connect a serial cable between the host and the target.
Prepare the system for symbolic debugging. See "Enabling Symbolic Debugging" for information on how to do this.
Start and configure the ChorusOS debug server chserver. See "Starting the Debug Server" for more information.
Register the target with chadmin, the ChorusOS debug server administration tool. See "Registering a Target".
Configure and start the GDB debugging tool for ChorusOS.
GDB performs the system console function during system debugging. However, you can also use the standalone chconsole tool. If the debug server is not connected to a target, you can still view the system console using the tip or cu commands (but cannot debug). See the tip(1) and cu(1C) man pages for more information.
For subsequent debugging sessions, you need only perform the following steps:
Start the ChorusOS debug server chserver, if it is not already running.
Start the GDB debugging tool for ChorusOS systems.
The ChorusOS debug server chserver communicates with the target through a serial cable connection and must be run on the host to which the target is connected.
The debug server is a Sun RPC server that is registered with the rpcbind server. When you require more than one debug server to run on the same host, associate a unique slot number with each of them so that individual debug servers can be identified. If only one debug server is started on a given host, it is not necessary to allocate a slot number; 0 is used by default.
Use the debug server environment variable CHSERVER_HOST to assign a slot number to a debug server.
The debug server and all other tools based on the ChorusOS system Debug Library use the optional environment variable CHSERVER_HOST to indicate:
The host name on which the debug server is running.
Optionally, the slot number for the debug server RPC service.
The format of the environment string is: host[:slot-id], as shown in the following example:
$ setenv CHSERVER_HOST jeriko $ setenv CHSERVER_HOST concerto:3 |
On the host to which your target or targets are connected, type the following:
$ chserver |
This starts the debug server as a background process. An empty configuration file called dbg_config.xml is copied into your home directory the first time you run the debug server.
If you have defined a slot number n and have not set the environment variable, you can start the debug server by typing:
$ chserver -slot n |
If the CHSERVER_HOST environment variable is set, it must contain the correct host name, otherwise the debug server will not operate correctly.
A complete description of the debug server is provided in the chserver(1CC) man page.
If chserver is run on a different host from the one on which the system image was built (particularly on a shared file system with a different view of the build directory) it will not be able to access the necessary source files during system debugging. The symbolic link created on one host may not be valid for another because of the relative file references in the layout.xml file. There are two solutions to this problem:
Break the build_dir/build-NUCLEUS/conf/mkimage/layout_typedef.xml symbolic link accessed by chserver and replace it with a copy of the file to which it points.
Copy the conf and image directories to the host where chserver will run, then use chadmin to set the path of the layout.xml file. You will need to do this each time the system image is regenerated.
Configuration information about targets is kept in a configuration file that the debug server reads every time it is run. For each target, the configuration file contains:
The name of the target.
The serial device used to communicate with the target.
Configuration parameters for the serial device (baud rate and parity) .
The architecture type of the target (for example, x86, PPC, SPARC) .
The absolute path of the layout.xml image layout file generated by mkimage.
When a new target is registered, the configuration file is modified. (See "Registering a Target" for details of how to do this). A sample configuration file is shown below.
<!-- ChorusOS debug server configuration file --> <!-- Generated by ChorusOS debug server v1.0 --> <package> <object name="target_name" type="target_type"> <set param="pathmap" value=""/> <set param="layout_file" value="build_dir/image/bmon/chorus/layout.xml"/> <set param="get_image_desc_cmd" value="chgetlayout -stamp $(image_stamp) $(abs_layout_file)"/> <set param="archive_file" value=""/> <set param="activate" value="1"/> <object name="backends" type="BackendList"> <object name="log:bkpts:cache:log:serial" type="SerialBackend"> <set param="device" value="/dev/term/a"/> <set param="baud" value="9600"/> <set param="parity" value="none"/> <set param="debug_mode" value="1"/> <set param="reboot_cmd" value=""/> <set param="reboot_wait" value="5"/> <set param="connect_timeout" value="120000"/> <set param="sync_retry_delay" value="5000"/> </object> </object> </object> </package>
To stop the debug server, use the chadmin tool:
$ chadmin -shutdown |
Stopping the debug server is not advised because you can lose communication with the target.
Before registering a target you must know:
The name of the serial device on the host.
The path of the layout.xml file generated by mkimage (the path of this file is printed by mkimage when a system image is built).
You must also have chosen a name for the target (typically its host name).
Register the target by typing:
$ chadmin -add-serial-target target_name\ -device device\ -layout-file layout_file\ -pathmap original_dir new_dir |
In the preceding example, device is the serial device that you have identified and layout_file is the absolute path of the layout.xml file.
The -pathmap option enables you to set a translation pathmap. original_dir is the original directory that cannot be accessed by the debug server. new_dir is the new directory for the debug server to use (instead of the original one).
You only need to register a target once, as configuration information is saved in your dbg_config.xml file.
If you modify the dbg_config.xml file manually, without using chadmin, you must restart the debug server for changes to take effect.
When a target is activated, the debug server synchronizes with the debug agent and the debug agent switches to binary protocol mode. Use chconsole at this stage to access the system debugging console.
Use chadmin to update the information provided during the registration of the target.
The following example sets the baud rate to 38400 and sets the parity to none. It uses the device /dev/ttya for the target name:
$ chadmin -baud 38400 -parity none -device /dev/ttya target_name |
Before the target updates, it is necessary to adjust certain tunables for the debug agent. See "Configuring the Debug Agent" for more information.
To specify a new layout.xml file because the path has changed, use the following command to inform the debug server of the new path:
$ chadmin -layout-file pathname/layout.xml target_name |
When you change the mode in which the system image boots (using the BOOT_MODE
global variable) or select a different system image
configuration (using the SYSTEM
global variable),
the path to the layout.xml file changes.
For example, if you type:
$ configurator -set SYSTEM=kts |
the path changes to build_dir/image/RAM/kts/layout.xml.
If you then type:
$ configurator -set SYSTEM=chorus |
the path changes to build_dir/image/RAM/chorus/layout.xml.
Similarly, if you change the mode in which the system image boots by typing:
$ configurator -set BOOT_MODE=ROM |
the path changes to build_dir/image/ROM/chorus/layout.xml.
A target can be deactivated to disconnect the debug server from the debug agent and to release the serial device used by the debug server. When a target is deactivated, the debug agent switches to standalone mode. The chconsole can no longer be used because the debug server no longer reads the serial line. Instead, you must start the tip or cu tools to access the system debugging console.
A target can be temporarily removed (deactivated) with the command:
$ chadmin -deactivate target_name |
When a target is deactivated, it is not removed from the debug server configuration file. It is therefore possible to reactivate it later.
Before a target can be reactivated, stop any tip or cu tools which may be using the serial line.
A target is reactivated with the following command:
$ chadmin -activate target_name |
A target can be removed permanently by deactivating it (see "Deactivating a Target") then unregistering it with the following command:
$ chadmin -remove-target target_name |
If you have deactivated the target properly, its configuration information will be deleted from the configuration file.
The debug agent is activated by enabling the DEBUG_SYSTEM feature with the configurator command as follows:
$ configurator -set DEBUG_SYSTEM=true |
The DEBUG_SYSTEM feature is set to true by default.
When the debug agent is activated, communications on the serial line are performed in binary mode (if the debug server is attached) or in ASCII mode (if it is not).
The debug agent has eight tunable options that you can configure with Ews or configurator. The following three tunables control the behavior of the debug agent when it is enabled (DEBUG_SYSTEM=true):
dbg.agent.startup specifies the behavior of the debug agent at boot time. Possible values are stop or resume. In stop mode the system waits indefinitely until the debug server connects to the debug agent. In resume mode the system waits for no more than one second. In both cases, the debug agent issues the prompt:
DebugAgent: trying to sync with DebugServer...
over the serial line and sounds a beep. If the debug server does not connect, the system will continue booting and console operations will be performed without any processing by the debug agent, on the serial line.
dbg.agent.exceptmode specifies the behavior of the debug agent when an exception (caught by deafult) is raised before the debug server has connected. Possible values are catch or forward. In catch mode the debug agent blocks the target until a debug server has connected and resumed the execution of the target. In forward mode the debug agent forwards all exceptions directly to the handlers installed by the microkernel.
dbg.agent.consolemode specifies the operating mode of the system console. Possible values are sync or async. In sync mode the target is blocked until each message has been transmitted to the host for output and acknowledged. In async mode, console output is buffered and transmitted to the host periodically, either when the buffer is full or on each timer interrupt (whichever occurs first).
The following five tunables control the serial line used by the debug agent:
dbg.agent.device specifies the serial device used by the debug agent. Possible values are COM1, COM2, COM3, or COM4. COM1 refers to communication port 1 on a PC, or the first serial line on other boards. COM2 refers to communication port 2 on a PC, or the second serial line on other boards, and so on.
dbg.agent.baud specifies the baud rate of the serial line. Possible values are: 115200, 57600, 38400, 19200, 9600, 4800, 2400, or 1200.
dbg.agent.parity specifies the parity of the serial line. Possible values are none, even, or odd.
dbg.agent.databits specifies the number of data bits. The only possible value is 8.
dbg.agent.stopbits specifies the number of stop bits. Possible values are 1 or 2.
When the debug agent is not active (DEBUG_SYSTEM=false), the serial line is used by the system debugging console, and the five tunables control the serial device and speed.
This section describes the use of the Insight GUI and of GDB for debugging ChorusOS systems.
Before starting Insight for system debugging, ensure that the debug agent is running on the target system and that the debug server is connected to it.
The name of the Insight executable differs according to the target platform and takes the form target-type-chorusos-gdb. Thus, depending on the platform, type one of the following to start Insight:
$ sparc-chorusos-gdb
$ powerpc-chorusos-gdb
$ i386-chorusos-gdb
By default, the Insight GUI is started when you start GDB.
Select File -> Target Settings.
Select ChorusOS System Debug from the Target list.
In the Target name field, type the target name, as registered in the debug server.
In the Chserver host field, type the name of the host on which the debug server is running.
If the chserver uses the default slot, type chserver_host_name.
If the chserver does not use the default slot, type chserver_host_name:slot-id.
Click OK to save the target settings.
Select Run -> Connect to target.
Once you have connected to the target successfully, the symbols for
all components of your system image are automatically loaded. The connection
is complete when the message Successfully connected
is displayed.
If you recompiled the microkernel from source after enabling symbolic debugging, the target stops executing and the line of code on which it stops is displayed in the Source Window when a successful connection is made.
Using the Run button or selecting Run -> Run will reboot your ChorusOS target. You can also reboot your target using the Run command in the View -> Console window.
Selecting Run -> Connect to target before setting your target causes the Target Selection window to be displayed automatically.
Before starting GDB for system debugging, make sure that the debug agent is running on the target and that the debug server is connected to it.
The name of the GDB executable differs according to the target platform and takes the form target-type-chorusos-gdb. Thus, depending on the platform, type one of the following to start GDB:
$ sparc-chorusos-gdb --nw
$ powerpc-chorusos-gdb --nw
$ i386-chorusos-gdb --nw
By default, the Insight GUI is started when you start GDB. To start GDB without the Insight GUI, you must include the --nw option.
If GDB is not started on the same host as the debug server, and the CHSERVER_HOST is not set or is incorrectly set, set the host with the following command:
(chgdb) set chserver host_name [:slot-id] |
where host_name is the name of the host on which the debug server is running and the optional slot-id is the occupied slot.
Connect to the target using the target chorusos target_name command, as indicated in the example below:
(chgdb) target chorusos target_name |
When GDB is connected to the target, load the symbols for all the components of your system image as follows:
(chgdb) chload-symbols |
Once you have started GDB and connected to the target successfully, the system is stopped, usually in the clock interrupt handler. The debugging session follows the standard GDB debugging process. For more information on this process, see Debugging with GDB.
Using the run command at any point will reboot your ChorusOS system.
Most of the Insight windows used in ChorusOS system debugging sessions are standard and information on their use is available in the standard Insight documentation. Some functionality has been added or customized for ChorusOS operating systems. These additions and customizations are described in the following sections.
The ChorusOS DebugServers Objects window displays a list of ChorusOS entities (threads, actors, and regions). To view the DebugServers Objects window, select ChorusOS -> DebugServer Objects.
Use the buttons at the top of the window to execute predefined commands, or enter an argument for the Chls command and click Display.
The following system debugging commands are available:
Loads the symbols for the attached system.
Changes the current thread. This command is similar to thread thread-id but uses ChorusOS thread numbers. It does not accept the apply keyword.
Lists ChorusOS system objects. Refer to the chls(1CC) man page.
Sets the resume target flag on exit. By default, the target resumes when GDB detaches from it. You can clear the target flag to keep the target stopped when GDB detaches.
Enables or disables debug traces for maintenance.
Sets the host name and slot number to connect to the debug server. The format of the argument is the same as the CHSERVER_HOST environment variable. This variable is set automatically, according to the CHSERVER_HOST environment variable. The host name indicates the host on which the debug server is running. The optional slot number represents the slot number used when the debug server was started.
Defines the format of the template to be used by GDB when reporting information about a thread. The template uses the thread attributes defined by the debug server to insert variable information into the constructed name.
Connects to the ChorusOS target for system debugging. The optional argument machinename is the name of the target as registered in the debug server. The command attempts to find a default active target registered in the debug server. If several targets are registered and active, you must specify the name of a target.
Additional commands may have been added after the release of this manual. To obtain a complete list of these commands, type:
$ ch |
or
% set ch |
and press the Tab key twice.