From 024fac84edce8519cebbf1623ae8afecaaf66abc Mon Sep 17 00:00:00 2001 From: Sepalani Date: Sun, 24 Nov 2024 13:03:22 +0400 Subject: [PATCH] PPCSymbolDB: Deduplicate parsing of the 'entry of' string --- Source/Core/Core/PowerPC/PPCSymbolDB.cpp | 51 +++++++++++------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index 77decee7ba90..39f8259be65d 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -328,7 +328,26 @@ bool PPCSymbolDB::LoadMap(const Core::CPUThreadGuard& guard, const std::string& } u32 address, vaddress, size, offset, alignment; - char name[512], container[512]; + char name[512]; + static constexpr char ENTRY_OF_STRING[] = "(entry of "; + static constexpr std::string_view ENTRY_OF_VIEW(ENTRY_OF_STRING); + auto parse_entry_of = [](const char* line, char* name) { + const char* s = strstr(line, ENTRY_OF_STRING); + if (s) + { + char container[512]; + 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] != '.') + { + s2[0] = '\0'; + strcat(container, "::"); + strcat(container, name); + strcpy(name, container); + } + } + }; if (column_count == 4) { // sometimes there is no alignment value, and sometimes it is because it is an entry of @@ -337,19 +356,7 @@ bool PPCSymbolDB::LoadMap(const Core::CPUThreadGuard& guard, const std::string& { alignment = 0; sscanf(line, "%08x %08x %08x %08x %511s", &address, &size, &vaddress, &offset, name); - char* s = strstr(line, "(entry of "); - 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); - } - } + parse_entry_of(line, name); } 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 // container name, followed by ")" // 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; sscanf(line, "%08x %08x %08x %511s", &address, &size, &vaddress, name); - char* s = strstr(line, "(entry of "); - 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); - } - } + parse_entry_of(line, name); } else {