diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-19 05:31:58 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-19 05:31:58 +0300 |
commit | a8d767a99e4c09975503e092ee4674962b27c3ce (patch) | |
tree | 0d341e027a980981e8d719133f785d1eb5dbd702 /include/pdb/module.hpp | |
parent | add displacement to symbols (diff) | |
download | winapi-debug-a8d767a99e4c09975503e092ee4674962b27c3ce.tar.gz winapi-debug-a8d767a99e4c09975503e092ee4674962b27c3ce.zip |
refactoring
Diffstat (limited to 'include/pdb/module.hpp')
-rw-r--r-- | include/pdb/module.hpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/pdb/module.hpp b/include/pdb/module.hpp index 118a53b..3e785c4 100644 --- a/include/pdb/module.hpp +++ b/include/pdb/module.hpp @@ -12,6 +12,8 @@ #include <cstring> +#include <sstream> +#include <stdexcept> #include <string> namespace pdb @@ -59,7 +61,39 @@ namespace pdb Address get_online_base() const { return online_base; } + Address translate_offline_address(Address offline) const + { + if (offline < get_offline_base()) + throw std::range_error{invalid_offline_address(offline)}; + return offline - get_offline_base() + get_online_base(); + } + + Address translate_online_address(Address online) const + { + if (online < get_online_base()) + throw std::range_error{invalid_online_address(online)}; + return online - get_online_base() + get_offline_base(); + } + private: + std::string invalid_offline_address(Address offline) const + { + std::ostringstream oss; + oss << "offline address " << format_address(offline) + << " doesn't belong to module " << get_name() + << " (base offline address " << format_address(get_offline_base()) << ')'; + return oss.str(); + } + + std::string invalid_online_address(Address online) const + { + std::ostringstream oss; + oss << "online address " << format_address(online) + << " doesn't belong to module " << get_name() + << " (base online address " << format_address(get_online_base()) << ')'; + return oss.str(); + } + const Address online_base; }; } |