Skip to content

Latest commit

 

History

History
101 lines (77 loc) · 4.97 KB

DevelopmentGuide.md

File metadata and controls

101 lines (77 loc) · 4.97 KB

Design

The following design abstracting the debugger was taken from libheap:

-----------------------------------------------------------------------
                       debugger frontend (commands and prettyprinters)
                                                      libptmalloc/frontend

                     +-----+
                     |     |
                     | gdb |
                     |     |
                     +--+--+
                        |
------------------------+----------------------------------------------
                        |               core logic (debugger-agnostic)
                        |                             libptmalloc/ptmalloc
                   +----+-----+
                   |          |
                   | ptmalloc |
                   |          |
                   +----+-----+
                        |
------------------------+----------------------------------------------
                        |                      debugger-dependent APIs
                        |                                libptmalloc/pydbg
   +--------------+-----+---------+-------------+
   |              |               |             |
+--+---+   +------+------+   +----+----+   +----+---+
|      |   |             |   |         |   |        |
| lldb |   | pygdbpython |   | pygdbmi |   | r2pipe |
| TODO |   |             |   |  TODO   |   |  TODO  |
|      |   |             |   |         |   |        |
+---+--+   +-------+-----+   +---+-----+   +----+---+
    |              |             |              |
    |              |             |    +---------+
    |              |             |    |
----+--------------+-------------+----+--------------------------------
    |              |             |    |      debugger-provided backend
    |              |             | +--+
    |              |    +--------+ |
 +--+---+       +--+--+ |   +------+-+
 |      |       |     | |   |        |
 | lldb |       | gdb +-+   | ptrace |
 |      |       |     |     |        |
 +------+       +-----+     +--------+
-----------------------------------------------------------------------

pyptmalloc-dev.py

The normal way to use libptmalloc is to install it in Python libraries with setup.py but during development it is easier to use pyptmalloc-dev.py that will import libptmalloc after adding the root folder in the Python path.

dev branch

The dev branch only supports Python >= 3.7. This is for commodity reasons, as detailed below and in the following post.

Python namespaces limitation

One quirk of Python namespaces and tools like gdb which allows importing Python files is that it won't reload files that have been already imported, except if you especially request it. So let's consider a scenario where you source A.py which imports B.py (using import B or from B import *), it will import B. Now you modify B.py and re-source A.py in your debugger to test your changes. Unfortunately the changes made to B.py won't be taken into account. The only solution will be to reload gdb entirely before reloading A.py.

To work around that limitation, we use importlib.reload() in the dev branch for all the imported modules. This slows down significantly reloading libptmalloc but it is still faster than reloading gdb :)

Do not use from XXX import YYY

When modifying libptmalloc's source code, it is handy to be able to re-import libptmalloc in gdb without having to restart gdb itself.

In the master branch, we use: from libptmalloc import *.

In the dev branch, we don't. We need to use importlib.reload() for all imported sub modules, hence we never use from XXX import YYY but instead always use import XXX so we can then use importlib.reload(XXX).

glibc references

The main reference to use when modifying libptmalloc is the different versions of the glibc source code from here. E.g. comparing glibc 2.25 and 2.26 shows the introduction of tcache (USE_TCACHE).

glibc recommended versions

In particular we recommend having at least the following versions:

There are important changes between 2 versions that follow each other above.