aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-03-24 01:34:52 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-03-24 02:06:22 +0300
commitc073ed8f702e98ec56ed05e0c02167e355e6ee31 (patch)
treef726a5830ed4f47724ac6c447571398ef5b12ea2 /src
parentadd Process class (diff)
downloadwinapi-debug-c073ed8f702e98ec56ed05e0c02167e355e6ee31.tar.gz
winapi-debug-c073ed8f702e98ec56ed05e0c02167e355e6ee31.zip
switch to Boost.Nowide everywhere
Diffstat (limited to '')
-rw-r--r--src/dbghelp.cpp29
-rw-r--r--src/error.cpp20
-rw-r--r--src/module.cpp6
-rw-r--r--src/symbol.cpp10
4 files changed, 42 insertions, 23 deletions
diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp
index cb71282..5b66914 100644
--- a/src/dbghelp.cpp
+++ b/src/dbghelp.cpp
@@ -5,6 +5,8 @@
#include "pdb/all.hpp"
+#include <boost/nowide/convert.hpp>
+
#include <SafeInt.hpp>
#include <dbghelp.h>
@@ -48,7 +50,7 @@ Address gen_next_offline_base(std::size_t pdb_size) {
ModuleInfo get_module_info(HANDLE id, Address offline_base) {
ModuleInfo info;
- if (!SymGetModuleInfo64(id, offline_base, &static_cast<ModuleInfo::Impl&>(info)))
+ if (!SymGetModuleInfoW64(id, offline_base, &static_cast<ModuleInfo::Impl&>(info)))
throw error::windows(GetLastError());
return info;
@@ -59,14 +61,14 @@ struct ModuleEnumerator {
DbgHelp::OnModule callback;
};
-BOOL CALLBACK enum_modules_callback(PCSTR, DWORD64 offline_base, PVOID raw_enumerator_ptr) {
+BOOL CALLBACK enum_modules_callback(PCWSTR, DWORD64 offline_base, PVOID raw_enumerator_ptr) {
const auto enumerator_ptr = reinterpret_cast<ModuleEnumerator*>(raw_enumerator_ptr);
const auto& enumerator = *enumerator_ptr;
enumerator.callback(get_module_info(enumerator.id, offline_base));
return TRUE;
}
-BOOL CALLBACK enum_symbols_callback(SYMBOL_INFO* info, ULONG, VOID* raw_callback_ptr) {
+BOOL CALLBACK enum_symbols_callback(SYMBOL_INFOW* info, ULONG, VOID* raw_callback_ptr) {
const auto callback_ptr = reinterpret_cast<DbgHelp::OnSymbol*>(raw_callback_ptr);
const auto& callback = *callback_ptr;
callback(SymbolInfo{*info});
@@ -77,11 +79,11 @@ void enum_symbols(HANDLE id,
Address module_base,
const std::string& mask,
const DbgHelp::OnSymbol& callback) {
- if (!SymEnumSymbols(id,
- module_base,
- mask.c_str(),
- &enum_symbols_callback,
- const_cast<DbgHelp::OnSymbol*>(&callback)))
+ if (!SymEnumSymbolsW(id,
+ module_base,
+ boost::nowide::widen(mask).c_str(),
+ &enum_symbols_callback,
+ const_cast<DbgHelp::OnSymbol*>(&callback)))
throw error::windows(GetLastError());
}
@@ -128,6 +130,7 @@ ModuleInfo DbgHelp::load_pdb(const std::string& path) const {
_path.assign(path.cbegin(), path.cend());
_path.emplace_back('\0');
+ // TODO: switch to the W version?
const auto offline_base =
SymLoadModule64(id, NULL, _path.data(), NULL, gen_next_offline_base(size), size);
@@ -139,7 +142,7 @@ ModuleInfo DbgHelp::load_pdb(const std::string& path) const {
void DbgHelp::enum_modules(const OnModule& callback) const {
ModuleEnumerator enumerator{id, callback};
- if (!SymEnumerateModules64(id, &enum_modules_callback, &enumerator))
+ if (!SymEnumerateModulesW64(id, &enum_modules_callback, &enumerator))
throw error::windows(GetLastError());
}
@@ -169,7 +172,7 @@ SymbolInfo DbgHelp::resolve_symbol(Address offline) const {
Address displacement = 0;
SymbolInfo symbol;
- if (!SymFromAddr(id, offline, &displacement, &static_cast<SYMBOL_INFO&>(symbol)))
+ if (!SymFromAddrW(id, offline, &displacement, &static_cast<SYMBOL_INFOW&>(symbol)))
throw error::windows(GetLastError());
symbol.set_displacement(displacement);
@@ -179,20 +182,20 @@ SymbolInfo DbgHelp::resolve_symbol(Address offline) const {
SymbolInfo DbgHelp::resolve_symbol(const std::string& name) const {
SymbolInfo symbol;
- if (!SymFromName(id, name.c_str(), &static_cast<SYMBOL_INFO&>(symbol)))
+ if (!SymFromNameW(id, boost::nowide::widen(name).c_str(), &static_cast<SYMBOL_INFOW&>(symbol)))
throw error::windows(GetLastError());
return symbol;
}
LineInfo DbgHelp::resolve_line(Address offline) const {
- IMAGEHLP_LINE64 impl;
+ IMAGEHLP_LINEW64 impl;
std::memset(&impl, 0, sizeof(impl));
impl.SizeOfStruct = sizeof(impl);
DWORD displacement = 0;
- if (!SymGetLineFromAddr64(id, offline, &displacement, &impl))
+ if (!SymGetLineFromAddrW64(id, offline, &displacement, &impl))
throw error::windows(GetLastError());
return LineInfo{impl};
diff --git a/src/error.cpp b/src/error.cpp
index 16512b3..d305e88 100644
--- a/src/error.cpp
+++ b/src/error.cpp
@@ -5,6 +5,8 @@
#include "pdb/all.hpp"
+#include <boost/nowide/convert.hpp>
+
#include <windows.h>
#include <string>
@@ -13,9 +15,9 @@ namespace pdb {
namespace error {
namespace {
-std::string trim_trailing_newline(const std::string& s) {
- const auto last_pos = s.find_last_not_of("\r\n");
- if (std::string::npos == last_pos)
+std::wstring trim_trailing_newline(const std::wstring& s) {
+ const auto last_pos = s.find_last_not_of(L"\r\n");
+ if (std::wstring::npos == last_pos)
return {};
return s.substr(0, last_pos + 1);
}
@@ -23,25 +25,25 @@ std::string trim_trailing_newline(const std::string& s) {
} // namespace
std::string CategoryWindows::message(int code) const {
- char* buf;
+ wchar_t* buf;
- const auto nbwritten = FormatMessageA(
+ const auto len = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- reinterpret_cast<char*>(&buf),
+ reinterpret_cast<wchar_t*>(&buf),
0,
NULL);
- if (0 == nbwritten) {
+ if (0 == len) {
LocalFree(buf);
return "Couldn't format the error message";
}
- std::string msg{buf, nbwritten};
+ std::wstring msg{buf, len};
LocalFree(buf);
- return trim_trailing_newline(msg);
+ return boost::nowide::narrow(trim_trailing_newline(msg));
}
} // namespace error
diff --git a/src/module.cpp b/src/module.cpp
index 6ee0c08..f4f3eb9 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -5,6 +5,8 @@
#include "pdb/all.hpp"
+#include <boost/nowide/convert.hpp>
+
#include <SafeInt.hpp>
#include <cstring>
@@ -28,6 +30,10 @@ ModuleInfo::Impl ModuleInfo::create_impl() {
return impl;
}
+std::string ModuleInfo::get_name() const {
+ return boost::nowide::narrow(impl.ModuleName);
+}
+
Address Module::translate_offline_address(Address offline) const {
if (offline < get_offline_base())
throw std::range_error{invalid_offline_address(offline)};
diff --git a/src/symbol.cpp b/src/symbol.cpp
index e679f4a..1973f0b 100644
--- a/src/symbol.cpp
+++ b/src/symbol.cpp
@@ -5,6 +5,8 @@
#include "pdb/all.hpp"
+#include <boost/nowide/convert.hpp>
+
#include <SafeInt.hpp>
#include <dbghelp.h>
@@ -13,6 +15,7 @@
#include <cstddef>
#include <cstring>
#include <stdexcept>
+#include <string>
namespace pdb {
namespace {
@@ -51,7 +54,12 @@ SymbolInfo::SymbolInfo(const Impl& impl) : SymbolInfo{} {
std::memcpy(buffer.data(), &impl, impl_size);
}
+std::string SymbolInfo::get_name() const {
+ return boost::nowide::narrow(std::wstring{get_impl().Name, get_impl().NameLen});
+}
+
LineInfo::LineInfo(const Impl& impl)
- : file_path{impl.FileName}, line_number{cast_line_number(impl.LineNumber)} {}
+ : file_path{boost::nowide::narrow(impl.FileName)},
+ line_number{cast_line_number(impl.LineNumber)} {}
} // namespace pdb