]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Debugger.h
Update from sqlite3-3.14.1 to sqlite3-3.20.0. This is a private lib.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / Debugger.h
1 //===-- Debugger.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_Debugger_h_
11 #define liblldb_Debugger_h_
12
13 // C Includes
14 #include <stdint.h>
15
16 // C++ Includes
17 #include <memory>
18 #include <vector>
19
20 // Other libraries and framework includes
21 // Project includes
22 #include "lldb/Core/Broadcaster.h"
23 #include "lldb/Core/FormatEntity.h"
24 #include "lldb/Core/IOHandler.h"
25 #include "lldb/Core/SourceManager.h"
26 #include "lldb/Core/UserSettingsController.h"
27 #include "lldb/Host/HostThread.h"
28 #include "lldb/Host/Terminal.h"
29 #include "lldb/Target/ExecutionContext.h" // for ExecutionContext
30 #include "lldb/Target/Platform.h"
31 #include "lldb/Target/TargetList.h"
32 #include "lldb/Utility/ConstString.h" // for ConstString
33 #include "lldb/Utility/FileSpec.h"    // for FileSpec
34 #include "lldb/Utility/Status.h"      // for Status
35 #include "lldb/Utility/UserID.h"
36 #include "lldb/lldb-defines.h"              // for DISALLOW_COPY_AND_ASSIGN
37 #include "lldb/lldb-enumerations.h"         // for ScriptLanguage, Langua...
38 #include "lldb/lldb-forward.h"              // for StreamFileSP, DebuggerSP
39 #include "lldb/lldb-private-enumerations.h" // for VarSetOperationType
40 #include "lldb/lldb-private-types.h"        // for LoadPluginCallbackType
41 #include "lldb/lldb-types.h"                // for LogOutputCallback, thr...
42
43 #include "llvm/ADT/ArrayRef.h"           // for ArrayRef
44 #include "llvm/ADT/StringMap.h"          // for StringMap
45 #include "llvm/ADT/StringRef.h"          // for StringRef
46 #include "llvm/Support/DynamicLibrary.h" // for DynamicLibrary
47 #include "llvm/Support/Threading.h"
48
49 #include <assert.h> // for assert
50 #include <stddef.h> // for size_t
51 #include <stdio.h>
52
53 namespace lldb_private {
54 class Address;
55 }
56 namespace lldb_private {
57 class CommandInterpreter;
58 }
59 namespace lldb_private {
60 class Process;
61 }
62 namespace lldb_private {
63 class Stream;
64 }
65 namespace lldb_private {
66 class SymbolContext;
67 }
68 namespace lldb_private {
69 class Target;
70 }
71 namespace llvm {
72 class raw_ostream;
73 }
74
75 namespace lldb_private {
76
77 //----------------------------------------------------------------------
78 /// @class Debugger Debugger.h "lldb/Core/Debugger.h"
79 /// @brief A class to manage flag bits.
80 ///
81 /// Provides a global root objects for the debugger core.
82 //----------------------------------------------------------------------
83
84 class Debugger : public std::enable_shared_from_this<Debugger>,
85                  public UserID,
86                  public Properties {
87   friend class SourceManager; // For GetSourceFileCache.
88
89 public:
90   ~Debugger() override;
91
92   static lldb::DebuggerSP
93   CreateInstance(lldb::LogOutputCallback log_callback = nullptr,
94                  void *baton = nullptr);
95
96   static lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid);
97
98   static lldb::TargetSP FindTargetWithProcess(Process *process);
99
100   static void Initialize(LoadPluginCallbackType load_plugin_callback);
101
102   static void Terminate();
103
104   static void SettingsInitialize();
105
106   static void SettingsTerminate();
107
108   static void Destroy(lldb::DebuggerSP &debugger_sp);
109
110   static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id);
111
112   static lldb::DebuggerSP
113   FindDebuggerWithInstanceName(const ConstString &instance_name);
114
115   static size_t GetNumDebuggers();
116
117   static lldb::DebuggerSP GetDebuggerAtIndex(size_t index);
118
119   static bool FormatDisassemblerAddress(const FormatEntity::Entry *format,
120                                         const SymbolContext *sc,
121                                         const SymbolContext *prev_sc,
122                                         const ExecutionContext *exe_ctx,
123                                         const Address *addr, Stream &s);
124
125   void Clear();
126
127   bool GetAsyncExecution();
128
129   void SetAsyncExecution(bool async);
130
131   lldb::StreamFileSP GetInputFile() { return m_input_file_sp; }
132
133   lldb::StreamFileSP GetOutputFile() { return m_output_file_sp; }
134
135   lldb::StreamFileSP GetErrorFile() { return m_error_file_sp; }
136
137   void SetInputFileHandle(FILE *fh, bool tranfer_ownership);
138
139   void SetOutputFileHandle(FILE *fh, bool tranfer_ownership);
140
141   void SetErrorFileHandle(FILE *fh, bool tranfer_ownership);
142
143   void SaveInputTerminalState();
144
145   void RestoreInputTerminalState();
146
147   lldb::StreamSP GetAsyncOutputStream();
148
149   lldb::StreamSP GetAsyncErrorStream();
150
151   CommandInterpreter &GetCommandInterpreter() {
152     assert(m_command_interpreter_ap.get());
153     return *m_command_interpreter_ap;
154   }
155
156   lldb::ListenerSP GetListener() { return m_listener_sp; }
157
158   // This returns the Debugger's scratch source manager.  It won't be able to
159   // look up files in debug
160   // information, but it can look up files by absolute path and display them to
161   // you.
162   // To get the target's source manager, call GetSourceManager on the target
163   // instead.
164   SourceManager &GetSourceManager();
165
166   lldb::TargetSP GetSelectedTarget() {
167     return m_target_list.GetSelectedTarget();
168   }
169
170   ExecutionContext GetSelectedExecutionContext();
171   //------------------------------------------------------------------
172   /// Get accessor for the target list.
173   ///
174   /// The target list is part of the global debugger object. This
175   /// the single debugger shared instance to control where targets
176   /// get created and to allow for tracking and searching for targets
177   /// based on certain criteria.
178   ///
179   /// @return
180   ///     A global shared target list.
181   //------------------------------------------------------------------
182   TargetList &GetTargetList() { return m_target_list; }
183
184   PlatformList &GetPlatformList() { return m_platform_list; }
185
186   void DispatchInputInterrupt();
187
188   void DispatchInputEndOfFile();
189
190   //------------------------------------------------------------------
191   // If any of the streams are not set, set them to the in/out/err
192   // stream of the top most input reader to ensure they at least have
193   // something
194   //------------------------------------------------------------------
195   void AdoptTopIOHandlerFilesIfInvalid(lldb::StreamFileSP &in,
196                                        lldb::StreamFileSP &out,
197                                        lldb::StreamFileSP &err);
198
199   void PushIOHandler(const lldb::IOHandlerSP &reader_sp);
200
201   bool PopIOHandler(const lldb::IOHandlerSP &reader_sp);
202
203   // Synchronously run an input reader until it is done
204   void RunIOHandler(const lldb::IOHandlerSP &reader_sp);
205
206   bool IsTopIOHandler(const lldb::IOHandlerSP &reader_sp);
207
208   bool CheckTopIOHandlerTypes(IOHandler::Type top_type,
209                               IOHandler::Type second_top_type);
210
211   void PrintAsync(const char *s, size_t len, bool is_stdout);
212
213   ConstString GetTopIOHandlerControlSequence(char ch);
214
215   const char *GetIOHandlerCommandPrefix();
216
217   const char *GetIOHandlerHelpPrologue();
218
219   void ClearIOHandlers();
220
221   bool GetCloseInputOnEOF() const;
222
223   void SetCloseInputOnEOF(bool b);
224
225   bool EnableLog(llvm::StringRef channel,
226                  llvm::ArrayRef<const char *> categories,
227                  llvm::StringRef log_file, uint32_t log_options,
228                  llvm::raw_ostream &error_stream);
229
230   void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton);
231
232   //----------------------------------------------------------------------
233   // Properties Functions
234   //----------------------------------------------------------------------
235   enum StopDisassemblyType {
236     eStopDisassemblyTypeNever = 0,
237     eStopDisassemblyTypeNoDebugInfo,
238     eStopDisassemblyTypeNoSource,
239     eStopDisassemblyTypeAlways
240   };
241
242   Status SetPropertyValue(const ExecutionContext *exe_ctx,
243                           VarSetOperationType op, llvm::StringRef property_path,
244                           llvm::StringRef value) override;
245
246   bool GetAutoConfirm() const;
247
248   const FormatEntity::Entry *GetDisassemblyFormat() const;
249
250   const FormatEntity::Entry *GetFrameFormat() const;
251
252   const FormatEntity::Entry *GetFrameFormatUnique() const;
253
254   const FormatEntity::Entry *GetThreadFormat() const;
255
256   const FormatEntity::Entry *GetThreadStopFormat() const;
257
258   lldb::ScriptLanguage GetScriptLanguage() const;
259
260   bool SetScriptLanguage(lldb::ScriptLanguage script_lang);
261
262   uint32_t GetTerminalWidth() const;
263
264   bool SetTerminalWidth(uint32_t term_width);
265
266   llvm::StringRef GetPrompt() const;
267
268   void SetPrompt(llvm::StringRef p);
269   void SetPrompt(const char *) = delete;
270
271   bool GetUseExternalEditor() const;
272
273   bool SetUseExternalEditor(bool use_external_editor_p);
274
275   bool GetUseColor() const;
276
277   bool SetUseColor(bool use_color);
278
279   lldb::StopShowColumn GetStopShowColumn() const;
280
281   const FormatEntity::Entry *GetStopShowColumnAnsiPrefix() const;
282
283   const FormatEntity::Entry *GetStopShowColumnAnsiSuffix() const;
284
285   uint32_t GetStopSourceLineCount(bool before) const;
286
287   StopDisassemblyType GetStopDisassemblyDisplay() const;
288
289   uint32_t GetDisassemblyLineCount() const;
290
291   bool GetAutoOneLineSummaries() const;
292
293   bool GetAutoIndent() const;
294
295   bool SetAutoIndent(bool b);
296
297   bool GetPrintDecls() const;
298
299   bool SetPrintDecls(bool b);
300
301   uint32_t GetTabSize() const;
302
303   bool SetTabSize(uint32_t tab_size);
304
305   bool GetEscapeNonPrintables() const;
306
307   bool GetNotifyVoid() const;
308
309   const ConstString &GetInstanceName() { return m_instance_name; }
310
311   bool LoadPlugin(const FileSpec &spec, Status &error);
312
313   void ExecuteIOHandlers();
314
315   bool IsForwardingEvents();
316
317   void EnableForwardEvents(const lldb::ListenerSP &listener_sp);
318
319   void CancelForwardEvents(const lldb::ListenerSP &listener_sp);
320
321   bool IsHandlingEvents() const { return m_event_handler_thread.IsJoinable(); }
322
323   Status RunREPL(lldb::LanguageType language, const char *repl_options);
324
325   // This is for use in the command interpreter, when you either want the
326   // selected target, or if no target
327   // is present you want to prime the dummy target with entities that will be
328   // copied over to new targets.
329   Target *GetSelectedOrDummyTarget(bool prefer_dummy = false);
330   Target *GetDummyTarget();
331
332   lldb::BroadcasterManagerSP GetBroadcasterManager() {
333     return m_broadcaster_manager_sp;
334   }
335
336 protected:
337   friend class CommandInterpreter;
338   friend class REPL;
339
340   bool StartEventHandlerThread();
341
342   void StopEventHandlerThread();
343
344   static lldb::thread_result_t EventHandlerThread(lldb::thread_arg_t arg);
345
346   bool HasIOHandlerThread();
347
348   bool StartIOHandlerThread();
349
350   void StopIOHandlerThread();
351
352   void JoinIOHandlerThread();
353
354   static lldb::thread_result_t IOHandlerThread(lldb::thread_arg_t arg);
355
356   void DefaultEventHandler();
357
358   void HandleBreakpointEvent(const lldb::EventSP &event_sp);
359
360   void HandleProcessEvent(const lldb::EventSP &event_sp);
361
362   void HandleThreadEvent(const lldb::EventSP &event_sp);
363
364   size_t GetProcessSTDOUT(Process *process, Stream *stream);
365
366   size_t GetProcessSTDERR(Process *process, Stream *stream);
367
368   SourceManager::SourceFileCache &GetSourceFileCache() {
369     return m_source_file_cache;
370   }
371
372   void InstanceInitialize();
373
374   lldb::StreamFileSP m_input_file_sp;
375   lldb::StreamFileSP m_output_file_sp;
376   lldb::StreamFileSP m_error_file_sp;
377
378   lldb::BroadcasterManagerSP m_broadcaster_manager_sp; // The debugger acts as a
379                                                        // broadcaster manager of
380                                                        // last resort.
381   // It needs to get constructed before the target_list or any other
382   // member that might want to broadcast through the debugger.
383
384   TerminalState m_terminal_state;
385   TargetList m_target_list;
386
387   PlatformList m_platform_list;
388   lldb::ListenerSP m_listener_sp;
389   std::unique_ptr<SourceManager> m_source_manager_ap; // This is a scratch
390                                                       // source manager that we
391                                                       // return if we have no
392                                                       // targets.
393   SourceManager::SourceFileCache m_source_file_cache; // All the source managers
394                                                       // for targets created in
395                                                       // this debugger used this
396                                                       // shared
397                                                       // source file cache.
398   std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
399
400   IOHandlerStack m_input_reader_stack;
401   llvm::StringMap<std::weak_ptr<llvm::raw_ostream>> m_log_streams;
402   std::shared_ptr<llvm::raw_ostream> m_log_callback_stream_sp;
403   ConstString m_instance_name;
404   static LoadPluginCallbackType g_load_plugin_callback;
405   typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
406   LoadedPluginsList m_loaded_plugins;
407   HostThread m_event_handler_thread;
408   HostThread m_io_handler_thread;
409   Broadcaster m_sync_broadcaster;
410   lldb::ListenerSP m_forward_listener_sp;
411   llvm::once_flag m_clear_once;
412
413   //----------------------------------------------------------------------
414   // Events for m_sync_broadcaster
415   //----------------------------------------------------------------------
416   enum {
417     eBroadcastBitEventThreadIsListening = (1 << 0),
418   };
419
420 private:
421   // Use Debugger::CreateInstance() to get a shared pointer to a new
422   // debugger object
423   Debugger(lldb::LogOutputCallback m_log_callback, void *baton);
424
425   DISALLOW_COPY_AND_ASSIGN(Debugger);
426 };
427
428 } // namespace lldb_private
429
430 #endif // liblldb_Debugger_h_