-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data formatter for libc++ std::queue
Summary: std::queue is just a fancy wrapper around another container, so all we need to do is to delegate to the it. Reviewers: jingham, EricWF Subscribers: srhines, mgorny, lldb-commits, eugene Differential Revision: https://reviews.llvm.org/D35666 llvm-svn: 317099
- Loading branch information
Showing
7 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
...on/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
LEVEL = ../../../../../make | ||
|
||
CXX_SOURCES := main.cpp | ||
|
||
USE_LIBCPP := 1 | ||
include $(LEVEL)/Makefile.rules |
43 changes: 43 additions & 0 deletions
43
...ionalities/data-formatter/data-formatter-stl/libcxx/queue/TestDataFormatterLibcxxQueue.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Test lldb data formatter subsystem. | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
|
||
import lldb | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
|
||
class TestDataFormatterLibcxxQueue(TestBase): | ||
|
||
mydir = TestBase.compute_mydir(__file__) | ||
|
||
def setUp(self): | ||
TestBase.setUp(self) | ||
ns = 'ndk' if lldbplatformutil.target_is_android() else '' | ||
self.namespace = 'std::__' + ns + '1' | ||
|
||
def check_variable(self, name): | ||
var = self.frame().FindVariable(name) | ||
self.assertTrue(var.IsValid()) | ||
|
||
queue = self.namespace + '::queue' | ||
self.assertTrue(queue in var.GetTypeName()) | ||
self.assertEqual(var.GetNumChildren(), 5) | ||
for i in range(5): | ||
ch = var.GetChildAtIndex(i) | ||
self.assertTrue(ch.IsValid()) | ||
self.assertEqual(ch.GetValueAsSigned(), i+1) | ||
|
||
@add_test_categories(["libc++"]) | ||
def test(self): | ||
"""Test that std::queue is displayed correctly""" | ||
self.build() | ||
lldbutil.run_to_source_breakpoint(self, '// break here', | ||
lldb.SBFileSpec("main.cpp", False)) | ||
|
||
self.check_variable('q1') | ||
self.check_variable('q2') |
11 changes: 11 additions & 0 deletions
11
...on/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/queue/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <queue> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
queue<int> q1{{1,2,3,4,5}}; | ||
queue<int, std::vector<int>> q2{{1,2,3,4,5}}; | ||
int ret = q1.size() + q2.size(); // break here | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//===-- LibCxxQueue.cpp -----------------------------------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "LibCxx.h" | ||
#include "lldb/DataFormatters/FormattersHelpers.h" | ||
|
||
using namespace lldb; | ||
using namespace lldb_private; | ||
|
||
namespace { | ||
|
||
class QueueFrontEnd : public SyntheticChildrenFrontEnd { | ||
public: | ||
QueueFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) { | ||
Update(); | ||
} | ||
|
||
size_t GetIndexOfChildWithName(const ConstString &name) override { | ||
return m_container_sp ? m_container_sp->GetIndexOfChildWithName(name) | ||
: UINT32_MAX; | ||
} | ||
|
||
bool MightHaveChildren() override { return true; } | ||
bool Update() override; | ||
|
||
size_t CalculateNumChildren() override { | ||
return m_container_sp ? m_container_sp->GetNumChildren() : 0; | ||
} | ||
|
||
ValueObjectSP GetChildAtIndex(size_t idx) override { | ||
return m_container_sp ? m_container_sp->GetChildAtIndex(idx, true) | ||
: nullptr; | ||
} | ||
|
||
private: | ||
ValueObjectSP m_container_sp; | ||
}; | ||
} // namespace | ||
|
||
bool QueueFrontEnd::Update() { | ||
m_container_sp.reset(); | ||
ValueObjectSP c_sp = m_backend.GetChildMemberWithName(ConstString("c"), true); | ||
if (!c_sp) | ||
return false; | ||
m_container_sp = c_sp->GetSyntheticValue(); | ||
return false; | ||
} | ||
|
||
SyntheticChildrenFrontEnd * | ||
formatters::LibcxxQueueFrontEndCreator(CXXSyntheticChildren *, | ||
lldb::ValueObjectSP valobj_sp) { | ||
if (valobj_sp) | ||
return new QueueFrontEnd(*valobj_sp); | ||
return nullptr; | ||
} |