@@ -535,7 +535,9 @@ static void darwinPrintStab(MachOObjectFile *MachO, SymbolListT::iterator I) {
535
535
outs () << Str;
536
536
}
537
537
538
- static void sortAndPrintSymbolList (SymbolicFile *Obj, bool printName) {
538
+ static void sortAndPrintSymbolList (SymbolicFile *Obj, bool printName,
539
+ std::string ArchiveName,
540
+ std::string ArchitectureName) {
539
541
if (!NoSort) {
540
542
if (NumericSort)
541
543
std::sort (SymbolList.begin (), SymbolList.end (), compareSymbolAddress);
@@ -545,14 +547,16 @@ static void sortAndPrintSymbolList(SymbolicFile *Obj, bool printName) {
545
547
std::sort (SymbolList.begin (), SymbolList.end (), compareSymbolName);
546
548
}
547
549
548
- if (OutputFormat == posix && MultipleFiles && printName) {
549
- outs () << ' \n ' << CurrentFilename << " :\n " ;
550
- } else if (OutputFormat == bsd && MultipleFiles && printName) {
551
- outs () << " \n " << CurrentFilename << " :\n " ;
552
- } else if (OutputFormat == sysv) {
553
- outs () << " \n\n Symbols from " << CurrentFilename << " :\n\n "
554
- << " Name Value Class Type"
555
- << " Size Line Section\n " ;
550
+ if (!PrintFileName) {
551
+ if (OutputFormat == posix && MultipleFiles && printName) {
552
+ outs () << ' \n ' << CurrentFilename << " :\n " ;
553
+ } else if (OutputFormat == bsd && MultipleFiles && printName) {
554
+ outs () << " \n " << CurrentFilename << " :\n " ;
555
+ } else if (OutputFormat == sysv) {
556
+ outs () << " \n\n Symbols from " << CurrentFilename << " :\n\n "
557
+ << " Name Value Class Type"
558
+ << " Size Line Section\n " ;
559
+ }
556
560
}
557
561
558
562
const char *printBlanks, *printFormat;
@@ -572,6 +576,13 @@ static void sortAndPrintSymbolList(SymbolicFile *Obj, bool printName) {
572
576
continue ;
573
577
if (SizeSort && !PrintAddress && I->Size == UnknownAddressOrSize)
574
578
continue ;
579
+ if (PrintFileName) {
580
+ if (!ArchitectureName.empty ())
581
+ outs () << " (for architecture " << ArchitectureName << " ):" ;
582
+ if (!ArchiveName.empty ())
583
+ outs () << ArchiveName << " :" ;
584
+ outs () << CurrentFilename << " : " ;
585
+ }
575
586
if (JustSymbolName) {
576
587
outs () << I->Name << " \n " ;
577
588
continue ;
@@ -883,7 +894,10 @@ static unsigned getNsectInMachO(MachOObjectFile &Obj, basic_symbol_iterator I) {
883
894
return 0 ;
884
895
}
885
896
886
- static void dumpSymbolNamesFromObject (SymbolicFile *Obj, bool printName) {
897
+ static void dumpSymbolNamesFromObject (SymbolicFile *Obj, bool printName,
898
+ std::string ArchiveName = std::string(),
899
+ std::string ArchitectureName =
900
+ std::string()) {
887
901
basic_symbol_iterator IBegin = Obj->symbol_begin ();
888
902
basic_symbol_iterator IEnd = Obj->symbol_end ();
889
903
if (DynamicSyms) {
@@ -951,7 +965,7 @@ static void dumpSymbolNamesFromObject(SymbolicFile *Obj, bool printName) {
951
965
}
952
966
953
967
CurrentFilename = Obj->getFileName ();
954
- sortAndPrintSymbolList (Obj, printName);
968
+ sortAndPrintSymbolList (Obj, printName, ArchiveName, ArchitectureName );
955
969
}
956
970
957
971
// checkMachOAndArchFlags() checks to see if the SymbolicFile is a Mach-O file
@@ -1029,13 +1043,15 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
1029
1043
if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get ())) {
1030
1044
if (!checkMachOAndArchFlags (O, Filename))
1031
1045
return ;
1032
- outs () << " \n " ;
1033
- if (isa<MachOObjectFile>(O)) {
1034
- outs () << Filename << " (" << O->getFileName () << " )" ;
1035
- } else
1036
- outs () << O->getFileName ();
1037
- outs () << " :\n " ;
1038
- dumpSymbolNamesFromObject (O, false );
1046
+ if (!PrintFileName) {
1047
+ outs () << " \n " ;
1048
+ if (isa<MachOObjectFile>(O)) {
1049
+ outs () << Filename << " (" << O->getFileName () << " )" ;
1050
+ } else
1051
+ outs () << O->getFileName ();
1052
+ outs () << " :\n " ;
1053
+ }
1054
+ dumpSymbolNamesFromObject (O, false , Filename);
1039
1055
}
1040
1056
}
1041
1057
return ;
@@ -1055,14 +1071,22 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
1055
1071
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
1056
1072
I->getAsObjectFile ();
1057
1073
std::unique_ptr<Archive> A;
1074
+ std::string ArchiveName;
1075
+ std::string ArchitectureName;
1076
+ ArchiveName.clear ();
1077
+ ArchitectureName.clear ();
1058
1078
if (ObjOrErr) {
1059
1079
std::unique_ptr<ObjectFile> Obj = std::move (ObjOrErr.get ());
1060
1080
if (ArchFlags.size () > 1 ) {
1061
- outs () << " \n " << Obj->getFileName () << " (for architecture "
1062
- << I->getArchTypeName () << " )"
1063
- << " :\n " ;
1081
+ if (PrintFileName)
1082
+ ArchitectureName = I->getArchTypeName ();
1083
+ else
1084
+ outs () << " \n " << Obj->getFileName () << " (for architecture "
1085
+ << I->getArchTypeName () << " )"
1086
+ << " :\n " ;
1064
1087
}
1065
- dumpSymbolNamesFromObject (Obj.get (), false );
1088
+ dumpSymbolNamesFromObject (Obj.get (), false , ArchiveName,
1089
+ ArchitectureName);
1066
1090
} else if (!I->getAsArchive (A)) {
1067
1091
for (Archive::child_iterator AI = A->child_begin (),
1068
1092
AE = A->child_end ();
@@ -1073,14 +1097,21 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
1073
1097
continue ;
1074
1098
if (SymbolicFile *O =
1075
1099
dyn_cast<SymbolicFile>(&*ChildOrErr.get ())) {
1076
- outs () << " \n " << A->getFileName ();
1077
- outs () << " (" << O->getFileName () << " )" ;
1078
- if (ArchFlags.size () > 1 ) {
1079
- outs () << " (for architecture " << I->getArchTypeName ()
1080
- << " )" ;
1100
+ if (PrintFileName) {
1101
+ ArchiveName = A->getFileName ();
1102
+ if (ArchFlags.size () > 1 )
1103
+ ArchitectureName = I->getArchTypeName ();
1104
+ } else {
1105
+ outs () << " \n " << A->getFileName ();
1106
+ outs () << " (" << O->getFileName () << " )" ;
1107
+ if (ArchFlags.size () > 1 ) {
1108
+ outs () << " (for architecture " << I->getArchTypeName ()
1109
+ << " )" ;
1110
+ }
1111
+ outs () << " :\n " ;
1081
1112
}
1082
- outs () << " : \n " ;
1083
- dumpSymbolNamesFromObject (O, false );
1113
+ dumpSymbolNamesFromObject (O, false , ArchiveName,
1114
+ ArchitectureName );
1084
1115
}
1085
1116
}
1086
1117
}
@@ -1104,6 +1135,8 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
1104
1135
if (HostArchName == I->getArchTypeName ()) {
1105
1136
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile ();
1106
1137
std::unique_ptr<Archive> A;
1138
+ std::string ArchiveName;
1139
+ ArchiveName.clear ();
1107
1140
if (ObjOrErr) {
1108
1141
std::unique_ptr<ObjectFile> Obj = std::move (ObjOrErr.get ());
1109
1142
dumpSymbolNamesFromObject (Obj.get (), false );
@@ -1117,10 +1150,13 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
1117
1150
continue ;
1118
1151
if (SymbolicFile *O =
1119
1152
dyn_cast<SymbolicFile>(&*ChildOrErr.get ())) {
1120
- outs () << " \n " << A->getFileName () << " (" << O->getFileName ()
1121
- << " )"
1122
- << " :\n " ;
1123
- dumpSymbolNamesFromObject (O, false );
1153
+ if (PrintFileName)
1154
+ ArchiveName = A->getFileName ();
1155
+ else
1156
+ outs () << " \n " << A->getFileName () << " (" << O->getFileName ()
1157
+ << " )"
1158
+ << " :\n " ;
1159
+ dumpSymbolNamesFromObject (O, false , ArchiveName);
1124
1160
}
1125
1161
}
1126
1162
}
@@ -1136,15 +1172,25 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
1136
1172
I != E; ++I) {
1137
1173
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile ();
1138
1174
std::unique_ptr<Archive> A;
1175
+ std::string ArchiveName;
1176
+ std::string ArchitectureName;
1177
+ ArchiveName.clear ();
1178
+ ArchitectureName.clear ();
1139
1179
if (ObjOrErr) {
1140
1180
std::unique_ptr<ObjectFile> Obj = std::move (ObjOrErr.get ());
1141
- if (moreThanOneArch)
1142
- outs () << " \n " ;
1143
- outs () << Obj->getFileName ();
1144
- if (isa<MachOObjectFile>(Obj.get ()) && moreThanOneArch)
1145
- outs () << " (for architecture " << I->getArchTypeName () << " )" ;
1146
- outs () << " :\n " ;
1147
- dumpSymbolNamesFromObject (Obj.get (), false );
1181
+ if (PrintFileName) {
1182
+ if (isa<MachOObjectFile>(Obj.get ()) && moreThanOneArch)
1183
+ ArchitectureName = I->getArchTypeName ();
1184
+ } else {
1185
+ if (moreThanOneArch)
1186
+ outs () << " \n " ;
1187
+ outs () << Obj->getFileName ();
1188
+ if (isa<MachOObjectFile>(Obj.get ()) && moreThanOneArch)
1189
+ outs () << " (for architecture " << I->getArchTypeName () << " )" ;
1190
+ outs () << " :\n " ;
1191
+ }
1192
+ dumpSymbolNamesFromObject (Obj.get (), false , ArchiveName,
1193
+ ArchitectureName);
1148
1194
} else if (!I->getAsArchive (A)) {
1149
1195
for (Archive::child_iterator AI = A->child_begin (), AE = A->child_end ();
1150
1196
AI != AE; ++AI) {
@@ -1153,15 +1199,22 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
1153
1199
if (ChildOrErr.getError ())
1154
1200
continue ;
1155
1201
if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get ())) {
1156
- outs () << " \n " << A->getFileName ();
1157
- if (isa<MachOObjectFile>(O)) {
1158
- outs () << " (" << O->getFileName () << " )" ;
1159
- if (moreThanOneArch)
1160
- outs () << " (for architecture " << I->getArchTypeName () << " )" ;
1161
- } else
1162
- outs () << " :" << O->getFileName ();
1163
- outs () << " :\n " ;
1164
- dumpSymbolNamesFromObject (O, false );
1202
+ if (PrintFileName) {
1203
+ ArchiveName = A->getFileName ();
1204
+ if (isa<MachOObjectFile>(O) && moreThanOneArch)
1205
+ ArchitectureName = I->getArchTypeName ();
1206
+ } else {
1207
+ outs () << " \n " << A->getFileName ();
1208
+ if (isa<MachOObjectFile>(O)) {
1209
+ outs () << " (" << O->getFileName () << " )" ;
1210
+ if (moreThanOneArch)
1211
+ outs () << " (for architecture " << I->getArchTypeName ()
1212
+ << " )" ;
1213
+ } else
1214
+ outs () << " :" << O->getFileName ();
1215
+ outs () << " :\n " ;
1216
+ }
1217
+ dumpSymbolNamesFromObject (O, false , ArchiveName, ArchitectureName);
1165
1218
}
1166
1219
}
1167
1220
}
0 commit comments