Home | History | Annotate | Download | only in Interpreter
      1 //===-- OptionGroupValueObjectDisplay.cpp -----------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #include "lldb/lldb-python.h"
     11 
     12 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
     13 
     14 // C Includes
     15 // C++ Includes
     16 // Other libraries and framework includes
     17 // Project includes
     18 #include "lldb/Target/Target.h"
     19 #include "lldb/Interpreter/CommandInterpreter.h"
     20 #include "lldb/Utility/Utils.h"
     21 
     22 using namespace lldb;
     23 using namespace lldb_private;
     24 
     25 OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay()
     26 {
     27 }
     28 
     29 OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay ()
     30 {
     31 }
     32 
     33 static OptionDefinition
     34 g_option_table[] =
     35 {
     36     { LLDB_OPT_SET_1, false, "dynamic-type",       'd', required_argument, g_dynamic_value_types, 0, eArgTypeNone,      "Show the object as its full dynamic type, not its static type, if available."},
     37     { LLDB_OPT_SET_1, false, "synthetic-type",     'S', required_argument, NULL, 0, eArgTypeBoolean,   "Show the object obeying its synthetic provider, if available."},
     38     { LLDB_OPT_SET_1, false, "depth",              'D', required_argument, NULL, 0, eArgTypeCount,     "Set the max recurse depth when dumping aggregate types (default is infinity)."},
     39     { LLDB_OPT_SET_1, false, "flat",               'F', no_argument,       NULL, 0, eArgTypeNone,      "Display results in a flat format that uses expression paths for each variable or member."},
     40     { LLDB_OPT_SET_1, false, "location",           'L', no_argument,       NULL, 0, eArgTypeNone,      "Show variable location information."},
     41     { LLDB_OPT_SET_1, false, "object-description", 'O', no_argument,       NULL, 0, eArgTypeNone,      "Print as an Objective-C object."},
     42     { LLDB_OPT_SET_1, false, "ptr-depth",          'P', required_argument, NULL, 0, eArgTypeCount,     "The number of pointers to be traversed when dumping values (default is zero)."},
     43     { LLDB_OPT_SET_1, false, "show-types",         'T', no_argument,       NULL, 0, eArgTypeNone,      "Show variable types when dumping values."},
     44     { LLDB_OPT_SET_1, false, "no-summary-depth",   'Y', optional_argument, NULL, 0, eArgTypeCount,     "Set the depth at which omitting summary information stops (default is 1)."},
     45     { LLDB_OPT_SET_1, false, "raw-output",         'R', no_argument,       NULL, 0, eArgTypeNone,      "Don't use formatting options."},
     46     { LLDB_OPT_SET_1, false, "show-all-children",  'A', no_argument,       NULL, 0, eArgTypeNone,      "Ignore the upper bound on the number of children to show."},
     47     { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
     48 };
     49 
     50 uint32_t
     51 OptionGroupValueObjectDisplay::GetNumDefinitions ()
     52 {
     53     return llvm::array_lengthof(g_option_table);
     54 }
     55 
     56 const OptionDefinition *
     57 OptionGroupValueObjectDisplay::GetDefinitions ()
     58 {
     59     return g_option_table;
     60 }
     61 
     62 
     63 Error
     64 OptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter,
     65                                                uint32_t option_idx,
     66                                                const char *option_arg)
     67 {
     68     Error error;
     69     const int short_option = g_option_table[option_idx].short_option;
     70     bool success = false;
     71 
     72     switch (short_option)
     73     {
     74         case 'd':
     75             {
     76                 int32_t result;
     77                 result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error);
     78                 if (error.Success())
     79                     use_dynamic = (lldb::DynamicValueType) result;
     80             }
     81             break;
     82         case 'T':   show_types   = true;  break;
     83         case 'L':   show_location= true;  break;
     84         case 'F':   flat_output  = true;  break;
     85         case 'O':   use_objc     = true;  break;
     86         case 'R':   be_raw       = true;  break;
     87         case 'A':   ignore_cap   = true;  break;
     88 
     89         case 'D':
     90             max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
     91             if (!success)
     92                 error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg);
     93             break;
     94 
     95         case 'P':
     96             ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
     97             if (!success)
     98                 error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
     99             break;
    100 
    101         case 'Y':
    102             if (option_arg)
    103             {
    104                 no_summary_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
    105                 if (!success)
    106                     error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg);
    107             }
    108             else
    109                 no_summary_depth = 1;
    110             break;
    111 
    112         case 'S':
    113             use_synth = Args::StringToBoolean(option_arg, true, &success);
    114             if (!success)
    115                 error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg);
    116             break;
    117         default:
    118             error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
    119             break;
    120     }
    121 
    122     return error;
    123 }
    124 
    125 void
    126 OptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter)
    127 {
    128     // If these defaults change, be sure to modify AnyOptionWasSet().
    129     show_types        = false;
    130     no_summary_depth  = 0;
    131     show_location     = false;
    132     flat_output       = false;
    133     use_objc          = false;
    134     max_depth         = UINT32_MAX;
    135     ptr_depth         = 0;
    136     use_synth         = true;
    137     be_raw            = false;
    138     ignore_cap        = false;
    139 
    140     Target *target = interpreter.GetExecutionContext().GetTargetPtr();
    141     if (target != NULL)
    142         use_dynamic = target->GetPreferDynamicValue();
    143     else
    144     {
    145         // If we don't have any targets, then dynamic values won't do us much good.
    146         use_dynamic = lldb::eNoDynamicValues;
    147     }
    148 }
    149 
    150 ValueObject::DumpValueObjectOptions
    151 OptionGroupValueObjectDisplay::GetAsDumpOptions (bool objc_is_compact,
    152                                                  lldb::Format format,
    153                                                  lldb::TypeSummaryImplSP summary_sp)
    154 {
    155     ValueObject::DumpValueObjectOptions options;
    156     options.SetMaximumPointerDepth(ptr_depth);
    157     if (use_objc)
    158         options.SetShowSummary(false);
    159     else
    160         options.SetOmitSummaryDepth(no_summary_depth);
    161     options.SetMaximumDepth(max_depth)
    162     .SetShowTypes(show_types)
    163     .SetShowLocation(show_location)
    164     .SetUseObjectiveC(use_objc)
    165     .SetUseDynamicType(use_dynamic)
    166     .SetUseSyntheticValue(use_synth)
    167     .SetFlatOutput(flat_output)
    168     .SetIgnoreCap(ignore_cap)
    169     .SetFormat(format)
    170     .SetSummary(summary_sp);
    171 
    172     if (objc_is_compact)
    173         options.SetHideRootType(use_objc)
    174         .SetHideName(use_objc)
    175         .SetHideValue(use_objc);
    176 
    177     if (be_raw)
    178         options.SetRawDisplay(true);
    179 
    180     return options;
    181 }
    182