blob: e2a084ceb2f224a511c28d5e20a9e71038c7f1c2 [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 Claytonf5e56de2010-09-14 23:36:40 +000013#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014
15using namespace lldb;
16using namespace lldb_private;
17
Greg Claytone72dfb32012-02-24 01:59:29 +000018Section::Section (const ModuleSP &module_sp,
Michael Sartaina7499c92013-07-01 19:45:50 +000019 ObjectFile *obj_file,
Greg Claytone72dfb32012-02-24 01:59:29 +000020 user_id_t sect_id,
21 const ConstString &name,
22 SectionType sect_type,
23 addr_t file_addr,
24 addr_t byte_size,
Greg Clayton9422dd62013-03-04 21:46:16 +000025 lldb::offset_t file_offset,
26 lldb::offset_t file_size,
Greg Claytone72dfb32012-02-24 01:59:29 +000027 uint32_t flags) :
28 ModuleChild (module_sp),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029 UserID (sect_id),
30 Flags (flags),
Michael Sartaina7499c92013-07-01 19:45:50 +000031 m_obj_file (obj_file),
Greg Claytond8c3d4b2013-06-19 21:50:28 +000032 m_type (sect_type),
Greg Claytone72dfb32012-02-24 01:59:29 +000033 m_parent_wp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034 m_name (name),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035 m_file_addr (file_addr),
36 m_byte_size (byte_size),
37 m_file_offset (file_offset),
38 m_file_size (file_size),
39 m_children (),
40 m_fake (false),
Greg Clayton741f3f92012-03-27 21:10:07 +000041 m_encrypted (false),
Greg Clayton9422dd62013-03-04 21:46:16 +000042 m_thread_specific (false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043{
Daniel Malead01b2952012-11-29 21:49:15 +000044// 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 +000045// this, module_sp.get(), sect_id, file_addr, file_addr + byte_size, file_offset, file_offset + file_size, flags, name.GetCString());
46}
47
48Section::Section (const lldb::SectionSP &parent_section_sp,
49 const ModuleSP &module_sp,
Michael Sartaina7499c92013-07-01 19:45:50 +000050 ObjectFile *obj_file,
Greg Claytone72dfb32012-02-24 01:59:29 +000051 user_id_t sect_id,
52 const ConstString &name,
53 SectionType sect_type,
54 addr_t file_addr,
55 addr_t byte_size,
Greg Clayton9422dd62013-03-04 21:46:16 +000056 lldb::offset_t file_offset,
57 lldb::offset_t file_size,
Greg Claytone72dfb32012-02-24 01:59:29 +000058 uint32_t flags) :
59 ModuleChild (module_sp),
60 UserID (sect_id),
61 Flags (flags),
Michael Sartaina7499c92013-07-01 19:45:50 +000062 m_obj_file (obj_file),
Greg Claytond8c3d4b2013-06-19 21:50:28 +000063 m_type (sect_type),
Greg Claytone72dfb32012-02-24 01:59:29 +000064 m_parent_wp (),
65 m_name (name),
Greg Claytone72dfb32012-02-24 01:59:29 +000066 m_file_addr (file_addr),
67 m_byte_size (byte_size),
68 m_file_offset (file_offset),
69 m_file_size (file_size),
70 m_children (),
71 m_fake (false),
Greg Clayton741f3f92012-03-27 21:10:07 +000072 m_encrypted (false),
Greg Clayton9422dd62013-03-04 21:46:16 +000073 m_thread_specific (false)
Greg Claytone72dfb32012-02-24 01:59:29 +000074{
Daniel Malead01b2952012-11-29 21:49:15 +000075// 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 +000076// 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());
77 if (parent_section_sp)
78 m_parent_wp = parent_section_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079}
80
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081Section::~Section()
82{
Greg Claytone72dfb32012-02-24 01:59:29 +000083// printf ("Section::~Section(%p)\n", this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084}
85
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086addr_t
87Section::GetFileAddress () const
88{
Greg Claytone72dfb32012-02-24 01:59:29 +000089 SectionSP parent_sp (GetParent ());
90 if (parent_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091 {
92 // This section has a parent which means m_file_addr is an offset into
93 // the parent section, so the file address for this section is the file
94 // address of the parent plus the offset
Greg Claytone72dfb32012-02-24 01:59:29 +000095 return parent_sp->GetFileAddress() + m_file_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096 }
97 // This section has no parent, so m_file_addr is the file base address
98 return m_file_addr;
99}
100
Jason Molenda20eb31b2013-08-16 03:20:42 +0000101bool
102Section::SetFileAddress (lldb::addr_t file_addr)
103{
104 SectionSP parent_sp (GetParent ());
105 if (parent_sp)
106 {
107 if (m_file_addr >= file_addr)
108 return parent_sp->SetFileAddress (m_file_addr - file_addr);
109 return false;
110 }
111 else
112 {
113 // This section has no parent, so m_file_addr is the file base address
114 m_file_addr = file_addr;
115 return true;
116 }
117}
118
Greg Claytone72dfb32012-02-24 01:59:29 +0000119lldb::addr_t
120Section::GetOffset () const
121{
122 // This section has a parent which means m_file_addr is an offset.
123 SectionSP parent_sp (GetParent ());
124 if (parent_sp)
125 return m_file_addr;
126
127 // This section has no parent, so there is no offset to be had
128 return 0;
129}
130
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131addr_t
Greg Claytonf5e56de2010-09-14 23:36:40 +0000132Section::GetLoadBaseAddress (Target *target) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000133{
134 addr_t load_base_addr = LLDB_INVALID_ADDRESS;
Greg Clayton9422dd62013-03-04 21:46:16 +0000135 SectionSP parent_sp (GetParent ());
136 if (parent_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000138 load_base_addr = parent_sp->GetLoadBaseAddress (target);
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000139 if (load_base_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +0000140 load_base_addr += GetOffset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141 }
142 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000144 load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (const_cast<Section *>(this)->shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146 return load_base_addr;
147}
148
149bool
150Section::ResolveContainedAddress (addr_t offset, Address &so_addr) const
151{
Greg Claytonc7bece562013-01-25 18:06:21 +0000152 const size_t num_children = m_children.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153 if (num_children > 0)
154 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000155 for (size_t i=0; i<num_children; i++)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156 {
157 Section* child_section = m_children.GetSectionAtIndex (i).get();
158
159 addr_t child_offset = child_section->GetOffset();
160 if (child_offset <= offset && offset - child_offset < child_section->GetByteSize())
161 return child_section->ResolveContainedAddress (offset - child_offset, so_addr);
162 }
163 }
Greg Clayton9422dd62013-03-04 21:46:16 +0000164 so_addr.SetOffset(offset);
165 so_addr.SetSection(const_cast<Section *>(this)->shared_from_this());
166
Sean Callanan27e02d02012-07-12 20:44:21 +0000167#ifdef LLDB_CONFIGURATION_DEBUG
Greg Clayton9422dd62013-03-04 21:46:16 +0000168 // For debug builds, ensure that there are no orphaned (i.e., moduleless) sections.
169 assert(GetModule().get());
Sean Callanan27e02d02012-07-12 20:44:21 +0000170#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000171 return true;
172}
173
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174bool
175Section::ContainsFileAddress (addr_t vm_addr) const
176{
177 const addr_t file_addr = GetFileAddress();
178 if (file_addr != LLDB_INVALID_ADDRESS)
179 {
180 if (file_addr <= vm_addr)
181 {
182 const addr_t offset = vm_addr - file_addr;
183 return offset < GetByteSize();
184 }
185 }
186 return false;
187}
188
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189int
190Section::Compare (const Section& a, const Section& b)
191{
192 if (&a == &b)
193 return 0;
194
Greg Claytone72dfb32012-02-24 01:59:29 +0000195 const ModuleSP a_module_sp = a.GetModule();
196 const ModuleSP b_module_sp = b.GetModule();
197 if (a_module_sp == b_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 {
199 user_id_t a_sect_uid = a.GetID();
200 user_id_t b_sect_uid = b.GetID();
201 if (a_sect_uid < b_sect_uid)
202 return -1;
203 if (a_sect_uid > b_sect_uid)
204 return 1;
205 return 0;
206 }
207 else
208 {
209 // The modules are different, just compare the module pointers
Greg Claytone72dfb32012-02-24 01:59:29 +0000210 if (a_module_sp.get() < b_module_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211 return -1;
212 else
213 return 1; // We already know the modules aren't equal
214 }
215}
216
217
218void
Greg Clayton10177aa2010-12-08 05:08:21 +0000219Section::Dump (Stream *s, Target *target, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220{
Greg Clayton89411422010-10-08 00:21:05 +0000221// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000222 s->Indent();
Daniel Malead01b2952012-11-29 21:49:15 +0000223 s->Printf("0x%8.8" PRIx64 " %-16s ", GetID(), GetSectionTypeAsCString (m_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 bool resolved = true;
225 addr_t addr = LLDB_INVALID_ADDRESS;
226
227 if (GetByteSize() == 0)
228 s->Printf("%39s", "");
229 else
230 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000231 if (target)
Greg Claytonf5e56de2010-09-14 23:36:40 +0000232 addr = GetLoadBaseAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000233
234 if (addr == LLDB_INVALID_ADDRESS)
235 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000236 if (target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237 resolved = false;
238 addr = GetFileAddress();
239 }
240
241 VMRange range(addr, addr + m_byte_size);
242 range.Dump (s, 0);
243 }
244
Daniel Malead01b2952012-11-29 21:49:15 +0000245 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 +0000246
247 DumpName (s);
248
249 s->EOL();
250
Greg Clayton10177aa2010-12-08 05:08:21 +0000251 if (depth > 0)
252 m_children.Dump(s, target, false, depth - 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253}
254
255void
256Section::DumpName (Stream *s) const
257{
Greg Claytone72dfb32012-02-24 01:59:29 +0000258 SectionSP parent_sp (GetParent ());
259 if (parent_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000260 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000261 parent_sp->DumpName (s);
262 s->PutChar('.');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263 }
264 else
265 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000266 // The top most section prints the module basename
Michael Sartaina7499c92013-07-01 19:45:50 +0000267 const char * name = NULL;
Greg Claytone72dfb32012-02-24 01:59:29 +0000268 ModuleSP module_sp (GetModule());
Michael Sartaina7499c92013-07-01 19:45:50 +0000269 const FileSpec &file_spec = m_obj_file->GetFileSpec();
270
271 if (m_obj_file)
272 name = file_spec.GetFilename().AsCString();
273 if ((!name || !name[0]) && module_sp)
274 name = module_sp->GetFileSpec().GetFilename().AsCString();
275 if (name && name[0])
276 s->Printf("%s.", name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000277 }
278 m_name.Dump(s);
279}
280
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282Section::IsDescendant (const Section *section)
283{
284 if (this == section)
285 return true;
Greg Claytone72dfb32012-02-24 01:59:29 +0000286 SectionSP parent_sp (GetParent ());
287 if (parent_sp)
288 return parent_sp->IsDescendant (section);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289 return false;
290}
291
292bool
293Section::Slide (addr_t slide_amount, bool slide_children)
294{
295 if (m_file_addr != LLDB_INVALID_ADDRESS)
296 {
297 if (slide_amount == 0)
298 return true;
299
300 m_file_addr += slide_amount;
301
302 if (slide_children)
303 m_children.Slide (slide_amount, slide_children);
304
305 return true;
306 }
307 return false;
308}
309
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310#pragma mark SectionList
311
312SectionList::SectionList () :
313 m_sections()
314{
315}
316
317
318SectionList::~SectionList ()
319{
320}
321
Greg Clayton3046e662013-07-10 01:23:25 +0000322SectionList &
323SectionList::operator = (const SectionList& rhs)
Michael Sartaina7499c92013-07-01 19:45:50 +0000324{
Greg Clayton3046e662013-07-10 01:23:25 +0000325 if (this != &rhs)
326 m_sections = rhs.m_sections;
327 return *this;
Michael Sartaina7499c92013-07-01 19:45:50 +0000328}
329
Greg Claytonc7bece562013-01-25 18:06:21 +0000330size_t
Greg Claytone72dfb32012-02-24 01:59:29 +0000331SectionList::AddSection (const lldb::SectionSP& section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332{
Greg Claytone72dfb32012-02-24 01:59:29 +0000333 assert (section_sp.get());
Greg Claytonc7bece562013-01-25 18:06:21 +0000334 size_t section_index = m_sections.size();
Greg Claytone72dfb32012-02-24 01:59:29 +0000335 m_sections.push_back(section_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336 return section_index;
337}
338
Michael Sartaina7499c92013-07-01 19:45:50 +0000339// Warning, this can be slow as it's removing items from a std::vector.
340bool
341SectionList::DeleteSection (size_t idx)
342{
343 if (idx < m_sections.size())
344 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000345 m_sections.erase (m_sections.begin() + idx);
346 return true;
347 }
348 return false;
349}
350
Greg Claytonc7bece562013-01-25 18:06:21 +0000351size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000352SectionList::FindSectionIndex (const Section* sect)
353{
354 iterator sect_iter;
355 iterator begin = m_sections.begin();
356 iterator end = m_sections.end();
357 for (sect_iter = begin; sect_iter != end; ++sect_iter)
358 {
359 if (sect_iter->get() == sect)
360 {
361 // The secton was already in this section list
362 return std::distance (begin, sect_iter);
363 }
364 }
365 return UINT32_MAX;
366}
367
Greg Claytonc7bece562013-01-25 18:06:21 +0000368size_t
Greg Claytone72dfb32012-02-24 01:59:29 +0000369SectionList::AddUniqueSection (const lldb::SectionSP& sect_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370{
Greg Claytonc7bece562013-01-25 18:06:21 +0000371 size_t sect_idx = FindSectionIndex (sect_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372 if (sect_idx == UINT32_MAX)
Michael Sartaina7499c92013-07-01 19:45:50 +0000373 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374 sect_idx = AddSection (sect_sp);
Michael Sartaina7499c92013-07-01 19:45:50 +0000375 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376 return sect_idx;
377}
378
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379bool
Greg Claytone72dfb32012-02-24 01:59:29 +0000380SectionList::ReplaceSection (user_id_t sect_id, const lldb::SectionSP& sect_sp, uint32_t depth)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381{
382 iterator sect_iter, end = m_sections.end();
383 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
384 {
385 if ((*sect_iter)->GetID() == sect_id)
386 {
387 *sect_iter = sect_sp;
388 return true;
389 }
390 else if (depth > 0)
391 {
392 if ((*sect_iter)->GetChildren().ReplaceSection(sect_id, sect_sp, depth - 1))
393 return true;
394 }
395 }
396 return false;
397}
398
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400SectionList::GetNumSections (uint32_t depth) const
401{
402 size_t count = m_sections.size();
403 if (depth > 0)
404 {
405 const_iterator sect_iter, end = m_sections.end();
406 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
407 {
408 count += (*sect_iter)->GetChildren().GetNumSections(depth - 1);
409 }
410 }
411 return count;
412}
413
414SectionSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000415SectionList::GetSectionAtIndex (size_t idx) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416{
417 SectionSP sect_sp;
418 if (idx < m_sections.size())
419 sect_sp = m_sections[idx];
420 return sect_sp;
421}
422
423SectionSP
424SectionList::FindSectionByName (const ConstString &section_dstr) const
425{
426 SectionSP sect_sp;
427 // Check if we have a valid section string
Greg Claytone72dfb32012-02-24 01:59:29 +0000428 if (section_dstr && !m_sections.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 {
430 const_iterator sect_iter;
431 const_iterator end = m_sections.end();
432 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
433 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000434 Section *child_section = sect_iter->get();
435 assert (child_section);
436 if (child_section->GetName() == section_dstr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 {
438 sect_sp = *sect_iter;
439 }
440 else
441 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000442 sect_sp = child_section->GetChildren().FindSectionByName(section_dstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 }
444 }
445 }
446 return sect_sp;
447}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448
449SectionSP
450SectionList::FindSectionByID (user_id_t sect_id) const
451{
452 SectionSP sect_sp;
453 if (sect_id)
454 {
455 const_iterator sect_iter;
456 const_iterator end = m_sections.end();
457 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
458 {
459 if ((*sect_iter)->GetID() == sect_id)
460 {
461 sect_sp = *sect_iter;
462 break;
463 }
464 else
465 {
466 sect_sp = (*sect_iter)->GetChildren().FindSectionByID (sect_id);
467 }
468 }
469 }
470 return sect_sp;
471}
472
Greg Clayton70e33eb2010-07-21 21:49:46 +0000473
474SectionSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000475SectionList::FindSectionByType (SectionType sect_type, bool check_children, size_t start_idx) const
Greg Clayton70e33eb2010-07-21 21:49:46 +0000476{
477 SectionSP sect_sp;
Greg Claytonc7bece562013-01-25 18:06:21 +0000478 size_t num_sections = m_sections.size();
479 for (size_t idx = start_idx; idx < num_sections; ++idx)
Greg Clayton70e33eb2010-07-21 21:49:46 +0000480 {
481 if (m_sections[idx]->GetType() == sect_type)
482 {
483 sect_sp = m_sections[idx];
484 break;
485 }
Greg Clayton4ceb9982010-07-21 22:54:26 +0000486 else if (check_children)
487 {
488 sect_sp = m_sections[idx]->GetChildren().FindSectionByType (sect_type, check_children, 0);
489 if (sect_sp)
490 break;
491 }
Greg Clayton70e33eb2010-07-21 21:49:46 +0000492 }
493 return sect_sp;
494}
495
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496SectionSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497SectionList::FindSectionContainingFileAddress (addr_t vm_addr, uint32_t depth) const
498{
499 SectionSP sect_sp;
500 const_iterator sect_iter;
501 const_iterator end = m_sections.end();
502 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
503 {
504 Section *sect = sect_iter->get();
505 if (sect->ContainsFileAddress (vm_addr))
506 {
507 // The file address is in this section. We need to make sure one of our child
508 // sections doesn't contain this address as well as obeying the depth limit
509 // that was passed in.
510 if (depth > 0)
511 sect_sp = sect->GetChildren().FindSectionContainingFileAddress(vm_addr, depth - 1);
512
513 if (sect_sp.get() == NULL && !sect->IsFake())
514 sect_sp = *sect_iter;
515 }
516 }
517 return sect_sp;
518}
519
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520bool
521SectionList::ContainsSection(user_id_t sect_id) const
522{
523 return FindSectionByID (sect_id).get() != NULL;
524}
525
526void
Greg Clayton10177aa2010-12-08 05:08:21 +0000527SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000528{
Greg Claytonf6693582010-12-07 18:05:22 +0000529 bool target_has_loaded_sections = target && !target->GetSectionLoadList().IsEmpty();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 if (show_header && !m_sections.empty())
531 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532 s->Indent();
Greg Clayton44435ed2012-01-12 05:25:17 +0000533 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 +0000534 s->Indent();
Greg Clayton44435ed2012-01-12 05:25:17 +0000535 s->PutCString("---------- ---------------- --------------------------------------- ---------- ---------- ---------- ----------------------------\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536 }
537
538
539 const_iterator sect_iter;
540 const_iterator end = m_sections.end();
541 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
542 {
Greg Clayton10177aa2010-12-08 05:08:21 +0000543 (*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544 }
545
546 if (show_header && !m_sections.empty())
547 s->IndentLess();
548
549}
550
551size_t
552SectionList::Slide (addr_t slide_amount, bool slide_children)
553{
554 size_t count = 0;
555 const_iterator pos, end = m_sections.end();
556 for (pos = m_sections.begin(); pos != end; ++pos)
557 {
558 if ((*pos)->Slide(slide_amount, slide_children))
559 ++count;
560 }
561 return count;
562}