blob: 33a9b91e9060ea0a5ca0b270ef780e41a5857181 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/lldb-private.h"
11#include "lldb/Core/ConnectionFileDescriptor.h"
12#include "lldb/Core/Debugger.h"
13#include "lldb/Core/InputReader.h"
14#include "lldb/Core/State.h"
Greg Clayton1b654882010-09-19 02:33:57 +000015#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Core/Timer.h"
Greg Claytona3406612011-02-07 23:24:47 +000017#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000018#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Target/TargetList.h"
20#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000021#include "lldb/Target/RegisterContext.h"
22#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Target/Thread.h"
24
25
26using namespace lldb;
27using namespace lldb_private;
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
Greg Clayton1b654882010-09-19 02:33:57 +000030static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000031static lldb::user_id_t g_unique_id = 1;
32
Greg Clayton1b654882010-09-19 02:33:57 +000033#pragma mark Static Functions
34
35static Mutex &
36GetDebuggerListMutex ()
37{
38 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
39 return g_mutex;
40}
41
42typedef std::vector<DebuggerSP> DebuggerList;
43
44static DebuggerList &
45GetDebuggerList()
46{
47 // hide the static debugger list inside a singleton accessor to avoid
48 // global init contructors
49 static DebuggerList g_list;
50 return g_list;
51}
52
53
54#pragma mark Debugger
55
Greg Clayton99d0faf2010-11-18 23:32:35 +000056UserSettingsControllerSP &
57Debugger::GetSettingsController ()
58{
59 static UserSettingsControllerSP g_settings_controller;
60 return g_settings_controller;
61}
62
Caroline Tice2f88aad2011-01-14 00:29:16 +000063int
64Debugger::TestDebuggerRefCount ()
65{
66 return g_shared_debugger_refcount;
67}
68
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069void
70Debugger::Initialize ()
71{
Greg Clayton66111032010-06-23 01:19:29 +000072 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +000073 {
Greg Clayton99d0faf2010-11-18 23:32:35 +000074 UserSettingsControllerSP &usc = GetSettingsController();
75 usc.reset (new SettingsController);
76 UserSettingsController::InitializeSettingsController (usc,
77 SettingsController::global_settings_table,
78 SettingsController::instance_settings_table);
Greg Claytondbe54502010-11-19 03:46:01 +000079 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +000080 }
Greg Clayton66111032010-06-23 01:19:29 +000081 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +000082
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083}
84
85void
86Debugger::Terminate ()
87{
Greg Clayton66111032010-06-23 01:19:29 +000088 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089 {
Greg Clayton66111032010-06-23 01:19:29 +000090 g_shared_debugger_refcount--;
91 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092 {
Greg Claytondbe54502010-11-19 03:46:01 +000093 lldb_private::WillTerminate();
94 lldb_private::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +000095 UserSettingsControllerSP &usc = GetSettingsController();
96 UserSettingsController::FinalizeSettingsController (usc);
97 usc.reset();
Caroline Tice6760a512011-01-17 21:55:19 +000098
99 // Clear our master list of debugger objects
100 Mutex::Locker locker (GetDebuggerListMutex ());
101 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103 }
104}
105
Greg Clayton66111032010-06-23 01:19:29 +0000106DebuggerSP
107Debugger::CreateInstance ()
108{
109 DebuggerSP debugger_sp (new Debugger);
110 // Scope for locker
111 {
112 Mutex::Locker locker (GetDebuggerListMutex ());
113 GetDebuggerList().push_back(debugger_sp);
114 }
115 return debugger_sp;
116}
117
Caroline Ticee02657b2011-01-22 01:02:07 +0000118void
119Debugger::Destroy (lldb::DebuggerSP &debugger_sp)
120{
121 if (debugger_sp.get() == NULL)
122 return;
123
124 Mutex::Locker locker (GetDebuggerListMutex ());
125 DebuggerList &debugger_list = GetDebuggerList ();
126 DebuggerList::iterator pos, end = debugger_list.end();
127 for (pos = debugger_list.begin (); pos != end; ++pos)
128 {
129 if ((*pos).get() == debugger_sp.get())
130 {
131 debugger_list.erase (pos);
132 return;
133 }
134 }
135
136}
137
Greg Clayton66111032010-06-23 01:19:29 +0000138lldb::DebuggerSP
139Debugger::GetSP ()
140{
141 lldb::DebuggerSP debugger_sp;
142
143 Mutex::Locker locker (GetDebuggerListMutex ());
144 DebuggerList &debugger_list = GetDebuggerList();
145 DebuggerList::iterator pos, end = debugger_list.end();
146 for (pos = debugger_list.begin(); pos != end; ++pos)
147 {
148 if ((*pos).get() == this)
149 {
150 debugger_sp = *pos;
151 break;
152 }
153 }
154 return debugger_sp;
155}
156
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000157lldb::DebuggerSP
158Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
159{
160 lldb::DebuggerSP debugger_sp;
161
162 Mutex::Locker locker (GetDebuggerListMutex ());
163 DebuggerList &debugger_list = GetDebuggerList();
164 DebuggerList::iterator pos, end = debugger_list.end();
165
166 for (pos = debugger_list.begin(); pos != end; ++pos)
167 {
168 if ((*pos).get()->m_instance_name == instance_name)
169 {
170 debugger_sp = *pos;
171 break;
172 }
173 }
174 return debugger_sp;
175}
Greg Clayton66111032010-06-23 01:19:29 +0000176
177TargetSP
178Debugger::FindTargetWithProcessID (lldb::pid_t pid)
179{
180 lldb::TargetSP target_sp;
181 Mutex::Locker locker (GetDebuggerListMutex ());
182 DebuggerList &debugger_list = GetDebuggerList();
183 DebuggerList::iterator pos, end = debugger_list.end();
184 for (pos = debugger_list.begin(); pos != end; ++pos)
185 {
186 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
187 if (target_sp)
188 break;
189 }
190 return target_sp;
191}
192
193
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000195 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000196 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000197 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 m_input_file (),
199 m_output_file (),
200 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201 m_target_list (),
202 m_listener ("lldb.Debugger"),
203 m_source_manager (),
Greg Clayton66111032010-06-23 01:19:29 +0000204 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
205 m_exe_ctx (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 m_input_readers (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000207 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208{
Greg Claytond46c87a2010-12-04 02:39:47 +0000209 m_input_comm.SetCloseOnEOF(false);
Greg Clayton66111032010-06-23 01:19:29 +0000210 m_command_interpreter_ap->Initialize ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211}
212
213Debugger::~Debugger ()
214{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000215 CleanUpInputReaders();
Greg Clayton66111032010-06-23 01:19:29 +0000216 int num_targets = m_target_list.GetNumTargets();
217 for (int i = 0; i < num_targets; i++)
218 {
219 ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
220 if (process_sp)
221 process_sp->Destroy();
222 }
223 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224}
225
226
227bool
228Debugger::GetAsyncExecution ()
229{
Greg Clayton66111032010-06-23 01:19:29 +0000230 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231}
232
233void
234Debugger::SetAsyncExecution (bool async_execution)
235{
Greg Clayton66111032010-06-23 01:19:29 +0000236 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237}
238
239void
240Debugger::DisconnectInput()
241{
242 m_input_comm.Clear ();
243}
244
245void
246Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
247{
248 m_input_file.SetFileHandle (fh, tranfer_ownership);
249 if (m_input_file.GetFileHandle() == NULL)
250 m_input_file.SetFileHandle (stdin, false);
251
252 // Disconnect from any old connection if we had one
253 m_input_comm.Disconnect ();
254 m_input_comm.SetConnection (new ConnectionFileDescriptor (::fileno (GetInputFileHandle()), true));
255 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
256
257 Error error;
258 if (m_input_comm.StartReadThread (&error) == false)
259 {
260 FILE *err_fh = GetErrorFileHandle();
261 if (err_fh)
262 {
263 ::fprintf (err_fh, "error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
264 exit(1);
265 }
266 }
267
268}
269
270FILE *
271Debugger::GetInputFileHandle ()
272{
273 return m_input_file.GetFileHandle();
274}
275
276
277void
278Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
279{
280 m_output_file.SetFileHandle (fh, tranfer_ownership);
281 if (m_output_file.GetFileHandle() == NULL)
282 m_output_file.SetFileHandle (stdin, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000283
284 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285}
286
287FILE *
288Debugger::GetOutputFileHandle ()
289{
290 return m_output_file.GetFileHandle();
291}
292
293void
294Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
295{
296 m_error_file.SetFileHandle (fh, tranfer_ownership);
297 if (m_error_file.GetFileHandle() == NULL)
298 m_error_file.SetFileHandle (stdin, false);
299}
300
301
302FILE *
303Debugger::GetErrorFileHandle ()
304{
305 return m_error_file.GetFileHandle();
306}
307
308CommandInterpreter &
309Debugger::GetCommandInterpreter ()
310{
Greg Clayton66111032010-06-23 01:19:29 +0000311 assert (m_command_interpreter_ap.get());
312 return *m_command_interpreter_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313}
314
315Listener &
316Debugger::GetListener ()
317{
318 return m_listener;
319}
320
321
322TargetSP
Jim Ingham2976d002010-08-26 21:32:51 +0000323Debugger::GetSelectedTarget ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000324{
Jim Ingham2976d002010-08-26 21:32:51 +0000325 return m_target_list.GetSelectedTarget ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000326}
327
328ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000329Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000330{
331 ExecutionContext exe_ctx;
332 exe_ctx.Clear();
333
Jim Ingham2976d002010-08-26 21:32:51 +0000334 lldb::TargetSP target_sp = GetSelectedTarget();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335 exe_ctx.target = target_sp.get();
336
337 if (target_sp)
338 {
339 exe_ctx.process = target_sp->GetProcessSP().get();
340 if (exe_ctx.process && exe_ctx.process->IsRunning() == false)
341 {
Jim Ingham2976d002010-08-26 21:32:51 +0000342 exe_ctx.thread = exe_ctx.process->GetThreadList().GetSelectedThread().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343 if (exe_ctx.thread == NULL)
344 exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
345 if (exe_ctx.thread)
346 {
Jim Ingham2976d002010-08-26 21:32:51 +0000347 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348 if (exe_ctx.frame == NULL)
349 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex (0).get();
350 }
351 }
352 }
353 return exe_ctx;
354
355}
356
357SourceManager &
358Debugger::GetSourceManager ()
359{
360 return m_source_manager;
361}
362
363
364TargetList&
365Debugger::GetTargetList ()
366{
367 return m_target_list;
368}
369
370void
371Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
372{
Caroline Ticeefed6132010-11-19 20:47:54 +0000373 if (bytes_len > 0)
374 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
375 else
376 ((Debugger *)baton)->DispatchInputEndOfFile ();
377}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378
379
380void
381Debugger::DispatchInput (const char *bytes, size_t bytes_len)
382{
Caroline Ticeefed6132010-11-19 20:47:54 +0000383 if (bytes == NULL || bytes_len == 0)
384 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385
386 WriteToDefaultReader (bytes, bytes_len);
387}
388
389void
Caroline Ticeefed6132010-11-19 20:47:54 +0000390Debugger::DispatchInputInterrupt ()
391{
392 m_input_reader_data.clear();
393
394 if (!m_input_readers.empty())
395 {
396 while (CheckIfTopInputReaderIsDone ()) ;
397
398 InputReaderSP reader_sp(m_input_readers.top());
399 if (reader_sp)
400 reader_sp->Notify (eInputReaderInterrupt);
401
402 while (CheckIfTopInputReaderIsDone ()) ;
403 }
404}
405
406void
407Debugger::DispatchInputEndOfFile ()
408{
409 m_input_reader_data.clear();
410
411 if (!m_input_readers.empty())
412 {
413 while (CheckIfTopInputReaderIsDone ()) ;
414
415 InputReaderSP reader_sp(m_input_readers.top());
416 if (reader_sp)
417 reader_sp->Notify (eInputReaderEndOfFile);
418
419 while (CheckIfTopInputReaderIsDone ()) ;
420 }
421}
422
423void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000424Debugger::CleanUpInputReaders ()
425{
426 m_input_reader_data.clear();
427
428 while (m_input_readers.size() > 1)
429 {
430 while (CheckIfTopInputReaderIsDone ()) ;
431
432 InputReaderSP reader_sp (m_input_readers.top());
433 if (reader_sp)
434 {
435 reader_sp->Notify (eInputReaderEndOfFile);
436 reader_sp->SetIsDone (true);
437 }
438 }
439}
440
441void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
443{
444 if (bytes && bytes_len)
445 m_input_reader_data.append (bytes, bytes_len);
446
447 if (m_input_reader_data.empty())
448 return;
449
450 while (!m_input_readers.empty() && !m_input_reader_data.empty())
451 {
452 while (CheckIfTopInputReaderIsDone ())
453 /* Do nothing. */;
454
455 // Get the input reader from the top of the stack
456 InputReaderSP reader_sp(m_input_readers.top());
457
458 if (!reader_sp)
459 break;
460
Greg Clayton471b31c2010-07-20 22:52:08 +0000461 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462 m_input_reader_data.size());
463 if (bytes_handled)
464 {
465 m_input_reader_data.erase (0, bytes_handled);
466 }
467 else
468 {
469 // No bytes were handled, we might not have reached our
470 // granularity, just return and wait for more data
471 break;
472 }
473 }
474
475 // Flush out any input readers that are donesvn
476 while (CheckIfTopInputReaderIsDone ())
477 /* Do nothing. */;
478
479}
480
481void
482Debugger::PushInputReader (const InputReaderSP& reader_sp)
483{
484 if (!reader_sp)
485 return;
486 if (!m_input_readers.empty())
487 {
488 // Deactivate the old top reader
489 InputReaderSP top_reader_sp (m_input_readers.top());
490 if (top_reader_sp)
491 top_reader_sp->Notify (eInputReaderDeactivate);
492 }
493 m_input_readers.push (reader_sp);
494 reader_sp->Notify (eInputReaderActivate);
495 ActivateInputReader (reader_sp);
496}
497
498bool
499Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp)
500{
501 bool result = false;
502
503 // The reader on the stop of the stack is done, so let the next
504 // read on the stack referesh its prompt and if there is one...
505 if (!m_input_readers.empty())
506 {
507 InputReaderSP reader_sp(m_input_readers.top());
508
509 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
510 {
511 m_input_readers.pop ();
512 reader_sp->Notify (eInputReaderDeactivate);
513 reader_sp->Notify (eInputReaderDone);
514 result = true;
515
516 if (!m_input_readers.empty())
517 {
518 reader_sp = m_input_readers.top();
519 if (reader_sp)
520 {
521 ActivateInputReader (reader_sp);
522 reader_sp->Notify (eInputReaderReactivate);
523 }
524 }
525 }
526 }
527 return result;
528}
529
530bool
531Debugger::CheckIfTopInputReaderIsDone ()
532{
533 bool result = false;
534 if (!m_input_readers.empty())
535 {
536 InputReaderSP reader_sp(m_input_readers.top());
537
538 if (reader_sp && reader_sp->IsDone())
539 {
540 result = true;
541 PopInputReader (reader_sp);
542 }
543 }
544 return result;
545}
546
547void
548Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
549{
550 FILE *in_fh = GetInputFileHandle();
551
552 if (in_fh)
553 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554 int in_fd = fileno (in_fh);
Greg Claytona3406612011-02-07 23:24:47 +0000555 Terminal tty(in_fd);
556
557 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558
Greg Claytona3406612011-02-07 23:24:47 +0000559 switch (reader_sp->GetGranularity())
560 {
561 case eInputReaderGranularityByte:
562 case eInputReaderGranularityWord:
563 tty.SetCanonical (false);
564 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565
Greg Claytona3406612011-02-07 23:24:47 +0000566 case eInputReaderGranularityLine:
567 case eInputReaderGranularityAll:
568 tty.SetCanonical (true);
569 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570
Greg Claytona3406612011-02-07 23:24:47 +0000571 default:
572 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573 }
574 }
575}
Greg Clayton66111032010-06-23 01:19:29 +0000576
577void
578Debugger::UpdateExecutionContext (ExecutionContext *override_context)
579{
580 m_exe_ctx.Clear();
581
582 if (override_context != NULL)
583 {
584 m_exe_ctx.target = override_context->target;
585 m_exe_ctx.process = override_context->process;
586 m_exe_ctx.thread = override_context->thread;
587 m_exe_ctx.frame = override_context->frame;
588 }
589 else
590 {
Jim Ingham2976d002010-08-26 21:32:51 +0000591 TargetSP target_sp (GetSelectedTarget());
Greg Clayton66111032010-06-23 01:19:29 +0000592 if (target_sp)
593 {
594 m_exe_ctx.target = target_sp.get();
595 m_exe_ctx.process = target_sp->GetProcessSP().get();
Johnny Chen725945d2010-09-03 22:35:47 +0000596 if (m_exe_ctx.process && m_exe_ctx.process->IsAlive() && !m_exe_ctx.process->IsRunning())
Greg Clayton66111032010-06-23 01:19:29 +0000597 {
Jim Ingham2976d002010-08-26 21:32:51 +0000598 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetSelectedThread().get();
Greg Clayton66111032010-06-23 01:19:29 +0000599 if (m_exe_ctx.thread == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000600 {
Greg Clayton66111032010-06-23 01:19:29 +0000601 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000602 // If we didn't have a selected thread, select one here.
603 if (m_exe_ctx.thread != NULL)
Johnny Chenc13ee522010-09-14 00:53:53 +0000604 m_exe_ctx.process->GetThreadList().SetSelectedThreadByID(m_exe_ctx.thread->GetID());
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000605 }
Greg Clayton66111032010-06-23 01:19:29 +0000606 if (m_exe_ctx.thread)
607 {
Jim Ingham2976d002010-08-26 21:32:51 +0000608 m_exe_ctx.frame = m_exe_ctx.thread->GetSelectedFrame().get();
Greg Clayton66111032010-06-23 01:19:29 +0000609 if (m_exe_ctx.frame == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000610 {
Greg Clayton66111032010-06-23 01:19:29 +0000611 m_exe_ctx.frame = m_exe_ctx.thread->GetStackFrameAtIndex (0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000612 // If we didn't have a selected frame select one here.
613 if (m_exe_ctx.frame != NULL)
614 m_exe_ctx.thread->SetSelectedFrame(m_exe_ctx.frame);
615 }
Greg Clayton66111032010-06-23 01:19:29 +0000616 }
617 }
618 }
619 }
620}
621
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000622DebuggerSP
623Debugger::FindDebuggerWithID (lldb::user_id_t id)
624{
625 lldb::DebuggerSP debugger_sp;
626
627 Mutex::Locker locker (GetDebuggerListMutex ());
628 DebuggerList &debugger_list = GetDebuggerList();
629 DebuggerList::iterator pos, end = debugger_list.end();
630 for (pos = debugger_list.begin(); pos != end; ++pos)
631 {
632 if ((*pos).get()->GetID() == id)
633 {
634 debugger_sp = *pos;
635 break;
636 }
637 }
638 return debugger_sp;
639}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000640
Greg Clayton1b654882010-09-19 02:33:57 +0000641static void
642TestPromptFormats (StackFrame *frame)
643{
644 if (frame == NULL)
645 return;
646
647 StreamString s;
648 const char *prompt_format =
649 "{addr = '${addr}'\n}"
650 "{process.id = '${process.id}'\n}"
651 "{process.name = '${process.name}'\n}"
652 "{process.file.basename = '${process.file.basename}'\n}"
653 "{process.file.fullpath = '${process.file.fullpath}'\n}"
654 "{thread.id = '${thread.id}'\n}"
655 "{thread.index = '${thread.index}'\n}"
656 "{thread.name = '${thread.name}'\n}"
657 "{thread.queue = '${thread.queue}'\n}"
658 "{thread.stop-reason = '${thread.stop-reason}'\n}"
659 "{target.arch = '${target.arch}'\n}"
660 "{module.file.basename = '${module.file.basename}'\n}"
661 "{module.file.fullpath = '${module.file.fullpath}'\n}"
662 "{file.basename = '${file.basename}'\n}"
663 "{file.fullpath = '${file.fullpath}'\n}"
664 "{frame.index = '${frame.index}'\n}"
665 "{frame.pc = '${frame.pc}'\n}"
666 "{frame.sp = '${frame.sp}'\n}"
667 "{frame.fp = '${frame.fp}'\n}"
668 "{frame.flags = '${frame.flags}'\n}"
669 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
670 "{frame.reg.rip = '${frame.reg.rip}'\n}"
671 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
672 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
673 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
674 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
675 "{frame.reg.carp = '${frame.reg.carp}'\n}"
676 "{function.id = '${function.id}'\n}"
677 "{function.name = '${function.name}'\n}"
678 "{function.addr-offset = '${function.addr-offset}'\n}"
679 "{function.line-offset = '${function.line-offset}'\n}"
680 "{function.pc-offset = '${function.pc-offset}'\n}"
681 "{line.file.basename = '${line.file.basename}'\n}"
682 "{line.file.fullpath = '${line.file.fullpath}'\n}"
683 "{line.number = '${line.number}'\n}"
684 "{line.start-addr = '${line.start-addr}'\n}"
685 "{line.end-addr = '${line.end-addr}'\n}"
686;
687
688 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
689 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000690 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000691 const char *end = NULL;
692 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
693 {
694 printf("%s\n", s.GetData());
695 }
696 else
697 {
698 printf ("error: at '%s'\n", end);
699 printf ("what we got: %s\n", s.GetData());
700 }
701}
702
703bool
704Debugger::FormatPrompt
705(
706 const char *format,
707 const SymbolContext *sc,
708 const ExecutionContext *exe_ctx,
709 const Address *addr,
710 Stream &s,
711 const char **end
712)
713{
714 bool success = true;
715 const char *p;
716 for (p = format; *p != '\0'; ++p)
717 {
718 size_t non_special_chars = ::strcspn (p, "${}\\");
719 if (non_special_chars > 0)
720 {
721 if (success)
722 s.Write (p, non_special_chars);
723 p += non_special_chars;
724 }
725
726 if (*p == '\0')
727 {
728 break;
729 }
730 else if (*p == '{')
731 {
732 // Start a new scope that must have everything it needs if it is to
733 // to make it into the final output stream "s". If you want to make
734 // a format that only prints out the function or symbol name if there
735 // is one in the symbol context you can use:
736 // "{function =${function.name}}"
737 // The first '{' starts a new scope that end with the matching '}' at
738 // the end of the string. The contents "function =${function.name}"
739 // will then be evaluated and only be output if there is a function
740 // or symbol with a valid name.
741 StreamString sub_strm;
742
743 ++p; // Skip the '{'
744
745 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p))
746 {
747 // The stream had all it needed
748 s.Write(sub_strm.GetData(), sub_strm.GetSize());
749 }
750 if (*p != '}')
751 {
752 success = false;
753 break;
754 }
755 }
756 else if (*p == '}')
757 {
758 // End of a enclosing scope
759 break;
760 }
761 else if (*p == '$')
762 {
763 // We have a prompt variable to print
764 ++p;
765 if (*p == '{')
766 {
767 ++p;
768 const char *var_name_begin = p;
769 const char *var_name_end = ::strchr (p, '}');
770
771 if (var_name_end && var_name_begin < var_name_end)
772 {
773 // if we have already failed to parse, skip this variable
774 if (success)
775 {
776 const char *cstr = NULL;
777 Address format_addr;
778 bool calculate_format_addr_function_offset = false;
779 // Set reg_kind and reg_num to invalid values
780 RegisterKind reg_kind = kNumRegisterKinds;
781 uint32_t reg_num = LLDB_INVALID_REGNUM;
782 FileSpec format_file_spec;
783 const lldb::RegisterInfo *reg_info = NULL;
784 RegisterContext *reg_ctx = NULL;
785
786 // Each variable must set success to true below...
787 bool var_success = false;
788 switch (var_name_begin[0])
789 {
790 case 'a':
791 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
792 {
793 if (addr && addr->IsValid())
794 {
795 var_success = true;
796 format_addr = *addr;
797 }
798 }
799 break;
800
801 case 'p':
802 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
803 {
804 if (exe_ctx && exe_ctx->process != NULL)
805 {
806 var_name_begin += ::strlen ("process.");
807 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
808 {
809 s.Printf("%i", exe_ctx->process->GetID());
810 var_success = true;
811 }
812 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
813 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
814 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
815 {
816 ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
817 if (exe_module_sp)
818 {
819 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
820 {
821 format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
822 var_success = format_file_spec;
823 }
824 else
825 {
826 format_file_spec = exe_module_sp->GetFileSpec();
827 var_success = format_file_spec;
828 }
829 }
830 }
831 }
832 }
833 break;
834
835 case 't':
836 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
837 {
838 if (exe_ctx && exe_ctx->thread)
839 {
840 var_name_begin += ::strlen ("thread.");
841 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
842 {
843 s.Printf("0x%4.4x", exe_ctx->thread->GetID());
844 var_success = true;
845 }
846 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
847 {
848 s.Printf("%u", exe_ctx->thread->GetIndexID());
849 var_success = true;
850 }
851 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
852 {
853 cstr = exe_ctx->thread->GetName();
854 var_success = cstr && cstr[0];
855 if (var_success)
856 s.PutCString(cstr);
857 }
858 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
859 {
860 cstr = exe_ctx->thread->GetQueueName();
861 var_success = cstr && cstr[0];
862 if (var_success)
863 s.PutCString(cstr);
864 }
865 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
866 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000867 StopInfoSP stop_info_sp = exe_ctx->thread->GetStopInfo ();
868 if (stop_info_sp)
Greg Clayton1b654882010-09-19 02:33:57 +0000869 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000870 cstr = stop_info_sp->GetDescription();
Greg Clayton1b654882010-09-19 02:33:57 +0000871 if (cstr && cstr[0])
872 {
873 s.PutCString(cstr);
874 var_success = true;
875 }
876 }
877 }
878 }
879 }
880 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
881 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000882 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
883 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +0000884 {
Greg Clayton1b654882010-09-19 02:33:57 +0000885 var_name_begin += ::strlen ("target.");
886 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
887 {
888 ArchSpec arch (target->GetArchitecture ());
889 if (arch.IsValid())
890 {
891 s.PutCString (arch.AsCString());
892 var_success = true;
893 }
894 }
895 }
896 }
897 break;
898
899
900 case 'm':
901 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
902 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000903 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +0000904 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000905 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +0000906 var_name_begin += ::strlen ("module.");
907
908 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
909 {
910 if (module->GetFileSpec())
911 {
912 var_name_begin += ::strlen ("file.");
913
914 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
915 {
916 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
917 var_success = format_file_spec;
918 }
919 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
920 {
921 format_file_spec = module->GetFileSpec();
922 var_success = format_file_spec;
923 }
924 }
925 }
926 }
927 }
928 break;
929
930
931 case 'f':
932 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
933 {
934 if (sc && sc->comp_unit != NULL)
935 {
936 var_name_begin += ::strlen ("file.");
937
938 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
939 {
940 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
941 var_success = format_file_spec;
942 }
943 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
944 {
945 format_file_spec = *sc->comp_unit;
946 var_success = format_file_spec;
947 }
948 }
949 }
950 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
951 {
952 if (exe_ctx && exe_ctx->frame)
953 {
954 var_name_begin += ::strlen ("frame.");
955 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
956 {
957 s.Printf("%u", exe_ctx->frame->GetFrameIndex());
958 var_success = true;
959 }
960 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
961 {
962 reg_kind = eRegisterKindGeneric;
963 reg_num = LLDB_REGNUM_GENERIC_PC;
964 var_success = true;
965 }
966 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
967 {
968 reg_kind = eRegisterKindGeneric;
969 reg_num = LLDB_REGNUM_GENERIC_SP;
970 var_success = true;
971 }
972 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
973 {
974 reg_kind = eRegisterKindGeneric;
975 reg_num = LLDB_REGNUM_GENERIC_FP;
976 var_success = true;
977 }
978 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
979 {
980 reg_kind = eRegisterKindGeneric;
981 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
982 var_success = true;
983 }
984 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
985 {
Greg Clayton5ccbd292011-01-06 22:15:06 +0000986 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +0000987 if (reg_ctx)
988 {
989 var_name_begin += ::strlen ("reg.");
990 if (var_name_begin < var_name_end)
991 {
992 std::string reg_name (var_name_begin, var_name_end);
993 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
994 if (reg_info)
995 var_success = true;
996 }
997 }
998 }
999 }
1000 }
1001 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
1002 {
1003 if (sc && (sc->function != NULL || sc->symbol != NULL))
1004 {
1005 var_name_begin += ::strlen ("function.");
1006 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1007 {
1008 if (sc->function)
1009 s.Printf("function{0x%8.8x}", sc->function->GetID());
1010 else
1011 s.Printf("symbol[%u]", sc->symbol->GetID());
1012
1013 var_success = true;
1014 }
1015 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1016 {
1017 if (sc->function)
1018 cstr = sc->function->GetName().AsCString (NULL);
1019 else if (sc->symbol)
1020 cstr = sc->symbol->GetName().AsCString (NULL);
1021 if (cstr)
1022 {
1023 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001024
1025 if (sc->block)
1026 {
1027 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1028 if (inline_block)
1029 {
1030 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1031 if (inline_info)
1032 {
1033 s.PutCString(" [inlined] ");
1034 inline_info->GetName().Dump(&s);
1035 }
1036 }
1037 }
Greg Clayton1b654882010-09-19 02:33:57 +00001038 var_success = true;
1039 }
1040 }
1041 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1042 {
1043 var_success = addr != NULL;
1044 if (var_success)
1045 {
1046 format_addr = *addr;
1047 calculate_format_addr_function_offset = true;
1048 }
1049 }
1050 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1051 {
1052 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1053 if (var_success)
1054 {
1055 format_addr = sc->line_entry.range.GetBaseAddress();
1056 calculate_format_addr_function_offset = true;
1057 }
1058 }
1059 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1060 {
1061 var_success = exe_ctx->frame;
1062 if (var_success)
1063 {
1064 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1065 calculate_format_addr_function_offset = true;
1066 }
1067 }
1068 }
1069 }
1070 break;
1071
1072 case 'l':
1073 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1074 {
1075 if (sc && sc->line_entry.IsValid())
1076 {
1077 var_name_begin += ::strlen ("line.");
1078 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1079 {
1080 var_name_begin += ::strlen ("file.");
1081
1082 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1083 {
1084 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1085 var_success = format_file_spec;
1086 }
1087 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1088 {
1089 format_file_spec = sc->line_entry.file;
1090 var_success = format_file_spec;
1091 }
1092 }
1093 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1094 {
1095 var_success = true;
1096 s.Printf("%u", sc->line_entry.line);
1097 }
1098 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1099 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1100 {
1101 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1102 if (var_success)
1103 {
1104 format_addr = sc->line_entry.range.GetBaseAddress();
1105 if (var_name_begin[0] == 'e')
1106 format_addr.Slide (sc->line_entry.range.GetByteSize());
1107 }
1108 }
1109 }
1110 }
1111 break;
1112 }
1113
1114 if (var_success)
1115 {
1116 // If format addr is valid, then we need to print an address
1117 if (reg_num != LLDB_INVALID_REGNUM)
1118 {
1119 // We have a register value to display...
1120 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1121 {
1122 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1123 }
1124 else
1125 {
1126 if (reg_ctx == NULL)
Greg Clayton5ccbd292011-01-06 22:15:06 +00001127 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001128
1129 if (reg_ctx)
1130 {
1131 if (reg_kind != kNumRegisterKinds)
1132 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1133 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1134 var_success = reg_info != NULL;
1135 }
1136 }
1137 }
1138
1139 if (reg_info != NULL)
1140 {
1141 DataExtractor reg_data;
1142 var_success = reg_ctx->ReadRegisterBytes (reg_info->kinds[eRegisterKindLLDB], reg_data);
1143 {
1144 reg_data.Dump(&s, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
1145 }
1146 }
1147
1148 if (format_file_spec)
1149 {
1150 s << format_file_spec;
1151 }
1152
1153 // If format addr is valid, then we need to print an address
1154 if (format_addr.IsValid())
1155 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001156 var_success = false;
1157
Greg Clayton1b654882010-09-19 02:33:57 +00001158 if (calculate_format_addr_function_offset)
1159 {
1160 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001161
Greg Clayton0603aa92010-10-04 01:05:56 +00001162 if (sc)
1163 {
1164 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001165 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001166 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001167 if (sc->block)
1168 {
1169 // Check to make sure we aren't in an inline
1170 // function. If we are, use the inline block
1171 // range that contains "format_addr" since
1172 // blocks can be discontiguous.
1173 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1174 AddressRange inline_range;
1175 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1176 func_addr = inline_range.GetBaseAddress();
1177 }
1178 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001179 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1180 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1181 }
1182
1183 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001184 {
1185 if (func_addr.GetSection() == format_addr.GetSection())
1186 {
1187 addr_t func_file_addr = func_addr.GetFileAddress();
1188 addr_t addr_file_addr = format_addr.GetFileAddress();
1189 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001190 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001191 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001192 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001193 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001194 }
1195 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001196 {
1197 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1198 if (target)
1199 {
1200 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1201 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1202 if (addr_load_addr > func_load_addr)
1203 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1204 else if (addr_load_addr < func_load_addr)
1205 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1206 var_success = true;
1207 }
1208 }
Greg Clayton1b654882010-09-19 02:33:57 +00001209 }
1210 }
1211 else
1212 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001213 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001214 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001215 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1216 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001217 if (vaddr == LLDB_INVALID_ADDRESS)
1218 vaddr = format_addr.GetFileAddress ();
1219
1220 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001221 {
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001222 int addr_width = 0;
1223 if (exe_ctx && exe_ctx->process)
1224 addr_width = exe_ctx->process->GetAddressByteSize() * 2;
1225 if (addr_width == 0)
1226 addr_width = 16;
1227 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001228 var_success = true;
1229 }
Greg Clayton1b654882010-09-19 02:33:57 +00001230 }
1231 }
1232 }
1233
1234 if (var_success == false)
1235 success = false;
1236 }
1237 p = var_name_end;
1238 }
1239 else
1240 break;
1241 }
1242 else
1243 {
1244 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1245 s.PutChar(*p);
1246 }
1247 }
1248 else if (*p == '\\')
1249 {
1250 ++p; // skip the slash
1251 switch (*p)
1252 {
1253 case 'a': s.PutChar ('\a'); break;
1254 case 'b': s.PutChar ('\b'); break;
1255 case 'f': s.PutChar ('\f'); break;
1256 case 'n': s.PutChar ('\n'); break;
1257 case 'r': s.PutChar ('\r'); break;
1258 case 't': s.PutChar ('\t'); break;
1259 case 'v': s.PutChar ('\v'); break;
1260 case '\'': s.PutChar ('\''); break;
1261 case '\\': s.PutChar ('\\'); break;
1262 case '0':
1263 // 1 to 3 octal chars
1264 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001265 // Make a string that can hold onto the initial zero char,
1266 // up to 3 octal digits, and a terminating NULL.
1267 char oct_str[5] = { 0, 0, 0, 0, 0 };
1268
1269 int i;
1270 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1271 oct_str[i] = p[i];
1272
1273 // We don't want to consume the last octal character since
1274 // the main for loop will do this for us, so we advance p by
1275 // one less than i (even if i is zero)
1276 p += i - 1;
1277 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
1278 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001279 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001280 char octal_char = octal_value;
1281 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00001282 }
Greg Clayton1b654882010-09-19 02:33:57 +00001283 }
1284 break;
1285
1286 case 'x':
1287 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00001288 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001289 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001290 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00001291
Greg Clayton0603aa92010-10-04 01:05:56 +00001292 // Make a string that can hold onto two hex chars plus a
1293 // NULL terminator
1294 char hex_str[3] = { 0,0,0 };
1295 hex_str[0] = *p;
1296 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001297 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001298 ++p; // Skip the first of the two hex chars
1299 hex_str[1] = *p;
1300 }
1301
1302 unsigned long hex_value = strtoul (hex_str, NULL, 16);
1303 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001304 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00001305 }
1306 else
1307 {
1308 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00001309 }
1310 break;
1311
1312 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00001313 // Just desensitize any other character by just printing what
1314 // came after the '\'
1315 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00001316 break;
1317
1318 }
1319
1320 }
1321 }
1322 if (end)
1323 *end = p;
1324 return success;
1325}
1326
1327#pragma mark Debugger::SettingsController
1328
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001329//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001330// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001331//--------------------------------------------------
1332
Greg Clayton1b654882010-09-19 02:33:57 +00001333Debugger::SettingsController::SettingsController () :
Caroline Tice101c7c22010-09-09 06:25:08 +00001334 UserSettingsController ("", lldb::UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001335{
Caroline Tice91123da2010-09-08 17:48:55 +00001336 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
1337 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001338}
1339
Greg Clayton1b654882010-09-19 02:33:57 +00001340Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001341{
1342}
1343
1344
1345lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00001346Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001347{
Greg Claytondbe54502010-11-19 03:46:01 +00001348 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00001349 false, instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001350 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1351 return new_settings_sp;
1352}
1353
Greg Clayton1b654882010-09-19 02:33:57 +00001354#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001355//--------------------------------------------------
1356// class DebuggerInstanceSettings
1357//--------------------------------------------------
1358
Greg Claytona7015092010-09-18 01:14:36 +00001359DebuggerInstanceSettings::DebuggerInstanceSettings
1360(
1361 UserSettingsController &owner,
1362 bool live_instance,
1363 const char *name
1364) :
Greg Clayton85851dd2010-12-04 00:10:17 +00001365 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00001366 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001367 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00001368 m_frame_format (),
1369 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001370 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001371 m_use_external_editor (false),
1372 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001373{
Caroline Ticef20e8232010-09-09 18:26:37 +00001374 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1375 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
1376 // 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 +00001377 // The same is true of CreateInstanceName().
1378
1379 if (GetInstanceName() == InstanceSettings::InvalidName())
1380 {
1381 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1382 m_owner.RegisterInstanceSettings (this);
1383 }
Caroline Ticef20e8232010-09-09 18:26:37 +00001384
1385 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001386 {
1387 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1388 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001389 }
1390}
1391
1392DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00001393 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001394 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00001395 m_frame_format (rhs.m_frame_format),
1396 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001397 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001398 m_use_external_editor (rhs.m_use_external_editor),
1399 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001400{
1401 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1402 CopyInstanceSettings (pending_settings, false);
1403 m_owner.RemovePendingSettings (m_instance_name);
1404}
1405
1406DebuggerInstanceSettings::~DebuggerInstanceSettings ()
1407{
1408}
1409
1410DebuggerInstanceSettings&
1411DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
1412{
1413 if (this != &rhs)
1414 {
Greg Clayton1b654882010-09-19 02:33:57 +00001415 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001416 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00001417 m_frame_format = rhs.m_frame_format;
1418 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001419 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001420 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001421 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001422 }
1423
1424 return *this;
1425}
1426
Greg Clayton1b654882010-09-19 02:33:57 +00001427bool
1428DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
1429{
1430 bool valid = false;
1431
1432 // Verify we have a value string.
1433 if (value == NULL || value[0] == '\0')
1434 {
1435 err.SetErrorString ("Missing value. Can't set terminal width without a value.\n");
1436 }
1437 else
1438 {
1439 char *end = NULL;
1440 const uint32_t width = ::strtoul (value, &end, 0);
1441
Johnny Chenea9fc182010-09-20 16:36:43 +00001442 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00001443 {
Johnny Chen433d7742010-09-20 17:04:41 +00001444 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00001445 valid = true;
1446 else
1447 err.SetErrorString ("Invalid term-width value; value must be between 10 and 1024.\n");
1448 }
1449 else
1450 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string.\n", value);
1451 }
1452
1453 return valid;
1454}
1455
1456
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001457void
1458DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1459 const char *index_value,
1460 const char *value,
1461 const ConstString &instance_name,
1462 const SettingEntry &entry,
1463 lldb::VarSetOperationType op,
1464 Error &err,
1465 bool pending)
1466{
Greg Clayton0603aa92010-10-04 01:05:56 +00001467
1468 if (var_name == TermWidthVarName())
1469 {
1470 if (ValidTermWidthValue (value, err))
1471 {
1472 m_term_width = ::strtoul (value, NULL, 0);
1473 }
1474 }
1475 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001476 {
Caroline Tice101c7c22010-09-09 06:25:08 +00001477 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001478 if (!pending)
1479 {
Caroline Tice49e27372010-09-07 18:35:40 +00001480 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1481 // strip off the brackets before passing it to BroadcastPromptChange.
1482
1483 std::string tmp_instance_name (instance_name.AsCString());
1484 if ((tmp_instance_name[0] == '[')
1485 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
1486 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
1487 ConstString new_name (tmp_instance_name.c_str());
1488
1489 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001490 }
1491 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001492 else if (var_name == GetFrameFormatName())
1493 {
1494 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
1495 }
1496 else if (var_name == GetThreadFormatName())
1497 {
1498 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
1499 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001500 else if (var_name == ScriptLangVarName())
1501 {
1502 bool success;
1503 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
1504 &success);
1505 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001506 else if (var_name == UseExternalEditorVarName ())
1507 {
1508 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, err);
1509 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001510 else if (var_name == AutoConfirmName ())
1511 {
1512 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, err);
1513 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001514}
1515
Caroline Tice12cecd72010-09-20 21:37:42 +00001516bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001517DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1518 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00001519 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00001520 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001521{
1522 if (var_name == PromptVarName())
1523 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001524 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001525
1526 }
1527 else if (var_name == ScriptLangVarName())
1528 {
1529 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
1530 }
Caroline Tice101c7c22010-09-09 06:25:08 +00001531 else if (var_name == TermWidthVarName())
1532 {
1533 StreamString width_str;
1534 width_str.Printf ("%d", m_term_width);
1535 value.AppendString (width_str.GetData());
1536 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001537 else if (var_name == GetFrameFormatName ())
1538 {
1539 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
1540 }
1541 else if (var_name == GetThreadFormatName ())
1542 {
1543 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
1544 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001545 else if (var_name == UseExternalEditorVarName())
1546 {
1547 if (m_use_external_editor)
1548 value.AppendString ("true");
1549 else
1550 value.AppendString ("false");
1551 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001552 else if (var_name == AutoConfirmName())
1553 {
1554 if (m_auto_confirm_on)
1555 value.AppendString ("true");
1556 else
1557 value.AppendString ("false");
1558 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001559 else
Caroline Tice12cecd72010-09-20 21:37:42 +00001560 {
1561 if (err)
1562 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1563 return false;
1564 }
1565 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001566}
1567
1568void
1569DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1570 bool pending)
1571{
1572 if (new_settings.get() == NULL)
1573 return;
1574
1575 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
1576
1577 m_prompt = new_debugger_settings->m_prompt;
1578 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00001579 {
1580 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1581 // strip off the brackets before passing it to BroadcastPromptChange.
1582
1583 std::string tmp_instance_name (m_instance_name.AsCString());
1584 if ((tmp_instance_name[0] == '[')
1585 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
1586 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
1587 ConstString new_name (tmp_instance_name.c_str());
1588
1589 BroadcastPromptChange (new_name, m_prompt.c_str());
1590 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001591 m_frame_format = new_debugger_settings->m_frame_format;
1592 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001593 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001594 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001595 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001596 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001597}
1598
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001599
1600bool
1601DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
1602{
1603 std::string tmp_prompt;
1604
1605 if (new_prompt != NULL)
1606 {
1607 tmp_prompt = new_prompt ;
1608 int len = tmp_prompt.size();
1609 if (len > 1
1610 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
1611 && (tmp_prompt[len-1] == tmp_prompt[0]))
1612 {
1613 tmp_prompt = tmp_prompt.substr(1,len-2);
1614 }
1615 len = tmp_prompt.size();
1616 if (tmp_prompt[len-1] != ' ')
1617 tmp_prompt.append(" ");
1618 }
1619 EventSP new_event_sp;
1620 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
1621 new EventDataBytes (tmp_prompt.c_str())));
1622
1623 if (instance_name.GetLength() != 0)
1624 {
1625 // Set prompt for a particular instance.
1626 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
1627 if (dbg != NULL)
1628 {
1629 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
1630 }
1631 }
1632
1633 return true;
1634}
1635
1636const ConstString
1637DebuggerInstanceSettings::CreateInstanceName ()
1638{
1639 static int instance_count = 1;
1640 StreamString sstr;
1641
1642 sstr.Printf ("debugger_%d", instance_count);
1643 ++instance_count;
1644
1645 const ConstString ret_val (sstr.GetData());
1646
1647 return ret_val;
1648}
1649
1650const ConstString &
1651DebuggerInstanceSettings::PromptVarName ()
1652{
1653 static ConstString prompt_var_name ("prompt");
1654
1655 return prompt_var_name;
1656}
1657
1658const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00001659DebuggerInstanceSettings::GetFrameFormatName ()
1660{
1661 static ConstString prompt_var_name ("frame-format");
1662
1663 return prompt_var_name;
1664}
1665
1666const ConstString &
1667DebuggerInstanceSettings::GetThreadFormatName ()
1668{
1669 static ConstString prompt_var_name ("thread-format");
1670
1671 return prompt_var_name;
1672}
1673
1674const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001675DebuggerInstanceSettings::ScriptLangVarName ()
1676{
1677 static ConstString script_lang_var_name ("script-lang");
1678
1679 return script_lang_var_name;
1680}
1681
Caroline Tice101c7c22010-09-09 06:25:08 +00001682const ConstString &
1683DebuggerInstanceSettings::TermWidthVarName ()
1684{
1685 static ConstString term_width_var_name ("term-width");
1686
1687 return term_width_var_name;
1688}
1689
Caroline Ticedaccaa92010-09-20 20:44:43 +00001690const ConstString &
1691DebuggerInstanceSettings::UseExternalEditorVarName ()
1692{
1693 static ConstString use_external_editor_var_name ("use-external-editor");
1694
1695 return use_external_editor_var_name;
1696}
1697
Jim Ingham3bcdb292010-10-04 22:44:14 +00001698const ConstString &
1699DebuggerInstanceSettings::AutoConfirmName ()
1700{
1701 static ConstString use_external_editor_var_name ("auto-confirm");
1702
1703 return use_external_editor_var_name;
1704}
1705
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001706//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001707// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001708//--------------------------------------------------
1709
1710
1711SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001712Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001713{
1714 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00001715 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
1716 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001717 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1718};
1719
Greg Claytonbb562b12010-10-04 02:44:26 +00001720#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00001721#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001722
Greg Clayton0603aa92010-10-04 01:05:56 +00001723#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1724 "{, ${frame.pc}}"\
1725 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00001726 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00001727 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00001728 "\\n"
1729
Greg Clayton315d2ca2010-11-02 01:53:21 +00001730//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1731// "{, ${frame.pc}}"\
1732// MODULE_WITH_FUNC\
1733// FILE_AND_LINE\
1734// "{, stop reason = ${thread.stop-reason}}"\
1735// "{, name = ${thread.name}}"\
1736// "{, queue = ${thread.queue}}"\
1737// "\\n"
1738
Greg Clayton0603aa92010-10-04 01:05:56 +00001739#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
1740 MODULE_WITH_FUNC\
1741 FILE_AND_LINE\
1742 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001743
1744SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001745Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001746{
Greg Clayton0603aa92010-10-04 01:05:56 +00001747// NAME Setting variable type Default Enum Init'd Hidden Help
1748// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00001749{ "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 +00001750{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00001751{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
1752{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001753{ "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 +00001754{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
1755{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001756{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001757};