blob: 28f589f6f25170f33e866c8d5983fd347131b9e4 [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 Clayton99d0faf2010-11-18 23:32:35 +000074 UserSettingsControllerSP &usc = GetSettingsController();
75 usc.reset (new SettingsController);
76 UserSettingsController::InitializeSettingsController (usc,
77 SettingsController::global_settings_table,
78 SettingsController::instance_settings_table);
Greg Claytondbe54502010-11-19 03:46:01 +000079 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +000080 }
Greg Clayton66111032010-06-23 01:19:29 +000081 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +000082
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083}
84
85void
86Debugger::Terminate ()
87{
Greg Clayton66111032010-06-23 01:19:29 +000088 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089 {
Greg Clayton66111032010-06-23 01:19:29 +000090 g_shared_debugger_refcount--;
91 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092 {
Greg Claytondbe54502010-11-19 03:46:01 +000093 lldb_private::WillTerminate();
94 lldb_private::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +000095 UserSettingsControllerSP &usc = GetSettingsController();
96 UserSettingsController::FinalizeSettingsController (usc);
97 usc.reset();
Caroline Tice6760a512011-01-17 21:55:19 +000098
99 // Clear our master list of debugger objects
100 Mutex::Locker locker (GetDebuggerListMutex ());
101 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103 }
104}
105
Greg Clayton66111032010-06-23 01:19:29 +0000106DebuggerSP
107Debugger::CreateInstance ()
108{
109 DebuggerSP debugger_sp (new Debugger);
110 // Scope for locker
111 {
112 Mutex::Locker locker (GetDebuggerListMutex ());
113 GetDebuggerList().push_back(debugger_sp);
114 }
115 return debugger_sp;
116}
117
Caroline Ticee02657b2011-01-22 01:02:07 +0000118void
119Debugger::Destroy (lldb::DebuggerSP &debugger_sp)
120{
121 if (debugger_sp.get() == NULL)
122 return;
123
124 Mutex::Locker locker (GetDebuggerListMutex ());
125 DebuggerList &debugger_list = GetDebuggerList ();
126 DebuggerList::iterator pos, end = debugger_list.end();
127 for (pos = debugger_list.begin (); pos != end; ++pos)
128 {
129 if ((*pos).get() == debugger_sp.get())
130 {
131 debugger_list.erase (pos);
132 return;
133 }
134 }
135
136}
137
Greg Clayton66111032010-06-23 01:19:29 +0000138lldb::DebuggerSP
139Debugger::GetSP ()
140{
141 lldb::DebuggerSP debugger_sp;
142
143 Mutex::Locker locker (GetDebuggerListMutex ());
144 DebuggerList &debugger_list = GetDebuggerList();
145 DebuggerList::iterator pos, end = debugger_list.end();
146 for (pos = debugger_list.begin(); pos != end; ++pos)
147 {
148 if ((*pos).get() == this)
149 {
150 debugger_sp = *pos;
151 break;
152 }
153 }
154 return debugger_sp;
155}
156
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000157lldb::DebuggerSP
158Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
159{
160 lldb::DebuggerSP debugger_sp;
161
162 Mutex::Locker locker (GetDebuggerListMutex ());
163 DebuggerList &debugger_list = GetDebuggerList();
164 DebuggerList::iterator pos, end = debugger_list.end();
165
166 for (pos = debugger_list.begin(); pos != end; ++pos)
167 {
168 if ((*pos).get()->m_instance_name == instance_name)
169 {
170 debugger_sp = *pos;
171 break;
172 }
173 }
174 return debugger_sp;
175}
Greg Clayton66111032010-06-23 01:19:29 +0000176
177TargetSP
178Debugger::FindTargetWithProcessID (lldb::pid_t pid)
179{
180 lldb::TargetSP target_sp;
181 Mutex::Locker locker (GetDebuggerListMutex ());
182 DebuggerList &debugger_list = GetDebuggerList();
183 DebuggerList::iterator pos, end = debugger_list.end();
184 for (pos = debugger_list.begin(); pos != end; ++pos)
185 {
186 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
187 if (target_sp)
188 break;
189 }
190 return target_sp;
191}
192
193
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000195 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000196 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000197 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 m_input_file (),
199 m_output_file (),
200 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201 m_target_list (),
202 m_listener ("lldb.Debugger"),
203 m_source_manager (),
Greg Clayton66111032010-06-23 01:19:29 +0000204 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
205 m_exe_ctx (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 m_input_readers (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000207 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208{
Greg Claytond46c87a2010-12-04 02:39:47 +0000209 m_input_comm.SetCloseOnEOF(false);
Greg Clayton66111032010-06-23 01:19:29 +0000210 m_command_interpreter_ap->Initialize ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211}
212
213Debugger::~Debugger ()
214{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000215 CleanUpInputReaders();
Greg Clayton66111032010-06-23 01:19:29 +0000216 int num_targets = m_target_list.GetNumTargets();
217 for (int i = 0; i < num_targets; i++)
218 {
219 ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
220 if (process_sp)
221 process_sp->Destroy();
222 }
223 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224}
225
226
227bool
228Debugger::GetAsyncExecution ()
229{
Greg Clayton66111032010-06-23 01:19:29 +0000230 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231}
232
233void
234Debugger::SetAsyncExecution (bool async_execution)
235{
Greg Clayton66111032010-06-23 01:19:29 +0000236 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237}
238
239void
240Debugger::DisconnectInput()
241{
242 m_input_comm.Clear ();
243}
244
245void
246Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
247{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000248 File &in_file = GetInputFile();
249 in_file.SetStream (fh, tranfer_ownership);
250 if (in_file.IsValid() == false)
251 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252
253 // Disconnect from any old connection if we had one
254 m_input_comm.Disconnect ();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000255 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), true));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
257
258 Error error;
259 if (m_input_comm.StartReadThread (&error) == false)
260 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000261 File &err_file = GetErrorFile();
262
263 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
264 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266}
267
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268void
269Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
270{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000271 File &out_file = GetOutputFile();
272 out_file.SetStream (fh, tranfer_ownership);
273 if (out_file.IsValid() == false)
274 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000275
276 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000277}
278
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279void
280Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
281{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000282 File &err_file = GetErrorFile();
283 err_file.SetStream (fh, tranfer_ownership);
284 if (err_file.IsValid() == false)
285 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286}
287
288CommandInterpreter &
289Debugger::GetCommandInterpreter ()
290{
Greg Clayton66111032010-06-23 01:19:29 +0000291 assert (m_command_interpreter_ap.get());
292 return *m_command_interpreter_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293}
294
295Listener &
296Debugger::GetListener ()
297{
298 return m_listener;
299}
300
301
302TargetSP
Jim Ingham2976d002010-08-26 21:32:51 +0000303Debugger::GetSelectedTarget ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000304{
Jim Ingham2976d002010-08-26 21:32:51 +0000305 return m_target_list.GetSelectedTarget ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306}
307
308ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000309Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310{
311 ExecutionContext exe_ctx;
312 exe_ctx.Clear();
313
Jim Ingham2976d002010-08-26 21:32:51 +0000314 lldb::TargetSP target_sp = GetSelectedTarget();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315 exe_ctx.target = target_sp.get();
316
317 if (target_sp)
318 {
319 exe_ctx.process = target_sp->GetProcessSP().get();
320 if (exe_ctx.process && exe_ctx.process->IsRunning() == false)
321 {
Jim Ingham2976d002010-08-26 21:32:51 +0000322 exe_ctx.thread = exe_ctx.process->GetThreadList().GetSelectedThread().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323 if (exe_ctx.thread == NULL)
324 exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
325 if (exe_ctx.thread)
326 {
Jim Ingham2976d002010-08-26 21:32:51 +0000327 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328 if (exe_ctx.frame == NULL)
329 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex (0).get();
330 }
331 }
332 }
333 return exe_ctx;
334
335}
336
337SourceManager &
338Debugger::GetSourceManager ()
339{
340 return m_source_manager;
341}
342
343
344TargetList&
345Debugger::GetTargetList ()
346{
347 return m_target_list;
348}
349
Caroline Ticeb44880c2011-02-10 01:15:13 +0000350InputReaderSP
351Debugger::GetCurrentInputReader ()
352{
353 InputReaderSP reader_sp;
354
355 if (!m_input_readers.empty())
356 {
357 // Clear any finished readers from the stack
358 while (CheckIfTopInputReaderIsDone()) ;
359
360 if (!m_input_readers.empty())
361 reader_sp = m_input_readers.top();
362 }
363
364 return reader_sp;
365}
366
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000367void
368Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
369{
Caroline Ticeefed6132010-11-19 20:47:54 +0000370 if (bytes_len > 0)
371 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
372 else
373 ((Debugger *)baton)->DispatchInputEndOfFile ();
374}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375
376
377void
378Debugger::DispatchInput (const char *bytes, size_t bytes_len)
379{
Caroline Ticeefed6132010-11-19 20:47:54 +0000380 if (bytes == NULL || bytes_len == 0)
381 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382
383 WriteToDefaultReader (bytes, bytes_len);
384}
385
386void
Caroline Ticeefed6132010-11-19 20:47:54 +0000387Debugger::DispatchInputInterrupt ()
388{
389 m_input_reader_data.clear();
390
Caroline Ticeb44880c2011-02-10 01:15:13 +0000391 InputReaderSP reader_sp (GetCurrentInputReader ());
392 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000393 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000394 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000395
Caroline Ticeb44880c2011-02-10 01:15:13 +0000396 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000397 while (CheckIfTopInputReaderIsDone ()) ;
398 }
399}
400
401void
402Debugger::DispatchInputEndOfFile ()
403{
404 m_input_reader_data.clear();
405
Caroline Ticeb44880c2011-02-10 01:15:13 +0000406 InputReaderSP reader_sp (GetCurrentInputReader ());
407 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000408 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000409 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000410
Caroline Ticeb44880c2011-02-10 01:15:13 +0000411 // 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 +0000412 while (CheckIfTopInputReaderIsDone ()) ;
413 }
414}
415
416void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000417Debugger::CleanUpInputReaders ()
418{
419 m_input_reader_data.clear();
420
Caroline Ticeb44880c2011-02-10 01:15:13 +0000421 // 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 +0000422 while (m_input_readers.size() > 1)
423 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000424 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000425 if (reader_sp)
426 {
427 reader_sp->Notify (eInputReaderEndOfFile);
428 reader_sp->SetIsDone (true);
429 }
430 }
431}
432
433void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
435{
436 if (bytes && bytes_len)
437 m_input_reader_data.append (bytes, bytes_len);
438
439 if (m_input_reader_data.empty())
440 return;
441
442 while (!m_input_readers.empty() && !m_input_reader_data.empty())
443 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000445 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 if (!reader_sp)
447 break;
448
Greg Clayton471b31c2010-07-20 22:52:08 +0000449 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 m_input_reader_data.size());
451 if (bytes_handled)
452 {
453 m_input_reader_data.erase (0, bytes_handled);
454 }
455 else
456 {
457 // No bytes were handled, we might not have reached our
458 // granularity, just return and wait for more data
459 break;
460 }
461 }
462
Caroline Ticeb44880c2011-02-10 01:15:13 +0000463 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 while (CheckIfTopInputReaderIsDone ())
465 /* Do nothing. */;
466
467}
468
469void
470Debugger::PushInputReader (const InputReaderSP& reader_sp)
471{
472 if (!reader_sp)
473 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000474
475 // Deactivate the old top reader
476 InputReaderSP top_reader_sp (GetCurrentInputReader ());
477
478 if (top_reader_sp)
479 top_reader_sp->Notify (eInputReaderDeactivate);
480
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481 m_input_readers.push (reader_sp);
482 reader_sp->Notify (eInputReaderActivate);
483 ActivateInputReader (reader_sp);
484}
485
486bool
487Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp)
488{
489 bool result = false;
490
491 // The reader on the stop of the stack is done, so let the next
492 // read on the stack referesh its prompt and if there is one...
493 if (!m_input_readers.empty())
494 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000495 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496 InputReaderSP reader_sp(m_input_readers.top());
497
498 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
499 {
500 m_input_readers.pop ();
501 reader_sp->Notify (eInputReaderDeactivate);
502 reader_sp->Notify (eInputReaderDone);
503 result = true;
504
505 if (!m_input_readers.empty())
506 {
507 reader_sp = m_input_readers.top();
508 if (reader_sp)
509 {
510 ActivateInputReader (reader_sp);
511 reader_sp->Notify (eInputReaderReactivate);
512 }
513 }
514 }
515 }
516 return result;
517}
518
519bool
520Debugger::CheckIfTopInputReaderIsDone ()
521{
522 bool result = false;
523 if (!m_input_readers.empty())
524 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000525 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526 InputReaderSP reader_sp(m_input_readers.top());
527
528 if (reader_sp && reader_sp->IsDone())
529 {
530 result = true;
531 PopInputReader (reader_sp);
532 }
533 }
534 return result;
535}
536
537void
538Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
539{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000540 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000542 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000543 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000544 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000545
546 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547
Greg Claytona3406612011-02-07 23:24:47 +0000548 switch (reader_sp->GetGranularity())
549 {
550 case eInputReaderGranularityByte:
551 case eInputReaderGranularityWord:
552 tty.SetCanonical (false);
553 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554
Greg Claytona3406612011-02-07 23:24:47 +0000555 case eInputReaderGranularityLine:
556 case eInputReaderGranularityAll:
557 tty.SetCanonical (true);
558 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559
Greg Claytona3406612011-02-07 23:24:47 +0000560 default:
561 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562 }
563 }
564}
Greg Clayton66111032010-06-23 01:19:29 +0000565
566void
567Debugger::UpdateExecutionContext (ExecutionContext *override_context)
568{
569 m_exe_ctx.Clear();
570
571 if (override_context != NULL)
572 {
573 m_exe_ctx.target = override_context->target;
574 m_exe_ctx.process = override_context->process;
575 m_exe_ctx.thread = override_context->thread;
576 m_exe_ctx.frame = override_context->frame;
577 }
578 else
579 {
Jim Ingham2976d002010-08-26 21:32:51 +0000580 TargetSP target_sp (GetSelectedTarget());
Greg Clayton66111032010-06-23 01:19:29 +0000581 if (target_sp)
582 {
583 m_exe_ctx.target = target_sp.get();
584 m_exe_ctx.process = target_sp->GetProcessSP().get();
Johnny Chen725945d2010-09-03 22:35:47 +0000585 if (m_exe_ctx.process && m_exe_ctx.process->IsAlive() && !m_exe_ctx.process->IsRunning())
Greg Clayton66111032010-06-23 01:19:29 +0000586 {
Jim Ingham2976d002010-08-26 21:32:51 +0000587 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetSelectedThread().get();
Greg Clayton66111032010-06-23 01:19:29 +0000588 if (m_exe_ctx.thread == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000589 {
Greg Clayton66111032010-06-23 01:19:29 +0000590 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000591 // If we didn't have a selected thread, select one here.
592 if (m_exe_ctx.thread != NULL)
Johnny Chenc13ee522010-09-14 00:53:53 +0000593 m_exe_ctx.process->GetThreadList().SetSelectedThreadByID(m_exe_ctx.thread->GetID());
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000594 }
Greg Clayton66111032010-06-23 01:19:29 +0000595 if (m_exe_ctx.thread)
596 {
Jim Ingham2976d002010-08-26 21:32:51 +0000597 m_exe_ctx.frame = m_exe_ctx.thread->GetSelectedFrame().get();
Greg Clayton66111032010-06-23 01:19:29 +0000598 if (m_exe_ctx.frame == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000599 {
Greg Clayton66111032010-06-23 01:19:29 +0000600 m_exe_ctx.frame = m_exe_ctx.thread->GetStackFrameAtIndex (0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000601 // If we didn't have a selected frame select one here.
602 if (m_exe_ctx.frame != NULL)
603 m_exe_ctx.thread->SetSelectedFrame(m_exe_ctx.frame);
604 }
Greg Clayton66111032010-06-23 01:19:29 +0000605 }
606 }
607 }
608 }
609}
610
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000611DebuggerSP
612Debugger::FindDebuggerWithID (lldb::user_id_t id)
613{
614 lldb::DebuggerSP debugger_sp;
615
616 Mutex::Locker locker (GetDebuggerListMutex ());
617 DebuggerList &debugger_list = GetDebuggerList();
618 DebuggerList::iterator pos, end = debugger_list.end();
619 for (pos = debugger_list.begin(); pos != end; ++pos)
620 {
621 if ((*pos).get()->GetID() == id)
622 {
623 debugger_sp = *pos;
624 break;
625 }
626 }
627 return debugger_sp;
628}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000629
Greg Clayton1b654882010-09-19 02:33:57 +0000630static void
631TestPromptFormats (StackFrame *frame)
632{
633 if (frame == NULL)
634 return;
635
636 StreamString s;
637 const char *prompt_format =
638 "{addr = '${addr}'\n}"
639 "{process.id = '${process.id}'\n}"
640 "{process.name = '${process.name}'\n}"
641 "{process.file.basename = '${process.file.basename}'\n}"
642 "{process.file.fullpath = '${process.file.fullpath}'\n}"
643 "{thread.id = '${thread.id}'\n}"
644 "{thread.index = '${thread.index}'\n}"
645 "{thread.name = '${thread.name}'\n}"
646 "{thread.queue = '${thread.queue}'\n}"
647 "{thread.stop-reason = '${thread.stop-reason}'\n}"
648 "{target.arch = '${target.arch}'\n}"
649 "{module.file.basename = '${module.file.basename}'\n}"
650 "{module.file.fullpath = '${module.file.fullpath}'\n}"
651 "{file.basename = '${file.basename}'\n}"
652 "{file.fullpath = '${file.fullpath}'\n}"
653 "{frame.index = '${frame.index}'\n}"
654 "{frame.pc = '${frame.pc}'\n}"
655 "{frame.sp = '${frame.sp}'\n}"
656 "{frame.fp = '${frame.fp}'\n}"
657 "{frame.flags = '${frame.flags}'\n}"
658 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
659 "{frame.reg.rip = '${frame.reg.rip}'\n}"
660 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
661 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
662 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
663 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
664 "{frame.reg.carp = '${frame.reg.carp}'\n}"
665 "{function.id = '${function.id}'\n}"
666 "{function.name = '${function.name}'\n}"
667 "{function.addr-offset = '${function.addr-offset}'\n}"
668 "{function.line-offset = '${function.line-offset}'\n}"
669 "{function.pc-offset = '${function.pc-offset}'\n}"
670 "{line.file.basename = '${line.file.basename}'\n}"
671 "{line.file.fullpath = '${line.file.fullpath}'\n}"
672 "{line.number = '${line.number}'\n}"
673 "{line.start-addr = '${line.start-addr}'\n}"
674 "{line.end-addr = '${line.end-addr}'\n}"
675;
676
677 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
678 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000679 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000680 const char *end = NULL;
681 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
682 {
683 printf("%s\n", s.GetData());
684 }
685 else
686 {
687 printf ("error: at '%s'\n", end);
688 printf ("what we got: %s\n", s.GetData());
689 }
690}
691
692bool
693Debugger::FormatPrompt
694(
695 const char *format,
696 const SymbolContext *sc,
697 const ExecutionContext *exe_ctx,
698 const Address *addr,
699 Stream &s,
700 const char **end
701)
702{
703 bool success = true;
704 const char *p;
705 for (p = format; *p != '\0'; ++p)
706 {
707 size_t non_special_chars = ::strcspn (p, "${}\\");
708 if (non_special_chars > 0)
709 {
710 if (success)
711 s.Write (p, non_special_chars);
712 p += non_special_chars;
713 }
714
715 if (*p == '\0')
716 {
717 break;
718 }
719 else if (*p == '{')
720 {
721 // Start a new scope that must have everything it needs if it is to
722 // to make it into the final output stream "s". If you want to make
723 // a format that only prints out the function or symbol name if there
724 // is one in the symbol context you can use:
725 // "{function =${function.name}}"
726 // The first '{' starts a new scope that end with the matching '}' at
727 // the end of the string. The contents "function =${function.name}"
728 // will then be evaluated and only be output if there is a function
729 // or symbol with a valid name.
730 StreamString sub_strm;
731
732 ++p; // Skip the '{'
733
734 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p))
735 {
736 // The stream had all it needed
737 s.Write(sub_strm.GetData(), sub_strm.GetSize());
738 }
739 if (*p != '}')
740 {
741 success = false;
742 break;
743 }
744 }
745 else if (*p == '}')
746 {
747 // End of a enclosing scope
748 break;
749 }
750 else if (*p == '$')
751 {
752 // We have a prompt variable to print
753 ++p;
754 if (*p == '{')
755 {
756 ++p;
757 const char *var_name_begin = p;
758 const char *var_name_end = ::strchr (p, '}');
759
760 if (var_name_end && var_name_begin < var_name_end)
761 {
762 // if we have already failed to parse, skip this variable
763 if (success)
764 {
765 const char *cstr = NULL;
766 Address format_addr;
767 bool calculate_format_addr_function_offset = false;
768 // Set reg_kind and reg_num to invalid values
769 RegisterKind reg_kind = kNumRegisterKinds;
770 uint32_t reg_num = LLDB_INVALID_REGNUM;
771 FileSpec format_file_spec;
772 const lldb::RegisterInfo *reg_info = NULL;
773 RegisterContext *reg_ctx = NULL;
774
775 // Each variable must set success to true below...
776 bool var_success = false;
777 switch (var_name_begin[0])
778 {
779 case 'a':
780 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
781 {
782 if (addr && addr->IsValid())
783 {
784 var_success = true;
785 format_addr = *addr;
786 }
787 }
788 break;
789
790 case 'p':
791 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
792 {
793 if (exe_ctx && exe_ctx->process != NULL)
794 {
795 var_name_begin += ::strlen ("process.");
796 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
797 {
798 s.Printf("%i", exe_ctx->process->GetID());
799 var_success = true;
800 }
801 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
802 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
803 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
804 {
805 ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
806 if (exe_module_sp)
807 {
808 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
809 {
810 format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
811 var_success = format_file_spec;
812 }
813 else
814 {
815 format_file_spec = exe_module_sp->GetFileSpec();
816 var_success = format_file_spec;
817 }
818 }
819 }
820 }
821 }
822 break;
823
824 case 't':
825 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
826 {
827 if (exe_ctx && exe_ctx->thread)
828 {
829 var_name_begin += ::strlen ("thread.");
830 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
831 {
832 s.Printf("0x%4.4x", exe_ctx->thread->GetID());
833 var_success = true;
834 }
835 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
836 {
837 s.Printf("%u", exe_ctx->thread->GetIndexID());
838 var_success = true;
839 }
840 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
841 {
842 cstr = exe_ctx->thread->GetName();
843 var_success = cstr && cstr[0];
844 if (var_success)
845 s.PutCString(cstr);
846 }
847 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
848 {
849 cstr = exe_ctx->thread->GetQueueName();
850 var_success = cstr && cstr[0];
851 if (var_success)
852 s.PutCString(cstr);
853 }
854 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
855 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000856 StopInfoSP stop_info_sp = exe_ctx->thread->GetStopInfo ();
857 if (stop_info_sp)
Greg Clayton1b654882010-09-19 02:33:57 +0000858 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000859 cstr = stop_info_sp->GetDescription();
Greg Clayton1b654882010-09-19 02:33:57 +0000860 if (cstr && cstr[0])
861 {
862 s.PutCString(cstr);
863 var_success = true;
864 }
865 }
866 }
867 }
868 }
869 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
870 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000871 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
872 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +0000873 {
Greg Clayton1b654882010-09-19 02:33:57 +0000874 var_name_begin += ::strlen ("target.");
875 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
876 {
877 ArchSpec arch (target->GetArchitecture ());
878 if (arch.IsValid())
879 {
Greg Clayton64195a22011-02-23 00:35:02 +0000880 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +0000881 var_success = true;
882 }
883 }
884 }
885 }
886 break;
887
888
889 case 'm':
890 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
891 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000892 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +0000893 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000894 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +0000895 var_name_begin += ::strlen ("module.");
896
897 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
898 {
899 if (module->GetFileSpec())
900 {
901 var_name_begin += ::strlen ("file.");
902
903 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
904 {
905 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
906 var_success = format_file_spec;
907 }
908 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
909 {
910 format_file_spec = module->GetFileSpec();
911 var_success = format_file_spec;
912 }
913 }
914 }
915 }
916 }
917 break;
918
919
920 case 'f':
921 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
922 {
923 if (sc && sc->comp_unit != NULL)
924 {
925 var_name_begin += ::strlen ("file.");
926
927 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
928 {
929 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
930 var_success = format_file_spec;
931 }
932 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
933 {
934 format_file_spec = *sc->comp_unit;
935 var_success = format_file_spec;
936 }
937 }
938 }
939 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
940 {
941 if (exe_ctx && exe_ctx->frame)
942 {
943 var_name_begin += ::strlen ("frame.");
944 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
945 {
946 s.Printf("%u", exe_ctx->frame->GetFrameIndex());
947 var_success = true;
948 }
949 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
950 {
951 reg_kind = eRegisterKindGeneric;
952 reg_num = LLDB_REGNUM_GENERIC_PC;
953 var_success = true;
954 }
955 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
956 {
957 reg_kind = eRegisterKindGeneric;
958 reg_num = LLDB_REGNUM_GENERIC_SP;
959 var_success = true;
960 }
961 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
962 {
963 reg_kind = eRegisterKindGeneric;
964 reg_num = LLDB_REGNUM_GENERIC_FP;
965 var_success = true;
966 }
967 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
968 {
969 reg_kind = eRegisterKindGeneric;
970 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
971 var_success = true;
972 }
973 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
974 {
Greg Clayton5ccbd292011-01-06 22:15:06 +0000975 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +0000976 if (reg_ctx)
977 {
978 var_name_begin += ::strlen ("reg.");
979 if (var_name_begin < var_name_end)
980 {
981 std::string reg_name (var_name_begin, var_name_end);
982 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
983 if (reg_info)
984 var_success = true;
985 }
986 }
987 }
988 }
989 }
990 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
991 {
992 if (sc && (sc->function != NULL || sc->symbol != NULL))
993 {
994 var_name_begin += ::strlen ("function.");
995 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
996 {
997 if (sc->function)
998 s.Printf("function{0x%8.8x}", sc->function->GetID());
999 else
1000 s.Printf("symbol[%u]", sc->symbol->GetID());
1001
1002 var_success = true;
1003 }
1004 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1005 {
1006 if (sc->function)
1007 cstr = sc->function->GetName().AsCString (NULL);
1008 else if (sc->symbol)
1009 cstr = sc->symbol->GetName().AsCString (NULL);
1010 if (cstr)
1011 {
1012 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001013
1014 if (sc->block)
1015 {
1016 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1017 if (inline_block)
1018 {
1019 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1020 if (inline_info)
1021 {
1022 s.PutCString(" [inlined] ");
1023 inline_info->GetName().Dump(&s);
1024 }
1025 }
1026 }
Greg Clayton1b654882010-09-19 02:33:57 +00001027 var_success = true;
1028 }
1029 }
1030 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1031 {
1032 var_success = addr != NULL;
1033 if (var_success)
1034 {
1035 format_addr = *addr;
1036 calculate_format_addr_function_offset = true;
1037 }
1038 }
1039 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1040 {
1041 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1042 if (var_success)
1043 {
1044 format_addr = sc->line_entry.range.GetBaseAddress();
1045 calculate_format_addr_function_offset = true;
1046 }
1047 }
1048 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1049 {
1050 var_success = exe_ctx->frame;
1051 if (var_success)
1052 {
1053 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1054 calculate_format_addr_function_offset = true;
1055 }
1056 }
1057 }
1058 }
1059 break;
1060
1061 case 'l':
1062 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1063 {
1064 if (sc && sc->line_entry.IsValid())
1065 {
1066 var_name_begin += ::strlen ("line.");
1067 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1068 {
1069 var_name_begin += ::strlen ("file.");
1070
1071 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1072 {
1073 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1074 var_success = format_file_spec;
1075 }
1076 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1077 {
1078 format_file_spec = sc->line_entry.file;
1079 var_success = format_file_spec;
1080 }
1081 }
1082 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1083 {
1084 var_success = true;
1085 s.Printf("%u", sc->line_entry.line);
1086 }
1087 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1088 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1089 {
1090 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1091 if (var_success)
1092 {
1093 format_addr = sc->line_entry.range.GetBaseAddress();
1094 if (var_name_begin[0] == 'e')
1095 format_addr.Slide (sc->line_entry.range.GetByteSize());
1096 }
1097 }
1098 }
1099 }
1100 break;
1101 }
1102
1103 if (var_success)
1104 {
1105 // If format addr is valid, then we need to print an address
1106 if (reg_num != LLDB_INVALID_REGNUM)
1107 {
1108 // We have a register value to display...
1109 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1110 {
1111 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1112 }
1113 else
1114 {
1115 if (reg_ctx == NULL)
Greg Clayton5ccbd292011-01-06 22:15:06 +00001116 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001117
1118 if (reg_ctx)
1119 {
1120 if (reg_kind != kNumRegisterKinds)
1121 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1122 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1123 var_success = reg_info != NULL;
1124 }
1125 }
1126 }
1127
1128 if (reg_info != NULL)
1129 {
1130 DataExtractor reg_data;
1131 var_success = reg_ctx->ReadRegisterBytes (reg_info->kinds[eRegisterKindLLDB], reg_data);
1132 {
1133 reg_data.Dump(&s, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
1134 }
1135 }
1136
1137 if (format_file_spec)
1138 {
1139 s << format_file_spec;
1140 }
1141
1142 // If format addr is valid, then we need to print an address
1143 if (format_addr.IsValid())
1144 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001145 var_success = false;
1146
Greg Clayton1b654882010-09-19 02:33:57 +00001147 if (calculate_format_addr_function_offset)
1148 {
1149 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001150
Greg Clayton0603aa92010-10-04 01:05:56 +00001151 if (sc)
1152 {
1153 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001154 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001155 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001156 if (sc->block)
1157 {
1158 // Check to make sure we aren't in an inline
1159 // function. If we are, use the inline block
1160 // range that contains "format_addr" since
1161 // blocks can be discontiguous.
1162 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1163 AddressRange inline_range;
1164 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1165 func_addr = inline_range.GetBaseAddress();
1166 }
1167 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001168 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1169 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1170 }
1171
1172 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001173 {
1174 if (func_addr.GetSection() == format_addr.GetSection())
1175 {
1176 addr_t func_file_addr = func_addr.GetFileAddress();
1177 addr_t addr_file_addr = format_addr.GetFileAddress();
1178 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001179 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001180 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001181 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001182 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001183 }
1184 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001185 {
1186 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1187 if (target)
1188 {
1189 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1190 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1191 if (addr_load_addr > func_load_addr)
1192 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1193 else if (addr_load_addr < func_load_addr)
1194 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1195 var_success = true;
1196 }
1197 }
Greg Clayton1b654882010-09-19 02:33:57 +00001198 }
1199 }
1200 else
1201 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001202 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001203 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001204 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1205 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001206 if (vaddr == LLDB_INVALID_ADDRESS)
1207 vaddr = format_addr.GetFileAddress ();
1208
1209 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001210 {
Greg Clayton514487e2011-02-15 21:59:32 +00001211 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001212 if (addr_width == 0)
1213 addr_width = 16;
1214 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001215 var_success = true;
1216 }
Greg Clayton1b654882010-09-19 02:33:57 +00001217 }
1218 }
1219 }
1220
1221 if (var_success == false)
1222 success = false;
1223 }
1224 p = var_name_end;
1225 }
1226 else
1227 break;
1228 }
1229 else
1230 {
1231 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1232 s.PutChar(*p);
1233 }
1234 }
1235 else if (*p == '\\')
1236 {
1237 ++p; // skip the slash
1238 switch (*p)
1239 {
1240 case 'a': s.PutChar ('\a'); break;
1241 case 'b': s.PutChar ('\b'); break;
1242 case 'f': s.PutChar ('\f'); break;
1243 case 'n': s.PutChar ('\n'); break;
1244 case 'r': s.PutChar ('\r'); break;
1245 case 't': s.PutChar ('\t'); break;
1246 case 'v': s.PutChar ('\v'); break;
1247 case '\'': s.PutChar ('\''); break;
1248 case '\\': s.PutChar ('\\'); break;
1249 case '0':
1250 // 1 to 3 octal chars
1251 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001252 // Make a string that can hold onto the initial zero char,
1253 // up to 3 octal digits, and a terminating NULL.
1254 char oct_str[5] = { 0, 0, 0, 0, 0 };
1255
1256 int i;
1257 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1258 oct_str[i] = p[i];
1259
1260 // We don't want to consume the last octal character since
1261 // the main for loop will do this for us, so we advance p by
1262 // one less than i (even if i is zero)
1263 p += i - 1;
1264 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
1265 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001266 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001267 char octal_char = octal_value;
1268 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00001269 }
Greg Clayton1b654882010-09-19 02:33:57 +00001270 }
1271 break;
1272
1273 case 'x':
1274 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00001275 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001276 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001277 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00001278
Greg Clayton0603aa92010-10-04 01:05:56 +00001279 // Make a string that can hold onto two hex chars plus a
1280 // NULL terminator
1281 char hex_str[3] = { 0,0,0 };
1282 hex_str[0] = *p;
1283 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001284 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001285 ++p; // Skip the first of the two hex chars
1286 hex_str[1] = *p;
1287 }
1288
1289 unsigned long hex_value = strtoul (hex_str, NULL, 16);
1290 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001291 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00001292 }
1293 else
1294 {
1295 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00001296 }
1297 break;
1298
1299 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00001300 // Just desensitize any other character by just printing what
1301 // came after the '\'
1302 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00001303 break;
1304
1305 }
1306
1307 }
1308 }
1309 if (end)
1310 *end = p;
1311 return success;
1312}
1313
1314#pragma mark Debugger::SettingsController
1315
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001316//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001317// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001318//--------------------------------------------------
1319
Greg Clayton1b654882010-09-19 02:33:57 +00001320Debugger::SettingsController::SettingsController () :
Caroline Tice101c7c22010-09-09 06:25:08 +00001321 UserSettingsController ("", lldb::UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001322{
Caroline Tice91123da2010-09-08 17:48:55 +00001323 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
1324 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001325}
1326
Greg Clayton1b654882010-09-19 02:33:57 +00001327Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001328{
1329}
1330
1331
1332lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00001333Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001334{
Greg Claytondbe54502010-11-19 03:46:01 +00001335 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00001336 false, instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001337 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1338 return new_settings_sp;
1339}
1340
Greg Clayton1b654882010-09-19 02:33:57 +00001341#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001342//--------------------------------------------------
1343// class DebuggerInstanceSettings
1344//--------------------------------------------------
1345
Greg Claytona7015092010-09-18 01:14:36 +00001346DebuggerInstanceSettings::DebuggerInstanceSettings
1347(
1348 UserSettingsController &owner,
1349 bool live_instance,
1350 const char *name
1351) :
Greg Clayton85851dd2010-12-04 00:10:17 +00001352 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00001353 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001354 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00001355 m_frame_format (),
1356 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001357 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001358 m_use_external_editor (false),
1359 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001360{
Caroline Ticef20e8232010-09-09 18:26:37 +00001361 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1362 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
1363 // 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 +00001364 // The same is true of CreateInstanceName().
1365
1366 if (GetInstanceName() == InstanceSettings::InvalidName())
1367 {
1368 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1369 m_owner.RegisterInstanceSettings (this);
1370 }
Caroline Ticef20e8232010-09-09 18:26:37 +00001371
1372 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001373 {
1374 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1375 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001376 }
1377}
1378
1379DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00001380 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001381 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00001382 m_frame_format (rhs.m_frame_format),
1383 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001384 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001385 m_use_external_editor (rhs.m_use_external_editor),
1386 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001387{
1388 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1389 CopyInstanceSettings (pending_settings, false);
1390 m_owner.RemovePendingSettings (m_instance_name);
1391}
1392
1393DebuggerInstanceSettings::~DebuggerInstanceSettings ()
1394{
1395}
1396
1397DebuggerInstanceSettings&
1398DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
1399{
1400 if (this != &rhs)
1401 {
Greg Clayton1b654882010-09-19 02:33:57 +00001402 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001403 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00001404 m_frame_format = rhs.m_frame_format;
1405 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001406 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001407 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001408 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001409 }
1410
1411 return *this;
1412}
1413
Greg Clayton1b654882010-09-19 02:33:57 +00001414bool
1415DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
1416{
1417 bool valid = false;
1418
1419 // Verify we have a value string.
1420 if (value == NULL || value[0] == '\0')
1421 {
1422 err.SetErrorString ("Missing value. Can't set terminal width without a value.\n");
1423 }
1424 else
1425 {
1426 char *end = NULL;
1427 const uint32_t width = ::strtoul (value, &end, 0);
1428
Johnny Chenea9fc182010-09-20 16:36:43 +00001429 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00001430 {
Johnny Chen433d7742010-09-20 17:04:41 +00001431 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00001432 valid = true;
1433 else
1434 err.SetErrorString ("Invalid term-width value; value must be between 10 and 1024.\n");
1435 }
1436 else
1437 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string.\n", value);
1438 }
1439
1440 return valid;
1441}
1442
1443
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001444void
1445DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1446 const char *index_value,
1447 const char *value,
1448 const ConstString &instance_name,
1449 const SettingEntry &entry,
1450 lldb::VarSetOperationType op,
1451 Error &err,
1452 bool pending)
1453{
Greg Clayton0603aa92010-10-04 01:05:56 +00001454
1455 if (var_name == TermWidthVarName())
1456 {
1457 if (ValidTermWidthValue (value, err))
1458 {
1459 m_term_width = ::strtoul (value, NULL, 0);
1460 }
1461 }
1462 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001463 {
Caroline Tice101c7c22010-09-09 06:25:08 +00001464 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001465 if (!pending)
1466 {
Caroline Tice49e27372010-09-07 18:35:40 +00001467 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1468 // strip off the brackets before passing it to BroadcastPromptChange.
1469
1470 std::string tmp_instance_name (instance_name.AsCString());
1471 if ((tmp_instance_name[0] == '[')
1472 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
1473 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
1474 ConstString new_name (tmp_instance_name.c_str());
1475
1476 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001477 }
1478 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001479 else if (var_name == GetFrameFormatName())
1480 {
1481 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
1482 }
1483 else if (var_name == GetThreadFormatName())
1484 {
1485 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
1486 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001487 else if (var_name == ScriptLangVarName())
1488 {
1489 bool success;
1490 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
1491 &success);
1492 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001493 else if (var_name == UseExternalEditorVarName ())
1494 {
1495 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, err);
1496 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001497 else if (var_name == AutoConfirmName ())
1498 {
1499 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, err);
1500 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001501}
1502
Caroline Tice12cecd72010-09-20 21:37:42 +00001503bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001504DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1505 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00001506 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00001507 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001508{
1509 if (var_name == PromptVarName())
1510 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001511 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001512
1513 }
1514 else if (var_name == ScriptLangVarName())
1515 {
1516 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
1517 }
Caroline Tice101c7c22010-09-09 06:25:08 +00001518 else if (var_name == TermWidthVarName())
1519 {
1520 StreamString width_str;
1521 width_str.Printf ("%d", m_term_width);
1522 value.AppendString (width_str.GetData());
1523 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001524 else if (var_name == GetFrameFormatName ())
1525 {
1526 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
1527 }
1528 else if (var_name == GetThreadFormatName ())
1529 {
1530 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
1531 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001532 else if (var_name == UseExternalEditorVarName())
1533 {
1534 if (m_use_external_editor)
1535 value.AppendString ("true");
1536 else
1537 value.AppendString ("false");
1538 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001539 else if (var_name == AutoConfirmName())
1540 {
1541 if (m_auto_confirm_on)
1542 value.AppendString ("true");
1543 else
1544 value.AppendString ("false");
1545 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001546 else
Caroline Tice12cecd72010-09-20 21:37:42 +00001547 {
1548 if (err)
1549 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1550 return false;
1551 }
1552 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001553}
1554
1555void
1556DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1557 bool pending)
1558{
1559 if (new_settings.get() == NULL)
1560 return;
1561
1562 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
1563
1564 m_prompt = new_debugger_settings->m_prompt;
1565 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00001566 {
1567 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1568 // strip off the brackets before passing it to BroadcastPromptChange.
1569
1570 std::string tmp_instance_name (m_instance_name.AsCString());
1571 if ((tmp_instance_name[0] == '[')
1572 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
1573 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
1574 ConstString new_name (tmp_instance_name.c_str());
1575
1576 BroadcastPromptChange (new_name, m_prompt.c_str());
1577 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001578 m_frame_format = new_debugger_settings->m_frame_format;
1579 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001580 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001581 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001582 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001583 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001584}
1585
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001586
1587bool
1588DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
1589{
1590 std::string tmp_prompt;
1591
1592 if (new_prompt != NULL)
1593 {
1594 tmp_prompt = new_prompt ;
1595 int len = tmp_prompt.size();
1596 if (len > 1
1597 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
1598 && (tmp_prompt[len-1] == tmp_prompt[0]))
1599 {
1600 tmp_prompt = tmp_prompt.substr(1,len-2);
1601 }
1602 len = tmp_prompt.size();
1603 if (tmp_prompt[len-1] != ' ')
1604 tmp_prompt.append(" ");
1605 }
1606 EventSP new_event_sp;
1607 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
1608 new EventDataBytes (tmp_prompt.c_str())));
1609
1610 if (instance_name.GetLength() != 0)
1611 {
1612 // Set prompt for a particular instance.
1613 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
1614 if (dbg != NULL)
1615 {
1616 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
1617 }
1618 }
1619
1620 return true;
1621}
1622
1623const ConstString
1624DebuggerInstanceSettings::CreateInstanceName ()
1625{
1626 static int instance_count = 1;
1627 StreamString sstr;
1628
1629 sstr.Printf ("debugger_%d", instance_count);
1630 ++instance_count;
1631
1632 const ConstString ret_val (sstr.GetData());
1633
1634 return ret_val;
1635}
1636
1637const ConstString &
1638DebuggerInstanceSettings::PromptVarName ()
1639{
1640 static ConstString prompt_var_name ("prompt");
1641
1642 return prompt_var_name;
1643}
1644
1645const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00001646DebuggerInstanceSettings::GetFrameFormatName ()
1647{
1648 static ConstString prompt_var_name ("frame-format");
1649
1650 return prompt_var_name;
1651}
1652
1653const ConstString &
1654DebuggerInstanceSettings::GetThreadFormatName ()
1655{
1656 static ConstString prompt_var_name ("thread-format");
1657
1658 return prompt_var_name;
1659}
1660
1661const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001662DebuggerInstanceSettings::ScriptLangVarName ()
1663{
1664 static ConstString script_lang_var_name ("script-lang");
1665
1666 return script_lang_var_name;
1667}
1668
Caroline Tice101c7c22010-09-09 06:25:08 +00001669const ConstString &
1670DebuggerInstanceSettings::TermWidthVarName ()
1671{
1672 static ConstString term_width_var_name ("term-width");
1673
1674 return term_width_var_name;
1675}
1676
Caroline Ticedaccaa92010-09-20 20:44:43 +00001677const ConstString &
1678DebuggerInstanceSettings::UseExternalEditorVarName ()
1679{
1680 static ConstString use_external_editor_var_name ("use-external-editor");
1681
1682 return use_external_editor_var_name;
1683}
1684
Jim Ingham3bcdb292010-10-04 22:44:14 +00001685const ConstString &
1686DebuggerInstanceSettings::AutoConfirmName ()
1687{
1688 static ConstString use_external_editor_var_name ("auto-confirm");
1689
1690 return use_external_editor_var_name;
1691}
1692
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001693//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001694// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001695//--------------------------------------------------
1696
1697
1698SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001699Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001700{
1701 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00001702 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
1703 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001704 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1705};
1706
Greg Claytonbb562b12010-10-04 02:44:26 +00001707#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00001708#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001709
Greg Clayton0603aa92010-10-04 01:05:56 +00001710#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1711 "{, ${frame.pc}}"\
1712 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00001713 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00001714 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00001715 "\\n"
1716
Greg Clayton315d2ca2010-11-02 01:53:21 +00001717//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1718// "{, ${frame.pc}}"\
1719// MODULE_WITH_FUNC\
1720// FILE_AND_LINE\
1721// "{, stop reason = ${thread.stop-reason}}"\
1722// "{, name = ${thread.name}}"\
1723// "{, queue = ${thread.queue}}"\
1724// "\\n"
1725
Greg Clayton0603aa92010-10-04 01:05:56 +00001726#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
1727 MODULE_WITH_FUNC\
1728 FILE_AND_LINE\
1729 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001730
1731SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001732Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001733{
Greg Clayton0603aa92010-10-04 01:05:56 +00001734// NAME Setting variable type Default Enum Init'd Hidden Help
1735// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00001736{ "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 +00001737{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00001738{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
1739{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001740{ "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 +00001741{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
1742{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001743{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001744};