GDB Python Coding Standards

For everything that is not related to formatting (for that, see the Formatting section below), GDB follows the published Python coding standards in PEP008.

In addition, the guidelines in the Google Python Style Guide are also followed where they do not conflict with PEP008.


All Python source files under the gdb/ directory must be formatted using the tool black, version 21.4b0. This is the latest version at the time of writing, if you notice that a more recent version is available, feel free to submit a patch to format the code with the newest version available (if that causes any differences). We can then update this page to mention the new version.

A specific version can be installed using the following steps. This example uses a virtual environment to avoid polluting the home or system directories, but obviously if you Know What You Are Doing, you don't need to.

$ python3 -m virtualenv env/
$ source env/bin/activate
(env) $ pip install 'black == 21.4b0'
(env) $ black --version
black, version 21.4b0

All you need to do to re-format files is run black <file/directory>. Black will re-format any Python file it finds in there. It runs quite fast, so the simplest is to do:

$ black gdb/
All done! ✨ 🍰 ✨
87 files left unchanged.

from the top-level.

If you notice that black produces changes unrelated to your patch, it's probably because someone forgot to run it before ou. In this case, don't include unrelated hunks in your patch. Push an obvious patch fixing the formatting and rebase your work on top of that.

GDB-specific exceptions

There are a few exceptions to the published standards. They exist mainly for consistency with the C standards.

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