Fixed the god-awful indentation

This commit is contained in:
mathusummut
2018-05-06 00:01:36 +02:00
parent 643e3820f5
commit 35b7b1f1a6
459 changed files with 204893 additions and 217545 deletions

View File

@@ -49,7 +49,7 @@ using namespace std;
//occurred in a file where this header is included will have
//file and line number
static bool want_full_leak_stacktrace = false;
static bool want_full_leak_stacktrace = false;
static bool want_full_leak_stacktrace_line_numbers = false;
struct AllocInfo {
@@ -80,104 +80,102 @@ public:
: ptr(ptr), file(file), line(line), bytes(bytes), array(array), freetouse(false), inuse(true), stack(stacktrace) {
}
//#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
//#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
#if defined(HAS_GCC_BACKTRACE)
inline static int getFileAndLine(char *function, void *address, char *file, size_t flen) {
int line=-1;
if(want_full_leak_stacktrace_line_numbers == true && AllocInfo::get_application_binary() != "") {
const int maxbufSize = 8094;
char buf[maxbufSize+1]="";
//char *p=NULL;
int line = -1;
if (want_full_leak_stacktrace_line_numbers == true && AllocInfo::get_application_binary() != "") {
const int maxbufSize = 8094;
char buf[maxbufSize + 1] = "";
//char *p=NULL;
// prepare command to be executed
// our program need to be passed after the -e parameter
//sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr);
snprintf(buf, 8096,"addr2line -C -e %s -f -i %p",AllocInfo::get_application_binary().c_str(),address);
// prepare command to be executed
// our program need to be passed after the -e parameter
//sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr);
snprintf(buf, 8096, "addr2line -C -e %s -f -i %p", AllocInfo::get_application_binary().c_str(), address);
FILE* f = popen (buf, "r");
if (f == NULL) {
perror (buf);
return 0;
}
FILE* f = popen(buf, "r");
if (f == NULL) {
perror(buf);
return 0;
}
if(function != NULL && function[0] != '\0') {
line = 0;
for(;function != NULL && function[0] != '\0';) {
// get function name
char *ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return line;
}
//printf("Looking for [%s] Found [%s]\n",function,ret);
if(strstr(ret,function) != NULL) {
break;
}
// get file and line
ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return line;
}
if(strlen(buf) > 0 && buf[0] != '?') {
//int l;
char *p = buf;
// file name is until ':'
while(*p != 0 && *p != ':') {
p++;
}
*p++ = 0;
// after file name follows line number
strcpy (file , buf);
sscanf (p,"%d", &line);
}
else {
strcpy (file,"unknown");
line = 0;
}
if (function != NULL && function[0] != '\0') {
line = 0;
for (; function != NULL && function[0] != '\0';) {
// get function name
char *ret = fgets(buf, maxbufSize, f);
if (ret == NULL) {
pclose(f);
return line;
}
}
// get file and line
char *ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return line;
}
if(strlen(buf) > 0 && buf[0] != '?') {
//int l;
char *p = buf;
// file name is until ':'
while(*p != 0 && *p != ':') {
p++;
//printf("Looking for [%s] Found [%s]\n",function,ret);
if (strstr(ret, function) != NULL) {
break;
}
*p++ = 0;
// after file name follows line number
strcpy (file , buf);
sscanf (p,"%d", &line);
}
else {
strcpy (file,"unknown");
line = 0;
// get file and line
ret = fgets(buf, maxbufSize, f);
if (ret == NULL) {
pclose(f);
return line;
}
if (strlen(buf) > 0 && buf[0] != '?') {
//int l;
char *p = buf;
// file name is until ':'
while (*p != 0 && *p != ':') {
p++;
}
*p++ = 0;
// after file name follows line number
strcpy(file, buf);
sscanf(p, "%d", &line);
} else {
strcpy(file, "unknown");
line = 0;
}
}
}
// get file and line
char *ret = fgets(buf, maxbufSize, f);
if (ret == NULL) {
pclose(f);
}
return line;
return line;
}
if (strlen(buf) > 0 && buf[0] != '?') {
//int l;
char *p = buf;
// file name is until ':'
while (*p != 0 && *p != ':') {
p++;
}
*p++ = 0;
// after file name follows line number
strcpy(file, buf);
sscanf(p, "%d", &line);
} else {
strcpy(file, "unknown");
line = 0;
}
pclose(f);
}
return line;
}
#endif
inline static string getStackTrace() {
//#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
//#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
#if defined(HAS_GCC_BACKTRACE)
if(want_full_leak_stacktrace == true) {
string errMsg = "\nStack Trace:\n";
if (want_full_leak_stacktrace == true) {
string errMsg = "\nStack Trace:\n";
//errMsg += "To find line #'s use:\n";
//errMsg += "readelf --debug-dump=decodedline %s | egrep 0xaddress-of-stack\n";
@@ -191,9 +189,9 @@ public:
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(stack_depth > 0) {
char szBuf[8096]="";
for(size_t i = 1; i < stack_depth; i++) {
if (stack_depth > 0) {
char szBuf[8096] = "";
for (size_t i = 1; i < stack_depth; i++) {
void *lineAddress = stack_addrs[i]; //getStackAddress(stackIndex);
size_t sz = 8096; // just a guess, template names will go much wider
@@ -207,8 +205,7 @@ public:
for (char *j = stack_strings[i]; *j; ++j) {
if (*j == '(') {
begin = j;
}
else if (*j == '+') {
} else if (*j == '+') {
end = j;
}
}
@@ -222,31 +219,29 @@ public:
if (ret) {
// return value may be a realloc() of the input
function = ret;
}
else {
} else {
// demangling failed, just pretend it's a C function with no args
strncpy(function, begin, sz);
strncat(function, "()", sz);
function[sz-1] = '\0';
function[sz - 1] = '\0';
}
//fprintf(out, " %s:%s\n", stack.strings[i], function);
snprintf(szBuf,8096,"%s:%s address [%p]",stack_strings[i],function,lineAddress);
}
else {
snprintf(szBuf, 8096, "%s:%s address [%p]", stack_strings[i], function, lineAddress);
} else {
// didn't find the mangled name, just print the whole line
//fprintf(out, " %s\n", stack.strings[i]);
snprintf(szBuf,8096,"%s address [%p]",stack_strings[i],lineAddress);
snprintf(szBuf, 8096, "%s address [%p]", stack_strings[i], lineAddress);
}
errMsg += string(szBuf);
if(want_full_leak_stacktrace_line_numbers == true && AllocInfo::get_application_binary() != "") {
char file[8096]="";
if (want_full_leak_stacktrace_line_numbers == true && AllocInfo::get_application_binary() != "") {
char file[8096] = "";
int line = getFileAndLine(function, lineAddress, file, 8096);
if(line >= 0) {
char lineBuf[1024]="";
snprintf(lineBuf,1024,"%d",line);
if (line >= 0) {
char lineBuf[1024] = "";
snprintf(lineBuf, 1024, "%d", line);
errMsg += " line: " + string(lineBuf);
}
}
@@ -259,14 +254,13 @@ public:
//printf("%s",errMsg.c_str());
return errMsg;
}
else {
static string empty = "";
return empty;
}
} else {
static string empty = "";
return empty;
}
#else
static string empty = "";
return empty;
static string empty = "";
return empty;
#endif
}
};
@@ -277,7 +271,7 @@ public:
class AllocRegistry {
private:
static const size_t maxAllocs= 100000;
static const size_t maxAllocs = 100000;
Mutex *mutex;
private:
@@ -308,13 +302,13 @@ public:
}
inline void reset() {
allocCount= 0;
allocBytes= 0;
nonMonitoredCount= 0;
nonMonitoredBytes= 0;
allocCount = 0;
allocBytes = 0;
nonMonitoredCount = 0;
nonMonitoredBytes = 0;
nextFreeIndex = 0;
for(int i = 0; i < maxAllocs; ++i) {
for (int i = 0; i < maxAllocs; ++i) {
allocs[i].freetouse = true;
allocs[i].inuse = false;
}
@@ -326,14 +320,14 @@ public:
MutexSafeWrapper safeMutexMasterList(mutex);
//printf("ALLOCATE.\tfile: %s, line: %d, bytes: " MG_SIZE_T_SPECIFIER ", array: %d inuse: %d\n", info.file, info.line, info.bytes, info.array, info.inuse);
if(info.line > 0) {
if (info.line > 0) {
++allocCount;
allocBytes += info.bytes;
}
for(int i = (nextFreeIndex >= 0 ? nextFreeIndex : 0); i < maxAllocs; ++i) {
if(allocs[i].freetouse == true && allocs[i].inuse == false) {
allocs[i]= info;
nextFreeIndex=-1;
for (int i = (nextFreeIndex >= 0 ? nextFreeIndex : 0); i < maxAllocs; ++i) {
if (allocs[i].freetouse == true && allocs[i].inuse == false) {
allocs[i] = info;
nextFreeIndex = -1;
return;
}
@@ -342,26 +336,26 @@ public:
printf("ALLOCATE NOT MONITORED.\tfile: %s, line: %d, ptr [%p], bytes: " MG_SIZE_T_SPECIFIER ", array: %d inuse: %d, \n%s\n", info.file, info.line, info.ptr, info.bytes, info.array, info.inuse, info.stack.c_str());
++nonMonitoredCount;
nonMonitoredBytes+= info.bytes;
nonMonitoredBytes += info.bytes;
}
inline void deallocate(void* ptr, bool array,const char* file, int line) {
inline void deallocate(void* ptr, bool array, const char* file, int line) {
//if(line == 0) return;
MutexSafeWrapper safeMutexMasterList(mutex);
for(int i=0; i < maxAllocs; ++i) {
if(allocs[i].freetouse == false && allocs[i].inuse == true &&
allocs[i].ptr == ptr && allocs[i].array == array) {
allocs[i].freetouse= true;
for (int i = 0; i < maxAllocs; ++i) {
if (allocs[i].freetouse == false && allocs[i].inuse == true &&
allocs[i].ptr == ptr && allocs[i].array == array) {
allocs[i].freetouse = true;
allocs[i].inuse = false;
nextFreeIndex=i;
nextFreeIndex = i;
return;
}
}
if(line > 0) printf("WARNING, possible error on pointer delete for ptr [%p] array = %d, file [%s] line: %d\n%s\n",ptr,array,file, line,AllocInfo::getStackTrace().c_str());
if (line > 0) printf("WARNING, possible error on pointer delete for ptr [%p] array = %d, file [%s] line: %d\n%s\n", ptr, array, file, line, AllocInfo::getStackTrace().c_str());
}
void dump(const char *path);
@@ -370,7 +364,7 @@ public:
//if an allocation ocurrs in a file where "leaks_dumper.h" is not included
//this operator new is called and file and line will be unknown
inline void * operator new (size_t bytes) {
void *ptr= malloc(bytes);
void *ptr = malloc(bytes);
AllocRegistry::getInstance().allocate(AllocInfo(ptr, "unknown", 0, "", bytes, false));
return ptr;
}
@@ -381,7 +375,7 @@ inline void operator delete(void *ptr) {
}
inline void * operator new[](size_t bytes) {
void *ptr= malloc(bytes);
void *ptr = malloc(bytes);
AllocRegistry::getInstance().allocate(AllocInfo(ptr, "unknown", 0, "", bytes, true));
return ptr;
}
@@ -394,7 +388,7 @@ inline void operator delete [](void *ptr) {
//if an allocation ocurrs in a file where "leaks_dumper.h" is included
//this operator new is called and file and line will be known
inline void * operator new (size_t bytes, const char* file, int line, string stack) {
void *ptr= malloc(bytes);
void *ptr = malloc(bytes);
AllocRegistry::getInstance().allocate(AllocInfo(ptr, file, line, stack, bytes, false));
return ptr;
}
@@ -404,8 +398,8 @@ inline void operator delete(void *ptr, const char* file, int line) {
free(ptr);
}
inline void * operator new[](size_t bytes, const char* file, int line,string stack) {
void *ptr= malloc(bytes);
inline void * operator new[](size_t bytes, const char* file, int line, string stack) {
void *ptr = malloc(bytes);
AllocRegistry::getInstance().allocate(AllocInfo(ptr, file, line, stack, bytes, true));
return ptr;
}