Member-only story
C: Trace And Debug
4 min readJun 14, 2019
Set-up to facilitate for tracing and debugging
Create Tracing Helper Functions
Instead of commenting them:
and manually tracing them later:
Create tracer functions and tag switches to enable the ease to conduct selective testing and debug regions.
Create Timer Helper Functions
Having a timer to check the timing of the specific code portions will also be helpful.
GDB (GNU Project Debugger)
Let’s use an buffer overflow example as an observatory:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>int main(int argc, char** argv) {
volatile int cantoverflowme;
char buffer[64];
cantoverflowme = 0; gets(buffer);if (cantoverflowme != 0) {
printf("You OVERFLOW'ed Me\n");
} else {
printf("Can't Overflow Me\n");
}
}
/*
# compile
gcc overflow.c -o overflow -fno-stack-protector -z execstack -no-pie-z execstack : Disables Executable Stack
-fno-stack-protector : Disables Stack Canaries
-no-pie : Disables Position…