Common part of GDB and GDBserver

This page describes the work to move duplicate code of GDB and GDBserver to files in the gdb/common/ directory.

1. Goal

There's a lot of code duplication between GDB and GDBserver. The project has been taking baby steps in reducing such duplication, by putting shared code in the gdb/common/ directory. The goal of this project is to reduce the duplication as much as possible, and to signify the contents of the gdb/common/ directory.

2. Where's the duplication then?

2.1. Target backends

These are the biggest duplication offenders. That is, the gdb/*-nat.c files and the gdb/gdbserver/*-low.c files accomplish pretty much the same. (Some targets do things differently enough, that they're not really duplication of code, but can be considered different implementations. The Linux support is one such case. Over the years we've been converging them though -- see the LocalRemoteFeatureParity page for more details.). GDBserver supports fewer target OSs than GDB does. Ideally, we'd finish the LocalRemoteFeatureParity project first, and then just dump the GDB-side backends. Presently, there's overlap/duplication in:

2.2. Arch-specific bits of the target backends

Independently of the local/remote parity project, however, there are bits of the backends, most prominently, the arch specific bits, that can be shared between the target backend implementations before then, as the interfaces are similar enough. E.g., code accessing hardware registers, debug registers/watchpoint support; code that detects which variant of a processor the program is running (the xml target description to send to GDB core), etc.. Sharing such arch specific code significantly reduces the effort for new ports (those usually don't need to touch common code). As is today most ports involve doing the same work twice. We should clean up some of the existing ports, laying grounds for good examples for new ports.

Move these duplicated part to common/ directory, and give come up with logically reasonable file names. For example, the code for accessing debug registers are duplicated in gdbserver/i386-low.c and i386-nat.c, so they can be moved to common directory with file name i386-dbg-reg.c and i386-rdbg-reg.h. See Move common macros to i386-dbg-reg.h.

2.3. Terminal handling

Parts of terminal handling are duplicated.

GDB

GDBserver

comments

gdb/terminal.h

gdb/gdbserver/terminal.h

(parts)

2.4. Event loop machinery

GDB

GDBserver

comments

gdb/event-loop.c

gdb/gdbserver/event-loop.c

2.5. Build/Configure machinery

GDB

GDBserver

comments

gdb/configure.ac, etc.

gdb/gdbserver/configure.ac, etc.

So far, we have three possible approaches to address this:

  1. Don't have its own build stuff in common/, let gdb or gdbserver pick the pieces they want, and duplicate the necessary autoconf checks, etc.. This is the status quo.
  2. Make common/ have its own configure. In March 2011, Yao gave a try to build common/ as a library (libcommon.a), for both GDB and GDBserver to link. See the thread here. The patches went into CVS, but were later reverted, because of various issues they caused.

  3. Create Makefile fragments and m4 files in common/, then sourced by gdb and gdbserver's build machineries. No new configure. This is the direction we're heading towards now. See this thread (RFC: introduce common.m4).

3. Guidelines

3.1. File Naming


OngoingWork LocalRemoteFeatureParity

All content (C) 2008 Free Software Foundation. For terms of use, redistribution, and modification, please see the WikiLicense page.