diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/dethunk/header_preprocessor.py b/scripts/dethunk/header_preprocessor.py index d193abf..9448c6c 100644 --- a/scripts/dethunk/header_preprocessor.py +++ b/scripts/dethunk/header_preprocessor.py @@ -19,6 +19,9 @@ class ClassDefine: self.is_template = is_template self.is_empty = is_empty + # if is_empty: + # print(rpath) + def add_class_record(path: str, namespace: str, class_name: str, is_template: bool, is_empty: bool): assert len(path) > 0 and len(class_name) > 0 diff --git a/src/data_format/bound_symbol_list.cpp b/src/data_format/bound_symbol_list.cpp index 5407c50..2c1fc14 100644 --- a/src/data_format/bound_symbol_list.cpp +++ b/src/data_format/bound_symbol_list.cpp @@ -13,7 +13,7 @@ void BoundSymbolList::read(const fs::path& path) { auto data = nlohmann::json::parse(ifs); m_entities.clear(); - for (const auto& entity : data["data"]) { + for (const auto& entity : data) { m_entities.emplace(entity); } } diff --git a/src/data_format/typed_symbol_list.cpp b/src/data_format/typed_symbol_list.cpp index 55d2715..37ff6fd 100644 --- a/src/data_format/typed_symbol_list.cpp +++ b/src/data_format/typed_symbol_list.cpp @@ -27,7 +27,7 @@ void TypedSymbolList::read(const fs::path& path) { void TypedSymbolList::write(const fs::path& path) const { std::ofstream ofs(path); for (const auto& [symbol, decl_type] : m_data) { - ofs << symbol << ", " << decl_type.string() << "\n"; + ofs << decl_type.string() << ", " << symbol << "\n"; } } diff --git a/src/data_format/typed_symbol_list.h b/src/data_format/typed_symbol_list.h index 78e3e09..9b44285 100644 --- a/src/data_format/typed_symbol_list.h +++ b/src/data_format/typed_symbol_list.h @@ -18,6 +18,8 @@ public: void record(const std::string& symbol, DeclType type); + constexpr size_t count() const { return m_data.size(); } + constexpr void for_each(const for_each_callback_t& callback) const { for (const auto& entity : m_data) callback(entity); } diff --git a/src/error.h b/src/error.h index b79de7e..77f9dd9 100644 --- a/src/error.h +++ b/src/error.h @@ -47,11 +47,11 @@ public: if (!m_context_information.empty()) { context_information = "\n\nContext Information: \n"; for (const auto& [key, value] : m_context_information) { - context_information += std::format(" {} = {}", key, value); + context_information += std::format(" {} = {}\n", key, value); } } - std::string stacktrace = "\n\nStackTrace: \n"; + std::string stacktrace = "\nStackTrace: \n"; int stack_idx = -1; // ignore first entry. for (const auto& entry : m_stacktrace) { stack_idx++; @@ -61,7 +61,7 @@ public: if (func_name.empty()) func_name = ""; if (source_file.empty()) source_file = "<\?\?>"; stacktrace += std::format( - " #{} {} at {}:{}", + " #{} {} at {}:{}\n", stack_idx, func_name, source_file, @@ -70,7 +70,7 @@ public: } return std::format( - "[{}] {}{}{}\n", + "[{}] {}{}{}", category(), m_reason, context_information, diff --git a/src/object_file/pdb.cpp b/src/object_file/pdb.cpp index 34432ed..aaa54f7 100644 --- a/src/object_file/pdb.cpp +++ b/src/object_file/pdb.cpp @@ -26,6 +26,9 @@ void PDB::read(const fs::path& path) { loadDataForPDB(PDB_ReaderType::Native, path.string(), m_session) ); + m_storaged_Ipi.reset(new codeview::MergingTypeTableBuilder(m_Alloc)); + m_storaged_Tpi.reset(new codeview::MergingTypeTableBuilder(m_Alloc)); + auto& pdb_file = get_native_session().getPDBFile(); SmallVector type_map; @@ -162,17 +165,15 @@ void PDB::build() { this](const BoundSymbol& entity) { BulkPublic symbol; - auto section_index = - m_owning_coff->get_section_index(entity.m_rva - m_image_base); - auto section = check_llvm_result( + auto section_index = m_owning_coff->get_section_index(entity.m_rva); + auto section = check_llvm_result( m_owning_coff->get_owning_coff().getSection(section_index + 1) ); symbol.Name = strdup(entity.m_symbol_name.c_str()); symbol.NameLen = entity.m_symbol_name.size(); symbol.Segment = section_index + 1; - symbol.Offset = - entity.m_rva - m_image_base - section->VirtualAddress; + symbol.Offset = entity.m_rva - section->VirtualAddress; if (entity.m_is_function) symbol.setFlags(PublicSymFlags::Function); publics.emplace_back(symbol); diff --git a/src/tools/askrva/main.cpp b/src/tools/askrva/main.cpp index a884e50..df31587 100644 --- a/src/tools/askrva/main.cpp +++ b/src/tools/askrva/main.cpp @@ -66,33 +66,43 @@ using namespace di::data_format; int main(int argc, char* argv[]) try { - auto args = load_args(argc, argv); - auto symlist = TypedSymbolList(); + auto args = load_args(argc, argv); + TypedSymbolList symlist; BoundSymbolList bound_symbol_list; RawText failed_list; + for (const auto& input_path : args.m_input_paths) { + symlist.read(input_path); + } + + std::println( + "{} symbols loaded from {} file(s).", + symlist.count(), + args.m_input_paths.size() + ); + #if !DI_USE_NATIVE_SYMBOL_RESOLVER MagicBlob magic_blob; magic_blob.read(args.m_magic_blob_path); + + std::println("{} entries loaded from magicblob.", magic_blob.count()); #endif symlist.for_each([&](const TypedSymbol& symbol) { auto& sym = symbol.m_name; #if DI_USE_NATIVE_SYMBOL_RESOLVER - auto rva = pl::symbol_provider::pl_resolve_symbol_silent_n( + auto address = pl::symbol_provider::pl_resolve_symbol_silent_n( sym.c_str(), sym.size() ); + // TODO: imagebase... #else - auto rva = magic_blob.query(sym); + auto entry = magic_blob.query(sym); #endif - if (rva) { - bound_symbol_list.record( - symbol.m_name, - reinterpret_cast(rva), - symbol.m_type.is_function() - ); + if (entry) { + bound_symbol_list + .record(symbol.m_name, entry->rva, symbol.m_type.is_function()); } else { failed_list.record(symbol.m_name); } @@ -108,4 +118,7 @@ int main(int argc, char* argv[]) try { } catch (const BaseException& e) { std::cerr << e; return 1; +} catch (const std::exception& e) { + std::cerr << e.what() << "\n"; + return 1; } diff --git a/src/tools/blob-extractor/main.cpp b/src/tools/blob-extractor/main.cpp index f47d3e1..247f24d 100644 --- a/src/tools/blob-extractor/main.cpp +++ b/src/tools/blob-extractor/main.cpp @@ -55,5 +55,8 @@ int main(int argc, char* argv[]) try { return 0; } catch (const BaseException& e) { std::cerr << e; - return -1; + return 1; +} catch (const std::exception& e) { + std::cerr << e.what() << "\n"; + return 1; } diff --git a/src/tools/extractsym/main.cpp b/src/tools/extractsym/main.cpp index d4f0a07..c405fa7 100644 --- a/src/tools/extractsym/main.cpp +++ b/src/tools/extractsym/main.cpp @@ -57,9 +57,13 @@ int main(int argc, char* argv[]) try { ); }); + symbol_list.write(args.m_output_path); return 0; } catch (const BaseException& e) { std::cerr << e; - return -1; -} + return 1; +} catch (const std::exception& e) { + std::cerr << e.what() << "\n"; + return 1; +} \ No newline at end of file diff --git a/src/tools/makepdb/main.cpp b/src/tools/makepdb/main.cpp index 7fb03f9..a1bdd70 100644 --- a/src/tools/makepdb/main.cpp +++ b/src/tools/makepdb/main.cpp @@ -71,5 +71,8 @@ int main(int argc, char* argv[]) try { return 0; } catch (const BaseException& e) { std::cerr << e; - return -1; + return 1; +} catch (const std::exception& e) { + std::cerr << e.what() << "\n"; + return 1; } diff --git a/xmake.lua b/xmake.lua index 008525f..60021bc 100644 --- a/xmake.lua +++ b/xmake.lua @@ -47,6 +47,10 @@ end if is_mode('debug') then add_defines('DI_DEBUG') + + -- to fix llvm link problem + -- see https://stackoverflow.com/questions/53805007/compilation-failing-on-enableabibreakingchecks + add_defines('LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1') end --- targets