blob: 10bb26791a11301e86a36417d2e2c3d72edbc3b9 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/lldb-private.h"
11#include "lldb/Core/ConnectionFileDescriptor.h"
12#include "lldb/Core/Debugger.h"
13#include "lldb/Core/InputReader.h"
14#include "lldb/Core/State.h"
Greg Clayton1b654882010-09-19 02:33:57 +000015#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Core/Timer.h"
Greg Claytona3406612011-02-07 23:24:47 +000017#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000018#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Target/TargetList.h"
20#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000021#include "lldb/Target/RegisterContext.h"
22#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Target/Thread.h"
24
25
26using namespace lldb;
27using namespace lldb_private;
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
Greg Clayton1b654882010-09-19 02:33:57 +000030static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000031static lldb::user_id_t g_unique_id = 1;
32
Greg Clayton1b654882010-09-19 02:33:57 +000033#pragma mark Static Functions
34
35static Mutex &
36GetDebuggerListMutex ()
37{
38 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
39 return g_mutex;
40}
41
42typedef std::vector<DebuggerSP> DebuggerList;
43
44static DebuggerList &
45GetDebuggerList()
46{
47 // hide the static debugger list inside a singleton accessor to avoid
48 // global init contructors
49 static DebuggerList g_list;
50 return g_list;
51}
52
53
54#pragma mark Debugger
55
Greg Clayton99d0faf2010-11-18 23:32:35 +000056UserSettingsControllerSP &
57Debugger::GetSettingsController ()
58{
59 static UserSettingsControllerSP g_settings_controller;
60 return g_settings_controller;
61}
62
Caroline Tice2f88aad2011-01-14 00:29:16 +000063int
64Debugger::TestDebuggerRefCount ()
65{
66 return g_shared_debugger_refcount;
67}
68
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069void
70Debugger::Initialize ()
71{
Greg Clayton66111032010-06-23 01:19:29 +000072 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +000073 {
Greg Clayton99d0faf2010-11-18 23:32:35 +000074 UserSettingsControllerSP &usc = GetSettingsController();
75 usc.reset (new SettingsController);
76 UserSettingsController::InitializeSettingsController (usc,
77 SettingsController::global_settings_table,
78 SettingsController::instance_settings_table);
Greg Claytondbe54502010-11-19 03:46:01 +000079 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +000080 }
Greg Clayton66111032010-06-23 01:19:29 +000081 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +000082
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083}
84
85void
86Debugger::Terminate ()
87{
Greg Clayton66111032010-06-23 01:19:29 +000088 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089 {
Greg Clayton66111032010-06-23 01:19:29 +000090 g_shared_debugger_refcount--;
91 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092 {
Greg Claytondbe54502010-11-19 03:46:01 +000093 lldb_private::WillTerminate();
94 lldb_private::Terminate();
Greg Clayton99d0faf2010-11-18 23:32:35 +000095 UserSettingsControllerSP &usc = GetSettingsController();
96 UserSettingsController::FinalizeSettingsController (usc);
97 usc.reset();
Caroline Tice6760a512011-01-17 21:55:19 +000098
99 // Clear our master list of debugger objects
100 Mutex::Locker locker (GetDebuggerListMutex ());
101 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103 }
104}
105
Greg Clayton66111032010-06-23 01:19:29 +0000106DebuggerSP
107Debugger::CreateInstance ()
108{
109 DebuggerSP debugger_sp (new Debugger);
110 // Scope for locker
111 {
112 Mutex::Locker locker (GetDebuggerListMutex ());
113 GetDebuggerList().push_back(debugger_sp);
114 }
115 return debugger_sp;
116}
117
Caroline Ticee02657b2011-01-22 01:02:07 +0000118void
119Debugger::Destroy (lldb::DebuggerSP &debugger_sp)
120{
121 if (debugger_sp.get() == NULL)
122 return;
123
124 Mutex::Locker locker (GetDebuggerListMutex ());
125 DebuggerList &debugger_list = GetDebuggerList ();
126 DebuggerList::iterator pos, end = debugger_list.end();
127 for (pos = debugger_list.begin (); pos != end; ++pos)
128 {
129 if ((*pos).get() == debugger_sp.get())
130 {
131 debugger_list.erase (pos);
132 return;
133 }
134 }
135
136}
137
Greg Clayton66111032010-06-23 01:19:29 +0000138lldb::DebuggerSP
139Debugger::GetSP ()
140{
141 lldb::DebuggerSP debugger_sp;
142
143 Mutex::Locker locker (GetDebuggerListMutex ());
144 DebuggerList &debugger_list = GetDebuggerList();
145 DebuggerList::iterator pos, end = debugger_list.end();
146 for (pos = debugger_list.begin(); pos != end; ++pos)
147 {
148 if ((*pos).get() == this)
149 {
150 debugger_sp = *pos;
151 break;
152 }
153 }
154 return debugger_sp;
155}
156
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000157lldb::DebuggerSP
158Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
159{
160 lldb::DebuggerSP debugger_sp;
161
162 Mutex::Locker locker (GetDebuggerListMutex ());
163 DebuggerList &debugger_list = GetDebuggerList();
164 DebuggerList::iterator pos, end = debugger_list.end();
165
166 for (pos = debugger_list.begin(); pos != end; ++pos)
167 {
168 if ((*pos).get()->m_instance_name == instance_name)
169 {
170 debugger_sp = *pos;
171 break;
172 }
173 }
174 return debugger_sp;
175}
Greg Clayton66111032010-06-23 01:19:29 +0000176
177TargetSP
178Debugger::FindTargetWithProcessID (lldb::pid_t pid)
179{
180 lldb::TargetSP target_sp;
181 Mutex::Locker locker (GetDebuggerListMutex ());
182 DebuggerList &debugger_list = GetDebuggerList();
183 DebuggerList::iterator pos, end = debugger_list.end();
184 for (pos = debugger_list.begin(); pos != end; ++pos)
185 {
186 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
187 if (target_sp)
188 break;
189 }
190 return target_sp;
191}
192
193
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000195 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000196 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000197 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 m_input_file (),
199 m_output_file (),
200 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201 m_target_list (),
202 m_listener ("lldb.Debugger"),
203 m_source_manager (),
Greg Clayton66111032010-06-23 01:19:29 +0000204 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
205 m_exe_ctx (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 m_input_readers (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000207 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208{
Greg Claytond46c87a2010-12-04 02:39:47 +0000209 m_input_comm.SetCloseOnEOF(false);
Greg Clayton66111032010-06-23 01:19:29 +0000210 m_command_interpreter_ap->Initialize ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211}
212
213Debugger::~Debugger ()
214{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000215 CleanUpInputReaders();
Greg Clayton66111032010-06-23 01:19:29 +0000216 int num_targets = m_target_list.GetNumTargets();
217 for (int i = 0; i < num_targets; i++)
218 {
219 ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
220 if (process_sp)
221 process_sp->Destroy();
222 }
223 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224}
225
226
227bool
228Debugger::GetAsyncExecution ()
229{
Greg Clayton66111032010-06-23 01:19:29 +0000230 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231}
232
233void
234Debugger::SetAsyncExecution (bool async_execution)
235{
Greg Clayton66111032010-06-23 01:19:29 +0000236 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237}
238
239void
240Debugger::DisconnectInput()
241{
242 m_input_comm.Clear ();
243}
244
245void
246Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
247{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000248 File &in_file = GetInputFile();
249 in_file.SetStream (fh, tranfer_ownership);
250 if (in_file.IsValid() == false)
251 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252
253 // Disconnect from any old connection if we had one
254 m_input_comm.Disconnect ();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000255 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), true));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
257
258 Error error;
259 if (m_input_comm.StartReadThread (&error) == false)
260 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000261 File &err_file = GetErrorFile();
262
263 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
264 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266}
267
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268void
269Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
270{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000271 File &out_file = GetOutputFile();
272 out_file.SetStream (fh, tranfer_ownership);
273 if (out_file.IsValid() == false)
274 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000275
276 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000277}
278
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279void
280Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
281{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000282 File &err_file = GetErrorFile();
283 err_file.SetStream (fh, tranfer_ownership);
284 if (err_file.IsValid() == false)
285 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286}
287
288CommandInterpreter &
289Debugger::GetCommandInterpreter ()
290{
Greg Clayton66111032010-06-23 01:19:29 +0000291 assert (m_command_interpreter_ap.get());
292 return *m_command_interpreter_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293}
294
295Listener &
296Debugger::GetListener ()
297{
298 return m_listener;
299}
300
301
302TargetSP
Jim Ingham2976d002010-08-26 21:32:51 +0000303Debugger::GetSelectedTarget ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000304{
Jim Ingham2976d002010-08-26 21:32:51 +0000305 return m_target_list.GetSelectedTarget ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306}
307
308ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000309Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310{
311 ExecutionContext exe_ctx;
312 exe_ctx.Clear();
313
Jim Ingham2976d002010-08-26 21:32:51 +0000314 lldb::TargetSP target_sp = GetSelectedTarget();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315 exe_ctx.target = target_sp.get();
316
317 if (target_sp)
318 {
319 exe_ctx.process = target_sp->GetProcessSP().get();
320 if (exe_ctx.process && exe_ctx.process->IsRunning() == false)
321 {
Jim Ingham2976d002010-08-26 21:32:51 +0000322 exe_ctx.thread = exe_ctx.process->GetThreadList().GetSelectedThread().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323 if (exe_ctx.thread == NULL)
324 exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
325 if (exe_ctx.thread)
326 {
Jim Ingham2976d002010-08-26 21:32:51 +0000327 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328 if (exe_ctx.frame == NULL)
329 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex (0).get();
330 }
331 }
332 }
333 return exe_ctx;
334
335}
336
337SourceManager &
338Debugger::GetSourceManager ()
339{
340 return m_source_manager;
341}
342
343
344TargetList&
345Debugger::GetTargetList ()
346{
347 return m_target_list;
348}
349
350void
351Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
352{
Caroline Ticeefed6132010-11-19 20:47:54 +0000353 if (bytes_len > 0)
354 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
355 else
356 ((Debugger *)baton)->DispatchInputEndOfFile ();
357}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358
359
360void
361Debugger::DispatchInput (const char *bytes, size_t bytes_len)
362{
Caroline Ticeefed6132010-11-19 20:47:54 +0000363 if (bytes == NULL || bytes_len == 0)
364 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365
366 WriteToDefaultReader (bytes, bytes_len);
367}
368
369void
Caroline Ticeefed6132010-11-19 20:47:54 +0000370Debugger::DispatchInputInterrupt ()
371{
372 m_input_reader_data.clear();
373
374 if (!m_input_readers.empty())
375 {
376 while (CheckIfTopInputReaderIsDone ()) ;
377
378 InputReaderSP reader_sp(m_input_readers.top());
379 if (reader_sp)
380 reader_sp->Notify (eInputReaderInterrupt);
381
382 while (CheckIfTopInputReaderIsDone ()) ;
383 }
384}
385
386void
387Debugger::DispatchInputEndOfFile ()
388{
389 m_input_reader_data.clear();
390
391 if (!m_input_readers.empty())
392 {
393 while (CheckIfTopInputReaderIsDone ()) ;
394
395 InputReaderSP reader_sp(m_input_readers.top());
396 if (reader_sp)
397 reader_sp->Notify (eInputReaderEndOfFile);
398
399 while (CheckIfTopInputReaderIsDone ()) ;
400 }
401}
402
403void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000404Debugger::CleanUpInputReaders ()
405{
406 m_input_reader_data.clear();
407
408 while (m_input_readers.size() > 1)
409 {
410 while (CheckIfTopInputReaderIsDone ()) ;
411
412 InputReaderSP reader_sp (m_input_readers.top());
413 if (reader_sp)
414 {
415 reader_sp->Notify (eInputReaderEndOfFile);
416 reader_sp->SetIsDone (true);
417 }
418 }
419}
420
421void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
423{
424 if (bytes && bytes_len)
425 m_input_reader_data.append (bytes, bytes_len);
426
427 if (m_input_reader_data.empty())
428 return;
429
430 while (!m_input_readers.empty() && !m_input_reader_data.empty())
431 {
432 while (CheckIfTopInputReaderIsDone ())
433 /* Do nothing. */;
434
435 // Get the input reader from the top of the stack
436 InputReaderSP reader_sp(m_input_readers.top());
437
438 if (!reader_sp)
439 break;
440
Greg Clayton471b31c2010-07-20 22:52:08 +0000441 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442 m_input_reader_data.size());
443 if (bytes_handled)
444 {
445 m_input_reader_data.erase (0, bytes_handled);
446 }
447 else
448 {
449 // No bytes were handled, we might not have reached our
450 // granularity, just return and wait for more data
451 break;
452 }
453 }
454
455 // Flush out any input readers that are donesvn
456 while (CheckIfTopInputReaderIsDone ())
457 /* Do nothing. */;
458
459}
460
461void
462Debugger::PushInputReader (const InputReaderSP& reader_sp)
463{
464 if (!reader_sp)
465 return;
466 if (!m_input_readers.empty())
467 {
468 // Deactivate the old top reader
469 InputReaderSP top_reader_sp (m_input_readers.top());
470 if (top_reader_sp)
471 top_reader_sp->Notify (eInputReaderDeactivate);
472 }
473 m_input_readers.push (reader_sp);
474 reader_sp->Notify (eInputReaderActivate);
475 ActivateInputReader (reader_sp);
476}
477
478bool
479Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp)
480{
481 bool result = false;
482
483 // The reader on the stop of the stack is done, so let the next
484 // read on the stack referesh its prompt and if there is one...
485 if (!m_input_readers.empty())
486 {
487 InputReaderSP reader_sp(m_input_readers.top());
488
489 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
490 {
491 m_input_readers.pop ();
492 reader_sp->Notify (eInputReaderDeactivate);
493 reader_sp->Notify (eInputReaderDone);
494 result = true;
495
496 if (!m_input_readers.empty())
497 {
498 reader_sp = m_input_readers.top();
499 if (reader_sp)
500 {
501 ActivateInputReader (reader_sp);
502 reader_sp->Notify (eInputReaderReactivate);
503 }
504 }
505 }
506 }
507 return result;
508}
509
510bool
511Debugger::CheckIfTopInputReaderIsDone ()
512{
513 bool result = false;
514 if (!m_input_readers.empty())
515 {
516 InputReaderSP reader_sp(m_input_readers.top());
517
518 if (reader_sp && reader_sp->IsDone())
519 {
520 result = true;
521 PopInputReader (reader_sp);
522 }
523 }
524 return result;
525}
526
527void
528Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
529{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000530 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000532 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000534 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000535
536 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537
Greg Claytona3406612011-02-07 23:24:47 +0000538 switch (reader_sp->GetGranularity())
539 {
540 case eInputReaderGranularityByte:
541 case eInputReaderGranularityWord:
542 tty.SetCanonical (false);
543 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544
Greg Claytona3406612011-02-07 23:24:47 +0000545 case eInputReaderGranularityLine:
546 case eInputReaderGranularityAll:
547 tty.SetCanonical (true);
548 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549
Greg Claytona3406612011-02-07 23:24:47 +0000550 default:
551 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552 }
553 }
554}
Greg Clayton66111032010-06-23 01:19:29 +0000555
556void
557Debugger::UpdateExecutionContext (ExecutionContext *override_context)
558{
559 m_exe_ctx.Clear();
560
561 if (override_context != NULL)
562 {
563 m_exe_ctx.target = override_context->target;
564 m_exe_ctx.process = override_context->process;
565 m_exe_ctx.thread = override_context->thread;
566 m_exe_ctx.frame = override_context->frame;
567 }
568 else
569 {
Jim Ingham2976d002010-08-26 21:32:51 +0000570 TargetSP target_sp (GetSelectedTarget());
Greg Clayton66111032010-06-23 01:19:29 +0000571 if (target_sp)
572 {
573 m_exe_ctx.target = target_sp.get();
574 m_exe_ctx.process = target_sp->GetProcessSP().get();
Johnny Chen725945d2010-09-03 22:35:47 +0000575 if (m_exe_ctx.process && m_exe_ctx.process->IsAlive() && !m_exe_ctx.process->IsRunning())
Greg Clayton66111032010-06-23 01:19:29 +0000576 {
Jim Ingham2976d002010-08-26 21:32:51 +0000577 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetSelectedThread().get();
Greg Clayton66111032010-06-23 01:19:29 +0000578 if (m_exe_ctx.thread == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000579 {
Greg Clayton66111032010-06-23 01:19:29 +0000580 m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000581 // If we didn't have a selected thread, select one here.
582 if (m_exe_ctx.thread != NULL)
Johnny Chenc13ee522010-09-14 00:53:53 +0000583 m_exe_ctx.process->GetThreadList().SetSelectedThreadByID(m_exe_ctx.thread->GetID());
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000584 }
Greg Clayton66111032010-06-23 01:19:29 +0000585 if (m_exe_ctx.thread)
586 {
Jim Ingham2976d002010-08-26 21:32:51 +0000587 m_exe_ctx.frame = m_exe_ctx.thread->GetSelectedFrame().get();
Greg Clayton66111032010-06-23 01:19:29 +0000588 if (m_exe_ctx.frame == NULL)
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000589 {
Greg Clayton66111032010-06-23 01:19:29 +0000590 m_exe_ctx.frame = m_exe_ctx.thread->GetStackFrameAtIndex (0).get();
Jim Ingham59ce7fe2010-09-10 23:06:30 +0000591 // If we didn't have a selected frame select one here.
592 if (m_exe_ctx.frame != NULL)
593 m_exe_ctx.thread->SetSelectedFrame(m_exe_ctx.frame);
594 }
Greg Clayton66111032010-06-23 01:19:29 +0000595 }
596 }
597 }
598 }
599}
600
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000601DebuggerSP
602Debugger::FindDebuggerWithID (lldb::user_id_t id)
603{
604 lldb::DebuggerSP debugger_sp;
605
606 Mutex::Locker locker (GetDebuggerListMutex ());
607 DebuggerList &debugger_list = GetDebuggerList();
608 DebuggerList::iterator pos, end = debugger_list.end();
609 for (pos = debugger_list.begin(); pos != end; ++pos)
610 {
611 if ((*pos).get()->GetID() == id)
612 {
613 debugger_sp = *pos;
614 break;
615 }
616 }
617 return debugger_sp;
618}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000619
Greg Clayton1b654882010-09-19 02:33:57 +0000620static void
621TestPromptFormats (StackFrame *frame)
622{
623 if (frame == NULL)
624 return;
625
626 StreamString s;
627 const char *prompt_format =
628 "{addr = '${addr}'\n}"
629 "{process.id = '${process.id}'\n}"
630 "{process.name = '${process.name}'\n}"
631 "{process.file.basename = '${process.file.basename}'\n}"
632 "{process.file.fullpath = '${process.file.fullpath}'\n}"
633 "{thread.id = '${thread.id}'\n}"
634 "{thread.index = '${thread.index}'\n}"
635 "{thread.name = '${thread.name}'\n}"
636 "{thread.queue = '${thread.queue}'\n}"
637 "{thread.stop-reason = '${thread.stop-reason}'\n}"
638 "{target.arch = '${target.arch}'\n}"
639 "{module.file.basename = '${module.file.basename}'\n}"
640 "{module.file.fullpath = '${module.file.fullpath}'\n}"
641 "{file.basename = '${file.basename}'\n}"
642 "{file.fullpath = '${file.fullpath}'\n}"
643 "{frame.index = '${frame.index}'\n}"
644 "{frame.pc = '${frame.pc}'\n}"
645 "{frame.sp = '${frame.sp}'\n}"
646 "{frame.fp = '${frame.fp}'\n}"
647 "{frame.flags = '${frame.flags}'\n}"
648 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
649 "{frame.reg.rip = '${frame.reg.rip}'\n}"
650 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
651 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
652 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
653 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
654 "{frame.reg.carp = '${frame.reg.carp}'\n}"
655 "{function.id = '${function.id}'\n}"
656 "{function.name = '${function.name}'\n}"
657 "{function.addr-offset = '${function.addr-offset}'\n}"
658 "{function.line-offset = '${function.line-offset}'\n}"
659 "{function.pc-offset = '${function.pc-offset}'\n}"
660 "{line.file.basename = '${line.file.basename}'\n}"
661 "{line.file.fullpath = '${line.file.fullpath}'\n}"
662 "{line.number = '${line.number}'\n}"
663 "{line.start-addr = '${line.start-addr}'\n}"
664 "{line.end-addr = '${line.end-addr}'\n}"
665;
666
667 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
668 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000669 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000670 const char *end = NULL;
671 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
672 {
673 printf("%s\n", s.GetData());
674 }
675 else
676 {
677 printf ("error: at '%s'\n", end);
678 printf ("what we got: %s\n", s.GetData());
679 }
680}
681
682bool
683Debugger::FormatPrompt
684(
685 const char *format,
686 const SymbolContext *sc,
687 const ExecutionContext *exe_ctx,
688 const Address *addr,
689 Stream &s,
690 const char **end
691)
692{
693 bool success = true;
694 const char *p;
695 for (p = format; *p != '\0'; ++p)
696 {
697 size_t non_special_chars = ::strcspn (p, "${}\\");
698 if (non_special_chars > 0)
699 {
700 if (success)
701 s.Write (p, non_special_chars);
702 p += non_special_chars;
703 }
704
705 if (*p == '\0')
706 {
707 break;
708 }
709 else if (*p == '{')
710 {
711 // Start a new scope that must have everything it needs if it is to
712 // to make it into the final output stream "s". If you want to make
713 // a format that only prints out the function or symbol name if there
714 // is one in the symbol context you can use:
715 // "{function =${function.name}}"
716 // The first '{' starts a new scope that end with the matching '}' at
717 // the end of the string. The contents "function =${function.name}"
718 // will then be evaluated and only be output if there is a function
719 // or symbol with a valid name.
720 StreamString sub_strm;
721
722 ++p; // Skip the '{'
723
724 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p))
725 {
726 // The stream had all it needed
727 s.Write(sub_strm.GetData(), sub_strm.GetSize());
728 }
729 if (*p != '}')
730 {
731 success = false;
732 break;
733 }
734 }
735 else if (*p == '}')
736 {
737 // End of a enclosing scope
738 break;
739 }
740 else if (*p == '$')
741 {
742 // We have a prompt variable to print
743 ++p;
744 if (*p == '{')
745 {
746 ++p;
747 const char *var_name_begin = p;
748 const char *var_name_end = ::strchr (p, '}');
749
750 if (var_name_end && var_name_begin < var_name_end)
751 {
752 // if we have already failed to parse, skip this variable
753 if (success)
754 {
755 const char *cstr = NULL;
756 Address format_addr;
757 bool calculate_format_addr_function_offset = false;
758 // Set reg_kind and reg_num to invalid values
759 RegisterKind reg_kind = kNumRegisterKinds;
760 uint32_t reg_num = LLDB_INVALID_REGNUM;
761 FileSpec format_file_spec;
762 const lldb::RegisterInfo *reg_info = NULL;
763 RegisterContext *reg_ctx = NULL;
764
765 // Each variable must set success to true below...
766 bool var_success = false;
767 switch (var_name_begin[0])
768 {
769 case 'a':
770 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
771 {
772 if (addr && addr->IsValid())
773 {
774 var_success = true;
775 format_addr = *addr;
776 }
777 }
778 break;
779
780 case 'p':
781 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
782 {
783 if (exe_ctx && exe_ctx->process != NULL)
784 {
785 var_name_begin += ::strlen ("process.");
786 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
787 {
788 s.Printf("%i", exe_ctx->process->GetID());
789 var_success = true;
790 }
791 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
792 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
793 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
794 {
795 ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
796 if (exe_module_sp)
797 {
798 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
799 {
800 format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
801 var_success = format_file_spec;
802 }
803 else
804 {
805 format_file_spec = exe_module_sp->GetFileSpec();
806 var_success = format_file_spec;
807 }
808 }
809 }
810 }
811 }
812 break;
813
814 case 't':
815 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
816 {
817 if (exe_ctx && exe_ctx->thread)
818 {
819 var_name_begin += ::strlen ("thread.");
820 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
821 {
822 s.Printf("0x%4.4x", exe_ctx->thread->GetID());
823 var_success = true;
824 }
825 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
826 {
827 s.Printf("%u", exe_ctx->thread->GetIndexID());
828 var_success = true;
829 }
830 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
831 {
832 cstr = exe_ctx->thread->GetName();
833 var_success = cstr && cstr[0];
834 if (var_success)
835 s.PutCString(cstr);
836 }
837 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
838 {
839 cstr = exe_ctx->thread->GetQueueName();
840 var_success = cstr && cstr[0];
841 if (var_success)
842 s.PutCString(cstr);
843 }
844 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
845 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000846 StopInfoSP stop_info_sp = exe_ctx->thread->GetStopInfo ();
847 if (stop_info_sp)
Greg Clayton1b654882010-09-19 02:33:57 +0000848 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000849 cstr = stop_info_sp->GetDescription();
Greg Clayton1b654882010-09-19 02:33:57 +0000850 if (cstr && cstr[0])
851 {
852 s.PutCString(cstr);
853 var_success = true;
854 }
855 }
856 }
857 }
858 }
859 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
860 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000861 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
862 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +0000863 {
Greg Clayton1b654882010-09-19 02:33:57 +0000864 var_name_begin += ::strlen ("target.");
865 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
866 {
867 ArchSpec arch (target->GetArchitecture ());
868 if (arch.IsValid())
869 {
870 s.PutCString (arch.AsCString());
871 var_success = true;
872 }
873 }
874 }
875 }
876 break;
877
878
879 case 'm':
880 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
881 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000882 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +0000883 {
Greg Clayton0603aa92010-10-04 01:05:56 +0000884 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +0000885 var_name_begin += ::strlen ("module.");
886
887 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
888 {
889 if (module->GetFileSpec())
890 {
891 var_name_begin += ::strlen ("file.");
892
893 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
894 {
895 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
896 var_success = format_file_spec;
897 }
898 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
899 {
900 format_file_spec = module->GetFileSpec();
901 var_success = format_file_spec;
902 }
903 }
904 }
905 }
906 }
907 break;
908
909
910 case 'f':
911 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
912 {
913 if (sc && sc->comp_unit != NULL)
914 {
915 var_name_begin += ::strlen ("file.");
916
917 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
918 {
919 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
920 var_success = format_file_spec;
921 }
922 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
923 {
924 format_file_spec = *sc->comp_unit;
925 var_success = format_file_spec;
926 }
927 }
928 }
929 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
930 {
931 if (exe_ctx && exe_ctx->frame)
932 {
933 var_name_begin += ::strlen ("frame.");
934 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
935 {
936 s.Printf("%u", exe_ctx->frame->GetFrameIndex());
937 var_success = true;
938 }
939 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
940 {
941 reg_kind = eRegisterKindGeneric;
942 reg_num = LLDB_REGNUM_GENERIC_PC;
943 var_success = true;
944 }
945 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
946 {
947 reg_kind = eRegisterKindGeneric;
948 reg_num = LLDB_REGNUM_GENERIC_SP;
949 var_success = true;
950 }
951 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
952 {
953 reg_kind = eRegisterKindGeneric;
954 reg_num = LLDB_REGNUM_GENERIC_FP;
955 var_success = true;
956 }
957 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
958 {
959 reg_kind = eRegisterKindGeneric;
960 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
961 var_success = true;
962 }
963 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
964 {
Greg Clayton5ccbd292011-01-06 22:15:06 +0000965 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +0000966 if (reg_ctx)
967 {
968 var_name_begin += ::strlen ("reg.");
969 if (var_name_begin < var_name_end)
970 {
971 std::string reg_name (var_name_begin, var_name_end);
972 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
973 if (reg_info)
974 var_success = true;
975 }
976 }
977 }
978 }
979 }
980 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
981 {
982 if (sc && (sc->function != NULL || sc->symbol != NULL))
983 {
984 var_name_begin += ::strlen ("function.");
985 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
986 {
987 if (sc->function)
988 s.Printf("function{0x%8.8x}", sc->function->GetID());
989 else
990 s.Printf("symbol[%u]", sc->symbol->GetID());
991
992 var_success = true;
993 }
994 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
995 {
996 if (sc->function)
997 cstr = sc->function->GetName().AsCString (NULL);
998 else if (sc->symbol)
999 cstr = sc->symbol->GetName().AsCString (NULL);
1000 if (cstr)
1001 {
1002 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001003
1004 if (sc->block)
1005 {
1006 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1007 if (inline_block)
1008 {
1009 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1010 if (inline_info)
1011 {
1012 s.PutCString(" [inlined] ");
1013 inline_info->GetName().Dump(&s);
1014 }
1015 }
1016 }
Greg Clayton1b654882010-09-19 02:33:57 +00001017 var_success = true;
1018 }
1019 }
1020 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1021 {
1022 var_success = addr != NULL;
1023 if (var_success)
1024 {
1025 format_addr = *addr;
1026 calculate_format_addr_function_offset = true;
1027 }
1028 }
1029 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1030 {
1031 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1032 if (var_success)
1033 {
1034 format_addr = sc->line_entry.range.GetBaseAddress();
1035 calculate_format_addr_function_offset = true;
1036 }
1037 }
1038 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1039 {
1040 var_success = exe_ctx->frame;
1041 if (var_success)
1042 {
1043 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1044 calculate_format_addr_function_offset = true;
1045 }
1046 }
1047 }
1048 }
1049 break;
1050
1051 case 'l':
1052 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1053 {
1054 if (sc && sc->line_entry.IsValid())
1055 {
1056 var_name_begin += ::strlen ("line.");
1057 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1058 {
1059 var_name_begin += ::strlen ("file.");
1060
1061 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1062 {
1063 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1064 var_success = format_file_spec;
1065 }
1066 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1067 {
1068 format_file_spec = sc->line_entry.file;
1069 var_success = format_file_spec;
1070 }
1071 }
1072 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1073 {
1074 var_success = true;
1075 s.Printf("%u", sc->line_entry.line);
1076 }
1077 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1078 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1079 {
1080 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1081 if (var_success)
1082 {
1083 format_addr = sc->line_entry.range.GetBaseAddress();
1084 if (var_name_begin[0] == 'e')
1085 format_addr.Slide (sc->line_entry.range.GetByteSize());
1086 }
1087 }
1088 }
1089 }
1090 break;
1091 }
1092
1093 if (var_success)
1094 {
1095 // If format addr is valid, then we need to print an address
1096 if (reg_num != LLDB_INVALID_REGNUM)
1097 {
1098 // We have a register value to display...
1099 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1100 {
1101 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1102 }
1103 else
1104 {
1105 if (reg_ctx == NULL)
Greg Clayton5ccbd292011-01-06 22:15:06 +00001106 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001107
1108 if (reg_ctx)
1109 {
1110 if (reg_kind != kNumRegisterKinds)
1111 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1112 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1113 var_success = reg_info != NULL;
1114 }
1115 }
1116 }
1117
1118 if (reg_info != NULL)
1119 {
1120 DataExtractor reg_data;
1121 var_success = reg_ctx->ReadRegisterBytes (reg_info->kinds[eRegisterKindLLDB], reg_data);
1122 {
1123 reg_data.Dump(&s, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
1124 }
1125 }
1126
1127 if (format_file_spec)
1128 {
1129 s << format_file_spec;
1130 }
1131
1132 // If format addr is valid, then we need to print an address
1133 if (format_addr.IsValid())
1134 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001135 var_success = false;
1136
Greg Clayton1b654882010-09-19 02:33:57 +00001137 if (calculate_format_addr_function_offset)
1138 {
1139 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001140
Greg Clayton0603aa92010-10-04 01:05:56 +00001141 if (sc)
1142 {
1143 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001144 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001145 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001146 if (sc->block)
1147 {
1148 // Check to make sure we aren't in an inline
1149 // function. If we are, use the inline block
1150 // range that contains "format_addr" since
1151 // blocks can be discontiguous.
1152 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1153 AddressRange inline_range;
1154 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1155 func_addr = inline_range.GetBaseAddress();
1156 }
1157 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001158 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1159 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1160 }
1161
1162 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001163 {
1164 if (func_addr.GetSection() == format_addr.GetSection())
1165 {
1166 addr_t func_file_addr = func_addr.GetFileAddress();
1167 addr_t addr_file_addr = format_addr.GetFileAddress();
1168 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001169 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001170 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001171 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001172 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001173 }
1174 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001175 {
1176 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1177 if (target)
1178 {
1179 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1180 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1181 if (addr_load_addr > func_load_addr)
1182 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1183 else if (addr_load_addr < func_load_addr)
1184 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1185 var_success = true;
1186 }
1187 }
Greg Clayton1b654882010-09-19 02:33:57 +00001188 }
1189 }
1190 else
1191 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001192 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001193 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001194 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1195 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001196 if (vaddr == LLDB_INVALID_ADDRESS)
1197 vaddr = format_addr.GetFileAddress ();
1198
1199 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001200 {
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001201 int addr_width = 0;
1202 if (exe_ctx && exe_ctx->process)
1203 addr_width = exe_ctx->process->GetAddressByteSize() * 2;
1204 if (addr_width == 0)
1205 addr_width = 16;
1206 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001207 var_success = true;
1208 }
Greg Clayton1b654882010-09-19 02:33:57 +00001209 }
1210 }
1211 }
1212
1213 if (var_success == false)
1214 success = false;
1215 }
1216 p = var_name_end;
1217 }
1218 else
1219 break;
1220 }
1221 else
1222 {
1223 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1224 s.PutChar(*p);
1225 }
1226 }
1227 else if (*p == '\\')
1228 {
1229 ++p; // skip the slash
1230 switch (*p)
1231 {
1232 case 'a': s.PutChar ('\a'); break;
1233 case 'b': s.PutChar ('\b'); break;
1234 case 'f': s.PutChar ('\f'); break;
1235 case 'n': s.PutChar ('\n'); break;
1236 case 'r': s.PutChar ('\r'); break;
1237 case 't': s.PutChar ('\t'); break;
1238 case 'v': s.PutChar ('\v'); break;
1239 case '\'': s.PutChar ('\''); break;
1240 case '\\': s.PutChar ('\\'); break;
1241 case '0':
1242 // 1 to 3 octal chars
1243 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001244 // Make a string that can hold onto the initial zero char,
1245 // up to 3 octal digits, and a terminating NULL.
1246 char oct_str[5] = { 0, 0, 0, 0, 0 };
1247
1248 int i;
1249 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1250 oct_str[i] = p[i];
1251
1252 // We don't want to consume the last octal character since
1253 // the main for loop will do this for us, so we advance p by
1254 // one less than i (even if i is zero)
1255 p += i - 1;
1256 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
1257 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001258 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001259 char octal_char = octal_value;
1260 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00001261 }
Greg Clayton1b654882010-09-19 02:33:57 +00001262 }
1263 break;
1264
1265 case 'x':
1266 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00001267 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001268 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001269 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00001270
Greg Clayton0603aa92010-10-04 01:05:56 +00001271 // Make a string that can hold onto two hex chars plus a
1272 // NULL terminator
1273 char hex_str[3] = { 0,0,0 };
1274 hex_str[0] = *p;
1275 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001276 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001277 ++p; // Skip the first of the two hex chars
1278 hex_str[1] = *p;
1279 }
1280
1281 unsigned long hex_value = strtoul (hex_str, NULL, 16);
1282 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001283 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00001284 }
1285 else
1286 {
1287 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00001288 }
1289 break;
1290
1291 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00001292 // Just desensitize any other character by just printing what
1293 // came after the '\'
1294 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00001295 break;
1296
1297 }
1298
1299 }
1300 }
1301 if (end)
1302 *end = p;
1303 return success;
1304}
1305
1306#pragma mark Debugger::SettingsController
1307
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001308//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001309// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001310//--------------------------------------------------
1311
Greg Clayton1b654882010-09-19 02:33:57 +00001312Debugger::SettingsController::SettingsController () :
Caroline Tice101c7c22010-09-09 06:25:08 +00001313 UserSettingsController ("", lldb::UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001314{
Caroline Tice91123da2010-09-08 17:48:55 +00001315 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
1316 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001317}
1318
Greg Clayton1b654882010-09-19 02:33:57 +00001319Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001320{
1321}
1322
1323
1324lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00001325Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001326{
Greg Claytondbe54502010-11-19 03:46:01 +00001327 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00001328 false, instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001329 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1330 return new_settings_sp;
1331}
1332
Greg Clayton1b654882010-09-19 02:33:57 +00001333#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001334//--------------------------------------------------
1335// class DebuggerInstanceSettings
1336//--------------------------------------------------
1337
Greg Claytona7015092010-09-18 01:14:36 +00001338DebuggerInstanceSettings::DebuggerInstanceSettings
1339(
1340 UserSettingsController &owner,
1341 bool live_instance,
1342 const char *name
1343) :
Greg Clayton85851dd2010-12-04 00:10:17 +00001344 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00001345 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001346 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00001347 m_frame_format (),
1348 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001349 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001350 m_use_external_editor (false),
1351 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001352{
Caroline Ticef20e8232010-09-09 18:26:37 +00001353 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1354 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
1355 // 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 +00001356 // The same is true of CreateInstanceName().
1357
1358 if (GetInstanceName() == InstanceSettings::InvalidName())
1359 {
1360 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1361 m_owner.RegisterInstanceSettings (this);
1362 }
Caroline Ticef20e8232010-09-09 18:26:37 +00001363
1364 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001365 {
1366 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1367 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001368 }
1369}
1370
1371DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00001372 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001373 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00001374 m_frame_format (rhs.m_frame_format),
1375 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001376 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001377 m_use_external_editor (rhs.m_use_external_editor),
1378 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001379{
1380 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1381 CopyInstanceSettings (pending_settings, false);
1382 m_owner.RemovePendingSettings (m_instance_name);
1383}
1384
1385DebuggerInstanceSettings::~DebuggerInstanceSettings ()
1386{
1387}
1388
1389DebuggerInstanceSettings&
1390DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
1391{
1392 if (this != &rhs)
1393 {
Greg Clayton1b654882010-09-19 02:33:57 +00001394 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001395 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00001396 m_frame_format = rhs.m_frame_format;
1397 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001398 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001399 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001400 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001401 }
1402
1403 return *this;
1404}
1405
Greg Clayton1b654882010-09-19 02:33:57 +00001406bool
1407DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
1408{
1409 bool valid = false;
1410
1411 // Verify we have a value string.
1412 if (value == NULL || value[0] == '\0')
1413 {
1414 err.SetErrorString ("Missing value. Can't set terminal width without a value.\n");
1415 }
1416 else
1417 {
1418 char *end = NULL;
1419 const uint32_t width = ::strtoul (value, &end, 0);
1420
Johnny Chenea9fc182010-09-20 16:36:43 +00001421 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00001422 {
Johnny Chen433d7742010-09-20 17:04:41 +00001423 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00001424 valid = true;
1425 else
1426 err.SetErrorString ("Invalid term-width value; value must be between 10 and 1024.\n");
1427 }
1428 else
1429 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string.\n", value);
1430 }
1431
1432 return valid;
1433}
1434
1435
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001436void
1437DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1438 const char *index_value,
1439 const char *value,
1440 const ConstString &instance_name,
1441 const SettingEntry &entry,
1442 lldb::VarSetOperationType op,
1443 Error &err,
1444 bool pending)
1445{
Greg Clayton0603aa92010-10-04 01:05:56 +00001446
1447 if (var_name == TermWidthVarName())
1448 {
1449 if (ValidTermWidthValue (value, err))
1450 {
1451 m_term_width = ::strtoul (value, NULL, 0);
1452 }
1453 }
1454 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001455 {
Caroline Tice101c7c22010-09-09 06:25:08 +00001456 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001457 if (!pending)
1458 {
Caroline Tice49e27372010-09-07 18:35:40 +00001459 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1460 // strip off the brackets before passing it to BroadcastPromptChange.
1461
1462 std::string tmp_instance_name (instance_name.AsCString());
1463 if ((tmp_instance_name[0] == '[')
1464 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
1465 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
1466 ConstString new_name (tmp_instance_name.c_str());
1467
1468 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001469 }
1470 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001471 else if (var_name == GetFrameFormatName())
1472 {
1473 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
1474 }
1475 else if (var_name == GetThreadFormatName())
1476 {
1477 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
1478 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001479 else if (var_name == ScriptLangVarName())
1480 {
1481 bool success;
1482 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
1483 &success);
1484 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001485 else if (var_name == UseExternalEditorVarName ())
1486 {
1487 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, err);
1488 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001489 else if (var_name == AutoConfirmName ())
1490 {
1491 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, err);
1492 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001493}
1494
Caroline Tice12cecd72010-09-20 21:37:42 +00001495bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001496DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1497 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00001498 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00001499 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001500{
1501 if (var_name == PromptVarName())
1502 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001503 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001504
1505 }
1506 else if (var_name == ScriptLangVarName())
1507 {
1508 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
1509 }
Caroline Tice101c7c22010-09-09 06:25:08 +00001510 else if (var_name == TermWidthVarName())
1511 {
1512 StreamString width_str;
1513 width_str.Printf ("%d", m_term_width);
1514 value.AppendString (width_str.GetData());
1515 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001516 else if (var_name == GetFrameFormatName ())
1517 {
1518 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
1519 }
1520 else if (var_name == GetThreadFormatName ())
1521 {
1522 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
1523 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001524 else if (var_name == UseExternalEditorVarName())
1525 {
1526 if (m_use_external_editor)
1527 value.AppendString ("true");
1528 else
1529 value.AppendString ("false");
1530 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001531 else if (var_name == AutoConfirmName())
1532 {
1533 if (m_auto_confirm_on)
1534 value.AppendString ("true");
1535 else
1536 value.AppendString ("false");
1537 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001538 else
Caroline Tice12cecd72010-09-20 21:37:42 +00001539 {
1540 if (err)
1541 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1542 return false;
1543 }
1544 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001545}
1546
1547void
1548DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1549 bool pending)
1550{
1551 if (new_settings.get() == NULL)
1552 return;
1553
1554 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
1555
1556 m_prompt = new_debugger_settings->m_prompt;
1557 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00001558 {
1559 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1560 // strip off the brackets before passing it to BroadcastPromptChange.
1561
1562 std::string tmp_instance_name (m_instance_name.AsCString());
1563 if ((tmp_instance_name[0] == '[')
1564 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
1565 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
1566 ConstString new_name (tmp_instance_name.c_str());
1567
1568 BroadcastPromptChange (new_name, m_prompt.c_str());
1569 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001570 m_frame_format = new_debugger_settings->m_frame_format;
1571 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001572 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001573 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001574 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001575 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001576}
1577
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001578
1579bool
1580DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
1581{
1582 std::string tmp_prompt;
1583
1584 if (new_prompt != NULL)
1585 {
1586 tmp_prompt = new_prompt ;
1587 int len = tmp_prompt.size();
1588 if (len > 1
1589 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
1590 && (tmp_prompt[len-1] == tmp_prompt[0]))
1591 {
1592 tmp_prompt = tmp_prompt.substr(1,len-2);
1593 }
1594 len = tmp_prompt.size();
1595 if (tmp_prompt[len-1] != ' ')
1596 tmp_prompt.append(" ");
1597 }
1598 EventSP new_event_sp;
1599 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
1600 new EventDataBytes (tmp_prompt.c_str())));
1601
1602 if (instance_name.GetLength() != 0)
1603 {
1604 // Set prompt for a particular instance.
1605 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
1606 if (dbg != NULL)
1607 {
1608 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
1609 }
1610 }
1611
1612 return true;
1613}
1614
1615const ConstString
1616DebuggerInstanceSettings::CreateInstanceName ()
1617{
1618 static int instance_count = 1;
1619 StreamString sstr;
1620
1621 sstr.Printf ("debugger_%d", instance_count);
1622 ++instance_count;
1623
1624 const ConstString ret_val (sstr.GetData());
1625
1626 return ret_val;
1627}
1628
1629const ConstString &
1630DebuggerInstanceSettings::PromptVarName ()
1631{
1632 static ConstString prompt_var_name ("prompt");
1633
1634 return prompt_var_name;
1635}
1636
1637const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00001638DebuggerInstanceSettings::GetFrameFormatName ()
1639{
1640 static ConstString prompt_var_name ("frame-format");
1641
1642 return prompt_var_name;
1643}
1644
1645const ConstString &
1646DebuggerInstanceSettings::GetThreadFormatName ()
1647{
1648 static ConstString prompt_var_name ("thread-format");
1649
1650 return prompt_var_name;
1651}
1652
1653const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001654DebuggerInstanceSettings::ScriptLangVarName ()
1655{
1656 static ConstString script_lang_var_name ("script-lang");
1657
1658 return script_lang_var_name;
1659}
1660
Caroline Tice101c7c22010-09-09 06:25:08 +00001661const ConstString &
1662DebuggerInstanceSettings::TermWidthVarName ()
1663{
1664 static ConstString term_width_var_name ("term-width");
1665
1666 return term_width_var_name;
1667}
1668
Caroline Ticedaccaa92010-09-20 20:44:43 +00001669const ConstString &
1670DebuggerInstanceSettings::UseExternalEditorVarName ()
1671{
1672 static ConstString use_external_editor_var_name ("use-external-editor");
1673
1674 return use_external_editor_var_name;
1675}
1676
Jim Ingham3bcdb292010-10-04 22:44:14 +00001677const ConstString &
1678DebuggerInstanceSettings::AutoConfirmName ()
1679{
1680 static ConstString use_external_editor_var_name ("auto-confirm");
1681
1682 return use_external_editor_var_name;
1683}
1684
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001685//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001686// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001687//--------------------------------------------------
1688
1689
1690SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001691Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001692{
1693 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00001694 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
1695 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001696 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1697};
1698
Greg Claytonbb562b12010-10-04 02:44:26 +00001699#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00001700#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001701
Greg Clayton0603aa92010-10-04 01:05:56 +00001702#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1703 "{, ${frame.pc}}"\
1704 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00001705 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00001706 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00001707 "\\n"
1708
Greg Clayton315d2ca2010-11-02 01:53:21 +00001709//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
1710// "{, ${frame.pc}}"\
1711// MODULE_WITH_FUNC\
1712// FILE_AND_LINE\
1713// "{, stop reason = ${thread.stop-reason}}"\
1714// "{, name = ${thread.name}}"\
1715// "{, queue = ${thread.queue}}"\
1716// "\\n"
1717
Greg Clayton0603aa92010-10-04 01:05:56 +00001718#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
1719 MODULE_WITH_FUNC\
1720 FILE_AND_LINE\
1721 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001722
1723SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00001724Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001725{
Greg Clayton0603aa92010-10-04 01:05:56 +00001726// NAME Setting variable type Default Enum Init'd Hidden Help
1727// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00001728{ "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 +00001729{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00001730{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
1731{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001732{ "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 +00001733{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
1734{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00001735{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001736};