blob: 87cc56a364f471b9b1adfdcebff7b64094a04744 (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright (c) 2017 Egor Tensin <Egor.Tensin@gmail.com>
// 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 "command_line.hpp"
#include "pdb/all.hpp"
#include <boost/program_options.hpp>
#include <exception>
#include <iostream>
#include <string>
#include <vector>
namespace {
class EnumSymbols : public SettingsParser {
public:
explicit EnumSymbols(const std::string& argv0) : SettingsParser{argv0} {
namespace po = boost::program_options;
visible.add_options()("pdb",
po::value<std::vector<std::string>>(&pdbs)->value_name("PATH"),
"load a PDB file");
visible.add_options()(
"functions",
po::value<pdb::symbol::Tag>(&tag)->implicit_value(function_tag)->zero_tokens(),
"only list functions");
}
const char* get_short_description() const override {
return "[-h|--help] [--pdb PATH]... [--functions]";
}
std::vector<std::string> pdbs;
bool type_specified() const { return tag != reserved_tag; }
pdb::Symbol::Type get_type() const { return static_cast<pdb::Symbol::Type>(tag); }
private:
static constexpr auto reserved_tag = static_cast<pdb::symbol::Tag>(pdb::Symbol::Type::RESERVED);
static constexpr auto function_tag = static_cast<pdb::symbol::Tag>(pdb::Symbol::Type::Function);
pdb::symbol::Tag tag = reserved_tag;
};
constexpr pdb::symbol::Tag EnumSymbols::reserved_tag;
constexpr pdb::symbol::Tag EnumSymbols::function_tag;
} // namespace
int main(int argc, char* argv[]) {
try {
EnumSymbols settings{argv[0]};
try {
settings.parse(argc, argv);
} catch (const boost::program_options::error& e) {
settings.usage_error(e);
return 1;
}
if (settings.exit_with_usage) {
settings.usage();
return 0;
}
pdb::DbgHelp dbghelp;
for (const auto& pdb : settings.pdbs) {
const auto id = dbghelp.load_pdb(pdb);
dbghelp.enum_symbols(id, [&](const pdb::SymbolInfo& symbol) {
if (!settings.type_specified() || settings.get_type() == symbol.get_type())
std::cout << symbol.get_name() << '\n';
});
}
} catch (const std::exception& e) {
std::cerr << "error: " << e.what() << '\n';
return 1;
}
return 0;
}
|