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. Use the latest available black version.

If you notice formatting changes unrelated to your changes, then first submit or push an obvious patch that reformats the code using the latest black version. According to their stability policy, all versions of a given calendar year will produce the same output. So we can expect some small changes when they release a version after the new year. The spurious changes can also be because someone forgot to run black in a previous patch.

You can install black in 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/  # You can skip this to re-use an existing virtual environment
$ source env/bin/activate
(env) $ pip install --upgrade black

All you need to do then 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:

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

from the top-level.

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.