summaryrefslogtreecommitdiff
path: root/lldb/source/DataFormatters/StringPrinter.cpp
AgeCommit message (Collapse)Author
2024-10-24[lldb] Move ValueObject into its own library (NFC) (#113393)Jonas Devlieghere
ValueObject is part of lldbCore for historical reasons, but conceptually it deserves to be its own library. This does introduce a (link-time) circular dependency between lldbCore and lldbValueObject, which is unfortunate but probably unavoidable because so many things in LLDB rely on ValueObject. We already have cycles and these libraries are never built as dylibs so while this doesn't improve the situation, it also doesn't make things worse. The header includes were updated with the following command: ``` find . -type f -exec sed -i.bak "s%include \"lldb/Core/ValueObject%include \"lldb/ValueObject/ValueObject%" '{}' \; ```
2023-11-03[lldb][NFC] Use UNUSED_IF_ASSERT_DISABLED instead of (void) castDavid Spickett
Uses of (void) remain where they are for purposes other than an assert variable.
2023-03-30[lldb] Replace sprintf with snprintf (NFC)Dave Lee
On macOS, `sprintf` is deprecated, using `snprintf` is recommended instead. Differential Revision: https://reviews.llvm.org/D147246
2022-04-05[lldb] Refactor DataBuffer so we can map files as read-onlyJonas Devlieghere
Currently, all data buffers are assumed to be writable. This is a problem on macOS where it's not allowed to load unsigned binaries in memory as writable. To be more precise, MAP_RESILIENT_CODESIGN and MAP_RESILIENT_MEDIA need to be set for mapped (unsigned) binaries on our platform. Binaries are mapped through FileSystem::CreateDataBuffer which returns a DataBufferLLVM. The latter is backed by a llvm::WritableMemoryBuffer because every DataBuffer in LLDB is considered to be writable. In order to use a read-only llvm::MemoryBuffer I had to split our abstraction around it. This patch distinguishes between a DataBuffer (read-only) and WritableDataBuffer (read-write) and updates LLDB to use the appropriate one. rdar://74890607 Differential revision: https://reviews.llvm.org/D122856
2021-11-18[lldb] (Partially) enable formatting of utf strings before the program is ↵Pavel Labath
started The StringPrinter class was using a Process instance to read memory. This automatically prevented it from working before starting the program. This patch changes the class to use the Target object for reading memory, as targets are always available. This required moving ReadStringFromMemory from Process to Target. This is sufficient to make frame/target variable work, but further changes are necessary for the expression evaluator. Preliminary analysis indicates the failures are due to the expression result ValueObjects failing to provide an address, presumably because we're operating on file addresses before starting. I haven't looked into what would it take to make that work. Differential Revision: https://reviews.llvm.org/D113098
2021-08-04[nfc] [lldb] Prevent needless copies of DataExtractorJan Kratochvil
lldb_private::DataExtractor contains DataBufferSP m_data_sp which is relatively expensive to copy (due to multi-threading locking). llvm::DataExtractor does not have this problem as it uses StringRef instead. The copy constructor is explicit as otherwise it is easy to make unintended modification of a local copy instead of a caller's instance (D107470 but that is llvm::DataExtractor). Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D107485
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-06-03[lldb/StringPrinter] Support strings with invalid utf8 sub-sequencesVedant Kumar
Support printing strings which contain invalid utf8 sub-sequences, e.g. strings like "hello world \xfe", instead of bailing out with "Summary Unavailable". I took the opportunity here to delete some hand-rolled utf8 -> utf32 conversion code and replace it with calls into llvm's Support library. rdar://61554346
2020-06-03[lldb/StringPrinter] Convert DecodedCharBuffer to a class, NFCVedant Kumar
The m_size and m_data members of DecodedCharBuffer are meant to be private.
2020-05-04[lldb/DataFormatters] Delete GetStringPrinterEscapingHelperVedant Kumar
Summary: Languages can have different ways of formatting special characters. E.g. when debugging C++ code a string might look like "\b", but when debugging Swift code the same string would look like "\u{8}". To make this work, plugins override GetStringPrinterEscapingHelper. However, because there's a large amount of subtly divergent work done in each override, we end up with large amounts of duplicated code. And all the memory smashers fixed in one copy of the logic (see D73860) don't get fixed in the others. IMO the GetStringPrinterEscapingHelper is overly general and hard to use. I propose deleting it and replacing it with an EscapeStyle enum, which can be set as needed by each plugin. A fix for some swift-lldb memory smashers falls out fairly naturally from this deletion (https://github.com/apple/llvm-project/pull/1046). As the swift logic becomes really tiny, I propose moving it upstream as part of this change. I've added unit tests to cover it. rdar://61419673 Reviewers: JDevlieghere, davide Subscribers: mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D77843
2020-03-19Reland [lldb] Fix string summary of an empty NSPathStore2Raphael Isemann
(This is D68010 but I also set the new parameter in LibStdcpp.cpp to fix the Debian tests). Summary: Printing a summary for an empty NSPathStore2 string currently prints random bytes behind the empty string pointer from memory (rdar://55575888). It seems the reason for this is that the SourceSize parameter in the `ReadStringAndDumpToStreamOptions` - which is supposed to contain the string length - actually uses the length 0 as a magic value for saying "read as much as possible from the buffer" which is clearly wrong for empty strings. This patch adds another flag that indicates if we have know the string length or not and makes this behaviour dependent on that (which seemingly was the original purpose of this magic value). Reviewers: aprantl, JDevlieghere, shafik Reviewed By: aprantl Subscribers: christof, abidh, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68010
2020-03-19Revert "[lldb] Fix string summary of an empty NSPathStore2"Raphael Isemann
This reverts commit 939ca455e72e822450013eff37c9ea7746850350. This failed on the debian bot for some reason: File "/home/worker/lldb-x86_64-debian/lldb-x86_64-debian/llvm-project/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py", line 67, in test_with_run_command "s summary wrong") AssertionError: 'L"hello world! מזל טוב!\\0!\\0!!!!\\0\\0A\\0\\U0000fffd\\U0000fffd\\U0000fffd\\ [truncated]... != 'L"hello world! מזל טוב!"' Diff is 2156 characters long. Set self.maxDiff to None to see it. : s summary wrong
2020-03-19[lldb] Fix string summary of an empty NSPathStore2Raphael Isemann
Summary: Printing a summary for an empty NSPathStore2 string currently prints random bytes behind the empty string pointer from memory (rdar://55575888). It seems the reason for this is that the SourceSize parameter in the `ReadStringAndDumpToStreamOptions` - which is supposed to contain the string length - actually uses the length 0 as a magic value for saying "read as much as possible from the buffer" which is clearly wrong for empty strings. This patch adds another flag that indicates if we have know the string length or not and makes this behaviour dependent on that (which seemingly was the original purpose of this magic value). Reviewers: aprantl, JDevlieghere, shafik Reviewed By: aprantl Subscribers: christof, abidh, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68010
2020-02-12[lldb/StringPrinter] Avoid reading garbage in uninitialized stringsVedant Kumar
This patch fixes a few related out-of-bounds read bugs in the string data formatters. These issues have to do with mishandling of un- initialized strings. These manifest as ASan exceptions when debugging a clang binary. The first issue was that the std::string formatter treated strings in "short mode" with length greater than the size of the inline buffer as valid. The second issue was that the StringPrinter facility did not check that a full utf8 codepoint sequence can be read from the buffer (i.e. there are some missing range checks). I took the opportunity here to delete some untested code that was meant to deal with invalid input and replace it with fail-on-invalid logic ([1][2][3]). This means we'll give up on formatting an invalid string instead of guessing our way through it. The third issue is that StringPrinter did not check that a utf8 sequence could actually be fully read from the string payload. This one is especially tricky as we may overflow the buffer pointer while reading the sequence. I also noticed that the std::string formatter would spew the raw version of the underlying ValueObject when garbage is detected. I've changed this to just print "Summary Unavailable" instead, as we do elsewhere. I've added regression tests for these issues to test/functionalities/data-formatter/data-formatter-stl/libcxx/string. [1] http://lab.llvm.org:8080/coverage/coverage-reports/coverage/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/DataFormatters/StringPrinter.cpp.html#L136 [2] http://lab.llvm.org:8080/coverage/coverage-reports/coverage/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/DataFormatters/StringPrinter.cpp.html#L163 [3] http://lab.llvm.org:8080/coverage/coverage-reports/coverage/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/DataFormatters/StringPrinter.cpp.html#L357 rdar://59080026 Differential Revision: https://reviews.llvm.org/D73860
2020-02-03[lldb/StringPrinter] Simplify StringPrinterBufferPointer, NFCVedant Kumar
Remove its template arguments and delete its copy/assign methods.
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
2019-05-23[lldb] NFC modernize codebase with modernize-use-nullptrKonrad Kleine
Summary: NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]] This commit is the result of modernizing the LLDB codebase by using `nullptr` instread of `0` or `NULL`. See https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html for more information. This is the command I ran and I to fix and format the code base: ``` run-clang-tidy.py \ -header-filter='.*' \ -checks='-*,modernize-use-nullptr' \ -fix ~/dev/llvm-project/lldb/.* \ -format \ -style LLVM \ -p ~/llvm-builds/debug-ninja-gcc ``` NOTE: There were also changes to `llvm/utils/unittest` but I did not include them because I felt that maybe this library shall be updated in isolation somehow. NOTE: I know this is a rather large commit but it is a nobrainer in most parts. Reviewers: martong, espindola, shafik, #lldb, JDevlieghere Reviewed By: JDevlieghere Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits Tags: #lldb, #llvm Differential Revision: https://reviews.llvm.org/D61847 llvm-svn: 361484
2019-02-11Use std::make_shared in LLDB (NFC)Jonas Devlieghere
Unlike std::make_unique, which is only available since C++14, std::make_shared is available since C++11. Not only is std::make_shared a lot more readable compared to ::reset(new), it also performs a single heap allocation for the object and control block. Differential revision: https://reviews.llvm.org/D57990 llvm-svn: 353764
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-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-05-12Rename Error -> Status.Zachary Turner
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
2017-02-02Move classes from Core -> Utility.Zachary Turner
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
2016-10-05Make lldb -Werror clean on Windows.Zachary Turner
Differential Revision: https://reviews.llvm.org/D25247 llvm-svn: 283344
2016-09-30Move UTF functions into namespace llvm.Justin Lebar
Summary: This lets people link against LLVM and their own version of the UTF library. I determined this only affects llvm, clang, lld, and lldb by running $ git grep -wl 'UTF[0-9]\+\|\bConvertUTF\bisLegalUTF\|getNumBytesFor' | cut -f 1 -d '/' | sort | uniq clang lld lldb llvm Tested with ninja lldb ninja check-clang check-llvm check-lld (ninja check-lldb doesn't complete for me with or without this patch.) Reviewers: rnk Subscribers: klimek, beanz, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D24996 llvm-svn: 282822
2016-09-06*** This commit represents a complete reformatting of the LLDB source codeKate Stone
*** 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
2016-01-13Fix some compiler warnings with MSVC 2015.Zachary Turner
llvm-svn: 257671
2015-11-04Fix an issue where LLDB would truncate summaries for string types without ↵Enrico Granata
producing any evidence thereof llvm-svn: 252018
2015-10-20Rationalization of includes in the data formatters codeEnrico Granata
llvm-svn: 250798
2015-10-18Silence -Wreturn-type with gcc 5.2Saleem Abdulrasool
The switch is fully covered, mark "default" as unreachable. NFC. llvm-svn: 250667
2015-10-18Silence -Wqual-cast warnings from GCC 5.2Saleem Abdulrasool
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
2015-10-07Enable the StringPrinter to have prefixes that are strings instead of just a ↵Enrico Granata
single character; and also introduce a comparable suffix mechanism llvm-svn: 249506
2015-09-09Introduce the notion of an escape helper. Different languages have different ↵Enrico Granata
notion of what to print in a string and how to escape non-printable things. The escape helper is where this notion is provided to LLDB This is NFC, other than a code re-org llvm-svn: 247200
2015-09-09Preparatory work for letting language plugins help the StringPrinter with ↵Enrico Granata
formatting special characters llvm-svn: 247189
2015-07-17Teach the std::wstring data formatter how to properly display strings with ↵Enrico Granata
embedded NUL bytes llvm-svn: 242501
2015-07-17Add StringPrinter support for printing a std::string with embedded NUL bytesEnrico Granata
llvm-svn: 242496
2015-05-13Fixed a ton of gcc compile warningsVince Harron
Removed some unused variables, added some consts, changed some casts to const_cast. I don't think any of these changes are very controversial. Differential Revision: http://reviews.llvm.org/D9674 llvm-svn: 237218
2015-05-01Fix an issue where the UTF dumper was ignoring the direction to generate ↵Enrico Granata
uncapped dumps llvm-svn: 236362
2014-12-29Fix trivial signed/unsigned comparison warningsAndy Gibbs
llvm-svn: 224932
2014-12-18We don't really handle printing embedded NULs in strings, but if we were to, ↵Enrico Granata
we would need to have this logic inside the StringPrinter. So, add it.. For, you know, one day in the future where we might want to handle embedded NULs in strings... llvm-svn: 224537
2014-11-18Add the ability for the NSString and libc++ std::string formatters to ↵Enrico Granata
retrieve uncapped data llvm-svn: 222277
2014-11-17Fix a problem where the StringPrinter could be mistaking an empty string for ↵Enrico Granata
a read error, and reporting spurious 'unable to read data' messages. rdar://19007243 llvm-svn: 222190
2014-11-05Add a setting escape-non-printables that drives whether the StringPrinter ↵Enrico Granata
should or should not escape sequences such as \t, \n, .. and generally any non-printing character The recent StringPrinter changes made this behavior the default, and the setting defaults to yes If you want to change this behavior and see non-printables unescaped (e.g. "a\tb" as "a b"), set it to false Fixes rdar://12969594 llvm-svn: 221399
2014-11-04for Siva Chandra: Fix compilation of StringPrinter.cpp with GCC. ↵Shawn Best
Differential Revision: http://reviews.llvm.org/D6122 llvm-svn: 221310
2014-10-30Remove #include <codecvt>. It isn't supported on all compilers.Zachary Turner
Also it wasn't being used anyway, so it appears to be a dead include. llvm-svn: 220921
2014-10-30Start adopting the StringPrinter API. The StringPrinter API is the new ↵Enrico Granata
blessed way of printing strings that supports escaping non-printables, and has better handling of different UTF encodings llvm-svn: 220894