@@ -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 );
@@ -598,6 +598,10 @@ settings, otherwise debugging features may not work.)");
598
598
bool openAssembler = false ;
599
599
bool openSymbolAdder = false ;
600
600
601
+ float lineHeight = ImGui::GetTextLineHeight ();
602
+ float previousSymbolY = topleft.y ;
603
+ std::optional<std::string> previousSymbol;
604
+
601
605
while (clipper.Step ()) {
602
606
bool skipNext = false ;
603
607
bool delaySlotNext = false ;
@@ -676,11 +680,23 @@ settings, otherwise debugging features may not work.)");
676
680
tcode >>= 8 ;
677
681
b[3 ] = tcode & 0xff ;
678
682
679
- auto symbols = findSymbol (dispAddr);
680
- if (symbols.size () != 0 ) {
681
- ImGui::PushStyleColor (ImGuiCol_Text, s_labelColor);
682
- ImGui::Text (" %s:" , symbols.begin ()->c_str ());
683
- ImGui::PopStyleColor ();
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
+ }
698
+ }
699
+ }
684
700
}
685
701
686
702
for (int i = 0 ; i < m_numColumns * ImGui::GetWindowDpiScale (); i++) {
@@ -750,15 +766,15 @@ settings, otherwise debugging features may not work.)");
750
766
}
751
767
std::string contextMenuID = fmt::format (" assembly address menu {}" , dispAddr);
752
768
if (ImGui::BeginPopupContextItem (contextMenuID.c_str ())) {
753
- if (symbols.size () == 0 ) {
769
+ if (symbol) {
770
+ if (ImGui::MenuItem (_ (" Remove symbol" ))) {
771
+ cpu->m_symbols .erase (dispAddr);
772
+ }
773
+ } else {
754
774
if (ImGui::MenuItem (_ (" Create symbol here" ))) {
755
775
openSymbolAdder = true ;
756
776
m_symbolAddress = dispAddr;
757
777
}
758
- } else {
759
- if (ImGui::MenuItem (_ (" Remove symbol" ))) {
760
- cpu->m_symbols .erase (dispAddr);
761
- }
762
778
}
763
779
if (ImGui::MenuItem (_ (" Copy Address" ))) {
764
780
char fmtAddr[10 ];
@@ -938,6 +954,13 @@ settings, otherwise debugging features may not work.)");
938
954
}
939
955
}
940
956
drawList->ChannelsMerge ();
957
+ if (previousSymbol) {
958
+ ImVec2 pos (ImGui::GetCursorScreenPos ().x , previousSymbolY);
959
+ ImVec2 posEnd (pos.x + glyphWidth * 64 , pos.y + ImGui::GetTextLineHeight ());
960
+ drawList->AddRectFilled (pos, posEnd, ImGui::GetColorU32 (ImGuiCol_WindowBg));
961
+ std::string text = " ^ " + previousSymbol.value () + " ^" ;
962
+ drawList->AddText (pos, ImGui::GetColorU32 (s_labelColor), text.data (), text.data () + text.size ());
963
+ }
941
964
ImGui::EndChild ();
942
965
ImGui::PopFont ();
943
966
if (m_jumpToPC.has_value ()) {
@@ -1078,7 +1101,7 @@ if not success then return msg else return nil end
1078
1101
1079
1102
if (m_showSymbols) {
1080
1103
if (ImGui::Begin (_ (" Symbols" ), &m_showSymbols)) {
1081
- if (ImGui::Button (_ (" Refresh" ))) rebuildSymbolsCaches ();
1104
+ if (ImGui::Button (_ (" Refresh" ))) rebuildSymbolsCache ();
1082
1105
ImGui::SameLine ();
1083
1106
ImGui::InputText (_ (" Filter" ), &m_symbolFilter);
1084
1107
ImGui::BeginChild (" symbolsList" );
@@ -1114,24 +1137,11 @@ if not success then return msg else return nil end
1114
1137
return changed;
1115
1138
}
1116
1139
1117
- std::list<std::string> PCSX::Widgets::Assembly::findSymbol (uint32_t addr) {
1118
- auto & cpu = g_emulator->m_cpu ;
1119
- std::list<std::string> ret;
1120
- auto symbol = cpu->m_symbols .find (addr);
1121
- if (symbol != cpu->m_symbols .end ()) ret.emplace_back (symbol->second );
1122
-
1123
- if (!m_symbolsCachesValid) rebuildSymbolsCaches ();
1124
- auto elfSymbol = m_elfSymbolsCache.find (addr);
1125
- if (elfSymbol != m_elfSymbolsCache.end ()) ret.emplace_back (elfSymbol->second );
1126
-
1127
- return ret;
1128
- }
1129
-
1130
- void PCSX::Widgets::Assembly::rebuildSymbolsCaches () {
1140
+ void PCSX::Widgets::Assembly::rebuildSymbolsCache () {
1131
1141
auto & cpu = g_emulator->m_cpu ;
1132
1142
m_symbolsCache.clear ();
1133
1143
for (auto & symbol : cpu->m_symbols ) {
1134
1144
m_symbolsCache.insert (std::pair (symbol.second , symbol.first ));
1135
1145
}
1136
- m_symbolsCachesValid = true ;
1146
+ m_symbolsCacheValid = true ;
1137
1147
}
0 commit comments