blob: 115c662b9f87610643333542469034230b0235c3 [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 Clayton3698a712014-05-14 01:12:09 +0000334 if (section_sp)
335 {
336 size_t section_index = m_sections.size();
337 m_sections.push_back(section_sp);
338 return section_index;
339 }
340 return SIZE_T_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341}
342
Michael Sartaina7499c92013-07-01 19:45:50 +0000343// Warning, this can be slow as it's removing items from a std::vector.
344bool
345SectionList::DeleteSection (size_t idx)
346{
347 if (idx < m_sections.size())
348 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000349 m_sections.erase (m_sections.begin() + idx);
350 return true;
351 }
352 return false;
353}
354
Greg Claytonc7bece562013-01-25 18:06:21 +0000355size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356SectionList::FindSectionIndex (const Section* sect)
357{
358 iterator sect_iter;
359 iterator begin = m_sections.begin();
360 iterator end = m_sections.end();
361 for (sect_iter = begin; sect_iter != end; ++sect_iter)
362 {
363 if (sect_iter->get() == sect)
364 {
365 // The secton was already in this section list
366 return std::distance (begin, sect_iter);
367 }
368 }
369 return UINT32_MAX;
370}
371
Greg Claytonc7bece562013-01-25 18:06:21 +0000372size_t
Greg Claytone72dfb32012-02-24 01:59:29 +0000373SectionList::AddUniqueSection (const lldb::SectionSP& sect_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374{
Greg Claytonc7bece562013-01-25 18:06:21 +0000375 size_t sect_idx = FindSectionIndex (sect_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376 if (sect_idx == UINT32_MAX)
Michael Sartaina7499c92013-07-01 19:45:50 +0000377 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378 sect_idx = AddSection (sect_sp);
Michael Sartaina7499c92013-07-01 19:45:50 +0000379 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380 return sect_idx;
381}
382
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383bool
Greg Claytone72dfb32012-02-24 01:59:29 +0000384SectionList::ReplaceSection (user_id_t sect_id, const lldb::SectionSP& sect_sp, uint32_t depth)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385{
386 iterator sect_iter, end = m_sections.end();
387 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
388 {
389 if ((*sect_iter)->GetID() == sect_id)
390 {
391 *sect_iter = sect_sp;
392 return true;
393 }
394 else if (depth > 0)
395 {
396 if ((*sect_iter)->GetChildren().ReplaceSection(sect_id, sect_sp, depth - 1))
397 return true;
398 }
399 }
400 return false;
401}
402
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404SectionList::GetNumSections (uint32_t depth) const
405{
406 size_t count = m_sections.size();
407 if (depth > 0)
408 {
409 const_iterator sect_iter, end = m_sections.end();
410 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
411 {
412 count += (*sect_iter)->GetChildren().GetNumSections(depth - 1);
413 }
414 }
415 return count;
416}
417
418SectionSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000419SectionList::GetSectionAtIndex (size_t idx) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420{
421 SectionSP sect_sp;
422 if (idx < m_sections.size())
423 sect_sp = m_sections[idx];
424 return sect_sp;
425}
426
427SectionSP
428SectionList::FindSectionByName (const ConstString &section_dstr) const
429{
430 SectionSP sect_sp;
431 // Check if we have a valid section string
Greg Claytone72dfb32012-02-24 01:59:29 +0000432 if (section_dstr && !m_sections.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433 {
434 const_iterator sect_iter;
435 const_iterator end = m_sections.end();
436 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
437 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000438 Section *child_section = sect_iter->get();
Greg Clayton3698a712014-05-14 01:12:09 +0000439 if (child_section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440 {
Greg Clayton3698a712014-05-14 01:12:09 +0000441 if (child_section->GetName() == section_dstr)
442 {
443 sect_sp = *sect_iter;
444 }
445 else
446 {
447 sect_sp = child_section->GetChildren().FindSectionByName(section_dstr);
448 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449 }
450 }
451 }
452 return sect_sp;
453}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454
455SectionSP
456SectionList::FindSectionByID (user_id_t sect_id) const
457{
458 SectionSP sect_sp;
459 if (sect_id)
460 {
461 const_iterator sect_iter;
462 const_iterator end = m_sections.end();
463 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
464 {
465 if ((*sect_iter)->GetID() == sect_id)
466 {
467 sect_sp = *sect_iter;
468 break;
469 }
470 else
471 {
472 sect_sp = (*sect_iter)->GetChildren().FindSectionByID (sect_id);
473 }
474 }
475 }
476 return sect_sp;
477}
478
Greg Clayton70e33eb2010-07-21 21:49:46 +0000479
480SectionSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000481SectionList::FindSectionByType (SectionType sect_type, bool check_children, size_t start_idx) const
Greg Clayton70e33eb2010-07-21 21:49:46 +0000482{
483 SectionSP sect_sp;
Greg Claytonc7bece562013-01-25 18:06:21 +0000484 size_t num_sections = m_sections.size();
485 for (size_t idx = start_idx; idx < num_sections; ++idx)
Greg Clayton70e33eb2010-07-21 21:49:46 +0000486 {
487 if (m_sections[idx]->GetType() == sect_type)
488 {
489 sect_sp = m_sections[idx];
490 break;
491 }
Greg Clayton4ceb9982010-07-21 22:54:26 +0000492 else if (check_children)
493 {
494 sect_sp = m_sections[idx]->GetChildren().FindSectionByType (sect_type, check_children, 0);
495 if (sect_sp)
496 break;
497 }
Greg Clayton70e33eb2010-07-21 21:49:46 +0000498 }
499 return sect_sp;
500}
501
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502SectionSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503SectionList::FindSectionContainingFileAddress (addr_t vm_addr, uint32_t depth) const
504{
505 SectionSP sect_sp;
506 const_iterator sect_iter;
507 const_iterator end = m_sections.end();
508 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
509 {
510 Section *sect = sect_iter->get();
511 if (sect->ContainsFileAddress (vm_addr))
512 {
513 // The file address is in this section. We need to make sure one of our child
514 // sections doesn't contain this address as well as obeying the depth limit
515 // that was passed in.
516 if (depth > 0)
517 sect_sp = sect->GetChildren().FindSectionContainingFileAddress(vm_addr, depth - 1);
518
519 if (sect_sp.get() == NULL && !sect->IsFake())
520 sect_sp = *sect_iter;
521 }
522 }
523 return sect_sp;
524}
525
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526bool
527SectionList::ContainsSection(user_id_t sect_id) const
528{
529 return FindSectionByID (sect_id).get() != NULL;
530}
531
532void
Greg Clayton10177aa2010-12-08 05:08:21 +0000533SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534{
Greg Claytonf6693582010-12-07 18:05:22 +0000535 bool target_has_loaded_sections = target && !target->GetSectionLoadList().IsEmpty();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536 if (show_header && !m_sections.empty())
537 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 s->Indent();
Greg Clayton44435ed2012-01-12 05:25:17 +0000539 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 +0000540 s->Indent();
Greg Clayton44435ed2012-01-12 05:25:17 +0000541 s->PutCString("---------- ---------------- --------------------------------------- ---------- ---------- ---------- ----------------------------\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 }
543
544
545 const_iterator sect_iter;
546 const_iterator end = m_sections.end();
547 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
548 {
Greg Clayton10177aa2010-12-08 05:08:21 +0000549 (*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 }
551
552 if (show_header && !m_sections.empty())
553 s->IndentLess();
554
555}
556
557size_t
558SectionList::Slide (addr_t slide_amount, bool slide_children)
559{
560 size_t count = 0;
561 const_iterator pos, end = m_sections.end();
562 for (pos = m_sections.begin(); pos != end; ++pos)
563 {
564 if ((*pos)->Slide(slide_amount, slide_children))
565 ++count;
566 }
567 return count;
568}