jpou
jpou

Reputation: 1995

Output of Remote GDB Debugger in Visual Studio

Is it possible to have access to stdout of remote GDB session in Visual Studio? I am using Visual Studio Visual C++ for Linux Development and would like to have access to all printf'd data.

Upvotes: 4

Views: 1760

Answers (1)

svobodb
svobodb

Reputation: 46

IMHO both stdout and stderr should be passed to an Output or Debug window by the ssh/gdb pipe of MSVC but they aren't, at least in MSVC 2017, version 15.3. Hopefully Microsoft will implement this for us later.

In the meantime, a workaround can be used in gdbserver mode. Debuggee's stdout ends up somewhere in the ssh virtual terminal. It can be redirected, e.g. to /tmp/stdout by setting Debug/solution Properties/Debugging/Program Arguments to >/tmp/stdout, which can be watched in another terminal by tail -f /tmp/stdout.

Another way to see stdout is to show it in a separate window when the debugger starts, much like a new console in Win32 Console process shows up. This can be achieved through X server running on the same machine as MSVC. E.g. Xming works fine on Windows 7 (note that the remote Linux machine must be allowed in c:\Program Files (x86)\Xming\X0.hosts). X's DISPLAY environment variable on the remote Linux machine must be set to the debugging Windows machine's display, e.g. to 192.168.1.10:0. Set Debug/solution Properties/Debugging/Pre-Launch Command to export DISPLAY=192.168.1.10:0 (replace the IP address by your Windows' machine one) or let shell to fill the IP for you by export DISPLAY="`sed -e 's/ .*/:0/'<<<"$SSH_CLIENT"`". This time pipe stdout by setting Debug/solution Properties/Debugging/Program Arguments to |xless -f (xless must be installed on the remote Linux machine, e.g. by apt-get install xless).

Note that stdout is not always flushed by the debuggee with a new line when redirected, so setvbuf(stdout, NULL, _IONBF, 0) as the first call in main() will help.

It also looks like stderr is eaten by MSVC debugging pipe, so it cannot be redirected without debugging failure, but stderr=stdout in main() will help.

Upvotes: 2

Related Questions