1.4.10 updates

This commit is contained in:
WolverinDEV
2020-02-28 11:24:02 +01:00
parent 51d9a002e3
commit fd8aba2ede
8 changed files with 119 additions and 437 deletions
-119
View File
@@ -1,119 +0,0 @@
#include <execinfo.h> // for backtrace
#include <string>
#include <sstream>
#include <functional>
#include <src/log/LogUtils.h>
#include "TraceUtils.h"
#include "../../../music/providers/shared/pstream.h"
#define READ_BUFFER_SIZE 128
namespace TraceUtils {
static bool addr2line_present = true;
inline std::string addr2lineInfo(StackTraceElement *element) {
if(!addr2line_present)
return "??\n??:0";
char buffer[READ_BUFFER_SIZE];
sprintf(buffer, "addr2line -Cif -e %s %p", element->file.c_str(), element->offset); //last parameter is the name of this app
redi::pstream stream(buffer, redi::pstream::pstdout | redi::pstream::pstderr);
std::string result;
std::string error;
do {
auto read = stream.err().readsome(buffer, READ_BUFFER_SIZE);
if(read > 0) error += string(buffer, read);
read = stream.out().readsome(buffer, READ_BUFFER_SIZE);
if(read > 0) result += string(buffer, read);
} while(stream.good());
if(!error.empty()) {
while(!error.empty() && (error.back() == '\n' || error.back() == '\r')) error = error.substr(0, error.length() - 1);
logError("Could not resolve symbols. (Error: " + error + ")");
addr2line_present = false;
return "??\n??:0";
}
return result;
}
void StackTrace::printStackTrace() {
printStackTrace([](StackTraceElement* e) {
cerr << " at "+e->getFunctionName()+"( " + e->getSourceFile() + ":" + to_string(e->getSourceLine()) + ")" << endl;
});
}
void StackTrace::printStackTrace(std::function<void(StackTraceElement*)> writeMessage) {
for (int i = 0; i < stackSize; i++) {
writeMessage((StackTraceElement*) elements[i]);
}
}
StackTrace backTrace(int size) {
int backtraceLength;
void *buffer[BT_BUF_SIZE];
char **symbols;
backtraceLength = backtrace(buffer, BT_BUF_SIZE);
symbols = backtrace_symbols(buffer, backtraceLength);
if (symbols == nullptr) {
perror("backtrace_symbols");
exit(EXIT_FAILURE);
}
StackTrace out(backtraceLength);
for (int i = 0; i < backtraceLength; i++) {
auto sym = std::string(symbols[i]);
string file = "undefined";
if (sym.find_first_of('(') != std::string::npos) file = sym.substr(0, sym.find_first_of('('));
out.elements[i] = new StackTraceElement{i, buffer[i], file, sym};
}
free(symbols);
return out;
}
StackTrace::StackTrace(int size) : stackSize(size), elements(static_cast<const StackTraceElement **>(malloc(size * sizeof(void *)))) {}
StackTrace::~StackTrace() {
for (int i = 0; i < this->stackSize; i++)
if (this->elements[i]) delete this->elements[i];
free(this->elements);
}
void StackTraceElement::loadSymbols() {
if (this->symbolLoadState == 0) {
auto strInfo = addr2lineInfo(this);
this->fnName = strInfo.substr(0, strInfo.find_first_of('\n'));
auto srcInfo = strInfo.substr(strInfo.find_first_of('\n') + 1);
this->srcFile = srcInfo.substr(0, srcInfo.find_first_of(':'));
this->srcLine = atoi(srcInfo.substr(srcInfo.find_first_of(':') + 1).c_str());
this->symbolLoadState = 1;
}
}
string StackTraceElement::getFunctionName() {
loadSymbols();
return this->fnName;
}
string StackTraceElement::getSourceFile() {
loadSymbols();
return this->srcFile;
}
int StackTraceElement::getSourceLine() {
loadSymbols();
return this->srcLine;
}
StackTraceElement::StackTraceElement(int elementIndex, void *offset, string file, string symbol) : elementIndex(elementIndex), offset(offset), file(file), symbol(symbol) {}
}
-56
View File
@@ -1,56 +0,0 @@
#pragma once
#include <string>
#include <stdio.h>
#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#define BT_BUF_SIZE 100
using namespace std;
namespace TraceUtils {
struct StackTraceElement {
public:
StackTraceElement(int elementIndex, void *offset,string file,string symbol);
int elementIndex;
void *offset;
string file;
string symbol;
string getFunctionName();
string getSourceFile();
int getSourceLine();
private:
int symbolLoadState = 0;
string fnName;
string srcFile;
int srcLine;
void loadSymbols();
};
struct StackTrace {
public:
explicit StackTrace(int size);
~StackTrace();
const StackTraceElement** elements;
const int stackSize;
void printStackTrace();
void printStackTrace(std::function<void(StackTraceElement*)> format);
};
extern StackTrace backTrace(int size);
};
+13 -14
View File
@@ -1,17 +1,16 @@
#define NO_OPEN_SSL
#include "./digest.h"
#ifdef NO_OPEN_SSL
#include <tomcrypt.h>
#include <tomcrypt.h>
#define DECLARE_DIGEST(name, digestLength) \
void digest::tomcrypt::name(const char* input, size_t length, uint8_t* result) { \
hash_state hash{}; \
\
name ##_init(&hash); \
name ##_process(&hash, (uint8_t*) input, (unsigned long) length); \
name ##_done(&hash, result); \
}
#define DECLARE_DIGEST(name, digestLength) \
void digest::tomcrypt::name(const char* input, size_t length, uint8_t* result) { \
hash_state hash{}; \
\
name ##_init(&hash); \
name ##_process(&hash, (uint8_t*) input, (unsigned long) length); \
name ##_done(&hash, result); \
}
DECLARE_DIGEST(sha1, SHA_DIGEST_LENGTH)
DECLARE_DIGEST(sha256, SHA256_DIGEST_LENGTH)
DECLARE_DIGEST(sha512, SHA512_DIGEST_LENGTH)
#endif
DECLARE_DIGEST(sha1, SHA_DIGEST_LENGTH)
DECLARE_DIGEST(sha256, SHA256_DIGEST_LENGTH)
DECLARE_DIGEST(sha512, SHA512_DIGEST_LENGTH)
-1
View File
@@ -35,7 +35,6 @@
inline void name(const char* input, size_t length, uint8_t* result) { \
tomcrypt::name(input, length, result); \
}
#else
#include <openssl/sha.h>
+1 -1
View File
@@ -67,7 +67,7 @@ namespace memtrack {
inline std::string as_mangled() {
#ifndef WIN32
int status;
std::unique_ptr<char[], void (*)(void*)> result(abi::__cxa_demangle(name, 0, 0, &status), std::free);
std::unique_ptr<char[], void (*)(void*)> result(abi::__cxa_demangle(name, nullptr, nullptr, &status), std::free);
if(status != 0)
return "error: " + to_string(status);