[trace] Use vector instead of ArrayRef when reading data
authorWalter Erquinigo <wallace@fb.com>
Mon, 21 Mar 2022 22:46:19 +0000 (15:46 -0700)
committerWalter Erquinigo <wallace@fb.com>
Mon, 21 Mar 2022 23:03:37 +0000 (16:03 -0700)
I incorrectly returned an ArrayRef when the underlying object didn't own
the data. Instead, returning a vector<uint8_t> is what we should do.

This fixes an issue when trying to access an intel-pt trace buffer
larger than 16 MB.

repro
```
go to a breakpoint
thread trace start -s 16777216
n
thread trace dump instructions # this doesn't fail anymore
```

Differential Revision: https://reviews.llvm.org/D122192

lldb/include/lldb/Target/Trace.h
lldb/source/Target/Trace.cpp

index 643b761..c4ca192 100644 (file)
@@ -253,7 +253,7 @@ protected:
   /// \return
   ///     A vector of bytes with the requested data, or an \a llvm::Error in
   ///     case of failures.
-  llvm::Expected<llvm::ArrayRef<uint8_t>>
+  llvm::Expected<std::vector<uint8_t>>
   GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind);
 
   /// Get binary data of the current process given a data identifier.
@@ -264,7 +264,7 @@ protected:
   /// \return
   ///     A vector of bytes with the requested data, or an \a llvm::Error in
   ///     case of failures.
-  llvm::Expected<llvm::ArrayRef<uint8_t>>
+  llvm::Expected<std::vector<uint8_t>>
   GetLiveProcessBinaryData(llvm::StringRef kind);
 
   /// Get the size of the data returned by \a GetLiveThreadBinaryData
index 38b3a7c..7f9ae54 100644 (file)
@@ -142,7 +142,7 @@ Optional<size_t> Trace::GetLiveProcessBinaryDataSize(llvm::StringRef kind) {
   return data_it->second;
 }
 
-Expected<ArrayRef<uint8_t>>
+Expected<std::vector<uint8_t>>
 Trace::GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind) {
   if (!m_live_process)
     return createStringError(inconvertibleErrorCode(),
@@ -160,7 +160,7 @@ Trace::GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind) {
   return m_live_process->TraceGetBinaryData(request);
 }
 
-Expected<ArrayRef<uint8_t>>
+Expected<std::vector<uint8_t>>
 Trace::GetLiveProcessBinaryData(llvm::StringRef kind) {
   if (!m_live_process)
     return createStringError(inconvertibleErrorCode(),