//===-- 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= eFormatDefault && format < kNumFormats) return g_format_infos[format].format_name; return NULL; } bool FormatManager::GetFormatForType (const ConstString &type_name, lldb::Format& format, bool& cascade) { Mutex::Locker locker (m_format_map_mutex); FormatMap& fmtmap = m_format_map; FormatMap::iterator iter = fmtmap.find(type_name.GetCString()); if(iter == fmtmap.end()) return false; else { format = iter->second.format; cascade = iter->second.cascades; return true; } } void FormatManager::AddFormatForType (const ConstString &type_name, lldb::Format format, bool cascade) { Entry entry(format, cascade); Mutex::Locker locker (m_format_map_mutex); FormatMap& fmtmap = m_format_map; fmtmap[type_name.GetCString()] = entry; } bool FormatManager::DeleteFormatForType (const ConstString &type_name) { Mutex::Locker locker (m_format_map_mutex); FormatMap& fmtmap = m_format_map; const char* typeCS = type_name.GetCString(); FormatMap::iterator iter = fmtmap.find(typeCS); if (iter != fmtmap.end()) { fmtmap.erase(typeCS); return true; } return false; } void FormatManager::LoopThroughFormatList (Callback callback, void* param) { if (callback) { Mutex::Locker locker (m_format_map_mutex); FormatIterator pos, end = m_format_map.end(); for (pos = m_format_map.begin(); pos != end; ++pos) { const char* type = pos->first; lldb::Format format = pos->second.format; bool cascade = pos->second.cascades; if (!callback(param, type, format, cascade)) break; } } }