1 //===------------------- ABISysV_i386.h -------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_ABISysV_i386_h_
10 #define liblldb_ABISysV_i386_h_
11 
12 #include "lldb/Target/ABI.h"
13 #include "lldb/lldb-private.h"
14 
15 class ABISysV_i386 : public lldb_private::ABI {
16 public:
17   ~ABISysV_i386() override = default;
18 
GetRedZoneSize()19   size_t GetRedZoneSize() const override {
20     return 0; // There is no red zone for i386 Architecture
21   }
22 
23   bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
24                           lldb::addr_t functionAddress,
25                           lldb::addr_t returnAddress,
26                           llvm::ArrayRef<lldb::addr_t> args) const override;
27 
28   bool GetArgumentValues(lldb_private::Thread &thread,
29                          lldb_private::ValueList &values) const override;
30 
31   lldb_private::Status
32   SetReturnValueObject(lldb::StackFrameSP &frame_sp,
33                        lldb::ValueObjectSP &new_value) override;
34 
35   lldb::ValueObjectSP
36   GetReturnValueObjectImpl(lldb_private::Thread &thread,
37                            lldb_private::CompilerType &type) const override;
38 
39   bool
40   CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
41 
42   bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
43 
RegisterIsVolatile(const lldb_private::RegisterInfo * reg_info)44   bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override {
45     return !RegisterIsCalleeSaved(reg_info);
46   }
47 
48   // The SysV i386 ABI requires that stack frames be 16 byte aligned.
49   // When there is a trap handler on the stack, e.g. _sigtramp in userland
50   // code, we've seen that the stack pointer is often not aligned properly
51   // before the handler is invoked.  This means that lldb will stop the unwind
52   // early -- before the function which caused the trap.
53   //
54   // To work around this, we relax that alignment to be just word-size
55   // (4-bytes).
56   // Whitelisting the trap handlers for user space would be easy (_sigtramp) but
57   // in other environments there can be a large number of different functions
58   // involved in async traps.
59 
60   // ToDo: When __m256 arguments are passed then stack frames should be
61   // 32 byte aligned. Decide what to do for 32 byte alignment checking
CallFrameAddressIsValid(lldb::addr_t cfa)62   bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
63     // Make sure the stack call frame addresses are 4 byte aligned
64     if (cfa & (4ull - 1ull))
65       return false; // Not 4 byte aligned
66     if (cfa == 0)
67       return false; // Zero is not a valid stack address
68     return true;
69   }
70 
CodeAddressIsValid(lldb::addr_t pc)71   bool CodeAddressIsValid(lldb::addr_t pc) override {
72     // Check whether the address is a valid 32 bit address
73     return (pc <= UINT32_MAX);
74   }
75 
76   const lldb_private::RegisterInfo *
77   GetRegisterInfoArray(uint32_t &count) override;
78 
79   // Static Functions
80 
81   static void Initialize();
82 
83   static void Terminate();
84 
85   static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch);
86 
87   // PluginInterface protocol
88 
89   static lldb_private::ConstString GetPluginNameStatic();
90 
91   lldb_private::ConstString GetPluginName() override;
92 
GetPluginVersion()93   uint32_t GetPluginVersion() override { return 1; }
94 
95 protected:
96   lldb::ValueObjectSP
97   GetReturnValueObjectSimple(lldb_private::Thread &thread,
98                              lldb_private::CompilerType &ast_type) const;
99 
100   bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
101 
102 private:
ABISysV_i386(lldb::ProcessSP process_sp,std::unique_ptr<llvm::MCRegisterInfo> info_up)103   ABISysV_i386(lldb::ProcessSP process_sp,
104                std::unique_ptr<llvm::MCRegisterInfo> info_up)
105       : lldb_private::ABI(std::move(process_sp), std::move(info_up)) {
106     // Call CreateInstance instead.
107   }
108 };
109 
110 #endif // liblldb_ABISysV_i386_h_
111