From: Saleem Abdulrasool Date: Mon, 14 Apr 2014 02:37:28 +0000 (+0000) Subject: tools: simplify symbol handling in objdump X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1b1e4e27e146ff4969767d32184ebb28b0bb3514;p=oota-llvm.git tools: simplify symbol handling in objdump Rather than switching behaviour on whether a previous symbol has an auxiliary symbol record for the next count of elements, simply iterate over the auxiliary symbols right after processing the current symbol entry. This makes the behaviour much simpler to follow and similar to llvm-readobj and yaml2obj. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206146 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 8d5035efcdf..aff83f0cbd1 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -664,14 +664,31 @@ static void PrintSectionContents(const ObjectFile *Obj) { static void PrintCOFFSymbolTable(const COFFObjectFile *coff) { const coff_file_header *header; - if (error(coff->getHeader(header))) return; - int aux_count = 0; - const coff_symbol *symbol = 0; - for (int i = 0, e = header->NumberOfSymbols; i != e; ++i) { - if (aux_count--) { - if (symbol->isSectionDefinition()) { + if (error(coff->getHeader(header))) + return; + + for (unsigned SI = 0, SE = header->NumberOfSymbols; SI != SE; ++SI) { + const coff_symbol *Symbol; + StringRef Name; + if (error(coff->getSymbol(SI, Symbol))) + return; + + if (error(coff->getSymbolName(Symbol, Name))) + return; + + outs() << "[" << format("%2d", SI) << "]" + << "(sec " << format("%2d", int(Symbol->SectionNumber)) << ")" + << "(fl 0x00)" // Flag bits, which COFF doesn't have. + << "(ty " << format("%3x", unsigned(Symbol->Type)) << ")" + << "(scl " << format("%3x", unsigned(Symbol->StorageClass)) << ") " + << "(nx " << unsigned(Symbol->NumberOfAuxSymbols) << ") " + << "0x" << format("%08x", unsigned(Symbol->Value)) << " " + << Name << "\n"; + + for (unsigned AI = 0, AE = Symbol->NumberOfAuxSymbols; AI < AE; ++AI, ++SI) { + if (Symbol->isSectionDefinition()) { const coff_aux_section_definition *asd; - if (error(coff->getAuxSymbol(i, asd))) + if (error(coff->getAuxSymbol(SI + 1, asd))) return; outs() << "AUX " @@ -683,31 +700,17 @@ static void PrintCOFFSymbolTable(const COFFObjectFile *coff) { << format("assoc %d comdat %d\n" , unsigned(asd->Number) , unsigned(asd->Selection)); - } else if (symbol->isFileRecord()) { + } else if (Symbol->isFileRecord()) { const coff_aux_file *AF; - if (error(coff->getAuxSymbol(i, AF))) + if (error(coff->getAuxSymbol(SI + 1, AF))) return; - StringRef Name(AF->FileName, (aux_count + 1) * COFF::SymbolSize); + StringRef Name(AF->FileName, + Symbol->NumberOfAuxSymbols * COFF::SymbolSize); outs() << "AUX " << Name.rtrim(StringRef("\0", 1)) << '\n'; - i = i + aux_count; - aux_count = 0; } else { outs() << "AUX Unknown\n"; } - } else { - StringRef name; - if (error(coff->getSymbol(i, symbol))) return; - if (error(coff->getSymbolName(symbol, name))) return; - outs() << "[" << format("%2d", i) << "]" - << "(sec " << format("%2d", int(symbol->SectionNumber)) << ")" - << "(fl 0x00)" // Flag bits, which COFF doesn't have. - << "(ty " << format("%3x", unsigned(symbol->Type)) << ")" - << "(scl " << format("%3x", unsigned(symbol->StorageClass)) << ") " - << "(nx " << unsigned(symbol->NumberOfAuxSymbols) << ") " - << "0x" << format("%08x", unsigned(symbol->Value)) << " " - << name << "\n"; - aux_count = symbol->NumberOfAuxSymbols; } } }