Skip to content

Commit

Permalink
feat(telemetry): print stacktrace on CUBOS_FAIL
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 27, 2024
1 parent 0494afb commit 620da88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Handle body rotation on physics integration (#1242, **&fallenatlas**).
- Binary Serializer and Deserializer (#1306, **@RiscadoA**).
- Type Client and Type Server (#1302, **@RiscadoA**).
- Print stacktrace with *cpptrace* on calls to CUBOS_FAIL (#1172, **@RiscadoA**).

### Fixed

Expand Down
8 changes: 5 additions & 3 deletions core/include/cubos/core/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#pragma once

#include <cstdlib>

#include <cubos/core/memory/buffer_stream.hpp>
#include <cubos/core/reflection/reflect.hpp>

Expand Down Expand Up @@ -172,7 +170,7 @@
{ \
CUBOS_CRITICAL("" __VA_ARGS__); \
} \
std::abort(); \
::cubos::core::abort(); \
} while (false)

/// @brief Marks a code path as supposedly unreachable. Aborts the program when reached.
Expand Down Expand Up @@ -238,6 +236,10 @@

namespace cubos::core
{
/// @brief Aborts the program and prints a pretty stack trace.
/// @ingroup core
[[noreturn]] void abort();

/// @brief Singleton which holds the logging state.
/// @ingroup core
class CUBOS_CORE_API Logger final
Expand Down
8 changes: 8 additions & 0 deletions core/src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <mutex>
#include <vector>

#include <cpptrace/cpptrace.hpp>

#include <cubos/core/data/fs/file.hpp>
#include <cubos/core/data/fs/file_system.hpp>
#include <cubos/core/data/fs/standard_archive.hpp>
Expand Down Expand Up @@ -88,6 +90,12 @@ static const char* levelColor(Logger::Level level)
}
}

void cubos::core::abort()

Check warning on line 93 in core/src/log.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/log.cpp#L93

Added line #L93 was not covered by tests
{
cpptrace::generate_trace(1).print();
std::abort();

Check warning on line 96 in core/src/log.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/log.cpp#L95-L96

Added lines #L95 - L96 were not covered by tests
}

std::string Logger::Location::string() const
{
// Extract the file name.
Expand Down

0 comments on commit 620da88

Please sign in to comment.