Browse code

- separate memdbg log level which controls the memory/malloc related debug messages (to see them ser must be compiled with malloc debuging: -DDBG_QM_MALLOC or -DDBG_FM_MALLOC and memdbg must be <= debug ). By default is set to L_DBG. E.g.: setting memdbg=100 in ser.cfg will make sure that you'll never see a malloc debug message. Note: memdbg is different from memlog, memlog is the log level used for malloc statistics (printed on exit or on SIGUSR1).

- default log level switched to 0: this means that in the absence
of -d* commandline parameters or of the debug=no in ser.cfg, only
errors and other critical messages will be logged (no warnings,
info, notice or dbg).

Andrei Pelinescu-Onciul authored on 07/04/2006 14:55:27
Showing 12 changed files
... ...
@@ -66,7 +66,7 @@ MAIN_NAME=ser
66 66
 VERSION = 0
67 67
 PATCHLEVEL = 10
68 68
 SUBLEVEL =   99
69
-EXTRAVERSION = -dev36
69
+EXTRAVERSION = -dev37
70 70
 
71 71
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
72 72
 			$(SUBLEVEL) )
... ...
@@ -49,6 +49,11 @@ modules:
49 49
               Vias a.s.o) and not on the original message
50 50
  
51 51
 core:
52
+ - default log level switched to 0 (only messages < L_WARN will be printed
53
+   by default)
54
+ - separate memdbg log level which controls the memory/malloc related
55
+   debug messages (to see them ser must be compiled with malloc debuging:
56
+     -DDBG_QM_MALLOC or -DDBG_FM_MALLOC and memdbg must be <= debug )
52 57
  - added named routes: names can be used instead of numbers in all the
53 58
    route commads or route declarations. route(number) is equivalent to
54 59
    route("number").
... ...
@@ -229,6 +229,7 @@ CHILDREN children
229 229
 CHECK_VIA	check_via
230 230
 SYN_BRANCH syn_branch
231 231
 MEMLOG		"memlog"|"mem_log"
232
+MEMDBG		"memdbg"|"mem_dbg"
232 233
 SIP_WARNING sip_warning
233 234
 SERVER_SIGNATURE server_signature
234 235
 REPLY_TO_VIA reply_to_via
... ...
@@ -418,6 +419,7 @@ EAT_ABLE	[\ \t\b\r]
418 418
 <INITIAL>{CHECK_VIA}	{ count(); yylval.strval=yytext; return CHECK_VIA; }
419 419
 <INITIAL>{SYN_BRANCH}	{ count(); yylval.strval=yytext; return SYN_BRANCH; }
420 420
 <INITIAL>{MEMLOG}	{ count(); yylval.strval=yytext; return MEMLOG; }
421
+<INITIAL>{MEMDBG}	{ count(); yylval.strval=yytext; return MEMDBG; }
421 422
 <INITIAL>{SIP_WARNING}	{ count(); yylval.strval=yytext; return SIP_WARNING; }
422 423
 <INITIAL>{USER}		{ count(); yylval.strval=yytext; return USER; }
423 424
 <INITIAL>{GROUP}	{ count(); yylval.strval=yytext; return GROUP; }
... ...
@@ -236,6 +236,7 @@ static struct socket_id* mk_listen_id(char*, int, int);
236 236
 %token CHECK_VIA
237 237
 %token SYN_BRANCH
238 238
 %token MEMLOG
239
+%token MEMDBG
239 240
 %token SIP_WARNING
240 241
 %token SERVER_SIGNATURE
241 242
 %token REPLY_TO_VIA
... ...
@@ -504,6 +505,8 @@ assign_stm:
504 504
 	| SYN_BRANCH EQUAL error { yyerror("boolean value expected"); }
505 505
 	| MEMLOG EQUAL NUMBER { memlog=$3; }
506 506
 	| MEMLOG EQUAL error { yyerror("int value expected"); }
507
+	| MEMDBG EQUAL NUMBER { memdbg=$3; }
508
+	| MEMDBG EQUAL error { yyerror("int value expected"); }
507 509
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
508 510
 	| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
509 511
 	| USER EQUAL STRING     { user=$3; }
... ...
@@ -36,6 +36,7 @@
36 36
 #define L_ALERT -3
37 37
 #define L_CRIT  -2
38 38
 #define L_ERR   -1
39
+#define L_DEFAULT 0
39 40
 #define L_WARN   1
40 41
 #define L_NOTICE 2
41 42
 #define L_INFO   3
... ...
@@ -139,6 +139,8 @@ extern int is_main;
139 139
 
140 140
 /* debugging level for dumping memory status */
141 141
 extern int memlog;
142
+/* debugging level for malloc debugging messages */
143
+extern int memdbg;
142 144
 
143 145
 /* debugging level for timer debugging (see -DTIMER_DEBUG) */
144 146
 extern int timerlog;
... ...
@@ -242,7 +242,7 @@ int tls_disable = 0; /* 1 if tls is disabled */
242 242
 struct process_table *pt=0;		/*array with children pids, 0= main proc,
243 243
 									alloc'ed in shared mem if possible*/
244 244
 int sig_flag = 0;              /* last signal received */
245
-int debug = L_NOTICE;
245
+int debug = L_DEFAULT; /* print only msg. < L_WARN */
246 246
 int dont_fork = 0;
247 247
 int log_stderr = 0;
248 248
 /* log facility (see syslog(3)) */
... ...
@@ -254,6 +254,8 @@ int check_via =  0;
254 254
 int syn_branch = 1;
255 255
 /* debugging level for memory stats */
256 256
 int memlog = L_DBG;
257
+/* debugging level for the malloc debug messages */
258
+int memdbg = L_DBG;
257 259
 /* debugging level for timer debugging */
258 260
 int timerlog = L_WARN;
259 261
 /* should replies include extensive warnings? by default yes,
... ...
@@ -37,6 +37,7 @@
37 37
  *  2005-12-12  fixed realloc shrink real_used accounting (andrei)
38 38
  *              fixed initial size (andrei)
39 39
  *  2006-02-03  fixed realloc out of mem. free bug (andrei)
40
+ *  2006-04-07  s/DBG/MDBG (andrei)
40 41
  */
41 42
 
42 43
 
... ...
@@ -48,6 +49,7 @@
48 48
 #include "f_malloc.h"
49 49
 #include "../dprint.h"
50 50
 #include "../globals.h"
51
+#include "memdbg.h"
51 52
 
52 53
 
53 54
 /*useful macros*/
... ...
@@ -256,7 +258,7 @@ void* fm_malloc(struct fm_block* qm, unsigned long size)
256 256
 	int hash;
257 257
 	
258 258
 #ifdef DBG_F_MALLOC
259
-	DBG("fm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
259
+	MDBG("fm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
260 260
 			line);
261 261
 #endif
262 262
 	/*size must be a multiple of 8*/
... ...
@@ -292,7 +294,7 @@ found:
292 292
 	frag->func=func;
293 293
 	frag->line=line;
294 294
 	frag->check=ST_CHECK_PATTERN;
295
-	DBG("fm_malloc(%p, %lu) returns address %p \n", qm, size,
295
+	MDBG("fm_malloc(%p, %lu) returns address %p \n", qm, size,
296 296
 		(char*)frag+sizeof(struct fm_frag));
297 297
 #else
298 298
 	fm_split_frag(qm, frag, size);
... ...
@@ -320,7 +322,7 @@ void fm_free(struct fm_block* qm, void* p)
320 320
 	unsigned long size;
321 321
 
322 322
 #ifdef DBG_F_MALLOC
323
-	DBG("fm_free(%p, %p), called from %s: %s(%d)\n", qm, p, file, func, line);
323
+	MDBG("fm_free(%p, %p), called from %s: %s(%d)\n", qm, p, file, func, line);
324 324
 	if (p>(void*)qm->last_frag || p<(void*)qm->first_frag){
325 325
 		LOG(L_CRIT, "BUG: fm_free: bad pointer %p (out of memory block!) - "
326 326
 				"aborting\n", p);
... ...
@@ -333,8 +335,8 @@ void fm_free(struct fm_block* qm, void* p)
333 333
 	}
334 334
 	f=(struct fm_frag*) ((char*)p-sizeof(struct fm_frag));
335 335
 #ifdef DBG_F_MALLOC
336
-	DBG("fm_free: freeing block alloc'ed from %s: %s(%ld)\n", f->file, f->func,
337
-			f->line);
336
+	MDBG("fm_free: freeing block alloc'ed from %s: %s(%ld)\n",
337
+			f->file, f->func, f->line);
338 338
 #endif
339 339
 	size=f->size;
340 340
 #if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
... ...
@@ -366,7 +368,7 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
366 366
 	int hash;
367 367
 	
368 368
 #ifdef DBG_F_MALLOC
369
-	DBG("fm_realloc(%p, %p, %lu) called from %s: %s(%d)\n", qm, p, size,
369
+	MDBG("fm_realloc(%p, %p, %lu) called from %s: %s(%d)\n", qm, p, size,
370 370
 			file, func, line);
371 371
 	if ((p)&&(p>(void*)qm->last_frag || p<(void*)qm->first_frag)){
372 372
 		LOG(L_CRIT, "BUG: fm_free: bad pointer %p (out of memory block!) - "
... ...
@@ -391,7 +393,7 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
391 391
 #endif
392 392
 	f=(struct fm_frag*) ((char*)p-sizeof(struct fm_frag));
393 393
 #ifdef DBG_F_MALLOC
394
-	DBG("fm_realloc: realloc'ing frag %p alloc'ed from %s: %s(%ld)\n",
394
+	MDBG("fm_realloc: realloc'ing frag %p alloc'ed from %s: %s(%ld)\n",
395 395
 			f, f->file, f->func, f->line);
396 396
 #endif
397 397
 	size=ROUNDUP(size);
... ...
@@ -399,7 +401,7 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
399 399
 	if (f->size > size){
400 400
 		/* shrink */
401 401
 #ifdef DBG_F_MALLOC
402
-		DBG("fm_realloc: shrinking from %lu to %lu\n", f->size, size);
402
+		MDBG("fm_realloc: shrinking from %lu to %lu\n", f->size, size);
403 403
 		fm_split_frag(qm, f, size, file, "frag. from fm_realloc", line);
404 404
 #else
405 405
 		fm_split_frag(qm, f, size);
... ...
@@ -411,7 +413,7 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
411 411
 	}else if (f->size<size){
412 412
 		/* grow */
413 413
 #ifdef DBG_F_MALLOC
414
-		DBG("fm_realloc: growing from %lu to %lu\n", f->size, size);
414
+		MDBG("fm_realloc: growing from %lu to %lu\n", f->size, size);
415 415
 #endif
416 416
 		diff=size-f->size;
417 417
 		n=FRAG_NEXT(f);
... ...
@@ -471,12 +473,12 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
471 471
 	}else{
472 472
 		/* do nothing */
473 473
 #ifdef DBG_F_MALLOC
474
-		DBG("fm_realloc: doing nothing, same size: %lu - %lu\n", 
474
+		MDBG("fm_realloc: doing nothing, same size: %lu - %lu\n", 
475 475
 				f->size, size);
476 476
 #endif
477 477
 	}
478 478
 #ifdef DBG_F_MALLOC
479
-	DBG("fm_realloc: returning %p\n", p);
479
+	MDBG("fm_realloc: returning %p\n", p);
480 480
 #endif
481 481
 	return p;
482 482
 }
... ...
@@ -121,11 +121,12 @@
121 121
 #	define pkg_status()  shm_status()
122 122
 #else
123 123
 #	include <stdlib.h>
124
+#	include "memdbg.h"
124 125
 #	define pkg_malloc(s) \
125 126
 	(  { void *v; v=malloc((s)); \
126
-	   DBG("malloc %p size %d end %p\n", v, s, (char*)v+(s));\
127
+	   MDBG("malloc %p size %d end %p\n", v, s, (char*)v+(s));\
127 128
 	   v; } )
128
-#	define pkg_free(p)  do{ DBG("free %p\n", (p)); free((p)); }while(0);
129
+#	define pkg_free(p)  do{ MDBG("free %p\n", (p)); free((p)); }while(0);
129 130
 #	define pkg_status()
130 131
 #endif
131 132
 
132 133
new file mode 100644
... ...
@@ -0,0 +1,45 @@
0
+/*
1
+ * $Id$
2
+ *
3
+ * Copyright (C) 2006 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/* malloc debug messages
18
+ * History:
19
+ * --------
20
+ *  2006-04-07             created by andrei
21
+ */
22
+
23
+
24
+#ifndef _memdbg_h
25
+#define _memdbg_h
26
+
27
+extern int memdbg;
28
+
29
+#ifdef NO_DEBUG
30
+	#ifdef __SUNPRO_C
31
+		#define MDBG(...)
32
+	#else
33
+		#define MDBG(fmt, args...)
34
+	#endif
35
+#else /* NO_DEBUG */
36
+	#ifdef __SUNPRO_C
37
+		#define MDBG(...) LOG(memdbg, __VA_ARGS__)
38
+	#else
39
+		#define MDBG(fmt, args...) LOG(memdbg, fmt,  ## args)
40
+	#endif
41
+#endif /* NO_DEBUG */
42
+
43
+
44
+#endif
... ...
@@ -38,6 +38,7 @@
38 38
  *  2005-12-12  fixed realloc shrink real_used & used accounting;
39 39
  *              fixed initial size (andrei)
40 40
  *  2006-02-03  fixed realloc out of mem. free bug (andrei)
41
+ *  2006-04-07  s/DBG/MDBG (andrei)
41 42
  */
42 43
 
43 44
 
... ...
@@ -50,6 +51,7 @@
50 50
 #include "q_malloc.h"
51 51
 #include "../dprint.h"
52 52
 #include "../globals.h"
53
+#include "memdbg.h"
53 54
 
54 55
 
55 56
 /*useful macros*/
... ...
@@ -364,7 +366,7 @@ void* qm_malloc(struct qm_block* qm, unsigned long size)
364 364
 	unsigned int list_cntr;
365 365
 
366 366
 	list_cntr = 0;
367
-	DBG("qm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
367
+	MDBG("qm_malloc(%p, %lu) called from %s: %s(%d)\n", qm, size, file, func,
368 368
 			line);
369 369
 #endif
370 370
 	/*size must be a multiple of 8*/
... ...
@@ -403,7 +405,7 @@ void* qm_malloc(struct qm_block* qm, unsigned long size)
403 403
 		f->check=ST_CHECK_PATTERN;
404 404
 		/*  FRAG_END(f)->check1=END_CHECK_PATTERN1;
405 405
 			FRAG_END(f)->check2=END_CHECK_PATTERN2;*/
406
-		DBG("qm_malloc(%p, %lu) returns address %p frag. %p (size=%lu) on %d"
406
+		MDBG("qm_malloc(%p, %lu) returns address %p frag. %p (size=%lu) on %d"
407 407
 				" -th hit\n",
408 408
 			 qm, size, (char*)f+sizeof(struct qm_frag), f, f->size, list_cntr );
409 409
 #endif
... ...
@@ -427,7 +429,7 @@ void qm_free(struct qm_block* qm, void* p)
427 427
 	unsigned long size;
428 428
 
429 429
 #ifdef DBG_QM_MALLOC
430
-	DBG("qm_free(%p, %p), called from %s: %s(%d)\n", qm, p, file, func, line);
430
+	MDBG("qm_free(%p, %p), called from %s: %s(%d)\n", qm, p, file, func, line);
431 431
 	if (p>(void*)qm->last_frag_end || p<(void*)qm->first_frag){
432 432
 		LOG(L_CRIT, "BUG: qm_free: bad pointer %p (out of memory block!) - "
433 433
 				"aborting\n", p);
... ...
@@ -448,7 +450,7 @@ void qm_free(struct qm_block* qm, void* p)
448 448
 				f->file, f->func, f->line);
449 449
 		abort();
450 450
 	}
451
-	DBG("qm_free: freeing frag. %p alloc'ed from %s: %s(%ld)\n",
451
+	MDBG("qm_free: freeing frag. %p alloc'ed from %s: %s(%ld)\n",
452 452
 			f, f->file, f->func, f->line);
453 453
 #endif
454 454
 	size=f->size;
... ...
@@ -513,7 +515,7 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
513 513
 	
514 514
 	
515 515
 #ifdef DBG_QM_MALLOC
516
-	DBG("qm_realloc(%p, %p, %lu) called from %s: %s(%d)\n", qm, p, size,
516
+	MDBG("qm_realloc(%p, %p, %lu) called from %s: %s(%d)\n", qm, p, size,
517 517
 			file, func, line);
518 518
 	if ((p)&&(p>(void*)qm->last_frag_end || p<(void*)qm->first_frag)){
519 519
 		LOG(L_CRIT, "BUG: qm_free: bad pointer %p (out of memory block!) - "
... ...
@@ -540,7 +542,7 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
540 540
 	f=(struct qm_frag*) ((char*)p-sizeof(struct qm_frag));
541 541
 #ifdef DBG_QM_MALLOC
542 542
 	qm_debug_frag(qm, f);
543
-	DBG("qm_realloc: realloc'ing frag %p alloc'ed from %s: %s(%ld)\n",
543
+	MDBG("qm_realloc: realloc'ing frag %p alloc'ed from %s: %s(%ld)\n",
544 544
 			f, f->file, f->func, f->line);
545 545
 	if (f->u.is_free){
546 546
 		LOG(L_CRIT, "BUG:qm_realloc: trying to realloc an already freed "
... ...
@@ -554,9 +556,9 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
554 554
 		orig_size=f->size;
555 555
 		/* shrink */
556 556
 #ifdef DBG_QM_MALLOC
557
-		DBG("qm_realloc: shrinking from %lu to %lu\n", f->size, size);
557
+		MDBG("qm_realloc: shrinking from %lu to %lu\n", f->size, size);
558 558
 		if(split_frag(qm, f, size, file, "fragm. from qm_realloc", line)!=0){
559
-		DBG("qm_realloc : shrinked successful\n");
559
+		MDBG("qm_realloc : shrinked successful\n");
560 560
 #else
561 561
 		if(split_frag(qm, f, size)!=0){
562 562
 #endif
... ...
@@ -568,7 +570,7 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
568 568
 	}else if (f->size < size){
569 569
 		/* grow */
570 570
 #ifdef DBG_QM_MALLOC
571
-		DBG("qm_realloc: growing from %lu to %lu\n", f->size, size);
571
+		MDBG("qm_realloc: growing from %lu to %lu\n", f->size, size);
572 572
 #endif
573 573
 			orig_size=f->size;
574 574
 			diff=size-f->size;
... ...
@@ -614,12 +616,12 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
614 614
 	}else{
615 615
 		/* do nothing */
616 616
 #ifdef DBG_QM_MALLOC
617
-		DBG("qm_realloc: doing nothing, same size: %lu - %lu\n",
617
+		MDBG("qm_realloc: doing nothing, same size: %lu - %lu\n",
618 618
 				f->size, size);
619 619
 #endif
620 620
 	}
621 621
 #ifdef DBG_QM_MALLOC
622
-	DBG("qm_realloc: returning %p\n", p);
622
+	MDBG("qm_realloc: returning %p\n", p);
623 623
 #endif
624 624
 	return p;
625 625
 }
... ...
@@ -42,6 +42,7 @@
42 42
 #include "shm_mem.h"
43 43
 #include "../config.h"
44 44
 #include "../globals.h"
45
+#include "memdbg.h"
45 46
 
46 47
 #ifdef  SHM_MMAP
47 48
 
... ...
@@ -107,7 +108,7 @@ void* _shm_resize( void* p , unsigned int s)
107 107
 #	ifdef DBG_QM_MALLOC
108 108
 #	ifdef VQ_MALLOC
109 109
 	f=(struct  vqm_frag*) ((char*)p-sizeof(struct vqm_frag));
110
-	DBG("_shm_resize(%p, %d), called from %s: %s(%d)\n",  
110
+	MDBG("_shm_resize(%p, %d), called from %s: %s(%d)\n",  
111 111
 		p, s, file, func, line);
112 112
 	VQM_DEBUG_FRAG(shm_block, f);
113 113
 	if (p>(void *)shm_block->core_end || p<(void*)shm_block->init_core){