blob: ba1e4b3d070d6072d924be64b106759dfffa84d8 [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
Caroline Tice9088b062011-05-09 23:06:58 +0000440bool
441Debugger::InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp)
442{
443 if (reader_sp)
444 {
445 InputReaderSP top_reader_sp (GetCurrentInputReader());
446 if (top_reader_sp)
447 {
448 return (reader_sp.get() == top_reader_sp.get());
449 }
450 else
451 return false;
452 }
453 else
454 return false;
455
456}
457
458
Caroline Tice969ed3d2011-05-02 20:41:46 +0000459void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
461{
462 if (bytes && bytes_len)
463 m_input_reader_data.append (bytes, bytes_len);
464
465 if (m_input_reader_data.empty())
466 return;
467
468 while (!m_input_readers.empty() && !m_input_reader_data.empty())
469 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000471 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 if (!reader_sp)
473 break;
474
Greg Clayton471b31c2010-07-20 22:52:08 +0000475 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 m_input_reader_data.size());
477 if (bytes_handled)
478 {
479 m_input_reader_data.erase (0, bytes_handled);
480 }
481 else
482 {
483 // No bytes were handled, we might not have reached our
484 // granularity, just return and wait for more data
485 break;
486 }
487 }
488
Caroline Ticeb44880c2011-02-10 01:15:13 +0000489 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490 while (CheckIfTopInputReaderIsDone ())
491 /* Do nothing. */;
492
493}
494
495void
496Debugger::PushInputReader (const InputReaderSP& reader_sp)
497{
498 if (!reader_sp)
499 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000500
501 // Deactivate the old top reader
502 InputReaderSP top_reader_sp (GetCurrentInputReader ());
503
504 if (top_reader_sp)
505 top_reader_sp->Notify (eInputReaderDeactivate);
506
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507 m_input_readers.push (reader_sp);
508 reader_sp->Notify (eInputReaderActivate);
509 ActivateInputReader (reader_sp);
510}
511
512bool
513Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp)
514{
515 bool result = false;
516
517 // The reader on the stop of the stack is done, so let the next
518 // read on the stack referesh its prompt and if there is one...
519 if (!m_input_readers.empty())
520 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000521 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522 InputReaderSP reader_sp(m_input_readers.top());
523
524 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
525 {
526 m_input_readers.pop ();
527 reader_sp->Notify (eInputReaderDeactivate);
528 reader_sp->Notify (eInputReaderDone);
529 result = true;
530
531 if (!m_input_readers.empty())
532 {
533 reader_sp = m_input_readers.top();
534 if (reader_sp)
535 {
536 ActivateInputReader (reader_sp);
537 reader_sp->Notify (eInputReaderReactivate);
538 }
539 }
540 }
541 }
542 return result;
543}
544
545bool
546Debugger::CheckIfTopInputReaderIsDone ()
547{
548 bool result = false;
549 if (!m_input_readers.empty())
550 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000551 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552 InputReaderSP reader_sp(m_input_readers.top());
553
554 if (reader_sp && reader_sp->IsDone())
555 {
556 result = true;
557 PopInputReader (reader_sp);
558 }
559 }
560 return result;
561}
562
563void
564Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
565{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000566 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000568 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000570 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000571
572 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573
Greg Claytona3406612011-02-07 23:24:47 +0000574 switch (reader_sp->GetGranularity())
575 {
576 case eInputReaderGranularityByte:
577 case eInputReaderGranularityWord:
578 tty.SetCanonical (false);
579 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580
Greg Claytona3406612011-02-07 23:24:47 +0000581 case eInputReaderGranularityLine:
582 case eInputReaderGranularityAll:
583 tty.SetCanonical (true);
584 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585
Greg Claytona3406612011-02-07 23:24:47 +0000586 default:
587 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588 }
589 }
590}
Greg Clayton66111032010-06-23 01:19:29 +0000591
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000592DebuggerSP
593Debugger::FindDebuggerWithID (lldb::user_id_t id)
594{
595 lldb::DebuggerSP debugger_sp;
596
597 Mutex::Locker locker (GetDebuggerListMutex ());
598 DebuggerList &debugger_list = GetDebuggerList();
599 DebuggerList::iterator pos, end = debugger_list.end();
600 for (pos = debugger_list.begin(); pos != end; ++pos)
601 {
602 if ((*pos).get()->GetID() == id)
603 {
604 debugger_sp = *pos;
605 break;
606 }
607 }
608 return debugger_sp;
609}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000610
Greg Clayton1b654882010-09-19 02:33:57 +0000611static void
612TestPromptFormats (StackFrame *frame)
613{
614 if (frame == NULL)
615 return;
616
617 StreamString s;
618 const char *prompt_format =
619 "{addr = '${addr}'\n}"
620 "{process.id = '${process.id}'\n}"
621 "{process.name = '${process.name}'\n}"
622 "{process.file.basename = '${process.file.basename}'\n}"
623 "{process.file.fullpath = '${process.file.fullpath}'\n}"
624 "{thread.id = '${thread.id}'\n}"
625 "{thread.index = '${thread.index}'\n}"
626 "{thread.name = '${thread.name}'\n}"
627 "{thread.queue = '${thread.queue}'\n}"
628 "{thread.stop-reason = '${thread.stop-reason}'\n}"
629 "{target.arch = '${target.arch}'\n}"
630 "{module.file.basename = '${module.file.basename}'\n}"
631 "{module.file.fullpath = '${module.file.fullpath}'\n}"
632 "{file.basename = '${file.basename}'\n}"
633 "{file.fullpath = '${file.fullpath}'\n}"
634 "{frame.index = '${frame.index}'\n}"
635 "{frame.pc = '${frame.pc}'\n}"
636 "{frame.sp = '${frame.sp}'\n}"
637 "{frame.fp = '${frame.fp}'\n}"
638 "{frame.flags = '${frame.flags}'\n}"
639 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
640 "{frame.reg.rip = '${frame.reg.rip}'\n}"
641 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
642 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
643 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
644 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
645 "{frame.reg.carp = '${frame.reg.carp}'\n}"
646 "{function.id = '${function.id}'\n}"
647 "{function.name = '${function.name}'\n}"
648 "{function.addr-offset = '${function.addr-offset}'\n}"
649 "{function.line-offset = '${function.line-offset}'\n}"
650 "{function.pc-offset = '${function.pc-offset}'\n}"
651 "{line.file.basename = '${line.file.basename}'\n}"
652 "{line.file.fullpath = '${line.file.fullpath}'\n}"
653 "{line.number = '${line.number}'\n}"
654 "{line.start-addr = '${line.start-addr}'\n}"
655 "{line.end-addr = '${line.end-addr}'\n}"
656;
657
658 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
659 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000660 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000661 const char *end = NULL;
662 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
663 {
664 printf("%s\n", s.GetData());
665 }
666 else
667 {
668 printf ("error: at '%s'\n", end);
669 printf ("what we got: %s\n", s.GetData());
670 }
671}
672
673bool
674Debugger::FormatPrompt
675(
676 const char *format,
677 const SymbolContext *sc,
678 const ExecutionContext *exe_ctx,
679 const Address *addr,
680 Stream &s,
681 const char **end
682)
683{
684 bool success = true;
685 const char *p;
686 for (p = format; *p != '\0'; ++p)
687 {
688 size_t non_special_chars = ::strcspn (p, "${}\\");
689 if (non_special_chars > 0)
690 {
691 if (success)
692 s.Write (p, non_special_chars);
693 p += non_special_chars;
694 }
695
696 if (*p == '\0')
697 {
698 break;
699 }
700 else if (*p == '{')
701 {
702 // Start a new scope that must have everything it needs if it is to
703 // to make it into the final output stream "s". If you want to make
704 // a format that only prints out the function or symbol name if there
705 // is one in the symbol context you can use:
706 // "{function =${function.name}}"
707 // The first '{' starts a new scope that end with the matching '}' at
708 // the end of the string. The contents "function =${function.name}"
709 // will then be evaluated and only be output if there is a function
710 // or symbol with a valid name.
711 StreamString sub_strm;
712
713 ++p; // Skip the '{'
714
715 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p))
716 {
717 // The stream had all it needed
718 s.Write(sub_strm.GetData(), sub_strm.GetSize());
719 }
720 if (*p != '}')
721 {
722 success = false;
723 break;
724 }
725 }
726 else if (*p == '}')
727 {
728 // End of a enclosing scope
729 break;
730 }
731 else if (*p == '$')
732 {
733 // We have a prompt variable to print
734 ++p;
735 if (*p == '{')
736 {
737 ++p;
738 const char *var_name_begin = p;
739 const char *var_name_end = ::strchr (p, '}');
740
741 if (var_name_end && var_name_begin < var_name_end)
742 {
743 // if we have already failed to parse, skip this variable
744 if (success)
745 {
746 const char *cstr = NULL;
747 Address format_addr;
748 bool calculate_format_addr_function_offset = false;
749 // Set reg_kind and reg_num to invalid values
750 RegisterKind reg_kind = kNumRegisterKinds;
751 uint32_t reg_num = LLDB_INVALID_REGNUM;
752 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +0000753 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +0000754 RegisterContext *reg_ctx = NULL;
755
756 // Each variable must set success to true below...
757 bool var_success = false;
758 switch (var_name_begin[0])
759 {
760 case 'a':
761 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
762 {
763 if (addr && addr->IsValid())
764 {
765 var_success = true;
766 format_addr = *addr;
767 }
768 }
769 break;
770
771 case 'p':
772 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
773 {
774 if (exe_ctx && exe_ctx->process != NULL)
775 {
776 var_name_begin += ::strlen ("process.");
777 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
778 {
779 s.Printf("%i", exe_ctx->process->GetID());
780 var_success = true;
781 }
782 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
783 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
784 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
785 {
786 ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
787 if (exe_module_sp)
788 {
789 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
790 {
791 format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
792 var_success = format_file_spec;
793 }
794 else
795 {
796 format_file_spec = exe_module_sp->GetFileSpec();
797 var_success = format_file_spec;
798 }
799 }
800 }
801 }
802 }
803 break;
804
805 case 't':
806 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
807 {
808 if (exe_ctx && exe_ctx->thread)
809 {
810 var_name_begin += ::strlen ("thread.");
811 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
812 {
813 s.Printf("0x%4.4x", exe_ctx->thread->GetID());
814 var_success = true;
815 }
816 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
817 {
818 s.Printf("%u", exe_ctx->thread->GetIndexID());
819 var_success = true;
820 }
821 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
822 {
823 cstr = exe_ctx->thread->GetName();
824 var_success = cstr && cstr[0];
825 if (var_success)
826 s.PutCString(cstr);
827 }
828 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
829 {
830 cstr = exe_ctx->thread->GetQueueName();
831 var_success = cstr && cstr[0];
832 if (var_success)
833 s.PutCString(cstr);
834 }
835 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
836 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000837 StopInfoSP stop_info_sp = exe_ctx->thread->GetStopInfo ();
838 if (stop_info_sp)
Greg Clayton1b654882010-09-19 02:33:57 +0000839 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000840 cstr = stop_info_sp->GetDescription();
Greg Clayton1b654882010-09-19 02:33:57 +0000841 if (cstr && cstr[0])
842 {
843 s.PutCString(cstr);
844 var_success = true;
845 }
846 }
847 }
848 }
849 }
850 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
851 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000852 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
853 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +0000854 {
Greg Clayton1b654882010-09-19 02:33:57 +0000855 var_name_begin += ::strlen ("target.");
856 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
857 {
858 ArchSpec arch (target->GetArchitecture ());
859 if (arch.IsValid())
860 {
Greg Clayton64195a22011-02-23 00:35:02 +0000861 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +0000862 var_success = true;
863 }
864 }
865 }
866 }
867 break;
868
869
870 case 'm':
871 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
872 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000873 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +0000874 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000875 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +0000876 var_name_begin += ::strlen ("module.");
877
878 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
879 {
880 if (module->GetFileSpec())
881 {
882 var_name_begin += ::strlen ("file.");
883
884 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
885 {
886 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
887 var_success = format_file_spec;
888 }
889 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
890 {
891 format_file_spec = module->GetFileSpec();
892 var_success = format_file_spec;
893 }
894 }
895 }
896 }
897 }
898 break;
899
900
901 case 'f':
902 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
903 {
904 if (sc && sc->comp_unit != NULL)
905 {
906 var_name_begin += ::strlen ("file.");
907
908 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
909 {
910 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
911 var_success = format_file_spec;
912 }
913 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
914 {
915 format_file_spec = *sc->comp_unit;
916 var_success = format_file_spec;
917 }
918 }
919 }
920 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
921 {
922 if (exe_ctx && exe_ctx->frame)
923 {
924 var_name_begin += ::strlen ("frame.");
925 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
926 {
927 s.Printf("%u", exe_ctx->frame->GetFrameIndex());
928 var_success = true;
929 }
930 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
931 {
932 reg_kind = eRegisterKindGeneric;
933 reg_num = LLDB_REGNUM_GENERIC_PC;
934 var_success = true;
935 }
936 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
937 {
938 reg_kind = eRegisterKindGeneric;
939 reg_num = LLDB_REGNUM_GENERIC_SP;
940 var_success = true;
941 }
942 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
943 {
944 reg_kind = eRegisterKindGeneric;
945 reg_num = LLDB_REGNUM_GENERIC_FP;
946 var_success = true;
947 }
948 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
949 {
950 reg_kind = eRegisterKindGeneric;
951 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
952 var_success = true;
953 }
954 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
955 {
Greg Clayton5ccbd292011-01-06 22:15:06 +0000956 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +0000957 if (reg_ctx)
958 {
959 var_name_begin += ::strlen ("reg.");
960 if (var_name_begin < var_name_end)
961 {
962 std::string reg_name (var_name_begin, var_name_end);
963 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
964 if (reg_info)
965 var_success = true;
966 }
967 }
968 }
969 }
970 }
971 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
972 {
973 if (sc && (sc->function != NULL || sc->symbol != NULL))
974 {
975 var_name_begin += ::strlen ("function.");
976 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
977 {
978 if (sc->function)
979 s.Printf("function{0x%8.8x}", sc->function->GetID());
980 else
981 s.Printf("symbol[%u]", sc->symbol->GetID());
982
983 var_success = true;
984 }
985 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
986 {
987 if (sc->function)
988 cstr = sc->function->GetName().AsCString (NULL);
989 else if (sc->symbol)
990 cstr = sc->symbol->GetName().AsCString (NULL);
991 if (cstr)
992 {
993 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +0000994
995 if (sc->block)
996 {
997 Block *inline_block = sc->block->GetContainingInlinedBlock ();
998 if (inline_block)
999 {
1000 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1001 if (inline_info)
1002 {
1003 s.PutCString(" [inlined] ");
1004 inline_info->GetName().Dump(&s);
1005 }
1006 }
1007 }
Greg Clayton1b654882010-09-19 02:33:57 +00001008 var_success = true;
1009 }
1010 }
1011 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1012 {
1013 var_success = addr != NULL;
1014 if (var_success)
1015 {
1016 format_addr = *addr;
1017 calculate_format_addr_function_offset = true;
1018 }
1019 }
1020 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1021 {
1022 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1023 if (var_success)
1024 {
1025 format_addr = sc->line_entry.range.GetBaseAddress();
1026 calculate_format_addr_function_offset = true;
1027 }
1028 }
1029 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1030 {
1031 var_success = exe_ctx->frame;
1032 if (var_success)
1033 {
1034 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1035 calculate_format_addr_function_offset = true;
1036 }
1037 }
1038 }
1039 }
1040 break;
1041
1042 case 'l':
1043 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1044 {
1045 if (sc && sc->line_entry.IsValid())
1046 {
1047 var_name_begin += ::strlen ("line.");
1048 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1049 {
1050 var_name_begin += ::strlen ("file.");
1051
1052 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1053 {
1054 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1055 var_success = format_file_spec;
1056 }
1057 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1058 {
1059 format_file_spec = sc->line_entry.file;
1060 var_success = format_file_spec;
1061 }
1062 }
1063 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1064 {
1065 var_success = true;
1066 s.Printf("%u", sc->line_entry.line);
1067 }
1068 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1069 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1070 {
1071 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1072 if (var_success)
1073 {
1074 format_addr = sc->line_entry.range.GetBaseAddress();
1075 if (var_name_begin[0] == 'e')
1076 format_addr.Slide (sc->line_entry.range.GetByteSize());
1077 }
1078 }
1079 }
1080 }
1081 break;
1082 }
1083
1084 if (var_success)
1085 {
1086 // If format addr is valid, then we need to print an address
1087 if (reg_num != LLDB_INVALID_REGNUM)
1088 {
1089 // We have a register value to display...
1090 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1091 {
1092 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1093 }
1094 else
1095 {
1096 if (reg_ctx == NULL)
Greg Clayton5ccbd292011-01-06 22:15:06 +00001097 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001098
1099 if (reg_ctx)
1100 {
1101 if (reg_kind != kNumRegisterKinds)
1102 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1103 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1104 var_success = reg_info != NULL;
1105 }
1106 }
1107 }
1108
1109 if (reg_info != NULL)
1110 {
Greg Clayton7349bd92011-05-09 20:18:18 +00001111 RegisterValue reg_value;
1112 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
1113 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001114 {
Greg Clayton7349bd92011-05-09 20:18:18 +00001115 reg_value.Dump(&s, reg_info, false);
Greg Clayton1b654882010-09-19 02:33:57 +00001116 }
1117 }
1118
1119 if (format_file_spec)
1120 {
1121 s << format_file_spec;
1122 }
1123
1124 // If format addr is valid, then we need to print an address
1125 if (format_addr.IsValid())
1126 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001127 var_success = false;
1128
Greg Clayton1b654882010-09-19 02:33:57 +00001129 if (calculate_format_addr_function_offset)
1130 {
1131 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001132
Greg Clayton0603aa92010-10-04 01:05:56 +00001133 if (sc)
1134 {
1135 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001136 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001137 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001138 if (sc->block)
1139 {
1140 // Check to make sure we aren't in an inline
1141 // function. If we are, use the inline block
1142 // range that contains "format_addr" since
1143 // blocks can be discontiguous.
1144 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1145 AddressRange inline_range;
1146 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1147 func_addr = inline_range.GetBaseAddress();
1148 }
1149 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001150 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1151 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1152 }
1153
1154 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001155 {
1156 if (func_addr.GetSection() == format_addr.GetSection())
1157 {
1158 addr_t func_file_addr = func_addr.GetFileAddress();
1159 addr_t addr_file_addr = format_addr.GetFileAddress();
1160 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001161 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001162 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001163 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001164 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001165 }
1166 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001167 {
1168 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1169 if (target)
1170 {
1171 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1172 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1173 if (addr_load_addr > func_load_addr)
1174 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1175 else if (addr_load_addr < func_load_addr)
1176 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1177 var_success = true;
1178 }
1179 }
Greg Clayton1b654882010-09-19 02:33:57 +00001180 }
1181 }
1182 else
1183 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001184 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001185 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001186 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1187 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001188 if (vaddr == LLDB_INVALID_ADDRESS)
1189 vaddr = format_addr.GetFileAddress ();
1190
1191 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001192 {
Greg Clayton514487e2011-02-15 21:59:32 +00001193 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001194 if (addr_width == 0)
1195 addr_width = 16;
1196 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001197 var_success = true;
1198 }
Greg Clayton1b654882010-09-19 02:33:57 +00001199 }
1200 }
1201 }
1202
1203 if (var_success == false)
1204 success = false;
1205 }
1206 p = var_name_end;
1207 }
1208 else
1209 break;
1210 }
1211 else
1212 {
1213 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1214 s.PutChar(*p);
1215 }
1216 }
1217 else if (*p == '\\')
1218 {
1219 ++p; // skip the slash
1220 switch (*p)
1221 {
1222 case 'a': s.PutChar ('\a'); break;
1223 case 'b': s.PutChar ('\b'); break;
1224 case 'f': s.PutChar ('\f'); break;
1225 case 'n': s.PutChar ('\n'); break;
1226 case 'r': s.PutChar ('\r'); break;
1227 case 't': s.PutChar ('\t'); break;
1228 case 'v': s.PutChar ('\v'); break;
1229 case '\'': s.PutChar ('\''); break;
1230 case '\\': s.PutChar ('\\'); break;
1231 case '0':
1232 // 1 to 3 octal chars
1233 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001234 // Make a string that can hold onto the initial zero char,
1235 // up to 3 octal digits, and a terminating NULL.
1236 char oct_str[5] = { 0, 0, 0, 0, 0 };
1237
1238 int i;
1239 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1240 oct_str[i] = p[i];
1241
1242 // We don't want to consume the last octal character since
1243 // the main for loop will do this for us, so we advance p by
1244 // one less than i (even if i is zero)
1245 p += i - 1;
1246 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
1247 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001248 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001249 char octal_char = octal_value;
1250 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00001251 }
Greg Clayton1b654882010-09-19 02:33:57 +00001252 }
1253 break;
1254
1255 case 'x':
1256 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00001257 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001258 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001259 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00001260
Greg Clayton0603aa92010-10-04 01:05:56 +00001261 // Make a string that can hold onto two hex chars plus a
1262 // NULL terminator
1263 char hex_str[3] = { 0,0,0 };
1264 hex_str[0] = *p;
1265 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001266 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001267 ++p; // Skip the first of the two hex chars
1268 hex_str[1] = *p;
1269 }
1270
1271 unsigned long hex_value = strtoul (hex_str, NULL, 16);
1272 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001273 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00001274 }
1275 else
1276 {
1277 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00001278 }
1279 break;
1280
1281 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00001282 // Just desensitize any other character by just printing what
1283 // came after the '\'
1284 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00001285 break;
1286
1287 }
1288
1289 }
1290 }
1291 if (end)
1292 *end = p;
1293 return success;
1294}
1295
1296#pragma mark Debugger::SettingsController
1297
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001298//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001299// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001300//--------------------------------------------------
1301
Greg Clayton1b654882010-09-19 02:33:57 +00001302Debugger::SettingsController::SettingsController () :
Caroline Tice101c7c22010-09-09 06:25:08 +00001303 UserSettingsController ("", lldb::UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001304{
Caroline Tice91123da2010-09-08 17:48:55 +00001305 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
1306 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001307}
1308
Greg Clayton1b654882010-09-19 02:33:57 +00001309Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001310{
1311}
1312
1313
1314lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00001315Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001316{
Greg Claytondbe54502010-11-19 03:46:01 +00001317 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00001318 false, instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001319 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1320 return new_settings_sp;
1321}
1322
Greg Clayton1b654882010-09-19 02:33:57 +00001323#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001324//--------------------------------------------------
1325// class DebuggerInstanceSettings
1326//--------------------------------------------------
1327
Greg Claytona7015092010-09-18 01:14:36 +00001328DebuggerInstanceSettings::DebuggerInstanceSettings
1329(
1330 UserSettingsController &owner,
1331 bool live_instance,
1332 const char *name
1333) :
Greg Clayton85851dd2010-12-04 00:10:17 +00001334 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00001335 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001336 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00001337 m_frame_format (),
1338 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001339 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001340 m_use_external_editor (false),
1341 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001342{
Caroline Ticef20e8232010-09-09 18:26:37 +00001343 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1344 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
1345 // 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 +00001346 // The same is true of CreateInstanceName().
1347
1348 if (GetInstanceName() == InstanceSettings::InvalidName())
1349 {
1350 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1351 m_owner.RegisterInstanceSettings (this);
1352 }
Caroline Ticef20e8232010-09-09 18:26:37 +00001353
1354 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001355 {
1356 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1357 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001358 }
1359}
1360
1361DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00001362 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001363 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00001364 m_frame_format (rhs.m_frame_format),
1365 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001366 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001367 m_use_external_editor (rhs.m_use_external_editor),
1368 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001369{
1370 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1371 CopyInstanceSettings (pending_settings, false);
1372 m_owner.RemovePendingSettings (m_instance_name);
1373}
1374
1375DebuggerInstanceSettings::~DebuggerInstanceSettings ()
1376{
1377}
1378
1379DebuggerInstanceSettings&
1380DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
1381{
1382 if (this != &rhs)
1383 {
Greg Clayton1b654882010-09-19 02:33:57 +00001384 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001385 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00001386 m_frame_format = rhs.m_frame_format;
1387 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001388 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001389 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001390 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001391 }
1392
1393 return *this;
1394}
1395
Greg Clayton1b654882010-09-19 02:33:57 +00001396bool
1397DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
1398{
1399 bool valid = false;
1400
1401 // Verify we have a value string.
1402 if (value == NULL || value[0] == '\0')
1403 {
1404 err.SetErrorString ("Missing value. Can't set terminal width without a value.\n");
1405 }
1406 else
1407 {
1408 char *end = NULL;
1409 const uint32_t width = ::strtoul (value, &end, 0);
1410
Johnny Chenea9fc182010-09-20 16:36:43 +00001411 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00001412 {
Johnny Chen433d7742010-09-20 17:04:41 +00001413 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00001414 valid = true;
1415 else
1416 err.SetErrorString ("Invalid term-width value; value must be between 10 and 1024.\n");
1417 }
1418 else
1419 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string.\n", value);
1420 }
1421
1422 return valid;
1423}
1424
1425
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001426void
1427DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1428 const char *index_value,
1429 const char *value,
1430 const ConstString &instance_name,
1431 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00001432 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001433 Error &err,
1434 bool pending)
1435{
Greg Clayton0603aa92010-10-04 01:05:56 +00001436
1437 if (var_name == TermWidthVarName())
1438 {
1439 if (ValidTermWidthValue (value, err))
1440 {
1441 m_term_width = ::strtoul (value, NULL, 0);
1442 }
1443 }
1444 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001445 {
Caroline Tice101c7c22010-09-09 06:25:08 +00001446 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001447 if (!pending)
1448 {
Caroline Tice49e27372010-09-07 18:35:40 +00001449 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1450 // strip off the brackets before passing it to BroadcastPromptChange.
1451
1452 std::string tmp_instance_name (instance_name.AsCString());
1453 if ((tmp_instance_name[0] == '[')
1454 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
1455 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
1456 ConstString new_name (tmp_instance_name.c_str());
1457
1458 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001459 }
1460 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001461 else if (var_name == GetFrameFormatName())
1462 {
1463 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
1464 }
1465 else if (var_name == GetThreadFormatName())
1466 {
1467 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
1468 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001469 else if (var_name == ScriptLangVarName())
1470 {
1471 bool success;
1472 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
1473 &success);
1474 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001475 else if (var_name == UseExternalEditorVarName ())
1476 {
Greg Clayton385aa282011-04-22 03:55:06 +00001477 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00001478 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001479 else if (var_name == AutoConfirmName ())
1480 {
Greg Clayton385aa282011-04-22 03:55:06 +00001481 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00001482 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001483}
1484
Caroline Tice12cecd72010-09-20 21:37:42 +00001485bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001486DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1487 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00001488 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00001489 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001490{
1491 if (var_name == PromptVarName())
1492 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001493 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001494
1495 }
1496 else if (var_name == ScriptLangVarName())
1497 {
1498 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
1499 }
Caroline Tice101c7c22010-09-09 06:25:08 +00001500 else if (var_name == TermWidthVarName())
1501 {
1502 StreamString width_str;
1503 width_str.Printf ("%d", m_term_width);
1504 value.AppendString (width_str.GetData());
1505 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001506 else if (var_name == GetFrameFormatName ())
1507 {
1508 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
1509 }
1510 else if (var_name == GetThreadFormatName ())
1511 {
1512 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
1513 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001514 else if (var_name == UseExternalEditorVarName())
1515 {
1516 if (m_use_external_editor)
1517 value.AppendString ("true");
1518 else
1519 value.AppendString ("false");
1520 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001521 else if (var_name == AutoConfirmName())
1522 {
1523 if (m_auto_confirm_on)
1524 value.AppendString ("true");
1525 else
1526 value.AppendString ("false");
1527 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001528 else
Caroline Tice12cecd72010-09-20 21:37:42 +00001529 {
1530 if (err)
1531 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1532 return false;
1533 }
1534 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001535}
1536
1537void
1538DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1539 bool pending)
1540{
1541 if (new_settings.get() == NULL)
1542 return;
1543
1544 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
1545
1546 m_prompt = new_debugger_settings->m_prompt;
1547 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00001548 {
1549 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1550 // strip off the brackets before passing it to BroadcastPromptChange.
1551
1552 std::string tmp_instance_name (m_instance_name.AsCString());
1553 if ((tmp_instance_name[0] == '[')
1554 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
1555 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
1556 ConstString new_name (tmp_instance_name.c_str());
1557
1558 BroadcastPromptChange (new_name, m_prompt.c_str());
1559 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001560 m_frame_format = new_debugger_settings->m_frame_format;
1561 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001562 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001563 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001564 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001565 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001566}
1567
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001568
1569bool
1570DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
1571{
1572 std::string tmp_prompt;
1573
1574 if (new_prompt != NULL)
1575 {
1576 tmp_prompt = new_prompt ;
1577 int len = tmp_prompt.size();
1578 if (len > 1
1579 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
1580 && (tmp_prompt[len-1] == tmp_prompt[0]))
1581 {
1582 tmp_prompt = tmp_prompt.substr(1,len-2);
1583 }
1584 len = tmp_prompt.size();
1585 if (tmp_prompt[len-1] != ' ')
1586 tmp_prompt.append(" ");
1587 }
1588 EventSP new_event_sp;
1589 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
1590 new EventDataBytes (tmp_prompt.c_str())));
1591
1592 if (instance_name.GetLength() != 0)
1593 {
1594 // Set prompt for a particular instance.
1595 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
1596 if (dbg != NULL)
1597 {
1598 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
1599 }
1600 }
1601
1602 return true;
1603}
1604
1605const ConstString
1606DebuggerInstanceSettings::CreateInstanceName ()
1607{
1608 static int instance_count = 1;
1609 StreamString sstr;
1610
1611 sstr.Printf ("debugger_%d", instance_count);
1612 ++instance_count;
1613
1614 const ConstString ret_val (sstr.GetData());
1615
1616 return ret_val;
1617}
1618
1619const ConstString &
1620DebuggerInstanceSettings::PromptVarName ()
1621{
1622 static ConstString prompt_var_name ("prompt");
1623
1624 return prompt_var_name;
1625}
1626
1627const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00001628DebuggerInstanceSettings::GetFrameFormatName ()
1629{
1630 static ConstString prompt_var_name ("frame-format");
1631
1632 return prompt_var_name;
1633}
1634
1635const ConstString &
1636DebuggerInstanceSettings::GetThreadFormatName ()
1637{
1638 static ConstString prompt_var_name ("thread-format");
1639
1640 return prompt_var_name;
1641}
1642
1643const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001644DebuggerInstanceSettings::ScriptLangVarName ()
1645{
1646 static ConstString script_lang_var_name ("script-lang");
1647
1648 return script_lang_var_name;
1649}
1650
Caroline Tice101c7c22010-09-09 06:25:08 +00001651const ConstString &
1652DebuggerInstanceSettings::TermWidthVarName ()
1653{
1654 static ConstString term_width_var_name ("term-width");
1655
1656 return term_width_var_name;
1657}
1658
Caroline Ticedaccaa92010-09-20 20:44:43 +00001659const ConstString &
1660DebuggerInstanceSettings::UseExternalEditorVarName ()
1661{
1662 static ConstString use_external_editor_var_name ("use-external-editor");
1663
1664 return use_external_editor_var_name;
1665}
1666
Jim Ingham3bcdb292010-10-04 22:44:14 +00001667const ConstString &
1668DebuggerInstanceSettings::AutoConfirmName ()
1669{
1670 static ConstString use_external_editor_var_name ("auto-confirm");
1671
1672 return use_external_editor_var_name;
1673}
1674
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001675//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001676// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001677//--------------------------------------------------
1678
1679
1680SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001681Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001682{
1683 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00001684 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
1685 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001686 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1687};
1688
Greg Claytonbb562b12010-10-04 02:44:26 +00001689#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00001690#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001691
Greg Clayton0603aa92010-10-04 01:05:56 +00001692#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1693 "{, ${frame.pc}}"\
1694 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00001695 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00001696 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00001697 "\\n"
1698
Greg Clayton315d2ca2010-11-02 01:53:21 +00001699//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1700// "{, ${frame.pc}}"\
1701// MODULE_WITH_FUNC\
1702// FILE_AND_LINE\
1703// "{, stop reason = ${thread.stop-reason}}"\
1704// "{, name = ${thread.name}}"\
1705// "{, queue = ${thread.queue}}"\
1706// "\\n"
1707
Greg Clayton0603aa92010-10-04 01:05:56 +00001708#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
1709 MODULE_WITH_FUNC\
1710 FILE_AND_LINE\
1711 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001712
1713SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001714Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001715{
Greg Clayton0603aa92010-10-04 01:05:56 +00001716// NAME Setting variable type Default Enum Init'd Hidden Help
1717// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00001718{ "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 +00001719{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00001720{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
1721{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001722{ "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 +00001723{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
1724{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001725{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001726};