Extending GDB with Python - Lisa Roach

preview_player
Показать описание

Description
GDB is powerful, and can be extended with Python to do more than just one-off debugging. This talk will describe using Python with GDB to with GDB to write tools that interact with running processes, highlighting GDB’s ability to call C functions and how this can be coupled with Python’s C-API to inject code without needing to stop the process.

Abstract
The first half of the talk will be introductory in nature. I will talk about GDB and some of the specifics of how it can be extended with Python. The second half of the talk I will use the things discussed to create a program that does simple memory analysis of all objects in a running Python process.

Introduction- who I am, what this talk is about (1 min)
GDB Introduction (3 min) a. What it is typically used for- debugging segfaults, etc b. How it works- ptrace under the hood c. Can execute C code (this will be important later in the talk) d. Source files (also important later in the talk)
Problem Statement: I want to know what objects are taking up the most memory in my program, but I don’t want to (or more realistically, can’t) add code to my process to do the data collection. Solution: Use GDB to inject into my running process some memory analysis code (we can use open-source projects like objgraph or pympler to do the memory work for us) and get that data back without killing the debugged process. (2 min)
Launch a GDB subprocess and attach to the running process we are interested in debugging. (2 min)
In the GDB subprocess command, connect to a Python script file that GDB can use as a ‘source file’. This file will be able to import gdb and use the GDB Python API to create custom commands. (1 mins)
Two gotchas: locking the GIL, and making sure the running process has access to the memory analysis modules (2 min)
Conclusion (2 min)

About the speaker
Lisa is a Production Engineer at Facebook and a CPython Core Developer. She is passionate about Python, and has spent time using Python on networking and security teams, and now focuses on improving the language itself and enabling other users of it.

Sponsor Acknowledgement

#pybay #pybay2019 #python #python3 #gdb
Рекомендации по теме
Комментарии
Автор

Great lecture! very informative and useful.. congrats!

doronnadav
Автор

Love this topic, though not touch gdb for many years. Plus the presenter is beautiful.

linhw
join shbcf.ru