blob: eceaf83091ff7b32184f4717dcb4188ca31e0dcb [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 Clayton66111032010-06-23 01:19:29 +000017#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Target/TargetList.h"
19#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000020#include "lldb/Target/RegisterContext.h"
21#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Target/Thread.h"
23
24
25using namespace lldb;
26using namespace lldb_private;
27
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
Greg Clayton1b654882010-09-19 02:33:57 +000029static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000030static lldb::user_id_t g_unique_id = 1;
31
Greg Clayton1b654882010-09-19 02:33:57 +000032#pragma mark Static Functions
33
34static Mutex &
35GetDebuggerListMutex ()
36{
37 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
38 return g_mutex;
39}
40
41typedef std::vector<DebuggerSP> DebuggerList;
42
43static DebuggerList &
44GetDebuggerList()
45{
46 // hide the static debugger list inside a singleton accessor to avoid
47 // global init contructors
48 static DebuggerList g_list;
49 return g_list;
50}
51
52
53#pragma mark Debugger
54
Greg Clayton99d0faf2010-11-18 23:32:35 +000055UserSettingsControllerSP &
56Debugger::GetSettingsController ()
57{
58 static UserSettingsControllerSP g_settings_controller;
59 return g_settings_controller;
60}
61
Caroline Tice2f88aad2011-01-14 00:29:16 +000062int
63Debugger::TestDebuggerRefCount ()
64{
65 return g_shared_debugger_refcount;
66}
67
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068void
69Debugger::Initialize ()
70{
Greg Clayton66111032010-06-23 01:19:29 +000071 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +000072 {
Greg Clayton99d0faf2010-11-18 23:32:35 +000073 UserSettingsControllerSP &usc = GetSettingsController();
74 usc.reset (new SettingsController);
75 UserSettingsController::InitializeSettingsController (usc,
76 SettingsController::global_settings_table,
77 SettingsController::instance_settings_table);
Greg Claytondbe54502010-11-19 03:46:01 +000078 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +000079 }
Greg Clayton66111032010-06-23 01:19:29 +000080 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +000081
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082}
83
84void
85Debugger::Terminate ()
86{
Greg Clayton66111032010-06-23 01:19:29 +000087 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088 {
Greg Clayton66111032010-06-23 01:19:29 +000089 g_shared_debugger_refcount--;
90 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091 {
Greg Claytondbe54502010-11-19 03:46:01 +000092 lldb_private::WillTerminate();
93 lldb_private::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +000094 UserSettingsControllerSP &usc = GetSettingsController();
95 UserSettingsController::FinalizeSettingsController (usc);
96 usc.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098 }
Greg Clayton99d0faf2010-11-18 23:32:35 +000099 // Clear our master list of debugger objects
100 Mutex::Locker locker (GetDebuggerListMutex ());
101 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102}
103
Greg Clayton66111032010-06-23 01:19:29 +0000104DebuggerSP
105Debugger::CreateInstance ()
106{
107 DebuggerSP debugger_sp (new Debugger);
108 // Scope for locker
109 {
110 Mutex::Locker locker (GetDebuggerListMutex ());
111 GetDebuggerList().push_back(debugger_sp);
112 }
113 return debugger_sp;
114}
115
116lldb::DebuggerSP
117Debugger::GetSP ()
118{
119 lldb::DebuggerSP debugger_sp;
120
121 Mutex::Locker locker (GetDebuggerListMutex ());
122 DebuggerList &debugger_list = GetDebuggerList();
123 DebuggerList::iterator pos, end = debugger_list.end();
124 for (pos = debugger_list.begin(); pos != end; ++pos)
125 {
126 if ((*pos).get() == this)
127 {
128 debugger_sp = *pos;
129 break;
130 }
131 }
132 return debugger_sp;
133}
134
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000135lldb::DebuggerSP
136Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
137{
138 lldb::DebuggerSP debugger_sp;
139
140 Mutex::Locker locker (GetDebuggerListMutex ());
141 DebuggerList &debugger_list = GetDebuggerList();
142 DebuggerList::iterator pos, end = debugger_list.end();
143
144 for (pos = debugger_list.begin(); pos != end; ++pos)
145 {
146 if ((*pos).get()->m_instance_name == instance_name)
147 {
148 debugger_sp = *pos;
149 break;
150 }
151 }
152 return debugger_sp;
153}
Greg Clayton66111032010-06-23 01:19:29 +0000154
155TargetSP
156Debugger::FindTargetWithProcessID (lldb::pid_t pid)
157{
158 lldb::TargetSP target_sp;
159 Mutex::Locker locker (GetDebuggerListMutex ());
160 DebuggerList &debugger_list = GetDebuggerList();
161 DebuggerList::iterator pos, end = debugger_list.end();
162 for (pos = debugger_list.begin(); pos != end; ++pos)
163 {
164 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
165 if (target_sp)
166 break;
167 }
168 return target_sp;
169}
170
171
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000172Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000173 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000174 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000175 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176 m_input_file (),
177 m_output_file (),
178 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179 m_target_list (),
180 m_listener ("lldb.Debugger"),
181 m_source_manager (),
Greg Clayton66111032010-06-23 01:19:29 +0000182 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
183 m_exe_ctx (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184 m_input_readers (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000185 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186{
Greg Claytond46c87a2010-12-04 02:39:47 +0000187 m_input_comm.SetCloseOnEOF(false);
Greg Clayton66111032010-06-23 01:19:29 +0000188 m_command_interpreter_ap->Initialize ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189}
190
191Debugger::~Debugger ()
192{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000193 CleanUpInputReaders();
Greg Clayton66111032010-06-23 01:19:29 +0000194 int num_targets = m_target_list.GetNumTargets();
195 for (int i = 0; i < num_targets; i++)
196 {
197 ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
198 if (process_sp)
199 process_sp->Destroy();
200 }
201 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202}
203
204
205bool
206Debugger::GetAsyncExecution ()
207{
Greg Clayton66111032010-06-23 01:19:29 +0000208 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000209}
210
211void
212Debugger::SetAsyncExecution (bool async_execution)
213{
Greg Clayton66111032010-06-23 01:19:29 +0000214 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215}
216
217void
218Debugger::DisconnectInput()
219{
220 m_input_comm.Clear ();
221}
222
223void
224Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
225{
226 m_input_file.SetFileHandle (fh, tranfer_ownership);
227 if (m_input_file.GetFileHandle() == NULL)
228 m_input_file.SetFileHandle (stdin, false);
229
230 // Disconnect from any old connection if we had one
231 m_input_comm.Disconnect ();
232 m_input_comm.SetConnection (new ConnectionFileDescriptor (::fileno (GetInputFileHandle()), true));
233 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
234
235 Error error;
236 if (m_input_comm.StartReadThread (&error) == false)
237 {
238 FILE *err_fh = GetErrorFileHandle();
239 if (err_fh)
240 {
241 ::fprintf (err_fh, "error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
242 exit(1);
243 }
244 }
245
246}
247
248FILE *
249Debugger::GetInputFileHandle ()
250{
251 return m_input_file.GetFileHandle();
252}
253
254
255void
256Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
257{
258 m_output_file.SetFileHandle (fh, tranfer_ownership);
259 if (m_output_file.GetFileHandle() == NULL)
260 m_output_file.SetFileHandle (stdin, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000261
262 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263}
264
265FILE *
266Debugger::GetOutputFileHandle ()
267{
268 return m_output_file.GetFileHandle();
269}
270
271void
272Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
273{
274 m_error_file.SetFileHandle (fh, tranfer_ownership);
275 if (m_error_file.GetFileHandle() == NULL)
276 m_error_file.SetFileHandle (stdin, false);
277}
278
279
280FILE *
281Debugger::GetErrorFileHandle ()
282{
283 return m_error_file.GetFileHandle();
284}
285
286CommandInterpreter &
287Debugger::GetCommandInterpreter ()
288{
Greg Clayton66111032010-06-23 01:19:29 +0000289 assert (m_command_interpreter_ap.get());
290 return *m_command_interpreter_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000291}
292
293Listener &
294Debugger::GetListener ()
295{
296 return m_listener;
297}
298
299
300TargetSP
Jim Ingham2976d002010-08-26 21:32:51 +0000301Debugger::GetSelectedTarget ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302{
Jim Ingham2976d002010-08-26 21:32:51 +0000303 return m_target_list.GetSelectedTarget ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000304}
305
306ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000307Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308{
309 ExecutionContext exe_ctx;
310 exe_ctx.Clear();
311
Jim Ingham2976d002010-08-26 21:32:51 +0000312 lldb::TargetSP target_sp = GetSelectedTarget();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313 exe_ctx.target = target_sp.get();
314
315 if (target_sp)
316 {
317 exe_ctx.process = target_sp->GetProcessSP().get();
318 if (exe_ctx.process && exe_ctx.process->IsRunning() == false)
319 {
Jim Ingham2976d002010-08-26 21:32:51 +0000320 exe_ctx.thread = exe_ctx.process->GetThreadList().GetSelectedThread().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321 if (exe_ctx.thread == NULL)
322 exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
323 if (exe_ctx.thread)
324 {
Jim Ingham2976d002010-08-26 21:32:51 +0000325 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000326 if (exe_ctx.frame == NULL)
327 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex (0).get();
328 }
329 }
330 }
331 return exe_ctx;
332
333}
334
335SourceManager &
336Debugger::GetSourceManager ()
337{
338 return m_source_manager;
339}
340
341
342TargetList&
343Debugger::GetTargetList ()
344{
345 return m_target_list;
346}
347
348void
349Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
350{
Caroline Ticeefed6132010-11-19 20:47:54 +0000351 if (bytes_len > 0)
352 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
353 else
354 ((Debugger *)baton)->DispatchInputEndOfFile ();
355}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356
357
358void
359Debugger::DispatchInput (const char *bytes, size_t bytes_len)
360{
Caroline Ticeefed6132010-11-19 20:47:54 +0000361 if (bytes == NULL || bytes_len == 0)
362 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000363
364 WriteToDefaultReader (bytes, bytes_len);
365}
366
367void
Caroline Ticeefed6132010-11-19 20:47:54 +0000368Debugger::DispatchInputInterrupt ()
369{
370 m_input_reader_data.clear();
371
372 if (!m_input_readers.empty())
373 {
374 while (CheckIfTopInputReaderIsDone ()) ;
375
376 InputReaderSP reader_sp(m_input_readers.top());
377 if (reader_sp)
378 reader_sp->Notify (eInputReaderInterrupt);
379
380 while (CheckIfTopInputReaderIsDone ()) ;
381 }
382}
383
384void
385Debugger::DispatchInputEndOfFile ()
386{
387 m_input_reader_data.clear();
388
389 if (!m_input_readers.empty())
390 {
391 while (CheckIfTopInputReaderIsDone ()) ;
392
393 InputReaderSP reader_sp(m_input_readers.top());
394 if (reader_sp)
395 reader_sp->Notify (eInputReaderEndOfFile);
396
397 while (CheckIfTopInputReaderIsDone ()) ;
398 }
399}
400
401void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000402Debugger::CleanUpInputReaders ()
403{
404 m_input_reader_data.clear();
405
406 while (m_input_readers.size() > 1)
407 {
408 while (CheckIfTopInputReaderIsDone ()) ;
409
410 InputReaderSP reader_sp (m_input_readers.top());
411 if (reader_sp)
412 {
413 reader_sp->Notify (eInputReaderEndOfFile);
414 reader_sp->SetIsDone (true);
415 }
416 }
417}
418
419void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
421{
422 if (bytes && bytes_len)
423 m_input_reader_data.append (bytes, bytes_len);
424
425 if (m_input_reader_data.empty())
426 return;
427
428 while (!m_input_readers.empty() && !m_input_reader_data.empty())
429 {
430 while (CheckIfTopInputReaderIsDone ())
431 /* Do nothing. */;
432
433 // Get the input reader from the top of the stack
434 InputReaderSP reader_sp(m_input_readers.top());
435
436 if (!reader_sp)
437 break;
438
Greg Clayton471b31c2010-07-20 22:52:08 +0000439 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440 m_input_reader_data.size());
441 if (bytes_handled)
442 {
443 m_input_reader_data.erase (0, bytes_handled);
444 }
445 else
446 {
447 // No bytes were handled, we might not have reached our
448 // granularity, just return and wait for more data
449 break;
450 }
451 }
452
453 // Flush out any input readers that are donesvn
454 while (CheckIfTopInputReaderIsDone ())
455 /* Do nothing. */;
456
457}
458
459void
460Debugger::PushInputReader (const InputReaderSP& reader_sp)
461{
462 if (!reader_sp)
463 return;
464 if (!m_input_readers.empty())
465 {
466 // Deactivate the old top reader
467 InputReaderSP top_reader_sp (m_input_readers.top());
468 if (top_reader_sp)
469 top_reader_sp->Notify (eInputReaderDeactivate);
470 }
471 m_input_readers.push (reader_sp);
472 reader_sp->Notify (eInputReaderActivate);
473 ActivateInputReader (reader_sp);
474}
475
476bool
477Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp)
478{
479 bool result = false;
480
481 // The reader on the stop of the stack is done, so let the next
482 // read on the stack referesh its prompt and if there is one...
483 if (!m_input_readers.empty())
484 {
485 InputReaderSP reader_sp(m_input_readers.top());
486
487 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
488 {
489 m_input_readers.pop ();
490 reader_sp->Notify (eInputReaderDeactivate);
491 reader_sp->Notify (eInputReaderDone);
492 result = true;
493
494 if (!m_input_readers.empty())
495 {
496 reader_sp = m_input_readers.top();
497 if (reader_sp)
498 {
499 ActivateInputReader (reader_sp);
500 reader_sp->Notify (eInputReaderReactivate);
501 }
502 }
503 }
504 }
505 return result;
506}
507
508bool
509Debugger::CheckIfTopInputReaderIsDone ()
510{
511 bool result = false;
512 if (!m_input_readers.empty())
513 {
514 InputReaderSP reader_sp(m_input_readers.top());
515
516 if (reader_sp && reader_sp->IsDone())
517 {
518 result = true;
519 PopInputReader (reader_sp);
520 }
521 }
522 return result;
523}
524
525void
526Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
527{
528 FILE *in_fh = GetInputFileHandle();
529
530 if (in_fh)
531 {
532 struct termios in_fh_termios;
533 int in_fd = fileno (in_fh);
534 if (::tcgetattr(in_fd, &in_fh_termios) == 0)
535 {
536 if (reader_sp->GetEcho())
537 in_fh_termios.c_lflag |= ECHO; // Turn on echoing
538 else
539 in_fh_termios.c_lflag &= ~ECHO; // Turn off echoing
540
541 switch (reader_sp->GetGranularity())
542 {
543 case eInputReaderGranularityByte:
544 case eInputReaderGranularityWord:
545 in_fh_termios.c_lflag &= ~ICANON; // Get one char at a time
546 break;
547
548 case eInputReaderGranularityLine:
549 case eInputReaderGranularityAll:
550 in_fh_termios.c_lflag |= ICANON; // Get lines at a time
551 break;
552
553 default:
554 break;
555 }
556 ::tcsetattr (in_fd, TCSANOW, &in_fh_termios);
557 }
558 }
559}
Greg Clayton66111032010-06-23 01:19:29 +0000560
561void
562Debugger::UpdateExecutionContext (ExecutionContext *override_context)
563{
564 m_exe_ctx.Clear();
565
566 if (override_context != NULL)
567 {
568 m_exe_ctx.target = override_context->target;
569 m_exe_ctx.process = override_context->process;
570 m_exe_ctx.thread = override_context->thread;
571 m_exe_ctx.frame = override_context->frame;
572 }
573 else
574 {
Jim Ingham2976d002010-08-26 21:32:51 +0000575 TargetSP target_sp (GetSelectedTarget());
Greg Clayton66111032010-06-23 01:19:29 +0000576 if (target_sp)
577 {
578 m_exe_ctx.target = target_sp.get();
579 m_exe_ctx.process = target_sp->GetProcessSP().get();
Johnny Chen725945d2010-09-03 22:35:47 +0000580 if (m_exe_ctx.process && m_exe_ctx.process->IsAlive() && !m_exe_ctx.process->IsRunning())
Greg Clayton66111032010-06-23 01:19:29 +0000581 {
Jim Ingham2976d002010-08-26 21:32:51 +0000582 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetSelectedThread().get();
Greg Clayton66111032010-06-23 01:19:29 +0000583 if (m_exe_ctx.thread == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000584 {
Greg Clayton66111032010-06-23 01:19:29 +0000585 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000586 // If we didn't have a selected thread, select one here.
587 if (m_exe_ctx.thread != NULL)
Johnny Chenc13ee522010-09-14 00:53:53 +0000588 m_exe_ctx.process->GetThreadList().SetSelectedThreadByID(m_exe_ctx.thread->GetID());
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000589 }
Greg Clayton66111032010-06-23 01:19:29 +0000590 if (m_exe_ctx.thread)
591 {
Jim Ingham2976d002010-08-26 21:32:51 +0000592 m_exe_ctx.frame = m_exe_ctx.thread->GetSelectedFrame().get();
Greg Clayton66111032010-06-23 01:19:29 +0000593 if (m_exe_ctx.frame == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000594 {
Greg Clayton66111032010-06-23 01:19:29 +0000595 m_exe_ctx.frame = m_exe_ctx.thread->GetStackFrameAtIndex (0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000596 // If we didn't have a selected frame select one here.
597 if (m_exe_ctx.frame != NULL)
598 m_exe_ctx.thread->SetSelectedFrame(m_exe_ctx.frame);
599 }
Greg Clayton66111032010-06-23 01:19:29 +0000600 }
601 }
602 }
603 }
604}
605
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000606DebuggerSP
607Debugger::FindDebuggerWithID (lldb::user_id_t id)
608{
609 lldb::DebuggerSP debugger_sp;
610
611 Mutex::Locker locker (GetDebuggerListMutex ());
612 DebuggerList &debugger_list = GetDebuggerList();
613 DebuggerList::iterator pos, end = debugger_list.end();
614 for (pos = debugger_list.begin(); pos != end; ++pos)
615 {
616 if ((*pos).get()->GetID() == id)
617 {
618 debugger_sp = *pos;
619 break;
620 }
621 }
622 return debugger_sp;
623}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000624
Greg Clayton1b654882010-09-19 02:33:57 +0000625static void
626TestPromptFormats (StackFrame *frame)
627{
628 if (frame == NULL)
629 return;
630
631 StreamString s;
632 const char *prompt_format =
633 "{addr = '${addr}'\n}"
634 "{process.id = '${process.id}'\n}"
635 "{process.name = '${process.name}'\n}"
636 "{process.file.basename = '${process.file.basename}'\n}"
637 "{process.file.fullpath = '${process.file.fullpath}'\n}"
638 "{thread.id = '${thread.id}'\n}"
639 "{thread.index = '${thread.index}'\n}"
640 "{thread.name = '${thread.name}'\n}"
641 "{thread.queue = '${thread.queue}'\n}"
642 "{thread.stop-reason = '${thread.stop-reason}'\n}"
643 "{target.arch = '${target.arch}'\n}"
644 "{module.file.basename = '${module.file.basename}'\n}"
645 "{module.file.fullpath = '${module.file.fullpath}'\n}"
646 "{file.basename = '${file.basename}'\n}"
647 "{file.fullpath = '${file.fullpath}'\n}"
648 "{frame.index = '${frame.index}'\n}"
649 "{frame.pc = '${frame.pc}'\n}"
650 "{frame.sp = '${frame.sp}'\n}"
651 "{frame.fp = '${frame.fp}'\n}"
652 "{frame.flags = '${frame.flags}'\n}"
653 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
654 "{frame.reg.rip = '${frame.reg.rip}'\n}"
655 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
656 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
657 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
658 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
659 "{frame.reg.carp = '${frame.reg.carp}'\n}"
660 "{function.id = '${function.id}'\n}"
661 "{function.name = '${function.name}'\n}"
662 "{function.addr-offset = '${function.addr-offset}'\n}"
663 "{function.line-offset = '${function.line-offset}'\n}"
664 "{function.pc-offset = '${function.pc-offset}'\n}"
665 "{line.file.basename = '${line.file.basename}'\n}"
666 "{line.file.fullpath = '${line.file.fullpath}'\n}"
667 "{line.number = '${line.number}'\n}"
668 "{line.start-addr = '${line.start-addr}'\n}"
669 "{line.end-addr = '${line.end-addr}'\n}"
670;
671
672 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
673 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000674 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000675 const char *end = NULL;
676 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
677 {
678 printf("%s\n", s.GetData());
679 }
680 else
681 {
682 printf ("error: at '%s'\n", end);
683 printf ("what we got: %s\n", s.GetData());
684 }
685}
686
687bool
688Debugger::FormatPrompt
689(
690 const char *format,
691 const SymbolContext *sc,
692 const ExecutionContext *exe_ctx,
693 const Address *addr,
694 Stream &s,
695 const char **end
696)
697{
698 bool success = true;
699 const char *p;
700 for (p = format; *p != '\0'; ++p)
701 {
702 size_t non_special_chars = ::strcspn (p, "${}\\");
703 if (non_special_chars > 0)
704 {
705 if (success)
706 s.Write (p, non_special_chars);
707 p += non_special_chars;
708 }
709
710 if (*p == '\0')
711 {
712 break;
713 }
714 else if (*p == '{')
715 {
716 // Start a new scope that must have everything it needs if it is to
717 // to make it into the final output stream "s". If you want to make
718 // a format that only prints out the function or symbol name if there
719 // is one in the symbol context you can use:
720 // "{function =${function.name}}"
721 // The first '{' starts a new scope that end with the matching '}' at
722 // the end of the string. The contents "function =${function.name}"
723 // will then be evaluated and only be output if there is a function
724 // or symbol with a valid name.
725 StreamString sub_strm;
726
727 ++p; // Skip the '{'
728
729 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p))
730 {
731 // The stream had all it needed
732 s.Write(sub_strm.GetData(), sub_strm.GetSize());
733 }
734 if (*p != '}')
735 {
736 success = false;
737 break;
738 }
739 }
740 else if (*p == '}')
741 {
742 // End of a enclosing scope
743 break;
744 }
745 else if (*p == '$')
746 {
747 // We have a prompt variable to print
748 ++p;
749 if (*p == '{')
750 {
751 ++p;
752 const char *var_name_begin = p;
753 const char *var_name_end = ::strchr (p, '}');
754
755 if (var_name_end && var_name_begin < var_name_end)
756 {
757 // if we have already failed to parse, skip this variable
758 if (success)
759 {
760 const char *cstr = NULL;
761 Address format_addr;
762 bool calculate_format_addr_function_offset = false;
763 // Set reg_kind and reg_num to invalid values
764 RegisterKind reg_kind = kNumRegisterKinds;
765 uint32_t reg_num = LLDB_INVALID_REGNUM;
766 FileSpec format_file_spec;
767 const lldb::RegisterInfo *reg_info = NULL;
768 RegisterContext *reg_ctx = NULL;
769
770 // Each variable must set success to true below...
771 bool var_success = false;
772 switch (var_name_begin[0])
773 {
774 case 'a':
775 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
776 {
777 if (addr && addr->IsValid())
778 {
779 var_success = true;
780 format_addr = *addr;
781 }
782 }
783 break;
784
785 case 'p':
786 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
787 {
788 if (exe_ctx && exe_ctx->process != NULL)
789 {
790 var_name_begin += ::strlen ("process.");
791 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
792 {
793 s.Printf("%i", exe_ctx->process->GetID());
794 var_success = true;
795 }
796 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
797 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
798 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
799 {
800 ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
801 if (exe_module_sp)
802 {
803 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
804 {
805 format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
806 var_success = format_file_spec;
807 }
808 else
809 {
810 format_file_spec = exe_module_sp->GetFileSpec();
811 var_success = format_file_spec;
812 }
813 }
814 }
815 }
816 }
817 break;
818
819 case 't':
820 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
821 {
822 if (exe_ctx && exe_ctx->thread)
823 {
824 var_name_begin += ::strlen ("thread.");
825 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
826 {
827 s.Printf("0x%4.4x", exe_ctx->thread->GetID());
828 var_success = true;
829 }
830 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
831 {
832 s.Printf("%u", exe_ctx->thread->GetIndexID());
833 var_success = true;
834 }
835 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
836 {
837 cstr = exe_ctx->thread->GetName();
838 var_success = cstr && cstr[0];
839 if (var_success)
840 s.PutCString(cstr);
841 }
842 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
843 {
844 cstr = exe_ctx->thread->GetQueueName();
845 var_success = cstr && cstr[0];
846 if (var_success)
847 s.PutCString(cstr);
848 }
849 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
850 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000851 StopInfoSP stop_info_sp = exe_ctx->thread->GetStopInfo ();
852 if (stop_info_sp)
Greg Clayton1b654882010-09-19 02:33:57 +0000853 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000854 cstr = stop_info_sp->GetDescription();
Greg Clayton1b654882010-09-19 02:33:57 +0000855 if (cstr && cstr[0])
856 {
857 s.PutCString(cstr);
858 var_success = true;
859 }
860 }
861 }
862 }
863 }
864 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
865 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000866 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
867 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +0000868 {
Greg Clayton1b654882010-09-19 02:33:57 +0000869 var_name_begin += ::strlen ("target.");
870 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
871 {
872 ArchSpec arch (target->GetArchitecture ());
873 if (arch.IsValid())
874 {
875 s.PutCString (arch.AsCString());
876 var_success = true;
877 }
878 }
879 }
880 }
881 break;
882
883
884 case 'm':
885 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
886 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000887 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +0000888 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000889 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +0000890 var_name_begin += ::strlen ("module.");
891
892 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
893 {
894 if (module->GetFileSpec())
895 {
896 var_name_begin += ::strlen ("file.");
897
898 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
899 {
900 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
901 var_success = format_file_spec;
902 }
903 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
904 {
905 format_file_spec = module->GetFileSpec();
906 var_success = format_file_spec;
907 }
908 }
909 }
910 }
911 }
912 break;
913
914
915 case 'f':
916 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
917 {
918 if (sc && sc->comp_unit != NULL)
919 {
920 var_name_begin += ::strlen ("file.");
921
922 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
923 {
924 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
925 var_success = format_file_spec;
926 }
927 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
928 {
929 format_file_spec = *sc->comp_unit;
930 var_success = format_file_spec;
931 }
932 }
933 }
934 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
935 {
936 if (exe_ctx && exe_ctx->frame)
937 {
938 var_name_begin += ::strlen ("frame.");
939 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
940 {
941 s.Printf("%u", exe_ctx->frame->GetFrameIndex());
942 var_success = true;
943 }
944 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
945 {
946 reg_kind = eRegisterKindGeneric;
947 reg_num = LLDB_REGNUM_GENERIC_PC;
948 var_success = true;
949 }
950 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
951 {
952 reg_kind = eRegisterKindGeneric;
953 reg_num = LLDB_REGNUM_GENERIC_SP;
954 var_success = true;
955 }
956 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
957 {
958 reg_kind = eRegisterKindGeneric;
959 reg_num = LLDB_REGNUM_GENERIC_FP;
960 var_success = true;
961 }
962 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
963 {
964 reg_kind = eRegisterKindGeneric;
965 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
966 var_success = true;
967 }
968 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
969 {
Greg Clayton5ccbd292011-01-06 22:15:06 +0000970 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +0000971 if (reg_ctx)
972 {
973 var_name_begin += ::strlen ("reg.");
974 if (var_name_begin < var_name_end)
975 {
976 std::string reg_name (var_name_begin, var_name_end);
977 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
978 if (reg_info)
979 var_success = true;
980 }
981 }
982 }
983 }
984 }
985 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
986 {
987 if (sc && (sc->function != NULL || sc->symbol != NULL))
988 {
989 var_name_begin += ::strlen ("function.");
990 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
991 {
992 if (sc->function)
993 s.Printf("function{0x%8.8x}", sc->function->GetID());
994 else
995 s.Printf("symbol[%u]", sc->symbol->GetID());
996
997 var_success = true;
998 }
999 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1000 {
1001 if (sc->function)
1002 cstr = sc->function->GetName().AsCString (NULL);
1003 else if (sc->symbol)
1004 cstr = sc->symbol->GetName().AsCString (NULL);
1005 if (cstr)
1006 {
1007 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001008
1009 if (sc->block)
1010 {
1011 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1012 if (inline_block)
1013 {
1014 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1015 if (inline_info)
1016 {
1017 s.PutCString(" [inlined] ");
1018 inline_info->GetName().Dump(&s);
1019 }
1020 }
1021 }
Greg Clayton1b654882010-09-19 02:33:57 +00001022 var_success = true;
1023 }
1024 }
1025 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1026 {
1027 var_success = addr != NULL;
1028 if (var_success)
1029 {
1030 format_addr = *addr;
1031 calculate_format_addr_function_offset = true;
1032 }
1033 }
1034 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1035 {
1036 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1037 if (var_success)
1038 {
1039 format_addr = sc->line_entry.range.GetBaseAddress();
1040 calculate_format_addr_function_offset = true;
1041 }
1042 }
1043 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1044 {
1045 var_success = exe_ctx->frame;
1046 if (var_success)
1047 {
1048 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1049 calculate_format_addr_function_offset = true;
1050 }
1051 }
1052 }
1053 }
1054 break;
1055
1056 case 'l':
1057 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1058 {
1059 if (sc && sc->line_entry.IsValid())
1060 {
1061 var_name_begin += ::strlen ("line.");
1062 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1063 {
1064 var_name_begin += ::strlen ("file.");
1065
1066 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1067 {
1068 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1069 var_success = format_file_spec;
1070 }
1071 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1072 {
1073 format_file_spec = sc->line_entry.file;
1074 var_success = format_file_spec;
1075 }
1076 }
1077 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1078 {
1079 var_success = true;
1080 s.Printf("%u", sc->line_entry.line);
1081 }
1082 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1083 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1084 {
1085 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1086 if (var_success)
1087 {
1088 format_addr = sc->line_entry.range.GetBaseAddress();
1089 if (var_name_begin[0] == 'e')
1090 format_addr.Slide (sc->line_entry.range.GetByteSize());
1091 }
1092 }
1093 }
1094 }
1095 break;
1096 }
1097
1098 if (var_success)
1099 {
1100 // If format addr is valid, then we need to print an address
1101 if (reg_num != LLDB_INVALID_REGNUM)
1102 {
1103 // We have a register value to display...
1104 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1105 {
1106 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1107 }
1108 else
1109 {
1110 if (reg_ctx == NULL)
Greg Clayton5ccbd292011-01-06 22:15:06 +00001111 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001112
1113 if (reg_ctx)
1114 {
1115 if (reg_kind != kNumRegisterKinds)
1116 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1117 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1118 var_success = reg_info != NULL;
1119 }
1120 }
1121 }
1122
1123 if (reg_info != NULL)
1124 {
1125 DataExtractor reg_data;
1126 var_success = reg_ctx->ReadRegisterBytes (reg_info->kinds[eRegisterKindLLDB], reg_data);
1127 {
1128 reg_data.Dump(&s, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
1129 }
1130 }
1131
1132 if (format_file_spec)
1133 {
1134 s << format_file_spec;
1135 }
1136
1137 // If format addr is valid, then we need to print an address
1138 if (format_addr.IsValid())
1139 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001140 var_success = false;
1141
Greg Clayton1b654882010-09-19 02:33:57 +00001142 if (calculate_format_addr_function_offset)
1143 {
1144 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001145
Greg Clayton0603aa92010-10-04 01:05:56 +00001146 if (sc)
1147 {
1148 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001149 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001150 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001151 if (sc->block)
1152 {
1153 // Check to make sure we aren't in an inline
1154 // function. If we are, use the inline block
1155 // range that contains "format_addr" since
1156 // blocks can be discontiguous.
1157 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1158 AddressRange inline_range;
1159 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1160 func_addr = inline_range.GetBaseAddress();
1161 }
1162 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001163 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1164 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1165 }
1166
1167 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001168 {
1169 if (func_addr.GetSection() == format_addr.GetSection())
1170 {
1171 addr_t func_file_addr = func_addr.GetFileAddress();
1172 addr_t addr_file_addr = format_addr.GetFileAddress();
1173 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001174 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001175 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001176 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001177 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001178 }
1179 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001180 {
1181 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1182 if (target)
1183 {
1184 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1185 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1186 if (addr_load_addr > func_load_addr)
1187 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1188 else if (addr_load_addr < func_load_addr)
1189 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1190 var_success = true;
1191 }
1192 }
Greg Clayton1b654882010-09-19 02:33:57 +00001193 }
1194 }
1195 else
1196 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001197 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001198 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001199 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1200 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001201 if (vaddr == LLDB_INVALID_ADDRESS)
1202 vaddr = format_addr.GetFileAddress ();
1203
1204 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001205 {
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001206 int addr_width = 0;
1207 if (exe_ctx && exe_ctx->process)
1208 addr_width = exe_ctx->process->GetAddressByteSize() * 2;
1209 if (addr_width == 0)
1210 addr_width = 16;
1211 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001212 var_success = true;
1213 }
Greg Clayton1b654882010-09-19 02:33:57 +00001214 }
1215 }
1216 }
1217
1218 if (var_success == false)
1219 success = false;
1220 }
1221 p = var_name_end;
1222 }
1223 else
1224 break;
1225 }
1226 else
1227 {
1228 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1229 s.PutChar(*p);
1230 }
1231 }
1232 else if (*p == '\\')
1233 {
1234 ++p; // skip the slash
1235 switch (*p)
1236 {
1237 case 'a': s.PutChar ('\a'); break;
1238 case 'b': s.PutChar ('\b'); break;
1239 case 'f': s.PutChar ('\f'); break;
1240 case 'n': s.PutChar ('\n'); break;
1241 case 'r': s.PutChar ('\r'); break;
1242 case 't': s.PutChar ('\t'); break;
1243 case 'v': s.PutChar ('\v'); break;
1244 case '\'': s.PutChar ('\''); break;
1245 case '\\': s.PutChar ('\\'); break;
1246 case '0':
1247 // 1 to 3 octal chars
1248 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001249 // Make a string that can hold onto the initial zero char,
1250 // up to 3 octal digits, and a terminating NULL.
1251 char oct_str[5] = { 0, 0, 0, 0, 0 };
1252
1253 int i;
1254 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1255 oct_str[i] = p[i];
1256
1257 // We don't want to consume the last octal character since
1258 // the main for loop will do this for us, so we advance p by
1259 // one less than i (even if i is zero)
1260 p += i - 1;
1261 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
1262 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001263 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001264 char octal_char = octal_value;
1265 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00001266 }
Greg Clayton1b654882010-09-19 02:33:57 +00001267 }
1268 break;
1269
1270 case 'x':
1271 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00001272 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001273 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001274 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00001275
Greg Clayton0603aa92010-10-04 01:05:56 +00001276 // Make a string that can hold onto two hex chars plus a
1277 // NULL terminator
1278 char hex_str[3] = { 0,0,0 };
1279 hex_str[0] = *p;
1280 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001281 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001282 ++p; // Skip the first of the two hex chars
1283 hex_str[1] = *p;
1284 }
1285
1286 unsigned long hex_value = strtoul (hex_str, NULL, 16);
1287 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001288 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00001289 }
1290 else
1291 {
1292 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00001293 }
1294 break;
1295
1296 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00001297 // Just desensitize any other character by just printing what
1298 // came after the '\'
1299 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00001300 break;
1301
1302 }
1303
1304 }
1305 }
1306 if (end)
1307 *end = p;
1308 return success;
1309}
1310
1311#pragma mark Debugger::SettingsController
1312
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001313//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001314// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001315//--------------------------------------------------
1316
Greg Clayton1b654882010-09-19 02:33:57 +00001317Debugger::SettingsController::SettingsController () :
Caroline Tice101c7c22010-09-09 06:25:08 +00001318 UserSettingsController ("", lldb::UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001319{
Caroline Tice91123da2010-09-08 17:48:55 +00001320 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
1321 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001322}
1323
Greg Clayton1b654882010-09-19 02:33:57 +00001324Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001325{
1326}
1327
1328
1329lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00001330Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001331{
Greg Claytondbe54502010-11-19 03:46:01 +00001332 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00001333 false, instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001334 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1335 return new_settings_sp;
1336}
1337
Greg Clayton1b654882010-09-19 02:33:57 +00001338#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001339//--------------------------------------------------
1340// class DebuggerInstanceSettings
1341//--------------------------------------------------
1342
Greg Claytona7015092010-09-18 01:14:36 +00001343DebuggerInstanceSettings::DebuggerInstanceSettings
1344(
1345 UserSettingsController &owner,
1346 bool live_instance,
1347 const char *name
1348) :
Greg Clayton85851dd2010-12-04 00:10:17 +00001349 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00001350 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001351 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00001352 m_frame_format (),
1353 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001354 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001355 m_use_external_editor (false),
1356 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001357{
Caroline Ticef20e8232010-09-09 18:26:37 +00001358 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1359 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
1360 // 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 +00001361 // The same is true of CreateInstanceName().
1362
1363 if (GetInstanceName() == InstanceSettings::InvalidName())
1364 {
1365 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1366 m_owner.RegisterInstanceSettings (this);
1367 }
Caroline Ticef20e8232010-09-09 18:26:37 +00001368
1369 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001370 {
1371 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1372 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001373 }
1374}
1375
1376DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00001377 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001378 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00001379 m_frame_format (rhs.m_frame_format),
1380 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001381 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001382 m_use_external_editor (rhs.m_use_external_editor),
1383 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001384{
1385 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1386 CopyInstanceSettings (pending_settings, false);
1387 m_owner.RemovePendingSettings (m_instance_name);
1388}
1389
1390DebuggerInstanceSettings::~DebuggerInstanceSettings ()
1391{
1392}
1393
1394DebuggerInstanceSettings&
1395DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
1396{
1397 if (this != &rhs)
1398 {
Greg Clayton1b654882010-09-19 02:33:57 +00001399 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001400 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00001401 m_frame_format = rhs.m_frame_format;
1402 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001403 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001404 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001405 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001406 }
1407
1408 return *this;
1409}
1410
Greg Clayton1b654882010-09-19 02:33:57 +00001411bool
1412DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
1413{
1414 bool valid = false;
1415
1416 // Verify we have a value string.
1417 if (value == NULL || value[0] == '\0')
1418 {
1419 err.SetErrorString ("Missing value. Can't set terminal width without a value.\n");
1420 }
1421 else
1422 {
1423 char *end = NULL;
1424 const uint32_t width = ::strtoul (value, &end, 0);
1425
Johnny Chenea9fc182010-09-20 16:36:43 +00001426 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00001427 {
Johnny Chen433d7742010-09-20 17:04:41 +00001428 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00001429 valid = true;
1430 else
1431 err.SetErrorString ("Invalid term-width value; value must be between 10 and 1024.\n");
1432 }
1433 else
1434 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string.\n", value);
1435 }
1436
1437 return valid;
1438}
1439
1440
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001441void
1442DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1443 const char *index_value,
1444 const char *value,
1445 const ConstString &instance_name,
1446 const SettingEntry &entry,
1447 lldb::VarSetOperationType op,
1448 Error &err,
1449 bool pending)
1450{
Greg Clayton0603aa92010-10-04 01:05:56 +00001451
1452 if (var_name == TermWidthVarName())
1453 {
1454 if (ValidTermWidthValue (value, err))
1455 {
1456 m_term_width = ::strtoul (value, NULL, 0);
1457 }
1458 }
1459 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001460 {
Caroline Tice101c7c22010-09-09 06:25:08 +00001461 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001462 if (!pending)
1463 {
Caroline Tice49e27372010-09-07 18:35:40 +00001464 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1465 // strip off the brackets before passing it to BroadcastPromptChange.
1466
1467 std::string tmp_instance_name (instance_name.AsCString());
1468 if ((tmp_instance_name[0] == '[')
1469 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
1470 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
1471 ConstString new_name (tmp_instance_name.c_str());
1472
1473 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001474 }
1475 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001476 else if (var_name == GetFrameFormatName())
1477 {
1478 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
1479 }
1480 else if (var_name == GetThreadFormatName())
1481 {
1482 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
1483 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001484 else if (var_name == ScriptLangVarName())
1485 {
1486 bool success;
1487 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
1488 &success);
1489 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001490 else if (var_name == UseExternalEditorVarName ())
1491 {
1492 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, err);
1493 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001494 else if (var_name == AutoConfirmName ())
1495 {
1496 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, err);
1497 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001498}
1499
Caroline Tice12cecd72010-09-20 21:37:42 +00001500bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001501DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1502 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00001503 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00001504 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001505{
1506 if (var_name == PromptVarName())
1507 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001508 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001509
1510 }
1511 else if (var_name == ScriptLangVarName())
1512 {
1513 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
1514 }
Caroline Tice101c7c22010-09-09 06:25:08 +00001515 else if (var_name == TermWidthVarName())
1516 {
1517 StreamString width_str;
1518 width_str.Printf ("%d", m_term_width);
1519 value.AppendString (width_str.GetData());
1520 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001521 else if (var_name == GetFrameFormatName ())
1522 {
1523 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
1524 }
1525 else if (var_name == GetThreadFormatName ())
1526 {
1527 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
1528 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001529 else if (var_name == UseExternalEditorVarName())
1530 {
1531 if (m_use_external_editor)
1532 value.AppendString ("true");
1533 else
1534 value.AppendString ("false");
1535 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001536 else if (var_name == AutoConfirmName())
1537 {
1538 if (m_auto_confirm_on)
1539 value.AppendString ("true");
1540 else
1541 value.AppendString ("false");
1542 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001543 else
Caroline Tice12cecd72010-09-20 21:37:42 +00001544 {
1545 if (err)
1546 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1547 return false;
1548 }
1549 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001550}
1551
1552void
1553DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1554 bool pending)
1555{
1556 if (new_settings.get() == NULL)
1557 return;
1558
1559 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
1560
1561 m_prompt = new_debugger_settings->m_prompt;
1562 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00001563 {
1564 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1565 // strip off the brackets before passing it to BroadcastPromptChange.
1566
1567 std::string tmp_instance_name (m_instance_name.AsCString());
1568 if ((tmp_instance_name[0] == '[')
1569 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
1570 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
1571 ConstString new_name (tmp_instance_name.c_str());
1572
1573 BroadcastPromptChange (new_name, m_prompt.c_str());
1574 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001575 m_frame_format = new_debugger_settings->m_frame_format;
1576 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001577 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001578 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001579 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001580 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001581}
1582
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001583
1584bool
1585DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
1586{
1587 std::string tmp_prompt;
1588
1589 if (new_prompt != NULL)
1590 {
1591 tmp_prompt = new_prompt ;
1592 int len = tmp_prompt.size();
1593 if (len > 1
1594 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
1595 && (tmp_prompt[len-1] == tmp_prompt[0]))
1596 {
1597 tmp_prompt = tmp_prompt.substr(1,len-2);
1598 }
1599 len = tmp_prompt.size();
1600 if (tmp_prompt[len-1] != ' ')
1601 tmp_prompt.append(" ");
1602 }
1603 EventSP new_event_sp;
1604 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
1605 new EventDataBytes (tmp_prompt.c_str())));
1606
1607 if (instance_name.GetLength() != 0)
1608 {
1609 // Set prompt for a particular instance.
1610 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
1611 if (dbg != NULL)
1612 {
1613 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
1614 }
1615 }
1616
1617 return true;
1618}
1619
1620const ConstString
1621DebuggerInstanceSettings::CreateInstanceName ()
1622{
1623 static int instance_count = 1;
1624 StreamString sstr;
1625
1626 sstr.Printf ("debugger_%d", instance_count);
1627 ++instance_count;
1628
1629 const ConstString ret_val (sstr.GetData());
1630
1631 return ret_val;
1632}
1633
1634const ConstString &
1635DebuggerInstanceSettings::PromptVarName ()
1636{
1637 static ConstString prompt_var_name ("prompt");
1638
1639 return prompt_var_name;
1640}
1641
1642const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00001643DebuggerInstanceSettings::GetFrameFormatName ()
1644{
1645 static ConstString prompt_var_name ("frame-format");
1646
1647 return prompt_var_name;
1648}
1649
1650const ConstString &
1651DebuggerInstanceSettings::GetThreadFormatName ()
1652{
1653 static ConstString prompt_var_name ("thread-format");
1654
1655 return prompt_var_name;
1656}
1657
1658const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001659DebuggerInstanceSettings::ScriptLangVarName ()
1660{
1661 static ConstString script_lang_var_name ("script-lang");
1662
1663 return script_lang_var_name;
1664}
1665
Caroline Tice101c7c22010-09-09 06:25:08 +00001666const ConstString &
1667DebuggerInstanceSettings::TermWidthVarName ()
1668{
1669 static ConstString term_width_var_name ("term-width");
1670
1671 return term_width_var_name;
1672}
1673
Caroline Ticedaccaa92010-09-20 20:44:43 +00001674const ConstString &
1675DebuggerInstanceSettings::UseExternalEditorVarName ()
1676{
1677 static ConstString use_external_editor_var_name ("use-external-editor");
1678
1679 return use_external_editor_var_name;
1680}
1681
Jim Ingham3bcdb292010-10-04 22:44:14 +00001682const ConstString &
1683DebuggerInstanceSettings::AutoConfirmName ()
1684{
1685 static ConstString use_external_editor_var_name ("auto-confirm");
1686
1687 return use_external_editor_var_name;
1688}
1689
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001690//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001691// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001692//--------------------------------------------------
1693
1694
1695SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001696Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001697{
1698 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00001699 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
1700 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001701 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1702};
1703
Greg Claytonbb562b12010-10-04 02:44:26 +00001704#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00001705#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001706
Greg Clayton0603aa92010-10-04 01:05:56 +00001707#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1708 "{, ${frame.pc}}"\
1709 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00001710 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00001711 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00001712 "\\n"
1713
Greg Clayton315d2ca2010-11-02 01:53:21 +00001714//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1715// "{, ${frame.pc}}"\
1716// MODULE_WITH_FUNC\
1717// FILE_AND_LINE\
1718// "{, stop reason = ${thread.stop-reason}}"\
1719// "{, name = ${thread.name}}"\
1720// "{, queue = ${thread.queue}}"\
1721// "\\n"
1722
Greg Clayton0603aa92010-10-04 01:05:56 +00001723#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
1724 MODULE_WITH_FUNC\
1725 FILE_AND_LINE\
1726 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001727
1728SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001729Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001730{
Greg Clayton0603aa92010-10-04 01:05:56 +00001731// NAME Setting variable type Default Enum Init'd Hidden Help
1732// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00001733{ "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 +00001734{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00001735{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
1736{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001737{ "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 +00001738{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
1739{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001740{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001741};