pydev debug python program started by another program - pydev

I have a C++ program that starts two instances of a python program in separate processes. I have a problem in the python program which causes it to not to display any logging information. The python program instances communicate with the C++ program via Stdin and Stdout/Stderr. I want to, if possible, to run one instance of the program under the Pydev debugger since the C++ program is complaining about receiving invalid input from both of the python programs. The python program can do nothing without communication to the C++ program so running the python program in isolation does not help.
Because Stdin and Stdout are used for inter-process communication so I cannot use print() statements but must use python logging but the program seems to be crashing before anything can reach the log file. The python program was working before my last changes so the architecture is functioning OK.
Any suggestions?

My suggestion for debugging the Python program launched from the C++ program would be using the remote debugger feature:
http://www.pydev.org/manual_adv_remote_debugger.html
(that way you can add programatically start the debugger on the python code wherever you'd like without needing to do anything special to launch it).

Related

Decorate VSCode (jupyter) interactive window with (python) process-id

I often debug a python interactive session that calls external C#, C++ or CUDA code by attaching an external debugger to the python process. I always type os.getpid(), but in trying to save a few keystrokes, I wonder if there is a way to decorate the interactive window in VS Code with the pid? E.g. ref. the attached screenshot, add it somewhere/somehow to the other meta-info?

GDB input redirection not working on Mac OS High Sierra 10.13.3

I'm using GDB 8.0.1 on Mac OS High Sierra 10.13.3. Basically, doing:
(gdb) r < some_input_file.in
ignores the input file. It acts as if the command ran was simply
(gdb) r
The closest thread I found about this problem was Input redirection from file gdb but no solution was posted.
Any clues?
Thanks!
You are probably running into an interaction between gdb and macOS SIP ("System Integrity Protection").
gdb implements run redirections by passing the command line to the shell; then it waits for the shell to invoke your program before starting to "really debug". The shell is actually still controlled by gdb using ptrace -- gdb uses this to observe the eventual exec and to ensure that your process is also traced.
However, SIP prevents certain programs from being traced, and in particular programs in /usr/bin, like most shells. This causes run to stop working entirely, because the shell can't be started.
So, to make gdb continue to work, users often set startup-with-shell off. Perhaps whatever gdb build you are using does this by default (or maybe, like me, you put this in your .gdbinit and forgot about it). This setting lets run work -- but at the cost of disabling redirections.
There's a gdb bug for this which you can follow.

eclipse: how to debug a Scala program called from a shell script

I have a Scala program that is triggered from a shell script. I'd like to be able to run the program in eclipse in debug mode. Anybody knows how that can be done?
Thanks.
I'm not sure if there is a way to debug both together, but what you can do is run your script with the option -xv. So...
user#mypc$: bash -xv myscript other_args
That will show you the commands that are executed along with their parameters.
Then in Eclipse you can debug your Scala program normally and pass those parameters to it through the main method or run configuration.
Typically debuggers are language specific and won't be able to do both bash scripts and code in another language, but with this method, you should be able to figure out what's going on.

How to debug a tcl script which is argument to an executable?

I have a application which takes tcl script as argument. I want to debug tcl script when the application processes it.
My development environment consists of Dynamic Languages Toolkit along with Active state remote debugger -dbgp_tcldebug. I am able to debug the individual tcl scripts with this setup.
I created a tcl project in eclipse and added 'startup.tcl' and 'argumentScript.tcl' scripts and added following command to the startup script,
set ExecutableName "xyz.exe"
set returnValue [catch {eval exec $ExecutableName "argumentScript.tcl" } result]
My debugger works fine with 'startup.tcl' script. I added the breakpoint in 'argumentScript.tcl' but it is not working. How can I debug the "argumentScript.tcl" script ?
Edit: A solution without using eclipse environment is Tcl Dev Kit with remote debugging feature.
you could use tcls introspective abilities to have the script debug itself e.g. using trace
puts f "debug message" is our all!
Just dump all that you need in log file. Simple, Stupid and Robust :)

Is it possible for Eclipse to terminate gently instead of using SIGKILL?

I'm using Eclipse on Windows, with the PyDev plugin for Python development. When I use 'Run' to start my application, it spawns a new Python (CPython) instance. When I use the 'terminate' button (red square), it kills the process. However, it appears to do a SIGKILL, so my shutdown handler is unable to clean up.
Is there any way to get Eclipse to send a SIGTERM, or simulate a keyboard interrupt (ctrl-c) from the Eclipse console?
Note: I'm aware there are other Python IDEs like Komodo or Wing that might solve this problem, but I'm not looking to switch over this.
Eclipse uses the Java Process API which sends the signal. This is a native API and there is no way to change that. I assume that you've tried to install a handler for SIGKILL, too, and that didn't work.
Therefore, the only solution would be to write a small batch file which lists the processes and sends SIGTERM to one of them. Invoke that from a command prompt. If you use Alt-Tab to switch to it, it's almost as comfortable as doing it from inside Eclipse.
Or write a plugin to invoke batch files.
I looked at How can a Java program get its own process ID? and came up with this.
System.out.println("kill -SIGINT "+ProcessHandle.current().pid());
I realize this isn't ideal if you don't want it printing this out for production but if you're just prototyping it's handy. Or you could put it inside an if that only runs if you're debugging.