PPCSymbolDB: Deduplicate parsing of the 'entry of' string

This commit is contained in:
Sepalani 2024-11-24 13:03:22 +04:00
parent 5c151c11ac
commit 5778cb42db

View File

@ -328,20 +328,17 @@ bool PPCSymbolDB::LoadMap(const Core::CPUThreadGuard& guard, const std::string&
} }
u32 address, vaddress, size, offset, alignment; u32 address, vaddress, size, offset, alignment;
char name[512], container[512]; char name[512];
if (column_count == 4) static constexpr char ENTRY_OF_STRING[] = "(entry of ";
{ static constexpr std::string_view ENTRY_OF_VIEW(ENTRY_OF_STRING);
// sometimes there is no alignment value, and sometimes it is because it is an entry of auto parse_entry_of = [](const char* line, char* name) {
// something else const char* s = strstr(line, ENTRY_OF_STRING);
if (length > 37 && line[37] == ' ')
{
alignment = 0;
sscanf(line, "%08x %08x %08x %08x %511s", &address, &size, &vaddress, &offset, name);
char* s = strstr(line, "(entry of ");
if (s) if (s)
{ {
sscanf(s + 10, "%511s", container); char container[512];
char* s2 = (strchr(container, ')')); sscanf(s + ENTRY_OF_VIEW.size(), "%511s", container);
char* s2 = strchr(container, ')');
// Skip sections, those start with a dot, e.g. (entry of .text)
if (s2 && container[0] != '.') if (s2 && container[0] != '.')
{ {
s2[0] = '\0'; s2[0] = '\0';
@ -350,6 +347,16 @@ bool PPCSymbolDB::LoadMap(const Core::CPUThreadGuard& guard, const std::string&
strcpy(name, container); strcpy(name, container);
} }
} }
};
if (column_count == 4)
{
// sometimes there is no alignment value, and sometimes it is because it is an entry of
// something else
if (length > 37 && line[37] == ' ')
{
alignment = 0;
sscanf(line, "%08x %08x %08x %08x %511s", &address, &size, &vaddress, &offset, name);
parse_entry_of(line, name);
} }
else else
{ {
@ -362,23 +369,11 @@ bool PPCSymbolDB::LoadMap(const Core::CPUThreadGuard& guard, const std::string&
// some entries in the table have a function name followed by " (entry of " followed by a // some entries in the table have a function name followed by " (entry of " followed by a
// container name, followed by ")" // container name, followed by ")"
// instead of a space followed by a number followed by a space followed by a name // instead of a space followed by a number followed by a space followed by a name
if (length > 27 && line[27] != ' ' && strstr(line, "(entry of ")) if (length > 27 && line[27] != ' ' && strstr(line, ENTRY_OF_STRING))
{ {
alignment = 0; alignment = 0;
sscanf(line, "%08x %08x %08x %511s", &address, &size, &vaddress, name); sscanf(line, "%08x %08x %08x %511s", &address, &size, &vaddress, name);
char* s = strstr(line, "(entry of "); parse_entry_of(line, name);
if (s)
{
sscanf(s + 10, "%511s", container);
char* s2 = (strchr(container, ')'));
if (s2 && container[0] != '.')
{
s2[0] = '\0';
strcat(container, "::");
strcat(container, name);
strcpy(name, container);
}
}
} }
else else
{ {