llvm-project/lldb/source/Commands
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
..
CMakeLists.txt Remove `bugreport` command 2019-09-05 21:43:32 +00:00
CommandCompletions.cpp [lldb][NFC] Simplify regex_chars in CommandCompletions 2019-11-29 12:34:23 +01:00
CommandObjectApropos.cpp [lldb][NFC] Remove ArgEntry::ref member 2019-09-13 11:26:48 +00:00
CommandObjectApropos.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectBreakpoint.cpp BreakpointDummyOptionGroup was using g_breakpoint_modify_options rather than g_breakpoint_dummy_options 2019-11-07 14:25:04 -08:00
CommandObjectBreakpoint.h [lldb] Remove dead code from STLUtils.h 2019-11-06 15:06:29 -08:00
CommandObjectBreakpointCommand.cpp [lldb][NFC] Use raw_ostream instead of Stream in Baton::GetDescription 2019-12-02 13:27:21 +01:00
CommandObjectBreakpointCommand.h Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectCommands.cpp Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectCommands.h [lldb] Remove dead code from STLUtils.h 2019-11-06 15:06:29 -08:00
CommandObjectDisassemble.cpp Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectDisassemble.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectExpression.cpp [lldb] Make Target* a Target& in CommandObjectExpression::DoExecute REPL logic 2019-11-08 12:28:49 +01:00
CommandObjectExpression.h [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
CommandObjectFrame.cpp Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectFrame.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectGUI.cpp [lldb][NFC] Move Curses interface implementation to own file 2019-12-03 14:01:18 +01:00
CommandObjectGUI.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectHelp.cpp Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectHelp.h [lldb][NFC] Remove dead code that is supposed to handle invalid command options 2019-08-22 08:08:05 +00:00
CommandObjectLanguage.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CommandObjectLanguage.h Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectLog.cpp [lldb] Add completion support for log enable/disable/list 2019-09-24 07:18:09 +00:00
CommandObjectLog.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectMemory.cpp MemoryRegion: Print "don't know" permission values as such 2019-11-05 11:17:27 +01:00
CommandObjectMemory.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CommandObjectMultiword.cpp [lldb] Print an error message for an empty subcommand 2019-09-27 08:49:41 +00:00
CommandObjectPlatform.cpp Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectPlatform.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectPlugin.cpp [lldb][NFC] Remove ArgEntry::ref member 2019-09-13 11:26:48 +00:00
CommandObjectPlugin.h Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectProcess.cpp Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectProcess.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectQuit.cpp [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectQuit.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectRegister.cpp [lldb][NFC] Remove ArgEntry::ref member 2019-09-13 11:26:48 +00:00
CommandObjectRegister.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectReproducer.cpp [Reproducer] Make 'reproducer xcrash' behave the same during capture & replay 2019-11-21 13:34:04 -08:00
CommandObjectReproducer.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectSettings.cpp Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectSettings.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectSource.cpp [lldb] s/FileSpec::Equal/FileSpec::Match 2019-12-04 10:42:32 +01:00
CommandObjectSource.h [lldb] Remove dead code from STLUtils.h 2019-11-06 15:06:29 -08:00
CommandObjectStats.cpp Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectStats.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CommandObjectTarget.cpp [lldb][NFC] Migrate to raw_ostream in ArchSpec::DumpTriple 2019-12-04 08:28:52 +01:00
CommandObjectTarget.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectThread.cpp [lldb] Remove FileSpec->CompileUnit inheritance 2019-11-29 11:44:45 +01:00
CommandObjectThread.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CommandObjectType.cpp Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectType.h Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectVersion.cpp [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectVersion.h [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
CommandObjectWatchpoint.cpp Modernize the rest of the Find.* API (NFC) 2019-10-17 19:56:40 +00:00
CommandObjectWatchpoint.h Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
CommandObjectWatchpointCommand.cpp [lldb][NFC] Use raw_ostream instead of Stream in Baton::GetDescription 2019-12-02 13:27:21 +01:00
CommandObjectWatchpointCommand.h Run clang-format on lldb/source/Commands (NFC) 2019-10-30 16:03:00 -07:00
Options.td [Reproducer] Generate LLDB reproducer on crash 2019-11-20 13:14:16 -08:00
OptionsBase.td [lldb] Don't dynamically allocate the posix option validator. 2019-07-26 11:46:21 +00:00