[Lldb-commits] [lldb] r133728 - in /lldb/trunk: include/lldb/Core/Debugger.h include/lldb/Core/FormatManager.h include/lldb/Symbol/ClangASTType.h lldb.xcodeproj/project.pbxproj source/Commands/CommandObjectType.cpp source/Commands/CommandObjectType.h source/Core/Debugger.cpp source/Core/FormatManager.cpp source/Interpreter/Args.cpp source/Interpreter/CommandInterpreter.cpp source/Symbol/ClangASTType.cpp

Greg Clayton gclayton at apple.com
Thu Jun 23 10:59:56 PDT 2011


Author: gclayton
Date: Thu Jun 23 12:59:56 2011
New Revision: 133728

URL: http://llvm.org/viewvc/llvm-project?rev=133728&view=rev
Log:
Committing type format code for Enrico Granata.

This commit adds a new top level command named "type". Currently this command
implements three commands:

type format add <format> <typename1> [<typename2> ...]
type format delete <typename1> [<typename2> ...]
type format list [<typename1> [<typename2>] ...]

This allows you to specify the default format that will be used to display
types when you use "frame variable" or "expression", or the SBValue classes.

Examples:

// Format uint*_t as hex
type format add x uint16_t uint32_t uint64_t

// Format intptr_t as a pointer
type format add p intptr_t

The format characters are the same as "printf" for the most part with many
additions. These format character specifiers are also used in many other 
commands ("frame variable" for one). The current list of format characters
include:

a - char buffer
b - binary
B - boolean
c - char
C - printable char
d - signed decimal
e - float
f - float
g - float
i - signed decimal
I - complex integer
o - octal
O - OSType
p - pointer
s - c-string
u - unsigned decimal
x - hex
X - complex float
y - bytes
Y - bytes with ASCII



Added:
    lldb/trunk/include/lldb/Core/FormatManager.h
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/source/Commands/CommandObjectType.h
    lldb/trunk/source/Core/FormatManager.cpp
Modified:
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/include/lldb/Symbol/ClangASTType.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Interpreter/Args.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/source/Symbol/ClangASTType.cpp

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=133728&r1=133727&r2=133728&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Thu Jun 23 12:59:56 2011
@@ -17,7 +17,9 @@
 
 #include <stack>
 
+#include "lldb/lldb-public.h"
 #include "lldb/Core/Communication.h"
+#include "lldb/Core/FormatManager.h"
 #include "lldb/Core/InputReaderStack.h"
 #include "lldb/Core/Listener.h"
 #include "lldb/Core/StreamFile.h"
@@ -468,6 +470,20 @@
     Debugger ();
 
     DISALLOW_COPY_AND_ASSIGN (Debugger);
+    
+public:
+    
+    static bool
+    GetFormatForType (const ConstString &type, lldb::Format& format, bool& cascade);
+    
+    static void
+    AddFormatForType (const ConstString &type, lldb::Format format, bool cascade);
+    
+    static bool
+    DeleteFormatForType (const ConstString &type);
+    
+    static void
+    LoopThroughFormatList (FormatCallback cback, void* param);
 };
 
 } // namespace lldb_private

Added: lldb/trunk/include/lldb/Core/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatManager.h?rev=133728&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatManager.h (added)
+++ lldb/trunk/include/lldb/Core/FormatManager.h Thu Jun 23 12:59:56 2011
@@ -0,0 +1,91 @@
+//===-- FormatManager.h -------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_FormatManager_h_
+#define lldb_FormatManager_h_
+
+// C Includes
+
+#include <stdint.h>
+#include <unistd.h>
+
+// C++ Includes
+
+#ifdef __GNUC__
+#include <ext/hash_map>
+
+namespace std
+{
+    using namespace __gnu_cxx;
+}
+
+#else
+#include <hash_map>
+#endif
+
+#include <map>
+#include <stack>
+
+// Other libraries and framework includes
+// Project includes
+#include "lldb/lldb-public.h"
+#include "lldb-enumerations.h"
+
+#include "lldb/Core/Communication.h"
+#include "lldb/Core/InputReaderStack.h"
+#include "lldb/Core/Listener.h"
+#include "lldb/Core/Stream.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Core/SourceManager.h"
+#include "lldb/Core/UserID.h"
+#include "lldb/Core/UserSettingsController.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Platform.h"
+#include "lldb/Target/TargetList.h"
+
+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);
+
+private:
+    FormatMap m_format_map;
+    Mutex m_format_map_mutex;
+};
+
+} // namespace lldb_private
+
+#endif	// lldb_FormatManager_h_

Modified: lldb/trunk/include/lldb/Symbol/ClangASTType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTType.h?rev=133728&r1=133727&r2=133728&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTType.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTType.h Thu Jun 23 12:59:56 2011
@@ -74,6 +74,9 @@
     static ConstString
     GetClangTypeName (lldb::clang_type_t clang_type);
 
+    static ConstString
+    GetClangTypeName (clang::QualType qual_type);
+    
     uint32_t
     GetClangTypeBitWidth ();
 

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=133728&r1=133727&r2=133728&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Thu Jun 23 12:59:56 2011
@@ -399,6 +399,8 @@
 		4C74CB6312288704006A8171 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C74CB6212288704006A8171 /* Carbon.framework */; };
 		4CABA9E0134A8BCD00539BDD /* ValueObjectMemory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CABA9DF134A8BCD00539BDD /* ValueObjectMemory.cpp */; };
 		4CD0BD0F134BFADF00CB44D4 /* ValueObjectDynamicValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CD0BD0E134BFADF00CB44D4 /* ValueObjectDynamicValue.cpp */; };
+		9415F61813B2C0EF00A52B36 /* FormatManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9415F61713B2C0EF00A52B36 /* FormatManager.cpp */; };
+		9463D4CD13B1798800C230D4 /* CommandObjectType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9463D4CC13B1798800C230D4 /* CommandObjectType.cpp */; };
 		9A19A6AF1163BBB200E0D453 /* SBValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A19A6A51163BB7E00E0D453 /* SBValue.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		9A19A6B01163BBB300E0D453 /* SBValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A19A6AD1163BB9800E0D453 /* SBValue.cpp */; };
 		9A22A161135E30370024DDC3 /* EmulateInstructionARM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A22A15D135E30370024DDC3 /* EmulateInstructionARM.cpp */; };
@@ -1156,6 +1158,10 @@
 		69A01E1E1236C5D400C660B5 /* Mutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Mutex.cpp; sourceTree = "<group>"; };
 		69A01E1F1236C5D400C660B5 /* Symbols.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Symbols.cpp; sourceTree = "<group>"; };
 		69A01E201236C5D400C660B5 /* TimeValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TimeValue.cpp; sourceTree = "<group>"; };
+		9415F61613B2C0DC00A52B36 /* FormatManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FormatManager.h; path = include/lldb/Core/FormatManager.h; sourceTree = "<group>"; };
+		9415F61713B2C0EF00A52B36 /* FormatManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FormatManager.cpp; path = source/Core/FormatManager.cpp; sourceTree = "<group>"; };
+		9463D4CC13B1798800C230D4 /* CommandObjectType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectType.cpp; path = source/Commands/CommandObjectType.cpp; sourceTree = "<group>"; };
+		9463D4CE13B179A500C230D4 /* CommandObjectType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CommandObjectType.h; path = source/Commands/CommandObjectType.h; sourceTree = "<group>"; };
 		961FABB81235DE1600F93A47 /* FuncUnwinders.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FuncUnwinders.cpp; path = source/Symbol/FuncUnwinders.cpp; sourceTree = "<group>"; };
 		961FABB91235DE1600F93A47 /* UnwindPlan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnwindPlan.cpp; path = source/Symbol/UnwindPlan.cpp; sourceTree = "<group>"; };
 		961FABBA1235DE1600F93A47 /* UnwindTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnwindTable.cpp; path = source/Symbol/UnwindTable.cpp; sourceTree = "<group>"; };
@@ -1899,6 +1905,8 @@
 				26BC7D6310F1B77400F91463 /* FileSpecList.h */,
 				26BC7E7B10F1B85900F91463 /* FileSpecList.cpp */,
 				26BC7D6410F1B77400F91463 /* Flags.h */,
+				9415F61613B2C0DC00A52B36 /* FormatManager.h */,
+				9415F61713B2C0EF00A52B36 /* FormatManager.cpp */,
 				26F7305F139D8FC900FD51C7 /* History.h */,
 				26F73061139D8FDB00FD51C7 /* History.cpp */,
 				9AA69DBB118A029E00D753A0 /* InputReader.h */,
@@ -2132,6 +2140,8 @@
 				269416AD119A024800FF2715 /* CommandObjectTarget.cpp */,
 				26BC7D2D10F1B76300F91463 /* CommandObjectThread.h */,
 				26BC7E4610F1B84700F91463 /* CommandObjectThread.cpp */,
+				9463D4CE13B179A500C230D4 /* CommandObjectType.h */,
+				9463D4CC13B1798800C230D4 /* CommandObjectType.cpp */,
 				B296983512C2FB2B002D92C3 /* CommandObjectVersion.h */,
 				B296983412C2FB2B002D92C3 /* CommandObjectVersion.cpp */,
 			);
@@ -3221,6 +3231,8 @@
 				9A9E1EFF1398086D005AC039 /* InputReaderStack.cpp in Sources */,
 				B28058A1139988B0002D96D0 /* InferiorCallPOSIX.cpp in Sources */,
 				26F73062139D8FDB00FD51C7 /* History.cpp in Sources */,
+				9463D4CD13B1798800C230D4 /* CommandObjectType.cpp in Sources */,
+				9415F61813B2C0EF00A52B36 /* FormatManager.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=133728&view=auto
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (added)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Thu Jun 23 12:59:56 2011
@@ -0,0 +1,415 @@
+//===-- CommandObjectType.cpp ----------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CommandObjectType.h"
+
+// C Includes
+// C++ Includes
+
+#include "lldb/Core/ConstString.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandObject.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/Options.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+//-------------------------------------------------------------------------
+// CommandObjectTypeAdd
+//-------------------------------------------------------------------------
+
+class CommandObjectTypeAdd : public CommandObject
+{
+    
+private:
+    
+    class CommandOptions : public Options
+    {
+    public:
+        
+        CommandOptions (CommandInterpreter &interpreter) :
+        Options (interpreter)
+        {
+        }
+        
+        virtual
+        ~CommandOptions (){}
+        
+        virtual Error
+        SetOptionValue (uint32_t option_idx, const char *option_arg)
+        {
+            Error error;
+            char short_option = (char) m_getopt_table[option_idx].val;
+            bool success;
+            
+            switch (short_option)
+            {
+                case 'c':
+                    m_cascade = Args::StringToBoolean(option_arg, true, &success);
+                    if (!success)
+                        error.SetErrorStringWithFormat("Invalid value for cascade: %s.\n", option_arg);
+                    break;
+                default:
+                    error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
+                    break;
+            }
+            
+            return error;
+        }
+        
+        void
+        OptionParsingStarting ()
+        {
+            m_cascade = true;
+        }
+        
+        const OptionDefinition*
+        GetDefinitions ()
+        {
+            return g_option_table;
+        }
+        
+        // Options table: Required for subclasses of Options.
+        
+        static OptionDefinition g_option_table[];
+        
+        // Instance variables to hold the values for command options.
+        
+        bool m_cascade;
+    };
+    
+    CommandOptions m_options;
+    
+    virtual Options *
+    GetOptions ()
+    {
+        return &m_options;
+    }
+    
+public:
+    CommandObjectTypeAdd (CommandInterpreter &interpreter) :
+    CommandObject (interpreter,
+                   "type format add",
+                   "Add a new formatting style for a type.",
+                   NULL), m_options (interpreter)
+    {
+        CommandArgumentEntry format_arg;
+        CommandArgumentData format_style_arg;
+        CommandArgumentEntry type_arg;
+        CommandArgumentData type_style_arg;
+        
+        format_style_arg.arg_type = eArgTypeFormat;
+        format_style_arg.arg_repetition = eArgRepeatPlain;
+                
+        type_style_arg.arg_type = eArgTypeName;
+        type_style_arg.arg_repetition = eArgRepeatPlus;
+        
+        format_arg.push_back (format_style_arg);
+        type_arg.push_back (type_style_arg);
+        
+        m_arguments.push_back (format_arg);
+        m_arguments.push_back (type_arg);
+    }
+    
+    ~CommandObjectTypeAdd ()
+    {
+    }
+    
+    bool
+    Execute (Args& command, CommandReturnObject &result)
+    {
+        const size_t argc = command.GetArgumentCount();
+        
+        if (argc < 2)
+        {
+            result.AppendErrorWithFormat ("%s takes two or more args.\n", m_cmd_name.c_str());
+            result.SetStatus(eReturnStatusFailed);
+            return false;
+        }
+        
+        const char* formatA = command.GetArgumentAtIndex(0);
+        ConstString formatCS(formatA);
+        const char* formatU = formatCS.GetCString();
+        lldb::Format format;
+        uint32_t byte_size_ptr;
+        Error fmt_error = Args::StringToFormat(formatU, format, &byte_size_ptr);
+        
+        if(fmt_error.Fail()) {
+            result.AppendError(fmt_error.AsCString());
+            result.SetStatus(eReturnStatusFailed);
+            return false;
+        }
+        
+        // now I have a valid format, let's add it to every type
+        
+        for(int i = 1; i < argc; i++) {
+            const char* typeA = command.GetArgumentAtIndex(i);
+            ConstString typeCS(typeA);
+            Debugger::AddFormatForType(typeCS, format, m_options.m_cascade);
+        }
+        
+        
+        return result.Succeeded();
+    }
+        
+};
+
+OptionDefinition
+CommandObjectTypeAdd::CommandOptions::g_option_table[] =
+{
+    { LLDB_OPT_SET_ALL, false, "cascade", 'c', required_argument, NULL, 0, eArgTypeBoolean,    "If true, cascade to derived typedefs."},
+    { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
+};
+
+
+//-------------------------------------------------------------------------
+// CommandObjectTypeDelete
+//-------------------------------------------------------------------------
+
+class CommandObjectTypeDelete : public CommandObject
+{
+public:
+    CommandObjectTypeDelete (CommandInterpreter &interpreter) :
+    CommandObject (interpreter,
+                   "type format delete",
+                   "Delete an existing formatting style for a type.",
+                   NULL)
+    {
+        CommandArgumentEntry type_arg;
+        CommandArgumentData type_style_arg;
+                
+        type_style_arg.arg_type = eArgTypeName;
+        type_style_arg.arg_repetition = eArgRepeatPlain;
+        
+        type_arg.push_back (type_style_arg);
+        
+        m_arguments.push_back (type_arg);
+
+    }
+    
+    ~CommandObjectTypeDelete ()
+    {
+    }
+    
+    bool
+    Execute (Args& command, CommandReturnObject &result)
+    {
+        const size_t argc = command.GetArgumentCount();
+        
+        if (argc != 1)
+        {
+            result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
+            result.SetStatus(eReturnStatusFailed);
+            return false;
+        }
+        
+        const char* typeA = command.GetArgumentAtIndex(0);
+        ConstString typeCS(typeA);
+        
+        if(Debugger::DeleteFormatForType(typeCS))
+            return result.Succeeded();
+        else
+        {
+            result.AppendErrorWithFormat ("no custom format for %s.\n", typeA);
+            result.SetStatus(eReturnStatusFailed);
+            return false;
+        }
+
+    }
+    
+};
+
+//-------------------------------------------------------------------------
+// CommandObjectTypeList
+//-------------------------------------------------------------------------
+
+bool CommandObjectTypeList_LoopCallback(void* pt2self, const char* type, lldb::Format format, bool cascade);
+
+class CommandObjectTypeList;
+
+struct CommandObjectTypeList_LoopCallbackParam {
+    CommandObjectTypeList* self;
+    CommandReturnObject* result;
+    RegularExpression* regex;
+    CommandObjectTypeList_LoopCallbackParam(CommandObjectTypeList* S, CommandReturnObject* R,
+                                            RegularExpression* X = NULL) : self(S), result(R), regex(X) {}
+};
+
+class CommandObjectTypeList : public CommandObject
+{
+public:
+    CommandObjectTypeList (CommandInterpreter &interpreter) :
+    CommandObject (interpreter,
+                   "type format list",
+                   "Show a list of current formatting styles.",
+                   NULL)
+    {
+        CommandArgumentEntry type_arg;
+        CommandArgumentData type_style_arg;
+        
+        type_style_arg.arg_type = eArgTypeName;
+        type_style_arg.arg_repetition = eArgRepeatOptional;
+        
+        type_arg.push_back (type_style_arg);
+        
+        m_arguments.push_back (type_arg);
+    }
+    
+    ~CommandObjectTypeList ()
+    {
+    }
+    
+    bool
+    Execute (Args& command, CommandReturnObject &result)
+    {
+        const size_t argc = command.GetArgumentCount();
+        
+        CommandObjectTypeList_LoopCallbackParam *param;
+        
+        if (argc == 1) {
+            RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
+            regex->Compile(command.GetArgumentAtIndex(0));
+            param = new CommandObjectTypeList_LoopCallbackParam(this,&result,regex);
+        }
+        else
+            param = new CommandObjectTypeList_LoopCallbackParam(this,&result);
+        Debugger::LoopThroughFormatList(CommandObjectTypeList_LoopCallback, param);
+        delete param;
+        return result.Succeeded();
+    }
+    
+private:
+    
+    bool
+    LoopCallback (
+                  const char* type,
+                  lldb::Format format,
+                  bool cascade,
+                  RegularExpression* regex,
+                  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;
+        }
+        return true;
+    }
+    
+    friend bool CommandObjectTypeList_LoopCallback(void* pt2self, const char* type, lldb::Format format, bool cascade);
+    
+};
+
+bool
+CommandObjectTypeList_LoopCallback (
+                                    void* pt2self,
+                                    const char* type,
+                                    lldb::Format format,
+                                    bool cascade)
+{
+    CommandObjectTypeList_LoopCallbackParam* param = (CommandObjectTypeList_LoopCallbackParam*)pt2self;
+    return param->self->LoopCallback(type, format, cascade, param->regex, param->result);
+}
+
+class CommandObjectTypeFormat : public CommandObjectMultiword
+{
+public:
+    CommandObjectTypeFormat (CommandInterpreter &interpreter) :
+        CommandObjectMultiword (interpreter,
+                                "type format",
+                                "A set of commands for editing variable display options",
+                                "type format [<sub-command-options>] ")
+    {
+        LoadSubCommand ("add",    CommandObjectSP (new CommandObjectTypeAdd (interpreter)));
+        LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeDelete (interpreter)));
+        LoadSubCommand ("list",   CommandObjectSP (new CommandObjectTypeList (interpreter)));
+    }
+
+
+    ~CommandObjectTypeFormat ()
+    {
+    }
+};
+
+//-------------------------------------------------------------------------
+// CommandObjectType
+//-------------------------------------------------------------------------
+
+CommandObjectType::CommandObjectType (CommandInterpreter &interpreter) :
+    CommandObjectMultiword (interpreter,
+                            "type",
+                            "A set of commands for operating on the type system",
+                            "type [<sub-command-options>]")
+{
+    LoadSubCommand ("format",    CommandObjectSP (new CommandObjectTypeFormat (interpreter)));
+}
+
+
+CommandObjectType::~CommandObjectType ()
+{
+}
+
+

Added: lldb/trunk/source/Commands/CommandObjectType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.h?rev=133728&view=auto
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.h (added)
+++ lldb/trunk/source/Commands/CommandObjectType.h Thu Jun 23 12:59:56 2011
@@ -0,0 +1,42 @@
+//===-- CommandObjectType.h ------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_CommandObjectType_h_
+#define liblldb_CommandObjectType_h_
+
+// C Includes
+// C++ Includes
+
+
+// Other libraries and framework includes
+// Project includes
+
+#include "lldb/lldb-types.h"
+#include "lldb/Interpreter/CommandObjectMultiword.h"
+
+namespace lldb_private {
+
+//-------------------------------------------------------------------------
+// CommandObjectMultiwordBreakpoint
+//-------------------------------------------------------------------------
+
+class CommandObjectType : public CommandObjectMultiword
+{
+public:
+    CommandObjectType (CommandInterpreter &interpreter);
+
+    virtual
+    ~CommandObjectType ();
+};
+
+
+
+} // namespace lldb_private
+
+#endif  // liblldb_CommandObjectType_h_

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=133728&r1=133727&r2=133728&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Thu Jun 23 12:59:56 2011
@@ -7,9 +7,13 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "lldb/Core/Debugger.h"
+
+#include <map>
+
 #include "lldb/lldb-private.h"
 #include "lldb/Core/ConnectionFileDescriptor.h"
-#include "lldb/Core/Debugger.h"
+#include "lldb/Core/FormatManager.h"
 #include "lldb/Core/InputReader.h"
 #include "lldb/Core/RegisterValue.h"
 #include "lldb/Core/State.h"
@@ -1309,6 +1313,37 @@
     return success;
 }
 
+
+static FormatManager&
+GetFormatManager() {
+    static FormatManager g_format_manager;
+    return g_format_manager;
+}
+
+bool
+Debugger::GetFormatForType (const ConstString &type, lldb::Format& format, bool& cascade)
+{
+    return GetFormatManager().GetFormatForType(type, format, cascade);
+}
+
+void
+Debugger::AddFormatForType (const ConstString &type, lldb::Format format, bool cascade)
+{
+    GetFormatManager().AddFormatForType(type,format, cascade);
+}
+
+bool
+Debugger::DeleteFormatForType (const ConstString &type)
+{
+    return GetFormatManager().DeleteFormatForType(type);
+}
+
+void
+Debugger::LoopThroughFormatList (FormatCallback cback, void* param)
+{
+    return GetFormatManager().LoopThroughFormatList(cback, param);
+}
+
 #pragma mark Debugger::SettingsController
 
 //--------------------------------------------------

Added: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=133728&view=auto
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (added)
+++ lldb/trunk/source/Core/FormatManager.cpp Thu Jun 23 12:59:56 2011
@@ -0,0 +1,69 @@
+//===-- 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;
+
+bool FormatManager::GetFormatForType (const ConstString &type, lldb::Format& format, bool& cascade)
+{
+    Mutex::Locker locker (m_format_map_mutex);
+    FormatMap& fmtmap = m_format_map;
+    FormatMap::iterator iter = fmtmap.find(type.GetCString());
+    if(iter == fmtmap.end())
+        return false;
+    else {
+        format = iter->second.FormatStyle;
+        cascade = iter->second.Cascades;
+        return true;
+    }
+}
+
+void FormatManager::AddFormatForType (const ConstString &type, lldb::Format format, bool cascade)
+{
+    format_entry_t entry(format, cascade);
+    Mutex::Locker locker (m_format_map_mutex);
+    FormatMap& fmtmap = m_format_map;
+    fmtmap[type.GetCString()] = entry;
+}
+
+bool FormatManager::DeleteFormatForType (const ConstString &type)
+{
+    Mutex::Locker locker (m_format_map_mutex);
+    FormatMap& fmtmap = m_format_map;
+    const char* typeCS = type.GetCString();
+    FormatMap::iterator iter = fmtmap.find(typeCS);
+    if (iter == fmtmap.end())
+        return false;
+    else {
+        fmtmap.erase(typeCS);
+        return true;
+    }
+}
+
+void FormatManager::LoopThroughFormatList (FormatCallback cback, 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++;
+    }
+}
+

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=133728&r1=133727&r2=133728&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Thu Jun 23 12:59:56 2011
@@ -941,7 +941,7 @@
                                             "  f - float\n"
                                             "  g - float\n"
                                             "  i - signed decimal\n"
-                                            "  i - complex integer\n"
+                                            "  I - complex integer\n"
                                             "  o - octal\n"
                                             "  O - OSType\n"
                                             "  p - pointer\n"

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=133728&r1=133727&r2=133728&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Thu Jun 23 12:59:56 2011
@@ -13,13 +13,14 @@
 #include <getopt.h>
 #include <stdlib.h>
 
+#include "CommandObjectScript.h"
+#include "CommandObjectRegexCommand.h"
+
 #include "../Commands/CommandObjectApropos.h"
 #include "../Commands/CommandObjectArgs.h"
 #include "../Commands/CommandObjectBreakpoint.h"
-//#include "../Commands/CommandObjectCall.h"
 #include "../Commands/CommandObjectDisassemble.h"
 #include "../Commands/CommandObjectExpression.h"
-//#include "../Commands/CommandObjectFile.h"
 #include "../Commands/CommandObjectFrame.h"
 #include "../Commands/CommandObjectHelp.h"
 #include "../Commands/CommandObjectLog.h"
@@ -27,15 +28,14 @@
 #include "../Commands/CommandObjectPlatform.h"
 #include "../Commands/CommandObjectProcess.h"
 #include "../Commands/CommandObjectQuit.h"
-#include "lldb/Interpreter/CommandObjectRegexCommand.h"
 #include "../Commands/CommandObjectRegister.h"
-#include "CommandObjectScript.h"
 #include "../Commands/CommandObjectSettings.h"
 #include "../Commands/CommandObjectSource.h"
 #include "../Commands/CommandObjectCommands.h"
 #include "../Commands/CommandObjectSyntax.h"
 #include "../Commands/CommandObjectTarget.h"
 #include "../Commands/CommandObjectThread.h"
+#include "../Commands/CommandObjectType.h"
 #include "../Commands/CommandObjectVersion.h"
 
 #include "lldb/Interpreter/Args.h"
@@ -261,6 +261,7 @@
     m_command_dict["source"]    = CommandObjectSP (new CommandObjectMultiwordSource (*this));
     m_command_dict["target"]    = CommandObjectSP (new CommandObjectMultiwordTarget (*this));
     m_command_dict["thread"]    = CommandObjectSP (new CommandObjectMultiwordThread (*this));
+    m_command_dict["type"]    = CommandObjectSP (new CommandObjectType (*this));
     m_command_dict["version"]   = CommandObjectSP (new CommandObjectVersion (*this));
 
     std::auto_ptr<CommandObjectRegexCommand>

Modified: lldb/trunk/source/Symbol/ClangASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=133728&r1=133727&r2=133728&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTType.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTType.cpp Thu Jun 23 12:59:56 2011
@@ -16,6 +16,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclGroup.h"
 #include "clang/AST/RecordLayout.h"
+#include "clang/AST/Type.h"
 
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/IdentifierTable.h"
@@ -36,6 +37,9 @@
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
 
+
+#include "Debugger.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -55,22 +59,9 @@
     ConstString clang_type_name;
     if (clang_type)
     {
-        clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
-
-        const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
-        if (typedef_type)
-        {
-            const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
-            std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString());
-            if (!clang_typedef_name.empty())
-                clang_type_name.SetCString (clang_typedef_name.c_str());
-        }
-        else
-        {
-            std::string type_name(qual_type.getAsString());
-            if (!type_name.empty())
-                clang_type_name.SetCString (type_name.c_str());
-        }
+        clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));        
+        return GetClangTypeName(qual_type);
+        
     }
     else
     {
@@ -80,6 +71,26 @@
     return clang_type_name;
 }
 
+ConstString
+ClangASTType::GetClangTypeName (clang::QualType qual_type)
+{
+    ConstString clang_type_name;
+    const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
+    if (typedef_type)
+    {
+        const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
+        std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString());
+        if (!clang_typedef_name.empty())
+            clang_type_name.SetCString (clang_typedef_name.c_str());
+    }
+    else
+    {
+        std::string type_name(qual_type.getAsString());
+        if (!type_name.empty())
+            clang_type_name.SetCString (type_name.c_str());
+    }
+    return clang_type_name;
+}
 
 clang_type_t
 ClangASTType::GetPointeeType ()
@@ -237,8 +248,25 @@
 lldb::Format
 ClangASTType::GetFormat (clang_type_t clang_type)
 {
+    // first of all, check for a valid format for this type itself
     clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
-
+    lldb::Format format;
+    bool cascade;
+    if(Debugger::GetFormatForType(GetClangTypeName(qual_type), format, cascade))
+        return format; // return it if found
+    
+    // here, I know this type does not have a direct format. two things can happen:
+    // 1) this is a typedef - I expand this to its parent type and look there
+    // 2) this is not a typedef - I use the default formatting options
+    const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
+    while (typedef_type) {
+        qual_type = typedef_type->getDecl()->getUnderlyingType();
+        std::string name = qual_type.getAsString();
+        if(Debugger::GetFormatForType(GetClangTypeName(qual_type), format, cascade) && cascade) // if I have a cascading format...
+            return format; // ...use it
+        typedef_type = qual_type->getAs<clang::TypedefType>(); // try to expand another level
+    }
+    
     switch (qual_type->getTypeClass())
     {
     case clang::Type::FunctionNoProto:





More information about the lldb-commits mailing list