فهرست منبع

Merge branch 'debug-buf'

* debug-buf:
  * Use ContextNote for debug buffer appending
  * Add more debug Contexts
  * Don't see 'user@::' hostname automatically
  * Make 'Context' log the file/line number into the debug buffer
Bryan Drewery 16 سال پیش
والد
کامیت
7b2cedfb00
11فایلهای تغییر یافته به همراه30 افزوده شده و 92 حذف شده
  1. 1 1
      src/binds.c
  2. 4 0
      src/botnet.c
  3. 2 0
      src/cmds.c
  4. 4 0
      src/dcc.c
  5. 1 61
      src/debug.c
  6. 11 17
      src/debug.h
  7. 2 4
      src/egg_timer.c
  8. 1 2
      src/mod/irc.mod/irc.c
  9. 2 0
      src/mod/server.mod/servmsg.c
  10. 1 4
      src/net.c
  11. 1 3
      src/userent.c

+ 1 - 1
src/binds.c

@@ -275,7 +275,7 @@ static int bind_entry_exec(bind_table_t *table, bind_entry_t *entry, void **al)
 	bind_entry_t *prev = NULL;
 	int retval;
 
-	ContextNote(entry->mask);
+	ContextNote("bind", entry->mask);
 	/* Give this entry a hit. */
 	entry->nhits++;
 

+ 4 - 0
src/botnet.c

@@ -1052,6 +1052,8 @@ static void botlink_dns_callback(int id, void *client_data, const char *host, bd
   long data = (long) client_data;
   int i = (int) data;
 
+  Context;
+
   if (!valid_dns_id(i, id))
     return;
 
@@ -1212,6 +1214,8 @@ static void tandem_relay_dns_callback(int id, void *client_data, const char *hos
   long data = (long) client_data;
   int i = (int) data, idx = -1;
 
+  Context;
+
   if (!valid_dns_id(i, id))
     return;
 

+ 2 - 0
src/cmds.c

@@ -4140,6 +4140,8 @@ static void my_dns_callback(int id, void *client_data, const char *host, bd::Arr
   long data = (long) client_data;
   int idx = (int) data;
 
+  Context;
+
   if (!valid_idx(idx))
     return;
 

+ 4 - 0
src/dcc.c

@@ -1472,6 +1472,8 @@ static void dcc_telnet_dns_callback(int id, void *client_data, const char *ip, b
   long data = (long) client_data;
   int i = (int) data;
 
+  Context;
+
   if (!valid_dns_id(i, id))
     return;
 
@@ -1511,6 +1513,8 @@ static void dcc_telnet_dns_forward_callback(int id, void *client_data, const cha
   long data = (long) client_data;
   int i = (int) data;
 
+  Context;
+
   if (!valid_dns_id(i, id))
     return;
 

+ 1 - 61
src/debug.c

@@ -55,14 +55,6 @@ char	get_buf[GET_BUFS][SGRAB + 5];
 size_t	current_get_buf = 0;
 
 
-#ifdef DEBUG_CONTEXT
-/* Context storage for fatal crashes */
-char    cx_file[16][16];
-char    cx_note[16][16];
-int     cx_line[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-int     cx_ptr = 0;
-#endif /* DEBUG_CONTEXT */
-
 void setlimits()
 {
 #ifndef CYGWIN_HACKS
@@ -99,13 +91,6 @@ void setlimits()
 
 void init_debug()
 {
-  for (int i = 0; i < 16; i ++)
-    Context;
-
-#ifdef DEBUG_CONTEXT
-  bzero(&cx_file, sizeof cx_file);
-  bzero(&cx_note, sizeof cx_note);
-#endif /* DEBUG_CONTEXT */
 }
 
 void sdprintf (const char *format, ...)
@@ -135,20 +120,6 @@ void sdprintf (const char *format, ...)
 #endif
 }
 
-#ifdef DEBUG_CONTEXT
-
-#define CX(ptr) cx_file[ptr] && cx_file[ptr][0] ? cx_file[ptr] : "", cx_line[ptr], cx_note[ptr] && cx_note[ptr][0] ? cx_note[ptr] : ""
-static void write_debug()
-{
-  char tmpout[150] = "";
-
-  simple_snprintf(tmpout, sizeof tmpout, "* Last 3 contexts: %s/%d [%s], %s/%d [%s], %s/%d [%s]",
-                                  CX(cx_ptr - 2), CX(cx_ptr - 1), CX(cx_ptr));
-  putlog(LOG_MISC, "*", "%s (Paste to bryan)", tmpout);
-  printf("%s\n", tmpout);
-}
-#endif /* DEBUG_CONTEXT */
-
 static void write_debug()
 {
   putlog(LOG_MISC, "*", "** Paste to bryan:");
@@ -274,10 +245,7 @@ static void got_alarm(int z)
  */
 static void got_ill(int z)
 {
-#ifdef DEBUG_CONTEXT
-  putlog(LOG_MISC, "*", "* Context: %s/%d [%s]", cx_file[cx_ptr], cx_line[cx_ptr],
-                         (cx_note[cx_ptr][0]) ? cx_note[cx_ptr] : "");
-#endif /* DEBUG_CONTEXT */
+  write_debug();
 }
 
 static void
@@ -314,31 +282,3 @@ void init_signals()
   signal(SIGHUP, got_hup);
   signal(SIGUSR1, got_usr1);
 }
-
-#ifdef DEBUG_CONTEXT
-/* Context */
-void eggContext(const char *file, int line)
-{
-  char x[31] = "", *p = strrchr(file, '/');
-
-  strlcpy(x, p ? p + 1 : file, sizeof x);
-  cx_ptr = ((cx_ptr + 1) & 15);
-  strcpy(cx_file[cx_ptr], x);
-  cx_line[cx_ptr] = line;
-  cx_note[cx_ptr][0] = 0;
-}
-
-/* Called from the ContextNote macro.
- */
-void eggContextNote(const char *file, int line, const char *note)
-{
-  char x[31] = "", *p = strrchr(file, '/');
-
-  strlcpy(x, p ? p + 1 : file, sizeof x);
-  cx_ptr = ((cx_ptr + 1) & 15);
-  strcpy(cx_file[cx_ptr], x);
-  cx_line[cx_ptr] = line;
-  strlcpy(cx_note[cx_ptr], note, sizeof cx_note[cx_ptr]);
-}
-#endif
-

+ 11 - 17
src/debug.h

@@ -5,27 +5,23 @@
 #  include "config.h"
 #endif
 
-/*
- * Undefine this to completely disable context debugging.
- * WARNING: DO NOT send in bug reports if you undefine this!
- */
-
-#undef DEBUG_CONTEXT
-
 #define GET_BUFS 30
 #define get_buf_inc() if (++current_get_buf == GET_BUFS) current_get_buf = 0;
 
+#define Context do { \
+  simple_snprintf(get_buf[current_get_buf], sizeof(get_buf[current_get_buf]), "Context: %s:%d", __FILE__, __LINE__); \
+  get_buf_inc(); \
+} while (0)
+
+#define ContextNote(from, buf) do { \
+  simple_snprintf(get_buf[current_get_buf], sizeof(get_buf[current_get_buf]), "%s: %s", from, buf); \
+  get_buf_inc(); \
+} while(0)
+
+
 /*
  *    Handy aliases for memory tracking and core dumps
  */
-#ifdef DEBUG_CONTEXT
-#  define Context               eggContext(__FILE__, __LINE__)
-#  define ContextNote(note)     eggContextNote(__FILE__, __LINE__, note)
-#else
-#  define Context               {}
-#  define ContextNote(note)     {}
-#endif
-
 #define debug0(x)               putlog(LOG_DEBUG,"*",x)
 #define debug1(x,a1)            putlog(LOG_DEBUG,"*",x,a1)
 #define debug2(x,a1,a2)         putlog(LOG_DEBUG,"*",x,a1,a2)
@@ -41,6 +37,4 @@ void setlimits();
 void sdprintf (const char *, ...) __attribute__((format(printf, 1, 2)));
 void init_signals();
 void init_debug();
-void eggContext(const char *, int);
-void eggContextNote(const char *, int, const char *);
 #endif /* !_DEBUG_H */

+ 2 - 4
src/egg_timer.c

@@ -253,10 +253,8 @@ static bool process_timer(egg_timer_t* timer) {
 		deleted = 1;
 	}
 
-	if (timer->name) {
-		simple_snprintf(get_buf[current_get_buf], sizeof(get_buf[current_get_buf]), "Execing timer: %s", timer->name);
-		get_buf_inc();
-	}
+	if (timer->name)
+		ContextNote("Timer", timer->name);
 
 	callback(client_data);
 	return deleted;

+ 1 - 2
src/mod/irc.mod/irc.c

@@ -1684,8 +1684,7 @@ flush_modes()
 
   memberlist *m = NULL;
 
-  strlcpy(get_buf[current_get_buf], "Idle", sizeof(get_buf[current_get_buf]));
-  get_buf_inc();
+  Context;
 
   for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
     for (m = chan->channel.member; m && m->nick[0]; m = m->next) {

+ 2 - 0
src/mod/server.mod/servmsg.c

@@ -1943,6 +1943,8 @@ static void server_dns_callback(int id, void *client_data, const char *host, bd:
   long data = (long) client_data;
   int idx = (int) data;
 
+  Context;
+
   resolvserv = 0;
 
   if (!valid_dns_id(idx, id))

+ 1 - 4
src/net.c

@@ -1481,15 +1481,12 @@ bool socket_run() {
 
   int xx = sockgets(buf, &i);
 
-  get_buf[current_get_buf][0] = 0;
-
   if (xx >= 0) {		/* Non-error */
     if ((idx = findanyidx(xx)) != -1) {
       if (likely(dcc[idx].type->activity)) {
         /* Traffic stats */
         if (dcc[idx].type->name) {
-          simple_snprintf(get_buf[current_get_buf], sizeof(get_buf[current_get_buf]), "%s: %s", dcc[idx].type->name, buf);
-          get_buf_inc();
+          ContextNote(dcc[idx].type->name, buf);
 
           if (!strncmp(dcc[idx].type->name, "BOT", 3))
             traffic.in_today.bn += i + 1;

+ 1 - 3
src/userent.c

@@ -778,7 +778,6 @@ static bool botaddr_unpack(struct userrec *u, struct user_entry *e)
   struct bot_addr *bi = (struct bot_addr *) my_calloc(1, sizeof(struct bot_addr));
 
   /* address:port/port:hublevel:uplink */
-  Context;
 
   strlcpy(p, e->u.list->extra, sizeof(p));
   q1 = strchr(p, ':');
@@ -838,7 +837,6 @@ static bool botaddr_set(struct userrec *u, struct user_entry *e, void *buf)
 {
   register struct bot_addr *bi = (struct bot_addr *) e->u.extra;
 
-  Context;
   if (!bi && !buf)
     return 1;
   if (bi != buf) {
@@ -847,7 +845,7 @@ static bool botaddr_set(struct userrec *u, struct user_entry *e, void *buf)
       free(bi->uplink);
       free(bi);
     }
-    ContextNote("(sharebug) occurred in botaddr_set");
+    ContextNote("botaddr_set", "(sharebug) occurred in botaddr_set");
     bi = (struct bot_addr *) buf;
     e->u.extra = (struct bot_addr *) buf;
   }