【整理】Linux 下 自己使用的 debug宏 printf
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了【整理】Linux 下 自己使用的 debug宏 printf,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3848字,纯文字阅读大概需要6分钟。
内容图文
![【整理】Linux 下 自己使用的 debug宏 printf](/upload/InfoBanner/zyjiaocheng/975/ea1963cf686945c0bfb89f175b27340b.jpg)
![【整理】Linux 下 自己使用的 debug宏 printf - 文章图片](/upload/getfiles/0001/2021/5/13/20210513052753664.jpg)
![【整理】Linux 下 自己使用的 debug宏 printf - 文章图片](/upload/getfiles/0001/2021/5/13/20210513052753711.jpg)
#ifdef __DEBUG_PRINTF__ /* * * Some Debug printf kit for devlopment * * Date : 2019.03.04 * * Editor : SCHIPS * */ #include <stdio.h> /* Debug with file name and line. */ #define DEBUG(format,...) printf(""format"\n", ##__VA_ARGS__ ) #define DEBUG_RED(format,...) printf("\033[30m\033[31m"format"\033[0m\n", ##__VA_ARGS__) #define DEBUG_GREEN(format,...) printf("\033[30m\033[32m"format"\033[0m\n", ##__VA_ARGS__) #define DEBUG_YELLOW(format,...) printf("\033[30m\033[33m"format"\033[0m\n", ##__VA_ARGS__) #define DEBUG_PURP(format,...) printf("\033[30m\033[35m"format"\033[0m\n", ##__VA_ARGS__) #define DEBUG_BLUE(format,...) printf("\033[30m\033[36m"format"\033[0m\n", ##__VA_ARGS__) /* Debug printf infomration with color. */ #define DEBUG_FL(format,...) printf("["__FILE__"](%05d) - %s]\n "format"\n", __LINE__, ##__VA_ARGS__ , __FUNCTION__) #define DEBUG_FLR(format,...) printf("\033[30m\033[31m["__FILE__"](%05d) - %s]\n\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define DEBUG_FLG(format,...) printf("\033[30m\033[32m["__FILE__"](%05d) - %s]\n\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define DEBUG_FLY(format,...) printf("\033[30m\033[33m["__FILE__"](%05d) - %s]\n\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define DEBUG_FLP(format,...) printf("\033[30m\033[35m["__FILE__"](%05d) - %s]\n\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define DEBUG_FLB(format,...) printf("\033[30m\033[36m["__FILE__"](%05d) - %s]\n\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define DEBUG_SFL(format,...) printf("["__FILE__"](%05d) - %s] "format"\n", __LINE__, ##__VA_ARGS__ , __FUNCTION__) #define DEBUG_SFLR(format,...) printf("\033[30m\033[31m["__FILE__"](%05d) - %s]\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define DEBUG_SFLG(format,...) printf("\033[30m\033[32m["__FILE__"](%05d) - %s]\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define DEBUG_SFLY(format,...) printf("\033[30m\033[33m["__FILE__"](%05d) - %s]\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define DEBUG_SFLP(format,...) printf("\033[30m\033[35m["__FILE__"](%05d) - %s]\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define DEBUG_SFLB(format,...) printf("\033[30m\033[36m["__FILE__"](%05d) - %s]\033[0m "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__) #define SC_CLEAR() printf("\033[2J") #if 0 /* Another format to Print (Too ugly to me to use.)*/ #define DEBUGA(fmt,args...) printf("[%s(%05d) - %s]\n "#fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##args) #endif #else #define DEBUG(format,...) #define DEBUG_RED(format,...) #define DEBUG_GREEN(format,...) #define DEBUG_YELLOW(format,...) #define DEBUG_PURP(format,...) #define DEBUG_BLUE(format,...) #define DEBUG_FL(format,...) #define DEBUG_FLR(format,...) #define DEBUG_FLG(format,...) #define DEBUG_FLY(format,...) #define DEBUG_FLP(format,...) #define DEBUG_FLB(format,...) #define DEBUG_SFL(format,...) #define DEBUG_SFLR(format,...) #define DEBUG_SFLG(format,...) #define DEBUG_SFLY(format,...) #define DEBUG_SFLP(format,...) #define DEBUG_SFLB(format,...) #define SC_CLEAR(format,...) #endifdebug.h
![【整理】Linux 下 自己使用的 debug宏 printf - 文章图片](/upload/getfiles/0001/2021/5/13/20210513052753664.jpg)
![【整理】Linux 下 自己使用的 debug宏 printf - 文章图片](/upload/getfiles/0001/2021/5/13/20210513052753711.jpg)
#include <stdio.h> #if 1 // To turn on/off Debug printf; #define __DEBUG_PRINTF__ #endif #include "debug.h" void fun1(void) { DEBUG("DEBUG"); DEBUG_RED("RED."); DEBUG_GREEN("GREEN."); DEBUG_YELLOW("YELLOW."); return ; } void fun2(char* buff) { int i = 0; DEBUG_FL("fun2"); DEBUG_FLB("i = %d", i); DEBUG_FLR("buff = %s", buff); DEBUG_FLP("buff = %s", buff); return ; } void fun3(char* buff, int i) { DEBUG_SFL("fun3"); DEBUG_SFLB("i = %d", i); DEBUG_SFLR("buff = %s", buff); DEBUG_SFLP("buff = %s", buff); return ; } int main(void) { SC_CLEAR(); fun1(); printf("---------\n"); fun2("fun 2"); printf("---------\n"); fun3("fun3",3); return 0; }demo_main.c
内容总结
以上是互联网集市为您收集整理的【整理】Linux 下 自己使用的 debug宏 printf全部内容,希望文章能够帮你解决【整理】Linux 下 自己使用的 debug宏 printf所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。