[llvm] r307204 - [llvm-pdbutil] Add the ability to truncate stream purpose names.

Mikael Holmén via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 5 23:30:58 PDT 2017


Hi Zachary,

I get a warning about unused function when compiling this patch:

In file included from ../tools/llvm-pdbutil/BytesOutputStyle.cpp:12:
../tools/llvm-pdbutil/FormatUtil.h:26:20: error: unused function 
'truncateStringFront' [-Werror,-Wunused-function]
static std::string truncateStringFront(StringRef S, uint32_t MaxLen);
                    ^
1 error generated.

Regards,
Mikael

On 07/05/2017 11:54 PM, Zachary Turner via llvm-commits wrote:
> Author: zturner
> Date: Wed Jul  5 14:54:58 2017
> New Revision: 307204
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=307204&view=rev
> Log:
> [llvm-pdbutil] Add the ability to truncate stream purpose names.
> 
> This will be useful for aligning fields to a fixed with in
> subsequent patches.
> 
> Modified:
>      llvm/trunk/tools/llvm-pdbutil/FormatUtil.cpp
>      llvm/trunk/tools/llvm-pdbutil/FormatUtil.h
>      llvm/trunk/tools/llvm-pdbutil/StreamUtil.cpp
>      llvm/trunk/tools/llvm-pdbutil/StreamUtil.h
> 
> Modified: llvm/trunk/tools/llvm-pdbutil/FormatUtil.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/FormatUtil.cpp?rev=307204&r1=307203&r2=307204&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbutil/FormatUtil.cpp (original)
> +++ llvm/trunk/tools/llvm-pdbutil/FormatUtil.cpp Wed Jul  5 14:54:58 2017
> @@ -16,6 +16,47 @@
>   using namespace llvm;
>   using namespace llvm::pdb;
>   
> +std::string llvm::pdb::truncateStringBack(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);
> +  S = S.take_front(FinalLen);
> +  return std::string(S) + std::string("...");
> +}
> +
> +std::string llvm::pdb::truncateStringFront(StringRef S, uint32_t MaxLen) {
> +  if (MaxLen == 0 || S.size() <= MaxLen || S.size() <= 3)
> +    return S;
> +
> +  assert(MaxLen >= 3);
> +  S = S.take_back(MaxLen - 3);
> +  return std::string("...") + std::string(S);
> +}
> +
> +std::string llvm::pdb::truncateQuotedNameFront(StringRef Label, StringRef Name,
> +                                               uint32_t MaxLen) {
> +  uint32_t RequiredExtraChars = Label.size() + 1 + 2;
> +  if (MaxLen == 0 || RequiredExtraChars + Name.size() <= MaxLen)
> +    return formatv("{0} \"{1}\"", Label, Name).str();
> +
> +  assert(MaxLen >= RequiredExtraChars);
> +  std::string TN = truncateStringFront(Name, MaxLen - RequiredExtraChars);
> +  return formatv("{0} \"{1}\"", Label, TN).str();
> +}
> +
> +std::string llvm::pdb::truncateQuotedNameBack(StringRef Label, StringRef Name,
> +                                              uint32_t MaxLen) {
> +  uint32_t RequiredExtraChars = Label.size() + 1 + 2;
> +  if (MaxLen == 0 || RequiredExtraChars + Name.size() <= MaxLen)
> +    return formatv("{0} \"{1}\"", Label, Name).str();
> +
> +  assert(MaxLen >= RequiredExtraChars);
> +  std::string TN = truncateStringBack(Name, MaxLen - RequiredExtraChars);
> +  return formatv("{0} \"{1}\"", Label, TN).str();
> +}
> +
>   std::string llvm::pdb::typesetItemList(ArrayRef<std::string> Opts,
>                                          uint32_t IndentLevel, uint32_t GroupSize,
>                                          StringRef Sep) {
> 
> Modified: llvm/trunk/tools/llvm-pdbutil/FormatUtil.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/FormatUtil.h?rev=307204&r1=307203&r2=307204&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbutil/FormatUtil.h (original)
> +++ llvm/trunk/tools/llvm-pdbutil/FormatUtil.h Wed Jul  5 14:54:58 2017
> @@ -22,6 +22,13 @@
>   namespace llvm {
>   namespace pdb {
>   
> +std::string truncateStringBack(StringRef S, uint32_t MaxLen);
> +static std::string truncateStringFront(StringRef S, uint32_t MaxLen);
> +std::string truncateQuotedNameFront(StringRef Label, StringRef Name,
> +                                    uint32_t MaxLen);
> +std::string truncateQuotedNameBack(StringRef Label, StringRef Name,
> +                                   uint32_t MaxLen);
> +
>   #define PUSH_MASKED_FLAG(Enum, Mask, TheOpt, Value, Text)                      \
>     if (Enum::TheOpt == (Value & Mask))                                          \
>       Opts.push_back(Text);
> 
> Modified: llvm/trunk/tools/llvm-pdbutil/StreamUtil.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/StreamUtil.cpp?rev=307204&r1=307203&r2=307204&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbutil/StreamUtil.cpp (original)
> +++ llvm/trunk/tools/llvm-pdbutil/StreamUtil.cpp Wed Jul  5 14:54:58 2017
> @@ -8,6 +8,7 @@
>   //===----------------------------------------------------------------------===//
>   
>   #include "StreamUtil.h"
> +#include "FormatUtil.h"
>   
>   #include "llvm/ADT/DenseMap.h"
>   #include "llvm/ADT/DenseMapInfo.h"
> @@ -18,10 +19,12 @@
>   #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
>   #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
>   
> -namespace llvm {
> -namespace pdb {
> -void discoverStreamPurposes(PDBFile &File,
> -                            SmallVectorImpl<std::string> &Purposes) {
> +using namespace llvm;
> +using namespace llvm::pdb;
> +
> +void llvm::pdb::discoverStreamPurposes(PDBFile &File,
> +                                       SmallVectorImpl<std::string> &Purposes,
> +                                       uint32_t MaxLen) {
>   
>     // It's OK if we fail to load some of these streams, we still attempt to print
>     // what we can.
> @@ -54,70 +57,67 @@ void discoverStreamPurposes(PDBFile &Fil
>     for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
>       std::string Value;
>       if (StreamIdx == OldMSFDirectory)
> -      Value = "Old MSF Directory";
> +      Value = truncateStringBack("Old MSF Directory", MaxLen);
>       else if (StreamIdx == StreamPDB)
> -      Value = "PDB Stream";
> +      Value = truncateStringBack("PDB Stream", MaxLen);
>       else if (StreamIdx == StreamDBI)
> -      Value = "DBI Stream";
> +      Value = truncateStringBack("DBI Stream", MaxLen);
>       else if (StreamIdx == StreamTPI)
> -      Value = "TPI Stream";
> +      Value = truncateStringBack("TPI Stream", MaxLen);
>       else if (StreamIdx == StreamIPI)
> -      Value = "IPI Stream";
> +      Value = truncateStringBack("IPI Stream", MaxLen);
>       else if (Dbi && StreamIdx == Dbi->getGlobalSymbolStreamIndex())
> -      Value = "Global Symbol Hash";
> +      Value = truncateStringBack("Global Symbol Hash", MaxLen);
>       else if (Dbi && StreamIdx == Dbi->getPublicSymbolStreamIndex())
> -      Value = "Public Symbol Hash";
> +      Value = truncateStringBack("Public Symbol Hash", MaxLen);
>       else if (Dbi && StreamIdx == Dbi->getSymRecordStreamIndex())
> -      Value = "Public Symbol Records";
> +      Value = truncateStringBack("Public Symbol Records", MaxLen);
>       else if (Tpi && StreamIdx == Tpi->getTypeHashStreamIndex())
> -      Value = "TPI Hash";
> +      Value = truncateStringBack("TPI Hash", MaxLen);
>       else if (Tpi && StreamIdx == Tpi->getTypeHashStreamAuxIndex())
> -      Value = "TPI Aux Hash";
> +      Value = truncateStringBack("TPI Aux Hash", MaxLen);
>       else if (Ipi && StreamIdx == Ipi->getTypeHashStreamIndex())
> -      Value = "IPI Hash";
> +      Value = truncateStringBack("IPI Hash", MaxLen);
>       else if (Ipi && StreamIdx == Ipi->getTypeHashStreamAuxIndex())
> -      Value = "IPI Aux Hash";
> +      Value = truncateStringBack("IPI Aux Hash", MaxLen);
>       else if (Dbi &&
>                StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Exception))
> -      Value = "Exception Data";
> +      Value = truncateStringBack("Exception Data", MaxLen);
>       else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Fixup))
> -      Value = "Fixup Data";
> +      Value = truncateStringBack("Fixup Data", MaxLen);
>       else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::FPO))
> -      Value = "FPO Data";
> +      Value = truncateStringBack("FPO Data", MaxLen);
>       else if (Dbi &&
>                StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::NewFPO))
> -      Value = "New FPO Data";
> +      Value = truncateStringBack("New FPO Data", MaxLen);
>       else if (Dbi &&
>                StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapFromSrc))
> -      Value = "Omap From Source Data";
> +      Value = truncateStringBack("Omap From Source Data", MaxLen);
>       else if (Dbi &&
>                StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapToSrc))
> -      Value = "Omap To Source Data";
> +      Value = truncateStringBack("Omap To Source Data", MaxLen);
>       else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Pdata))
> -      Value = "Pdata";
> +      Value = truncateStringBack("Pdata", MaxLen);
>       else if (Dbi &&
>                StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdr))
> -      Value = "Section Header Data";
> +      Value = truncateStringBack("Section Header Data", MaxLen);
>       else if (Dbi &&
>                StreamIdx ==
>                    Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdrOrig))
> -      Value = "Section Header Original Data";
> +      Value = truncateStringBack("Section Header Original Data", MaxLen);
>       else if (Dbi &&
>                StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::TokenRidMap))
> -      Value = "Token Rid Data";
> +      Value = truncateStringBack("Token Rid Data", MaxLen);
>       else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Xdata))
> -      Value = "Xdata";
> +      Value = truncateStringBack("Xdata", MaxLen);
>       else {
>         auto ModIter = ModStreams.find(StreamIdx);
>         auto NSIter = NamedStreams.find(StreamIdx);
>         if (ModIter != ModStreams.end()) {
> -        Value = "Module \"";
> -        Value += ModIter->second.getModuleName();
> -        Value += "\"";
> +        Value = truncateQuotedNameFront(
> +            "Module", ModIter->second.getModuleName(), MaxLen);
>         } else if (NSIter != NamedStreams.end()) {
> -        Value = "Named Stream \"";
> -        Value += NSIter->second;
> -        Value += "\"";
> +        Value = truncateQuotedNameBack("Named Stream", NSIter->second, MaxLen);
>         } else {
>           Value = "???";
>         }
> @@ -135,5 +135,3 @@ void discoverStreamPurposes(PDBFile &Fil
>     if (!Info)
>       consumeError(Info.takeError());
>   }
> -}
> -}
> 
> Modified: llvm/trunk/tools/llvm-pdbutil/StreamUtil.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/StreamUtil.h?rev=307204&r1=307203&r2=307204&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-pdbutil/StreamUtil.h (original)
> +++ llvm/trunk/tools/llvm-pdbutil/StreamUtil.h Wed Jul  5 14:54:58 2017
> @@ -18,7 +18,8 @@ namespace llvm {
>   namespace pdb {
>   class PDBFile;
>   void discoverStreamPurposes(PDBFile &File,
> -                            SmallVectorImpl<std::string> &Purposes);
> +                            SmallVectorImpl<std::string> &Purposes,
> +                            uint32_t MaxLen = 0);
>   }
>   }
>   
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> 


More information about the llvm-commits mailing list