blob: ffeef8951c938a0b7f2c44013b66176839cfddc0 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Driver.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 lldb_Driver_h_
11#define lldb_Driver_h_
12
Jason Molendaa34a0c62010-06-09 21:28:42 +000013#include "lldb/Utility/PseudoTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014
15#include <set>
16#include <bitset>
17#include <string>
18#include <vector>
19
Eli Friedman778b0852010-06-09 06:50:29 +000020#include "lldb/API/SBDefines.h"
21#include "lldb/API/SBBroadcaster.h"
Greg Clayton66111032010-06-23 01:19:29 +000022#include "lldb/API/SBDebugger.h"
Eli Friedman778b0852010-06-09 06:50:29 +000023#include "lldb/API/SBError.h"
24#include "lldb/API/SBInputReader.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025
26
27class IOChannel;
28
29namespace lldb
30{
31 class SBInputReader;
32}
33
34
35class Driver : public lldb::SBBroadcaster
36{
37public:
38 enum {
39 eBroadcastBitReadyForInput = (1 << 0),
40 eBroadcastBitThreadShouldExit = (1 << 1)
41 };
42
43 Driver ();
44
45 virtual
46 ~Driver ();
47
48 void
49 MainLoop ();
50
51 void
52 PutSTDIN (const char *src, size_t src_len);
53
54 void
55 GetFromMaster (const char *src, size_t src_len);
56
57 bool
58 HandleIOEvent (const lldb::SBEvent &event);
59
60 void
61 HandleProcessEvent (const lldb::SBEvent &event);
62
Greg Clayton66111032010-06-23 01:19:29 +000063 lldb::SBError
64 ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &do_exit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
66 const char *
67 GetFilename() const;
68
69 const char *
70 GetCrashLogFilename() const;
71
72 const char *
73 GetArchName() const;
74
75 lldb::ScriptLanguage
76 GetScriptLanguage() const;
77
78 size_t
79 GetNumSourceCommandFiles () const;
80
81 const char *
82 GetSourceCommandFileAtIndex (uint32_t idx) const;
83
84 bool
85 GetDebugMode() const;
86
87
88 class OptionData
89 {
90 public:
91 OptionData ();
92 ~OptionData ();
93
94 void
95 Clear();
96
Greg Claytone0d378b2011-03-24 21:19:54 +000097 //static OptionDefinition m_cmd_option_table[];
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098
Greg Clayton8d846da2010-12-08 22:23:24 +000099 std::vector<std::string> m_args;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100 lldb::ScriptLanguage m_script_lang;
101 std::string m_crash_log;
102 std::vector<std::string> m_source_command_files;
103 bool m_debug_mode;
104 bool m_print_version;
105 bool m_print_help;
Jim Inghame40e4212010-08-30 19:44:40 +0000106 bool m_use_external_editor; // FIXME: When we have set/show variables we can remove this from here.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107 typedef std::set<char> OptionSet;
108 OptionSet m_seen_options;
109 };
110
111
112 static lldb::SBError
113 SetOptionValue (int option_idx,
114 const char *option_arg,
115 Driver::OptionData &data);
116
117
Greg Clayton66111032010-06-23 01:19:29 +0000118 lldb::SBDebugger &
119 GetDebugger()
120 {
121 return m_debugger;
122 }
123
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124private:
Greg Clayton66111032010-06-23 01:19:29 +0000125 lldb::SBDebugger m_debugger;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126 lldb_utility::PseudoTerminal m_editline_pty;
127 FILE *m_editline_slave_fh;
128 lldb::SBInputReader m_editline_reader;
129 std::auto_ptr<IOChannel> m_io_channel_ap;
130 OptionData m_option_data;
131 bool m_waiting_for_command;
132
133 void
134 ResetOptionValues ();
135
Caroline Ticebd13b8d2010-09-29 18:35:42 +0000136 size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137 GetProcessSTDOUT ();
138
Caroline Ticebd13b8d2010-09-29 18:35:42 +0000139 size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000140 GetProcessSTDERR ();
141
142 void
Jim Ingham2976d002010-08-26 21:32:51 +0000143 UpdateSelectedThread ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144
145 void
146 CloseIOChannelFile ();
147
148 static size_t
149 EditLineInputReaderCallback (void *baton,
150 lldb::SBInputReader *reader,
151 lldb::InputReaderAction notification,
152 const char *bytes,
153 size_t bytes_len);
154
155 static void
156 ReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
157
158 static void
159 MasterThreadBytesReceived (void *baton, const void *src, size_t src_len);
160
161 void
162 ReadyForCommand ();
163};
164
Eli Friedmana382d472010-06-09 09:50:17 +0000165#endif // lldb_Driver_h_