diff options
author | Enrico Granata <egranata@apple.com> | 2015-09-04 00:33:51 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2015-09-04 00:33:51 +0000 |
commit | 419d79189f56a4d819f7e958a7ea695efaef9875 (patch) | |
tree | dadbea9cf2f24f50366ca359b9b935f4b0014008 /lldb/source/DataFormatters/FormattersHelpers.cpp | |
parent | f9cdea9d7466617ee772e9d9b19707e391763870 (diff) | |
download | bcm5719-llvm-419d79189f56a4d819f7e958a7ea695efaef9875.tar.gz bcm5719-llvm-419d79189f56a4d819f7e958a7ea695efaef9875.zip |
Nuke CXXFormatterFunctions.cpp - split the contents of it across different files, so that things are better organized along the C++/ObjC line
This is preparatory work for moving these formatters into language categories
llvm-svn: 246827
Diffstat (limited to 'lldb/source/DataFormatters/FormattersHelpers.cpp')
-rw-r--r-- | lldb/source/DataFormatters/FormattersHelpers.cpp | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/lldb/source/DataFormatters/FormattersHelpers.cpp b/lldb/source/DataFormatters/FormattersHelpers.cpp index cbded9da963..ba5f6c04f78 100644 --- a/lldb/source/DataFormatters/FormattersHelpers.cpp +++ b/lldb/source/DataFormatters/FormattersHelpers.cpp @@ -18,6 +18,8 @@ #include "lldb/Core/ConstString.h" #include "lldb/Core/RegularExpression.h" +#include "lldb/Target/StackFrame.h" +#include "lldb/Target/Thread.h" using namespace lldb; using namespace lldb_private; @@ -118,3 +120,178 @@ lldb_private::formatters::AddFilter (TypeCategoryImpl::SharedPointer category_s category_sp->GetTypeFiltersContainer()->Add(type_name,filter_sp); } #endif + +StackFrame* +lldb_private::formatters::GetViableFrame (ExecutionContext exe_ctx) +{ + StackFrame* frame = exe_ctx.GetFramePtr(); + if (frame) + return frame; + + Process* process = exe_ctx.GetProcessPtr(); + if (!process) + return nullptr; + + ThreadSP thread_sp(process->GetThreadList().GetSelectedThread()); + if (thread_sp) + return thread_sp->GetSelectedFrame().get(); + return nullptr; +} + +bool +lldb_private::formatters::ExtractValueFromObjCExpression (ValueObject &valobj, + const char* target_type, + const char* selector, + uint64_t &value) +{ + if (!target_type || !*target_type) + return false; + if (!selector || !*selector) + return false; + StreamString expr; + expr.Printf("(%s)[(id)0x%" PRIx64 " %s]",target_type,valobj.GetPointerValue(),selector); + ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); + lldb::ValueObjectSP result_sp; + Target* target = exe_ctx.GetTargetPtr(); + StackFrame* stack_frame = GetViableFrame(exe_ctx); + if (!target || !stack_frame) + return false; + + EvaluateExpressionOptions options; + options.SetCoerceToId(false); + options.SetUnwindOnError(true); + options.SetKeepInMemory(true); + + target->EvaluateExpression(expr.GetData(), + stack_frame, + result_sp, + options); + if (!result_sp) + return false; + value = result_sp->GetValueAsUnsigned(0); + return true; +} + +bool +lldb_private::formatters::ExtractSummaryFromObjCExpression (ValueObject &valobj, + const char* target_type, + const char* selector, + Stream &stream) +{ + if (!target_type || !*target_type) + return false; + if (!selector || !*selector) + return false; + StreamString expr; + expr.Printf("(%s)[(id)0x%" PRIx64 " %s]",target_type,valobj.GetPointerValue(),selector); + ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); + lldb::ValueObjectSP result_sp; + Target* target = exe_ctx.GetTargetPtr(); + StackFrame* stack_frame = GetViableFrame(exe_ctx); + if (!target || !stack_frame) + return false; + + EvaluateExpressionOptions options; + options.SetCoerceToId(false); + options.SetUnwindOnError(true); + options.SetKeepInMemory(true); + options.SetUseDynamic(lldb::eDynamicCanRunTarget); + + target->EvaluateExpression(expr.GetData(), + stack_frame, + result_sp, + options); + if (!result_sp) + return false; + stream.Printf("%s",result_sp->GetSummaryAsCString()); + return true; +} + +lldb::ValueObjectSP +lldb_private::formatters::CallSelectorOnObject (ValueObject &valobj, + const char* return_type, + const char* selector, + uint64_t index) +{ + lldb::ValueObjectSP valobj_sp; + if (!return_type || !*return_type) + return valobj_sp; + if (!selector || !*selector) + return valobj_sp; + StreamString expr_path_stream; + valobj.GetExpressionPath(expr_path_stream, false); + StreamString expr; + expr.Printf("(%s)[%s %s:%" PRId64 "]",return_type,expr_path_stream.GetData(),selector,index); + ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); + lldb::ValueObjectSP result_sp; + Target* target = exe_ctx.GetTargetPtr(); + StackFrame* stack_frame = GetViableFrame(exe_ctx); + if (!target || !stack_frame) + return valobj_sp; + + EvaluateExpressionOptions options; + options.SetCoerceToId(false); + options.SetUnwindOnError(true); + options.SetKeepInMemory(true); + options.SetUseDynamic(lldb::eDynamicCanRunTarget); + + target->EvaluateExpression(expr.GetData(), + stack_frame, + valobj_sp, + options); + return valobj_sp; +} + +lldb::ValueObjectSP +lldb_private::formatters::CallSelectorOnObject (ValueObject &valobj, + const char* return_type, + const char* selector, + const char* key) +{ + lldb::ValueObjectSP valobj_sp; + if (!return_type || !*return_type) + return valobj_sp; + if (!selector || !*selector) + return valobj_sp; + if (!key || !*key) + return valobj_sp; + StreamString expr_path_stream; + valobj.GetExpressionPath(expr_path_stream, false); + StreamString expr; + expr.Printf("(%s)[%s %s:%s]",return_type,expr_path_stream.GetData(),selector,key); + ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); + lldb::ValueObjectSP result_sp; + Target* target = exe_ctx.GetTargetPtr(); + StackFrame* stack_frame = GetViableFrame(exe_ctx); + if (!target || !stack_frame) + return valobj_sp; + + EvaluateExpressionOptions options; + options.SetCoerceToId(false); + options.SetUnwindOnError(true); + options.SetKeepInMemory(true); + options.SetUseDynamic(lldb::eDynamicCanRunTarget); + + target->EvaluateExpression(expr.GetData(), + stack_frame, + valobj_sp, + options); + return valobj_sp; +} + +size_t +lldb_private::formatters::ExtractIndexFromString (const char* item_name) +{ + if (!item_name || !*item_name) + return UINT32_MAX; + if (*item_name != '[') + return UINT32_MAX; + item_name++; + char* endptr = NULL; + unsigned long int idx = ::strtoul(item_name, &endptr, 0); + if (idx == 0 && endptr == item_name) + return UINT32_MAX; + if (idx == ULONG_MAX) + return UINT32_MAX; + return idx; +} |