Debugging C/C++ code in Docker containers with VisualGDB
This tutorial shows how to debug applications running in Docker containers using Visual Studio and VisualGDB.
WARNING: this tutorial features older versions of Docker and VisualGDB. For more recent instructions, please refer to the following tutorials:
- Using Docker Containers to Manage Toolchains
- Building Projects with Toolchains from Docker Containers
Before we begin with the debugging part, we will show why the Docker containers are needed and how they work based on a simple example. Assume we have two Linux machines, one having glibc (Standard C library) version 2.13 and another one having glibc 2.14. Let’s create a very simple C program using the memcpy() function:
#include <stdio.h> #include <memory.h> void CopyMemory(volatile void *pDest, volatile void *pSrc, volatile int size) { memcpy((void *)pDest, (void *)pSrc, (int)size); } int main() { char str1[256] = "Hello", str2[sizeof(str1)]; CopyMemory(str2, str1, sizeof(str2)); puts(str2); return 0; } |
If we compile and run it on the machine with glibc 2.14, it will run properly:
