mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.46k stars 194 forks source link

Console only outputs data with `std::endl` #1061

Closed Green0wl closed 11 months ago

Green0wl commented 11 months ago

Debug adapter definition and debug configuration

Installed the adapter via mason-nvim-dap.

return function(config)
  config.adapters = {
    type = 'server',
    port = '${port}',
    executable = {
      command = vim.fn.exepath('codelldb'),
      args = { '--port', '${port}' },
    },
  }
  require('mason-nvim-dap').default_setup(config) -- don't forget this!
end

then other scripts pick it up and call it at the right moment.

cpp configuration:

dap.configurations.cpp = {
  {
    name = "Launch file",
    type = "codelldb",
    request = "launch",
    program = function()
      return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
    end,
    cwd = '${workspaceFolder}',
    stopOnEntry = false,
  },
}

Debug adapter version

1.10.0

Steps to Reproduce

  1. mkdir a; cd a; touch main.cpp; nvim main.cpp
  2. Put it in the file:
    #include <iostream>
    int main(int argc, char *argv[]) {
    int x;
    std::cout << "Type a number: ";
    std::cin >> x;
    std::cout << "Your number is: " << x;
    return 0;
    }
  3. :!g++ -g -o main main.cpp
  4. Put a breakpoint on the line std::cout << "Type a number: ";.
  5. Start the debugger by entering the path to executable Path to executable: some/path/main having plugins mfussenegger/nvim-dap and rcarriga/nvim-dap-ui.
  6. Press 2 times Step Into until it is possible to enter a variable.
  7. Go to dap-terminal, press i to be able to enter something, then enter the number 5, and press Enter, getting an error (or a warning. but everything keeps working):
    Debug adapter reported a frame at line 6 column 16, but: Cursor position outside buffer. Ensure executable is up2date and if using a source mapping ensure it is correct.
  8. Press <c-\><c-n> and Step into all the way to the end of the file.

video: https://github.com/mfussenegger/nvim-dap/assets/72041440/3f788267-d373-4c98-b6ea-9f73f14fc11d

Expected Result

I get the message Your number is: 5 when I have already gone through with the debugger the line std::cout << "Your number is: " << x;.

Actual Result

I don't get any messages after typing unless I put << std::endl; at the end.

mfussenegger commented 11 months ago

This is because of the stdout buffering mode/the terminal. It doesn't output anything until there is a newline

See https://en.cppreference.com/w/c/io/setvbuf for how to change it.

This has nothing to do with the debugger itself.