@@ -302,8 +302,8 @@ void PCSX::Widgets::Assembly::Target(uint32_t value) {
302
302
if (m_displayArrowForJumps) m_arrows.push_back ({m_currentAddr, value});
303
303
std::snprintf (label, sizeof (label), " 0x%8.8x##%8.8x" , value, m_currentAddr);
304
304
std::string longLabel = label;
305
- auto symbols = findSymbol (value);
306
- if (symbols. size () != 0 ) longLabel = *symbols. begin () + " ;" + label;
305
+ std::string* symbol = g_emulator-> m_cpu -> getSymbolAt (value);
306
+ if (symbol) longLabel = *symbol + " ;" + label;
307
307
ImGui::PushStyleVar (ImGuiStyleVar_FramePadding, ImVec2 (0 , 0 ));
308
308
if (ImGui::Button (longLabel.c_str ())) {
309
309
m_jumpToPC = value;
@@ -366,8 +366,8 @@ void PCSX::Widgets::Assembly::OfB(int16_t offset, uint8_t reg, int size) {
366
366
uint32_t addr = m_registers->GPR .r [reg] + offset;
367
367
368
368
std::string longLabel;
369
- auto symbols = findSymbol (addr);
370
- if (symbols. size () != 0 ) longLabel = *symbols. begin () + " ; " ;
369
+ std::string* symbol = g_emulator-> m_cpu -> getSymbolAt (addr);
370
+ if (symbol) longLabel = *symbol + " ; " ;
371
371
372
372
const auto & io = ImGui::GetIO ();
373
373
unsigned targetEditorIndex = io.KeyShift ? 1 : (io.KeyCtrl ? 2 : 0 );
@@ -405,17 +405,17 @@ void PCSX::Widgets::Assembly::BranchDest(uint32_t value) {
405
405
sameLine ();
406
406
m_arrows.push_back ({m_currentAddr, value});
407
407
std::snprintf (label, sizeof (label), " 0x%8.8x##%8.8x" , value, m_currentAddr);
408
- auto symbols = findSymbol (value);
409
- if (symbols.size () == 0 ) {
408
+ std::string* symbol = g_emulator->m_cpu ->getSymbolAt (value);
409
+ if (symbol) {
410
+ std::string longLabel = *symbol + " ;" + label;
410
411
ImGui::PushStyleVar (ImGuiStyleVar_FramePadding, ImVec2 (0 , 0 ));
411
- if (ImGui::Button (label )) {
412
+ if (ImGui::Button (longLabel. c_str () )) {
412
413
m_jumpToPC = value;
413
414
}
414
415
ImGui::PopStyleVar ();
415
416
} else {
416
- std::string longLabel = *symbols.begin () + " ;" + label;
417
417
ImGui::PushStyleVar (ImGuiStyleVar_FramePadding, ImVec2 (0 , 0 ));
418
- if (ImGui::Button (longLabel. c_str () )) {
418
+ if (ImGui::Button (label )) {
419
419
m_jumpToPC = value;
420
420
}
421
421
ImGui::PopStyleVar ();
@@ -427,8 +427,8 @@ void PCSX::Widgets::Assembly::Offset(uint32_t addr, int size) {
427
427
char label[32 ];
428
428
std::snprintf (label, sizeof (label), " 0x%8.8x##%8.8x" , addr, m_currentAddr);
429
429
std::string longLabel = label;
430
- auto symbols = findSymbol (addr);
431
- if (symbols. size () != 0 ) longLabel = *symbols. begin () + " ;" + label;
430
+ std::string* symbol = g_emulator-> m_cpu -> getSymbolAt (addr);
431
+ if (symbol) longLabel = *symbol + " ;" + label;
432
432
433
433
const auto & io = ImGui::GetIO ();
434
434
unsigned targetEditorIndex = io.KeyShift ? 1 : (io.KeyCtrl ? 2 : 0 );
@@ -680,20 +680,21 @@ settings, otherwise debugging features may not work.)");
680
680
tcode >>= 8 ;
681
681
b[3 ] = tcode & 0xff ;
682
682
683
- auto symbols = findSymbol (dispAddr);
684
- if (symbols.size () != 0 ) {
685
- ImGui::PushStyleColor (ImGuiCol_Text, s_labelColor);
686
- ImGui::Text (" %s:" , symbols.begin ()->c_str ());
687
- ImGui::PopStyleColor ();
688
- } else {
689
- // if the first visible line is not a symbol, show the previous symbol
690
- float y = ImGui::GetCursorScreenPos ().y ;
691
- if (y + lineHeight >= topleft.y && y <= topleft.y + lineHeight) {
692
- previousSymbol = findPreviousSymbol (dispAddr);
693
- // if the second line is a symbol, push the previous symbol display up
694
- auto secondLineSymbol = findSymbol (dispAddr + 4 );
695
- if (secondLineSymbol.size () != 0 && y < previousSymbolY) {
696
- previousSymbolY = y;
683
+ std::pair<const uint32_t , std::string>* symbol = cpu->findContainingSymbol (dispAddr);
684
+ if (symbol) {
685
+ if (symbol->first == dispAddr) {
686
+ ImGui::PushStyleColor (ImGuiCol_Text, s_labelColor);
687
+ ImGui::Text (" %s:" , symbol->second .c_str ());
688
+ ImGui::PopStyleColor ();
689
+ } else {
690
+ // if this is the first visible line and it's not a label itself, store the previous symbol
691
+ float y = ImGui::GetCursorScreenPos ().y ;
692
+ if (y + lineHeight >= topleft.y && y <= topleft.y + lineHeight) {
693
+ previousSymbol = symbol->second ;
694
+ // if the second visible line is a symbol, push the previous symbol display up
695
+ if (cpu->getSymbolAt (dispAddr + 4 ) && y < previousSymbolY) {
696
+ previousSymbolY = y;
697
+ }
697
698
}
698
699
}
699
700
}
@@ -765,15 +766,15 @@ settings, otherwise debugging features may not work.)");
765
766
}
766
767
std::string contextMenuID = fmt::format (" assembly address menu {}" , dispAddr);
767
768
if (ImGui::BeginPopupContextItem (contextMenuID.c_str ())) {
768
- if (symbols.size () == 0 ) {
769
+ if (symbol) {
770
+ if (ImGui::MenuItem (_ (" Remove symbol" ))) {
771
+ cpu->m_symbols .erase (dispAddr);
772
+ }
773
+ } else {
769
774
if (ImGui::MenuItem (_ (" Create symbol here" ))) {
770
775
openSymbolAdder = true ;
771
776
m_symbolAddress = dispAddr;
772
777
}
773
- } else {
774
- if (ImGui::MenuItem (_ (" Remove symbol" ))) {
775
- cpu->m_symbols .erase (dispAddr);
776
- }
777
778
}
778
779
if (ImGui::MenuItem (_ (" Copy Address" ))) {
779
780
char fmtAddr[10 ];
@@ -1100,7 +1101,7 @@ if not success then return msg else return nil end
1100
1101
1101
1102
if (m_showSymbols) {
1102
1103
if (ImGui::Begin (_ (" Symbols" ), &m_showSymbols)) {
1103
- if (ImGui::Button (_ (" Refresh" ))) rebuildSymbolsCaches ();
1104
+ if (ImGui::Button (_ (" Refresh" ))) rebuildSymbolsCache ();
1104
1105
ImGui::SameLine ();
1105
1106
ImGui::InputText (_ (" Filter" ), &m_symbolFilter);
1106
1107
ImGui::BeginChild (" symbolsList" );
@@ -1136,36 +1137,11 @@ if not success then return msg else return nil end
1136
1137
return changed;
1137
1138
}
1138
1139
1139
- std::list<std::string> PCSX::Widgets::Assembly::findSymbol (uint32_t addr) {
1140
- auto & cpu = g_emulator->m_cpu ;
1141
- std::list<std::string> ret;
1142
- auto symbol = cpu->m_symbols .find (addr);
1143
- if (symbol != cpu->m_symbols .end ()) ret.emplace_back (symbol->second );
1144
-
1145
- if (!m_symbolsCachesValid) rebuildSymbolsCaches ();
1146
- auto elfSymbol = m_elfSymbolsCache.find (addr);
1147
- if (elfSymbol != m_elfSymbolsCache.end ()) ret.emplace_back (elfSymbol->second );
1148
-
1149
- return ret;
1150
- }
1151
-
1152
- std::optional<std::string> PCSX::Widgets::Assembly::findPreviousSymbol (uint32_t addr) {
1153
- auto & symbols = g_emulator->m_cpu ->m_symbols ;
1154
- auto symBeforeAddr = symbols.lower_bound (addr);
1155
- if (symBeforeAddr != symbols.begin ()) { // verify there is actually a symbol before addr
1156
- symBeforeAddr--;
1157
- if (symBeforeAddr->first < addr && symBeforeAddr->first >= m_ramBase) {
1158
- return symBeforeAddr->second ;
1159
- }
1160
- }
1161
- return {};
1162
- }
1163
-
1164
- void PCSX::Widgets::Assembly::rebuildSymbolsCaches () {
1140
+ void PCSX::Widgets::Assembly::rebuildSymbolsCache () {
1165
1141
auto & cpu = g_emulator->m_cpu ;
1166
1142
m_symbolsCache.clear ();
1167
1143
for (auto & symbol : cpu->m_symbols ) {
1168
1144
m_symbolsCache.insert (std::pair (symbol.second , symbol.first ));
1169
1145
}
1170
- m_symbolsCachesValid = true ;
1146
+ m_symbolsCacheValid = true ;
1171
1147
}
0 commit comments