blob: 3c62240f8f56e52ecb928fbb64bf6acb51349e91 [file] [log] [blame]
Benjamin Kramer0b8b7712011-09-19 17:56:04 +00001//===-- 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
18namespace llvm {
19
Michael J. Spencereef7b622012-12-05 20:12:35 +000020namespace object {
21 class COFFObjectFile;
Michael J. Spencerb2c064c2013-01-06 03:56:49 +000022 class ObjectFile;
Michael J. Spencereef7b622012-12-05 20:12:35 +000023 class RelocationRef;
24}
25class error_code;
26
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000027extern cl::opt<std::string> TripleName;
28extern cl::opt<std::string> ArchName;
29
30// Various helper functions.
Michael J. Spencereef7b622012-12-05 20:12:35 +000031bool error(error_code ec);
32bool RelocAddressLess(object::RelocationRef a, object::RelocationRef b);
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000033void DumpBytes(StringRef bytes);
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000034void DisassembleInputMachO(StringRef Filename);
Michael J. Spencereef7b622012-12-05 20:12:35 +000035void printCOFFUnwindInfo(const object::COFFObjectFile* o);
Michael J. Spencerb2c064c2013-01-06 03:56:49 +000036void printELFFileHeader(const object::ObjectFile *o);
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000037
38class StringRefMemoryObject : public MemoryObject {
David Blaikie2d24e2a2011-12-20 02:50:00 +000039 virtual void anchor();
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000040 StringRef Bytes;
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +000041 uint64_t Base;
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000042public:
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +000043 StringRefMemoryObject(StringRef bytes, uint64_t Base = 0)
44 : Bytes(bytes), Base(Base) {}
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000045
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +000046 uint64_t getBase() const { return Base; }
Derek Schuffadef06a2012-02-29 01:09:06 +000047 uint64_t getExtent() const { return Bytes.size(); }
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000048
Derek Schuffadef06a2012-02-29 01:09:06 +000049 int readByte(uint64_t Addr, uint8_t *Byte) const {
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +000050 if (Addr >= Base + getExtent() || Addr < Base)
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000051 return -1;
Ahmed Bougacha2c94d0f2013-05-24 00:39:57 +000052 *Byte = Bytes[Addr - Base];
Benjamin Kramer0b8b7712011-09-19 17:56:04 +000053 return 0;
54 }
55};
56
57}
58
59#endif