[Lldb-commits] [lldb] r217303 - Add a -V <bool> flag to frame variable/expression that enables execution of type validators. The jury is still out on what the user experience of type validators should be, so for now gate it on a specific flag. The mode I am using is prefix variables that fail to validate with a bang, and then emitting the actual validation error on a separate line. Of course, given the total absence of validators, this should never actually happen to you

Enrico Granata egranata at apple.com
Fri Sep 5 19:20:19 PDT 2014


Author: enrico
Date: Fri Sep  5 21:20:19 2014
New Revision: 217303

URL: http://llvm.org/viewvc/llvm-project?rev=217303&view=rev
Log:
Add a -V <bool> flag to frame variable/expression that enables execution of type validators. The jury is still out on what the user experience of type validators should be, so for now gate it on a specific flag. The mode I am using is prefix variables that fail to validate with a bang, and then emitting the actual validation error on a separate line. Of course, given the total absence of validators, this should never actually happen to you

Modified:
    lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h
    lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h
    lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp
    lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp

Modified: lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h?rev=217303&r1=217302&r2=217303&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h Fri Sep  5 21:20:19 2014
@@ -44,6 +44,7 @@ struct DumpValueObjectOptions
     bool m_hide_name;
     bool m_hide_value;
     bool m_be_raw;
+    bool m_run_validator;
     
     DumpValueObjectOptions() :
     m_max_ptr_depth(0),
@@ -63,7 +64,8 @@ struct DumpValueObjectOptions
     m_hide_root_type(false),  // provide a special compact display for "po"
     m_hide_name(false), // provide a special compact display for "po"
     m_hide_value(false), // provide a special compact display for "po"
-    m_be_raw(false)
+    m_be_raw(false),
+    m_run_validator(false)
     {}
     
     static const DumpValueObjectOptions
@@ -92,7 +94,8 @@ struct DumpValueObjectOptions
     m_hide_root_type(rhs.m_hide_root_type),
     m_hide_name(rhs.m_hide_name),
     m_hide_value(rhs.m_hide_value),
-    m_be_raw(rhs.m_be_raw)
+    m_be_raw(rhs.m_be_raw),
+    m_run_validator(rhs.m_run_validator)
     {}
     
     DumpValueObjectOptions&
@@ -250,6 +253,13 @@ struct DumpValueObjectOptions
         m_hide_value = hide_value;
         return *this;
     }
+    
+    DumpValueObjectOptions&
+    SetRunValidator (bool run = true)
+    {
+        m_run_validator = run;
+        return *this;
+    }
 };
     
 class ValueObjectPrinter
@@ -297,6 +307,9 @@ protected:
     ShouldPrintValueObject ();
     
     bool
+    ShouldPrintValidation ();
+    
+    bool
     IsNil ();
     
     bool
@@ -309,6 +322,12 @@ protected:
     IsAggregate ();
     
     bool
+    PrintValidationMarkerIfNeeded ();
+    
+    bool
+    PrintValidationErrorIfNeeded ();
+    
+    bool
     PrintLocationIfNeeded ();
     
     bool
@@ -385,6 +404,7 @@ private:
     std::string m_value;
     std::string m_summary;
     std::string m_error;
+    std::pair<TypeValidatorResult,std::string> m_validation;
     
     friend struct StringSummaryFormat;
     

Modified: lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h?rev=217303&r1=217302&r2=217303&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h Fri Sep  5 21:20:19 2014
@@ -59,7 +59,8 @@ public:
                ptr_depth != 0 ||
                use_synth == false ||
                be_raw == true ||
-               ignore_cap == true;
+               ignore_cap == true ||
+               run_validator == true;
     }
     
     DumpValueObjectOptions
@@ -67,17 +68,19 @@ public:
                       lldb::Format format = lldb::eFormatDefault,
                       lldb::TypeSummaryImplSP summary_sp = lldb::TypeSummaryImplSP());
 
-    bool show_types;
+    bool show_types : 1,
+         show_location : 1,
+         flat_output : 1,
+         use_objc : 1,
+         use_synth : 1,
+         be_raw : 1,
+         ignore_cap : 1,
+         run_validator : 1;
+    
     uint32_t no_summary_depth;
-    bool show_location;
-    bool flat_output;
-    bool use_objc;
     uint32_t max_depth;
     uint32_t ptr_depth;
     lldb::DynamicValueType use_dynamic;
-    bool use_synth;
-    bool be_raw;
-    bool ignore_cap;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp?rev=217303&r1=217302&r2=217303&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp (original)
+++ lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp Fri Sep  5 21:20:19 2014
@@ -71,6 +71,8 @@ ValueObjectPrinter::PrintValueObject ()
     
     if (ShouldPrintValueObject())
     {
+        PrintValidationMarkerIfNeeded();
+        
         PrintLocationIfNeeded();
         m_stream->Indent();
         
@@ -89,6 +91,8 @@ ValueObjectPrinter::PrintValueObject ()
     else
         m_stream->EOL();
     
+    PrintValidationErrorIfNeeded();
+    
     return true;
 }
 
@@ -624,3 +628,44 @@ ValueObjectPrinter::PrintChildrenIfNeede
     else
         m_stream->EOL();
 }
+
+bool
+ValueObjectPrinter::ShouldPrintValidation ()
+{
+    return options.m_run_validator;
+}
+
+bool
+ValueObjectPrinter::PrintValidationMarkerIfNeeded ()
+{
+    if (!ShouldPrintValidation())
+        return false;
+    
+    m_validation = m_valobj->GetValidationStatus();
+    
+    if (TypeValidatorResult::Failure == m_validation.first)
+    {
+        m_stream->Printf("! ");
+        return true;
+    }
+    
+    return false;
+}
+
+bool
+ValueObjectPrinter::PrintValidationErrorIfNeeded ()
+{
+    if (!ShouldPrintValidation())
+        return false;
+    
+    if (TypeValidatorResult::Success == m_validation.first)
+        return false;
+    
+    if (m_validation.second.empty())
+        m_validation.second.assign("unknown error");
+    
+    m_stream->Printf(" ! validation error: %s", m_validation.second.c_str());
+    m_stream->EOL();
+    
+    return true;
+}

Modified: lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp?rev=217303&r1=217302&r2=217303&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp Fri Sep  5 21:20:19 2014
@@ -45,6 +45,7 @@ g_option_table[] =
     { LLDB_OPT_SET_1, false, "no-summary-depth",   'Y', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeCount,     "Set the depth at which omitting summary information stops (default is 1)."},
     { LLDB_OPT_SET_1, false, "raw-output",         'R', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,      "Don't use formatting options."},
     { LLDB_OPT_SET_1, false, "show-all-children",  'A', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,      "Ignore the upper bound on the number of children to show."},
+    { LLDB_OPT_SET_1, false, "validate",           'V',  OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean,   "Show results of type validators."},
     { 0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
 };
 
@@ -115,6 +116,13 @@ OptionGroupValueObjectDisplay::SetOption
             if (!success)
                 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg);
             break;
+            
+        case 'V':
+            run_validator = Args::StringToBoolean(option_arg, true, &success);
+            if (!success)
+                error.SetErrorStringWithFormat("invalid validate '%s'", option_arg);
+            break;
+            
         default:
             error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
             break;
@@ -137,6 +145,7 @@ OptionGroupValueObjectDisplay::OptionPar
     use_synth         = true;
     be_raw            = false;
     ignore_cap        = false;
+    run_validator     = false;
     
     Target *target = interpreter.GetExecutionContext().GetTargetPtr();
     if (target != nullptr)
@@ -177,6 +186,8 @@ OptionGroupValueObjectDisplay::GetAsDump
     
     if (be_raw)
         options.SetRawDisplay(true);
+    
+    options.SetRunValidator(run_validator);
 
     return options;
 }





More information about the lldb-commits mailing list