[Lldb-commits] [lldb] [lldb][Utility] Remove address size from Stream class (NFC) (PR #190375)

Sergei Barannikov via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 3 11:19:28 PDT 2026


https://github.com/s-barannikov updated https://github.com/llvm/llvm-project/pull/190375

>From 990c5dcdbd2eccd9a256b4433de46d3567202d76 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Fri, 3 Apr 2026 20:47:56 +0300
Subject: [PATCH 1/3] [lldb][Utility] Remove address size from Stream class
 (NFC)

It violates abstraction. Luckily, it was used only in two places, see
DumpDataExtractor.cpp and CommandObjectMemory.cpp.
---
 lldb/include/lldb/Host/StreamFile.h           |  2 +-
 lldb/include/lldb/Utility/GDBRemote.h         |  3 +-
 lldb/include/lldb/Utility/Stream.h            | 25 +++-------------
 lldb/include/lldb/Utility/StreamBuffer.h      |  6 ++--
 lldb/include/lldb/Utility/StreamString.h      |  2 +-
 lldb/source/Commands/CommandObjectMemory.cpp  |  7 ++---
 lldb/source/Commands/CommandObjectSource.cpp  |  4 ---
 lldb/source/Commands/CommandObjectTarget.cpp  | 30 -------------------
 lldb/source/Core/DumpDataExtractor.cpp        |  2 +-
 lldb/source/Core/EmulateInstruction.cpp       |  2 +-
 lldb/source/Core/StreamAsynchronousIO.cpp     |  2 +-
 lldb/source/Host/common/StreamFile.cpp        |  4 +--
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp     |  9 +++---
 .../ObjectFile/Mach-O/ObjectFileMachO.h       |  4 +--
 .../gdb-remote/GDBRemoteCommunication.cpp     |  4 +--
 .../Breakpad/SymbolFileBreakpad.cpp           |  3 +-
 .../Plugins/SymbolFile/CTF/SymbolFileCTF.cpp  |  2 +-
 .../NativePDB/DWARFLocationExpression.cpp     |  5 ++--
 .../PDB/PDBLocationToDWARFExpression.cpp      |  2 +-
 lldb/source/Utility/GDBRemote.cpp             |  5 ++--
 lldb/source/Utility/Stream.cpp                | 12 ++------
 lldb/source/Utility/StreamString.cpp          |  7 ++---
 22 files changed, 38 insertions(+), 104 deletions(-)

diff --git a/lldb/include/lldb/Host/StreamFile.h b/lldb/include/lldb/Host/StreamFile.h
index 172a9a29bf491..2a542631ac481 100644
--- a/lldb/include/lldb/Host/StreamFile.h
+++ b/lldb/include/lldb/Host/StreamFile.h
@@ -24,7 +24,7 @@ namespace lldb_private {
 
 class StreamFile : public Stream {
 public:
-  StreamFile(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order);
+  StreamFile(uint32_t flags, lldb::ByteOrder byte_order);
 
   StreamFile(int fd, bool transfer_ownership);
 
diff --git a/lldb/include/lldb/Utility/GDBRemote.h b/lldb/include/lldb/Utility/GDBRemote.h
index ab700c00474ae..3b839c5d79485 100644
--- a/lldb/include/lldb/Utility/GDBRemote.h
+++ b/lldb/include/lldb/Utility/GDBRemote.h
@@ -26,8 +26,7 @@ class StreamGDBRemote : public StreamString {
 public:
   StreamGDBRemote();
 
-  StreamGDBRemote(uint32_t flags, uint32_t addr_size,
-                  lldb::ByteOrder byte_order);
+  StreamGDBRemote(uint32_t flags, lldb::ByteOrder byte_order);
 
   ~StreamGDBRemote() override;
 
diff --git a/lldb/include/lldb/Utility/Stream.h b/lldb/include/lldb/Utility/Stream.h
index d0b60a4f5fe38..f54d1785502a8 100644
--- a/lldb/include/lldb/Utility/Stream.h
+++ b/lldb/include/lldb/Utility/Stream.h
@@ -65,10 +65,9 @@ class Stream {
 
   /// Construct with flags and address size and byte order.
   ///
-  /// Construct with dump flags \a flags and the default address size. \a
-  /// flags can be any of the above enumeration logical OR'ed together.
-  Stream(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order,
-         bool colors = false);
+  /// Construct with dump flags \a flags.
+  /// \a flags can be any of the above enumeration logical OR'ed together.
+  Stream(uint32_t flags, lldb::ByteOrder byte_order, bool colors = false);
 
   /// Construct a default Stream, not binary, host byte order and host addr
   /// size.
@@ -80,7 +79,6 @@ class Stream {
 
   Stream &operator=(const Stream &rhs) {
     m_flags = rhs.m_flags;
-    m_addr_size = rhs.m_addr_size;
     m_byte_order = rhs.m_byte_order;
     m_indent_level = rhs.m_indent_level;
     return *this;
@@ -279,13 +277,6 @@ class Stream {
   /// Output and End of Line character to the stream.
   size_t EOL();
 
-  /// Get the address size in bytes.
-  ///
-  /// \return
-  ///     The size of an address in bytes that is used when outputting
-  ///     address and pointer values to the stream.
-  uint32_t GetAddressByteSize() const;
-
   /// The flags accessor.
   ///
   /// \return
@@ -389,13 +380,6 @@ class Stream {
   ///     The optional C string format that can be overridden.
   void QuotedCString(const char *cstr, const char *format = "\"%s\"");
 
-  /// Set the address size in bytes.
-  ///
-  /// \param[in] addr_size
-  ///     The new size in bytes of an address to use when outputting
-  ///     address and pointer values.
-  void SetAddressByteSize(uint32_t addr_size);
-
   /// Output a SLEB128 number to the stream.
   ///
   /// Put an SLEB128 \a uval out to the stream using the printf format in \a
@@ -421,8 +405,7 @@ class Stream {
 
 protected:
   // Member variables
-  Flags m_flags;        ///< Dump flags.
-  uint32_t m_addr_size = 4; ///< Size of an address in bytes.
+  Flags m_flags; ///< Dump flags.
   lldb::ByteOrder
       m_byte_order;   ///< Byte order to use when encoding scalar types.
   unsigned m_indent_level = 0;     ///< Indention level.
diff --git a/lldb/include/lldb/Utility/StreamBuffer.h b/lldb/include/lldb/Utility/StreamBuffer.h
index d6edfff0129ca..b5dcd4242dda3 100644
--- a/lldb/include/lldb/Utility/StreamBuffer.h
+++ b/lldb/include/lldb/Utility/StreamBuffer.h
@@ -18,10 +18,10 @@ namespace lldb_private {
 
 template <unsigned N> class StreamBuffer : public Stream {
 public:
-  StreamBuffer() : Stream(0, 4, lldb::eByteOrderBig), m_packet() {}
+  StreamBuffer() : Stream(0, lldb::eByteOrderBig), m_packet() {}
 
-  StreamBuffer(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order)
-      : Stream(flags, addr_size, byte_order), m_packet() {}
+  StreamBuffer(uint32_t flags, lldb::ByteOrder byte_order)
+      : Stream(flags, byte_order), m_packet() {}
 
   ~StreamBuffer() override = default;
 
diff --git a/lldb/include/lldb/Utility/StreamString.h b/lldb/include/lldb/Utility/StreamString.h
index 3287f328a1be3..1a6444fc29c24 100644
--- a/lldb/include/lldb/Utility/StreamString.h
+++ b/lldb/include/lldb/Utility/StreamString.h
@@ -26,7 +26,7 @@ class StreamString : public Stream {
 public:
   StreamString(bool colors = false);
 
-  StreamString(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order);
+  StreamString(uint32_t flags, lldb::ByteOrder byte_order);
 
   ~StreamString() override;
 
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index f8d9d027bdff0..3c7f03aa050f7 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1279,10 +1279,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
       return;
     }
 
-    StreamString buffer(
-        Stream::eBinary,
-        process->GetTarget().GetArchitecture().GetAddressByteSize(),
-        process->GetTarget().GetArchitecture().GetByteOrder());
+    StreamString buffer(Stream::eBinary, process->GetByteOrder());
 
     OptionValueUInt64 &byte_size_value = m_format_options.GetByteSizeValue();
     size_t item_byte_size = byte_size_value.GetCurrentValue();
@@ -1336,7 +1333,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
       return;
     } else if (item_byte_size == 0) {
       if (m_format_options.GetFormat() == eFormatPointer)
-        item_byte_size = buffer.GetAddressByteSize();
+        item_byte_size = process->GetAddressByteSize();
       else
         item_byte_size = 1;
     }
diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp
index db9dcea4e6a8d..f387d1194cd5d 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -535,10 +535,6 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
   void DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetTarget();
 
-    uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
-    result.GetOutputStream().SetAddressByteSize(addr_byte_size);
-    result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
     // Collect the list of modules to search.
     m_module_list.Clear();
     if (!m_options.modules.empty()) {
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 288655f79f442..7ed40bff3a985 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1911,10 +1911,6 @@ class CommandObjectTargetModulesDumpObjfile
   void DoExecute(Args &command, CommandReturnObject &result) override {
     Target &target = GetTarget();
 
-    uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
-    result.GetOutputStream().SetAddressByteSize(addr_byte_size);
-    result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
     size_t num_dumped = 0;
     if (command.GetArgumentCount() == 0) {
       // Dump all headers for all modules images
@@ -2016,10 +2012,6 @@ class CommandObjectTargetModulesDumpSymtab
         (m_options.m_prefer_mangled ? Mangled::ePreferMangled
                                     : Mangled::ePreferDemangled);
 
-    uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
-    result.GetOutputStream().SetAddressByteSize(addr_byte_size);
-    result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
     if (command.GetArgumentCount() == 0) {
       // Dump all sections for all modules images
       const ModuleList &module_list = target.GetImages();
@@ -2111,10 +2103,6 @@ class CommandObjectTargetModulesDumpSections
     Target &target = GetTarget();
     uint32_t num_dumped = 0;
 
-    uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
-    result.GetOutputStream().SetAddressByteSize(addr_byte_size);
-    result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
     if (command.GetArgumentCount() == 0) {
       // Dump all sections for all modules images
       const size_t num_modules = target.GetImages().GetSize();
@@ -2339,10 +2327,6 @@ class CommandObjectTargetModulesDumpSymfile
     Target &target = GetTarget();
     uint32_t num_dumped = 0;
 
-    uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
-    result.GetOutputStream().SetAddressByteSize(addr_byte_size);
-    result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
     if (command.GetArgumentCount() == 0) {
       // Dump all sections for all modules images
       const ModuleList &target_modules = target.GetImages();
@@ -2422,10 +2406,6 @@ class CommandObjectTargetModulesDumpLineTable
     Target *target = m_exe_ctx.GetTargetPtr();
     uint32_t total_num_dumped = 0;
 
-    uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
-    result.GetOutputStream().SetAddressByteSize(addr_byte_size);
-    result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
     if (command.GetArgumentCount() == 0) {
       result.AppendError("file option must be specified");
       return;
@@ -2569,10 +2549,6 @@ class CommandObjectTargetModulesDumpSeparateDebugInfoFiles
     Target &target = GetTarget();
     uint32_t num_dumped = 0;
 
-    uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
-    result.GetOutputStream().SetAddressByteSize(addr_byte_size);
-    result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
     StructuredData::Array separate_debug_info_lists_by_module;
     if (command.GetArgumentCount() == 0) {
       // Dump all sections for all modules images
@@ -3207,9 +3183,6 @@ class CommandObjectTargetModulesList : public CommandObjectParsed {
     // "locker" object which might lock its contents below (through the
     // "module_list_ptr" variable).
     ModuleList module_list;
-    uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
-    result.GetOutputStream().SetAddressByteSize(addr_byte_size);
-    result.GetErrorStream().SetAddressByteSize(addr_byte_size);
     // Dump all sections for all modules images
     Stream &strm = result.GetOutputStream();
 
@@ -4099,9 +4072,6 @@ class CommandObjectTargetModulesLookup : public CommandObjectParsed {
     bool syntax_error = false;
     uint32_t i;
     uint32_t num_successful_lookups = 0;
-    uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize();
-    result.GetOutputStream().SetAddressByteSize(addr_byte_size);
-    result.GetErrorStream().SetAddressByteSize(addr_byte_size);
     // Dump all sections for all modules images
 
     if (command.GetArgumentCount() == 0) {
diff --git a/lldb/source/Core/DumpDataExtractor.cpp b/lldb/source/Core/DumpDataExtractor.cpp
index 1e794494ab35a..4e4e45b4f2f23 100644
--- a/lldb/source/Core/DumpDataExtractor.cpp
+++ b/lldb/source/Core/DumpDataExtractor.cpp
@@ -361,7 +361,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
 
   if (item_format == eFormatPointer) {
     if (item_byte_size != 4 && item_byte_size != 8)
-      item_byte_size = s->GetAddressByteSize();
+      item_byte_size = DE.GetAddressByteSize();
   }
 
   offset_t offset = start_offset;
diff --git a/lldb/source/Core/EmulateInstruction.cpp b/lldb/source/Core/EmulateInstruction.cpp
index 79ada4eef50a1..5f2c6372acb2a 100644
--- a/lldb/source/Core/EmulateInstruction.cpp
+++ b/lldb/source/Core/EmulateInstruction.cpp
@@ -198,7 +198,7 @@ uint64_t EmulateInstruction::ReadMemoryUnsigned(const Context &context,
 bool EmulateInstruction::WriteMemoryUnsigned(const Context &context,
                                              lldb::addr_t addr, uint64_t uval,
                                              size_t uval_byte_size) {
-  StreamString strm(Stream::eBinary, GetAddressByteSize(), GetByteOrder());
+  StreamString strm(Stream::eBinary, GetByteOrder());
   strm.PutMaxHex64(uval, uval_byte_size);
 
   size_t bytes_written = m_write_mem_callback(
diff --git a/lldb/source/Core/StreamAsynchronousIO.cpp b/lldb/source/Core/StreamAsynchronousIO.cpp
index dbd56a69675b4..561e275a9a81c 100644
--- a/lldb/source/Core/StreamAsynchronousIO.cpp
+++ b/lldb/source/Core/StreamAsynchronousIO.cpp
@@ -16,7 +16,7 @@ using namespace lldb_private;
 
 StreamAsynchronousIO::StreamAsynchronousIO(
     Debugger &debugger, StreamAsynchronousIO::ForSTDOUT for_stdout)
-    : Stream(0, 4, eByteOrderBig, debugger.GetUseColor()), m_debugger(debugger),
+    : Stream(0, eByteOrderBig, debugger.GetUseColor()), m_debugger(debugger),
       m_data(), m_for_stdout(for_stdout) {}
 
 StreamAsynchronousIO::~StreamAsynchronousIO() {
diff --git a/lldb/source/Host/common/StreamFile.cpp b/lldb/source/Host/common/StreamFile.cpp
index 131412d81983b..4dcc1ce5a77f9 100644
--- a/lldb/source/Host/common/StreamFile.cpp
+++ b/lldb/source/Host/common/StreamFile.cpp
@@ -16,8 +16,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
-StreamFile::StreamFile(uint32_t flags, uint32_t addr_size, ByteOrder byte_order)
-    : Stream(flags, addr_size, byte_order) {
+StreamFile::StreamFile(uint32_t flags, ByteOrder byte_order)
+    : Stream(flags, byte_order) {
   m_file_sp = std::make_shared<File>();
 }
 
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index d8b017b492b1b..7d663c83f6eca 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6406,7 +6406,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
           segment_load_commands.push_back(segment);
         }
 
-        StreamString buffer(Stream::eBinary, addr_byte_size, byte_order);
+        StreamString buffer(Stream::eBinary, byte_order);
 
         llvm::MachO::mach_header_64 mach_header;
         mach_header.magic = addr_byte_size == 8 ? MH_MAGIC_64 : MH_MAGIC;
@@ -6426,7 +6426,6 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
         std::vector<StreamString> LC_THREAD_datas(num_threads);
         for (auto &LC_THREAD_data : LC_THREAD_datas) {
           LC_THREAD_data.GetFlags().Set(Stream::eBinary);
-          LC_THREAD_data.SetAddressByteSize(addr_byte_size);
           LC_THREAD_data.SetByteOrder(byte_order);
         }
         for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
@@ -6511,7 +6510,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
         // Add "addrable bits" LC_NOTE when an address mask is available
         if (address_mask != LLDB_INVALID_ADDRESS_MASK) {
           std::unique_ptr<LCNoteEntry> addrable_bits_lcnote_up(
-              new LCNoteEntry(addr_byte_size, byte_order));
+              new LCNoteEntry(byte_order));
           addrable_bits_lcnote_up->name = "addrable bits";
           addrable_bits_lcnote_up->payload_file_offset = file_offset;
           int bits = std::bitset<64>(~address_mask).count();
@@ -6529,7 +6528,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
 
         // Add "process metadata" LC_NOTE
         std::unique_ptr<LCNoteEntry> thread_extrainfo_lcnote_up(
-            new LCNoteEntry(addr_byte_size, byte_order));
+            new LCNoteEntry(byte_order));
         thread_extrainfo_lcnote_up->name = "process metadata";
         thread_extrainfo_lcnote_up->payload_file_offset = file_offset;
 
@@ -6556,7 +6555,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
 
         // Add "all image infos" LC_NOTE
         std::unique_ptr<LCNoteEntry> all_image_infos_lcnote_up(
-            new LCNoteEntry(addr_byte_size, byte_order));
+            new LCNoteEntry(byte_order));
         all_image_infos_lcnote_up->name = "all image infos";
         all_image_infos_lcnote_up->payload_file_offset = file_offset;
         file_offset = CreateAllImageInfosPayload(
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
index da12158ade3ba..4a0b9041b2f87 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -247,8 +247,8 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
   };
 
   struct LCNoteEntry {
-    LCNoteEntry(uint32_t addr_byte_size, lldb::ByteOrder byte_order)
-        : payload(lldb_private::Stream::eBinary, addr_byte_size, byte_order) {}
+    explicit LCNoteEntry(lldb::ByteOrder byte_order)
+        : payload(lldb_private::Stream::eBinary, byte_order) {}
 
     std::string name;
     lldb::addr_t payload_file_offset = 0;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 781faffdc0f74..80a9954ea9e3b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -100,7 +100,7 @@ size_t GDBRemoteCommunication::SendNack() {
 
 GDBRemoteCommunication::PacketResult
 GDBRemoteCommunication::SendPacketNoLock(llvm::StringRef payload) {
-  StreamString packet(0, 4, eByteOrderBig);
+  StreamString packet(0, eByteOrderBig);
   packet.PutChar('$');
   packet.Write(payload.data(), payload.size());
   packet.PutChar('#');
@@ -119,7 +119,7 @@ GDBRemoteCommunication::SendNotificationPacketNoLock(
   // If there are no notification in the queue, send the notification
   // packet.
   if (queue.empty()) {
-    StreamString packet(0, 4, eByteOrderBig);
+    StreamString packet(0, eByteOrderBig);
     packet.PutChar('%');
     packet.Write(notify_type.data(), notify_type.size());
     packet.PutChar(':');
diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
index 39f21250649d8..7aee41e8073f6 100644
--- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
+++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
@@ -564,8 +564,7 @@ ResolveRegisterOrRA(const llvm::Triple &triple,
 
 llvm::ArrayRef<uint8_t> SymbolFileBreakpad::SaveAsDWARF(postfix::Node &node) {
   ArchSpec arch = m_objfile_sp->GetArchitecture();
-  StreamString dwarf(Stream::eBinary, arch.GetAddressByteSize(),
-                     arch.GetByteOrder());
+  StreamString dwarf(Stream::eBinary, arch.GetByteOrder());
   ToDWARF(node, dwarf);
   uint8_t *saved = m_allocator.Allocate<uint8_t>(dwarf.GetSize());
   std::memcpy(saved, dwarf.GetData(), dwarf.GetSize());
diff --git a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
index 09251e2f57e1c..07dcebeddc736 100644
--- a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
+++ b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
@@ -850,7 +850,7 @@ static DWARFExpression CreateDWARFExpression(ModuleSP module_sp,
   ByteOrder byte_order = architecture.GetByteOrder();
   uint32_t address_size = architecture.GetAddressByteSize();
 
-  StreamBuffer<32> stream(Stream::eBinary, address_size, byte_order);
+  StreamBuffer<32> stream(Stream::eBinary, byte_order);
   stream.PutHex8(llvm::dwarf::DW_OP_addr);
   stream.PutMaxHex64(symbol.GetFileAddress(), address_size, byte_order);
 
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp
index 0b7e2e31c1414..1019f825577e7 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp
@@ -118,7 +118,7 @@ static DWARFExpression MakeLocationExpressionInternal(lldb::ModuleSP module,
     return DWARFExpression();
 
   RegisterKind register_kind = eRegisterKindDWARF;
-  StreamBuffer<32> stream(Stream::eBinary, address_size, byte_order);
+  StreamBuffer<32> stream(Stream::eBinary, byte_order);
 
   if (!writer(stream, register_kind))
     return DWARFExpression();
@@ -245,8 +245,9 @@ DWARFExpression lldb_private::npdb::MakeGlobalLocationExpression(
         if (!section_ptr)
           return false;
 
+        const ArchSpec &arch = module->GetArchitecture();
         stream.PutMaxHex64(section_ptr->GetFileAddress() + offset,
-                           stream.GetAddressByteSize(), stream.GetByteOrder());
+                           arch.GetAddressByteSize(), arch.GetByteOrder());
 
         return true;
       });
diff --git a/lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp
index b53c2cb894690..69925d1d6d794 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp
@@ -80,7 +80,7 @@ DWARFExpression ConvertPDBLocationToDWARFExpression(
     return DWARFExpression();
 
   RegisterKind register_kind = eRegisterKindDWARF;
-  StreamBuffer<32> stream(Stream::eBinary, address_size, byte_order);
+  StreamBuffer<32> stream(Stream::eBinary, byte_order);
   switch (symbol.getLocationType()) {
   case PDB_LocType::Static:
   case PDB_LocType::TLS: {
diff --git a/lldb/source/Utility/GDBRemote.cpp b/lldb/source/Utility/GDBRemote.cpp
index 276b1276f4e6d..f987ebcd4f63e 100644
--- a/lldb/source/Utility/GDBRemote.cpp
+++ b/lldb/source/Utility/GDBRemote.cpp
@@ -19,9 +19,8 @@ using namespace llvm;
 
 StreamGDBRemote::StreamGDBRemote() : StreamString() {}
 
-StreamGDBRemote::StreamGDBRemote(uint32_t flags, uint32_t addr_size,
-                                 ByteOrder byte_order)
-    : StreamString(flags, addr_size, byte_order) {}
+StreamGDBRemote::StreamGDBRemote(uint32_t flags, ByteOrder byte_order)
+    : StreamString(flags, byte_order) {}
 
 StreamGDBRemote::~StreamGDBRemote() = default;
 
diff --git a/lldb/source/Utility/Stream.cpp b/lldb/source/Utility/Stream.cpp
index fbe7bdb6dd27c..c37fa1e6317a1 100644
--- a/lldb/source/Utility/Stream.cpp
+++ b/lldb/source/Utility/Stream.cpp
@@ -24,10 +24,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
-Stream::Stream(uint32_t flags, uint32_t addr_size, ByteOrder byte_order,
-               bool colors)
-    : m_flags(flags), m_addr_size(addr_size), m_byte_order(byte_order),
-      m_forwarder(*this, colors) {}
+Stream::Stream(uint32_t flags, ByteOrder byte_order, bool colors)
+    : m_flags(flags), m_byte_order(byte_order), m_forwarder(*this, colors) {}
 
 Stream::Stream(bool colors)
     : m_flags(0), m_byte_order(endian::InlHostByteOrder()),
@@ -216,12 +214,6 @@ Stream::IndentScope Stream::MakeIndentScope(unsigned indent_amount) {
   return indent_scope;
 }
 
-// Get the address size in bytes
-uint32_t Stream::GetAddressByteSize() const { return m_addr_size; }
-
-// Set the address size in bytes
-void Stream::SetAddressByteSize(uint32_t addr_size) { m_addr_size = addr_size; }
-
 // The flags get accessor
 Flags &Stream::GetFlags() { return m_flags; }
 
diff --git a/lldb/source/Utility/StreamString.cpp b/lldb/source/Utility/StreamString.cpp
index 0d35ccbdbbd0f..883790e0ce19c 100644
--- a/lldb/source/Utility/StreamString.cpp
+++ b/lldb/source/Utility/StreamString.cpp
@@ -11,11 +11,10 @@
 using namespace lldb;
 using namespace lldb_private;
 
-StreamString::StreamString(bool colors) : Stream(0, 4, eByteOrderBig, colors) {}
+StreamString::StreamString(bool colors) : Stream(0, eByteOrderBig, colors) {}
 
-StreamString::StreamString(uint32_t flags, uint32_t addr_size,
-                           ByteOrder byte_order)
-    : Stream(flags, addr_size, byte_order), m_packet() {}
+StreamString::StreamString(uint32_t flags, ByteOrder byte_order)
+    : Stream(flags, byte_order) {}
 
 StreamString::~StreamString() = default;
 

>From dbfee3d4a5603c5139c0dabf3702ed8bdff2e7a0 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Fri, 3 Apr 2026 21:10:48 +0300
Subject: [PATCH 2/3] Update unit tests

---
 lldb/unittests/Symbol/PostfixExpressionTest.cpp               | 2 +-
 .../NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lldb/unittests/Symbol/PostfixExpressionTest.cpp b/lldb/unittests/Symbol/PostfixExpressionTest.cpp
index f60b5d2c389ed..2f941efe9e672 100644
--- a/lldb/unittests/Symbol/PostfixExpressionTest.cpp
+++ b/lldb/unittests/Symbol/PostfixExpressionTest.cpp
@@ -151,7 +151,7 @@ static std::string ParseAndGenerateDWARF(llvm::StringRef expr) {
   }
 
   const size_t addr_size = 4;
-  StreamString dwarf(Stream::eBinary, addr_size, lldb::eByteOrderLittle);
+  StreamString dwarf(Stream::eBinary, lldb::eByteOrderLittle);
   ToDWARF(*ast, dwarf);
 
   // print dwarf expression to comparable textual representation
diff --git a/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp b/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp
index c60688ef22939..c4c196a3790eb 100644
--- a/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp
+++ b/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp
@@ -30,7 +30,7 @@ CheckValidProgramTranslation(llvm::StringRef fpo_program,
                              llvm::StringRef target_register_name,
                              llvm::StringRef expected_dwarf_expression) {
   // program translation
-  StreamBuffer<32> stream(Stream::eBinary, 4, eByteOrderLittle);
+  StreamBuffer<32> stream(Stream::eBinary, eByteOrderLittle);
   ASSERT_TRUE(TranslateFPOProgramToDWARFExpression(
       fpo_program, target_register_name, llvm::Triple::x86, stream));
 
@@ -79,7 +79,7 @@ CheckInvalidProgramTranslation(llvm::StringRef fpo_program,
   uint32_t address_size = arch_spec.GetAddressByteSize();
 
   // program translation
-  StreamBuffer<32> stream(Stream::eBinary, address_size, byte_order);
+  StreamBuffer<32> stream(Stream::eBinary, byte_order);
   EXPECT_FALSE(TranslateFPOProgramToDWARFExpression(
       fpo_program, target_register_name, arch_type, stream));
   EXPECT_EQ((size_t)0, stream.GetSize());

>From 4dc6311eda63fdd0cc6f49896c51d0dfb8e140e8 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Fri, 3 Apr 2026 21:19:12 +0300
Subject: [PATCH 3/3] Remove unused variable that caused warning

---
 .../SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp b/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp
index c4c196a3790eb..eb618b74fb136 100644
--- a/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp
+++ b/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp
@@ -76,7 +76,6 @@ CheckInvalidProgramTranslation(llvm::StringRef fpo_program,
   ArchSpec arch_spec("i686-pc-windows");
   llvm::Triple::ArchType arch_type = arch_spec.GetMachine();
   ByteOrder byte_order = arch_spec.GetByteOrder();
-  uint32_t address_size = arch_spec.GetAddressByteSize();
 
   // program translation
   StreamBuffer<32> stream(Stream::eBinary, byte_order);



More information about the lldb-commits mailing list