Ver código fonte

* Make 'Context' log the file/line number into the debug buffer

Bryan Drewery 16 anos atrás
pai
commit
83e1dfa7b8
3 arquivos alterados com 6 adições e 78 exclusões
  1. 1 61
      src/debug.c
  2. 5 15
      src/debug.h
  3. 0 2
      src/userent.c

+ 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
-

+ 5 - 15
src/debug.h

@@ -5,26 +5,18 @@
 #  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)
+
 /*
  *    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)
@@ -41,6 +33,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 */

+ 0 - 2
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) {