Skip to content

Commit f10a871

Browse files
committed
Revert "Revert "llvm-strings: support printing the filename""
Change the dynamic files to static in the hope that it will actually fix the transient errors that Ive been unable to reproduce. llvm-svn: 286891
1 parent 1cdd87a commit f10a871

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
abcd
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
RUN: rm -f %T/archive.a
2+
RUN: llvm-ar -format gnu crs %T/archive.a %S/Inputs/abcd
3+
RUN: llvm-strings -f %T/archive.a | FileCheck %s
4+
RUN: llvm-strings --print-file-name %T/archive.a | FileCheck %s
5+
6+
CHECK: archive.a: !<arch>
7+
CHECK: archive.a: abcd/ 0 0 0 644 4 `
8+
CHECK: archive.a: abcd
9+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RUN: llvm-strings -f %S/Inputs/abcd | FileCheck %s
2+
RUN: llvm-strings --print-file-name %S/Inputs/abcd | FileCheck %s
3+
CHECK: {{[\\/]}}abcd: abcd

llvm/test/tools/llvm-strings/nested-archives.test

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
RUN: echo -n abcd > %T/abcd
21
RUN: rm -f %T/inner.ar
3-
RUN: llvm-ar crs %T/inner.a %T/abcd
2+
RUN: llvm-ar -format gnu crs %T/inner.a %S/Inputs/abcd
43
RUN: rm -f %T/outer.ar
5-
RUN: llvm-ar crs %T/outer.a %T/inner.a
4+
RUN: llvm-ar -format gnu crs %T/outer.a %T/inner.a
65
RUN: llvm-strings %T/outer.a | FileCheck %s
76

87
CHECK: !<arch>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RUN: echo abcd | llvm-strings -f - | FileCheck %s
2+
RUN: echo abcd | llvm-strings --print-file-name - | FileCheck %s
3+
CHECK: {standard input}: abcd

llvm/tools/llvm-strings/llvm-strings.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,32 @@ static cl::list<std::string> InputFileNames(cl::Positional,
2929
cl::desc("<input object files>"),
3030
cl::ZeroOrMore);
3131

32-
static void strings(raw_ostream &OS, StringRef Contents) {
32+
static cl::opt<bool>
33+
PrintFileName("print-file-name",
34+
cl::desc("Print the name of the file before each string"));
35+
static cl::alias PrintFileNameShort("f", cl::desc(""),
36+
cl::aliasopt(PrintFileName));
37+
38+
static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) {
39+
auto print = [&OS, FileName](StringRef L) {
40+
if (PrintFileName)
41+
OS << FileName << ": ";
42+
OS << L << '\n';
43+
};
44+
3345
const char *P = nullptr, *E = nullptr, *S = nullptr;
3446
for (P = Contents.begin(), E = Contents.end(); P < E; ++P) {
3547
if (std::isgraph(*P) || std::isblank(*P)) {
3648
if (S == nullptr)
3749
S = P;
3850
} else if (S) {
3951
if (P - S > 3)
40-
OS << StringRef(S, P - S) << '\n';
52+
print(StringRef(S, P - S));
4153
S = nullptr;
4254
}
4355
}
4456
if (S && E - S > 3)
45-
OS << StringRef(S, E - S) << '\n';
57+
print(StringRef(S, E - S));
4658
}
4759

4860
int main(int argc, char **argv) {
@@ -60,7 +72,8 @@ int main(int argc, char **argv) {
6072
if (std::error_code EC = Buffer.getError())
6173
errs() << File << ": " << EC.message() << '\n';
6274
else
63-
strings(llvm::outs(), Buffer.get()->getMemBufferRef().getBuffer());
75+
strings(llvm::outs(), File == "-" ? "{standard input}" : File,
76+
Buffer.get()->getMemBufferRef().getBuffer());
6477
}
6578

6679
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)