blob: 28d7d93b9bb9ad07add9cf826f5eb88bb84a8e95 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Section.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/Section.h"
11#include "lldb/Core/Module.h"
12#include "lldb/Symbol/ObjectFile.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000013#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000014#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
16using namespace lldb;
17using namespace lldb_private;
18
Greg Claytone72dfb32012-02-24 01:59:29 +000019Section::Section (const ModuleSP &module_sp,
Michael Sartaina7499c92013-07-01 19:45:50 +000020 ObjectFile *obj_file,
Greg Claytone72dfb32012-02-24 01:59:29 +000021 user_id_t sect_id,
22 const ConstString &name,
23 SectionType sect_type,
24 addr_t file_addr,
25 addr_t byte_size,
Greg Clayton9422dd62013-03-04 21:46:16 +000026 lldb::offset_t file_offset,
27 lldb::offset_t file_size,
Greg Claytone72dfb32012-02-24 01:59:29 +000028 uint32_t flags) :
29 ModuleChild (module_sp),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030 UserID (sect_id),
31 Flags (flags),
Michael Sartaina7499c92013-07-01 19:45:50 +000032 m_obj_file (obj_file),
Greg Claytond8c3d4b2013-06-19 21:50:28 +000033 m_type (sect_type),
Greg Claytone72dfb32012-02-24 01:59:29 +000034 m_parent_wp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035 m_name (name),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036 m_file_addr (file_addr),
37 m_byte_size (byte_size),
38 m_file_offset (file_offset),
39 m_file_size (file_size),
40 m_children (),
41 m_fake (false),
Greg Clayton741f3f92012-03-27 21:10:07 +000042 m_encrypted (false),
Greg Clayton9422dd62013-03-04 21:46:16 +000043 m_thread_specific (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044{
Daniel Malead01b2952012-11-29 21:49:15 +000045// printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16" PRIx64 ", addr=[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), file [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), flags = 0x%8.8x, name = %s\n",
Greg Claytone72dfb32012-02-24 01:59:29 +000046// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, name.GetCString());
47}
48
49Section::Section (const lldb::SectionSP &parent_section_sp,
50 const ModuleSP &module_sp,
Michael Sartaina7499c92013-07-01 19:45:50 +000051 ObjectFile *obj_file,
Greg Claytone72dfb32012-02-24 01:59:29 +000052 user_id_t sect_id,
53 const ConstString &name,
54 SectionType sect_type,
55 addr_t file_addr,
56 addr_t byte_size,
Greg Clayton9422dd62013-03-04 21:46:16 +000057 lldb::offset_t file_offset,
58 lldb::offset_t file_size,
Greg Claytone72dfb32012-02-24 01:59:29 +000059 uint32_t flags) :
60 ModuleChild (module_sp),
61 UserID (sect_id),
62 Flags (flags),
Michael Sartaina7499c92013-07-01 19:45:50 +000063 m_obj_file (obj_file),
Greg Claytond8c3d4b2013-06-19 21:50:28 +000064 m_type (sect_type),
Greg Claytone72dfb32012-02-24 01:59:29 +000065 m_parent_wp (),
66 m_name (name),
Greg Claytone72dfb32012-02-24 01:59:29 +000067 m_file_addr (file_addr),
68 m_byte_size (byte_size),
69 m_file_offset (file_offset),
70 m_file_size (file_size),
71 m_children (),
72 m_fake (false),
Greg Clayton741f3f92012-03-27 21:10:07 +000073 m_encrypted (false),
Greg Clayton9422dd62013-03-04 21:46:16 +000074 m_thread_specific (false)
Greg Claytone72dfb32012-02-24 01:59:29 +000075{
Daniel Malead01b2952012-11-29 21:49:15 +000076// printf ("Section::Section(%p): module=%p, sect_id = 0x%16.16" PRIx64 ", addr=[0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), file [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 "), flags = 0x%8.8x, name = %s.%s\n",
Greg Claytone72dfb32012-02-24 01:59:29 +000077// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, parent_section_sp->GetName().GetCString(), name.GetCString());
78 if (parent_section_sp)
79 m_parent_wp = parent_section_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080}
81
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082Section::~Section()
83{
Greg Claytone72dfb32012-02-24 01:59:29 +000084// printf ("Section::~Section(%p)\n", this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085}
86
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087addr_t
88Section::GetFileAddress () const
89{
Greg Claytone72dfb32012-02-24 01:59:29 +000090 SectionSP parent_sp (GetParent ());
91 if (parent_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092 {
93 // This section has a parent which means m_file_addr is an offset into
94 // the parent section, so the file address for this section is the file
95 // address of the parent plus the offset
Greg Claytone72dfb32012-02-24 01:59:29 +000096 return parent_sp->GetFileAddress() + m_file_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097 }
98 // This section has no parent, so m_file_addr is the file base address
99 return m_file_addr;
100}
101
Jason Molenda20eb31b2013-08-16 03:20:42 +0000102bool
103Section::SetFileAddress (lldb::addr_t file_addr)
104{
105 SectionSP parent_sp (GetParent ());
106 if (parent_sp)
107 {
108 if (m_file_addr >= file_addr)
109 return parent_sp->SetFileAddress (m_file_addr - file_addr);
110 return false;
111 }
112 else
113 {
114 // This section has no parent, so m_file_addr is the file base address
115 m_file_addr = file_addr;
116 return true;
117 }
118}
119
Greg Claytone72dfb32012-02-24 01:59:29 +0000120lldb::addr_t
121Section::GetOffset () const
122{
123 // This section has a parent which means m_file_addr is an offset.
124 SectionSP parent_sp (GetParent ());
125 if (parent_sp)
126 return m_file_addr;
127
128 // This section has no parent, so there is no offset to be had
129 return 0;
130}
131
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132addr_t
Greg Claytonf5e56de2010-09-14 23:36:40 +0000133Section::GetLoadBaseAddress (Target *target) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134{
135 addr_t load_base_addr = LLDB_INVALID_ADDRESS;
Greg Clayton9422dd62013-03-04 21:46:16 +0000136 SectionSP parent_sp (GetParent ());
137 if (parent_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000139 load_base_addr = parent_sp->GetLoadBaseAddress (target);
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000140 if (load_base_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +0000141 load_base_addr += GetOffset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000142 }
143 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000145 load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (const_cast<Section *>(this)->shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147 return load_base_addr;
148}
149
150bool
151Section::ResolveContainedAddress (addr_t offset, Address &so_addr) const
152{
Greg Claytonc7bece562013-01-25 18:06:21 +0000153 const size_t num_children = m_children.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000154 if (num_children > 0)
155 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000156 for (size_t i=0; i<num_children; i++)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157 {
158 Section* child_section = m_children.GetSectionAtIndex (i).get();
159
160 addr_t child_offset = child_section->GetOffset();
161 if (child_offset <= offset && offset - child_offset < child_section->GetByteSize())
162 return child_section->ResolveContainedAddress (offset - child_offset, so_addr);
163 }
164 }
Greg Clayton9422dd62013-03-04 21:46:16 +0000165 so_addr.SetOffset(offset);
166 so_addr.SetSection(const_cast<Section *>(this)->shared_from_this());
167
Sean Callanan27e02d02012-07-12 20:44:21 +0000168#ifdef LLDB_CONFIGURATION_DEBUG
Greg Clayton9422dd62013-03-04 21:46:16 +0000169 // For debug builds, ensure that there are no orphaned (i.e., moduleless) sections.
170 assert(GetModule().get());
Sean Callanan27e02d02012-07-12 20:44:21 +0000171#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000172 return true;
173}
174
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175bool
176Section::ContainsFileAddress (addr_t vm_addr) const
177{
178 const addr_t file_addr = GetFileAddress();
179 if (file_addr != LLDB_INVALID_ADDRESS)
180 {
181 if (file_addr <= vm_addr)
182 {
183 const addr_t offset = vm_addr - file_addr;
184 return offset < GetByteSize();
185 }
186 }
187 return false;
188}
189
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190int
191Section::Compare (const Section& a, const Section& b)
192{
193 if (&a == &b)
194 return 0;
195
Greg Claytone72dfb32012-02-24 01:59:29 +0000196 const ModuleSP a_module_sp = a.GetModule();
197 const ModuleSP b_module_sp = b.GetModule();
198 if (a_module_sp == b_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199 {
200 user_id_t a_sect_uid = a.GetID();
201 user_id_t b_sect_uid = b.GetID();
202 if (a_sect_uid < b_sect_uid)
203 return -1;
204 if (a_sect_uid > b_sect_uid)
205 return 1;
206 return 0;
207 }
208 else
209 {
210 // The modules are different, just compare the module pointers
Greg Claytone72dfb32012-02-24 01:59:29 +0000211 if (a_module_sp.get() < b_module_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000212 return -1;
213 else
214 return 1; // We already know the modules aren't equal
215 }
216}
217
218
219void
Greg Clayton10177aa2010-12-08 05:08:21 +0000220Section::Dump (Stream *s, Target *target, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221{
Greg Clayton89411422010-10-08 00:21:05 +0000222// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000223 s->Indent();
Daniel Malead01b2952012-11-29 21:49:15 +0000224 s->Printf("0x%8.8" PRIx64 " %-16s ", GetID(), GetSectionTypeAsCString (m_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225 bool resolved = true;
226 addr_t addr = LLDB_INVALID_ADDRESS;
227
228 if (GetByteSize() == 0)
229 s->Printf("%39s", "");
230 else
231 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000232 if (target)
Greg Claytonf5e56de2010-09-14 23:36:40 +0000233 addr = GetLoadBaseAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234
235 if (addr == LLDB_INVALID_ADDRESS)
236 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000237 if (target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238 resolved = false;
239 addr = GetFileAddress();
240 }
241
242 VMRange range(addr, addr + m_byte_size);
243 range.Dump (s, 0);
244 }
245
Daniel Malead01b2952012-11-29 21:49:15 +0000246 s->Printf("%c 0x%8.8" PRIx64 " 0x%8.8" PRIx64 " 0x%8.8x ", resolved ? ' ' : '*', m_file_offset, m_file_size, Get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247
248 DumpName (s);
249
250 s->EOL();
251
Greg Clayton10177aa2010-12-08 05:08:21 +0000252 if (depth > 0)
253 m_children.Dump(s, target, false, depth - 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254}
255
256void
257Section::DumpName (Stream *s) const
258{
Greg Claytone72dfb32012-02-24 01:59:29 +0000259 SectionSP parent_sp (GetParent ());
260 if (parent_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000262 parent_sp->DumpName (s);
263 s->PutChar('.');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264 }
265 else
266 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000267 // The top most section prints the module basename
Michael Sartaina7499c92013-07-01 19:45:50 +0000268 const char * name = NULL;
Greg Claytone72dfb32012-02-24 01:59:29 +0000269 ModuleSP module_sp (GetModule());
Michael Sartaina7499c92013-07-01 19:45:50 +0000270 const FileSpec &file_spec = m_obj_file->GetFileSpec();
271
272 if (m_obj_file)
273 name = file_spec.GetFilename().AsCString();
274 if ((!name || !name[0]) && module_sp)
275 name = module_sp->GetFileSpec().GetFilename().AsCString();
276 if (name && name[0])
277 s->Printf("%s.", name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278 }
279 m_name.Dump(s);
280}
281
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283Section::IsDescendant (const Section *section)
284{
285 if (this == section)
286 return true;
Greg Claytone72dfb32012-02-24 01:59:29 +0000287 SectionSP parent_sp (GetParent ());
288 if (parent_sp)
289 return parent_sp->IsDescendant (section);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290 return false;
291}
292
293bool
294Section::Slide (addr_t slide_amount, bool slide_children)
295{
296 if (m_file_addr != LLDB_INVALID_ADDRESS)
297 {
298 if (slide_amount == 0)
299 return true;
300
301 m_file_addr += slide_amount;
302
303 if (slide_children)
304 m_children.Slide (slide_amount, slide_children);
305
306 return true;
307 }
308 return false;
309}
310
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311#pragma mark SectionList
312
313SectionList::SectionList () :
314 m_sections()
315{
316}
317
318
319SectionList::~SectionList ()
320{
321}
322
Greg Clayton3046e662013-07-10 01:23:25 +0000323SectionList &
324SectionList::operator = (const SectionList& rhs)
Michael Sartaina7499c92013-07-01 19:45:50 +0000325{
Greg Clayton3046e662013-07-10 01:23:25 +0000326 if (this != &rhs)
327 m_sections = rhs.m_sections;
328 return *this;
Michael Sartaina7499c92013-07-01 19:45:50 +0000329}
330
Greg Claytonc7bece562013-01-25 18:06:21 +0000331size_t
Greg Claytone72dfb32012-02-24 01:59:29 +0000332SectionList::AddSection (const lldb::SectionSP& section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333{
Greg Claytone72dfb32012-02-24 01:59:29 +0000334 assert (section_sp.get());
Greg Claytonc7bece562013-01-25 18:06:21 +0000335 size_t section_index = m_sections.size();
Greg Claytone72dfb32012-02-24 01:59:29 +0000336 m_sections.push_back(section_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000337 return section_index;
338}
339
Michael Sartaina7499c92013-07-01 19:45:50 +0000340// Warning, this can be slow as it's removing items from a std::vector.
341bool
342SectionList::DeleteSection (size_t idx)
343{
344 if (idx < m_sections.size())
345 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000346 m_sections.erase (m_sections.begin() + idx);
347 return true;
348 }
349 return false;
350}
351
Greg Claytonc7bece562013-01-25 18:06:21 +0000352size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000353SectionList::FindSectionIndex (const Section* sect)
354{
355 iterator sect_iter;
356 iterator begin = m_sections.begin();
357 iterator end = m_sections.end();
358 for (sect_iter = begin; sect_iter != end; ++sect_iter)
359 {
360 if (sect_iter->get() == sect)
361 {
362 // The secton was already in this section list
363 return std::distance (begin, sect_iter);
364 }
365 }
366 return UINT32_MAX;
367}
368
Greg Claytonc7bece562013-01-25 18:06:21 +0000369size_t
Greg Claytone72dfb32012-02-24 01:59:29 +0000370SectionList::AddUniqueSection (const lldb::SectionSP& sect_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371{
Greg Claytonc7bece562013-01-25 18:06:21 +0000372 size_t sect_idx = FindSectionIndex (sect_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 if (sect_idx == UINT32_MAX)
Michael Sartaina7499c92013-07-01 19:45:50 +0000374 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375 sect_idx = AddSection (sect_sp);
Michael Sartaina7499c92013-07-01 19:45:50 +0000376 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377 return sect_idx;
378}
379
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380bool
Greg Claytone72dfb32012-02-24 01:59:29 +0000381SectionList::ReplaceSection (user_id_t sect_id, const lldb::SectionSP& sect_sp, uint32_t depth)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382{
383 iterator sect_iter, end = m_sections.end();
384 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
385 {
386 if ((*sect_iter)->GetID() == sect_id)
387 {
388 *sect_iter = sect_sp;
389 return true;
390 }
391 else if (depth > 0)
392 {
393 if ((*sect_iter)->GetChildren().ReplaceSection(sect_id, sect_sp, depth - 1))
394 return true;
395 }
396 }
397 return false;
398}
399
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401SectionList::GetNumSections (uint32_t depth) const
402{
403 size_t count = m_sections.size();
404 if (depth > 0)
405 {
406 const_iterator sect_iter, end = m_sections.end();
407 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
408 {
409 count += (*sect_iter)->GetChildren().GetNumSections(depth - 1);
410 }
411 }
412 return count;
413}
414
415SectionSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000416SectionList::GetSectionAtIndex (size_t idx) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417{
418 SectionSP sect_sp;
419 if (idx < m_sections.size())
420 sect_sp = m_sections[idx];
421 return sect_sp;
422}
423
424SectionSP
425SectionList::FindSectionByName (const ConstString &section_dstr) const
426{
427 SectionSP sect_sp;
428 // Check if we have a valid section string
Greg Claytone72dfb32012-02-24 01:59:29 +0000429 if (section_dstr && !m_sections.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430 {
431 const_iterator sect_iter;
432 const_iterator end = m_sections.end();
433 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
434 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000435 Section *child_section = sect_iter->get();
436 assert (child_section);
437 if (child_section->GetName() == section_dstr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438 {
439 sect_sp = *sect_iter;
440 }
441 else
442 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000443 sect_sp = child_section->GetChildren().FindSectionByName(section_dstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444 }
445 }
446 }
447 return sect_sp;
448}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449
450SectionSP
451SectionList::FindSectionByID (user_id_t sect_id) const
452{
453 SectionSP sect_sp;
454 if (sect_id)
455 {
456 const_iterator sect_iter;
457 const_iterator end = m_sections.end();
458 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
459 {
460 if ((*sect_iter)->GetID() == sect_id)
461 {
462 sect_sp = *sect_iter;
463 break;
464 }
465 else
466 {
467 sect_sp = (*sect_iter)->GetChildren().FindSectionByID (sect_id);
468 }
469 }
470 }
471 return sect_sp;
472}
473
Greg Clayton70e33eb2010-07-21 21:49:46 +0000474
475SectionSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000476SectionList::FindSectionByType (SectionType sect_type, bool check_children, size_t start_idx) const
Greg Clayton70e33eb2010-07-21 21:49:46 +0000477{
478 SectionSP sect_sp;
Greg Claytonc7bece562013-01-25 18:06:21 +0000479 size_t num_sections = m_sections.size();
480 for (size_t idx = start_idx; idx < num_sections; ++idx)
Greg Clayton70e33eb2010-07-21 21:49:46 +0000481 {
482 if (m_sections[idx]->GetType() == sect_type)
483 {
484 sect_sp = m_sections[idx];
485 break;
486 }
Greg Clayton4ceb9982010-07-21 22:54:26 +0000487 else if (check_children)
488 {
489 sect_sp = m_sections[idx]->GetChildren().FindSectionByType (sect_type, check_children, 0);
490 if (sect_sp)
491 break;
492 }
Greg Clayton70e33eb2010-07-21 21:49:46 +0000493 }
494 return sect_sp;
495}
496
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497SectionSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000498SectionList::FindSectionContainingFileAddress (addr_t vm_addr, uint32_t depth) const
499{
500 SectionSP sect_sp;
501 const_iterator sect_iter;
502 const_iterator end = m_sections.end();
503 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
504 {
505 Section *sect = sect_iter->get();
506 if (sect->ContainsFileAddress (vm_addr))
507 {
508 // The file address is in this section. We need to make sure one of our child
509 // sections doesn't contain this address as well as obeying the depth limit
510 // that was passed in.
511 if (depth > 0)
512 sect_sp = sect->GetChildren().FindSectionContainingFileAddress(vm_addr, depth - 1);
513
514 if (sect_sp.get() == NULL && !sect->IsFake())
515 sect_sp = *sect_iter;
516 }
517 }
518 return sect_sp;
519}
520
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521bool
522SectionList::ContainsSection(user_id_t sect_id) const
523{
524 return FindSectionByID (sect_id).get() != NULL;
525}
526
527void
Greg Clayton10177aa2010-12-08 05:08:21 +0000528SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529{
Greg Claytonf6693582010-12-07 18:05:22 +0000530 bool target_has_loaded_sections = target && !target->GetSectionLoadList().IsEmpty();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 if (show_header && !m_sections.empty())
532 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 s->Indent();
Greg Clayton44435ed2012-01-12 05:25:17 +0000534 s->Printf( "SectID Type %s Address File Off. File Size Flags Section Name\n", target_has_loaded_sections ? "Load" : "File");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535 s->Indent();
Greg Clayton44435ed2012-01-12 05:25:17 +0000536 s->PutCString("---------- ---------------- --------------------------------------- ---------- ---------- ---------- ----------------------------\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537 }
538
539
540 const_iterator sect_iter;
541 const_iterator end = m_sections.end();
542 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
543 {
Greg Clayton10177aa2010-12-08 05:08:21 +0000544 (*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545 }
546
547 if (show_header && !m_sections.empty())
548 s->IndentLess();
549
550}
551
552size_t
553SectionList::Slide (addr_t slide_amount, bool slide_children)
554{
555 size_t count = 0;
556 const_iterator pos, end = m_sections.end();
557 for (pos = m_sections.begin(); pos != end; ++pos)
558 {
559 if ((*pos)->Slide(slide_amount, slide_children))
560 ++count;
561 }
562 return count;
563}