summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter/Args.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Move Args.cpp from Interpreter to UtilityPavel Labath2018-04-171-694/+0
| | | | | | | | | | | | | | | | | | | | | Summary: The Args class is used in plenty of places besides the command interpreter (e.g., anything requiring an argc+argv combo, such as when launching a process), so it needs to be in a lower layer. Now that the class has no external dependencies, it can be moved down to the Utility module. This removes the last (direct) dependency from the Host module to Interpreter, so I remove the Interpreter module from Host's dependency list. Reviewers: zturner, jingham, davide Subscribers: mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D45480 llvm-svn: 330200
* Args: replace isprint8 usage with isprintPavel Labath2018-04-101-2/+1
| | | | | | | | | | | | | It looks like we introduced isprint8 way back in r169417 to be used on getopt's short_options, which we sometimes set to values which are out of range for normal chars to indicate options with no short form. However, this is not how the function is used in the Args class, where we explicitly process a string character by character. This removes the last external dependency from the Args class. llvm-svn: 329682
* Move Args::StringTo*** functions to a new OptionArgParser classPavel Labath2018-04-101-238/+4
| | | | | | | | | | | | | | | | Summary: The idea behind this is to move the functionality which depend on other lldb classes into a separate class. This way, the Args class can be turned into a lightweight arc+argv wrapper and moved into the lower lldb layers. Reviewers: jingham, zturner Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D44306 llvm-svn: 329677
* Move option parsing out of the Args classPavel Labath2018-03-091-527/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add Utility/Environment class for handling... environmentsPavel Labath2018-01-101-44/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: There was some confusion in the code about how to represent process environment. Most of the code (ab)used the Args class for this purpose, but some of it used a more basic StringList class instead. In either case, the fact that the underlying abstraction did not provide primitive operations for the typical environment operations meant that even a simple operation like checking for an environment variable value was several lines of code. This patch adds a separate Environment class, which is essentialy a llvm::StringMap<std::string> in disguise. To standard StringMap functionality, it adds a couple of new functions, which are specific to the environment use case: - (most important) envp conversion for passing into execve() and likes. Instead of trying to maintain a constantly up-to-date envp view, it provides a function which creates a envp view on demand, with the expectation that this will be called as the very last thing before handing the value to the system function. - insert(StringRef KeyEqValue) - splits KeyEqValue into (key, value) pair and inserts it into the environment map. - compose(value_type KeyValue) - takes a map entry and converts in back into "KEY=VALUE" representation. With this interface most of the environment-manipulating code becomes one-liners. The only tricky part was maintaining compatibility in SBLaunchInfo, which expects that the environment entries are accessible by index and that the returned const char* is backed by the launch info object (random access into maps is hard and the map stores the entry in a deconstructed form, so we cannot just return a .c_str() value). To solve this, I have the SBLaunchInfo convert the environment into the "envp" form, and use it to answer the environment queries. Extra code is added to make sure the envp version is always in sync. (This also improves the layering situation as Args was in the Interpreter module whereas Environment is in Utility.) Reviewers: zturner, davide, jingham, clayborg Subscribers: emaste, lldb-commits, mgorny Differential Revision: https://reviews.llvm.org/D41359 llvm-svn: 322174
* Add a StringList constructor to Args classPavel Labath2017-12-111-0/+5
| | | | | | | | | Host::GetEnvironment returns a StringList, but the interface for launching a process takes Args. The fact that we use two classes for representing an environment is not ideal, but for now we should at least have an easy way to convert between the two. llvm-svn: 320366
* Rename Error -> Status.Zachary Turner2017-05-121-9/+9
| | | | | | | | | | | | | | | This renames the LLDB error class to Status, as discussed on the lldb-dev mailing list. A change of this magnitude cannot easily be done without find and replace, but that has potential to catch unwanted occurrences of common strings such as "Error". Every effort was made to find all the obvious things such as the word "Error" appearing in a string, etc, but it's possible there are still some lingering occurences left around. Hopefully nothing too serious. llvm-svn: 302872
* Delete some more dead includes.Zachary Turner2017-03-221-7/+2
| | | | | | | This breaks the cycle between Target and PluginLanguageC++, reducing the overall cycle count from 43 to 42. llvm-svn: 298561
* Fix up some enumerate() callsites in LLDB.Zachary Turner2017-03-131-5/+5
| | | | llvm-svn: 297640
* Move classes from Core -> Utility.Zachary Turner2017-02-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | 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
* Fix a couple of incorrect format string warningsLuke Drummond2016-12-221-3/+2
| | | | | | | | | | | This patch fixes use of incorrect `%zi` to format a plain `int`, and using `%llu` to format a `uint64_t`. The fix is to use the new typesafe `llvm::Formatv` based API. Differential Revision: https://reviews.llvm.org/D28028 Subscribers: lldb-commits llvm-svn: 290359
* Remove some more uses of Args::GetArgumentAtIndex.Zachary Turner2016-12-091-6/+5
| | | | llvm-svn: 289188
* Don't allow direct access to StreamString's internal buffer.Zachary Turner2016-11-161-6/+7
| | | | | | | | | | | | | | | 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
* Make OptionParser::Parse() take StringRef.Zachary Turner2016-11-131-6/+6
| | | | llvm-svn: 286747
* Fix some cases where we were printf'ing StringRefs.Zachary Turner2016-11-081-3/+3
| | | | llvm-svn: 286303
* Convert some Expression parser functions to StringRef.Zachary Turner2016-11-081-86/+94
| | | | llvm-svn: 286208
* Interpreter: Don't return StringRef from functions whose return value is ↵Justin Bogner2016-10-171-14/+10
| | | | | | | | | | never used StringRef is passed through all of these APIs but never actually used. Just remove it from the API for now and if people want to use it they can add it back. llvm-svn: 284362
* Match printf field width arg and typeEd Maste2016-10-061-1/+1
| | | | | | | A '*' as a field width or precision specifies that the field width or precision is supplied by an int argument. llvm-svn: 283472
* Convert CommandObject constructors to StringRef.Zachary Turner2016-10-051-13/+16
| | | | llvm-svn: 283384
* Convert various CommandInterpreter functions to StringRef.Zachary Turner2016-10-051-47/+40
| | | | llvm-svn: 283370
* Make lldb -Werror clean on Windows.Zachary Turner2016-10-051-4/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D25247 llvm-svn: 283344
* Modernize some code related to Args usage / implementation.Zachary Turner2016-10-031-77/+56
| | | | | | | Mostly this involves simplifying some logical constructs and using some ranges instead of index-based iteration. NFC llvm-svn: 283159
* Refactor the Args class.Zachary Turner2016-10-031-291/+210
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | There were a number of issues with the Args class preventing efficient use of strings and incoporating LLVM's StringRef class. The two biggest were: 1. Backing memory stored in a std::string, so we would frequently have to use const_cast to get a mutable buffer for passing to various low level APIs. 2. backing std::strings stored in a std::list, which doesn't provide random access. I wanted to solve these two issues so that we could provide StringRef access to the underlying arguments, and also a way to provide range-based access to the underlying argument array while still providing convenient c-style access via an argv style const char**. The solution here is to store arguments in a single "entry" class which contains the backing memory, a StringRef with precomputed length, and the quote char. The backing memory is a manually allocated const char* so that it is not invalidated when the container is resized, and there is a separate argv array provided for c-style access. Differential revision: https://reviews.llvm.org/D25099 llvm-svn: 283157
* Update OptionGroup::SetValue to take StringRef.Zachary Turner2016-09-231-19/+22
| | | | | | | | Then deal with all the fallout. Differential Revision: https://reviews.llvm.org/D24847 llvm-svn: 282265
* Convert option tables to ArrayRefs.Zachary Turner2016-09-221-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | | This change is very mechanical. All it does is change the signature of `Options::GetDefinitions()` and `OptionGroup:: GetDefinitions()` to return an `ArrayRef<OptionDefinition>` instead of a `const OptionDefinition *`. In the case of the former, it deletes the sentinel entry from every table, and in the case of the latter, it removes the `GetNumDefinitions()` method from the interface. These are no longer necessary as `ArrayRef` carries its own length. In the former case, iteration was done by using a sentinel entry, so there was no knowledge of length. Because of this the individual option tables were allowed to be defined below the corresponding class (after all, only a pointer was needed). Now, however, the length must be known at compile time to construct the `ArrayRef`, and as a result it is necessary to move every option table before its corresponding class. This results in this CL looking very big, but in terms of substance there is not much here. Differential revision: https://reviews.llvm.org/D24834 llvm-svn: 282188
* added environment variable-related Args gtestsTodd Fiala2016-09-221-4/+6
| | | | | | | | Also fixed up a couple misbehaving functions. It is perfectly legal to have env vars with no values (i.e. the '=' and following need not be present). llvm-svn: 282171
* fix Args function broken in r281942Todd Fiala2016-09-221-1/+1
| | | | | | | | The method was hard-coded to check only the 0th element of the array. This manifested as NSLog messages behaving incorrectly on macOS. (This is independent of the broken DarwinLog feature). llvm-svn: 282128
* Fix an incorrect nullptr conversion.Zachary Turner2016-09-211-1/+1
| | | | llvm-svn: 282117
* Make lldb::Regex use StringRef.Zachary Turner2016-09-211-3/+5
| | | | | | | | | | This updates getters and setters to use StringRef instead of const char *. I tested the build on Linux, Windows, and OSX and saw no build or test failures. I cannot test any BSD or Android variants, however I expect the required changes to be minimal or non-existant. llvm-svn: 282079
* Convert 3 more functions to use a StringRef.Zachary Turner2016-09-191-54/+24
| | | | | | | | This converts Args::Unshift, Args::AddOrReplaceEnvironmentVariable, and Args::ContainsEnvironmentVariable to use StringRefs. The code is also simplified somewhat as a result. llvm-svn: 281942
* Fix more functions in Args to use StringRef.Zachary Turner2016-09-191-32/+15
| | | | | | | | | | | | | | | This patch also marks the const char* versions as =delete to prevent their use. This has the potential to cause build breakages on some platforms which I can't compile. I have tested on Windows, Linux, and OSX. Best practices for fixing broken callsites are outlined in Args.h in a comment above the deleted function declarations. Eventually we can remove these =delete declarations, but for now they are important to make sure that all implicit conversions from const char * are manually audited to make sure that they do not invoke a conversion from nullptr. llvm-svn: 281919
* Convert many functions to use StringRefs.Zachary Turner2016-09-171-27/+17
| | | | | | | | | | | | | Where possible, remove the const char* version. To keep the risk and impact here minimal, I've only done the simplest functions. In the process, I found a few opportunities for adding some unit tests, so I added those as well. Tested on Windows, Linux, and OSX. llvm-svn: 281799
* Add unit tests for a few string conversion functions in Args.Zachary Turner2016-09-161-37/+25
| | | | | | | Also provided a StringRef overload for these functions and have the const char* overloads delegate to the StringRef overload. llvm-svn: 281764
* *** This commit represents a complete reformatting of the LLDB source codeKate Stone2016-09-061-1620/+1433
| | | | | | | | | | | | | | | | | | | | | | | *** 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
* Revert r280137 and 280139 and subsequent build fixesPavel Labath2016-08-311-18/+6
| | | | | | | | | | The rewrite of StringExtractor::GetHexMaxU32 changes functionality in a way which makes lldb-server crash. The crash (assert) happens when parsing the "qRegisterInfo0" packet, because the function tries to drop_front more bytes than the packet contains. It's not clear to me whether we should consider this a bug in the caller or the callee, but it any case, it worked before, so I am reverting this until we can figure out what the proper interface should be. llvm-svn: 280207
* A few minor stylistic cleanups in StringExtractor.Zachary Turner2016-08-301-6/+18
| | | | | | | | | | | Makes Peek() return a StringRef instead of a const char*. This leads to a few callers of Peek() being able to be made a little nicer (for example using StringRef member functions instead of c-style strncmp and related functions) and generally safer usage. llvm-svn: 280139
* Fix fallout from the GetNameColonValue() refactor (r280000)Pavel Labath2016-08-301-8/+9
| | | | | | This fixes the linux test suite. llvm-svn: 280074
* Convert GetNameColonValue to return StringRefs.Zachary Turner2016-08-291-50/+53
| | | | | | | | | | | | StringExtractor::GetNameColonValue() looks for a substring of the form "<name>:<value>" and returns <name> and <value> to the caller. This results in two unnecessary string copies, since the name and value are not translated in any way and simply returned as-is. By converting this to return StringRefs we can get rid of hundreds of string copies. llvm-svn: 280000
* Add StructuredData plugin type; showcase with new DarwinLog featureTodd Fiala2016-08-191-1/+45
| | | | | | | | | | | | Take 2, with missing cmake line fixed. Build tested on Ubuntu 14.04 with clang-3.6. See docs/structured_data/StructuredDataPlugins.md for details. differential review: https://reviews.llvm.org/D22976 reviewers: clayborg, jingham llvm-svn: 279202
* Revert "Add StructuredData plugin type; showcase with new DarwinLog feature"Todd Fiala2016-08-191-45/+1
| | | | | | This reverts commit 1d885845d1451e7b232f53fba2e36be67aadabd8. llvm-svn: 279200
* Add StructuredData plugin type; showcase with new DarwinLog featureTodd Fiala2016-08-191-1/+45
| | | | | | | | | See docs/structured_data/StructuredDataPlugins.md for details. differential review: https://reviews.llvm.org/D22976 reviewers: clayborg, jingham llvm-svn: 279198
* Decoupled Options from CommandInterpreter.Todd Fiala2016-08-111-7/+38
| | | | | | | | | | | | | | | | 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 command-line LLDB so NSLog messages show upTodd Fiala2016-07-141-0/+41
| | | | | | | | | | | Changes to the underlying logging infrastructure in Fall 2016 Darwin OSes were no longer showing up NSLog messages in command-line LLDB. This change restores that functionality, and adds test cases to verify the new behavior. rdar://26732492 llvm-svn: 275472
* Implement ProcessInfo::Dump(), log gdb-remote stub launchTodd Fiala2016-05-311-5/+8
| | | | | | | | | | | | | | | | | | This change implements dumping the executable, triple, args and environment when using ProcessInfo::Dump(). It also tweaks the way Args::Dump() works so that it prints a configurable label rather than argv[{index}]={value}. By default it behaves the same, but if the Dump() method with the additional arg is provided, it can be overridden. The environment variables dumped as part of ProcessInfo::Dump() make use of that. lldb-server has been modified to dump the gdb-remote stub's ProcessInfo before launching if the "gdb-remote process" channel is logged. llvm-svn: 271312
* second pass over removal of Mutex and ConditionSaleem Abdulrasool2016-05-191-6/+6
| | | | llvm-svn: 270024
* Improve the way LLDB escapes arguments before passing them to the shellEnrico Granata2016-04-041-3/+31
| | | | | | | | | | | | | Teach LLDB that different shells have different characters they are sensitive to, and use that knowledge to do shell-aware escaping This helps solve a class of problems on OS X where LLDB would try to launch via sh, and run into problems if the command line being passed to the inferior contained such special markers (hint: the shell would error out and we'd fail to launch) This makes those launch scenarios work transparently via shell expansion Slightly improve the error message when this kind of failure occurs to at least suggest that the user try going through 'process launch' directly Fixes rdar://problem/22749408 llvm-svn: 265357
* LLDB needs a mutex around getopt_long_only() function calls to avoid ↵Jim Ingham2015-11-051-3/+6
| | | | | | | | multi-threading option parsing issues. <rdar://problem/17052381> llvm-svn: 252111
* Silence -Wqual-cast warnings from GCC 5.2Saleem Abdulrasool2015-10-181-3/+3
| | | | | | | | There were a number of const qualifiers being cast away which caused warnings. This cluttered the output hiding real errors. Silence them by explicit casting. NFC. llvm-svn: 250662
* Fix tab completion for command arguments containing spacesTamas Berghammer2015-09-021-0/+30
| | | | | | | | | | | If a command argument contains a space then it have to be escaped with backslash signs so the argument parsing logic can parse it properly. This CL fixes the tab completion code for the arguments to create complitions with correctly escaped strings. Differential revision: http://reviews.llvm.org/D12531 llvm-svn: 246639
* Fix typos.Bruce Mitchener2015-07-221-1/+1
| | | | | | | | | | | | Summary: Fix a bunch of typos. Reviewers: clayborg Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D11386 llvm-svn: 242856
OpenPOWER on IntegriCloud