[sr-dev] git:master: mem: include the module name in the debugging info
Andrei Pelinescu-Onciul
andrei at iptel.org
Thu Oct 8 12:16:44 CEST 2009
Module: sip-router
Branch: master
Commit: 220ac6e202bd7bbd69989bc812465cb4173831a6
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=220ac6e202bd7bbd69989bc812465cb4173831a6
Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date: Thu Oct 8 11:33:25 2009 +0200
mem: include the module name in the debugging info
- use <module_name: file> when recording the filename information
for debugging (DBQ_QM_MALLOC defined)
- added a new file that should define in a portable way the
various location info (file, function, a.s.o.)
---
mem/mem.h | 29 +++++++++----------
mem/shm_mem.h | 14 ++++-----
mem/src_loc.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 103 insertions(+), 23 deletions(-)
diff --git a/mem/mem.h b/mem/mem.h
index ab052bd..aed1442 100644
--- a/mem/mem.h
+++ b/mem/mem.h
@@ -62,23 +62,22 @@
# ifdef DBG_QM_MALLOC
-#ifdef __SUNPRO_C
- #define __FUNCTION__ "" /* gcc specific */
-#endif
+
+# include "src_loc.h" /* src location macros: _SRC_* */
# ifdef F_MALLOC
-# define pkg_malloc(s) fm_malloc(mem_block, (s),__FILE__, \
- __FUNCTION__, __LINE__)
-# define pkg_free(p) fm_free(mem_block, (p), __FILE__, \
- __FUNCTION__, __LINE__)
-# define pkg_realloc(p, s) fm_realloc(mem_block, (p), (s),__FILE__, \
- __FUNCTION__, __LINE__)
+# define pkg_malloc(s) fm_malloc(mem_block, (s), _SRC_LOC_, \
+ _SRC_FUNCTION_, _SRC_LINE_)
+# define pkg_free(p) fm_free(mem_block, (p), _SRC_LOC_, \
+ _SRC_FUNCTION_, _SRC_LINE_)
+# define pkg_realloc(p, s) fm_realloc(mem_block, (p), (s), \
+ _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_)
# else
-# define pkg_malloc(s) qm_malloc(mem_block, (s),__FILE__, \
- __FUNCTION__, __LINE__)
-# define pkg_realloc(p, s) qm_realloc(mem_block, (p), (s),__FILE__, \
- __FUNCTION__, __LINE__)
-# define pkg_free(p) qm_free(mem_block, (p), __FILE__, \
- __FUNCTION__, __LINE__)
+# define pkg_malloc(s) qm_malloc(mem_block, (s),_SRC_LOC_, \
+ _SRC_FUNCTION_, _SRC_LINE_)
+# define pkg_realloc(p, s) qm_realloc(mem_block, (p), (s), \
+ _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_)
+# define pkg_free(p) qm_free(mem_block, (p), _SRC_LOC_, \
+ _SRC_FUNCTION_, _SRC_LINE_)
# endif
# else
# ifdef F_MALLOC
diff --git a/mem/shm_mem.h b/mem/shm_mem.h
index e4009a5..2dce31a 100644
--- a/mem/shm_mem.h
+++ b/mem/shm_mem.h
@@ -187,12 +187,10 @@ void shm_mem_destroy();
#ifdef DBG_QM_MALLOC
-#ifdef __SUNPRO_C
- #define __FUNCTION__ "" /* gcc specific */
-#endif
+#include "src_loc.h"
#define shm_malloc_unsafe(_size ) \
- MY_MALLOC(shm_block, (_size), __FILE__, __FUNCTION__, __LINE__ )
+ MY_MALLOC(shm_block, (_size), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
inline static void* _shm_malloc(unsigned int size,
@@ -218,15 +216,15 @@ inline static void* _shm_realloc(void *ptr, unsigned int size,
}
#define shm_malloc( _size ) _shm_malloc((_size), \
- __FILE__, __FUNCTION__, __LINE__ )
+ _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
#define shm_realloc( _ptr, _size ) _shm_realloc( (_ptr), (_size), \
- __FILE__, __FUNCTION__, __LINE__ )
+ _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
#define shm_free_unsafe( _p ) \
- MY_FREE( shm_block, (_p), __FILE__, __FUNCTION__, __LINE__ )
+ MY_FREE( shm_block, (_p), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
#define shm_free(_p) \
do { \
@@ -240,7 +238,7 @@ do { \
void* _shm_resize(void* ptr, unsigned int size, const char* f, const char* fn,
int line);
#define shm_resize(_p, _s ) _shm_resize((_p), (_s), \
- __FILE__, __FUNCTION__, __LINE__ )
+ _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
/*#define shm_resize(_p, _s ) shm_realloc( (_p), (_s))*/
diff --git a/mem/src_loc.h b/mem/src_loc.h
new file mode 100644
index 0000000..3877d17
--- /dev/null
+++ b/mem/src_loc.h
@@ -0,0 +1,83 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2009 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * mem/src_loc.h - defines for src location ( function name, module a.s.o.),
+ * used for recording a *malloc()/ *free() caller.
+ *
+ * Expects MOD_NAME defined for modules (if it's not defined "core" will be
+ * assumed).
+ * Defines:
+ * _SRC_FUNCTION_ - current function name
+ * _SRC_FILENAME_ - current .c filename
+ * _SRC_LINE_ - current line
+ * _SRC_MODULE_ - module name, lib name or "<core>" (depends on MOD_NAME
+ * being properly set)
+ * _SRC_LOC_ - module name + file name
+ *
+ */
+/*
+ * History:
+ * --------
+ * 2009-10-08 initial version (andrei)
+*/
+
+#ifndef __src_loc_h
+#define __src_loc_h
+
+
+/* C >= 99 has __func__, older gcc versions have __FUNCTION__ */
+#ifndef _SRC_FUNCTION_
+# if __STDC_VERSION__ < 199901L
+# if __GNUC__ >= 2
+# define _SRC_FUNCTION_ __FUNCTION__
+# else
+# define _SRC_FUNCTION_ ""
+# endif
+# else
+# define _SRC_FUNCTION_ __func__
+# endif /* __STDC_VERSION_ < 199901L */
+#endif /* _FUNC_NAME_ */
+
+
+#ifndef _SRC_FILENAME_
+# define _SRC_FILENAME_ __FILE__
+#endif /* _SRC_FILENAME_ */
+
+
+#ifndef _SRC_LINE_
+# define _SRC_LINE_ __LINE__
+#endif /* _SRC_LINE_ */
+
+
+#ifndef _SRC_MODULE_
+# ifdef MOD_NAME
+# define _SRC_MODULE_ MOD_NAME
+# else
+# define _SRC_MODULE_ "<core>"
+# endif /* MOD_NAME */
+#endif /* _SRC_MODULE_ */
+
+
+#ifndef _SRC_LOC_
+# define _SRC_LOC_ _SRC_MODULE_ ": " _SRC_FILENAME_
+#endif /*_SRC_LOC_ */
+
+
+#endif /*__src_loc_h*/
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
More information about the sr-dev
mailing list