summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Language/Java/JavaFormatterFunctions.cpp
blob: ab368b33fbc7c33e331918482391a41c0ba1cb49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//===-- JavaFormatterFunctions.cpp-------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "JavaFormatterFunctions.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/DataFormatters/StringPrinter.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;

bool
lldb_private::formatters::JavaStringSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &opts)
{
    if (valobj.IsPointerOrReferenceType())
    {
        Error error;
        ValueObjectSP deref = valobj.Dereference(error);
        if (error.Fail())
            return false;
        return JavaStringSummaryProvider(*deref, stream, opts);
    }

    ProcessSP process_sp = valobj.GetProcessSP();
    if (!process_sp)
        return false;

    ConstString data_name("value");
    ConstString length_name("count");

    ValueObjectSP length_sp = valobj.GetChildMemberWithName(length_name, true);
    ValueObjectSP data_sp = valobj.GetChildMemberWithName(data_name, true);
    if (!data_sp || !length_sp)
        return false;

    bool success = false;
    uint64_t length = length_sp->GetValueAsUnsigned(0, &success);
    if (!success)
        return false;

    if (length == 0)
    {
        stream.Printf("\"\"");
        return true;
    }
    lldb::addr_t valobj_addr = data_sp->GetAddressOf();

    StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
    options.SetLocation(valobj_addr);
    options.SetProcessSP(process_sp);
    options.SetStream(&stream);
    options.SetSourceSize(length);
    options.SetNeedsZeroTermination(false);
    options.SetLanguage(eLanguageTypeJava);

    if (StringPrinter::ReadStringAndDumpToStream<StringPrinter::StringElementType::UTF16>(options))
        return true;

    stream.Printf("Summary Unavailable");
    return true;
}
OpenPOWER on IntegriCloud