llvm-capstone/lldb
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
..
cmake Revert "[CMake] Re-enable -Wno-gnu-anonymous-struct & -Wno-nested-anon-types." 2019-11-18 17:00:35 -08:00
docs [Docs] Generate the LLDB man page with Sphinx 2019-11-21 10:04:11 -08:00
examples [Examples] Move structured-data unpacking out of the loop. (NFC) 2019-11-22 15:43:39 -08:00
include/lldb [lldb] s/FileSpec::Equal/FileSpec::Match 2019-12-04 10:42:32 +01:00
packages/Python/lldbsuite Revert "[LiveDebugValues] Introduce entry values of unmodified params" 2019-12-03 13:13:27 +01:00
resources
scripts [LLDB][Python] remove ArgInfo::count 2019-11-04 12:48:49 -08:00
source [lldb] s/FileSpec::Equal/FileSpec::Match 2019-12-04 10:42:32 +01:00
test [lldb/Reproducer] Add version check 2019-12-03 07:54:42 -08:00
third_party/Python/module Increase timeout in pexpect to lower chances of tests failing under ASAN. 2019-10-10 16:16:49 +00:00
tools [lldb/Reproducer] Add version check 2019-12-03 07:54:42 -08:00
unittests [lldb] s/FileSpec::Equal/FileSpec::Match 2019-12-04 10:42:32 +01:00
utils [LLDB] Fix inline variable only used in assertion. (NFC) 2019-10-25 15:47:17 -07:00
.arcconfig
.clang-format
.gitignore
CMakeLists.txt [lldb/CMake] Add in_call_stack to the utilities package 2019-12-02 13:03:24 -08:00
CODE_OWNERS.txt
LICENSE.TXT
use_lldb_suite_root.py