Jason Molenda | 3a4ea24 | 2010-09-10 07:49:16 +0000 | [diff] [blame] | 1 | //===-- ArchDefaultUnwindPlan-x86.cpp --------------------------*- C++ -*-===// |
| 2 | // |
| 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 | |
| 10 | #include "ArchDefaultUnwindPlan-x86.h" |
| 11 | |
| 12 | #include "lldb/lldb-private.h" |
| 13 | #include "lldb/Utility/ArchDefaultUnwindPlan.h" |
| 14 | #include "lldb/Core/ArchSpec.h" |
| 15 | #include "lldb/Core/PluginManager.h" |
| 16 | #include "lldb/lldb-enumerations.h" |
| 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | lldb_private::UnwindPlan* |
| 22 | ArchDefaultUnwindPlan_x86::GetArchDefaultUnwindPlan (Thread& thread, Address current_pc) |
| 23 | { |
| 24 | if (m_cpu == CPU_TYPE_X86_64) |
| 25 | { |
| 26 | return &m_64bit_default; |
| 27 | } |
| 28 | if (m_cpu == CPU_TYPE_I386) |
| 29 | { |
| 30 | return &m_32bit_default; |
| 31 | } |
| 32 | return NULL; |
| 33 | } |
| 34 | |
| 35 | lldb_private::ArchDefaultUnwindPlan * |
| 36 | ArchDefaultUnwindPlan_x86::CreateInstance (const lldb_private::ArchSpec &arch) |
| 37 | { |
| 38 | uint32_t cpu = arch.GetCPUType (); |
| 39 | if (cpu != CPU_TYPE_X86_64 && cpu != CPU_TYPE_I386) |
| 40 | return NULL; |
| 41 | |
| 42 | return new ArchDefaultUnwindPlan_x86 (cpu); |
| 43 | } |
| 44 | |
| 45 | ArchDefaultUnwindPlan_x86::ArchDefaultUnwindPlan_x86(int cpu) : |
| 46 | lldb_private::ArchDefaultUnwindPlan(), |
| 47 | m_cpu(cpu), |
| 48 | m_32bit_default(), |
| 49 | m_64bit_default() |
| 50 | { |
| 51 | UnwindPlan::Row row; |
| 52 | UnwindPlan::Row::RegisterLocation regloc; |
| 53 | |
| 54 | m_32bit_default.SetRegisterKind (eRegisterKindGeneric); |
| 55 | row.SetCFARegister (LLDB_REGNUM_GENERIC_FP); |
| 56 | row.SetCFAOffset (2 * 4); |
| 57 | row.SetOffset (0); |
| 58 | |
| 59 | regloc.SetAtCFAPlusOffset (2 * -4); |
| 60 | row.SetRegisterInfo (LLDB_REGNUM_GENERIC_FP, regloc); |
| 61 | regloc.SetAtCFAPlusOffset (1 * -4); |
| 62 | row.SetRegisterInfo (LLDB_REGNUM_GENERIC_PC, regloc); |
| 63 | regloc.SetIsCFAPlusOffset (0); |
| 64 | row.SetRegisterInfo (LLDB_REGNUM_GENERIC_SP, regloc); |
| 65 | |
| 66 | m_32bit_default.AppendRow (row); |
| 67 | |
| 68 | row.Clear(); |
| 69 | |
| 70 | m_64bit_default.SetRegisterKind (eRegisterKindGeneric); |
| 71 | row.SetCFARegister (LLDB_REGNUM_GENERIC_FP); |
| 72 | row.SetCFAOffset (2 * 8); |
| 73 | row.SetOffset (0); |
| 74 | |
| 75 | regloc.SetAtCFAPlusOffset (2 * -8); |
| 76 | row.SetRegisterInfo (LLDB_REGNUM_GENERIC_FP, regloc); |
| 77 | regloc.SetAtCFAPlusOffset (1 * -8); |
| 78 | row.SetRegisterInfo (LLDB_REGNUM_GENERIC_PC, regloc); |
| 79 | regloc.SetIsCFAPlusOffset (0); |
| 80 | row.SetRegisterInfo (LLDB_REGNUM_GENERIC_SP, regloc); |
| 81 | |
| 82 | m_64bit_default.AppendRow (row); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | //------------------------------------------------------------------ |
| 89 | // PluginInterface protocol in UnwindAssemblyParser_x86 |
| 90 | //------------------------------------------------------------------ |
| 91 | |
| 92 | const char * |
| 93 | ArchDefaultUnwindPlan_x86::GetPluginName() |
| 94 | { |
| 95 | return "ArchDefaultUnwindPlan_x86"; |
| 96 | } |
| 97 | |
| 98 | const char * |
| 99 | ArchDefaultUnwindPlan_x86::GetShortPluginName() |
| 100 | { |
| 101 | return "archdefaultunwindplan.x86"; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | uint32_t |
| 106 | ArchDefaultUnwindPlan_x86::GetPluginVersion() |
| 107 | { |
| 108 | return 1; |
| 109 | } |
| 110 | |
| 111 | void |
| 112 | ArchDefaultUnwindPlan_x86::GetPluginCommandHelp (const char *command, Stream *strm) |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | Error |
| 117 | ArchDefaultUnwindPlan_x86::ExecutePluginCommand (Args &command, Stream *strm) |
| 118 | { |
| 119 | Error error; |
| 120 | error.SetErrorString("No plug-in command are currently supported."); |
| 121 | return error; |
| 122 | } |
| 123 | |
| 124 | Log * |
| 125 | ArchDefaultUnwindPlan_x86::EnablePluginLogging (Stream *strm, Args &command) |
| 126 | { |
| 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | void |
| 131 | ArchDefaultUnwindPlan_x86::Initialize() |
| 132 | { |
| 133 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 134 | GetPluginDescriptionStatic(), |
| 135 | CreateInstance); |
| 136 | } |
| 137 | |
| 138 | void |
| 139 | ArchDefaultUnwindPlan_x86::Terminate() |
| 140 | { |
| 141 | PluginManager::UnregisterPlugin (CreateInstance); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | const char * |
| 146 | ArchDefaultUnwindPlan_x86::GetPluginNameStatic() |
| 147 | { |
| 148 | return "ArchDefaultUnwindPlan_x86"; |
| 149 | } |
| 150 | |
| 151 | const char * |
| 152 | ArchDefaultUnwindPlan_x86::GetPluginDescriptionStatic() |
| 153 | { |
| 154 | return "i386 and x86_64 architecture default unwind plan assembly plugin."; |
| 155 | } |