Skip to content

Commit

Permalink
error: Deprecate adbg_error_current
Browse files Browse the repository at this point in the history
Because it was a little on the unsafe side (ABI wise, if fields change), and required to know the structure layout, it is deprecated.

But I added _line(), _function(), and _code() to retrieve last error parameters. Which I find a lot safer.
  • Loading branch information
dd86k committed Oct 30, 2024
1 parent be58d19 commit 40531d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 2 additions & 4 deletions common/errormgmt.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ void print_error(const(char) *message, int code,
void print_error_adbg(
const(char)* mod = __FILE__.ptr, int line = __LINE__) {
debug printf("[%s@%d] ", mod, line);
const(adbg_error_t)* e = adbg_error_current();
print_error(adbg_error_message(), e.code, null, e.func, e.line);
print_error(adbg_error_message(), adbg_error_code(), null, adbg_error_function(), adbg_error_line());
}

void panic(int code, const(char)* message,
Expand All @@ -45,8 +44,7 @@ void panic_crt(const(char)* prefix = null, const(char)* mod = __MODULE__.ptr, in
panic(errno, strerror(errno), prefix, mod, line);
}
void panic_adbg(const(char)* prefix = null, const(char)* mod = __MODULE__.ptr) {
const(adbg_error_t)* e = adbg_error_current();
panic(adbg_errno(), adbg_error_message(), prefix, e.func, e.line);
panic(adbg_errno(), adbg_error_message(), prefix, adbg_error_function(), adbg_error_line());
}

void reset_error() {
Expand Down
12 changes: 12 additions & 0 deletions src/adbg/error.d
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ enum AdbgError {
libCapstone = 3002, /// Capstone
}

// TODO: Make adbg_error_t struct private after removing adbg_error_current()
/// Represents an error in alicedbg.
struct adbg_error_t {
int code; /// Error code
Expand All @@ -117,6 +118,16 @@ struct adbg_error_t {
/// Last error in alicedbg.
private __gshared adbg_error_t error;

int adbg_error_code() {
return error.code;
}
int adbg_error_line() {
return error.line;
}
const(char)* adbg_error_function() {
return error.func;
}

//TODO: Strongly consider string, provides .ptr and .length
private struct adbg_error_msg_t {
int code;
Expand Down Expand Up @@ -189,6 +200,7 @@ private immutable adbg_error_msg_t[] errors_msg = [
/// Returns: Pointer to the only error instance.
//TODO: Deprecate as dangerous
// Getting extra info such as source (string) and al. should be via functions
deprecated("Use adbg_error_function, adbg_error_line")
const(adbg_error_t)* adbg_error_current() {
return &error;
}
Expand Down

0 comments on commit 40531d8

Please sign in to comment.