2014-10-30 09:45:39 +08:00
|
|
|
//===-- StringPrinter.cpp ----------------------------------------*- C++
|
|
|
|
//-*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-10-30 09:45:39 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/DataFormatters/StringPrinter.h"
|
|
|
|
|
2014-11-06 05:20:48 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
|
|
|
#include "lldb/Core/ValueObject.h"
|
2015-09-10 06:30:24 +08:00
|
|
|
#include "lldb/Target/Language.h"
|
2014-10-30 09:45:39 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2014-10-30 09:45:39 +08:00
|
|
|
|
|
|
|
#include "llvm/Support/ConvertUTF.h"
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <locale>
|
2019-02-12 07:13:08 +08:00
|
|
|
#include <memory>
|
2014-10-30 09:45:39 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
using namespace lldb_private::formatters;
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// we define this for all values of type but only implement it for those we
|
|
|
|
// care about that's good because we get linker errors for any unsupported type
|
2015-09-10 06:30:24 +08:00
|
|
|
template <lldb_private::formatters::StringPrinter::StringElementType type>
|
2015-09-10 04:59:49 +08:00
|
|
|
static StringPrinter::StringPrinterBufferPointer<>
|
2014-10-30 09:45:39 +08:00
|
|
|
GetPrintableImpl(uint8_t *buffer, uint8_t *buffer_end, uint8_t *&next);
|
|
|
|
|
|
|
|
// mimic isprint() for Unicode codepoints
|
|
|
|
static bool isprint(char32_t codepoint) {
|
|
|
|
if (codepoint <= 0x1F || codepoint == 0x7F) // C0
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (codepoint >= 0x80 && codepoint <= 0x9F) // C1
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (codepoint == 0x2028 || codepoint == 0x2029) // line/paragraph separators
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (codepoint == 0x200E || codepoint == 0x200F ||
|
|
|
|
(codepoint >= 0x202A &&
|
|
|
|
codepoint <= 0x202E)) // bidirectional text control
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (codepoint >= 0xFFF9 &&
|
|
|
|
codepoint <= 0xFFFF) // interlinears and generally specials
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 04:59:49 +08:00
|
|
|
StringPrinter::StringPrinterBufferPointer<>
|
2015-09-10 06:30:24 +08:00
|
|
|
GetPrintableImpl<StringPrinter::StringElementType::ASCII>(uint8_t *buffer,
|
|
|
|
uint8_t *buffer_end,
|
|
|
|
uint8_t *&next) {
|
2015-09-10 04:59:49 +08:00
|
|
|
StringPrinter::StringPrinterBufferPointer<> retval = {nullptr};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
switch (*buffer) {
|
2014-12-19 03:43:29 +08:00
|
|
|
case 0:
|
|
|
|
retval = {"\\0", 2};
|
|
|
|
break;
|
2014-10-30 09:45:39 +08:00
|
|
|
case '\a':
|
|
|
|
retval = {"\\a", 2};
|
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
retval = {"\\b", 2};
|
|
|
|
break;
|
|
|
|
case '\f':
|
|
|
|
retval = {"\\f", 2};
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
retval = {"\\n", 2};
|
|
|
|
break;
|
|
|
|
case '\r':
|
|
|
|
retval = {"\\r", 2};
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
retval = {"\\t", 2};
|
|
|
|
break;
|
|
|
|
case '\v':
|
|
|
|
retval = {"\\v", 2};
|
|
|
|
break;
|
|
|
|
case '\"':
|
|
|
|
retval = {"\\\"", 2};
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
retval = {"\\\\", 2};
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (isprint(*buffer))
|
2015-05-13 08:25:54 +08:00
|
|
|
retval = {buffer, 1};
|
2014-10-30 09:45:39 +08:00
|
|
|
else {
|
2015-05-13 08:25:54 +08:00
|
|
|
uint8_t *data = new uint8_t[5];
|
|
|
|
sprintf((char *)data, "\\x%02x", *buffer);
|
|
|
|
retval = {data, 4, [](const uint8_t *c) { delete[] c; }};
|
|
|
|
break;
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
next = buffer + 1;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1) {
|
|
|
|
return (c0 - 192) * 64 + (c1 - 128);
|
|
|
|
}
|
|
|
|
static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1,
|
|
|
|
unsigned char c2) {
|
|
|
|
return (c0 - 224) * 4096 + (c1 - 128) * 64 + (c2 - 128);
|
|
|
|
}
|
|
|
|
static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1,
|
|
|
|
unsigned char c2, unsigned char c3) {
|
|
|
|
return (c0 - 240) * 262144 + (c2 - 128) * 4096 + (c2 - 128) * 64 + (c3 - 128);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 04:59:49 +08:00
|
|
|
StringPrinter::StringPrinterBufferPointer<>
|
2015-09-10 06:30:24 +08:00
|
|
|
GetPrintableImpl<StringPrinter::StringElementType::UTF8>(uint8_t *buffer,
|
|
|
|
uint8_t *buffer_end,
|
|
|
|
uint8_t *&next) {
|
2015-09-10 04:59:49 +08:00
|
|
|
StringPrinter::StringPrinterBufferPointer<> retval{nullptr};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-30 08:38:45 +08:00
|
|
|
unsigned utf8_encoded_len = llvm::getNumBytesForUTF8(*buffer);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-10-06 01:07:34 +08:00
|
|
|
if (1u + std::distance(buffer, buffer_end) < utf8_encoded_len) {
|
2014-10-30 09:45:39 +08:00
|
|
|
// I don't have enough bytes - print whatever I have left
|
|
|
|
retval = {buffer, static_cast<size_t>(1 + buffer_end - buffer)};
|
|
|
|
next = buffer_end + 1;
|
|
|
|
return retval;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
char32_t codepoint = 0;
|
|
|
|
switch (utf8_encoded_len) {
|
|
|
|
case 1:
|
|
|
|
// this is just an ASCII byte - ask ASCII
|
2015-09-10 06:30:24 +08:00
|
|
|
return GetPrintableImpl<StringPrinter::StringElementType::ASCII>(
|
|
|
|
buffer, buffer_end, next);
|
2014-10-30 09:45:39 +08:00
|
|
|
case 2:
|
|
|
|
codepoint = ConvertUTF8ToCodePoint((unsigned char)*buffer,
|
|
|
|
(unsigned char)*(buffer + 1));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
codepoint = ConvertUTF8ToCodePoint((unsigned char)*buffer,
|
|
|
|
(unsigned char)*(buffer + 1),
|
|
|
|
(unsigned char)*(buffer + 2));
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2014-10-30 09:45:39 +08:00
|
|
|
codepoint = ConvertUTF8ToCodePoint(
|
|
|
|
(unsigned char)*buffer, (unsigned char)*(buffer + 1),
|
|
|
|
(unsigned char)*(buffer + 2), (unsigned char)*(buffer + 3));
|
|
|
|
break;
|
|
|
|
default:
|
2018-05-01 00:49:04 +08:00
|
|
|
// this is probably some bogus non-character thing just print it as-is and
|
|
|
|
// hope to sync up again soon
|
2014-10-30 09:45:39 +08:00
|
|
|
retval = {buffer, 1};
|
|
|
|
next = buffer + 1;
|
|
|
|
return retval;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
if (codepoint) {
|
|
|
|
switch (codepoint) {
|
2014-12-19 03:43:29 +08:00
|
|
|
case 0:
|
|
|
|
retval = {"\\0", 2};
|
|
|
|
break;
|
2014-10-30 09:45:39 +08:00
|
|
|
case '\a':
|
|
|
|
retval = {"\\a", 2};
|
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
retval = {"\\b", 2};
|
|
|
|
break;
|
|
|
|
case '\f':
|
|
|
|
retval = {"\\f", 2};
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
retval = {"\\n", 2};
|
|
|
|
break;
|
|
|
|
case '\r':
|
|
|
|
retval = {"\\r", 2};
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
retval = {"\\t", 2};
|
|
|
|
break;
|
|
|
|
case '\v':
|
|
|
|
retval = {"\\v", 2};
|
|
|
|
break;
|
|
|
|
case '\"':
|
|
|
|
retval = {"\\\"", 2};
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
retval = {"\\\\", 2};
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (isprint(codepoint))
|
|
|
|
retval = {buffer, utf8_encoded_len};
|
|
|
|
else {
|
2015-05-13 08:25:54 +08:00
|
|
|
uint8_t *data = new uint8_t[11];
|
2016-01-14 05:22:00 +08:00
|
|
|
sprintf((char *)data, "\\U%08x", (unsigned)codepoint);
|
2015-05-13 08:25:54 +08:00
|
|
|
retval = {data, 10, [](const uint8_t *c) { delete[] c; }};
|
2014-10-30 09:45:39 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
next = buffer + utf8_encoded_len;
|
|
|
|
return retval;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
// this should not happen - but just in case.. try to resync at some point
|
|
|
|
retval = {buffer, 1};
|
|
|
|
next = buffer + 1;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Given a sequence of bytes, this function returns: a sequence of bytes to
|
|
|
|
// actually print out + a length the following unscanned position of the buffer
|
|
|
|
// is in next
|
2015-09-10 04:59:49 +08:00
|
|
|
static StringPrinter::StringPrinterBufferPointer<>
|
2015-09-10 06:30:24 +08:00
|
|
|
GetPrintable(StringPrinter::StringElementType type, uint8_t *buffer,
|
|
|
|
uint8_t *buffer_end, uint8_t *&next) {
|
2014-10-30 09:45:39 +08:00
|
|
|
if (!buffer)
|
|
|
|
return {nullptr};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
switch (type) {
|
2015-09-10 06:30:24 +08:00
|
|
|
case StringPrinter::StringElementType::ASCII:
|
|
|
|
return GetPrintableImpl<StringPrinter::StringElementType::ASCII>(
|
|
|
|
buffer, buffer_end, next);
|
|
|
|
case StringPrinter::StringElementType::UTF8:
|
|
|
|
return GetPrintableImpl<StringPrinter::StringElementType::UTF8>(
|
|
|
|
buffer, buffer_end, next);
|
2014-10-30 09:45:39 +08:00
|
|
|
default:
|
|
|
|
return {nullptr};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-10 06:30:24 +08:00
|
|
|
StringPrinter::EscapingHelper
|
|
|
|
StringPrinter::GetDefaultEscapingHelper(GetPrintableElementType elem_type) {
|
|
|
|
switch (elem_type) {
|
|
|
|
case GetPrintableElementType::UTF8:
|
|
|
|
return [](uint8_t *buffer, uint8_t *buffer_end,
|
|
|
|
uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer<> {
|
|
|
|
return GetPrintable(StringPrinter::StringElementType::UTF8, buffer,
|
|
|
|
buffer_end, next);
|
|
|
|
};
|
|
|
|
case GetPrintableElementType::ASCII:
|
|
|
|
return [](uint8_t *buffer, uint8_t *buffer_end,
|
|
|
|
uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer<> {
|
|
|
|
return GetPrintable(StringPrinter::StringElementType::ASCII, buffer,
|
|
|
|
buffer_end, next);
|
|
|
|
};
|
|
|
|
}
|
2015-10-19 04:51:18 +08:00
|
|
|
llvm_unreachable("bad element type");
|
2015-09-10 06:30:24 +08:00
|
|
|
}
|
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
// use this call if you already have an LLDB-side buffer for the data
|
|
|
|
template <typename SourceDataType>
|
|
|
|
static bool DumpUTFBufferToStream(
|
2016-09-30 08:38:45 +08:00
|
|
|
llvm::ConversionResult (*ConvertFunction)(const SourceDataType **,
|
|
|
|
const SourceDataType *,
|
|
|
|
llvm::UTF8 **, llvm::UTF8 *,
|
|
|
|
llvm::ConversionFlags),
|
2015-09-10 06:30:24 +08:00
|
|
|
const StringPrinter::ReadBufferAndDumpToStreamOptions &dump_options) {
|
2015-07-17 09:03:59 +08:00
|
|
|
Stream &stream(*dump_options.GetStream());
|
[lldb] NFC modernize codebase with modernize-use-nullptr
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-05-23 19:14:47 +08:00
|
|
|
if (dump_options.GetPrefixToken() != nullptr)
|
2015-10-07 10:06:48 +08:00
|
|
|
stream.Printf("%s", dump_options.GetPrefixToken());
|
2015-07-17 09:03:59 +08:00
|
|
|
if (dump_options.GetQuote() != 0)
|
|
|
|
stream.Printf("%c", dump_options.GetQuote());
|
|
|
|
auto data(dump_options.GetData());
|
2015-05-13 08:25:54 +08:00
|
|
|
auto source_size(dump_options.GetSourceSize());
|
|
|
|
if (data.GetByteSize() && data.GetDataStart() && data.GetDataEnd()) {
|
2015-07-17 09:03:59 +08:00
|
|
|
const int bufferSPSize = data.GetByteSize();
|
|
|
|
if (dump_options.GetSourceSize() == 0) {
|
|
|
|
const int origin_encoding = 8 * sizeof(SourceDataType);
|
|
|
|
source_size = bufferSPSize / (origin_encoding / 4);
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-07-17 09:03:59 +08:00
|
|
|
const SourceDataType *data_ptr =
|
|
|
|
(const SourceDataType *)data.GetDataStart();
|
2014-10-30 09:45:39 +08:00
|
|
|
const SourceDataType *data_end_ptr = data_ptr + source_size;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-07-17 09:03:59 +08:00
|
|
|
const bool zero_is_terminator = dump_options.GetBinaryZeroIsTerminator();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-10 06:30:24 +08:00
|
|
|
if (zero_is_terminator) {
|
|
|
|
while (data_ptr < data_end_ptr) {
|
|
|
|
if (!*data_ptr) {
|
|
|
|
data_end_ptr = data_ptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2015-09-10 06:30:24 +08:00
|
|
|
}
|
2014-10-30 09:45:39 +08:00
|
|
|
data_ptr++;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
data_ptr = (const SourceDataType *)data.GetDataStart();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
lldb::DataBufferSP utf8_data_buffer_sp;
|
2016-09-30 08:38:45 +08:00
|
|
|
llvm::UTF8 *utf8_data_ptr = nullptr;
|
|
|
|
llvm::UTF8 *utf8_data_end_ptr = nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
if (ConvertFunction) {
|
2019-02-12 07:13:08 +08:00
|
|
|
utf8_data_buffer_sp =
|
|
|
|
std::make_shared<DataBufferHeap>(4 * bufferSPSize, 0);
|
2016-09-30 08:38:45 +08:00
|
|
|
utf8_data_ptr = (llvm::UTF8 *)utf8_data_buffer_sp->GetBytes();
|
2015-09-10 06:30:24 +08:00
|
|
|
utf8_data_end_ptr = utf8_data_ptr + utf8_data_buffer_sp->GetByteSize();
|
|
|
|
ConvertFunction(&data_ptr, data_end_ptr, &utf8_data_ptr,
|
2016-09-30 08:38:45 +08:00
|
|
|
utf8_data_end_ptr, llvm::lenientConversion);
|
2018-12-15 08:15:33 +08:00
|
|
|
if (!zero_is_terminator)
|
2014-10-30 09:45:39 +08:00
|
|
|
utf8_data_end_ptr = utf8_data_ptr;
|
2016-09-30 08:38:45 +08:00
|
|
|
// needed because the ConvertFunction will change the value of the
|
|
|
|
// data_ptr.
|
2014-10-30 09:45:39 +08:00
|
|
|
utf8_data_ptr =
|
2016-09-30 08:38:45 +08:00
|
|
|
(llvm::UTF8 *)utf8_data_buffer_sp->GetBytes();
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2014-10-30 09:45:39 +08:00
|
|
|
// just copy the pointers - the cast is necessary to make the compiler
|
2018-05-01 00:49:04 +08:00
|
|
|
// happy but this should only happen if we are reading UTF8 data
|
2016-09-30 08:38:45 +08:00
|
|
|
utf8_data_ptr = const_cast<llvm::UTF8 *>(
|
|
|
|
reinterpret_cast<const llvm::UTF8 *>(data_ptr));
|
|
|
|
utf8_data_end_ptr = const_cast<llvm::UTF8 *>(
|
|
|
|
reinterpret_cast<const llvm::UTF8 *>(data_end_ptr));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-09-10 06:30:24 +08:00
|
|
|
const bool escape_non_printables = dump_options.GetEscapeNonPrintables();
|
2014-10-30 09:45:39 +08:00
|
|
|
lldb_private::formatters::StringPrinter::EscapingHelper escaping_callback;
|
2015-09-10 06:30:24 +08:00
|
|
|
if (escape_non_printables) {
|
2014-10-30 09:45:39 +08:00
|
|
|
if (Language *language = Language::FindPlugin(dump_options.GetLanguage()))
|
2015-09-10 06:30:24 +08:00
|
|
|
escaping_callback = language->GetStringPrinterEscapingHelper(
|
2014-10-30 09:45:39 +08:00
|
|
|
lldb_private::formatters::StringPrinter::GetPrintableElementType::
|
2016-09-07 04:57:50 +08:00
|
|
|
UTF8);
|
|
|
|
else
|
2015-09-10 06:30:24 +08:00
|
|
|
escaping_callback =
|
2014-10-30 09:45:39 +08:00
|
|
|
lldb_private::formatters::StringPrinter::GetDefaultEscapingHelper(
|
2015-09-10 06:30:24 +08:00
|
|
|
lldb_private::formatters::StringPrinter::
|
2014-10-30 09:45:39 +08:00
|
|
|
GetPrintableElementType::UTF8);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
// since we tend to accept partial data (and even partially malformed data)
|
2018-05-01 00:49:04 +08:00
|
|
|
// we might end up with no NULL terminator before the end_ptr hence we need
|
|
|
|
// to take a slower route and ensure we stay within boundaries
|
2014-10-30 09:45:39 +08:00
|
|
|
for (; utf8_data_ptr < utf8_data_end_ptr;) {
|
2015-07-17 09:03:59 +08:00
|
|
|
if (zero_is_terminator && !*utf8_data_ptr)
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
if (escape_non_printables) {
|
|
|
|
uint8_t *next_data = nullptr;
|
|
|
|
auto printable =
|
|
|
|
escaping_callback(utf8_data_ptr, utf8_data_end_ptr, next_data);
|
|
|
|
auto printable_bytes = printable.GetBytes();
|
|
|
|
auto printable_size = printable.GetSize();
|
|
|
|
if (!printable_bytes || !next_data) {
|
2014-11-05 06:43:34 +08:00
|
|
|
// GetPrintable() failed on us - print one byte in a desperate resync
|
|
|
|
// attempt
|
2014-10-30 09:45:39 +08:00
|
|
|
printable_bytes = utf8_data_ptr;
|
2014-11-05 06:43:34 +08:00
|
|
|
printable_size = 1;
|
2014-10-30 09:45:39 +08:00
|
|
|
next_data = utf8_data_ptr + 1;
|
|
|
|
}
|
2014-12-29 21:03:19 +08:00
|
|
|
for (unsigned c = 0; c < printable_size; c++)
|
2014-10-30 09:45:39 +08:00
|
|
|
stream.Printf("%c", *(printable_bytes + c));
|
|
|
|
utf8_data_ptr = (uint8_t *)next_data;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2014-10-30 09:45:39 +08:00
|
|
|
stream.Printf("%c", *utf8_data_ptr);
|
|
|
|
utf8_data_ptr++;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-07-17 09:03:59 +08:00
|
|
|
if (dump_options.GetQuote() != 0)
|
|
|
|
stream.Printf("%c", dump_options.GetQuote());
|
[lldb] NFC modernize codebase with modernize-use-nullptr
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-05-23 19:14:47 +08:00
|
|
|
if (dump_options.GetSuffixToken() != nullptr)
|
2015-10-07 10:06:48 +08:00
|
|
|
stream.Printf("%s", dump_options.GetSuffixToken());
|
2015-11-04 08:02:08 +08:00
|
|
|
if (dump_options.GetIsTruncated())
|
|
|
|
stream.Printf("...");
|
2014-10-30 09:45:39 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-10 06:30:24 +08:00
|
|
|
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::
|
|
|
|
ReadStringAndDumpToStreamOptions(ValueObject &valobj)
|
2014-11-06 05:20:48 +08:00
|
|
|
: ReadStringAndDumpToStreamOptions() {
|
|
|
|
SetEscapeNonPrintables(
|
|
|
|
valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables());
|
|
|
|
}
|
|
|
|
|
2015-09-10 06:30:24 +08:00
|
|
|
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::
|
|
|
|
ReadBufferAndDumpToStreamOptions(ValueObject &valobj)
|
2014-11-06 05:20:48 +08:00
|
|
|
: ReadBufferAndDumpToStreamOptions() {
|
|
|
|
SetEscapeNonPrintables(
|
|
|
|
valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables());
|
|
|
|
}
|
|
|
|
|
2015-09-10 06:30:24 +08:00
|
|
|
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::
|
|
|
|
ReadBufferAndDumpToStreamOptions(
|
|
|
|
const ReadStringAndDumpToStreamOptions &options)
|
2015-07-17 09:03:59 +08:00
|
|
|
: ReadBufferAndDumpToStreamOptions() {
|
|
|
|
SetStream(options.GetStream());
|
|
|
|
SetPrefixToken(options.GetPrefixToken());
|
2015-10-07 10:06:48 +08:00
|
|
|
SetSuffixToken(options.GetSuffixToken());
|
2015-07-17 09:03:59 +08:00
|
|
|
SetQuote(options.GetQuote());
|
|
|
|
SetEscapeNonPrintables(options.GetEscapeNonPrintables());
|
|
|
|
SetBinaryZeroIsTerminator(options.GetBinaryZeroIsTerminator());
|
2015-09-10 06:30:24 +08:00
|
|
|
SetLanguage(options.GetLanguage());
|
2015-07-17 09:03:59 +08:00
|
|
|
}
|
|
|
|
|
2014-11-05 06:43:34 +08:00
|
|
|
namespace lldb_private {
|
2014-11-06 05:20:48 +08:00
|
|
|
|
2014-11-05 06:43:34 +08:00
|
|
|
namespace formatters {
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 06:30:24 +08:00
|
|
|
bool StringPrinter::ReadStringAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::ASCII>(
|
|
|
|
const ReadStringAndDumpToStreamOptions &options) {
|
2014-11-05 06:43:34 +08:00
|
|
|
assert(options.GetStream() && "need a Stream to print the string to");
|
2017-05-12 12:51:55 +08:00
|
|
|
Status my_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-11-05 06:43:34 +08:00
|
|
|
ProcessSP process_sp(options.GetProcessSP());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-11-05 06:43:34 +08:00
|
|
|
if (process_sp.get() == nullptr || options.GetLocation() == 0)
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-11-05 06:43:34 +08:00
|
|
|
size_t size;
|
2015-11-04 08:02:08 +08:00
|
|
|
const auto max_size = process_sp->GetTarget().GetMaximumSizeOfStringSummary();
|
|
|
|
bool is_truncated = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-11-05 06:43:34 +08:00
|
|
|
if (options.GetSourceSize() == 0)
|
2015-11-04 08:02:08 +08:00
|
|
|
size = max_size;
|
2014-11-19 06:54:45 +08:00
|
|
|
else if (!options.GetIgnoreMaxLength()) {
|
2015-11-04 08:02:08 +08:00
|
|
|
size = options.GetSourceSize();
|
|
|
|
if (size > max_size) {
|
|
|
|
size = max_size;
|
|
|
|
is_truncated = true;
|
|
|
|
}
|
2014-11-19 06:54:45 +08:00
|
|
|
} else
|
|
|
|
size = options.GetSourceSize();
|
2014-11-05 06:43:34 +08:00
|
|
|
|
|
|
|
lldb::DataBufferSP buffer_sp(new DataBufferHeap(size, 0));
|
|
|
|
|
2015-05-13 08:25:54 +08:00
|
|
|
process_sp->ReadCStringFromMemory(
|
|
|
|
options.GetLocation(), (char *)buffer_sp->GetBytes(), size, my_error);
|
2014-11-05 06:43:34 +08:00
|
|
|
|
|
|
|
if (my_error.Fail())
|
|
|
|
return false;
|
|
|
|
|
2015-10-07 10:06:48 +08:00
|
|
|
const char *prefix_token = options.GetPrefixToken();
|
2014-11-05 06:43:34 +08:00
|
|
|
char quote = options.GetQuote();
|
|
|
|
|
[lldb] NFC modernize codebase with modernize-use-nullptr
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-05-23 19:14:47 +08:00
|
|
|
if (prefix_token != nullptr)
|
2015-10-07 10:06:48 +08:00
|
|
|
options.GetStream()->Printf("%s%c", prefix_token, quote);
|
2014-11-05 06:43:34 +08:00
|
|
|
else if (quote != 0)
|
|
|
|
options.GetStream()->Printf("%c", quote);
|
|
|
|
|
|
|
|
uint8_t *data_end = buffer_sp->GetBytes() + buffer_sp->GetByteSize();
|
|
|
|
|
2015-09-10 06:30:24 +08:00
|
|
|
const bool escape_non_printables = options.GetEscapeNonPrintables();
|
|
|
|
lldb_private::formatters::StringPrinter::EscapingHelper escaping_callback;
|
|
|
|
if (escape_non_printables) {
|
|
|
|
if (Language *language = Language::FindPlugin(options.GetLanguage()))
|
|
|
|
escaping_callback = language->GetStringPrinterEscapingHelper(
|
|
|
|
lldb_private::formatters::StringPrinter::GetPrintableElementType::
|
|
|
|
ASCII);
|
|
|
|
else
|
|
|
|
escaping_callback =
|
|
|
|
lldb_private::formatters::StringPrinter::GetDefaultEscapingHelper(
|
|
|
|
lldb_private::formatters::StringPrinter::GetPrintableElementType::
|
|
|
|
ASCII);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-11-05 06:43:34 +08:00
|
|
|
// since we tend to accept partial data (and even partially malformed data)
|
2018-05-01 00:49:04 +08:00
|
|
|
// we might end up with no NULL terminator before the end_ptr hence we need
|
|
|
|
// to take a slower route and ensure we stay within boundaries
|
2014-11-05 06:43:34 +08:00
|
|
|
for (uint8_t *data = buffer_sp->GetBytes(); *data && (data < data_end);) {
|
2015-09-10 06:30:24 +08:00
|
|
|
if (escape_non_printables) {
|
2014-11-05 06:43:34 +08:00
|
|
|
uint8_t *next_data = nullptr;
|
2015-09-10 06:30:24 +08:00
|
|
|
auto printable = escaping_callback(data, data_end, next_data);
|
2014-11-05 06:43:34 +08:00
|
|
|
auto printable_bytes = printable.GetBytes();
|
|
|
|
auto printable_size = printable.GetSize();
|
|
|
|
if (!printable_bytes || !next_data) {
|
|
|
|
// GetPrintable() failed on us - print one byte in a desperate resync
|
|
|
|
// attempt
|
|
|
|
printable_bytes = data;
|
|
|
|
printable_size = 1;
|
|
|
|
next_data = data + 1;
|
|
|
|
}
|
2014-12-29 21:03:19 +08:00
|
|
|
for (unsigned c = 0; c < printable_size; c++)
|
2014-11-05 06:43:34 +08:00
|
|
|
options.GetStream()->Printf("%c", *(printable_bytes + c));
|
|
|
|
data = (uint8_t *)next_data;
|
|
|
|
} else {
|
|
|
|
options.GetStream()->Printf("%c", *data);
|
|
|
|
data++;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-07 10:06:48 +08:00
|
|
|
const char *suffix_token = options.GetSuffixToken();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
[lldb] NFC modernize codebase with modernize-use-nullptr
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-05-23 19:14:47 +08:00
|
|
|
if (suffix_token != nullptr)
|
2015-10-07 10:06:48 +08:00
|
|
|
options.GetStream()->Printf("%c%s", quote, suffix_token);
|
|
|
|
else if (quote != 0)
|
2014-11-05 06:43:34 +08:00
|
|
|
options.GetStream()->Printf("%c", quote);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-04 08:02:08 +08:00
|
|
|
if (is_truncated)
|
|
|
|
options.GetStream()->Printf("...");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-11-05 06:43:34 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
template <typename SourceDataType>
|
2015-09-10 06:30:24 +08:00
|
|
|
static bool ReadUTFBufferAndDumpToStream(
|
|
|
|
const StringPrinter::ReadStringAndDumpToStreamOptions &options,
|
2016-09-30 08:38:45 +08:00
|
|
|
llvm::ConversionResult (*ConvertFunction)(const SourceDataType **,
|
|
|
|
const SourceDataType *,
|
|
|
|
llvm::UTF8 **, llvm::UTF8 *,
|
|
|
|
llvm::ConversionFlags)) {
|
2014-10-30 09:45:39 +08:00
|
|
|
assert(options.GetStream() && "need a Stream to print the string to");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
if (options.GetLocation() == 0 ||
|
|
|
|
options.GetLocation() == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
lldb::ProcessSP process_sp(options.GetProcessSP());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
if (!process_sp)
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
const int type_width = sizeof(SourceDataType);
|
|
|
|
const int origin_encoding = 8 * type_width;
|
|
|
|
if (origin_encoding != 8 && origin_encoding != 16 && origin_encoding != 32)
|
|
|
|
return false;
|
|
|
|
// if not UTF8, I need a conversion function to return proper UTF8
|
|
|
|
if (origin_encoding != 8 && !ConvertFunction)
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
if (!options.GetStream())
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
uint32_t sourceSize = options.GetSourceSize();
|
|
|
|
bool needs_zero_terminator = options.GetNeedsZeroTermination();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-04 08:02:08 +08:00
|
|
|
bool is_truncated = false;
|
|
|
|
const auto max_size = process_sp->GetTarget().GetMaximumSizeOfStringSummary();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
if (!sourceSize) {
|
2015-11-04 08:02:08 +08:00
|
|
|
sourceSize = max_size;
|
2014-10-30 09:45:39 +08:00
|
|
|
needs_zero_terminator = true;
|
2015-05-02 06:57:38 +08:00
|
|
|
} else if (!options.GetIgnoreMaxLength()) {
|
2015-11-04 08:02:08 +08:00
|
|
|
if (sourceSize > max_size) {
|
|
|
|
sourceSize = max_size;
|
|
|
|
is_truncated = true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
const int bufferSPSize = sourceSize * type_width;
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
lldb::DataBufferSP buffer_sp(new DataBufferHeap(bufferSPSize, 0));
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
if (!buffer_sp->GetBytes())
|
|
|
|
return false;
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2014-10-30 09:45:39 +08:00
|
|
|
char *buffer = reinterpret_cast<char *>(buffer_sp->GetBytes());
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
if (needs_zero_terminator)
|
2015-05-13 08:25:54 +08:00
|
|
|
process_sp->ReadStringFromMemory(options.GetLocation(), buffer,
|
|
|
|
bufferSPSize, error, type_width);
|
2014-10-30 09:45:39 +08:00
|
|
|
else
|
2015-05-13 08:25:54 +08:00
|
|
|
process_sp->ReadMemoryFromInferior(options.GetLocation(),
|
|
|
|
(char *)buffer_sp->GetBytes(),
|
|
|
|
bufferSPSize, error);
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2014-11-18 07:14:11 +08:00
|
|
|
if (error.Fail()) {
|
2014-10-30 09:45:39 +08:00
|
|
|
options.GetStream()->Printf("unable to read data");
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-30 09:45:39 +08:00
|
|
|
DataExtractor data(buffer_sp, process_sp->GetByteOrder(),
|
|
|
|
process_sp->GetAddressByteSize());
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2015-09-10 06:30:24 +08:00
|
|
|
StringPrinter::ReadBufferAndDumpToStreamOptions dump_options(options);
|
2015-07-17 09:03:59 +08:00
|
|
|
dump_options.SetData(data);
|
|
|
|
dump_options.SetSourceSize(sourceSize);
|
2015-11-04 08:02:08 +08:00
|
|
|
dump_options.SetIsTruncated(is_truncated);
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2015-07-17 09:03:59 +08:00
|
|
|
return DumpUTFBufferToStream(ConvertFunction, dump_options);
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 06:30:24 +08:00
|
|
|
bool StringPrinter::ReadStringAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF8>(
|
|
|
|
const ReadStringAndDumpToStreamOptions &options) {
|
2016-09-30 08:38:45 +08:00
|
|
|
return ReadUTFBufferAndDumpToStream<llvm::UTF8>(options, nullptr);
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 06:30:24 +08:00
|
|
|
bool StringPrinter::ReadStringAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF16>(
|
|
|
|
const ReadStringAndDumpToStreamOptions &options) {
|
2016-09-30 08:38:45 +08:00
|
|
|
return ReadUTFBufferAndDumpToStream<llvm::UTF16>(options,
|
|
|
|
llvm::ConvertUTF16toUTF8);
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 06:30:24 +08:00
|
|
|
bool StringPrinter::ReadStringAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF32>(
|
|
|
|
const ReadStringAndDumpToStreamOptions &options) {
|
2016-09-30 08:38:45 +08:00
|
|
|
return ReadUTFBufferAndDumpToStream<llvm::UTF32>(options,
|
|
|
|
llvm::ConvertUTF32toUTF8);
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 06:30:24 +08:00
|
|
|
bool StringPrinter::ReadBufferAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF8>(
|
|
|
|
const ReadBufferAndDumpToStreamOptions &options) {
|
2014-10-30 09:45:39 +08:00
|
|
|
assert(options.GetStream() && "need a Stream to print the string to");
|
|
|
|
|
2016-09-30 08:38:45 +08:00
|
|
|
return DumpUTFBufferToStream<llvm::UTF8>(nullptr, options);
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 06:30:24 +08:00
|
|
|
bool StringPrinter::ReadBufferAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::ASCII>(
|
|
|
|
const ReadBufferAndDumpToStreamOptions &options) {
|
2014-10-30 09:45:39 +08:00
|
|
|
// treat ASCII the same as UTF8
|
|
|
|
// FIXME: can we optimize ASCII some more?
|
|
|
|
return ReadBufferAndDumpToStream<StringElementType::UTF8>(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 06:30:24 +08:00
|
|
|
bool StringPrinter::ReadBufferAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF16>(
|
|
|
|
const ReadBufferAndDumpToStreamOptions &options) {
|
2014-10-30 09:45:39 +08:00
|
|
|
assert(options.GetStream() && "need a Stream to print the string to");
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2016-09-30 08:38:45 +08:00
|
|
|
return DumpUTFBufferToStream(llvm::ConvertUTF16toUTF8, options);
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-09-10 06:30:24 +08:00
|
|
|
bool StringPrinter::ReadBufferAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF32>(
|
|
|
|
const ReadBufferAndDumpToStreamOptions &options) {
|
2014-10-30 09:45:39 +08:00
|
|
|
assert(options.GetStream() && "need a Stream to print the string to");
|
2014-11-05 06:43:34 +08:00
|
|
|
|
2016-09-30 08:38:45 +08:00
|
|
|
return DumpUTFBufferToStream(llvm::ConvertUTF32toUTF8, options);
|
2014-10-30 09:45:39 +08:00
|
|
|
}
|
2014-11-05 06:43:34 +08:00
|
|
|
|
|
|
|
} // namespace formatters
|
|
|
|
|
|
|
|
} // namespace lldb_private
|