Debugging programs built with Linux cross-compilers

This tutorial shows how to develop and debug applications built with a cross-compiler on one Linux machine and then deployed to another one.

We will show how to configure VisualGDB to build a simple Raspberry Pi application on an x86 Linux machine, deploy it to Raspberry Pi and debug it there. Before you begin, install VisualGDB and ensure that your x86 Linux machine has the arm-linux-ghueabihf cross-compiler and a matching gdb.

  1. Start Visual Studio and open the VisualGDB Linux Project Wizard:01-prjname
  2. Proceed with the default “Create a new project -> Application” setting:02-prjtype
  3. On the next page select “Build the project under Linux over network” and select the x86 computer with the cross-toolchain. Then select “Specify toolchain manually by locating gdb”:03-toolchain
  4. VisualGDB will ask for the location of the gdb. Find it and click “Open”. In this example the gdb binary is called arm-linux-gnueabihf-gdb and is located in /usr/bin:04-gdb
  5. Enable the “Deploy” the project to another Linux computer checkbox and select your Raspberry Pi in the “Deployment computer” field:deploy
  6. On the next page select where should VisualGDB store your source files on the Linux machine. The easiest way is to proceed with the default settings and let VisualGDB manage the source file locations:06-src
  7. Press “Finish” to generate your project. VisualGDB will automatically detect the include directories used by the cross-toolchain and cache them on the Windows machine to setup IntelilSense:07-includes
  8. Now we will slightly modify the project to actually print the hostname of the machine where it is running. Replace the contents of the main file with the following:

    Then press F5 to build your project and start debugging it:08-debugYou will see that the project is built, deployed and the hostname matches the name of the deployment machine.
  9. Sometimes the build machine cannot connect to the deployment machine because it cannot resolve the host name or it needs to use a different IP address. You can override this by opening VisualGDB Project Properties on the Debug Settings page and switching the target selection command to “target remote <IP>:<port>”. Ensure you set the “debugging start mode” to “Use ‘continue’ command”:09-target
  10. You can double-check the command that VisualGDB uses to connect to the target by switching the GDB Session window to the “All GDB interaction” or “Raw output from GDB” mode and then searching for “target”:10-cmd