[Lldb-commits] [lldb] 71e2788 - [lldb] Fix DataExtractor symbol conflict

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 3 08:48:39 PST 2022


Author: Emre Kultursay
Date: 2022-03-03T08:48:16-08:00
New Revision: 71e278805a7232826f27be081d036ca3f1c85d65

URL: https://github.com/llvm/llvm-project/commit/71e278805a7232826f27be081d036ca3f1c85d65
DIFF: https://github.com/llvm/llvm-project/commit/71e278805a7232826f27be081d036ca3f1c85d65.diff

LOG: [lldb] Fix DataExtractor symbol conflict

There are two DataExtractors in scope: one from the llvm namespace and
one from the lldb_private namespace. Some Microsoft Visual C++ compilers
(I tested with MSVC 14.23 specifically) cannot handle this situation,
and generate ambiguous symbol errors. This change fixes this compile
error.

Differential revision: https://reviews.llvm.org/D120718

Added: 
    

Modified: 
    lldb/source/Core/DataFileCache.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Core/DataFileCache.cpp b/lldb/source/Core/DataFileCache.cpp
index 84f787e6184e1..f9b632f34e417 100644
--- a/lldb/source/Core/DataFileCache.cpp
+++ b/lldb/source/Core/DataFileCache.cpp
@@ -17,17 +17,16 @@
 #include "llvm/Support/CachePruning.h"
 #include "llvm/Support/MemoryBuffer.h"
 
-using namespace llvm;
 using namespace lldb_private;
 
-DataFileCache::DataFileCache(StringRef path) {
+DataFileCache::DataFileCache(llvm::StringRef path) {
   m_cache_dir.SetPath(path);
 
   // Prune the cache based off of the LLDB settings each time we create a cache
   // object.
   ModuleListProperties &properties =
       ModuleList::GetGlobalModuleListProperties();
-  CachePruningPolicy policy;
+  llvm::CachePruningPolicy policy;
   // Only scan once an hour. If we have lots of debug sessions we don't want
   // to scan this directory too often. A timestamp file is written to the
   // directory to ensure 
diff erent processes don't scan the directory too often.
@@ -52,7 +51,7 @@ DataFileCache::DataFileCache(StringRef path) {
     if (m_take_ownership)
       m_mem_buff_up = std::move(m);
   };
-  Expected<FileCache> cache_or_err =
+  llvm::Expected<llvm::FileCache> cache_or_err =
       llvm::localCache("LLDBModuleCache", "lldb-module", path, add_buffer);
   if (cache_or_err)
     m_cache_callback = std::move(*cache_or_err);
@@ -64,7 +63,7 @@ DataFileCache::DataFileCache(StringRef path) {
 }
 
 std::unique_ptr<llvm::MemoryBuffer>
-DataFileCache::GetCachedData(StringRef key) {
+DataFileCache::GetCachedData(llvm::StringRef key) {
   std::lock_guard<std::mutex> guard(m_mutex);
 
   const unsigned task = 1;
@@ -73,13 +72,14 @@ DataFileCache::GetCachedData(StringRef key) {
   // call the "add_buffer" lambda function from the constructor which will in
   // turn take ownership of the member buffer that is passed to the callback and
   // put it into a member variable.
-  Expected<AddStreamFn> add_stream_or_err = m_cache_callback(task, key);
+  llvm::Expected<llvm::AddStreamFn> add_stream_or_err =
+      m_cache_callback(task, key);
   m_take_ownership = false;
   // At this point we either already called the "add_buffer" lambda with
   // the data or we haven't. We can tell if we got the cached data by checking
   // the add_stream function pointer value below.
   if (add_stream_or_err) {
-    AddStreamFn &add_stream = *add_stream_or_err;
+    llvm::AddStreamFn &add_stream = *add_stream_or_err;
     // If the "add_stream" is nullptr, then the data was cached and we already
     // called the "add_buffer" lambda. If it is valid, then if we were to call
     // the add_stream function it would cause a cache file to get generated
@@ -97,18 +97,20 @@ DataFileCache::GetCachedData(StringRef key) {
   return std::unique_ptr<llvm::MemoryBuffer>();
 }
 
-bool DataFileCache::SetCachedData(StringRef key, llvm::ArrayRef<uint8_t> data) {
+bool DataFileCache::SetCachedData(llvm::StringRef key,
+                                  llvm::ArrayRef<uint8_t> data) {
   std::lock_guard<std::mutex> guard(m_mutex);
   const unsigned task = 2;
   // If we call this function and the data is cached, it will call the
   // add_buffer lambda function from the constructor which will ignore the
   // data.
-  Expected<AddStreamFn> add_stream_or_err = m_cache_callback(task, key);
+  llvm::Expected<llvm::AddStreamFn> add_stream_or_err =
+      m_cache_callback(task, key);
   // If we reach this code then we either already called the callback with
   // the data or we haven't. We can tell if we had the cached data by checking
   // the CacheAddStream function pointer value below.
   if (add_stream_or_err) {
-    AddStreamFn &add_stream = *add_stream_or_err;
+    llvm::AddStreamFn &add_stream = *add_stream_or_err;
     // If the "add_stream" is nullptr, then the data was cached. If it is
     // valid, then if we call the add_stream function with a task it will
     // cause the file to get generated, but we only want to check if the data
@@ -117,10 +119,10 @@ bool DataFileCache::SetCachedData(StringRef key, llvm::ArrayRef<uint8_t> data) {
     // provided, but we won't take ownership of the memory buffer as we just
     // want to write the data.
     if (add_stream) {
-      Expected<std::unique_ptr<CachedFileStream>> file_or_err =
+      llvm::Expected<std::unique_ptr<llvm::CachedFileStream>> file_or_err =
           add_stream(task);
       if (file_or_err) {
-        CachedFileStream *cfs = file_or_err->get();
+        llvm::CachedFileStream *cfs = file_or_err->get();
         cfs->OS->write((const char *)data.data(), data.size());
         return true;
       } else {
@@ -219,7 +221,7 @@ bool CacheSignature::Encode(DataEncoder &encoder) {
   return true;
 }
 
-bool CacheSignature::Decode(const DataExtractor &data,
+bool CacheSignature::Decode(const lldb_private::DataExtractor &data,
                             lldb::offset_t *offset_ptr) {
   Clear();
   while (uint8_t sig_encoding = data.GetU8(offset_ptr)) {
@@ -284,7 +286,7 @@ bool ConstStringTable::Encode(DataEncoder &encoder) {
   return true;
 }
 
-bool StringTableReader::Decode(const DataExtractor &data,
+bool StringTableReader::Decode(const lldb_private::DataExtractor &data,
                                lldb::offset_t *offset_ptr) {
   llvm::StringRef identifier((const char *)data.GetData(offset_ptr, 4), 4);
   if (identifier != kStringTableIdentifier)
@@ -296,12 +298,12 @@ bool StringTableReader::Decode(const DataExtractor &data,
   const char *bytes = (const char *)data.GetData(offset_ptr, length);
   if (bytes == nullptr)
     return false;
-  m_data = StringRef(bytes, length);
+  m_data = llvm::StringRef(bytes, length);
   return true;
 }
 
-StringRef StringTableReader::Get(uint32_t offset) const {
+llvm::StringRef StringTableReader::Get(uint32_t offset) const {
   if (offset >= m_data.size())
-    return StringRef();
-  return StringRef(m_data.data() + offset);
+    return llvm::StringRef();
+  return llvm::StringRef(m_data.data() + offset);
 }


        


More information about the lldb-commits mailing list