1 //===- lib/System/Disassembler.cpp ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Anton Korobeynikov and is distributed under the
6 // University of Illinois Open Source 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 std::string llvm::sys::disassembleBuffer(uint8_t* start, size_t length,
31 std::stringstream res;
33 #if defined (__i386__) || defined (__amd64__) || defined (__x86_64__)
35 # if defined(__i386__)
45 ud_set_input_buffer(&ud_obj, start, length);
46 ud_set_mode(&ud_obj, bits);
47 ud_set_pc(&ud_obj, pc);
48 ud_set_syntax(&ud_obj, UD_SYN_ATT);
50 res << std::setbase(16)
53 while (ud_disassemble(&ud_obj)) {
54 res << ud_insn_off(&ud_obj) << ":\t" << ud_insn_asm(&ud_obj) << "\n";
57 res << "No disassembler available. See configure help for avaiable options.\n";
61 res << "No disassembler available. See configure help for avaiable options.\n";