llvm.org GIT mirror llvm / fd58e6e
Moved disassembler to libSystem git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33461 91177308-0d34-0410-b5e6-96231b3b80d8 Anton Korobeynikov 13 years ago
5 changed file(s) with 98 addition(s) and 99 deletion(s). Raw diff Collapse all Expand all
+0
-36
include/llvm/Support/Disassembler.h less more
None //===- llvm/Support/Disassembler.h ------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by Anton Korobeynikov and is distributed under the
5 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the necessary glue to call external disassembler
10 // libraries.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SUPPORT_DISASSEMBLER_H
15 #define LLVM_SUPPORT_DISASSEMBLER_H
16
17 #include "llvm/Support/DataTypes.h"
18 #include
19
20 namespace llvm {
21
22 namespace Disassembler {
23 enum Type {
24 X86_32,
25 X86_64,
26 Undefined
27 };
28 }
29
30
31 std::string disassembleBuffer(uint8_t* start, size_t length,
32 Disassembler::Type type, uint64_t pc);
33 }
34
35 #endif // LLVM_SUPPORT_DISASSEMBLER_H
0 //===- llvm/Support/Disassembler.h ------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by Anton Korobeynikov and is distributed under the
5 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the necessary glue to call external disassembler
10 // libraries.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_DISASSEMBLER_H
15 #define LLVM_SYSTEM_DISASSEMBLER_H
16
17 #include "llvm/Support/DataTypes.h"
18 #include
19
20 namespace llvm {
21 namespace sys {
22
23 /// This function provides some "glue" code to call external disassembler
24 /// libraries.
25 std::string disassembleBuffer(uint8_t* start, size_t length, uint64_t pc = 0);
26
27 }
28 }
29
30 #endif // LLVM_SYSTEM_DISASSEMBLER_H
2626 #include "llvm/Target/TargetJITInfo.h"
2727 #include "llvm/Target/TargetMachine.h"
2828 #include "llvm/Support/Debug.h"
29 #include "llvm/Support/Disassembler.h"
3029 #include "llvm/Support/MutexGuard.h"
30 #include "llvm/System/Disassembler.h"
3131 #include "llvm/ADT/Statistic.h"
3232 #include "llvm/System/Memory.h"
3333 #include
867867
868868 #ifndef NDEBUG
869869 DOUT << "Disassembled code:\n"
870 #if defined(__i386__)
871 << disassembleBuffer(FnStart, FnEnd-FnStart,
872 Disassembler::X86_32, (uint32_t)FnStart);
873 #elif defined(__amd64__) || defined(__x86_64__)
874 << disassembleBuffer(FnStart, FnEnd-FnStart,
875 Disassembler::X86_64, (uint64_t)FnStart);
876 #else
877 << "N/A\n";
878 #endif
870 << sys::disassembleBuffer(FnStart, FnEnd-FnStart, (uintptr_t)FnStart);
879871 #endif
880872
881873 return false;
+0
-53
lib/Support/Disassembler.cpp less more
None //===- lib/Support/Disassembler.cpp -----------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by Anton Korobeynikov and is distributed under the
5 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the necessary glue to call external disassembler
10 // libraries.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Config/config.h"
15 #include "llvm/Support/Disassembler.h"
16
17 #include
18 #include
19 #include
20 #include
21
22 #if USE_UDIS86
23 #include
24 #endif
25
26 using namespace llvm;
27
28 std::string llvm::disassembleBuffer(uint8_t* start, size_t length,
29 Disassembler::Type type, uint64_t pc) {
30 std::stringstream res;
31
32 if (type == Disassembler::X86_32 || type == Disassembler::X86_64) {
33 #if USE_UDIS86
34 ud_t ud_obj;
35
36 ud_init(&ud_obj);
37 ud_set_input_buffer(&ud_obj, start, length);
38 ud_set_mode(&ud_obj, (type == Disassembler::X86_32 ? 32 : 64));
39 ud_set_pc(&ud_obj, pc);
40 ud_set_syntax(&ud_obj, UD_SYN_ATT);
41
42 res << std::setbase(16)
43 << std::setw((type == Disassembler::X86_32 ? 8 : 16));
44
45 while (ud_disassemble(&ud_obj)) {
46 res << ud_insn_off(&ud_obj) << ":\t" << ud_insn_asm(&ud_obj) << "\n";
47 }
48 #endif
49 }
50
51 return res.str();
52 }
0 //===- lib/System/Disassembler.cpp ------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by Anton Korobeynikov and is distributed under the
5 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the necessary glue to call external disassembler
10 // libraries.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Config/config.h"
15 #include "llvm/System/Disassembler.h"
16
17 #include
18 #include
19 #include
20 #include
21
22 #if USE_UDIS86
23 #include
24 #endif
25
26 using namespace llvm;
27
28 std::string llvm::sys::disassembleBuffer(uint8_t* start, size_t length,
29 uint64_t pc) {
30 std::stringstream res;
31
32 #if defined (__i386__) || defined (__amd64__) || defined (__x86_64__)
33 unsigned bits;
34 # if defined(__i386__)
35 bits = 32;
36 # else
37 bits = 64;
38 # endif
39
40 # if USE_UDIS86
41 ud_t ud_obj;
42
43 ud_init(&ud_obj);
44 ud_set_input_buffer(&ud_obj, start, length);
45 ud_set_mode(&ud_obj, bits);
46 ud_set_pc(&ud_obj, pc);
47 ud_set_syntax(&ud_obj, UD_SYN_ATT);
48
49 res << std::setbase(16)
50 << std::setw(bits/4);
51
52 while (ud_disassemble(&ud_obj)) {
53 res << ud_insn_off(&ud_obj) << ":\t" << ud_insn_asm(&ud_obj) << "\n";
54 }
55 # else
56 res << "No disassembler available. See configure help for avaiable options.\n";
57 # endif
58
59 #else
60 res << "No disassembler available. See configure help for avaiable options.\n";
61 #endif
62
63 return res.str();
64 }