Merge pull request #6309 from sepalani/rsbk-sym-map

PPCSymbolDB: two columns symbol map support added
This commit is contained in:
Léo Lam 2018-01-26 13:12:46 +01:00 committed by GitHub
commit 28176d0117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@
#include "Core/PowerPC/PPCSymbolDB.h" #include "Core/PowerPC/PPCSymbolDB.h"
#include <algorithm>
#include <map> #include <map>
#include <string> #include <string>
#include <utility> #include <utility>
@ -73,7 +74,10 @@ void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& nam
PPCAnalyst::AnalyzeFunction(startAddr, tf, size); PPCAnalyst::AnalyzeFunction(startAddr, tf, size);
checksumToFunction[tf.hash].insert(&functions[startAddr]); checksumToFunction[tf.hash].insert(&functions[startAddr]);
} }
else
{
tf.size = size; tf.size = size;
}
functions[startAddr] = tf; functions[startAddr] = tf;
} }
} }
@ -219,8 +223,10 @@ bool PPCSymbolDB::LoadMap(const std::string& filename, bool bad)
if (!f) if (!f)
return false; return false;
// four columns are used in American Mensa Academy map files and perhaps other games // Two columns are used by Super Smash Bros. Brawl Korean map file
bool four_columns = false; // Three columns are commonly used
// Four columns are used in American Mensa Academy map files and perhaps other games
int column_count = 0;
int good_count = 0; int good_count = 0;
int bad_count = 0; int bad_count = 0;
@ -234,7 +240,7 @@ bool PPCSymbolDB::LoadMap(const std::string& filename, bool bad)
if (length == 34 && strcmp(line, " address Size address offset\n") == 0) if (length == 34 && strcmp(line, " address Size address offset\n") == 0)
{ {
four_columns = true; column_count = 4;
continue; continue;
} }
@ -287,9 +293,19 @@ bool PPCSymbolDB::LoadMap(const std::string& filename, bool bad)
if (section_name.empty()) if (section_name.empty())
continue; continue;
// Detect two columns with three columns fallback
if (column_count == 0)
{
const std::string stripped_line = StripSpaces(line);
if (std::count(stripped_line.begin(), stripped_line.end(), ' ') == 1)
column_count = 2;
else
column_count = 3;
}
u32 address, vaddress, size, offset, alignment; u32 address, vaddress, size, offset, alignment;
char name[512], container[512]; char name[512], container[512];
if (four_columns) if (column_count == 4)
{ {
// sometimes there is no alignment value, and sometimes it is because it is an entry of // sometimes there is no alignment value, and sometimes it is because it is an entry of
// something else // something else
@ -317,10 +333,12 @@ bool PPCSymbolDB::LoadMap(const std::string& filename, bool bad)
&alignment, name); &alignment, name);
} }
} }
else if (column_count == 3)
{
// 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
else if (length > 27 && line[27] != ' ' && strstr(line, "(entry of ")) if (length > 27 && line[27] != ' ' && strstr(line, "(entry of "))
{ {
alignment = 0; alignment = 0;
sscanf(line, "%08x %08x %08x %511s", &address, &size, &vaddress, name); sscanf(line, "%08x %08x %08x %511s", &address, &size, &vaddress, name);
@ -342,7 +360,17 @@ bool PPCSymbolDB::LoadMap(const std::string& filename, bool bad)
{ {
sscanf(line, "%08x %08x %08x %i %511s", &address, &size, &vaddress, &alignment, name); sscanf(line, "%08x %08x %08x %i %511s", &address, &size, &vaddress, &alignment, name);
} }
}
else if (column_count == 2)
{
sscanf(line, "%08x %511s", &address, name);
vaddress = address;
size = 0;
}
else
{
break;
}
const char* namepos = strstr(line, name); const char* namepos = strstr(line, name);
if (namepos != nullptr) // would be odd if not :P if (namepos != nullptr) // would be odd if not :P
strcpy(name, namepos); strcpy(name, namepos);