aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/utils/pdb_descr.hpp
blob: 5925b937c7a91f8d87be59156c72f5af55939a48 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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 <winapi/debug.hpp>

#include <boost/program_options.hpp>

#include <sstream>
#include <string>
#include <vector>

struct PDB {
    winapi::Address online_base;
    std::string path;

    static PDB parse(std::string src) {
        static constexpr auto sep = ',';

        const auto sep_pos = src.find(sep);
        if (sep_pos == std::string::npos)
            boost::throw_exception(boost::program_options::invalid_option_value{src});

        winapi::Address online_base;
        if (!winapi::parse_address(online_base, src.substr(0, sep_pos)))
            boost::throw_exception(boost::program_options::invalid_option_value{src});

        return {online_base, src.substr(sep_pos + 1)};
    }

    static winapi::Address parse_address(const std::string& src) {
        winapi::Address dest;
        if (!winapi::parse_address(dest, src))
            boost::throw_exception(boost::program_options::invalid_option_value{src});
        return dest;
    }
};

template <typename charT>
void validate(boost::any& dest,
              const std::vector<std::basic_string<charT>>& src_tokens,
              PDB*,
              int) {
    namespace po = boost::program_options;
    po::validators::check_first_occurrence(dest);
    const auto& src_token = po::validators::get_single_string(src_tokens);
    dest = boost::any{PDB::parse(src_token)};
}

template <typename charT>
void validate(boost::any& dest,
              const std::vector<std::basic_string<charT>>& src_tokens,
              winapi::Address*,
              int) {
    namespace po = boost::program_options;
    po::validators::check_first_occurrence(dest);
    const auto& src_token = po::validators::get_single_string(src_tokens);
    dest = boost::any{PDB::parse_address(src_token)};
}