forked from OSchip/llvm-project
[lldb][NFC] Move Address and AddressRange functions out of Stream and let them take raw_ostream
Summary: Yet another step on the long road towards getting rid of lldb's Stream class. We probably should just make this some kind of member of Address/AddressRange, but it seems quite often we just push in random integers in there and this is just about getting rid of Stream and not improving arbitrary APIs. I had to rename another `DumpAddress` function in FormatEntity that is dumping the content of an address to make Clang happy. Reviewers: labath Reviewed By: labath Subscribers: JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D71052
This commit is contained in:
parent
18b72d337e
commit
1462f5a4c1
|
@ -222,47 +222,6 @@ public:
|
|||
Stream &operator<<(int32_t sval) = delete;
|
||||
Stream &operator<<(int64_t sval) = delete;
|
||||
|
||||
/// Output an address value to this stream.
|
||||
///
|
||||
/// Put an address \a addr out to the stream with optional \a prefix and \a
|
||||
/// suffix strings.
|
||||
///
|
||||
/// \param[in] addr
|
||||
/// An address value.
|
||||
///
|
||||
/// \param[in] addr_size
|
||||
/// Size in bytes of the address, used for formatting.
|
||||
///
|
||||
/// \param[in] prefix
|
||||
/// A prefix C string. If nullptr, no prefix will be output.
|
||||
///
|
||||
/// \param[in] suffix
|
||||
/// A suffix C string. If nullptr, no suffix will be output.
|
||||
void Address(uint64_t addr, uint32_t addr_size, const char *prefix = nullptr,
|
||||
const char *suffix = nullptr);
|
||||
|
||||
/// Output an address range to this stream.
|
||||
///
|
||||
/// Put an address range \a lo_addr - \a hi_addr out to the stream with
|
||||
/// optional \a prefix and \a suffix strings.
|
||||
///
|
||||
/// \param[in] lo_addr
|
||||
/// The start address of the address range.
|
||||
///
|
||||
/// \param[in] hi_addr
|
||||
/// The end address of the address range.
|
||||
///
|
||||
/// \param[in] addr_size
|
||||
/// Size in bytes of the address, used for formatting.
|
||||
///
|
||||
/// \param[in] prefix
|
||||
/// A prefix C string. If nullptr, no prefix will be output.
|
||||
///
|
||||
/// \param[in] suffix
|
||||
/// A suffix C string. If nullptr, no suffix will be output.
|
||||
void AddressRange(uint64_t lo_addr, uint64_t hi_addr, uint32_t addr_size,
|
||||
const char *prefix = nullptr, const char *suffix = nullptr);
|
||||
|
||||
/// Output a C string to the stream.
|
||||
///
|
||||
/// Print a C string \a cstr to the stream.
|
||||
|
@ -452,6 +411,54 @@ protected:
|
|||
RawOstreamForward m_forwarder;
|
||||
};
|
||||
|
||||
/// Output an address value to this stream.
|
||||
///
|
||||
/// Put an address \a addr out to the stream with optional \a prefix and \a
|
||||
/// suffix strings.
|
||||
///
|
||||
/// \param[in] s
|
||||
/// The output stream.
|
||||
///
|
||||
/// \param[in] addr
|
||||
/// An address value.
|
||||
///
|
||||
/// \param[in] addr_size
|
||||
/// Size in bytes of the address, used for formatting.
|
||||
///
|
||||
/// \param[in] prefix
|
||||
/// A prefix C string. If nullptr, no prefix will be output.
|
||||
///
|
||||
/// \param[in] suffix
|
||||
/// A suffix C string. If nullptr, no suffix will be output.
|
||||
void DumpAddress(llvm::raw_ostream &s, uint64_t addr, uint32_t addr_size,
|
||||
const char *prefix = nullptr, const char *suffix = nullptr);
|
||||
|
||||
/// Output an address range to this stream.
|
||||
///
|
||||
/// Put an address range \a lo_addr - \a hi_addr out to the stream with
|
||||
/// optional \a prefix and \a suffix strings.
|
||||
///
|
||||
/// \param[in] s
|
||||
/// The output stream.
|
||||
///
|
||||
/// \param[in] lo_addr
|
||||
/// The start address of the address range.
|
||||
///
|
||||
/// \param[in] hi_addr
|
||||
/// The end address of the address range.
|
||||
///
|
||||
/// \param[in] addr_size
|
||||
/// Size in bytes of the address, used for formatting.
|
||||
///
|
||||
/// \param[in] prefix
|
||||
/// A prefix C string. If nullptr, no prefix will be output.
|
||||
///
|
||||
/// \param[in] suffix
|
||||
/// A suffix C string. If nullptr, no suffix will be output.
|
||||
void DumpAddressRange(llvm::raw_ostream &s, uint64_t lo_addr, uint64_t hi_addr,
|
||||
uint32_t addr_size, const char *prefix = nullptr,
|
||||
const char *suffix = nullptr);
|
||||
|
||||
} // namespace lldb_private
|
||||
|
||||
#endif // liblldb_Stream_h_
|
||||
|
|
|
@ -418,13 +418,13 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
|
|||
section_sp->DumpName(s);
|
||||
s->Printf(" + %" PRIu64, m_offset);
|
||||
} else {
|
||||
s->Address(m_offset, addr_size);
|
||||
DumpAddress(s->AsRawOstream(), m_offset, addr_size);
|
||||
}
|
||||
break;
|
||||
|
||||
case DumpStyleSectionPointerOffset:
|
||||
s->Printf("(Section *)%p + ", static_cast<void *>(section_sp.get()));
|
||||
s->Address(m_offset, addr_size);
|
||||
DumpAddress(s->AsRawOstream(), m_offset, addr_size);
|
||||
break;
|
||||
|
||||
case DumpStyleModuleWithFileAddress:
|
||||
|
@ -444,7 +444,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
|
|||
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
||||
return false;
|
||||
}
|
||||
s->Address(file_addr, addr_size);
|
||||
DumpAddress(s->AsRawOstream(), file_addr, addr_size);
|
||||
if (style == DumpStyleModuleWithFileAddress && section_sp)
|
||||
s->PutChar(']');
|
||||
} break;
|
||||
|
@ -472,7 +472,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
|
|||
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
|
||||
return false;
|
||||
}
|
||||
s->Address(load_addr, addr_size);
|
||||
DumpAddress(s->AsRawOstream(), load_addr, addr_size);
|
||||
} break;
|
||||
|
||||
case DumpStyleResolvedDescription:
|
||||
|
@ -754,7 +754,8 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
|
|||
if (dereferenced_addr.Dump(&strm, exe_scope,
|
||||
DumpStyleResolvedDescription,
|
||||
DumpStyleInvalid, addr_size)) {
|
||||
s->Address(dereferenced_load_addr, addr_size, " -> ", " ");
|
||||
DumpAddress(s->AsRawOstream(), dereferenced_load_addr, addr_size,
|
||||
" -> ", " ");
|
||||
s->Write(strm.GetString().data(), strm.GetSize());
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -161,7 +161,8 @@ bool AddressRange::Dump(Stream *s, Target *target, Address::DumpStyle style,
|
|||
s->PutChar('[');
|
||||
m_base_addr.Dump(s, target, style, fallback_style);
|
||||
s->PutChar('-');
|
||||
s->Address(m_base_addr.GetOffset() + GetByteSize(), addr_size);
|
||||
DumpAddress(s->AsRawOstream(), m_base_addr.GetOffset() + GetByteSize(),
|
||||
addr_size);
|
||||
s->PutChar(')');
|
||||
return true;
|
||||
break;
|
||||
|
@ -185,7 +186,8 @@ bool AddressRange::Dump(Stream *s, Target *target, Address::DumpStyle style,
|
|||
s->Printf("%s", module_sp->GetFileSpec().GetFilename().AsCString(
|
||||
"<Unknown>"));
|
||||
}
|
||||
s->AddressRange(vmaddr, vmaddr + GetByteSize(), addr_size);
|
||||
DumpAddressRange(s->AsRawOstream(), vmaddr, vmaddr + GetByteSize(),
|
||||
addr_size);
|
||||
return true;
|
||||
} else if (fallback_style != Address::DumpStyleInvalid) {
|
||||
return Dump(s, target, fallback_style, Address::DumpStyleInvalid);
|
||||
|
|
|
@ -467,9 +467,10 @@ lldb::offset_t lldb_private::DumpDataExtractor(
|
|||
} break;
|
||||
|
||||
case eFormatPointer:
|
||||
s->Address(DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
|
||||
item_bit_offset),
|
||||
sizeof(addr_t));
|
||||
DumpAddress(s->AsRawOstream(),
|
||||
DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
|
||||
item_bit_offset),
|
||||
sizeof(addr_t));
|
||||
break;
|
||||
|
||||
case eFormatComplexInteger: {
|
||||
|
|
|
@ -414,9 +414,10 @@ static bool RunScriptFormatKeyword(Stream &s, const SymbolContext *sc,
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool DumpAddress(Stream &s, const SymbolContext *sc,
|
||||
const ExecutionContext *exe_ctx, const Address &addr,
|
||||
bool print_file_addr_or_load_addr) {
|
||||
static bool DumpAddressAndContent(Stream &s, const SymbolContext *sc,
|
||||
const ExecutionContext *exe_ctx,
|
||||
const Address &addr,
|
||||
bool print_file_addr_or_load_addr) {
|
||||
Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
|
||||
addr_t vaddr = LLDB_INVALID_ADDRESS;
|
||||
if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
|
||||
|
@ -1145,9 +1146,10 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
|
|||
case Entry::Type::AddressFile:
|
||||
case Entry::Type::AddressLoad:
|
||||
case Entry::Type::AddressLoadOrFile:
|
||||
return (addr != nullptr && addr->IsValid() &&
|
||||
DumpAddress(s, sc, exe_ctx, *addr,
|
||||
entry.type == Entry::Type::AddressLoadOrFile));
|
||||
return (
|
||||
addr != nullptr && addr->IsValid() &&
|
||||
DumpAddressAndContent(s, sc, exe_ctx, *addr,
|
||||
entry.type == Entry::Type::AddressLoadOrFile));
|
||||
|
||||
case Entry::Type::ProcessID:
|
||||
if (exe_ctx) {
|
||||
|
@ -1415,7 +1417,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
|
|||
if (frame) {
|
||||
const Address &pc_addr = frame->GetFrameCodeAddress();
|
||||
if (pc_addr.IsValid()) {
|
||||
if (DumpAddress(s, sc, exe_ctx, pc_addr, false))
|
||||
if (DumpAddressAndContent(s, sc, exe_ctx, pc_addr, false))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1827,7 +1829,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
|
|||
|
||||
if (entry.type == Entry::Type::LineEntryEndAddress)
|
||||
addr.Slide(sc->line_entry.range.GetByteSize());
|
||||
if (DumpAddress(s, sc, exe_ctx, addr, false))
|
||||
if (DumpAddressAndContent(s, sc, exe_ctx, addr, false))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -2929,8 +2929,9 @@ void DWARFExpression::PrintDWARFLocationList(
|
|||
s.PutCString("\n ");
|
||||
s.Indent();
|
||||
if (cu)
|
||||
s.AddressRange(start_addr + base_addr, end_addr + base_addr,
|
||||
cu->GetAddressByteSize(), nullptr, ": ");
|
||||
DumpAddressRange(s.AsRawOstream(), start_addr + base_addr,
|
||||
end_addr + base_addr, cu->GetAddressByteSize(), nullptr,
|
||||
": ");
|
||||
uint32_t loc_length = debug_loc_data.GetU16(&offset);
|
||||
|
||||
DataExtractor locationData(debug_loc_data, offset, loc_length);
|
||||
|
|
|
@ -95,13 +95,15 @@ void DWARFDebugRanges::Dump(Stream &s,
|
|||
} else if (begin == LLDB_INVALID_ADDRESS) {
|
||||
// A base address selection entry
|
||||
base_addr = end;
|
||||
s.Address(base_addr, sizeof(dw_addr_t), " Base address = ");
|
||||
DumpAddress(s.AsRawOstream(), base_addr, sizeof(dw_addr_t),
|
||||
" Base address = ");
|
||||
} else {
|
||||
// Convert from offset to an address
|
||||
dw_addr_t begin_addr = begin + base_addr;
|
||||
dw_addr_t end_addr = end + base_addr;
|
||||
|
||||
s.AddressRange(begin_addr, end_addr, sizeof(dw_addr_t), nullptr);
|
||||
DumpAddressRange(s.AsRawOstream(), begin_addr, end_addr,
|
||||
sizeof(dw_addr_t), nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -333,7 +333,7 @@ void DWARFFormValue::Dump(Stream &s) const {
|
|||
|
||||
switch (m_form) {
|
||||
case DW_FORM_addr:
|
||||
s.Address(uvalue, sizeof(uint64_t));
|
||||
DumpAddress(s.AsRawOstream(), uvalue, sizeof(uint64_t));
|
||||
break;
|
||||
case DW_FORM_flag:
|
||||
case DW_FORM_data1:
|
||||
|
@ -409,10 +409,11 @@ void DWARFFormValue::Dump(Stream &s) const {
|
|||
assert(m_unit); // Unit must be valid for DW_FORM_ref_addr objects or we
|
||||
// will get this wrong
|
||||
if (m_unit->GetVersion() <= 2)
|
||||
s.Address(uvalue, sizeof(uint64_t) * 2);
|
||||
DumpAddress(s.AsRawOstream(), uvalue, sizeof(uint64_t) * 2);
|
||||
else
|
||||
s.Address(uvalue, 4 * 2); // 4 for DWARF32, 8 for DWARF64, but we don't
|
||||
// support DWARF64 yet
|
||||
DumpAddress(s.AsRawOstream(), uvalue,
|
||||
4 * 2); // 4 for DWARF32, 8 for DWARF64, but we don't
|
||||
// support DWARF64 yet
|
||||
break;
|
||||
}
|
||||
case DW_FORM_ref1:
|
||||
|
|
|
@ -44,8 +44,8 @@ void Block::GetDescription(Stream *s, Function *function,
|
|||
s->Printf(", range%s = ", num_ranges > 1 ? "s" : "");
|
||||
for (size_t i = 0; i < num_ranges; ++i) {
|
||||
const Range &range = m_ranges.GetEntryRef(i);
|
||||
s->AddressRange(base_addr + range.GetRangeBase(),
|
||||
base_addr + range.GetRangeEnd(), 4);
|
||||
DumpAddressRange(s->AsRawOstream(), base_addr + range.GetRangeBase(),
|
||||
base_addr + range.GetRangeEnd(), 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,8 +87,8 @@ void Block::Dump(Stream *s, addr_t base_addr, int32_t depth,
|
|||
*s << '!';
|
||||
else
|
||||
*s << ' ';
|
||||
s->AddressRange(base_addr + range.GetRangeBase(),
|
||||
base_addr + range.GetRangeEnd(), 4);
|
||||
DumpAddressRange(s->AsRawOstream(), base_addr + range.GetRangeBase(),
|
||||
base_addr + range.GetRangeEnd(), 4);
|
||||
}
|
||||
}
|
||||
s->EOL();
|
||||
|
@ -160,8 +160,8 @@ void Block::DumpAddressRanges(Stream *s, lldb::addr_t base_addr) {
|
|||
size_t num_ranges = m_ranges.GetSize();
|
||||
for (size_t i = 0; i < num_ranges; ++i) {
|
||||
const Range &range = m_ranges.GetEntryRef(i);
|
||||
s->AddressRange(base_addr + range.GetRangeBase(),
|
||||
base_addr + range.GetRangeEnd(), 4);
|
||||
DumpAddressRange(s->AsRawOstream(), base_addr + range.GetRangeBase(),
|
||||
base_addr + range.GetRangeEnd(), 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ void ThreadPlanRunToAddress::GetDescription(Stream *s,
|
|||
s->Printf("run to addresses: ");
|
||||
|
||||
for (size_t i = 0; i < num_addresses; i++) {
|
||||
s->Address(m_addresses[i], sizeof(addr_t));
|
||||
DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t));
|
||||
s->Printf(" ");
|
||||
}
|
||||
} else {
|
||||
|
@ -116,7 +116,7 @@ void ThreadPlanRunToAddress::GetDescription(Stream *s,
|
|||
s->Indent();
|
||||
}
|
||||
|
||||
s->Address(m_addresses[i], sizeof(addr_t));
|
||||
DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t));
|
||||
s->Printf(" using breakpoint: %d - ", m_break_ids[i]);
|
||||
Breakpoint *breakpoint =
|
||||
m_thread.CalculateTarget()->GetBreakpointByID(m_break_ids[i]).get();
|
||||
|
@ -143,7 +143,7 @@ bool ThreadPlanRunToAddress::ValidatePlan(Stream *error) {
|
|||
all_bps_good = false;
|
||||
if (error) {
|
||||
error->Printf("Could not set breakpoint for address: ");
|
||||
error->Address(m_addresses[i], sizeof(addr_t));
|
||||
DumpAddress(error->AsRawOstream(), m_addresses[i], sizeof(addr_t));
|
||||
error->Printf("\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,8 +145,8 @@ bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) {
|
|||
|
||||
if (log) {
|
||||
StreamString s;
|
||||
s.Address(
|
||||
m_thread.GetRegisterContext()->GetPC(),
|
||||
DumpAddress(
|
||||
s.AsRawOstream(), m_thread.GetRegisterContext()->GetPC(),
|
||||
m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
|
||||
LLDB_LOGF(log, "ThreadPlanStepInRange reached %s.", s.GetData());
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ void ThreadPlanStepInstruction::GetDescription(Stream *s,
|
|||
PrintFailureIfAny();
|
||||
} else {
|
||||
s->Printf("Stepping one instruction past ");
|
||||
s->Address(m_instruction_addr, sizeof(addr_t));
|
||||
DumpAddress(s->AsRawOstream(), m_instruction_addr, sizeof(addr_t));
|
||||
if (!m_start_has_symbol)
|
||||
s->Printf(" which has no symbol");
|
||||
|
||||
|
@ -182,14 +182,16 @@ bool ThreadPlanStepInstruction::ShouldStop(Event *event_ptr) {
|
|||
s.PutCString("Stepped in to: ");
|
||||
addr_t stop_addr =
|
||||
m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
|
||||
s.Address(stop_addr, m_thread.CalculateTarget()
|
||||
->GetArchitecture()
|
||||
.GetAddressByteSize());
|
||||
DumpAddress(s.AsRawOstream(), stop_addr,
|
||||
m_thread.CalculateTarget()
|
||||
->GetArchitecture()
|
||||
.GetAddressByteSize());
|
||||
s.PutCString(" stepping out to: ");
|
||||
addr_t return_addr = return_frame->GetRegisterContext()->GetPC();
|
||||
s.Address(return_addr, m_thread.CalculateTarget()
|
||||
->GetArchitecture()
|
||||
.GetAddressByteSize());
|
||||
DumpAddress(s.AsRawOstream(), return_addr,
|
||||
m_thread.CalculateTarget()
|
||||
->GetArchitecture()
|
||||
.GetAddressByteSize());
|
||||
LLDB_LOGF(log, "%s.", s.GetData());
|
||||
}
|
||||
|
||||
|
|
|
@ -128,8 +128,8 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) {
|
|||
|
||||
if (log) {
|
||||
StreamString s;
|
||||
s.Address(
|
||||
m_thread.GetRegisterContext()->GetPC(),
|
||||
DumpAddress(
|
||||
s.AsRawOstream(), m_thread.GetRegisterContext()->GetPC(),
|
||||
m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
|
||||
LLDB_LOGF(log, "ThreadPlanStepOverRange reached %s.", s.GetData());
|
||||
}
|
||||
|
|
|
@ -119,11 +119,11 @@ void ThreadPlanStepThrough::GetDescription(Stream *s,
|
|||
s->Printf("Step through");
|
||||
else {
|
||||
s->PutCString("Stepping through trampoline code from: ");
|
||||
s->Address(m_start_address, sizeof(addr_t));
|
||||
DumpAddress(s->AsRawOstream(), m_start_address, sizeof(addr_t));
|
||||
if (m_backstop_bkpt_id != LLDB_INVALID_BREAK_ID) {
|
||||
s->Printf(" with backstop breakpoint ID: %d at address: ",
|
||||
m_backstop_bkpt_id);
|
||||
s->Address(m_backstop_addr, sizeof(addr_t));
|
||||
DumpAddress(s->AsRawOstream(), m_backstop_addr, sizeof(addr_t));
|
||||
} else
|
||||
s->PutCString(" unable to set a backstop breakpoint.");
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "lldb/Utility/Endian.h"
|
||||
#include "lldb/Utility/VASPrintf.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/LEB128.h"
|
||||
|
||||
#include <string>
|
||||
|
@ -76,28 +77,27 @@ void Stream::QuotedCString(const char *cstr, const char *format) {
|
|||
|
||||
// Put an address "addr" out to the stream with optional prefix and suffix
|
||||
// strings.
|
||||
void Stream::Address(uint64_t addr, uint32_t addr_size, const char *prefix,
|
||||
const char *suffix) {
|
||||
void lldb_private::DumpAddress(llvm::raw_ostream &s, uint64_t addr,
|
||||
uint32_t addr_size, const char *prefix,
|
||||
const char *suffix) {
|
||||
if (prefix == nullptr)
|
||||
prefix = "";
|
||||
if (suffix == nullptr)
|
||||
suffix = "";
|
||||
// int addr_width = m_addr_size << 1;
|
||||
// Printf ("%s0x%0*" PRIx64 "%s", prefix, addr_width, addr, suffix);
|
||||
Printf("%s0x%0*" PRIx64 "%s", prefix, addr_size * 2, addr, suffix);
|
||||
s << prefix << llvm::format_hex(addr, 2 + 2 * addr_size) << suffix;
|
||||
}
|
||||
|
||||
// Put an address range out to the stream with optional prefix and suffix
|
||||
// strings.
|
||||
void Stream::AddressRange(uint64_t lo_addr, uint64_t hi_addr,
|
||||
uint32_t addr_size, const char *prefix,
|
||||
const char *suffix) {
|
||||
void lldb_private::DumpAddressRange(llvm::raw_ostream &s, uint64_t lo_addr,
|
||||
uint64_t hi_addr, uint32_t addr_size,
|
||||
const char *prefix, const char *suffix) {
|
||||
if (prefix && prefix[0])
|
||||
PutCString(prefix);
|
||||
Address(lo_addr, addr_size, "[");
|
||||
Address(hi_addr, addr_size, "-", ")");
|
||||
s << prefix;
|
||||
DumpAddress(s, lo_addr, addr_size, "[");
|
||||
DumpAddress(s, hi_addr, addr_size, "-", ")");
|
||||
if (suffix && suffix[0])
|
||||
PutCString(suffix);
|
||||
s << suffix;
|
||||
}
|
||||
|
||||
size_t Stream::PutChar(char ch) { return Write(&ch, 1); }
|
||||
|
|
|
@ -36,8 +36,8 @@ bool VMRange::ContainsRange(const VMRange::collection &coll,
|
|||
}
|
||||
|
||||
void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const {
|
||||
s->AddressRange(offset + GetBaseAddress(), offset + GetEndAddress(),
|
||||
addr_width);
|
||||
DumpAddressRange(s->AsRawOstream(), offset + GetBaseAddress(),
|
||||
offset + GetEndAddress(), addr_width);
|
||||
}
|
||||
|
||||
bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
|
||||
|
|
|
@ -37,94 +37,90 @@ struct BinaryStreamTest : StreamTest {
|
|||
}
|
||||
|
||||
TEST_F(StreamTest, AddressPrefix) {
|
||||
s.Address(0x1, 1, "foo");
|
||||
DumpAddress(s.AsRawOstream(), 0x1, 1, "foo");
|
||||
EXPECT_EQ("foo0x01", TakeValue());
|
||||
}
|
||||
|
||||
TEST_F(StreamTest, AddressEmptyPrefix) {
|
||||
s.Address(0x1, 1, nullptr);
|
||||
DumpAddress(s.AsRawOstream(), 0x1, 1, nullptr);
|
||||
EXPECT_EQ("0x01", TakeValue());
|
||||
s.Address(0x1, 1, "");
|
||||
DumpAddress(s.AsRawOstream(), 0x1, 1, "");
|
||||
EXPECT_EQ("0x01", TakeValue());
|
||||
}
|
||||
|
||||
TEST_F(StreamTest, AddressSuffix) {
|
||||
s.Address(0x1, 1, nullptr, "foo");
|
||||
DumpAddress(s.AsRawOstream(), 0x1, 1, nullptr, "foo");
|
||||
EXPECT_EQ("0x01foo", TakeValue());
|
||||
}
|
||||
|
||||
TEST_F(StreamTest, AddressNoSuffix) {
|
||||
s.Address(0x1, 1, nullptr, nullptr);
|
||||
DumpAddress(s.AsRawOstream(), 0x1, 1, nullptr, nullptr);
|
||||
EXPECT_EQ("0x01", TakeValue());
|
||||
s.Address(0x1, 1, nullptr, "");
|
||||
DumpAddress(s.AsRawOstream(), 0x1, 1, nullptr, "");
|
||||
EXPECT_EQ("0x01", TakeValue());
|
||||
}
|
||||
|
||||
TEST_F(StreamTest, AddressPrefixAndSuffix) {
|
||||
s.Address(0x1, 1, "foo", "bar");
|
||||
DumpAddress(s.AsRawOstream(), 0x1, 1, "foo", "bar");
|
||||
EXPECT_EQ("foo0x01bar", TakeValue());
|
||||
}
|
||||
|
||||
TEST_F(StreamTest, AddressSize) {
|
||||
s.Address(0x0, 0);
|
||||
DumpAddress(s.AsRawOstream(), 0x0, 0);
|
||||
EXPECT_EQ("0x0", TakeValue());
|
||||
s.Address(0x1, 0);
|
||||
DumpAddress(s.AsRawOstream(), 0x1, 0);
|
||||
EXPECT_EQ("0x1", TakeValue());
|
||||
|
||||
s.Address(0x1, 1);
|
||||
DumpAddress(s.AsRawOstream(), 0x1, 1);
|
||||
EXPECT_EQ("0x01", TakeValue());
|
||||
s.Address(0xf1, 1);
|
||||
DumpAddress(s.AsRawOstream(), 0xf1, 1);
|
||||
EXPECT_EQ("0xf1", TakeValue());
|
||||
s.Address(0xff, 1);
|
||||
DumpAddress(s.AsRawOstream(), 0xff, 1);
|
||||
EXPECT_EQ("0xff", TakeValue());
|
||||
s.Address(0x100, 1);
|
||||
DumpAddress(s.AsRawOstream(), 0x100, 1);
|
||||
EXPECT_EQ("0x100", TakeValue());
|
||||
|
||||
s.Address(0xf00, 4);
|
||||
DumpAddress(s.AsRawOstream(), 0xf00, 4);
|
||||
EXPECT_EQ("0x00000f00", TakeValue());
|
||||
s.Address(0x100, 8);
|
||||
DumpAddress(s.AsRawOstream(), 0x100, 8);
|
||||
EXPECT_EQ("0x0000000000000100", TakeValue());
|
||||
s.Address(0x100, 10);
|
||||
EXPECT_EQ("0x00000000000000000100", TakeValue());
|
||||
s.Address(0x1234, 10);
|
||||
EXPECT_EQ("0x00000000000000001234", TakeValue());
|
||||
}
|
||||
|
||||
TEST_F(StreamTest, AddressRange) {
|
||||
s.AddressRange(0x100, 0x101, 2);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 2);
|
||||
EXPECT_EQ("[0x0100-0x0101)", TakeValue());
|
||||
}
|
||||
|
||||
TEST_F(StreamTest, AddressRangeEmptyRange) {
|
||||
s.AddressRange(0x100, 0x100, 2);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x100, 0x100, 2);
|
||||
EXPECT_EQ("[0x0100-0x0100)", TakeValue());
|
||||
s.AddressRange(0x0, 0x0, 2);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x0, 0x0, 2);
|
||||
EXPECT_EQ("[0x0000-0x0000)", TakeValue());
|
||||
}
|
||||
|
||||
TEST_F(StreamTest, AddressRangeInvalidRange) {
|
||||
s.AddressRange(0x100, 0x0FF, 2);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x100, 0x0FF, 2);
|
||||
EXPECT_EQ("[0x0100-0x00ff)", TakeValue());
|
||||
s.AddressRange(0x100, 0x0, 2);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x100, 0x0, 2);
|
||||
EXPECT_EQ("[0x0100-0x0000)", TakeValue());
|
||||
}
|
||||
|
||||
TEST_F(StreamTest, AddressRangeSize) {
|
||||
s.AddressRange(0x100, 0x101, 0);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 0);
|
||||
EXPECT_EQ("[0x100-0x101)", TakeValue());
|
||||
s.AddressRange(0x100, 0x101, 2);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 2);
|
||||
EXPECT_EQ("[0x0100-0x0101)", TakeValue());
|
||||
s.AddressRange(0x100, 0x101, 4);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 4);
|
||||
EXPECT_EQ("[0x00000100-0x00000101)", TakeValue());
|
||||
|
||||
s.AddressRange(0x100, 0x101, 4);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x100, 0x101, 4);
|
||||
EXPECT_EQ("[0x00000100-0x00000101)", TakeValue());
|
||||
s.AddressRange(0x1, 0x101, 4);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x1, 0x101, 4);
|
||||
EXPECT_EQ("[0x00000001-0x00000101)", TakeValue());
|
||||
s.AddressRange(0x101, 0x1, 4);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x101, 0x1, 4);
|
||||
EXPECT_EQ("[0x00000101-0x00000001)", TakeValue());
|
||||
|
||||
s.AddressRange(0x1, 0x101, 1);
|
||||
DumpAddressRange(s.AsRawOstream(), 0x1, 0x101, 1);
|
||||
EXPECT_EQ("[0x01-0x101)", TakeValue());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue