blob: ca0dde920bd8f71a5448ed66acc52c812ba1b67e [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"
14#include "lldb/Core/State.h"
Greg Clayton1b654882010-09-19 02:33:57 +000015#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Core/Timer.h"
Greg Claytona3406612011-02-07 23:24:47 +000017#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000018#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Target/TargetList.h"
20#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000021#include "lldb/Target/RegisterContext.h"
22#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Target/Thread.h"
24
25
26using namespace lldb;
27using namespace lldb_private;
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
Greg Clayton1b654882010-09-19 02:33:57 +000030static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000031static lldb::user_id_t g_unique_id = 1;
32
Greg Clayton1b654882010-09-19 02:33:57 +000033#pragma mark Static Functions
34
35static Mutex &
36GetDebuggerListMutex ()
37{
38 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
39 return g_mutex;
40}
41
42typedef std::vector<DebuggerSP> DebuggerList;
43
44static DebuggerList &
45GetDebuggerList()
46{
47 // hide the static debugger list inside a singleton accessor to avoid
48 // global init contructors
49 static DebuggerList g_list;
50 return g_list;
51}
52
53
54#pragma mark Debugger
55
Greg Clayton99d0faf2010-11-18 23:32:35 +000056UserSettingsControllerSP &
57Debugger::GetSettingsController ()
58{
59 static UserSettingsControllerSP g_settings_controller;
60 return g_settings_controller;
61}
62
Caroline Tice2f88aad2011-01-14 00:29:16 +000063int
64Debugger::TestDebuggerRefCount ()
65{
66 return g_shared_debugger_refcount;
67}
68
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069void
70Debugger::Initialize ()
71{
Greg Clayton66111032010-06-23 01:19:29 +000072 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +000073 {
Greg Claytondbe54502010-11-19 03:46:01 +000074 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +000075 }
Greg Clayton66111032010-06-23 01:19:29 +000076 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +000077
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078}
79
80void
81Debugger::Terminate ()
82{
Greg Clayton66111032010-06-23 01:19:29 +000083 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084 {
Greg Clayton66111032010-06-23 01:19:29 +000085 g_shared_debugger_refcount--;
86 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087 {
Greg Claytondbe54502010-11-19 03:46:01 +000088 lldb_private::WillTerminate();
89 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +000090
91 // Clear our master list of debugger objects
92 Mutex::Locker locker (GetDebuggerListMutex ());
93 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000095 }
96}
97
Caroline Tice20bd37f2011-03-10 22:14:10 +000098void
99Debugger::SettingsInitialize ()
100{
101 static bool g_initialized = false;
102
103 if (!g_initialized)
104 {
105 g_initialized = true;
106 UserSettingsControllerSP &usc = GetSettingsController();
107 usc.reset (new SettingsController);
108 UserSettingsController::InitializeSettingsController (usc,
109 SettingsController::global_settings_table,
110 SettingsController::instance_settings_table);
111 // Now call SettingsInitialize for each settings 'child' of Debugger
112 Target::SettingsInitialize ();
113 }
114}
115
116void
117Debugger::SettingsTerminate ()
118{
119
120 // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
121 // Settings.
122
123 Target::SettingsTerminate ();
124
125 // Now terminate the Debugger Settings.
126
127 UserSettingsControllerSP &usc = GetSettingsController();
128 UserSettingsController::FinalizeSettingsController (usc);
129 usc.reset();
130}
131
Greg Clayton66111032010-06-23 01:19:29 +0000132DebuggerSP
133Debugger::CreateInstance ()
134{
135 DebuggerSP debugger_sp (new Debugger);
136 // Scope for locker
137 {
138 Mutex::Locker locker (GetDebuggerListMutex ());
139 GetDebuggerList().push_back(debugger_sp);
140 }
141 return debugger_sp;
142}
143
Caroline Ticee02657b2011-01-22 01:02:07 +0000144void
145Debugger::Destroy (lldb::DebuggerSP &debugger_sp)
146{
147 if (debugger_sp.get() == NULL)
148 return;
149
150 Mutex::Locker locker (GetDebuggerListMutex ());
151 DebuggerList &debugger_list = GetDebuggerList ();
152 DebuggerList::iterator pos, end = debugger_list.end();
153 for (pos = debugger_list.begin (); pos != end; ++pos)
154 {
155 if ((*pos).get() == debugger_sp.get())
156 {
157 debugger_list.erase (pos);
158 return;
159 }
160 }
161
162}
163
Greg Clayton66111032010-06-23 01:19:29 +0000164lldb::DebuggerSP
165Debugger::GetSP ()
166{
167 lldb::DebuggerSP debugger_sp;
168
169 Mutex::Locker locker (GetDebuggerListMutex ());
170 DebuggerList &debugger_list = GetDebuggerList();
171 DebuggerList::iterator pos, end = debugger_list.end();
172 for (pos = debugger_list.begin(); pos != end; ++pos)
173 {
174 if ((*pos).get() == this)
175 {
176 debugger_sp = *pos;
177 break;
178 }
179 }
180 return debugger_sp;
181}
182
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000183lldb::DebuggerSP
184Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
185{
186 lldb::DebuggerSP debugger_sp;
187
188 Mutex::Locker locker (GetDebuggerListMutex ());
189 DebuggerList &debugger_list = GetDebuggerList();
190 DebuggerList::iterator pos, end = debugger_list.end();
191
192 for (pos = debugger_list.begin(); pos != end; ++pos)
193 {
194 if ((*pos).get()->m_instance_name == instance_name)
195 {
196 debugger_sp = *pos;
197 break;
198 }
199 }
200 return debugger_sp;
201}
Greg Clayton66111032010-06-23 01:19:29 +0000202
203TargetSP
204Debugger::FindTargetWithProcessID (lldb::pid_t pid)
205{
206 lldb::TargetSP target_sp;
207 Mutex::Locker locker (GetDebuggerListMutex ());
208 DebuggerList &debugger_list = GetDebuggerList();
209 DebuggerList::iterator pos, end = debugger_list.end();
210 for (pos = debugger_list.begin(); pos != end; ++pos)
211 {
212 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
213 if (target_sp)
214 break;
215 }
216 return target_sp;
217}
218
219
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000221 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000222 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000223 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 m_input_file (),
225 m_output_file (),
226 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227 m_target_list (),
Greg Claytonded470d2011-03-19 01:12:21 +0000228 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229 m_listener ("lldb.Debugger"),
230 m_source_manager (),
Greg Clayton66111032010-06-23 01:19:29 +0000231 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
232 m_exe_ctx (),
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
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
428{
429 if (bytes && bytes_len)
430 m_input_reader_data.append (bytes, bytes_len);
431
432 if (m_input_reader_data.empty())
433 return;
434
435 while (!m_input_readers.empty() && !m_input_reader_data.empty())
436 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000438 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 if (!reader_sp)
440 break;
441
Greg Clayton471b31c2010-07-20 22:52:08 +0000442 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 m_input_reader_data.size());
444 if (bytes_handled)
445 {
446 m_input_reader_data.erase (0, bytes_handled);
447 }
448 else
449 {
450 // No bytes were handled, we might not have reached our
451 // granularity, just return and wait for more data
452 break;
453 }
454 }
455
Caroline Ticeb44880c2011-02-10 01:15:13 +0000456 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 while (CheckIfTopInputReaderIsDone ())
458 /* Do nothing. */;
459
460}
461
462void
463Debugger::PushInputReader (const InputReaderSP& reader_sp)
464{
465 if (!reader_sp)
466 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000467
468 // Deactivate the old top reader
469 InputReaderSP top_reader_sp (GetCurrentInputReader ());
470
471 if (top_reader_sp)
472 top_reader_sp->Notify (eInputReaderDeactivate);
473
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474 m_input_readers.push (reader_sp);
475 reader_sp->Notify (eInputReaderActivate);
476 ActivateInputReader (reader_sp);
477}
478
479bool
480Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp)
481{
482 bool result = false;
483
484 // The reader on the stop of the stack is done, so let the next
485 // read on the stack referesh its prompt and if there is one...
486 if (!m_input_readers.empty())
487 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000488 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489 InputReaderSP reader_sp(m_input_readers.top());
490
491 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
492 {
493 m_input_readers.pop ();
494 reader_sp->Notify (eInputReaderDeactivate);
495 reader_sp->Notify (eInputReaderDone);
496 result = true;
497
498 if (!m_input_readers.empty())
499 {
500 reader_sp = m_input_readers.top();
501 if (reader_sp)
502 {
503 ActivateInputReader (reader_sp);
504 reader_sp->Notify (eInputReaderReactivate);
505 }
506 }
507 }
508 }
509 return result;
510}
511
512bool
513Debugger::CheckIfTopInputReaderIsDone ()
514{
515 bool result = false;
516 if (!m_input_readers.empty())
517 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000518 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 InputReaderSP reader_sp(m_input_readers.top());
520
521 if (reader_sp && reader_sp->IsDone())
522 {
523 result = true;
524 PopInputReader (reader_sp);
525 }
526 }
527 return result;
528}
529
530void
531Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
532{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000533 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000535 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000537 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000538
539 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540
Greg Claytona3406612011-02-07 23:24:47 +0000541 switch (reader_sp->GetGranularity())
542 {
543 case eInputReaderGranularityByte:
544 case eInputReaderGranularityWord:
545 tty.SetCanonical (false);
546 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547
Greg Claytona3406612011-02-07 23:24:47 +0000548 case eInputReaderGranularityLine:
549 case eInputReaderGranularityAll:
550 tty.SetCanonical (true);
551 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552
Greg Claytona3406612011-02-07 23:24:47 +0000553 default:
554 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555 }
556 }
557}
Greg Clayton66111032010-06-23 01:19:29 +0000558
559void
560Debugger::UpdateExecutionContext (ExecutionContext *override_context)
561{
562 m_exe_ctx.Clear();
563
564 if (override_context != NULL)
565 {
566 m_exe_ctx.target = override_context->target;
567 m_exe_ctx.process = override_context->process;
568 m_exe_ctx.thread = override_context->thread;
569 m_exe_ctx.frame = override_context->frame;
570 }
571 else
572 {
Jim Ingham2976d002010-08-26 21:32:51 +0000573 TargetSP target_sp (GetSelectedTarget());
Greg Clayton66111032010-06-23 01:19:29 +0000574 if (target_sp)
575 {
576 m_exe_ctx.target = target_sp.get();
577 m_exe_ctx.process = target_sp->GetProcessSP().get();
Johnny Chen725945d2010-09-03 22:35:47 +0000578 if (m_exe_ctx.process && m_exe_ctx.process->IsAlive() && !m_exe_ctx.process->IsRunning())
Greg Clayton66111032010-06-23 01:19:29 +0000579 {
Jim Ingham2976d002010-08-26 21:32:51 +0000580 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetSelectedThread().get();
Greg Clayton66111032010-06-23 01:19:29 +0000581 if (m_exe_ctx.thread == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000582 {
Greg Clayton66111032010-06-23 01:19:29 +0000583 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000584 // If we didn't have a selected thread, select one here.
585 if (m_exe_ctx.thread != NULL)
Johnny Chenc13ee522010-09-14 00:53:53 +0000586 m_exe_ctx.process->GetThreadList().SetSelectedThreadByID(m_exe_ctx.thread->GetID());
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000587 }
Greg Clayton66111032010-06-23 01:19:29 +0000588 if (m_exe_ctx.thread)
589 {
Jim Ingham2976d002010-08-26 21:32:51 +0000590 m_exe_ctx.frame = m_exe_ctx.thread->GetSelectedFrame().get();
Greg Clayton66111032010-06-23 01:19:29 +0000591 if (m_exe_ctx.frame == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000592 {
Greg Clayton66111032010-06-23 01:19:29 +0000593 m_exe_ctx.frame = m_exe_ctx.thread->GetStackFrameAtIndex (0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000594 // If we didn't have a selected frame select one here.
595 if (m_exe_ctx.frame != NULL)
596 m_exe_ctx.thread->SetSelectedFrame(m_exe_ctx.frame);
597 }
Greg Clayton66111032010-06-23 01:19:29 +0000598 }
599 }
600 }
601 }
602}
603
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000604DebuggerSP
605Debugger::FindDebuggerWithID (lldb::user_id_t id)
606{
607 lldb::DebuggerSP debugger_sp;
608
609 Mutex::Locker locker (GetDebuggerListMutex ());
610 DebuggerList &debugger_list = GetDebuggerList();
611 DebuggerList::iterator pos, end = debugger_list.end();
612 for (pos = debugger_list.begin(); pos != end; ++pos)
613 {
614 if ((*pos).get()->GetID() == id)
615 {
616 debugger_sp = *pos;
617 break;
618 }
619 }
620 return debugger_sp;
621}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000622
Greg Clayton1b654882010-09-19 02:33:57 +0000623static void
624TestPromptFormats (StackFrame *frame)
625{
626 if (frame == NULL)
627 return;
628
629 StreamString s;
630 const char *prompt_format =
631 "{addr = '${addr}'\n}"
632 "{process.id = '${process.id}'\n}"
633 "{process.name = '${process.name}'\n}"
634 "{process.file.basename = '${process.file.basename}'\n}"
635 "{process.file.fullpath = '${process.file.fullpath}'\n}"
636 "{thread.id = '${thread.id}'\n}"
637 "{thread.index = '${thread.index}'\n}"
638 "{thread.name = '${thread.name}'\n}"
639 "{thread.queue = '${thread.queue}'\n}"
640 "{thread.stop-reason = '${thread.stop-reason}'\n}"
641 "{target.arch = '${target.arch}'\n}"
642 "{module.file.basename = '${module.file.basename}'\n}"
643 "{module.file.fullpath = '${module.file.fullpath}'\n}"
644 "{file.basename = '${file.basename}'\n}"
645 "{file.fullpath = '${file.fullpath}'\n}"
646 "{frame.index = '${frame.index}'\n}"
647 "{frame.pc = '${frame.pc}'\n}"
648 "{frame.sp = '${frame.sp}'\n}"
649 "{frame.fp = '${frame.fp}'\n}"
650 "{frame.flags = '${frame.flags}'\n}"
651 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
652 "{frame.reg.rip = '${frame.reg.rip}'\n}"
653 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
654 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
655 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
656 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
657 "{frame.reg.carp = '${frame.reg.carp}'\n}"
658 "{function.id = '${function.id}'\n}"
659 "{function.name = '${function.name}'\n}"
660 "{function.addr-offset = '${function.addr-offset}'\n}"
661 "{function.line-offset = '${function.line-offset}'\n}"
662 "{function.pc-offset = '${function.pc-offset}'\n}"
663 "{line.file.basename = '${line.file.basename}'\n}"
664 "{line.file.fullpath = '${line.file.fullpath}'\n}"
665 "{line.number = '${line.number}'\n}"
666 "{line.start-addr = '${line.start-addr}'\n}"
667 "{line.end-addr = '${line.end-addr}'\n}"
668;
669
670 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
671 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000672 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000673 const char *end = NULL;
674 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
675 {
676 printf("%s\n", s.GetData());
677 }
678 else
679 {
680 printf ("error: at '%s'\n", end);
681 printf ("what we got: %s\n", s.GetData());
682 }
683}
684
685bool
686Debugger::FormatPrompt
687(
688 const char *format,
689 const SymbolContext *sc,
690 const ExecutionContext *exe_ctx,
691 const Address *addr,
692 Stream &s,
693 const char **end
694)
695{
696 bool success = true;
697 const char *p;
698 for (p = format; *p != '\0'; ++p)
699 {
700 size_t non_special_chars = ::strcspn (p, "${}\\");
701 if (non_special_chars > 0)
702 {
703 if (success)
704 s.Write (p, non_special_chars);
705 p += non_special_chars;
706 }
707
708 if (*p == '\0')
709 {
710 break;
711 }
712 else if (*p == '{')
713 {
714 // Start a new scope that must have everything it needs if it is to
715 // to make it into the final output stream "s". If you want to make
716 // a format that only prints out the function or symbol name if there
717 // is one in the symbol context you can use:
718 // "{function =${function.name}}"
719 // The first '{' starts a new scope that end with the matching '}' at
720 // the end of the string. The contents "function =${function.name}"
721 // will then be evaluated and only be output if there is a function
722 // or symbol with a valid name.
723 StreamString sub_strm;
724
725 ++p; // Skip the '{'
726
727 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p))
728 {
729 // The stream had all it needed
730 s.Write(sub_strm.GetData(), sub_strm.GetSize());
731 }
732 if (*p != '}')
733 {
734 success = false;
735 break;
736 }
737 }
738 else if (*p == '}')
739 {
740 // End of a enclosing scope
741 break;
742 }
743 else if (*p == '$')
744 {
745 // We have a prompt variable to print
746 ++p;
747 if (*p == '{')
748 {
749 ++p;
750 const char *var_name_begin = p;
751 const char *var_name_end = ::strchr (p, '}');
752
753 if (var_name_end && var_name_begin < var_name_end)
754 {
755 // if we have already failed to parse, skip this variable
756 if (success)
757 {
758 const char *cstr = NULL;
759 Address format_addr;
760 bool calculate_format_addr_function_offset = false;
761 // Set reg_kind and reg_num to invalid values
762 RegisterKind reg_kind = kNumRegisterKinds;
763 uint32_t reg_num = LLDB_INVALID_REGNUM;
764 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +0000765 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +0000766 RegisterContext *reg_ctx = NULL;
767
768 // Each variable must set success to true below...
769 bool var_success = false;
770 switch (var_name_begin[0])
771 {
772 case 'a':
773 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
774 {
775 if (addr && addr->IsValid())
776 {
777 var_success = true;
778 format_addr = *addr;
779 }
780 }
781 break;
782
783 case 'p':
784 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
785 {
786 if (exe_ctx && exe_ctx->process != NULL)
787 {
788 var_name_begin += ::strlen ("process.");
789 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
790 {
791 s.Printf("%i", exe_ctx->process->GetID());
792 var_success = true;
793 }
794 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
795 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
796 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
797 {
798 ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
799 if (exe_module_sp)
800 {
801 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
802 {
803 format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
804 var_success = format_file_spec;
805 }
806 else
807 {
808 format_file_spec = exe_module_sp->GetFileSpec();
809 var_success = format_file_spec;
810 }
811 }
812 }
813 }
814 }
815 break;
816
817 case 't':
818 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
819 {
820 if (exe_ctx && exe_ctx->thread)
821 {
822 var_name_begin += ::strlen ("thread.");
823 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
824 {
825 s.Printf("0x%4.4x", exe_ctx->thread->GetID());
826 var_success = true;
827 }
828 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
829 {
830 s.Printf("%u", exe_ctx->thread->GetIndexID());
831 var_success = true;
832 }
833 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
834 {
835 cstr = exe_ctx->thread->GetName();
836 var_success = cstr && cstr[0];
837 if (var_success)
838 s.PutCString(cstr);
839 }
840 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
841 {
842 cstr = exe_ctx->thread->GetQueueName();
843 var_success = cstr && cstr[0];
844 if (var_success)
845 s.PutCString(cstr);
846 }
847 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
848 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000849 StopInfoSP stop_info_sp = exe_ctx->thread->GetStopInfo ();
850 if (stop_info_sp)
Greg Clayton1b654882010-09-19 02:33:57 +0000851 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000852 cstr = stop_info_sp->GetDescription();
Greg Clayton1b654882010-09-19 02:33:57 +0000853 if (cstr && cstr[0])
854 {
855 s.PutCString(cstr);
856 var_success = true;
857 }
858 }
859 }
860 }
861 }
862 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
863 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000864 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
865 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +0000866 {
Greg Clayton1b654882010-09-19 02:33:57 +0000867 var_name_begin += ::strlen ("target.");
868 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
869 {
870 ArchSpec arch (target->GetArchitecture ());
871 if (arch.IsValid())
872 {
Greg Clayton64195a22011-02-23 00:35:02 +0000873 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +0000874 var_success = true;
875 }
876 }
877 }
878 }
879 break;
880
881
882 case 'm':
883 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
884 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000885 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +0000886 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000887 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +0000888 var_name_begin += ::strlen ("module.");
889
890 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
891 {
892 if (module->GetFileSpec())
893 {
894 var_name_begin += ::strlen ("file.");
895
896 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
897 {
898 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
899 var_success = format_file_spec;
900 }
901 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
902 {
903 format_file_spec = module->GetFileSpec();
904 var_success = format_file_spec;
905 }
906 }
907 }
908 }
909 }
910 break;
911
912
913 case 'f':
914 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
915 {
916 if (sc && sc->comp_unit != NULL)
917 {
918 var_name_begin += ::strlen ("file.");
919
920 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
921 {
922 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
923 var_success = format_file_spec;
924 }
925 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
926 {
927 format_file_spec = *sc->comp_unit;
928 var_success = format_file_spec;
929 }
930 }
931 }
932 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
933 {
934 if (exe_ctx && exe_ctx->frame)
935 {
936 var_name_begin += ::strlen ("frame.");
937 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
938 {
939 s.Printf("%u", exe_ctx->frame->GetFrameIndex());
940 var_success = true;
941 }
942 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
943 {
944 reg_kind = eRegisterKindGeneric;
945 reg_num = LLDB_REGNUM_GENERIC_PC;
946 var_success = true;
947 }
948 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
949 {
950 reg_kind = eRegisterKindGeneric;
951 reg_num = LLDB_REGNUM_GENERIC_SP;
952 var_success = true;
953 }
954 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
955 {
956 reg_kind = eRegisterKindGeneric;
957 reg_num = LLDB_REGNUM_GENERIC_FP;
958 var_success = true;
959 }
960 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
961 {
962 reg_kind = eRegisterKindGeneric;
963 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
964 var_success = true;
965 }
966 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
967 {
Greg Clayton5ccbd292011-01-06 22:15:06 +0000968 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +0000969 if (reg_ctx)
970 {
971 var_name_begin += ::strlen ("reg.");
972 if (var_name_begin < var_name_end)
973 {
974 std::string reg_name (var_name_begin, var_name_end);
975 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
976 if (reg_info)
977 var_success = true;
978 }
979 }
980 }
981 }
982 }
983 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
984 {
985 if (sc && (sc->function != NULL || sc->symbol != NULL))
986 {
987 var_name_begin += ::strlen ("function.");
988 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
989 {
990 if (sc->function)
991 s.Printf("function{0x%8.8x}", sc->function->GetID());
992 else
993 s.Printf("symbol[%u]", sc->symbol->GetID());
994
995 var_success = true;
996 }
997 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
998 {
999 if (sc->function)
1000 cstr = sc->function->GetName().AsCString (NULL);
1001 else if (sc->symbol)
1002 cstr = sc->symbol->GetName().AsCString (NULL);
1003 if (cstr)
1004 {
1005 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001006
1007 if (sc->block)
1008 {
1009 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1010 if (inline_block)
1011 {
1012 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1013 if (inline_info)
1014 {
1015 s.PutCString(" [inlined] ");
1016 inline_info->GetName().Dump(&s);
1017 }
1018 }
1019 }
Greg Clayton1b654882010-09-19 02:33:57 +00001020 var_success = true;
1021 }
1022 }
1023 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1024 {
1025 var_success = addr != NULL;
1026 if (var_success)
1027 {
1028 format_addr = *addr;
1029 calculate_format_addr_function_offset = true;
1030 }
1031 }
1032 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1033 {
1034 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1035 if (var_success)
1036 {
1037 format_addr = sc->line_entry.range.GetBaseAddress();
1038 calculate_format_addr_function_offset = true;
1039 }
1040 }
1041 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1042 {
1043 var_success = exe_ctx->frame;
1044 if (var_success)
1045 {
1046 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1047 calculate_format_addr_function_offset = true;
1048 }
1049 }
1050 }
1051 }
1052 break;
1053
1054 case 'l':
1055 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1056 {
1057 if (sc && sc->line_entry.IsValid())
1058 {
1059 var_name_begin += ::strlen ("line.");
1060 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1061 {
1062 var_name_begin += ::strlen ("file.");
1063
1064 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1065 {
1066 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1067 var_success = format_file_spec;
1068 }
1069 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1070 {
1071 format_file_spec = sc->line_entry.file;
1072 var_success = format_file_spec;
1073 }
1074 }
1075 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1076 {
1077 var_success = true;
1078 s.Printf("%u", sc->line_entry.line);
1079 }
1080 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1081 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1082 {
1083 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1084 if (var_success)
1085 {
1086 format_addr = sc->line_entry.range.GetBaseAddress();
1087 if (var_name_begin[0] == 'e')
1088 format_addr.Slide (sc->line_entry.range.GetByteSize());
1089 }
1090 }
1091 }
1092 }
1093 break;
1094 }
1095
1096 if (var_success)
1097 {
1098 // If format addr is valid, then we need to print an address
1099 if (reg_num != LLDB_INVALID_REGNUM)
1100 {
1101 // We have a register value to display...
1102 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1103 {
1104 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1105 }
1106 else
1107 {
1108 if (reg_ctx == NULL)
Greg Clayton5ccbd292011-01-06 22:15:06 +00001109 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001110
1111 if (reg_ctx)
1112 {
1113 if (reg_kind != kNumRegisterKinds)
1114 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1115 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1116 var_success = reg_info != NULL;
1117 }
1118 }
1119 }
1120
1121 if (reg_info != NULL)
1122 {
1123 DataExtractor reg_data;
1124 var_success = reg_ctx->ReadRegisterBytes (reg_info->kinds[eRegisterKindLLDB], reg_data);
1125 {
1126 reg_data.Dump(&s, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
1127 }
1128 }
1129
1130 if (format_file_spec)
1131 {
1132 s << format_file_spec;
1133 }
1134
1135 // If format addr is valid, then we need to print an address
1136 if (format_addr.IsValid())
1137 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001138 var_success = false;
1139
Greg Clayton1b654882010-09-19 02:33:57 +00001140 if (calculate_format_addr_function_offset)
1141 {
1142 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001143
Greg Clayton0603aa92010-10-04 01:05:56 +00001144 if (sc)
1145 {
1146 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001147 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001148 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001149 if (sc->block)
1150 {
1151 // Check to make sure we aren't in an inline
1152 // function. If we are, use the inline block
1153 // range that contains "format_addr" since
1154 // blocks can be discontiguous.
1155 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1156 AddressRange inline_range;
1157 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1158 func_addr = inline_range.GetBaseAddress();
1159 }
1160 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001161 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1162 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1163 }
1164
1165 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001166 {
1167 if (func_addr.GetSection() == format_addr.GetSection())
1168 {
1169 addr_t func_file_addr = func_addr.GetFileAddress();
1170 addr_t addr_file_addr = format_addr.GetFileAddress();
1171 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001172 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001173 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001174 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001175 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001176 }
1177 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001178 {
1179 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1180 if (target)
1181 {
1182 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1183 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1184 if (addr_load_addr > func_load_addr)
1185 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1186 else if (addr_load_addr < func_load_addr)
1187 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1188 var_success = true;
1189 }
1190 }
Greg Clayton1b654882010-09-19 02:33:57 +00001191 }
1192 }
1193 else
1194 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001195 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001196 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001197 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1198 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001199 if (vaddr == LLDB_INVALID_ADDRESS)
1200 vaddr = format_addr.GetFileAddress ();
1201
1202 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001203 {
Greg Clayton514487e2011-02-15 21:59:32 +00001204 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001205 if (addr_width == 0)
1206 addr_width = 16;
1207 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001208 var_success = true;
1209 }
Greg Clayton1b654882010-09-19 02:33:57 +00001210 }
1211 }
1212 }
1213
1214 if (var_success == false)
1215 success = false;
1216 }
1217 p = var_name_end;
1218 }
1219 else
1220 break;
1221 }
1222 else
1223 {
1224 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1225 s.PutChar(*p);
1226 }
1227 }
1228 else if (*p == '\\')
1229 {
1230 ++p; // skip the slash
1231 switch (*p)
1232 {
1233 case 'a': s.PutChar ('\a'); break;
1234 case 'b': s.PutChar ('\b'); break;
1235 case 'f': s.PutChar ('\f'); break;
1236 case 'n': s.PutChar ('\n'); break;
1237 case 'r': s.PutChar ('\r'); break;
1238 case 't': s.PutChar ('\t'); break;
1239 case 'v': s.PutChar ('\v'); break;
1240 case '\'': s.PutChar ('\''); break;
1241 case '\\': s.PutChar ('\\'); break;
1242 case '0':
1243 // 1 to 3 octal chars
1244 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001245 // Make a string that can hold onto the initial zero char,
1246 // up to 3 octal digits, and a terminating NULL.
1247 char oct_str[5] = { 0, 0, 0, 0, 0 };
1248
1249 int i;
1250 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1251 oct_str[i] = p[i];
1252
1253 // We don't want to consume the last octal character since
1254 // the main for loop will do this for us, so we advance p by
1255 // one less than i (even if i is zero)
1256 p += i - 1;
1257 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
1258 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001259 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001260 char octal_char = octal_value;
1261 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00001262 }
Greg Clayton1b654882010-09-19 02:33:57 +00001263 }
1264 break;
1265
1266 case 'x':
1267 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00001268 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001269 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001270 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00001271
Greg Clayton0603aa92010-10-04 01:05:56 +00001272 // Make a string that can hold onto two hex chars plus a
1273 // NULL terminator
1274 char hex_str[3] = { 0,0,0 };
1275 hex_str[0] = *p;
1276 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001277 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001278 ++p; // Skip the first of the two hex chars
1279 hex_str[1] = *p;
1280 }
1281
1282 unsigned long hex_value = strtoul (hex_str, NULL, 16);
1283 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001284 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00001285 }
1286 else
1287 {
1288 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00001289 }
1290 break;
1291
1292 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00001293 // Just desensitize any other character by just printing what
1294 // came after the '\'
1295 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00001296 break;
1297
1298 }
1299
1300 }
1301 }
1302 if (end)
1303 *end = p;
1304 return success;
1305}
1306
1307#pragma mark Debugger::SettingsController
1308
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001309//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001310// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001311//--------------------------------------------------
1312
Greg Clayton1b654882010-09-19 02:33:57 +00001313Debugger::SettingsController::SettingsController () :
Caroline Tice101c7c22010-09-09 06:25:08 +00001314 UserSettingsController ("", lldb::UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001315{
Caroline Tice91123da2010-09-08 17:48:55 +00001316 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
1317 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001318}
1319
Greg Clayton1b654882010-09-19 02:33:57 +00001320Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001321{
1322}
1323
1324
1325lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00001326Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001327{
Greg Claytondbe54502010-11-19 03:46:01 +00001328 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00001329 false, instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001330 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1331 return new_settings_sp;
1332}
1333
Greg Clayton1b654882010-09-19 02:33:57 +00001334#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001335//--------------------------------------------------
1336// class DebuggerInstanceSettings
1337//--------------------------------------------------
1338
Greg Claytona7015092010-09-18 01:14:36 +00001339DebuggerInstanceSettings::DebuggerInstanceSettings
1340(
1341 UserSettingsController &owner,
1342 bool live_instance,
1343 const char *name
1344) :
Greg Clayton85851dd2010-12-04 00:10:17 +00001345 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00001346 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001347 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00001348 m_frame_format (),
1349 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001350 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001351 m_use_external_editor (false),
1352 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001353{
Caroline Ticef20e8232010-09-09 18:26:37 +00001354 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1355 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
1356 // 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 +00001357 // The same is true of CreateInstanceName().
1358
1359 if (GetInstanceName() == InstanceSettings::InvalidName())
1360 {
1361 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1362 m_owner.RegisterInstanceSettings (this);
1363 }
Caroline Ticef20e8232010-09-09 18:26:37 +00001364
1365 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001366 {
1367 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1368 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001369 }
1370}
1371
1372DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00001373 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001374 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00001375 m_frame_format (rhs.m_frame_format),
1376 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001377 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001378 m_use_external_editor (rhs.m_use_external_editor),
1379 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001380{
1381 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1382 CopyInstanceSettings (pending_settings, false);
1383 m_owner.RemovePendingSettings (m_instance_name);
1384}
1385
1386DebuggerInstanceSettings::~DebuggerInstanceSettings ()
1387{
1388}
1389
1390DebuggerInstanceSettings&
1391DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
1392{
1393 if (this != &rhs)
1394 {
Greg Clayton1b654882010-09-19 02:33:57 +00001395 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001396 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00001397 m_frame_format = rhs.m_frame_format;
1398 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001399 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001400 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001401 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001402 }
1403
1404 return *this;
1405}
1406
Greg Clayton1b654882010-09-19 02:33:57 +00001407bool
1408DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
1409{
1410 bool valid = false;
1411
1412 // Verify we have a value string.
1413 if (value == NULL || value[0] == '\0')
1414 {
1415 err.SetErrorString ("Missing value. Can't set terminal width without a value.\n");
1416 }
1417 else
1418 {
1419 char *end = NULL;
1420 const uint32_t width = ::strtoul (value, &end, 0);
1421
Johnny Chenea9fc182010-09-20 16:36:43 +00001422 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00001423 {
Johnny Chen433d7742010-09-20 17:04:41 +00001424 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00001425 valid = true;
1426 else
1427 err.SetErrorString ("Invalid term-width value; value must be between 10 and 1024.\n");
1428 }
1429 else
1430 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string.\n", value);
1431 }
1432
1433 return valid;
1434}
1435
1436
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001437void
1438DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1439 const char *index_value,
1440 const char *value,
1441 const ConstString &instance_name,
1442 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00001443 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001444 Error &err,
1445 bool pending)
1446{
Greg Clayton0603aa92010-10-04 01:05:56 +00001447
1448 if (var_name == TermWidthVarName())
1449 {
1450 if (ValidTermWidthValue (value, err))
1451 {
1452 m_term_width = ::strtoul (value, NULL, 0);
1453 }
1454 }
1455 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001456 {
Caroline Tice101c7c22010-09-09 06:25:08 +00001457 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001458 if (!pending)
1459 {
Caroline Tice49e27372010-09-07 18:35:40 +00001460 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1461 // strip off the brackets before passing it to BroadcastPromptChange.
1462
1463 std::string tmp_instance_name (instance_name.AsCString());
1464 if ((tmp_instance_name[0] == '[')
1465 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
1466 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
1467 ConstString new_name (tmp_instance_name.c_str());
1468
1469 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001470 }
1471 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001472 else if (var_name == GetFrameFormatName())
1473 {
1474 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
1475 }
1476 else if (var_name == GetThreadFormatName())
1477 {
1478 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
1479 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001480 else if (var_name == ScriptLangVarName())
1481 {
1482 bool success;
1483 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
1484 &success);
1485 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001486 else if (var_name == UseExternalEditorVarName ())
1487 {
1488 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, err);
1489 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001490 else if (var_name == AutoConfirmName ())
1491 {
1492 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, err);
1493 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001494}
1495
Caroline Tice12cecd72010-09-20 21:37:42 +00001496bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001497DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1498 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00001499 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00001500 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001501{
1502 if (var_name == PromptVarName())
1503 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001504 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001505
1506 }
1507 else if (var_name == ScriptLangVarName())
1508 {
1509 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
1510 }
Caroline Tice101c7c22010-09-09 06:25:08 +00001511 else if (var_name == TermWidthVarName())
1512 {
1513 StreamString width_str;
1514 width_str.Printf ("%d", m_term_width);
1515 value.AppendString (width_str.GetData());
1516 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001517 else if (var_name == GetFrameFormatName ())
1518 {
1519 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
1520 }
1521 else if (var_name == GetThreadFormatName ())
1522 {
1523 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
1524 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001525 else if (var_name == UseExternalEditorVarName())
1526 {
1527 if (m_use_external_editor)
1528 value.AppendString ("true");
1529 else
1530 value.AppendString ("false");
1531 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001532 else if (var_name == AutoConfirmName())
1533 {
1534 if (m_auto_confirm_on)
1535 value.AppendString ("true");
1536 else
1537 value.AppendString ("false");
1538 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001539 else
Caroline Tice12cecd72010-09-20 21:37:42 +00001540 {
1541 if (err)
1542 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1543 return false;
1544 }
1545 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001546}
1547
1548void
1549DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1550 bool pending)
1551{
1552 if (new_settings.get() == NULL)
1553 return;
1554
1555 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
1556
1557 m_prompt = new_debugger_settings->m_prompt;
1558 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00001559 {
1560 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1561 // strip off the brackets before passing it to BroadcastPromptChange.
1562
1563 std::string tmp_instance_name (m_instance_name.AsCString());
1564 if ((tmp_instance_name[0] == '[')
1565 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
1566 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
1567 ConstString new_name (tmp_instance_name.c_str());
1568
1569 BroadcastPromptChange (new_name, m_prompt.c_str());
1570 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001571 m_frame_format = new_debugger_settings->m_frame_format;
1572 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001573 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001574 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001575 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001576 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001577}
1578
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001579
1580bool
1581DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
1582{
1583 std::string tmp_prompt;
1584
1585 if (new_prompt != NULL)
1586 {
1587 tmp_prompt = new_prompt ;
1588 int len = tmp_prompt.size();
1589 if (len > 1
1590 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
1591 && (tmp_prompt[len-1] == tmp_prompt[0]))
1592 {
1593 tmp_prompt = tmp_prompt.substr(1,len-2);
1594 }
1595 len = tmp_prompt.size();
1596 if (tmp_prompt[len-1] != ' ')
1597 tmp_prompt.append(" ");
1598 }
1599 EventSP new_event_sp;
1600 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
1601 new EventDataBytes (tmp_prompt.c_str())));
1602
1603 if (instance_name.GetLength() != 0)
1604 {
1605 // Set prompt for a particular instance.
1606 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
1607 if (dbg != NULL)
1608 {
1609 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
1610 }
1611 }
1612
1613 return true;
1614}
1615
1616const ConstString
1617DebuggerInstanceSettings::CreateInstanceName ()
1618{
1619 static int instance_count = 1;
1620 StreamString sstr;
1621
1622 sstr.Printf ("debugger_%d", instance_count);
1623 ++instance_count;
1624
1625 const ConstString ret_val (sstr.GetData());
1626
1627 return ret_val;
1628}
1629
1630const ConstString &
1631DebuggerInstanceSettings::PromptVarName ()
1632{
1633 static ConstString prompt_var_name ("prompt");
1634
1635 return prompt_var_name;
1636}
1637
1638const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00001639DebuggerInstanceSettings::GetFrameFormatName ()
1640{
1641 static ConstString prompt_var_name ("frame-format");
1642
1643 return prompt_var_name;
1644}
1645
1646const ConstString &
1647DebuggerInstanceSettings::GetThreadFormatName ()
1648{
1649 static ConstString prompt_var_name ("thread-format");
1650
1651 return prompt_var_name;
1652}
1653
1654const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001655DebuggerInstanceSettings::ScriptLangVarName ()
1656{
1657 static ConstString script_lang_var_name ("script-lang");
1658
1659 return script_lang_var_name;
1660}
1661
Caroline Tice101c7c22010-09-09 06:25:08 +00001662const ConstString &
1663DebuggerInstanceSettings::TermWidthVarName ()
1664{
1665 static ConstString term_width_var_name ("term-width");
1666
1667 return term_width_var_name;
1668}
1669
Caroline Ticedaccaa92010-09-20 20:44:43 +00001670const ConstString &
1671DebuggerInstanceSettings::UseExternalEditorVarName ()
1672{
1673 static ConstString use_external_editor_var_name ("use-external-editor");
1674
1675 return use_external_editor_var_name;
1676}
1677
Jim Ingham3bcdb292010-10-04 22:44:14 +00001678const ConstString &
1679DebuggerInstanceSettings::AutoConfirmName ()
1680{
1681 static ConstString use_external_editor_var_name ("auto-confirm");
1682
1683 return use_external_editor_var_name;
1684}
1685
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001686//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001687// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001688//--------------------------------------------------
1689
1690
1691SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001692Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001693{
1694 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00001695 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
1696 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001697 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1698};
1699
Greg Claytonbb562b12010-10-04 02:44:26 +00001700#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00001701#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001702
Greg Clayton0603aa92010-10-04 01:05:56 +00001703#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1704 "{, ${frame.pc}}"\
1705 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00001706 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00001707 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00001708 "\\n"
1709
Greg Clayton315d2ca2010-11-02 01:53:21 +00001710//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1711// "{, ${frame.pc}}"\
1712// MODULE_WITH_FUNC\
1713// FILE_AND_LINE\
1714// "{, stop reason = ${thread.stop-reason}}"\
1715// "{, name = ${thread.name}}"\
1716// "{, queue = ${thread.queue}}"\
1717// "\\n"
1718
Greg Clayton0603aa92010-10-04 01:05:56 +00001719#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
1720 MODULE_WITH_FUNC\
1721 FILE_AND_LINE\
1722 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001723
1724SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001725Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001726{
Greg Clayton0603aa92010-10-04 01:05:56 +00001727// NAME Setting variable type Default Enum Init'd Hidden Help
1728// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00001729{ "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 +00001730{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00001731{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
1732{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001733{ "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 +00001734{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
1735{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001736{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001737};