Every time comes the debugging part with the GDB, I feel quite lost. To a novice like me, GDB is not so handy compared with debuggers in IDEs of other languages and the graphic debugger is not working. I've tried to debug load()
and indexes()
with GDB. I tried to set breakpoints at load
and run curl -i http://localhost:8080/hello.html
, but nothing happened. What exact steps do I need to take to debug? More details will be appreciated. Thanks in advance!
Snippets of my problematic code:
load()
bool load(FILE* file, BYTE** content, size_t* length)
{
// TODO
BYTE* cursor;
*content = realloc(*content, 1);
if (*content == NULL)
{
return false;
}
cursor = *content;
while (fread(cursor, 1, 1, file) == 1)
{
(*length)++;
cursor = realloc(cursor, (*length) + 1);
if (cursor == NULL)
{
return false;
}
}
return true;
}
indexes()
char* indexes(const char* path)
{
// TODO
const char* php = "index.php";
const char* html = "index.html";
char* full_path = calloc(1, sizeof(*path) + sizeof(*php));
if (full_path == NULL)
{
return NULL;
}
full_path = strcpy(full_path, path);
full_path = strcat(full_path, php);
if (access(full_path, F_OK) == 0)
{
return full_path;
}
else
{
free(full_path);
full_path = calloc(1, sizeof(*path) + sizeof(*html));
full_path = strcpy(full_path, path);
full_path = strcat(full_path, html);
if (access(full_path, F_OK) == 0)
{
return full_path;
}
}
return NULL;
}
EDIT: update the debugging pictures.