📄 debug.c
字号:
/* $Id: debug.c,v 1.8 2001/08/05 17:32:51 jm Exp $ * Debug function for debugging messages * * Dynamic hierarchial IP tunnel * Copyright (C) 1998-2000, Dynamics group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See README and COPYING for * more details. */#include <stdio.h>#include <stdarg.h>#include <stdlib.h>#include "debug.h"/* bit field operations */#define DYN_SET_BIT(bits, bit) \ (bits[((bit) & 0xff) / 32] |= (1 << ((bit) & 0x1f)))#define DYN_CLR_BIT(bits, bit) \ (bits[((bit) & 0xff) / 32] &= ~(1 << ((bit) & 0x1f)))#define DYN_BIT(bits, bit) \ (bits[((bit) & 0xff) / 32] & (1 << ((bit) & 0x1f)))extern int opt_debug;/* bit field for debug flags */static char debug_flags_set = 0;static unsigned int debug_flags[8]; /* bit field, len = 256 *//* debug */static char *default_debug = "-LBhf";static void debug_initialize(void){ int i; char *env; env = getenv("DYNAMICS_DEBUG"); if (env == NULL) env = default_debug; if (*env == '-') { /* set all bits */ for (i = 0; i < 8; i++) debug_flags[i] = (unsigned int)-1; } if (*env == '-') { for (env++; *env != '\0'; env++) { DYN_CLR_BIT(debug_flags, (unsigned char) *env); } } else { for ( ; *env != '\0'; env++) { DYN_SET_BIT(debug_flags, (unsigned char) *env); printf("Setting %c\n", *env); } } debug_flags_set = 1; if (DYN_BIT(debug_flags, 'D')) { printf("DEBUG_FLAGS["); for (i = 0; i < 8; i++) printf("%08x", debug_flags[i]); printf("]\n"); }}void debug(char flag, char *format, ...){ va_list ap; if (!opt_debug) return; if (debug_flags_set == 0) debug_initialize(); if (!DYN_BIT(debug_flags, (unsigned char)flag)) return; va_start(ap, format); vfprintf(stdout, format, ap); fflush(stdout); va_end(ap);}void nodebug(char flag, char *format, ...){}void debug_hexdump(char flag, const char *title, const unsigned char *buf, int len){ int i, left; const unsigned char *c = buf; if (!opt_debug) return; if (debug_flags_set == 0) debug_initialize(); if (!DYN_BIT(debug_flags, (unsigned char) flag)) return; printf("%s - hexdump (len=%i)\n", title, len); left = len; while (left > 0) { printf("\t"); for (i = 0; i < 16; i++) { printf("%02x ", *c++); left--; if (left == 0) break; } printf("\n"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -