Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 1 | //===-- ArchVolatileRegs-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 "ArchVolatileRegs-x86.h" |
Chris Lattner | 2fcb13e | 2010-10-04 21:24:01 +0000 | [diff] [blame] | 11 | #include "llvm/Support/MachO.h" |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 12 | #include "lldb/lldb-private.h" |
| 13 | #include "lldb/Utility/ArchVolatileRegs.h" |
| 14 | #include "lldb/Core/ArchSpec.h" |
| 15 | #include "lldb/Core/PluginManager.h" |
| 16 | #include "lldb/lldb-enumerations.h" |
| 17 | #include "lldb/Target/Thread.h" |
| 18 | #include "lldb/Target/RegisterContext.h" |
| 19 | #include <set> |
| 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | bool |
| 25 | ArchVolatileRegs_x86::RegisterIsVolatile (Thread& thread, uint32_t regnum) |
| 26 | { |
| 27 | initialize_regset (thread); |
| 28 | if (m_non_volatile_regs.find (regnum) == m_non_volatile_regs.end()) |
| 29 | return true; |
| 30 | else |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | lldb_private::ArchVolatileRegs * |
| 35 | ArchVolatileRegs_x86::CreateInstance (const lldb_private::ArchSpec &arch) |
| 36 | { |
| 37 | uint32_t cpu = arch.GetCPUType (); |
Chris Lattner | 2fcb13e | 2010-10-04 21:24:01 +0000 | [diff] [blame] | 38 | if (cpu != llvm::MachO::CPUTypeX86_64 && cpu != llvm::MachO::CPUTypeI386) |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 39 | return NULL; |
| 40 | |
| 41 | return new ArchVolatileRegs_x86 (cpu); |
| 42 | } |
| 43 | |
| 44 | ArchVolatileRegs_x86::ArchVolatileRegs_x86(int cpu) : |
| 45 | lldb_private::ArchVolatileRegs(), |
| 46 | m_cpu(cpu), |
| 47 | m_non_volatile_regs() |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | |
| 53 | ArchVolatileRegs_x86::initialize_regset(Thread& thread) |
| 54 | { |
| 55 | if (m_non_volatile_regs.size() > 0) |
| 56 | return; |
| 57 | |
| 58 | |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame^] | 59 | RegisterContext *reg_ctx = thread.GetRegisterContext().get(); |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 60 | const RegisterInfo *ri; |
| 61 | |
| 62 | const char *x86_64_regnames[] = { "rbx", |
| 63 | "rsp", |
| 64 | "rbp", |
| 65 | "r12", |
| 66 | "r13", |
| 67 | "r14", |
| 68 | "r15", |
| 69 | "rip" }; |
| 70 | |
| 71 | const char *i386_regnames[] = { "ebx", |
| 72 | "ebp", |
| 73 | "esi", |
| 74 | "edi", |
| 75 | "esp", |
| 76 | "eip" }; |
| 77 | |
| 78 | |
| 79 | const char **names; |
| 80 | int namecount; |
Chris Lattner | 2fcb13e | 2010-10-04 21:24:01 +0000 | [diff] [blame] | 81 | if (m_cpu == llvm::MachO::CPUTypeX86_64) |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 82 | { |
| 83 | names = x86_64_regnames; |
| 84 | namecount = sizeof (x86_64_regnames) / sizeof (char *); |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | names = i386_regnames; |
| 89 | namecount = sizeof (i386_regnames) / sizeof (char *); |
| 90 | } |
| 91 | |
| 92 | for (int i = 0; i < namecount; i++) |
| 93 | { |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame^] | 94 | ri = reg_ctx->GetRegisterInfoByName (names[i]); |
Jason Molenda | ea0dbca | 2010-09-22 07:37:07 +0000 | [diff] [blame] | 95 | if (ri) |
| 96 | m_non_volatile_regs.insert (ri->kinds[eRegisterKindLLDB]); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | |
| 101 | //------------------------------------------------------------------ |
| 102 | // PluginInterface protocol in ArchVolatileRegs_x86 |
| 103 | //------------------------------------------------------------------ |
| 104 | |
| 105 | const char * |
| 106 | ArchVolatileRegs_x86::GetPluginName() |
| 107 | { |
| 108 | return "ArchVolatileRegs_x86"; |
| 109 | } |
| 110 | |
| 111 | const char * |
| 112 | ArchVolatileRegs_x86::GetShortPluginName() |
| 113 | { |
| 114 | return "archvolatileregs.x86"; |
| 115 | } |
| 116 | |
| 117 | |
| 118 | uint32_t |
| 119 | ArchVolatileRegs_x86::GetPluginVersion() |
| 120 | { |
| 121 | return 1; |
| 122 | } |
| 123 | |
| 124 | void |
| 125 | ArchVolatileRegs_x86::GetPluginCommandHelp (const char *command, Stream *strm) |
| 126 | { |
| 127 | } |
| 128 | |
| 129 | Error |
| 130 | ArchVolatileRegs_x86::ExecutePluginCommand (Args &command, Stream *strm) |
| 131 | { |
| 132 | Error error; |
| 133 | error.SetErrorString("No plug-in command are currently supported."); |
| 134 | return error; |
| 135 | } |
| 136 | |
| 137 | Log * |
| 138 | ArchVolatileRegs_x86::EnablePluginLogging (Stream *strm, Args &command) |
| 139 | { |
| 140 | return NULL; |
| 141 | } |
| 142 | |
| 143 | void |
| 144 | ArchVolatileRegs_x86::Initialize() |
| 145 | { |
| 146 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 147 | GetPluginDescriptionStatic(), |
| 148 | CreateInstance); |
| 149 | } |
| 150 | |
| 151 | void |
| 152 | ArchVolatileRegs_x86::Terminate() |
| 153 | { |
| 154 | PluginManager::UnregisterPlugin (CreateInstance); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | const char * |
| 159 | ArchVolatileRegs_x86::GetPluginNameStatic() |
| 160 | { |
| 161 | return "ArchVolatileRegs_x86"; |
| 162 | } |
| 163 | |
| 164 | const char * |
| 165 | ArchVolatileRegs_x86::GetPluginDescriptionStatic() |
| 166 | { |
| 167 | return "i386 and x86_64 architecture volatile register information."; |
| 168 | } |