## 18 Porting gdb

Most of the work in making gdb compile on a new machine is in specifying the configuration of the machine. Porting a new architecture to gdb can be broken into a number of steps.

- Ensure a bfd exists for executables of the target architecture in the `bfd` directory. If one does not exist, create one by modifying an existing similar one.
- Implement a disassembler for the target architecture in the `opcodes` directory.
- Define the target architecture in the `gdb` directory (see Adding a New Target). Add the pattern for the new target to `configure.tgt` with the names of the files that contain the code. By convention the target architecture definition for an architecture arch is placed in `arch-tdep.c`.

  Within `arch-tdep.c` define the function `_initialize_`arch`_tdep` which calls `gdbarch_register` to create the new `struct gdbarch` for the architecture.

- If a new remote target is needed, consider adding a new remote target by defining a function `_initialize_remote_`arch. However if at all possible use the gdb Remote Serial Protocol for this and implement the server side protocol independently with the target.
- If desired implement a simulator in the `sim` directory. This should create the library `libsim.a` implementing the interface in `remote-sim.h` (found in the `include` directory).
- Build and test. If desired, lobby the gdb steering group to have the new port included in the main distribution!
- Add a description of the new architecture to the main gdb user guide (see Configuration Specific Information).