2015年2月24日 星期二

[C] Debug function and tools

============================
shell:
grep -Inr --color "XXX" --include="*.c" . 2>/dev/null # Grep specific and just show c file

============================
vim tool:
:%! perl -pne '$random=int(rand 10000000000); s/XYZ123/$random/' # For replace XYZ123 to random number

%s/.*pattern.*//ec # For delete whole line when search specific pattern
============================
kernel Space :
#define DPRINTK(format,args…) if (debug) printk(format,##args)

printk (KERN_ERR "GOGO - Debug - dbridge_main.c - function name - XYZ123 \n");

============================
User Space :
fprintf(stderr,"GOGO - Debug - C code name - function name - XYZ123 \n");

static bool verbose = 1;
#define dbg_print(fmt, args...) do { if (verbose) fprintf(stdout, "%s " fmt, __func__, ##args); } while(0)
#define print_err(fmt, args...) do { if (verbose) fprintf(stderr, "Error: %s " fmt, __func__, ##args); } while(0)

void error(char *msg)
{
perror(msg);
exit(1);
}

Reference:

0 意見:

張貼留言