Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed May 21, 2024
1 parent 1c97343 commit f0c359a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 36 deletions.
2 changes: 1 addition & 1 deletion bee/crash/handler_linux.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <bee/crash/allocator.h>
#include <bee/crash/handler_linux.h>
#include <bee/crash/nanoid.h>
#include <bee/crash/stacktrace_linux.h>
#include <bee/crash/stacktrace.h>
#include <bee/crash/unwind_linux.h>
#include <errno.h>
#include <fcntl.h>
Expand Down
2 changes: 1 addition & 1 deletion bee/crash/handler_win.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <bee/crash/handler_win.h>
#include <bee/crash/nanoid.h>
#include <bee/crash/stacktrace_win.h>
#include <bee/crash/stacktrace.h>
#include <bee/crash/unwind_win.h>
#include <bee/win/wtf8.h>
#include <io.h>
Expand Down
File renamed without changes.
36 changes: 18 additions & 18 deletions bee/crash/stacktrace_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace bee::crash {
}

struct address_finder {
asymbol **syms;
asymbol **syms = NULL;
bfd_vma pc;
const char *filename;
const char *functionname;
Expand Down Expand Up @@ -51,7 +51,6 @@ namespace bee::crash {
const char *file;
bfd_vma address;
bfd_vma base;

static int iter(struct dl_phdr_info *info, size_t size, void *data) noexcept {
struct module_finder *f = (struct module_finder *)data;
ElfW(Addr) load_base = info->dlpi_addr;
Expand All @@ -67,7 +66,6 @@ namespace bee::crash {
}
return 0;
}

static module_finder find(bfd_vma pc) noexcept {
struct module_finder f = { .address = pc };
dl_iterate_phdr(module_finder::iter, &f);
Expand All @@ -79,26 +77,27 @@ namespace bee::crash {
}
};

static void address_to_string(const char *modulename, bfd_vma addr, strbuilder &sb) noexcept {
static bool address_to_string(const char *modulename, bfd_vma addr, strbuilder &sb) noexcept {
bfd *abfd = bfd_openr(modulename, NULL);
if (abfd == NULL) {
exit(1);
return false;
}
if (bfd_check_format(abfd, bfd_archive)) {
exit(1);
return false;
}
char **matching;
if (!bfd_check_format_matches(abfd, bfd_object, &matching)) {
exit(1);
return false;
}
address_finder f;
if ((bfd_get_file_flags(abfd) & HAS_SYMS) != 0) {
unsigned int size;
long symcount = bfd_read_minisymbols(abfd, false, (void **)&f.syms, &size);
if (symcount == 0)
if (symcount == 0) {
symcount = bfd_read_minisymbols(abfd, true, (void **)&f.syms, &size);
}
if (symcount < 0) {
exit(1);
return false;
}
}

Expand Down Expand Up @@ -134,19 +133,12 @@ namespace bee::crash {
#else
strbuilder_append(sb, f.functionname);
#endif
} else {
constexpr size_t max_num = 32;
sb.expansion(max_num);
const int ret = std::snprintf(sb.remaining_data(), max_num + 1, "[0x%llx]", (long long unsigned int)addr);
if (ret <= 0) {
std::abort();
}
sb.append(ret);
}
if (f.syms != NULL) {
free(f.syms);
}
bfd_close(abfd);
return f.found;
}

struct stacktrace_impl {
Expand All @@ -165,7 +157,15 @@ namespace bee::crash {
}
sb.append(ret);
auto f = module_finder::find((bfd_vma)pc);
address_to_string(f.file, f.address, sb);
if (!address_to_string(f.file, f.address, sb)) {
constexpr size_t max_num = 32;
sb.expansion(max_num);
const int ret = std::snprintf(sb.remaining_data(), max_num + 1, "[0x%llx]", (long long unsigned int)(f.base + f.address));
if (ret <= 0) {
std::abort();
}
sb.append(ret);
}
sb += "\n";
}
std::string to_string() noexcept {
Expand Down
2 changes: 1 addition & 1 deletion bee/crash/stacktrace_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <DbgEng.h>
#include <DbgHelp.h>
#include <bee/crash/stacktrace_win.h>
#include <bee/crash/stacktrace.h>
#include <bee/crash/strbuilder.h>
#include <bee/utility/span.h>

Expand Down
15 changes: 0 additions & 15 deletions bee/crash/stacktrace_win.h

This file was deleted.

0 comments on commit f0c359a

Please sign in to comment.