Merge pull request #54 from georgemoralis/skmp/stub-log-unknown-nids

Stubs: Log nids for unknown ones
This commit is contained in:
georgemoralis 2023-10-14 19:50:48 +03:00 committed by GitHub
commit 22cbfd860d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View file

@ -623,11 +623,11 @@ void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolReco
if (aeronid) {
return_info->name = aeronid->name;
return_info->virtual_address = GetStub(aeronid->nid);
LOG_ERROR_IF(debug_loader, "Linker: Stub resolved {} as {} (lib: {}, mod: {}) \n", sr.name, return_info->name, library->name, module->name);
} else {
return_info->virtual_address = (u64)&UnresolvedStub;
return_info->name = "Unresolved!!!";
return_info->virtual_address = GetStub(sr.name.c_str());
return_info->name = "Unknown !!!";
}
LOG_ERROR_IF(debug_loader, "Linker: Stub resolved {} as {} (lib: {}, mod: {}) \n", sr.name, return_info->name, library->name, module->name);
}
}
else

View file

@ -19,23 +19,27 @@
#define MAX_STUBS 128
u64 UnresolvedStub() {
LOG_ERROR("Unknown Stub: called, returning zero\n");
LOG_ERROR("Unresolved Stub: called, returning zero\n");
return 0;
}
static u64 UnknownStub() {
LOG_ERROR("Unknown Stub: called, returning zero\n");
LOG_ERROR("Stub: Unknown (nid: Unknown) called, returning zero\n");
return 0;
}
static aerolib::nid_entry* stub_nids[MAX_STUBS];
static std::string stub_nids_unknown[MAX_STUBS];
template <int stub_index>
static u64 CommonStub() {
auto entry = stub_nids[stub_index];
LOG_ERROR("Stub: {} ({}) called, returning zero\n", entry->name, entry->nid);
if (entry) {
LOG_ERROR("Stub: {} (nid: {}) called, returning zero\n", entry->name, entry->nid);
} else {
LOG_ERROR("Stub: Unknown (nid: {}) called, returning zero\n", stub_nids_unknown[stub_index]);
}
return 0;
}
@ -61,11 +65,16 @@ static u64 (*stub_handlers[MAX_STUBS])() = {
};
u64 GetStub(const char* nid) {
auto entry = aerolib::find_by_nid(nid);
if (!entry || UsedStubEntries >= MAX_STUBS) {
if (UsedStubEntries >= MAX_STUBS) {
return (u64)&UnknownStub;
}
auto entry = aerolib::find_by_nid(nid);
if (!entry) {
stub_nids_unknown[UsedStubEntries] = nid;
} else {
stub_nids[UsedStubEntries] = entry;
return (u64)stub_handlers[UsedStubEntries++];
}
return (u64)stub_handlers[UsedStubEntries++];
}