From c80d04fe521bbae68c142d885516294085f5089d Mon Sep 17 00:00:00 2001 From: firesgc Date: Sat, 25 Jan 2025 11:55:54 +0100 Subject: [PATCH] Add GetLastError() and switch to unordered_map --- src/platform/dbghelp_syminit_manager.cpp | 4 ++-- src/platform/dbghelp_syminit_manager.hpp | 4 ++-- src/symbols/symbols_with_dbghelp.cpp | 4 ++-- src/unwind/unwind_with_dbghelp.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/platform/dbghelp_syminit_manager.cpp b/src/platform/dbghelp_syminit_manager.cpp index 2b4dc39..3acb576 100644 --- a/src/platform/dbghelp_syminit_manager.cpp +++ b/src/platform/dbghelp_syminit_manager.cpp @@ -7,7 +7,7 @@ #include "utils/error.hpp" #include "utils/microfmt.hpp" -#include +#include #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)) { diff --git a/src/platform/dbghelp_syminit_manager.hpp b/src/platform/dbghelp_syminit_manager.hpp index e569dda..db8c24e 100644 --- a/src/platform/dbghelp_syminit_manager.hpp +++ b/src/platform/dbghelp_syminit_manager.hpp @@ -1,14 +1,14 @@ #ifndef DBGHELP_SYMINIT_MANAGER_HPP #define DBGHELP_SYMINIT_MANAGER_HPP -#include +#include 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 cache; + std::unordered_map cache; ~dbghelp_syminit_manager(); void* init(void* proc); diff --git a/src/symbols/symbols_with_dbghelp.cpp b/src/symbols/symbols_with_dbghelp.cpp index c3a6eae..b01d1f2 100644 --- a/src/symbols/symbols_with_dbghelp.cpp +++ b/src/symbols/symbols_with_dbghelp.cpp @@ -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) { diff --git a/src/unwind/unwind_with_dbghelp.cpp b/src/unwind/unwind_with_dbghelp.cpp index 66c4e86..30a268a 100644 --- a/src/unwind/unwind_with_dbghelp.cpp +++ b/src/unwind/unwind_with_dbghelp.cpp @@ -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) {