[Lldb-commits] [lldb] r133765 - in /lldb/trunk: include/lldb/Core/Debugger.h include/lldb/Core/FormatManager.h include/lldb/Core/State.h include/lldb/lldb-enumerations.h source/Commands/CommandObjectMemory.cpp source/Commands/CommandObjectType.cpp source/Core/Debugger.cpp source/Core/FormatManager.cpp source/Core/State.cpp source/Core/ValueObject.cpp source/Interpreter/Args.cpp source/Interpreter/NamedOptionValue.cpp

Greg Clayton gclayton at apple.com
Thu Jun 23 14:22:24 PDT 2011


Author: gclayton
Date: Thu Jun 23 16:22:24 2011
New Revision: 133765

URL: http://llvm.org/viewvc/llvm-project?rev=133765&view=rev
Log:
Centralized all of the format to c-string and to format character code inside
the FormatManager class. Modified the format arguments in any commands to be
able to use a single character format, or a full format name, or a partial 
format name if no full format names match.

Modified any code that was displaying formats to use the new FormatManager
calls so that our help text and errors never get out of date.

Modified the display of the "type format list" command to be a bit more
human readable by showing the format as a format string rather than the single
character format char.


Modified:
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/include/lldb/Core/FormatManager.h
    lldb/trunk/include/lldb/Core/State.h
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/source/Commands/CommandObjectMemory.cpp
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Core/FormatManager.cpp
    lldb/trunk/source/Core/State.cpp
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Interpreter/Args.cpp
    lldb/trunk/source/Interpreter/NamedOptionValue.cpp

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Thu Jun 23 16:22:24 2011
@@ -483,7 +483,8 @@
     DeleteFormatForType (const ConstString &type);
     
     static void
-    LoopThroughFormatList (FormatCallback cback, void* param);
+    LoopThroughFormatList (FormatManager::Callback callback, 
+                           void* callback_baton);
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/include/lldb/Core/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatManager.h?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatManager.h (original)
+++ lldb/trunk/include/lldb/Core/FormatManager.h Thu Jun 23 16:22:24 2011
@@ -51,37 +51,57 @@
 
 namespace lldb_private {
 
-    struct compareFormatMapKeys {
-        bool operator()(const char* k1, const char* k2) {
-            //return strcmp(k1,k2) == 0;
-            return (k1 == k2);
-        } 
-    };
-    
-    typedef struct format_entry_t {
-        lldb::Format FormatStyle;
-        bool Cascades;
-        format_entry_t(lldb::Format fmt) : FormatStyle(fmt), Cascades(false) {}
-        format_entry_t(lldb::Format fmt, bool csc) : FormatStyle(fmt), Cascades(csc) {}
-        format_entry_t() : FormatStyle((lldb::Format)0), Cascades(false) {} //eFormatDefault
-    } FormatEntry;
-    
-    typedef std::map<const char*, format_entry_t> FormatMap;
-    typedef FormatMap::iterator FormatIterator;
-    
-    typedef bool(*FormatCallback)(void*, const char*, lldb::Format, bool);
     
 class FormatManager
 {
 public:
-    
-    FormatManager() : m_format_map(FormatMap()), m_format_map_mutex(Mutex::eMutexTypeRecursive) {}
-    bool GetFormatForType (const ConstString &type, lldb::Format& format, bool& cascade);
-    void AddFormatForType (const ConstString &type, lldb::Format format, bool cascade);
-    bool DeleteFormatForType (const ConstString &type);
-    void LoopThroughFormatList (FormatCallback cback, void* param);
+
+    typedef bool(*Callback)(void*, const char*, lldb::Format, bool);
+
+    FormatManager() : 
+        m_format_map(FormatMap()), 
+        m_format_map_mutex(Mutex::eMutexTypeRecursive) 
+    {
+    }
+
+    bool
+    GetFormatForType (const ConstString &type, lldb::Format& format, bool& cascade);
+
+    void
+    AddFormatForType (const ConstString &type, lldb::Format format, bool cascade);
+
+    bool
+    DeleteFormatForType (const ConstString &type);
+
+    void
+    LoopThroughFormatList (Callback cback, void* param);
+
+    static bool
+    GetFormatFromCString (const char *format_cstr,
+                          bool partial_match_ok,
+                          lldb::Format &format);
+
+    static char
+    GetFormatAsFormatChar (lldb::Format format);
+
+    static const char *
+    GetFormatAsCString (lldb::Format format);
 
 private:
+    struct Entry 
+    {
+        lldb::Format format;
+        bool cascades;
+        Entry (lldb::Format f = lldb::eFormatInvalid, bool c = false) : 
+            format (f), 
+            cascades (c) 
+        {
+        }
+    };
+    
+    typedef std::map<const char*, Entry> FormatMap;
+    typedef FormatMap::iterator FormatIterator;
+
     FormatMap m_format_map;
     Mutex m_format_map_mutex;
 };

Modified: lldb/trunk/include/lldb/Core/State.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/State.h?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/State.h (original)
+++ lldb/trunk/include/lldb/Core/State.h Thu Jun 23 16:22:24 2011
@@ -37,9 +37,6 @@
 
 bool
 StateIsStoppedState (lldb::StateType state);
-
-const char *
-GetFormatAsCString (lldb::Format format);
     
 const char *
 GetPermissionsAsCString (uint32_t permissions);

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Thu Jun 23 16:22:24 2011
@@ -92,7 +92,6 @@
         eFormatBytesWithASCII,
         eFormatChar,
         eFormatCharPrintable,   // Only printable characters, space if not printable
-        eFormatCharArray,       // Print characters with no single quotes, used for character arrays that can contain non printable characters
         eFormatComplex,         // Floating point complex type
         eFormatComplexFloat = eFormatComplex,
         eFormatCString,         // NULL terminated C strings
@@ -118,8 +117,9 @@
         eFormatVectorOfFloat32,
         eFormatVectorOfFloat64,
         eFormatVectorOfUInt128,
-        eFormatComplexInteger   // Integer complex type
-
+        eFormatComplexInteger,   // Integer complex type
+        eFormatCharArray,       // Print characters with no single quotes, used for character arrays that can contain non printable characters
+        kNumFormats
     } Format;
 
     //----------------------------------------------------------------------

Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Thu Jun 23 16:22:24 2011
@@ -988,6 +988,7 @@
 
             switch (m_options.m_format)
             {
+            case kNumFormats:
             case eFormatFloat:  // TODO: add support for floats soon
             case eFormatCharPrintable:
             case eFormatBytesWithASCII:

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Thu Jun 23 16:22:24 2011
@@ -14,6 +14,8 @@
 
 #include "lldb/Core/ConstString.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/FormatManager.h"
+#include "lldb/Core/State.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
 #include "lldb/Interpreter/CommandObject.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
@@ -135,15 +137,13 @@
             return false;
         }
         
-        const char* formatA = command.GetArgumentAtIndex(0);
-        ConstString formatCS(formatA);
-        const char* formatU = formatCS.GetCString();
+        const char* format_cstr = command.GetArgumentAtIndex(0);
         lldb::Format format;
-        uint32_t byte_size_ptr;
-        Error fmt_error = Args::StringToFormat(formatU, format, &byte_size_ptr);
+        Error error = Args::StringToFormat(format_cstr, format, NULL);
         
-        if(fmt_error.Fail()) {
-            result.AppendError(fmt_error.AsCString());
+        if (error.Fail()) 
+        {
+            result.AppendError(error.AsCString());
             result.SetStatus(eReturnStatusFailed);
             return false;
         }
@@ -289,72 +289,15 @@
 private:
     
     bool
-    LoopCallback (
-                  const char* type,
+    LoopCallback (const char* type,
                   lldb::Format format,
                   bool cascade,
                   RegularExpression* regex,
-                  CommandReturnObject *result
-                  )
+                  CommandReturnObject *result)
     {
-        if(regex && !regex->Execute(type)) return true;
-        Stream &ostrm = result->GetOutputStream();
-        ostrm.Printf("(%s) %scascading ",type, cascade ? "" : "not ");
-        switch(format) {
-            case eFormatBytes:
-                ostrm.Printf("y\n");
-                break;
-            case eFormatBytesWithASCII:
-                ostrm.Printf("Y\n");
-                break;
-            case eFormatBinary:
-                ostrm.Printf("b\n");
-                break;
-            case eFormatBoolean:
-                ostrm.Printf("B\n");
-                break;
-            case eFormatCharArray:
-                ostrm.Printf("a\n");
-                break;
-            case eFormatChar:
-                ostrm.Printf("c\n");
-                break;
-            case eFormatCharPrintable:
-                ostrm.Printf("C\n");
-                break;
-            case eFormatOctal:
-                ostrm.Printf("o\n");
-                break;
-            case eFormatOSType:
-                ostrm.Printf("O\n");
-                break;
-            case eFormatDecimal:
-                ostrm.Printf("i or d\n");
-                break;
-            case eFormatComplexInteger:
-                ostrm.Printf("I\n");
-                break;
-            case eFormatUnsigned:
-                ostrm.Printf("u\n");
-                break;
-            case eFormatHex:
-                ostrm.Printf("x\n");
-                break;
-            case eFormatComplex:
-                ostrm.Printf("X\n");
-                break;
-            case eFormatFloat:
-                ostrm.Printf("f e or g\n");
-                break;
-            case eFormatPointer:
-                ostrm.Printf("p\n");
-                break;
-            case eFormatCString:
-                ostrm.Printf("s\n");
-                break;
-            default:
-                ostrm.Printf("other\n");
-                break;
+        if (regex == NULL || regex->Execute(type)) 
+        {
+            result->GetOutputStream().Printf ("%s: %s\n", type, FormatManager::GetFormatAsCString (format));
         }
         return true;
     }

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Thu Jun 23 16:22:24 2011
@@ -1339,9 +1339,9 @@
 }
 
 void
-Debugger::LoopThroughFormatList (FormatCallback cback, void* param)
+Debugger::LoopThroughFormatList (FormatManager::Callback callback, void* callback_baton)
 {
-    return GetFormatManager().LoopThroughFormatList(cback, param);
+    return GetFormatManager().LoopThroughFormatList(callback, callback_baton);
 }
 
 #pragma mark Debugger::SettingsController

Modified: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (original)
+++ lldb/trunk/source/Core/FormatManager.cpp Thu Jun 23 16:22:24 2011
@@ -17,53 +17,195 @@
 using namespace lldb;
 using namespace lldb_private;
 
-bool FormatManager::GetFormatForType (const ConstString &type, lldb::Format& format, bool& cascade)
+
+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;
+}
+
+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.GetCString());
+    FormatMap::iterator iter = fmtmap.find(type_name.GetCString());
     if(iter == fmtmap.end())
         return false;
     else {
-        format = iter->second.FormatStyle;
-        cascade = iter->second.Cascades;
+        format = iter->second.format;
+        cascade = iter->second.cascades;
         return true;
     }
 }
 
-void FormatManager::AddFormatForType (const ConstString &type, lldb::Format format, bool cascade)
+void
+FormatManager::AddFormatForType (const ConstString &type_name, lldb::Format format, bool cascade)
 {
-    format_entry_t entry(format, cascade);
+    Entry entry(format, cascade);
     Mutex::Locker locker (m_format_map_mutex);
     FormatMap& fmtmap = m_format_map;
-    fmtmap[type.GetCString()] = entry;
+    fmtmap[type_name.GetCString()] = entry;
 }
 
-bool FormatManager::DeleteFormatForType (const ConstString &type)
+bool
+FormatManager::DeleteFormatForType (const ConstString &type_name)
 {
     Mutex::Locker locker (m_format_map_mutex);
     FormatMap& fmtmap = m_format_map;
-    const char* typeCS = type.GetCString();
+    const char* typeCS = type_name.GetCString();
     FormatMap::iterator iter = fmtmap.find(typeCS);
-    if (iter == fmtmap.end())
-        return false;
-    else {
+    if (iter != fmtmap.end())
+    {
         fmtmap.erase(typeCS);
         return true;
     }
+    return false;
 }
 
-void FormatManager::LoopThroughFormatList (FormatCallback cback, void* param)
+void
+FormatManager::LoopThroughFormatList (Callback callback, void* param)
 {
-    Mutex::Locker locker (m_format_map_mutex);
-    FormatMap& fmtmap = m_format_map;
-    FormatIterator iter = fmtmap.begin();
-    while(iter != fmtmap.end()) {
-        const char* type = iter->first;
-        lldb::Format format = iter->second.FormatStyle;
-        bool cascade = iter->second.Cascades;
-        if(!cback(param, type,format, cascade)) break;
-        iter++;
+    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;
+        }
     }
 }
 

Modified: lldb/trunk/source/Core/State.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/State.cpp?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/source/Core/State.cpp (original)
+++ lldb/trunk/source/Core/State.cpp Thu Jun 23 16:22:24 2011
@@ -41,52 +41,6 @@
 }
 
 const char *
-lldb_private::GetFormatAsCString (lldb::Format format)
-{
-    switch (format)
-    {
-        case eFormatDefault:        return "default";
-        case eFormatBoolean:        return "boolean";
-        case eFormatBinary:         return "binary";
-        case eFormatBytes:          return "bytes";
-        case eFormatBytesWithASCII: return "bytes with ASCII";
-        case eFormatChar:           return "character";
-        case eFormatCharArray:      return "character array";
-        case eFormatCharPrintable:  return "printable character";
-        case eFormatComplexFloat:   return "complet float";
-        case eFormatCString:        return "c-string";
-        case eFormatDecimal:        return "signed decimal";
-        case eFormatEnum:           return "enumeration";
-        case eFormatHex:            return "hex";
-        case eFormatFloat:          return "float";
-        case eFormatOctal:          return "octal";
-        case eFormatOSType:         return "OSType";
-        case eFormatUnicode16:      return "Unicode16";
-        case eFormatUnicode32:      return "Unicode32";
-        case eFormatUnsigned:       return "unsigned decimal";
-        case eFormatPointer:        return "pointer";
-        case eFormatVectorOfChar:   return "vector of characters";
-        case eFormatVectorOfSInt8:  return "vector of int8_t";
-        case eFormatVectorOfUInt8:  return "vector of uint8_t";
-        case eFormatVectorOfSInt16: return "vector of int16_t";
-        case eFormatVectorOfUInt16: return "vector of uint16_t";
-        case eFormatVectorOfSInt32: return "vector of int32_t";
-        case eFormatVectorOfUInt32: return "vector of uint32_t";
-        case eFormatVectorOfSInt64: return "vector of int64_t";
-        case eFormatVectorOfUInt64: return "vector of uint64_t";
-        case eFormatVectorOfFloat32:return "vector of float32";
-        case eFormatVectorOfFloat64:return "vector of float64";
-        case eFormatVectorOfUInt128:return "vector of uint128_t";
-        case eFormatComplexInteger: return "complex integer";
-        default: break;
-    }
-    static char unknown_format_string[64];
-    snprintf(unknown_format_string, sizeof (unknown_format_string), "Format = %u", format);
-    return unknown_format_string;
-}
-
-
-const char *
 lldb_private::GetPermissionsAsCString (uint32_t permissions)
 {
     switch (permissions)

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Thu Jun 23 16:22:24 2011
@@ -672,9 +672,14 @@
                     case Value::eContextTypeClangType:
                     case Value::eContextTypeLLDBType:
                     case Value::eContextTypeVariable:
-                        Format format = GetFormat();
-                        if (format != m_last_format)
-                            m_value_str.clear();
+                        {
+                            Format format = GetFormat();
+                            if (format != m_last_format)
+                                m_value_str.clear();
+                        }
+                        break;
+
+                    default:
                         break;
                 }
             }

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Thu Jun 23 16:22:24 2011
@@ -14,6 +14,7 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Interpreter/Args.h"
+#include "lldb/Core/FormatManager.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/StreamString.h"
@@ -899,61 +900,25 @@
                 *byte_size_ptr = 0;
         }
 
-        bool success = s[1] == '\0';
-        if (success)
+        const bool partial_match_ok = true;
+        if (!FormatManager::GetFormatFromCString (s, partial_match_ok, format))
         {
-            switch (s[0])
+            StreamString error_strm;
+            error_strm.Printf ("Invalid format character or name '%s'. Valid values are:\n", s);
+            for (Format f = eFormatDefault; f < kNumFormats; ++f)
             {
-            case 'y': format = eFormatBytes;            break;
-            case 'Y': format = eFormatBytesWithASCII;   break;
-            case 'b': format = eFormatBinary;           break;
-            case 'B': format = eFormatBoolean;          break;
-            case 'a': format = eFormatCharArray;        break;
-            case 'c': format = eFormatChar;             break;
-            case 'C': format = eFormatCharPrintable;    break;
-            case 'o': format = eFormatOctal;            break;
-            case 'O': format = eFormatOSType;           break;
-            case 'i':
-            case 'd': format = eFormatDecimal;          break;
-            case 'I': format = eFormatComplexInteger;   break;
-            case 'u': format = eFormatUnsigned;         break;
-            case 'x': format = eFormatHex;              break;
-            case 'X': format = eFormatComplex;          break;
-            case 'f':
-            case 'e':
-            case 'g': format = eFormatFloat;            break;
-            case 'p': format = eFormatPointer;          break;
-            case 's': format = eFormatCString;          break;
-            default:
-                success = false;
-                break;
+                char format_char = FormatManager::GetFormatAsFormatChar(f);
+                if (format_char)
+                    error_strm.Printf ("'%c' or ", format_char);
+            
+                error_strm.Printf ("\"%s\"", FormatManager::GetFormatAsCString(f));
+                error_strm.EOL();
             }
+            
+            if (byte_size_ptr)
+                error_strm.PutCString ("An optional byte size can precede the format character.\n");
+            error.SetErrorString(error_strm.GetString().c_str());
         }
-        if (!success)
-            error.SetErrorStringWithFormat ("Invalid format specification '%s'. Valid values are:\n"
-                                            "  a - char buffer\n"
-                                            "  b - binary\n"
-                                            "  B - boolean\n"
-                                            "  c - char\n"
-                                            "  C - printable char\n"
-                                            "  d - signed decimal\n"
-                                            "  e - float\n"
-                                            "  f - float\n"
-                                            "  g - float\n"
-                                            "  i - signed decimal\n"
-                                            "  I - complex integer\n"
-                                            "  o - octal\n"
-                                            "  O - OSType\n"
-                                            "  p - pointer\n"
-                                            "  s - c-string\n"
-                                            "  u - unsigned decimal\n"
-                                            "  x - hex\n"
-                                            "  X - complex float\n"
-                                            "  y - bytes\n"
-                                            "  Y - bytes with ASCII\n%s",
-                                            s, 
-                                            byte_size_ptr ? "An optional byte size can precede the format character.\n" : "");
-
 
         if (error.Fail())
             return error;

Modified: lldb/trunk/source/Interpreter/NamedOptionValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/NamedOptionValue.cpp?rev=133765&r1=133764&r2=133765&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/NamedOptionValue.cpp (original)
+++ lldb/trunk/source/Interpreter/NamedOptionValue.cpp Thu Jun 23 16:22:24 2011
@@ -13,6 +13,7 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Core/FormatManager.h"
 #include "lldb/Core/State.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Interpreter/Args.h"
@@ -339,7 +340,7 @@
 void
 OptionValueFormat::DumpValue (Stream &strm)
 {
-    strm.PutCString (GetFormatAsCString (m_current_value));
+    strm.PutCString (FormatManager::GetFormatAsCString (m_current_value));
 }
 
 Error





More information about the lldb-commits mailing list