Always print the disassembler output to file.
It will be better to print the disassembler output to a file
instead of stdout, since the stdout will be dropped by default.
Even if we have "setprop log.redirect-stdio true", you will
find out the output will be messed up by other messages.
Change-Id: I0fc02b082a5a3dff22f8b1ea5809562810a20915
diff --git a/Android.mk b/Android.mk
index b45d990..b7c9258 100644
--- a/Android.mk
+++ b/Android.mk
@@ -37,7 +37,6 @@
libbcc_USE_MCJIT := $(call libbcc_GET_CONFIG,USE_MCJIT)
libbcc_USE_CACHE := $(call libbcc_GET_CONFIG,USE_CACHE)
libbcc_USE_DISASSEMBLER := $(call libbcc_GET_CONFIG,USE_DISASSEMBLER)
-libbcc_USE_DISASSEMBLER_FILE := $(call libbcc_GET_CONFIG,USE_DISASSEMBLER_FILE)
libbcc_USE_LIBBCC_SHA1SUM := $(call libbcc_GET_CONFIG,USE_LIBBCC_SHA1SUM)
# Source Files
diff --git a/Config.h b/Config.h
index 12e2d7e..fa7314e 100644
--- a/Config.h
+++ b/Config.h
@@ -21,7 +21,6 @@
#define DEBUG_OLD_JIT_DISASSEMBLE 0
#define DEBUG_MCJIT_DISASSEMBLE 0
-#define USE_DISASSEMBLER_FILE 0
#define DEBUG_OLD_JIT_DISASSEMBLER_FILE "/data/local/tmp/oldjit-dis.s"
#define DEBUG_MCJIT_DISASSEMBLER_FILE "/data/local/tmp/mcjit-dis.s"
diff --git a/lib/Disassembler/Disassembler.cpp b/lib/Disassembler/Disassembler.cpp
index 29eecc7..1ecf726 100644
--- a/lib/Disassembler/Disassembler.cpp
+++ b/lib/Disassembler/Disassembler.cpp
@@ -18,6 +18,7 @@
#include "Config.h"
+#include "DebugHelper.h"
#include "ExecutionEngine/Compiler.h"
#include "llvm/MC/MCAsmInfo.h"
@@ -88,23 +89,20 @@
std::string const &Name,
unsigned char const *Func,
size_t FuncSize) {
- llvm::raw_ostream *OS;
-#if USE_DISASSEMBLER_FILE
std::string ErrorInfo;
- OS = new llvm::raw_fd_ostream(OutputFileName, ErrorInfo,
- llvm::raw_fd_ostream::F_Append);
- if (!ErrorInfo.empty()) { // some errors occurred
- // LOGE("Error in creating disassembly file");
- delete OS;
+ // Open the disassembler output file
+ llvm::raw_fd_ostream OS(OutputFileName, ErrorInfo,
+ llvm::raw_fd_ostream::F_Append);
+
+ if (!ErrorInfo.empty()) {
+ LOGE("Unable to open disassembler output file: %s\n", OutputFileName);
return;
}
-#else
- OS = &llvm::outs();
-#endif
- *OS << "Disassembled code: " << Name << "\n";
+ // Disassemble the given function
+ OS << "Disassembled code: " << Name << "\n";
const llvm::MCAsmInfo *AsmInfo;
const llvm::MCDisassembler *Disassmbler;
@@ -126,30 +124,28 @@
if (Disassmbler->getInstruction(Inst, Size, *BufferMObj, Index,
/* REMOVED */ llvm::nulls())) {
- OS->indent(4);
- OS->write("0x", 2);
- OS->write_hex((uint32_t)Func + Index);
- OS->write(": 0x", 4);
- OS->write_hex(*(uint32_t *)(Func + Index));
- IP->printInst(&Inst, *OS);
- *OS << "\n";
+ OS.indent(4);
+ OS.write("0x", 2);
+ OS.write_hex((uint32_t)Func + Index);
+ OS.write(": 0x", 4);
+ OS.write_hex(*(uint32_t *)(Func + Index));
+ IP->printInst(&Inst, OS);
+ OS << "\n";
} else {
if (Size == 0)
Size = 1; // skip illegible bytes
}
}
- *OS << "\n";
+ OS << "\n";
+
delete BufferMObj;
delete AsmInfo;
delete Disassmbler;
delete IP;
-#if USE_DISASSEMBLER_FILE
- ((llvm::raw_fd_ostream*)OS)->close();
- delete OS;
-#endif
+ OS.close();
}
} // namespace bcc