blob: 7ae54bd38bdd7d8a72c2014c92a395ef1fb2fdbe [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- 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#include "lldb/lldb-private.h"
11#include "lldb/Core/ConnectionFileDescriptor.h"
12#include "lldb/Core/Debugger.h"
13#include "lldb/Core/InputReader.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000014#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Core/State.h"
Greg Clayton1b654882010-09-19 02:33:57 +000016#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Core/Timer.h"
Greg Claytona3406612011-02-07 23:24:47 +000018#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000019#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Target/TargetList.h"
21#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000022#include "lldb/Target/RegisterContext.h"
23#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Target/Thread.h"
25
26
27using namespace lldb;
28using namespace lldb_private;
29
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
Greg Clayton1b654882010-09-19 02:33:57 +000031static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000032static lldb::user_id_t g_unique_id = 1;
33
Greg Clayton1b654882010-09-19 02:33:57 +000034#pragma mark Static Functions
35
36static Mutex &
37GetDebuggerListMutex ()
38{
39 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
40 return g_mutex;
41}
42
43typedef std::vector<DebuggerSP> DebuggerList;
44
45static DebuggerList &
46GetDebuggerList()
47{
48 // hide the static debugger list inside a singleton accessor to avoid
49 // global init contructors
50 static DebuggerList g_list;
51 return g_list;
52}
53
54
55#pragma mark Debugger
56
Greg Clayton99d0faf2010-11-18 23:32:35 +000057UserSettingsControllerSP &
58Debugger::GetSettingsController ()
59{
60 static UserSettingsControllerSP g_settings_controller;
61 return g_settings_controller;
62}
63
Caroline Tice2f88aad2011-01-14 00:29:16 +000064int
65Debugger::TestDebuggerRefCount ()
66{
67 return g_shared_debugger_refcount;
68}
69
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070void
71Debugger::Initialize ()
72{
Greg Clayton66111032010-06-23 01:19:29 +000073 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +000074 {
Greg Claytondbe54502010-11-19 03:46:01 +000075 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +000076 }
Greg Clayton66111032010-06-23 01:19:29 +000077 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +000078
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079}
80
81void
82Debugger::Terminate ()
83{
Greg Clayton66111032010-06-23 01:19:29 +000084 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085 {
Greg Clayton66111032010-06-23 01:19:29 +000086 g_shared_debugger_refcount--;
87 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088 {
Greg Claytondbe54502010-11-19 03:46:01 +000089 lldb_private::WillTerminate();
90 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +000091
92 // Clear our master list of debugger objects
93 Mutex::Locker locker (GetDebuggerListMutex ());
94 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096 }
97}
98
Caroline Tice20bd37f2011-03-10 22:14:10 +000099void
100Debugger::SettingsInitialize ()
101{
102 static bool g_initialized = false;
103
104 if (!g_initialized)
105 {
106 g_initialized = true;
107 UserSettingsControllerSP &usc = GetSettingsController();
108 usc.reset (new SettingsController);
109 UserSettingsController::InitializeSettingsController (usc,
110 SettingsController::global_settings_table,
111 SettingsController::instance_settings_table);
112 // Now call SettingsInitialize for each settings 'child' of Debugger
113 Target::SettingsInitialize ();
114 }
115}
116
117void
118Debugger::SettingsTerminate ()
119{
120
121 // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
122 // Settings.
123
124 Target::SettingsTerminate ();
125
126 // Now terminate the Debugger Settings.
127
128 UserSettingsControllerSP &usc = GetSettingsController();
129 UserSettingsController::FinalizeSettingsController (usc);
130 usc.reset();
131}
132
Greg Clayton66111032010-06-23 01:19:29 +0000133DebuggerSP
134Debugger::CreateInstance ()
135{
136 DebuggerSP debugger_sp (new Debugger);
137 // Scope for locker
138 {
139 Mutex::Locker locker (GetDebuggerListMutex ());
140 GetDebuggerList().push_back(debugger_sp);
141 }
142 return debugger_sp;
143}
144
Caroline Ticee02657b2011-01-22 01:02:07 +0000145void
146Debugger::Destroy (lldb::DebuggerSP &debugger_sp)
147{
148 if (debugger_sp.get() == NULL)
149 return;
150
151 Mutex::Locker locker (GetDebuggerListMutex ());
152 DebuggerList &debugger_list = GetDebuggerList ();
153 DebuggerList::iterator pos, end = debugger_list.end();
154 for (pos = debugger_list.begin (); pos != end; ++pos)
155 {
156 if ((*pos).get() == debugger_sp.get())
157 {
158 debugger_list.erase (pos);
159 return;
160 }
161 }
162
163}
164
Greg Clayton66111032010-06-23 01:19:29 +0000165lldb::DebuggerSP
166Debugger::GetSP ()
167{
168 lldb::DebuggerSP debugger_sp;
169
170 Mutex::Locker locker (GetDebuggerListMutex ());
171 DebuggerList &debugger_list = GetDebuggerList();
172 DebuggerList::iterator pos, end = debugger_list.end();
173 for (pos = debugger_list.begin(); pos != end; ++pos)
174 {
175 if ((*pos).get() == this)
176 {
177 debugger_sp = *pos;
178 break;
179 }
180 }
181 return debugger_sp;
182}
183
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000184lldb::DebuggerSP
185Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
186{
187 lldb::DebuggerSP debugger_sp;
188
189 Mutex::Locker locker (GetDebuggerListMutex ());
190 DebuggerList &debugger_list = GetDebuggerList();
191 DebuggerList::iterator pos, end = debugger_list.end();
192
193 for (pos = debugger_list.begin(); pos != end; ++pos)
194 {
195 if ((*pos).get()->m_instance_name == instance_name)
196 {
197 debugger_sp = *pos;
198 break;
199 }
200 }
201 return debugger_sp;
202}
Greg Clayton66111032010-06-23 01:19:29 +0000203
204TargetSP
205Debugger::FindTargetWithProcessID (lldb::pid_t pid)
206{
207 lldb::TargetSP target_sp;
208 Mutex::Locker locker (GetDebuggerListMutex ());
209 DebuggerList &debugger_list = GetDebuggerList();
210 DebuggerList::iterator pos, end = debugger_list.end();
211 for (pos = debugger_list.begin(); pos != end; ++pos)
212 {
213 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
214 if (target_sp)
215 break;
216 }
217 return target_sp;
218}
219
220
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000222 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000223 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000224 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225 m_input_file (),
226 m_output_file (),
227 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228 m_target_list (),
Greg Claytonded470d2011-03-19 01:12:21 +0000229 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230 m_listener ("lldb.Debugger"),
231 m_source_manager (),
Greg Clayton66111032010-06-23 01:19:29 +0000232 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000233 m_input_readers (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000234 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235{
Greg Claytond46c87a2010-12-04 02:39:47 +0000236 m_input_comm.SetCloseOnEOF(false);
Greg Clayton66111032010-06-23 01:19:29 +0000237 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000238 // Always add our default platform to the platform list
239 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
240 assert (default_platform_sp.get());
241 m_platform_list.Append (default_platform_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242}
243
244Debugger::~Debugger ()
245{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000246 CleanUpInputReaders();
Greg Clayton66111032010-06-23 01:19:29 +0000247 int num_targets = m_target_list.GetNumTargets();
248 for (int i = 0; i < num_targets; i++)
249 {
250 ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
251 if (process_sp)
252 process_sp->Destroy();
253 }
254 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000255}
256
257
258bool
259Debugger::GetAsyncExecution ()
260{
Greg Clayton66111032010-06-23 01:19:29 +0000261 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262}
263
264void
265Debugger::SetAsyncExecution (bool async_execution)
266{
Greg Clayton66111032010-06-23 01:19:29 +0000267 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268}
269
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270
271void
272Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
273{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000274 File &in_file = GetInputFile();
275 in_file.SetStream (fh, tranfer_ownership);
276 if (in_file.IsValid() == false)
277 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278
279 // Disconnect from any old connection if we had one
280 m_input_comm.Disconnect ();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000281 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), true));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
283
284 Error error;
285 if (m_input_comm.StartReadThread (&error) == false)
286 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000287 File &err_file = GetErrorFile();
288
289 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
290 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000291 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292}
293
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000294void
295Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
296{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000297 File &out_file = GetOutputFile();
298 out_file.SetStream (fh, tranfer_ownership);
299 if (out_file.IsValid() == false)
300 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000301
302 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000303}
304
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000305void
306Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
307{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000308 File &err_file = GetErrorFile();
309 err_file.SetStream (fh, tranfer_ownership);
310 if (err_file.IsValid() == false)
311 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312}
313
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000315Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316{
317 ExecutionContext exe_ctx;
318 exe_ctx.Clear();
319
Jim Ingham2976d002010-08-26 21:32:51 +0000320 lldb::TargetSP target_sp = GetSelectedTarget();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321 exe_ctx.target = target_sp.get();
322
323 if (target_sp)
324 {
325 exe_ctx.process = target_sp->GetProcessSP().get();
326 if (exe_ctx.process && exe_ctx.process->IsRunning() == false)
327 {
Jim Ingham2976d002010-08-26 21:32:51 +0000328 exe_ctx.thread = exe_ctx.process->GetThreadList().GetSelectedThread().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329 if (exe_ctx.thread == NULL)
330 exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
331 if (exe_ctx.thread)
332 {
Jim Ingham2976d002010-08-26 21:32:51 +0000333 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000334 if (exe_ctx.frame == NULL)
335 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex (0).get();
336 }
337 }
338 }
339 return exe_ctx;
340
341}
342
Caroline Ticeb44880c2011-02-10 01:15:13 +0000343InputReaderSP
344Debugger::GetCurrentInputReader ()
345{
346 InputReaderSP reader_sp;
347
348 if (!m_input_readers.empty())
349 {
350 // Clear any finished readers from the stack
351 while (CheckIfTopInputReaderIsDone()) ;
352
353 if (!m_input_readers.empty())
354 reader_sp = m_input_readers.top();
355 }
356
357 return reader_sp;
358}
359
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360void
361Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
362{
Caroline Ticeefed6132010-11-19 20:47:54 +0000363 if (bytes_len > 0)
364 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
365 else
366 ((Debugger *)baton)->DispatchInputEndOfFile ();
367}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368
369
370void
371Debugger::DispatchInput (const char *bytes, size_t bytes_len)
372{
Caroline Ticeefed6132010-11-19 20:47:54 +0000373 if (bytes == NULL || bytes_len == 0)
374 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375
376 WriteToDefaultReader (bytes, bytes_len);
377}
378
379void
Caroline Ticeefed6132010-11-19 20:47:54 +0000380Debugger::DispatchInputInterrupt ()
381{
382 m_input_reader_data.clear();
383
Caroline Ticeb44880c2011-02-10 01:15:13 +0000384 InputReaderSP reader_sp (GetCurrentInputReader ());
385 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000386 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000387 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000388
Caroline Ticeb44880c2011-02-10 01:15:13 +0000389 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000390 while (CheckIfTopInputReaderIsDone ()) ;
391 }
392}
393
394void
395Debugger::DispatchInputEndOfFile ()
396{
397 m_input_reader_data.clear();
398
Caroline Ticeb44880c2011-02-10 01:15:13 +0000399 InputReaderSP reader_sp (GetCurrentInputReader ());
400 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000401 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000402 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000403
Caroline Ticeb44880c2011-02-10 01:15:13 +0000404 // If notifying the reader of the end-of-file finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000405 while (CheckIfTopInputReaderIsDone ()) ;
406 }
407}
408
409void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000410Debugger::CleanUpInputReaders ()
411{
412 m_input_reader_data.clear();
413
Caroline Ticeb44880c2011-02-10 01:15:13 +0000414 // The bottom input reader should be the main debugger input reader. We do not want to close that one here.
Caroline Tice3d6086f2010-12-20 18:35:50 +0000415 while (m_input_readers.size() > 1)
416 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000417 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000418 if (reader_sp)
419 {
420 reader_sp->Notify (eInputReaderEndOfFile);
421 reader_sp->SetIsDone (true);
422 }
423 }
424}
425
426void
Caroline Tice969ed3d2011-05-02 20:41:46 +0000427Debugger::NotifyTopInputReader (InputReaderAction notification)
428{
429 InputReaderSP reader_sp (GetCurrentInputReader());
430 if (reader_sp)
431 {
432 reader_sp->Notify (notification);
433
434 // Flush out any input readers that are done.
435 while (CheckIfTopInputReaderIsDone ())
436 /* Do nothing. */;
437 }
438}
439
440void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
442{
443 if (bytes && bytes_len)
444 m_input_reader_data.append (bytes, bytes_len);
445
446 if (m_input_reader_data.empty())
447 return;
448
449 while (!m_input_readers.empty() && !m_input_reader_data.empty())
450 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000452 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 if (!reader_sp)
454 break;
455
Greg Clayton471b31c2010-07-20 22:52:08 +0000456 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 m_input_reader_data.size());
458 if (bytes_handled)
459 {
460 m_input_reader_data.erase (0, bytes_handled);
461 }
462 else
463 {
464 // No bytes were handled, we might not have reached our
465 // granularity, just return and wait for more data
466 break;
467 }
468 }
469
Caroline Ticeb44880c2011-02-10 01:15:13 +0000470 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471 while (CheckIfTopInputReaderIsDone ())
472 /* Do nothing. */;
473
474}
475
476void
477Debugger::PushInputReader (const InputReaderSP& reader_sp)
478{
479 if (!reader_sp)
480 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000481
482 // Deactivate the old top reader
483 InputReaderSP top_reader_sp (GetCurrentInputReader ());
484
485 if (top_reader_sp)
486 top_reader_sp->Notify (eInputReaderDeactivate);
487
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488 m_input_readers.push (reader_sp);
489 reader_sp->Notify (eInputReaderActivate);
490 ActivateInputReader (reader_sp);
491}
492
493bool
494Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp)
495{
496 bool result = false;
497
498 // The reader on the stop of the stack is done, so let the next
499 // read on the stack referesh its prompt and if there is one...
500 if (!m_input_readers.empty())
501 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000502 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503 InputReaderSP reader_sp(m_input_readers.top());
504
505 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
506 {
507 m_input_readers.pop ();
508 reader_sp->Notify (eInputReaderDeactivate);
509 reader_sp->Notify (eInputReaderDone);
510 result = true;
511
512 if (!m_input_readers.empty())
513 {
514 reader_sp = m_input_readers.top();
515 if (reader_sp)
516 {
517 ActivateInputReader (reader_sp);
518 reader_sp->Notify (eInputReaderReactivate);
519 }
520 }
521 }
522 }
523 return result;
524}
525
526bool
527Debugger::CheckIfTopInputReaderIsDone ()
528{
529 bool result = false;
530 if (!m_input_readers.empty())
531 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000532 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 InputReaderSP reader_sp(m_input_readers.top());
534
535 if (reader_sp && reader_sp->IsDone())
536 {
537 result = true;
538 PopInputReader (reader_sp);
539 }
540 }
541 return result;
542}
543
544void
545Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
546{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000547 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000549 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000551 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000552
553 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554
Greg Claytona3406612011-02-07 23:24:47 +0000555 switch (reader_sp->GetGranularity())
556 {
557 case eInputReaderGranularityByte:
558 case eInputReaderGranularityWord:
559 tty.SetCanonical (false);
560 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561
Greg Claytona3406612011-02-07 23:24:47 +0000562 case eInputReaderGranularityLine:
563 case eInputReaderGranularityAll:
564 tty.SetCanonical (true);
565 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566
Greg Claytona3406612011-02-07 23:24:47 +0000567 default:
568 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 }
570 }
571}
Greg Clayton66111032010-06-23 01:19:29 +0000572
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000573DebuggerSP
574Debugger::FindDebuggerWithID (lldb::user_id_t id)
575{
576 lldb::DebuggerSP debugger_sp;
577
578 Mutex::Locker locker (GetDebuggerListMutex ());
579 DebuggerList &debugger_list = GetDebuggerList();
580 DebuggerList::iterator pos, end = debugger_list.end();
581 for (pos = debugger_list.begin(); pos != end; ++pos)
582 {
583 if ((*pos).get()->GetID() == id)
584 {
585 debugger_sp = *pos;
586 break;
587 }
588 }
589 return debugger_sp;
590}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000591
Greg Clayton1b654882010-09-19 02:33:57 +0000592static void
593TestPromptFormats (StackFrame *frame)
594{
595 if (frame == NULL)
596 return;
597
598 StreamString s;
599 const char *prompt_format =
600 "{addr = '${addr}'\n}"
601 "{process.id = '${process.id}'\n}"
602 "{process.name = '${process.name}'\n}"
603 "{process.file.basename = '${process.file.basename}'\n}"
604 "{process.file.fullpath = '${process.file.fullpath}'\n}"
605 "{thread.id = '${thread.id}'\n}"
606 "{thread.index = '${thread.index}'\n}"
607 "{thread.name = '${thread.name}'\n}"
608 "{thread.queue = '${thread.queue}'\n}"
609 "{thread.stop-reason = '${thread.stop-reason}'\n}"
610 "{target.arch = '${target.arch}'\n}"
611 "{module.file.basename = '${module.file.basename}'\n}"
612 "{module.file.fullpath = '${module.file.fullpath}'\n}"
613 "{file.basename = '${file.basename}'\n}"
614 "{file.fullpath = '${file.fullpath}'\n}"
615 "{frame.index = '${frame.index}'\n}"
616 "{frame.pc = '${frame.pc}'\n}"
617 "{frame.sp = '${frame.sp}'\n}"
618 "{frame.fp = '${frame.fp}'\n}"
619 "{frame.flags = '${frame.flags}'\n}"
620 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
621 "{frame.reg.rip = '${frame.reg.rip}'\n}"
622 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
623 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
624 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
625 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
626 "{frame.reg.carp = '${frame.reg.carp}'\n}"
627 "{function.id = '${function.id}'\n}"
628 "{function.name = '${function.name}'\n}"
629 "{function.addr-offset = '${function.addr-offset}'\n}"
630 "{function.line-offset = '${function.line-offset}'\n}"
631 "{function.pc-offset = '${function.pc-offset}'\n}"
632 "{line.file.basename = '${line.file.basename}'\n}"
633 "{line.file.fullpath = '${line.file.fullpath}'\n}"
634 "{line.number = '${line.number}'\n}"
635 "{line.start-addr = '${line.start-addr}'\n}"
636 "{line.end-addr = '${line.end-addr}'\n}"
637;
638
639 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
640 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000641 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000642 const char *end = NULL;
643 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
644 {
645 printf("%s\n", s.GetData());
646 }
647 else
648 {
649 printf ("error: at '%s'\n", end);
650 printf ("what we got: %s\n", s.GetData());
651 }
652}
653
654bool
655Debugger::FormatPrompt
656(
657 const char *format,
658 const SymbolContext *sc,
659 const ExecutionContext *exe_ctx,
660 const Address *addr,
661 Stream &s,
662 const char **end
663)
664{
665 bool success = true;
666 const char *p;
667 for (p = format; *p != '\0'; ++p)
668 {
669 size_t non_special_chars = ::strcspn (p, "${}\\");
670 if (non_special_chars > 0)
671 {
672 if (success)
673 s.Write (p, non_special_chars);
674 p += non_special_chars;
675 }
676
677 if (*p == '\0')
678 {
679 break;
680 }
681 else if (*p == '{')
682 {
683 // Start a new scope that must have everything it needs if it is to
684 // to make it into the final output stream "s". If you want to make
685 // a format that only prints out the function or symbol name if there
686 // is one in the symbol context you can use:
687 // "{function =${function.name}}"
688 // The first '{' starts a new scope that end with the matching '}' at
689 // the end of the string. The contents "function =${function.name}"
690 // will then be evaluated and only be output if there is a function
691 // or symbol with a valid name.
692 StreamString sub_strm;
693
694 ++p; // Skip the '{'
695
696 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p))
697 {
698 // The stream had all it needed
699 s.Write(sub_strm.GetData(), sub_strm.GetSize());
700 }
701 if (*p != '}')
702 {
703 success = false;
704 break;
705 }
706 }
707 else if (*p == '}')
708 {
709 // End of a enclosing scope
710 break;
711 }
712 else if (*p == '$')
713 {
714 // We have a prompt variable to print
715 ++p;
716 if (*p == '{')
717 {
718 ++p;
719 const char *var_name_begin = p;
720 const char *var_name_end = ::strchr (p, '}');
721
722 if (var_name_end && var_name_begin < var_name_end)
723 {
724 // if we have already failed to parse, skip this variable
725 if (success)
726 {
727 const char *cstr = NULL;
728 Address format_addr;
729 bool calculate_format_addr_function_offset = false;
730 // Set reg_kind and reg_num to invalid values
731 RegisterKind reg_kind = kNumRegisterKinds;
732 uint32_t reg_num = LLDB_INVALID_REGNUM;
733 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +0000734 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +0000735 RegisterContext *reg_ctx = NULL;
736
737 // Each variable must set success to true below...
738 bool var_success = false;
739 switch (var_name_begin[0])
740 {
741 case 'a':
742 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
743 {
744 if (addr && addr->IsValid())
745 {
746 var_success = true;
747 format_addr = *addr;
748 }
749 }
750 break;
751
752 case 'p':
753 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
754 {
755 if (exe_ctx && exe_ctx->process != NULL)
756 {
757 var_name_begin += ::strlen ("process.");
758 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
759 {
760 s.Printf("%i", exe_ctx->process->GetID());
761 var_success = true;
762 }
763 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
764 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
765 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
766 {
767 ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
768 if (exe_module_sp)
769 {
770 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
771 {
772 format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
773 var_success = format_file_spec;
774 }
775 else
776 {
777 format_file_spec = exe_module_sp->GetFileSpec();
778 var_success = format_file_spec;
779 }
780 }
781 }
782 }
783 }
784 break;
785
786 case 't':
787 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
788 {
789 if (exe_ctx && exe_ctx->thread)
790 {
791 var_name_begin += ::strlen ("thread.");
792 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
793 {
794 s.Printf("0x%4.4x", exe_ctx->thread->GetID());
795 var_success = true;
796 }
797 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
798 {
799 s.Printf("%u", exe_ctx->thread->GetIndexID());
800 var_success = true;
801 }
802 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
803 {
804 cstr = exe_ctx->thread->GetName();
805 var_success = cstr && cstr[0];
806 if (var_success)
807 s.PutCString(cstr);
808 }
809 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
810 {
811 cstr = exe_ctx->thread->GetQueueName();
812 var_success = cstr && cstr[0];
813 if (var_success)
814 s.PutCString(cstr);
815 }
816 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
817 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000818 StopInfoSP stop_info_sp = exe_ctx->thread->GetStopInfo ();
819 if (stop_info_sp)
Greg Clayton1b654882010-09-19 02:33:57 +0000820 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000821 cstr = stop_info_sp->GetDescription();
Greg Clayton1b654882010-09-19 02:33:57 +0000822 if (cstr && cstr[0])
823 {
824 s.PutCString(cstr);
825 var_success = true;
826 }
827 }
828 }
829 }
830 }
831 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
832 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000833 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
834 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +0000835 {
Greg Clayton1b654882010-09-19 02:33:57 +0000836 var_name_begin += ::strlen ("target.");
837 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
838 {
839 ArchSpec arch (target->GetArchitecture ());
840 if (arch.IsValid())
841 {
Greg Clayton64195a22011-02-23 00:35:02 +0000842 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +0000843 var_success = true;
844 }
845 }
846 }
847 }
848 break;
849
850
851 case 'm':
852 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
853 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000854 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +0000855 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000856 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +0000857 var_name_begin += ::strlen ("module.");
858
859 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
860 {
861 if (module->GetFileSpec())
862 {
863 var_name_begin += ::strlen ("file.");
864
865 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
866 {
867 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
868 var_success = format_file_spec;
869 }
870 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
871 {
872 format_file_spec = module->GetFileSpec();
873 var_success = format_file_spec;
874 }
875 }
876 }
877 }
878 }
879 break;
880
881
882 case 'f':
883 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
884 {
885 if (sc && sc->comp_unit != NULL)
886 {
887 var_name_begin += ::strlen ("file.");
888
889 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
890 {
891 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
892 var_success = format_file_spec;
893 }
894 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
895 {
896 format_file_spec = *sc->comp_unit;
897 var_success = format_file_spec;
898 }
899 }
900 }
901 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
902 {
903 if (exe_ctx && exe_ctx->frame)
904 {
905 var_name_begin += ::strlen ("frame.");
906 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
907 {
908 s.Printf("%u", exe_ctx->frame->GetFrameIndex());
909 var_success = true;
910 }
911 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
912 {
913 reg_kind = eRegisterKindGeneric;
914 reg_num = LLDB_REGNUM_GENERIC_PC;
915 var_success = true;
916 }
917 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
918 {
919 reg_kind = eRegisterKindGeneric;
920 reg_num = LLDB_REGNUM_GENERIC_SP;
921 var_success = true;
922 }
923 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
924 {
925 reg_kind = eRegisterKindGeneric;
926 reg_num = LLDB_REGNUM_GENERIC_FP;
927 var_success = true;
928 }
929 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
930 {
931 reg_kind = eRegisterKindGeneric;
932 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
933 var_success = true;
934 }
935 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
936 {
Greg Clayton5ccbd292011-01-06 22:15:06 +0000937 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +0000938 if (reg_ctx)
939 {
940 var_name_begin += ::strlen ("reg.");
941 if (var_name_begin < var_name_end)
942 {
943 std::string reg_name (var_name_begin, var_name_end);
944 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
945 if (reg_info)
946 var_success = true;
947 }
948 }
949 }
950 }
951 }
952 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
953 {
954 if (sc && (sc->function != NULL || sc->symbol != NULL))
955 {
956 var_name_begin += ::strlen ("function.");
957 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
958 {
959 if (sc->function)
960 s.Printf("function{0x%8.8x}", sc->function->GetID());
961 else
962 s.Printf("symbol[%u]", sc->symbol->GetID());
963
964 var_success = true;
965 }
966 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
967 {
968 if (sc->function)
969 cstr = sc->function->GetName().AsCString (NULL);
970 else if (sc->symbol)
971 cstr = sc->symbol->GetName().AsCString (NULL);
972 if (cstr)
973 {
974 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +0000975
976 if (sc->block)
977 {
978 Block *inline_block = sc->block->GetContainingInlinedBlock ();
979 if (inline_block)
980 {
981 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
982 if (inline_info)
983 {
984 s.PutCString(" [inlined] ");
985 inline_info->GetName().Dump(&s);
986 }
987 }
988 }
Greg Clayton1b654882010-09-19 02:33:57 +0000989 var_success = true;
990 }
991 }
992 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
993 {
994 var_success = addr != NULL;
995 if (var_success)
996 {
997 format_addr = *addr;
998 calculate_format_addr_function_offset = true;
999 }
1000 }
1001 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1002 {
1003 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1004 if (var_success)
1005 {
1006 format_addr = sc->line_entry.range.GetBaseAddress();
1007 calculate_format_addr_function_offset = true;
1008 }
1009 }
1010 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1011 {
1012 var_success = exe_ctx->frame;
1013 if (var_success)
1014 {
1015 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1016 calculate_format_addr_function_offset = true;
1017 }
1018 }
1019 }
1020 }
1021 break;
1022
1023 case 'l':
1024 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1025 {
1026 if (sc && sc->line_entry.IsValid())
1027 {
1028 var_name_begin += ::strlen ("line.");
1029 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1030 {
1031 var_name_begin += ::strlen ("file.");
1032
1033 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1034 {
1035 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1036 var_success = format_file_spec;
1037 }
1038 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1039 {
1040 format_file_spec = sc->line_entry.file;
1041 var_success = format_file_spec;
1042 }
1043 }
1044 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1045 {
1046 var_success = true;
1047 s.Printf("%u", sc->line_entry.line);
1048 }
1049 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1050 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1051 {
1052 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1053 if (var_success)
1054 {
1055 format_addr = sc->line_entry.range.GetBaseAddress();
1056 if (var_name_begin[0] == 'e')
1057 format_addr.Slide (sc->line_entry.range.GetByteSize());
1058 }
1059 }
1060 }
1061 }
1062 break;
1063 }
1064
1065 if (var_success)
1066 {
1067 // If format addr is valid, then we need to print an address
1068 if (reg_num != LLDB_INVALID_REGNUM)
1069 {
1070 // We have a register value to display...
1071 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1072 {
1073 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1074 }
1075 else
1076 {
1077 if (reg_ctx == NULL)
Greg Clayton5ccbd292011-01-06 22:15:06 +00001078 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001079
1080 if (reg_ctx)
1081 {
1082 if (reg_kind != kNumRegisterKinds)
1083 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1084 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1085 var_success = reg_info != NULL;
1086 }
1087 }
1088 }
1089
1090 if (reg_info != NULL)
1091 {
Greg Clayton7349bd92011-05-09 20:18:18 +00001092 RegisterValue reg_value;
1093 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
1094 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001095 {
Greg Clayton7349bd92011-05-09 20:18:18 +00001096 reg_value.Dump(&s, reg_info, false);
Greg Clayton1b654882010-09-19 02:33:57 +00001097 }
1098 }
1099
1100 if (format_file_spec)
1101 {
1102 s << format_file_spec;
1103 }
1104
1105 // If format addr is valid, then we need to print an address
1106 if (format_addr.IsValid())
1107 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001108 var_success = false;
1109
Greg Clayton1b654882010-09-19 02:33:57 +00001110 if (calculate_format_addr_function_offset)
1111 {
1112 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001113
Greg Clayton0603aa92010-10-04 01:05:56 +00001114 if (sc)
1115 {
1116 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001117 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001118 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001119 if (sc->block)
1120 {
1121 // Check to make sure we aren't in an inline
1122 // function. If we are, use the inline block
1123 // range that contains "format_addr" since
1124 // blocks can be discontiguous.
1125 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1126 AddressRange inline_range;
1127 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1128 func_addr = inline_range.GetBaseAddress();
1129 }
1130 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001131 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1132 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1133 }
1134
1135 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001136 {
1137 if (func_addr.GetSection() == format_addr.GetSection())
1138 {
1139 addr_t func_file_addr = func_addr.GetFileAddress();
1140 addr_t addr_file_addr = format_addr.GetFileAddress();
1141 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001142 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001143 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001144 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001145 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001146 }
1147 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001148 {
1149 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1150 if (target)
1151 {
1152 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1153 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1154 if (addr_load_addr > func_load_addr)
1155 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1156 else if (addr_load_addr < func_load_addr)
1157 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1158 var_success = true;
1159 }
1160 }
Greg Clayton1b654882010-09-19 02:33:57 +00001161 }
1162 }
1163 else
1164 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001165 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001166 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001167 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1168 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001169 if (vaddr == LLDB_INVALID_ADDRESS)
1170 vaddr = format_addr.GetFileAddress ();
1171
1172 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001173 {
Greg Clayton514487e2011-02-15 21:59:32 +00001174 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001175 if (addr_width == 0)
1176 addr_width = 16;
1177 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001178 var_success = true;
1179 }
Greg Clayton1b654882010-09-19 02:33:57 +00001180 }
1181 }
1182 }
1183
1184 if (var_success == false)
1185 success = false;
1186 }
1187 p = var_name_end;
1188 }
1189 else
1190 break;
1191 }
1192 else
1193 {
1194 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1195 s.PutChar(*p);
1196 }
1197 }
1198 else if (*p == '\\')
1199 {
1200 ++p; // skip the slash
1201 switch (*p)
1202 {
1203 case 'a': s.PutChar ('\a'); break;
1204 case 'b': s.PutChar ('\b'); break;
1205 case 'f': s.PutChar ('\f'); break;
1206 case 'n': s.PutChar ('\n'); break;
1207 case 'r': s.PutChar ('\r'); break;
1208 case 't': s.PutChar ('\t'); break;
1209 case 'v': s.PutChar ('\v'); break;
1210 case '\'': s.PutChar ('\''); break;
1211 case '\\': s.PutChar ('\\'); break;
1212 case '0':
1213 // 1 to 3 octal chars
1214 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001215 // Make a string that can hold onto the initial zero char,
1216 // up to 3 octal digits, and a terminating NULL.
1217 char oct_str[5] = { 0, 0, 0, 0, 0 };
1218
1219 int i;
1220 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1221 oct_str[i] = p[i];
1222
1223 // We don't want to consume the last octal character since
1224 // the main for loop will do this for us, so we advance p by
1225 // one less than i (even if i is zero)
1226 p += i - 1;
1227 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
1228 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001229 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001230 char octal_char = octal_value;
1231 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00001232 }
Greg Clayton1b654882010-09-19 02:33:57 +00001233 }
1234 break;
1235
1236 case 'x':
1237 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00001238 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001239 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001240 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00001241
Greg Clayton0603aa92010-10-04 01:05:56 +00001242 // Make a string that can hold onto two hex chars plus a
1243 // NULL terminator
1244 char hex_str[3] = { 0,0,0 };
1245 hex_str[0] = *p;
1246 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001247 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001248 ++p; // Skip the first of the two hex chars
1249 hex_str[1] = *p;
1250 }
1251
1252 unsigned long hex_value = strtoul (hex_str, NULL, 16);
1253 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001254 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00001255 }
1256 else
1257 {
1258 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00001259 }
1260 break;
1261
1262 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00001263 // Just desensitize any other character by just printing what
1264 // came after the '\'
1265 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00001266 break;
1267
1268 }
1269
1270 }
1271 }
1272 if (end)
1273 *end = p;
1274 return success;
1275}
1276
1277#pragma mark Debugger::SettingsController
1278
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001279//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001280// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001281//--------------------------------------------------
1282
Greg Clayton1b654882010-09-19 02:33:57 +00001283Debugger::SettingsController::SettingsController () :
Caroline Tice101c7c22010-09-09 06:25:08 +00001284 UserSettingsController ("", lldb::UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001285{
Caroline Tice91123da2010-09-08 17:48:55 +00001286 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
1287 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001288}
1289
Greg Clayton1b654882010-09-19 02:33:57 +00001290Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001291{
1292}
1293
1294
1295lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00001296Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001297{
Greg Claytondbe54502010-11-19 03:46:01 +00001298 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00001299 false, instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001300 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1301 return new_settings_sp;
1302}
1303
Greg Clayton1b654882010-09-19 02:33:57 +00001304#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001305//--------------------------------------------------
1306// class DebuggerInstanceSettings
1307//--------------------------------------------------
1308
Greg Claytona7015092010-09-18 01:14:36 +00001309DebuggerInstanceSettings::DebuggerInstanceSettings
1310(
1311 UserSettingsController &owner,
1312 bool live_instance,
1313 const char *name
1314) :
Greg Clayton85851dd2010-12-04 00:10:17 +00001315 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00001316 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001317 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00001318 m_frame_format (),
1319 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001320 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001321 m_use_external_editor (false),
1322 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001323{
Caroline Ticef20e8232010-09-09 18:26:37 +00001324 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1325 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
1326 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
Caroline Tice9e41c152010-09-16 19:05:55 +00001327 // The same is true of CreateInstanceName().
1328
1329 if (GetInstanceName() == InstanceSettings::InvalidName())
1330 {
1331 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1332 m_owner.RegisterInstanceSettings (this);
1333 }
Caroline Ticef20e8232010-09-09 18:26:37 +00001334
1335 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001336 {
1337 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1338 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001339 }
1340}
1341
1342DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00001343 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001344 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00001345 m_frame_format (rhs.m_frame_format),
1346 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001347 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001348 m_use_external_editor (rhs.m_use_external_editor),
1349 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001350{
1351 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1352 CopyInstanceSettings (pending_settings, false);
1353 m_owner.RemovePendingSettings (m_instance_name);
1354}
1355
1356DebuggerInstanceSettings::~DebuggerInstanceSettings ()
1357{
1358}
1359
1360DebuggerInstanceSettings&
1361DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
1362{
1363 if (this != &rhs)
1364 {
Greg Clayton1b654882010-09-19 02:33:57 +00001365 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001366 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00001367 m_frame_format = rhs.m_frame_format;
1368 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001369 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001370 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001371 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001372 }
1373
1374 return *this;
1375}
1376
Greg Clayton1b654882010-09-19 02:33:57 +00001377bool
1378DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
1379{
1380 bool valid = false;
1381
1382 // Verify we have a value string.
1383 if (value == NULL || value[0] == '\0')
1384 {
1385 err.SetErrorString ("Missing value. Can't set terminal width without a value.\n");
1386 }
1387 else
1388 {
1389 char *end = NULL;
1390 const uint32_t width = ::strtoul (value, &end, 0);
1391
Johnny Chenea9fc182010-09-20 16:36:43 +00001392 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00001393 {
Johnny Chen433d7742010-09-20 17:04:41 +00001394 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00001395 valid = true;
1396 else
1397 err.SetErrorString ("Invalid term-width value; value must be between 10 and 1024.\n");
1398 }
1399 else
1400 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string.\n", value);
1401 }
1402
1403 return valid;
1404}
1405
1406
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001407void
1408DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1409 const char *index_value,
1410 const char *value,
1411 const ConstString &instance_name,
1412 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00001413 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001414 Error &err,
1415 bool pending)
1416{
Greg Clayton0603aa92010-10-04 01:05:56 +00001417
1418 if (var_name == TermWidthVarName())
1419 {
1420 if (ValidTermWidthValue (value, err))
1421 {
1422 m_term_width = ::strtoul (value, NULL, 0);
1423 }
1424 }
1425 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001426 {
Caroline Tice101c7c22010-09-09 06:25:08 +00001427 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001428 if (!pending)
1429 {
Caroline Tice49e27372010-09-07 18:35:40 +00001430 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1431 // strip off the brackets before passing it to BroadcastPromptChange.
1432
1433 std::string tmp_instance_name (instance_name.AsCString());
1434 if ((tmp_instance_name[0] == '[')
1435 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
1436 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
1437 ConstString new_name (tmp_instance_name.c_str());
1438
1439 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001440 }
1441 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001442 else if (var_name == GetFrameFormatName())
1443 {
1444 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
1445 }
1446 else if (var_name == GetThreadFormatName())
1447 {
1448 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
1449 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001450 else if (var_name == ScriptLangVarName())
1451 {
1452 bool success;
1453 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
1454 &success);
1455 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001456 else if (var_name == UseExternalEditorVarName ())
1457 {
Greg Clayton385aa282011-04-22 03:55:06 +00001458 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00001459 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001460 else if (var_name == AutoConfirmName ())
1461 {
Greg Clayton385aa282011-04-22 03:55:06 +00001462 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00001463 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001464}
1465
Caroline Tice12cecd72010-09-20 21:37:42 +00001466bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001467DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1468 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00001469 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00001470 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001471{
1472 if (var_name == PromptVarName())
1473 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001474 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001475
1476 }
1477 else if (var_name == ScriptLangVarName())
1478 {
1479 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
1480 }
Caroline Tice101c7c22010-09-09 06:25:08 +00001481 else if (var_name == TermWidthVarName())
1482 {
1483 StreamString width_str;
1484 width_str.Printf ("%d", m_term_width);
1485 value.AppendString (width_str.GetData());
1486 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001487 else if (var_name == GetFrameFormatName ())
1488 {
1489 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
1490 }
1491 else if (var_name == GetThreadFormatName ())
1492 {
1493 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
1494 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001495 else if (var_name == UseExternalEditorVarName())
1496 {
1497 if (m_use_external_editor)
1498 value.AppendString ("true");
1499 else
1500 value.AppendString ("false");
1501 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001502 else if (var_name == AutoConfirmName())
1503 {
1504 if (m_auto_confirm_on)
1505 value.AppendString ("true");
1506 else
1507 value.AppendString ("false");
1508 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001509 else
Caroline Tice12cecd72010-09-20 21:37:42 +00001510 {
1511 if (err)
1512 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1513 return false;
1514 }
1515 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001516}
1517
1518void
1519DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1520 bool pending)
1521{
1522 if (new_settings.get() == NULL)
1523 return;
1524
1525 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
1526
1527 m_prompt = new_debugger_settings->m_prompt;
1528 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00001529 {
1530 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1531 // strip off the brackets before passing it to BroadcastPromptChange.
1532
1533 std::string tmp_instance_name (m_instance_name.AsCString());
1534 if ((tmp_instance_name[0] == '[')
1535 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
1536 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
1537 ConstString new_name (tmp_instance_name.c_str());
1538
1539 BroadcastPromptChange (new_name, m_prompt.c_str());
1540 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001541 m_frame_format = new_debugger_settings->m_frame_format;
1542 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001543 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001544 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001545 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001546 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001547}
1548
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001549
1550bool
1551DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
1552{
1553 std::string tmp_prompt;
1554
1555 if (new_prompt != NULL)
1556 {
1557 tmp_prompt = new_prompt ;
1558 int len = tmp_prompt.size();
1559 if (len > 1
1560 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
1561 && (tmp_prompt[len-1] == tmp_prompt[0]))
1562 {
1563 tmp_prompt = tmp_prompt.substr(1,len-2);
1564 }
1565 len = tmp_prompt.size();
1566 if (tmp_prompt[len-1] != ' ')
1567 tmp_prompt.append(" ");
1568 }
1569 EventSP new_event_sp;
1570 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
1571 new EventDataBytes (tmp_prompt.c_str())));
1572
1573 if (instance_name.GetLength() != 0)
1574 {
1575 // Set prompt for a particular instance.
1576 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
1577 if (dbg != NULL)
1578 {
1579 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
1580 }
1581 }
1582
1583 return true;
1584}
1585
1586const ConstString
1587DebuggerInstanceSettings::CreateInstanceName ()
1588{
1589 static int instance_count = 1;
1590 StreamString sstr;
1591
1592 sstr.Printf ("debugger_%d", instance_count);
1593 ++instance_count;
1594
1595 const ConstString ret_val (sstr.GetData());
1596
1597 return ret_val;
1598}
1599
1600const ConstString &
1601DebuggerInstanceSettings::PromptVarName ()
1602{
1603 static ConstString prompt_var_name ("prompt");
1604
1605 return prompt_var_name;
1606}
1607
1608const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00001609DebuggerInstanceSettings::GetFrameFormatName ()
1610{
1611 static ConstString prompt_var_name ("frame-format");
1612
1613 return prompt_var_name;
1614}
1615
1616const ConstString &
1617DebuggerInstanceSettings::GetThreadFormatName ()
1618{
1619 static ConstString prompt_var_name ("thread-format");
1620
1621 return prompt_var_name;
1622}
1623
1624const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001625DebuggerInstanceSettings::ScriptLangVarName ()
1626{
1627 static ConstString script_lang_var_name ("script-lang");
1628
1629 return script_lang_var_name;
1630}
1631
Caroline Tice101c7c22010-09-09 06:25:08 +00001632const ConstString &
1633DebuggerInstanceSettings::TermWidthVarName ()
1634{
1635 static ConstString term_width_var_name ("term-width");
1636
1637 return term_width_var_name;
1638}
1639
Caroline Ticedaccaa92010-09-20 20:44:43 +00001640const ConstString &
1641DebuggerInstanceSettings::UseExternalEditorVarName ()
1642{
1643 static ConstString use_external_editor_var_name ("use-external-editor");
1644
1645 return use_external_editor_var_name;
1646}
1647
Jim Ingham3bcdb292010-10-04 22:44:14 +00001648const ConstString &
1649DebuggerInstanceSettings::AutoConfirmName ()
1650{
1651 static ConstString use_external_editor_var_name ("auto-confirm");
1652
1653 return use_external_editor_var_name;
1654}
1655
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001656//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001657// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001658//--------------------------------------------------
1659
1660
1661SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001662Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001663{
1664 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00001665 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
1666 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001667 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1668};
1669
Greg Claytonbb562b12010-10-04 02:44:26 +00001670#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00001671#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001672
Greg Clayton0603aa92010-10-04 01:05:56 +00001673#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1674 "{, ${frame.pc}}"\
1675 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00001676 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00001677 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00001678 "\\n"
1679
Greg Clayton315d2ca2010-11-02 01:53:21 +00001680//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1681// "{, ${frame.pc}}"\
1682// MODULE_WITH_FUNC\
1683// FILE_AND_LINE\
1684// "{, stop reason = ${thread.stop-reason}}"\
1685// "{, name = ${thread.name}}"\
1686// "{, queue = ${thread.queue}}"\
1687// "\\n"
1688
Greg Clayton0603aa92010-10-04 01:05:56 +00001689#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
1690 MODULE_WITH_FUNC\
1691 FILE_AND_LINE\
1692 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001693
1694SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001695Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001696{
Greg Clayton0603aa92010-10-04 01:05:56 +00001697// NAME Setting variable type Default Enum Init'd Hidden Help
1698// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00001699{ "frame-format", eSetVarTypeString, DEFAULT_FRAME_FORMAT, NULL, false, false, "The default frame format string to use when displaying thread information." },
Greg Clayton54180392010-10-22 21:15:00 +00001700{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00001701{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
1702{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001703{ "thread-format", eSetVarTypeString, DEFAULT_THREAD_FORMAT, NULL, false, false, "The default thread format string to use when displaying thread information." },
Jim Ingham06e827c2010-11-11 19:26:09 +00001704{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
1705{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001706{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001707};