[Lldb-commits] [lldb] b14c37a - [lldb/Platform] Return a	std::string from GetSDKPath
    Jonas Devlieghere via lldb-commits 
    lldb-commits at lists.llvm.org
       
    Tue Apr 28 19:22:07 PDT 2020
    
    
  
Author: Jonas Devlieghere
Date: 2020-04-28T19:21:58-07:00
New Revision: b14c37a29a5455853419f5fe0605f6023c51de89
URL: https://github.com/llvm/llvm-project/commit/b14c37a29a5455853419f5fe0605f6023c51de89
DIFF: https://github.com/llvm/llvm-project/commit/b14c37a29a5455853419f5fe0605f6023c51de89.diff
LOG: [lldb/Platform] Return a std::string from GetSDKPath
Nothing guarantees that the objects in the StringMap remains at the same
address when the StringMap grows. Therefore we shouldn't return a
reference into the StringMap but return a copy of the string instead.
Added: 
    
Modified: 
    lldb/include/lldb/Target/Platform.h
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Removed: 
    
################################################################################
diff  --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index 872e5301d984..640261033c4b 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -435,7 +435,7 @@ class Platform : public PluginInterface {
     return lldb_private::ConstString();
   }
 
-  virtual llvm::StringRef GetSDKPath(lldb_private::XcodeSDK sdk) {
+  virtual std::string GetSDKPath(lldb_private::XcodeSDK sdk) {
     return {};
   }
 
diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 0777c78aa22d..5252d37a01c5 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1761,11 +1761,11 @@ PlatformDarwin::FindXcodeContentsDirectoryInPath(llvm::StringRef path) {
   return {};
 }
 
-llvm::StringRef PlatformDarwin::GetSDKPath(XcodeSDK sdk) {
+std::string PlatformDarwin::GetSDKPath(XcodeSDK sdk) {
   std::string &path = m_sdk_path[sdk.GetString()];
-  if (path.empty())
-    path = HostInfo::GetXcodeSDK(sdk);
-  return path;
+  if (!path.empty())
+    return path;
+  return HostInfo::GetXcodeSDK(sdk);
 }
 
 FileSpec PlatformDarwin::GetXcodeContentsDirectory() {
diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index 7d205be59689..d3b4181aafa0 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -89,7 +89,7 @@ class PlatformDarwin : public PlatformPOSIX {
   llvm::Expected<lldb_private::StructuredData::DictionarySP>
   FetchExtendedCrashInformation(lldb_private::Process &process) override;
 
-  llvm::StringRef GetSDKPath(lldb_private::XcodeSDK sdk) override;
+  std::string GetSDKPath(lldb_private::XcodeSDK sdk) override;
 
   static lldb_private::FileSpec GetXcodeContentsDirectory();
   static lldb_private::FileSpec GetXcodeDeveloperDirectory();
        
    
    
More information about the lldb-commits
mailing list