Skip to content

Commit 1462f5a

Browse files
committed
[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
1 parent 18b72d3 commit 1462f5a

17 files changed

+149
-134
lines changed

lldb/include/lldb/Utility/Stream.h

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -222,47 +222,6 @@ class Stream {
222222
Stream &operator<<(int32_t sval) = delete;
223223
Stream &operator<<(int64_t sval) = delete;
224224

225-
/// Output an address value to this stream.
226-
///
227-
/// Put an address \a addr out to the stream with optional \a prefix and \a
228-
/// suffix strings.
229-
///
230-
/// \param[in] addr
231-
/// An address value.
232-
///
233-
/// \param[in] addr_size
234-
/// Size in bytes of the address, used for formatting.
235-
///
236-
/// \param[in] prefix
237-
/// A prefix C string. If nullptr, no prefix will be output.
238-
///
239-
/// \param[in] suffix
240-
/// A suffix C string. If nullptr, no suffix will be output.
241-
void Address(uint64_t addr, uint32_t addr_size, const char *prefix = nullptr,
242-
const char *suffix = nullptr);
243-
244-
/// Output an address range to this stream.
245-
///
246-
/// Put an address range \a lo_addr - \a hi_addr out to the stream with
247-
/// optional \a prefix and \a suffix strings.
248-
///
249-
/// \param[in] lo_addr
250-
/// The start address of the address range.
251-
///
252-
/// \param[in] hi_addr
253-
/// The end address of the address range.
254-
///
255-
/// \param[in] addr_size
256-
/// Size in bytes of the address, used for formatting.
257-
///
258-
/// \param[in] prefix
259-
/// A prefix C string. If nullptr, no prefix will be output.
260-
///
261-
/// \param[in] suffix
262-
/// A suffix C string. If nullptr, no suffix will be output.
263-
void AddressRange(uint64_t lo_addr, uint64_t hi_addr, uint32_t addr_size,
264-
const char *prefix = nullptr, const char *suffix = nullptr);
265-
266225
/// Output a C string to the stream.
267226
///
268227
/// Print a C string \a cstr to the stream.
@@ -452,6 +411,54 @@ class Stream {
452411
RawOstreamForward m_forwarder;
453412
};
454413

414+
/// Output an address value to this stream.
415+
///
416+
/// Put an address \a addr out to the stream with optional \a prefix and \a
417+
/// suffix strings.
418+
///
419+
/// \param[in] s
420+
/// The output stream.
421+
///
422+
/// \param[in] addr
423+
/// An address value.
424+
///
425+
/// \param[in] addr_size
426+
/// Size in bytes of the address, used for formatting.
427+
///
428+
/// \param[in] prefix
429+
/// A prefix C string. If nullptr, no prefix will be output.
430+
///
431+
/// \param[in] suffix
432+
/// A suffix C string. If nullptr, no suffix will be output.
433+
void DumpAddress(llvm::raw_ostream &s, uint64_t addr, uint32_t addr_size,
434+
const char *prefix = nullptr, const char *suffix = nullptr);
435+
436+
/// Output an address range to this stream.
437+
///
438+
/// Put an address range \a lo_addr - \a hi_addr out to the stream with
439+
/// optional \a prefix and \a suffix strings.
440+
///
441+
/// \param[in] s
442+
/// The output stream.
443+
///
444+
/// \param[in] lo_addr
445+
/// The start address of the address range.
446+
///
447+
/// \param[in] hi_addr
448+
/// The end address of the address range.
449+
///
450+
/// \param[in] addr_size
451+
/// Size in bytes of the address, used for formatting.
452+
///
453+
/// \param[in] prefix
454+
/// A prefix C string. If nullptr, no prefix will be output.
455+
///
456+
/// \param[in] suffix
457+
/// A suffix C string. If nullptr, no suffix will be output.
458+
void DumpAddressRange(llvm::raw_ostream &s, uint64_t lo_addr, uint64_t hi_addr,
459+
uint32_t addr_size, const char *prefix = nullptr,
460+
const char *suffix = nullptr);
461+
455462
} // namespace lldb_private
456463

457464
#endif // liblldb_Stream_h_

lldb/source/Core/Address.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,13 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
418418
section_sp->DumpName(s);
419419
s->Printf(" + %" PRIu64, m_offset);
420420
} else {
421-
s->Address(m_offset, addr_size);
421+
DumpAddress(s->AsRawOstream(), m_offset, addr_size);
422422
}
423423
break;
424424

425425
case DumpStyleSectionPointerOffset:
426426
s->Printf("(Section *)%p + ", static_cast<void *>(section_sp.get()));
427-
s->Address(m_offset, addr_size);
427+
DumpAddress(s->AsRawOstream(), m_offset, addr_size);
428428
break;
429429

430430
case DumpStyleModuleWithFileAddress:
@@ -444,7 +444,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
444444
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
445445
return false;
446446
}
447-
s->Address(file_addr, addr_size);
447+
DumpAddress(s->AsRawOstream(), file_addr, addr_size);
448448
if (style == DumpStyleModuleWithFileAddress && section_sp)
449449
s->PutChar(']');
450450
} break;
@@ -472,7 +472,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
472472
return Dump(s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
473473
return false;
474474
}
475-
s->Address(load_addr, addr_size);
475+
DumpAddress(s->AsRawOstream(), load_addr, addr_size);
476476
} break;
477477

478478
case DumpStyleResolvedDescription:
@@ -754,7 +754,8 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
754754
if (dereferenced_addr.Dump(&strm, exe_scope,
755755
DumpStyleResolvedDescription,
756756
DumpStyleInvalid, addr_size)) {
757-
s->Address(dereferenced_load_addr, addr_size, " -> ", " ");
757+
DumpAddress(s->AsRawOstream(), dereferenced_load_addr, addr_size,
758+
" -> ", " ");
758759
s->Write(strm.GetString().data(), strm.GetSize());
759760
return true;
760761
}

lldb/source/Core/AddressRange.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ bool AddressRange::Dump(Stream *s, Target *target, Address::DumpStyle style,
161161
s->PutChar('[');
162162
m_base_addr.Dump(s, target, style, fallback_style);
163163
s->PutChar('-');
164-
s->Address(m_base_addr.GetOffset() + GetByteSize(), addr_size);
164+
DumpAddress(s->AsRawOstream(), m_base_addr.GetOffset() + GetByteSize(),
165+
addr_size);
165166
s->PutChar(')');
166167
return true;
167168
break;
@@ -185,7 +186,8 @@ bool AddressRange::Dump(Stream *s, Target *target, Address::DumpStyle style,
185186
s->Printf("%s", module_sp->GetFileSpec().GetFilename().AsCString(
186187
"<Unknown>"));
187188
}
188-
s->AddressRange(vmaddr, vmaddr + GetByteSize(), addr_size);
189+
DumpAddressRange(s->AsRawOstream(), vmaddr, vmaddr + GetByteSize(),
190+
addr_size);
189191
return true;
190192
} else if (fallback_style != Address::DumpStyleInvalid) {
191193
return Dump(s, target, fallback_style, Address::DumpStyleInvalid);

lldb/source/Core/DumpDataExtractor.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,10 @@ lldb::offset_t lldb_private::DumpDataExtractor(
467467
} break;
468468

469469
case eFormatPointer:
470-
s->Address(DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
471-
item_bit_offset),
472-
sizeof(addr_t));
470+
DumpAddress(s->AsRawOstream(),
471+
DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
472+
item_bit_offset),
473+
sizeof(addr_t));
473474
break;
474475

475476
case eFormatComplexInteger: {

lldb/source/Core/FormatEntity.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,10 @@ static bool RunScriptFormatKeyword(Stream &s, const SymbolContext *sc,
414414
return false;
415415
}
416416

417-
static bool DumpAddress(Stream &s, const SymbolContext *sc,
418-
const ExecutionContext *exe_ctx, const Address &addr,
419-
bool print_file_addr_or_load_addr) {
417+
static bool DumpAddressAndContent(Stream &s, const SymbolContext *sc,
418+
const ExecutionContext *exe_ctx,
419+
const Address &addr,
420+
bool print_file_addr_or_load_addr) {
420421
Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
421422
addr_t vaddr = LLDB_INVALID_ADDRESS;
422423
if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
@@ -1145,9 +1146,10 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
11451146
case Entry::Type::AddressFile:
11461147
case Entry::Type::AddressLoad:
11471148
case Entry::Type::AddressLoadOrFile:
1148-
return (addr != nullptr && addr->IsValid() &&
1149-
DumpAddress(s, sc, exe_ctx, *addr,
1150-
entry.type == Entry::Type::AddressLoadOrFile));
1149+
return (
1150+
addr != nullptr && addr->IsValid() &&
1151+
DumpAddressAndContent(s, sc, exe_ctx, *addr,
1152+
entry.type == Entry::Type::AddressLoadOrFile));
11511153

11521154
case Entry::Type::ProcessID:
11531155
if (exe_ctx) {
@@ -1415,7 +1417,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
14151417
if (frame) {
14161418
const Address &pc_addr = frame->GetFrameCodeAddress();
14171419
if (pc_addr.IsValid()) {
1418-
if (DumpAddress(s, sc, exe_ctx, pc_addr, false))
1420+
if (DumpAddressAndContent(s, sc, exe_ctx, pc_addr, false))
14191421
return true;
14201422
}
14211423
}
@@ -1827,7 +1829,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
18271829

18281830
if (entry.type == Entry::Type::LineEntryEndAddress)
18291831
addr.Slide(sc->line_entry.range.GetByteSize());
1830-
if (DumpAddress(s, sc, exe_ctx, addr, false))
1832+
if (DumpAddressAndContent(s, sc, exe_ctx, addr, false))
18311833
return true;
18321834
}
18331835
return false;

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,8 +2929,9 @@ void DWARFExpression::PrintDWARFLocationList(
29292929
s.PutCString("\n ");
29302930
s.Indent();
29312931
if (cu)
2932-
s.AddressRange(start_addr + base_addr, end_addr + base_addr,
2933-
cu->GetAddressByteSize(), nullptr, ": ");
2932+
DumpAddressRange(s.AsRawOstream(), start_addr + base_addr,
2933+
end_addr + base_addr, cu->GetAddressByteSize(), nullptr,
2934+
": ");
29342935
uint32_t loc_length = debug_loc_data.GetU16(&offset);
29352936

29362937
DataExtractor locationData(debug_loc_data, offset, loc_length);

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ void DWARFDebugRanges::Dump(Stream &s,
9595
} else if (begin == LLDB_INVALID_ADDRESS) {
9696
// A base address selection entry
9797
base_addr = end;
98-
s.Address(base_addr, sizeof(dw_addr_t), " Base address = ");
98+
DumpAddress(s.AsRawOstream(), base_addr, sizeof(dw_addr_t),
99+
" Base address = ");
99100
} else {
100101
// Convert from offset to an address
101102
dw_addr_t begin_addr = begin + base_addr;
102103
dw_addr_t end_addr = end + base_addr;
103104

104-
s.AddressRange(begin_addr, end_addr, sizeof(dw_addr_t), nullptr);
105+
DumpAddressRange(s.AsRawOstream(), begin_addr, end_addr,
106+
sizeof(dw_addr_t), nullptr);
105107
}
106108
}
107109
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void DWARFFormValue::Dump(Stream &s) const {
333333

334334
switch (m_form) {
335335
case DW_FORM_addr:
336-
s.Address(uvalue, sizeof(uint64_t));
336+
DumpAddress(s.AsRawOstream(), uvalue, sizeof(uint64_t));
337337
break;
338338
case DW_FORM_flag:
339339
case DW_FORM_data1:
@@ -409,10 +409,11 @@ void DWARFFormValue::Dump(Stream &s) const {
409409
assert(m_unit); // Unit must be valid for DW_FORM_ref_addr objects or we
410410
// will get this wrong
411411
if (m_unit->GetVersion() <= 2)
412-
s.Address(uvalue, sizeof(uint64_t) * 2);
412+
DumpAddress(s.AsRawOstream(), uvalue, sizeof(uint64_t) * 2);
413413
else
414-
s.Address(uvalue, 4 * 2); // 4 for DWARF32, 8 for DWARF64, but we don't
415-
// support DWARF64 yet
414+
DumpAddress(s.AsRawOstream(), uvalue,
415+
4 * 2); // 4 for DWARF32, 8 for DWARF64, but we don't
416+
// support DWARF64 yet
416417
break;
417418
}
418419
case DW_FORM_ref1:

lldb/source/Symbol/Block.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ void Block::GetDescription(Stream *s, Function *function,
4444
s->Printf(", range%s = ", num_ranges > 1 ? "s" : "");
4545
for (size_t i = 0; i < num_ranges; ++i) {
4646
const Range &range = m_ranges.GetEntryRef(i);
47-
s->AddressRange(base_addr + range.GetRangeBase(),
48-
base_addr + range.GetRangeEnd(), 4);
47+
DumpAddressRange(s->AsRawOstream(), base_addr + range.GetRangeBase(),
48+
base_addr + range.GetRangeEnd(), 4);
4949
}
5050
}
5151

@@ -87,8 +87,8 @@ void Block::Dump(Stream *s, addr_t base_addr, int32_t depth,
8787
*s << '!';
8888
else
8989
*s << ' ';
90-
s->AddressRange(base_addr + range.GetRangeBase(),
91-
base_addr + range.GetRangeEnd(), 4);
90+
DumpAddressRange(s->AsRawOstream(), base_addr + range.GetRangeBase(),
91+
base_addr + range.GetRangeEnd(), 4);
9292
}
9393
}
9494
s->EOL();
@@ -160,8 +160,8 @@ void Block::DumpAddressRanges(Stream *s, lldb::addr_t base_addr) {
160160
size_t num_ranges = m_ranges.GetSize();
161161
for (size_t i = 0; i < num_ranges; ++i) {
162162
const Range &range = m_ranges.GetEntryRef(i);
163-
s->AddressRange(base_addr + range.GetRangeBase(),
164-
base_addr + range.GetRangeEnd(), 4);
163+
DumpAddressRange(s->AsRawOstream(), base_addr + range.GetRangeBase(),
164+
base_addr + range.GetRangeEnd(), 4);
165165
}
166166
}
167167
}

lldb/source/Target/ThreadPlanRunToAddress.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void ThreadPlanRunToAddress::GetDescription(Stream *s,
9797
s->Printf("run to addresses: ");
9898

9999
for (size_t i = 0; i < num_addresses; i++) {
100-
s->Address(m_addresses[i], sizeof(addr_t));
100+
DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t));
101101
s->Printf(" ");
102102
}
103103
} else {
@@ -116,7 +116,7 @@ void ThreadPlanRunToAddress::GetDescription(Stream *s,
116116
s->Indent();
117117
}
118118

119-
s->Address(m_addresses[i], sizeof(addr_t));
119+
DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t));
120120
s->Printf(" using breakpoint: %d - ", m_break_ids[i]);
121121
Breakpoint *breakpoint =
122122
m_thread.CalculateTarget()->GetBreakpointByID(m_break_ids[i]).get();
@@ -143,7 +143,7 @@ bool ThreadPlanRunToAddress::ValidatePlan(Stream *error) {
143143
all_bps_good = false;
144144
if (error) {
145145
error->Printf("Could not set breakpoint for address: ");
146-
error->Address(m_addresses[i], sizeof(addr_t));
146+
DumpAddress(error->AsRawOstream(), m_addresses[i], sizeof(addr_t));
147147
error->Printf("\n");
148148
}
149149
}

lldb/source/Target/ThreadPlanStepInRange.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) {
145145

146146
if (log) {
147147
StreamString s;
148-
s.Address(
149-
m_thread.GetRegisterContext()->GetPC(),
148+
DumpAddress(
149+
s.AsRawOstream(), m_thread.GetRegisterContext()->GetPC(),
150150
m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
151151
LLDB_LOGF(log, "ThreadPlanStepInRange reached %s.", s.GetData());
152152
}

lldb/source/Target/ThreadPlanStepInstruction.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void ThreadPlanStepInstruction::GetDescription(Stream *s,
6565
PrintFailureIfAny();
6666
} else {
6767
s->Printf("Stepping one instruction past ");
68-
s->Address(m_instruction_addr, sizeof(addr_t));
68+
DumpAddress(s->AsRawOstream(), m_instruction_addr, sizeof(addr_t));
6969
if (!m_start_has_symbol)
7070
s->Printf(" which has no symbol");
7171

@@ -182,14 +182,16 @@ bool ThreadPlanStepInstruction::ShouldStop(Event *event_ptr) {
182182
s.PutCString("Stepped in to: ");
183183
addr_t stop_addr =
184184
m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
185-
s.Address(stop_addr, m_thread.CalculateTarget()
186-
->GetArchitecture()
187-
.GetAddressByteSize());
185+
DumpAddress(s.AsRawOstream(), stop_addr,
186+
m_thread.CalculateTarget()
187+
->GetArchitecture()
188+
.GetAddressByteSize());
188189
s.PutCString(" stepping out to: ");
189190
addr_t return_addr = return_frame->GetRegisterContext()->GetPC();
190-
s.Address(return_addr, m_thread.CalculateTarget()
191-
->GetArchitecture()
192-
.GetAddressByteSize());
191+
DumpAddress(s.AsRawOstream(), return_addr,
192+
m_thread.CalculateTarget()
193+
->GetArchitecture()
194+
.GetAddressByteSize());
193195
LLDB_LOGF(log, "%s.", s.GetData());
194196
}
195197

lldb/source/Target/ThreadPlanStepOverRange.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) {
128128

129129
if (log) {
130130
StreamString s;
131-
s.Address(
132-
m_thread.GetRegisterContext()->GetPC(),
131+
DumpAddress(
132+
s.AsRawOstream(), m_thread.GetRegisterContext()->GetPC(),
133133
m_thread.CalculateTarget()->GetArchitecture().GetAddressByteSize());
134134
LLDB_LOGF(log, "ThreadPlanStepOverRange reached %s.", s.GetData());
135135
}

0 commit comments

Comments
 (0)