Commit 27493a6d authored by Scott Snyder's avatar Scott Snyder Committed by Graeme Stewart
Browse files

Work around apparent cling inconsistency in application of NDEBUG. (CxxUtils-00-01-48)

	* Tagging CxxUtils-00-01-48.
	* CxxUtils/Array.icc: Work around apparent cling inconsistency in
	application of NDEBUG: use UNUSED instead of #ifndef NDEBUG.

2015-04-21  scott snyder  <snyder@bnl.gov>

	* Tagging CxxUtils-00-01-47.
	* test/pointer_list_test.cxx: Fix gcc5 compilation warning.

2015-03-16  scott snyder  <snyder@bnl.gov>

	* Tagging CxxUtils-00-01-46.
	* Root/FloatPacker.cxx (min_int): Avoid undefined behavior in bit
	shifting.
	* CxxUtils/procmaps.h, Root/procmaps.cxx: Work correctly on
	64-bit platforms.
	* test/stacktrace_test.cxx: Fix for compatibility with address
	sanitizer.
parent c12870de
......@@ -13,6 +13,7 @@
*/
#include "CxxUtils/unused.h"
#include <cassert>
......@@ -277,11 +278,7 @@ std::vector<unsigned int> Array<0>::shape() const
* will always return 1.
*/
inline
unsigned int Array<0>::size (unsigned int
#ifndef NDEBUG
dim
#endif
/*=0*/) const
unsigned int Array<0>::size (unsigned int UNUSED(dim) /*=0*/) const
{
assert (dim == 0);
return 1;
......
......@@ -18,8 +18,8 @@ class procmaps {
public:
struct Entry {
Entry(const char* line);
unsigned int begAddress;
unsigned int endAddress;
unsigned long begAddress;
unsigned long endAddress;
bool readable;
bool writable;
bool executable;
......
......@@ -102,7 +102,7 @@ int max_int (int nbits)
inline
int min_int (int nbits)
{
return ((-1 << nbits) >> 1);
return static_cast<int>(~0U << nbits) >> 1;
}
......
......@@ -19,7 +19,7 @@ procmaps::Entry::Entry(const char* procMapsLine) :
char pageProts[5];
memset(pageProts,' ', 4);
sscanf(procMapsLine,
"%8x-%8x %4s %x %2x:%2x %x %31s",
"%lx-%lx %4s %x %2x:%2x %x %31s",
&this->begAddress,
&this->endAddress,
pageProts,
......
......@@ -24,7 +24,7 @@ using namespace CxxUtils;
size_t toerase[] = {
0, 1, 5, 14, 15, 16, 17, 20, 29, 30, 31, 500
};
size_t n_toerase = sizeof (toerase) / sizeof (toerase[0]);
const size_t n_toerase = sizeof (toerase) / sizeof (toerase[0]);
void testerase (pointer_list<>& l,
......
......@@ -88,6 +88,8 @@ void dumptrace (FILE* fp)
fseek (fp, 0, SEEK_SET);
char buf[65536];
while (fgets (buf, sizeof (buf), fp)) {
if (strstr (buf, "libasan") != nullptr)
continue;
filter (buf);
fputs (buf, stdout);
}
......@@ -96,15 +98,18 @@ void dumptrace (FILE* fp)
bool initialized = false;
bool initializing = false;
bool finishing = false;
bool nomalloc = false;
void *(*old_malloc)(size_t size);
void (*old_free)(void* ptr);
void *(*old_realloc)(void* ptr, size_t size);
void initpointers()
{
initializing = true;
old_malloc = (void* (*)(size_t)) (unsigned long) dlsym(RTLD_NEXT, "__libc_malloc");
old_free = (void (*)(void*)) (unsigned long) dlsym(RTLD_NEXT, "__libc_free");
old_realloc = (void* (*)(void*, size_t)) (unsigned long) dlsym(RTLD_NEXT, "__libc_realloc");
initialized = true;
initializing = false;
......@@ -148,6 +153,35 @@ void* __libc_malloc (size_t size)
}
void do_free (void* ptr)
{
if (!initialized) {
if (initializing)
return;
initpointers();
}
if (finishing)
return;
(*old_free) (ptr);
}
void free (void* ptr)
#ifndef __APPLE__
throw()
#endif
{
return do_free (ptr);
}
void __libc_free (void* ptr)
{
return do_free (ptr);
}
void* do_realloc (void* ptr, size_t size)
{
if (!initialized) {
......@@ -179,6 +213,7 @@ void* __libc_realloc (void* ptr, size_t size)
}
// Used to check that we don't call malloc during the stack trace.
void sethooks()
{
......@@ -214,5 +249,6 @@ int main()
initpointers();
Athena::DebugAids::setStackTraceAddr2Line ("/usr/bin/addr2line");
fromhere();
finishing = true;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment