blob: 18dcd82e3508819cd8bac69406738b910b951b19 [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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062void
63Debugger::Initialize ()
64{
Greg Clayton66111032010-06-23 01:19:29 +000065 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +000066 {
Greg Clayton99d0faf2010-11-18 23:32:35 +000067 UserSettingsControllerSP &usc = GetSettingsController();
68 usc.reset (new SettingsController);
69 UserSettingsController::InitializeSettingsController (usc,
70 SettingsController::global_settings_table,
71 SettingsController::instance_settings_table);
Greg Claytondbe54502010-11-19 03:46:01 +000072 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +000073 }
Greg Clayton66111032010-06-23 01:19:29 +000074 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +000075
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076}
77
78void
79Debugger::Terminate ()
80{
Greg Clayton66111032010-06-23 01:19:29 +000081 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082 {
Greg Clayton66111032010-06-23 01:19:29 +000083 g_shared_debugger_refcount--;
84 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085 {
Greg Claytondbe54502010-11-19 03:46:01 +000086 lldb_private::WillTerminate();
87 lldb_private::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +000088 UserSettingsControllerSP &usc = GetSettingsController();
89 UserSettingsController::FinalizeSettingsController (usc);
90 usc.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092 }
Greg Clayton99d0faf2010-11-18 23:32:35 +000093 // Clear our master list of debugger objects
94 Mutex::Locker locker (GetDebuggerListMutex ());
95 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096}
97
Greg Clayton66111032010-06-23 01:19:29 +000098DebuggerSP
99Debugger::CreateInstance ()
100{
101 DebuggerSP debugger_sp (new Debugger);
102 // Scope for locker
103 {
104 Mutex::Locker locker (GetDebuggerListMutex ());
105 GetDebuggerList().push_back(debugger_sp);
106 }
107 return debugger_sp;
108}
109
110lldb::DebuggerSP
111Debugger::GetSP ()
112{
113 lldb::DebuggerSP debugger_sp;
114
115 Mutex::Locker locker (GetDebuggerListMutex ());
116 DebuggerList &debugger_list = GetDebuggerList();
117 DebuggerList::iterator pos, end = debugger_list.end();
118 for (pos = debugger_list.begin(); pos != end; ++pos)
119 {
120 if ((*pos).get() == this)
121 {
122 debugger_sp = *pos;
123 break;
124 }
125 }
126 return debugger_sp;
127}
128
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000129lldb::DebuggerSP
130Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
131{
132 lldb::DebuggerSP debugger_sp;
133
134 Mutex::Locker locker (GetDebuggerListMutex ());
135 DebuggerList &debugger_list = GetDebuggerList();
136 DebuggerList::iterator pos, end = debugger_list.end();
137
138 for (pos = debugger_list.begin(); pos != end; ++pos)
139 {
140 if ((*pos).get()->m_instance_name == instance_name)
141 {
142 debugger_sp = *pos;
143 break;
144 }
145 }
146 return debugger_sp;
147}
Greg Clayton66111032010-06-23 01:19:29 +0000148
149TargetSP
150Debugger::FindTargetWithProcessID (lldb::pid_t pid)
151{
152 lldb::TargetSP target_sp;
153 Mutex::Locker locker (GetDebuggerListMutex ());
154 DebuggerList &debugger_list = GetDebuggerList();
155 DebuggerList::iterator pos, end = debugger_list.end();
156 for (pos = debugger_list.begin(); pos != end; ++pos)
157 {
158 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
159 if (target_sp)
160 break;
161 }
162 return target_sp;
163}
164
165
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000167 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000168 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000169 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170 m_input_file (),
171 m_output_file (),
172 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000173 m_target_list (),
174 m_listener ("lldb.Debugger"),
175 m_source_manager (),
Greg Clayton66111032010-06-23 01:19:29 +0000176 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
177 m_exe_ctx (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178 m_input_readers (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000179 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000180{
Greg Claytond46c87a2010-12-04 02:39:47 +0000181 m_input_comm.SetCloseOnEOF(false);
Greg Clayton66111032010-06-23 01:19:29 +0000182 m_command_interpreter_ap->Initialize ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183}
184
185Debugger::~Debugger ()
186{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000187 CleanUpInputReaders();
Greg Clayton66111032010-06-23 01:19:29 +0000188 int num_targets = m_target_list.GetNumTargets();
189 for (int i = 0; i < num_targets; i++)
190 {
191 ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
192 if (process_sp)
193 process_sp->Destroy();
194 }
195 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196}
197
198
199bool
200Debugger::GetAsyncExecution ()
201{
Greg Clayton66111032010-06-23 01:19:29 +0000202 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000203}
204
205void
206Debugger::SetAsyncExecution (bool async_execution)
207{
Greg Clayton66111032010-06-23 01:19:29 +0000208 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000209}
210
211void
212Debugger::DisconnectInput()
213{
214 m_input_comm.Clear ();
215}
216
217void
218Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
219{
220 m_input_file.SetFileHandle (fh, tranfer_ownership);
221 if (m_input_file.GetFileHandle() == NULL)
222 m_input_file.SetFileHandle (stdin, false);
223
224 // Disconnect from any old connection if we had one
225 m_input_comm.Disconnect ();
226 m_input_comm.SetConnection (new ConnectionFileDescriptor (::fileno (GetInputFileHandle()), true));
227 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
228
229 Error error;
230 if (m_input_comm.StartReadThread (&error) == false)
231 {
232 FILE *err_fh = GetErrorFileHandle();
233 if (err_fh)
234 {
235 ::fprintf (err_fh, "error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
236 exit(1);
237 }
238 }
239
240}
241
242FILE *
243Debugger::GetInputFileHandle ()
244{
245 return m_input_file.GetFileHandle();
246}
247
248
249void
250Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
251{
252 m_output_file.SetFileHandle (fh, tranfer_ownership);
253 if (m_output_file.GetFileHandle() == NULL)
254 m_output_file.SetFileHandle (stdin, false);
255}
256
257FILE *
258Debugger::GetOutputFileHandle ()
259{
260 return m_output_file.GetFileHandle();
261}
262
263void
264Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
265{
266 m_error_file.SetFileHandle (fh, tranfer_ownership);
267 if (m_error_file.GetFileHandle() == NULL)
268 m_error_file.SetFileHandle (stdin, false);
269}
270
271
272FILE *
273Debugger::GetErrorFileHandle ()
274{
275 return m_error_file.GetFileHandle();
276}
277
278CommandInterpreter &
279Debugger::GetCommandInterpreter ()
280{
Greg Clayton66111032010-06-23 01:19:29 +0000281 assert (m_command_interpreter_ap.get());
282 return *m_command_interpreter_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283}
284
285Listener &
286Debugger::GetListener ()
287{
288 return m_listener;
289}
290
291
292TargetSP
Jim Ingham2976d002010-08-26 21:32:51 +0000293Debugger::GetSelectedTarget ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000294{
Jim Ingham2976d002010-08-26 21:32:51 +0000295 return m_target_list.GetSelectedTarget ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000296}
297
298ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000299Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300{
301 ExecutionContext exe_ctx;
302 exe_ctx.Clear();
303
Jim Ingham2976d002010-08-26 21:32:51 +0000304 lldb::TargetSP target_sp = GetSelectedTarget();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000305 exe_ctx.target = target_sp.get();
306
307 if (target_sp)
308 {
309 exe_ctx.process = target_sp->GetProcessSP().get();
310 if (exe_ctx.process && exe_ctx.process->IsRunning() == false)
311 {
Jim Ingham2976d002010-08-26 21:32:51 +0000312 exe_ctx.thread = exe_ctx.process->GetThreadList().GetSelectedThread().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313 if (exe_ctx.thread == NULL)
314 exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
315 if (exe_ctx.thread)
316 {
Jim Ingham2976d002010-08-26 21:32:51 +0000317 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000318 if (exe_ctx.frame == NULL)
319 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex (0).get();
320 }
321 }
322 }
323 return exe_ctx;
324
325}
326
327SourceManager &
328Debugger::GetSourceManager ()
329{
330 return m_source_manager;
331}
332
333
334TargetList&
335Debugger::GetTargetList ()
336{
337 return m_target_list;
338}
339
340void
341Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
342{
Caroline Ticeefed6132010-11-19 20:47:54 +0000343 if (bytes_len > 0)
344 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
345 else
346 ((Debugger *)baton)->DispatchInputEndOfFile ();
347}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348
349
350void
351Debugger::DispatchInput (const char *bytes, size_t bytes_len)
352{
Caroline Ticeefed6132010-11-19 20:47:54 +0000353 if (bytes == NULL || bytes_len == 0)
354 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355
356 WriteToDefaultReader (bytes, bytes_len);
357}
358
359void
Caroline Ticeefed6132010-11-19 20:47:54 +0000360Debugger::DispatchInputInterrupt ()
361{
362 m_input_reader_data.clear();
363
364 if (!m_input_readers.empty())
365 {
366 while (CheckIfTopInputReaderIsDone ()) ;
367
368 InputReaderSP reader_sp(m_input_readers.top());
369 if (reader_sp)
370 reader_sp->Notify (eInputReaderInterrupt);
371
372 while (CheckIfTopInputReaderIsDone ()) ;
373 }
374}
375
376void
377Debugger::DispatchInputEndOfFile ()
378{
379 m_input_reader_data.clear();
380
381 if (!m_input_readers.empty())
382 {
383 while (CheckIfTopInputReaderIsDone ()) ;
384
385 InputReaderSP reader_sp(m_input_readers.top());
386 if (reader_sp)
387 reader_sp->Notify (eInputReaderEndOfFile);
388
389 while (CheckIfTopInputReaderIsDone ()) ;
390 }
391}
392
393void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000394Debugger::CleanUpInputReaders ()
395{
396 m_input_reader_data.clear();
397
398 while (m_input_readers.size() > 1)
399 {
400 while (CheckIfTopInputReaderIsDone ()) ;
401
402 InputReaderSP reader_sp (m_input_readers.top());
403 if (reader_sp)
404 {
405 reader_sp->Notify (eInputReaderEndOfFile);
406 reader_sp->SetIsDone (true);
407 }
408 }
409}
410
411void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
413{
414 if (bytes && bytes_len)
415 m_input_reader_data.append (bytes, bytes_len);
416
417 if (m_input_reader_data.empty())
418 return;
419
420 while (!m_input_readers.empty() && !m_input_reader_data.empty())
421 {
422 while (CheckIfTopInputReaderIsDone ())
423 /* Do nothing. */;
424
425 // Get the input reader from the top of the stack
426 InputReaderSP reader_sp(m_input_readers.top());
427
428 if (!reader_sp)
429 break;
430
Greg Clayton471b31c2010-07-20 22:52:08 +0000431 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432 m_input_reader_data.size());
433 if (bytes_handled)
434 {
435 m_input_reader_data.erase (0, bytes_handled);
436 }
437 else
438 {
439 // No bytes were handled, we might not have reached our
440 // granularity, just return and wait for more data
441 break;
442 }
443 }
444
445 // Flush out any input readers that are donesvn
446 while (CheckIfTopInputReaderIsDone ())
447 /* Do nothing. */;
448
449}
450
451void
452Debugger::PushInputReader (const InputReaderSP& reader_sp)
453{
454 if (!reader_sp)
455 return;
456 if (!m_input_readers.empty())
457 {
458 // Deactivate the old top reader
459 InputReaderSP top_reader_sp (m_input_readers.top());
460 if (top_reader_sp)
461 top_reader_sp->Notify (eInputReaderDeactivate);
462 }
463 m_input_readers.push (reader_sp);
464 reader_sp->Notify (eInputReaderActivate);
465 ActivateInputReader (reader_sp);
466}
467
468bool
469Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp)
470{
471 bool result = false;
472
473 // The reader on the stop of the stack is done, so let the next
474 // read on the stack referesh its prompt and if there is one...
475 if (!m_input_readers.empty())
476 {
477 InputReaderSP reader_sp(m_input_readers.top());
478
479 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
480 {
481 m_input_readers.pop ();
482 reader_sp->Notify (eInputReaderDeactivate);
483 reader_sp->Notify (eInputReaderDone);
484 result = true;
485
486 if (!m_input_readers.empty())
487 {
488 reader_sp = m_input_readers.top();
489 if (reader_sp)
490 {
491 ActivateInputReader (reader_sp);
492 reader_sp->Notify (eInputReaderReactivate);
493 }
494 }
495 }
496 }
497 return result;
498}
499
500bool
501Debugger::CheckIfTopInputReaderIsDone ()
502{
503 bool result = false;
504 if (!m_input_readers.empty())
505 {
506 InputReaderSP reader_sp(m_input_readers.top());
507
508 if (reader_sp && reader_sp->IsDone())
509 {
510 result = true;
511 PopInputReader (reader_sp);
512 }
513 }
514 return result;
515}
516
517void
518Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
519{
520 FILE *in_fh = GetInputFileHandle();
521
522 if (in_fh)
523 {
524 struct termios in_fh_termios;
525 int in_fd = fileno (in_fh);
526 if (::tcgetattr(in_fd, &in_fh_termios) == 0)
527 {
528 if (reader_sp->GetEcho())
529 in_fh_termios.c_lflag |= ECHO; // Turn on echoing
530 else
531 in_fh_termios.c_lflag &= ~ECHO; // Turn off echoing
532
533 switch (reader_sp->GetGranularity())
534 {
535 case eInputReaderGranularityByte:
536 case eInputReaderGranularityWord:
537 in_fh_termios.c_lflag &= ~ICANON; // Get one char at a time
538 break;
539
540 case eInputReaderGranularityLine:
541 case eInputReaderGranularityAll:
542 in_fh_termios.c_lflag |= ICANON; // Get lines at a time
543 break;
544
545 default:
546 break;
547 }
548 ::tcsetattr (in_fd, TCSANOW, &in_fh_termios);
549 }
550 }
551}
Greg Clayton66111032010-06-23 01:19:29 +0000552
553void
554Debugger::UpdateExecutionContext (ExecutionContext *override_context)
555{
556 m_exe_ctx.Clear();
557
558 if (override_context != NULL)
559 {
560 m_exe_ctx.target = override_context->target;
561 m_exe_ctx.process = override_context->process;
562 m_exe_ctx.thread = override_context->thread;
563 m_exe_ctx.frame = override_context->frame;
564 }
565 else
566 {
Jim Ingham2976d002010-08-26 21:32:51 +0000567 TargetSP target_sp (GetSelectedTarget());
Greg Clayton66111032010-06-23 01:19:29 +0000568 if (target_sp)
569 {
570 m_exe_ctx.target = target_sp.get();
571 m_exe_ctx.process = target_sp->GetProcessSP().get();
Johnny Chen725945d2010-09-03 22:35:47 +0000572 if (m_exe_ctx.process && m_exe_ctx.process->IsAlive() && !m_exe_ctx.process->IsRunning())
Greg Clayton66111032010-06-23 01:19:29 +0000573 {
Jim Ingham2976d002010-08-26 21:32:51 +0000574 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetSelectedThread().get();
Greg Clayton66111032010-06-23 01:19:29 +0000575 if (m_exe_ctx.thread == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000576 {
Greg Clayton66111032010-06-23 01:19:29 +0000577 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000578 // If we didn't have a selected thread, select one here.
579 if (m_exe_ctx.thread != NULL)
Johnny Chenc13ee522010-09-14 00:53:53 +0000580 m_exe_ctx.process->GetThreadList().SetSelectedThreadByID(m_exe_ctx.thread->GetID());
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000581 }
Greg Clayton66111032010-06-23 01:19:29 +0000582 if (m_exe_ctx.thread)
583 {
Jim Ingham2976d002010-08-26 21:32:51 +0000584 m_exe_ctx.frame = m_exe_ctx.thread->GetSelectedFrame().get();
Greg Clayton66111032010-06-23 01:19:29 +0000585 if (m_exe_ctx.frame == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000586 {
Greg Clayton66111032010-06-23 01:19:29 +0000587 m_exe_ctx.frame = m_exe_ctx.thread->GetStackFrameAtIndex (0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000588 // If we didn't have a selected frame select one here.
589 if (m_exe_ctx.frame != NULL)
590 m_exe_ctx.thread->SetSelectedFrame(m_exe_ctx.frame);
591 }
Greg Clayton66111032010-06-23 01:19:29 +0000592 }
593 }
594 }
595 }
596}
597
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000598DebuggerSP
599Debugger::FindDebuggerWithID (lldb::user_id_t id)
600{
601 lldb::DebuggerSP debugger_sp;
602
603 Mutex::Locker locker (GetDebuggerListMutex ());
604 DebuggerList &debugger_list = GetDebuggerList();
605 DebuggerList::iterator pos, end = debugger_list.end();
606 for (pos = debugger_list.begin(); pos != end; ++pos)
607 {
608 if ((*pos).get()->GetID() == id)
609 {
610 debugger_sp = *pos;
611 break;
612 }
613 }
614 return debugger_sp;
615}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000616
Greg Clayton1b654882010-09-19 02:33:57 +0000617static void
618TestPromptFormats (StackFrame *frame)
619{
620 if (frame == NULL)
621 return;
622
623 StreamString s;
624 const char *prompt_format =
625 "{addr = '${addr}'\n}"
626 "{process.id = '${process.id}'\n}"
627 "{process.name = '${process.name}'\n}"
628 "{process.file.basename = '${process.file.basename}'\n}"
629 "{process.file.fullpath = '${process.file.fullpath}'\n}"
630 "{thread.id = '${thread.id}'\n}"
631 "{thread.index = '${thread.index}'\n}"
632 "{thread.name = '${thread.name}'\n}"
633 "{thread.queue = '${thread.queue}'\n}"
634 "{thread.stop-reason = '${thread.stop-reason}'\n}"
635 "{target.arch = '${target.arch}'\n}"
636 "{module.file.basename = '${module.file.basename}'\n}"
637 "{module.file.fullpath = '${module.file.fullpath}'\n}"
638 "{file.basename = '${file.basename}'\n}"
639 "{file.fullpath = '${file.fullpath}'\n}"
640 "{frame.index = '${frame.index}'\n}"
641 "{frame.pc = '${frame.pc}'\n}"
642 "{frame.sp = '${frame.sp}'\n}"
643 "{frame.fp = '${frame.fp}'\n}"
644 "{frame.flags = '${frame.flags}'\n}"
645 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
646 "{frame.reg.rip = '${frame.reg.rip}'\n}"
647 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
648 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
649 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
650 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
651 "{frame.reg.carp = '${frame.reg.carp}'\n}"
652 "{function.id = '${function.id}'\n}"
653 "{function.name = '${function.name}'\n}"
654 "{function.addr-offset = '${function.addr-offset}'\n}"
655 "{function.line-offset = '${function.line-offset}'\n}"
656 "{function.pc-offset = '${function.pc-offset}'\n}"
657 "{line.file.basename = '${line.file.basename}'\n}"
658 "{line.file.fullpath = '${line.file.fullpath}'\n}"
659 "{line.number = '${line.number}'\n}"
660 "{line.start-addr = '${line.start-addr}'\n}"
661 "{line.end-addr = '${line.end-addr}'\n}"
662;
663
664 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
665 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000666 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000667 const char *end = NULL;
668 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
669 {
670 printf("%s\n", s.GetData());
671 }
672 else
673 {
674 printf ("error: at '%s'\n", end);
675 printf ("what we got: %s\n", s.GetData());
676 }
677}
678
679bool
680Debugger::FormatPrompt
681(
682 const char *format,
683 const SymbolContext *sc,
684 const ExecutionContext *exe_ctx,
685 const Address *addr,
686 Stream &s,
687 const char **end
688)
689{
690 bool success = true;
691 const char *p;
692 for (p = format; *p != '\0'; ++p)
693 {
694 size_t non_special_chars = ::strcspn (p, "${}\\");
695 if (non_special_chars > 0)
696 {
697 if (success)
698 s.Write (p, non_special_chars);
699 p += non_special_chars;
700 }
701
702 if (*p == '\0')
703 {
704 break;
705 }
706 else if (*p == '{')
707 {
708 // Start a new scope that must have everything it needs if it is to
709 // to make it into the final output stream "s". If you want to make
710 // a format that only prints out the function or symbol name if there
711 // is one in the symbol context you can use:
712 // "{function =${function.name}}"
713 // The first '{' starts a new scope that end with the matching '}' at
714 // the end of the string. The contents "function =${function.name}"
715 // will then be evaluated and only be output if there is a function
716 // or symbol with a valid name.
717 StreamString sub_strm;
718
719 ++p; // Skip the '{'
720
721 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p))
722 {
723 // The stream had all it needed
724 s.Write(sub_strm.GetData(), sub_strm.GetSize());
725 }
726 if (*p != '}')
727 {
728 success = false;
729 break;
730 }
731 }
732 else if (*p == '}')
733 {
734 // End of a enclosing scope
735 break;
736 }
737 else if (*p == '$')
738 {
739 // We have a prompt variable to print
740 ++p;
741 if (*p == '{')
742 {
743 ++p;
744 const char *var_name_begin = p;
745 const char *var_name_end = ::strchr (p, '}');
746
747 if (var_name_end && var_name_begin < var_name_end)
748 {
749 // if we have already failed to parse, skip this variable
750 if (success)
751 {
752 const char *cstr = NULL;
753 Address format_addr;
754 bool calculate_format_addr_function_offset = false;
755 // Set reg_kind and reg_num to invalid values
756 RegisterKind reg_kind = kNumRegisterKinds;
757 uint32_t reg_num = LLDB_INVALID_REGNUM;
758 FileSpec format_file_spec;
759 const lldb::RegisterInfo *reg_info = NULL;
760 RegisterContext *reg_ctx = NULL;
761
762 // Each variable must set success to true below...
763 bool var_success = false;
764 switch (var_name_begin[0])
765 {
766 case 'a':
767 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
768 {
769 if (addr && addr->IsValid())
770 {
771 var_success = true;
772 format_addr = *addr;
773 }
774 }
775 break;
776
777 case 'p':
778 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
779 {
780 if (exe_ctx && exe_ctx->process != NULL)
781 {
782 var_name_begin += ::strlen ("process.");
783 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
784 {
785 s.Printf("%i", exe_ctx->process->GetID());
786 var_success = true;
787 }
788 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
789 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
790 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
791 {
792 ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
793 if (exe_module_sp)
794 {
795 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
796 {
797 format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
798 var_success = format_file_spec;
799 }
800 else
801 {
802 format_file_spec = exe_module_sp->GetFileSpec();
803 var_success = format_file_spec;
804 }
805 }
806 }
807 }
808 }
809 break;
810
811 case 't':
812 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
813 {
814 if (exe_ctx && exe_ctx->thread)
815 {
816 var_name_begin += ::strlen ("thread.");
817 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
818 {
819 s.Printf("0x%4.4x", exe_ctx->thread->GetID());
820 var_success = true;
821 }
822 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
823 {
824 s.Printf("%u", exe_ctx->thread->GetIndexID());
825 var_success = true;
826 }
827 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
828 {
829 cstr = exe_ctx->thread->GetName();
830 var_success = cstr && cstr[0];
831 if (var_success)
832 s.PutCString(cstr);
833 }
834 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
835 {
836 cstr = exe_ctx->thread->GetQueueName();
837 var_success = cstr && cstr[0];
838 if (var_success)
839 s.PutCString(cstr);
840 }
841 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
842 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000843 StopInfoSP stop_info_sp = exe_ctx->thread->GetStopInfo ();
844 if (stop_info_sp)
Greg Clayton1b654882010-09-19 02:33:57 +0000845 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000846 cstr = stop_info_sp->GetDescription();
Greg Clayton1b654882010-09-19 02:33:57 +0000847 if (cstr && cstr[0])
848 {
849 s.PutCString(cstr);
850 var_success = true;
851 }
852 }
853 }
854 }
855 }
856 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
857 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000858 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
859 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +0000860 {
Greg Clayton1b654882010-09-19 02:33:57 +0000861 var_name_begin += ::strlen ("target.");
862 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
863 {
864 ArchSpec arch (target->GetArchitecture ());
865 if (arch.IsValid())
866 {
867 s.PutCString (arch.AsCString());
868 var_success = true;
869 }
870 }
871 }
872 }
873 break;
874
875
876 case 'm':
877 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
878 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000879 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +0000880 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000881 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +0000882 var_name_begin += ::strlen ("module.");
883
884 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
885 {
886 if (module->GetFileSpec())
887 {
888 var_name_begin += ::strlen ("file.");
889
890 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
891 {
892 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
893 var_success = format_file_spec;
894 }
895 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
896 {
897 format_file_spec = module->GetFileSpec();
898 var_success = format_file_spec;
899 }
900 }
901 }
902 }
903 }
904 break;
905
906
907 case 'f':
908 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
909 {
910 if (sc && sc->comp_unit != NULL)
911 {
912 var_name_begin += ::strlen ("file.");
913
914 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
915 {
916 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
917 var_success = format_file_spec;
918 }
919 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
920 {
921 format_file_spec = *sc->comp_unit;
922 var_success = format_file_spec;
923 }
924 }
925 }
926 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
927 {
928 if (exe_ctx && exe_ctx->frame)
929 {
930 var_name_begin += ::strlen ("frame.");
931 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
932 {
933 s.Printf("%u", exe_ctx->frame->GetFrameIndex());
934 var_success = true;
935 }
936 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
937 {
938 reg_kind = eRegisterKindGeneric;
939 reg_num = LLDB_REGNUM_GENERIC_PC;
940 var_success = true;
941 }
942 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
943 {
944 reg_kind = eRegisterKindGeneric;
945 reg_num = LLDB_REGNUM_GENERIC_SP;
946 var_success = true;
947 }
948 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
949 {
950 reg_kind = eRegisterKindGeneric;
951 reg_num = LLDB_REGNUM_GENERIC_FP;
952 var_success = true;
953 }
954 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
955 {
956 reg_kind = eRegisterKindGeneric;
957 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
958 var_success = true;
959 }
960 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
961 {
Greg Clayton5ccbd292011-01-06 22:15:06 +0000962 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +0000963 if (reg_ctx)
964 {
965 var_name_begin += ::strlen ("reg.");
966 if (var_name_begin < var_name_end)
967 {
968 std::string reg_name (var_name_begin, var_name_end);
969 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
970 if (reg_info)
971 var_success = true;
972 }
973 }
974 }
975 }
976 }
977 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
978 {
979 if (sc && (sc->function != NULL || sc->symbol != NULL))
980 {
981 var_name_begin += ::strlen ("function.");
982 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
983 {
984 if (sc->function)
985 s.Printf("function{0x%8.8x}", sc->function->GetID());
986 else
987 s.Printf("symbol[%u]", sc->symbol->GetID());
988
989 var_success = true;
990 }
991 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
992 {
993 if (sc->function)
994 cstr = sc->function->GetName().AsCString (NULL);
995 else if (sc->symbol)
996 cstr = sc->symbol->GetName().AsCString (NULL);
997 if (cstr)
998 {
999 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001000
1001 if (sc->block)
1002 {
1003 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1004 if (inline_block)
1005 {
1006 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1007 if (inline_info)
1008 {
1009 s.PutCString(" [inlined] ");
1010 inline_info->GetName().Dump(&s);
1011 }
1012 }
1013 }
Greg Clayton1b654882010-09-19 02:33:57 +00001014 var_success = true;
1015 }
1016 }
1017 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1018 {
1019 var_success = addr != NULL;
1020 if (var_success)
1021 {
1022 format_addr = *addr;
1023 calculate_format_addr_function_offset = true;
1024 }
1025 }
1026 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1027 {
1028 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1029 if (var_success)
1030 {
1031 format_addr = sc->line_entry.range.GetBaseAddress();
1032 calculate_format_addr_function_offset = true;
1033 }
1034 }
1035 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1036 {
1037 var_success = exe_ctx->frame;
1038 if (var_success)
1039 {
1040 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1041 calculate_format_addr_function_offset = true;
1042 }
1043 }
1044 }
1045 }
1046 break;
1047
1048 case 'l':
1049 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1050 {
1051 if (sc && sc->line_entry.IsValid())
1052 {
1053 var_name_begin += ::strlen ("line.");
1054 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1055 {
1056 var_name_begin += ::strlen ("file.");
1057
1058 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1059 {
1060 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1061 var_success = format_file_spec;
1062 }
1063 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1064 {
1065 format_file_spec = sc->line_entry.file;
1066 var_success = format_file_spec;
1067 }
1068 }
1069 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1070 {
1071 var_success = true;
1072 s.Printf("%u", sc->line_entry.line);
1073 }
1074 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1075 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1076 {
1077 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1078 if (var_success)
1079 {
1080 format_addr = sc->line_entry.range.GetBaseAddress();
1081 if (var_name_begin[0] == 'e')
1082 format_addr.Slide (sc->line_entry.range.GetByteSize());
1083 }
1084 }
1085 }
1086 }
1087 break;
1088 }
1089
1090 if (var_success)
1091 {
1092 // If format addr is valid, then we need to print an address
1093 if (reg_num != LLDB_INVALID_REGNUM)
1094 {
1095 // We have a register value to display...
1096 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1097 {
1098 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1099 }
1100 else
1101 {
1102 if (reg_ctx == NULL)
Greg Clayton5ccbd292011-01-06 22:15:06 +00001103 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001104
1105 if (reg_ctx)
1106 {
1107 if (reg_kind != kNumRegisterKinds)
1108 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1109 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1110 var_success = reg_info != NULL;
1111 }
1112 }
1113 }
1114
1115 if (reg_info != NULL)
1116 {
1117 DataExtractor reg_data;
1118 var_success = reg_ctx->ReadRegisterBytes (reg_info->kinds[eRegisterKindLLDB], reg_data);
1119 {
1120 reg_data.Dump(&s, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
1121 }
1122 }
1123
1124 if (format_file_spec)
1125 {
1126 s << format_file_spec;
1127 }
1128
1129 // If format addr is valid, then we need to print an address
1130 if (format_addr.IsValid())
1131 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001132 var_success = false;
1133
Greg Clayton1b654882010-09-19 02:33:57 +00001134 if (calculate_format_addr_function_offset)
1135 {
1136 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001137
Greg Clayton0603aa92010-10-04 01:05:56 +00001138 if (sc)
1139 {
1140 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001141 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001142 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001143 if (sc->block)
1144 {
1145 // Check to make sure we aren't in an inline
1146 // function. If we are, use the inline block
1147 // range that contains "format_addr" since
1148 // blocks can be discontiguous.
1149 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1150 AddressRange inline_range;
1151 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1152 func_addr = inline_range.GetBaseAddress();
1153 }
1154 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001155 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1156 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1157 }
1158
1159 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001160 {
1161 if (func_addr.GetSection() == format_addr.GetSection())
1162 {
1163 addr_t func_file_addr = func_addr.GetFileAddress();
1164 addr_t addr_file_addr = format_addr.GetFileAddress();
1165 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001166 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001167 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001168 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001169 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001170 }
1171 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001172 {
1173 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1174 if (target)
1175 {
1176 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1177 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1178 if (addr_load_addr > func_load_addr)
1179 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1180 else if (addr_load_addr < func_load_addr)
1181 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1182 var_success = true;
1183 }
1184 }
Greg Clayton1b654882010-09-19 02:33:57 +00001185 }
1186 }
1187 else
1188 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001189 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001190 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001191 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1192 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001193 if (vaddr == LLDB_INVALID_ADDRESS)
1194 vaddr = format_addr.GetFileAddress ();
1195
1196 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001197 {
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001198 int addr_width = 0;
1199 if (exe_ctx && exe_ctx->process)
1200 addr_width = exe_ctx->process->GetAddressByteSize() * 2;
1201 if (addr_width == 0)
1202 addr_width = 16;
1203 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001204 var_success = true;
1205 }
Greg Clayton1b654882010-09-19 02:33:57 +00001206 }
1207 }
1208 }
1209
1210 if (var_success == false)
1211 success = false;
1212 }
1213 p = var_name_end;
1214 }
1215 else
1216 break;
1217 }
1218 else
1219 {
1220 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1221 s.PutChar(*p);
1222 }
1223 }
1224 else if (*p == '\\')
1225 {
1226 ++p; // skip the slash
1227 switch (*p)
1228 {
1229 case 'a': s.PutChar ('\a'); break;
1230 case 'b': s.PutChar ('\b'); break;
1231 case 'f': s.PutChar ('\f'); break;
1232 case 'n': s.PutChar ('\n'); break;
1233 case 'r': s.PutChar ('\r'); break;
1234 case 't': s.PutChar ('\t'); break;
1235 case 'v': s.PutChar ('\v'); break;
1236 case '\'': s.PutChar ('\''); break;
1237 case '\\': s.PutChar ('\\'); break;
1238 case '0':
1239 // 1 to 3 octal chars
1240 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001241 // Make a string that can hold onto the initial zero char,
1242 // up to 3 octal digits, and a terminating NULL.
1243 char oct_str[5] = { 0, 0, 0, 0, 0 };
1244
1245 int i;
1246 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1247 oct_str[i] = p[i];
1248
1249 // We don't want to consume the last octal character since
1250 // the main for loop will do this for us, so we advance p by
1251 // one less than i (even if i is zero)
1252 p += i - 1;
1253 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
1254 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001255 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001256 char octal_char = octal_value;
1257 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00001258 }
Greg Clayton1b654882010-09-19 02:33:57 +00001259 }
1260 break;
1261
1262 case 'x':
1263 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00001264 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001265 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001266 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00001267
Greg Clayton0603aa92010-10-04 01:05:56 +00001268 // Make a string that can hold onto two hex chars plus a
1269 // NULL terminator
1270 char hex_str[3] = { 0,0,0 };
1271 hex_str[0] = *p;
1272 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001273 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001274 ++p; // Skip the first of the two hex chars
1275 hex_str[1] = *p;
1276 }
1277
1278 unsigned long hex_value = strtoul (hex_str, NULL, 16);
1279 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001280 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00001281 }
1282 else
1283 {
1284 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00001285 }
1286 break;
1287
1288 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00001289 // Just desensitize any other character by just printing what
1290 // came after the '\'
1291 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00001292 break;
1293
1294 }
1295
1296 }
1297 }
1298 if (end)
1299 *end = p;
1300 return success;
1301}
1302
1303#pragma mark Debugger::SettingsController
1304
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001305//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001306// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001307//--------------------------------------------------
1308
Greg Clayton1b654882010-09-19 02:33:57 +00001309Debugger::SettingsController::SettingsController () :
Caroline Tice101c7c22010-09-09 06:25:08 +00001310 UserSettingsController ("", lldb::UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001311{
Caroline Tice91123da2010-09-08 17:48:55 +00001312 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
1313 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001314}
1315
Greg Clayton1b654882010-09-19 02:33:57 +00001316Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001317{
1318}
1319
1320
1321lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00001322Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001323{
Greg Claytondbe54502010-11-19 03:46:01 +00001324 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00001325 false, instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001326 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1327 return new_settings_sp;
1328}
1329
Greg Clayton1b654882010-09-19 02:33:57 +00001330#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001331//--------------------------------------------------
1332// class DebuggerInstanceSettings
1333//--------------------------------------------------
1334
Greg Claytona7015092010-09-18 01:14:36 +00001335DebuggerInstanceSettings::DebuggerInstanceSettings
1336(
1337 UserSettingsController &owner,
1338 bool live_instance,
1339 const char *name
1340) :
Greg Clayton85851dd2010-12-04 00:10:17 +00001341 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00001342 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001343 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00001344 m_frame_format (),
1345 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001346 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001347 m_use_external_editor (false),
1348 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001349{
Caroline Ticef20e8232010-09-09 18:26:37 +00001350 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1351 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
1352 // 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 +00001353 // The same is true of CreateInstanceName().
1354
1355 if (GetInstanceName() == InstanceSettings::InvalidName())
1356 {
1357 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1358 m_owner.RegisterInstanceSettings (this);
1359 }
Caroline Ticef20e8232010-09-09 18:26:37 +00001360
1361 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001362 {
1363 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1364 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001365 }
1366}
1367
1368DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00001369 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001370 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00001371 m_frame_format (rhs.m_frame_format),
1372 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001373 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001374 m_use_external_editor (rhs.m_use_external_editor),
1375 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001376{
1377 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1378 CopyInstanceSettings (pending_settings, false);
1379 m_owner.RemovePendingSettings (m_instance_name);
1380}
1381
1382DebuggerInstanceSettings::~DebuggerInstanceSettings ()
1383{
1384}
1385
1386DebuggerInstanceSettings&
1387DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
1388{
1389 if (this != &rhs)
1390 {
Greg Clayton1b654882010-09-19 02:33:57 +00001391 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001392 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00001393 m_frame_format = rhs.m_frame_format;
1394 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001395 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001396 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001397 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001398 }
1399
1400 return *this;
1401}
1402
Greg Clayton1b654882010-09-19 02:33:57 +00001403bool
1404DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
1405{
1406 bool valid = false;
1407
1408 // Verify we have a value string.
1409 if (value == NULL || value[0] == '\0')
1410 {
1411 err.SetErrorString ("Missing value. Can't set terminal width without a value.\n");
1412 }
1413 else
1414 {
1415 char *end = NULL;
1416 const uint32_t width = ::strtoul (value, &end, 0);
1417
Johnny Chenea9fc182010-09-20 16:36:43 +00001418 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00001419 {
Johnny Chen433d7742010-09-20 17:04:41 +00001420 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00001421 valid = true;
1422 else
1423 err.SetErrorString ("Invalid term-width value; value must be between 10 and 1024.\n");
1424 }
1425 else
1426 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string.\n", value);
1427 }
1428
1429 return valid;
1430}
1431
1432
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001433void
1434DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1435 const char *index_value,
1436 const char *value,
1437 const ConstString &instance_name,
1438 const SettingEntry &entry,
1439 lldb::VarSetOperationType op,
1440 Error &err,
1441 bool pending)
1442{
Greg Clayton0603aa92010-10-04 01:05:56 +00001443
1444 if (var_name == TermWidthVarName())
1445 {
1446 if (ValidTermWidthValue (value, err))
1447 {
1448 m_term_width = ::strtoul (value, NULL, 0);
1449 }
1450 }
1451 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001452 {
Caroline Tice101c7c22010-09-09 06:25:08 +00001453 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001454 if (!pending)
1455 {
Caroline Tice49e27372010-09-07 18:35:40 +00001456 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1457 // strip off the brackets before passing it to BroadcastPromptChange.
1458
1459 std::string tmp_instance_name (instance_name.AsCString());
1460 if ((tmp_instance_name[0] == '[')
1461 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
1462 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
1463 ConstString new_name (tmp_instance_name.c_str());
1464
1465 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001466 }
1467 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001468 else if (var_name == GetFrameFormatName())
1469 {
1470 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
1471 }
1472 else if (var_name == GetThreadFormatName())
1473 {
1474 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
1475 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001476 else if (var_name == ScriptLangVarName())
1477 {
1478 bool success;
1479 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
1480 &success);
1481 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001482 else if (var_name == UseExternalEditorVarName ())
1483 {
1484 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, err);
1485 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001486 else if (var_name == AutoConfirmName ())
1487 {
1488 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, err);
1489 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001490}
1491
Caroline Tice12cecd72010-09-20 21:37:42 +00001492bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001493DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1494 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00001495 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00001496 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001497{
1498 if (var_name == PromptVarName())
1499 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001500 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001501
1502 }
1503 else if (var_name == ScriptLangVarName())
1504 {
1505 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
1506 }
Caroline Tice101c7c22010-09-09 06:25:08 +00001507 else if (var_name == TermWidthVarName())
1508 {
1509 StreamString width_str;
1510 width_str.Printf ("%d", m_term_width);
1511 value.AppendString (width_str.GetData());
1512 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001513 else if (var_name == GetFrameFormatName ())
1514 {
1515 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
1516 }
1517 else if (var_name == GetThreadFormatName ())
1518 {
1519 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
1520 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001521 else if (var_name == UseExternalEditorVarName())
1522 {
1523 if (m_use_external_editor)
1524 value.AppendString ("true");
1525 else
1526 value.AppendString ("false");
1527 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001528 else if (var_name == AutoConfirmName())
1529 {
1530 if (m_auto_confirm_on)
1531 value.AppendString ("true");
1532 else
1533 value.AppendString ("false");
1534 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001535 else
Caroline Tice12cecd72010-09-20 21:37:42 +00001536 {
1537 if (err)
1538 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1539 return false;
1540 }
1541 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001542}
1543
1544void
1545DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1546 bool pending)
1547{
1548 if (new_settings.get() == NULL)
1549 return;
1550
1551 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
1552
1553 m_prompt = new_debugger_settings->m_prompt;
1554 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00001555 {
1556 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1557 // strip off the brackets before passing it to BroadcastPromptChange.
1558
1559 std::string tmp_instance_name (m_instance_name.AsCString());
1560 if ((tmp_instance_name[0] == '[')
1561 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
1562 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
1563 ConstString new_name (tmp_instance_name.c_str());
1564
1565 BroadcastPromptChange (new_name, m_prompt.c_str());
1566 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001567 m_frame_format = new_debugger_settings->m_frame_format;
1568 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001569 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001570 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001571 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001572 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001573}
1574
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001575
1576bool
1577DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
1578{
1579 std::string tmp_prompt;
1580
1581 if (new_prompt != NULL)
1582 {
1583 tmp_prompt = new_prompt ;
1584 int len = tmp_prompt.size();
1585 if (len > 1
1586 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
1587 && (tmp_prompt[len-1] == tmp_prompt[0]))
1588 {
1589 tmp_prompt = tmp_prompt.substr(1,len-2);
1590 }
1591 len = tmp_prompt.size();
1592 if (tmp_prompt[len-1] != ' ')
1593 tmp_prompt.append(" ");
1594 }
1595 EventSP new_event_sp;
1596 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
1597 new EventDataBytes (tmp_prompt.c_str())));
1598
1599 if (instance_name.GetLength() != 0)
1600 {
1601 // Set prompt for a particular instance.
1602 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
1603 if (dbg != NULL)
1604 {
1605 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
1606 }
1607 }
1608
1609 return true;
1610}
1611
1612const ConstString
1613DebuggerInstanceSettings::CreateInstanceName ()
1614{
1615 static int instance_count = 1;
1616 StreamString sstr;
1617
1618 sstr.Printf ("debugger_%d", instance_count);
1619 ++instance_count;
1620
1621 const ConstString ret_val (sstr.GetData());
1622
1623 return ret_val;
1624}
1625
1626const ConstString &
1627DebuggerInstanceSettings::PromptVarName ()
1628{
1629 static ConstString prompt_var_name ("prompt");
1630
1631 return prompt_var_name;
1632}
1633
1634const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00001635DebuggerInstanceSettings::GetFrameFormatName ()
1636{
1637 static ConstString prompt_var_name ("frame-format");
1638
1639 return prompt_var_name;
1640}
1641
1642const ConstString &
1643DebuggerInstanceSettings::GetThreadFormatName ()
1644{
1645 static ConstString prompt_var_name ("thread-format");
1646
1647 return prompt_var_name;
1648}
1649
1650const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001651DebuggerInstanceSettings::ScriptLangVarName ()
1652{
1653 static ConstString script_lang_var_name ("script-lang");
1654
1655 return script_lang_var_name;
1656}
1657
Caroline Tice101c7c22010-09-09 06:25:08 +00001658const ConstString &
1659DebuggerInstanceSettings::TermWidthVarName ()
1660{
1661 static ConstString term_width_var_name ("term-width");
1662
1663 return term_width_var_name;
1664}
1665
Caroline Ticedaccaa92010-09-20 20:44:43 +00001666const ConstString &
1667DebuggerInstanceSettings::UseExternalEditorVarName ()
1668{
1669 static ConstString use_external_editor_var_name ("use-external-editor");
1670
1671 return use_external_editor_var_name;
1672}
1673
Jim Ingham3bcdb292010-10-04 22:44:14 +00001674const ConstString &
1675DebuggerInstanceSettings::AutoConfirmName ()
1676{
1677 static ConstString use_external_editor_var_name ("auto-confirm");
1678
1679 return use_external_editor_var_name;
1680}
1681
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001682//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001683// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001684//--------------------------------------------------
1685
1686
1687SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001688Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001689{
1690 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00001691 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
1692 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001693 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1694};
1695
Greg Claytonbb562b12010-10-04 02:44:26 +00001696#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00001697#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001698
Greg Clayton0603aa92010-10-04 01:05:56 +00001699#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1700 "{, ${frame.pc}}"\
1701 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00001702 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00001703 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00001704 "\\n"
1705
Greg Clayton315d2ca2010-11-02 01:53:21 +00001706//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1707// "{, ${frame.pc}}"\
1708// MODULE_WITH_FUNC\
1709// FILE_AND_LINE\
1710// "{, stop reason = ${thread.stop-reason}}"\
1711// "{, name = ${thread.name}}"\
1712// "{, queue = ${thread.queue}}"\
1713// "\\n"
1714
Greg Clayton0603aa92010-10-04 01:05:56 +00001715#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
1716 MODULE_WITH_FUNC\
1717 FILE_AND_LINE\
1718 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001719
1720SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001721Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001722{
Greg Clayton0603aa92010-10-04 01:05:56 +00001723// NAME Setting variable type Default Enum Init'd Hidden Help
1724// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00001725{ "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 +00001726{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00001727{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
1728{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001729{ "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 +00001730{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
1731{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001732{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001733};