1 //===-- BreakpointSite.cpp --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Breakpoint/BreakpointSite.h"
14 // Other libraries and framework includes
16 #include "lldb/Breakpoint/Breakpoint.h"
17 #include "lldb/Breakpoint/BreakpointLocation.h"
18 #include "lldb/Breakpoint/BreakpointSiteList.h"
21 using namespace lldb_private;
23 BreakpointSite::BreakpointSite
25 BreakpointSiteList *list,
26 const BreakpointLocationSP& owner,
30 StoppointLocation(GetNextID(), addr, 0, use_hardware),
31 m_type (eSoftware), // Process subclasses need to set this correctly using SetType()
34 m_enabled(false), // Need to create it disabled, so the first enable turns it on.
40 BreakpointSite::~BreakpointSite()
42 BreakpointLocationSP bp_loc_sp;
43 const size_t owner_count = m_owners.GetSize();
44 for (size_t i = 0; i < owner_count; i++)
46 m_owners.GetByIndex(i)->ClearBreakpointSite();
51 BreakpointSite::GetNextID()
53 static break_id_t g_next_id = 0;
57 // RETURNS - true if we should stop at this breakpoint, false if we
61 BreakpointSite::ShouldStop (StoppointCallbackContext *context)
64 return m_owners.ShouldStop (context);
68 BreakpointSite::IsBreakpointAtThisSite (lldb::break_id_t bp_id)
70 const size_t owner_count = m_owners.GetSize();
71 for (size_t i = 0; i < owner_count; i++)
73 if (m_owners.GetByIndex(i)->GetBreakpoint().GetID() == bp_id)
80 BreakpointSite::Dump(Stream *s) const
85 s->Printf("BreakpointSite %u: addr = 0x%8.8" PRIx64 " type = %s breakpoint hw_index = %i hit_count = %-4u",
88 IsHardware() ? "hardware" : "software",
94 BreakpointSite::GetDescription (Stream *s, lldb::DescriptionLevel level)
96 if (level != lldb::eDescriptionLevelBrief)
97 s->Printf ("breakpoint site: %d at 0x%8.8" PRIx64, GetID(), GetLoadAddress());
98 m_owners.GetDescription (s, level);
102 BreakpointSite::IsInternal() const
104 return m_owners.IsInternal();
108 BreakpointSite::GetTrapOpcodeBytes()
110 return &m_trap_opcode[0];
114 BreakpointSite::GetTrapOpcodeBytes() const
116 return &m_trap_opcode[0];
120 BreakpointSite::GetTrapOpcodeMaxByteSize() const
122 return sizeof(m_trap_opcode);
126 BreakpointSite::SetTrapOpcode (const uint8_t *trap_opcode, uint32_t trap_opcode_size)
128 if (trap_opcode_size > 0 && trap_opcode_size <= sizeof(m_trap_opcode))
130 m_byte_size = trap_opcode_size;
131 ::memcpy (m_trap_opcode, trap_opcode, trap_opcode_size);
139 BreakpointSite::GetSavedOpcodeBytes()
141 return &m_saved_opcode[0];
145 BreakpointSite::GetSavedOpcodeBytes() const
147 return &m_saved_opcode[0];
151 BreakpointSite::IsEnabled () const
157 BreakpointSite::SetEnabled (bool enabled)
163 BreakpointSite::AddOwner (const BreakpointLocationSP &owner)
169 BreakpointSite::RemoveOwner (lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
171 m_owners.Remove(break_id, break_loc_id);
172 return m_owners.GetSize();
176 BreakpointSite::GetNumberOfOwners ()
178 return m_owners.GetSize();
182 BreakpointSite::GetOwnerAtIndex (size_t index)
184 return m_owners.GetByIndex (index);
188 BreakpointSite::ValidForThisThread (Thread *thread)
190 return m_owners.ValidForThisThread(thread);
194 BreakpointSite::IntersectsRange(lldb::addr_t addr, size_t size, lldb::addr_t *intersect_addr, size_t *intersect_size, size_t *opcode_offset) const
196 // We only use software traps for software breakpoints
201 const lldb::addr_t bp_end_addr = m_addr + m_byte_size;
202 const lldb::addr_t end_addr = addr + size;
203 // Is the breakpoint end address before the passed in start address?
204 if (bp_end_addr <= addr)
206 // Is the breakpoint start address after passed in end address?
207 if (end_addr <= m_addr)
209 if (intersect_addr || intersect_size || opcode_offset)
214 *intersect_addr = addr;
216 *intersect_size = std::min<lldb::addr_t>(bp_end_addr, end_addr) - addr;
218 *opcode_offset = addr - m_addr;
223 *intersect_addr = m_addr;
225 *intersect_size = std::min<lldb::addr_t>(bp_end_addr, end_addr) - m_addr;