summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter/CommandAlias.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [LLDB] Fix compilation with GCC 5Martin Storsjö2020-02-061-1/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D74084 (cherry picked from commit 5bbaf543585c54868f8a2bdd9e74edcf395b24b3)
* [lldb][NFC] Remove ArgEntry::ref memberRaphael Isemann2019-09-131-2/+2
| | | | | | | | | | | The StringRef should always be identical to the C string, so we might as well just create the StringRef from the C-string. This might be slightly slower until we implement the storage of ArgEntry with a string instead of a std::unique_ptr<char[]>. Until then we have to do the additional strlen on the C string to construct the StringRef. llvm-svn: 371842
* [lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and ↵Raphael Isemann2019-08-221-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | remove any undocumented/redundant return values Summary: We still have some leftovers of the old completion API in the internals of LLDB that haven't been replaced by the new CompletionRequest. These leftovers are: * The return values (int/size_t) in all completion functions. * Our result array that starts indexing at 1. * `WordComplete` mode. I didn't replace them back then because it's tricky to figure out what exactly they are used for and the completion code is relatively untested. I finally got around to writing more tests for the API and understanding the semantics, so I think it's a good time to get rid of them. A few words why those things should be removed/replaced: * The return values are really cryptic, partly redundant and rarely documented. They are also completely ignored by Xcode, so whatever information they contain will end up breaking Xcode's completion mechanism. They are also partly impossible to even implement as we assign negative values special meaning and our completion API sometimes returns size_t. Completion functions are supposed to return -2 to rewrite the current line. We seem to use this in some untested code path to expand the history repeat character to the full command, but I haven't figured out why that doesn't work at the moment. Completion functions return -1 to 'insert the completion character', but that isn't implemented (even though we seem to activate this feature in LLDB sometimes). All positive values have to match the number of results. This is obviously just redundant information as the user can just look at the result list to get that information (which is what Xcode does). * The result array that starts indexing at 1 is obviously unexpected. The first element of the array is reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is that we calculate this to make the life of the API caller easier, but obviously forcing people to have 1-based indices is not helpful (or even worse, forces them to manually copy the results to make it 0-based like Xcode has to do). * The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The idea is that we let the top-level API know that we just provided a full completion. Interestingly we `WordComplete` is just a single bool that somehow represents all N completions. And we always provide full completions in LLDB, so in theory it should always be true. The only use it currently serves is providing redundant information about whether we have a single definitive completion or not (which we already know from the number of results we get). This patch essentially removes `WordComplete` mode and makes the result array indexed from 0. It also removes all return values from all internal completion functions. The only non-redundant information they contain is about rewriting the current line (which is broken), so that functionality was moved to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)` to do the same. For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we didn't even implement them in the Editline handler (e.g. -1). I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code, but I would prefer doing this in follow-up NFC commits Reviewers: JDevlieghere Reviewed By: JDevlieghere Subscribers: arphaman, abidh, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D66536 llvm-svn: 369624
* Options: Reduce code duplicationPavel Labath2019-07-101-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: While investigating breakages caused by D63110, I noticed we were building the short options strings in three places. Some of them used a leading ':' to detect missing arguments, and some didn't. This was the indirect cause of D63110. Here, I move the common code into a utility function. Also, unify the code which appends the sentinel value at the end of the option vector, and make it harder for users to pass invalid argc-argv combos to getopt (another component of D63110) by having the OptionParser::Parse function take a (Mutable)ArrayRef. This unification has uncovered that we don't handle missing arguments while building aliases, However, it's not possible to write an effective test for this, as right now it is not possible to return an error out of the alias parsing code (which means we are printing the generic "failure" message even after this patch). Reviewers: mgorny, aprantl Reviewed By: mgorny Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D63770 llvm-svn: 365665
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [NFC] Replace `compare` with (in)equality operator where applicable.Jonas Devlieghere2018-12-211-2/+1
| | | | | | | | Using compare is verbose, bug prone and potentially inefficient (because of early termination). Replace relevant call sites with the (in)equality operator. llvm-svn: 349972
* Refactoring for for the internal command line completion API (NFC)Raphael Isemann2018-07-021-13/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch refactors the internal completion API. It now takes (as far as possible) a single CompletionRequest object instead o half a dozen in/out/in-out parameters. The CompletionRequest contains a common superset of the different parameters as far as it makes sense. This includes the raw command line string and raw cursor position, which should make the `expr` command possible to implement (at least without hacks that reconstruct the command line from the args). This patch is not intended to change the observable behavior of lldb in any way. It's also as minimal as possible and doesn't attempt to fix all the problems the API has. Some Q&A: Q: Why is this not fixing all the problems in the completion API? A: Because is a blocker for the expr command completion which I want to get in ASAP. This is the smallest patch that unblocks the expr completion patch and which allows trivial refactoring in the future. The patch also doesn't really change the internal information flow in the API, so that hopefully saves us from ever having to revert and resubmit this humongous patch. Q: Can we merge all the copy-pasted code in the completion methods (like computing the current incomplete arg) into CompletionRequest class? A: Yes, but it's out of scope for this patch. Q: Why the `word_complete = request.GetWordComplete(); ... ` pattern? A: I don't want to add a getter that returns a reference to the internal integer. So we have to use a temporary variable and the Getter/Setter instead. We don't throw exceptions from what I can tell, so the behavior doesn't change. Q: Why are we not owning the list of matches? A: Because that's how the previous API works. But that should be fixed too (in another patch). Q: Can we make the constructor simpler and compute some of the values from the plain command? A: I think this works, but I rather want to have this in a follow up commit. Especially when making nested request it's a bit awkward that the parsed arguments behave as both input/output (as we should in theory propagate the changes on the nested request back to the parent request if we don't want to change the behavior too much). Q: Can't we pass one const request object and then just return another result object instead of mixing them together in one in/out parameter? A: It's hard to get keep the same behavior with that pattern, but I think we can also get a nice API with just a single request object. If we make all input parameters read-only, we have a clear separation between what is actually an input and what an output parameter (and hopefully we get rid of the in-out parameters). Q: Can we throw out the 'match' variables that are not implemented according to the comment? A: We currently just forward them as in the old code to the different methods, even though I think they are really not used. We can easily remove and readd them once every single completion method just takes a CompletionRequest, but for now I prefer NFC behavior from the perspective of the API user. Reviewers: davide, jingham, labath Reviewed By: jingham Subscribers: mgorny, friss, lldb-commits Differential Revision: https://reviews.llvm.org/D48796 llvm-svn: 336146
* Reflow paragraphs in comments.Adrian Prantl2018-04-301-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is intended as a clean up after the big clang-format commit (r280751), which unfortunately resulted in many of the comment paragraphs in LLDB being very hard to read. FYI, the script I used was: import textwrap import commands import os import sys import re tmp = "%s.tmp"%sys.argv[1] out = open(tmp, "w+") with open(sys.argv[1], "r") as f: header = "" text = "" comment = re.compile(r'^( *//) ([^ ].*)$') special = re.compile(r'^((([A-Z]+[: ])|([0-9]+ )).*)|(.*;)$') for line in f: match = comment.match(line) if match and not special.match(match.group(2)): # skip intentionally short comments. if not text and len(match.group(2)) < 40: out.write(line) continue if text: text += " " + match.group(2) else: header = match.group(1) text = match.group(2) continue if text: filled = textwrap.wrap(text, width=(78-len(header)), break_long_words=False) for l in filled: out.write(header+" "+l+'\n') text = "" out.write(line) os.rename(tmp, sys.argv[1]) Differential Revision: https://reviews.llvm.org/D46144 llvm-svn: 331197
* Move option parsing out of the Args classPavel Labath2018-03-091-6/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The args class is used in plenty of places (a lot of them in the lower lldb layers) for representing a list of arguments, and most of these places don't care about option parsing. Moving the option parsing out of the class removes the largest external dependency (there are a couple more, but these are in static functions), and brings us closer to being able to move it to the Utility module). The new home for these functions is the Options class, which was already used as an argument to the parse calls, so this just inverts the dependency between the two. The functions are themselves are mainly just copied -- the biggest functional change I've made to them is to avoid modifying the input Args argument (getopt likes to permute the argument vector), as it was weird to have another class reorder the entries in Args class. So now the functions don't modify the input arguments, and (for those where it makes sense) return a new Args vector instead. I've also made the addition of a "fake arg0" (required for getopt compatibility) an implementation detail rather than a part of interface. While doing that I noticed that ParseForCompletion function was recording the option indexes in the shuffled vector, but then the consumer was looking up the entries in the unshuffled one. This manifested itself as us not being able to complete "watchpoint set variable foo --" (because getopt would move "foo" to the end). Surprisingly all other completions (e.g. "watchpoint set variable foo --w") were not affected by this. However, I couldn't find a comprehensive test for command argument completion, so I consolidated the existing tests and added a bunch of new ones. Reviewers: davide, jingham, zturner Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D43837 llvm-svn: 327110
* Move classes from Core -> Utility.Zachary Turner2017-02-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | This moves the following classes from Core -> Utility. ConstString Error RegularExpression Stream StreamString The goal here is to get lldbUtility into a state where it has no dependendencies except on itself and LLVM, so it can be the starting point at which to start untangling LLDB's dependencies. These are all low level and very widely used classes, and previously lldbUtility had dependencies up to lldbCore in order to use these classes. So moving then down to lldbUtility makes sense from both the short term and long term perspective in solving this problem. Differential Revision: https://reviews.llvm.org/D29427 llvm-svn: 293941
* Don't allow direct access to StreamString's internal buffer.Zachary Turner2016-11-161-1/+1
| | | | | | | | | | | | | | | This is a large API change that removes the two functions from StreamString that return a std::string& and a const std::string&, and instead provide one function which returns a StringRef. Direct access to the underlying buffer violates the concept of a "stream" which is intended to provide forward only access, and makes porting to llvm::raw_ostream more difficult in the future. Differential Revision: https://reviews.llvm.org/D26698 llvm-svn: 287152
* Fix some more Printf warnings.Zachary Turner2016-11-151-2/+3
| | | | llvm-svn: 286916
* Fix some more StringRef printf warnings.Zachary Turner2016-11-151-1/+1
| | | | llvm-svn: 286915
* Make CommandObject help getters/setters use StringRef.Zachary Turner2016-11-121-8/+8
| | | | llvm-svn: 286731
* Convert some Args index-based iteration to range-style iteration.Zachary Turner2016-10-051-5/+4
| | | | | | | | | | | | | | This is better for a number of reasons. Mostly style, but also: 1) Signed-unsigned comparison warnings disappear since there is no loop index. 2) Iterating with the range-for style gives you back an entry that has more than just a const char*, so it's more efficient and more useful. 3) Makes code safter since the type system enforces that it's impossible to index out of bounds. llvm-svn: 283413
* Update some command aliasing functions to use StringRef.Zachary Turner2016-10-051-1/+1
| | | | llvm-svn: 283385
* Convert CommandObject constructors to StringRef.Zachary Turner2016-10-051-13/+13
| | | | llvm-svn: 283384
* Modernize some code related to Args usage / implementation.Zachary Turner2016-10-031-35/+42
| | | | | | | Mostly this involves simplifying some logical constructs and using some ranges instead of index-based iteration. NFC llvm-svn: 283159
* Convert 3 more functions to use a StringRef.Zachary Turner2016-09-191-1/+1
| | | | | | | | This converts Args::Unshift, Args::AddOrReplaceEnvironmentVariable, and Args::ContainsEnvironmentVariable to use StringRefs. The code is also simplified somewhat as a result. llvm-svn: 281942
* *** This commit represents a complete reformatting of the LLDB source codeKate Stone2016-09-061-264/+199
| | | | | | | | | | | | | | | | | | | | | | | *** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
* Decoupled Options from CommandInterpreter.Todd Fiala2016-08-111-1/+4
| | | | | | | | | | | | | | | | Options used to store a reference to the CommandInterpreter instance in the base Options class. This made it impossible to parse options independent of a CommandInterpreter. This change removes the reference from the base class. Instead, it modifies the options-parsing-related methods to take an ExecutionContext pointer, which the options may inspect if they need to do so. Closes https://reviews.llvm.org/D23416 Reviewers: clayborg, jingham llvm-svn: 278440
* Fix an issue with nested aliases where the help system wouldn't correctly ↵Enrico Granata2016-03-251-0/+11
| | | | | | | | track the fact that an alias is an alias to a dash-dash alias (and I hope I typed the word 'alias' enough times in this commit message :-) llvm-svn: 264468
* Make it so that a command alias can actually remove the help/long help from ↵Enrico Granata2016-03-221-3/+19
| | | | | | its parent command by setting itself to an empty help string llvm-svn: 264108
* Fix a bug caused by my alias refactoring where, if an alias was defined in ↵Enrico Granata2016-03-221-0/+19
| | | | | | terms of another alias, trying to run the nested command would actually cause a crash in the command interpreter llvm-svn: 264096
* Improve the way we decide whether an alias is a dashdash aliasEnrico Granata2016-03-151-1/+2
| | | | llvm-svn: 263519
* Lots of progress on the CommandAlias refactoringEnrico Granata2016-03-141-1/+110
| | | | | | | | | This cleans things up such CommandAlias essentially can work as its own object; the aliases still live in a separate map, but are now just full-fledged CommandObjectSPs This patch also cleans up help generation for aliases, allows aliases to vend their own help, and adds a tweak such that "dash-dash aliases", such as po, don't show the list of options for their underlying command, since those can't be provided anyway I plan to fix up a few more things here, and then add a test case and proclaim victory llvm-svn: 263499
* More of the alias refactoring work! CommandAlias is now a CommandObjectEnrico Granata2016-03-141-12/+40
| | | | llvm-svn: 263468
* Last round of preliminary cleanup in my refactoring of aliases.Enrico Granata2016-03-091-0/+112
| | | | | | | | | | | | | | The next step is to actually turn CommandAlias into a full-blown CommandObject citizen. This is tricky given the current architecture of the CommandInterpreter but I think I have found a reasonable path forward. The current plan is to make class CommandAlias : public CommandObject, and have all the several GetCommand calls not actually traverse through the alias to the underlying command object The only times that an alias will be traversed are: a) execution; when time comes to run an alias, I will just grab the underlying command and options, and make the interpreter execute that according to its current algorithm b) subcommand traversal; if one has an alias to a multiword command, grabbing a subcommand will see through to the subcommand Other operations, e.g. command listing, command names, command helps, ..., will all use the alias directly. This will, in turn, lead to the removal of the separate alias dictionary, and just mix user commands and aliases in one map llvm-svn: 262986
* Move CommandAlias to its own file; alsoEnrico Granata2016-03-081-0/+11
Store std::unique_ptr<CommandAlias> instead of instances llvm-svn: 262958
OpenPOWER on IntegriCloud