llvm.org GIT mirror llvm / 4679ff9
llvm-cvtres: Make new dupe resource error a bit friendlier For well-known type IDs, include the name of the type. To not duplicate the ID->name map, make llvm-readobj call this new function as well. It has slightly different output, so this also requires updating a few tests. Differential Revision: https://reviews.llvm.org/D61086 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359153 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 3 months ago
8 changed file(s) with 58 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
3636 #include "llvm/Support/ConvertUTF.h"
3737 #include "llvm/Support/Endian.h"
3838 #include "llvm/Support/Error.h"
39 #include "llvm/Support/ScopedPrinter.h"
4039
4140 #include
4241
4342 namespace llvm {
43
44 class raw_ostream;
45 class ScopedPrinter;
46
4447 namespace object {
4548
4649 class WindowsResource;
229232 writeWindowsResourceCOFF(llvm::COFF::MachineTypes MachineType,
230233 const WindowsResourceParser &Parser);
231234
235 void printResourceTypeName(uint16_t TypeID, raw_ostream &OS);
232236 } // namespace object
233237 } // namespace llvm
234238
1414 #include "llvm/Support/FileOutputBuffer.h"
1515 #include "llvm/Support/FormatVariadic.h"
1616 #include "llvm/Support/MathExtras.h"
17 #include "llvm/Support/ScopedPrinter.h"
1718 #include
1819 #include
1920 #include
126127
127128 WindowsResourceParser::WindowsResourceParser() : Root(false) {}
128129
129 static Error duplicateResourceError(const ResourceEntryRef& Entry,
130 StringRef File1, StringRef File2) {
130 void printResourceTypeName(uint16_t TypeID, raw_ostream &OS) {
131 switch (TypeID) {
132 case 1: OS << "CURSOR (ID 1)"; break;
133 case 2: OS << "BITMAP (ID 2)"; break;
134 case 3: OS << "ICON (ID 3)"; break;
135 case 4: OS << "MENU (ID 4)"; break;
136 case 5: OS << "DIALOG (ID 5)"; break;
137 case 6: OS << "STRINGTABLE (ID 6)"; break;
138 case 7: OS << "FONTDIR (ID 7)"; break;
139 case 8: OS << "FONT (ID 8)"; break;
140 case 9: OS << "ACCELERATOR (ID 9)"; break;
141 case 10: OS << "RCDATA (ID 10)"; break;
142 case 11: OS << "MESSAGETABLE (ID 11)"; break;
143 case 12: OS << "GROUP_CURSOR (ID 12)"; break;
144 case 14: OS << "GROUP_ICON (ID 14)"; break;
145 case 16: OS << "VERSIONINFO (ID 16)"; break;
146 case 17: OS << "DLGINCLUDE (ID 17)"; break;
147 case 19: OS << "PLUGPLAY (ID 19)"; break;
148 case 20: OS << "VXD (ID 20)"; break;
149 case 21: OS << "ANICURSOR (ID 21)"; break;
150 case 22: OS << "ANIICON (ID 22)"; break;
151 case 23: OS << "HTML (ID 23)"; break;
152 case 24: OS << "MANIFEST (ID 24)"; break;
153 default: OS << "ID " << TypeID; break;
154 }
155 }
156
157 static Error makeDuplicateResourceError(const ResourceEntryRef &Entry,
158 StringRef File1, StringRef File2) {
131159 std::string Ret;
132160 raw_string_ostream OS(Ret);
133161
139167 if (!convertUTF16ToUTF8String(Entry.getTypeString(), UTF8))
140168 UTF8 = "(failed conversion from UTF16)";
141169 OS << '\"' << UTF8 << '\"';
142 } else {
143 OS << "ID " << Entry.getTypeID();
144 }
170 } else
171 printResourceTypeName(Entry.getTypeID(), OS);
145172
146173 OS << "/name ";
147174 if (Entry.checkNameString()) {
189216 IsNewTypeString, IsNewNameString, Node);
190217 InputFilenames.push_back(WR->getFileName());
191218 if (!IsNewNode)
192 return duplicateResourceError(Entry, InputFilenames[Node->Origin],
193 WR->getFileName());
219 return makeDuplicateResourceError(Entry, InputFilenames[Node->Origin],
220 WR->getFileName());
194221
195222 if (IsNewTypeString)
196223 StringTable.push_back(Entry.getTypeString());
3131 CHECK-NEXT: ]
3232 CHECK-NEXT: ]
3333 CHECK-NEXT: ]
34 CHECK-NEXT: Type: kRT_BITMAP (ID 2) [
34 CHECK-NEXT: Type: BITMAP (ID 2) [
3535 CHECK-NEXT: Table Offset: 0x58
3636 CHECK-NEXT: Number of String Entries: 2
3737 CHECK-NEXT: Number of ID Entries: 0
6060 CHECK-NEXT: ]
6161 CHECK-NEXT: ]
6262 CHECK-NEXT: ]
63 CHECK-NEXT: Type: kRT_MENU (ID 4) [
63 CHECK-NEXT: Type: MENU (ID 4) [
6464 CHECK-NEXT: Table Offset: 0x78
6565 CHECK-NEXT: Number of String Entries: 1
6666 CHECK-NEXT: Number of ID Entries: 1
8989 CHECK-NEXT: ]
9090 CHECK-NEXT: ]
9191 CHECK-NEXT: ]
92 CHECK-NEXT: Type: kRT_DIALOG (ID 5) [
92 CHECK-NEXT: Type: DIALOG (ID 5) [
9393 CHECK-NEXT: Table Offset: 0x98
9494 CHECK-NEXT: Number of String Entries: 1
9595 CHECK-NEXT: Number of ID Entries: 0
106106 CHECK-NEXT: ]
107107 CHECK-NEXT: ]
108108 CHECK-NEXT: ]
109 CHECK-NEXT: Type: kRT_ACCELERATOR (ID 9) [
109 CHECK-NEXT: Type: ACCELERATOR (ID 9) [
110110 CHECK-NEXT: Table Offset: 0xB0
111111 CHECK-NEXT: Number of String Entries: 1
112112 CHECK-NEXT: Number of ID Entries: 1
142142 CHECK-NEXT: ]
143143 CHECK-NEXT: ]
144144 CHECK-NEXT: ]
145 CHECK-NEXT: Type: kRT_RCDATA (ID 10) [
145 CHECK-NEXT: Type: RCDATA (ID 10) [
146146 CHECK-NEXT: Table Offset: 0xD0
147147 CHECK-NEXT: Number of String Entries: 1
148148 CHECK-NEXT: Number of ID Entries: 0
99 RUN: cp %S/Inputs/id.res %t.dir/id2.res
1010 RUN: not llvm-cvtres /machine:X86 %t.dir/id1.res %t.dir/id2.res 2>&1 | \
1111 RUN: FileCheck -check-prefix=ID %s
12 ID: duplicate resource: type ID 6/name ID 3/language 1033, in {{.*}}id1.res and in {{.*}}id2.res
12 ID: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in {{.*}}id1.res and in {{.*}}id2.res
1313
1414 RUN: cp %S/Inputs/name.res %t.dir/name1.res
1515 RUN: cp %S/Inputs/name.res %t.dir/name2.res
3030 CHECK-NEXT: ]
3131 CHECK-NEXT: ]
3232 CHECK-NEXT: ]
33 CHECK-NEXT: Type: kRT_BITMAP (ID 2) [
33 CHECK-NEXT: Type: BITMAP (ID 2) [
3434 CHECK-NEXT: Table Offset: 0x50
3535 CHECK-NEXT: Number of String Entries: 2
3636 CHECK-NEXT: Number of ID Entries: 0
5959 CHECK-NEXT: ]
6060 CHECK-NEXT: ]
6161 CHECK-NEXT: ]
62 CHECK-NEXT: Type: kRT_MENU (ID 4) [
62 CHECK-NEXT: Type: MENU (ID 4) [
6363 CHECK-NEXT: Table Offset: 0x70
6464 CHECK-NEXT: Number of String Entries: 1
6565 CHECK-NEXT: Number of ID Entries: 1
8888 CHECK-NEXT: ]
8989 CHECK-NEXT: ]
9090 CHECK-NEXT: ]
91 CHECK-NEXT: Type: kRT_DIALOG (ID 5) [
91 CHECK-NEXT: Type: DIALOG (ID 5) [
9292 CHECK-NEXT: Table Offset: 0x90
9393 CHECK-NEXT: Number of String Entries: 1
9494 CHECK-NEXT: Number of ID Entries: 0
105105 CHECK-NEXT: ]
106106 CHECK-NEXT: ]
107107 CHECK-NEXT: ]
108 CHECK-NEXT: Type: kRT_ACCELERATOR (ID 9) [
108 CHECK-NEXT: Type: ACCELERATOR (ID 9) [
109109 CHECK-NEXT: Table Offset: 0xA8
110110 CHECK-NEXT: Number of String Entries: 1
111111 CHECK-NEXT: Number of ID Entries: 1
1313 ZERO-NEXT: Base Table Address: 0x188
1414 ZERO-DAG: Number of String Entries: 0
1515 ZERO-NEXT: Number of ID Entries: 1
16 ZERO-NEXT: Type: kRT_STRING (ID 6) [
16 ZERO-NEXT: Type: STRINGTABLE (ID 6) [
1717 ZERO-NEXT: Table Offset: 0x18
1818 ZERO-NEXT: Number of String Entries: 0
1919 ZERO-NEXT: Number of ID Entries: 1
3636 TEST_RES-NEXT: Base Table Address: 0x1C0
3737 TEST_RES-DAG: Number of String Entries: 0
3838 TEST_RES-NEXT: Number of ID Entries: 4
39 TEST_RES-NEXT: Type: kRT_BITMAP (ID 2) [
39 TEST_RES-NEXT: Type: BITMAP (ID 2) [
4040 TEST_RES-NEXT: Table Offset: 0x30
4141 TEST_RES-NEXT: Number of String Entries: 2
4242 TEST_RES-NEXT: Number of ID Entries: 0
6565 TEST_RES-NEXT: ]
6666 TEST_RES-NEXT: ]
6767 TEST_RES-NEXT: ]
68 TEST_RES-NEXT: Type: kRT_MENU (ID 4) [
68 TEST_RES-NEXT: Type: MENU (ID 4) [
6969 TEST_RES-NEXT: Table Offset: 0x50
7070 TEST_RES-NEXT: Number of String Entries: 1
7171 TEST_RES-NEXT: Number of ID Entries: 1
9494 TEST_RES-NEXT: ]
9595 TEST_RES-NEXT: ]
9696 TEST_RES-NEXT: ]
97 TEST_RES-NEXT: Type: kRT_DIALOG (ID 5) [
97 TEST_RES-NEXT: Type: DIALOG (ID 5) [
9898 TEST_RES-NEXT: Table Offset: 0x70
9999 TEST_RES-NEXT: Number of String Entries: 1
100100 TEST_RES-NEXT: Number of ID Entries: 0
111111 TEST_RES-NEXT: ]
112112 TEST_RES-NEXT: ]
113113 TEST_RES-NEXT: ]
114 TEST_RES-NEXT: Type: kRT_ACCELERATOR (ID 9) [
114 TEST_RES-NEXT: Type: ACCELERATOR (ID 9) [
115115 TEST_RES-NEXT: Table Offset: 0x88
116116 TEST_RES-NEXT: Number of String Entries: 1
117117 TEST_RES-NEXT: Number of ID Entries: 1
2323 #include "llvm/Support/Path.h"
2424 #include "llvm/Support/PrettyStackTrace.h"
2525 #include "llvm/Support/Process.h"
26 #include "llvm/Support/ScopedPrinter.h"
2627 #include "llvm/Support/Signals.h"
2728 #include "llvm/Support/raw_ostream.h"
2829
4242 #include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
4343 #include "llvm/Object/COFF.h"
4444 #include "llvm/Object/ObjectFile.h"
45 #include "llvm/Object/WindowsResource.h"
4546 #include "llvm/Support/BinaryStreamReader.h"
4647 #include "llvm/Support/Casting.h"
4748 #include "llvm/Support/Compiler.h"
568569 LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, SHA256),
569570 };
570571
571 static const EnumEntry ResourceTypeNames[]{
572 {"kRT_CURSOR (ID 1)", COFF::RID_Cursor},
573 {"kRT_BITMAP (ID 2)", COFF::RID_Bitmap},
574 {"kRT_ICON (ID 3)", COFF::RID_Icon},
575 {"kRT_MENU (ID 4)", COFF::RID_Menu},
576 {"kRT_DIALOG (ID 5)", COFF::RID_Dialog},
577 {"kRT_STRING (ID 6)", COFF::RID_String},
578 {"kRT_FONTDIR (ID 7)", COFF::RID_FontDir},
579 {"kRT_FONT (ID 8)", COFF::RID_Font},
580 {"kRT_ACCELERATOR (ID 9)", COFF::RID_Accelerator},
581 {"kRT_RCDATA (ID 10)", COFF::RID_RCData},
582 {"kRT_MESSAGETABLE (ID 11)", COFF::RID_MessageTable},
583 {"kRT_GROUP_CURSOR (ID 12)", COFF::RID_Group_Cursor},
584 {"kRT_GROUP_ICON (ID 14)", COFF::RID_Group_Icon},
585 {"kRT_VERSION (ID 16)", COFF::RID_Version},
586 {"kRT_DLGINCLUDE (ID 17)", COFF::RID_DLGInclude},
587 {"kRT_PLUGPLAY (ID 19)", COFF::RID_PlugPlay},
588 {"kRT_VXD (ID 20)", COFF::RID_VXD},
589 {"kRT_ANICURSOR (ID 21)", COFF::RID_AniCursor},
590 {"kRT_ANIICON (ID 22)", COFF::RID_AniIcon},
591 {"kRT_HTML (ID 23)", COFF::RID_HTML},
592 {"kRT_MANIFEST (ID 24)", COFF::RID_Manifest}};
593
594572 template
595573 static std::error_code getSymbolAuxData(const COFFObjectFile *Obj,
596574 COFFSymbolRef Symbol,
18041782 OS << EntryNameString;
18051783 } else {
18061784 if (Level == "Type") {
1807 ScopedPrinter Printer(OS);
1808 Printer.printEnum("", Entry.Identifier.ID,
1809 makeArrayRef(ResourceTypeNames));
1785 OS << ": ";
1786 printResourceTypeName(Entry.Identifier.ID, OS);
18101787 IDStr = IDStr.slice(0, IDStr.find_first_of(")", 0) + 1);
18111788 } else {
18121789 OS << ": (ID " << Entry.Identifier.ID << ")";