void MachODebugMapParser::dumpSymTabEntry(raw_ostream &OS, uint64_t Index, uint32_t StringIndex, uint8_t Type, uint8_t SectionIndex, uint16_t Flags, uint64_t Value) { // Index OS << '[' << format_decimal(Index, 6) << "] " // n_strx << format_hex_no_prefix(StringIndex, 8) << ' ' // n_type... << format_hex_no_prefix(Type, 2) << " ("; if (Type & MachO::N_STAB) OS << left_justify(getDarwinStabString(Type), 13); else { if (Type & MachO::N_PEXT) OS << "PEXT "; else OS << " "; switch (Type & MachO::N_TYPE) { case MachO::N_UNDF: // 0x0 undefined, n_sect == NO_SECT OS << "UNDF"; break; case MachO::N_ABS: // 0x2 absolute, n_sect == NO_SECT OS << "ABS "; break; case MachO::N_SECT: // 0xe defined in section number n_sect OS << "SECT"; break; case MachO::N_PBUD: // 0xc prebound undefined (defined in a dylib) OS << "PBUD"; break; case MachO::N_INDR: // 0xa indirect OS << "INDR"; break; default: OS << format_hex_no_prefix(Type, 2) << " "; break; } if (Type & MachO::N_EXT) OS << " EXT"; else OS << " "; } OS << ") " // n_sect << format_hex_no_prefix(SectionIndex, 2) << " " // n_desc << format_hex_no_prefix(Flags, 4) << " " // n_value << format_hex_no_prefix(Value, 16); const char *Name = &MainBinaryStrings.data()[StringIndex]; if (Name && Name[0]) OS << " '" << Name << "'"; OS << "\n"; }
void ObjDumper::SectionHexDump(StringRef SecName, const uint8_t *Section, size_t Size) { const uint8_t *SecContent = Section; const uint8_t *SecEnd = Section + Size; W.startLine() << "Hex dump of section '" << SecName << "':\n"; for (const uint8_t *SecPtr = SecContent; SecPtr < SecEnd; SecPtr += 16) { const uint8_t *TmpSecPtr = SecPtr; uint8_t i; uint8_t k; W.startLine() << format_hex(SecPtr - SecContent, 10); W.startLine() << ' '; for (i = 0; TmpSecPtr < SecEnd && i < 4; ++i) { for (k = 0; TmpSecPtr < SecEnd && k < 4; k++, TmpSecPtr++) { uint8_t Val = *(reinterpret_cast<const uint8_t *>(TmpSecPtr)); W.startLine() << format_hex_no_prefix(Val, 2); } W.startLine() << ' '; } // We need to print the correct amount of spaces to match the format. // We are adding the (4 - i) last rows that are 8 characters each. // Then, the (4 - i) spaces that are in between the rows. // Least, if we cut in a middle of a row, we add the remaining characters, // which is (8 - (k * 2)) if (i < 4) W.startLine() << format("%*c", (4 - i) * 8 + (4 - i) + (8 - (k * 2)), ' '); TmpSecPtr = SecPtr; for (i = 0; TmpSecPtr + i < SecEnd && i < 16; ++i) { if (isprint(TmpSecPtr[i])) W.startLine() << TmpSecPtr[i]; else W.startLine() << '.'; } W.startLine() << '\n'; } }
const std::string to_hexString(uint64_t Value, bool UpperCase) { std::string number; llvm::raw_string_ostream stream(number); stream << format_hex_no_prefix(Value, 1, UpperCase); return stream.str(); }