diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-16 01:21:58 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-16 01:21:58 +0300 |
commit | de5c928779d69e22221d08c21ce3b5455157004e (patch) | |
tree | 50ac3106f4fd91c5c900540596bed8b1c5db807d | |
parent | use error reporting from winapi-common (diff) | |
download | winapi-debug-de5c928779d69e22221d08c21ce3b5455157004e.tar.gz winapi-debug-de5c928779d69e22221d08c21ce3b5455157004e.zip |
export pdb::file to winapi-common's File
m--------- | 3rdparty/winapi/common | 0 | ||||
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | include/pdb/all.hpp | 1 | ||||
-rw-r--r-- | include/pdb/repo.hpp | 5 | ||||
-rw-r--r-- | include/pdb/utils/file.hpp | 52 | ||||
-rw-r--r-- | src/dbghelp.cpp | 3 | ||||
-rw-r--r-- | src/repo.cpp | 4 | ||||
-rw-r--r-- | src/utils/file.cpp | 64 |
8 files changed, 11 insertions, 130 deletions
diff --git a/3rdparty/winapi/common b/3rdparty/winapi/common -Subproject 8deb061efcfc33f5606d6a39e565a6779ccc2a1 +Subproject 23aa1a5c37677a38873dc627f4b8077e0390f42 diff --git a/CMakeLists.txt b/CMakeLists.txt index 081e8e2..1a80fec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,20 +34,14 @@ file(GLOB_RECURSE winapi_debug_src "src/*.cpp") add_library(winapi_debug ${winapi_debug_include} ${winapi_debug_src}) target_compile_definitions(winapi_debug PUBLIC _NO_CVCONST_H) target_include_directories(winapi_debug PUBLIC include/) -target_link_libraries(winapi_debug PRIVATE winapi_common winapi_utf8) +target_link_libraries(winapi_debug + PUBLIC winapi_common + PRIVATE winapi_utf8) target_link_libraries(winapi_debug PUBLIC Boost::boost PRIVATE Boost::disable_autolinking) target_link_libraries(winapi_debug PRIVATE dbghelp) -if(MINGW) - # FILE_ID_INFO and friends require at least 0x0602: - message("MINGW") - target_compile_definitions(winapi_debug PUBLIC - NTDDI_VERSION=NTDDI_WIN8 - _WIN32_WINNT=_WIN32_WINNT_WIN8) -endif() - if(MSVC_VERSION EQUAL 1900) # DbgHelp warnings on Visual Studio 2015: target_compile_options(winapi_debug PUBLIC /wd4091) diff --git a/include/pdb/all.hpp b/include/pdb/all.hpp index 0f02c98..3e6c3e8 100644 --- a/include/pdb/all.hpp +++ b/include/pdb/all.hpp @@ -13,4 +13,3 @@ #include "process.hpp" #include "repo.hpp" #include "symbol.hpp" -#include "utils/file.hpp" diff --git a/include/pdb/repo.hpp b/include/pdb/repo.hpp index 571a164..3b194ff 100644 --- a/include/pdb/repo.hpp +++ b/include/pdb/repo.hpp @@ -9,7 +9,8 @@ #include "dbghelp.hpp" #include "module.hpp" #include "symbol.hpp" -#include "utils/file.hpp" + +#include <winapi/file.hpp> #include <functional> #include <map> @@ -49,7 +50,7 @@ private: const DbgHelp dbghelp{DbgHelp::post_mortem()}; - std::unordered_set<file::ID> file_ids; + std::unordered_set<winapi::File::ID> file_ids; std::map<Address, Module> online_bases; std::map<Address, const Module&> offline_bases; }; diff --git a/include/pdb/utils/file.hpp b/include/pdb/utils/file.hpp deleted file mode 100644 index 44d3d5f..0000000 --- a/include/pdb/utils/file.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2017 Egor Tensin <Egor.Tensin@gmail.com> -// This file is part of the "winapi-debug" project. -// For details, see https://github.com/egor-tensin/winapi-debug. -// Distributed under the MIT License. - -#pragma once - -#include <boost/functional/hash.hpp> - -#include <windows.h> - -#include <cstddef> -#include <cstring> -#include <functional> -#include <string> - -namespace pdb { -namespace file { - -std::size_t get_size(const std::string&); - -inline bool operator==(const FILE_ID_128& a, const FILE_ID_128& b) { - return 0 == std::memcmp(a.Identifier, b.Identifier, sizeof(a.Identifier)); -} - -struct ID { - const FILE_ID_INFO raw; - - bool operator==(const ID& other) const { - return raw.VolumeSerialNumber == other.raw.VolumeSerialNumber && - raw.FileId == other.raw.FileId; - } -}; - -ID query_id(const std::string&); - -} // namespace file -} // namespace pdb - -namespace std { - -template <> -struct hash<pdb::file::ID> { - std::size_t operator()(const pdb::file::ID& id) const { - std::size_t seed = 0; - boost::hash_combine(seed, id.raw.VolumeSerialNumber); - boost::hash_combine(seed, id.raw.FileId.Identifier); - return seed; - } -}; - -} // namespace std diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp index fb94835..d42c900 100644 --- a/src/dbghelp.cpp +++ b/src/dbghelp.cpp @@ -6,6 +6,7 @@ #include <pdb/all.hpp> #include <winapi/error.hpp> +#include <winapi/file.hpp> #include <winapi/utf8.hpp> #include <dbghelp.h> @@ -127,7 +128,7 @@ ModuleInfo DbgHelp::load_pdb(const std::string& path) const { DWORD size = 0; { - const auto raw_size = file::get_size(path); + const auto raw_size = winapi::File::open_read_attributes(path).get_size(); if (raw_size > std::numeric_limits<decltype(size)>::max()) throw std::range_error{"PDB file is too large"}; size = static_cast<decltype(size)>(raw_size); diff --git a/src/repo.cpp b/src/repo.cpp index af56373..610ef9a 100644 --- a/src/repo.cpp +++ b/src/repo.cpp @@ -5,6 +5,8 @@ #include <pdb/all.hpp> +#include <winapi/file.hpp> + #include <map> #include <sstream> #include <stdexcept> @@ -89,7 +91,7 @@ Address Repo::add_pdb(Address online_base, const std::string& path) { if (online_bases.find(online_base) != online_bases.cend()) throw std::runtime_error{pdb_already_loaded(online_base, path)}; - auto file_id = file::query_id(path); + auto file_id = winapi::File::open_read_attributes(path).query_id(); if (file_ids.find(file_id) != file_ids.cend()) throw std::runtime_error{pdb_already_loaded(path)}; diff --git a/src/utils/file.cpp b/src/utils/file.cpp deleted file mode 100644 index fdc695f..0000000 --- a/src/utils/file.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2017 Egor Tensin <Egor.Tensin@gmail.com> -// This file is part of the "winapi-debug" project. -// For details, see https://github.com/egor-tensin/winapi-debug. -// Distributed under the MIT License. - -#include <pdb/all.hpp> - -#include <winapi/error.hpp> -#include <winapi/utf8.hpp> - -#include <windows.h> - -#include <cstddef> -#include <cstdint> -#include <stdexcept> -#include <string> - -namespace pdb { -namespace file { - -std::size_t get_size(const std::string& path) { - const Handle handle{CreateFileW(winapi::widen(path).c_str(), - FILE_READ_ATTRIBUTES, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL)}; - - if (handle.get() == INVALID_HANDLE_VALUE) - throw winapi::error::windows(GetLastError(), "CreateFileW"); - - LARGE_INTEGER size; - - if (!GetFileSizeEx(handle.get(), &size)) - throw winapi::error::windows(GetLastError(), "GetFileSizeEx"); - - if (size.QuadPart < 0 || size.QuadPart > SIZE_MAX) - throw std::runtime_error{"invalid file size"}; - return static_cast<std::size_t>(size.QuadPart); -} - -ID query_id(const std::string& path) { - const Handle handle{CreateFileW(winapi::widen(path).c_str(), - FILE_READ_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL)}; - - if (handle.get() == INVALID_HANDLE_VALUE) - throw winapi::error::windows(GetLastError(), "CreateFileW"); - - FILE_ID_INFO id; - - if (!GetFileInformationByHandleEx(handle.get(), FileIdInfo, &id, sizeof(id))) - throw winapi::error::windows(GetLastError(), "GetFileInformationByHandleEx"); - - return {id}; -} - -} // namespace file -} // namespace pdb |