From a9741c9cadcef7752ec0e1bcc0e1aba580477a5e Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 15 Jan 2020 03:58:41 +0300 Subject: split symbol.hpp --- src/symbol.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/symbol.cpp (limited to 'src/symbol.cpp') diff --git a/src/symbol.cpp b/src/symbol.cpp new file mode 100644 index 0000000..98ec427 --- /dev/null +++ b/src/symbol.cpp @@ -0,0 +1,57 @@ +// Copyright (c) 2020 Egor Tensin +// This file is part of the "PDB repository" project. +// For details, see https://github.com/egor-tensin/pdb-repo. +// Distributed under the MIT License. + +#include "pdb/all.hpp" + +#include + +#include +#include + +#include +#include +#include + +namespace pdb { +namespace { + +std::size_t calc_size(const SymbolInfo::Impl& impl) { + try { + return SafeInt{impl.SizeOfStruct} + impl.NameLen - 1; + } catch (const SafeIntException&) { + throw std::runtime_error{"invalid SYMBOL_INFO size"}; + } +} + +unsigned long cast_line_number(DWORD impl) { + unsigned long dest = 0; + + if (!SafeCast(impl, dest)) + throw std::runtime_error{"invalid line number"}; + + return dest; +} + +} // namespace + +SymbolInfo::SymbolInfo() : buffer{}, impl{*reinterpret_cast(buffer.data())} { + buffer.fill(0); + impl.SizeOfStruct = sizeof(Impl); + impl.MaxNameLen = MAX_SYM_NAME; +} + +SymbolInfo::SymbolInfo(const Impl& impl) : SymbolInfo{} { + if (impl.SizeOfStruct != sizeof(impl)) + throw std::runtime_error{"invalid SYMBOL_INFO.SizeOfStruct"}; + const auto impl_size = calc_size(impl); + if (impl_size > buffer.size()) + throw std::runtime_error{"SYMBOL_INFO is too large"}; + std::memcpy(buffer.data(), &impl, impl_size); +} + +LineInfo::LineInfo(const Impl& impl) + : file_path{impl.FileName}, line_number{cast_line_number(impl.LineNumber)} {} + +} // namespace pdb -- cgit v1.2.3