Skip to content

Commit

Permalink
Astobj2: Allow reference debugging to be enabled/disabled by config.
Browse files Browse the repository at this point in the history
* The REF_DEBUG compiler flag no longer has any effect on code that uses
  Astobj2.  It is used to determine if reference debugging is enabled by
  default.  Reference debugging can be enabled or disabled in asterisk.conf.
* Caller information is provided in logger errors for ao2 bad magic numbers.
* Optimizes AO2 by merging internal functions with the public counterpart.
  This was possible now that we no longer require a dual ABI.

ASTERISK-24974 #close
Reported by: Corey Farrell

Change-Id: Icf3552721fe999365ba8a8cf00a965aa6b897cc1
  • Loading branch information
coreyfarrell committed Apr 27, 2015
1 parent d7f4788 commit 5c1d07b
Show file tree
Hide file tree
Showing 26 changed files with 406 additions and 992 deletions.
3 changes: 3 additions & 0 deletions UPGRADE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ chan_dahdi:
Caller-ID detection.

Core:
- The REF_DEBUG compiler flag is now used to enable refdebug by default.
The setting can be overridden in asterisk.conf by setting refdebug in
the options category. No recompile is required to enable/disable it.

AMI:
- The 'ModuleCheck' Action's Version key will no longer show the module
Expand Down
31 changes: 4 additions & 27 deletions apps/app_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1814,49 +1814,26 @@ static void queue_member_follower_removal(struct call_queue *queue, struct membe
ao2_callback(queue->members, OBJ_NODATA | OBJ_MULTIPLE, queue_member_decrement_followers, &pos);
}

#ifdef REF_DEBUG
#define queue_ref(q) _queue_ref(q, "", __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define queue_unref(q) _queue_unref(q, "", __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define queue_t_ref(q, tag) _queue_ref(q, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define queue_t_unref(q, tag) _queue_unref(q, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define queues_t_link(c, q, tag) __ao2_link_debug(c, q, 0, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define queues_t_unlink(c, q, tag) __ao2_unlink_debug(c, q, 0, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)

static inline struct call_queue *_queue_ref(struct call_queue *q, const char *tag, const char *file, int line, const char *filename)
{
__ao2_ref_debug(q, 1, tag, file, line, filename);
return q;
}

static inline struct call_queue *_queue_unref(struct call_queue *q, const char *tag, const char *file, int line, const char *filename)
{
if (q) {
__ao2_ref_debug(q, -1, tag, file, line, filename);
}
return NULL;
}

#else

#define queue_t_ref(q, tag) queue_ref(q)
#define queue_t_unref(q, tag) queue_unref(q)
#define queues_t_link(c, q, tag) ao2_t_link(c, q, tag)
#define queues_t_unlink(c, q, tag) ao2_t_unlink(c, q, tag)

static inline struct call_queue *queue_ref(struct call_queue *q)
static inline struct call_queue *_queue_ref(struct call_queue *q, const char *tag, const char *file, int line, const char *filename)
{
ao2_ref(q, 1);
__ao2_ref(q, 1, tag, file, line, filename);
return q;
}

static inline struct call_queue *queue_unref(struct call_queue *q)
static inline struct call_queue *_queue_unref(struct call_queue *q, const char *tag, const char *file, int line, const char *filename)
{
if (q) {
ao2_ref(q, -1);
__ao2_ref(q, -1, tag, file, line, filename);
}
return NULL;
}
#endif

/*! \brief Set variables of queue */
static void set_queue_variables(struct call_queue *q, struct ast_channel *chan)
Expand Down
2 changes: 1 addition & 1 deletion build_tools/cflags.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<member name="DEBUG_THREADS" displayname="Enable Thread Debugging">
<support_level>core</support_level>
</member>
<member name="REF_DEBUG" displayname="Enable reference count debugging">
<member name="REF_DEBUG" displayname="Enable reference count debugging by default">
<support_level>extended</support_level>
</member>
<member name="AO2_DEBUG" displayname="Enable internal Astobj2 debugging">
Expand Down
14 changes: 14 additions & 0 deletions build_tools/make_buildopts_h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ END
TMP=`${GREP} -e "^MENUSELECT_CFLAGS" menuselect.makeopts | sed 's/MENUSELECT_CFLAGS\=//g' | sed 's/-D//g'`
for x in ${TMP}; do
echo "#define ${x} 1"
if test "${x}" = "DONT_OPTIMIZE" \
-o "${x}" = "BETTER_BACKTRACES" \
-o "${x}" = "LOTS_OF_SPANS" \
-o "${x}" = "BUILD_NATIVE" \
-o "${x}" = "REF_DEBUG" \
-o "${x}" = "AO2_DEBUG" \
-o "${x}" = "REBUILD_PARSERS" \
-o "${x}" = "RADIO_RELAX" \
-o "${x}" = "DEBUG_SCHEDULER" \
-o "${x}" = "DETECT_DEADLOCKS" \
-o "${x}" = "DUMP_SCHEDULER" ; then
# These aren't ABI affecting options, keep them out of AST_BUILDOPTS
continue
fi
if test "x${BUILDOPTS}" != "x" ; then
BUILDOPTS="${BUILDOPTS}, ${x}"
else
Expand Down
12 changes: 6 additions & 6 deletions channels/chan_sip.c
Original file line number Diff line number Diff line change
Expand Up @@ -8599,9 +8599,9 @@ struct sip_pvt *__sip_alloc(ast_string_field callid, struct ast_sockaddr *addr,
{
struct sip_pvt *p;

p = __ao2_alloc_debug(sizeof(*p), sip_destroy_fn,
p = __ao2_alloc(sizeof(*p), sip_destroy_fn,
AO2_ALLOC_OPT_LOCK_MUTEX, "allocate a dialog(pvt) struct",
file, line, func, 1);
file, line, func);
if (!p) {
return NULL;
}
Expand Down Expand Up @@ -9178,7 +9178,7 @@ static struct sip_pvt *__find_call(struct sip_request *req, struct ast_sockaddr
struct sip_pvt tmp_dialog = {
.callid = callid,
};
sip_pvt_ptr = __ao2_find_debug(dialogs, &tmp_dialog, OBJ_POINTER,
sip_pvt_ptr = __ao2_find(dialogs, &tmp_dialog, OBJ_POINTER,
"find_call in dialogs", file, line, func);
if (sip_pvt_ptr) { /* well, if we don't find it-- what IS in there? */
/* Found the call */
Expand All @@ -9193,7 +9193,7 @@ static struct sip_pvt *__find_call(struct sip_request *req, struct ast_sockaddr
struct sip_pvt *fork_pvt = NULL;
struct match_req_args args = { 0, };
int found;
struct ao2_iterator *iterator = __ao2_callback_debug(dialogs,
struct ao2_iterator *iterator = __ao2_callback(dialogs,
OBJ_POINTER | OBJ_MULTIPLE,
dialog_find_multiple,
&tmp_dialog,
Expand Down Expand Up @@ -9243,7 +9243,7 @@ static struct sip_pvt *__find_call(struct sip_request *req, struct ast_sockaddr
/* This is likely a forked Request that somehow resulted in us receiving multiple parts of the fork.
* RFC 3261 section 8.2.2.2, Indicate that we want to merge requests by sending a 482 response. */
transmit_response_using_temp(callid, addr, 1, intended_method, req, "482 (Loop Detected)");
__ao2_ref_debug(sip_pvt_ptr, -1, "pvt did not match incoming SIP msg, unref from search.",
__ao2_ref(sip_pvt_ptr, -1, "pvt did not match incoming SIP msg, unref from search.",
file, line, func);
ao2_iterator_destroy(iterator);
dialog_unref(fork_pvt, "unref fork_pvt");
Expand All @@ -9255,7 +9255,7 @@ static struct sip_pvt *__find_call(struct sip_request *req, struct ast_sockaddr
/* fall through */
case SIP_REQ_NOT_MATCH:
default:
__ao2_ref_debug(sip_pvt_ptr, -1, "pvt did not match incoming SIP msg, unref from search",
__ao2_ref(sip_pvt_ptr, -1, "pvt did not match incoming SIP msg, unref from search",
file, line, func);
break;
}
Expand Down
1 change: 1 addition & 0 deletions configs/samples/asterisk.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ astsbindir => /usr/sbin
[options]
;verbose = 3
;debug = 3
;refdebug = yes ; Enable reference count debug logging.
;alwaysfork = yes ; Same as -F at startup.
;nofork = yes ; Same as -f at startup.
;quiet = yes ; Same as -q at startup.
Expand Down
6 changes: 2 additions & 4 deletions contrib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ clean:
include $(ASTTOPDIR)/Makefile.rules

install:
if [ -n "$(findstring REF_DEBUG,$(MENUSELECT_CFLAGS))" ]; then \
$(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/scripts"; \
$(INSTALL) -m 755 scripts/refcounter.py "$(DESTDIR)$(ASTDATADIR)/scripts/refcounter.py"; \
fi
$(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/scripts"; \
$(INSTALL) -m 755 scripts/refcounter.py "$(DESTDIR)$(ASTDATADIR)/scripts/refcounter.py"; \

uninstall:
rm -f "$(DESTDIR)$(ASTDATADIR)/scripts/refcounter.py"
4 changes: 2 additions & 2 deletions contrib/scripts/refcounter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
"""Process a ref debug log
This file will process a log file created by the REF_DEBUG
build option in Asterisk.
This file will process a log file created by enabling
the refdebug config option in asterisk.conf.
See http://www.asterisk.org for more information about
the Asterisk project. Please do not directly contact
Expand Down
Loading

0 comments on commit 5c1d07b

Please sign in to comment.