1254721Semaste//===-- OptionGroupValueObjectDisplay.cpp -----------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "lldb/lldb-python.h" 11254721Semaste 12254721Semaste#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" 13254721Semaste 14254721Semaste// C Includes 15254721Semaste// C++ Includes 16254721Semaste// Other libraries and framework includes 17254721Semaste// Project includes 18263363Semaste#include "lldb/DataFormatters/ValueObjectPrinter.h" 19254721Semaste#include "lldb/Target/Target.h" 20254721Semaste#include "lldb/Interpreter/CommandInterpreter.h" 21254721Semaste#include "lldb/Utility/Utils.h" 22254721Semaste 23254721Semasteusing namespace lldb; 24254721Semasteusing namespace lldb_private; 25254721Semaste 26254721SemasteOptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() 27254721Semaste{ 28254721Semaste} 29254721Semaste 30254721SemasteOptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay () 31254721Semaste{ 32254721Semaste} 33254721Semaste 34254721Semastestatic OptionDefinition 35254721Semasteg_option_table[] = 36254721Semaste{ 37263363Semaste { LLDB_OPT_SET_1, false, "dynamic-type", 'd', OptionParser::eRequiredArgument, g_dynamic_value_types, 0, eArgTypeNone, "Show the object as its full dynamic type, not its static type, if available."}, 38263363Semaste { LLDB_OPT_SET_1, false, "synthetic-type", 'S', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."}, 39263363Semaste { LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount, "Set the max recurse depth when dumping aggregate types (default is infinity)."}, 40263363Semaste { LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Display results in a flat format that uses expression paths for each variable or member."}, 41263363Semaste { LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Show variable location information."}, 42263363Semaste { LLDB_OPT_SET_1, false, "object-description", 'O', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Print as an Objective-C object."}, 43263363Semaste { LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount, "The number of pointers to be traversed when dumping values (default is zero)."}, 44263363Semaste { LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Show variable types when dumping values."}, 45263363Semaste { LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', OptionParser::eOptionalArgument, NULL, 0, eArgTypeCount, "Set the depth at which omitting summary information stops (default is 1)."}, 46263363Semaste { LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use formatting options."}, 47263363Semaste { LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Ignore the upper bound on the number of children to show."}, 48254721Semaste { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 49254721Semaste}; 50254721Semaste 51254721Semasteuint32_t 52254721SemasteOptionGroupValueObjectDisplay::GetNumDefinitions () 53254721Semaste{ 54254721Semaste return llvm::array_lengthof(g_option_table); 55254721Semaste} 56254721Semaste 57254721Semasteconst OptionDefinition * 58254721SemasteOptionGroupValueObjectDisplay::GetDefinitions () 59254721Semaste{ 60254721Semaste return g_option_table; 61254721Semaste} 62254721Semaste 63254721Semaste 64254721SemasteError 65254721SemasteOptionGroupValueObjectDisplay::SetOptionValue (CommandInterpreter &interpreter, 66254721Semaste uint32_t option_idx, 67254721Semaste const char *option_arg) 68254721Semaste{ 69254721Semaste Error error; 70254721Semaste const int short_option = g_option_table[option_idx].short_option; 71254721Semaste bool success = false; 72254721Semaste 73254721Semaste switch (short_option) 74254721Semaste { 75254721Semaste case 'd': 76254721Semaste { 77254721Semaste int32_t result; 78254721Semaste result = Args::StringToOptionEnum (option_arg, g_dynamic_value_types, 2, error); 79254721Semaste if (error.Success()) 80254721Semaste use_dynamic = (lldb::DynamicValueType) result; 81254721Semaste } 82254721Semaste break; 83254721Semaste case 'T': show_types = true; break; 84254721Semaste case 'L': show_location= true; break; 85254721Semaste case 'F': flat_output = true; break; 86254721Semaste case 'O': use_objc = true; break; 87254721Semaste case 'R': be_raw = true; break; 88254721Semaste case 'A': ignore_cap = true; break; 89254721Semaste 90254721Semaste case 'D': 91254721Semaste max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success); 92254721Semaste if (!success) 93254721Semaste error.SetErrorStringWithFormat("invalid max depth '%s'", option_arg); 94254721Semaste break; 95254721Semaste 96254721Semaste case 'P': 97254721Semaste ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success); 98254721Semaste if (!success) 99254721Semaste error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); 100254721Semaste break; 101254721Semaste 102254721Semaste case 'Y': 103254721Semaste if (option_arg) 104254721Semaste { 105254721Semaste no_summary_depth = Args::StringToUInt32 (option_arg, 0, 0, &success); 106254721Semaste if (!success) 107254721Semaste error.SetErrorStringWithFormat("invalid pointer depth '%s'", option_arg); 108254721Semaste } 109254721Semaste else 110254721Semaste no_summary_depth = 1; 111254721Semaste break; 112254721Semaste 113254721Semaste case 'S': 114254721Semaste use_synth = Args::StringToBoolean(option_arg, true, &success); 115254721Semaste if (!success) 116254721Semaste error.SetErrorStringWithFormat("invalid synthetic-type '%s'", option_arg); 117254721Semaste break; 118254721Semaste default: 119254721Semaste error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 120254721Semaste break; 121254721Semaste } 122254721Semaste 123254721Semaste return error; 124254721Semaste} 125254721Semaste 126254721Semastevoid 127254721SemasteOptionGroupValueObjectDisplay::OptionParsingStarting (CommandInterpreter &interpreter) 128254721Semaste{ 129254721Semaste // If these defaults change, be sure to modify AnyOptionWasSet(). 130254721Semaste show_types = false; 131254721Semaste no_summary_depth = 0; 132254721Semaste show_location = false; 133254721Semaste flat_output = false; 134254721Semaste use_objc = false; 135254721Semaste max_depth = UINT32_MAX; 136254721Semaste ptr_depth = 0; 137254721Semaste use_synth = true; 138254721Semaste be_raw = false; 139254721Semaste ignore_cap = false; 140254721Semaste 141254721Semaste Target *target = interpreter.GetExecutionContext().GetTargetPtr(); 142254721Semaste if (target != NULL) 143254721Semaste use_dynamic = target->GetPreferDynamicValue(); 144254721Semaste else 145254721Semaste { 146254721Semaste // If we don't have any targets, then dynamic values won't do us much good. 147254721Semaste use_dynamic = lldb::eNoDynamicValues; 148254721Semaste } 149254721Semaste} 150254721Semaste 151263363SemasteDumpValueObjectOptions 152263363SemasteOptionGroupValueObjectDisplay::GetAsDumpOptions (LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity, 153254721Semaste lldb::Format format, 154254721Semaste lldb::TypeSummaryImplSP summary_sp) 155254721Semaste{ 156263363Semaste DumpValueObjectOptions options; 157254721Semaste options.SetMaximumPointerDepth(ptr_depth); 158254721Semaste if (use_objc) 159254721Semaste options.SetShowSummary(false); 160254721Semaste else 161254721Semaste options.SetOmitSummaryDepth(no_summary_depth); 162254721Semaste options.SetMaximumDepth(max_depth) 163254721Semaste .SetShowTypes(show_types) 164254721Semaste .SetShowLocation(show_location) 165254721Semaste .SetUseObjectiveC(use_objc) 166254721Semaste .SetUseDynamicType(use_dynamic) 167254721Semaste .SetUseSyntheticValue(use_synth) 168254721Semaste .SetFlatOutput(flat_output) 169254721Semaste .SetIgnoreCap(ignore_cap) 170254721Semaste .SetFormat(format) 171254721Semaste .SetSummary(summary_sp); 172254721Semaste 173263363Semaste if (lang_descr_verbosity == eLanguageRuntimeDescriptionDisplayVerbosityCompact) 174254721Semaste options.SetHideRootType(use_objc) 175254721Semaste .SetHideName(use_objc) 176254721Semaste .SetHideValue(use_objc); 177254721Semaste 178254721Semaste if (be_raw) 179254721Semaste options.SetRawDisplay(true); 180254721Semaste 181254721Semaste return options; 182254721Semaste} 183