blob: 492abec357b2050ef8f8ce5032a6358f47352bdb [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
Greg Claytone72dfb32012-02-24 01:59:29 +0000101lldb::addr_t
102Section::GetOffset () const
103{
104 // This section has a parent which means m_file_addr is an offset.
105 SectionSP parent_sp (GetParent ());
106 if (parent_sp)
107 return m_file_addr;
108
109 // This section has no parent, so there is no offset to be had
110 return 0;
111}
112
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113addr_t
Greg Claytonf5e56de2010-09-14 23:36:40 +0000114Section::GetLoadBaseAddress (Target *target) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115{
116 addr_t load_base_addr = LLDB_INVALID_ADDRESS;
Greg Clayton9422dd62013-03-04 21:46:16 +0000117 SectionSP parent_sp (GetParent ());
118 if (parent_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000120 load_base_addr = parent_sp->GetLoadBaseAddress (target);
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000121 if (load_base_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +0000122 load_base_addr += GetOffset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000123 }
124 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000126 load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (const_cast<Section *>(this)->shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000127 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128 return load_base_addr;
129}
130
131bool
132Section::ResolveContainedAddress (addr_t offset, Address &so_addr) const
133{
Greg Claytonc7bece562013-01-25 18:06:21 +0000134 const size_t num_children = m_children.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000135 if (num_children > 0)
136 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000137 for (size_t i=0; i<num_children; i++)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138 {
139 Section* child_section = m_children.GetSectionAtIndex (i).get();
140
141 addr_t child_offset = child_section->GetOffset();
142 if (child_offset <= offset && offset - child_offset < child_section->GetByteSize())
143 return child_section->ResolveContainedAddress (offset - child_offset, so_addr);
144 }
145 }
Greg Clayton9422dd62013-03-04 21:46:16 +0000146 so_addr.SetOffset(offset);
147 so_addr.SetSection(const_cast<Section *>(this)->shared_from_this());
148
Sean Callanan27e02d02012-07-12 20:44:21 +0000149#ifdef LLDB_CONFIGURATION_DEBUG
Greg Clayton9422dd62013-03-04 21:46:16 +0000150 // For debug builds, ensure that there are no orphaned (i.e., moduleless) sections.
151 assert(GetModule().get());
Sean Callanan27e02d02012-07-12 20:44:21 +0000152#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153 return true;
154}
155
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156bool
157Section::ContainsFileAddress (addr_t vm_addr) const
158{
159 const addr_t file_addr = GetFileAddress();
160 if (file_addr != LLDB_INVALID_ADDRESS)
161 {
162 if (file_addr <= vm_addr)
163 {
164 const addr_t offset = vm_addr - file_addr;
165 return offset < GetByteSize();
166 }
167 }
168 return false;
169}
170
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000171int
172Section::Compare (const Section& a, const Section& b)
173{
174 if (&a == &b)
175 return 0;
176
Greg Claytone72dfb32012-02-24 01:59:29 +0000177 const ModuleSP a_module_sp = a.GetModule();
178 const ModuleSP b_module_sp = b.GetModule();
179 if (a_module_sp == b_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000180 {
181 user_id_t a_sect_uid = a.GetID();
182 user_id_t b_sect_uid = b.GetID();
183 if (a_sect_uid < b_sect_uid)
184 return -1;
185 if (a_sect_uid > b_sect_uid)
186 return 1;
187 return 0;
188 }
189 else
190 {
191 // The modules are different, just compare the module pointers
Greg Claytone72dfb32012-02-24 01:59:29 +0000192 if (a_module_sp.get() < b_module_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193 return -1;
194 else
195 return 1; // We already know the modules aren't equal
196 }
197}
198
199
200void
Greg Clayton10177aa2010-12-08 05:08:21 +0000201Section::Dump (Stream *s, Target *target, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202{
Greg Clayton89411422010-10-08 00:21:05 +0000203// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204 s->Indent();
Daniel Malead01b2952012-11-29 21:49:15 +0000205 s->Printf("0x%8.8" PRIx64 " %-16s ", GetID(), GetSectionTypeAsCString (m_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 bool resolved = true;
207 addr_t addr = LLDB_INVALID_ADDRESS;
208
209 if (GetByteSize() == 0)
210 s->Printf("%39s", "");
211 else
212 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000213 if (target)
Greg Claytonf5e56de2010-09-14 23:36:40 +0000214 addr = GetLoadBaseAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215
216 if (addr == LLDB_INVALID_ADDRESS)
217 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000218 if (target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000219 resolved = false;
220 addr = GetFileAddress();
221 }
222
223 VMRange range(addr, addr + m_byte_size);
224 range.Dump (s, 0);
225 }
226
Daniel Malead01b2952012-11-29 21:49:15 +0000227 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 +0000228
229 DumpName (s);
230
231 s->EOL();
232
Greg Clayton10177aa2010-12-08 05:08:21 +0000233 if (depth > 0)
234 m_children.Dump(s, target, false, depth - 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235}
236
237void
238Section::DumpName (Stream *s) const
239{
Greg Claytone72dfb32012-02-24 01:59:29 +0000240 SectionSP parent_sp (GetParent ());
241 if (parent_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000243 parent_sp->DumpName (s);
244 s->PutChar('.');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245 }
246 else
247 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000248 // The top most section prints the module basename
Michael Sartaina7499c92013-07-01 19:45:50 +0000249 const char * name = NULL;
Greg Claytone72dfb32012-02-24 01:59:29 +0000250 ModuleSP module_sp (GetModule());
Michael Sartaina7499c92013-07-01 19:45:50 +0000251 const FileSpec &file_spec = m_obj_file->GetFileSpec();
252
253 if (m_obj_file)
254 name = file_spec.GetFilename().AsCString();
255 if ((!name || !name[0]) && module_sp)
256 name = module_sp->GetFileSpec().GetFilename().AsCString();
257 if (name && name[0])
258 s->Printf("%s.", name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259 }
260 m_name.Dump(s);
261}
262
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264Section::IsDescendant (const Section *section)
265{
266 if (this == section)
267 return true;
Greg Claytone72dfb32012-02-24 01:59:29 +0000268 SectionSP parent_sp (GetParent ());
269 if (parent_sp)
270 return parent_sp->IsDescendant (section);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271 return false;
272}
273
274bool
275Section::Slide (addr_t slide_amount, bool slide_children)
276{
277 if (m_file_addr != LLDB_INVALID_ADDRESS)
278 {
279 if (slide_amount == 0)
280 return true;
281
282 m_file_addr += slide_amount;
283
284 if (slide_children)
285 m_children.Slide (slide_amount, slide_children);
286
287 return true;
288 }
289 return false;
290}
291
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292#pragma mark SectionList
293
294SectionList::SectionList () :
295 m_sections()
296{
297}
298
299
300SectionList::~SectionList ()
301{
302}
303
Greg Clayton3046e662013-07-10 01:23:25 +0000304SectionList &
305SectionList::operator = (const SectionList& rhs)
Michael Sartaina7499c92013-07-01 19:45:50 +0000306{
Greg Clayton3046e662013-07-10 01:23:25 +0000307 if (this != &rhs)
308 m_sections = rhs.m_sections;
309 return *this;
Michael Sartaina7499c92013-07-01 19:45:50 +0000310}
311
Greg Claytonc7bece562013-01-25 18:06:21 +0000312size_t
Greg Claytone72dfb32012-02-24 01:59:29 +0000313SectionList::AddSection (const lldb::SectionSP& section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314{
Greg Claytone72dfb32012-02-24 01:59:29 +0000315 assert (section_sp.get());
Greg Claytonc7bece562013-01-25 18:06:21 +0000316 size_t section_index = m_sections.size();
Greg Claytone72dfb32012-02-24 01:59:29 +0000317 m_sections.push_back(section_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000318 return section_index;
319}
320
Michael Sartaina7499c92013-07-01 19:45:50 +0000321// Warning, this can be slow as it's removing items from a std::vector.
322bool
323SectionList::DeleteSection (size_t idx)
324{
325 if (idx < m_sections.size())
326 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000327 m_sections.erase (m_sections.begin() + idx);
328 return true;
329 }
330 return false;
331}
332
Greg Claytonc7bece562013-01-25 18:06:21 +0000333size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000334SectionList::FindSectionIndex (const Section* sect)
335{
336 iterator sect_iter;
337 iterator begin = m_sections.begin();
338 iterator end = m_sections.end();
339 for (sect_iter = begin; sect_iter != end; ++sect_iter)
340 {
341 if (sect_iter->get() == sect)
342 {
343 // The secton was already in this section list
344 return std::distance (begin, sect_iter);
345 }
346 }
347 return UINT32_MAX;
348}
349
Greg Claytonc7bece562013-01-25 18:06:21 +0000350size_t
Greg Claytone72dfb32012-02-24 01:59:29 +0000351SectionList::AddUniqueSection (const lldb::SectionSP& sect_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000352{
Greg Claytonc7bece562013-01-25 18:06:21 +0000353 size_t sect_idx = FindSectionIndex (sect_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354 if (sect_idx == UINT32_MAX)
Michael Sartaina7499c92013-07-01 19:45:50 +0000355 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356 sect_idx = AddSection (sect_sp);
Michael Sartaina7499c92013-07-01 19:45:50 +0000357 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358 return sect_idx;
359}
360
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361bool
Greg Claytone72dfb32012-02-24 01:59:29 +0000362SectionList::ReplaceSection (user_id_t sect_id, const lldb::SectionSP& sect_sp, uint32_t depth)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000363{
364 iterator sect_iter, end = m_sections.end();
365 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
366 {
367 if ((*sect_iter)->GetID() == sect_id)
368 {
369 *sect_iter = sect_sp;
370 return true;
371 }
372 else if (depth > 0)
373 {
374 if ((*sect_iter)->GetChildren().ReplaceSection(sect_id, sect_sp, depth - 1))
375 return true;
376 }
377 }
378 return false;
379}
380
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382SectionList::GetNumSections (uint32_t depth) const
383{
384 size_t count = m_sections.size();
385 if (depth > 0)
386 {
387 const_iterator sect_iter, end = m_sections.end();
388 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
389 {
390 count += (*sect_iter)->GetChildren().GetNumSections(depth - 1);
391 }
392 }
393 return count;
394}
395
396SectionSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000397SectionList::GetSectionAtIndex (size_t idx) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398{
399 SectionSP sect_sp;
400 if (idx < m_sections.size())
401 sect_sp = m_sections[idx];
402 return sect_sp;
403}
404
405SectionSP
406SectionList::FindSectionByName (const ConstString &section_dstr) const
407{
408 SectionSP sect_sp;
409 // Check if we have a valid section string
Greg Claytone72dfb32012-02-24 01:59:29 +0000410 if (section_dstr && !m_sections.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 {
412 const_iterator sect_iter;
413 const_iterator end = m_sections.end();
414 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
415 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000416 Section *child_section = sect_iter->get();
417 assert (child_section);
418 if (child_section->GetName() == section_dstr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419 {
420 sect_sp = *sect_iter;
421 }
422 else
423 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000424 sect_sp = child_section->GetChildren().FindSectionByName(section_dstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 }
426 }
427 }
428 return sect_sp;
429}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430
431SectionSP
432SectionList::FindSectionByID (user_id_t sect_id) const
433{
434 SectionSP sect_sp;
435 if (sect_id)
436 {
437 const_iterator sect_iter;
438 const_iterator end = m_sections.end();
439 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
440 {
441 if ((*sect_iter)->GetID() == sect_id)
442 {
443 sect_sp = *sect_iter;
444 break;
445 }
446 else
447 {
448 sect_sp = (*sect_iter)->GetChildren().FindSectionByID (sect_id);
449 }
450 }
451 }
452 return sect_sp;
453}
454
Greg Clayton70e33eb2010-07-21 21:49:46 +0000455
456SectionSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000457SectionList::FindSectionByType (SectionType sect_type, bool check_children, size_t start_idx) const
Greg Clayton70e33eb2010-07-21 21:49:46 +0000458{
459 SectionSP sect_sp;
Greg Claytonc7bece562013-01-25 18:06:21 +0000460 size_t num_sections = m_sections.size();
461 for (size_t idx = start_idx; idx < num_sections; ++idx)
Greg Clayton70e33eb2010-07-21 21:49:46 +0000462 {
463 if (m_sections[idx]->GetType() == sect_type)
464 {
465 sect_sp = m_sections[idx];
466 break;
467 }
Greg Clayton4ceb9982010-07-21 22:54:26 +0000468 else if (check_children)
469 {
470 sect_sp = m_sections[idx]->GetChildren().FindSectionByType (sect_type, check_children, 0);
471 if (sect_sp)
472 break;
473 }
Greg Clayton70e33eb2010-07-21 21:49:46 +0000474 }
475 return sect_sp;
476}
477
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478SectionSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479SectionList::FindSectionContainingFileAddress (addr_t vm_addr, uint32_t depth) const
480{
481 SectionSP sect_sp;
482 const_iterator sect_iter;
483 const_iterator end = m_sections.end();
484 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
485 {
486 Section *sect = sect_iter->get();
487 if (sect->ContainsFileAddress (vm_addr))
488 {
489 // The file address is in this section. We need to make sure one of our child
490 // sections doesn't contain this address as well as obeying the depth limit
491 // that was passed in.
492 if (depth > 0)
493 sect_sp = sect->GetChildren().FindSectionContainingFileAddress(vm_addr, depth - 1);
494
495 if (sect_sp.get() == NULL && !sect->IsFake())
496 sect_sp = *sect_iter;
497 }
498 }
499 return sect_sp;
500}
501
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502bool
503SectionList::ContainsSection(user_id_t sect_id) const
504{
505 return FindSectionByID (sect_id).get() != NULL;
506}
507
508void
Greg Clayton10177aa2010-12-08 05:08:21 +0000509SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510{
Greg Claytonf6693582010-12-07 18:05:22 +0000511 bool target_has_loaded_sections = target && !target->GetSectionLoadList().IsEmpty();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512 if (show_header && !m_sections.empty())
513 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 s->Indent();
Greg Clayton44435ed2012-01-12 05:25:17 +0000515 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 +0000516 s->Indent();
Greg Clayton44435ed2012-01-12 05:25:17 +0000517 s->PutCString("---------- ---------------- --------------------------------------- ---------- ---------- ---------- ----------------------------\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518 }
519
520
521 const_iterator sect_iter;
522 const_iterator end = m_sections.end();
523 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
524 {
Greg Clayton10177aa2010-12-08 05:08:21 +0000525 (*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526 }
527
528 if (show_header && !m_sections.empty())
529 s->IndentLess();
530
531}
532
533size_t
534SectionList::Slide (addr_t slide_amount, bool slide_children)
535{
536 size_t count = 0;
537 const_iterator pos, end = m_sections.end();
538 for (pos = m_sections.begin(); pos != end; ++pos)
539 {
540 if ((*pos)->Slide(slide_amount, slide_children))
541 ++count;
542 }
543 return count;
544}