fix: minor bug fixes.

This commit is contained in:
2025-03-06 12:34:40 +08:00
parent af44d604b1
commit 60ab9d6154
12 changed files with 58 additions and 25 deletions

View File

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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";
}
}

View File

@@ -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);
}

View File

@@ -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 = "<unknown>";
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,

View File

@@ -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<codeview::TypeIndex, 128> 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);

View File

@@ -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<uintptr_t>(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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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