summaryrefslogtreecommitdiff
path: root/lldb/source/Utility/StructuredData.cpp
AgeCommit message (Collapse)Author
2024-09-05[lldb] Make conversions from llvm::Error explicit with Status::FromEr… ↵Adrian Prantl
(#107163) …ror() [NFC]
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl
This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected<ResultTy> DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup.
2023-09-14[lldb][NFCI] Remove use of ConstString in StructuredDataAlex Langford
The remaining use of ConstString in StructuredData is the Dictionary class. Internally it's backed by a `std::map<ConstString, ObjectSP>`. I propose that we replace it with a `llvm::StringMap<ObjectSP>`. Many StructuredData::Dictionary objects are ephemeral and only exist for a short amount of time. Many of these Dictionaries are only produced once and are never used again. That leaves us with a lot of string data in the ConstString StringPool that is sitting there never to be used again. Even if the same string is used many times for keys of different Dictionary objects, that is something we can measure and adjust for instead of assuming that every key may be reused at some point in the future. Quick comparisons of key data is likely not a concern with Dictionary, but the use of `llvm::StringMap` means that lookups should be fast with its hashing strategy. Switching to a llvm::StringMap meant that the iteration order may be different. To account for this when serializing/dumping the dictionary, I added some code to sort the output by key before emitting anything. Differential Revision: https://reviews.llvm.org/D159313
2023-08-31[lldb][NFCI] Replace bespoke iterator check with std::nextAlex Langford
The primary goal of this change is to change `if (pair != *(--m_dict.end()))` to `if (std::next(iter) != m_dict.end())`. I was experimenting with changing the underlying type of `m_dict` and found that this was an issue. Specifically, it assumes that m_dict iterators are bidirectional. This change should make it so we only need to assume m_dict iterators can move forward. Differential Revision: https://reviews.llvm.org/D159150
2023-07-09[lldb] Add missing StringExtras.h includesElliot Goodrich
In preparation for removing the `#include "llvm/ADT/StringExtras.h"` from the header to source file of `llvm/Support/Error.h`, first add in all the missing includes that were previously included transitively through this header. This is fixing all files missed in b0abd4893fa1, 39d8e6e22cd1, and a11efd49266f. Differential Revision: https://reviews.llvm.org/D154775
2023-07-06[lldb][NFCI] Minor cleanups to StructuredData::GetObjectForDotSeparatedPathAlex Langford
This accomplishes a few minor things: - Removed unnecessary uses of `this->` - Removed an unnecessary std::string allocation. - Removed some nesting to improve readability using early returns where it makes sense. - Replaced `strtoul` with `llvm::to_integer` which avoids another std::string allocation. - Removed braces from single statement conditions, removed else-after-returns. Differential Revision: https://reviews.llvm.org/D154534
2023-05-22[lldb] Add support for negative integer to {SB,}StructuredDataMed Ismail Bennani
This patch refactors the `StructuredData::Integer` class to make it templated, makes it private and adds 2 public specialization for both `int64_t` & `uint64_t` with a public type aliases, respectively `SignedInteger` & `UnsignedInteger`. It adds new getter for signed and unsigned interger values to the `StructuredData::Object` base class and changes the implementation of `StructuredData::Array::GetItemAtIndexAsInteger` and `StructuredData::Dictionary::GetValueForKeyAsInteger` to support signed and unsigned integers. This patch also adds 2 new `Get{Signed,Unsigned}IntegerValue` to the `SBStructuredData` class and marks `GetIntegerValue` as deprecated. Finally, this patch audits all the caller of `StructuredData::Integer` or `StructuredData::GetIntegerValue` to use the proper type as well the various tests that uses `SBStructuredData.GetIntegerValue`. rdar://105575764 Differential Revision: https://reviews.llvm.org/D150485 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-04-17[lldb] Change parameter type of StructuredData::ParseJSONAlex Langford
Instead of taking a `const std::string &` we can take an `llvm::StringRef`. The motivation for this change is that many of the callers of `ParseJSON` end up creating a temporary `std::string` from an existing `StringRef` or `const char *` in order to satisfy the API. There's no reason we need to do this. Differential Revision: https://reviews.llvm.org/D148579
2023-02-17[lldb] StructuredData should not truncate uint64_t valuesAlex Langford
In json::Value, getAsInteger returns an optional<int64_t> and getAsNumber returns an optional<double>. If a value is larger than what an int64_t can hold but smaller than what a uint64_t can hold, the getAsInteger function will fail but the getAsNumber will succeed. However, the value shouldn't be interpreted as a double. rdar://105556974 Differential Revision: https://reviews.llvm.org/D144238
2022-11-03[lldb/Utility] Add GetDescription(Stream&) to StructureData::*Med Ismail Bennani
This patch improves the StructuredData classes to provide a GetDescription(lldb_private::Stream&) affordance. This is very convenient compared to the Dump method because this try to pretty print the structure instead of just serializing it into a JSON. This patch also updates some parts of lldb (i.e. extended crash info) to use this new affordance instead of StructuredData::Dump. Differential Revision: https://reviews.llvm.org/D135547 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-11-03[lldb/Utility] Fix StructuredData::ParseJSONValue for null itemsMed Ismail Bennani
This patch fixes the JSON parser for StructuredData to handle JSON null entries. Differential Revision: https://reviews.llvm.org/D135616 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2021-05-26[lldb][NFC] Use C++ versions of the deprecated C standard library headersRaphael Isemann
The C headers are deprecated so as requested in D102845, this is replacing them all with their (not deprecated) C++ equivalent. Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D103084
2020-09-24Fix LLDB tweak in 62a47e994fcf5b73e29547d26cd9676b30cb69a3Sam McCall
2020-09-24[JSON] Add error reporting to fromJSON and ObjectMapperSam McCall
Translating between JSON objects and C++ strutctures is common. From experience in clangd, fromJSON/ObjectMapper work well and save a lot of code, but aren't adopted elsewhere at least partly due to total lack of error reporting beyond "ok"/"bad". The recently-added error model should be rich enough for most applications. It requires tracking the path within the root object and reporting local errors at appropriate places. To do this, we exploit the fact that the call graph of recursive parse functions mirror the structure of the JSON itself. The current path is represented as a linked list of segments, each of which is on the stack as a parameter. Concretely, fromJSON now looks like: bool fromJSON(const Value&, T&, Path); Beyond the signature change, this is reasonably unobtrusive: building the path segments is mostly handled by ObjectMapper and the vector<T> fromJSON. However the root caller of fromJSON must now create a Root object to store the errors, which is a little clunky. I've added high-level parse<T>(StringRef) -> Expected<T>, but it's not general enough to be the primary interface I think (at least, not usable in clangd). All existing users (mostly just clangd) are updated in this patch, making this change backwards-compatible is a bit hairy. Differential Revision: https://reviews.llvm.org/D88103
2020-09-21Add a "Trace" plug-in to LLDB to add process trace support in stages.Walter Erquinigo
This is the first in a series of patches that will adds a new processor trace plug-in to LLDB. The idea for this first patch to to add the plug-in interface with simple commands for the trace files that can "load" and "dump" the trace information. We can test the functionality and ensure people are happy with the way things are done and how things are organized before moving on to adding more functionality. Processor trace information can be view in a few different ways: - post mortem where a trace is saved off that can be viewed later in the debugger - gathered while a process is running and allow the user to step back in time (with no variables, memory or registers) to see how each thread arrived at where it is currently stopped. This patch attempts to start with the first solution of loading a trace file after the fact. The idea is that we will use a JSON file to load the trace information. JSON allows us to specify information about the trace like: - plug-in name in LLDB - path to trace file - shared library load information so we can re-create a target and symbolicate the information in the trace - any other info that the trace plug-in will need to be able to successfully parse the trace information - cpu type - version info - ??? A new "trace" command was added at the top level of the LLDB commmands: - "trace load" - "trace dump" I did this because if we load trace information we don't need to have a process and we might end up creating a new target for the trace information that will become active. If anyone has any input on where this would be better suited, please let me know. Walter Erquinigo will end up filling in the Intel PT specific plug-in so that it works and is tested once we can agree that the direction of this patch is the correct one, so please feel free to chime in with ideas on comments! Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D85705
2020-07-22[lldb] Eliminate unneeded value parameters in Utility (NFC)Jonas Devlieghere
Eliminates value parameter for types that are not trivially copyable.
2020-02-11[lldb][NFC] Remove several inefficient ConstString -> const char * -> ↵Raphael Isemann
StringRef conversions StringRef will call strlen on the C string which is inefficient (as ConstString already knows the string lenght and so does StringRef). This patch replaces all those calls with GetStringRef() which doesn't recompute the length.
2020-01-24[lldb][NFC] Fix all formatting errors in .cpp file headersRaphael Isemann
Summary: A *.cpp file header in LLDB (and in LLDB) should like this: ``` //===-- TestUtilities.cpp -------------------------------------------------===// ``` However in LLDB most of our source files have arbitrary changes to this format and these changes are spreading through LLDB as folks usually just use the existing source files as templates for their new files (most notably the unnecessary editor language indicator `-*- C++ -*-` is spreading and in every review someone is pointing out that this is wrong, resulting in people pointing out that this is done in the same way in other files). This patch removes most of these inconsistencies including the editor language indicators, all the different missing/additional '-' characters, files that center the file name, missing trailing `===//` (mostly caused by clang-format breaking the line). Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere Reviewed By: JDevlieghere Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D73258
2020-01-13[lldb/Utility] Add std::move to make placate clang 3.8Jonas Devlieghere
This fixes an error thrown by clang 3.8 that no viable conversion from returned value to the function return type.
2019-12-13[lldb][NFC] Remove unused includes in Utility's source filesRaphael Isemann
2019-10-01[JSON] Use LLVM's library for decoding JSON in StructuredDataJonas Devlieghere
This patch replaces the hand-rolled JSON decoding in StructuredData with LLVM's JSON library. Differential revision: https://reviews.llvm.org/D68282 llvm-svn: 373360
2019-10-01[JSON] Use LLVM's library for encoding JSON in StructuredDataJonas Devlieghere
This patch replaces the hand-rolled JSON emission in StructuredData with LLVM's JSON library. Differential revision: https://reviews.llvm.org/D68248 llvm-svn: 373359
2019-08-14[LLDB] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368933
2019-05-24Fix integer literals which are cast to boolJonas Devlieghere
This change replaces built-in types that are implicitly converted to booleans. Differential revision: https://reviews.llvm.org/D62284 llvm-svn: 361580
2019-04-10[NFC] Remove ASCII lines from commentsJonas Devlieghere
A lot of comments in LLDB are surrounded by an ASCII line to delimit the begging and end of the comment. Its use is not really consistent across the code base, sometimes the lines are longer, sometimes they are shorter and sometimes they are omitted. Furthermore, it looks kind of weird with the 80 column limit, where the comment actually extends past the line, but not by much. Furthermore, when /// is used for Doxygen comments, it looks particularly odd. And when // is used, it incorrectly gives the impression that it's actually a Doxygen comment. I assume these lines were added to improve distinguishing between comments and code. However, given that todays editors and IDEs do a great job at highlighting comments, I think it's worth to drop this for the sake of consistency. The alternative is fixing all the inconsistencies, which would create a lot more churn. Differential revision: https://reviews.llvm.org/D60508 llvm-svn: 358135
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
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
2018-12-15Simplify Boolean expressionsJonas Devlieghere
This patch simplifies boolean expressions acorss LLDB. It was generated using clang-tidy with the following command: run-clang-tidy.py -checks='-*,readability-simplify-boolean-expr' -format -fix $PWD Differential revision: https://reviews.llvm.org/D55584 llvm-svn: 349215
2018-12-13[NFC] Small code cleanups in utility.Jonas Devlieghere
Fix a few small annoyances in Utility I ran into. llvm-svn: 348996
2018-11-11Remove comments after header includes.Jonas Devlieghere
This patch removes the comments following the header includes. They were added after running IWYU over the LLDB codebase. However they add little value, are often outdates and burdensome to maintain. Differential revision: https://reviews.llvm.org/D54385 llvm-svn: 346625
2018-11-01[FileSystem] Remove Exists() from FileSpecJonas Devlieghere
This patch removes the Exists method from FileSpec and updates its uses with calls to the FileSystem. Differential revision: https://reviews.llvm.org/D53845 llvm-svn: 345854
2018-04-30Reflow paragraphs in comments.Adrian Prantl
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
2017-11-17Fix LLDB build.Eugene Zemtsov
It was broken by r318489. llvm-svn: 318504
2017-06-27Move StructuredData from Core to UtilityPavel Labath
Summary: It had a dependency on StringConvert and file reading code, which is not in Utility. I've replaced that code by equivalent llvm operations. I've added a unit test to demonstrate that parsing a file still works. Reviewers: zturner, jingham Subscribers: kubamracek, mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D34625 llvm-svn: 306394