I have a C++ project and a python script that calls .exe file. I set breakpoints in one of cpp files, but they are not hit. I can't even go into this C++ project.
I found similar question here, but for Visual Studio:
Debug C++ code in visual studio from python code running in eclipse
Is there a similar way to do this trick in Eclipse?
Or is there some other approriate way to debug C++ code, which is called from another process? I tried to attach to the process, but the problem is that, after script makes call, child process finishes very fast and I can't catch its pid.
To debug the executable, use the DebugBreak function in place of a breakpoint in your program. So in your C++ code, call DebugBreak somewhere in your program, preferably near the beginning -- this will serve as the breakpoint.
What will happen is that when your C++ executable runs from Python, your C++ executable will "crash" (not really crash, but it will seem like it did). What really is happening is that the DebugBreak function was called.
After the Windows OS goes through its set of message boxes saying "your application has something wrong with it" (note that there really is nothing wrong with the program), you are then given the option to debug it. Choose the "debug" option, the debugger you want to use (which will be Visual Studio), and you should be able from that point on to single step through your C++ code.
Related
there may very well be an answer to this question, but it's really hard to google for.
you can add commands to gdb by writing them in python. I am interested in debugging one of those python scripts that's running in gdb session.
my best guess is to run gdb on gdb and execute the user added command and somehow magically break on the python program code?
has anybody done anything like this before? I don't know the mechanism by which gdb calls python code, so if it's not in the same process space as the gdb that's calling it, I don't see how I'd be able to set breakpoints in the python program.
or do I somehow get pdb to run in gdb? I guess I can put pdb.set_trace() in the python program, but here's the extra catch: I'd like to be able to do all this from vscode.
so I guess my question is: what order of what things do I need to run to be able to vscode debug a python script that was initiated by gdb?
anybody have any idea?
thanks.
so I figured it out. it's kinda neat.
you run gdb to debug your program as normal, then in another window you attach to a running python program.
in this case the running python program is the gdb process.
once you attach, you can set breakpoints in the python program, and then when you run commands in the first window where the gdb session is, if it hits a breakpoint in the python code, it will pop up in the second window.
the tipoff was that when you run gdb there does not appear to be any other python process that's a child of gdb or related anywhere, so I figured gdb must dynamically link to some python library so that the python compiler/interpreter must be running in the gdb process space, so I figured I'd try attaching to that, and it worked.
I just started to code on Python, so I downloaded the "Python 3.10 (64-bit)". The problem is that it runs the code without my permission. For example, if I am trying to type in print("example") it just runs on it's own. This means I can't do an actual coding project, it just runs the 1 piece of code right after I hit the Enter button. I don't know if I'm just blind or it's obvious, but I can't figure it out. What do I do?
Hitting enter after you type is "giving permission" to run the code that is typed (or copied)...
You can still write "scripts" this way - you define variables, functions, classes, etc, and they remain in scope of the interactive session.
If you want to "code a project," though, you should use an external IDE such as Visual Studio Code, PyCharm, Spyder, etc. The built-in IDLE is very basic, but still does allow for file execution.
Where do you write your code?
If you are using the command line, you cannot do anything to change this; you have to use a file with the extension ".py", for example "first_file.py", and write the code inside that file. When you are done or when you want to test your code, you have to open the terminal in the file folder and type python [filename].py and after that, your code will be compiled and executed in the terminal. I recommend using a code-writing program like VS Code, Atom or something like that.
I'm getting an interesting problem and I can't determine whether it's a problem with my code or the executable that I'm running. Basically I have a Python program that needs to call an external executable to process some data. If I call the executable via PowerShell or cmd, it works fine. However, if I attempt to run the executable via os.system() or subprocess.run(), I get the following error:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
From my understanding of googling the issue, it would appear that this is some sort of C++-related issue, which is the language of the .exe that I'm running. I reinstalled the latest Visual C++ Redist and that did not seem to affect the problem. I've also tried to create a .bat and .ps1 script that runs the .exe. These both run fine via PowerShell and CMD, but raise the same error when run via os.system() and subprocess.run(). The error message is rather nondescript so I'm wondering if anyone knows anything about it and why os.system() etc. might be throwing it.
The relevant code is simply
os.system("GaussBin.exe gaussInput.txt gaussOutput.txt")
When the string is pasted into cmd, it runs perfectly. Additionally, if the parameters of the system() call are incorrect, the exe properly displays the usage function. It's only when I add the output.txt and the program is supposed to run fully that things start to break.
I've had some confusion about what directory os.system runs in. Should I be using .\ when calling the exe?
The .exe file is provided, not built by me.
I need something similar to "-i" option of original Python interpreter, but to be able to watch variables state, use code completion and other nice IDE features as well.
I've installed appropriate Python extension for Visual Studio Code, but so far by pressing F5 it just runs module once and exit without letting me do anything, pretty much in the same way as C/C++ Visual Studio debugger work. I can use break points, but I want to use power of Python interactive mode.
There is stopOnEntry which starts the debugger when the program stops, but there's no equivalent stopOnExit. If you would like that then please file a feature request at https://github.com/microsoft/vscode-python.
I have integrated PTVS into Visual studio so that i can have intellisense support and debugging capability.
I set Breakpoints at Function definitions, but when i debug the control goes directly out of function. And in some points the Console window pops up and it never iterates to the next line of code.
I liked PTVS but this thing has stuck me up.
In options->Python tools-> Interpreter options i have set it as Python 2.7
Can Anyone tell me whats wrong with the options and why that console screen is appearing.
Thanks in advance.
When you say you're setting breakpoint at function definitions do you mean on the line with the "def ..." or are you setting the breakpoint on the 1st statement of the function?
In Python functions are executable statements so if you're putting the breakpoint on the def line then you're going to hit the breakpoint when the function is being defined rather than being executed.
As far as the console window it will generally open unless you mark your app as a Windows application in project properties (this will launch pythonw.exe which doesn't include a console window).
If that doesn't help you might want to post the code you're having trouble with or a screenshot of the code with where the breakpoints are set.