llvm-project/llvm/lib
Greg Clayton bde0a1632b Added the ability to dump hex bytes easily into a raw_ostream.
Unit tests were added to verify this functionality keeps working correctly.

Example output for raw hex bytes:
llvm::ArrayRef<uint8_t> Bytes = ...;
llvm::outs() << format_hex_bytes(Bytes);
554889e5 4881ec70 04000048 8d051002
00004c8d 05fd0100 004c8b0d d0020000

Example output for raw hex bytes with offsets:
llvm::outs() << format_hex_bytes(Bytes, 0x100000d10);
0x0000000100000d10: 554889e5 4881ec70 04000048 8d051002
0x0000000100000d20: 00004c8d 05fd0100 004c8b0d d0020000

Example output for raw hex bytes with ASCII with offsets:
llvm::outs() << format_hex_bytes_with_ascii(Bytes, 0x100000d10);
0x0000000100000d10: 554889e5 4881ec70 04000048 8d051002 |UH.?H.?p...H....|
0x0000000100000d20: 00004c8d 05fd0100 004c8b0d d0020000 |..L..?...L..?...|

The default groups bytes into 4 byte groups, but this can be changed to 1 byte:
llvm::outs() << format_hex_bytes(Bytes, 0x100000d10, 16 /*NumPerLine*/, 1 /*ByteGroupSize*/);
0x0000000100000d10: 55 48 89 e5 48 81 ec 70 04 00 00 48 8d 05 10 02
0x0000000100000d20: 00 00 4c 8d 05 fd 01 00 00 4c 8b 0d d0 02 00 00

llvm::outs() << format_hex_bytes(Bytes, 0x100000d10, 16 /*NumPerLine*/, 2 /*ByteGroupSize*/);
0x0000000100000d10: 5548 89e5 4881 ec70 0400 0048 8d05 1002
0x0000000100000d20: 0000 4c8d 05fd 0100 004c 8b0d d002 0000

llvm::outs() << format_hex_bytes(Bytes, 0x100000d10, 8 /*NumPerLine*/, 1 /*ByteGroupSize*/);
0x0000000100000d10: 55 48 89 e5 48 81 ec 70
0x0000000100000d18: 04 00 00 48 8d 05 10 02
0x0000000100000d20: 00 00 4c 8d 05 fd 01 00
0x0000000100000d28: 00 4c 8b 0d d0 02 00 00

https://reviews.llvm.org/D26405

llvm-svn: 286316
2016-11-09 00:15:54 +00:00
..
Analysis [ThinLTO] Prevent exporting of locals used/defined in module level asm 2016-11-08 21:53:35 +00:00
AsmParser Add DWARF debug info support for C++11 inline namespaces. 2016-11-03 19:42:02 +00:00
Bitcode [ThinLTO] Prevent exporting of locals used/defined in module level asm 2016-11-08 21:53:35 +00:00
CodeGen [CodeView] Hook up CodeViewRecordIO to type serialization path. 2016-11-08 22:24:53 +00:00
DebugInfo Fix some size_t / uint32_t ambiguity errors. 2016-11-08 22:30:11 +00:00
Demangle Avoid using alignas and constexpr. 2016-09-06 20:36:24 +00:00
ExecutionEngine Fix cross-endianness RuntimeDyld relocation for ARM 2016-10-20 22:15:56 +00:00
Fuzzer [libFuzzer] fix -error_exitcode=N, now with a test 2016-11-03 19:31:18 +00:00
IR [TBAA] Drop support for "old style" scalar TBAA tags 2016-11-08 20:46:01 +00:00
IRReader IR, Bitcode: Change bitcode reader to no longer own its memory buffer. 2016-11-08 06:03:43 +00:00
LTO Don't store Twine in a local variable. 2016-11-08 19:43:56 +00:00
LibDriver Object: Replace NewArchiveIterator with a simpler NewArchiveMember class. NFCI. 2016-06-29 22:27:42 +00:00
LineEditor
Linker Typo: nomed struct -> named struct 2016-10-19 20:10:03 +00:00
MC Fix 24560: assembler does not share constant pool for same constants 2016-11-04 19:17:32 +00:00
Object [ThinLTO] Prevent exporting of locals used/defined in module level asm 2016-11-08 21:53:35 +00:00
ObjectYAML Fix Clang-tidy readability-redundant-string-cstr warnings 2016-11-02 16:43:50 +00:00
Option Generalize ArgList::AddAllArgs more 2016-09-29 19:47:58 +00:00
Passes Conditionally eliminate library calls where the result value is not used 2016-10-18 21:36:27 +00:00
ProfileData Retire llvm::alignOf in favor of C++11 alignof. 2016-10-20 15:02:18 +00:00
Support Added the ability to dump hex bytes easily into a raw_ostream. 2016-11-09 00:15:54 +00:00
TableGen Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes. 2016-08-23 17:14:32 +00:00
Target AArch64DeadRegisterDefinitionsPass: Fix Changed flag 2016-11-08 20:59:03 +00:00
Transforms [InstCombine] fix profitability equation for max-of-nots transform 2016-11-09 00:13:11 +00:00
CMakeLists.txt Try to fix a circular dependency in the modules build. 2016-09-06 20:16:19 +00:00
LLVMBuild.txt Add an c++ itanium demangler to llvm. 2016-09-06 19:16:48 +00:00