12 #include "llvm-c/Disassembler.h"
13 #include "llvm/ADT/STLExtras.h"
14 #include "llvm/Support/TargetSelect.h"
42 delete m_assembly_inspection_engine;
49 if (m_assembly_inspection_engine ==
nullptr)
52 if (process_sp.get() ==
nullptr)
54 std::vector<uint8_t> function_text(func.
GetByteSize());
56 if (process_sp->GetTarget().ReadMemory(
60 m_assembly_inspection_engine->Initialize(reg_ctx);
61 return m_assembly_inspection_engine->GetNonCallSiteUnwindPlanFromAssembly(
62 function_text.data(), func.
GetByteSize(), func, unwind_plan);
69 bool do_augment_unwindplan =
true;
76 if (process_sp.get() ==
nullptr)
79 wordsize = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
92 if (first_row->GetCFAValue().GetValueType() !=
93 UnwindPlan::Row::FAValue::isRegisterPlusOffset ||
95 first_row->GetCFAValue().GetRegisterNumber()) !=
97 first_row->GetCFAValue().GetOffset() != wordsize) {
101 if (!first_row->GetRegisterInfo(
105 first_row_pc_loc.
GetOffset() != -wordsize) {
112 if (first_row != last_row &&
113 first_row->GetOffset() != last_row->GetOffset()) {
120 if (first_row->GetCFAValue().GetValueType() ==
121 last_row->GetCFAValue().GetValueType() &&
122 first_row->GetCFAValue().GetRegisterNumber() ==
123 last_row->GetCFAValue().GetRegisterNumber() &&
124 first_row->GetCFAValue().GetOffset() ==
125 last_row->GetCFAValue().GetOffset()) {
130 if (last_row->GetRegisterInfo(
142 if (first_row_pc_loc.
GetOffset() == -wordsize) {
150 if (do_augment_unwindplan) {
153 if (m_assembly_inspection_engine ==
nullptr)
155 std::vector<uint8_t> function_text(func.
GetByteSize());
157 if (process_sp->GetTarget().ReadMemory(
161 m_assembly_inspection_engine->Initialize(reg_ctx);
162 return m_assembly_inspection_engine->AugmentUnwindPlanFromCallSite(
163 function_text.data(), func.
GetByteSize(), func, unwind_plan, reg_ctx);
181 llvm::SmallVector<uint8_t, 4> opcode_data;
185 Target &target(process_sp->GetTarget());
189 uint8_t i386_push_mov[] = {0x55, 0x89, 0xe5};
190 uint8_t x86_64_push_mov[] = {0x55, 0x48, 0x89, 0xe5};
192 if (memcmp(opcode_data.data(), i386_push_mov,
sizeof(i386_push_mov)) ==
194 memcmp(opcode_data.data(), x86_64_push_mov,
195 sizeof(x86_64_push_mov)) == 0) {
196 ABISP abi_sp = process_sp->GetABI();
198 return abi_sp->CreateDefaultUnwindPlan(unwind_plan);
208 Address &first_non_prologue_insn) {
214 if (target ==
nullptr)
217 if (m_assembly_inspection_engine ==
nullptr)
220 std::vector<uint8_t> function_text(func.
GetByteSize());
225 if (m_assembly_inspection_engine->FindFirstNonPrologueInstruction(
226 function_text.data(), func.
GetByteSize(), offset)) {
228 first_non_prologue_insn.
Slide(offset);
236 const llvm::Triple::ArchType cpu = arch.
GetMachine();
237 if (cpu == llvm::Triple::x86 || cpu == llvm::Triple::x86_64)
243 PluginManager::RegisterPlugin(GetPluginNameStatic(),
244 GetPluginDescriptionStatic(), CreateInstance);
248 PluginManager::UnregisterPlugin(CreateInstance);
252 return "i386 and x86_64 assembly language profiler plugin.";