blob: e92a50040116211b75392e339c147ca90869a839 [file] [log] [blame]
Greg Clayton078daac2011-04-25 21:07:40 +00001//===-- UnwindAssembly-x86.cpp ----------------------------------*- C++ -*-===//
Jason Molendafbcb7f22010-09-10 07:49:16 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Greg Clayton078daac2011-04-25 21:07:40 +000010#include "UnwindAssembly-x86.h"
Jason Molendafbcb7f22010-09-10 07:49:16 +000011
Jason Molendaa8399a82012-10-10 01:45:33 +000012#include "llvm-c/Disassembler.h"
Johnny Chen62212f02011-11-29 01:09:49 +000013#include "llvm/Support/TargetSelect.h"
Greg Claytondc5eb692011-04-25 18:36:36 +000014
Jason Molendafbcb7f22010-09-10 07:49:16 +000015#include "lldb/Core/Address.h"
16#include "lldb/Core/Error.h"
17#include "lldb/Core/ArchSpec.h"
18#include "lldb/Core/PluginManager.h"
Greg Claytondc5eb692011-04-25 18:36:36 +000019#include "lldb/Symbol/UnwindPlan.h"
Jason Molendafbcb7f22010-09-10 07:49:16 +000020#include "lldb/Target/ExecutionContext.h"
21#include "lldb/Target/Process.h"
22#include "lldb/Target/RegisterContext.h"
23#include "lldb/Target/Thread.h"
24#include "lldb/Target/Target.h"
Greg Clayton7be25422011-04-25 21:14:26 +000025#include "lldb/Target/UnwindAssembly.h"
Jason Molendafbcb7f22010-09-10 07:49:16 +000026
27using namespace lldb;
28using namespace lldb_private;
29
30enum CPU {
31 k_i386,
32 k_x86_64
33};
34
35enum i386_register_numbers {
36 k_machine_eax = 0,
37 k_machine_ecx = 1,
38 k_machine_edx = 2,
39 k_machine_ebx = 3,
40 k_machine_esp = 4,
41 k_machine_ebp = 5,
42 k_machine_esi = 6,
43 k_machine_edi = 7,
44 k_machine_eip = 8
45};
46
47enum x86_64_register_numbers {
48 k_machine_rax = 0,
49 k_machine_rcx = 1,
50 k_machine_rdx = 2,
51 k_machine_rbx = 3,
52 k_machine_rsp = 4,
53 k_machine_rbp = 5,
54 k_machine_rsi = 6,
55 k_machine_rdi = 7,
56 k_machine_r8 = 8,
57 k_machine_r9 = 9,
58 k_machine_r10 = 10,
59 k_machine_r11 = 11,
60 k_machine_r12 = 12,
61 k_machine_r13 = 13,
62 k_machine_r14 = 14,
63 k_machine_r15 = 15,
64 k_machine_rip = 16
65};
66
67struct regmap_ent {
68 const char *name;
69 int machine_regno;
70 int lldb_regno;
71};
72
73static struct regmap_ent i386_register_map[] = {
74 {"eax", k_machine_eax, -1},
75 {"ecx", k_machine_ecx, -1},
76 {"edx", k_machine_edx, -1},
77 {"ebx", k_machine_ebx, -1},
78 {"esp", k_machine_esp, -1},
79 {"ebp", k_machine_ebp, -1},
80 {"esi", k_machine_esi, -1},
81 {"edi", k_machine_edi, -1},
82 {"eip", k_machine_eip, -1}
83};
84
85const int size_of_i386_register_map = sizeof (i386_register_map) / sizeof (struct regmap_ent);
86
87static int i386_register_map_initialized = 0;
88
89static struct regmap_ent x86_64_register_map[] = {
90 {"rax", k_machine_rax, -1},
91 {"rcx", k_machine_rcx, -1},
92 {"rdx", k_machine_rdx, -1},
93 {"rbx", k_machine_rbx, -1},
94 {"rsp", k_machine_rsp, -1},
95 {"rbp", k_machine_rbp, -1},
96 {"rsi", k_machine_rsi, -1},
97 {"rdi", k_machine_rdi, -1},
98 {"r8", k_machine_r8, -1},
99 {"r9", k_machine_r9, -1},
100 {"r10", k_machine_r10, -1},
101 {"r11", k_machine_r11, -1},
102 {"r12", k_machine_r12, -1},
103 {"r13", k_machine_r13, -1},
104 {"r14", k_machine_r14, -1},
105 {"r15", k_machine_r15, -1},
106 {"rip", k_machine_rip, -1}
107};
108
109const int size_of_x86_64_register_map = sizeof (x86_64_register_map) / sizeof (struct regmap_ent);
110
111static int x86_64_register_map_initialized = 0;
112
113//-----------------------------------------------------------------------------------------------
114// AssemblyParse_x86 local-file class definition & implementation functions
115//-----------------------------------------------------------------------------------------------
116
117class AssemblyParse_x86 {
118public:
119
Jason Molendaa8399a82012-10-10 01:45:33 +0000120 AssemblyParse_x86 (const ExecutionContext &exe_ctx, int cpu, ArchSpec &arch, AddressRange func);
121
122 ~AssemblyParse_x86 ();
Jason Molendafbcb7f22010-09-10 07:49:16 +0000123
124 bool get_non_call_site_unwind_plan (UnwindPlan &unwind_plan);
125
Jason Molendaab4f1922010-10-25 11:12:07 +0000126 bool get_fast_unwind_plan (AddressRange& func, UnwindPlan &unwind_plan);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000127
128 bool find_first_non_prologue_insn (Address &address);
129
130private:
131 enum { kMaxInstructionByteSize = 32 };
132
133 bool nonvolatile_reg_p (int machine_regno);
134 bool push_rbp_pattern_p ();
135 bool push_0_pattern_p ();
136 bool mov_rsp_rbp_pattern_p ();
137 bool sub_rsp_pattern_p (int& amount);
138 bool push_reg_p (int& regno);
139 bool mov_reg_to_local_stack_frame_p (int& regno, int& fp_offset);
140 bool ret_pattern_p ();
141 uint32_t extract_4 (uint8_t *b);
142 bool machine_regno_to_lldb_regno (int machine_regno, uint32_t& lldb_regno);
143 bool instruction_length (Address addr, int &length);
144
Greg Clayton1ac04c32012-02-21 00:09:25 +0000145 const ExecutionContext m_exe_ctx;
Jason Molendafbcb7f22010-09-10 07:49:16 +0000146
147 AddressRange m_func_bounds;
148
149 Address m_cur_insn;
150 uint8_t m_cur_insn_bytes[kMaxInstructionByteSize];
151
152 int m_machine_ip_regnum;
153 int m_machine_sp_regnum;
154 int m_machine_fp_regnum;
155
156 int m_lldb_ip_regnum;
157 int m_lldb_sp_regnum;
158 int m_lldb_fp_regnum;
159
160 int m_wordsize;
161 int m_cpu;
Jason Molendaa8399a82012-10-10 01:45:33 +0000162 ArchSpec m_arch;
163 ::LLVMDisasmContextRef m_disasm_context;
Jason Molendafa19c3e72010-11-04 09:40:56 +0000164
165 DISALLOW_COPY_AND_ASSIGN (AssemblyParse_x86);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000166};
167
Jason Molendaa8399a82012-10-10 01:45:33 +0000168AssemblyParse_x86::AssemblyParse_x86 (const ExecutionContext &exe_ctx, int cpu, ArchSpec &arch, AddressRange func) :
Greg Clayton1ac04c32012-02-21 00:09:25 +0000169 m_exe_ctx (exe_ctx),
170 m_func_bounds(func),
171 m_cur_insn (),
172 m_machine_ip_regnum (LLDB_INVALID_REGNUM),
173 m_machine_sp_regnum (LLDB_INVALID_REGNUM),
174 m_machine_fp_regnum (LLDB_INVALID_REGNUM),
175 m_lldb_ip_regnum (LLDB_INVALID_REGNUM),
176 m_lldb_sp_regnum (LLDB_INVALID_REGNUM),
177 m_lldb_fp_regnum (LLDB_INVALID_REGNUM),
178 m_wordsize (-1),
Jason Molendaa8399a82012-10-10 01:45:33 +0000179 m_cpu(cpu),
180 m_arch(arch)
Jason Molendaab4f1922010-10-25 11:12:07 +0000181{
Jason Molendafbcb7f22010-09-10 07:49:16 +0000182 int *initialized_flag = NULL;
Jason Molendafbcb7f22010-09-10 07:49:16 +0000183 if (cpu == k_i386)
184 {
185 m_machine_ip_regnum = k_machine_eip;
186 m_machine_sp_regnum = k_machine_esp;
187 m_machine_fp_regnum = k_machine_ebp;
188 m_wordsize = 4;
189 initialized_flag = &i386_register_map_initialized;
190 }
191 else
192 {
193 m_machine_ip_regnum = k_machine_rip;
194 m_machine_sp_regnum = k_machine_rsp;
195 m_machine_fp_regnum = k_machine_rbp;
196 m_wordsize = 8;
197 initialized_flag = &x86_64_register_map_initialized;
198 }
199
200 // we only look at prologue - it will be complete earlier than 512 bytes into func
201 if (m_func_bounds.GetByteSize() == 0)
202 m_func_bounds.SetByteSize(512);
203
Greg Clayton1ac04c32012-02-21 00:09:25 +0000204 Thread *thread = m_exe_ctx.GetThreadPtr();
205 if (thread && *initialized_flag == 0)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000206 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000207 RegisterContext *reg_ctx = thread->GetRegisterContext().get();
Greg Clayton5ccbd292011-01-06 22:15:06 +0000208 if (reg_ctx)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000209 {
210 struct regmap_ent *ent;
211 int count, i;
212 if (cpu == k_i386)
213 {
214 ent = i386_register_map;
215 count = size_of_i386_register_map;
216 }
217 else
218 {
219 ent = x86_64_register_map;
220 count = size_of_x86_64_register_map;
221 }
222 for (i = 0; i < count; i++, ent++)
223 {
Greg Clayton5ccbd292011-01-06 22:15:06 +0000224 const RegisterInfo *ri = reg_ctx->GetRegisterInfoByName (ent->name);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000225 if (ri)
226 ent->lldb_regno = ri->kinds[eRegisterKindLLDB];
227 }
228 *initialized_flag = 1;
229 }
230 }
231
232 // on initial construction we may not have a Thread so these have to remain
233 // uninitialized until we can get a RegisterContext to set up the register map table
234 if (*initialized_flag == 1)
235 {
236 uint32_t lldb_regno;
237 if (machine_regno_to_lldb_regno (m_machine_sp_regnum, lldb_regno))
238 m_lldb_sp_regnum = lldb_regno;
239 if (machine_regno_to_lldb_regno (m_machine_fp_regnum, lldb_regno))
240 m_lldb_fp_regnum = lldb_regno;
241 if (machine_regno_to_lldb_regno (m_machine_ip_regnum, lldb_regno))
242 m_lldb_ip_regnum = lldb_regno;
243 }
Jason Molendaa8399a82012-10-10 01:45:33 +0000244
245 m_disasm_context = ::LLVMCreateDisasm(m_arch.GetTriple().getTriple().c_str(),
246 (void*)this,
247 /*TagType=*/1,
248 NULL,
249 NULL);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000250}
251
Jason Molendaa8399a82012-10-10 01:45:33 +0000252AssemblyParse_x86::~AssemblyParse_x86 ()
253{
254 ::LLVMDisasmDispose(m_disasm_context);
255}
Jason Molendafbcb7f22010-09-10 07:49:16 +0000256
257// This function expects an x86 native register number (i.e. the bits stripped out of the
258// actual instruction), not an lldb register number.
259
260bool
261AssemblyParse_x86::nonvolatile_reg_p (int machine_regno)
262{
263 if (m_cpu == k_i386)
264 {
265 switch (machine_regno) {
266 case k_machine_ebx:
267 case k_machine_ebp: // not actually a nonvolatile but often treated as such by convention
268 case k_machine_esi:
269 case k_machine_edi:
270 case k_machine_esp:
271 return true;
272 default:
273 return false;
274 }
275 }
276 if (m_cpu == k_x86_64)
277 {
278 switch (machine_regno) {
279 case k_machine_rbx:
280 case k_machine_rsp:
281 case k_machine_rbp: // not actually a nonvolatile but often treated as such by convention
282 case k_machine_r12:
283 case k_machine_r13:
284 case k_machine_r14:
285 case k_machine_r15:
286 return true;
287 default:
288 return false;
289 }
290 }
291 return false;
292}
293
294
295// Macro to detect if this is a REX mode prefix byte.
296#define REX_W_PREFIX_P(opcode) (((opcode) & (~0x5)) == 0x48)
297
298// The high bit which should be added to the source register number (the "R" bit)
299#define REX_W_SRCREG(opcode) (((opcode) & 0x4) >> 2)
300
301// The high bit which should be added to the destination register number (the "B" bit)
302#define REX_W_DSTREG(opcode) ((opcode) & 0x1)
303
304// pushq %rbp [0x55]
305bool AssemblyParse_x86::push_rbp_pattern_p () {
306 uint8_t *p = m_cur_insn_bytes;
307 if (*p == 0x55)
308 return true;
309 return false;
310}
311
312// pushq $0 ; the first instruction in start() [0x6a 0x00]
313bool AssemblyParse_x86::push_0_pattern_p ()
314{
315 uint8_t *p = m_cur_insn_bytes;
316 if (*p == 0x6a && *(p + 1) == 0x0)
317 return true;
318 return false;
319}
320
321// movq %rsp, %rbp [0x48 0x8b 0xec] or [0x48 0x89 0xe5]
322// movl %esp, %ebp [0x8b 0xec] or [0x89 0xe5]
323bool AssemblyParse_x86::mov_rsp_rbp_pattern_p () {
324 uint8_t *p = m_cur_insn_bytes;
325 if (m_wordsize == 8 && *p == 0x48)
326 p++;
327 if (*(p) == 0x8b && *(p + 1) == 0xec)
328 return true;
329 if (*(p) == 0x89 && *(p + 1) == 0xe5)
330 return true;
331 return false;
332}
333
334// subq $0x20, %rsp
335bool AssemblyParse_x86::sub_rsp_pattern_p (int& amount) {
336 uint8_t *p = m_cur_insn_bytes;
337 if (m_wordsize == 8 && *p == 0x48)
338 p++;
339 // 8-bit immediate operand
340 if (*p == 0x83 && *(p + 1) == 0xec) {
341 amount = (int8_t) *(p + 2);
342 return true;
343 }
344 // 32-bit immediate operand
345 if (*p == 0x81 && *(p + 1) == 0xec) {
346 amount = (int32_t) extract_4 (p + 2);
347 return true;
348 }
349 // Not handled: [0x83 0xc4] for imm8 with neg values
350 // [0x81 0xc4] for imm32 with neg values
351 return false;
352}
353
354// pushq %rbx
355// pushl $ebx
356bool AssemblyParse_x86::push_reg_p (int& regno) {
357 uint8_t *p = m_cur_insn_bytes;
358 int regno_prefix_bit = 0;
359 // If we have a rex prefix byte, check to see if a B bit is set
360 if (m_wordsize == 8 && *p == 0x41) {
361 regno_prefix_bit = 1 << 3;
362 p++;
363 }
364 if (*p >= 0x50 && *p <= 0x57) {
365 regno = (*p - 0x50) | regno_prefix_bit;
366 return true;
367 }
368 return false;
369}
370
371// Look for an instruction sequence storing a nonvolatile register
372// on to the stack frame.
373
374// movq %rax, -0x10(%rbp) [0x48 0x89 0x45 0xf0]
375// movl %eax, -0xc(%ebp) [0x89 0x45 0xf4]
376bool AssemblyParse_x86::mov_reg_to_local_stack_frame_p (int& regno, int& rbp_offset) {
377 uint8_t *p = m_cur_insn_bytes;
378 int src_reg_prefix_bit = 0;
379 int target_reg_prefix_bit = 0;
380
381 if (m_wordsize == 8 && REX_W_PREFIX_P (*p)) {
382 src_reg_prefix_bit = REX_W_SRCREG (*p) << 3;
383 target_reg_prefix_bit = REX_W_DSTREG (*p) << 3;
384 if (target_reg_prefix_bit == 1) {
385 // rbp/ebp don't need a prefix bit - we know this isn't the
386 // reg we care about.
387 return false;
388 }
389 p++;
390 }
391
392 if (*p == 0x89) {
393 /* Mask off the 3-5 bits which indicate the destination register
394 if this is a ModR/M byte. */
395 int opcode_destreg_masked_out = *(p + 1) & (~0x38);
396
397 /* Is this a ModR/M byte with Mod bits 01 and R/M bits 101
398 and three bits between them, e.g. 01nnn101
399 We're looking for a destination of ebp-disp8 or ebp-disp32. */
400 int immsize;
401 if (opcode_destreg_masked_out == 0x45)
402 immsize = 2;
403 else if (opcode_destreg_masked_out == 0x85)
404 immsize = 4;
405 else
406 return false;
407
408 int offset = 0;
409 if (immsize == 2)
410 offset = (int8_t) *(p + 2);
411 if (immsize == 4)
412 offset = (uint32_t) extract_4 (p + 2);
413 if (offset > 0)
414 return false;
415
416 regno = ((*(p + 1) >> 3) & 0x7) | src_reg_prefix_bit;
417 rbp_offset = offset > 0 ? offset : -offset;
418 return true;
419 }
420 return false;
421}
422
423// ret [0xc9] or [0xc2 imm8] or [0xca imm8]
424bool
425AssemblyParse_x86::ret_pattern_p ()
426{
427 uint8_t *p = m_cur_insn_bytes;
428 if (*p == 0xc9 || *p == 0xc2 || *p == 0xca || *p == 0xc3)
429 return true;
430 return false;
431}
432
433uint32_t
434AssemblyParse_x86::extract_4 (uint8_t *b)
435{
436 uint32_t v = 0;
437 for (int i = 3; i >= 0; i--)
438 v = (v << 8) | b[i];
439 return v;
440}
441
442bool
443AssemblyParse_x86::machine_regno_to_lldb_regno (int machine_regno, uint32_t &lldb_regno)
444{
445 struct regmap_ent *ent;
446 int count, i;
447 if (m_cpu == k_i386)
448 {
449 ent = i386_register_map;
450 count = size_of_i386_register_map;
451 }
452 else
453 {
454 ent = x86_64_register_map;
455 count = size_of_x86_64_register_map;
456 }
457 for (i = 0; i < count; i++, ent++)
458 {
459 if (ent->machine_regno == machine_regno)
460 if (ent->lldb_regno != -1)
461 {
462 lldb_regno = ent->lldb_regno;
463 return true;
464 }
465 }
466 return false;
467}
468
Jason Molendafbcb7f22010-09-10 07:49:16 +0000469bool
470AssemblyParse_x86::instruction_length (Address addr, int &length)
471{
Jason Molendaa8399a82012-10-10 01:45:33 +0000472 const uint32_t max_op_byte_size = m_arch.GetMaximumOpcodeByteSize();
Jason Molenda59762002010-11-04 00:53:20 +0000473
474 if (!addr.IsValid())
475 return false;
476
Jason Molendaa8399a82012-10-10 01:45:33 +0000477 uint8_t *opcode_data = (uint8_t *) malloc (max_op_byte_size);
478 if (opcode_data == NULL)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000479 {
Jason Molendaab4f1922010-10-25 11:12:07 +0000480 return false;
Jason Molendafbcb7f22010-09-10 07:49:16 +0000481 }
482
Jason Molendaa8399a82012-10-10 01:45:33 +0000483 const bool prefer_file_cache = true;
484 Error error;
485 Target *target = m_exe_ctx.GetTargetPtr();
486 if (target->ReadMemory (addr, prefer_file_cache, opcode_data, max_op_byte_size, error) == -1)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000487 {
Jason Molendaab4f1922010-10-25 11:12:07 +0000488 return false;
Jason Molendafbcb7f22010-09-10 07:49:16 +0000489 }
Jason Molendaa8399a82012-10-10 01:45:33 +0000490
491 char out_string[512];
492 const addr_t pc = addr.GetFileAddress();
493 const size_t inst_size = ::LLVMDisasmInstruction (m_disasm_context,
494 opcode_data,
495 max_op_byte_size,
496 pc, // PC value
497 out_string,
498 sizeof(out_string));
499
500 length = inst_size;
501
Jason Molendafbcb7f22010-09-10 07:49:16 +0000502 return true;
503}
504
505
506bool
507AssemblyParse_x86::get_non_call_site_unwind_plan (UnwindPlan &unwind_plan)
508{
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000509 UnwindPlan::RowSP row(new UnwindPlan::Row);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000510 int non_prologue_insn_count = 0;
Jason Molenda59762002010-11-04 00:53:20 +0000511 m_cur_insn = m_func_bounds.GetBaseAddress ();
Jason Molendafbcb7f22010-09-10 07:49:16 +0000512 int current_func_text_offset = 0;
513 int current_sp_bytes_offset_from_cfa = 0;
Jason Molendafa19c3e72010-11-04 09:40:56 +0000514 UnwindPlan::Row::RegisterLocation initial_regloc;
Jason Molenda59203332010-11-16 03:01:20 +0000515 Error error;
Jason Molendafbcb7f22010-09-10 07:49:16 +0000516
Jason Molenda59762002010-11-04 00:53:20 +0000517 if (!m_cur_insn.IsValid())
518 {
519 return false;
520 }
521
Jason Molendafbcb7f22010-09-10 07:49:16 +0000522 unwind_plan.SetPlanValidAddressRange (m_func_bounds);
523 unwind_plan.SetRegisterKind (eRegisterKindLLDB);
524
525 // At the start of the function, find the CFA by adding wordsize to the SP register
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000526 row->SetOffset (current_func_text_offset);
527 row->SetCFARegister (m_lldb_sp_regnum);
528 row->SetCFAOffset (m_wordsize);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000529
530 // caller's stack pointer value before the call insn is the CFA address
Jason Molendafa19c3e72010-11-04 09:40:56 +0000531 initial_regloc.SetIsCFAPlusOffset (0);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000532 row->SetRegisterInfo (m_lldb_sp_regnum, initial_regloc);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000533
534 // saved instruction pointer can be found at CFA - wordsize.
535 current_sp_bytes_offset_from_cfa = m_wordsize;
Jason Molendafa19c3e72010-11-04 09:40:56 +0000536 initial_regloc.SetAtCFAPlusOffset (-current_sp_bytes_offset_from_cfa);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000537 row->SetRegisterInfo (m_lldb_ip_regnum, initial_regloc);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000538
539 unwind_plan.AppendRow (row);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000540
541 // Allocate a new Row, populate it with the existing Row contents.
542 UnwindPlan::Row *newrow = new UnwindPlan::Row;
543 *newrow = *row.get();
544 row.reset(newrow);
545
Greg Claytondb598232011-01-07 01:57:07 +0000546 const bool prefer_file_cache = true;
Jason Molendafbcb7f22010-09-10 07:49:16 +0000547
Greg Clayton1ac04c32012-02-21 00:09:25 +0000548 Target *target = m_exe_ctx.GetTargetPtr();
Jason Molendafbcb7f22010-09-10 07:49:16 +0000549 while (m_func_bounds.ContainsFileAddress (m_cur_insn) && non_prologue_insn_count < 10)
550 {
551 int stack_offset, insn_len;
552 int machine_regno; // register numbers masked directly out of instructions
553 uint32_t lldb_regno; // register numbers in lldb's eRegisterKindLLDB numbering scheme
Jason Molendafbcb7f22010-09-10 07:49:16 +0000554
555 if (!instruction_length (m_cur_insn, insn_len) || insn_len == 0 || insn_len > kMaxInstructionByteSize)
556 {
557 // An unrecognized/junk instruction
558 break;
559 }
Greg Clayton1ac04c32012-02-21 00:09:25 +0000560 if (target->ReadMemory (m_cur_insn, prefer_file_cache, m_cur_insn_bytes, insn_len, error) == -1)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000561 {
562 // Error reading the instruction out of the file, stop scanning
563 break;
564 }
565
566 if (push_rbp_pattern_p ())
567 {
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000568 row->SetOffset (current_func_text_offset + insn_len);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000569 current_sp_bytes_offset_from_cfa += m_wordsize;
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000570 row->SetCFAOffset (current_sp_bytes_offset_from_cfa);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000571 UnwindPlan::Row::RegisterLocation regloc;
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000572 regloc.SetAtCFAPlusOffset (-row->GetCFAOffset());
573 row->SetRegisterInfo (m_lldb_fp_regnum, regloc);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000574 unwind_plan.AppendRow (row);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000575 // Allocate a new Row, populate it with the existing Row contents.
576 newrow = new UnwindPlan::Row;
577 *newrow = *row.get();
578 row.reset(newrow);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000579 goto loopnext;
580 }
Jason Molenda5c01cb62010-10-26 00:47:17 +0000581
582 if (mov_rsp_rbp_pattern_p ())
583 {
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000584 row->SetOffset (current_func_text_offset + insn_len);
585 row->SetCFARegister (m_lldb_fp_regnum);
Jason Molenda5c01cb62010-10-26 00:47:17 +0000586 unwind_plan.AppendRow (row);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000587 // Allocate a new Row, populate it with the existing Row contents.
588 newrow = new UnwindPlan::Row;
589 *newrow = *row.get();
590 row.reset(newrow);
Jason Molenda5c01cb62010-10-26 00:47:17 +0000591 goto loopnext;
592 }
593
Jason Molendaab4f1922010-10-25 11:12:07 +0000594 // This is the start() function (or a pthread equivalent), it starts with a pushl $0x0 which puts the
595 // saved pc value of 0 on the stack. In this case we want to pretend we didn't see a stack movement at all --
596 // normally the saved pc value is already on the stack by the time the function starts executing.
Jason Molendafbcb7f22010-09-10 07:49:16 +0000597 if (push_0_pattern_p ())
598 {
Jason Molendafbcb7f22010-09-10 07:49:16 +0000599 goto loopnext;
600 }
601
602 if (push_reg_p (machine_regno))
603 {
604 current_sp_bytes_offset_from_cfa += m_wordsize;
605 if (nonvolatile_reg_p (machine_regno) && machine_regno_to_lldb_regno (machine_regno, lldb_regno))
606 {
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000607 row->SetOffset (current_func_text_offset + insn_len);
608 if (row->GetCFARegister() == m_lldb_sp_regnum)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000609 {
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000610 row->SetCFAOffset (current_sp_bytes_offset_from_cfa);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000611 }
612 UnwindPlan::Row::RegisterLocation regloc;
613 regloc.SetAtCFAPlusOffset (-current_sp_bytes_offset_from_cfa);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000614 row->SetRegisterInfo (lldb_regno, regloc);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000615 unwind_plan.AppendRow (row);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000616 // Allocate a new Row, populate it with the existing Row contents.
617 newrow = new UnwindPlan::Row;
618 *newrow = *row.get();
619 row.reset(newrow);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000620 }
621 goto loopnext;
622 }
623
624 if (mov_reg_to_local_stack_frame_p (machine_regno, stack_offset) && nonvolatile_reg_p (machine_regno))
625 {
626 if (machine_regno_to_lldb_regno (machine_regno, lldb_regno))
627 {
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000628 row->SetOffset (current_func_text_offset + insn_len);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000629 UnwindPlan::Row::RegisterLocation regloc;
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000630 regloc.SetAtCFAPlusOffset (-row->GetCFAOffset());
631 row->SetRegisterInfo (lldb_regno, regloc);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000632 unwind_plan.AppendRow (row);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000633 // Allocate a new Row, populate it with the existing Row contents.
634 newrow = new UnwindPlan::Row;
635 *newrow = *row.get();
636 row.reset(newrow);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000637 goto loopnext;
638 }
639 }
640
641 if (sub_rsp_pattern_p (stack_offset))
642 {
643 current_sp_bytes_offset_from_cfa += stack_offset;
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000644 if (row->GetCFARegister() == m_lldb_sp_regnum)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000645 {
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000646 row->SetOffset (current_func_text_offset + insn_len);
647 row->SetCFAOffset (current_sp_bytes_offset_from_cfa);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000648 unwind_plan.AppendRow (row);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000649 // Allocate a new Row, populate it with the existing Row contents.
650 newrow = new UnwindPlan::Row;
651 *newrow = *row.get();
652 row.reset(newrow);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000653 }
654 goto loopnext;
655 }
656
Jason Molendafbcb7f22010-09-10 07:49:16 +0000657 if (ret_pattern_p ())
658 {
659 // we know where the end of the function is; set the limit on the PlanValidAddressRange
660 // in case our initial "high pc" value was overly large
661 // int original_size = m_func_bounds.GetByteSize();
662 // int calculated_size = m_cur_insn.GetOffset() - m_func_bounds.GetBaseAddress().GetOffset() + insn_len + 1;
663 // m_func_bounds.SetByteSize (calculated_size);
664 // unwind_plan.SetPlanValidAddressRange (m_func_bounds);
665 break;
666 }
667
668 // FIXME recognize the i386 picbase setup instruction sequence,
669 // 0x1f16: call 0x1f1b ; main + 11 at /private/tmp/a.c:3
670 // 0x1f1b: popl %eax
671 // and record the temporary stack movements if the CFA is not expressed in terms of ebp.
672
673 non_prologue_insn_count++;
674loopnext:
675 m_cur_insn.SetOffset (m_cur_insn.GetOffset() + insn_len);
676 current_func_text_offset += insn_len;
677 }
678
Jason Molenda59203332010-11-16 03:01:20 +0000679 // Now look at the byte at the end of the AddressRange for a limited attempt at describing the
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000680 // epilogue. We're looking for the sequence
Jason Molenda59203332010-11-16 03:01:20 +0000681
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000682 // [ 0x5d ] mov %rbp, %rsp
683 // [ 0xc3 ] ret
684 // [ 0xe8 xx xx xx xx ] call __stack_chk_fail (this is sometimes the final insn in the function)
685
686 // We want to add a Row describing how to unwind when we're stopped on the 'ret' instruction where the
687 // CFA is no longer defined in terms of rbp, but is now defined in terms of rsp like on function entry.
688
689 uint64_t ret_insn_offset = LLDB_INVALID_ADDRESS;
690 Address end_of_fun(m_func_bounds.GetBaseAddress());
691 end_of_fun.SetOffset (end_of_fun.GetOffset() + m_func_bounds.GetByteSize());
692
693 if (m_func_bounds.GetByteSize() > 7)
Jason Molenda59203332010-11-16 03:01:20 +0000694 {
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000695 uint8_t bytebuf[7];
696 Address last_seven_bytes(end_of_fun);
697 last_seven_bytes.SetOffset (last_seven_bytes.GetOffset() - 7);
698 if (target->ReadMemory (last_seven_bytes, prefer_file_cache, bytebuf, 7, error) != -1)
Jason Molenda59203332010-11-16 03:01:20 +0000699 {
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000700 if (bytebuf[5] == 0x5d && bytebuf[6] == 0xc3) // mov, ret
Jason Molenda59203332010-11-16 03:01:20 +0000701 {
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000702 ret_insn_offset = m_func_bounds.GetByteSize() - 1;
703 }
704 else if (bytebuf[0] == 0x5d && bytebuf[1] == 0xc3 && bytebuf[2] == 0xe8) // mov, ret, call
705 {
706 ret_insn_offset = m_func_bounds.GetByteSize() - 6;
Jason Molenda59203332010-11-16 03:01:20 +0000707 }
708 }
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000709 } else if (m_func_bounds.GetByteSize() > 2)
710 {
711 uint8_t bytebuf[2];
712 Address last_two_bytes(end_of_fun);
713 last_two_bytes.SetOffset (last_two_bytes.GetOffset() - 2);
714 if (target->ReadMemory (last_two_bytes, prefer_file_cache, bytebuf, 2, error) != -1)
715 {
716 if (bytebuf[0] == 0x5d && bytebuf[1] == 0xc3) // mov, ret
717 {
718 ret_insn_offset = m_func_bounds.GetByteSize() - 1;
719 }
720 }
721 }
722
723 if (ret_insn_offset != LLDB_INVALID_ADDRESS)
724 {
725 // Create a fresh, empty Row and RegisterLocation - don't mention any other registers
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000726 UnwindPlan::RowSP epi_row(new UnwindPlan::Row);
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000727 UnwindPlan::Row::RegisterLocation epi_regloc;
728
729 // When the ret instruction is about to be executed, here's our state
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000730 epi_row->SetOffset (ret_insn_offset);
731 epi_row->SetCFARegister (m_lldb_sp_regnum);
732 epi_row->SetCFAOffset (m_wordsize);
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000733
734 // caller's stack pointer value before the call insn is the CFA address
735 epi_regloc.SetIsCFAPlusOffset (0);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000736 epi_row->SetRegisterInfo (m_lldb_sp_regnum, epi_regloc);
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000737
738 // saved instruction pointer can be found at CFA - wordsize
739 epi_regloc.SetAtCFAPlusOffset (-m_wordsize);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000740 epi_row->SetRegisterInfo (m_lldb_ip_regnum, epi_regloc);
Jason Molenda6f5e8c22012-05-25 01:54:06 +0000741
742 unwind_plan.AppendRow (epi_row);
Jason Molenda59203332010-11-16 03:01:20 +0000743 }
744
Jason Molendaab4f1922010-10-25 11:12:07 +0000745 unwind_plan.SetSourceName ("assembly insn profiling");
746
Jason Molendafbcb7f22010-09-10 07:49:16 +0000747 return true;
748}
749
Jason Molendaab4f1922010-10-25 11:12:07 +0000750/* The "fast unwind plan" is valid for functions that follow the usual convention of
751 using the frame pointer register (ebp, rbp), i.e. the function prologue looks like
752 push %rbp [0x55]
753 mov %rsp,%rbp [0x48 0x89 0xe5] (this is a 2-byte insn seq on i386)
754*/
755
Jason Molendafbcb7f22010-09-10 07:49:16 +0000756bool
Jason Molendaab4f1922010-10-25 11:12:07 +0000757AssemblyParse_x86::get_fast_unwind_plan (AddressRange& func, UnwindPlan &unwind_plan)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000758{
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000759 UnwindPlan::RowSP row(new UnwindPlan::Row);
Jason Molendaab4f1922010-10-25 11:12:07 +0000760 UnwindPlan::Row::RegisterLocation pc_reginfo;
761 UnwindPlan::Row::RegisterLocation sp_reginfo;
762 UnwindPlan::Row::RegisterLocation fp_reginfo;
763 unwind_plan.SetRegisterKind (eRegisterKindLLDB);
764
765 if (!func.GetBaseAddress().IsValid())
766 return false;
767
Greg Clayton1ac04c32012-02-21 00:09:25 +0000768 Target *target = m_exe_ctx.GetTargetPtr();
769
Jason Molendaab4f1922010-10-25 11:12:07 +0000770 uint8_t bytebuf[4];
771 Error error;
Greg Claytondb598232011-01-07 01:57:07 +0000772 const bool prefer_file_cache = true;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000773 if (target->ReadMemory (func.GetBaseAddress(), prefer_file_cache, bytebuf, sizeof (bytebuf), error) == -1)
Jason Molendaab4f1922010-10-25 11:12:07 +0000774 return false;
775
776 uint8_t i386_prologue[] = {0x55, 0x89, 0xe5};
777 uint8_t x86_64_prologue[] = {0x55, 0x48, 0x89, 0xe5};
778 int prologue_size;
779
780 if (memcmp (bytebuf, i386_prologue, sizeof (i386_prologue)) == 0)
781 {
782 prologue_size = sizeof (i386_prologue);
783 }
784 else if (memcmp (bytebuf, x86_64_prologue, sizeof (x86_64_prologue)) == 0)
785 {
786 prologue_size = sizeof (x86_64_prologue);
787 }
788 else
789 {
790 return false;
791 }
792
793 pc_reginfo.SetAtCFAPlusOffset (-m_wordsize);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000794 row->SetRegisterInfo (m_lldb_ip_regnum, pc_reginfo);
Jason Molendaab4f1922010-10-25 11:12:07 +0000795
796 sp_reginfo.SetIsCFAPlusOffset (0);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000797 row->SetRegisterInfo (m_lldb_sp_regnum, sp_reginfo);
Jason Molendaab4f1922010-10-25 11:12:07 +0000798
799 // Zero instructions into the function
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000800 row->SetCFARegister (m_lldb_sp_regnum);
801 row->SetCFAOffset (m_wordsize);
802 row->SetOffset (0);
Jason Molendaab4f1922010-10-25 11:12:07 +0000803 unwind_plan.AppendRow (row);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000804 UnwindPlan::Row *newrow = new UnwindPlan::Row;
805 *newrow = *row.get();
806 row.reset(newrow);
Jason Molendaab4f1922010-10-25 11:12:07 +0000807
808 // push %rbp has executed - stack moved, rbp now saved
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000809 row->SetCFAOffset (2 * m_wordsize);
Jason Molendaab4f1922010-10-25 11:12:07 +0000810 fp_reginfo.SetAtCFAPlusOffset (2 * -m_wordsize);
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000811 row->SetRegisterInfo (m_lldb_fp_regnum, fp_reginfo);
812 row->SetOffset (1);
Jason Molendaab4f1922010-10-25 11:12:07 +0000813 unwind_plan.AppendRow (row);
814
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000815 newrow = new UnwindPlan::Row;
816 *newrow = *row.get();
817 row.reset(newrow);
818
Jason Molendaab4f1922010-10-25 11:12:07 +0000819 // mov %rsp, %rbp has executed
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000820 row->SetCFARegister (m_lldb_fp_regnum);
821 row->SetCFAOffset (2 * m_wordsize);
822 row->SetOffset (prologue_size); /// 3 or 4 bytes depending on arch
Jason Molendaab4f1922010-10-25 11:12:07 +0000823 unwind_plan.AppendRow (row);
824
Jason Molenda1d42c7b2012-07-14 04:52:53 +0000825 newrow = new UnwindPlan::Row;
826 *newrow = *row.get();
827 row.reset(newrow);
828
Jason Molendaab4f1922010-10-25 11:12:07 +0000829 unwind_plan.SetPlanValidAddressRange (func);
830 return true;
Jason Molendafbcb7f22010-09-10 07:49:16 +0000831}
832
833bool
834AssemblyParse_x86::find_first_non_prologue_insn (Address &address)
835{
836 m_cur_insn = m_func_bounds.GetBaseAddress ();
Jason Molenda59762002010-11-04 00:53:20 +0000837 if (!m_cur_insn.IsValid())
838 {
839 return false;
840 }
841
Greg Claytondb598232011-01-07 01:57:07 +0000842 const bool prefer_file_cache = true;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000843 Target *target = m_exe_ctx.GetTargetPtr();
Jason Molendafbcb7f22010-09-10 07:49:16 +0000844 while (m_func_bounds.ContainsFileAddress (m_cur_insn))
845 {
846 Error error;
847 int insn_len, offset, regno;
848 if (!instruction_length (m_cur_insn, insn_len) || insn_len > kMaxInstructionByteSize || insn_len == 0)
849 {
850 // An error parsing the instruction, i.e. probably data/garbage - stop scanning
851 break;
852 }
Greg Clayton1ac04c32012-02-21 00:09:25 +0000853 if (target->ReadMemory (m_cur_insn, prefer_file_cache, m_cur_insn_bytes, insn_len, error) == -1)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000854 {
855 // Error reading the instruction out of the file, stop scanning
856 break;
857 }
858
859 if (push_rbp_pattern_p () || mov_rsp_rbp_pattern_p () || sub_rsp_pattern_p (offset)
860 || push_reg_p (regno) || mov_reg_to_local_stack_frame_p (regno, offset))
861 {
862 m_cur_insn.SetOffset (m_cur_insn.GetOffset() + insn_len);
863 continue;
864 }
865
866 // Unknown non-prologue instruction - stop scanning
867 break;
868 }
869
870 address = m_cur_insn;
871 return true;
872}
873
874
875
876
877
878
879//-----------------------------------------------------------------------------------------------
880// UnwindAssemblyParser_x86 method definitions
881//-----------------------------------------------------------------------------------------------
882
Greg Clayton2ed751b2011-04-26 04:39:08 +0000883UnwindAssembly_x86::UnwindAssembly_x86 (const ArchSpec &arch, int cpu) :
884 lldb_private::UnwindAssembly(arch),
Jason Molendaa8399a82012-10-10 01:45:33 +0000885 m_cpu(cpu),
886 m_arch(arch)
Greg Clayton2ed751b2011-04-26 04:39:08 +0000887{
888}
889
890
891UnwindAssembly_x86::~UnwindAssembly_x86 ()
892{
893}
894
Jason Molendafbcb7f22010-09-10 07:49:16 +0000895bool
Greg Claytonffc922e32011-04-25 21:05:07 +0000896UnwindAssembly_x86::GetNonCallSiteUnwindPlanFromAssembly (AddressRange& func, Thread& thread, UnwindPlan& unwind_plan)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000897{
Greg Clayton1ac04c32012-02-21 00:09:25 +0000898 ExecutionContext exe_ctx (thread.shared_from_this());
Jason Molendaa8399a82012-10-10 01:45:33 +0000899 AssemblyParse_x86 asm_parse(exe_ctx, m_cpu, m_arch, func);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000900 return asm_parse.get_non_call_site_unwind_plan (unwind_plan);
901}
902
903bool
Greg Claytonffc922e32011-04-25 21:05:07 +0000904UnwindAssembly_x86::GetFastUnwindPlan (AddressRange& func, Thread& thread, UnwindPlan &unwind_plan)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000905{
Greg Clayton1ac04c32012-02-21 00:09:25 +0000906 ExecutionContext exe_ctx (thread.shared_from_this());
Jason Molendaa8399a82012-10-10 01:45:33 +0000907 AssemblyParse_x86 asm_parse(exe_ctx, m_cpu, m_arch, func);
Jason Molendaab4f1922010-10-25 11:12:07 +0000908 return asm_parse.get_fast_unwind_plan (func, unwind_plan);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000909}
910
911bool
Greg Clayton1ac04c32012-02-21 00:09:25 +0000912UnwindAssembly_x86::FirstNonPrologueInsn (AddressRange& func, const ExecutionContext &exe_ctx, Address& first_non_prologue_insn)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000913{
Jason Molendaa8399a82012-10-10 01:45:33 +0000914 AssemblyParse_x86 asm_parse(exe_ctx, m_cpu, m_arch, func);
Jason Molendafbcb7f22010-09-10 07:49:16 +0000915 return asm_parse.find_first_non_prologue_insn (first_non_prologue_insn);
916}
917
Greg Clayton7be25422011-04-25 21:14:26 +0000918UnwindAssembly *
Greg Claytonffc922e32011-04-25 21:05:07 +0000919UnwindAssembly_x86::CreateInstance (const ArchSpec &arch)
Jason Molendafbcb7f22010-09-10 07:49:16 +0000920{
Greg Clayton64195a22011-02-23 00:35:02 +0000921 const llvm::Triple::ArchType cpu = arch.GetMachine ();
922 if (cpu == llvm::Triple::x86)
Greg Clayton2ed751b2011-04-26 04:39:08 +0000923 return new UnwindAssembly_x86 (arch, k_i386);
Greg Clayton64195a22011-02-23 00:35:02 +0000924 else if (cpu == llvm::Triple::x86_64)
Greg Clayton2ed751b2011-04-26 04:39:08 +0000925 return new UnwindAssembly_x86 (arch, k_x86_64);
Greg Clayton64195a22011-02-23 00:35:02 +0000926 return NULL;
Jason Molendafbcb7f22010-09-10 07:49:16 +0000927}
928
929
930//------------------------------------------------------------------
931// PluginInterface protocol in UnwindAssemblyParser_x86
932//------------------------------------------------------------------
933
934const char *
Greg Claytonffc922e32011-04-25 21:05:07 +0000935UnwindAssembly_x86::GetPluginName()
Jason Molendafbcb7f22010-09-10 07:49:16 +0000936{
Greg Claytonffc922e32011-04-25 21:05:07 +0000937 return "UnwindAssembly_x86";
Jason Molendafbcb7f22010-09-10 07:49:16 +0000938}
939
940const char *
Greg Claytonffc922e32011-04-25 21:05:07 +0000941UnwindAssembly_x86::GetShortPluginName()
Jason Molendafbcb7f22010-09-10 07:49:16 +0000942{
Greg Claytonffc922e32011-04-25 21:05:07 +0000943 return "unwindassembly.x86";
Jason Molendafbcb7f22010-09-10 07:49:16 +0000944}
945
946
947uint32_t
Greg Claytonffc922e32011-04-25 21:05:07 +0000948UnwindAssembly_x86::GetPluginVersion()
Jason Molendafbcb7f22010-09-10 07:49:16 +0000949{
950 return 1;
951}
952
953void
Greg Claytonffc922e32011-04-25 21:05:07 +0000954UnwindAssembly_x86::Initialize()
Jason Molendafbcb7f22010-09-10 07:49:16 +0000955{
956 PluginManager::RegisterPlugin (GetPluginNameStatic(),
957 GetPluginDescriptionStatic(),
958 CreateInstance);
959}
960
961void
Greg Claytonffc922e32011-04-25 21:05:07 +0000962UnwindAssembly_x86::Terminate()
Jason Molendafbcb7f22010-09-10 07:49:16 +0000963{
964 PluginManager::UnregisterPlugin (CreateInstance);
965}
966
967
968const char *
Greg Claytonffc922e32011-04-25 21:05:07 +0000969UnwindAssembly_x86::GetPluginNameStatic()
Jason Molendafbcb7f22010-09-10 07:49:16 +0000970{
Greg Claytonffc922e32011-04-25 21:05:07 +0000971 return "UnwindAssembly_x86";
Jason Molendafbcb7f22010-09-10 07:49:16 +0000972}
973
974const char *
Greg Claytonffc922e32011-04-25 21:05:07 +0000975UnwindAssembly_x86::GetPluginDescriptionStatic()
Jason Molendafbcb7f22010-09-10 07:49:16 +0000976{
977 return "i386 and x86_64 assembly language profiler plugin.";
978}