diff options
13 files changed, 427 insertions, 345 deletions
diff --git a/lldb/include/lldb/Core/FormatClasses.h b/lldb/include/lldb/Core/FormatClasses.h index bacd8b5e8d3..d29ba7ff2af 100644 --- a/lldb/include/lldb/Core/FormatClasses.h +++ b/lldb/include/lldb/Core/FormatClasses.h @@ -31,10 +31,8 @@ #include "lldb/lldb-public.h" #include "lldb/lldb-enumerations.h" -#include "lldb/API/SBValue.h" #include "lldb/Core/ValueObject.h" #include "lldb/Interpreter/ScriptInterpreterPython.h" -#include "lldb/Symbol/SymbolContext.h" namespace lldb_private { @@ -48,13 +46,7 @@ struct ValueFormat ValueFormat (lldb::Format f = lldb::eFormatInvalid, bool casc = false, bool skipptr = false, - bool skipref = false) : - m_cascades(casc), - m_skip_pointers(skipptr), - m_skip_references(skipref), - m_format (f) - { - } + bool skipref = false); typedef lldb::SharedPtr<ValueFormat>::Type SharedPointer; typedef bool(*ValueCallback)(void*, ConstString, const lldb::ValueFormatSP&); @@ -335,25 +327,7 @@ public: } virtual lldb::ValueObjectSP - GetChildAtIndex (uint32_t idx, bool can_create) - { - if (m_wrapper == NULL || m_interpreter == NULL) - return lldb::ValueObjectSP(); - - PyObject* py_return = (PyObject*)m_interpreter->GetChildAtIndex(m_wrapper, idx); - if (py_return == NULL || py_return == Py_None) - { - Py_XDECREF(py_return); - return lldb::ValueObjectSP(); - } - - lldb::SBValue *sb_ptr = m_interpreter->CastPyObjectToSBValue(py_return); - - if (py_return == NULL || sb_ptr == NULL) - return lldb::ValueObjectSP(); - - return sb_ptr->m_opaque_sp; - } + GetChildAtIndex (uint32_t idx, bool can_create); virtual void Update() @@ -383,122 +357,121 @@ public: } }; - -struct SyntheticArrayRange -{ -private: - int m_low; - int m_high; - SyntheticArrayRange* m_next; +class SyntheticArrayView : public SyntheticChildren +{ public: - SyntheticArrayRange () : + struct SyntheticArrayRange + { + private: + int m_low; + int m_high; + SyntheticArrayRange* m_next; + + public: + + SyntheticArrayRange () : m_low(-1), m_high(-2), m_next(NULL) - {} - - SyntheticArrayRange (int L) : + {} + + SyntheticArrayRange (int L) : m_low(L), m_high(L), m_next(NULL) - {} - - SyntheticArrayRange (int L, int H) : + {} + + SyntheticArrayRange (int L, int H) : m_low(L), m_high(H), m_next(NULL) - {} - - SyntheticArrayRange (int L, int H, SyntheticArrayRange* N) : + {} + + SyntheticArrayRange (int L, int H, SyntheticArrayRange* N) : m_low(L), m_high(H), m_next(N) - {} - - inline int - GetLow () - { - return m_low; - } - - inline int - GetHigh () - { - return m_high; - } - - inline void - SetLow (int L) - { - m_low = L; - } - - inline void - SetHigh (int H) - { - m_high = H; - } - - inline int - GetSelfCount() - { - return GetHigh() - GetLow() + 1; - } - - int - GetCount() - { - int count = GetSelfCount(); - if (m_next) - count += m_next->GetCount(); - return count; - } - - inline SyntheticArrayRange* - GetNext() - { - return m_next; - } - - void - SetNext(SyntheticArrayRange* N) - { - if (m_next) - delete m_next; - m_next = N; - } - - void - SetNext(int L, int H) - { - if (m_next) - delete m_next; - m_next = new SyntheticArrayRange(L, H); - } - - void - SetNext(int L) - { - if (m_next) + {} + + inline int + GetLow () + { + return m_low; + } + + inline int + GetHigh () + { + return m_high; + } + + inline void + SetLow (int L) + { + m_low = L; + } + + inline void + SetHigh (int H) + { + m_high = H; + } + + inline int + GetSelfCount() + { + return GetHigh() - GetLow() + 1; + } + + int + GetCount() + { + int count = GetSelfCount(); + if (m_next) + count += m_next->GetCount(); + return count; + } + + inline SyntheticArrayRange* + GetNext() + { + return m_next; + } + + void + SetNext(SyntheticArrayRange* N) + { + if (m_next) + delete m_next; + m_next = N; + } + + void + SetNext(int L, int H) + { + if (m_next) + delete m_next; + m_next = new SyntheticArrayRange(L, H); + } + + void + SetNext(int L) + { + if (m_next) + delete m_next; + m_next = new SyntheticArrayRange(L); + } + + ~SyntheticArrayRange() + { delete m_next; - m_next = new SyntheticArrayRange(L); - } - - ~SyntheticArrayRange() - { - delete m_next; - m_next = NULL; - } - -}; + m_next = NULL; + } + + }; -class SyntheticArrayView : public SyntheticChildren -{ - SyntheticArrayRange m_head; - SyntheticArrayRange *m_tail; -public: SyntheticArrayView(bool casc = false, bool skipptr = false, bool skipref = false) : @@ -524,29 +497,7 @@ public: } const int - GetRealIndexForIndex(int i) - { - if (i >= GetCount()) - return -1; - - SyntheticArrayRange* ptr = &m_head; - - int residual = i; - - while(ptr && ptr != m_tail) - { - if (residual >= ptr->GetSelfCount()) - { - residual -= ptr->GetSelfCount(); - ptr = ptr->GetNext(); - } - - return ptr->GetLow() + residual; - } - - return -1; - - } + GetRealIndexForIndex(int i); bool IsScripted() @@ -592,20 +543,7 @@ public: Update() {} virtual uint32_t - GetIndexOfChildWithName (const ConstString &name_cs) - { - const char* name_cstr = name_cs.GetCString(); - if (*name_cstr != '[') - return UINT32_MAX; - std::string name(name_cstr+1); - if (name[name.size()-1] != ']') - return UINT32_MAX; - name = name.erase(name.size()-1,1); - int index = Args::StringToSInt32 (name.c_str(), -1); - if (index < 0) - return UINT32_MAX; - return index; - } + GetIndexOfChildWithName (const ConstString &name_cs); typedef lldb::SharedPtr<SyntheticChildrenFrontEnd>::Type SharedPointer; @@ -616,6 +554,9 @@ public: { return SyntheticChildrenFrontEnd::SharedPointer(new FrontEnd(this, backend)); } +private: + SyntheticArrayRange m_head; + SyntheticArrayRange *m_tail; }; @@ -635,15 +576,7 @@ struct SummaryFormat bool skipref = false, bool nochildren = true, bool novalue = true, - bool oneliner = false) : - m_cascades(casc), - m_skip_pointers(skipptr), - m_skip_references(skipref), - m_dont_show_children(nochildren), - m_dont_show_value(novalue), - m_show_members_oneliner(oneliner) - { - } + bool oneliner = false); bool Cascades() const @@ -707,11 +640,7 @@ struct StringSummaryFormat : public SummaryFormat bool nochildren = true, bool novalue = true, bool oneliner = false, - std::string f = "") : - SummaryFormat(casc,skipptr,skipref,nochildren,novalue,oneliner), - m_format(f) - { - } + std::string f = ""); std::string GetFormat() const @@ -745,12 +674,7 @@ struct ScriptSummaryFormat : public SummaryFormat bool novalue = true, bool oneliner = false, std::string fname = "", - std::string pscri = "") : - SummaryFormat(casc,skipptr,skipref,nochildren,novalue,oneliner), - m_function_name(fname), - m_python_script(pscri) - { - } + std::string pscri = ""); std::string GetFunctionName() const diff --git a/lldb/include/lldb/Core/FormatManager.h b/lldb/include/lldb/Core/FormatManager.h index 0bac0e27a7d..2f58aecaf54 100644 --- a/lldb/include/lldb/Core/FormatManager.h +++ b/lldb/include/lldb/Core/FormatManager.h @@ -115,39 +115,14 @@ public: Get (ValueObject& valobj, lldb::SummaryFormatSP& entry, lldb::DynamicValueType use_dynamic, - uint32_t* reason = NULL) - { - if (!IsEnabled()) - return false; - if (GetSummaryNavigator()->Get(valobj, entry, use_dynamic, reason)) - return true; - bool regex = GetRegexSummaryNavigator()->Get(valobj, entry, use_dynamic, reason); - if (regex && reason) - *reason |= lldb::eFormatterChoiceCriterionRegularExpressionSummary; - return regex; - } + uint32_t* reason = NULL); bool Get (ValueObject& valobj, lldb::SyntheticChildrenSP& entry, lldb::DynamicValueType use_dynamic, uint32_t* reason = NULL); - - // just a shortcut for GetSummaryNavigator()->Clear; GetRegexSummaryNavigator()->Clear() - void - ClearSummaries () - { - Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); - } - - // just a shortcut for (GetSummaryNavigator()->Delete(name) || GetRegexSummaryNavigator()->Delete(name)) - bool - DeleteSummaries (ConstString name) - { - return Delete(name, (eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary)); - } - - + void Clear (FormatCategoryItems items = ALL_ITEM_TYPES); @@ -275,19 +250,6 @@ public: m_active_categories.push_front(category); } - class delete_matching_categories - { - lldb::FormatCategorySP ptr; - public: - delete_matching_categories(lldb::FormatCategorySP p) : ptr(p) - {} - - bool operator()(const lldb::FormatCategorySP& other) - { - return ptr.get() == other.get(); - } - }; - void Disable (KeyType category_name) { @@ -329,22 +291,7 @@ public: FormatCategory::FormatCategoryItems items = FormatCategory::ALL_ITEM_TYPES, bool only_enabled = true, const char** matching_category = NULL, - FormatCategory::FormatCategoryItems* matching_type = NULL) - { - Mutex::Locker(m_map_mutex); - - MapIterator pos, end = m_map.end(); - for (pos = m_map.begin(); pos != end; pos++) - { - if (pos->second->AnyMatches(type_name, - items, - only_enabled, - matching_category, - matching_type)) - return true; - } - return false; - } + FormatCategory::FormatCategoryItems* matching_type = NULL); uint32_t GetCount () @@ -355,49 +302,28 @@ public: bool Get (ValueObject& valobj, lldb::SummaryFormatSP& entry, - lldb::DynamicValueType use_dynamic) - { - Mutex::Locker(m_map_mutex); - - uint32_t reason_why; - ActiveCategoriesIterator begin, end = m_active_categories.end(); - - for (begin = m_active_categories.begin(); begin != end; begin++) - { - lldb::FormatCategorySP category = *begin; - lldb::SummaryFormatSP current_format; - if (!category->Get(valobj, current_format, use_dynamic, &reason_why)) - continue; - entry = current_format; - return true; - } - return false; - } + lldb::DynamicValueType use_dynamic); bool Get (ValueObject& valobj, lldb::SyntheticChildrenSP& entry, - lldb::DynamicValueType use_dynamic) + lldb::DynamicValueType use_dynamic); + +private: + + class delete_matching_categories { - Mutex::Locker(m_map_mutex); - - uint32_t reason_why; - - ActiveCategoriesIterator begin, end = m_active_categories.end(); + lldb::FormatCategorySP ptr; + public: + delete_matching_categories(lldb::FormatCategorySP p) : ptr(p) + {} - for (begin = m_active_categories.begin(); begin != end; begin++) + bool operator()(const lldb::FormatCategorySP& other) { - lldb::FormatCategorySP category = *begin; - lldb::SyntheticChildrenSP current_format; - if (!category->Get(valobj, current_format, use_dynamic, &reason_why)) - continue; - entry = current_format; - return true; + return ptr.get() == other.get(); } - return false; - } + }; -private: Mutex m_map_mutex; IFormatChangeListener* listener; @@ -425,14 +351,10 @@ private: class FormatManager : public IFormatChangeListener { -private: - typedef FormatNavigator<ConstString, ValueFormat> ValueNavigator; - typedef ValueNavigator::MapType ValueMap; typedef FormatMap<ConstString, SummaryFormat> NamedSummariesMap; typedef CategoryMap::MapType::iterator CategoryMapIterator; - public: typedef CategoryMap::CallbackType CategoryCallback; @@ -498,20 +420,7 @@ public: lldb::FormatCategorySP Category (const ConstString& category_name, - bool can_create = true) - { - if (!category_name) - return Category(m_default_category_name); - lldb::FormatCategorySP category; - if (m_categories_map.Get(category_name, category)) - return category; - - if (!can_create) - return lldb::FormatCategorySP(); - - m_categories_map.Add(category_name,lldb::FormatCategorySP(new FormatCategory(this, category_name.AsCString()))); - return Category(category_name); - } + bool can_create = true); bool Get (ValueObject& valobj, @@ -520,6 +429,7 @@ public: { return m_categories_map.Get(valobj, entry, use_dynamic); } + bool Get (ValueObject& valobj, lldb::SyntheticChildrenSP& entry, diff --git a/lldb/include/lldb/lldb-private-enumerations.h b/lldb/include/lldb/lldb-private-enumerations.h index f27c93d0389..fc346450b04 100644 --- a/lldb/include/lldb/lldb-private-enumerations.h +++ b/lldb/include/lldb/lldb-private-enumerations.h @@ -207,11 +207,11 @@ typedef enum InstructionType typedef enum FormatCategoryItem { eFormatCategoryItemSummary = 0x0001, - eFormatCategoryItemRegexSummary = 0x1001, - eFormatCategoryItemFilter = 0x0002, - eFormatCategoryItemRegexFilter = 0x1002, - eFormatCategoryItemSynth = 0x0004, - eFormatCategoryItemRegexSynth = 0x1004, + eFormatCategoryItemRegexSummary = 0x0002, + eFormatCategoryItemFilter = 0x0004, + eFormatCategoryItemRegexFilter = 0x0008, + eFormatCategoryItemSynth = 0x0010, + eFormatCategoryItemRegexSynth = 0x0020, } FormatCategoryItem; } // namespace lldb diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig index b50dd056b5e..964f96a57ef 100644 --- a/lldb/scripts/Python/python-wrapper.swig +++ b/lldb/scripts/Python/python-wrapper.swig @@ -679,6 +679,4 @@ LLDBSwigPythonCallCommand return retval; } -#undef RETURN_RETVAL - %} diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index e82932c41af..bf1947a6db0 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -627,7 +627,7 @@ CommandObjectTypeSummaryAdd::CommandOptions::SetOptionValue (uint32_t option_idx case 'n': m_name = new ConstString(option_arg); break; - case 's': + case 'o': m_python_script = std::string(option_arg); m_is_add_script = true; break; @@ -1082,7 +1082,7 @@ CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] = { LLDB_OPT_SET_ALL, false, "regex", 'x', no_argument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."}, { LLDB_OPT_SET_1 , true, "inline-children", 'c', no_argument, NULL, 0, eArgTypeNone, "If true, inline all child values into summary string."}, { LLDB_OPT_SET_2 , true, "summary-string", 'f', required_argument, NULL, 0, eArgTypeSummaryString, "Summary string used to display text and object contents."}, - { LLDB_OPT_SET_3, false, "python-script", 's', required_argument, NULL, 0, eArgTypeName, "Give a one-liner Python script as part of the command."}, + { LLDB_OPT_SET_3, false, "python-script", 'o', required_argument, NULL, 0, eArgTypeName, "Give a one-liner Python script as part of the command."}, { LLDB_OPT_SET_3, false, "python-function", 'F', required_argument, NULL, 0, eArgTypeName, "Give the name of a Python function to use for this type."}, { LLDB_OPT_SET_3, false, "input-python", 'P', no_argument, NULL, 0, eArgTypeNone, "Input Python code to use for this type manually."}, { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "expand", 'e', no_argument, NULL, 0, eArgTypeNone, "Expand aggregate data types to show children on separate lines."}, @@ -1228,7 +1228,8 @@ public: lldb::FormatCategorySP category; DataVisualization::Categories::Get(ConstString(m_options.m_category.c_str()), category); - bool delete_category = category->DeleteSummaries(typeCS); + bool delete_category = category->Delete(typeCS, + eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); bool delete_named = DataVisualization::NamedSummaryFormats::Delete(typeCS); if (delete_category || delete_named) @@ -1360,7 +1361,7 @@ public: } else DataVisualization::Categories::Get(ConstString(NULL), category); - category->ClearSummaries(); + category->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); } DataVisualization::NamedSummaryFormats::Clear(); @@ -3436,6 +3437,32 @@ public: m_arguments.push_back (type_arg); + SetHelpLong( + "Some examples of using this command.\n" + "We use as reference the following snippet of code:\n" + "\n" + "class Foo {;\n" + " int a;\n" + " int b;\n" + " int c;\n" + " int d;\n" + " int e;\n" + " int f;\n" + " int g;\n" + " int h;\n" + " int i;\n" + "} \n" + "Typing:\n" + "type filter add --child a -- child g Foo\n" + "frame variable a_foo\n" + "will produce an output where only a and b are displayed\n" + "Other children of a_foo (b,c,d,e,f,h and i) are available by asking for them, as in:\n" + "frame variable a_foo.b a_foo.c ... a_foo.i\n" + "\n" + "Use option --raw to frame variable prevails on the filter\n" + "frame variable a_foo --raw\n" + "shows all the children of a_foo (a thru i) as if no filter was defined\n" + ); } ~CommandObjectTypeFilterAdd () diff --git a/lldb/source/Core/DataVisualization.cpp b/lldb/source/Core/DataVisualization.cpp index 10a9c2a4bde..6974132617a 100644 --- a/lldb/source/Core/DataVisualization.cpp +++ b/lldb/source/Core/DataVisualization.cpp @@ -132,7 +132,7 @@ DataVisualization::Categories::Clear () void DataVisualization::Categories::Clear (ConstString &category) { - GetFormatManager().Category(category)->ClearSummaries(); + GetFormatManager().Category(category)->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); } void diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 07cbe7b92a7..ecca589cab6 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -694,20 +694,13 @@ TestPromptFormats (StackFrame *frame) } } -#define IFERROR_PRINT_IT if (error.Fail()) \ -{ \ - if (log) \ - log->Printf("ERROR: %s\n", error.AsCString("unknown")); \ - break; \ -} - static bool -ScanFormatDescriptor(const char* var_name_begin, - const char* var_name_end, - const char** var_name_final, - const char** percent_position, - lldb::Format* custom_format, - ValueObject::ValueObjectRepresentationStyle* val_obj_display) +ScanFormatDescriptor (const char* var_name_begin, + const char* var_name_end, + const char** var_name_final, + const char** percent_position, + lldb::Format* custom_format, + ValueObject::ValueObjectRepresentationStyle* val_obj_display) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); *percent_position = ::strchr(var_name_begin,'%'); @@ -766,15 +759,15 @@ ScanFormatDescriptor(const char* var_name_begin, } static bool -ScanBracketedRange(const char* var_name_begin, - const char* var_name_end, - const char* var_name_final, - const char** open_bracket_position, - const char** separator_position, - const char** close_bracket_position, - const char** var_name_final_if_array_range, - int64_t* index_lower, - int64_t* index_higher) +ScanBracketedRange (const char* var_name_begin, + const char* var_name_end, + const char* var_name_final, + const char** open_bracket_position, + const char** separator_position, + const char** close_bracket_position, + const char** var_name_final_if_array_range, + int64_t* index_lower, + int64_t* index_higher) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); *open_bracket_position = ::strchr(var_name_begin,'['); @@ -829,12 +822,12 @@ ScanBracketedRange(const char* var_name_begin, static ValueObjectSP -ExpandExpressionPath(ValueObject* valobj, - StackFrame* frame, - bool* do_deref_pointer, - const char* var_name_begin, - const char* var_name_final, - Error& error) +ExpandExpressionPath (ValueObject* valobj, + StackFrame* frame, + bool* do_deref_pointer, + const char* var_name_begin, + const char* var_name_final, + Error& error) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); StreamString sstring; @@ -870,10 +863,10 @@ ExpandExpressionPath(ValueObject* valobj, } static ValueObjectSP -ExpandIndexedExpression(ValueObject* valobj, - uint32_t index, - StackFrame* frame, - bool deref_pointer) +ExpandIndexedExpression (ValueObject* valobj, + uint32_t index, + StackFrame* frame, + bool deref_pointer) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); const char* ptr_deref_format = "[%d]"; @@ -1153,7 +1146,12 @@ Debugger::FormatPrompt // to get to the target ValueObject Error error; target = target->Dereference(error).get(); - IFERROR_PRINT_IT + if (error.Fail()) + { + if (log) + log->Printf("ERROR: %s\n", error.AsCString("unknown")); \ + break; + } do_deref_pointer = false; } diff --git a/lldb/source/Core/FormatClasses.cpp b/lldb/source/Core/FormatClasses.cpp index cd09d0c4fc0..a23225d3825 100644 --- a/lldb/source/Core/FormatClasses.cpp +++ b/lldb/source/Core/FormatClasses.cpp @@ -30,6 +30,17 @@ using namespace lldb; using namespace lldb_private; +ValueFormat::ValueFormat (lldb::Format f, + bool casc, + bool skipptr, + bool skipref) : + m_cascades(casc), + m_skip_pointers(skipptr), + m_skip_references(skipref), + m_format (f) +{ +} + std::string ValueFormat::FormatObject(lldb::ValueObjectSP object) { @@ -54,6 +65,39 @@ ValueFormat::FormatObject(lldb::ValueObjectSP object) } } +SummaryFormat::SummaryFormat(bool casc, + bool skipptr, + bool skipref, + bool nochildren, + bool novalue, + bool oneliner) : + m_cascades(casc), + m_skip_pointers(skipptr), + m_skip_references(skipref), + m_dont_show_children(nochildren), + m_dont_show_value(novalue), + m_show_members_oneliner(oneliner) +{ +} + +StringSummaryFormat::StringSummaryFormat(bool casc, + bool skipptr, + bool skipref, + bool nochildren, + bool novalue, + bool oneliner, + std::string f) : + SummaryFormat(casc, + skipptr, + skipref, + nochildren, + novalue, + oneliner), + m_format(f) +{ +} + + std::string StringSummaryFormat::FormatObject(lldb::ValueObjectSP object) { @@ -119,6 +163,26 @@ StringSummaryFormat::GetDescription() return sstr.GetString(); } +ScriptSummaryFormat::ScriptSummaryFormat(bool casc, + bool skipptr, + bool skipref, + bool nochildren, + bool novalue, + bool oneliner, + std::string fname, + std::string pscri) : + SummaryFormat(casc, + skipptr, + skipref, + nochildren, + novalue, + oneliner), + m_function_name(fname), + m_python_script(pscri) +{ +} + + std::string ScriptSummaryFormat::FormatObject(lldb::ValueObjectSP object) { @@ -245,6 +309,27 @@ SyntheticScriptProvider::FrontEnd::FrontEnd(std::string pclass, m_wrapper = (PyObject*)m_interpreter->CreateSyntheticScriptedProvider(m_python_class, m_backend); } +lldb::ValueObjectSP +SyntheticScriptProvider::FrontEnd::GetChildAtIndex (uint32_t idx, bool can_create) +{ + if (m_wrapper == NULL || m_interpreter == NULL) + return lldb::ValueObjectSP(); + + PyObject* py_return = (PyObject*)m_interpreter->GetChildAtIndex(m_wrapper, idx); + if (py_return == NULL || py_return == Py_None) + { + Py_XDECREF(py_return); + return lldb::ValueObjectSP(); + } + + lldb::SBValue *sb_ptr = m_interpreter->CastPyObjectToSBValue(py_return); + + if (py_return == NULL || sb_ptr == NULL) + return lldb::ValueObjectSP(); + + return sb_ptr->m_opaque_sp; +} + std::string SyntheticScriptProvider::GetDescription() { @@ -257,3 +342,43 @@ SyntheticScriptProvider::GetDescription() return sstr.GetString(); } + +const int +SyntheticArrayView::GetRealIndexForIndex(int i) +{ + if (i >= GetCount()) + return -1; + + SyntheticArrayRange* ptr = &m_head; + + int residual = i; + + while(ptr && ptr != m_tail) + { + if (residual >= ptr->GetSelfCount()) + { + residual -= ptr->GetSelfCount(); + ptr = ptr->GetNext(); + } + + return ptr->GetLow() + residual; + } + + return -1; +} + +uint32_t +SyntheticArrayView::FrontEnd::GetIndexOfChildWithName (const ConstString &name_cs) +{ + const char* name_cstr = name_cs.GetCString(); + if (*name_cstr != '[') + return UINT32_MAX; + std::string name(name_cstr+1); + if (name[name.size()-1] != ']') + return UINT32_MAX; + name = name.erase(name.size()-1,1); + int index = Args::StringToSInt32 (name.c_str(), -1); + if (index < 0) + return UINT32_MAX; + return index; +}
\ No newline at end of file diff --git a/lldb/source/Core/FormatManager.cpp b/lldb/source/Core/FormatManager.cpp index 9e7fe8602b8..89f92166475 100644 --- a/lldb/source/Core/FormatManager.cpp +++ b/lldb/source/Core/FormatManager.cpp @@ -169,6 +169,22 @@ FormatCategory::FormatCategory(IFormatChangeListener* clist, {} bool +FormatCategory::Get (ValueObject& valobj, + lldb::SummaryFormatSP& entry, + lldb::DynamicValueType use_dynamic, + uint32_t* reason) +{ + if (!IsEnabled()) + return false; + if (GetSummaryNavigator()->Get(valobj, entry, use_dynamic, reason)) + return true; + bool regex = GetRegexSummaryNavigator()->Get(valobj, entry, use_dynamic, reason); + if (regex && reason) + *reason |= lldb::eFormatterChoiceCriterionRegularExpressionSummary; + return regex; +} + +bool FormatCategory::Get(ValueObject& valobj, lldb::SyntheticChildrenSP& entry, lldb::DynamicValueType use_dynamic, @@ -364,6 +380,73 @@ FormatCategory::AnyMatches(ConstString type_name, return false; } +bool +CategoryMap::AnyMatches (ConstString type_name, + FormatCategory::FormatCategoryItems items, + bool only_enabled, + const char** matching_category, + FormatCategory::FormatCategoryItems* matching_type) +{ + Mutex::Locker(m_map_mutex); + + MapIterator pos, end = m_map.end(); + for (pos = m_map.begin(); pos != end; pos++) + { + if (pos->second->AnyMatches(type_name, + items, + only_enabled, + matching_category, + matching_type)) + return true; + } + return false; +} + +bool +CategoryMap::Get (ValueObject& valobj, + lldb::SummaryFormatSP& entry, + lldb::DynamicValueType use_dynamic) +{ + Mutex::Locker(m_map_mutex); + + uint32_t reason_why; + ActiveCategoriesIterator begin, end = m_active_categories.end(); + + for (begin = m_active_categories.begin(); begin != end; begin++) + { + lldb::FormatCategorySP category = *begin; + lldb::SummaryFormatSP current_format; + if (!category->Get(valobj, current_format, use_dynamic, &reason_why)) + continue; + entry = current_format; + return true; + } + return false; +} + +bool +CategoryMap::Get (ValueObject& valobj, + lldb::SyntheticChildrenSP& entry, + lldb::DynamicValueType use_dynamic) +{ + Mutex::Locker(m_map_mutex); + + uint32_t reason_why; + + ActiveCategoriesIterator begin, end = m_active_categories.end(); + + for (begin = m_active_categories.begin(); begin != end; begin++) + { + lldb::FormatCategorySP category = *begin; + lldb::SyntheticChildrenSP current_format; + if (!category->Get(valobj, current_format, use_dynamic, &reason_why)) + continue; + entry = current_format; + return true; + } + return false; +} + void CategoryMap::LoopThrough(CallbackType callback, void* param) { @@ -398,6 +481,23 @@ CategoryMap::LoopThrough(CallbackType callback, void* param) } } +lldb::FormatCategorySP +FormatManager::Category (const ConstString& category_name, + bool can_create) +{ + if (!category_name) + return Category(m_default_category_name); + lldb::FormatCategorySP category; + if (m_categories_map.Get(category_name, category)) + return category; + + if (!can_create) + return lldb::FormatCategorySP(); + + m_categories_map.Add(category_name,lldb::FormatCategorySP(new FormatCategory(this, category_name.AsCString()))); + return Category(category_name); +} + lldb::Format FormatManager::GetSingleItemFormat(lldb::Format vector_format) { diff --git a/lldb/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py b/lldb/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py index b11849884d3..5bac87a6403 100644 --- a/lldb/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py +++ b/lldb/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py @@ -102,7 +102,7 @@ class DataFormatterTestCase(TestBase): # Add summaries to two different categories and check that we can switch self.runCmd("type summary add -f \"Width = ${var.w}, Height = ${var.h}\" Rectangle -w Category1") - self.runCmd("type summary add -s \"return 'Area = ' + str( int(valobj.GetChildMemberWithName('w').GetValue()) * int(valobj.GetChildMemberWithName('h').GetValue()) );\" Rectangle -w Category2") + self.runCmd("type summary add --python-script \"return 'Area = ' + str( int(valobj.GetChildMemberWithName('w').GetValue()) * int(valobj.GetChildMemberWithName('h').GetValue()) );\" Rectangle -w Category2") # check that enable A B is the same as enable B enable A self.runCmd("type category enable Category1 Category2") diff --git a/lldb/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py b/lldb/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py index b56b48e23b0..cb700a416c4 100644 --- a/lldb/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py +++ b/lldb/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py @@ -67,7 +67,7 @@ class DataFormatterTestCase(TestBase): substrs = ['(Point *) g_point_pointer =']) # Test Python code on resulting SBValue - self.runCmd("type summary add -s \"return 'x=' + str(valobj.GetChildMemberWithName('x').GetValue());\" Point") + self.runCmd("type summary add --python-script \"return 'x=' + str(valobj.GetChildMemberWithName('x').GetValue());\" Point") self.expect("target variable g_point", substrs = ['x=']) diff --git a/lldb/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py b/lldb/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py index 2ba39705326..16d23362d60 100644 --- a/lldb/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py +++ b/lldb/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py @@ -56,7 +56,7 @@ class DataFormatterTestCase(TestBase): # Set the script here to ease the formatting script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'Hello from Python, \' + a_val + \' time\'; return str + (\'!\' if a_val == \'1\' else \'s!\');' - self.runCmd("type summary add i_am_cool -s \"%s\"" % script) + self.runCmd("type summary add i_am_cool --python-script \"%s\"" % script) self.expect("frame variable one", substrs = ['Hello from Python', @@ -81,7 +81,7 @@ class DataFormatterTestCase(TestBase): script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'int says \' + a_val; return str;' # Check that changes in the script are immediately reflected - self.runCmd("type summary add i_am_cool -s \"%s\"" % script) + self.runCmd("type summary add i_am_cool --python-script \"%s\"" % script) self.expect("frame variable two", substrs = ['int says 1']) @@ -101,14 +101,14 @@ class DataFormatterTestCase(TestBase): 'and float says 2.71']) # Force a failure for pointers - self.runCmd("type summary add i_am_cool -p -s \"%s\"" % script) + self.runCmd("type summary add i_am_cool -p --python-script \"%s\"" % script) self.expect("frame variable twoptr", matching=False, substrs = ['and float says 2.71']) script = 'return \'Python summary\''; - self.runCmd("type summary add --name test_summary -s \"%s\"" % script) + self.runCmd("type summary add --name test_summary --python-script \"%s\"" % script) # attach the Python named summary to someone self.runCmd("frame variable one --summary test_summary") @@ -140,7 +140,7 @@ class DataFormatterTestCase(TestBase): # disable type summary for pointers, and make a Python regex summary self.runCmd("type summary add i_am_cool -p -f \"Text summary\"") - self.runCmd("type summary add -x cool -s \"%s\"" % script) + self.runCmd("type summary add -x cool --python-script \"%s\"" % script) # variables should stick to the type summary self.expect("frame variable one", diff --git a/lldb/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py b/lldb/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py index e51e0bc4fc4..57e34f4d78d 100644 --- a/lldb/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py +++ b/lldb/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py @@ -90,7 +90,7 @@ class DataFormatterTestCase(TestBase): 'z = 8']) # Same output, but using Python - self.runCmd("type summary add BagOfInts -s \"return 'y='+valobj.GetChildMemberWithName('y').GetValue()\" -e") + self.runCmd("type summary add BagOfInts --python-script \"return 'y='+valobj.GetChildMemberWithName('y').GetValue()\" -e") self.expect('frame variable int_bag', substrs = ['y=7', 'x = 6', |