[Lldb-commits] [PATCH] D50293: Added unit test for StringList
teemperor created this revision. Herald added a subscriber: mgorny. Repository: rLLDB LLDB https://reviews.llvm.org/D50293 Files: unittests/Utility/CMakeLists.txt unittests/Utility/StringListTest.cpp Index: unittests/Utility/StringListTest.cpp === --- /dev/null +++ unittests/Utility/StringListTest.cpp @@ -0,0 +1,512 @@ +//===-- StringListTest.cpp ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "lldb/Utility/StringList.h" +#include "lldb/Utility/StreamString.h" +#include "gtest/gtest.h" + +using namespace lldb_private; + +TEST(StringListTest, DefaultConstructor) { + StringList s; + EXPECT_EQ(0U, s.GetSize()); +} + +TEST(StringListTest, Assignment) { + StringList orig; + orig.AppendString("foo"); + orig.AppendString("bar"); + + StringList s = orig; + + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); + + ASSERT_EQ(2U, orig.GetSize()); + EXPECT_STREQ("foo", orig.GetStringAtIndex(0)); + EXPECT_STREQ("bar", orig.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendStringStdString) { + StringList s; + s.AppendString("foo"); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s.AppendString("bar"); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendStringCString) { + StringList s; + s.AppendString("foo", strlen("foo")); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s.AppendString("bar", strlen("bar")); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendStringMove) { + StringList s; + std::string foo = "foo"; + std::string bar = "bar"; + + s.AppendString(std::move(foo)); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s.AppendString(std::move(bar)); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, ShiftStdString) { + StringList s; + std::string foo = "foo"; + std::string bar = "bar"; + + s << foo; + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s << bar; + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, ShiftCString) { + StringList s; + s << "foo"; + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s << "bar"; + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, ShiftMove) { + StringList s; + std::string foo = "foo"; + std::string bar = "bar"; + + s << std::move(foo); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s << std::move(bar); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendListCStringArrayEmpty) { + StringList s; + s.AppendList(nullptr, 0); + EXPECT_EQ(0U, s.GetSize()); +} + +TEST(StringListTest, AppendListCStringArray) { + StringList s; + const char *items[3] = {"foo", "", "bar"}; + s.AppendList(items, 3); + + EXPECT_EQ(3U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("", s.GetStringAtIndex(1)); + EXPECT_STREQ("bar", s.GetStringAtIndex(2)); +} + +TEST(StringListTest, AppendList) { + StringList other; + other.AppendString("foo"); + other.AppendString(""); + other.AppendString("bar"); + + StringList empty; + + StringList s; + s.AppendList(other); + + EXPECT_EQ(3U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("", s.GetStringAtIndex(1)); + EXPECT_STREQ("bar", s.GetStringAtIndex(2)); + + EXPECT_EQ(3U, other.GetSize()); + EXPECT_STREQ("foo", other.GetStringAtIndex(0)); + EXPECT_STREQ("", other.GetStringAtIndex(1)); + EXPECT_STREQ("bar", other.GetStringAtIndex(2)); + + s.AppendList(empty); + s.AppendList(other); + EXPECT_EQ(6U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("", s.GetStringAtIndex(1)); + EXPECT_STREQ("bar", s.GetStringAtIndex(2)); + EXPECT_STREQ("foo", s.GetStringAtIndex(3)); + EXPECT_STREQ("", s.GetStringAtIndex(4)); + EXPECT_STREQ("bar", s.GetStringAtIndex(5)); + + EXPECT_EQ(3U, other.GetSize()); + EXPECT_STREQ("foo", other.GetStringAtIndex(0)); + EXPECT_STREQ("", other.GetStringAtIndex(1)); + EXPE
[Lldb-commits] [PATCH] D50274: Misc module/dwarf logging improvements
labath added inline comments. Comment at: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:3400-3403 +GetModule()->ReportWarning( +"Unable to initialize decompressor for section '%s'", +section->GetName().GetCString()); +return 0; You have to consume the `Decompressor.takeError()` object to fulfill the `llvm::Error` contract. Easiest way to do that is to actually print it out. Comment at: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:3407 std::make_shared(Decompressor->getDecompressedSize(), 0); if (auto Error = Decompressor->decompress( {reinterpret_cast(buffer_sp->GetBytes()), Same here. Comment at: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:3413 +section->GetName().GetCString()); +return 0; } `lit/Modules/compressed-sections.yaml` test will need to be updated to account for the return 0. Repository: rLLDB LLDB https://reviews.llvm.org/D50274 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50274: Misc module/dwarf logging improvements
clayborg added a comment. LGTM after Pavel's inline comments are addressed. Repository: rLLDB LLDB https://reviews.llvm.org/D50274 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] r338961 - Added unit test for StringList
Author: teemperor Date: Sat Aug 4 10:28:21 2018 New Revision: 338961 URL: http://llvm.org/viewvc/llvm-project?rev=338961&view=rev Log: Added unit test for StringList Reviewers: labath Reviewed By: labath Subscribers: mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D50293 Added: lldb/trunk/unittests/Utility/StringListTest.cpp Modified: lldb/trunk/unittests/Utility/CMakeLists.txt Modified: lldb/trunk/unittests/Utility/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/CMakeLists.txt?rev=338961&r1=338960&r2=338961&view=diff == --- lldb/trunk/unittests/Utility/CMakeLists.txt (original) +++ lldb/trunk/unittests/Utility/CMakeLists.txt Sat Aug 4 10:28:21 2018 @@ -16,6 +16,7 @@ add_lldb_unittest(UtilityTests StreamTeeTest.cpp StreamTest.cpp StringExtractorTest.cpp + StringListTest.cpp StructuredDataTest.cpp TildeExpressionResolverTest.cpp TimeoutTest.cpp Added: lldb/trunk/unittests/Utility/StringListTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/StringListTest.cpp?rev=338961&view=auto == --- lldb/trunk/unittests/Utility/StringListTest.cpp (added) +++ lldb/trunk/unittests/Utility/StringListTest.cpp Sat Aug 4 10:28:21 2018 @@ -0,0 +1,512 @@ +//===-- StringListTest.cpp ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "lldb/Utility/StringList.h" +#include "lldb/Utility/StreamString.h" +#include "gtest/gtest.h" + +using namespace lldb_private; + +TEST(StringListTest, DefaultConstructor) { + StringList s; + EXPECT_EQ(0U, s.GetSize()); +} + +TEST(StringListTest, Assignment) { + StringList orig; + orig.AppendString("foo"); + orig.AppendString("bar"); + + StringList s = orig; + + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); + + ASSERT_EQ(2U, orig.GetSize()); + EXPECT_STREQ("foo", orig.GetStringAtIndex(0)); + EXPECT_STREQ("bar", orig.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendStringStdString) { + StringList s; + s.AppendString("foo"); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s.AppendString("bar"); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendStringCString) { + StringList s; + s.AppendString("foo", strlen("foo")); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s.AppendString("bar", strlen("bar")); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendStringMove) { + StringList s; + std::string foo = "foo"; + std::string bar = "bar"; + + s.AppendString(std::move(foo)); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s.AppendString(std::move(bar)); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, ShiftStdString) { + StringList s; + std::string foo = "foo"; + std::string bar = "bar"; + + s << foo; + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s << bar; + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, ShiftCString) { + StringList s; + s << "foo"; + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s << "bar"; + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, ShiftMove) { + StringList s; + std::string foo = "foo"; + std::string bar = "bar"; + + s << std::move(foo); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s << std::move(bar); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendListCStringArrayEmpty) { + StringList s; + s.AppendList(nullptr, 0); + EXPECT_EQ(0U, s.GetSize()); +} + +TEST(StringListTest, AppendListCStringArray) { + StringList s; + const char *items[3] = {"foo", "", "bar"}; + s.AppendList(items, 3); + + EXPECT_EQ(3U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("", s.GetStringAtIndex(1)); + EXPECT_STREQ("bar", s.GetStringAtIndex(2)); +} + +TEST(StringListTest, AppendList)
[Lldb-commits] [PATCH] D50293: Added unit test for StringList
This revision was automatically updated to reflect the committed changes. Closed by commit rL338961: Added unit test for StringList (authored by teemperor, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D50293?vs=159165&id=159185#toc Repository: rL LLVM https://reviews.llvm.org/D50293 Files: lldb/trunk/unittests/Utility/CMakeLists.txt lldb/trunk/unittests/Utility/StringListTest.cpp Index: lldb/trunk/unittests/Utility/CMakeLists.txt === --- lldb/trunk/unittests/Utility/CMakeLists.txt +++ lldb/trunk/unittests/Utility/CMakeLists.txt @@ -16,6 +16,7 @@ StreamTeeTest.cpp StreamTest.cpp StringExtractorTest.cpp + StringListTest.cpp StructuredDataTest.cpp TildeExpressionResolverTest.cpp TimeoutTest.cpp Index: lldb/trunk/unittests/Utility/StringListTest.cpp === --- lldb/trunk/unittests/Utility/StringListTest.cpp +++ lldb/trunk/unittests/Utility/StringListTest.cpp @@ -0,0 +1,512 @@ +//===-- StringListTest.cpp ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "lldb/Utility/StringList.h" +#include "lldb/Utility/StreamString.h" +#include "gtest/gtest.h" + +using namespace lldb_private; + +TEST(StringListTest, DefaultConstructor) { + StringList s; + EXPECT_EQ(0U, s.GetSize()); +} + +TEST(StringListTest, Assignment) { + StringList orig; + orig.AppendString("foo"); + orig.AppendString("bar"); + + StringList s = orig; + + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); + + ASSERT_EQ(2U, orig.GetSize()); + EXPECT_STREQ("foo", orig.GetStringAtIndex(0)); + EXPECT_STREQ("bar", orig.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendStringStdString) { + StringList s; + s.AppendString("foo"); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s.AppendString("bar"); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendStringCString) { + StringList s; + s.AppendString("foo", strlen("foo")); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s.AppendString("bar", strlen("bar")); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendStringMove) { + StringList s; + std::string foo = "foo"; + std::string bar = "bar"; + + s.AppendString(std::move(foo)); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s.AppendString(std::move(bar)); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, ShiftStdString) { + StringList s; + std::string foo = "foo"; + std::string bar = "bar"; + + s << foo; + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s << bar; + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, ShiftCString) { + StringList s; + s << "foo"; + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s << "bar"; + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, ShiftMove) { + StringList s; + std::string foo = "foo"; + std::string bar = "bar"; + + s << std::move(foo); + ASSERT_EQ(1U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + + s << std::move(bar); + ASSERT_EQ(2U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("bar", s.GetStringAtIndex(1)); +} + +TEST(StringListTest, AppendListCStringArrayEmpty) { + StringList s; + s.AppendList(nullptr, 0); + EXPECT_EQ(0U, s.GetSize()); +} + +TEST(StringListTest, AppendListCStringArray) { + StringList s; + const char *items[3] = {"foo", "", "bar"}; + s.AppendList(items, 3); + + EXPECT_EQ(3U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("", s.GetStringAtIndex(1)); + EXPECT_STREQ("bar", s.GetStringAtIndex(2)); +} + +TEST(StringListTest, AppendList) { + StringList other; + other.AppendString("foo"); + other.AppendString(""); + other.AppendString("bar"); + + StringList empty; + + StringList s; + s.AppendList(other); + + EXPECT_EQ(3U, s.GetSize()); + EXPECT_STREQ("foo", s.GetStringAtIndex(0)); + EXPECT_STREQ("", s.GetStringAtIndex(1)); + EXPECT_STREQ("bar", s
[Lldb-commits] [PATCH] D49740: Move RegisterValue, Scalar, State from Core to Utility
labath added a comment. In https://reviews.llvm.org/D49740#1188055, @jingham wrote: > First off, I'm fine with Zachary's suggestion that we let the dust settle a > bit before we try to organize things better. We'll probably do a better job > then. Thanks. I agree this can wait, but I also do have some ideas below on what could done differently right now for the Scalar and State classes. Let me know if you think I should try that instead. (Otherwise, I'll just go ahead with this.) > But just to use these cases, for instance, Scalar is the base of how we > realize values in the debugger (ValueObject lives on top of this). It would > be good if its landing place was such that if I was looking at how we > represent values it was logically placed for that. I think putting Scalar next to the ValueObject stuff would make sense, if the ValueObjects were the only user of this class. However, that isn't the case right now. The reason I am touching this class in the first place is that it is being used from within the RegisterValue class. This means it is more than just a ValueObject helper, but more like a self-contained "utility" which can be reused in different contexts. Now, I am not actually sure whether using Scalar within RegisterValue is a good idea (seems a bit overkill for that), but it seemed to work, so I didn't want to disturb that (and I do believe that Scalar could be useful outside of the ValueObject hierarchy). However, I can take another look at what it would take to stop using Scalar in the context of RegisterValues, which would free us up to move RegisterValue without touching the Scalar class. > State is part of how we present the Process current state, so it seems like > it should be grouped with other process related entities. State is a bit funny. It is currently used from both liblldb and lldb-server, but these use different hierarchies for "process-related entities", so that's why I'm moving it to a common place. However, I can certainly see a case for LLGS and liblldb having different State enums. Sharing it doesn't buy us much (ATM it's just the StateAsCString function), and using a different enum in LLGS would have another benefit. Right now it only uses a subset of all State values, so using an different enum would allow us to capture the possible states more precisely. Doing that instead of moving State.h around should be easy enough. > And RegisterValue belongs with the other parts of lldb that take apart the > machine level state of a process. I am not sure which parts are *you* thinking about here, but I think it would be nice to have this class together with all the definitions of RegisterInfo structs and associated constants. These are now mostly in Plugin/Process/Utility, but so is a lot of other stuff. At one point I will get around to worrying about those too, so maybe then we could move all of these things to a separate module. > It will probably go away, but FastDemangle really belongs around the language > handling code. I agree that Utility is an odd place for CompletionRequest... > > SafeMachO is weird. It gets used in Host - both common & macosx, and we're > trying not to include out of Plugins so the MachO object file plugin > directory doesn't seem right. Maybe Host is a better place, it's reason for > being is so you can include both llvm/Support/MachO.h and mach/machine.h, so > even though it's not directly a host functionality it look a bit like that. > Not sure. I think Host makes sense. None of the other code (except the NativeProcessXXX classes, I guess) should really be including OS-specific stuff, so there shouldn't be a need (in an ideal world, I don't know how far we are from it right now) for this header anywhere except Host code. > There's also tension between "things that belong together functionally" and > "things that need to be separated because we want to layer one strictly on > top of the other, since we seem to be treating directories as a > representation of dependencies. Do we want to have a Values directory with > ValueObject at the top level, and Scalar in a no-dependency subdirectory? > > , if I need to find a file these days, I either Cmd-Click on a type to go > to its definition, or type Cmd-Shift-O and start typing some bits of the file > name and Xcode finds it for me. I'm pretty familiar with the code, so I > don't need a higher level skeleton to help me figure out what all is in this > project. I think at this point many of us are in this state... > > But once you get past the build issues, the real audience for this level of > organization is folks coming new to the project. It would be good to hear > from some of the newer folks what they found confusing or what would have > helped them navigate around the project as they are starting out. Yes, that's certainly a good point. I'd like to hear that too. https://reviews.llvm.org/D49740 __
[Lldb-commits] [PATCH] D49740: Move RegisterValue, Scalar, State from Core to Utility
labath added a comment. In https://reviews.llvm.org/D49740#1188079, @teemperor wrote: > > CompletionRequest - this sounds like it could go next to the command > > interpreter > > Yeah, makes sense. Even though Utility classes then can either not offer > completion methods (currently only ArchSpec is doing that) or work around > that with a forward decl. But I think that's not a big issue. I am not too bothered by that either, but I think that for the thing that the ArchSpec function is doing, passing it the entire CompletionRequest is overkill. Ideally, I'd set things up such that ArchSpec and friends don't have any knowledge of "completion" -- they would just offer an interface for accessing all possible values(*), and then completion could be built on top of that. This way the data source can be independent of the actual algorithm computing the completions. (*) The interface could be as simple as an iterator over all ArchSpec string values. However, this may not be good enough in terms of performance (it wouldn't matter for ArchSpec, but it might for some other classes), in which case we might want to do something slightly more fancy (`GiveMeAllValuesStartingWith("foo")`). https://reviews.llvm.org/D49740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50298: Add unit test for StringLexer
teemperor created this revision. teemperor added a reviewer: labath. Herald added a subscriber: mgorny. Repository: rLLDB LLDB https://reviews.llvm.org/D50298 Files: unittests/Utility/CMakeLists.txt unittests/Utility/StringLexerTest.cpp Index: unittests/Utility/StringLexerTest.cpp === --- /dev/null +++ unittests/Utility/StringLexerTest.cpp @@ -0,0 +1,141 @@ +//===-- StringLexerTest.cpp -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "lldb/Utility/StringLexer.h" +#include "gtest/gtest.h" + +using namespace lldb_utility; + +TEST(StringLexerTest, GetUnlexed) { + StringLexer l("foo"); + EXPECT_EQ("foo", l.GetUnlexed()); + l.Next(); + EXPECT_EQ("oo", l.GetUnlexed()); + l.Next(); + l.Next(); + EXPECT_EQ("", l.GetUnlexed()); +} + +TEST(StringLexerTest, HasAtLest) { + StringLexer l("foo"); + EXPECT_FALSE(l.HasAtLeast(5)); + EXPECT_FALSE(l.HasAtLeast(4)); + EXPECT_TRUE(l.HasAtLeast(3)); + EXPECT_TRUE(l.HasAtLeast(2)); + EXPECT_TRUE(l.HasAtLeast(1)); + + l.Next(); + EXPECT_FALSE(l.HasAtLeast(5)); + EXPECT_FALSE(l.HasAtLeast(4)); + EXPECT_FALSE(l.HasAtLeast(3)); + EXPECT_TRUE(l.HasAtLeast(2)); + EXPECT_TRUE(l.HasAtLeast(1)); + + l.Next(); + l.Next(); + EXPECT_FALSE(l.HasAtLeast(5)); + EXPECT_FALSE(l.HasAtLeast(4)); + EXPECT_FALSE(l.HasAtLeast(3)); + EXPECT_FALSE(l.HasAtLeast(2)); + EXPECT_FALSE(l.HasAtLeast(1)); +} + +TEST(StringLexerTest, AdvanceIf) { + StringLexer l("foobar"); + + EXPECT_FALSE(l.AdvanceIf("oo")); + // Skip the "fo" part. + EXPECT_TRUE(l.AdvanceIf("fo")); + EXPECT_FALSE(l.AdvanceIf("obarz")); + // Skip the remaining string. + EXPECT_TRUE(l.AdvanceIf("obar")); + + EXPECT_FALSE(l.AdvanceIf("obarz")); + EXPECT_FALSE(l.AdvanceIf("foo")); + EXPECT_FALSE(l.AdvanceIf("o")); + EXPECT_FALSE(l.AdvanceIf(" ")); +} + +TEST(StringLexerTest, PutBack) { + StringLexer l("foo"); + + l.Next(); + l.PutBack(1); + EXPECT_EQ("foo", l.GetUnlexed()); + + l.Next(); + l.Next(); + l.Next(); + l.PutBack(2); + EXPECT_EQ("oo", l.GetUnlexed()); + + l.PutBack(1); + EXPECT_EQ("foo", l.GetUnlexed()); +} + +TEST(StringLexerTest, Peek) { + StringLexer l("foo"); + + EXPECT_EQ('f', l.Peek()); + l.Next(); + EXPECT_EQ('o', l.Peek()); + l.Next(); + EXPECT_EQ('o', l.Peek()); +} + +TEST(StringLexerTest, Next) { + StringLexer l("foo"); + EXPECT_EQ('f', l.Next()); + EXPECT_EQ('o', l.Next()); + EXPECT_EQ('o', l.Next()); +} + +TEST(StringLexerTest, NextIf) { + StringLexer l("foo"); + + EXPECT_FALSE(l.NextIf('\0')); + EXPECT_FALSE(l.NextIf(' ')); + EXPECT_FALSE(l.NextIf('o')); + + EXPECT_TRUE(l.NextIf('f')); + + EXPECT_FALSE(l.NextIf('\0')); + EXPECT_FALSE(l.NextIf(' ')); + EXPECT_FALSE(l.NextIf('f')); + + EXPECT_TRUE(l.NextIf('o')); + + EXPECT_FALSE(l.NextIf('\0')); + EXPECT_FALSE(l.NextIf(' ')); + EXPECT_FALSE(l.NextIf('f')); + + EXPECT_TRUE(l.NextIf('o')); +} + +TEST(StringLexerTest, NextIfList) { + StringLexer l("foo"); + + EXPECT_FALSE(l.NextIf({'\0', ' ', 'o'}).first); + + auto r = l.NextIf({'f'}); + EXPECT_TRUE(r.first); + EXPECT_EQ('f', r.second); + + EXPECT_FALSE(l.NextIf({'\0', ' ', 'f'}).first); + + r = l.NextIf({'f', 'o'}); + EXPECT_TRUE(r.first); + EXPECT_EQ('o', r.second); + + EXPECT_FALSE(l.NextIf({'\0', ' ', 'f'}).first); + + r = l.NextIf({'*', 'f', 'o', 'o'}); + EXPECT_TRUE(r.first); + EXPECT_EQ('o', r.second); +} Index: unittests/Utility/CMakeLists.txt === --- unittests/Utility/CMakeLists.txt +++ unittests/Utility/CMakeLists.txt @@ -16,6 +16,7 @@ StreamTeeTest.cpp StreamTest.cpp StringExtractorTest.cpp + StringLexerTest.cpp StringListTest.cpp StructuredDataTest.cpp TildeExpressionResolverTest.cpp ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D49969: DWZ 04/06: ManualDWARFIndex::GetGlobalVariables for DIEs in PUs
jankratochvil updated this revision to Diff 159192. Repository: rLLDB LLDB https://reviews.llvm.org/D49969 Files: source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h source/Plugins/SymbolFile/DWARF/NameToDIE.cpp source/Plugins/SymbolFile/DWARF/NameToDIE.h Index: source/Plugins/SymbolFile/DWARF/NameToDIE.h === --- source/Plugins/SymbolFile/DWARF/NameToDIE.h +++ source/Plugins/SymbolFile/DWARF/NameToDIE.h @@ -11,6 +11,7 @@ #define SymbolFileDWARF_NameToDIE_h_ #include +#include #include "DIERef.h" #include "lldb/Core/UniqueCStringMap.h" @@ -39,9 +40,16 @@ size_t Find(const lldb_private::RegularExpression ®ex, DIEArray &info_array) const; + size_t FindAllEntriesForCompileUnit( + std::function compare, DIEArray &info_array) const; + size_t FindAllEntriesForCompileUnit(dw_offset_t cu_offset, DIEArray &info_array) const; + size_t FindAllEntriesForCompileUnit( + const std::unordered_set &cu_offsets, + DIEArray &info_array) const; + void ForEach(std::function const Index: source/Plugins/SymbolFile/DWARF/NameToDIE.cpp === --- source/Plugins/SymbolFile/DWARF/NameToDIE.cpp +++ source/Plugins/SymbolFile/DWARF/NameToDIE.cpp @@ -39,18 +39,33 @@ return m_map.GetValues(regex, info_array); } -size_t NameToDIE::FindAllEntriesForCompileUnit(dw_offset_t cu_offset, - DIEArray &info_array) const { +size_t NameToDIE::FindAllEntriesForCompileUnit( +std::function compare, DIEArray &info_array) const { const size_t initial_size = info_array.size(); const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i); -if (cu_offset == die_ref.cu_offset) +if (compare(die_ref.cu_offset)) info_array.push_back(die_ref); } return info_array.size() - initial_size; } +size_t NameToDIE::FindAllEntriesForCompileUnit(dw_offset_t cu_offset, + DIEArray &info_array) const { + return FindAllEntriesForCompileUnit([cu_offset](dw_offset_t offset) { +return offset == cu_offset; + }, info_array); +} + +size_t NameToDIE::FindAllEntriesForCompileUnit( +const std::unordered_set &cu_offsets, +DIEArray &info_array) const { + return FindAllEntriesForCompileUnit([&cu_offsets](dw_offset_t offset) { +return cu_offsets.count(offset) != 0; + }, info_array); +} + void NameToDIE::Dump(Stream *s) { const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { Index: source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h === --- source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -11,8 +11,12 @@ #define LLDB_MANUALDWARFINDEX_H #include "Plugins/SymbolFile/DWARF/DWARFIndex.h" +#include "Plugins/SymbolFile/DWARF/DWARFUnit.h" #include "Plugins/SymbolFile/DWARF/NameToDIE.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/Support/RWMutex.h" + +#include namespace lldb_private { class ManualDWARFIndex : public DWARFIndex { @@ -22,6 +26,8 @@ : DWARFIndex(module), m_debug_info(debug_info), m_units_to_avoid(std::move(units_to_avoid)) {} + ~ManualDWARFIndex() override; + void Preload() override { Index(); } void GetGlobalVariables(ConstString basename, DIEArray &offsets) override; @@ -68,7 +74,19 @@ /// Which dwarf units should we skip while building the index. llvm::DenseSet m_units_to_avoid; + void AddExtractedPU(DWARFUnit &importer, DWARFUnit &importee); + IndexSet m_set; + + // All DW_TAG_partial_unit's extracted for Index-ing this DW_TAG_compile_unit. + struct ExtractedForUnit { +// FIXME: The pointer is already contained in the value; but we wound need +// a combination of DenseSet::insert_as and DenseSet::try_emplace. +std::unordered_map m_map; +llvm::sys::RWMutex m_mutex; + }; + std::unordered_map m_extracted_pu; + llvm::sys::RWMutex m_extracted_pu_mutex; }; } // namespace lldb_private Index: source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp === --- source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -409,6 +409,7 @@ break; } import_cu->SetMainCU(&main_unit); +AddExtractedPU(unit, *import_cu); IndexUnit(*import_cu,set); } break; @@ -433,7 +434,34 @@ void ManualDWARFIndex::GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) { Index(); - m_set.globals.FindAllEntriesForCompileUnit(cu.GetOffset(), offsets); + if (m_e
[Lldb-commits] [PATCH] D50298: Add unit test for StringLexer
jloser added inline comments. Comment at: unittests/Utility/StringLexerTest.cpp:25 + +TEST(StringLexerTest, HasAtLest) { + StringLexer l("foo"); Nit: typo in the test case name. Repository: rLLDB LLDB https://reviews.llvm.org/D50298 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50298: Add unit test for StringLexer
teemperor updated this revision to Diff 159193. teemperor added a comment. - Fixed typo (Thanks Joe!) https://reviews.llvm.org/D50298 Files: unittests/Utility/CMakeLists.txt unittests/Utility/StringLexerTest.cpp Index: unittests/Utility/StringLexerTest.cpp === --- /dev/null +++ unittests/Utility/StringLexerTest.cpp @@ -0,0 +1,141 @@ +//===-- StringLexerTest.cpp -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "lldb/Utility/StringLexer.h" +#include "gtest/gtest.h" + +using namespace lldb_utility; + +TEST(StringLexerTest, GetUnlexed) { + StringLexer l("foo"); + EXPECT_EQ("foo", l.GetUnlexed()); + l.Next(); + EXPECT_EQ("oo", l.GetUnlexed()); + l.Next(); + l.Next(); + EXPECT_EQ("", l.GetUnlexed()); +} + +TEST(StringLexerTest, HasAtLeast) { + StringLexer l("foo"); + EXPECT_FALSE(l.HasAtLeast(5)); + EXPECT_FALSE(l.HasAtLeast(4)); + EXPECT_TRUE(l.HasAtLeast(3)); + EXPECT_TRUE(l.HasAtLeast(2)); + EXPECT_TRUE(l.HasAtLeast(1)); + + l.Next(); + EXPECT_FALSE(l.HasAtLeast(5)); + EXPECT_FALSE(l.HasAtLeast(4)); + EXPECT_FALSE(l.HasAtLeast(3)); + EXPECT_TRUE(l.HasAtLeast(2)); + EXPECT_TRUE(l.HasAtLeast(1)); + + l.Next(); + l.Next(); + EXPECT_FALSE(l.HasAtLeast(5)); + EXPECT_FALSE(l.HasAtLeast(4)); + EXPECT_FALSE(l.HasAtLeast(3)); + EXPECT_FALSE(l.HasAtLeast(2)); + EXPECT_FALSE(l.HasAtLeast(1)); +} + +TEST(StringLexerTest, AdvanceIf) { + StringLexer l("foobar"); + + EXPECT_FALSE(l.AdvanceIf("oo")); + // Skip the "fo" part. + EXPECT_TRUE(l.AdvanceIf("fo")); + EXPECT_FALSE(l.AdvanceIf("obarz")); + // Skip the remaining string. + EXPECT_TRUE(l.AdvanceIf("obar")); + + EXPECT_FALSE(l.AdvanceIf("obarz")); + EXPECT_FALSE(l.AdvanceIf("foo")); + EXPECT_FALSE(l.AdvanceIf("o")); + EXPECT_FALSE(l.AdvanceIf(" ")); +} + +TEST(StringLexerTest, PutBack) { + StringLexer l("foo"); + + l.Next(); + l.PutBack(1); + EXPECT_EQ("foo", l.GetUnlexed()); + + l.Next(); + l.Next(); + l.Next(); + l.PutBack(2); + EXPECT_EQ("oo", l.GetUnlexed()); + + l.PutBack(1); + EXPECT_EQ("foo", l.GetUnlexed()); +} + +TEST(StringLexerTest, Peek) { + StringLexer l("foo"); + + EXPECT_EQ('f', l.Peek()); + l.Next(); + EXPECT_EQ('o', l.Peek()); + l.Next(); + EXPECT_EQ('o', l.Peek()); +} + +TEST(StringLexerTest, Next) { + StringLexer l("foo"); + EXPECT_EQ('f', l.Next()); + EXPECT_EQ('o', l.Next()); + EXPECT_EQ('o', l.Next()); +} + +TEST(StringLexerTest, NextIf) { + StringLexer l("foo"); + + EXPECT_FALSE(l.NextIf('\0')); + EXPECT_FALSE(l.NextIf(' ')); + EXPECT_FALSE(l.NextIf('o')); + + EXPECT_TRUE(l.NextIf('f')); + + EXPECT_FALSE(l.NextIf('\0')); + EXPECT_FALSE(l.NextIf(' ')); + EXPECT_FALSE(l.NextIf('f')); + + EXPECT_TRUE(l.NextIf('o')); + + EXPECT_FALSE(l.NextIf('\0')); + EXPECT_FALSE(l.NextIf(' ')); + EXPECT_FALSE(l.NextIf('f')); + + EXPECT_TRUE(l.NextIf('o')); +} + +TEST(StringLexerTest, NextIfList) { + StringLexer l("foo"); + + EXPECT_FALSE(l.NextIf({'\0', ' ', 'o'}).first); + + auto r = l.NextIf({'f'}); + EXPECT_TRUE(r.first); + EXPECT_EQ('f', r.second); + + EXPECT_FALSE(l.NextIf({'\0', ' ', 'f'}).first); + + r = l.NextIf({'f', 'o'}); + EXPECT_TRUE(r.first); + EXPECT_EQ('o', r.second); + + EXPECT_FALSE(l.NextIf({'\0', ' ', 'f'}).first); + + r = l.NextIf({'*', 'f', 'o', 'o'}); + EXPECT_TRUE(r.first); + EXPECT_EQ('o', r.second); +} Index: unittests/Utility/CMakeLists.txt === --- unittests/Utility/CMakeLists.txt +++ unittests/Utility/CMakeLists.txt @@ -16,6 +16,7 @@ StreamTeeTest.cpp StreamTest.cpp StringExtractorTest.cpp + StringLexerTest.cpp StringListTest.cpp StructuredDataTest.cpp TildeExpressionResolverTest.cpp ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits