blob: 09394b266f37b057165d73eb88b1c1a716ff3f75 [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
18Section::Section
19(
20 Section *parent,
21 Module* module,
22 user_id_t sect_id,
23 const ConstString &name,
24 SectionType sect_type,
25 addr_t file_addr,
26 addr_t byte_size,
27 uint64_t file_offset,
28 uint64_t file_size,
29 uint32_t flags
30) :
31 ModuleChild (module),
32 UserID (sect_id),
33 Flags (flags),
34 m_parent (parent),
35 m_name (name),
36 m_type (sect_type),
37 m_file_addr (file_addr),
38 m_byte_size (byte_size),
39 m_file_offset (file_offset),
40 m_file_size (file_size),
41 m_children (),
42 m_fake (false),
43 m_linked_section(NULL),
44 m_linked_offset (0)
45{
46}
47
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048Section::~Section()
49{
50}
51
52
53// Get a valid shared pointer to this section object
54SectionSP
55Section::GetSharedPointer() const
56{
57 SectionSP this_sp;
58 if (m_parent)
59 this_sp = m_parent->GetChildren().GetSharedPointer (this, false);
60 else
61 {
62 ObjectFile *objfile = m_module->GetObjectFile();
63 if (objfile)
64 {
65 SectionList *section_list = objfile->GetSectionList();
66 if (section_list)
67 this_sp = section_list->GetSharedPointer (this, false);
68 }
69 }
70 return this_sp;
71}
72
73
74
75ConstString&
76Section::GetName()
77{
78 if (m_linked_section)
79 return const_cast<Section *>(m_linked_section)->GetName();
80 return m_name;
81}
82
83const ConstString&
84Section::GetName() const
85{
86 if (m_linked_section)
87 return m_linked_section->GetName();
88 return m_name;
89}
90
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091addr_t
92Section::GetFileAddress () const
93{
94 if (m_parent)
95 {
96 // This section has a parent which means m_file_addr is an offset into
97 // the parent section, so the file address for this section is the file
98 // address of the parent plus the offset
99 return m_parent->GetFileAddress() + m_file_addr;
100 }
101 // This section has no parent, so m_file_addr is the file base address
102 return m_file_addr;
103}
104
105addr_t
106Section::GetLinkedFileAddress () const
107{
108 if (m_linked_section)
109 return m_linked_section->GetFileAddress() + m_linked_offset;
110 return LLDB_INVALID_ADDRESS;
111}
112
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113
114addr_t
Greg Claytonf5e56de2010-09-14 23:36:40 +0000115Section::GetLoadBaseAddress (Target *target) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116{
117 addr_t load_base_addr = LLDB_INVALID_ADDRESS;
118 if (m_linked_section)
119 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000120 load_base_addr = m_linked_section->GetLoadBaseAddress(target);
121 if (load_base_addr != LLDB_INVALID_ADDRESS)
122 load_base_addr += m_linked_offset;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000123 }
124 else
125 if (m_parent)
126 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000127 load_base_addr = m_parent->GetLoadBaseAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128 if (load_base_addr != LLDB_INVALID_ADDRESS)
129 load_base_addr += GetOffset();
130 }
131 else
132 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000133 load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134 }
135
136 return load_base_addr;
137}
138
139bool
140Section::ResolveContainedAddress (addr_t offset, Address &so_addr) const
141{
142 const uint32_t num_children = m_children.GetSize();
143 if (num_children > 0)
144 {
145 for (uint32_t i=0; i<num_children; i++)
146 {
147 Section* child_section = m_children.GetSectionAtIndex (i).get();
148
149 addr_t child_offset = child_section->GetOffset();
150 if (child_offset <= offset && offset - child_offset < child_section->GetByteSize())
151 return child_section->ResolveContainedAddress (offset - child_offset, so_addr);
152 }
153 }
154 if (m_linked_section)
155 {
156 so_addr.SetOffset(m_linked_offset + offset);
157 so_addr.SetSection(m_linked_section);
158 }
159 else
160 {
161 so_addr.SetOffset(offset);
162 so_addr.SetSection(this);
163 }
164 return true;
165}
166
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167bool
168Section::ContainsFileAddress (addr_t vm_addr) const
169{
170 const addr_t file_addr = GetFileAddress();
171 if (file_addr != LLDB_INVALID_ADDRESS)
172 {
173 if (file_addr <= vm_addr)
174 {
175 const addr_t offset = vm_addr - file_addr;
176 return offset < GetByteSize();
177 }
178 }
179 return false;
180}
181
182bool
183Section::ContainsLinkedFileAddress (addr_t vm_addr) const
184{
185 const addr_t linked_file_addr = GetLinkedFileAddress();
186 if (linked_file_addr != LLDB_INVALID_ADDRESS)
187 {
188 if (linked_file_addr <= vm_addr)
189 {
190 const addr_t offset = vm_addr - linked_file_addr;
191 return offset < GetByteSize();
192 }
193 }
194 return false;
195}
196
197int
198Section::Compare (const Section& a, const Section& b)
199{
200 if (&a == &b)
201 return 0;
202
203 const Module* a_module = a.GetModule();
204 const Module* b_module = b.GetModule();
205 if (a_module == b_module)
206 {
207 user_id_t a_sect_uid = a.GetID();
208 user_id_t b_sect_uid = b.GetID();
209 if (a_sect_uid < b_sect_uid)
210 return -1;
211 if (a_sect_uid > b_sect_uid)
212 return 1;
213 return 0;
214 }
215 else
216 {
217 // The modules are different, just compare the module pointers
218 if (a_module < b_module)
219 return -1;
220 else
221 return 1; // We already know the modules aren't equal
222 }
223}
224
225
226void
Greg Clayton10177aa2010-12-08 05:08:21 +0000227Section::Dump (Stream *s, Target *target, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228{
Greg Clayton89411422010-10-08 00:21:05 +0000229// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230 s->Indent();
Greg Clayton81c22f62011-10-19 18:09:39 +0000231 s->Printf("0x%8.8llx %-14s ", GetID(), GetSectionTypeAsCString (m_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232 bool resolved = true;
233 addr_t addr = LLDB_INVALID_ADDRESS;
234
235 if (GetByteSize() == 0)
236 s->Printf("%39s", "");
237 else
238 {
Greg Claytonf6693582010-12-07 18:05:22 +0000239 if (target && m_linked_section == NULL)
Greg Claytonf5e56de2010-09-14 23:36:40 +0000240 addr = GetLoadBaseAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241
242 if (addr == LLDB_INVALID_ADDRESS)
243 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000244 if (target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245 resolved = false;
246 addr = GetFileAddress();
247 }
248
249 VMRange range(addr, addr + m_byte_size);
250 range.Dump (s, 0);
251 }
252
Greg Clayton73b472d2010-10-27 03:32:59 +0000253 s->Printf("%c 0x%8.8llx 0x%8.8llx 0x%8.8x ", resolved ? ' ' : '*', m_file_offset, m_file_size, Get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254
255 DumpName (s);
256
257 s->EOL();
258
259 if (m_linked_section)
260 {
261 addr = LLDB_INVALID_ADDRESS;
Greg Claytonf6693582010-12-07 18:05:22 +0000262 resolved = true;
Greg Claytonf5e56de2010-09-14 23:36:40 +0000263 if (target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000265 addr = m_linked_section->GetLoadBaseAddress(target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266 if (addr != LLDB_INVALID_ADDRESS)
267 addr += m_linked_offset;
268 }
269
270 if (addr == LLDB_INVALID_ADDRESS)
271 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000272 if (target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000273 resolved = false;
274 addr = m_linked_section->GetFileAddress() + m_linked_offset;
275 }
276
Greg Clayton65e364e2010-12-07 07:37:38 +0000277 int indent = 26 + s->GetIndentLevel();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278 s->Printf("%*.*s", indent, indent, "");
279 VMRange linked_range(addr, addr + m_byte_size);
280 linked_range.Dump (s, 0);
281 indent = 3 * (sizeof(uint32_t) * 2 + 2 + 1) + 1;
282 s->Printf("%c%*.*s", resolved ? ' ' : '*', indent, indent, "");
283
284 m_linked_section->DumpName(s);
285 s->Printf(" + 0x%llx\n", m_linked_offset);
286 }
287
Greg Clayton10177aa2010-12-08 05:08:21 +0000288 if (depth > 0)
289 m_children.Dump(s, target, false, depth - 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290}
291
292void
293Section::DumpName (Stream *s) const
294{
Greg Clayton65e364e2010-12-07 07:37:38 +0000295 if (m_parent == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000296 {
297 // The top most section prints the module basename
298 const char *module_basename = m_module->GetFileSpec().GetFilename().AsCString();
299 if (module_basename && module_basename[0])
300 s->Printf("%s.", module_basename);
301 }
302 else
303 {
304 m_parent->DumpName (s);
305 s->PutChar('.');
306 }
307 m_name.Dump(s);
308}
309
310//----------------------------------------------------------------------
311// Get the section data from a complete contiguous copy of the
312// entire executable image.
313//----------------------------------------------------------------------
314size_t
315Section::GetSectionDataFromImage (const DataExtractor& image_data, DataExtractor& section_data) const
316{
317 size_t file_size = GetByteSize();
318 if (file_size > 0)
319 {
320 off_t file_offset = GetFileOffset();
321 if (section_data.SetData (image_data, file_offset, file_size) == file_size)
322 return true;
323 }
324 return false;
325}
326
Greg Claytondda4f7b2010-06-30 23:03:03 +0000327size_t
328Section::ReadSectionDataFromObjectFile (const ObjectFile* objfile, off_t section_offset, void *dst, size_t dst_len) const
329{
330 if (objfile && dst && dst_len)
331 {
332 const FileSpec& file = objfile->GetFileSpec();
333
334 if (file)
335 {
Greg Clayton644247c2011-07-07 01:59:51 +0000336 size_t bytes_left = dst_len;
337 size_t bytes_read = 0;
338 const uint64_t file_size = GetFileSize();
339 if (section_offset < file_size)
340 {
341 off_t section_file_offset = objfile->GetOffset() + GetFileOffset() + section_offset;
Greg Clayton4017fa32012-01-06 02:01:06 +0000342 bytes_read = file.ReadFileContents (section_file_offset, dst, dst_len, NULL);
Greg Clayton644247c2011-07-07 01:59:51 +0000343 if (bytes_read >= dst_len)
344 return bytes_read;
345 bytes_left -= bytes_read;
346 }
347
348 const uint64_t byte_size = GetByteSize();
349 if (section_offset + bytes_read < byte_size)
350 {
351 memset ((uint8_t*)dst + bytes_read, 0, bytes_left);
352 bytes_read += bytes_left;
353 }
354 return bytes_read;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000355 }
356 }
357 return 0;
358}
359
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360//----------------------------------------------------------------------
361// Get the section data the file on disk
362//----------------------------------------------------------------------
363size_t
364Section::ReadSectionDataFromObjectFile(const ObjectFile* objfile, DataExtractor& section_data) const
365{
366 if (objfile == NULL)
367 return 0;
368
369 const FileSpec& file = objfile->GetFileSpec();
370
371 if (file)
372 {
373 size_t section_file_size = GetByteSize();
374 if (section_file_size > 0)
375 {
376 off_t section_file_offset = GetFileOffset() + objfile->GetOffset();
Greg Claytondda4f7b2010-06-30 23:03:03 +0000377 DataBufferSP section_data_sp(file.ReadFileContents(section_file_offset, section_file_size));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378
379 section_data.SetByteOrder(objfile->GetByteOrder());
380 section_data.SetAddressByteSize(objfile->GetAddressByteSize());
Greg Claytondda4f7b2010-06-30 23:03:03 +0000381 return section_data.SetData (section_data_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382 }
383 }
384 return 0;
385}
386
387size_t
388Section::MemoryMapSectionDataFromObjectFile(const ObjectFile* objfile, DataExtractor& section_data) const
389{
390 if (objfile == NULL)
391 return 0;
392
393 const FileSpec& file = objfile->GetFileSpec();
394
395 if (file)
396 {
397 size_t section_file_size = GetFileSize();
398 if (section_file_size > 0)
399 {
400 off_t section_file_offset = GetFileOffset() + objfile->GetOffset();
Greg Claytondda4f7b2010-06-30 23:03:03 +0000401 DataBufferSP section_data_sp(file.MemoryMapFileContents(section_file_offset, section_file_size));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402 section_data.SetByteOrder(objfile->GetByteOrder());
403 section_data.SetAddressByteSize(objfile->GetAddressByteSize());
Greg Claytondda4f7b2010-06-30 23:03:03 +0000404 return section_data.SetData (section_data_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405 }
406 }
407 return 0;
408}
409
410bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411Section::IsDescendant (const Section *section)
412{
413 if (this == section)
414 return true;
415 if (m_parent)
416 return m_parent->IsDescendant (section);
417 return false;
418}
419
420bool
421Section::Slide (addr_t slide_amount, bool slide_children)
422{
423 if (m_file_addr != LLDB_INVALID_ADDRESS)
424 {
425 if (slide_amount == 0)
426 return true;
427
428 m_file_addr += slide_amount;
429
430 if (slide_children)
431 m_children.Slide (slide_amount, slide_children);
432
433 return true;
434 }
435 return false;
436}
437
438void
439Section::SetLinkedLocation (const Section *linked_section, uint64_t linked_offset)
440{
441 if (linked_section)
442 m_module = linked_section->GetModule();
443 m_linked_section = linked_section;
444 m_linked_offset = linked_offset;
445}
446
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447#pragma mark SectionList
448
449SectionList::SectionList () :
450 m_sections()
451{
452}
453
454
455SectionList::~SectionList ()
456{
457}
458
459uint32_t
460SectionList::AddSection (SectionSP& sect_sp)
461{
462 uint32_t section_index = m_sections.size();
463 m_sections.push_back(sect_sp);
464 return section_index;
465}
466
467uint32_t
468SectionList::FindSectionIndex (const Section* sect)
469{
470 iterator sect_iter;
471 iterator begin = m_sections.begin();
472 iterator end = m_sections.end();
473 for (sect_iter = begin; sect_iter != end; ++sect_iter)
474 {
475 if (sect_iter->get() == sect)
476 {
477 // The secton was already in this section list
478 return std::distance (begin, sect_iter);
479 }
480 }
481 return UINT32_MAX;
482}
483
484uint32_t
485SectionList::AddUniqueSection (SectionSP& sect_sp)
486{
487 uint32_t sect_idx = FindSectionIndex (sect_sp.get());
488 if (sect_idx == UINT32_MAX)
489 sect_idx = AddSection (sect_sp);
490 return sect_idx;
491}
492
493
494bool
495SectionList::ReplaceSection (user_id_t sect_id, SectionSP& sect_sp, uint32_t depth)
496{
497 iterator sect_iter, end = m_sections.end();
498 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
499 {
500 if ((*sect_iter)->GetID() == sect_id)
501 {
502 *sect_iter = sect_sp;
503 return true;
504 }
505 else if (depth > 0)
506 {
507 if ((*sect_iter)->GetChildren().ReplaceSection(sect_id, sect_sp, depth - 1))
508 return true;
509 }
510 }
511 return false;
512}
513
514
515size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516SectionList::GetNumSections (uint32_t depth) const
517{
518 size_t count = m_sections.size();
519 if (depth > 0)
520 {
521 const_iterator sect_iter, end = m_sections.end();
522 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
523 {
524 count += (*sect_iter)->GetChildren().GetNumSections(depth - 1);
525 }
526 }
527 return count;
528}
529
530SectionSP
531SectionList::GetSectionAtIndex (uint32_t idx) const
532{
533 SectionSP sect_sp;
534 if (idx < m_sections.size())
535 sect_sp = m_sections[idx];
536 return sect_sp;
537}
538
539SectionSP
540SectionList::FindSectionByName (const ConstString &section_dstr) const
541{
542 SectionSP sect_sp;
543 // Check if we have a valid section string
544 if (section_dstr)
545 {
546 const_iterator sect_iter;
547 const_iterator end = m_sections.end();
548 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
549 {
550 if ((*sect_iter)->GetName() == section_dstr)
551 {
552 sect_sp = *sect_iter;
553 }
554 else
555 {
556 sect_sp = (*sect_iter)->GetChildren().FindSectionByName(section_dstr);
557 }
558 }
559 }
560 return sect_sp;
561}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562
563SectionSP
564SectionList::FindSectionByID (user_id_t sect_id) const
565{
566 SectionSP sect_sp;
567 if (sect_id)
568 {
569 const_iterator sect_iter;
570 const_iterator end = m_sections.end();
571 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
572 {
573 if ((*sect_iter)->GetID() == sect_id)
574 {
575 sect_sp = *sect_iter;
576 break;
577 }
578 else
579 {
580 sect_sp = (*sect_iter)->GetChildren().FindSectionByID (sect_id);
581 }
582 }
583 }
584 return sect_sp;
585}
586
Greg Clayton70e33eb2010-07-21 21:49:46 +0000587
588SectionSP
Greg Claytone0d378b2011-03-24 21:19:54 +0000589SectionList::FindSectionByType (SectionType sect_type, bool check_children, uint32_t start_idx) const
Greg Clayton70e33eb2010-07-21 21:49:46 +0000590{
591 SectionSP sect_sp;
592 uint32_t num_sections = m_sections.size();
593 for (uint32_t idx = start_idx; idx < num_sections; ++idx)
594 {
595 if (m_sections[idx]->GetType() == sect_type)
596 {
597 sect_sp = m_sections[idx];
598 break;
599 }
Greg Clayton4ceb9982010-07-21 22:54:26 +0000600 else if (check_children)
601 {
602 sect_sp = m_sections[idx]->GetChildren().FindSectionByType (sect_type, check_children, 0);
603 if (sect_sp)
604 break;
605 }
Greg Clayton70e33eb2010-07-21 21:49:46 +0000606 }
607 return sect_sp;
608}
609
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610SectionSP
611SectionList::GetSharedPointer (const Section *section, bool check_children) const
612{
613 SectionSP sect_sp;
614 if (section)
615 {
616 const_iterator sect_iter;
617 const_iterator end = m_sections.end();
618 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
619 {
620 if (sect_iter->get() == section)
621 {
622 sect_sp = *sect_iter;
623 break;
624 }
625 else if (check_children)
626 {
627 sect_sp = (*sect_iter)->GetChildren().GetSharedPointer (section, true);
628 }
629 }
630 }
631 return sect_sp;
632}
633
634
635
636SectionSP
637SectionList::FindSectionContainingFileAddress (addr_t vm_addr, uint32_t depth) const
638{
639 SectionSP sect_sp;
640 const_iterator sect_iter;
641 const_iterator end = m_sections.end();
642 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
643 {
644 Section *sect = sect_iter->get();
645 if (sect->ContainsFileAddress (vm_addr))
646 {
647 // The file address is in this section. We need to make sure one of our child
648 // sections doesn't contain this address as well as obeying the depth limit
649 // that was passed in.
650 if (depth > 0)
651 sect_sp = sect->GetChildren().FindSectionContainingFileAddress(vm_addr, depth - 1);
652
653 if (sect_sp.get() == NULL && !sect->IsFake())
654 sect_sp = *sect_iter;
655 }
656 }
657 return sect_sp;
658}
659
660
661SectionSP
Greg Clayton016a95e2010-09-14 02:20:48 +0000662SectionList::FindSectionContainingLinkedFileAddress (addr_t vm_addr, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663{
664 SectionSP sect_sp;
665 const_iterator sect_iter;
666 const_iterator end = m_sections.end();
667 for (sect_iter = m_sections.begin(); sect_iter != end && sect_sp.get() == NULL; ++sect_iter)
668 {
669 Section *sect = sect_iter->get();
670 if (sect->ContainsLinkedFileAddress (vm_addr))
671 {
672 sect_sp = *sect_iter;
Greg Clayton016a95e2010-09-14 02:20:48 +0000673 }
674 else if (depth > 0)
675 {
676 sect_sp = sect->GetChildren().FindSectionContainingLinkedFileAddress (vm_addr, depth - 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 }
678 }
679 return sect_sp;
680}
681
682bool
683SectionList::ContainsSection(user_id_t sect_id) const
684{
685 return FindSectionByID (sect_id).get() != NULL;
686}
687
688void
Greg Clayton10177aa2010-12-08 05:08:21 +0000689SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000690{
Greg Claytonf6693582010-12-07 18:05:22 +0000691 bool target_has_loaded_sections = target && !target->GetSectionLoadList().IsEmpty();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692 if (show_header && !m_sections.empty())
693 {
Greg Clayton89411422010-10-08 00:21:05 +0000694// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
695// s->Indent();
696// s->PutCString( "SectionList\n");
697// s->IndentMore();
698// s->Printf("%*s", 2*(sizeof(void *) + 2), "");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000699 s->Indent();
Greg Claytonf6693582010-12-07 18:05:22 +0000700 s->Printf("SectID Type %s Address File Off. File Size Flags Section Name\n", target_has_loaded_sections ? "Load" : "File");
Greg Clayton89411422010-10-08 00:21:05 +0000701// s->Printf("%*s", 2*(sizeof(void *) + 2), "");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000702 s->Indent();
Greg Clayton89411422010-10-08 00:21:05 +0000703 s->PutCString("---------- -------------- --------------------------------------- ---------- ---------- ---------- ----------------------------\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704 }
705
706
707 const_iterator sect_iter;
708 const_iterator end = m_sections.end();
709 for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
710 {
Greg Clayton10177aa2010-12-08 05:08:21 +0000711 (*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712 }
713
714 if (show_header && !m_sections.empty())
715 s->IndentLess();
716
717}
718
719size_t
720SectionList::Slide (addr_t slide_amount, bool slide_children)
721{
722 size_t count = 0;
723 const_iterator pos, end = m_sections.end();
724 for (pos = m_sections.begin(); pos != end; ++pos)
725 {
726 if ((*pos)->Slide(slide_amount, slide_children))
727 ++count;
728 }
729 return count;
730}
731