1 //===- lib/System/Disassembler.cpp ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the necessary glue to call external disassembler
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Config/config.h"
16 #include "llvm/System/Disassembler.h"
29 bool llvm::sys::hasDisassembler()
31 #if defined (__i386__) || defined (__amd64__) || defined (__x86_64__)
32 // We have option to enable udis86 library.
43 std::string
llvm::sys::disassembleBuffer(uint8_t* start
, size_t length
,
45 std::stringstream res
;
47 #if defined (__i386__) || defined (__amd64__) || defined (__x86_64__)
49 # if defined(__i386__)
59 ud_set_input_buffer(&ud_obj
, start
, length
);
60 ud_set_mode(&ud_obj
, bits
);
61 ud_set_pc(&ud_obj
, pc
);
62 ud_set_syntax(&ud_obj
, UD_SYN_ATT
);
64 res
<< std::setbase(16)
67 while (ud_disassemble(&ud_obj
)) {
68 res
<< ud_insn_off(&ud_obj
) << ":\t" << ud_insn_asm(&ud_obj
) << "\n";
71 res
<< "No disassembler available. See configure help for options.\n";
75 res
<< "No disassembler available. See configure help for options.\n";