From 0bff1d2776e0da589dd98eca69e7f04fb07dfd02 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 14 Jan 2020 19:36:53 +0300 Subject: clang-format all the code --- include/pdb/symbol.hpp | 167 +++++++++++++++++++++---------------------------- 1 file changed, 73 insertions(+), 94 deletions(-) (limited to 'include/pdb/symbol.hpp') diff --git a/include/pdb/symbol.hpp b/include/pdb/symbol.hpp index ec0f80c..d9f3f0c 100644 --- a/include/pdb/symbol.hpp +++ b/include/pdb/symbol.hpp @@ -8,134 +8,113 @@ #include "address.hpp" #include "module.hpp" -#include - #include +#include #pragma warning(push, 0) #include #pragma warning(pop) #include #include - #include #include -namespace pdb -{ - class SymbolInfo - { - public: - typedef SYMBOL_INFO Raw; - - SymbolInfo() - : raw{*reinterpret_cast(buffer)} - { - raw.SizeOfStruct = sizeof(Raw); - raw.MaxNameLen = MAX_SYM_NAME; - } +namespace pdb { - explicit SymbolInfo(const Raw& raw) - : SymbolInfo{} - { - if (raw.SizeOfStruct != sizeof(raw)) - throw std::runtime_error{"invalid SYMBOL_INFO.SizeOfStruct"}; - const auto raw_size = calc_size(raw); - if (raw_size > sizeof(buffer)) - throw std::runtime_error{"SYMBOL_INFO is too large"}; - std::memcpy(buffer, &raw, raw_size); - } +class SymbolInfo { +public: + typedef SYMBOL_INFO Raw; - explicit operator Raw&() { return raw; } + SymbolInfo() : raw{*reinterpret_cast(buffer)} { + raw.SizeOfStruct = sizeof(Raw); + raw.MaxNameLen = MAX_SYM_NAME; + } - explicit operator const Raw&() const { return raw; } + explicit SymbolInfo(const Raw& raw) : SymbolInfo{} { + if (raw.SizeOfStruct != sizeof(raw)) + throw std::runtime_error{"invalid SYMBOL_INFO.SizeOfStruct"}; + const auto raw_size = calc_size(raw); + if (raw_size > sizeof(buffer)) + throw std::runtime_error{"SYMBOL_INFO is too large"}; + std::memcpy(buffer, &raw, raw_size); + } - Address get_displacement() const { return displacement; } + explicit operator Raw&() { return raw; } - void set_displacement(Address new_value) - { - displacement = new_value; - } + explicit operator const Raw&() const { return raw; } - std::string get_name() const { return {raw.Name, raw.NameLen}; } + Address get_displacement() const { return displacement; } - Address get_offline_base() const { return raw.ModBase; } + void set_displacement(Address new_value) { displacement = new_value; } - Address get_offline_address() const { return raw.Address; } + std::string get_name() const { return {raw.Name, raw.NameLen}; } - typedef ULONG Tag; + Address get_offline_base() const { return raw.ModBase; } - Tag get_tag() const { return raw.Tag; } + Address get_offline_address() const { return raw.Address; } - enum class Type : Tag - { - Function = SymTagFunction, - RESERVED = SymTagMax, - }; + typedef ULONG Tag; - Type get_type() const { return static_cast(get_tag()); } + Tag get_tag() const { return raw.Tag; } - bool is_function() const { return get_type() == Type::Function; } + enum class Type : Tag { + Function = SymTagFunction, + RESERVED = SymTagMax, + }; - private: - static constexpr std::size_t max_buffer_size = sizeof(Raw) + MAX_SYM_NAME - 1; + Type get_type() const { return static_cast(get_tag()); } - static std::size_t calc_size(const Raw& raw) - { - using namespace msl::utilities; - try - { - return SafeInt{raw.SizeOfStruct} + raw.NameLen - 1; - } - catch (const SafeIntException&) - { - throw std::runtime_error{"invalid SYMBOL_INFO size"}; - } + bool is_function() const { return get_type() == Type::Function; } + +private: + static constexpr std::size_t max_buffer_size = sizeof(Raw) + MAX_SYM_NAME - 1; + + static std::size_t calc_size(const Raw& raw) { + using namespace msl::utilities; + try { + return SafeInt{raw.SizeOfStruct} + raw.NameLen - 1; + } catch (const SafeIntException&) { + throw std::runtime_error{"invalid SYMBOL_INFO size"}; } + } - unsigned char buffer[max_buffer_size] = {0}; - Address displacement = 0; + unsigned char buffer[max_buffer_size] = {0}; + Address displacement = 0; - protected: - Raw& raw; - }; +protected: + Raw& raw; +}; - class Symbol : public SymbolInfo - { - public: - Symbol(Address online_address, const SymbolInfo& info) - : SymbolInfo{info} - , online_address{online_address} - { } +class Symbol : public SymbolInfo { +public: + Symbol(Address online_address, const SymbolInfo& info) + : SymbolInfo{info}, online_address{online_address} {} - Address get_online_address() const { return online_address; } + Address get_online_address() const { return online_address; } - private: - const Address online_address; - }; +private: + const Address online_address; +}; - class LineInfo - { - public: - typedef IMAGEHLP_LINE64 Raw; +class LineInfo { +public: + typedef IMAGEHLP_LINE64 Raw; - explicit LineInfo(const Raw& raw) - : file_path{raw.FileName} - , line_number{cast_line_number(raw.LineNumber)} - { } + explicit LineInfo(const Raw& raw) + : file_path{raw.FileName}, line_number{cast_line_number(raw.LineNumber)} {} - const std::string file_path; - const unsigned long line_number; + const std::string file_path; + const unsigned long line_number; - private: - static unsigned long cast_line_number(DWORD raw) - { - unsigned long dest = 0; +private: + static unsigned long cast_line_number(DWORD raw) { + unsigned long dest = 0; - if (!msl::utilities::SafeCast(raw, dest)) - throw std::runtime_error{"invalid line number"}; + if (!msl::utilities::SafeCast(raw, dest)) + throw std::runtime_error{"invalid line number"}; - return dest; - } - }; -} + return dest; + } +}; + +} // namespace pdb -- cgit v1.2.3