| 642 | } |
| 643 | |
| 644 | void TinyDBR::TranslateBasicBlock(char* address, |
| 645 | ModuleInfo* module, |
| 646 | std::set<char*>* queue, |
| 647 | std::list<std::pair<uint32_t, uint32_t>>* offset_fixes) |
| 648 | { |
| 649 | uint32_t original_offset = (uint32_t)((size_t)address - (size_t)(module->min_address)); |
| 650 | uint32_t translated_offset = (uint32_t)module->instrumented_code_allocated; |
| 651 | |
| 652 | unwind_generator->OnBasicBlockStart(module, |
| 653 | (size_t)address, |
| 654 | GetCurrentInstrumentedAddress(module)); |
| 655 | |
| 656 | //printf("[%08X]: Instrumenting bb, original at %p, instrumented at %p\n", |
| 657 | // GetCurTid(), address, module->instrumented_code_remote + translated_offset); |
| 658 | |
| 659 | module->basic_blocks.insert({ original_offset, translated_offset }); |
| 660 | |
| 661 | AddressRange* range = GetRegion(module, (size_t)address); |
| 662 | if (!range) |
| 663 | { |
| 664 | // just insert a jump to address |
| 665 | assembler_->JmpAddress(module, (size_t)address); |
| 666 | return; |
| 667 | } |
| 668 | |
| 669 | uint32_t range_offset = (uint32_t)((size_t)address - (size_t)range->from); |
| 670 | size_t code_size = (uint32_t)((size_t)range->to - (size_t)address); |
| 671 | char* code_ptr = range->data + range_offset; |
| 672 | |
| 673 | size_t offset = 0, last_offset = 0; |
| 674 | |
| 675 | if (trace_basic_blocks) |
| 676 | { |
| 677 | size_t breakpoint_address = GetCurrentInstrumentedAddress(module); |
| 678 | assembler_->Breakpoint(module); |
| 679 | module->tracepoints[breakpoint_address] = (size_t)address; |
| 680 | } |
| 681 | |
| 682 | // write pre-bb instrumentation |
| 683 | InstrumentBasicBlock(module, (size_t)address); |
| 684 | |
| 685 | Instruction inst; |
| 686 | while (true) |
| 687 | { |
| 688 | bool success = |
| 689 | assembler_->DecodeInstruction( |
| 690 | inst, |
| 691 | (const unsigned char*)(code_ptr + offset), |
| 692 | (unsigned int)(code_size - offset)); |
| 693 | |
| 694 | if (!success) |
| 695 | break; |
| 696 | |
| 697 | unwind_generator->OnInstruction(module, |
| 698 | (size_t)address + offset, |
| 699 | GetCurrentInstrumentedAddress(module)); |
| 700 | |
| 701 | // instruction-level-instrumentation |
nothing calls this directly
no test coverage detected