How to obtain .pdb debug symbols for PySide2? - python

It seems like when you build PySide2 from the source there are no debug symbols. Is there a symbol store or some location where the debug symbols can be downloaded from? I'm having crashes in my python app. I can't find anything on google.

Related

Use .pyc for entire Python distribution and apps

I have a restriction on my embedded device to only contain python main distribution and apps to be .pyc, i.e. no source code .py files. Note this has nothing to do with protecting source code or hiding IP.
The requirement comes from a security standard (fips 140-3) that wants to keep all just in time compiled code to be in binary and not in source format. Any ideas ?

Google Translate not working with Buildozer for android kivy app

Essentially I had to import not only the libraries I use, but also the dependencies inside those libraries. httpcore is a dependency used by Google Translate library.
logcat before app crashes:
module 'httpcore' has no attribute 'SyncHTTPTransport'
At first I thought it was an issue with the version of httpcore, but specifying the version that gets downloaded normally with a pycharm terminal doesn't work either. Essentially code in Google Translate crashes when using httpcore because a specific httpcore function doesn't exist which Google Translate is using...
Why is this happening? I can't even get the libraries I download to work now either.
Edit: Based on Reddit Commenter, seems like I need to add what's called "recipes" which is a template of code added inside the python code.
Seems to be templates you need to add inside the python code: https://python-for-android.readthedocs.io/en/latest/recipes/
YouTuber NeuralNine seems to have a detailed tutorial for this, I've seen other stuff he's done and he's good. I'll give it a go after work: https://www.youtube.com/watch?v=6gNpSuE01qE

Python for check debug symbols

I am trying to made multiple platform script for checking if binary has a debug symbols. I want a whole script be written in python. I am wondering to evoke commands like gdb or objdump. for this purpose. What are your suggestions for the efficient use of this tools?
For example objdump -g should return if there is any debug symbols, however it doesn't. Maybe someone know any API for python for checking debug symbols.

How to disable instant linting from [Python (parser)] in Visual Studio Code

The Python parser in Visual Studio Code 1.25.1 lints any error directly while typing.
How can I turn that off?
I would like to disable the live-parser-linting.
I do not want to completely disable linting from pep8 or pylint too.
Maybe the issue got adressed here too:
https://github.com/Microsoft/vscode-python/issues/2270
I found a setting for "List of surpressed diagnostic message" but I do not know, what to insert here (or if this is even the right place) nor do I find any documentation for the python.analysis.disabled settings on the web.
Help appreciated.
"python.analysis.disabled": [
"",
],
Is there any workaround?
[I am assuming you have the latest version of the Python extension for VS code installed as this won't have anything directly to do with VS Code 1.25.1]
If you are using the new language server from the Python extension then errors as you type do not turn off at the moment (you referenced the specific issue suggesting having a setting to turn that off).
If you're not using the new language server than the extension only runs linters on save, which would mean you have automatic saving as you type turned on and that's triggering the constant linting of your code. Tweak your settings to not automatically save and that will stop constant linting (and you can specify settings in VS Code for specific languages if you only want to change this for Python).

How to debug C extensions for Python on Windows

I have a problem with a segfault in pyodbc and would like to debug it in Windows XP x86. However, the information online seems primarily Linux-centric. What is the best way to go about this?
So I was able to successfully resolve my issue by using Visual Studio 2008. I loosely followed the steps listed here -
http://www.velocityreviews.com/forums/t329214-debugging-python-extensions.html
And some tips on workarounds here -
Compiling python modules whith DEBUG defined on MSVC
Here is my version of the steps for anyone else who may encounter this problem.
In case you haven't already, be sure to setup the Python header and libs directories in VS
a. Go to Tools > Options > Projects and Solutions > VC++ Directories. Be sure to add your include and libs path to the Include and Library files' path, respectively. (e.g. C:\Python27\include, C:\Python27\libs)
Go to your Python include folder (once again, e.g. C:\Python27\include) and edit pyconfig.h. Comment out the line # define Py_DEBUG and save. Go to your libs folder (e.g. C:\Python27\libs) and make a copy of python27.lib. Name the copy python27_d.lib.
Create a new project. Choose Win32 Project and name it the module name (in my case pyodbc. Click Next then choose DLL for Application type and check Empty Project.
In the Solution Explorer, right-click on Header Files and choose Add > Existing Item. Select all of the header files that you need. Do the same for Source Files.
Go to Project > Properties, then under Configuration Properties -
a. General - ensure that you are using the correct Character Set. For me it was Use Multi-Byte Character Set. Python 3 probably needs Use Unicode Character Set.
b. Debugging - enter the path to Python in the Command field. (e.g. C:\Python27\python.exe). Then set Attach to Yes.
c. Linker > General - change the Output File to end in .pyd instead of .dll.
Ensure that your configuration is set to Debug. Go to Build > Build Solution.
Open a cmd and cd into the directory where your pyd file was compiled. Start python from the cmd window. To attach debugger on this running python process, go back to Visual Studio and click the green play button to start debugging. You can also use Debugging -> Attach to Process... Now go back to Python and import your module. Play, test, and try to break it!
Debugging workflow with WinDbg
This workflow will create debugging information for a Release build, so you
don't have to mess with the original include and library files of Python.
Download and install Debugging Tools for Windows
Get the symbol files for your Python version and extract them. For Python
2.7.3 this would be http://www.python.org/ftp/python/2.7.3/python-2.7.3-pdb.zip.
Modify setup.py to generate debugging files. You have to add '/Zi' to
extra_compile_args and '/DEBUG' to extra_link_args. Example:
ext_modules = [Extension('pyuv', sources=['src/pyuv.c'],
extra_compile_args=['/Zi'],
extra_link_args=['/DEBUG'])
]
Build the extension as always (python setup.py ...).
Start WinDbg and specify the Symbol Search Path (Ctrl + S).
C:\Path\To\Extension_pdb
C:\Path\To\Extracted\python-2.7.3-pdb
srv*;SRV*c:\tmp*http://msdl.microsoft.com/download/symbols
The last line will download and cache required symbols for Windows modules.
Start the Python executable (Ctrl + E). You can directly execute a
script or run in interactive mode.
Skip the initial breakpoint with "Go" (F5).
If there is a Segmentation fault the execution will break and you will
see something like Access violation - code c0000005 (first chance)
in the WinDbg console.
You can get detailed exception information by typing !analyze -v
in the WinDbg console and the current stack trace with kb.
Here is an
example of such an output.
You should be able to combine this approach with pyrospade's
answer to debug with
Visual Studio if you omit his second step and build the project with
Release configuration.
A further tutorial for WinDbg could be found here.
Segfaults are especially mysterious, as there is no way to trap for them from your Python code, or even to get much stacktrace information on the C side of things. One thing that can give you at least a little more info is to use the Google breakpad C library to report a C stack trace when the segfault occurs.
You may want to try David Malcolm's tool CPyChecker which statically analyses C extensions for memory leaks and other bugs. The tool is documented here.

Categories