I have a c++ library that I can debug in Xcode.
This library is 'bridged' to python via SWIG. I have some python code running, making calls to the library. In PyCharm I can debug the python version.
I would like to debug the c++ code that is called by the python function, using the Attach to Process feature of Xcode, in order to
check that the python call is correct, and
the arguments are passed as expected.
So, I start debugging the Python code from PyCharm, stop at a breakpoint (early) in the python code, identify the Python PID using os.getpid(), then in Xcode I try to attach to that process. However I get an error:
"error: attach by pid '61889' failed -- attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries when the attached failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)"
In the console I can't see any message about why it was denied.
Any idea? Is it a setting in PyCharm? In Xcode? In the system?
My setting: Mac OS 10.15, Xcode 12.4, PyCharm 2020.1; Python 3.7
Related
I want to be able to step through C++ code that is part of a dll used by a Python script.
I have looked at https://learn.microsoft.com/en-us/visualstudio/python/debugging-mixed-mode-c-cpp-python-in-visual-studio?view=vs-2019 and I think I've implemented this correctly. However when ever I enable Enable Native code debugging the breakpoints in Python are no longer functioning and it states that no symbols are found in code.
I went to the Visual Studio Python installation and have selected Python native development tools
And the Python symbols have been installed and are present in the active environment:
On the debug tab I have tried setting the interpreter path to python_d.exe and in Debug>Options on the Symbols tab I've selected the associated symbols:
I have tried selecting multiple options in the image above with no success.
I suspect it is something simple that I'm doing wrong, any ideas? Thanks!
I faced the same problem and didn't find a solution.
If you want a workaround, try to attach your native code to the python.exe process:
Start the debugging of your python script (without native support) and wait on some breakpoint
Launch your native project in another VisualStudio instance, set needed breakpoint and then go to Debug -> Attach to process, select started python.exe process (you can find it by PID)
Continue python execution.
It worked for me. Note that you need your native code to be compiled with debug symbols as well.
Happy bug-hunting! =)
I'm developing an application with PySide2 and scikit-learn. The application works properly if I use a single thread, but if I move the sckikit-learn calculations to a worker QThread (to keep the UI responsive during the processing) I get random segmentation faults on Mac OS Catalina. The same program seems to work fine on Windows (on Mac I get a segmentation fault every other time I run the program; I ran the program at least twenty times on Windows and it never crashed). I was trying to follow the suggestions in this answer, but I can't have either gdb nor lldb to work properly on Catalina.
This is what I get with lldb:
% lldb python
(lldb) target create "python"
Current executable set to 'python' (x86_64).
(lldb) run test.py
error: process exited with status -1 (attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries when the attached failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.))
I then tried to install gdb with MacPorts, then I followed the instructions from the GDB Wiki to allow gdb to debug another process, however gdb either hangs after the run command or gives me an Unknown signal error while running a simple script (just print a string):
% ggdb python
GNU gdb (GDB) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin19.5.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python...
(No debugging symbols found in python)
(gdb) run test.py
Starting program: /usr/bin/python test.py
[New Thread 0x2603 of process 92261]
[New Thread 0x1803 of process 92261]
During startup program terminated with signal ?, Unknown signal.
Is there a way to debug Python segmentation faults on Catalina?
SIP (System Integrity Protection) on macOS prohibits the debugger from attaching to system applications, including the shipping version of Python. That's what you are seeing.
You either need to turn off SIP or build your own version of the Python. OTOH, debugging your problem in Python will be a lot easier if you are debugging a -O0 built Python, so figuring out how to build it yourself (it's actually not that hard to do) its likely to be worthwhile in the long term.
I am trying to write Python3 code with Gtk3, in SLES11 linux machine
I get this error:
D-Bus library appears to be incorrectly set up; failed to read machine
uuid: Failed to open "/etc/machine-id"
the /etc/machine-id not present in my machine, but I can't have permissions to generate that using "dbus-uuidgen"
Is there any option to override that in the python code itself or in some env variable ?
Thanks
Oren
No, having /etc/machine-id set is a requirement of D-Bus being installed. It looks like D-Bus was not installed correctly. You should be able to run dbus-uuidgen --ensure as root (or using sudo). If you don’t have root access, you cannot fix this situation and you should get in touch with your system administrator.
I have created an exe using Pyinstaller with python virtualenv, I am able to do this in the normal python environment without any problems, however when creating it on a virtual server the exe once created fails to execute (open).
I have created the exe with the following debug options,
Scripts\pyinstaller --debug=all --log-level=DEBUG
There is nothing in the log that indicates any specific error.
However when I try to open the exe, In the Tracing process while clicking through the different windows, the following message pops up:
'
[49852]: LOADER: Error activating the context: ActivateActCtx:
An Attempt to set the process default activation context failed because the process default activation context as already set.
It allows you to click "OK" through the rest of the messages and then:
I have tried to trace and debug and find the error, however I have not had much success, there are no missing modules or errors in the log.
I am using Python 3.7.4
Any help would be appreciated.
I'm currently trying to debug issues in Caffe for Windows PyCaffe.
Because of a bug in Python Tools for Visual Studio, PTVS doesn't work so I'm using PyCharm and trying to attach to PyCaffe's process through Visual Studio 2013. That is, I'm running PyCharm debugger on a Python script with a breakpoint set at the point where I call the Python entry point into PyCaffe.
I debug the Python script in PyCharm which calls modules written in C++ in VS. I want to debug those modules in C++. So I'm trying to attach to the PyCharm or Python processes with breakpoints set in VS.
The problem is that the breakpoint isn't firing at the entry point in PyCaffe in the Visual Studio C++ code.
Has anyone successfully gotten this kind of thing to work or is there an alternative way of doing this?
I faced a similar problem a few years ago, trying to
debug a user-mode driver wish was loading automatically from a RPC, the solution I found was:
Download Debugging Tool for Windows (depending on your system x86 or x64), wish is free,from the Microsoft Download.
Add "__asm int 3"(this is asm instruction for a hardware breakpoint) in the place on the C code where you whant to the break point to take effect.
Compile the C program, nomally with debug info (this part is important,because help the Debugger to find the source file), this should not make any problems.
Attach the Debugger to the running process (in my case was the explorer process), in your case should be the process that make first call to the library, for example if PyCharm create a process for the new python code, the debugger need to be attached to that process(you can manage this by setting a breakpoint in python, wish will give you time for doing the attach process), the easy way for me to figure this out was to let the process crash, because "__asm int 3" cause a process crash if a debugger is not attach, you can take advantage of this waiting for the crash and when windows shows you the screen "Process ... has detected a problem an need to be closed", you know who is the process that you are looking for.
This could be painful the first time but for me quite effective, because you
can see the data flow from one program to another,
We attach to one process and allow to set breakpoints within code that has not started from the VS debugger. But one important issue is that we often debug/run the app in the VS, for example, we debug the Web code that runs under IIS, we will attach to the IIS process or others.
Your project is different from the above sample, you run/debug your app in Pycharm (not the VS), but you want use the VS Attach to process function, so it would have a limitation. As you said that you debug script in PyCharm, and want to call C++, so you would check that whether the PyCharm supports a similar feature like the attach tool in VS.