1 //===-- SectionLoadHistory.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/Target/SectionLoadHistory.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Stream.h"
17 #include "lldb/Target/SectionLoadList.h"
20 using namespace lldb_private;
24 SectionLoadHistory::IsEmpty() const
26 Mutex::Locker locker(m_mutex);
27 return m_stop_id_to_section_load_list.empty();
31 SectionLoadHistory::Clear ()
33 Mutex::Locker locker(m_mutex);
34 m_stop_id_to_section_load_list.clear();
38 SectionLoadHistory::GetLastStopID() const
40 Mutex::Locker locker(m_mutex);
41 if (m_stop_id_to_section_load_list.empty())
44 return m_stop_id_to_section_load_list.rbegin()->first;
48 SectionLoadHistory::GetSectionLoadListForStopID (uint32_t stop_id, bool read_only)
50 if (m_stop_id_to_section_load_list.empty())
52 SectionLoadListSP section_load_list_sp(new SectionLoadList());
53 if (stop_id == eStopIDNow)
55 m_stop_id_to_section_load_list[stop_id] = section_load_list_sp;
56 return section_load_list_sp.get();
62 // The section load list is for reading data only so we don't need to create
63 // a new SectionLoadList for the current stop ID, just return the section
64 // load list for the stop ID that is equal to or less than the current stop ID
65 if (stop_id == eStopIDNow)
67 // If we are asking for the latest and greatest value, it is always
68 // at the end of our list becuase that will be the highest stop ID.
69 StopIDToSectionLoadList::reverse_iterator rpos = m_stop_id_to_section_load_list.rbegin();
70 return rpos->second.get();
74 StopIDToSectionLoadList::iterator pos = m_stop_id_to_section_load_list.lower_bound(stop_id);
75 if (pos != m_stop_id_to_section_load_list.end() && pos->first == stop_id)
76 return pos->second.get();
77 else if (pos != m_stop_id_to_section_load_list.begin())
80 return pos->second.get();
86 // You can only use "eStopIDNow" when reading from the section load history
87 assert(stop_id != eStopIDNow);
89 // We are updating the section load list (not read only), so if the stop ID
90 // passed in isn't the same as the last stop ID in our collection, then create
91 // a new node using the current stop ID
92 StopIDToSectionLoadList::iterator pos = m_stop_id_to_section_load_list.lower_bound(stop_id);
93 if (pos != m_stop_id_to_section_load_list.end() && pos->first == stop_id)
95 // We already have an entry for this value
96 return pos->second.get();
99 // We must make a new section load list that is based on the last valid
100 // section load list, so here we copy the last section load list and add
101 // a new node for the current stop ID.
102 StopIDToSectionLoadList::reverse_iterator rpos = m_stop_id_to_section_load_list.rbegin();
103 SectionLoadListSP section_load_list_sp(new SectionLoadList(*rpos->second.get()));
104 m_stop_id_to_section_load_list[stop_id] = section_load_list_sp;
105 return section_load_list_sp.get();
112 SectionLoadHistory::GetCurrentSectionLoadList ()
114 const bool read_only = true;
115 SectionLoadList *section_load_list = GetSectionLoadListForStopID (eStopIDNow, read_only);
116 assert(section_load_list != NULL);
117 return *section_load_list;
121 SectionLoadHistory::GetSectionLoadAddress (uint32_t stop_id, const lldb::SectionSP §ion_sp)
123 Mutex::Locker locker(m_mutex);
124 const bool read_only = true;
125 SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
126 return section_load_list->GetSectionLoadAddress(section_sp);
130 SectionLoadHistory::ResolveLoadAddress (uint32_t stop_id, addr_t load_addr, Address &so_addr)
132 // First find the top level section that this load address exists in
133 Mutex::Locker locker(m_mutex);
134 const bool read_only = true;
135 SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
136 return section_load_list->ResolveLoadAddress (load_addr, so_addr);
140 SectionLoadHistory::SetSectionLoadAddress (uint32_t stop_id,
141 const lldb::SectionSP §ion_sp,
145 Mutex::Locker locker(m_mutex);
146 const bool read_only = false;
147 SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
148 return section_load_list->SetSectionLoadAddress(section_sp, load_addr, warn_multiple);
152 SectionLoadHistory::SetSectionUnloaded (uint32_t stop_id, const lldb::SectionSP §ion_sp)
154 Mutex::Locker locker(m_mutex);
155 const bool read_only = false;
156 SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
157 return section_load_list->SetSectionUnloaded (section_sp);
161 SectionLoadHistory::SetSectionUnloaded (uint32_t stop_id, const lldb::SectionSP §ion_sp, addr_t load_addr)
163 Mutex::Locker locker(m_mutex);
164 const bool read_only = false;
165 SectionLoadList *section_load_list = GetSectionLoadListForStopID (stop_id, read_only);
166 return section_load_list->SetSectionUnloaded (section_sp, load_addr);
170 SectionLoadHistory::Dump (Stream &s, Target *target)
172 Mutex::Locker locker(m_mutex);
173 StopIDToSectionLoadList::iterator pos, end = m_stop_id_to_section_load_list.end();
174 for (pos = m_stop_id_to_section_load_list.begin(); pos != end; ++pos)
176 s.Printf("StopID = %u:\n", pos->first);
177 pos->second->Dump(s, target);