Ad esempio, v'è la fonte:Come dire a gcc di codificare il codice con chiamate alla mia funzione ogni _line_ di codice?
void my_special_debugging_function(const char* function_name, const char* file_name, int line_number);
void func1() {
func3();
func4();
}
void foo() {
func1();
if(qqq) {
func2();
};
func3();
func4();
for(...) {
func5();
}
}
Dovrebbe compilare come:
void my_special_debugging_function(const char* function_name, const char* file_name, int line_number);
void func1() {
my_special_debugging_function("func1", "prog.c", 3);
func3();
my_special_debugging_function("func1", "prog.c", 4);
func4();
my_special_debugging_function("func1", "prog.c", 5);
}
void foo() {
my_special_debugging_function("foo", "prog.c", 8);
func1();
my_special_debugging_function("foo", "prog.c", 9);
if(qqq) {
my_special_debugging_function("foo", "prog.c", 10);
func2();
my_special_debugging_function("foo", "prog.c", 11);
};
my_special_debugging_function("foo", "prog.c", 12);
func3();
my_special_debugging_function("foo", "prog.c", 13);
func4();
my_special_debugging_function("foo", "prog.c", 14);
for(...) {
my_special_debugging_function("foo", "prog.c", 15);
func5();
my_special_debugging_function("foo", "prog.c", 16);
}
my_special_debugging_function("foo", "prog.c", 17);
}
Naturalmente, my_special_debugging_function dovrebbe essere in grado di utilizzare backtrace
funzione.
C'è un'opzione di gcc per farlo? O c'è uno strumento per farlo a livello di codice sorgente? (Ad esempio generare altra souce C con la mia funzione)
@relatedHow to "interleave" C/C++ souce with my string (only inside functions at appropriate places)?
Non esattamente. Dovresti essere a conoscenza dei macro '__FILE__',' __LINE__' e '__func__', comunque. – nategoose