r04 Debugging
r04 Debugging
THE
REAL WORLD
15-441: Recitation 4
Outline
What can go wrong?
How can we avoid errors?
What tools are available to debug errors?
Valgrind
GDB
What can go wrong?
Project 1: IRC server, what are our components?
managing connections (e.g., sockets)
handling clients (e.g., client pool)
handling data (e.g., buffers and strings manipulation)
IRC protocol (e.g., RFC … JOIN, PART, MSG)
#include <stdlib.h>
void f(void) {
int* x = malloc(10 * sizeof(int));
x[10] = 0;
} 1. Invalid memory access
int main(void) {
2. Memory never free()’d
f();
return 0;
}
Running Example in Valgrind
Running valgrind with the program:
valgrind --leak-check=yes myprog arg1 arg2
Questions on project 1?
IRC protocol, sockets, client pool, buffers…