0

POSSIBLE DUPLICATE HERE

What differs is that the answers there don't have much to do with the problem.

Classic print-statements don't show up during remote debugging of raspberry pi until termination of the program. Tested with std::out and printf(). After crossing return 0; all statements get printed at once. Running VScode insiders 1.60.0 on a Win10 machine, ssh-connection to raspberry pi 4

my launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "preLaunchTask": "cmake",
            "type": "gdb",
            "request": "launch",
            "target": "./build/${workspaceFolderBasename}",
            "cwd": "${workspaceRoot}",
            "externalConsole": true,
            "valuesFormatting": "parseText"
        }
    ]
}

my tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558&WT.mc_id=iot-0000-dglover
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "cmake",
            "type": "shell",
            "options": {
                "cwd": "${workspaceRoot}/build"
            },
            "command": "cmake",
            "args": [
                "--build",
                "${workspaceRoot}/build",
                "--config",
                "Debug",
                "--target",
                "all",
                "--",
                "-j",
                "6"
            ]
        }
    ]
}

example to reproduce:

#include <iostream>
#include <stdio.h>

int main(int, char**) {
    std::cout << "Hello, world!\n";
    std::cout << "Test!\n";
    printf("now in C\n");

    for(int i = 0; i < 10; i++){

        std::cout << i;

    }

    return 0;
}

Output at breakpoint:

Running executable

Breakpoint 1, main () at /home/pi/Workspace/learn_cpp/programs_jakob/main.cpp:11
11          std::cout << i;

Output after exit:

Running executable
Hello, world!
Test!
now in C
0123456789
[Inferior 1 (process 6916) exited normally]

Any suggestions?

1. EDIT:

Suggested by @molbdnilo, explicitly flushing works:

#include <iostream>
#include <stdio.h>

int main(int, char**) {
    std::cout << "Hello, world!\n";
    std::cout << "Test!\n";
    printf("now in C\n");
    std::cout.flush();

    for(int i = 0; i < 10; i++){ //breakpoint

        std::cout << i;
    }
    return 0;
}

Output:

Running executable
Hello, world!
Test!
now in C

Breakpoint 1, main () at /home/pi/Workspace/learn_cpp/programs_jakob/main.cpp:10
10      for(int i = 0; i < 10; i++){
4
  • Have you tried explicitly flushing standard output? Commented Sep 2, 2021 at 13:50
  • @molbdnilo just tried and edited the post. It works, thank you. Still, why could this be necessary? Especially with cout i thought this was done automatically... Commented Sep 2, 2021 at 13:56
  • If memory serves, POSIX says that if standard output is a tty, it is flushed on a newline. But it's probably not a tty when you're remote-debugging. Commented Sep 2, 2021 at 14:00
  • @molbdnilo is there any way to either access the written to tty or to map the output to the (i suppose) local terminal? Commented Sep 2, 2021 at 14:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.