llvm-project/lldb/unittests
Pavel Labath 532290e69f [lldb] s/FileSpec::Equal/FileSpec::Match
Summary:
The FileSpec class is often used as a sort of a pattern -- one specifies
a bare file name to search, and we check if in matches the full file
name of an existing module (for example).

These comparisons used FileSpec::Equal, which had some support for it
(via the full=false argument), but it was not a good fit for this job.

For one, it did a symmetric comparison, which makes sense for a function
called "equal", but not for typical searches (when searching for
"/foo/bar.so", we don't want to find a module whose name is just
"bar.so"). This resulted in patterns like:
    if (FileSpec::Equal(pattern, file, pattern.GetDirectory()))
which would request a "full" match only if the pattern really contained
a directory. This worked, but the intended behavior was very unobvious.

On top of that, a lot of the code wanted to handle the case of an
"empty" pattern, and treat it as matching everything. This resulted in
conditions like:
    if (pattern && !FileSpec::Equal(pattern, file, pattern.GetDirectory())
which are nearly impossible to decipher.

This patch introduces a FileSpec::Match function, which does exactly
what most of FileSpec::Equal callers want, an asymmetric match between a
"pattern" FileSpec and a an actual FileSpec. Empty paterns match
everything, filename-only patterns match only the filename component.

I've tried to update all callers of FileSpec::Equal to use a simpler
interface. Those that hardcoded full=true have been changed to use
operator==. Those passing full=pattern.GetDirectory() have been changed
to use FileSpec::Match.

There was also a handful of places which hardcoded full=false. I've
changed these to use FileSpec::Match too. This is a slight change in
semantics, but it does not look like that was ever intended, and it was
more likely a result of a misunderstanding of the "proper" way to use
FileSpec::Equal.

[In an ideal world a "FileSpec" and a "FileSpec pattern" would be two
different types, but given how widespread FileSpec is, it is unlikely
we'll get there in one go. This at least provides a good starting point
by centralizing all matching behavior.]

Reviewers: teemperor, JDevlieghere, jdoerfert

Subscribers: emaste, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70851
2019-12-04 10:42:32 +01:00
..
Breakpoint Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Core [LLDB] Fix handling for the clang name mangling extension for block invocations 2019-11-06 14:20:00 -08:00
Disassembler When disassembling Aarch64 target and vendor Apple, set the cpu to 2019-03-07 03:16:45 +00:00
Editline [lldb][NFC] Allow for-ranges on StringList 2019-08-16 14:27:35 +00:00
Expression whitespace cleanup 2019-10-21 22:48:27 +00:00
Host [lldb] [unittest] Reenable MainLoopTest.DetectsEOF on NetBSD 2019-11-18 22:36:01 +01:00
Interpreter [lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values 2019-08-22 07:41:23 +00:00
Language [lldb] Fix that trailing backslashes in source lines break the Clang highlighter 2019-11-14 11:11:20 +01:00
ObjectFile [Windows] Use information from the PE32 exceptions directory to construct unwind plans 2019-10-11 09:03:29 +00:00
Platform Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Process [LLDB] Implement pure virtual method in MockConnection 2019-11-13 15:37:57 -08:00
ScriptInterpreter [LLDB] Disable MSVC warning C4190: 'LLDBSwigPythonBreakpointCallbackFunction' has C-linkage specified, but returns UDT 'llvm::Expected<bool>' which is incompatible with C 2019-12-03 09:53:26 -05:00
Signals Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Symbol [lldb][NFC] Remove ClangASTContext::GetBuiltinTypeForEncodingAndBitSize overload 2019-11-29 13:57:02 +01:00
SymbolFile [lldb] Fix windows build for 38870af 2019-11-29 12:48:25 +01:00
Target Modernize the rest of the Find.* API (NFC) 2019-10-17 19:56:40 +00:00
TestingSupport [lldb] - Update unit tests after lib/ObjectYAML change. 2019-09-13 16:00:28 +00:00
UnwindAssembly Fix the unwinding plan augmentation from x86 assembly 2019-10-10 13:23:09 +00:00
Utility [lldb] s/FileSpec::Equal/FileSpec::Match 2019-12-04 10:42:32 +01:00
debugserver [lldb] Fix JSON parser to allow empty arrays 2019-11-18 15:12:55 +01:00
tools [lldb] [unittest] Skip TestStopReplyContainsThreadPcs on NetBSD 2019-11-18 22:36:02 +01:00
CMakeLists.txt [CMake] Track test dependencies with add_lldb_test_dependency 2019-10-08 00:21:34 +00:00
gtest_common.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00