1 //===------------------- ABISysV_i386.h -------------------------*- 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 #ifndef liblldb_ABISysV_i386_h_ 11 #define liblldb_ABISysV_i386_h_ 12 13 // C Includes 14 // C++ Includes 15 // Other libraries and framework includes 16 // Project includes 17 #include "lldb/lldb-private.h" 18 #include "lldb/Target/ABI.h" 19 20 class ABISysV_i386 : 21 public lldb_private::ABI 22 { 23 public: 24 ~ABISysV_i386()25 ~ABISysV_i386() 26 { 27 } 28 29 size_t GetRedZoneSize()30 GetRedZoneSize () const override 31 { 32 return 0; // There is no red zone for i386 Architecture 33 } 34 35 bool 36 PrepareTrivialCall (lldb_private::Thread &thread, 37 lldb::addr_t sp, 38 lldb::addr_t functionAddress, 39 lldb::addr_t returnAddress, 40 llvm::ArrayRef<lldb::addr_t> args) const override; 41 42 bool 43 GetArgumentValues (lldb_private::Thread &thread, 44 lldb_private::ValueList &values) const override; 45 46 lldb_private::Error 47 SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override; 48 49 protected: 50 lldb::ValueObjectSP 51 GetReturnValueObjectSimple (lldb_private::Thread &thread, 52 lldb_private::ClangASTType &ast_type) const; 53 54 bool 55 RegisterIsCalleeSaved (const lldb_private::RegisterInfo *reg_info); 56 57 public: 58 lldb::ValueObjectSP 59 GetReturnValueObjectImpl (lldb_private::Thread &thread, 60 lldb_private::ClangASTType &type) const override; 61 62 bool 63 CreateFunctionEntryUnwindPlan (lldb_private::UnwindPlan &unwind_plan) override; 64 65 bool 66 CreateDefaultUnwindPlan (lldb_private::UnwindPlan &unwind_plan) override; 67 68 bool RegisterIsVolatile(const lldb_private::RegisterInfo * reg_info)69 RegisterIsVolatile (const lldb_private::RegisterInfo *reg_info) override 70 { 71 return !RegisterIsCalleeSaved (reg_info); 72 } 73 74 // The SysV i386 ABI requires that stack frames be 16 byte aligned. 75 // When there is a trap handler on the stack, e.g. _sigtramp in userland 76 // code, we've seen that the stack pointer is often not aligned properly 77 // before the handler is invoked. This means that lldb will stop the unwind 78 // early -- before the function which caused the trap. 79 // 80 // To work around this, we relax that alignment to be just word-size (4-bytes). 81 // Whitelisting the trap handlers for user space would be easy (_sigtramp) but 82 // in other environments there can be a large number of different functions 83 // involved in async traps. 84 85 // ToDo: When __m256 arguments are passed then stack frames should be 86 // 32 byte aligned. Decide what to do for 32 byte alignment checking 87 bool CallFrameAddressIsValid(lldb::addr_t cfa)88 CallFrameAddressIsValid (lldb::addr_t cfa) override 89 { 90 // Make sure the stack call frame addresses are 4 byte aligned 91 if (cfa & (4ull - 1ull)) 92 return false; // Not 4 byte aligned 93 if (cfa == 0) 94 return false; // Zero is not a valid stack address 95 return true; 96 } 97 98 bool CodeAddressIsValid(lldb::addr_t pc)99 CodeAddressIsValid (lldb::addr_t pc) override 100 { 101 // Check whether the address is a valid 32 bit address 102 return (pc <= UINT32_MAX); 103 } 104 105 const lldb_private::RegisterInfo * 106 GetRegisterInfoArray (uint32_t &count) override; 107 //------------------------------------------------------------------ 108 // Static Functions 109 //------------------------------------------------------------------ 110 static void 111 Initialize(); 112 113 static void 114 Terminate(); 115 116 static lldb::ABISP 117 CreateInstance (const lldb_private::ArchSpec &arch); 118 119 //------------------------------------------------------------------ 120 // PluginInterface protocol 121 //------------------------------------------------------------------ 122 static lldb_private::ConstString 123 GetPluginNameStatic(); 124 125 lldb_private::ConstString 126 GetPluginName() override; 127 128 uint32_t GetPluginVersion()129 GetPluginVersion() override 130 { 131 return 1; 132 } 133 134 private: ABISysV_i386()135 ABISysV_i386() : lldb_private::ABI() { } // Call CreateInstance instead. 136 }; 137 138 #endif // liblldb_ABI_h 139