llvm-project/lldb/tools
Greg Clayton 529a3d87a7 [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
2022-07-28 13:28:26 -07:00
..
argdumper [lldb] Remove a few unused .exports files 2021-08-05 22:17:00 +02:00
compact-unwind Don't re-define constants that are now in compact_unwind_encoding.h. 2021-09-09 17:01:43 -07:00
darwin-debug [lldb][NFC] Use C++ versions of the deprecated C standard library headers 2021-05-26 12:46:12 +02:00
darwin-threads
debugserver jGetLoadedDynamicLibrariesInfos can inspect machos not yet loaded 2022-07-14 00:56:14 -07:00
driver [lldb] Fix building for mingw after changes to sigtstp_handler 2022-03-26 22:32:53 +02:00
intel-features [lldb][tests] Automatically call compute_mydir (NFC) 2022-06-17 14:34:49 -07:00
lldb-fuzzer Revert "[lldb/Fuzzer] Add fuzzer for expression evaluator" 2022-07-22 15:24:40 -07:00
lldb-instr [lldb] Revive lldb-instr 2022-01-20 18:06:14 -08:00
lldb-server [NFC] Improve FileSpec internal APIs and usage in preparation for adding caching of resolved/absolute. 2022-07-28 13:28:26 -07:00
lldb-test [NFC] Improve FileSpec internal APIs and usage in preparation for adding caching of resolved/absolute. 2022-07-28 13:28:26 -07:00
lldb-vscode Don't use Optional::hasValue (NFC) 2022-06-20 20:26:05 -07:00
CMakeLists.txt [lldb] Add a fuzzer for target creation 2022-03-25 09:34:00 -07:00