[Mesa-dev] [PATCH 1/4] add some malloc debug functions
marvin24 at gmx.de
marvin24 at gmx.de
Sat Jun 12 13:13:32 PDT 2010
---
src/mesa/drivers/dri/radeon/radeon_debug.h | 52 ++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/src/mesa/drivers/dri/radeon/radeon_debug.h b/src/mesa/drivers/dri/radeon/radeon_debug.h
index ef8b967..7de54d2 100644
--- a/src/mesa/drivers/dri/radeon/radeon_debug.h
+++ b/src/mesa/drivers/dri/radeon/radeon_debug.h
@@ -171,4 +171,56 @@ static inline void radeon_debug_remove_indent(void)
} while(0)
+/* uncomment to enable malloc debugging */
+/* #define DEBUG_MALLOC */
+
+#ifdef DEBUG_MALLOC
+
+static inline void *mycs(size_t T, const char *fi, const char *fu, unsigned l)
+{
+ void *a = calloc(1, T);
+ radeon_error("calloc struct of %zu bytes in %p (%s@%s:%d)\n", T, a, fu, fi, l);
+ return a;
+}
+
+static inline void *myms(size_t T, const char *fi, const char *fu, unsigned l)
+{
+ void *a = malloc(T);
+ radeon_error("malloc struct of %zu bytes in %p (%s@%s:%d)\n", T, a, fu, fi, l);
+ return a;
+}
+
+static inline void *mym(size_t T, const char *fi, const char *fu, unsigned l)
+{
+ void *a = malloc(T);
+ radeon_error("malloc of %zu bytes in %p (%s@%s:%d)\n", T, a, fu, fi, l);
+ return a;
+}
+
+static inline void *myc(size_t T, const char *fi, const char *fu, unsigned l)
+{
+ void *a = calloc(1, T);
+ radeon_error("calloc of %zu bytes in %p (%s@%s:%d)\n", T, a, fu, fi, l);
+ return a;
+}
+
+#undef CALLOC_STRUCT
+#undef CALLOC
+#undef MALLOC
+#undef MALLOC_STRUCT
+#undef FREE
+
+#define CALLOC_STRUCT(T) mycs(sizeof(struct T), __FILE__, __func__, __LINE__)
+#define MALLOC_STRUCT(T) myms(sizeof(struct T), __FILE__, __func__, __LINE__)
+#define CALLOC(BYTES) myc(BYTES, __FILE__, __func__, __LINE__)
+#define MALLOC(BYTES) mym(BYTES, __FILE__, __func__, __LINE__)
+#define FREE(PTR) \
+do { \
+ radeon_error("free of %p in %s@%s:%d\n", PTR, __func__, __FILE__, __LINE__); \
+ free(PTR); \
+} while (0)
+
+#endif /* DEBUG_MALLOC */
+
#endif
+
--
1.7.0.4
More information about the mesa-dev
mailing list