]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdBase.h
Merge ^/head r274961 through r276342.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdBase.h
1 //===-- MICmdBase.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 //++
11 // File:                MICmdBase.h
12 //
13 // Overview:    CMICmdBase interface.
14 //
15 // Environment: Compilers:      Visual C++ 12.
16 //                                                      gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //                              Libraries:      See MIReadmetxt. 
18 //
19 // Copyright:   None.
20 //--
21
22 #pragma once
23
24 // In-house headers:
25 #include "MIUtilString.h"
26 #include "MICmnBase.h"
27 #include "MICmnResources.h"
28 #include "MICmdInvoker.h"
29 #include "MICmdFactory.h"
30 #include "MICmdData.h"
31 #include "MICmnMIResultRecord.h"
32 #include "MICmdArgSet.h"
33
34 // Declarations:
35 class CMICmnLLDBDebugSessionInfo;
36
37 //++ ============================================================================
38 // Details:     MI command base class. MI commands derive from this base class.
39 //                      The Command Factory creates command objects and passes them to the
40 //                      Command Invoker. The Invoker takes ownersip of any commands created 
41 //                      which means it is the only object to delete them when a command is 
42 //                      finished working. Commands do not delete themselves.
43 //                      There are two types of command implicitly defined by the state of 
44 //                      the m_bWaitForEventFromSBDebugger flag. There is the event type
45 //                      command which registers (command fn) callbacks with the SBListener 
46 //                      does some work then wakes up again when called back, does more work
47 //                      perhaps, ends, then the Invoker calls the command's Acknowledge 
48 //                      function. The other type of command is one that just does some work,
49 //                      ends, then the Invoker calls the command's Acknowledge function. No
50 //                      events set up.
51 //                      A command's Execute(), Acknowledge() and event callback functions are 
52 //                      carried out in the main thread.
53 //                      A command may use the argument derived object classes (CMICmdArgValBase)
54 //                      to factor handling and parsing of different types of arguments 
55 //                      presented to a command. A command will produce an error should it
56 //                      be presented with arguments or options it does not understand.
57 // Gotchas:     None.
58 // Authors:     Illya Rudkin 18/02/2014.
59 // Changes:     None.
60 //--
61 class CMICmdBase
62 :       public CMICmnBase
63 ,       public CMICmdInvoker::ICmd
64 ,       public CMICmdFactory::ICmd
65 {
66 // Methods:
67 public:
68         /* ctor */      CMICmdBase( void );
69
70 // Overridden:
71 public: 
72         // From CMICmdInvoker::ICmd
73         virtual const SMICmdData &              GetCmdData( void ) const;
74         virtual const CMIUtilString &   GetErrorDescription( void ) const;
75         virtual bool                                    SetCmdData( const SMICmdData & vCmdData );
76         virtual void                                    CmdFinishedTellInvoker( void ) const;
77         virtual const CMIUtilString &   GetMIResultRecord( void ) const;
78         virtual const CMIUtilString &   GetMIResultRecordExtra( void ) const;
79         virtual bool                                    HasMIResultRecordExtra( void ) const;
80         virtual bool                                    ParseArgs( void );
81         // From CMICmdFactory::ICmd
82         virtual const CMIUtilString &                   GetMiCmd( void ) const;
83         virtual CMICmdFactory::CmdCreatorFnPtr  GetCmdCreatorFn( void ) const;
84
85         virtual MIuint GetGUID( void );
86
87 // Overrideable:
88 public:
89         /* dtor */ virtual ~CMICmdBase( void );
90         virtual bool    GetExitAppOnCommandFailure( void ) const;
91
92 // Methods:
93 protected:
94         void    SetError( const CMIUtilString & rErrMsg );
95         template< class T >
96                 T * GetOption( const CMIUtilString & vStrOptionName );
97         bool    ParseValidateCmdOptions( void );
98         
99 // Attributes:
100 protected:
101         CMICmdFactory::CmdCreatorFnPtr  m_pSelfCreatorFn;
102         CMIUtilString                                   m_strCurrentErrDescription;                     // Reason for Execute or Acknowledge function failure
103         SMICmdData                                              m_cmdData;                                                      // Holds information/status of *this command. Used by other MI code to report or determine state of a command.
104         bool                                                    m_bWaitForEventFromSBDebugger;          // True = yes event type command wait, false = command calls Acknowledge() straight after Execute() no waiting
105         CMIUtilString                                   m_strMiCmd;                                                     // The MI text identifying *this command i.e. 'break-insert'
106         CMICmnMIResultRecord                    m_miResultRecord;                                       // This is completed in the Acknowledge() function and returned to the Command Invoker to proceed stdout output. Each command forms 1 response to its input.
107         CMIUtilString                                   m_miResultRecordExtra;                          // This is completed in the Acknowledge() function and returned to the Command Invoker to proceed stdout output. Hack command produce more response text to help the client because of using LLDB
108         CMICmnLLDBDebugSessionInfo &    m_rLLDBDebugSessionInfo;                        // Access to command sharing information or data across any and all command based derived classes.
109         bool                                                    m_bHasResultRecordExtra;                        // True = Yes command produced additional MI output to its 1 line response, false = no extra MI output formed.
110         CMICmdArgSet                                    m_setCmdArgs;                                           // The list of arguments *this command needs to parse from the options string to carry out work.
111 };
112
113 //++ ------------------------------------------------------------------------------------
114 // Details:     Retrieve the command argument or option object pointer so that it can be
115 //                      examined. If the option found and valid get the value (number, string or list
116 //                      - see CMICmdArgValBase class) from it to use with the command's decision
117 //                      making. If the argument is not found the command's error description is set
118 //                      describing the error condition.
119 // Type:        Template method.
120 // Args:        vStrOptionName  - (R)   The text name of the argument or option to search for in
121 //                                                                      the list of the command's possible arguments or options.
122 // Return:      T * - CMICmdArgValBase derived object.
123 //                              - NULL = function has failed, unable to retrieve the option/arg object.
124 // Throws:      None.
125 //--
126 template< class T >
127 T * CMICmdBase::GetOption( const CMIUtilString & vStrOptionName )
128 {
129         CMICmdArgValBase * pPtrBase = nullptr;
130         if( !m_setCmdArgs.GetArg( vStrOptionName, pPtrBase ) )
131         {
132                 SetError( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_OPTION_NOT_FOUND ), m_cmdData.strMiCmd.c_str(), vStrOptionName.c_str() ) );
133                 return nullptr;
134         }
135
136         return static_cast< T * >( pPtrBase );
137 }
138
139 //++ ------------------------------------------------------------------------------------
140 // Details:     Retrieve the command argument or option object pointer using template function
141 //                      CMICmdBase::GetOption(). Should the argument (by name) not be found the 
142 //                      command will exit with a failure (set in GetOption()).
143 // Type:        Preprocessor macro.
144 // Args:        a       - (R) The actual variable's name.
145 //                      b       - (R) The type of variable (appended to CMICmdArgVal i.e. CMICmdArgValString).
146 //                      c       - (R)   The text name of the argument or option to search for in the list of
147 //                                              the command's possible arguments or options.
148 // Return:      T * - CMICmdArgValBase derived object.
149 //                              - NULL = function has failed, unable to retrieve the option/arg object.
150 // Throws:      None.
151 //--
152 #define CMICMDBASE_GETOPTION( a, b, c )                                                                 \
153         CMICmdArgVal##b * a = CMICmdBase::GetOption< CMICmdArgVal##b >( c );\
154         if( a == nullptr )                                                                                                      \
155                 return MIstatus::failure;
156 // This comment is to stop compile warning for #define