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.
- Please install VisualGDB 3.0 or newer on your Windows machine.
- 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
- When the source code is downloaded, go to the newly created directory and configure Midnight Commander with default settings:
cd mc-<VERSION> ./configure
- Build the program with make.
- Locate the mc executable and run it.
find -name mc ./src/mc
- Now open Visual Studio and go to Debug->Attach to
Process… . Change the ‘Transport’ to VisualGDB.
- Then on the ‘Qualifier’ line click on the ‘Find…’ button. Choose ‘Linux application’.
- Choose a remote host from the list or make a new SSH connection.
- Press ‘OK’ on the port selection window. Now the processes on that Linux machine are listed.
- Find mc from the list and click on ‘Attach’.
- 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.
- 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.
- If prompted by a SIGINT dialog, just press on ‘Break’.
- The execution is now paused. In the call stack double click on ‘fg_message()’.
- Hover over the ‘text’, it show the text that the dialog is showing. Hence we are debugging that particular program.
- Additionally you can move between the files by opening them via the ‘GDB Session’ tool window. Click there now.
- 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.