mirror of
https://github.com/intel/llvm.git
synced 2026-01-19 01:15:50 +08:00
- type names can now be regular expressions (exact matching is done first, and is faster)
- integral (and floating) types can be printed as bitfields, i.e. ${var[low-high]} will extract bits low thru high of the value and print them
- array subscripts are supported, both for arrays and for pointers. the syntax is ${*var[low-high]}, or ${*var[]} to print the whole array (the latter only works for statically sized arrays)
- summary is now printed by default when a summary string references a variable. if that variable's type has no summary, value is printed instead. to force value, you can use %V as a format specifier
- basic support for ObjectiveC:
- ObjectiveC inheritance chains are now walked through
- %@ can be specified as a summary format, to print the ObjectiveC runtime description for an object
- some bug fixes
llvm-svn: 134293
191 lines
6.1 KiB
C++
191 lines
6.1 KiB
C++
//===-- FormatManager.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/Core/FormatManager.h"
|
|
|
|
// C Includes
|
|
// C++ Includes
|
|
// Other libraries and framework includes
|
|
// Project includes
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
|
|
struct FormatInfo
|
|
{
|
|
Format format;
|
|
const char format_char; // One or more format characters that can be used for this format.
|
|
const char *format_name; // Long format name that can be used to specify the current format
|
|
};
|
|
|
|
static FormatInfo
|
|
g_format_infos[] =
|
|
{
|
|
{ eFormatDefault , '\0' , "default" },
|
|
{ eFormatBoolean , 'B' , "boolean" },
|
|
{ eFormatBinary , 'b' , "binary" },
|
|
{ eFormatBytes , 'y' , "bytes" },
|
|
{ eFormatBytesWithASCII , 'Y' , "bytes with ASCII" },
|
|
{ eFormatChar , 'c' , "character" },
|
|
{ eFormatCharPrintable , 'C' , "printable character" },
|
|
{ eFormatComplexFloat , 'F' , "complex float" },
|
|
{ eFormatCString , 's' , "c-string" },
|
|
{ eFormatDecimal , 'i' , "signed decimal" },
|
|
{ eFormatEnum , 'E' , "enumeration" },
|
|
{ eFormatHex , 'x' , "hex" },
|
|
{ eFormatFloat , 'f' , "float" },
|
|
{ eFormatOctal , 'o' , "octal" },
|
|
{ eFormatOSType , 'O' , "OSType" },
|
|
{ eFormatUnicode16 , 'U' , "unicode16" },
|
|
{ eFormatUnicode32 , '\0' , "unicode32" },
|
|
{ eFormatUnsigned , 'u' , "unsigned decimal" },
|
|
{ eFormatPointer , 'p' , "pointer" },
|
|
{ eFormatVectorOfChar , '\0' , "char[]" },
|
|
{ eFormatVectorOfSInt8 , '\0' , "int8_t[]" },
|
|
{ eFormatVectorOfUInt8 , '\0' , "uint8_t[]" },
|
|
{ eFormatVectorOfSInt16 , '\0' , "int16_t[]" },
|
|
{ eFormatVectorOfUInt16 , '\0' , "uint16_t[]" },
|
|
{ eFormatVectorOfSInt32 , '\0' , "int16_t[]" },
|
|
{ eFormatVectorOfUInt32 , '\0' , "uint16_t[]" },
|
|
{ eFormatVectorOfSInt64 , '\0' , "int16_t[]" },
|
|
{ eFormatVectorOfUInt64 , '\0' , "uint16_t[]" },
|
|
{ eFormatVectorOfFloat32, '\0' , "float32[]" },
|
|
{ eFormatVectorOfFloat64, '\0' , "float64[]" },
|
|
{ eFormatVectorOfUInt128, '\0' , "uint128_t[]" },
|
|
{ eFormatComplexInteger , 'I' , "complex integer" },
|
|
{ eFormatCharArray , 'a' , "character array" }
|
|
};
|
|
|
|
static uint32_t
|
|
g_num_format_infos = sizeof(g_format_infos)/sizeof(FormatInfo);
|
|
|
|
static bool
|
|
GetFormatFromFormatChar (char format_char, Format &format)
|
|
{
|
|
for (uint32_t i=0; i<g_num_format_infos; ++i)
|
|
{
|
|
if (g_format_infos[i].format_char == format_char)
|
|
{
|
|
format = g_format_infos[i].format;
|
|
return true;
|
|
}
|
|
}
|
|
format = eFormatInvalid;
|
|
return false;
|
|
}
|
|
|
|
static bool
|
|
GetFormatFromFormatName (const char *format_name, bool partial_match_ok, Format &format)
|
|
{
|
|
uint32_t i;
|
|
for (i=0; i<g_num_format_infos; ++i)
|
|
{
|
|
if (strcasecmp (g_format_infos[i].format_name, format_name) == 0)
|
|
{
|
|
format = g_format_infos[i].format;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (partial_match_ok)
|
|
{
|
|
for (i=0; i<g_num_format_infos; ++i)
|
|
{
|
|
if (strcasestr (g_format_infos[i].format_name, format_name) == g_format_infos[i].format_name)
|
|
{
|
|
format = g_format_infos[i].format;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
format = eFormatInvalid;
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
FormatManager::GetFormatFromCString (const char *format_cstr,
|
|
bool partial_match_ok,
|
|
lldb::Format &format)
|
|
{
|
|
bool success = false;
|
|
if (format_cstr && format_cstr[0])
|
|
{
|
|
if (format_cstr[1] == '\0')
|
|
{
|
|
success = GetFormatFromFormatChar (format_cstr[0], format);
|
|
if (success)
|
|
return true;
|
|
}
|
|
|
|
success = GetFormatFromFormatName (format_cstr, partial_match_ok, format);
|
|
}
|
|
if (!success)
|
|
format = eFormatInvalid;
|
|
return success;
|
|
}
|
|
|
|
char
|
|
FormatManager::GetFormatAsFormatChar (lldb::Format format)
|
|
{
|
|
for (uint32_t i=0; i<g_num_format_infos; ++i)
|
|
{
|
|
if (g_format_infos[i].format == format)
|
|
return g_format_infos[i].format_char;
|
|
}
|
|
return '\0';
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
FormatManager::GetFormatAsCString (Format format)
|
|
{
|
|
if (format >= eFormatDefault && format < kNumFormats)
|
|
return g_format_infos[format].format_name;
|
|
return NULL;
|
|
}
|
|
|
|
template<>
|
|
bool
|
|
FormatNavigator<std::map<lldb::RegularExpressionSP, SummaryFormat::SharedPointer>, SummaryFormat::RegexSummaryCallback>::Get(const char* key,
|
|
SummaryFormat::SharedPointer& value)
|
|
{
|
|
Mutex::Locker(m_map_mutex);
|
|
MapIterator pos, end = m_map.end();
|
|
for (pos = m_map.begin(); pos != end; pos++)
|
|
{
|
|
lldb::RegularExpressionSP regex = pos->first;
|
|
if (regex->Execute(key))
|
|
{
|
|
value = pos->second;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
template<>
|
|
bool
|
|
FormatNavigator<std::map<lldb::RegularExpressionSP, SummaryFormat::SharedPointer>, SummaryFormat::RegexSummaryCallback>::Delete(const char* type)
|
|
{
|
|
Mutex::Locker(m_map_mutex);
|
|
MapIterator pos, end = m_map.end();
|
|
for (pos = m_map.begin(); pos != end; pos++)
|
|
{
|
|
lldb::RegularExpressionSP regex = pos->first;
|
|
if ( ::strcmp(type,regex->GetText()) == 0)
|
|
{
|
|
m_map.erase(pos);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|