Written by Mike James | ||||||
Monday, 06 May 2024 | ||||||
Page 5 of 5
Multimodal DebuggingThis is an advanced topic and you can skip it and come back to it when you need to debug an extension – you will need to find out how run a debugger on an extension at some point. Of course, the problem is that there are two programming languages involved – Python and C. We need to use two debuggers we need multimodal debugging. The Python debugger can be invoked in the usual way when the Python program is run, but the C debugger can only be invoked when our C program is doing something. It has to be attached to the Python system running in response to starting the Python program. Of course, we can’t attach the C debugger until the Python program is running and, if we just let the Python program run, it will end before we have a chance to attach the debugger. The solution is that we have to pause the Python program while it is debugging, then start the C debugger and finally start the Python program again. We need to set up VS Code with two debugging profiles. Using the standard gdb debugger the launch.json file is: { "version": "0.2.0", You have to change "program": to be the path to the Python interpreter. The big problem is that you have to set the processId of the Python process and this isn’t something you can know or set in advance. The solution is that the pickProcess command gives you a drop-down list from which you can select the process and this is not always easy. With this launch.json the procedure to debug an extension is:
You can now use the debugger to step through the code of both programs. Initially it can be difficult to work out how to get to a particular section of the C code, but you quickly get used to it. The only frustrating part is having to repeatedly specify the process Id for the Python program. Notice that if everything is set up correctly you should be able to single-step and examine calls into the C API. Summary
Extending & Embedding Python Using CBy Mike JamesBuy from Amazon. ContentsPreface
<ASIN:B0CK3X93KF> To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Court Rejects Google's Appeal - An Epic Win 06/08/2025 Following closely on the similar decision in Epic v Apple, the United States Court of Appeals for the Ninth Circuit has rejected Google's appeal. Is this the end of the monopoly of the app stores? Python Still Growing - 2024 Developer Survey Results 20/08/2025 The results of the 2024 Python Developers Survey, conducted as a collaborative effort between the Python Software Foundation and JetBrains have been published. This was the eighth editi [ ... ] More News
Comments
or email your comment to: comments@i-programmer.info << Prev - Next |
||||||
Last Updated ( Tuesday, 07 May 2024 ) |
Extending & Embedding Python Using C - A Module Using Linux