Skip to content

Commit c8a3adc

Browse files
committed
Check during configure whether decode() returns an Instruction::Ptr or an Instruction
1 parent 8abad7b commit c8a3adc

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

config/macros.m4

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,40 @@ AC_DEFUN([AX_PROG_DYNINST],
18561856
CPPFLAGS="${CPPFLAGS} -I${DYNINST_INCLUDES} -I${BOOST_HOME}/include"
18571857
AC_CHECK_HEADERS([BPatch.h], [], [DYNINST_INSTALLED="no"])
18581858
1859+
AC_MSG_CHECKING([whether DynInst uses Instruction::Ptr])
1860+
AC_COMPILE_IFELSE(
1861+
[AC_LANG_PROGRAM(
1862+
[[#include <InstructionDecoder.h>]],
1863+
[[
1864+
InstructionAPI::InstructionDecoder dec((unsigned char*)nullptr,0,Arch_x86);
1865+
InstructionAPI::Instruction insn = dec.decode();
1866+
insn.isValid();
1867+
]]
1868+
)
1869+
],
1870+
[dyninst_decode_returns_instr_ptr="no"],
1871+
[AC_COMPILE_IFELSE(
1872+
[AC_LANG_PROGRAM(
1873+
[[#include <InstructionDecoder.h>]],
1874+
[[
1875+
InstructionAPI::InstructionDecoder dec((unsigned char*)nullptr,0,Arch_x86);
1876+
InstructionAPI::Instruction::Ptr insn = dec.decode();
1877+
insn->isValid();
1878+
]]
1879+
)
1880+
],
1881+
[dyninst_decode_returns_instr_ptr="yes"],
1882+
[dyninst_decode_returns_instr_ptr="unknown"]
1883+
)
1884+
]
1885+
)
1886+
AC_MSG_RESULT([$dyninst_decode_returns_instr_ptr])
1887+
AS_IF([test "$dyninst_decode_returns_instr_ptr" = "yes"],
1888+
[AC_DEFINE([DYNINST_DECODE_RETURNS_PTR], 1, [Define to 1 if DYNINST decoder's function decode() return value is of type Intruction::Ptr])],
1889+
[test "$dyninst_decode_returns_instr_ptr" = "unknown"],
1890+
[AC_MSG_ERROR([Unable to determine whether DynInst uses Instruction::Ptr or not])]
1891+
)
1892+
18591893
AC_SUBST(DYNINST_CXXFLAGS)
18601894
AC_SUBST(DYNINST_CPPFLAGS)
18611895

src/launcher/dyninst/commonSnippets.C

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,17 @@ string decodeBasicBlocks(BPatch_function * function, string routine)
482482
ParseAPI::Block* b = ParseAPI::convert(block);
483483
void * buf = b->region()->getPtrToInstruction(b->start());
484484
InstructionAPI::InstructionDecoder dec((unsigned char*)buf,b->size(),b->region()->getArch());
485+
#if defined(DYNINST_DECODE_RETURNS_PTR)
486+
InstructionAPI::Instruction::Ptr insn;
487+
while((insn = dec.decode())) {
488+
res <<loop_name<<"# "<<line++<<": "<< insn->format() << endl;
489+
}
490+
#else
485491
InstructionAPI::Instruction insn;
486492
while((insn = dec.decode()).isValid()) {
487493
res <<loop_name<<"# "<<line++<<": "<< insn.format() << endl;
488494
}
495+
#endif // defined(DYNINST_DECODE_RETURNS_PTR)
489496
}
490497
return res.str();
491498
}

0 commit comments

Comments
 (0)