Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 1 | //===-- llvm-objdump.h ----------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLVM_OBJDUMP_H |
| 11 | #define LLVM_OBJDUMP_H |
| 12 | |
| 13 | #include "llvm/ADT/StringRef.h" |
| 14 | #include "llvm/Support/CommandLine.h" |
| 15 | #include "llvm/Support/DataTypes.h" |
| 16 | #include "llvm/Support/MemoryObject.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | |
Michael J. Spencer | eef7b62 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 20 | namespace object { |
| 21 | class COFFObjectFile; |
Michael J. Spencer | b2c064c | 2013-01-06 03:56:49 +0000 | [diff] [blame] | 22 | class ObjectFile; |
Michael J. Spencer | eef7b62 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 23 | class RelocationRef; |
| 24 | } |
| 25 | class error_code; |
| 26 | |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 27 | extern cl::opt<std::string> TripleName; |
| 28 | extern cl::opt<std::string> ArchName; |
| 29 | |
| 30 | // Various helper functions. |
Michael J. Spencer | eef7b62 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 31 | bool error(error_code ec); |
| 32 | bool RelocAddressLess(object::RelocationRef a, object::RelocationRef b); |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 33 | void DumpBytes(StringRef bytes); |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 34 | void DisassembleInputMachO(StringRef Filename); |
Michael J. Spencer | eef7b62 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 35 | void printCOFFUnwindInfo(const object::COFFObjectFile* o); |
Michael J. Spencer | b2c064c | 2013-01-06 03:56:49 +0000 | [diff] [blame] | 36 | void printELFFileHeader(const object::ObjectFile *o); |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 37 | |
| 38 | class StringRefMemoryObject : public MemoryObject { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 39 | virtual void anchor(); |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 40 | StringRef Bytes; |
Ahmed Bougacha | 2c94d0f | 2013-05-24 00:39:57 +0000 | [diff] [blame^] | 41 | uint64_t Base; |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 42 | public: |
Ahmed Bougacha | 2c94d0f | 2013-05-24 00:39:57 +0000 | [diff] [blame^] | 43 | StringRefMemoryObject(StringRef bytes, uint64_t Base = 0) |
| 44 | : Bytes(bytes), Base(Base) {} |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 45 | |
Ahmed Bougacha | 2c94d0f | 2013-05-24 00:39:57 +0000 | [diff] [blame^] | 46 | uint64_t getBase() const { return Base; } |
Derek Schuff | adef06a | 2012-02-29 01:09:06 +0000 | [diff] [blame] | 47 | uint64_t getExtent() const { return Bytes.size(); } |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 48 | |
Derek Schuff | adef06a | 2012-02-29 01:09:06 +0000 | [diff] [blame] | 49 | int readByte(uint64_t Addr, uint8_t *Byte) const { |
Ahmed Bougacha | 2c94d0f | 2013-05-24 00:39:57 +0000 | [diff] [blame^] | 50 | if (Addr >= Base + getExtent() || Addr < Base) |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 51 | return -1; |
Ahmed Bougacha | 2c94d0f | 2013-05-24 00:39:57 +0000 | [diff] [blame^] | 52 | *Byte = Bytes[Addr - Base]; |
Benjamin Kramer | 0b8b771 | 2011-09-19 17:56:04 +0000 | [diff] [blame] | 53 | return 0; |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | } |
| 58 | |
| 59 | #endif |