Also, add a basic test for dumping sections.
class DataExtractor;
class ObjectFile;
class Section;
-class Stream;
class Target;
class SectionList {
bool ContainsSection(lldb::user_id_t sect_id) const;
- void Dump(Stream *s, Target *target, bool show_header, uint32_t depth) const;
+ void Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
+ bool show_header, uint32_t depth) const;
lldb::SectionSP FindSectionByName(ConstString section_dstr) const;
const SectionList &GetChildren() const { return m_children; }
- void Dump(Stream *s, Target *target, uint32_t depth) const;
+ void Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
+ uint32_t depth) const;
- void DumpName(Stream *s) const;
+ void DumpName(llvm::raw_ostream &s) const;
lldb::addr_t GetLoadBaseAddress(Target *target) const;
const addr_t file_addr = section_sp->GetFileAddress();
strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 ") ", file_addr,
file_addr + section_sp->GetByteSize());
- section_sp->DumpName(&strm);
+ section_sp->DumpName(strm.AsRawOstream());
} else {
strm.PutCString("No value");
}
strm.Printf("Sections for '%s' (%s):\n",
module->GetSpecificationDescription().c_str(),
module->GetArchitecture().GetArchitectureName());
- strm.IndentMore();
- section_list->Dump(&strm,
+ section_list->Dump(strm.AsRawOstream(), strm.GetIndentLevel() + 2,
interpreter.GetExecutionContext().GetTargetPtr(), true,
UINT32_MAX);
- strm.IndentLess();
}
}
}
case DumpStyleSectionNameOffset:
if (section_sp) {
- section_sp->DumpName(s);
+ section_sp->DumpName(s->AsRawOstream());
s->Printf(" + %" PRIu64, m_offset);
} else {
DumpAddress(s->AsRawOstream(), m_offset, addr_size);
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/FileSpec.h"
-#include "lldb/Utility/Stream.h"
#include "lldb/Utility/VMRange.h"
#include <inttypes.h>
return false;
}
-void Section::Dump(Stream *s, Target *target, uint32_t depth) const {
- // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
- s->Indent();
- s->Printf("0x%8.8" PRIx64 " %-16s ", GetID(), GetTypeAsCString());
+void Section::Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
+ uint32_t depth) const {
+ s.indent(indent);
+ s << llvm::format("0x%8.8" PRIx64 " %-16s ", GetID(), GetTypeAsCString());
bool resolved = true;
addr_t addr = LLDB_INVALID_ADDRESS;
if (GetByteSize() == 0)
- s->Printf("%39s", "");
+ s.indent(39);
else {
if (target)
addr = GetLoadBaseAddress(target);
}
VMRange range(addr, addr + m_byte_size);
- range.Dump(s->AsRawOstream(), 0);
+ range.Dump(s, 0);
}
- s->Printf("%c %c%c%c 0x%8.8" PRIx64 " 0x%8.8" PRIx64 " 0x%8.8x ",
- resolved ? ' ' : '*', m_readable ? 'r' : '-',
- m_writable ? 'w' : '-', m_executable ? 'x' : '-', m_file_offset,
- m_file_size, Get());
+ s << llvm::format("%c %c%c%c 0x%8.8" PRIx64 " 0x%8.8" PRIx64 " 0x%8.8x ",
+ resolved ? ' ' : '*', m_readable ? 'r' : '-',
+ m_writable ? 'w' : '-', m_executable ? 'x' : '-',
+ m_file_offset, m_file_size, Get());
DumpName(s);
- s->EOL();
+ s << "\n";
if (depth > 0)
- m_children.Dump(s, target, false, depth - 1);
+ m_children.Dump(s, indent, target, false, depth - 1);
}
-void Section::DumpName(Stream *s) const {
+void Section::DumpName(llvm::raw_ostream &s) const {
SectionSP parent_sp(GetParent());
if (parent_sp) {
parent_sp->DumpName(s);
- s->PutChar('.');
+ s << '.';
} else {
// The top most section prints the module basename
const char *name = nullptr;
if ((!name || !name[0]) && module_sp)
name = module_sp->GetFileSpec().GetFilename().AsCString();
if (name && name[0])
- s->Printf("%s.", name);
+ s << name << '.';
}
- m_name.Dump(s);
+ s << m_name.GetStringRef();
}
bool Section::IsDescendant(const Section *section) {
return FindSectionByID(sect_id).get() != nullptr;
}
-void SectionList::Dump(Stream *s, Target *target, bool show_header,
- uint32_t depth) const {
+void SectionList::Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
+ bool show_header, uint32_t depth) const {
bool target_has_loaded_sections =
target && !target->GetSectionLoadList().IsEmpty();
if (show_header && !m_sections.empty()) {
- s->Indent();
- s->Printf("SectID Type %s Address "
- " Perm File Off. File Size Flags "
- " Section Name\n",
- target_has_loaded_sections ? "Load" : "File");
- s->Indent();
- s->PutCString("---------- ---------------- "
- "--------------------------------------- ---- ---------- "
- "---------- "
- "---------- ----------------------------\n");
+ s.indent(indent);
+ s << llvm::formatv(
+ "SectID Type {0} Address "
+ " Perm File Off. File Size Flags "
+ " Section Name\n",
+ target_has_loaded_sections ? "Load" : "File");
+ s.indent(indent);
+ s << "---------- ---------------- "
+ "--------------------------------------- ---- ---------- "
+ "---------- "
+ "---------- ----------------------------\n";
}
- const_iterator sect_iter;
- const_iterator end = m_sections.end();
- for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter) {
- (*sect_iter)->Dump(s, target_has_loaded_sections ? target : nullptr, depth);
- }
-
- if (show_header && !m_sections.empty())
- s->IndentLess();
+ for (const auto §ion_sp : m_sections)
+ section_sp->Dump(s, indent, target_has_loaded_sections ? target : nullptr,
+ depth);
}
size_t SectionList::Slide(addr_t slide_amount, bool slide_children) {
s->EOL();
SectionList *section_list = GetSectionList();
if (section_list)
- section_list->Dump(s, nullptr, true, UINT32_MAX);
+ section_list->Dump(s->AsRawOstream(), s->GetIndentLevel(), nullptr, true,
+ UINT32_MAX);
Symtab *symtab = GetSymtab();
if (symtab)
symtab->Dump(s, nullptr, eSortOrderNone);
SectionList *sections = GetSectionList();
if (sections)
- sections->Dump(s, nullptr, true, UINT32_MAX);
+ sections->Dump(s->AsRawOstream(), s->GetIndentLevel(), nullptr, true,
+ UINT32_MAX);
if (m_symtab_up)
m_symtab_up->Dump(s, nullptr, eSortOrderNone);
*s << "\n";
SectionList *sections = GetSectionList();
if (sections)
- sections->Dump(s, nullptr, true, UINT32_MAX);
+ sections->Dump(s->AsRawOstream(), s->GetIndentLevel(), nullptr, true,
+ UINT32_MAX);
if (m_symtab_up)
m_symtab_up->Dump(s, nullptr, eSortOrderNone);
SectionList *sections = GetSectionList();
if (sections)
- sections->Dump(s, nullptr, true, UINT32_MAX);
+ sections->Dump(s->AsRawOstream(), s->GetIndentLevel(), nullptr, true,
+ UINT32_MAX);
if (m_symtab_up)
m_symtab_up->Dump(s, nullptr, eSortOrderNone);
SectionList *sections = GetSectionList();
if (sections) {
- sections->Dump(s, nullptr, true, UINT32_MAX);
+ sections->Dump(s->AsRawOstream(), s->GetIndentLevel(), nullptr, true,
+ UINT32_MAX);
}
ostream << "\n";
DumpSectionHeaders(ostream);
++pos) {
s.Printf("addr = 0x%16.16" PRIx64 ", section = %p: ", pos->first,
static_cast<void *>(pos->second.get()));
- pos->second->Dump(&s, target, 0);
+ pos->second->Dump(s.AsRawOstream(), s.GetIndentLevel(), target, 0);
}
}
--- /dev/null
+# RUN: yaml2obj %s > %t
+# RUN: %lldb %t -o "target modules dump sections" -o exit \
+# RUN: | FileCheck --match-full-lines --strict-whitespace %s
+
+# CHECK:Sections for '{{.*}}command-target-modules-dump-sections.yaml.tmp' (x86_64):
+# CHECK-NEXT: SectID Type File Address Perm File Off. File Size Flags Section Name
+# CHECK-NEXT: ---------- ---------------- --------------------------------------- ---- ---------- ---------- ---------- ----------------------------
+# CHECK-NEXT: 0x00000001 code [0x0000000000004000-0x0000000000005000) r-x 0x00001000 0x00001000 0x00000006 command-target-modules-dump-sections.yaml.tmp..text
+# CHECK-NEXT: 0x00000002 regular [0x0000000000005000-0x0000000000005100) r-- 0x00002000 0x00000100 0x00000002 command-target-modules-dump-sections.yaml.tmp..rodata
+# CHECK-NEXT: 0x00000003 eh-frame [0x0000000000006000-0x0000000000006040) r-- 0x00002100 0x00000040 0x00000002 command-target-modules-dump-sections.yaml.tmp..eh_frame
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x0000000000004000
+ AddressAlign: 0x0000000000001000
+ Size: 0x1000
+ - Name: .rodata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ Address: 0x0000000000005000
+ AddressAlign: 0x0000000000000020
+ Size: 0x100
+ - Name: .eh_frame
+ Type: SHT_X86_64_UNWIND
+ Flags: [ SHF_ALLOC ]
+ Address: 0x0000000000006000
+ AddressAlign: 0x0000000000000008
+ Size: 0x40
+...