From 1543d364f11defccaab2ed595b48457e582f1564 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Mon, 14 Feb 2011 05:47:35 -0800 Subject: [PATCH] assert.cc: some cleanup Signed-off-by: Colin McCabe --- src/common/assert.cc | 82 ++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/src/common/assert.cc b/src/common/assert.cc index dc3fedb8d9a4f..60bdef80cf61d 100644 --- a/src/common/assert.cc +++ b/src/common/assert.cc @@ -1,38 +1,62 @@ - -#include "include/assert.h" -#include "config.h" +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2008-2011 New Dream Network + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include #include "BackTrace.h" +#include "common/debug.h" +#include "config.h" +#include "include/assert.h" namespace ceph { + void __ceph_assert_fail(const char *assertion, const char *file, int line, const char *func) + { + // TODO: replace this with a trylock + DoutLocker _dout_locker; + + char buf[8096]; + BackTrace *bt = new BackTrace(1); + snprintf(buf, sizeof(buf), + "%s: In function '%s', in thread '%p'\n" + "%s: %d: FAILED assert(%s)\n", + file, func, (void*)pthread_self(), file, line, assertion); + dout_emergency(buf); + + // TODO: get rid of this memory allocation. + ostringstream oss; + bt->print(oss); + dout_emergency(oss.str()); + + snprintf(buf, sizeof(buf), + " NOTE: a copy of the executable, or `objdump -rdS ` " + "is needed to interpret this.\n"); + dout_emergency(oss.str()); -void __ceph_assert_fail(const char *assertion, const char *file, int line, const char *func) -{ - BackTrace *bt = new BackTrace(1); - - _dout_lock.Lock(); - *_dout << file << ": In function '" << func << "', " - << "In thread " << hex << pthread_self() << dec << std::endl; - *_dout << file << ":" << line << ": FAILED assert(" << assertion << ")" << std::endl; - bt->print(*_dout); - *_dout << " NOTE: a copy of the executable, or `objdump -rdS ` is needed to interpret this." << std::endl; - - _dout->flush(); - - if (1) { throw FailedAssertion(bt); - } else { - // make myself core dump. - char *p = 0; - while (1) - *p-- = 0; } -} - -void __ceph_assert_warn(const char *assertion, const char *file, - int line, const char *func) -{ - derr << "WARNING: assert(" << assertion << ") at: " << file << ":" << line << ": " << func << "()" << dendl; -} + void __ceph_assert_warn(const char *assertion, const char *file, + int line, const char *func) + { + // TODO: replace this with a trylock + DoutLocker _dout_locker; + + char buf[8096]; + snprintf(buf, sizeof(buf), + "WARNING: assert(%s) at: %s: %d: %s()\n", + assertion, file, line, func); + dout_emergency(buf); + } } -- 2.39.5