Skip to content

Commit

Permalink
Remove extra code.
Browse files Browse the repository at this point in the history
  • Loading branch information
yomaytk committed Sep 28, 2024
1 parent be44f3b commit f77f741
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 92 deletions.
2 changes: 0 additions & 2 deletions backend/remill/include/remill/BC/HelperMacro.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once

// #define LIFT_DEBUG 1
// #define LIFT_CALLSTACK_DEBUG 1
// #define LIFT_INSN_DEBUG 1
// #define LIFT_MEMORY_VALUE_CHANGE 1
// #define ELFCONV_SYSCALL_DEBUG 1

Expand Down
5 changes: 1 addition & 4 deletions backend/remill/include/remill/BC/InstructionLifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,12 @@ class InstructionLifterIntf : public OperandLifter {
// this instruction will execute within the delay slot of another instruction.
virtual LiftStatus LiftIntoBlock(Instruction &inst, llvm::BasicBlock *block,
llvm::Value *state_ptr, BBRegInfoNode *bb_reg_info_node,
uint64_t debug_insn_addr = UINT64_MAX,
bool is_delayed = false) = 0;

// Lift a single instruction into a basic block. `is_delayed` signifies that
// this instruction will execute within the delay slot of another instruction.
LiftStatus LiftIntoBlock(Instruction &inst, llvm::BasicBlock *block,
BBRegInfoNode *bb_reg_info_node, uint64_t debug_insn_addr = UINT64_MAX,
bool is_delayed = false);
BBRegInfoNode *bb_reg_info_node, bool is_delayed = false);
};

// Wraps the process of lifting an instruction into a block. This resolves
Expand All @@ -246,7 +244,6 @@ class InstructionLifter : public InstructionLifterIntf {
// this instruction will execute within the delay slot of another instruction.
virtual LiftStatus LiftIntoBlock(Instruction &inst, llvm::BasicBlock *block,
llvm::Value *state_ptr, BBRegInfoNode *bb_reg_info_node,
uint64_t debug_insn_addr = UINT64_MAX,
bool is_delayed = false) override;


Expand Down
2 changes: 1 addition & 1 deletion backend/remill/include/remill/BC/SleighLifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SleighLifterWithState final : public InstructionLifterIntf {
// this instruction will execute within the delay slot of another instruction.
virtual LiftStatus LiftIntoBlock(Instruction &inst, llvm::BasicBlock *block,
llvm::Value *state_ptr, BBRegInfoNode *bb_reg_info_node,
uint64_t __debug_insn_addr, bool is_delayed = false) override;
bool is_delayed = false) override;

virtual llvm::Value *LoadRegValueBeforeInst(llvm::BasicBlock *block, llvm::Value *state_ptr,
std::string_view reg_name,
Expand Down
1 change: 0 additions & 1 deletion backend/remill/include/remill/BC/TraceLifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ class TraceLifter::Impl {
std::string inst_bytes;
Instruction inst;
Instruction delayed_inst;
std::set<uint64_t> control_flow_debug_fnvma_set;
DecoderWorkList trace_work_list;
DecoderWorkList inst_work_list;
DecoderWorkList dead_inst_work_list;
Expand Down
24 changes: 10 additions & 14 deletions backend/remill/lib/BC/InstructionLifter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,9 @@ InstructionLifter::InstructionLifter(const Arch *arch_, const IntrinsicTable *in
// Lift a single instruction into a basic block. `is_delayed` signifies that
// this instruction will execute within the delay slot of another instruction.
LiftStatus InstructionLifterIntf::LiftIntoBlock(Instruction &inst, llvm::BasicBlock *block,
BBRegInfoNode *bb_reg_info_node,
uint64_t debug_insn_addr, bool is_delayed) {
BBRegInfoNode *bb_reg_info_node, bool is_delayed) {
return LiftIntoBlock(inst, block, NthArgument(block->getParent(), kStatePointerArgNum),
bb_reg_info_node, debug_insn_addr, is_delayed);
bb_reg_info_node, is_delayed);
}

llvm::Type *get_llvm_type(llvm::LLVMContext &context, EcvRegClass ecv_reg_class) {
Expand Down Expand Up @@ -346,8 +345,7 @@ llvm::Type *get_llvm_type(llvm::LLVMContext &context, EcvRegClass ecv_reg_class)
// Lift a single instruction into a basic block.
LiftStatus InstructionLifter::LiftIntoBlock(Instruction &arch_inst, llvm::BasicBlock *block,
llvm::Value *state_ptr, BBRegInfoNode *bb_reg_info_node,

uint64_t debug_insn_addr, bool is_delayed) {
bool is_delayed) {
llvm::Function *const func = block->getParent();
llvm::Module *const module = func->getParent();
auto &context = func->getContext();
Expand Down Expand Up @@ -618,17 +616,15 @@ LiftStatus InstructionLifter::LiftIntoBlock(Instruction &arch_inst, llvm::BasicB
// ir.CreateStore(ir.CreateCall(impl->intrinsics->delay_slot_end, temp_args), mem_ptr_ref);
}

/* append debug_insn function call */
if (UINT64_MAX != debug_insn_addr) {
llvm::IRBuilder<> __debug_ir(block);
/* append `debug_memory_value_change` function call */
#if defined(LIFT_MEMORY_VALUE_CHANGE)
auto _debug_memory_value_change_fn = module->getFunction(debug_memory_value_change_name);
auto [runtime_manager_ptr, _] = LoadRegAddress(block, state_ptr, kRuntimeVariableName);
__debug_ir.CreateCall(_debug_memory_value_change_fn,
{__debug_ir.CreateLoad(llvm::Type::getInt64PtrTy(module->getContext()),
runtime_manager_ptr)});
llvm::IRBuilder<> __debug_ir(block);
auto _debug_memory_value_change_fn = module->getFunction(debug_memory_value_change_name);
auto [runtime_manager_ptr, _] = LoadRegAddress(block, state_ptr, kRuntimeVariableName);
__debug_ir.CreateCall(_debug_memory_value_change_fn,
{__debug_ir.CreateLoad(llvm::Type::getInt64PtrTy(module->getContext()),
runtime_manager_ptr)});
#endif
}

return status;
}
Expand Down
3 changes: 1 addition & 2 deletions backend/remill/lib/BC/SleighLifter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1665,8 +1665,7 @@ SleighLifterWithState::SleighLifterWithState(sleigh::MaybeBranchTakenVar btaken_
// this instruction will execute within the delay slot of another instruction.
LiftStatus SleighLifterWithState::LiftIntoBlock(Instruction &inst, llvm::BasicBlock *block,
llvm::Value *state_ptr,
BBRegInfoNode *bb_reg_info_node,
uint64_t __debug_insn_addr, bool is_delayed) {
BBRegInfoNode *bb_reg_info_node, bool is_delayed) {
return this->lifter->LiftIntoBlockWithSleighState(inst, block, state_ptr, is_delayed,
this->btaken, this->context_values);
}
Expand Down
11 changes: 1 addition & 10 deletions backend/remill/lib/BC/TraceLifter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,8 @@ bool TraceLifter::Impl::Lift(uint64_t addr, const char *fn_name,
std::ignore =
arch->DecodeInstruction(inst_addr, inst_bytes, inst, this->arch->CreateInitialContext());

#if defined(LIFT_DEBUG)
(void) new llvm::StoreInst(llvm::ConstantInt::get(llvm::Type::getInt64Ty(context), inst_addr),
LoadProgramCounterRef(block), block);
#endif

// Lift instruction
auto lift_status =
control_flow_debug_fnvma_set.contains(trace_addr)
? inst.GetLifter()->LiftIntoBlock(inst, block, state_ptr, bb_reg_info_node, inst_addr)
: inst.GetLifter()->LiftIntoBlock(inst, block, state_ptr, bb_reg_info_node,
UINT64_MAX);
auto lift_status = inst.GetLifter()->LiftIntoBlock(inst, block, state_ptr, bb_reg_info_node);

if (!tmp_patch_fn_check && manager._io_file_xsputn_vma == trace_addr) {
llvm::IRBuilder<> ir(block);
Expand Down
17 changes: 0 additions & 17 deletions lifter/Lift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,6 @@ int main(int argc, char *argv[]) {

std::unordered_map<uint64_t, const char *> addr_fn_map;

#if defined(LIFT_DEBUG)
std::cout << "[\033[32mINFO\033[0m] DEBUG MODE ON." << std::endl;
#endif

/* target function control flow */
std::set<uint64_t> control_flow_debug_fnvma_set = {0x423360};
if (!FLAGS_dbg_fun_cfg.empty()) {
for (auto &[fn_addr, dasm_func] : manager.disasm_funcs) {
/* append the address of necesarry debug function */
if (strncmp(dasm_func.func_name.substr(0, FLAGS_dbg_fun_cfg.length() + 4).c_str(),
(FLAGS_dbg_fun_cfg + "_____").c_str(), FLAGS_dbg_fun_cfg.length() + 4) == 0) {
control_flow_debug_fnvma_set.insert(fn_addr);
break;
}
}
}
main_lifter.SetControlFlowDebugList(control_flow_debug_fnvma_set);
/* declare debug function */
main_lifter.DeclareDebugFunction();
/* declare helper function for lifted LLVM bitcode */
Expand Down
11 changes: 0 additions & 11 deletions lifter/MainLifter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ void MainLifter::Optimize() {
static_cast<WrapImpl *>(impl.get())->Optimize();
}

/* Set Control Flow debug list */
void MainLifter::SetControlFlowDebugList(std::set<uint64_t> &__control_flow_debug_fnvma_set) {
static_cast<WrapImpl *>(impl.get())->SetControlFlowDebugList(__control_flow_debug_fnvma_set);
}

/* Declare debug function */
void MainLifter::DeclareDebugFunction() {
static_cast<WrapImpl *>(impl.get())->DeclareDebugFunction();
Expand Down Expand Up @@ -282,12 +277,6 @@ void MainLifter::WrapImpl::AddTestFailedBlock() {
elfconv_runtime_error("%s must be called by derived class.\n", __func__);
}

/* Set control flow debug list */
void MainLifter::WrapImpl::SetControlFlowDebugList(
std::set<uint64_t> &__control_flow_debug_fnvma_set) {
control_flow_debug_fnvma_set = __control_flow_debug_fnvma_set;
}

/* Declare debug function */
llvm::Function *MainLifter::WrapImpl::DeclareDebugFunction() {

Expand Down
3 changes: 0 additions & 3 deletions lifter/MainLifter.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ class MainLifter : public TraceLifter {
void AddTestFailedBlock() override;

/* debug helper */
/* Set control flow debug list */
void SetControlFlowDebugList(std::set<uint64_t> &__control_flow_debug_fnvma_set);
/* Declare debug function */
llvm::Function *DeclareDebugFunction();
/* Set lifted function symbol name table */
Expand Down Expand Up @@ -154,7 +152,6 @@ class MainLifter : public TraceLifter {

void Optimize();
/* debug */
void SetControlFlowDebugList(std::set<uint64_t> &control_flow_debug_fnvma_set);
void DeclareDebugFunction();
void SetFuncSymbolNameTable(std::unordered_map<uint64_t, const char *> &addr_fn_map);
void SetRegisterNames();
Expand Down
14 changes: 0 additions & 14 deletions runtime/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

#include <cstdint>
#include <cstring>
#include <remill/BC/HelperMacro.h>
#if defined(LIFT_DEBUG) && defined(__linux__)
# include <signal.h>
# include <utils/Util.h>
# include <utils/elfconv.h>
#endif
#include <iostream>
#include <map>
#include <remill/Arch/AArch64/Runtime/State.h>
Expand All @@ -21,14 +15,6 @@ int main(int argc, char *argv[]) {

std::vector<MappedMemory *> mapped_memorys;

#if defined(LIFT_DEBUG) && defined(__linux__)
struct sigaction segv_action = {0};
segv_action.sa_flags = SA_SIGINFO;
segv_action.sa_sigaction = segv_debug_state_machine;
if (sigaction(SIGSEGV, &segv_action, NULL) < 0)
elfconv_runtime_error("sigaction for SIGSEGV failed.\n");
#endif

/* allocate Stack */
auto mapped_stack = MappedMemory::VMAStackEntryInit(argc, argv, &g_state);
/* allocate Heap */
Expand Down
9 changes: 0 additions & 9 deletions utils/elfconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,3 @@ extern "C" void debug_insn() {
extern "C" void debug_reach() {
std::cout << "Reach!" << std::endl;
}

#if defined(LIFT_DEBUG) && defined(__linux__)
extern "C" void segv_debug_state_machine(int sig, siginfo_t *info, void *ctx) {
std::cout << "[ERROR] Segmantation Fault." << std::endl;
std::cout << "signo: " << info->si_signo << " code: " << info->si_code << std::endl;
debug_state_machine();
exit(0);
}
#endif
5 changes: 1 addition & 4 deletions utils/elfconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

#include <iostream>
#include <remill/BC/HelperMacro.h>
#if defined(LIFT_DEBUG) && defined(__linux__)
#if defined(RUNTIME_SIGSEGV_DEBUG) && defined(__linux__)
# include <signal.h>
#endif

/* debug function */
extern "C" void debug_state_machine();
extern "C" void debug_state_machine_vectors();
extern "C" void debug_insn();
#if defined(LIFT_DEBUG) && defined(__linux__)
extern "C" void segv_debug_state_machine(int sig, siginfo_t *info, void *ctx);
#endif

0 comments on commit f77f741

Please sign in to comment.