-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
karm-base: Added backtrace collection api.
- Loading branch information
1 parent
5e171fd
commit 9ea85f7
Showing
7 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
#include <karm-base/backtrace.h> | ||
#include <karm-base/panic.h> | ||
#include <karm-sys/chan.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void __panicHandler(Karm::PanicKind kind, char const *msg) { | ||
fprintf(stderr, "%s: %s\n", kind == Karm::PanicKind::PANIC ? "panic" : "debug", msg); | ||
|
||
// NOTE: We hare calling backinto the framework here, it might cause another | ||
// panic, this is why we are keeping track of nested panics | ||
static isize _panicDepth = 1; | ||
_panicDepth++; | ||
if (_panicDepth == 1) { | ||
auto bt = Karm::Backtrace::capture(); | ||
if (bt.status() == Karm::Backtrace::Status::CAPTURED) | ||
Sys::println("backtrace:\n{}", bt); | ||
} | ||
|
||
if (kind == Karm::PanicKind::PANIC) { | ||
abort(); | ||
__builtin_unreachable(); | ||
} | ||
_panicDepth--; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "backtrace.h" | ||
|
||
#include "_embed.h" | ||
|
||
namespace Karm { | ||
|
||
Backtrace Backtrace::capture() { | ||
return _Embed::captureBacktrace(); | ||
} | ||
|
||
Backtrace Backtrace::forceCapture() { | ||
return _Embed::forceCaptureBacktrace(); | ||
} | ||
|
||
} // namespace Karm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "string.h" | ||
#include "vec.h" | ||
|
||
namespace Karm { | ||
|
||
struct Backtrace { | ||
struct Frame { | ||
String desc; | ||
String file; | ||
usize line; | ||
|
||
bool operator==(Frame const &other) const = default; | ||
|
||
auto operator<=>(Frame const &other) const = default; | ||
}; | ||
|
||
enum struct Status { | ||
UNSUPPORTED, | ||
DISABLED, | ||
CAPTURED, | ||
}; | ||
|
||
using enum Status; | ||
|
||
Vec<Frame> _frames; | ||
Status _status; | ||
|
||
Backtrace(Status status) : _status(status) {} | ||
|
||
static Backtrace capture(); | ||
|
||
static Backtrace forceCapture(); | ||
|
||
Slice<Frame> frames() const { | ||
return _frames; | ||
} | ||
|
||
Status status() const { | ||
return _status; | ||
} | ||
|
||
bool operator==(Backtrace const &other) const = default; | ||
|
||
auto operator<=>(Backtrace const &other) const = default; | ||
}; | ||
|
||
} // namespace Karm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters