Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Program flow tracing (with source modification)
* assert()
Instead of
if (variable < 0)
assert(variable > 0);
* __func__
Formerly gcc-specific __FUNC__, nowadays part of the C standard.
Trace program flow by adding
printf("### %s\n", __func__);
at the beginning of each relevant function.
Vim: %s/^{/{\r\l\tprintf("### %s\\n", __func__);/g
* backtrace()
Linux kernel: dump_stack
* Determine exact source of function error return code
int fce(void) {
if (...)
return -EINVAL;
if (...)
return -EINVAL;
if (...)
return -EINVAL;
Reaplace each relevant return value with __LINE__
Vim: %s/EINVAL/__LINE__/g
Program flow tracing (without source modification)
* strace
* ltrace
* gdb
Source code tracing
* Vim + ctags
apt-get install vim exuberant-ctags
find . | egrep -i "*\.c|*\.h" | ctags -L-
vim main.c
* grep/egrep
egrep -irn "tlb_write_indexed" .
./arch/mips/cpu/cpu.c:37: tlb_write_indexed();
./arch/mips/include/asm/mipsregs.h:1304:static inline void tlb_write_indexed(void)
vim ./arch/mips/cpu/cpu.c +37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment