summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2013-06-08 22:09:07 +0000
committerMatthew Jordan <mjordan@digium.com>2013-06-08 22:09:07 +0000
commitc43f380d036783ae10c426f23e8863ec1efdaa68 (patch)
treef4487b920b741d1e6a0d3195168a234935906ea1 /include
parent2fe6b6a5331e41b351774da0b66de40aa2f77ae7 (diff)
Add backtrace generation to MALLOC_DEBUG memory corruption reports
This patch allows astmm to access the backtrace generation code in Asterisk. When memory is allocated, a backtrace is created and stored with the memory region that tracks the allocation. If a memory corruption is detected, the backtrace is printed to the astmm log. The backtrace will make use of the BETTER_BACKTRACES build option if available. As a result, this patch moves the backtrace generation code into its own file and uses the non-wrapped versions of the C library memory allocation routines. This allows the memory allocation code to safely use the backtrace generation routines without infinitely recursing. Review: https://reviewboard.asterisk.org/r/2567 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391012 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/backtrace.h97
-rw-r--r--include/asterisk/lock.h1
-rw-r--r--include/asterisk/logger.h62
3 files changed, 102 insertions, 58 deletions
diff --git a/include/asterisk/backtrace.h b/include/asterisk/backtrace.h
new file mode 100644
index 000000000..fef1d86fa
--- /dev/null
+++ b/include/asterisk/backtrace.h
@@ -0,0 +1,97 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2013, Digium, Inc.
+ *
+ * Matt Jordan <mjordan@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ * \brief Asterisk backtrace generation
+ *
+ * This file provides backtrace generation utilities
+ */
+
+
+#ifndef BACKTRACE_H_
+#define BACKTRACE_H_
+
+#define AST_MAX_BT_FRAMES 32
+
+#ifdef HAVE_BKTR
+#define ast_bt_get_addresses(bt) __ast_bt_get_addresses((bt))
+#define ast_bt_create() __ast_bt_create()
+#define ast_bt_destroy(bt) __ast_bt_destroy((bt))
+#define ast_bt_get_symbols(addresses, num_frames) __ast_bt_get_symbols((addresses), (num_frames))
+#else
+#define ast_bt_get_addresses(bt) 0
+#define ast_bt_create() NULL
+#define ast_bt_destroy(bt) NULL
+#define ast_bt_get_symbols(addresses, num_frames) NULL
+#endif
+
+/* \brief
+ *
+ * A structure to hold backtrace information. This structure provides an easy means to
+ * store backtrace information or pass backtraces to other functions.
+ */
+struct ast_bt {
+ /*! The addresses of the stack frames. This is filled in by calling the glibc backtrace() function */
+ void *addresses[AST_MAX_BT_FRAMES];
+ /*! The number of stack frames in the backtrace */
+ int num_frames;
+ /*! Tells if the ast_bt structure was dynamically allocated */
+ unsigned int alloced:1;
+};
+
+#ifdef HAVE_BKTR
+
+/* \brief
+ * Allocates memory for an ast_bt and stores addresses and symbols.
+ *
+ * \return Returns NULL on failure, or the allocated ast_bt on success
+ * \since 1.6.1
+ */
+struct ast_bt *__ast_bt_create(void);
+
+/* \brief
+ * Fill an allocated ast_bt with addresses
+ *
+ * \retval 0 Success
+ * \retval -1 Failure
+ * \since 1.6.1
+ */
+int __ast_bt_get_addresses(struct ast_bt *bt);
+
+/* \brief
+ *
+ * Free dynamically allocated portions of an ast_bt
+ *
+ * \retval NULL.
+ * \since 1.6.1
+ */
+void *__ast_bt_destroy(struct ast_bt *bt);
+
+/* \brief Retrieve symbols for a set of backtrace addresses
+ *
+ * \param addresses A list of addresses, such as the ->addresses structure element of struct ast_bt.
+ * \param num_frames Number of addresses in the addresses list
+ * \retval NULL Unable to allocate memory
+ * \return List of strings. This should be freed with a single call to free.
+ * \since 1.6.2.16
+ */
+char **__ast_bt_get_symbols(void **addresses, size_t num_frames);
+
+#endif /* HAVE_BKTR */
+
+#endif /* BACKTRACE_H_ */
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index d7e895c77..4b1752cc4 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -59,6 +59,7 @@
#include "asterisk/time.h"
#endif
+#include "asterisk/backtrace.h"
#include "asterisk/logger.h"
#include "asterisk/compiler.h"
diff --git a/include/asterisk/logger.h b/include/asterisk/logger.h
index 1632291df..09d2b4c7a 100644
--- a/include/asterisk/logger.h
+++ b/include/asterisk/logger.h
@@ -80,7 +80,10 @@ struct ast_callid;
void ast_log_callid(int level, const char *file, int line, const char *function, struct ast_callid *callid, const char *fmt, ...)
__attribute__((format(printf, 6, 7)));
-void ast_backtrace(void);
+/*!
+ * \brief Log a backtrace of the current thread's execution stack to the Asterisk log
+ */
+void ast_log_backtrace(void);
/*! \brief Reload logger without rotating log files */
int logger_reload(void);
@@ -362,63 +365,6 @@ void ast_callid_strnprint(char *buffer, size_t buffer_size, struct ast_callid *c
#define ast_verb(level, ...) __ast_verbose(__FILE__, __LINE__, __PRETTY_FUNCTION__, level, __VA_ARGS__)
#define ast_verb_callid(level, callid, ...) __ast_verbose_callid(__FILE__, __LINE__, __PRETTY_FUNCTION__, level, callid, __VA_ARGS__)
-#ifndef _LOGGER_BACKTRACE_H
-#define _LOGGER_BACKTRACE_H
-#ifdef HAVE_BKTR
-#define AST_MAX_BT_FRAMES 32
-/* \brief
- *
- * A structure to hold backtrace information. This structure provides an easy means to
- * store backtrace information or pass backtraces to other functions.
- */
-struct ast_bt {
- /*! The addresses of the stack frames. This is filled in by calling the glibc backtrace() function */
- void *addresses[AST_MAX_BT_FRAMES];
- /*! The number of stack frames in the backtrace */
- int num_frames;
- /*! Tells if the ast_bt structure was dynamically allocated */
- unsigned int alloced:1;
-};
-
-/* \brief
- * Allocates memory for an ast_bt and stores addresses and symbols.
- *
- * \return Returns NULL on failure, or the allocated ast_bt on success
- * \since 1.6.1
- */
-struct ast_bt *ast_bt_create(void);
-
-/* \brief
- * Fill an allocated ast_bt with addresses
- *
- * \retval 0 Success
- * \retval -1 Failure
- * \since 1.6.1
- */
-int ast_bt_get_addresses(struct ast_bt *bt);
-
-/* \brief
- *
- * Free dynamically allocated portions of an ast_bt
- *
- * \retval NULL.
- * \since 1.6.1
- */
-void *ast_bt_destroy(struct ast_bt *bt);
-
-/* \brief Retrieve symbols for a set of backtrace addresses
- *
- * \param addresses A list of addresses, such as the ->addresses structure element of struct ast_bt.
- * \param num_frames Number of addresses in the addresses list
- * \retval NULL Unable to allocate memory
- * \return List of strings
- * \since 1.6.2.16
- */
-char **ast_bt_get_symbols(void **addresses, size_t num_frames);
-
-#endif /* HAVE_BKTR */
-#endif /* _LOGGER_BACKTRACE_H */
-
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif