Cleanup and work on fixing test cases

This commit is contained in:
Jeremy 2023-07-04 07:54:31 -04:00
parent 1a1c0d9875
commit 323aeebe3e
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4
22 changed files with 115 additions and 86 deletions

View File

@ -4,6 +4,8 @@ on:
push:
pull_request:
# TODO: Test statically linked
jobs:
test-linux:
runs-on: ubuntu-22.04
@ -41,12 +43,12 @@ jobs:
-D${{matrix.symbols}}=On \
-D${{matrix.demangle}}=On \
-DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h \
-DCPPTRACE_BUILD_TEST=On
-DCPPTRACE_BUILD_TEST=On \
-DBUILD_SHARED_LIBS=On
make
- name: test
working-directory: build
run: |
#readelf --debug-dump=info test | grep foo
./test | python3 ../test/test.py "${{matrix.compiler}}"
test-windows:
runs-on: windows-2019
@ -86,7 +88,8 @@ jobs:
-D${{matrix.unwind}}=On `
-D${{matrix.symbols}}=On `
-D${{matrix.demangle}}=On `
-DCPPTRACE_BUILD_TEST=On
-DCPPTRACE_BUILD_TEST=On `
-DBUILD_SHARED_LIBS=On
msbuild .\cpptrace.sln
- name: test
working-directory: build
@ -116,7 +119,8 @@ jobs:
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DCPPTRACE_BACKTRACE_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/include/backtrace.h \
${{matrix.config}} \
-DCPPTRACE_BUILD_TEST=On
-DCPPTRACE_BUILD_TEST=On \
-DBUILD_SHARED_LIBS=On
make
- name: test
working-directory: build
@ -146,7 +150,8 @@ jobs:
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} `
-DCMAKE_CXX_STANDARD=${{matrix.std}} `
${{matrix.config}} `
-DCPPTRACE_BUILD_TEST=On
-DCPPTRACE_BUILD_TEST=On `
-DBUILD_SHARED_LIBS=On
msbuild .\cpptrace.sln
- name: test
working-directory: build

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ build
build2
a.out
test/build
repro*/

View File

@ -10,7 +10,7 @@ Make stack traces simple for once.
Support for MacOS and cygwin/mingw will be added soon.
*Some day C++23's `<stacktrace>` will be ubiquitous*
*Some day C++23's `<stacktrace>` will be ubiquitous, and maybe one day the msvc implementation will be acceptable*
## Table of contents

View File

@ -5,12 +5,12 @@
#include <vector>
#include <iostream>
#ifndef CPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE
#if !(defined(CPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE) || defined(CPPTRACE_FULL_TRACE_WITH_STACKTRACE))
#include "symbols/libcpp_symbols.hpp"
#include "unwind/libcpp_unwind.hpp"
#include "demangle/libcpp_demangle.hpp"
#include "platform/libcpp_common.hpp"
#include "symbols/cpptrace_symbols.hpp"
#include "unwind/cpptrace_unwind.hpp"
#include "demangle/cpptrace_demangle.hpp"
#include "platform/cpptrace_common.hpp"
namespace cpptrace {
CPPTRACE_FORCE_NO_INLINE
@ -31,8 +31,8 @@ namespace cpptrace {
// full trace
#include "full/libcpp_full_trace.hpp"
#include "demangle/libcpp_demangle.hpp"
#include "full/cpptrace_full_trace.hpp"
#include "demangle/cpptrace_demangle.hpp"
namespace cpptrace {
CPPTRACE_FORCE_NO_INLINE

View File

@ -1,5 +1,5 @@
#ifndef LIBCPP_DEMANGLE_HPP
#define LIBCPP_DEMANGLE_HPP
#ifndef CPPTRACE_DEMANGLE_HPP
#define CPPTRACE_DEMANGLE_HPP
#include <cpptrace/cpptrace.hpp>

View File

@ -1,7 +1,7 @@
#ifdef CPPTRACE_DEMANGLE_WITH_CXXABI
#include <cpptrace/cpptrace.hpp>
#include "libcpp_demangle.hpp"
#include "cpptrace_demangle.hpp"
#include <cxxabi.h>

View File

@ -1,7 +1,7 @@
#ifdef CPPTRACE_DEMANGLE_WITH_NOTHING
#include <cpptrace/cpptrace.hpp>
#include "libcpp_demangle.hpp"
#include "cpptrace_demangle.hpp"
#include <cstdlib>
#include <string>

View File

@ -1,8 +1,8 @@
#ifndef LIBCPP_FULL_TRACE_HPP
#define LIBCPP_FULL_TRACE_HPP
#ifndef CPPTRACE_FULL_TRACE_HPP
#define CPPTRACE_FULL_TRACE_HPP
#include <cpptrace/cpptrace.hpp>
#include "../platform/libcpp_common.hpp"
#include "../platform/cpptrace_common.hpp"
#include <cstddef>
#include <vector>

View File

@ -1,9 +1,9 @@
#ifdef CPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE
#include <cpptrace/cpptrace.hpp>
#include "libcpp_full_trace.hpp"
#include "../platform/libcpp_program_name.hpp"
#include "../platform/libcpp_common.hpp"
#include "cpptrace_full_trace.hpp"
#include "../platform/cpptrace_program_name.hpp"
#include "../platform/cpptrace_common.hpp"
#include <vector>
@ -50,7 +50,7 @@ namespace cpptrace {
static backtrace_state* state = nullptr;
static bool called = false;
if(!called) {
state = backtrace_create_state(program_name().c_str(), true, error_callback, nullptr);
state = backtrace_create_state(program_name(), true, error_callback, nullptr);
called = true;
}
return state;

View File

@ -1,8 +1,8 @@
#ifdef CPPTRACE_FULL_TRACE_WITH_STACKTRACE
#include <cpptrace/cpptrace.hpp>
#include "libcpp_full_trace.hpp"
#include "../platform/libcpp_common.hpp"
#include "cpptrace_full_trace.hpp"
#include "../platform/cpptrace_common.hpp"
#include <vector>
#include <stacktrace>

View File

@ -1,5 +1,5 @@
#ifndef LIBCPP_COMMON_HPP
#define LIBCPP_COMMON_HPP
#ifndef CPPTRACE_COMMON_HPP
#define CPPTRACE_COMMON_HPP
#ifdef _MSC_VER
#define CPPTRACE_FORCE_NO_INLINE __declspec(noinline)

View File

@ -0,0 +1,51 @@
#ifndef CPPTRACE_PROGRAM_NAME_HPP
#define CPPTRACE_PROGRAM_NAME_HPP
#include <string>
#ifdef _WIN32
#include <windows.h>
namespace cpptrace {
namespace detail {
inline std::string program_name() {
char buffer[MAX_PATH + 1];
int res = GetModuleFileNameA(nullptr, buffer, MAX_PATH);
if(res) {
return buffer;
} else {
return "";
}
}
}
}
#else
#include <linux/limits.h>
#include <unistd.h>
namespace cpptrace {
namespace detail {
inline const char* program_name() {
static std::string name;
static bool did_init = false;
static bool valid = false;
if(!did_init) {
did_init = true;
char buffer[PATH_MAX + 1];
ssize_t s = readlink("/proc/self/exe", buffer, PATH_MAX);
if(s == -1) {
return nullptr;
}
buffer[s] = 0;
name = buffer;
valid = true;
}
return valid ? name.c_str() : nullptr;
}
}
}
#endif
#endif

View File

@ -1,35 +0,0 @@
#ifndef LIBCPP_PROGRAM_NAME_HPP
#define LIBCPP_PROGRAM_NAME_HPP
#include <string>
#ifdef _WIN32
#include <windows.h>
namespace cpptrace {
namespace detail {
inline std::string program_name() {
char buffer[MAX_PATH + 1];
int res = GetModuleFileNameA(nullptr, buffer, MAX_PATH);
if(res) {
return buffer;
} else {
return "";
}
}
}
}
#else
namespace cpptrace {
namespace detail {
inline std::string program_name() {
return "";
}
}
}
#endif
#endif

View File

@ -1,5 +1,5 @@
#ifndef LIBCPP_SYMBOLS_HPP
#define LIBCPP_SYMBOLS_HPP
#ifndef CPPTRACE_SYMBOLS_HPP
#define CPPTRACE_SYMBOLS_HPP
#include <cpptrace/cpptrace.hpp>

View File

@ -1,8 +1,8 @@
#ifdef CPPTRACE_GET_SYMBOLS_WITH_DBGHELP
#include <cpptrace/cpptrace.hpp>
#include "libcpp_symbols.hpp"
#include "../platform/libcpp_program_name.hpp"
#include "cpptrace_symbols.hpp"
#include "../platform/cpptrace_program_name.hpp"
#include <memory>
#include <regex>

View File

@ -1,8 +1,8 @@
#ifdef CPPTRACE_GET_SYMBOLS_WITH_LIBBACKTRACE
#include <cpptrace/cpptrace.hpp>
#include "libcpp_symbols.hpp"
#include "../platform/libcpp_program_name.hpp"
#include "cpptrace_symbols.hpp"
#include "../platform/cpptrace_program_name.hpp"
#include <memory>
#include <vector>
@ -18,7 +18,7 @@ namespace cpptrace {
int full_callback(void* data, uintptr_t address, const char* file, int line, const char* symbol) {
stacktrace_frame& frame = *static_cast<stacktrace_frame*>(data);
if(line == 0) {
fprintf(stderr, "Getting bad data for some reason\n");
///fprintf(stderr, "Getting bad data for some reason\n"); // TODO: Eliminate
}
frame.address = address;
frame.line = line;
@ -37,7 +37,7 @@ namespace cpptrace {
void error_callback(void* data, const char* msg, int errnum) {
// nothing at the moment
fprintf(stderr, "Backtrace error %s %d %p\n", msg, errnum, data);
///fprintf(stderr, "Backtrace error %s %d %p\n", msg, errnum, data); // TODO: Eliminate
}
backtrace_state* get_backtrace_state() {
@ -45,7 +45,7 @@ namespace cpptrace {
static backtrace_state* state = nullptr;
static bool called = false;
if(!called) {
state = backtrace_create_state(program_name().c_str(), true, error_callback, nullptr);
state = backtrace_create_state(program_name(), true, error_callback, nullptr);
called = true;
}
return state;
@ -56,13 +56,15 @@ namespace cpptrace {
stacktrace_frame resolve_frame(void* addr) {
stacktrace_frame frame;
frame.col = -1;
if(!backtrace_pcinfo(
backtrace_pcinfo(
get_backtrace_state(),
reinterpret_cast<uintptr_t>(addr),
full_callback,
error_callback,
&frame
)) {
);
if(frame.symbol.empty()) {
// fallback, try to at least recover the symbol name with backtrace_syminfo
backtrace_syminfo(
get_backtrace_state(),
reinterpret_cast<uintptr_t>(addr),

View File

@ -1,8 +1,8 @@
#ifdef CPPTRACE_GET_SYMBOLS_WITH_NOTHING
#include <cpptrace/cpptrace.hpp>
#include "libcpp_symbols.hpp"
#include "../platform/libcpp_program_name.hpp"
#include "cpptrace_symbols.hpp"
#include "../platform/cpptrace_program_name.hpp"
#include <vector>

View File

@ -1,8 +1,8 @@
#ifndef LIBCPP_UNWIND_HPP
#define LIBCPP_UNWIND_HPP
#ifndef CPPTRACE_UNWIND_HPP
#define CPPTRACE_UNWIND_HPP
#include <cpptrace/cpptrace.hpp>
#include "../platform/libcpp_common.hpp"
#include "../platform/cpptrace_common.hpp"
#include <cstddef>

View File

@ -1,8 +1,8 @@
#ifdef CPPTRACE_UNWIND_WITH_EXECINFO
#include <cpptrace/cpptrace.hpp>
#include "libcpp_unwind.hpp"
#include "../platform/libcpp_common.hpp"
#include "cpptrace_unwind.hpp"
#include "../platform/cpptrace_common.hpp"
#include <algorithm>
#include <vector>

View File

@ -1,7 +1,7 @@
#ifdef CPPTRACE_UNWIND_WITH_NOTHING
#include <cpptrace/cpptrace.hpp>
#include "libcpp_unwind.hpp"
#include "cpptrace_unwind.hpp"
#include <vector>

View File

@ -1,8 +1,8 @@
#ifdef CPPTRACE_UNWIND_WITH_WINAPI
#include <cpptrace/cpptrace.hpp>
#include "libcpp_unwind.hpp"
#include "../platform/libcpp_common.hpp"
#include "cpptrace_unwind.hpp"
#include "../platform/cpptrace_common.hpp"
#include <vector>

View File

@ -22,6 +22,8 @@ def main():
output = sys.stdin.read()
print(output) # for debug reasons
if output.strip() == "":
print(f"Error: No output from test", file=sys.stderr)
sys.exit(1)
@ -47,8 +49,11 @@ def main():
break
if errored:
print("Test output:", file=sys.stderr)
print(raw_output, file=sys.stderr)
#print("Test output:", file=sys.stderr)
#print(raw_output, file=sys.stderr)
print("Test failed")
sys.exit(1)
else:
print("Test passed")
main()