Debugging 101 Video Edition

 

A couple years ago I did a detailed text tutorial on how to use a debugger which oddly is a massively important skill that simply isn’t taught.  Given that this article is still popular two years later I’ve decided to follow it up with a video version.  This video, Debugging 101, walks through the basic tasks involved in debugging.  It used Visual Studio 2017 and C++ but should be applicable in most languages and IDEs.  The video shows how breakpoints and conditional break points work, how to step into, over and out of your code, how to use the local and watch window, call stacks, how to do memory debugging and more.  Basically the video shows you how to get started using a debugger.

 

The following is the code used in this example.  There is nothing special to this code, it’s extremely contrived, but it enabled me to show the various features available in most debuggers.

#include <iostream>    // These two functions are used to illustrate how the call stack works  // As well as how step into and step out of behave.  int innerFunction(int input) {  	int meaninglessCounter = 0;  	for (int i = input; i > 0; i--) {  		// First show stepping through the loop  		// Set a conditional breakpoint that breaks when i is a certain value.  		meaninglessCounter++;  	}  	return input;  }    int outerFunction() {  	int i = 42;  	return innerFunction(i);  }      class Demo {  	std::string stringValue;  	int intValue;  	bool booleanValue;    	public:   		Demo(std::string a, int b, bool c) : stringValue(a), intValue(b), booleanValue(  		c) {};  };    int main(int argc, char ** argv) {  	// Callstack demo, jump into, jump over example  	int someVal = 0;  	someVal = outerFunction();    	// Data example -- simply create a char buffer, fill it with 'a' then null   	terminate it so   	// it can be treated like a string.  	char * data = new char[1000];  	for (int i = 0; i < 1000; i++)  		data[i] = 'a';  	data[999] = 0;  	std::cout << data << std::endl;    	//set a watch on d.  Demonstrates watches and drilling into complex object  	Demo d("Hello", 42, true);  	  	std::cout << "End of demo" << std::endl;  	delete[] data;  	// delete[] data;  Calling delete again will trigger an exception  }  

Programming Applications


Scroll to Top