Skip to content

Commit

Permalink
[lldb] Fix DataExtractor symbol conflict
Browse files Browse the repository at this point in the history
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
  • Loading branch information
emrekultursay authored and JDevlieghere committed Mar 3, 2022
1 parent 139215a commit 71e2788
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lldb/source/Core/DataFileCache.cpp
Expand Up @@ -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 different processes don't scan the directory too often.
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}

0 comments on commit 71e2788

Please sign in to comment.