[Lldb-commits] [PATCH] D50587: Straight forward FastDemangle replacement in SubsPrimitiveParmItanium
JDevlieghere added inline comments. Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:281 llvm::StringRef replace) { - Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); - - const size_t max_len = - mangled.size() + mangled.count(search) * replace.size() + 1; + struct SwapParms { +llvm::StringRef mangled; I had to look at the old code to understand the name of this struct. How about DemangleContext or even just Context? Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:292 + +void Substitude(llvm::StringRef tail) { + if (tail.startswith(search)) { typo: substitute Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:316 + bool err = llvm::itaniumFindTypesInMangledName(mangled.data(), &context, + SwapParms::Hook); + In the other patch you call this argument a callback, maybe do the same here for consistency? https://reviews.llvm.org/D50587 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D49980: [PDB] Parse UDT symbols and pointers to members (combined patch)
aleksandr.urakov added a comment. Unfortunately, there was no people yet, who can review this :) Ping! Can anyone review this, please? https://reviews.llvm.org/D49980 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50587: Straight forward FastDemangle replacement in SubsPrimitiveParmItanium
sgraenitz updated this revision to Diff 160330. sgraenitz added a comment. Address Jonas' comments, fix logging, fix copying over remaining part from original, polishing https://reviews.llvm.org/D50587 Files: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp Index: unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp === --- unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp +++ unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp @@ -183,4 +183,5 @@ EXPECT_THAT(FindAlternate("_ZN1A1fEa"), Contains("_ZN1A1fEc")); EXPECT_THAT(FindAlternate("_ZN1A1fEx"), Contains("_ZN1A1fEl")); EXPECT_THAT(FindAlternate("_ZN1A1fEy"), Contains("_ZN1A1fEm")); + EXPECT_THAT(FindAlternate("_ZN1A1fEai"), Contains("_ZN1A1fEci")); } Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp === --- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -21,6 +21,7 @@ // Other libraries and framework includes #include "llvm/ADT/StringRef.h" +#include "llvm/Demangle/Demangle.h" // Project includes #include "lldb/Core/PluginManager.h" @@ -30,7 +31,6 @@ #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/VectorType.h" #include "lldb/Utility/ConstString.h" -#include "lldb/Utility/FastDemangle.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegularExpression.h" @@ -278,48 +278,67 @@ static ConstString SubsPrimitiveParmItanium(llvm::StringRef mangled, llvm::StringRef search, llvm::StringRef replace) { - Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); - - const size_t max_len = - mangled.size() + mangled.count(search) * replace.size() + 1; - - // Make a temporary buffer to fix up the mangled parameter types and copy the - // original there - std::string output_buf; - output_buf.reserve(max_len); - output_buf.insert(0, mangled.str()); - ptrdiff_t replaced_offset = 0; - - auto swap_parms_hook = [&](const char *parsee) { -if (!parsee || !*parsee) - return; - -// Check whether we've found a substitutee -llvm::StringRef s(parsee); -if (s.startswith(search)) { - // account for the case where a replacement is of a different length to - // the original - replaced_offset += replace.size() - search.size(); - - ptrdiff_t replace_idx = (mangled.size() - s.size()) + replaced_offset; - output_buf.erase(replace_idx, search.size()); - output_buf.insert(replace_idx, replace.str()); + class PrimitiveParmSubs { +llvm::StringRef mangled; +llvm::StringRef search; +llvm::StringRef replace; +ptrdiff_t read_pos; +std::string output; +std::back_insert_iterator writer; + + public: +PrimitiveParmSubs(llvm::StringRef m, llvm::StringRef s, llvm::StringRef r) +: mangled(m), search(s), replace(r), read_pos(0), + writer(std::back_inserter(output)) {} + +void Substitute(llvm::StringRef tail) { + assert(tail.data() >= mangled.data() && + tail.data() < mangled.data() + mangled.size() && + "tail must point into range of mangled"); + + if (tail.startswith(search)) { +auto reader = mangled.begin() + read_pos; +ptrdiff_t read_len = tail.data() - (mangled.data() + read_pos); + +// First write the unmatched part of the original. Then write the +// replacement string. Finally skip the search string in the original. +writer = std::copy(reader, reader + read_len, writer); +writer = std::copy(replace.begin(), replace.end(), writer); +read_pos += read_len + search.size(); + } +} + +ConstString Finalize() { + // If we did a substitution, write the remaining part of the original. + if (read_pos > 0) { +writer = std::copy(mangled.begin() + read_pos, mangled.end(), writer); +read_pos = mangled.size(); + } + + return ConstString(output); +} + +static void Callback(void *context, const char *match) { + ((PrimitiveParmSubs *)context)->Substitute(llvm::StringRef(match)); } }; - // FastDemangle will call our hook for each instance of a primitive type, + // FastDemangle will call back for each instance of a primitive type, // allowing us to perform substitution - char *const demangled = - FastDemangle(mangled.str().c_str(), mangled.size(), swap_parms_hook); - - if (log) -log->Printf("substituted mangling for %s:{%s} %s:{%s}\n", -mangled.str().c_str(), demangled, output_buf.c_str(), -FastDemangle(output_buf.c_str())); - // FastDemangle malloc'd this string. - free(demangled); + PrimitiveParmSubs parmSubs(mangled, search, replace); + assert(
[Lldb-commits] [PATCH] D50587: Straight forward FastDemangle replacement in SubsPrimitiveParmItanium
sgraenitz marked 3 inline comments as done. sgraenitz added inline comments. Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:281 llvm::StringRef replace) { - Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); - - const size_t max_len = - mangled.size() + mangled.count(search) * replace.size() + 1; + struct SwapParms { +llvm::StringRef mangled; JDevlieghere wrote: > I had to look at the old code to understand the name of this struct. How > about DemangleContext or even just Context? Aligned it with the function name Comment at: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp:316 +read_pos = mangled.size(); + } + This was missing. Also added a test. https://reviews.llvm.org/D50587 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50587: Straight forward FastDemangle replacement in SubsPrimitiveParmItanium
JDevlieghere accepted this revision. JDevlieghere added a comment. This revision is now accepted and ready to land. Looks good to me. https://reviews.llvm.org/D50587 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
Re: [Lldb-commits] [PATCH] D49980: [PDB] Parse UDT symbols and pointers to members (combined patch)
Ok I’ll take a look later today then when i get in On Mon, Aug 13, 2018 at 2:13 AM Aleksandr Urakov via Phabricator < revi...@reviews.llvm.org> wrote: > aleksandr.urakov added a comment. > > Unfortunately, there was no people yet, who can review this :) > > Ping! Can anyone review this, please? > > > https://reviews.llvm.org/D49980 > > > > ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D49980: [PDB] Parse UDT symbols and pointers to members (combined patch)
zturner added a comment. Ok I’ll take a look later today then when i get in https://reviews.llvm.org/D49980 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] r339583 - Straight forward FastDemangle replacement in SubsPrimitiveParmItanium
Author: stefan.graenitz Date: Mon Aug 13 09:45:06 2018 New Revision: 339583 URL: http://llvm.org/viewvc/llvm-project?rev=339583&view=rev Log: Straight forward FastDemangle replacement in SubsPrimitiveParmItanium Summary: Removing FastDemangle will greatly reduce maintenance efforts. This patch replaces the last point of use in LLDB. Semantics should be kept intact. Once this is agreed upon, we can: * Remove the FastDemangle sources * Add more features e.g. substitutions in template parameters, considering all variations, etc. Depends on LLVM patch https://reviews.llvm.org/D50586 Reviewers: erik.pilkington, friss, jingham, JDevlieghere Subscribers: kristof.beyls, chrib, lldb-commits Differential Revision: https://reviews.llvm.org/D50587 Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp?rev=339583&r1=339582&r2=339583&view=diff == --- lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp (original) +++ lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp Mon Aug 13 09:45:06 2018 @@ -21,6 +21,7 @@ // Other libraries and framework includes #include "llvm/ADT/StringRef.h" +#include "llvm/Demangle/Demangle.h" // Project includes #include "lldb/Core/PluginManager.h" @@ -30,7 +31,6 @@ #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/VectorType.h" #include "lldb/Utility/ConstString.h" -#include "lldb/Utility/FastDemangle.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegularExpression.h" @@ -278,48 +278,67 @@ bool CPlusPlusLanguage::ExtractContextAn static ConstString SubsPrimitiveParmItanium(llvm::StringRef mangled, llvm::StringRef search, llvm::StringRef replace) { - Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); + class PrimitiveParmSubs { +llvm::StringRef mangled; +llvm::StringRef search; +llvm::StringRef replace; +ptrdiff_t read_pos; +std::string output; +std::back_insert_iterator writer; + + public: +PrimitiveParmSubs(llvm::StringRef m, llvm::StringRef s, llvm::StringRef r) +: mangled(m), search(s), replace(r), read_pos(0), + writer(std::back_inserter(output)) {} + +void Substitute(llvm::StringRef tail) { + assert(tail.data() >= mangled.data() && + tail.data() < mangled.data() + mangled.size() && + "tail must point into range of mangled"); + + if (tail.startswith(search)) { +auto reader = mangled.begin() + read_pos; +ptrdiff_t read_len = tail.data() - (mangled.data() + read_pos); + +// First write the unmatched part of the original. Then write the +// replacement string. Finally skip the search string in the original. +writer = std::copy(reader, reader + read_len, writer); +writer = std::copy(replace.begin(), replace.end(), writer); +read_pos += read_len + search.size(); + } +} - const size_t max_len = - mangled.size() + mangled.count(search) * replace.size() + 1; +ConstString Finalize() { + // If we did a substitution, write the remaining part of the original. + if (read_pos > 0) { +writer = std::copy(mangled.begin() + read_pos, mangled.end(), writer); +read_pos = mangled.size(); + } - // Make a temporary buffer to fix up the mangled parameter types and copy the - // original there - std::string output_buf; - output_buf.reserve(max_len); - output_buf.insert(0, mangled.str()); - ptrdiff_t replaced_offset = 0; - - auto swap_parms_hook = [&](const char *parsee) { -if (!parsee || !*parsee) - return; - -// Check whether we've found a substitutee -llvm::StringRef s(parsee); -if (s.startswith(search)) { - // account for the case where a replacement is of a different length to - // the original - replaced_offset += replace.size() - search.size(); - - ptrdiff_t replace_idx = (mangled.size() - s.size()) + replaced_offset; - output_buf.erase(replace_idx, search.size()); - output_buf.insert(replace_idx, replace.str()); + return ConstString(output); +} + +static void Callback(void *context, const char *match) { + ((PrimitiveParmSubs *)context)->Substitute(llvm::StringRef(match)); } }; - // FastDemangle will call our hook for each instance of a primitive type, + // FastDemangle will call back for each instance of a primitive type, // allowing us to perform substitution - char *const demangled = - FastDemangle(mangled.str().c_str(), mangled.size(), swap_parms_hook); - - if (log) -
[Lldb-commits] [PATCH] D50587: Straight forward FastDemangle replacement in SubsPrimitiveParmItanium
This revision was automatically updated to reflect the committed changes. Closed by commit rL339583: Straight forward FastDemangle replacement in SubsPrimitiveParmItanium (authored by stefan.graenitz, committed by ). Herald added a subscriber: llvm-commits. Repository: rL LLVM https://reviews.llvm.org/D50587 Files: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp Index: lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp === --- lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp +++ lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp @@ -183,4 +183,5 @@ EXPECT_THAT(FindAlternate("_ZN1A1fEa"), Contains("_ZN1A1fEc")); EXPECT_THAT(FindAlternate("_ZN1A1fEx"), Contains("_ZN1A1fEl")); EXPECT_THAT(FindAlternate("_ZN1A1fEy"), Contains("_ZN1A1fEm")); + EXPECT_THAT(FindAlternate("_ZN1A1fEai"), Contains("_ZN1A1fEci")); } Index: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp === --- lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -21,6 +21,7 @@ // Other libraries and framework includes #include "llvm/ADT/StringRef.h" +#include "llvm/Demangle/Demangle.h" // Project includes #include "lldb/Core/PluginManager.h" @@ -30,7 +31,6 @@ #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/DataFormatters/VectorType.h" #include "lldb/Utility/ConstString.h" -#include "lldb/Utility/FastDemangle.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegularExpression.h" @@ -278,48 +278,67 @@ static ConstString SubsPrimitiveParmItanium(llvm::StringRef mangled, llvm::StringRef search, llvm::StringRef replace) { - Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); + class PrimitiveParmSubs { +llvm::StringRef mangled; +llvm::StringRef search; +llvm::StringRef replace; +ptrdiff_t read_pos; +std::string output; +std::back_insert_iterator writer; - const size_t max_len = - mangled.size() + mangled.count(search) * replace.size() + 1; + public: +PrimitiveParmSubs(llvm::StringRef m, llvm::StringRef s, llvm::StringRef r) +: mangled(m), search(s), replace(r), read_pos(0), + writer(std::back_inserter(output)) {} + +void Substitute(llvm::StringRef tail) { + assert(tail.data() >= mangled.data() && + tail.data() < mangled.data() + mangled.size() && + "tail must point into range of mangled"); + + if (tail.startswith(search)) { +auto reader = mangled.begin() + read_pos; +ptrdiff_t read_len = tail.data() - (mangled.data() + read_pos); + +// First write the unmatched part of the original. Then write the +// replacement string. Finally skip the search string in the original. +writer = std::copy(reader, reader + read_len, writer); +writer = std::copy(replace.begin(), replace.end(), writer); +read_pos += read_len + search.size(); + } +} + +ConstString Finalize() { + // If we did a substitution, write the remaining part of the original. + if (read_pos > 0) { +writer = std::copy(mangled.begin() + read_pos, mangled.end(), writer); +read_pos = mangled.size(); + } - // Make a temporary buffer to fix up the mangled parameter types and copy the - // original there - std::string output_buf; - output_buf.reserve(max_len); - output_buf.insert(0, mangled.str()); - ptrdiff_t replaced_offset = 0; - - auto swap_parms_hook = [&](const char *parsee) { -if (!parsee || !*parsee) - return; - -// Check whether we've found a substitutee -llvm::StringRef s(parsee); -if (s.startswith(search)) { - // account for the case where a replacement is of a different length to - // the original - replaced_offset += replace.size() - search.size(); - - ptrdiff_t replace_idx = (mangled.size() - s.size()) + replaced_offset; - output_buf.erase(replace_idx, search.size()); - output_buf.insert(replace_idx, replace.str()); + return ConstString(output); +} + +static void Callback(void *context, const char *match) { + ((PrimitiveParmSubs *)context)->Substitute(llvm::StringRef(match)); } }; - // FastDemangle will call our hook for each instance of a primitive type, + // FastDemangle will call back for each instance of a primitive type, // allowing us to perform substitution - char *const demangled = - FastDemangle(mangled.str().c_str(), mangled.size(), swap_parms_hook); - - if (log) -log->Printf("substituted mangling for %s:{%s} %s:{%s}\n", -mangled.str().c_str(), demangled, output_
[Lldb-commits] [PATCH] D50620: Added test for Core/Range class.
vsk accepted this revision. vsk added a comment. This revision is now accepted and ready to land. Thanks, looks good with nitpicks. Comment at: unittests/Core/RangeTest.cpp:139 + RangeT r; + // FIXME: This is probably not intended. + EXPECT_TRUE(r.ContainsEndInclusive(0)); Yeah, this looks wrong. Comment at: unittests/Core/RangeTest.cpp:177 + EXPECT_TRUE(r.Contains(RangeT(3, 0))); + EXPECT_TRUE(r.Contains(RangeT(4, 0))); + EXPECT_FALSE(r.Contains(RangeT(8, 0))); Yep, the first two results are at least inconsistent with the third, and look wrong to me. Comment at: unittests/Core/RangeTest.cpp:250 + +// For less than, we should +TEST(RangeTest, LessThan) { Drop this comment? Comment at: unittests/Core/RangeTest.cpp:253 + RangeT r(10, 20); + + // Equal range. Might help to have a helper lambda here, like `expectOrderedLessThan = [](r1, r2) { expect_true(r1 < r2); expect_false(r2 < r1); }`. https://reviews.llvm.org/D50620 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50620: Added test for Core/Range class.
teemperor updated this revision to Diff 160439. teemperor added a comment. - Addressed Vedant's comments (thanks!) https://reviews.llvm.org/D50620 Files: unittests/Core/CMakeLists.txt unittests/Core/RangeTest.cpp Index: unittests/Core/RangeTest.cpp === --- /dev/null +++ unittests/Core/RangeTest.cpp @@ -0,0 +1,330 @@ +//===-- RangeTest.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/Core/RangeMap.h" + +#include +#include + +#include "gtest/gtest.h" + +using namespace lldb; +using namespace lldb_private; + +TEST(RangeTest, SizeTypes) { + Range r; + static_assert(std::is_same::value, +"RangeBase type is not equal to the given one."); + static_assert(std::is_same::value, +"RangeEnd type is not equal to the given one."); + static_assert(std::is_same::value, +"Size type is not equal to the given one."); +} + +typedef Range RangeT; + +TEST(RangeTest, DefaultConstructor) { + RangeT r; + EXPECT_FALSE(r.IsValid()); + EXPECT_EQ(0U, r.GetByteSize()); + EXPECT_EQ(0U, r.GetRangeBase()); + EXPECT_EQ(0U, r.GetRangeEnd()); +} + +TEST(RangeTest, Constructor) { + RangeT r(3, 5); + EXPECT_TRUE(r.IsValid()); + EXPECT_EQ(5U, r.GetByteSize()); + EXPECT_EQ(3U, r.GetRangeBase()); + EXPECT_EQ(8U, r.GetRangeEnd()); +} + +TEST(RangeTest, Copy) { + RangeT orig(3, 5); + RangeT r = orig; + EXPECT_TRUE(r.IsValid()); + EXPECT_EQ(5U, r.GetByteSize()); + EXPECT_EQ(3U, r.GetRangeBase()); + EXPECT_EQ(8U, r.GetRangeEnd()); +} + +TEST(RangeTest, Clear) { + RangeT r(3, 5); + r.Clear(); + EXPECT_TRUE(r == RangeT()); +} + +TEST(RangeTest, ClearWithStarAddress) { + RangeT r(3, 5); + r.Clear(4); + EXPECT_TRUE(r == RangeT(4, 0)); +} + +TEST(RangeTest, SetRangeBase) { + RangeT r(3, 5); + r.SetRangeBase(6); + EXPECT_EQ(6U, r.GetRangeBase()); + EXPECT_EQ(11U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); +} + +TEST(RangeTest, Slide) { + RangeT r(3, 5); + r.Slide(1); + EXPECT_EQ(4U, r.GetRangeBase()); + EXPECT_EQ(9U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); + + r.Slide(2); + EXPECT_EQ(6U, r.GetRangeBase()); + EXPECT_EQ(11U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); +} + +TEST(RangeTest, SlideZero) { + RangeT r(3, 5); + r.Slide(0); + EXPECT_EQ(3U, r.GetRangeBase()); + EXPECT_EQ(8U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); +} + +TEST(RangeTest, ContainsAddr) { + RangeT r(3, 5); + EXPECT_FALSE(r.Contains(0)); + EXPECT_FALSE(r.Contains(1)); + EXPECT_FALSE(r.Contains(2)); + EXPECT_TRUE(r.Contains(3)); + EXPECT_TRUE(r.Contains(4)); + EXPECT_TRUE(r.Contains(5)); + EXPECT_TRUE(r.Contains(6)); + EXPECT_TRUE(r.Contains(7)); + EXPECT_FALSE(r.Contains(8)); + EXPECT_FALSE(r.Contains(9)); + EXPECT_FALSE(r.Contains(10)); +} + +TEST(RangeTest, ContainsAddrInvalid) { + RangeT r; + EXPECT_FALSE(r.Contains(0)); + EXPECT_FALSE(r.Contains(1)); + EXPECT_FALSE(r.Contains(2)); + EXPECT_FALSE(r.Contains(3)); + EXPECT_FALSE(r.Contains(4)); +} + +TEST(RangeTest, ContainsEndInclusive) { + RangeT r(3, 5); + EXPECT_FALSE(r.ContainsEndInclusive(0)); + EXPECT_FALSE(r.ContainsEndInclusive(1)); + EXPECT_FALSE(r.ContainsEndInclusive(2)); + EXPECT_TRUE(r.ContainsEndInclusive(3)); + EXPECT_TRUE(r.ContainsEndInclusive(4)); + EXPECT_TRUE(r.ContainsEndInclusive(5)); + EXPECT_TRUE(r.ContainsEndInclusive(6)); + EXPECT_TRUE(r.ContainsEndInclusive(7)); + EXPECT_TRUE(r.ContainsEndInclusive(8)); + EXPECT_FALSE(r.ContainsEndInclusive(9)); + EXPECT_FALSE(r.ContainsEndInclusive(10)); +} + +TEST(RangeTest, ContainsEndInclusiveInvalid) { + RangeT r; + // FIXME: This is probably not intended. + EXPECT_TRUE(r.ContainsEndInclusive(0)); + + EXPECT_FALSE(r.ContainsEndInclusive(1)); + EXPECT_FALSE(r.ContainsEndInclusive(2)); +} + +TEST(RangeTest, ContainsRange) { + RangeT r(3, 5); + + // Range always contains itself. + EXPECT_TRUE(r.Contains(r)); + // Invalid range. + EXPECT_FALSE(r.Contains(RangeT())); + // Range starts and ends before. + EXPECT_FALSE(r.Contains(RangeT(0, 3))); + // Range starts before but contains beginning. + EXPECT_FALSE(r.Contains(RangeT(0, 4))); + // Range starts before but contains beginning and more. + EXPECT_FALSE(r.Contains(RangeT(0, 5))); + // Range starts before and contains the other. + EXPECT_FALSE(r.Contains(RangeT(0, 9))); + // Range is fully inside. + EXPECT_TRUE(r.Contains(RangeT(4, 3))); + // Range has same start, but not as large. + EXPECT_TRUE(r.Contains(RangeT(3, 4))); + // Range has same end, but starts earlier. + EXPECT_TRUE(r.Contains(RangeT(4, 4))); + // Range starts inside, but stops after the end of r. + EXPECT_FALSE(
[Lldb-commits] [lldb] r339611 - Added test for Core/Range class.
Author: teemperor Date: Mon Aug 13 13:43:06 2018 New Revision: 339611 URL: http://llvm.org/viewvc/llvm-project?rev=339611&view=rev Log: Added test for Core/Range class. Summary: We can optimize and refactor some of the classes in RangeMap.h, but first we should have some tests for all the data structures in there. This adds a first batch of tests for the Range class itself. There are some unexpected results happening when mixing invalid and valid ranges, so I added some FIXME's for that in the tests. Reviewers: vsk Reviewed By: vsk Subscribers: mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D50620 Added: lldb/trunk/unittests/Core/RangeTest.cpp Modified: lldb/trunk/unittests/Core/CMakeLists.txt Modified: lldb/trunk/unittests/Core/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/CMakeLists.txt?rev=339611&r1=339610&r2=339611&view=diff == --- lldb/trunk/unittests/Core/CMakeLists.txt (original) +++ lldb/trunk/unittests/Core/CMakeLists.txt Mon Aug 13 13:43:06 2018 @@ -4,6 +4,7 @@ add_lldb_unittest(LLDBCoreTests EventTest.cpp ListenerTest.cpp MangledTest.cpp + RangeTest.cpp RichManglingContextTest.cpp StreamCallbackTest.cpp Added: lldb/trunk/unittests/Core/RangeTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/RangeTest.cpp?rev=339611&view=auto == --- lldb/trunk/unittests/Core/RangeTest.cpp (added) +++ lldb/trunk/unittests/Core/RangeTest.cpp Mon Aug 13 13:43:06 2018 @@ -0,0 +1,330 @@ +//===-- RangeTest.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/Core/RangeMap.h" + +#include +#include + +#include "gtest/gtest.h" + +using namespace lldb; +using namespace lldb_private; + +TEST(RangeTest, SizeTypes) { + Range r; + static_assert(std::is_same::value, +"RangeBase type is not equal to the given one."); + static_assert(std::is_same::value, +"RangeEnd type is not equal to the given one."); + static_assert(std::is_same::value, +"Size type is not equal to the given one."); +} + +typedef Range RangeT; + +TEST(RangeTest, DefaultConstructor) { + RangeT r; + EXPECT_FALSE(r.IsValid()); + EXPECT_EQ(0U, r.GetByteSize()); + EXPECT_EQ(0U, r.GetRangeBase()); + EXPECT_EQ(0U, r.GetRangeEnd()); +} + +TEST(RangeTest, Constructor) { + RangeT r(3, 5); + EXPECT_TRUE(r.IsValid()); + EXPECT_EQ(5U, r.GetByteSize()); + EXPECT_EQ(3U, r.GetRangeBase()); + EXPECT_EQ(8U, r.GetRangeEnd()); +} + +TEST(RangeTest, Copy) { + RangeT orig(3, 5); + RangeT r = orig; + EXPECT_TRUE(r.IsValid()); + EXPECT_EQ(5U, r.GetByteSize()); + EXPECT_EQ(3U, r.GetRangeBase()); + EXPECT_EQ(8U, r.GetRangeEnd()); +} + +TEST(RangeTest, Clear) { + RangeT r(3, 5); + r.Clear(); + EXPECT_TRUE(r == RangeT()); +} + +TEST(RangeTest, ClearWithStarAddress) { + RangeT r(3, 5); + r.Clear(4); + EXPECT_TRUE(r == RangeT(4, 0)); +} + +TEST(RangeTest, SetRangeBase) { + RangeT r(3, 5); + r.SetRangeBase(6); + EXPECT_EQ(6U, r.GetRangeBase()); + EXPECT_EQ(11U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); +} + +TEST(RangeTest, Slide) { + RangeT r(3, 5); + r.Slide(1); + EXPECT_EQ(4U, r.GetRangeBase()); + EXPECT_EQ(9U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); + + r.Slide(2); + EXPECT_EQ(6U, r.GetRangeBase()); + EXPECT_EQ(11U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); +} + +TEST(RangeTest, SlideZero) { + RangeT r(3, 5); + r.Slide(0); + EXPECT_EQ(3U, r.GetRangeBase()); + EXPECT_EQ(8U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); +} + +TEST(RangeTest, ContainsAddr) { + RangeT r(3, 5); + EXPECT_FALSE(r.Contains(0)); + EXPECT_FALSE(r.Contains(1)); + EXPECT_FALSE(r.Contains(2)); + EXPECT_TRUE(r.Contains(3)); + EXPECT_TRUE(r.Contains(4)); + EXPECT_TRUE(r.Contains(5)); + EXPECT_TRUE(r.Contains(6)); + EXPECT_TRUE(r.Contains(7)); + EXPECT_FALSE(r.Contains(8)); + EXPECT_FALSE(r.Contains(9)); + EXPECT_FALSE(r.Contains(10)); +} + +TEST(RangeTest, ContainsAddrInvalid) { + RangeT r; + EXPECT_FALSE(r.Contains(0)); + EXPECT_FALSE(r.Contains(1)); + EXPECT_FALSE(r.Contains(2)); + EXPECT_FALSE(r.Contains(3)); + EXPECT_FALSE(r.Contains(4)); +} + +TEST(RangeTest, ContainsEndInclusive) { + RangeT r(3, 5); + EXPECT_FALSE(r.ContainsEndInclusive(0)); + EXPECT_FALSE(r.ContainsEndInclusive(1)); + EXPECT_FALSE(r.ContainsEndInclusive(2)); + EXPECT_TRUE(r.ContainsEndInclusive(3)); + EXPECT_TRUE(r.ContainsEndInclusive(4)); + EXPECT_TRUE(r.ContainsEndInclusive(5)); + EXPECT_TRUE(r.ContainsEndInclusive(6)); + EXPECT_
[Lldb-commits] [PATCH] D50620: Added test for Core/Range class.
This revision was automatically updated to reflect the committed changes. Closed by commit rL339611: Added test for Core/Range class. (authored by teemperor, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D50620?vs=160439&id=160441#toc Repository: rL LLVM https://reviews.llvm.org/D50620 Files: lldb/trunk/unittests/Core/CMakeLists.txt lldb/trunk/unittests/Core/RangeTest.cpp Index: lldb/trunk/unittests/Core/RangeTest.cpp === --- lldb/trunk/unittests/Core/RangeTest.cpp +++ lldb/trunk/unittests/Core/RangeTest.cpp @@ -0,0 +1,330 @@ +//===-- RangeTest.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/Core/RangeMap.h" + +#include +#include + +#include "gtest/gtest.h" + +using namespace lldb; +using namespace lldb_private; + +TEST(RangeTest, SizeTypes) { + Range r; + static_assert(std::is_same::value, +"RangeBase type is not equal to the given one."); + static_assert(std::is_same::value, +"RangeEnd type is not equal to the given one."); + static_assert(std::is_same::value, +"Size type is not equal to the given one."); +} + +typedef Range RangeT; + +TEST(RangeTest, DefaultConstructor) { + RangeT r; + EXPECT_FALSE(r.IsValid()); + EXPECT_EQ(0U, r.GetByteSize()); + EXPECT_EQ(0U, r.GetRangeBase()); + EXPECT_EQ(0U, r.GetRangeEnd()); +} + +TEST(RangeTest, Constructor) { + RangeT r(3, 5); + EXPECT_TRUE(r.IsValid()); + EXPECT_EQ(5U, r.GetByteSize()); + EXPECT_EQ(3U, r.GetRangeBase()); + EXPECT_EQ(8U, r.GetRangeEnd()); +} + +TEST(RangeTest, Copy) { + RangeT orig(3, 5); + RangeT r = orig; + EXPECT_TRUE(r.IsValid()); + EXPECT_EQ(5U, r.GetByteSize()); + EXPECT_EQ(3U, r.GetRangeBase()); + EXPECT_EQ(8U, r.GetRangeEnd()); +} + +TEST(RangeTest, Clear) { + RangeT r(3, 5); + r.Clear(); + EXPECT_TRUE(r == RangeT()); +} + +TEST(RangeTest, ClearWithStarAddress) { + RangeT r(3, 5); + r.Clear(4); + EXPECT_TRUE(r == RangeT(4, 0)); +} + +TEST(RangeTest, SetRangeBase) { + RangeT r(3, 5); + r.SetRangeBase(6); + EXPECT_EQ(6U, r.GetRangeBase()); + EXPECT_EQ(11U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); +} + +TEST(RangeTest, Slide) { + RangeT r(3, 5); + r.Slide(1); + EXPECT_EQ(4U, r.GetRangeBase()); + EXPECT_EQ(9U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); + + r.Slide(2); + EXPECT_EQ(6U, r.GetRangeBase()); + EXPECT_EQ(11U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); +} + +TEST(RangeTest, SlideZero) { + RangeT r(3, 5); + r.Slide(0); + EXPECT_EQ(3U, r.GetRangeBase()); + EXPECT_EQ(8U, r.GetRangeEnd()); + EXPECT_EQ(5U, r.GetByteSize()); +} + +TEST(RangeTest, ContainsAddr) { + RangeT r(3, 5); + EXPECT_FALSE(r.Contains(0)); + EXPECT_FALSE(r.Contains(1)); + EXPECT_FALSE(r.Contains(2)); + EXPECT_TRUE(r.Contains(3)); + EXPECT_TRUE(r.Contains(4)); + EXPECT_TRUE(r.Contains(5)); + EXPECT_TRUE(r.Contains(6)); + EXPECT_TRUE(r.Contains(7)); + EXPECT_FALSE(r.Contains(8)); + EXPECT_FALSE(r.Contains(9)); + EXPECT_FALSE(r.Contains(10)); +} + +TEST(RangeTest, ContainsAddrInvalid) { + RangeT r; + EXPECT_FALSE(r.Contains(0)); + EXPECT_FALSE(r.Contains(1)); + EXPECT_FALSE(r.Contains(2)); + EXPECT_FALSE(r.Contains(3)); + EXPECT_FALSE(r.Contains(4)); +} + +TEST(RangeTest, ContainsEndInclusive) { + RangeT r(3, 5); + EXPECT_FALSE(r.ContainsEndInclusive(0)); + EXPECT_FALSE(r.ContainsEndInclusive(1)); + EXPECT_FALSE(r.ContainsEndInclusive(2)); + EXPECT_TRUE(r.ContainsEndInclusive(3)); + EXPECT_TRUE(r.ContainsEndInclusive(4)); + EXPECT_TRUE(r.ContainsEndInclusive(5)); + EXPECT_TRUE(r.ContainsEndInclusive(6)); + EXPECT_TRUE(r.ContainsEndInclusive(7)); + EXPECT_TRUE(r.ContainsEndInclusive(8)); + EXPECT_FALSE(r.ContainsEndInclusive(9)); + EXPECT_FALSE(r.ContainsEndInclusive(10)); +} + +TEST(RangeTest, ContainsEndInclusiveInvalid) { + RangeT r; + // FIXME: This is probably not intended. + EXPECT_TRUE(r.ContainsEndInclusive(0)); + + EXPECT_FALSE(r.ContainsEndInclusive(1)); + EXPECT_FALSE(r.ContainsEndInclusive(2)); +} + +TEST(RangeTest, ContainsRange) { + RangeT r(3, 5); + + // Range always contains itself. + EXPECT_TRUE(r.Contains(r)); + // Invalid range. + EXPECT_FALSE(r.Contains(RangeT())); + // Range starts and ends before. + EXPECT_FALSE(r.Contains(RangeT(0, 3))); + // Range starts before but contains beginning. + EXPECT_FALSE(r.Contains(RangeT(0, 4))); + // Range starts before but contains beginning and more. + EXPECT_FALSE(r.Contains(RangeT(0, 5))); + // Range starts before and contains the other. + EXPECT_FALSE(r.Contains(RangeT(0, 9))); + // Range is fully inside. + EXPECT_T
[Lldb-commits] [lldb] r339615 - Update TestTargetXMLArch.py test for llvm triple change with unspecified
Author: jmolenda Date: Mon Aug 13 14:20:29 2018 New Revision: 339615 URL: http://llvm.org/viewvc/llvm-project?rev=339615&view=rev Log: Update TestTargetXMLArch.py test for llvm triple change with unspecified components in r339294. Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestTargetXMLArch.py Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestTargetXMLArch.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestTargetXMLArch.py?rev=339615&r1=339614&r2=339615&view=diff == --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestTargetXMLArch.py (original) +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestTargetXMLArch.py Mon Aug 13 14:20:29 2018 @@ -121,4 +121,4 @@ class TestTargetXMLArch(GDBRemoteTestBas if self.TraceOn(): interp.HandleCommand("target list", result) print(result.GetOutput()) -self.assertTrue(target.GetTriple().startswith('x86_64--')) + self.assertTrue(target.GetTriple().startswith('x86_64-unknown-unknown')) ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50536: Fix: ConstString::GetConstCStringAndSetMangledCounterPart() should update the value if the key exists already
jingham accepted this revision. jingham added a comment. This revision is now accepted and ready to land. This looks fine to me. https://reviews.llvm.org/D50536 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50365: Add a new tool named "lldb-vscode" that implements the Visual Studio Code Debug Adaptor Protocol
clayborg updated this revision to Diff 160466. clayborg added a comment. Herald added subscribers: jfb, srhines. - Use the LLVM JSON parser - Split lldb-vscode.cpp into smaller files - Fix function names - ran clang format on everything https://reviews.llvm.org/D50365 Files: lldb.xcodeproj/project.pbxproj packages/Python/lldbsuite/test/dotest.py packages/Python/lldbsuite/test/lldbtest.py packages/Python/lldbsuite/test/tools/lldb-vscode/.categories packages/Python/lldbsuite/test/tools/lldb-vscode/attach/Makefile packages/Python/lldbsuite/test/tools/lldb-vscode/attach/TestVSCode_attach.py packages/Python/lldbsuite/test/tools/lldb-vscode/attach/main.c packages/Python/lldbsuite/test/tools/lldb-vscode/breakpoint/Makefile packages/Python/lldbsuite/test/tools/lldb-vscode/breakpoint/TestVSCode_setBreakpoints.py packages/Python/lldbsuite/test/tools/lldb-vscode/breakpoint/TestVSCode_setExceptionBreakpoints.py packages/Python/lldbsuite/test/tools/lldb-vscode/breakpoint/TestVSCode_setFunctionBreakpoints.py packages/Python/lldbsuite/test/tools/lldb-vscode/breakpoint/main.cpp packages/Python/lldbsuite/test/tools/lldb-vscode/launch/Makefile packages/Python/lldbsuite/test/tools/lldb-vscode/launch/TestVSCode_launch.py packages/Python/lldbsuite/test/tools/lldb-vscode/launch/main.c packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py packages/Python/lldbsuite/test/tools/lldb-vscode/stackTrace/Makefile packages/Python/lldbsuite/test/tools/lldb-vscode/stackTrace/TestVSCode_stackTrace.py packages/Python/lldbsuite/test/tools/lldb-vscode/stackTrace/main.c packages/Python/lldbsuite/test/tools/lldb-vscode/step/Makefile packages/Python/lldbsuite/test/tools/lldb-vscode/step/TestVSCode_step.py packages/Python/lldbsuite/test/tools/lldb-vscode/step/main.cpp packages/Python/lldbsuite/test/tools/lldb-vscode/variables/Makefile packages/Python/lldbsuite/test/tools/lldb-vscode/variables/TestVSCode_variables.py packages/Python/lldbsuite/test/tools/lldb-vscode/variables/main.cpp packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py tools/CMakeLists.txt tools/lldb-vscode/BreakpointBase.cpp tools/lldb-vscode/BreakpointBase.h tools/lldb-vscode/CMakeLists.txt tools/lldb-vscode/ExceptionBreakpoint.cpp tools/lldb-vscode/ExceptionBreakpoint.h tools/lldb-vscode/FunctionBreakpoint.cpp tools/lldb-vscode/FunctionBreakpoint.h tools/lldb-vscode/JSONUtils.cpp tools/lldb-vscode/JSONUtils.h tools/lldb-vscode/LLDBUtils.cpp tools/lldb-vscode/LLDBUtils.h tools/lldb-vscode/README.txt tools/lldb-vscode/SourceBreakpoint.cpp tools/lldb-vscode/SourceBreakpoint.h tools/lldb-vscode/SourceReference.h tools/lldb-vscode/VSCode.cpp tools/lldb-vscode/VSCode.h tools/lldb-vscode/VSCodeForward.h tools/lldb-vscode/lldb-vscode-Info.plist tools/lldb-vscode/lldb-vscode.cpp tools/lldb-vscode/package.json ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50676: Remove manual byte counting from Highlighter code.
teemperor created this revision. This removes the manual byte counting mechanism from the syntax highlighting code. This is no longer necessary as the Stream class now has built-in support for automatically counting the bytes that were written to it so far. The advantage of automatic byte counting via Stream is that it is less error-prone than the manual version and we need to write less boilerplate code. Repository: rLLDB LLDB https://reviews.llvm.org/D50676 Files: include/lldb/Core/Highlighter.h source/Core/Highlighter.cpp source/Core/SourceManager.cpp source/Plugins/Language/ClangCommon/ClangHighlighter.cpp source/Plugins/Language/ClangCommon/ClangHighlighter.h Index: source/Plugins/Language/ClangCommon/ClangHighlighter.h === --- source/Plugins/Language/ClangCommon/ClangHighlighter.h +++ source/Plugins/Language/ClangCommon/ClangHighlighter.h @@ -28,9 +28,8 @@ ClangHighlighter(); llvm::StringRef GetName() const override { return "clang"; } - std::size_t Highlight(const HighlightStyle &options, llvm::StringRef line, -llvm::StringRef previous_lines, -Stream &s) const override; + void Highlight(const HighlightStyle &options, llvm::StringRef line, + llvm::StringRef previous_lines, Stream &s) const override; /// Returns true if the given string represents a keywords in any Clang /// supported language. Index: source/Plugins/Language/ClangCommon/ClangHighlighter.cpp === --- source/Plugins/Language/ClangCommon/ClangHighlighter.cpp +++ source/Plugins/Language/ClangCommon/ClangHighlighter.cpp @@ -128,14 +128,12 @@ return HighlightStyle::ColorStyle(); } -std::size_t ClangHighlighter::Highlight(const HighlightStyle &options, -llvm::StringRef line, -llvm::StringRef previous_lines, -Stream &result) const { +void ClangHighlighter::Highlight(const HighlightStyle &options, + llvm::StringRef line, + llvm::StringRef previous_lines, + Stream &result) const { using namespace clang; - std::size_t written_bytes = 0; - FileSystemOptions file_opts; FileManager file_mgr(file_opts); @@ -210,18 +208,15 @@ HighlightStyle::ColorStyle color = determineClangStyle(*this, token, tok_str, options, in_pp_directive); -written_bytes += color.Apply(result, tok_str); +color.Apply(result, tok_str); } // If we went over the whole file but couldn't find our own file, then // somehow our setup was wrong. When we're in release mode we just give the // user the normal line and pretend we don't know how to highlight it. In // debug mode we bail out with an assert as this should never happen. if (!found_user_line) { result << line; -written_bytes += line.size(); assert(false && "We couldn't find the user line in the input file?"); } - - return written_bytes; } Index: source/Core/SourceManager.cpp === --- source/Core/SourceManager.cpp +++ source/Core/SourceManager.cpp @@ -533,6 +533,8 @@ if (!m_data_sp) return 0; + size_t bytes_written = s->GetWrittenBytes(); + std::string previous_content; HighlightStyle style = HighlightStyle::MakeVimStyle(); @@ -553,7 +555,6 @@ end_line_offset = m_data_sp->GetByteSize(); assert(start_line_offset <= end_line_offset); -size_t bytes_written = 0; if (start_line_offset < end_line_offset) { size_t count = end_line_offset - start_line_offset; const uint8_t *cstr = m_data_sp->GetBytes() + start_line_offset; @@ -563,8 +564,7 @@ auto debugger_sp = m_debugger_wp.lock(); if (should_highlight_source(debugger_sp)) { -bytes_written += -highlighter.Highlight(style, ref, previous_content, *s); +highlighter.Highlight(style, ref, previous_content, *s); displayed_line = true; // Add the new line to the previous lines. previous_content += ref.str(); @@ -586,7 +586,7 @@ // formatting the column (e.g. underline, inverse, etc.) // First print the part before the column to mark. -bytes_written = s->Write(cstr, column - 1); +s->Write(cstr, column - 1); // Write the pre escape sequence. const SymbolContext *sc = nullptr; @@ -599,15 +599,14 @@ FormatEntity::Format(*ansi_prefix_entry, *s, sc, exe_ctx, &addr, valobj, function_changed, initial_function); -// Write the marked column. -bytes_written += s->Write(cstr + column - 1, 1); +s->Write(cstr + column - 1, 1);
[Lldb-commits] [PATCH] D50677: Remove manual byte counting from Opcode::Dump
teemperor created this revision. teemperor added a reviewer: clayborg. Stream now has byte-counting functionality, so let's use this instead of manual byte counting. Repository: rLLDB LLDB https://reviews.llvm.org/D50677 Files: source/Core/Opcode.cpp Index: source/Core/Opcode.cpp === --- source/Core/Opcode.cpp +++ source/Core/Opcode.cpp @@ -23,40 +23,41 @@ using namespace lldb_private; int Opcode::Dump(Stream *s, uint32_t min_byte_width) { - int bytes_written = 0; + const uint32_t previous_bytes = s->GetWrittenBytes(); switch (m_type) { case Opcode::eTypeInvalid: -bytes_written = s->PutCString(""); +s->PutCString(""); break; case Opcode::eType8: -bytes_written = s->Printf("0x%2.2x", m_data.inst8); +s->Printf("0x%2.2x", m_data.inst8); break; case Opcode::eType16: -bytes_written = s->Printf("0x%4.4x", m_data.inst16); +s->Printf("0x%4.4x", m_data.inst16); break; case Opcode::eType16_2: case Opcode::eType32: -bytes_written = s->Printf("0x%8.8x", m_data.inst32); +s->Printf("0x%8.8x", m_data.inst32); break; case Opcode::eType64: -bytes_written = s->Printf("0x%16.16" PRIx64, m_data.inst64); +s->Printf("0x%16.16" PRIx64, m_data.inst64); break; case Opcode::eTypeBytes: for (uint32_t i = 0; i < m_data.inst.length; ++i) { if (i > 0) -bytes_written += s->PutChar(' '); - bytes_written += s->Printf("%2.2x", m_data.inst.bytes[i]); +s->PutChar(' '); + s->Printf("%2.2x", m_data.inst.bytes[i]); } break; } - // Add spaces to make sure bytes dispay comes out even in case opcodes aren't - // all the same size - if (static_cast(bytes_written) < min_byte_width) -bytes_written = s->Printf("%*s", min_byte_width - bytes_written, ""); - return bytes_written; + uint32_t bytes_written_so_far = s->GetWrittenBytes() - previous_bytes; + // Add spaces to make sure bytes display comes out even in case opcodes aren't + // all the same size. + if (bytes_written_so_far < min_byte_width) +s->Printf("%*s", min_byte_width - bytes_written_so_far, ""); + return s->GetWrittenBytes() - previous_bytes; } lldb::ByteOrder Opcode::GetDataByteOrder() const { Index: source/Core/Opcode.cpp === --- source/Core/Opcode.cpp +++ source/Core/Opcode.cpp @@ -23,40 +23,41 @@ using namespace lldb_private; int Opcode::Dump(Stream *s, uint32_t min_byte_width) { - int bytes_written = 0; + const uint32_t previous_bytes = s->GetWrittenBytes(); switch (m_type) { case Opcode::eTypeInvalid: -bytes_written = s->PutCString(""); +s->PutCString(""); break; case Opcode::eType8: -bytes_written = s->Printf("0x%2.2x", m_data.inst8); +s->Printf("0x%2.2x", m_data.inst8); break; case Opcode::eType16: -bytes_written = s->Printf("0x%4.4x", m_data.inst16); +s->Printf("0x%4.4x", m_data.inst16); break; case Opcode::eType16_2: case Opcode::eType32: -bytes_written = s->Printf("0x%8.8x", m_data.inst32); +s->Printf("0x%8.8x", m_data.inst32); break; case Opcode::eType64: -bytes_written = s->Printf("0x%16.16" PRIx64, m_data.inst64); +s->Printf("0x%16.16" PRIx64, m_data.inst64); break; case Opcode::eTypeBytes: for (uint32_t i = 0; i < m_data.inst.length; ++i) { if (i > 0) -bytes_written += s->PutChar(' '); - bytes_written += s->Printf("%2.2x", m_data.inst.bytes[i]); +s->PutChar(' '); + s->Printf("%2.2x", m_data.inst.bytes[i]); } break; } - // Add spaces to make sure bytes dispay comes out even in case opcodes aren't - // all the same size - if (static_cast(bytes_written) < min_byte_width) -bytes_written = s->Printf("%*s", min_byte_width - bytes_written, ""); - return bytes_written; + uint32_t bytes_written_so_far = s->GetWrittenBytes() - previous_bytes; + // Add spaces to make sure bytes display comes out even in case opcodes aren't + // all the same size. + if (bytes_written_so_far < min_byte_width) +s->Printf("%*s", min_byte_width - bytes_written_so_far, ""); + return s->GetWrittenBytes() - previous_bytes; } lldb::ByteOrder Opcode::GetDataByteOrder() const { ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50681: Remove manual byte counting from internal Stream methods.
teemperor created this revision. This patch removes the manual byte counting in all internal Stream methods. This is now done by the automatic byte counting provided by calling `GetWrittenBytes()` before and after writing the data (which is automatically done for us by the `ByteDelta` utility class). Repository: rLLDB LLDB https://reviews.llvm.org/D50681 Files: include/lldb/Utility/Stream.h source/Utility/Stream.cpp Index: source/Utility/Stream.cpp === --- source/Utility/Stream.cpp +++ source/Utility/Stream.cpp @@ -22,6 +22,26 @@ using namespace lldb; using namespace lldb_private; +namespace { +/// Utility class for counting the bytes that were written to a stream in a +/// certain time span. +/// @example +/// ByteDelta delta(*this); +/// WriteDataToStream("foo"); +/// return *delta; +/// @endcode +class ByteDelta { + Stream *m_stream; + /// Bytes we have written so far when ByteDelta was created. + size_t m_start; + +public: + ByteDelta(Stream &s) : m_stream(&s), m_start(s.GetWrittenBytes()) {} + + size_t operator*() const { return m_stream->GetWrittenBytes() - m_start; } +} +} // namespace + Stream::Stream(uint32_t flags, uint32_t addr_size, ByteOrder byte_order) : m_flags(flags), m_addr_size(addr_size), m_byte_order(byte_order), m_indent_level(0), m_forwarder(*this) {} @@ -313,26 +333,25 @@ llvm::SmallString<1024> buf; VASprintf(buf, format, args); - size_t length = 0; + ByteDelta delta(*this); for (char C : buf) -length += _PutHex8(C, false); +_PutHex8(C, false); va_end(args); - return length; + return *delta; } size_t Stream::PutNHex8(size_t n, uint8_t uvalue) { - size_t bytes_written = 0; + ByteDelta delta(*this); for (size_t i = 0; i < n; ++i) -bytes_written += _PutHex8(uvalue, false); - return bytes_written; +_PutHex8(uvalue, false); + return *delta; } -size_t Stream::_PutHex8(uint8_t uvalue, bool add_prefix) { - size_t bytes_written = 0; +void Stream::_PutHex8(uint8_t uvalue, bool add_prefix) { if (m_flags.Test(eBinary)) { -bytes_written = Write(&uvalue, 1); +Write(&uvalue, 1); } else { if (add_prefix) PutCString("0x"); @@ -343,56 +362,58 @@ char nibble_chars[2]; nibble_chars[0] = g_hex_to_ascii_hex_char[(uvalue >> 4) & 0xf]; nibble_chars[1] = g_hex_to_ascii_hex_char[(uvalue >> 0) & 0xf]; -bytes_written = Write(nibble_chars, sizeof(nibble_chars)); +Write(nibble_chars, sizeof(nibble_chars)); } - return bytes_written; } size_t Stream::PutHex8(uint8_t uvalue) { return _PutHex8(uvalue, false); } size_t Stream::PutHex16(uint16_t uvalue, ByteOrder byte_order) { + ByteDelta delta(*this); + if (byte_order == eByteOrderInvalid) byte_order = m_byte_order; - size_t bytes_written = 0; if (byte_order == eByteOrderLittle) { for (size_t byte = 0; byte < sizeof(uvalue); ++byte) - bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); } else { for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte) - bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); } - return bytes_written; + return *delta; } size_t Stream::PutHex32(uint32_t uvalue, ByteOrder byte_order) { + ByteDelta delta(*this); + if (byte_order == eByteOrderInvalid) byte_order = m_byte_order; - size_t bytes_written = 0; if (byte_order == eByteOrderLittle) { for (size_t byte = 0; byte < sizeof(uvalue); ++byte) - bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); } else { for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte) - bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); } - return bytes_written; + return *delta; } size_t Stream::PutHex64(uint64_t uvalue, ByteOrder byte_order) { + ByteDelta delta(*this); + if (byte_order == eByteOrderInvalid) byte_order = m_byte_order; - size_t bytes_written = 0; if (byte_order == eByteOrderLittle) { for (size_t byte = 0; byte < sizeof(uvalue); ++byte) - bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); } else { for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte) - bytes_written += _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); + _PutHex8((uint8_t)(uvalue >> (byte * 8)), false); } - return bytes_written; + return *delta; } size_t Stream::PutMaxHex64(uint64_t uvalue, size_t byte_size, @@ -438,65 +459,66 @@ size_t Stream::PutRawBytes(const void *s, size_t src_len, ByteOrder src_byte_order, ByteOrder dst_byte_order) { + ByteDelt