From f3b4b2d89d06ededb515703f86ca4ab8744c154d Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 7 Jul 2017 18:45:37 +0000 Subject: [llvm-pdbutil] Improve diff mode. We're getting to the point that some MS tools (e.g. DIA) can recognize our PDBs but others (e.g. link.exe) cannot. I think the way forward is to improve our tooling to help us find differences more easily. For example, if we can compile the same program with clang-cl and cl and have a tool tell us all the places where the PDBs differ, this could tell us what we're doing wrong. It's tricky though, because there are a lot of "benign" differences in a PDB. For example, if the string table in one PDB consists of "foo" followed by "bar" and in the other PDB it consists of "bar" followed by "foo", this is not necessarily a critical difference, as long as the uses of these strings also refer to the correct location. On the other hand, if the second PDB doesn't even contain the string "foo" at all, this is a critical difference. diff mode has been in llvm-pdbutil for quite a while, but because of the above challenge along with some others, it's been hard to make it useful. I think this patch addresses that. It looks for all the same things, but it now prints the output in tabular format (carefully formatted and aligned into tables and fields), and it highlights critical differences in red, non-critical differences in yellow, and identical fields in green. This makes it easy to spot the places we differ, and the general concept of outputting arbitrary fields in tabular format can be extended to provide analysis into many of the different types of information that show up in a PDB. Differential Revision: https://reviews.llvm.org/D35039 llvm-svn: 307421 --- llvm/tools/llvm-pdbutil/FormatUtil.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'llvm/tools/llvm-pdbutil/FormatUtil.cpp') diff --git a/llvm/tools/llvm-pdbutil/FormatUtil.cpp b/llvm/tools/llvm-pdbutil/FormatUtil.cpp index 46a1774f166..02030272dd4 100644 --- a/llvm/tools/llvm-pdbutil/FormatUtil.cpp +++ b/llvm/tools/llvm-pdbutil/FormatUtil.cpp @@ -26,6 +26,17 @@ std::string llvm::pdb::truncateStringBack(StringRef S, uint32_t MaxLen) { return std::string(S) + std::string("..."); } +std::string llvm::pdb::truncateStringMiddle(StringRef S, uint32_t MaxLen) { + if (MaxLen == 0 || S.size() <= MaxLen || S.size() <= 3) + return S; + + assert(MaxLen >= 3); + uint32_t FinalLen = std::min(S.size(), MaxLen - 3); + StringRef Front = S.take_front(FinalLen / 2); + StringRef Back = S.take_back(Front.size()); + return std::string(Front) + std::string("...") + std::string(Back); +} + std::string llvm::pdb::truncateStringFront(StringRef S, uint32_t MaxLen) { if (MaxLen == 0 || S.size() <= MaxLen || S.size() <= 3) return S; -- cgit v1.2.3