@@ -570,43 +570,40 @@ bool DebuggerBreakpoints::RemoveAbsolute(uint64_t remoteAddress)
570570 return false ;
571571
572572 ModuleNameAndOffset info = m_state->GetModules ()->AbsoluteAddressToRelative (remoteAddress);
573- if (ContainsOffset (info))
574- {
575- auto iter = std::find (m_breakpoints.begin (), m_breakpoints.end (), info);
576- if (iter != m_breakpoints.end ())
577- {
578- m_breakpoints.erase (iter);
579- }
580- m_enabledState.erase (info); // Remove enabled state
581- m_conditions.erase (info); // Remove condition
582- SerializeMetadata ();
583- m_state->GetAdapter ()->RemoveBreakpoint (remoteAddress);
584- return true ;
585- }
586- return false ;
573+ auto actualKey = FindBreakpointKey (info);
574+ if (!actualKey)
575+ return false ;
576+
577+ if (auto iter = std::ranges::find (m_breakpoints, *actualKey); iter != m_breakpoints.end ())
578+ m_breakpoints.erase (iter);
579+
580+ m_enabledState.erase (*actualKey);
581+ m_conditions.erase (*actualKey);
582+ SerializeMetadata ();
583+ m_state->GetAdapter ()->RemoveBreakpoint (remoteAddress);
584+ return true ;
587585}
588586
589587
590588bool DebuggerBreakpoints::RemoveOffset (const ModuleNameAndOffset& address)
591589{
592- if (ContainsOffset (address))
593- {
594- if (auto iter = std::find (m_breakpoints.begin (), m_breakpoints.end (), address); iter != m_breakpoints.end ())
595- m_breakpoints.erase (iter);
590+ auto actualKey = FindBreakpointKey (address);
591+ if (!actualKey)
592+ return false ;
596593
597- m_enabledState.erase (address); // Remove enabled state
598- m_conditions.erase (address); // Remove condition
599- SerializeMetadata ();
594+ if (const auto iter = std::ranges::find (m_breakpoints, *actualKey); iter != m_breakpoints.end ())
595+ m_breakpoints.erase (iter);
600596
601- if (m_state->GetAdapter () && m_state->IsConnected ())
602- {
603- uint64_t remoteAddress = m_state->GetModules ()->RelativeAddressToAbsolute (address);
604- m_state->GetAdapter ()->RemoveBreakpoint (remoteAddress);
605- return true ;
606- }
607- return true ;
597+ m_enabledState.erase (*actualKey);
598+ m_conditions.erase (*actualKey);
599+ SerializeMetadata ();
600+
601+ if (m_state->GetAdapter () && m_state->IsConnected ())
602+ {
603+ uint64_t remoteAddress = m_state->GetModules ()->RelativeAddressToAbsolute (*actualKey);
604+ m_state->GetAdapter ()->RemoveBreakpoint (remoteAddress);
608605 }
609- return false ;
606+ return true ;
610607}
611608
612609
@@ -619,18 +616,17 @@ bool DebuggerBreakpoints::EnableAbsolute(uint64_t remoteAddress)
619616
620617bool DebuggerBreakpoints::EnableOffset (const ModuleNameAndOffset& address)
621618{
622- if (!ContainsOffset (address))
619+ auto actualKey = FindBreakpointKey (address);
620+ if (!actualKey)
623621 return false ;
624622
625- m_enabledState[address ] = true ;
623+ m_enabledState[*actualKey ] = true ;
626624 SerializeMetadata ();
627625
628- // If connected, make sure the breakpoint is active in the target
629626 if (m_state->GetAdapter () && m_state->IsConnected ())
630627 {
631- uint64_t remoteAddress = m_state->GetModules ()->RelativeAddressToAbsolute (address );
628+ uint64_t remoteAddress = m_state->GetModules ()->RelativeAddressToAbsolute (*actualKey );
632629 m_state->GetAdapter ()->AddBreakpoint (remoteAddress);
633- return true ;
634630 }
635631 return true ;
636632}
@@ -645,18 +641,17 @@ bool DebuggerBreakpoints::DisableAbsolute(uint64_t remoteAddress)
645641
646642bool DebuggerBreakpoints::DisableOffset (const ModuleNameAndOffset& address)
647643{
648- if (!ContainsOffset (address))
644+ auto actualKey = FindBreakpointKey (address);
645+ if (!actualKey)
649646 return false ;
650647
651- m_enabledState[address ] = false ;
648+ m_enabledState[*actualKey ] = false ;
652649 SerializeMetadata ();
653650
654- // If connected, remove the breakpoint from the target but keep it in our list
655651 if (m_state->GetAdapter () && m_state->IsConnected ())
656652 {
657- uint64_t remoteAddress = m_state->GetModules ()->RelativeAddressToAbsolute (address );
653+ uint64_t remoteAddress = m_state->GetModules ()->RelativeAddressToAbsolute (*actualKey );
658654 m_state->GetAdapter ()->RemoveBreakpoint (remoteAddress);
659- return true ;
660655 }
661656 return true ;
662657}
@@ -671,12 +666,15 @@ bool DebuggerBreakpoints::IsEnabledAbsolute(uint64_t address)
671666
672667bool DebuggerBreakpoints::IsEnabledOffset (const ModuleNameAndOffset& address)
673668{
674- auto iter = m_enabledState.find (address);
669+ auto actualKey = FindBreakpointKey (address);
670+ if (!actualKey)
671+ return true ; // Default to enabled if breakpoint not found
672+
673+ auto iter = m_enabledState.find (*actualKey);
675674 if (iter != m_enabledState.end ())
676675 return iter->second ;
677-
678- // Default to enabled if not explicitly set
679- return true ;
676+
677+ return true ; // Default to enabled if not explicitly set
680678}
681679
682680
@@ -721,36 +719,37 @@ bool DebuggerBreakpoints::SetConditionAbsolute(const uint64_t remoteAddress, con
721719
722720bool DebuggerBreakpoints::SetConditionOffset (const ModuleNameAndOffset& address, const std::string& condition)
723721{
724- std::optional<ModuleNameAndOffset> actualKey;
722+ auto actualKey = FindBreakpointKey (address);
723+ if (!actualKey)
724+ return false ;
725+
726+ if (condition.empty ())
727+ m_conditions.erase (*actualKey);
728+ else
729+ m_conditions[*actualKey] = condition;
730+
731+ SerializeMetadata ();
732+ return true ;
733+ }
725734
735+
736+ std::optional<ModuleNameAndOffset> DebuggerBreakpoints::FindBreakpointKey (const ModuleNameAndOffset& address)
737+ {
726738 if (m_state->GetAdapter ())
727739 {
728740 const uint64_t targetAbsolute = m_state->GetModules ()->RelativeAddressToAbsolute (address);
729741 for (const ModuleNameAndOffset& bp : m_breakpoints)
730742 {
731743 if (m_state->GetModules ()->RelativeAddressToAbsolute (bp) == targetAbsolute)
732- {
733- actualKey = bp;
734- break ;
735- }
744+ return bp;
736745 }
737746 }
738747 else
739748 {
740749 if (const auto it = std::ranges::find (m_breakpoints, address); it != m_breakpoints.end ())
741- actualKey = *it;
750+ return *it;
742751 }
743-
744- if (!actualKey)
745- return false ;
746-
747- if (condition.empty ())
748- m_conditions.erase (*actualKey);
749- else
750- m_conditions[*actualKey] = condition;
751-
752- SerializeMetadata ();
753- return true ;
752+ return std::nullopt ;
754753}
755754
756755
0 commit comments