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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
//===-- CF.cpp ----------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/lldb-python.h"
#include "lldb/DataFormatters/CXXFormatterFunctions.h"
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Error.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Core/ValueObjectConstResult.h"
#include "lldb/Host/Endian.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Target/ObjCLanguageRuntime.h"
#include "lldb/Target/Target.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
bool
lldb_private::formatters::CFAbsoluteTimeSummaryProvider (ValueObject& valobj, Stream& stream)
{
time_t epoch = GetOSXEpoch();
epoch = epoch + (time_t)valobj.GetValueAsUnsigned(0);
tm *tm_date = localtime(&epoch);
if (!tm_date)
return false;
std::string buffer(1024,0);
if (strftime (&buffer[0], 1023, "%Z", tm_date) == 0)
return false;
stream.Printf("%04d-%02d-%02d %02d:%02d:%02d %s", tm_date->tm_year+1900, tm_date->tm_mon+1, tm_date->tm_mday, tm_date->tm_hour, tm_date->tm_min, tm_date->tm_sec, buffer.c_str());
return true;
}
bool
lldb_private::formatters::CFBagSummaryProvider (ValueObject& valobj, Stream& stream)
{
ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
return false;
ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
if (!runtime)
return false;
ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
if (!descriptor.get() || !descriptor->IsValid())
return false;
uint32_t ptr_size = process_sp->GetAddressByteSize();
lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
if (!valobj_addr)
return false;
uint32_t count = 0;
bool is_type_ok = false; // check to see if this is a CFBag we know about
if (descriptor->IsCFType())
{
ConstString type_name(valobj.GetTypeName());
if (type_name == ConstString("__CFBag") || type_name == ConstString("const struct __CFBag"))
{
if (valobj.IsPointerType())
is_type_ok = true;
}
}
if (is_type_ok == false)
{
StackFrameSP frame_sp(valobj.GetFrameSP());
if (!frame_sp)
return false;
ValueObjectSP count_sp;
StreamString expr;
expr.Printf("(int)CFBagGetCount((void*)0x%" PRIx64 ")",valobj.GetPointerValue());
if (process_sp->GetTarget().EvaluateExpression(expr.GetData(), frame_sp.get(), count_sp) != eExecutionCompleted)
return false;
if (!count_sp)
return false;
count = count_sp->GetValueAsUnsigned(0);
}
else
{
uint32_t offset = 2*ptr_size+4 + valobj_addr;
Error error;
count = process_sp->ReadUnsignedIntegerFromMemory(offset, 4, 0, error);
if (error.Fail())
return false;
}
stream.Printf("@\"%u value%s\"",
count,(count == 1 ? "" : "s"));
return true;
}
bool
lldb_private::formatters::CFBitVectorSummaryProvider (ValueObject& valobj, Stream& stream)
{
ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
return false;
ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
if (!runtime)
return false;
ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
if (!descriptor.get() || !descriptor->IsValid())
return false;
uint32_t ptr_size = process_sp->GetAddressByteSize();
lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
if (!valobj_addr)
return false;
uint32_t count = 0;
bool is_type_ok = false; // check to see if this is a CFBag we know about
if (descriptor->IsCFType())
{
ConstString type_name(valobj.GetTypeName());
if (type_name == ConstString("__CFMutableBitVector") || type_name == ConstString("__CFBitVector") || type_name == ConstString("CFMutableBitVectorRef") || type_name == ConstString("CFBitVectorRef"))
{
if (valobj.IsPointerType())
is_type_ok = true;
}
}
if (is_type_ok == false)
return false;
Error error;
count = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr+2*ptr_size, ptr_size, 0, error);
if (error.Fail())
return false;
uint64_t num_bytes = count / 8 + ((count & 7) ? 1 : 0);
addr_t data_ptr = process_sp->ReadPointerFromMemory(valobj_addr+2*ptr_size+2*ptr_size, error);
if (error.Fail())
return false;
// make sure we do not try to read huge amounts of data
if (num_bytes > 1024)
num_bytes = 1024;
DataBufferSP buffer_sp(new DataBufferHeap(num_bytes,0));
num_bytes = process_sp->ReadMemory(data_ptr, buffer_sp->GetBytes(), num_bytes, error);
if (error.Fail() || num_bytes == 0)
return false;
uint8_t *bytes = buffer_sp->GetBytes();
for (int byte_idx = 0; byte_idx < num_bytes-1; byte_idx++)
{
uint8_t byte = bytes[byte_idx];
bool bit0 = (byte & 1) == 1;
bool bit1 = (byte & 2) == 2;
bool bit2 = (byte & 4) == 4;
bool bit3 = (byte & 8) == 8;
bool bit4 = (byte & 16) == 16;
bool bit5 = (byte & 32) == 32;
bool bit6 = (byte & 64) == 64;
bool bit7 = (byte & 128) == 128;
stream.Printf("%c%c%c%c %c%c%c%c ",
(bit7 ? '1' : '0'),
(bit6 ? '1' : '0'),
(bit5 ? '1' : '0'),
(bit4 ? '1' : '0'),
(bit3 ? '1' : '0'),
(bit2 ? '1' : '0'),
(bit1 ? '1' : '0'),
(bit0 ? '1' : '0'));
count -= 8;
}
{
// print the last byte ensuring we do not print spurious bits
uint8_t byte = bytes[num_bytes-1];
bool bit0 = (byte & 1) == 1;
bool bit1 = (byte & 2) == 2;
bool bit2 = (byte & 4) == 4;
bool bit3 = (byte & 8) == 8;
bool bit4 = (byte & 16) == 16;
bool bit5 = (byte & 32) == 32;
bool bit6 = (byte & 64) == 64;
bool bit7 = (byte & 128) == 128;
if (count)
{
stream.Printf("%c",bit7 ? '1' : '0');
count -= 1;
}
if (count)
{
stream.Printf("%c",bit6 ? '1' : '0');
count -= 1;
}
if (count)
{
stream.Printf("%c",bit5 ? '1' : '0');
count -= 1;
}
if (count)
{
stream.Printf("%c",bit4 ? '1' : '0');
count -= 1;
}
if (count)
{
stream.Printf("%c",bit3 ? '1' : '0');
count -= 1;
}
if (count)
{
stream.Printf("%c",bit2 ? '1' : '0');
count -= 1;
}
if (count)
{
stream.Printf("%c",bit1 ? '1' : '0');
count -= 1;
}
if (count)
stream.Printf("%c",bit0 ? '1' : '0');
}
return true;
}
bool
lldb_private::formatters::CFBinaryHeapSummaryProvider (ValueObject& valobj, Stream& stream)
{
ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
return false;
ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
if (!runtime)
return false;
ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
if (!descriptor.get() || !descriptor->IsValid())
return false;
uint32_t ptr_size = process_sp->GetAddressByteSize();
lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
if (!valobj_addr)
return false;
uint32_t count = 0;
bool is_type_ok = false; // check to see if this is a CFBinaryHeap we know about
if (descriptor->IsCFType())
{
ConstString type_name(valobj.GetTypeName());
if (type_name == ConstString("__CFBinaryHeap") || type_name == ConstString("const struct __CFBinaryHeap"))
{
if (valobj.IsPointerType())
is_type_ok = true;
}
}
if (is_type_ok == false)
{
StackFrameSP frame_sp(valobj.GetFrameSP());
if (!frame_sp)
return false;
ValueObjectSP count_sp;
StreamString expr;
expr.Printf("(int)CFBinaryHeapGetCount((void*)0x%" PRIx64 ")",valobj.GetPointerValue());
if (process_sp->GetTarget().EvaluateExpression(expr.GetData(), frame_sp.get(), count_sp) != eExecutionCompleted)
return false;
if (!count_sp)
return false;
count = count_sp->GetValueAsUnsigned(0);
}
else
{
uint32_t offset = 2*ptr_size;
Error error;
count = process_sp->ReadUnsignedIntegerFromMemory(offset, 4, 0, error);
if (error.Fail())
return false;
}
stream.Printf("@\"%u item%s\"",
count,(count == 1 ? "" : "s"));
return true;
}
|