Attaching to remote Linux applications with VisualGDB

This tutorial shows how to attach to and debug a remote Linux process without creating a project in Visual Studio. We will download the sources of Midnight Commander to a Linux machine and build it there.

  1. Please install VisualGDB 3.0 or newer on your Windows machine.
  2. On your Linux machine get the source code of Midnight Commander by running the following commands from your home directory:
    sudo apt-get build-dep mc
    apt-get source mc

    01-getsource

  3. When the source code is downloaded, go to the newly created directory and configure Midnight Commander with default settings:
    cd mc-<VERSION>
    ./configure

    02-configure

  4. Build the program with make.
    make

    03-build

  5. Locate the mc executable and run it.
    find -name mc
    ./src/mc

    04-run05-running

  6. Now open Visual Studio and go to  Debug->Attach to
    Process… . Change the ‘Transport’ to VisualGDB.06-attachvgdb
  7. Then on the ‘Qualifier’ line click on the ‘Find…’ button. Choose ‘Linux application’.07-remote
  8. Choose a remote host from the list or make a new SSH connection.
  9. Press ‘OK’ on the port selection window. Now the processes on that Linux machine are listed.09-showprocesses10-processes
  10. Find mc from the list and click on ‘Attach’.11-attach
  11. VisualGDB attaches to the mc program on the Linux machine and pauses the execution.
    If attaching fails due to different user rights, then start VisualGDBBuildServer on the Linux machine as root.12-debugging
  12. Continue executing. Go to the Linux machine and trigger some dialog for a directory. Here we just press ‘F1′ on some directory. Then go back to Visual Studio and pause execution.12b-sometext
  13. If prompted by a SIGINT dialog, just press on ‘Break’.13-sigint
  14. The execution is now paused. In the call stack double click on ‘fg_message()’. 14-stopped
  15. Hover over the ‘text’, it show the text that the dialog is showing. Hence we are debugging that particular program. 15-correcttext
  16. Additionally you can move between the files by opening them via the ‘GDB Session’ tool window. Click there now. 16-allsources
  17. In this list you can find all the source files gdb knows. You can also open them and they will be auto-downloaded for local viewing. 17-sources