diff options
| author | Dawn Perchik <dawn@burble.org> | 2015-10-23 00:23:53 +0000 |
|---|---|---|
| committer | Dawn Perchik <dawn@burble.org> | 2015-10-23 00:23:53 +0000 |
| commit | b91779eb28c4162d5df2f4ea2cf57977c042c9e7 (patch) | |
| tree | 758504081b3a2831ea22fadb663ce1fa5b76d9f3 /lldb/tools | |
| parent | fbb958c24b79be477c99c46049a507d3435dab14 (diff) | |
| download | bcm5719-llvm-b91779eb28c4162d5df2f4ea2cf57977c042c9e7.tar.gz bcm5719-llvm-b91779eb28c4162d5df2f4ea2cf57977c042c9e7.zip | |
[lldb-mi] display summary for simple types + refactor (use lldb formatting for all cases)
Previously, lldb did not use type summaries for simple types with no children
(like function pointers). This patch enables MI to use lldb type summaries for
evaluation of all types of objects, so MI own formatters are no longer needed.
Patch from evgeny.leviant@gmail.com
Reviewed by: abidh
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D13799
llvm-svn: 251082
Diffstat (limited to 'lldb/tools')
| -rw-r--r-- | lldb/tools/lldb-mi/MICmnLLDBDebugger.cpp | 92 | ||||
| -rw-r--r-- | lldb/tools/lldb-mi/MICmnLLDBDebugger.h | 3 | ||||
| -rw-r--r-- | lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp | 212 | ||||
| -rw-r--r-- | lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.h | 5 |
4 files changed, 126 insertions, 186 deletions
diff --git a/lldb/tools/lldb-mi/MICmnLLDBDebugger.cpp b/lldb/tools/lldb-mi/MICmnLLDBDebugger.cpp index 91585eb263b..8b293bd4079 100644 --- a/lldb/tools/lldb-mi/MICmnLLDBDebugger.cpp +++ b/lldb/tools/lldb-mi/MICmnLLDBDebugger.cpp @@ -12,6 +12,11 @@ #include "lldb/API/SBThread.h" #include "lldb/API/SBProcess.h" #include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBTypeSummary.h" +#include "lldb/API/SBTypeCategory.h" +#include "lldb/API/SBTypeNameSpecifier.h" +#include "lldb/API/SBStream.h" +#include "lldb/API/SBType.h" // In-house headers: #include "MICmnLLDBDebugger.h" @@ -24,6 +29,40 @@ #include "MIUtilSingletonHelper.h" //++ ------------------------------------------------------------------------------------ +// MI private summary providers +static inline bool +MI_char_summary_provider(lldb::SBValue value, lldb::SBTypeSummaryOptions options, lldb::SBStream &stream) +{ + bool is_signed; + if (!value.IsValid()) + return false; + + lldb::SBType value_type = value.GetType(); + if(!value_type.IsValid()) + return false; + + lldb::BasicType type_code = value_type.GetBasicType(); + if (type_code == lldb::eBasicTypeSignedChar) + stream.Printf("%d %s", (int)value.GetValueAsSigned(), value.GetValue()); + else if (type_code == lldb::eBasicTypeUnsignedChar) + stream.Printf("%u %s", (unsigned)value.GetValueAsUnsigned(), value.GetValue()); + else + return false; + + return true; +} + +//++ ------------------------------------------------------------------------------------ +// MI summary helper routines +static inline bool +MI_add_summary(lldb::SBTypeCategory category, const char *typeName, lldb::SBTypeSummary::FormatCallback cb, + uint32_t options, bool regex = false) +{ + lldb::SBTypeSummary summary = lldb::SBTypeSummary::CreateWithCallback(cb, options); + return summary.IsValid() ? category.AddTypeSummary(lldb::SBTypeNameSpecifier(typeName, regex), summary) : false; +} + +//++ ------------------------------------------------------------------------------------ // Details: CMICmnLLDBDebugger constructor. // Type: Method. // Args: None. @@ -98,7 +137,7 @@ CMICmnLLDBDebugger::Initialize() errMsg += GetErrorDescription().c_str(); } bOk = bOk && InitStdStreams(); - + bOk = bOk && RegisterMISummaryProviders(); m_bInitialized = bOk; if (!bOk && !HaveErrorDescription()) @@ -791,3 +830,54 @@ CMICmnLLDBDebugger::ThreadGetName() const { return m_constStrThisThreadId; } + +//++ ------------------------------------------------------------------------------------ +// Details: Loads lldb-mi formatters +// Type: Method. +// Args: None. +// Return: true - Functionality succeeded. +// false - Functionality failed. +// Throws: None. +//-- +bool +CMICmnLLDBDebugger::LoadMIFormatters(lldb::SBTypeCategory miCategory) +{ + if (!MI_add_summary(miCategory, "char", MI_char_summary_provider, + lldb::eTypeOptionHideValue | lldb::eTypeOptionSkipPointers)) + return false; + + if (!MI_add_summary(miCategory, "unsigned char", MI_char_summary_provider, + lldb::eTypeOptionHideValue | lldb::eTypeOptionSkipPointers)) + return false; + + if (!MI_add_summary(miCategory, "signed char", MI_char_summary_provider, + lldb::eTypeOptionHideValue | lldb::eTypeOptionSkipPointers)) + return false; + + return true; +} + +//++ ------------------------------------------------------------------------------------ +// Details: Registers lldb-mi custom summary providers +// Type: Method. +// Args: None. +// Return: true - Functionality succeeded. +// false - Functionality failed. +// Throws: None. +//-- +bool +CMICmnLLDBDebugger::RegisterMISummaryProviders() +{ + static const char* miCategoryName = "lldb-mi"; + lldb::SBTypeCategory miCategory = m_lldbDebugger.CreateCategory(miCategoryName); + if (!miCategory.IsValid()) + return false; + + if (!LoadMIFormatters(miCategory)) + { + m_lldbDebugger.DeleteCategory(miCategoryName); + return false; + } + miCategory.SetEnabled(true); + return true; +} diff --git a/lldb/tools/lldb-mi/MICmnLLDBDebugger.h b/lldb/tools/lldb-mi/MICmnLLDBDebugger.h index 5451f91068b..83bc3c06bf6 100644 --- a/lldb/tools/lldb-mi/MICmnLLDBDebugger.h +++ b/lldb/tools/lldb-mi/MICmnLLDBDebugger.h @@ -93,7 +93,8 @@ class CMICmnLLDBDebugger : public CMICmnBase, public CMIUtilThreadActiveObjBase, bool ClientSaveMask(const CMIUtilString &vClientName, const CMIUtilString &vBroadcasterClass, const MIuint vEventMask); bool ClientRemoveTheirMask(const CMIUtilString &vClientName, const CMIUtilString &vBroadcasterClass); bool ClientGetTheirMask(const CMIUtilString &vClientName, const CMIUtilString &vBroadcasterClass, MIuint &vwEventMask); - + bool LoadMIFormatters(lldb::SBTypeCategory miCategory); + bool RegisterMISummaryProviders(); // Overridden: private: // From CMICmnBase diff --git a/lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp b/lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp index c9ff2c2cb96..54dabd4e101 100644 --- a/lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp +++ b/lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp @@ -123,31 +123,13 @@ CMICmnLLDBUtilSBValue::GetSimpleValue(const bool vbHandleArrayType, CMIUtilStrin const MIuint nChildren = m_rValue.GetNumChildren(); if (nChildren == 0) { - if (m_bHandleCharType && IsCharType()) - { - vwrValue = GetSimpleValueChar(); - return MIstatus::success; - } - else - { - const char *pValue = m_rValue.GetValue(); - vwrValue = pValue != nullptr ? pValue : m_pUnkwn; - return MIstatus::success; - } + vwrValue = GetValueSummary(!m_bHandleCharType && IsCharType(), m_pUnkwn); + return MIstatus::success; } else if (IsPointerType()) { - if (m_bHandleCharType && IsPointeeCharType()) - { - vwrValue = GetSimpleValueCStringPointer(); - return MIstatus::success; - } - else - { - const char *pValue = m_rValue.GetValue(); - vwrValue = pValue != nullptr ? pValue : m_pUnkwn; - return MIstatus::success; - } + vwrValue = GetValueSummary(!m_bHandleCharType && IsPointeeCharType(), m_pUnkwn); + return MIstatus::success; } else if (IsArrayType()) { @@ -157,7 +139,7 @@ CMICmnLLDBUtilSBValue::GetSimpleValue(const bool vbHandleArrayType, CMIUtilStrin bPrintCharArrayAsString) && bPrintCharArrayAsString; if (bPrintCharArrayAsString && m_bHandleCharType && IsFirstChildCharType()) { - vwrValue = GetSimpleValueCStringArray(); + vwrValue = GetValueSummary(false); return MIstatus::success; } else if (vbHandleArrayType) @@ -170,7 +152,7 @@ CMICmnLLDBUtilSBValue::GetSimpleValue(const bool vbHandleArrayType, CMIUtilStrin { // Treat composite value which has registered summary // (for example with AddCXXSummary) as simple value - vwrValue = GetValueSummary(); + vwrValue = GetValueSummary(false); if (!vwrValue.empty()) return MIstatus::success; } @@ -179,143 +161,6 @@ CMICmnLLDBUtilSBValue::GetSimpleValue(const bool vbHandleArrayType, CMIUtilStrin return MIstatus::failure; } -//++ ------------------------------------------------------------------------------------ -// Details: Retrieve from the LLDB SB Value object the char value of the variable. -// Type: Method. -// Args: None. -// Return: CMIUtilString - The char value of the variable. -// Throws: None. -//-- -CMIUtilString -CMICmnLLDBUtilSBValue::GetSimpleValueChar() const -{ - const CMIUtilString& summary = GetValueSummary(); - if (!summary.empty()) - return summary; - - const uint64_t value = m_rValue.GetValueAsUnsigned(); - if (value == 0) - { - const uint64_t nFailValue = 1; - if (nFailValue == m_rValue.GetValueAsUnsigned(nFailValue)) - return m_pUnkwn; - } - - const lldb::BasicType eType = m_rValue.GetType().GetBasicType(); - switch (eType) - { - default: - assert(0 && "value must be a char type"); - case lldb::eBasicTypeChar: - case lldb::eBasicTypeSignedChar: - case lldb::eBasicTypeUnsignedChar: - { - const CMIUtilString prefix(CMIUtilString::ConvertToPrintableASCII((char)value)); - return CMIUtilString::Format("%" PRIu8 " '%s'", (uint8_t)value, prefix.c_str()); - } - case lldb::eBasicTypeChar16: - { - const CMIUtilString prefix(CMIUtilString::ConvertToPrintableASCII((char16_t)value)); - return CMIUtilString::Format("U+%04" PRIx16 " u'%s'", (uint16_t)value, prefix.c_str()); - } - case lldb::eBasicTypeChar32: - { - const CMIUtilString prefix(CMIUtilString::ConvertToPrintableASCII((char32_t)value)); - return CMIUtilString::Format("U+%08" PRIx32 " U'%s'", (uint32_t)value, prefix.c_str()); - } - } -} - -//++ ------------------------------------------------------------------------------------ -// Details: Retrieve from the LLDB SB Value object of type char* the c-string value. -// Type: Method. -// Args: None. -// Return: CMIUtilString - The c-string value of the variable. -// Throws: None. -//-- -CMIUtilString -CMICmnLLDBUtilSBValue::GetSimpleValueCStringPointer() const -{ - const CMIUtilString& summary = GetValueSummary(); - if (!summary.empty()) - return summary; - - const char *value = m_rValue.GetValue(); - if (value == nullptr) - return m_pUnkwn; - - lldb::SBValue child = m_rValue.GetChildAtIndex(0); - const lldb::BasicType eType = child.GetType().GetBasicType(); - switch (eType) - { - default: - assert(0 && "child must be a char type"); - case lldb::eBasicTypeChar: - case lldb::eBasicTypeSignedChar: - case lldb::eBasicTypeUnsignedChar: - { - const CMIUtilString prefix(ReadCStringFromHostMemory<char>(child)); - // Note code that has const in will not show the text suffix to the string pointer - // i.e. const char * pMyStr = "blah"; ==> "0x00007000"" <-- Eclipse shows this - // but char * pMyStr = "blah"; ==> "0x00007000" "blah"" <-- Eclipse shows this - return CMIUtilString::Format("%s \"%s\"", value, prefix.c_str()); - } - case lldb::eBasicTypeChar16: - { - const CMIUtilString prefix(ReadCStringFromHostMemory<char16_t>(child)); - return CMIUtilString::Format("%s u\"%s\"", value, prefix.c_str()); - } - case lldb::eBasicTypeChar32: - { - const CMIUtilString prefix(ReadCStringFromHostMemory<char32_t>(child)); - return CMIUtilString::Format("%s U\"%s\"", value, prefix.c_str()); - } - } -} - -//++ ------------------------------------------------------------------------------------ -// Details: Retrieve from the LLDB SB Value object of type char[] the c-string value. -// Type: Method. -// Args: None. -// Return: CMIUtilString - The c-string value of the variable. -// Throws: None. -//-- -CMIUtilString -CMICmnLLDBUtilSBValue::GetSimpleValueCStringArray() const -{ - const CMIUtilString& summary = GetValueSummary(); - if (!summary.empty()) - return summary; - - const MIuint nChildren = m_rValue.GetNumChildren(); - lldb::SBValue child = m_rValue.GetChildAtIndex(0); - const lldb::BasicType eType = child.GetType().GetBasicType(); - switch (eType) - { - default: - assert(0 && "value must be a char[] type"); - case lldb::eBasicTypeChar: - case lldb::eBasicTypeSignedChar: - case lldb::eBasicTypeUnsignedChar: - { - const CMIUtilString prefix(ReadCStringFromHostMemory<char>(m_rValue, nChildren)); - // TODO: to match char* it should be the following - // return CMIUtilString::Format("[%u] \"%s\"", nChildren, prefix.c_str()); - return CMIUtilString::Format("\"%s\"", prefix.c_str()); - } - case lldb::eBasicTypeChar16: - { - const CMIUtilString prefix(ReadCStringFromHostMemory<char16_t>(m_rValue, nChildren)); - return CMIUtilString::Format("u\"%s\"", prefix.c_str()); - } - case lldb::eBasicTypeChar32: - { - const CMIUtilString prefix(ReadCStringFromHostMemory<char32_t>(m_rValue, nChildren)); - return CMIUtilString::Format("U\"%s\"", prefix.c_str()); - } - } -} - bool CMICmnLLDBUtilSBValue::GetCompositeValue(const bool vbPrintFieldNames, CMICmnMIValueTuple &vwrMiValueTuple, const MIuint vnDepth /* = 1 */) const @@ -368,30 +213,37 @@ CMICmnLLDBUtilSBValue::GetCompositeValue(const bool vbPrintFieldNames, CMICmnMIV return MIstatus::success; } +// Returns value or value + summary, depending on valueOnly parameter value. +// If result is an empty string returns failVal. CMIUtilString -CMICmnLLDBUtilSBValue::GetValueSummary() const -{ - CMIUtilString valSummary; - if (m_rValue.IsValid()) +CMICmnLLDBUtilSBValue::GetValueSummary(bool valueOnly, const CMIUtilString& failVal) const +{ + if (!m_rValue.IsValid()) + return failVal; + + CMIUtilString value, valSummary; + const char* c_value = m_rValue.GetValue(); + if (valueOnly) + return c_value == nullptr ? failVal : c_value; + + const char* c_summary = m_rValue.GetSummary(); + if (c_value) + value = c_value; + else if (c_summary == nullptr) + return failVal; + + if (c_summary && c_summary[0]) { -#ifndef LLDB_DISABLE_PYTHON - const char *c_str = m_rValue.GetSummary(); - if (c_str && c_str[0]) + valSummary = c_summary; + lldb::SBTypeSummary summary = m_rValue.GetTypeSummary(); + if (summary.IsValid() && summary.DoesPrintValue(m_rValue) && !value.empty()) { - valSummary = c_str; - lldb::SBTypeSummary summary = m_rValue.GetTypeSummary(); - if (summary.IsValid() && summary.DoesPrintValue(m_rValue)) - { - c_str = m_rValue.GetValue(); - if (c_str && c_str[0]) - { - valSummary.insert(0, std::string(c_str) + " "); - } - } + valSummary.insert(0, value + " "); } -#endif + return valSummary; } - return valSummary; + // no summary - return just value + return value; } //++ ------------------------------------------------------------------------------------ diff --git a/lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.h b/lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.h index 66e5870145f..36264da1e16 100644 --- a/lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.h +++ b/lldb/tools/lldb-mi/MICmnLLDBUtilSBValue.h @@ -51,11 +51,8 @@ class CMICmnLLDBUtilSBValue private: template <typename charT> CMIUtilString ReadCStringFromHostMemory(lldb::SBValue &vrValue, const MIuint vnMaxLen = UINT32_MAX) const; bool GetSimpleValue(const bool vbHandleArrayType, CMIUtilString &vrValue) const; - CMIUtilString GetSimpleValueChar() const; - CMIUtilString GetSimpleValueCStringPointer() const; - CMIUtilString GetSimpleValueCStringArray() const; bool GetCompositeValue(const bool vbPrintFieldNames, CMICmnMIValueTuple &vwrMiValueTuple, const MIuint vnDepth = 1) const; - CMIUtilString GetValueSummary() const; + CMIUtilString GetValueSummary(bool valueOnly, const CMIUtilString& failVal = CMIUtilString()) const; // Statics: private: |

