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