Skip to content

Commit

Permalink
[lldb-mi] display summary for simple types + refactor (use lldb forma…
Browse files Browse the repository at this point in the history
…tting 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
  • Loading branch information
Dawn Perchik committed Oct 23, 2015
1 parent fbb958c commit b91779e
Showing 6 changed files with 134 additions and 194 deletions.
12 changes: 6 additions & 6 deletions lldb/test/tools/lldb-mi/data/TestMiData.py
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ def test_lldbmi_data_disassemble(self):

# Get an address for disassembling: use main
self.runCmd("-data-evaluate-expression main")
self.expect("\^done,value=\"0x[0-9a-f]+\"")
addr = int(self.child.after.split("\"")[1], 16)
self.expect("\^done,value=\"0x[0-9a-f]+ \(a.out`main at main.cpp:[0-9]+\)\"")
addr = int(self.child.after.split("\"")[1].split(" ")[0], 16)

# Test -data-disassemble: try to disassemble some address
self.runCmd("-data-disassemble -s %#x -e %#x -- 0" % (addr, addr + 0x10))
@@ -49,8 +49,8 @@ def test_lldbmi_data_disassemble(self):

# Get an address for disassembling: use hello_world
self.runCmd("-data-evaluate-expression hello_world")
self.expect("\^done,value=\"0x[0-9a-f]+\"")
addr = int(self.child.after.split("\"")[1], 16)
self.expect("\^done,value=\"0x[0-9a-f]+ \(a.out`hello_world\(\) at main.cpp:[0-9]+\)\"")
addr = int(self.child.after.split("\"")[1].split(" ")[0], 16)

# Test -data-disassemble: try to disassemble some address
self.runCmd("-data-disassemble -s %#x -e %#x -- 0" % (addr, addr + 0x10))
@@ -288,8 +288,8 @@ def test_lldbmi_data_info_line(self):

# Get the address of main and its line
self.runCmd("-data-evaluate-expression main")
self.expect("\^done,value=\"0x[0-9a-f]+\"")
addr = int(self.child.after.split("\"")[1], 16)
self.expect("\^done,value=\"0x[0-9a-f]+ \(a.out`main at main.cpp:[0-9]+\)\"")
addr = int(self.child.after.split("\"")[1].split(" ")[0], 16)
line = line_number('main.cpp', '// FUNC_main')

# Test that -data-info-line works for address
4 changes: 2 additions & 2 deletions lldb/test/tools/lldb-mi/symbol/TestMiSymbol.py
Original file line number Diff line number Diff line change
@@ -32,8 +32,8 @@ def test_lldbmi_symbol_list_lines_file(self):

# Get address of main and its line
self.runCmd("-data-evaluate-expression main")
self.expect("\^done,value=\"0x[0-9a-f]+\"")
addr = int(self.child.after.split("\"")[1], 16)
self.expect("\^done,value=\"0x[0-9a-f]+ \(a.out`main at main.cpp:[0-9]+\)\"")
addr = int(self.child.after.split("\"")[1].split(" ")[0], 16)
line = line_number('main.cpp', '// FUNC_main')

# Test that -symbol-list-lines works on valid data
92 changes: 91 additions & 1 deletion lldb/tools/lldb-mi/MICmnLLDBDebugger.cpp
Original file line number Diff line number Diff line change
@@ -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"
@@ -23,6 +28,40 @@
#include "MICmnLLDBDebugSessionInfo.h"
#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.
@@ -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;
}
3 changes: 2 additions & 1 deletion lldb/tools/lldb-mi/MICmnLLDBDebugger.h
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit b91779e

Please sign in to comment.