[all-commits] [llvm/llvm-project] 532290: [lldb] s/FileSpec::Equal/FileSpec::Match

Pavel Labath via All-commits all-commits at lists.llvm.org
Wed Dec 4 01:45:17 PST 2019


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 532290e69fcb0e1f2005853241bc2cac6941e0f7
      https://github.com/llvm/llvm-project/commit/532290e69fcb0e1f2005853241bc2cac6941e0f7
  Author: Pavel Labath <pavel at labath.sk>
  Date:   2019-12-04 (Wed, 04 Dec 2019)

  Changed paths:
    M lldb/include/lldb/Core/ModuleSpec.h
    M lldb/include/lldb/Core/SourceManager.h
    M lldb/include/lldb/Utility/FileSpec.h
    M lldb/source/Breakpoint/Breakpoint.cpp
    M lldb/source/Commands/CommandObjectSource.cpp
    M lldb/source/Core/IOHandlerCursesGUI.cpp
    M lldb/source/Core/Module.cpp
    M lldb/source/Core/SearchFilter.cpp
    M lldb/source/Core/SourceManager.cpp
    M lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
    M lldb/source/Symbol/CompileUnit.cpp
    M lldb/source/Symbol/Declaration.cpp
    M lldb/source/Symbol/SymbolContext.cpp
    M lldb/source/Target/TargetList.cpp
    M lldb/source/Target/ThreadPlanStepInRange.cpp
    M lldb/source/Utility/FileSpec.cpp
    M lldb/unittests/Utility/FileSpecTest.cpp

  Log Message:
  -----------
  [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


  Commit: 817d6184e75db5eefca907a296e8379d8f570e7e
      https://github.com/llvm/llvm-project/commit/817d6184e75db5eefca907a296e8379d8f570e7e
  Author: Pavel Labath <pavel at labath.sk>
  Date:   2019-12-04 (Wed, 04 Dec 2019)

  Changed paths:
    M lldb/source/Host/common/Editline.cpp

  Log Message:
  -----------
  [lldb/Editline] Fix a -Wreturn-type warning with gcc


Compare: https://github.com/llvm/llvm-project/compare/a3af3ac39301...817d6184e75d


More information about the All-commits mailing list