Add GetLastError() and switch to unordered_map

This commit is contained in:
firesgc 2025-01-25 11:55:54 +01:00
parent efc63cb49f
commit c80d04fe52
4 changed files with 8 additions and 8 deletions

View File

@ -7,7 +7,7 @@
#include "utils/error.hpp"
#include "utils/microfmt.hpp"
#include <map>
#include <unordered_map>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
@ -38,7 +38,7 @@ namespace detail {
}
HANDLE duplicated_handle = nullptr;
if (!DuplicateHandle(proc, proc, proc, &duplicated_handle , 0, FALSE, DUPLICATE_SAME_ACCESS)) {
throw internal_error("DuplicateHandle failed");
throw internal_error("DuplicateHandle failed {}", GetLastError());
}
if(!SymInitialize(duplicated_handle , NULL, TRUE)) {

View File

@ -1,14 +1,14 @@
#ifndef DBGHELP_SYMINIT_MANAGER_HPP
#define DBGHELP_SYMINIT_MANAGER_HPP
#include <map>
#include <unordered_map>
namespace cpptrace {
namespace detail {
struct dbghelp_syminit_manager {
// The set below contains Windows `HANDLE` objects, `void*` is used to avoid
// including the (expensive) Windows header here
std::map<void*, void*> cache;
std::unordered_map<void*, void*> cache;
~dbghelp_syminit_manager();
void* init(void* proc);

View File

@ -433,10 +433,10 @@ namespace dbghelp {
duplicated_handle = get_syminit_manager().init(proc);
} else {
if (!DuplicateHandle(proc, proc, proc, &duplicated_handle , 0, FALSE, DUPLICATE_SAME_ACCESS)) {
throw internal_error("DuplicateHandle failed");
throw internal_error("DuplicateHandle failed {}", GetLastError());
}
if(!SymInitialize(duplicated_handle , NULL, TRUE)) {
throw internal_error("SymInitialize failed");
throw internal_error("SymInitialize failed {}", GetLastError());
}
}
for(const auto frame : frames) {

View File

@ -110,10 +110,10 @@ namespace detail {
duplicated_handle = get_syminit_manager().init(proc);
} else {
if (!DuplicateHandle(proc, proc, proc, &duplicated_handle , 0, FALSE, DUPLICATE_SAME_ACCESS)) {
throw internal_error("DuplicateHandle failed");
throw internal_error("DuplicateHandle failed{}", GetLastError());
}
if(!SymInitialize(duplicated_handle , NULL, TRUE)) {
throw internal_error("SymInitialize failed");
throw internal_error("SymInitialize failed{}", GetLastError());
}
}
while(trace.size() < max_depth) {