Debugging with GDB: Targets

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 19. Specifying a Debugging Target

A target is the execution environment occupied by your program.

Often, GDB runs in the same host environment as your program; in that case, the debugging target is specified as a side effect when you use the `file` or `core` commands. When you need more flexibility--for example, running GDB on a physically separate host, or controlling a standalone system over a serial port or a realtime system over a TCP/IP connection--you can use the `target` command to specify one of the target types configured for GDB (see section Commands for Managing Targets).

It is possible to build GDB for several different target architectures. When GDB is built like that, you can choose one of the available architectures with the `set architecture` command.

`set architecture arch`
  This command sets the current target architecture to arch. The value of arch can be `"auto"`, in addition to one of the supported architectures.

`show architecture`
  Show the current target architecture.

`set processor`
`processor`
  These are alias commands for, respectively, `set architecture` and `show architecture`.

> 19.1 Active Targets |  | Active targets
> 19.2 Commands for Managing Targets |  | Commands for managing targets
> 19.3 Choosing Target Byte Order |  | Choosing target byte order

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 19.1 Active Targets

There are multiple classes of targets such as: processes, executable files or recording sessions. Core files belong to the process class, making core file and process mutually exclusive. Otherwise, GDB can work concurrently on multiple active targets, one in each class. This allows you to (for example) start a process and inspect its activity, while still having access to the executable file after the process finishes. Or if you start process recording (see section 6. Running programs backward) and `reverse-step` there, you are presented a virtual layer of the recording target, while the process target remains stopped at the chronologically last point of the process execution.

Use the `core-file` and `exec-file` commands to select a new core file or executable target (see section Commands to Specify Files). To specify as a target a process that is already running, use the `attach` command (see section Debugging an Already-running Process).

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 19.2 Commands for Managing Targets

`target type parameters`
  Connects the GDB host environment to a target machine or process. A target is typically a protocol for talking to debugging facilities. You use the argument type to specify the type or protocol of the target machine.

  Further parameters are interpreted by the target protocol, but typically include things like device names or host names to connect with, process numbers, and baud rates.

  The `target` command does not repeat if you press `RET` again after executing the command.

`help target`
  Displays the names of all targets available. To display targets currently selected, use either `info target` or `info files` (see section Commands to Specify Files).

`help target name`
  Describe a particular target, including any parameters necessary to select it.

`set gnutarget args`
  GDB uses its own library BFD to read your files. GDB knows whether it is reading an executable, a core, or a .o file; however, you can specify the file format with the `set gnutarget` command. Unlike most `target` commands, with `gnutarget` the `target` refers to a program, not a machine.

  > Warning: To specify a file format with `set gnutarget`, you must know the actual BFD name.

  See section Commands to Specify Files.

`show gnutarget`
  Use the `show gnutarget` command to display what file format `gnutarget` is set to read. If you have not set `gnutarget`, GDB will determine the file format for each file automatically, and `show gnutarget` displays ``The current BFD target is "auto"'`.

Here are some common targets (available, or not, depending on the GDB configuration):

`target exec program`
  An executable file. ``target exec program'` is the same as ``exec-file program'`.

`target core filename`
  A core dump file. ``target core filename'` is the same as ``core-file filename'`.

`target remote medium`
  A remote system connected to GDB via a serial line or network connection. This command tells GDB to use its own remote protocol over medium for debugging. See section 20. Debugging Remote Programs.

  For example, if you have a board connected to ``/dev/ttya'` on the machine running GDB, you could say:

      target remote /dev/ttya

  `target remote` supports the `load` command. This is only useful if you have some other way of getting the stub to the target system, and you can put it somewhere in memory where it won't get clobbered by the download.

`target sim [simargs] ...`
  Builtin CPU simulator. GDB includes simulators for most architectures. In general,

              target sim
              load
              run

  works; however, you cannot assume that a specific memory map, device drivers, or even basic I/O is available, although some simulators do provide these. For info about any processor-specific simulator details, see the appropriate section in Embedded Processors.

Different targets are available on different configurations of GDB; your configuration may have more or fewer targets.

Many remote targets require you to download the executable's code once you've successfully established a connection. You may wish to control various aspects of this process.

`set hash`
  This command controls whether a hash mark ``#'` is displayed while downloading a file to the remote monitor. If on, a hash mark is displayed after each S-record is successfully downloaded to the monitor.

`show hash`
  Show the current status of displaying the hash mark.

`set debug monitor`
  Enable or disable display of communications messages between GDB and the remote monitor.

`show debug monitor`
  Show the current status of displaying communications between GDB and the remote monitor.

`load filename`
  Depending on what remote debugging facilities are configured into GDB, the `load` command may be available. Where it exists, it is meant to make filename (an executable) available for debugging on the remote system--by downloading, or dynamic linking, for example. `load` also records the filename symbol table in GDB, like the `add-symbol-file` command.

  If your GDB does not have a `load` command, attempting to execute it gets the error message "`You can't do that when your target is ...`"

  The file is loaded at whatever address is specified in the executable. For some object file formats, you can specify the load address when you link the program; for other formats, like a.out, the object file format specifies a fixed address.

  Depending on the remote side capabilities, GDB may be able to load programs into flash memory.

  `load` does not repeat if you press `RET` again after using it.

`unload filename`
  Depending on what remote debugging facilities are configured into GDB, the `unload` command may be available. Where it exists, it does the opposite of the `load` command.

  If your GDB does not have an `unload` command, attempting to execute it triggers the error message "`You can't do that when your target is ...`"

  `unload` does not repeat if you press `RET` again after using it.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 19.3 Choosing Target Byte Order

Some types of processors, such as the MIPS, PowerPC, and Renesas SH, offer the ability to run either big-endian or little-endian byte orders. Usually the executable or symbol will include a bit to designate the endian-ness, and you will not need to worry about which to use. However, you may still find it useful to adjust GDB's idea of processor endian-ness manually.

`set endian big`
  Instruct GDB to assume the target is big-endian.

`set endian little`
  Instruct GDB to assume the target is little-endian.

`set endian auto`
  Instruct GDB to use the byte order associated with the executable.

`show endian`
  Display GDB's current idea of the target byte order.

Note that these commands merely adjust interpretation of symbolic data on the host, and that they have absolutely no effect on the target system.

[ << ] | [ >> ] |  |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by GNAT Mailserver on April, 17 2014 using texi2html