aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.h
AgeCommit message (Collapse)AuthorFilesLines
2016-04-18[NFC] Header cleanupMehdi Amini1-1/+2
Removed some unused headers, replaced some headers with forward class declarations. Found using simple scripts like this one: clear && ack --cpp -l '#include "llvm/ADT/IndexedMap.h"' | xargs grep -L 'IndexedMap[<]' | xargs grep -n --color=auto 'IndexedMap' Patch by Eugene Kosov <claprix@yandex.ru> Differential Revision: http://reviews.llvm.org/D19219 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266595
2016-04-06Thread Expected<...> up from createMachOObjectFile() to allow llvm-objdump ↵Kevin Enderby1-0/+1
to produce a real error message Produce the first specific error message for a malformed Mach-O file describing the problem instead of the generic message for object_error::parse_failed of "Invalid data was encountered while parsing the file”.  Many more good error messages will follow after this first one. This is built on Lang Hames’ great work of adding the ’Error' class for structured error handling and threading Error through MachOObjectFile construction. And making createMachOObjectFile return Expected<...> . So to to get the error to the llvm-obdump tool, I changed the stack of these methods to also return Expected<...> : object::ObjectFile::createObjectFile() object::SymbolicFile::createSymbolicFile() object::createBinary() Then finally in ParseInputMachO() in MachODump.cpp the error can be reported and the specific error message can be printed in llvm-objdump and can be seen in the existing test case for the existing malformed binary but with the updated error message. Converting these interfaces to Expected<> from ErrorOr<> does involve touching a number of places. To contain the changes for now use of errorToErrorCode() and errorOrToExpected() are used where the callers are yet to be converted. Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values. So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: “// TODO: Actually report errors helpfully” and a call something like consumeError(ObjOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. Note there is one fix also needed to lld/COFF/InputFiles.cpp that goes along with this that I will commit right after this. So expect lld not to built after this commit and before the next one. llvm-svn: 265606
2016-01-26Re-submit r256008 "Improve DWARFDebugFrame::parse to also handle __eh_frame."Igor Laevsky1-0/+2
Originally this change was causing failures on windows buildbots. But those problems were fixed in r258806. llvm-svn: 258811
2016-01-13For llvm-objdump, add the option -private-header (without the trailing ’s’)Kevin Enderby1-0/+2
to only print the first private header. Which for Mach-O files only prints the Mach header and not the subsequent load commands. Which is used by scripts to match what the darwin otool(1) with the -h flag does without the -l flag. For non-Mach-O files it has the same functionality as -private-headers (with the trailing ’s’). rdar://24158331 llvm-svn: 257548
2015-12-29[llvm-objdump] Mark noreturn function as such.Davide Italiano1-1/+2
Match attribute in the header to make MSVC happy. llvm-svn: 256560
2015-12-20[llvm-objdump] Move COFF function to where it belongs.Davide Italiano1-0/+1
Ideally much more stuff should be moved out of llvm-objdump.cpp, but that will happen later. llvm-svn: 256118
2015-12-18Revert "Improve DWARFDebugFrame::parse to also handle __eh_frame."Pete Cooper1-2/+0
This reverts commit r256008. Its breaking multiple buildbots, although works for me locally. llvm-svn: 256013
2015-12-18Improve DWARFDebugFrame::parse to also handle __eh_frame.Pete Cooper1-0/+2
LLVM MC has single methods which can handle the output of EH frame and DWARF CIE's and FDE's. This code improves DWARFDebugFrame::parse to do the same for parsing. This also allows llvm-objdump to support the --dwarf=frames option which objdump supports. This option dumps the .eh_frame section using the new code in DWARFDebugFrame::parse. http://reviews.llvm.org/D15535 Reviewed by Rafael Espindola. llvm-svn: 256008
2015-12-08[llvm-objdump/MachO] Don't cut'n'paste the same code over and over.Davide Italiano1-0/+1
Use the appropriate helper instead. llvm-svn: 254990
2015-08-05[llvm-objdump] Call exit(1) on error, i.e. fail early.Davide Italiano1-1/+1
Previously we kept going on partly corrupted input, which might result in garbage being printed, or even worse, random crashes. Rafael mentioned that this is the GNU behavior as well, but after some discussion we both agreed it's probably better to emit a reasonable error message and exit. As a side-effect of this commit, now we don't rely on global state for error codes anymore. objdump was the last tool in the toolchain which needed to be converted. Hopefully the old behavior won't sneak into the tree again. llvm-svn: 244019
2015-07-29[llvm-objdump] Merging MachO DumpSections in to FilterSections. Simplifying ↵Colin LeMahieu1-2/+1
some predicate logic. llvm-svn: 243556
2015-07-29[llvm-objdump] Added -j flag to filter sections that are operated on.Colin LeMahieu1-1/+2
llvm-svn: 243526
2015-07-23[llvm-objdump] Add -D and --disassemble-all flags that attempt disassembly ↵Colin LeMahieu1-1/+2
on all sections instead of just text sections. llvm-svn: 243041
2015-07-08llvm-objdump: Replace the -macho -raw option with a generic -raw-clang-astAdrian Prantl1-1/+2
option that works with all object container formats. Now that clang modules/PCH are object containers this option is useful to to construct pipes like llvm-objdump -raw-clang-ast foo.pcm | llvm-bcanalyzer - to inspect the AST contents in a PCH container. Will be tested via clang. Belatedly addresses review feedback for r233390. llvm-svn: 241659
2015-06-07[objdump] Moving PrintImmHex out of MachODump and in to llvm-objdump and ↵Colin LeMahieu1-0/+1
setting instprinter appropriately. llvm-svn: 239265
2015-05-28[llvm] Parameterizing the output stream for dumpbytes and outputting ↵Colin LeMahieu1-1/+0
directly to stream. llvm-svn: 238453
2015-04-01Add the option -objc-meta-data to llvm-objdump used with -macho toKevin Enderby1-1/+1
print the Objective-C runtime meta data for Mach-O files. There are three types of Objective-C runtime meta data, Objc2 64-bit, Objc2 32-bit and Objc1 32-bit. This prints the first of these types. The changes to print the others will follow next. llvm-svn: 233840
2015-03-27Add a -raw option to the -section mode of llvm-objdump.Adrian Prantl1-0/+1
llvm-svn: 233390
2015-03-18[Objdump] DumpBytes of uint8_t from ArrayRef<uint8_t> instead of char from ↵Colin LeMahieu1-1/+1
StringRef. Removing reinterpret_casts. llvm-svn: 232659
2015-03-17Add the option, -dis-symname to llvm-objdump used with -macho andKevin Enderby1-0/+1
-disassemble to disassemble just one symbol’s instructions. llvm-svn: 232503
2015-03-16Add the options, -dylibs-used and -dylib-id to llvm-objdump used with -machoKevin Enderby1-0/+2
to print the Mach-O dynamic shared libraries used by a linked image or the library id of a shared library. llvm-svn: 232406
2015-03-13Add the option, -non-verbose to llvm-objdump used with -macho to print thingsKevin Enderby1-0/+1
using numeric values and not their symbolic constant names. The routines that print Mach-O stuff already had a verbose parameter and this change is just changing the passing true to passing !NonVerbose. With just a couple of fixes and a bunch of test case updates. llvm-svn: 232182
2015-03-11Add the option, -info-plist to llvm-objdump used with -macho to print theKevin Enderby1-0/+1
Mach-O info plist section as strings. llvm-svn: 231974
2015-01-31Add the -section option to llvm-objdump used with -macho that takes the argumentKevin Enderby1-0/+1
segname,sectname to specify a Mach-O section to print. The printing is based on the section type or section attributes. The printing of the module initialization and termination section types is printed with this change. Printing of other section types will be added next. llvm-svn: 227649
2015-01-27dd the option, -link-opt-hints to llvm-objdump used with -macho to print theKevin Enderby1-0/+1
Mach-O AArch64 linker optimization hints for ADRP code optimization. llvm-svn: 227246
2015-01-23Add the option, -data-in-code, to llvm-objdump used with -macho to print the ↵Kevin Enderby1-0/+1
Mach-O data in code table. llvm-svn: 226921
2015-01-22Add the option, -indirect-symbols, used with -macho to print the Mach-O ↵Kevin Enderby1-0/+1
indirect symbol table to llvm-objdump. llvm-svn: 226848
2015-01-20For llvm-objdump, hook up existing options to work when using -macho (the ↵Kevin Enderby1-0/+9
Mach-O parser). llvm-svn: 226612
2015-01-15Add the option, -archive-headers, used with -macho to print the Mach-O ↵Kevin Enderby1-0/+1
archive headers to llvm-objdump. llvm-svn: 226228
2015-01-09Add the option, -universal-headers, used with -macho to print the Mach-O ↵Kevin Enderby1-0/+1
universal headers to llvm-objdump. llvm-svn: 225537
2015-01-07Slightly refactor things for llvm-objdump and the -macho option so it can be ↵Kevin Enderby1-1/+13
used with options other than just -disassemble so that universal files can be used with other options combined with -arch options. No functional change to existing options and use. One test case added for the additional functionality with a universal file an a -arch option. llvm-svn: 225383
2014-11-12Remove the now unused StringRefMemoryObject.h.Rafael Espindola1-1/+0
llvm-svn: 221755
2014-09-24Flush out enough of llvm-objdump’s SymbolizerSymbolLookUp() for Mach-O ↵Kevin Enderby1-0/+1
files to get the literal string “Hello world” printed as a comment on the instruction that loads the pointer to it. For now this is just for x86_64. So for object files with relocation entries it produces things like: leaq L_.str(%rip), %rax ## literal pool for: "Hello world\n" and similar for fully linked images like executables: leaq 0x4f(%rip), %rax ## literal pool for: "Hello world\n" Also to allow testing against darwin’s otool(1), I hooked up the existing -no-show-raw-insn option to the Mach-O parser code, added the new Mach-O only -full-leading-addr option to match otool(1)'s printing of addresses and also added the new -print-imm-hex option. llvm-svn: 218423
2014-09-16[llvm-objdump] for mach-o add -bind, -lazy-bind, and -weak-bind optionsNick Kledzik1-0/+3
This finishes the ability of llvm-objdump to print out all information from the LC_DYLD_INFO load command. The -bind option prints out symbolic references that dyld must resolve immediately. The -lazy-bind option prints out symbolc reference that are lazily resolved on first use. The -weak-bind option prints out information about symbols which dyld must try to coalesce across images. llvm-svn: 217853
2014-09-12[llvm-objdump] support -rebase option for mach-o to dump rebasing infoNick Kledzik1-0/+1
Similar to my previous -exports-trie option, the -rebase option dumps info from the LC_DYLD_INFO load command. The rebasing info is a list of the the locations that dyld needs to adjust if a mach-o image is not loaded at its preferred address. Since ASLR is now the default, images almost never load at their preferred address, and thus need to be rebased by dyld. llvm-svn: 217709
2014-08-30Object/llvm-objdump: allow dumping of mach-o exports trieNick Kledzik1-1/+1
MachOObjectFile in lib/Object currently has no support for parsing the rebase, binding, and export information from the LC_DYLD_INFO load command in final linked mach-o images. This patch adds support for parsing the exports trie data structure. It also adds an option to llvm-objdump to dump that export info. I did the exports parsing first because it is the hardest. The information is encoded in a trie structure, but the standard ObjectFile way to inspect content is through iterators. So I needed to make an iterator that would do a non-recursive walk through the trie and maintain the concatenation of edges needed for the current string prefix. I plan to add similar support in MachOObjectFile and llvm-objdump to parse/display the rebasing and binding info too. llvm-svn: 216808
2014-08-22Add the start of the support for llvm-objdump’s -private-headers for ↵Kevin Enderby1-0/+1
Mach-O files. This adds the printing of the mach header. Load command printing will be next. llvm-svn: 216285
2014-08-13Canonicalize header guards into a common format.Benjamin Kramer1-2/+2
Add header guards to files that were missing guards. Remove #endif comments as they don't seem common in LLVM (we can easily add them back if we decide they're useful) Changes made by clang-tidy with minor tweaks. llvm-svn: 215558
2014-08-06Add the -mcpu= option to llvm-objdump for use with the disassemblers.Kevin Enderby1-0/+2
Also make the disassembler created with the Mach-O parser (the -m option) pick up the Target specific attributes specified with -mattr option. llvm-svn: 215032
2014-08-01llvm-objdump: implement printing for MachO __compact_unwind info.Tim Northover1-0/+3
llvm-svn: 214509
2014-06-13Remove all uses of 'using std::error_code' from headers.Rafael Espindola1-3/+1
llvm-svn: 210866
2014-06-12Don't use 'using std::error_code' in include/llvm.Rafael Espindola1-0/+1
This should make sure that most new uses use the std prefix. llvm-svn: 210835
2014-06-11Use std::error_code instead of llvm::error_code.Rafael Espindola1-1/+0
The idea of this patch is to turn llvm/Support/system_error.h into a transitional header that just brings in the erorr_code api to the llvm namespace. I will remove it shortly afterwards. The cases where the general idea needed some tweaking: * std::errc is a namespace in msvc, so we cannot use "using std::errc". I could add an #ifdef, but there were not that many uses, so I just added std:: to them in this patch. * Template specialization had to be moved to the std namespace in this patch set already. * The msvc implementation of default_error_condition doesn't seem to provide the same transformations as we need. Not too surprising since the standard doesn't actually say what "equivalent" means. I fixed the problem by keeping our old mapping and using it at error_code construction time. Despite these shortcomings I think this is still a good thing. Some reasons: * The different implementations of system_error might improve over time. * It removes 925 lines of code from llvm already. * It removes 6313 bytes from the text segment of the clang binary when it is built with gcc and 2816 bytes when building with clang and libstdc++. llvm-svn: 210687
2013-09-27Re-submit r191472 with a fix for big endian.Rui Ueyama1-1/+2
llvm-objdump: Dump COFF import table if -private-headers option is given. llvm-svn: 191557
2013-09-27Revert "llvm-objdump: Dump COFF import table if -private-headers option is ↵Rui Ueyama1-2/+1
given." This reverts commit r191472 because it's failing on BE machine. llvm-svn: 191480
2013-09-27llvm-objdump: Dump COFF import table if -private-headers option is given.Rui Ueyama1-1/+2
This is a patch to add capability to llvm-objdump to dump COFF Import Table entries, so that we can write tests for LLD checking Import Table contents. llvm-objdump did not print anything but just file name if the format is COFF and -private-headers option is given. This is a patch adds capability for dumping DLL Import Table, which is specific to the COFF format. In this patch I defined a new iterator to iterate over import table entries. Also added a few functions to COFFObjectFile.cpp to access fields of the entry. Differential Revision: http://llvm-reviews.chandlerc.com/D1719 llvm-svn: 191472
2013-05-24MC: Disassembled CFG reconstruction.Ahmed Bougacha1-20/+1
This patch builds on some existing code to do CFG reconstruction from a disassembled binary: - MCModule represents the binary, and has a list of MCAtoms. - MCAtom represents either disassembled instructions (MCTextAtom), or contiguous data (MCDataAtom), and covers a specific range of addresses. - MCBasicBlock and MCFunction form the reconstructed CFG. An MCBB is backed by an MCTextAtom, and has the usual successors/predecessors. - MCObjectDisassembler creates a module from an ObjectFile using a disassembler. It first builds an atom for each section. It can also construct the CFG, and this splits the text atoms into basic blocks. MCModule and MCAtom were only sketched out; MCFunction and MCBB were implemented under the experimental "-cfg" llvm-objdump -macho option. This cleans them up for further use; llvm-objdump -d -cfg now generates graphviz files for each function found in the binary. In the future, MCObjectDisassembler may be the right place to do "intelligent" disassembly: for example, handling constant islands is just a matter of splitting the atom, using information that may be available in the ObjectFile. Also, better initial atom formation than just using sections is possible using symbols (and things like Mach-O's function_starts load command). This brings two minor regressions in llvm-objdump -macho -cfg: - The printing of a relocation's referenced symbol. - An annotation on loop BBs, i.e., which are their own successor. Relocation printing is replaced by the MCSymbolizer; the basic CFG annotation will be superseded by more related functionality. llvm-svn: 182628
2013-05-24Add MCSymbolizer for symbolic/annotated disassembly.Ahmed Bougacha1-4/+6
This is a basic first step towards symbolization of disassembled instructions. This used to be done using externally provided (C API) callbacks. This patch introduces: - the MCSymbolizer class, that mimics the same functions that were used in the X86 and ARM disassemblers to symbolize immediate operands and to annotate loads based off PC (for things like c string literals). - the MCExternalSymbolizer class, which implements the old C API. - the MCRelocationInfo class, which provides a way for targets to translate relocations (either object::RelocationRef, or disassembler C API VariantKinds) to MCExprs. - the MCObjectSymbolizer class, which does symbolization using what it finds in an object::ObjectFile. This makes simple symbolization (with no fancy relocation stuff) work for all object formats! - x86-64 Mach-O and ELF MCRelocationInfos. - A basic ARM Mach-O MCRelocationInfo, that provides just enough to support the C API VariantKinds. Most of what works in otool (the only user of the old symbolization API that I know of) for x86-64 symbolic disassembly (-tvV) works, namely: - symbol references: call _foo; jmp 15 <_foo+50> - relocations: call _foo-_bar; call _foo-4 - __cf?string: leaq 193(%rip), %rax ## literal pool for "hello" Stub support is the main missing part (because libObject doesn't know, among other things, about mach-o indirect symbols). As for the MCSymbolizer API, instead of relying on the disassemblers to call the tryAdding* methods, maybe this could be done automagically using InstrInfo? For instance, even though PC-relative LEAs are used to get the address of string literals in a typical Mach-O file, a MOV would be used in an ELF file. And right now, the explicit symbolization only recognizes PC-relative LEAs. InstrInfo should have already have most of what is needed to know what to symbolize, so this can definitely be improved. I'd also like to remove object::RelocationRef::getValueString (it seems only used by relocation printing in objdump), as simply printing the created MCExpr is definitely enough (and cleaner than string concats). llvm-svn: 182625
2013-01-06[objdump] Add --private-headers, -p.Michael J. Spencer1-0/+2
This currently prints the ELF program headers. llvm-svn: 171649
2012-12-05Add dump of Win64 EH unwind data.Michael J. Spencer1-0/+9
The new command line option -unwind-info dumps the Win64 EH unwind data to the console. This is a nice feature if you need to debug generated EH data (e.g. from LLVM). Includes a test case. Initial patch by João Matos, extensions and rework by Kai Nacke. llvm-svn: 169415