This section provides examples on the use of GDB in all application debugging scenarios, including the analysis of a process dump.
Before starting GDB, ensure that:
RDBC is running on the target (for standard application debugging). If RDBC is not running, run it without any argument.
RDBD is running on the host (for process dump analysis).
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.
The following procedures describe how to connect to the target for a standard application debug and for a process dump.
Specify the communication port.
If RDBC has been started on a default port:
(chgdb) rdbport RDBC RDB port is now 2072 (chgdb) |
If RDBC has been started on a non-default port, specify the communication port as follows:
(chgdb) rdbport port_number RDB port is now port_number (chgdb) |
Connect to the target.
(chgdb) target chorusrdb remote_host Attaching remote machine across net... Setting path translation 'root_dir' '/' Connected to remote_host. Now the "run" command will start a remote process. (chgdb) |
You can also pass the port number directly in the target command:
(chgdb) target chorusrdb remote_host:RDBC Attaching remote machine across net... Setting path translation 'root_dir' '/' Connected to remote_host:RDBC. Now the "run" command will start a remote process. (chgdb) |
Specify the communication port.
If RDBD has been started on a default port:
(chgdb) rdbport RDBD RDB port is now 0 (chgdb) |
If RDBD has been started on a non-default port, specify the communication port as follows:
(chgdb) rdbport port_number RDB port is now port_number (chgdb) |
Connect to the target.
(chgdb) target chorusrdb remote_host Attaching remote machine across net... Connected to remote_host. Now the "run" command will start a remote process. (chgdb) |
You can also pass the port number directly in the target command:
(chgdb) target chorusrdb remote_host:RDBD Attaching remote machine across net... Setting path translation 'root_dir' '/' Connected to remote_host:RDBD. Now the "run" command will start a remote process. (chgdb) |
To debug an application with GDB, use the file command to specify its executable pathname on the host. Because GDB for ChorusOS systems is a cross-debugging tool, the debugged process is created remotely on the target by the target itself. The target view of files is different from the host view (the target root directory is usually a subdirectory on the host filesystem). It is therefore necessary to translate the host pathname of the executable file into its corresponding target form. GDB for ChorusOS includes a path translation mechanism for this purpose.
A default path translation (provided by RDBC) is established when you connect to a target using the NFS mount point information. It is possible to change this default translation, if necessary, using the rdbpathtranslate hostpath targetpath command. If a host pathname starts with hostpath, this portion of the pathname is replaced with targetpath. The default target path is /.
The following examples show how an application is executed for a debugging session with and without the use of rdbpathtranslate.
In the following example, the pathname of the executable matches the default path translation, so there is no need to change the path.
(chgdb) file root_dir/bin/examples/timers_u Reading symbols from root_dir/bin/examples/timers_u...done. (chgdb) run Starting program: root_dir/bin/examples/timers_u Program exited normally. (chgdb) |
In the following example, the default path translation does not match the pathname of the executable.
(chgdb) file build_dir/build-EXAMPLES/progov/timers_u Reading symbols from build_dir/build-EXAMPLES/progov/timers_u...done. (chgdb) rdbpathtranslate Syntax is: rdbpathtranslate <host-path> [target-path] Currently 'build_dir/root' '/' (chgdb) run Starting program: build_dir/build-EXAMPLES/progov/timers_u Warning: executable path 'build_dir/build-EXAMPLES/progov/timers_u' does not match the path translation set with 'rdbpathtranslate' (from 'build_dir/root' to '/'). It will be used without translation. Unable to create remote process (remote problem): File not found (maybe / has changed). (chgdb) |
In the preceding example, the pathname of the executable is build_dir/build-EXAMPLES/progov/timers_u. It does not start with hostpath, which is build_dir/root. However, the build_dir directory has been mounted as /tests on the target:
(chgdb) i rdbmounted TYPE MOUNTPOINT NAME pdevfs / root_device pdevfs /dev pdevfs pdevfs /image pdevfs msdos /image/sys_bank /dev/bd01 nfs / local_host_ip:/build_dir/root nfs /tests local_host_ip:build_dir (chgdb) |
You can execute the program successfully by redefining the path translation as follows:
(chgdb) rdbpathtranslate build_dir /tests (chgdb) run Starting program: build_dir/build-EXAMPLES/progov/timers_u Program exited normally. (chgdb) |
This procedure shows how a process is executed for a process dump rather than a standard debugging session.
Load the executable.
(chgdb) file root_dir/bin/examples/timers_u Reading symbols from root_dir/bin/examples/timers_u...done. |
Examine the available process dumps.
The available process dumps appear as stopped processes in the process list. Use the info command to display the process list.
(chgdb) info rdbprocesses PID STATE OWNERS UID PRIVLGE THREADS NAME (PATH) 1 Stop 0 0 Usr 2 core_timers_u |
Attach to the selected process.
Use the attach command to attach to the selected process id:
(chgdb) attach 1 Attaching program: root_dir/bin/examples/timers_u pid 1. [Switching to Thread 6 ()] 0xeffe41b8 in sampleThread () at root_dir/opt/examples/progov/timers.c:93 93 res = timerThreadPoolWait(&samplePool, &cookie, &overrun, K_NOTIMEOUT); (chgdb) |
When analyzing process dumps, certain standard commands (cont, next, step, run), and certain ChorusOS commands do not work.
In a GDB debugging session, threads have two numbers: a ChorusOS thread number and a GDB number. Both numbers are unique. The GDB thread number is never reused, unlike the ChorusOS thread number.
The standard command to list threads is info threads:
(chgdb) info threads 3 Thread 13 (Thread_13) sampleThread () at root_dir/system-int/opt/examples/progov/timers.c:81 2 Thread 14 (Thread_14) sampleThread () at root_dir/system-int/opt/examples/progov/timers.c:81 * 1 Thread 11 (main) main (argc=1, argv=0xeffd2008, envp=0xeffd2010) at root_dir/system-int/opt/examples/progov/timers.c:169 (chgdb) |
In the preceding example, the numbers in the first column (3, 2 and 1) are the GDB thread numbers. The numbers in the second column (13, 14 and 11) are the ChorusOS thread numbers.
To change the current thread, use the thread gdb_thread_number command.
In an application debugging session, you can use the info rdbthreads command to obtain additional information about threads:
(chgdb) info rdbthreads NUMBER STATE CURRENT PRIO TOTTIME INTTIME NAME 14 Run 140 0 0 Thread_14 13 Run 140 0 0 Thread_13 11 Run * 140 0 0 main |
Because this command is provided by the debug server, it displays ChorusOS thread numbers only. In the preceding example, the number under the NUMBER column is the ChorusOS thread number and the name in the NAME column (Thread_x) is the ChorusOS thread name.
Use the rdbthread chorusos_thread_number command to change the current thread.