You can also attach gdb to a running (python) process .. but the interpreter needs to have the symbol table (eg. not stripped).

I gave a presentation few years back on this exact topic (sorry for the quality, I was very in-experienced).

I hope this helps.

PS> I'm working on a tiny "relocatable" python interpreter + toolchain using docker (sort of miniconda but for plain python) https://bitbucket.org/cav71/builder3/src/master that might be useful. 

On Mon, 30 Mar 2020 at 20:07, Rhodri James <rhodri@kynesim.co.uk> wrote:
On 30/03/2020 23:20, Leandro Müller wrote:
> Hi
> Are there any away to debug C module during python debug?

In a word, gdb.

I've been doing this quite a lot lately.  The trick is to start Python
up under gdb, set a pending breakpoint in your C module, then carry on
as normal.  For example:


rhodri@Wildebeest:~/hub_module$ gdb python3
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.

[...large amounts of boilerplate omitted for brevity...]

Reading symbols from python3...Reading symbols from
/usr/lib/debug/.build-id/28/7763e881de67a59b31b452dd0161047f7c0135.debug...done.
done.
(gdb) b Hub_new
Function "Hub_new" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (Hub_init) pending.
(gdb) run
Starting program: /home/rhodri/Work/Lego/hub_module/hat_env/bin/python3
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> from hub import hub

Breakpoint 1, Hub_new (type=0x7ffff6236340 <HubType>, args=(), kwds=0x0)
     at src/hubmodule.c:164
164         HubObject *self = (HubObject *)type->tp_alloc(type, 0);
(gdb)


...and off you go!


--
Rhodri James *-* Kynesim Ltd
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/4JVUDRD5YZVVZ4FWC3BYN3RJDXBNBTIF/
Code of Conduct: http://python.org/psf/codeofconduct/