[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 20:01:26 PDT 2020


Actually the statement in the commit message is incorrect, it looks like
StringMap does guarantee both key and value to be stable. The patch is
still correct though, because GetXcodeSDK does return a std::string, so we
were returning a reference to a temporary.

On Tue, Apr 28, 2020 at 7:22 PM Jonas Devlieghere via lldb-commits <
lldb-commits at lists.llvm.org> wrote:

>
> 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();
>
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200428/16efc050/attachment.html>


More information about the lldb-commits mailing list