summaryrefslogtreecommitdiffstats
path: root/lldb/unittests/Symbol/PostfixExpressionTest.cpp
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-04-26 08:52:04 +0000
committerPavel Labath <pavel@labath.sk>2019-04-26 08:52:04 +0000
commit0eadd988662533f5ef89a2024dc7ebf830f16b67 (patch)
tree03ec674849fa9f86f9046f79abd66d7257816231 /lldb/unittests/Symbol/PostfixExpressionTest.cpp
parent5d5ee4aff748c827d54fa8c3224ad7090bb018bc (diff)
downloadbcm5719-llvm-0eadd988662533f5ef89a2024dc7ebf830f16b67.tar.gz
bcm5719-llvm-0eadd988662533f5ef89a2024dc7ebf830f16b67.zip
PostfixExpression: move DWARF generator out of NativePDB internals
Summary: The new dwarf generator is pretty much a verbatim copy of the one in PDB. In order to write a pdb-independent test for it, I needed to write a dummy "symbol resolver", which (together with the fact that I'll need one more for breakpad-specific resolution logic) prompted me to create a more simple interface for algorithms which replace or "resolve" SymbolNodes. The resolving algorithms in NativePDB have been updated to make use of that too. I have removed a couple of NativePDB tests which weren't testing anything pdb-specific and where the tested functionality was covered by the new format-agnostic tests I have added. Reviewers: amccarth, clayborg, aleksandr.urakov Subscribers: aprantl, markmentovai, lldb-commits, jasonmolenda, JDevlieghere Differential Revision: https://reviews.llvm.org/D61056 llvm-svn: 359288
Diffstat (limited to 'lldb/unittests/Symbol/PostfixExpressionTest.cpp')
-rw-r--r--lldb/unittests/Symbol/PostfixExpressionTest.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/lldb/unittests/Symbol/PostfixExpressionTest.cpp b/lldb/unittests/Symbol/PostfixExpressionTest.cpp
index 87cce32fc45..f919a944b0e 100644
--- a/lldb/unittests/Symbol/PostfixExpressionTest.cpp
+++ b/lldb/unittests/Symbol/PostfixExpressionTest.cpp
@@ -7,6 +7,9 @@
//===----------------------------------------------------------------------===//
#include "lldb/Symbol/PostfixExpression.h"
+#include "lldb/Expression/DWARFExpression.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/StreamString.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
@@ -95,3 +98,55 @@ TEST(PostfixExpression, Parse) {
EXPECT_EQ("nullptr", ParseAndStringify("1 2"));
EXPECT_EQ("nullptr", ParseAndStringify(""));
}
+
+static std::string ParseAndGenerateDWARF(llvm::StringRef expr) {
+ llvm::BumpPtrAllocator alloc;
+ Node *ast = Parse(expr, alloc);
+ if (!ast)
+ return "Parse failed.";
+ if (!ResolveSymbols(ast, [&](SymbolNode &symbol) -> Node * {
+ uint32_t num;
+ if (to_integer(symbol.GetName().drop_front(), num))
+ return MakeNode<RegisterNode>(alloc, num);
+ return nullptr;
+ })) {
+ return "Resolution failed.";
+ }
+
+ const size_t addr_size = 4;
+ StreamString dwarf(Stream::eBinary, addr_size, lldb::eByteOrderLittle);
+ ToDWARF(*ast, dwarf);
+
+ // print dwarf expression to comparable textual representation
+ DataExtractor extractor(dwarf.GetData(), dwarf.GetSize(),
+ lldb::eByteOrderLittle, addr_size);
+
+ StreamString result;
+ if (!DWARFExpression::PrintDWARFExpression(result, extractor, addr_size,
+ /*dwarf_ref_size*/ 4,
+ /*location_expression*/ false)) {
+ return "DWARF printing failed.";
+ }
+
+ return result.GetString();
+}
+
+TEST(PostfixExpression, ToDWARF) {
+ EXPECT_EQ("DW_OP_constu 0x0", ParseAndGenerateDWARF("0"));
+
+ EXPECT_EQ("DW_OP_breg1 +0", ParseAndGenerateDWARF("R1"));
+
+ EXPECT_EQ("DW_OP_bregx 65 0", ParseAndGenerateDWARF("R65"));
+
+ EXPECT_EQ("DW_OP_constu 0x4, DW_OP_constu 0x5, DW_OP_plus ",
+ ParseAndGenerateDWARF("4 5 +"));
+
+ EXPECT_EQ("DW_OP_constu 0x4, DW_OP_constu 0x5, DW_OP_minus ",
+ ParseAndGenerateDWARF("4 5 -"));
+
+ EXPECT_EQ("DW_OP_constu 0x4, DW_OP_deref ", ParseAndGenerateDWARF("4 ^"));
+
+ EXPECT_EQ("DW_OP_breg6 +0, DW_OP_constu 0x80, DW_OP_lit1 "
+ ", DW_OP_minus , DW_OP_not , DW_OP_and ",
+ ParseAndGenerateDWARF("R6 128 @"));
+}
OpenPOWER on IntegriCloud