To build complex binding upon instruction trace, additional metadata 'instruction type' is needed. This diff has followings: - Add a flag -k / --kind for instruction dump - Remove SetGranularity and SetIgnoreErros from Trace cursor Sample output: ``` (lldb) thread trace dump instruction -k thread #1: tid = 3198805 libc.so.6`_IO_puts + 356 2107: 0x00007ffff7163594 ( return) retq 2106: 0x00007ffff7163592 ( other) popq %r13 2105: 0x00007ffff7163590 ( other) popq %r12 2104: 0x00007ffff716358f ( other) popq %rbp 2103: 0x00007ffff716358e ( other) popq %rbx 2102: 0x00007ffff716358c ( other) movl %ebx, %eax 2101: 0x00007ffff7163588 ( other) addq $0x8, %rsp 2100: 0x00007ffff7163570 ( cond jump) je 0x89588 ; <+344> 2099: 0x00007ffff716356e ( other) decl (%rdx) 2098: 0x00007ffff7163565 ( cond jump) je 0x8956e ; <+318> 2097: 0x00007ffff716355e ( other) cmpl $0x0, 0x33c02b(%rip) ; __libc_multiple_threads 2096: 0x00007ffff7163556 ( other) movq $0x0, 0x8(%rdx) 2095: 0x00007ffff7163554 ( cond jump) jne 0x89588 ; <+344> 2094: 0x00007ffff7163550 ( other) subl $0x1, 0x4(%rdx) 2093: 0x00007ffff7163549 ( other) movq 0x88(%rbp), %rdx 2092: 0x00007ffff7163547 ( cond jump) jne 0x89588 ; <+344> 2091: 0x00007ffff7163540 ( other) testl $0x8000, (%rbp) ; imm = 0x8000 2090: 0x00007ffff716353c ( other) cmovaq %rax, %rbx 2089: 0x00007ffff7163535 ( other) cmpq $0x7fffffff, %rbx ; imm = 0x7FFFFFFF 2088: 0x00007ffff7163530 ( other) movl $0x7fffffff, %eax ; imm = 0x7FFFFFFF ``` Reviewed By: wallace Differential Revision: https://reviews.llvm.org/D128477
92 lines
2.9 KiB
C++
92 lines
2.9 KiB
C++
//===-- TestArmv7Disassembly.cpp ------------------------------------------===//
|
|
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "lldb/Core/Address.h"
|
|
#include "lldb/Core/Disassembler.h"
|
|
#include "lldb/Utility/ArchSpec.h"
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "Plugins/Disassembler/LLVMC/DisassemblerLLVMC.h"
|
|
#include "llvm/Support/TargetSelect.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
class TestArmv7Disassembly : public testing::Test {
|
|
public:
|
|
static void SetUpTestCase();
|
|
static void TearDownTestCase();
|
|
|
|
// virtual void SetUp() override { }
|
|
// virtual void TearDown() override { }
|
|
|
|
protected:
|
|
};
|
|
|
|
void TestArmv7Disassembly::SetUpTestCase() {
|
|
llvm::InitializeAllTargets();
|
|
llvm::InitializeAllAsmPrinters();
|
|
llvm::InitializeAllTargetMCs();
|
|
llvm::InitializeAllDisassemblers();
|
|
DisassemblerLLVMC::Initialize();
|
|
}
|
|
|
|
void TestArmv7Disassembly::TearDownTestCase() {
|
|
DisassemblerLLVMC::Terminate();
|
|
}
|
|
|
|
TEST_F(TestArmv7Disassembly, TestCortexFPDisass) {
|
|
ArchSpec arch("armv7em--");
|
|
|
|
const unsigned num_of_instructions = 3;
|
|
uint8_t data[] = {
|
|
0x00, 0xee, 0x10, 0x2a, // 0xee002a10 : vmov s0, r2
|
|
0xb8, 0xee, 0xc0, 0x0b, // 0xeeb80bc0 : vcvt.f64.s32 d0, s0
|
|
0xb6, 0xee, 0x00, 0x0a, // 0xeeb60a00 : vmov.f32 s0, #5.000000e-01
|
|
};
|
|
|
|
// these can be disassembled by hand with llvm-mc, e.g.
|
|
//
|
|
// 0x00, 0xee, 0x10, 0x2a, // 0xee002a10 : vmov s0, r2
|
|
//
|
|
// echo 0x00 0xee 0x10 0x2a | llvm-mc -arch thumb -disassemble -mattr=+fp-armv8
|
|
// vmov s0, r2
|
|
|
|
DisassemblerSP disass_sp;
|
|
Address start_addr(0x100);
|
|
disass_sp = Disassembler::DisassembleBytes(arch, nullptr, nullptr, start_addr,
|
|
&data, sizeof (data), num_of_instructions, false);
|
|
|
|
// If we failed to get a disassembler, we can assume it is because
|
|
// the llvm we linked against was not built with the ARM target,
|
|
// and we should skip these tests without marking anything as failing.
|
|
|
|
if (disass_sp) {
|
|
const InstructionList inst_list (disass_sp->GetInstructionList());
|
|
EXPECT_EQ (num_of_instructions, inst_list.GetSize());
|
|
|
|
InstructionSP inst_sp;
|
|
const char *mnemonic;
|
|
ExecutionContext exe_ctx (nullptr, nullptr, nullptr);
|
|
inst_sp = inst_list.GetInstructionAtIndex (0);
|
|
mnemonic = inst_sp->GetMnemonic(&exe_ctx);
|
|
ASSERT_STREQ ("vmov", mnemonic);
|
|
|
|
inst_sp = inst_list.GetInstructionAtIndex (1);
|
|
mnemonic = inst_sp->GetMnemonic(&exe_ctx);
|
|
ASSERT_STREQ ("vcvt.f64.s32", mnemonic);
|
|
|
|
inst_sp = inst_list.GetInstructionAtIndex (2);
|
|
mnemonic = inst_sp->GetMnemonic(&exe_ctx);
|
|
ASSERT_STREQ ("vmov.f32", mnemonic);
|
|
}
|
|
}
|