ABI.h revision 263367
1//===-- ABI.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_ABI_h_
11#define liblldb_ABI_h_
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16// Project includes
17#include "lldb/Core/Error.h"
18#include "lldb/Core/PluginInterface.h"
19#include "lldb/lldb-private.h"
20
21#include "llvm/ADT/ArrayRef.h"
22
23namespace lldb_private {
24
25class ABI :
26    public PluginInterface
27{
28public:
29    virtual
30    ~ABI();
31
32    virtual size_t
33    GetRedZoneSize () const = 0;
34
35    virtual bool
36    PrepareTrivialCall (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 = 0;
41
42    virtual bool
43    GetArgumentValues (Thread &thread,
44                       ValueList &values) const = 0;
45
46    lldb::ValueObjectSP
47    GetReturnValueObject (Thread &thread,
48                          ClangASTType &type,
49                          bool persistent = true) const;
50
51    // Set the Return value object in the current frame as though a function with
52    virtual Error
53    SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) = 0;
54
55protected:
56    // This is the method the ABI will call to actually calculate the return value.
57    // Don't put it in a persistant value object, that will be done by the ABI::GetReturnValueObject.
58    virtual lldb::ValueObjectSP
59    GetReturnValueObjectImpl (Thread &thread,
60                          ClangASTType &type) const = 0;
61public:
62    virtual bool
63    CreateFunctionEntryUnwindPlan (UnwindPlan &unwind_plan) = 0;
64
65    virtual bool
66    CreateDefaultUnwindPlan (UnwindPlan &unwind_plan) = 0;
67
68    virtual bool
69    RegisterIsVolatile (const RegisterInfo *reg_info) = 0;
70
71    // Should return true if your ABI uses frames when doing stack backtraces. This
72    // means a frame pointer is used that points to the previous stack frame in some
73    // way or another.
74    virtual bool
75    StackUsesFrames () = 0;
76
77    // Should take a look at a call frame address (CFA) which is just the stack
78    // pointer value upon entry to a function. ABIs usually impose alignment
79    // restrictions (4, 8 or 16 byte aligned), and zero is usually not allowed.
80    // This function should return true if "cfa" is valid call frame address for
81    // the ABI, and false otherwise. This is used by the generic stack frame unwinding
82    // code to help determine when a stack ends.
83    virtual bool
84    CallFrameAddressIsValid (lldb::addr_t cfa) = 0;
85
86    // Validates a possible PC value and returns true if an opcode can be at "pc".
87    virtual bool
88    CodeAddressIsValid (lldb::addr_t pc) = 0;
89
90    virtual lldb::addr_t
91    FixCodeAddress (lldb::addr_t pc)
92    {
93        // Some targets might use bits in a code address to indicate
94        // a mode switch. ARM uses bit zero to signify a code address is
95        // thumb, so any ARM ABI plug-ins would strip those bits.
96        return pc;
97    }
98
99    virtual const RegisterInfo *
100    GetRegisterInfoArray (uint32_t &count) = 0;
101
102    // Some architectures (e.g. x86) will push the return address on the stack and decrement
103    // the stack pointer when making a function call.  This means that every stack frame will
104    // have a unique CFA.
105    // Other architectures (e.g. arm) pass the return address in a register so it is possible
106    // to have a frame on a backtrace that does not push anything on the stack or change the
107    // CFA.
108    virtual bool
109    FunctionCallsChangeCFA () = 0;
110
111
112    bool
113    GetRegisterInfoByName (const ConstString &name, RegisterInfo &info);
114
115    bool
116    GetRegisterInfoByKind (lldb::RegisterKind reg_kind,
117                           uint32_t reg_num,
118                           RegisterInfo &info);
119
120    static lldb::ABISP
121    FindPlugin (const ArchSpec &arch);
122
123protected:
124    //------------------------------------------------------------------
125    // Classes that inherit from ABI can see and modify these
126    //------------------------------------------------------------------
127    ABI();
128private:
129    DISALLOW_COPY_AND_ASSIGN (ABI);
130};
131
132} // namespace lldb_private
133
134#endif  // liblldb_ABI_h_
135