Last active
August 29, 2015 14:22
-
-
Save lisovy/22e12a80e867688ccffa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Program flow tracing (with source modification) | |
=============================================== | |
* assert() | |
Instead of | |
if (variable < 0) | |
printf(...); | |
else | |
printf(...); | |
use | |
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() | |
http://man7.org/linux/man-pages/man3/backtrace.3.html | |
http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes | |
Linux kernel: dump_stack | |
* Determine exact source of function error return code | |
int fce(void) { | |
... | |
if (...) | |
return -EINVAL; | |
if (...) | |
... | |
else | |
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 | |
^] | |
^t | |
* 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