diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-11-15 00:43:52 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-11-15 00:43:52 +0000 |
commit | f7009b42f8a9d916f0ed69274089fae32e5a1bbc (patch) | |
tree | 09c436442cefccaab5758be594552a5b9e666e5f /llvm/tools/llvm-strings/llvm-strings.cpp | |
parent | 81da114e65cf18b719bc88322365248d2e05918b (diff) | |
download | bcm5719-llvm-f7009b42f8a9d916f0ed69274089fae32e5a1bbc.tar.gz bcm5719-llvm-f7009b42f8a9d916f0ed69274089fae32e5a1bbc.zip |
llvm-strings: support the `-n` option
Permit specifying the match length (the `-n` or `--bytes` option). The
deprecated `-[length]` form is not supported as an option. This allows the
strings tool to display only the specified length strings rather than the
hardcoded default length of >= 4.
llvm-svn: 286914
Diffstat (limited to 'llvm/tools/llvm-strings/llvm-strings.cpp')
-rw-r--r-- | llvm/tools/llvm-strings/llvm-strings.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/tools/llvm-strings/llvm-strings.cpp b/llvm/tools/llvm-strings/llvm-strings.cpp index cb0fb9651d9..e750995331e 100644 --- a/llvm/tools/llvm-strings/llvm-strings.cpp +++ b/llvm/tools/llvm-strings/llvm-strings.cpp @@ -35,8 +35,15 @@ static cl::opt<bool> static cl::alias PrintFileNameShort("f", cl::desc(""), cl::aliasopt(PrintFileName)); +static cl::opt<int> + MinLength("bytes", cl::desc("Print sequences of the specified length"), + cl::init(4)); +static cl::alias MinLengthShort("n", cl::desc(""), cl::aliasopt(MinLength)); + static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) { auto print = [&OS, FileName](StringRef L) { + if (L.size() < static_cast<size_t>(MinLength)) + return; if (PrintFileName) OS << FileName << ": "; OS << L << '\n'; @@ -48,12 +55,11 @@ static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) { if (S == nullptr) S = P; } else if (S) { - if (P - S > 3) - print(StringRef(S, P - S)); + print(StringRef(S, P - S)); S = nullptr; } } - if (S && E - S > 3) + if (S) print(StringRef(S, E - S)); } @@ -62,6 +68,10 @@ int main(int argc, char **argv) { PrettyStackTraceProgram X(argc, argv); cl::ParseCommandLineOptions(argc, argv, "llvm string dumper\n"); + if (MinLength == 0) { + errs() << "invalid minimum string length 0\n"; + return EXIT_FAILURE; + } if (InputFileNames.empty()) InputFileNames.push_back("-"); |