[llvm] r221899 - Fix a regression on the disassembling C API.
Kevin Enderby
enderby at apple.com
Thu Nov 13 10:07:04 PST 2014
Thanks Rafael!
On Nov 13, 2014, at 8:52 AM, Rafael Espindola <rafael.espindola at gmail.com> wrote:
> Author: rafael
> Date: Thu Nov 13 10:52:07 2014
> New Revision: 221899
>
> URL: http://llvm.org/viewvc/llvm-project?rev=221899&view=rev
> Log:
> Fix a regression on the disassembling C API.
>
> The fix is easy. Unfortunately, we had 0 tests, so adding one was somewhat
> complicated.
>
> Thanks to Kevin Enderby for the report.
>
> Added:
> llvm/trunk/unittests/MC/Disassembler.cpp
> Modified:
> llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
> llvm/trunk/unittests/MC/CMakeLists.txt
>
> Modified: llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp?rev=221899&r1=221898&r2=221899&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp (original)
> +++ llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp Thu Nov 13 10:52:07 2014
> @@ -253,7 +253,7 @@ size_t LLVMDisasmInstruction(LLVMDisasmC
> MCDisassembler::DecodeStatus S;
> SmallVector<char, 64> InsnStr;
> raw_svector_ostream Annotations(InsnStr);
> - S = DisAsm->getInstruction(Inst, Size, Data, 0,
> + S = DisAsm->getInstruction(Inst, Size, Data, PC,
> /*REMOVE*/ nulls(), Annotations);
> switch (S) {
> case MCDisassembler::Fail:
>
> Modified: llvm/trunk/unittests/MC/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/MC/CMakeLists.txt?rev=221899&r1=221898&r2=221899&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/MC/CMakeLists.txt (original)
> +++ llvm/trunk/unittests/MC/CMakeLists.txt Thu Nov 13 10:52:07 2014
> @@ -1,9 +1,12 @@
> set(LLVM_LINK_COMPONENTS
> + ${LLVM_TARGETS_TO_BUILD}
> MC
> + MCDisassembler
> Support
> )
>
> add_llvm_unittest(MCTests
> + Disassembler.cpp
> StringTableBuilderTest.cpp
> YAMLTest.cpp
> )
>
> Added: llvm/trunk/unittests/MC/Disassembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/MC/Disassembler.cpp?rev=221899&view=auto
> ==============================================================================
> --- llvm/trunk/unittests/MC/Disassembler.cpp (added)
> +++ llvm/trunk/unittests/MC/Disassembler.cpp Thu Nov 13 10:52:07 2014
> @@ -0,0 +1,62 @@
> +//===- llvm/unittest/Object/Disassembler.cpp ------------------------------===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#include "llvm-c/Disassembler.h"
> +#include "llvm/Support/TargetSelect.h"
> +#include "gtest/gtest.h"
> +
> +using namespace llvm;
> +
> +static const char *symbolLookupCallback(void *DisInfo, uint64_t ReferenceValue,
> + uint64_t *ReferenceType,
> + uint64_t ReferencePC,
> + const char **ReferenceName) {
> + *ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
> + return nullptr;
> +}
> +
> +TEST(Disassembler, Test1) {
> + llvm::InitializeAllTargetInfos();
> + llvm::InitializeAllTargetMCs();
> + llvm::InitializeAllDisassemblers();
> +
> + uint8_t Bytes[] = {0x90, 0x90, 0xeb, 0xfd};
> + uint8_t *BytesP = Bytes;
> + const char OutStringSize = 100;
> + char OutString[OutStringSize];
> + LLVMDisasmContextRef DCR = LLVMCreateDisasm("x86_64-pc-linux", nullptr, 0,
> + nullptr, symbolLookupCallback);
> + if (!DCR)
> + return;
> +
> + size_t InstSize;
> + unsigned NumBytes = sizeof(Bytes);
> + unsigned PC = 0;
> +
> + InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
> + OutStringSize);
> + EXPECT_EQ(InstSize, 1U);
> + EXPECT_EQ(StringRef(OutString), "\tnop");
> + PC += InstSize;
> + BytesP += InstSize;
> + NumBytes -= InstSize;
> +
> + InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
> + OutStringSize);
> + EXPECT_EQ(InstSize, 1U);
> + EXPECT_EQ(StringRef(OutString), "\tnop");
> + PC += InstSize;
> + BytesP += InstSize;
> + NumBytes -= InstSize;
> +
> + InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
> + OutStringSize);
> + EXPECT_EQ(InstSize, 2U);
> + EXPECT_EQ(StringRef(OutString), "\tjmp\t0x1");
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list