[yocto] Debugging custom python code in recipes

Alan Martinović alan.martinovic at gmail.com
Fri Nov 1 13:44:53 PDT 2019


Hey,
there was a question today about options for debugging python scripts in yocto.
I've patched up this PoC for remote debugging.

If someone finds it useful (it should be copy-pastable), feel free to
ping me back.
Am opet to shaping it into a friendlier format and discover potential issues.


```
# epdb is a python debugger which has a capability of attaching to breakpoints
# on running daemons. Install it on the host.
pip3 install epdb

git clone -b zeus git://git.yoctoproject.org/poky.git
cd poky

# Create a example .inc file in a random location
cat > meta/recipes-core/images/python-debug-example.inc << "EOF"
python () {

    # Import the epdb installed on the host
    import epdb
    random_action = 3

    # Set the breakpoint.
    # This will stop the program and open a channel to connect to the
interactive debugger
    epdb.serve()
    some_other_action = 5
    another_action = 6
}
EOF


# Add the .inc file to an arbitrary image
# Triggering the image build, the python code will be executed
# and the breakpoint reached
cat >> meta/recipes-core/images/core-image-minimal.bb << EOF
require python-debug-example.inc
EOF

source oe-init-build-env
# This will block because of the breakpoint
bitbake core-image-minimal

# Open a new terminal and connect to the debugger
python3 -c "import epdb; epdb.connect()"

# You should see something like...
# (Epdb) l
#  5         random_action = 3
#  6
#  7         # Set the breakpoint.
#  8         # This will stop the program and open a channel to
connect to the interactive debugger
#  9         epdb.serve()
# 10  ->     some_other_action = 5
# 11         another_action = 6
# 12     }
#[EOF]

# ... which is the interactive python debugger
```

Be Well,
Alan


More information about the yocto mailing list