]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/DataFormatters/CoreMedia.cpp
Update ELF Tool Chain to upstream rev 3400
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / DataFormatters / CoreMedia.cpp
1 //===-- CoreMedia.cpp --------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/DataFormatters/CXXFormatterFunctions.h"
11
12 #include "lldb/Core/Flags.h"
13 #include "lldb/Symbol/ClangASTContext.h"
14
15 #include <inttypes.h>
16
17 using namespace lldb;
18 using namespace lldb_private;
19 using namespace lldb_private::formatters;
20
21 bool
22 lldb_private::formatters::CMTimeSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
23 {
24     ClangASTContext *ast_ctx = ClangASTContext::GetASTContext(valobj.GetClangType().GetASTContext());
25     if (!ast_ctx)
26         return false;
27     
28     // fetch children by offset to compensate for potential lack of debug info
29     auto int64_ty = ast_ctx->GetIntTypeFromBitSize(64, true);
30     auto int32_ty = ast_ctx->GetIntTypeFromBitSize(32, true);
31     
32     auto value_sp(valobj.GetSyntheticChildAtOffset(0, int64_ty, true));
33     auto timescale_sp(valobj.GetSyntheticChildAtOffset(8, int32_ty, true));
34     auto flags_sp(valobj.GetSyntheticChildAtOffset(12, int32_ty, true));
35     
36     if (!value_sp || !timescale_sp || !flags_sp)
37         return false;
38     
39     auto value = value_sp->GetValueAsUnsigned(0);
40     auto timescale = (int32_t)timescale_sp->GetValueAsUnsigned(0); // the timescale specifies the fraction of a second each unit in the numerator occupies
41     auto flags = Flags(flags_sp->GetValueAsUnsigned(0) & 0x00000000000000FF); // the flags I need sit in the LSB
42     
43     const unsigned int FlagPositiveInf = 4;
44     const unsigned int FlagNegativeInf = 8;
45     const unsigned int FlagIndefinite = 16;
46     
47     if (flags.AnySet(FlagIndefinite))
48     {
49         stream.Printf("indefinite");
50         return true;
51     }
52     
53     if (flags.AnySet(FlagPositiveInf))
54     {
55         stream.Printf("+oo");
56         return true;
57     }
58     
59     if (flags.AnySet(FlagNegativeInf))
60     {
61         stream.Printf("-oo");
62         return true;
63     }
64     
65     if (timescale == 0)
66         return false;
67     
68     switch (timescale)
69     {
70         case 0:
71             return false;
72         case 1:
73             stream.Printf("%" PRId64 " seconds", value);
74             return true;
75         case 2:
76             stream.Printf("%" PRId64 " half seconds", value);
77             return true;
78         case 3:
79             stream.Printf("%" PRId64 " third%sof a second", value, value == 1 ? " " : "s ");
80             return true;
81         default:
82             stream.Printf("%" PRId64 " %" PRId32 "th%sof a second", value, timescale, value == 1 ? " " : "s ");
83             return true;
84     }
85 }