aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/utils
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-01-14 19:36:53 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-01-14 20:07:47 +0300
commit0bff1d2776e0da589dd98eca69e7f04fb07dfd02 (patch)
treef7f8b905a34133d80e93d20770bdb092c04e247d /utils
parentclang-format: don't BinPackArguments (diff)
downloadwinapi-debug-0bff1d2776e0da589dd98eca69e7f04fb07dfd02.tar.gz
winapi-debug-0bff1d2776e0da589dd98eca69e7f04fb07dfd02.zip
clang-format all the code
Diffstat (limited to 'utils')
-rw-r--r--utils/addr2name.cpp163
-rw-r--r--utils/command_line.hpp44
-rw-r--r--utils/enum_symbols.cpp94
-rw-r--r--utils/name2addr.cpp96
-rw-r--r--utils/pdb_descr.hpp59
5 files changed, 182 insertions, 274 deletions
diff --git a/utils/addr2name.cpp b/utils/addr2name.cpp
index 87206f2..fe749b8 100644
--- a/utils/addr2name.cpp
+++ b/utils/addr2name.cpp
@@ -4,9 +4,8 @@
// Distributed under the MIT License.
#include "command_line.hpp"
-#include "pdb_descr.hpp"
-
#include "pdb/all.hpp"
+#include "pdb_descr.hpp"
#pragma warning(push, 0)
#include <boost/program_options.hpp>
@@ -18,113 +17,89 @@
#include <string>
#include <vector>
-namespace
-{
- class Addr2Name : public SettingsParser
- {
- public:
- explicit Addr2Name(const std::string& argv0)
- : SettingsParser{argv0}
- {
- visible.add_options()
- ("pdb",
- boost::program_options::value<std::vector<PDB>>(&pdbs)
- ->value_name("ADDR,PATH"),
- "load a PDB file")
- ("lines,l",
- boost::program_options::bool_switch(&lines),
- "try to resolve source files & line numbers");
- hidden.add_options()
- ("address",
- boost::program_options::value<std::vector<pdb::Address>>(&addresses)
- ->value_name("ADDR"),
- "add an address to resolve");
- positional.add("address", -1);
- }
-
- const char* get_short_description() const override
- {
- return "[-h|--help] [--pdb ADDR,PATH]... [--] [ADDR]...";
- }
-
- std::vector<PDB> pdbs;
- std::vector<pdb::Address> addresses;
- bool lines = false;
- };
-
- std::string format_symbol(const pdb::Module& module, const pdb::Symbol& symbol)
- {
- std::ostringstream oss;
- oss << module.get_name() << '!' << symbol.get_name();
- const auto displacement = symbol.get_displacement();
- if (displacement)
- oss << '+' << pdb::format_address(displacement);
- return oss.str();
+namespace {
+
+class Addr2Name : public SettingsParser {
+public:
+ explicit Addr2Name(const std::string& argv0) : SettingsParser{argv0} {
+ namespace po = boost::program_options;
+
+ visible.add_options()(
+ "pdb", po::value<std::vector<PDB>>(&pdbs)->value_name("ADDR,PATH"), "load a PDB file");
+ visible.add_options()(
+ "lines,l", po::bool_switch(&lines), "try to resolve source files & line numbers");
+ hidden.add_options()("address",
+ po::value<std::vector<pdb::Address>>(&addresses)->value_name("ADDR"),
+ "add an address to resolve");
+ positional.add("address", -1);
}
- std::string format_line_info(const pdb::LineInfo& line_info)
- {
- std::ostringstream oss;
- oss << '[' << line_info.file_path << " @ " << line_info.line_number << ']';
- return oss.str();
+ const char* get_short_description() const override {
+ return "[-h|--help] [--pdb ADDR,PATH]... [--] [ADDR]...";
}
- void dump_error(const std::exception& e)
- {
- std::cerr << "error: " << e.what() << '\n';
- }
+ std::vector<PDB> pdbs;
+ std::vector<pdb::Address> addresses;
+ bool lines = false;
+};
+
+std::string format_symbol(const pdb::Module& module, const pdb::Symbol& symbol) {
+ std::ostringstream oss;
+ oss << module.get_name() << '!' << symbol.get_name();
+ const auto displacement = symbol.get_displacement();
+ if (displacement)
+ oss << '+' << pdb::format_address(displacement);
+ return oss.str();
+}
- void resolve_symbol(const pdb::Repo& repo, pdb::Address address, bool lines = false)
- {
- try
- {
- const auto symbol = repo.resolve_symbol(address);
- const auto& module = repo.module_with_offline_base(symbol.get_offline_base());
-
- std::ostringstream msg;
- msg << format_symbol(module, symbol);
-
- if (lines)
- {
- try
- {
- const auto line_info = repo.resolve_line(address);
- msg << ' ' << format_line_info(line_info);
- }
- catch (const std::exception& e)
- {
- dump_error(e);
- }
- }
+std::string format_line_info(const pdb::LineInfo& line_info) {
+ std::ostringstream oss;
+ oss << '[' << line_info.file_path << " @ " << line_info.line_number << ']';
+ return oss.str();
+}
- std::cout << msg.str() << '\n';
- }
- catch (const std::exception& e)
- {
- dump_error(e);
- std::cout << pdb::format_address(address) << '\n';
+void dump_error(const std::exception& e) {
+ std::cerr << "error: " << e.what() << '\n';
+}
+
+void resolve_symbol(const pdb::Repo& repo, pdb::Address address, bool lines = false) {
+ try {
+ const auto symbol = repo.resolve_symbol(address);
+ const auto& module = repo.module_with_offline_base(symbol.get_offline_base());
+
+ std::ostringstream msg;
+ msg << format_symbol(module, symbol);
+
+ if (lines) {
+ try {
+ const auto line_info = repo.resolve_line(address);
+ msg << ' ' << format_line_info(line_info);
+ } catch (const std::exception& e) {
+ dump_error(e);
+ }
}
+
+ std::cout << msg.str() << '\n';
+ } catch (const std::exception& e) {
+ dump_error(e);
+ std::cout << pdb::format_address(address) << '\n';
}
}
-int main(int argc, char* argv[])
-{
- try
- {
+} // namespace
+
+int main(int argc, char* argv[]) {
+ try {
Addr2Name settings{argv[0]};
- try
- {
+ try {
settings.parse(argc, argv);
- }
- catch (const boost::program_options::error& e)
- {
+ } catch (const boost::program_options::error& e) {
settings.usage_error(e);
return 1;
}
- if (settings.exit_with_usage)
- {
+ if (settings.exit_with_usage) {
settings.usage();
return 0;
}
@@ -136,9 +111,7 @@ int main(int argc, char* argv[])
for (const auto& address : settings.addresses)
resolve_symbol(repo, address, settings.lines);
- }
- catch (const std::exception& e)
- {
+ } catch (const std::exception& e) {
dump_error(e);
return 1;
}
diff --git a/utils/command_line.hpp b/utils/command_line.hpp
index 352c210..c991e4a 100644
--- a/utils/command_line.hpp
+++ b/utils/command_line.hpp
@@ -15,35 +15,25 @@
#include <ostream>
#include <string>
-class SettingsParser
-{
+class SettingsParser {
public:
- explicit SettingsParser(const std::string& argv0)
- : prog_name{extract_filename(argv0)}
- {
- visible.add_options()
- ("help,h",
- "show this message and exit");
+ explicit SettingsParser(const std::string& argv0) : prog_name{extract_filename(argv0)} {
+ visible.add_options()("help,h", "show this message and exit");
}
virtual ~SettingsParser() = default;
- virtual const char* get_short_description() const
- {
- return "[--option VALUE]...";
- }
+ virtual const char* get_short_description() const { return "[--option VALUE]..."; }
- virtual void parse(int argc, char* argv[])
- {
+ virtual void parse(int argc, char* argv[]) {
boost::program_options::options_description all;
all.add(hidden).add(visible);
boost::program_options::variables_map vm;
- boost::program_options::store(
- boost::program_options::command_line_parser{argc, argv}
- .options(all)
- .positional(positional)
- .run(),
- vm);
+ boost::program_options::store(boost::program_options::command_line_parser{argc, argv}
+ .options(all)
+ .positional(positional)
+ .run(),
+ vm);
if (vm.count("help"))
exit_with_usage = true;
else
@@ -52,13 +42,9 @@ public:
bool exit_with_usage = false;
- void usage() const
- {
- std::cout << *this;
- }
+ void usage() const { std::cout << *this; }
- void usage_error(const std::exception& e) const
- {
+ void usage_error(const std::exception& e) const {
std::cerr << "usage error: " << e.what() << '\n';
std::cerr << *this;
}
@@ -69,15 +55,13 @@ protected:
boost::program_options::positional_options_description positional;
private:
- static std::string extract_filename(const std::string& path)
- {
+ static std::string extract_filename(const std::string& path) {
return boost::filesystem::path{path}.filename().string();
}
const std::string prog_name;
- friend std::ostream& operator<<(std::ostream& os, const SettingsParser& parser)
- {
+ friend std::ostream& operator<<(std::ostream& os, const SettingsParser& parser) {
const auto short_descr = parser.get_short_description();
os << "usage: " << parser.prog_name << ' ' << short_descr << '\n';
os << parser.visible;
diff --git a/utils/enum_symbols.cpp b/utils/enum_symbols.cpp
index 8fa0960..0759dd6 100644
--- a/utils/enum_symbols.cpp
+++ b/utils/enum_symbols.cpp
@@ -4,9 +4,8 @@
// Distributed under the MIT License.
#include "command_line.hpp"
-#include "pdb_descr.hpp"
-
#include "pdb/all.hpp"
+#include "pdb_descr.hpp"
#pragma warning(push, 0)
#include <boost/program_options.hpp>
@@ -17,88 +16,67 @@
#include <string>
#include <vector>
-namespace
-{
- class EnumSymbols : public SettingsParser
- {
- public:
- explicit EnumSymbols(const std::string& argv0)
- : SettingsParser{argv0}
- {
- visible.add_options()
- ("pdb",
- boost::program_options::value<std::vector<PDB>>(&pdbs)
- ->value_name("ADDR,PATH"),
- "load a PDB file")
- ("functions",
- boost::program_options::value<pdb::Symbol::Tag>(&tag)
- ->implicit_value(function_tag)
- ->zero_tokens(),
- "only list functions");
- }
+namespace {
- const char* get_short_description() const override
- {
- return "[-h|--help] [--pdb ADDR,PATH]... [--functions]";
- }
+class EnumSymbols : public SettingsParser {
+public:
+ explicit EnumSymbols(const std::string& argv0) : SettingsParser{argv0} {
+ namespace po = boost::program_options;
- std::vector<PDB> pdbs;
+ visible.add_options()(
+ "pdb", po::value<std::vector<PDB>>(&pdbs)->value_name("ADDR,PATH"), "load a PDB file");
+ visible.add_options()(
+ "functions",
+ po::value<pdb::Symbol::Tag>(&tag)->implicit_value(function_tag)->zero_tokens(),
+ "only list functions");
+ }
- bool type_specified() const
- {
- return tag != reserved_tag;
- }
+ const char* get_short_description() const override {
+ return "[-h|--help] [--pdb ADDR,PATH]... [--functions]";
+ }
- pdb::Symbol::Type get_type() const
- {
- return static_cast<pdb::Symbol::Type>(tag);
- }
+ std::vector<PDB> pdbs;
- private:
- static const auto reserved_tag = static_cast<pdb::Symbol::Tag>(pdb::Symbol::Type::RESERVED);
- static const auto function_tag = static_cast<pdb::Symbol::Tag>(pdb::Symbol::Type::Function);
+ bool type_specified() const { return tag != reserved_tag; }
- pdb::Symbol::Tag tag = reserved_tag;
- };
-}
+ pdb::Symbol::Type get_type() const { return static_cast<pdb::Symbol::Type>(tag); }
+
+private:
+ static const auto reserved_tag = static_cast<pdb::Symbol::Tag>(pdb::Symbol::Type::RESERVED);
+ static const auto function_tag = static_cast<pdb::Symbol::Tag>(pdb::Symbol::Type::Function);
+
+ pdb::Symbol::Tag tag = reserved_tag;
+};
-int main(int argc, char* argv[])
-{
- try
- {
+} // namespace
+
+int main(int argc, char* argv[]) {
+ try {
EnumSymbols settings{argv[0]};
- try
- {
+ try {
settings.parse(argc, argv);
- }
- catch (const boost::program_options::error& e)
- {
+ } catch (const boost::program_options::error& e) {
settings.usage_error(e);
return 1;
}
- if (settings.exit_with_usage)
- {
+ if (settings.exit_with_usage) {
settings.usage();
return 0;
}
pdb::Repo repo;
- for (const auto& pdb : settings.pdbs)
- {
+ for (const auto& pdb : settings.pdbs) {
const auto id = repo.add_pdb(pdb.online_base, pdb.path);
- repo.enum_symbols(id, [&] (const pdb::Symbol& symbol)
- {
+ repo.enum_symbols(id, [&](const pdb::Symbol& symbol) {
if (!settings.type_specified() || settings.get_type() == symbol.get_type())
std::cout << symbol.get_name() << '\n';
});
}
- }
- catch (const std::exception& e)
- {
+ } catch (const std::exception& e) {
std::cerr << "error: " << e.what() << '\n';
return 1;
}
diff --git a/utils/name2addr.cpp b/utils/name2addr.cpp
index 22c637b..f5b3b26 100644
--- a/utils/name2addr.cpp
+++ b/utils/name2addr.cpp
@@ -4,9 +4,8 @@
// Distributed under the MIT License.
#include "command_line.hpp"
-#include "pdb_descr.hpp"
-
#include "pdb/all.hpp"
+#include "pdb_descr.hpp"
#pragma warning(push, 0)
#include <boost/program_options.hpp>
@@ -17,74 +16,57 @@
#include <string>
#include <vector>
-namespace
-{
- class Name2Addr : public SettingsParser
- {
- public:
- explicit Name2Addr(const std::string& argv0)
- : SettingsParser{argv0}
- {
- visible.add_options()
- ("pdb",
- boost::program_options::value<std::vector<PDB>>(&pdbs)
- ->value_name("ADDR,PATH"),
- "load a PDB file");
- hidden.add_options()
- ("name",
- boost::program_options::value<std::vector<std::string>>(&names)
- ->value_name("NAME"),
- "add a name to resolve");
- positional.add("name", -1);
- }
+namespace {
- const char* get_short_description() const override
- {
- return "[-h|--help] [--pdb ADDR,PATH]... [--] [NAME]...";
- }
+class Name2Addr : public SettingsParser {
+public:
+ explicit Name2Addr(const std::string& argv0) : SettingsParser{argv0} {
+ namespace po = boost::program_options;
- std::vector<PDB> pdbs;
- std::vector<std::string> names;
- };
+ visible.add_options()(
+ "pdb", po::value<std::vector<PDB>>(&pdbs)->value_name("ADDR,PATH"), "load a PDB file");
+ hidden.add_options()("name",
+ po::value<std::vector<std::string>>(&names)->value_name("NAME"),
+ "add a name to resolve");
+ positional.add("name", -1);
+ }
- void dump_error(const std::exception& e)
- {
- std::cerr << "error: " << e.what() << '\n';
+ const char* get_short_description() const override {
+ return "[-h|--help] [--pdb ADDR,PATH]... [--] [NAME]...";
}
- void resolve_symbol(const pdb::Repo& repo, const std::string& name)
- {
- try
- {
- const auto address = repo.resolve_symbol(name).get_online_address();
- std::cout << pdb::format_address(address) << '\n';
- }
- catch (const std::exception& e)
- {
- dump_error(e);
- std::cout << name << '\n';
- }
+ std::vector<PDB> pdbs;
+ std::vector<std::string> names;
+};
+
+void dump_error(const std::exception& e) {
+ std::cerr << "error: " << e.what() << '\n';
+}
+
+void resolve_symbol(const pdb::Repo& repo, const std::string& name) {
+ try {
+ const auto address = repo.resolve_symbol(name).get_online_address();
+ std::cout << pdb::format_address(address) << '\n';
+ } catch (const std::exception& e) {
+ dump_error(e);
+ std::cout << name << '\n';
}
}
-int main(int argc, char* argv[])
-{
- try
- {
+} // namespace
+
+int main(int argc, char* argv[]) {
+ try {
Name2Addr settings{argv[0]};
- try
- {
+ try {
settings.parse(argc, argv);
- }
- catch (const boost::program_options::error& e)
- {
+ } catch (const boost::program_options::error& e) {
settings.usage_error(e);
return 1;
}
- if (settings.exit_with_usage)
- {
+ if (settings.exit_with_usage) {
settings.usage();
return 0;
}
@@ -96,9 +78,7 @@ int main(int argc, char* argv[])
for (const auto& name : settings.names)
resolve_symbol(repo, name);
- }
- catch (const std::exception& e)
- {
+ } catch (const std::exception& e) {
dump_error(e);
return 1;
}
diff --git a/utils/pdb_descr.hpp b/utils/pdb_descr.hpp
index cde815a..f2e6f38 100644
--- a/utils/pdb_descr.hpp
+++ b/utils/pdb_descr.hpp
@@ -15,13 +15,11 @@
#include <string>
#include <vector>
-struct PDB
-{
+struct PDB {
pdb::Address online_base;
std::string path;
- static PDB parse(std::string src)
- {
+ static PDB parse(std::string src) {
static constexpr auto sep = ',';
const auto sep_pos = src.find(sep);
@@ -35,8 +33,7 @@ struct PDB
return {online_base, src.substr(sep_pos + 1)};
}
- static pdb::Address parse_address(const std::string& src)
- {
+ static pdb::Address parse_address(const std::string& src) {
pdb::Address dest;
if (!pdb::parse_address(dest, src))
boost::throw_exception(boost::program_options::invalid_option_value{src});
@@ -44,32 +41,28 @@ struct PDB
}
};
-namespace boost
-{
- namespace program_options
- {
- template <typename charT>
- void validate(
- boost::any& dest,
- const std::vector<std::basic_string<charT>>& src_tokens,
- PDB*,
- int)
- {
- validators::check_first_occurrence(dest);
- const auto& src_token = validators::get_single_string(src_tokens);
- dest = any{PDB::parse(src_token)};
- }
+namespace boost {
+namespace program_options {
- template <typename charT>
- void validate(
- boost::any& dest,
- const std::vector<std::basic_string<charT>>& src_tokens,
- pdb::Address*,
- int)
- {
- validators::check_first_occurrence(dest);
- const auto& src_token = validators::get_single_string(src_tokens);
- dest = any{PDB::parse_address(src_token)};
- }
- }
+template <typename charT>
+void validate(boost::any& dest,
+ const std::vector<std::basic_string<charT>>& src_tokens,
+ PDB*,
+ int) {
+ validators::check_first_occurrence(dest);
+ const auto& src_token = validators::get_single_string(src_tokens);
+ dest = any{PDB::parse(src_token)};
+}
+
+template <typename charT>
+void validate(boost::any& dest,
+ const std::vector<std::basic_string<charT>>& src_tokens,
+ pdb::Address*,
+ int) {
+ validators::check_first_occurrence(dest);
+ const auto& src_token = validators::get_single_string(src_tokens);
+ dest = any{PDB::parse_address(src_token)};
}
+
+} // namespace program_options
+} // namespace boost