[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Mon May 20 15:35:08 PDT 2024
================
@@ -0,0 +1,65 @@
+//===-- SBAddressRange.h ----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_API_SBADDRESSRANGE_H
+#define LLDB_API_SBADDRESSRANGE_H
+
+#include "lldb/API/SBDefines.h"
+
+namespace lldb {
+
+class LLDB_API SBAddressRange {
+public:
+ SBAddressRange();
+
+ SBAddressRange(const lldb::SBAddressRange &rhs);
+
+ SBAddressRange(lldb::SBAddress addr, lldb::addr_t byte_size);
+
+ ~SBAddressRange();
+
+ const lldb::SBAddressRange &operator=(const lldb::SBAddressRange &rhs);
+
+ void Clear();
+
+ /// Check the address range refers to a valid base address and has a byte
+ /// size greater than zero.
+ ///
+ /// \return
+ /// True if the address range is valid, false otherwise.
+ bool IsValid() const;
+
+ /// Get the base address of the range.
+ ///
+ /// \return
+ /// Base address object.
+ lldb::SBAddress GetBaseAddress() const;
+
+ /// Get the byte size of this range.
+ ///
+ /// \return
+ /// The size in bytes of this address range.
+ lldb::addr_t GetByteSize() const;
+
+ bool operator==(const SBAddressRange &rhs);
+
+ bool operator!=(const SBAddressRange &rhs);
+
+ bool GetDescription(lldb::SBStream &description, SBTarget *target);
----------------
clayborg wrote:
We don't pass pointers to SB objects in our current API. Can this be changed from `SBTarget *target` to `SBTarget &target`? Or will that make the `lldb.target` stuff not work in the python layer?
Either way this should be changed to use `SBTarget &`. If we need to work around this in the python extension code, then we might need to versions of this function: one with a `SBTarget &target` and one without. Then the python can do a:
```
def __repr__(self):
import lldb
stream = lldb.SBStream()
if lldb.target is None:
self.GetDescription(stream)
else:
self.GetDescription(stream, lldb.target)
return stream.GetData()
```
We might want to clarify why we have the target parameter here in headerdoc like:
```
/// Dump the contents of this SBAddressRange object.
///
/// \param[in] strm
/// The stream to dump the contents to.
///
/// \param[in] target
/// The target to use to resolve the SBAddress base address. If an invalid target
/// is passed in, or if the base address isn't loaded in the target yet the address
/// range will be shown as the module name followed by a file address range:
/// a.out[0x1000-0x02000). If a valid target is supplied and the section is loaded
/// then the address range will be dumped as a load address range: [0x101000-0x102000)
///
/// \return
/// <describe return value here>.
```
Where `...` above will be an explanation of how the address is displayed without being able to resolve the base address `a.out[0x1000-0x2000)`)
https://github.com/llvm/llvm-project/pull/92014
More information about the lldb-commits
mailing list