diff options
author | emaste <emaste@FreeBSD.org> | 2015-02-06 21:38:51 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2015-02-06 21:38:51 +0000 |
commit | 0c2019f4ca6b2dc6d710f6bb16a0e3ed10271531 (patch) | |
tree | 09bc83f73246ee3c7a779605cd0122093d2a8a19 /source/Commands/CommandObjectType.cpp | |
parent | 01ee1789d6aa7294e5966a97f8d29387f6f81699 (diff) | |
download | FreeBSD-src-0c2019f4ca6b2dc6d710f6bb16a0e3ed10271531.zip FreeBSD-src-0c2019f4ca6b2dc6d710f6bb16a0e3ed10271531.tar.gz |
Import LLDB as of upstream SVN r225923 (git 2b588ecd)
This corresponds with the branchpoint for the 3.6 release.
A number of files not required for the FreeBSD build have been removed.
Sponsored by: DARPA, AFRL
Diffstat (limited to 'source/Commands/CommandObjectType.cpp')
-rw-r--r-- | source/Commands/CommandObjectType.cpp | 125 |
1 files changed, 101 insertions, 24 deletions
diff --git a/source/Commands/CommandObjectType.cpp b/source/Commands/CommandObjectType.cpp index 640fd6d..3a4c60c 100644 --- a/source/Commands/CommandObjectType.cpp +++ b/source/Commands/CommandObjectType.cpp @@ -16,6 +16,7 @@ #include <ctype.h> // C++ Includes +#include <functional> #include "llvm/ADT/StringRef.h" @@ -31,6 +32,11 @@ #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/Options.h" #include "lldb/Interpreter/OptionGroupFormat.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/StackFrame.h" +#include "lldb/Target/Target.h" +#include "lldb/Target/Thread.h" +#include "lldb/Target/ThreadList.h" using namespace lldb; using namespace lldb_private; @@ -2465,22 +2471,7 @@ protected: if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0) { - // we want to make sure to enable "system" last and "default" first - DataVisualization::Categories::Enable(ConstString("default"), TypeCategoryMap::First); - uint32_t num_categories = DataVisualization::Categories::GetCount(); - for (uint32_t i = 0; i < num_categories; i++) - { - lldb::TypeCategoryImplSP category_sp = DataVisualization::Categories::GetCategoryAtIndex(i); - if (category_sp) - { - if ( ::strcmp(category_sp->GetName(), "system") == 0 || - ::strcmp(category_sp->GetName(), "default") == 0 ) - continue; - else - DataVisualization::Categories::Enable(category_sp, TypeCategoryMap::Default); - } - } - DataVisualization::Categories::Enable(ConstString("system"), TypeCategoryMap::Last); + DataVisualization::Categories::EnableStar(); } else { @@ -2630,14 +2621,7 @@ protected: if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0) { - uint32_t num_categories = DataVisualization::Categories::GetCount(); - for (uint32_t i = 0; i < num_categories; i++) - { - lldb::TypeCategoryImplSP category_sp = DataVisualization::Categories::GetCategoryAtIndex(i); - // no need to check if the category is enabled - disabling a disabled category has no effect - if (category_sp) - DataVisualization::Categories::Disable(category_sp); - } + DataVisualization::Categories::DisableStar(); } else { @@ -4253,6 +4237,84 @@ CommandObjectTypeFilterAdd::CommandOptions::g_option_table[] = { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } }; +template <typename FormatterType> +class CommandObjectFormatterInfo : public CommandObjectRaw +{ +public: + typedef std::function<typename FormatterType::SharedPointer(ValueObject&)> DiscoveryFunction; + CommandObjectFormatterInfo (CommandInterpreter &interpreter, + const char* formatter_name, + DiscoveryFunction discovery_func) : + CommandObjectRaw(interpreter, + nullptr, + nullptr, + nullptr, + eFlagRequiresFrame), + m_formatter_name(formatter_name ? formatter_name : ""), + m_discovery_function(discovery_func) + { + StreamString name; + name.Printf("type %s info", formatter_name); + SetCommandName(name.GetData()); + StreamString help; + help.Printf("This command evaluates the provided expression and shows which %s is applied to the resulting value (if any).", formatter_name); + SetHelp(help.GetData()); + StreamString syntax; + syntax.Printf("type %s info <expr>", formatter_name); + SetSyntax(syntax.GetData()); + } + + virtual + ~CommandObjectFormatterInfo () + { + } + +protected: + virtual bool + DoExecute (const char *command, CommandReturnObject &result) + { + auto target_sp = m_interpreter.GetDebugger().GetSelectedTarget(); + auto frame_sp = target_sp->GetProcessSP()->GetThreadList().GetSelectedThread()->GetSelectedFrame(); + ValueObjectSP result_valobj_sp; + EvaluateExpressionOptions options; + lldb::ExpressionResults expr_result = target_sp->EvaluateExpression(command, frame_sp.get(), result_valobj_sp, options); + if (expr_result == eExpressionCompleted && result_valobj_sp) + { + result_valobj_sp = result_valobj_sp->GetQualifiedRepresentationIfAvailable(target_sp->GetPreferDynamicValue(), target_sp->GetEnableSyntheticValue()); + typename FormatterType::SharedPointer formatter_sp = m_discovery_function(*result_valobj_sp); + if (formatter_sp) + { + std::string description(formatter_sp->GetDescription()); + result.AppendMessageWithFormat("%s applied to (%s) %s is: %s\n", + m_formatter_name.c_str(), + result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"), + command, + description.c_str()); + result.SetStatus(lldb::eReturnStatusSuccessFinishResult); + } + else + { + result.AppendMessageWithFormat("no %s applies to (%s) %s\n", + m_formatter_name.c_str(), + result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"), + command); + result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult); + } + return true; + } + else + { + result.AppendError("failed to evaluate expression"); + result.SetStatus(lldb::eReturnStatusFailed); + return false; + } + } + +private: + std::string m_formatter_name; + DiscoveryFunction m_discovery_function; +}; + class CommandObjectTypeFormat : public CommandObjectMultiword { public: @@ -4266,6 +4328,11 @@ public: LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFormatClear (interpreter))); LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFormatDelete (interpreter))); LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFormatList (interpreter))); + LoadSubCommand ("info", CommandObjectSP (new CommandObjectFormatterInfo<TypeFormatImpl>(interpreter, + "format", + [](ValueObject& valobj) -> TypeFormatImpl::SharedPointer { + return valobj.GetValueFormat(); + }))); } @@ -4289,6 +4356,11 @@ public: LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSynthClear (interpreter))); LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSynthDelete (interpreter))); LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSynthList (interpreter))); + LoadSubCommand ("info", CommandObjectSP (new CommandObjectFormatterInfo<SyntheticChildren>(interpreter, + "synthetic", + [](ValueObject& valobj) -> SyntheticChildren::SharedPointer { + return valobj.GetSyntheticChildren(); + }))); } @@ -4354,6 +4426,11 @@ public: LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSummaryClear (interpreter))); LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSummaryDelete (interpreter))); LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSummaryList (interpreter))); + LoadSubCommand ("info", CommandObjectSP (new CommandObjectFormatterInfo<TypeSummaryImpl>(interpreter, + "summary", + [](ValueObject& valobj) -> TypeSummaryImpl::SharedPointer { + return valobj.GetSummaryFormat(); + }))); } |