[all-commits] [llvm/llvm-project] 529a3d: [NFC] Improve FileSpec internal APIs and usage in ...

Greg Clayton via All-commits all-commits at lists.llvm.org
Thu Jul 28 13:28:41 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 529a3d87a799a2cba29bc1d0f426a00d5bb4c88f
      https://github.com/llvm/llvm-project/commit/529a3d87a799a2cba29bc1d0f426a00d5bb4c88f
  Author: Greg Clayton <gclayton at fb.com>
  Date:   2022-07-28 (Thu, 28 Jul 2022)

  Changed paths:
    M lldb/include/lldb/Utility/FileSpec.h
    M lldb/source/API/SBFileSpec.cpp
    M lldb/source/API/SBLaunchInfo.cpp
    M lldb/source/API/SBPlatform.cpp
    M lldb/source/API/SBReproducer.cpp
    M lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
    M lldb/source/Commands/CommandObjectLog.cpp
    M lldb/source/Commands/CommandObjectTarget.cpp
    M lldb/source/Core/Debugger.cpp
    M lldb/source/Core/IOHandlerCursesGUI.cpp
    M lldb/source/Expression/FunctionCaller.cpp
    M lldb/source/Expression/REPL.cpp
    M lldb/source/Host/common/FileAction.cpp
    M lldb/source/Host/common/FileSystem.cpp
    M lldb/source/Host/common/HostInfoBase.cpp
    M lldb/source/Host/linux/HostInfoLinux.cpp
    M lldb/source/Host/macosx/objcxx/Host.mm
    M lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
    M lldb/source/Host/posix/FileSystemPosix.cpp
    M lldb/source/Host/posix/HostInfoPosix.cpp
    M lldb/source/Host/windows/FileSystem.cpp
    M lldb/source/Host/windows/ProcessLauncherWindows.cpp
    M lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
    M lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
    M lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
    M lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
    M lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
    M lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
    M lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
    M lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
    M lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    M lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
    M lldb/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
    M lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
    M lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    M lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
    M lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
    M lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
    M lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
    M lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
    M lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
    M lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
    M lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    M lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    M lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
    M lldb/source/Symbol/Symbol.cpp
    M lldb/source/Symbol/SymbolContext.cpp
    M lldb/source/Target/Platform.cpp
    M lldb/source/Target/Target.cpp
    M lldb/source/Target/TargetList.cpp
    M lldb/source/Target/Trace.cpp
    M lldb/source/Utility/FileSpec.cpp
    M lldb/tools/lldb-server/lldb-platform.cpp
    M lldb/tools/lldb-test/lldb-test.cpp
    M lldb/unittests/Target/FindFileTest.cpp
    M lldb/unittests/Target/ModuleCacheTest.cpp
    M lldb/unittests/Utility/FileSpecTest.cpp

  Log Message:
  -----------
  [NFC] Improve FileSpec internal APIs and usage in preparation for adding caching of resolved/absolute.

Resubmission of https://reviews.llvm.org/D130309 with the 2 patches that fixed the linux buildbot, and new windows fixes.

The FileSpec APIs allow users to modify instance variables directly by getting a non const reference to the directory and filename instance variables. This makes it impossible to control all of the times the FileSpec object is modified so we can clear cached member variables like m_resolved and with an upcoming patch caching if the file is relative or absolute. This patch modifies the APIs of FileSpec so no one can modify the directory or filename instance variables directly by adding set accessors and by removing the get accessors that are non const.

Many clients were using FileSpec::GetCString(...) which returned a unique C string from a ConstString'ified version of the result of GetPath() which returned a std::string. This caused many locations to use this convenient function incorrectly and could cause many strings to be added to the constant string pool that didn't need to. Most clients were converted to using FileSpec::GetPath().c_str() when possible. Other clients were modified to use the newly renamed version of this function which returns an actualy ConstString:

ConstString FileSpec::GetPathAsConstString(bool denormalize = true) const;

This avoids the issue where people were getting an already uniqued "const char *" that came from a ConstString only to put the "const char *" back into a "ConstString" object. By returning the ConstString instead of a "const char *" clients can be more efficient with the result.

The patch:
- Removes the non const GetDirectory() and GetFilename() get accessors
- Adds set accessors to replace the above functions: SetDirectory() and SetFilename().
- Adds ClearDirectory() and ClearFilename() to replace usage of the FileSpec::GetDirectory().Clear()/FileSpec::GetFilename().Clear() call sites
- Fixed all incorrect usage of FileSpec::GetCString() to use FileSpec::GetPath().c_str() where appropriate, and updated other call sites that wanted a ConstString to use the newly returned ConstString appropriately and efficiently.

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




More information about the All-commits mailing list