blob: dac85c72bbafab85b2bee698ed6e2c3c05d2c774 [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
Greg Clayton4a33d312011-06-23 17:59:56 +000010#include "lldb/Core/Debugger.h"
11
12#include <map>
13
Enrico Granata4becb372011-06-29 22:27:15 +000014#include "clang/AST/DeclCXX.h"
15#include "clang/AST/Type.h"
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/lldb-private.h"
18#include "lldb/Core/ConnectionFileDescriptor.h"
Greg Clayton4a33d312011-06-23 17:59:56 +000019#include "lldb/Core/FormatManager.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/InputReader.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000021#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000023#include "lldb/Core/StreamAsynchronousIO.h"
Greg Clayton1b654882010-09-19 02:33:57 +000024#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000026#include "lldb/Core/ValueObject.h"
Greg Claytona3406612011-02-07 23:24:47 +000027#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000028#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Target/TargetList.h"
30#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000031#include "lldb/Target/RegisterContext.h"
32#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000034#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
36using namespace lldb;
37using namespace lldb_private;
38
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039
Greg Clayton1b654882010-09-19 02:33:57 +000040static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000041static lldb::user_id_t g_unique_id = 1;
42
Greg Clayton1b654882010-09-19 02:33:57 +000043#pragma mark Static Functions
44
45static Mutex &
46GetDebuggerListMutex ()
47{
48 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
49 return g_mutex;
50}
51
52typedef std::vector<DebuggerSP> DebuggerList;
53
54static DebuggerList &
55GetDebuggerList()
56{
57 // hide the static debugger list inside a singleton accessor to avoid
58 // global init contructors
59 static DebuggerList g_list;
60 return g_list;
61}
62
63
64#pragma mark Debugger
65
Greg Clayton99d0faf2010-11-18 23:32:35 +000066UserSettingsControllerSP &
67Debugger::GetSettingsController ()
68{
69 static UserSettingsControllerSP g_settings_controller;
70 return g_settings_controller;
71}
72
Caroline Tice2f88aad2011-01-14 00:29:16 +000073int
74Debugger::TestDebuggerRefCount ()
75{
76 return g_shared_debugger_refcount;
77}
78
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079void
80Debugger::Initialize ()
81{
Greg Clayton66111032010-06-23 01:19:29 +000082 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +000083 {
Greg Claytondbe54502010-11-19 03:46:01 +000084 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +000085 }
Greg Clayton66111032010-06-23 01:19:29 +000086 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +000087
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088}
89
90void
91Debugger::Terminate ()
92{
Greg Clayton66111032010-06-23 01:19:29 +000093 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094 {
Greg Clayton66111032010-06-23 01:19:29 +000095 g_shared_debugger_refcount--;
96 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097 {
Greg Claytondbe54502010-11-19 03:46:01 +000098 lldb_private::WillTerminate();
99 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000100
101 // Clear our master list of debugger objects
102 Mutex::Locker locker (GetDebuggerListMutex ());
103 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105 }
106}
107
Caroline Tice20bd37f2011-03-10 22:14:10 +0000108void
109Debugger::SettingsInitialize ()
110{
111 static bool g_initialized = false;
112
113 if (!g_initialized)
114 {
115 g_initialized = true;
116 UserSettingsControllerSP &usc = GetSettingsController();
117 usc.reset (new SettingsController);
118 UserSettingsController::InitializeSettingsController (usc,
119 SettingsController::global_settings_table,
120 SettingsController::instance_settings_table);
121 // Now call SettingsInitialize for each settings 'child' of Debugger
122 Target::SettingsInitialize ();
123 }
124}
125
126void
127Debugger::SettingsTerminate ()
128{
129
130 // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
131 // Settings.
132
133 Target::SettingsTerminate ();
134
135 // Now terminate the Debugger Settings.
136
137 UserSettingsControllerSP &usc = GetSettingsController();
138 UserSettingsController::FinalizeSettingsController (usc);
139 usc.reset();
140}
141
Greg Clayton66111032010-06-23 01:19:29 +0000142DebuggerSP
143Debugger::CreateInstance ()
144{
145 DebuggerSP debugger_sp (new Debugger);
146 // Scope for locker
147 {
148 Mutex::Locker locker (GetDebuggerListMutex ());
149 GetDebuggerList().push_back(debugger_sp);
150 }
151 return debugger_sp;
152}
153
Caroline Ticee02657b2011-01-22 01:02:07 +0000154void
Greg Clayton4d122c42011-09-17 08:33:22 +0000155Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000156{
157 if (debugger_sp.get() == NULL)
158 return;
159
Jim Ingham8314c522011-09-15 21:36:42 +0000160 debugger_sp->Clear();
161
Caroline Ticee02657b2011-01-22 01:02:07 +0000162 Mutex::Locker locker (GetDebuggerListMutex ());
163 DebuggerList &debugger_list = GetDebuggerList ();
164 DebuggerList::iterator pos, end = debugger_list.end();
165 for (pos = debugger_list.begin (); pos != end; ++pos)
166 {
167 if ((*pos).get() == debugger_sp.get())
168 {
169 debugger_list.erase (pos);
170 return;
171 }
172 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000173}
174
Greg Clayton4d122c42011-09-17 08:33:22 +0000175DebuggerSP
Greg Clayton66111032010-06-23 01:19:29 +0000176Debugger::GetSP ()
177{
Greg Clayton4d122c42011-09-17 08:33:22 +0000178 // This object contains an instrusive ref count base class so we can
179 // easily make a shared pointer to this object
180 return DebuggerSP (this);
Greg Clayton66111032010-06-23 01:19:29 +0000181}
182
Greg Clayton4d122c42011-09-17 08:33:22 +0000183DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000184Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
185{
Greg Clayton4d122c42011-09-17 08:33:22 +0000186 DebuggerSP debugger_sp;
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000187
188 Mutex::Locker locker (GetDebuggerListMutex ());
189 DebuggerList &debugger_list = GetDebuggerList();
190 DebuggerList::iterator pos, end = debugger_list.end();
191
192 for (pos = debugger_list.begin(); pos != end; ++pos)
193 {
194 if ((*pos).get()->m_instance_name == instance_name)
195 {
196 debugger_sp = *pos;
197 break;
198 }
199 }
200 return debugger_sp;
201}
Greg Clayton66111032010-06-23 01:19:29 +0000202
203TargetSP
204Debugger::FindTargetWithProcessID (lldb::pid_t pid)
205{
Greg Clayton4d122c42011-09-17 08:33:22 +0000206 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000207 Mutex::Locker locker (GetDebuggerListMutex ());
208 DebuggerList &debugger_list = GetDebuggerList();
209 DebuggerList::iterator pos, end = debugger_list.end();
210 for (pos = debugger_list.begin(); pos != end; ++pos)
211 {
212 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
213 if (target_sp)
214 break;
215 }
216 return target_sp;
217}
218
219
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000221 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000222 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000223 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 m_input_file (),
225 m_output_file (),
226 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227 m_target_list (),
Greg Claytonded470d2011-03-19 01:12:21 +0000228 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229 m_listener ("lldb.Debugger"),
Jim Inghame37d6052011-09-13 00:29:56 +0000230 m_source_manager(*this),
231 m_source_file_cache(),
Greg Clayton66111032010-06-23 01:19:29 +0000232 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000233 m_input_reader_stack (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000234 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235{
Greg Clayton66111032010-06-23 01:19:29 +0000236 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000237 // Always add our default platform to the platform list
238 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
239 assert (default_platform_sp.get());
240 m_platform_list.Append (default_platform_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241}
242
243Debugger::~Debugger ()
244{
Jim Ingham8314c522011-09-15 21:36:42 +0000245 Clear();
246}
247
248void
249Debugger::Clear()
250{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000251 CleanUpInputReaders();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000252 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000253 int num_targets = m_target_list.GetNumTargets();
254 for (int i = 0; i < num_targets; i++)
255 {
256 ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
257 if (process_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000258 {
259 if (process_sp->AttachedToProcess())
260 process_sp->Detach();
261 else
262 process_sp->Destroy();
263 }
Greg Clayton66111032010-06-23 01:19:29 +0000264 }
265 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266
Jim Ingham8314c522011-09-15 21:36:42 +0000267}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268
269bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000270Debugger::GetCloseInputOnEOF () const
271{
272 return m_input_comm.GetCloseOnEOF();
273}
274
275void
276Debugger::SetCloseInputOnEOF (bool b)
277{
278 m_input_comm.SetCloseOnEOF(b);
279}
280
281bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282Debugger::GetAsyncExecution ()
283{
Greg Clayton66111032010-06-23 01:19:29 +0000284 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285}
286
287void
288Debugger::SetAsyncExecution (bool async_execution)
289{
Greg Clayton66111032010-06-23 01:19:29 +0000290 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000291}
292
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293
294void
295Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
296{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000297 File &in_file = GetInputFile();
298 in_file.SetStream (fh, tranfer_ownership);
299 if (in_file.IsValid() == false)
300 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000301
302 // Disconnect from any old connection if we had one
303 m_input_comm.Disconnect ();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000304 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), true));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000305 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
306
307 Error error;
308 if (m_input_comm.StartReadThread (&error) == false)
309 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000310 File &err_file = GetErrorFile();
311
312 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
313 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315}
316
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317void
318Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
319{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000320 File &out_file = GetOutputFile();
321 out_file.SetStream (fh, tranfer_ownership);
322 if (out_file.IsValid() == false)
323 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000324
325 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000326}
327
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328void
329Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
330{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000331 File &err_file = GetErrorFile();
332 err_file.SetStream (fh, tranfer_ownership);
333 if (err_file.IsValid() == false)
334 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335}
336
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000337ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000338Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000339{
340 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000341 TargetSP target_sp(GetSelectedTarget());
342 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343
344 if (target_sp)
345 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000346 ProcessSP process_sp (target_sp->GetProcessSP());
347 exe_ctx.SetProcessSP (process_sp);
348 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000350 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
351 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000352 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000353 exe_ctx.SetThreadSP (thread_sp);
354 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
355 if (exe_ctx.GetFramePtr() == NULL)
356 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000357 }
358 }
359 }
360 return exe_ctx;
361
362}
363
Caroline Ticeb44880c2011-02-10 01:15:13 +0000364InputReaderSP
365Debugger::GetCurrentInputReader ()
366{
367 InputReaderSP reader_sp;
368
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000369 if (!m_input_reader_stack.IsEmpty())
Caroline Ticeb44880c2011-02-10 01:15:13 +0000370 {
371 // Clear any finished readers from the stack
372 while (CheckIfTopInputReaderIsDone()) ;
373
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000374 if (!m_input_reader_stack.IsEmpty())
375 reader_sp = m_input_reader_stack.Top();
Caroline Ticeb44880c2011-02-10 01:15:13 +0000376 }
377
378 return reader_sp;
379}
380
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381void
382Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
383{
Caroline Ticeefed6132010-11-19 20:47:54 +0000384 if (bytes_len > 0)
385 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
386 else
387 ((Debugger *)baton)->DispatchInputEndOfFile ();
388}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389
390
391void
392Debugger::DispatchInput (const char *bytes, size_t bytes_len)
393{
Caroline Ticeefed6132010-11-19 20:47:54 +0000394 if (bytes == NULL || bytes_len == 0)
395 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396
397 WriteToDefaultReader (bytes, bytes_len);
398}
399
400void
Caroline Ticeefed6132010-11-19 20:47:54 +0000401Debugger::DispatchInputInterrupt ()
402{
403 m_input_reader_data.clear();
404
Caroline Ticeb44880c2011-02-10 01:15:13 +0000405 InputReaderSP reader_sp (GetCurrentInputReader ());
406 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000407 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000408 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000409
Caroline Ticeb44880c2011-02-10 01:15:13 +0000410 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000411 while (CheckIfTopInputReaderIsDone ()) ;
412 }
413}
414
415void
416Debugger::DispatchInputEndOfFile ()
417{
418 m_input_reader_data.clear();
419
Caroline Ticeb44880c2011-02-10 01:15:13 +0000420 InputReaderSP reader_sp (GetCurrentInputReader ());
421 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000422 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000423 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000424
Caroline Ticeb44880c2011-02-10 01:15:13 +0000425 // If notifying the reader of the end-of-file finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000426 while (CheckIfTopInputReaderIsDone ()) ;
427 }
428}
429
430void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000431Debugger::CleanUpInputReaders ()
432{
433 m_input_reader_data.clear();
434
Caroline Ticeb44880c2011-02-10 01:15:13 +0000435 // The bottom input reader should be the main debugger input reader. We do not want to close that one here.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000436 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000437 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000438 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000439 if (reader_sp)
440 {
441 reader_sp->Notify (eInputReaderEndOfFile);
442 reader_sp->SetIsDone (true);
443 }
444 }
445}
446
447void
Caroline Tice969ed3d2011-05-02 20:41:46 +0000448Debugger::NotifyTopInputReader (InputReaderAction notification)
449{
450 InputReaderSP reader_sp (GetCurrentInputReader());
451 if (reader_sp)
452 {
453 reader_sp->Notify (notification);
454
455 // Flush out any input readers that are done.
456 while (CheckIfTopInputReaderIsDone ())
457 /* Do nothing. */;
458 }
459}
460
Caroline Tice9088b062011-05-09 23:06:58 +0000461bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000462Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp)
Caroline Tice9088b062011-05-09 23:06:58 +0000463{
Caroline Ticed61c10b2011-06-16 16:27:19 +0000464 InputReaderSP top_reader_sp (GetCurrentInputReader());
Caroline Tice9088b062011-05-09 23:06:58 +0000465
Caroline Ticed61c10b2011-06-16 16:27:19 +0000466 return (reader_sp.get() == top_reader_sp.get());
Caroline Tice9088b062011-05-09 23:06:58 +0000467}
468
469
Caroline Tice969ed3d2011-05-02 20:41:46 +0000470void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
472{
473 if (bytes && bytes_len)
474 m_input_reader_data.append (bytes, bytes_len);
475
476 if (m_input_reader_data.empty())
477 return;
478
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000479 while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000482 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483 if (!reader_sp)
484 break;
485
Greg Clayton471b31c2010-07-20 22:52:08 +0000486 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487 m_input_reader_data.size());
488 if (bytes_handled)
489 {
490 m_input_reader_data.erase (0, bytes_handled);
491 }
492 else
493 {
494 // No bytes were handled, we might not have reached our
495 // granularity, just return and wait for more data
496 break;
497 }
498 }
499
Caroline Ticeb44880c2011-02-10 01:15:13 +0000500 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501 while (CheckIfTopInputReaderIsDone ())
502 /* Do nothing. */;
503
504}
505
506void
507Debugger::PushInputReader (const InputReaderSP& reader_sp)
508{
509 if (!reader_sp)
510 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000511
512 // Deactivate the old top reader
513 InputReaderSP top_reader_sp (GetCurrentInputReader ());
514
515 if (top_reader_sp)
516 top_reader_sp->Notify (eInputReaderDeactivate);
517
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000518 m_input_reader_stack.Push (reader_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 reader_sp->Notify (eInputReaderActivate);
520 ActivateInputReader (reader_sp);
521}
522
523bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000524Debugger::PopInputReader (const InputReaderSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525{
526 bool result = false;
527
528 // The reader on the stop of the stack is done, so let the next
529 // read on the stack referesh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000530 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000532 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000533 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534
535 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
536 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000537 m_input_reader_stack.Pop ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 reader_sp->Notify (eInputReaderDeactivate);
539 reader_sp->Notify (eInputReaderDone);
540 result = true;
541
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000542 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000543 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000544 reader_sp = m_input_reader_stack.Top();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545 if (reader_sp)
546 {
547 ActivateInputReader (reader_sp);
548 reader_sp->Notify (eInputReaderReactivate);
549 }
550 }
551 }
552 }
553 return result;
554}
555
556bool
557Debugger::CheckIfTopInputReaderIsDone ()
558{
559 bool result = false;
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000560 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000562 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000563 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564
565 if (reader_sp && reader_sp->IsDone())
566 {
567 result = true;
568 PopInputReader (reader_sp);
569 }
570 }
571 return result;
572}
573
574void
575Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
576{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000577 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000579 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000581 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000582
583 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584
Greg Claytona3406612011-02-07 23:24:47 +0000585 switch (reader_sp->GetGranularity())
586 {
587 case eInputReaderGranularityByte:
588 case eInputReaderGranularityWord:
589 tty.SetCanonical (false);
590 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000591
Greg Claytona3406612011-02-07 23:24:47 +0000592 case eInputReaderGranularityLine:
593 case eInputReaderGranularityAll:
594 tty.SetCanonical (true);
595 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596
Greg Claytona3406612011-02-07 23:24:47 +0000597 default:
598 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599 }
600 }
601}
Greg Clayton66111032010-06-23 01:19:29 +0000602
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000603StreamSP
604Debugger::GetAsyncOutputStream ()
605{
606 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
607 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
608}
609
610StreamSP
611Debugger::GetAsyncErrorStream ()
612{
613 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
614 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
615}
616
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000617DebuggerSP
618Debugger::FindDebuggerWithID (lldb::user_id_t id)
619{
Greg Clayton4d122c42011-09-17 08:33:22 +0000620 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000621
622 Mutex::Locker locker (GetDebuggerListMutex ());
623 DebuggerList &debugger_list = GetDebuggerList();
624 DebuggerList::iterator pos, end = debugger_list.end();
625 for (pos = debugger_list.begin(); pos != end; ++pos)
626 {
627 if ((*pos).get()->GetID() == id)
628 {
629 debugger_sp = *pos;
630 break;
631 }
632 }
633 return debugger_sp;
634}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000635
Greg Clayton1b654882010-09-19 02:33:57 +0000636static void
637TestPromptFormats (StackFrame *frame)
638{
639 if (frame == NULL)
640 return;
641
642 StreamString s;
643 const char *prompt_format =
644 "{addr = '${addr}'\n}"
645 "{process.id = '${process.id}'\n}"
646 "{process.name = '${process.name}'\n}"
647 "{process.file.basename = '${process.file.basename}'\n}"
648 "{process.file.fullpath = '${process.file.fullpath}'\n}"
649 "{thread.id = '${thread.id}'\n}"
650 "{thread.index = '${thread.index}'\n}"
651 "{thread.name = '${thread.name}'\n}"
652 "{thread.queue = '${thread.queue}'\n}"
653 "{thread.stop-reason = '${thread.stop-reason}'\n}"
654 "{target.arch = '${target.arch}'\n}"
655 "{module.file.basename = '${module.file.basename}'\n}"
656 "{module.file.fullpath = '${module.file.fullpath}'\n}"
657 "{file.basename = '${file.basename}'\n}"
658 "{file.fullpath = '${file.fullpath}'\n}"
659 "{frame.index = '${frame.index}'\n}"
660 "{frame.pc = '${frame.pc}'\n}"
661 "{frame.sp = '${frame.sp}'\n}"
662 "{frame.fp = '${frame.fp}'\n}"
663 "{frame.flags = '${frame.flags}'\n}"
664 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
665 "{frame.reg.rip = '${frame.reg.rip}'\n}"
666 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
667 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
668 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
669 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
670 "{frame.reg.carp = '${frame.reg.carp}'\n}"
671 "{function.id = '${function.id}'\n}"
672 "{function.name = '${function.name}'\n}"
673 "{function.addr-offset = '${function.addr-offset}'\n}"
674 "{function.line-offset = '${function.line-offset}'\n}"
675 "{function.pc-offset = '${function.pc-offset}'\n}"
676 "{line.file.basename = '${line.file.basename}'\n}"
677 "{line.file.fullpath = '${line.file.fullpath}'\n}"
678 "{line.number = '${line.number}'\n}"
679 "{line.start-addr = '${line.start-addr}'\n}"
680 "{line.end-addr = '${line.end-addr}'\n}"
681;
682
683 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
684 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000685 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000686 const char *end = NULL;
687 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
688 {
689 printf("%s\n", s.GetData());
690 }
691 else
692 {
693 printf ("error: at '%s'\n", end);
694 printf ("what we got: %s\n", s.GetData());
695 }
696}
697
Enrico Granata9fc19442011-07-06 02:13:41 +0000698static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000699ScanFormatDescriptor (const char* var_name_begin,
700 const char* var_name_end,
701 const char** var_name_final,
702 const char** percent_position,
Greg Clayton4d122c42011-09-17 08:33:22 +0000703 Format* custom_format,
Enrico Granatadc940732011-08-23 00:32:52 +0000704 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
Enrico Granata9fc19442011-07-06 02:13:41 +0000705{
Enrico Granatae992a082011-07-22 17:03:19 +0000706 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000707 *percent_position = ::strchr(var_name_begin,'%');
Greg Clayton34132752011-07-06 04:07:21 +0000708 if (!*percent_position || *percent_position > var_name_end)
Enrico Granatae992a082011-07-22 17:03:19 +0000709 {
710 if (log)
711 log->Printf("no format descriptor in string, skipping");
Enrico Granata9fc19442011-07-06 02:13:41 +0000712 *var_name_final = var_name_end;
Enrico Granatae992a082011-07-22 17:03:19 +0000713 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000714 else
715 {
716 *var_name_final = *percent_position;
717 char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0';
718 memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1);
Enrico Granatae992a082011-07-22 17:03:19 +0000719 if (log)
720 log->Printf("parsing %s as a format descriptor", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000721 if ( !FormatManager::GetFormatFromCString(format_name,
722 true,
723 *custom_format) )
724 {
Enrico Granatae992a082011-07-22 17:03:19 +0000725 if (log)
726 log->Printf("%s is an unknown format", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000727 // if this is an @ sign, print ObjC description
Greg Clayton34132752011-07-06 04:07:21 +0000728 if (*format_name == '@')
Enrico Granata9fc19442011-07-06 02:13:41 +0000729 *val_obj_display = ValueObject::eDisplayLanguageSpecific;
730 // if this is a V, print the value using the default format
Enrico Granatae992a082011-07-22 17:03:19 +0000731 else if (*format_name == 'V')
Enrico Granata9fc19442011-07-06 02:13:41 +0000732 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatad55546b2011-07-22 00:16:08 +0000733 // if this is an L, print the location of the value
Enrico Granatae992a082011-07-22 17:03:19 +0000734 else if (*format_name == 'L')
Enrico Granataf2bbf712011-07-15 02:26:42 +0000735 *val_obj_display = ValueObject::eDisplayLocation;
Enrico Granatad55546b2011-07-22 00:16:08 +0000736 // if this is an S, print the summary after all
Enrico Granatae992a082011-07-22 17:03:19 +0000737 else if (*format_name == 'S')
Enrico Granatad55546b2011-07-22 00:16:08 +0000738 *val_obj_display = ValueObject::eDisplaySummary;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000739 else if (*format_name == '#')
740 *val_obj_display = ValueObject::eDisplayChildrenCount;
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000741 else if (*format_name == 'T')
742 *val_obj_display = ValueObject::eDisplayType;
Enrico Granatae992a082011-07-22 17:03:19 +0000743 else if (log)
744 log->Printf("%s is an error, leaving the previous value alone", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000745 }
746 // a good custom format tells us to print the value using it
747 else
Enrico Granatae992a082011-07-22 17:03:19 +0000748 {
749 if (log)
750 log->Printf("will display value for this VO");
Enrico Granata9fc19442011-07-06 02:13:41 +0000751 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatae992a082011-07-22 17:03:19 +0000752 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000753 delete format_name;
754 }
Enrico Granatae992a082011-07-22 17:03:19 +0000755 if (log)
756 log->Printf("final format description outcome: custom_format = %d, val_obj_display = %d",
757 *custom_format,
758 *val_obj_display);
Enrico Granata9fc19442011-07-06 02:13:41 +0000759 return true;
760}
761
762static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000763ScanBracketedRange (const char* var_name_begin,
764 const char* var_name_end,
765 const char* var_name_final,
766 const char** open_bracket_position,
767 const char** separator_position,
768 const char** close_bracket_position,
769 const char** var_name_final_if_array_range,
770 int64_t* index_lower,
771 int64_t* index_higher)
Enrico Granata9fc19442011-07-06 02:13:41 +0000772{
Enrico Granatae992a082011-07-22 17:03:19 +0000773 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000774 *open_bracket_position = ::strchr(var_name_begin,'[');
Greg Clayton34132752011-07-06 04:07:21 +0000775 if (*open_bracket_position && *open_bracket_position < var_name_final)
Enrico Granata9fc19442011-07-06 02:13:41 +0000776 {
777 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
778 *close_bracket_position = ::strchr(*open_bracket_position,']');
779 // as usual, we assume that [] will come before %
780 //printf("trying to expand a []\n");
781 *var_name_final_if_array_range = *open_bracket_position;
Greg Clayton34132752011-07-06 04:07:21 +0000782 if (*close_bracket_position - *open_bracket_position == 1)
Enrico Granata9fc19442011-07-06 02:13:41 +0000783 {
Enrico Granatae992a082011-07-22 17:03:19 +0000784 if (log)
785 log->Printf("[] detected.. going from 0 to end of data");
Enrico Granata9fc19442011-07-06 02:13:41 +0000786 *index_lower = 0;
787 }
788 else if (*separator_position == NULL || *separator_position > var_name_end)
789 {
790 char *end = NULL;
791 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
792 *index_higher = *index_lower;
Enrico Granatae992a082011-07-22 17:03:19 +0000793 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000794 log->Printf("[%lld] detected, high index is same", *index_lower);
Enrico Granata9fc19442011-07-06 02:13:41 +0000795 }
Greg Clayton34132752011-07-06 04:07:21 +0000796 else if (*close_bracket_position && *close_bracket_position < var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +0000797 {
798 char *end = NULL;
799 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
800 *index_higher = ::strtoul (*separator_position+1, &end, 0);
Enrico Granatae992a082011-07-22 17:03:19 +0000801 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000802 log->Printf("[%lld-%lld] detected", *index_lower, *index_higher);
Enrico Granata9fc19442011-07-06 02:13:41 +0000803 }
804 else
Enrico Granatae992a082011-07-22 17:03:19 +0000805 {
806 if (log)
807 log->Printf("expression is erroneous, cannot extract indices out of it");
Enrico Granata9fc19442011-07-06 02:13:41 +0000808 return false;
Enrico Granatae992a082011-07-22 17:03:19 +0000809 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000810 if (*index_lower > *index_higher && *index_higher > 0)
811 {
Enrico Granatae992a082011-07-22 17:03:19 +0000812 if (log)
813 log->Printf("swapping indices");
Enrico Granata9fc19442011-07-06 02:13:41 +0000814 int temp = *index_lower;
815 *index_lower = *index_higher;
816 *index_higher = temp;
817 }
818 }
Enrico Granatae992a082011-07-22 17:03:19 +0000819 else if (log)
820 log->Printf("no bracketed range, skipping entirely");
Enrico Granata9fc19442011-07-06 02:13:41 +0000821 return true;
822}
823
824
825static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000826ExpandExpressionPath (ValueObject* valobj,
827 StackFrame* frame,
828 bool* do_deref_pointer,
829 const char* var_name_begin,
830 const char* var_name_final,
831 Error& error)
Enrico Granata9fc19442011-07-06 02:13:41 +0000832{
Enrico Granatae992a082011-07-22 17:03:19 +0000833 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000834 StreamString sstring;
835 VariableSP var_sp;
836
Greg Clayton34132752011-07-06 04:07:21 +0000837 if (*do_deref_pointer)
Enrico Granatae992a082011-07-22 17:03:19 +0000838 {
839 if (log)
840 log->Printf("been told to deref_pointer by caller");
Enrico Granata9fc19442011-07-06 02:13:41 +0000841 sstring.PutChar('*');
Enrico Granatae992a082011-07-22 17:03:19 +0000842 }
Enrico Granatac482a192011-08-17 22:13:59 +0000843 else if (valobj->IsDereferenceOfParent() && ClangASTContext::IsPointerType(valobj->GetParent()->GetClangType()) && !valobj->IsArrayItemForPointer())
Enrico Granata9fc19442011-07-06 02:13:41 +0000844 {
Enrico Granatae992a082011-07-22 17:03:19 +0000845 if (log)
846 log->Printf("decided to deref_pointer myself");
Enrico Granata9fc19442011-07-06 02:13:41 +0000847 sstring.PutChar('*');
848 *do_deref_pointer = true;
849 }
850
Enrico Granatac482a192011-08-17 22:13:59 +0000851 valobj->GetExpressionPath(sstring, true, ValueObject::eHonorPointers);
Enrico Granatae992a082011-07-22 17:03:19 +0000852 if (log)
853 log->Printf("expression path to expand in phase 0: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000854 sstring.PutRawBytes(var_name_begin+3, var_name_final-var_name_begin-3);
Enrico Granatae992a082011-07-22 17:03:19 +0000855 if (log)
856 log->Printf("expression path to expand in phase 1: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000857 std::string name = std::string(sstring.GetData());
858 ValueObjectSP target = frame->GetValueForVariableExpressionPath (name.c_str(),
859 eNoDynamicValues,
860 0,
861 var_sp,
862 error);
863 return target;
864}
865
866static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000867ExpandIndexedExpression (ValueObject* valobj,
868 uint32_t index,
869 StackFrame* frame,
870 bool deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +0000871{
Enrico Granatae992a082011-07-22 17:03:19 +0000872 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000873 const char* ptr_deref_format = "[%d]";
874 std::auto_ptr<char> ptr_deref_buffer(new char[10]);
875 ::sprintf(ptr_deref_buffer.get(), ptr_deref_format, index);
Enrico Granatae992a082011-07-22 17:03:19 +0000876 if (log)
877 log->Printf("name to deref: %s",ptr_deref_buffer.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000878 const char* first_unparsed;
879 ValueObject::GetValueForExpressionPathOptions options;
880 ValueObject::ExpressionPathEndResultType final_value_type;
881 ValueObject::ExpressionPathScanEndReason reason_to_stop;
882 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eDereference : ValueObject::eNothing);
Enrico Granatac482a192011-08-17 22:13:59 +0000883 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000884 &first_unparsed,
885 &reason_to_stop,
886 &final_value_type,
887 options,
888 &what_next);
889 if (!item)
890 {
Enrico Granatae992a082011-07-22 17:03:19 +0000891 if (log)
892 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
893 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000894 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000895 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000896 else
897 {
Enrico Granatae992a082011-07-22 17:03:19 +0000898 if (log)
899 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
900 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000901 first_unparsed, reason_to_stop, final_value_type);
Enrico Granata9fc19442011-07-06 02:13:41 +0000902 }
903 return item;
904}
905
Greg Clayton1b654882010-09-19 02:33:57 +0000906bool
907Debugger::FormatPrompt
908(
909 const char *format,
910 const SymbolContext *sc,
911 const ExecutionContext *exe_ctx,
912 const Address *addr,
913 Stream &s,
Enrico Granata4becb372011-06-29 22:27:15 +0000914 const char **end,
Enrico Granatac482a192011-08-17 22:13:59 +0000915 ValueObject* valobj
Greg Clayton1b654882010-09-19 02:33:57 +0000916)
917{
Enrico Granatac482a192011-08-17 22:13:59 +0000918 ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers
Greg Clayton1b654882010-09-19 02:33:57 +0000919 bool success = true;
920 const char *p;
Enrico Granatae992a082011-07-22 17:03:19 +0000921 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Greg Clayton1b654882010-09-19 02:33:57 +0000922 for (p = format; *p != '\0'; ++p)
923 {
Enrico Granatac482a192011-08-17 22:13:59 +0000924 if (realvalobj)
Enrico Granata4becb372011-06-29 22:27:15 +0000925 {
Enrico Granatac482a192011-08-17 22:13:59 +0000926 valobj = realvalobj;
927 realvalobj = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +0000928 }
Greg Clayton1b654882010-09-19 02:33:57 +0000929 size_t non_special_chars = ::strcspn (p, "${}\\");
930 if (non_special_chars > 0)
931 {
932 if (success)
933 s.Write (p, non_special_chars);
934 p += non_special_chars;
935 }
936
937 if (*p == '\0')
938 {
939 break;
940 }
941 else if (*p == '{')
942 {
943 // Start a new scope that must have everything it needs if it is to
944 // to make it into the final output stream "s". If you want to make
945 // a format that only prints out the function or symbol name if there
946 // is one in the symbol context you can use:
947 // "{function =${function.name}}"
948 // The first '{' starts a new scope that end with the matching '}' at
949 // the end of the string. The contents "function =${function.name}"
950 // will then be evaluated and only be output if there is a function
951 // or symbol with a valid name.
952 StreamString sub_strm;
953
954 ++p; // Skip the '{'
955
Enrico Granatac482a192011-08-17 22:13:59 +0000956 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
Greg Clayton1b654882010-09-19 02:33:57 +0000957 {
958 // The stream had all it needed
959 s.Write(sub_strm.GetData(), sub_strm.GetSize());
960 }
961 if (*p != '}')
962 {
963 success = false;
964 break;
965 }
966 }
967 else if (*p == '}')
968 {
969 // End of a enclosing scope
970 break;
971 }
972 else if (*p == '$')
973 {
974 // We have a prompt variable to print
975 ++p;
976 if (*p == '{')
977 {
978 ++p;
979 const char *var_name_begin = p;
980 const char *var_name_end = ::strchr (p, '}');
981
982 if (var_name_end && var_name_begin < var_name_end)
983 {
984 // if we have already failed to parse, skip this variable
985 if (success)
986 {
987 const char *cstr = NULL;
988 Address format_addr;
989 bool calculate_format_addr_function_offset = false;
990 // Set reg_kind and reg_num to invalid values
991 RegisterKind reg_kind = kNumRegisterKinds;
992 uint32_t reg_num = LLDB_INVALID_REGNUM;
993 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +0000994 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +0000995 RegisterContext *reg_ctx = NULL;
Enrico Granata9fc19442011-07-06 02:13:41 +0000996 bool do_deref_pointer = false;
Enrico Granatae992a082011-07-22 17:03:19 +0000997 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eEndOfString;
998 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::ePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000999
Greg Clayton1b654882010-09-19 02:33:57 +00001000 // Each variable must set success to true below...
1001 bool var_success = false;
1002 switch (var_name_begin[0])
1003 {
Enrico Granata4becb372011-06-29 22:27:15 +00001004 case '*':
Enrico Granata4becb372011-06-29 22:27:15 +00001005 case 'v':
Enrico Granata6f3533f2011-07-29 19:53:35 +00001006 case 's':
Enrico Granata4becb372011-06-29 22:27:15 +00001007 {
Enrico Granatac482a192011-08-17 22:13:59 +00001008 if (!valobj)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001009 break;
1010
Enrico Granatac3e320a2011-08-02 17:27:39 +00001011 if (log)
1012 log->Printf("initial string: %s",var_name_begin);
1013
Enrico Granata6f3533f2011-07-29 19:53:35 +00001014 // check for *var and *svar
1015 if (*var_name_begin == '*')
1016 {
1017 do_deref_pointer = true;
1018 var_name_begin++;
1019 }
Enrico Granatac3e320a2011-08-02 17:27:39 +00001020
1021 if (log)
1022 log->Printf("initial string: %s",var_name_begin);
1023
Enrico Granata6f3533f2011-07-29 19:53:35 +00001024 if (*var_name_begin == 's')
1025 {
Greg Clayton4d122c42011-09-17 08:33:22 +00001026 valobj = valobj->GetSyntheticValue(eUseSyntheticFilter).get();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001027 var_name_begin++;
1028 }
1029
Enrico Granatac3e320a2011-08-02 17:27:39 +00001030 if (log)
1031 log->Printf("initial string: %s",var_name_begin);
1032
Enrico Granata6f3533f2011-07-29 19:53:35 +00001033 // should be a 'v' by now
1034 if (*var_name_begin != 'v')
1035 break;
1036
Enrico Granatac3e320a2011-08-02 17:27:39 +00001037 if (log)
1038 log->Printf("initial string: %s",var_name_begin);
1039
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001040 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
1041 ValueObject::eDereference : ValueObject::eNothing);
1042 ValueObject::GetValueForExpressionPathOptions options;
Enrico Granata8c9d3562011-08-11 17:08:01 +00001043 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren();
Greg Clayton34132752011-07-06 04:07:21 +00001044 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eDisplaySummary;
1045 ValueObject* target = NULL;
Greg Clayton4d122c42011-09-17 08:33:22 +00001046 Format custom_format = eFormatInvalid;
Greg Clayton34132752011-07-06 04:07:21 +00001047 const char* var_name_final = NULL;
1048 const char* var_name_final_if_array_range = NULL;
1049 const char* close_bracket_position = NULL;
1050 int64_t index_lower = -1;
1051 int64_t index_higher = -1;
1052 bool is_array_range = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001053 const char* first_unparsed;
Enrico Granata85933ed2011-08-18 16:38:26 +00001054 bool was_plain_var = false;
1055 bool was_var_format = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001056
Enrico Granatac482a192011-08-17 22:13:59 +00001057 if (!valobj) break;
1058 // simplest case ${var}, just print valobj's value
Greg Clayton34132752011-07-06 04:07:21 +00001059 if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0)
Enrico Granata4becb372011-06-29 22:27:15 +00001060 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001061 was_plain_var = true;
Enrico Granatac482a192011-08-17 22:13:59 +00001062 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001063 val_obj_display = ValueObject::eDisplayValue;
1064 }
1065 else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0)
1066 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001067 was_var_format = true;
Greg Clayton34132752011-07-06 04:07:21 +00001068 // this is a variable with some custom format applied to it
1069 const char* percent_position;
Enrico Granatac482a192011-08-17 22:13:59 +00001070 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001071 val_obj_display = ValueObject::eDisplayValue;
1072 ScanFormatDescriptor (var_name_begin,
1073 var_name_end,
1074 &var_name_final,
1075 &percent_position,
1076 &custom_format,
1077 &val_obj_display);
1078 }
1079 // this is ${var.something} or multiple .something nested
1080 else if (::strncmp (var_name_begin, "var", strlen("var")) == 0)
1081 {
1082
1083 const char* percent_position;
1084 ScanFormatDescriptor (var_name_begin,
1085 var_name_end,
1086 &var_name_final,
1087 &percent_position,
1088 &custom_format,
1089 &val_obj_display);
1090
1091 const char* open_bracket_position;
1092 const char* separator_position;
1093 ScanBracketedRange (var_name_begin,
1094 var_name_end,
1095 var_name_final,
1096 &open_bracket_position,
1097 &separator_position,
1098 &close_bracket_position,
1099 &var_name_final_if_array_range,
1100 &index_lower,
1101 &index_higher);
1102
1103 Error error;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001104
1105 std::auto_ptr<char> expr_path(new char[var_name_final-var_name_begin-1]);
1106 ::memset(expr_path.get(), 0, var_name_final-var_name_begin-1);
1107 memcpy(expr_path.get(), var_name_begin+3,var_name_final-var_name_begin-3);
1108
Enrico Granatae992a082011-07-22 17:03:19 +00001109 if (log)
1110 log->Printf("symbol to expand: %s",expr_path.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001111
Enrico Granatac482a192011-08-17 22:13:59 +00001112 target = valobj->GetValueForExpressionPath(expr_path.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001113 &first_unparsed,
1114 &reason_to_stop,
1115 &final_value_type,
1116 options,
1117 &what_next).get();
1118
1119 if (!target)
Enrico Granata9fc19442011-07-06 02:13:41 +00001120 {
Enrico Granatae992a082011-07-22 17:03:19 +00001121 if (log)
1122 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1123 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001124 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001125 break;
Enrico Granata9fc19442011-07-06 02:13:41 +00001126 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001127 else
1128 {
Enrico Granatae992a082011-07-22 17:03:19 +00001129 if (log)
1130 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1131 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001132 first_unparsed, reason_to_stop, final_value_type);
1133 }
Enrico Granata4becb372011-06-29 22:27:15 +00001134 }
Greg Clayton34132752011-07-06 04:07:21 +00001135 else
Enrico Granata9fc19442011-07-06 02:13:41 +00001136 break;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001137
1138 is_array_range = (final_value_type == ValueObject::eBoundedRange ||
1139 final_value_type == ValueObject::eUnboundedRange);
1140
1141 do_deref_pointer = (what_next == ValueObject::eDereference);
Enrico Granata9fc19442011-07-06 02:13:41 +00001142
Enrico Granataa7187d02011-07-06 19:27:11 +00001143 if (do_deref_pointer && !is_array_range)
Enrico Granata9fc19442011-07-06 02:13:41 +00001144 {
Greg Clayton34132752011-07-06 04:07:21 +00001145 // I have not deref-ed yet, let's do it
1146 // this happens when we are not going through GetValueForVariableExpressionPath
1147 // to get to the target ValueObject
Enrico Granata9fc19442011-07-06 02:13:41 +00001148 Error error;
Greg Clayton34132752011-07-06 04:07:21 +00001149 target = target->Dereference(error).get();
Enrico Granatadc940732011-08-23 00:32:52 +00001150 if (error.Fail())
1151 {
1152 if (log)
1153 log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
1154 break;
1155 }
Greg Clayton34132752011-07-06 04:07:21 +00001156 do_deref_pointer = false;
Enrico Granata9fc19442011-07-06 02:13:41 +00001157 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001158
Enrico Granata85933ed2011-08-18 16:38:26 +00001159 // TODO use flags for these
Enrico Granataf4efecd2011-07-12 22:56:10 +00001160 bool is_array = ClangASTContext::IsArrayType(target->GetClangType());
1161 bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType());
Enrico Granata85933ed2011-08-18 16:38:26 +00001162 bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType());
Enrico Granataf4efecd2011-07-12 22:56:10 +00001163
1164 if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eDisplayValue) // this should be wrong, but there are some exceptions
1165 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001166 StreamString str_temp;
Enrico Granatae992a082011-07-22 17:03:19 +00001167 if (log)
1168 log->Printf("I am into array || pointer && !range");
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001169
1170 if (target->HasSpecialCasesForPrintableRepresentation(val_obj_display,
1171 custom_format))
Enrico Granata85933ed2011-08-18 16:38:26 +00001172 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001173 // try to use the special cases
1174 var_success = target->DumpPrintableRepresentation(str_temp,
1175 val_obj_display,
1176 custom_format);
1177 if (log)
1178 log->Printf("special cases did%s match", var_success ? "" : "n't");
1179
1180 // should not happen
1181 if (!var_success)
1182 s << "<invalid usage of pointer value as object>";
1183 else
1184 s << str_temp.GetData();
Enrico Granata85933ed2011-08-18 16:38:26 +00001185 var_success = true;
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001186 break;
Enrico Granata85933ed2011-08-18 16:38:26 +00001187 }
1188 else
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001189 {
Enrico Granata88da35f2011-08-23 21:26:09 +00001190 if (was_plain_var) // if ${var}
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001191 {
1192 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1193 }
Enrico Granata88da35f2011-08-23 21:26:09 +00001194 else if (is_pointer) // if pointer, value is the address stored
1195 {
1196 var_success = target->GetPrintableRepresentation(s,
1197 val_obj_display,
1198 custom_format);
1199 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001200 else
1201 {
1202 s << "<invalid usage of pointer value as object>";
1203 }
1204 var_success = true;
1205 break;
1206 }
1207 }
1208
1209 // if directly trying to print ${var}, and this is an aggregate, display a nice
1210 // type @ location message
1211 if (is_aggregate && was_plain_var)
1212 {
1213 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1214 var_success = true;
Enrico Granata85933ed2011-08-18 16:38:26 +00001215 break;
1216 }
1217
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001218 // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it
1219 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eDisplayValue)))
Enrico Granata85933ed2011-08-18 16:38:26 +00001220 {
1221 s << "<invalid use of aggregate type>";
1222 var_success = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001223 break;
1224 }
Greg Clayton34132752011-07-06 04:07:21 +00001225
1226 if (!is_array_range)
Enrico Granatae992a082011-07-22 17:03:19 +00001227 {
1228 if (log)
1229 log->Printf("dumping ordinary printable output");
Greg Clayton34132752011-07-06 04:07:21 +00001230 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
Enrico Granatae992a082011-07-22 17:03:19 +00001231 }
Greg Clayton34132752011-07-06 04:07:21 +00001232 else
Enrico Granatae992a082011-07-22 17:03:19 +00001233 {
1234 if (log)
1235 log->Printf("checking if I can handle as array");
Greg Clayton34132752011-07-06 04:07:21 +00001236 if (!is_array && !is_pointer)
1237 break;
Enrico Granatae992a082011-07-22 17:03:19 +00001238 if (log)
1239 log->Printf("handle as array");
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001240 const char* special_directions = NULL;
1241 StreamString special_directions_writer;
Greg Clayton34132752011-07-06 04:07:21 +00001242 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1243 {
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001244 ConstString additional_data;
1245 additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1);
1246 special_directions_writer.Printf("${%svar%s}",
1247 do_deref_pointer ? "*" : "",
1248 additional_data.GetCString());
1249 special_directions = special_directions_writer.GetData();
Greg Clayton34132752011-07-06 04:07:21 +00001250 }
1251
1252 // let us display items index_lower thru index_higher of this array
1253 s.PutChar('[');
1254 var_success = true;
1255
1256 if (index_higher < 0)
Enrico Granatac482a192011-08-17 22:13:59 +00001257 index_higher = valobj->GetNumChildren() - 1;
Greg Clayton34132752011-07-06 04:07:21 +00001258
Enrico Granata22c55d12011-08-12 02:00:06 +00001259 uint32_t max_num_children = target->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
1260
Greg Clayton34132752011-07-06 04:07:21 +00001261 for (;index_lower<=index_higher;index_lower++)
1262 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001263 ValueObject* item = ExpandIndexedExpression (target,
1264 index_lower,
1265 exe_ctx->GetFramePtr(),
1266 false).get();
Greg Clayton34132752011-07-06 04:07:21 +00001267
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001268 if (!item)
1269 {
Enrico Granatae992a082011-07-22 17:03:19 +00001270 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001271 log->Printf("ERROR in getting child item at index %lld", index_lower);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001272 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001273 else
1274 {
Enrico Granatae992a082011-07-22 17:03:19 +00001275 if (log)
1276 log->Printf("special_directions for child item: %s",special_directions);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001277 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001278
Greg Clayton34132752011-07-06 04:07:21 +00001279 if (!special_directions)
1280 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1281 else
1282 var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
1283
Enrico Granata22c55d12011-08-12 02:00:06 +00001284 if (--max_num_children == 0)
1285 {
1286 s.PutCString(", ...");
1287 break;
1288 }
1289
Greg Clayton34132752011-07-06 04:07:21 +00001290 if (index_lower < index_higher)
1291 s.PutChar(',');
1292 }
1293 s.PutChar(']');
1294 }
Enrico Granata4becb372011-06-29 22:27:15 +00001295 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001296 break;
Greg Clayton1b654882010-09-19 02:33:57 +00001297 case 'a':
1298 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
1299 {
1300 if (addr && addr->IsValid())
1301 {
1302 var_success = true;
1303 format_addr = *addr;
1304 }
1305 }
Greg Clayton5a314712011-10-14 07:41:33 +00001306 else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0)
1307 {
1308 var_success = true;
1309 var_name_begin += strlen("ansi."); // Skip the "ansi."
1310 if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0)
1311 {
1312 var_name_begin += strlen("fg."); // Skip the "fg."
1313 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1314 {
1315 s.Printf ("%s%s%s",
1316 lldb_utility::ansi::k_escape_start,
1317 lldb_utility::ansi::k_fg_black,
1318 lldb_utility::ansi::k_escape_end);
1319 }
1320 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1321 {
1322 s.Printf ("%s%s%s",
1323 lldb_utility::ansi::k_escape_start,
1324 lldb_utility::ansi::k_fg_red,
1325 lldb_utility::ansi::k_escape_end);
1326 }
1327 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1328 {
1329 s.Printf ("%s%s%s",
1330 lldb_utility::ansi::k_escape_start,
1331 lldb_utility::ansi::k_fg_green,
1332 lldb_utility::ansi::k_escape_end);
1333 }
1334 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1335 {
1336 s.Printf ("%s%s%s",
1337 lldb_utility::ansi::k_escape_start,
1338 lldb_utility::ansi::k_fg_yellow,
1339 lldb_utility::ansi::k_escape_end);
1340 }
1341 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1342 {
1343 s.Printf ("%s%s%s",
1344 lldb_utility::ansi::k_escape_start,
1345 lldb_utility::ansi::k_fg_blue,
1346 lldb_utility::ansi::k_escape_end);
1347 }
1348 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1349 {
1350 s.Printf ("%s%s%s",
1351 lldb_utility::ansi::k_escape_start,
1352 lldb_utility::ansi::k_fg_purple,
1353 lldb_utility::ansi::k_escape_end);
1354 }
1355 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1356 {
1357 s.Printf ("%s%s%s",
1358 lldb_utility::ansi::k_escape_start,
1359 lldb_utility::ansi::k_fg_cyan,
1360 lldb_utility::ansi::k_escape_end);
1361 }
1362 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1363 {
1364 s.Printf ("%s%s%s",
1365 lldb_utility::ansi::k_escape_start,
1366 lldb_utility::ansi::k_fg_white,
1367 lldb_utility::ansi::k_escape_end);
1368 }
1369 else
1370 {
1371 var_success = false;
1372 }
1373 }
1374 else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0)
1375 {
1376 var_name_begin += strlen("bg."); // Skip the "bg."
1377 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1378 {
1379 s.Printf ("%s%s%s",
1380 lldb_utility::ansi::k_escape_start,
1381 lldb_utility::ansi::k_bg_black,
1382 lldb_utility::ansi::k_escape_end);
1383 }
1384 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1385 {
1386 s.Printf ("%s%s%s",
1387 lldb_utility::ansi::k_escape_start,
1388 lldb_utility::ansi::k_bg_red,
1389 lldb_utility::ansi::k_escape_end);
1390 }
1391 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1392 {
1393 s.Printf ("%s%s%s",
1394 lldb_utility::ansi::k_escape_start,
1395 lldb_utility::ansi::k_bg_green,
1396 lldb_utility::ansi::k_escape_end);
1397 }
1398 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1399 {
1400 s.Printf ("%s%s%s",
1401 lldb_utility::ansi::k_escape_start,
1402 lldb_utility::ansi::k_bg_yellow,
1403 lldb_utility::ansi::k_escape_end);
1404 }
1405 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1406 {
1407 s.Printf ("%s%s%s",
1408 lldb_utility::ansi::k_escape_start,
1409 lldb_utility::ansi::k_bg_blue,
1410 lldb_utility::ansi::k_escape_end);
1411 }
1412 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1413 {
1414 s.Printf ("%s%s%s",
1415 lldb_utility::ansi::k_escape_start,
1416 lldb_utility::ansi::k_bg_purple,
1417 lldb_utility::ansi::k_escape_end);
1418 }
1419 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1420 {
1421 s.Printf ("%s%s%s",
1422 lldb_utility::ansi::k_escape_start,
1423 lldb_utility::ansi::k_bg_cyan,
1424 lldb_utility::ansi::k_escape_end);
1425 }
1426 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1427 {
1428 s.Printf ("%s%s%s",
1429 lldb_utility::ansi::k_escape_start,
1430 lldb_utility::ansi::k_bg_white,
1431 lldb_utility::ansi::k_escape_end);
1432 }
1433 else
1434 {
1435 var_success = false;
1436 }
1437 }
1438 else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0)
1439 {
1440 s.Printf ("%s%s%s",
1441 lldb_utility::ansi::k_escape_start,
1442 lldb_utility::ansi::k_ctrl_normal,
1443 lldb_utility::ansi::k_escape_end);
1444 }
1445 else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0)
1446 {
1447 s.Printf ("%s%s%s",
1448 lldb_utility::ansi::k_escape_start,
1449 lldb_utility::ansi::k_ctrl_bold,
1450 lldb_utility::ansi::k_escape_end);
1451 }
1452 else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0)
1453 {
1454 s.Printf ("%s%s%s",
1455 lldb_utility::ansi::k_escape_start,
1456 lldb_utility::ansi::k_ctrl_faint,
1457 lldb_utility::ansi::k_escape_end);
1458 }
1459 else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0)
1460 {
1461 s.Printf ("%s%s%s",
1462 lldb_utility::ansi::k_escape_start,
1463 lldb_utility::ansi::k_ctrl_italic,
1464 lldb_utility::ansi::k_escape_end);
1465 }
1466 else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0)
1467 {
1468 s.Printf ("%s%s%s",
1469 lldb_utility::ansi::k_escape_start,
1470 lldb_utility::ansi::k_ctrl_underline,
1471 lldb_utility::ansi::k_escape_end);
1472 }
1473 else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0)
1474 {
1475 s.Printf ("%s%s%s",
1476 lldb_utility::ansi::k_escape_start,
1477 lldb_utility::ansi::k_ctrl_slow_blink,
1478 lldb_utility::ansi::k_escape_end);
1479 }
1480 else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0)
1481 {
1482 s.Printf ("%s%s%s",
1483 lldb_utility::ansi::k_escape_start,
1484 lldb_utility::ansi::k_ctrl_fast_blink,
1485 lldb_utility::ansi::k_escape_end);
1486 }
1487 else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0)
1488 {
1489 s.Printf ("%s%s%s",
1490 lldb_utility::ansi::k_escape_start,
1491 lldb_utility::ansi::k_ctrl_negative,
1492 lldb_utility::ansi::k_escape_end);
1493 }
1494 else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0)
1495 {
1496 s.Printf ("%s%s%s",
1497 lldb_utility::ansi::k_escape_start,
1498 lldb_utility::ansi::k_ctrl_conceal,
1499 lldb_utility::ansi::k_escape_end);
1500
1501 }
1502 else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0)
1503 {
1504 s.Printf ("%s%s%s",
1505 lldb_utility::ansi::k_escape_start,
1506 lldb_utility::ansi::k_ctrl_crossed_out,
1507 lldb_utility::ansi::k_escape_end);
1508 }
1509 else
1510 {
1511 var_success = false;
1512 }
1513 }
Greg Clayton1b654882010-09-19 02:33:57 +00001514 break;
1515
1516 case 'p':
1517 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
1518 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001519 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001520 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001521 Process *process = exe_ctx->GetProcessPtr();
1522 if (process)
Greg Clayton1b654882010-09-19 02:33:57 +00001523 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001524 var_name_begin += ::strlen ("process.");
1525 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001526 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001527 s.Printf("%llu", process->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001528 var_success = true;
1529 }
1530 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
1531 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
1532 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
1533 {
1534 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1535 if (exe_module)
Greg Clayton1b654882010-09-19 02:33:57 +00001536 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001537 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1538 {
1539 format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
1540 var_success = format_file_spec;
1541 }
1542 else
1543 {
1544 format_file_spec = exe_module->GetFileSpec();
1545 var_success = format_file_spec;
1546 }
Greg Clayton1b654882010-09-19 02:33:57 +00001547 }
1548 }
1549 }
Greg Claytonc14ee322011-09-22 04:58:26 +00001550 }
Greg Clayton1b654882010-09-19 02:33:57 +00001551 }
1552 break;
1553
1554 case 't':
1555 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
1556 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001557 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001558 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001559 Thread *thread = exe_ctx->GetThreadPtr();
1560 if (thread)
Greg Clayton1b654882010-09-19 02:33:57 +00001561 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001562 var_name_begin += ::strlen ("thread.");
1563 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001564 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001565 s.Printf("0x%4.4llx", thread->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001566 var_success = true;
1567 }
1568 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1569 {
1570 s.Printf("%u", thread->GetIndexID());
1571 var_success = true;
1572 }
1573 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1574 {
1575 cstr = thread->GetName();
1576 var_success = cstr && cstr[0];
1577 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001578 s.PutCString(cstr);
Greg Claytonc14ee322011-09-22 04:58:26 +00001579 }
1580 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
1581 {
1582 cstr = thread->GetQueueName();
1583 var_success = cstr && cstr[0];
1584 if (var_success)
1585 s.PutCString(cstr);
1586 }
1587 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
1588 {
1589 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1590 if (stop_info_sp)
1591 {
1592 cstr = stop_info_sp->GetDescription();
1593 if (cstr && cstr[0])
1594 {
1595 s.PutCString(cstr);
1596 var_success = true;
1597 }
Greg Clayton1b654882010-09-19 02:33:57 +00001598 }
1599 }
1600 }
1601 }
1602 }
1603 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
1604 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001605 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1606 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +00001607 {
Greg Clayton1b654882010-09-19 02:33:57 +00001608 var_name_begin += ::strlen ("target.");
1609 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
1610 {
1611 ArchSpec arch (target->GetArchitecture ());
1612 if (arch.IsValid())
1613 {
Greg Clayton64195a22011-02-23 00:35:02 +00001614 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +00001615 var_success = true;
1616 }
1617 }
1618 }
1619 }
1620 break;
1621
1622
1623 case 'm':
1624 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
1625 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001626 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +00001627 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001628 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +00001629 var_name_begin += ::strlen ("module.");
1630
1631 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1632 {
1633 if (module->GetFileSpec())
1634 {
1635 var_name_begin += ::strlen ("file.");
1636
1637 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1638 {
1639 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
1640 var_success = format_file_spec;
1641 }
1642 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1643 {
1644 format_file_spec = module->GetFileSpec();
1645 var_success = format_file_spec;
1646 }
1647 }
1648 }
1649 }
1650 }
1651 break;
1652
1653
1654 case 'f':
1655 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1656 {
1657 if (sc && sc->comp_unit != NULL)
1658 {
1659 var_name_begin += ::strlen ("file.");
1660
1661 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1662 {
1663 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
1664 var_success = format_file_spec;
1665 }
1666 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1667 {
1668 format_file_spec = *sc->comp_unit;
1669 var_success = format_file_spec;
1670 }
1671 }
1672 }
1673 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
1674 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001675 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001676 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001677 StackFrame *frame = exe_ctx->GetFramePtr();
1678 if (frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001679 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001680 var_name_begin += ::strlen ("frame.");
1681 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001682 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001683 s.Printf("%u", frame->GetFrameIndex());
1684 var_success = true;
1685 }
1686 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
1687 {
1688 reg_kind = eRegisterKindGeneric;
1689 reg_num = LLDB_REGNUM_GENERIC_PC;
1690 var_success = true;
1691 }
1692 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
1693 {
1694 reg_kind = eRegisterKindGeneric;
1695 reg_num = LLDB_REGNUM_GENERIC_SP;
1696 var_success = true;
1697 }
1698 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
1699 {
1700 reg_kind = eRegisterKindGeneric;
1701 reg_num = LLDB_REGNUM_GENERIC_FP;
1702 var_success = true;
1703 }
1704 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
1705 {
1706 reg_kind = eRegisterKindGeneric;
1707 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
1708 var_success = true;
1709 }
1710 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
1711 {
1712 reg_ctx = frame->GetRegisterContext().get();
1713 if (reg_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001714 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001715 var_name_begin += ::strlen ("reg.");
1716 if (var_name_begin < var_name_end)
1717 {
1718 std::string reg_name (var_name_begin, var_name_end);
1719 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
1720 if (reg_info)
1721 var_success = true;
1722 }
Greg Clayton1b654882010-09-19 02:33:57 +00001723 }
1724 }
1725 }
1726 }
1727 }
1728 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
1729 {
1730 if (sc && (sc->function != NULL || sc->symbol != NULL))
1731 {
1732 var_name_begin += ::strlen ("function.");
1733 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1734 {
1735 if (sc->function)
Greg Clayton81c22f62011-10-19 18:09:39 +00001736 s.Printf("function{0x%8.8llx}", sc->function->GetID());
Greg Clayton1b654882010-09-19 02:33:57 +00001737 else
1738 s.Printf("symbol[%u]", sc->symbol->GetID());
1739
1740 var_success = true;
1741 }
1742 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1743 {
1744 if (sc->function)
1745 cstr = sc->function->GetName().AsCString (NULL);
1746 else if (sc->symbol)
1747 cstr = sc->symbol->GetName().AsCString (NULL);
1748 if (cstr)
1749 {
1750 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001751
1752 if (sc->block)
1753 {
1754 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1755 if (inline_block)
1756 {
1757 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1758 if (inline_info)
1759 {
1760 s.PutCString(" [inlined] ");
1761 inline_info->GetName().Dump(&s);
1762 }
1763 }
1764 }
Greg Clayton1b654882010-09-19 02:33:57 +00001765 var_success = true;
1766 }
1767 }
1768 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1769 {
1770 var_success = addr != NULL;
1771 if (var_success)
1772 {
1773 format_addr = *addr;
1774 calculate_format_addr_function_offset = true;
1775 }
1776 }
1777 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1778 {
1779 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1780 if (var_success)
1781 {
1782 format_addr = sc->line_entry.range.GetBaseAddress();
1783 calculate_format_addr_function_offset = true;
1784 }
1785 }
1786 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1787 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001788 StackFrame *frame = exe_ctx->GetFramePtr();
1789 var_success = frame != NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00001790 if (var_success)
1791 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001792 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00001793 calculate_format_addr_function_offset = true;
1794 }
1795 }
1796 }
1797 }
1798 break;
1799
1800 case 'l':
1801 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1802 {
1803 if (sc && sc->line_entry.IsValid())
1804 {
1805 var_name_begin += ::strlen ("line.");
1806 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1807 {
1808 var_name_begin += ::strlen ("file.");
1809
1810 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1811 {
1812 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1813 var_success = format_file_spec;
1814 }
1815 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1816 {
1817 format_file_spec = sc->line_entry.file;
1818 var_success = format_file_spec;
1819 }
1820 }
1821 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1822 {
1823 var_success = true;
1824 s.Printf("%u", sc->line_entry.line);
1825 }
1826 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1827 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1828 {
1829 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1830 if (var_success)
1831 {
1832 format_addr = sc->line_entry.range.GetBaseAddress();
1833 if (var_name_begin[0] == 'e')
1834 format_addr.Slide (sc->line_entry.range.GetByteSize());
1835 }
1836 }
1837 }
1838 }
1839 break;
1840 }
1841
1842 if (var_success)
1843 {
1844 // If format addr is valid, then we need to print an address
1845 if (reg_num != LLDB_INVALID_REGNUM)
1846 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001847 StackFrame *frame = exe_ctx->GetFramePtr();
Greg Clayton1b654882010-09-19 02:33:57 +00001848 // We have a register value to display...
1849 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1850 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001851 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00001852 }
1853 else
1854 {
1855 if (reg_ctx == NULL)
Greg Claytonc14ee322011-09-22 04:58:26 +00001856 reg_ctx = frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001857
1858 if (reg_ctx)
1859 {
1860 if (reg_kind != kNumRegisterKinds)
1861 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1862 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1863 var_success = reg_info != NULL;
1864 }
1865 }
1866 }
1867
1868 if (reg_info != NULL)
1869 {
Greg Clayton7349bd92011-05-09 20:18:18 +00001870 RegisterValue reg_value;
1871 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
1872 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001873 {
Greg Clayton9a8fa912011-05-15 04:12:07 +00001874 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
Greg Clayton1b654882010-09-19 02:33:57 +00001875 }
1876 }
1877
1878 if (format_file_spec)
1879 {
1880 s << format_file_spec;
1881 }
1882
1883 // If format addr is valid, then we need to print an address
1884 if (format_addr.IsValid())
1885 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001886 var_success = false;
1887
Greg Clayton1b654882010-09-19 02:33:57 +00001888 if (calculate_format_addr_function_offset)
1889 {
1890 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001891
Greg Clayton0603aa92010-10-04 01:05:56 +00001892 if (sc)
1893 {
1894 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001895 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001896 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001897 if (sc->block)
1898 {
1899 // Check to make sure we aren't in an inline
1900 // function. If we are, use the inline block
1901 // range that contains "format_addr" since
1902 // blocks can be discontiguous.
1903 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1904 AddressRange inline_range;
1905 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1906 func_addr = inline_range.GetBaseAddress();
1907 }
1908 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001909 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1910 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1911 }
1912
1913 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001914 {
1915 if (func_addr.GetSection() == format_addr.GetSection())
1916 {
1917 addr_t func_file_addr = func_addr.GetFileAddress();
1918 addr_t addr_file_addr = format_addr.GetFileAddress();
1919 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001920 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001921 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001922 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001923 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001924 }
1925 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001926 {
1927 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1928 if (target)
1929 {
1930 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1931 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1932 if (addr_load_addr > func_load_addr)
1933 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1934 else if (addr_load_addr < func_load_addr)
1935 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1936 var_success = true;
1937 }
1938 }
Greg Clayton1b654882010-09-19 02:33:57 +00001939 }
1940 }
1941 else
1942 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001943 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001944 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001945 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1946 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001947 if (vaddr == LLDB_INVALID_ADDRESS)
1948 vaddr = format_addr.GetFileAddress ();
1949
1950 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001951 {
Greg Clayton514487e2011-02-15 21:59:32 +00001952 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001953 if (addr_width == 0)
1954 addr_width = 16;
1955 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001956 var_success = true;
1957 }
Greg Clayton1b654882010-09-19 02:33:57 +00001958 }
1959 }
1960 }
1961
1962 if (var_success == false)
1963 success = false;
1964 }
1965 p = var_name_end;
1966 }
1967 else
1968 break;
1969 }
1970 else
1971 {
1972 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1973 s.PutChar(*p);
1974 }
1975 }
1976 else if (*p == '\\')
1977 {
1978 ++p; // skip the slash
1979 switch (*p)
1980 {
1981 case 'a': s.PutChar ('\a'); break;
1982 case 'b': s.PutChar ('\b'); break;
1983 case 'f': s.PutChar ('\f'); break;
1984 case 'n': s.PutChar ('\n'); break;
1985 case 'r': s.PutChar ('\r'); break;
1986 case 't': s.PutChar ('\t'); break;
1987 case 'v': s.PutChar ('\v'); break;
1988 case '\'': s.PutChar ('\''); break;
1989 case '\\': s.PutChar ('\\'); break;
1990 case '0':
1991 // 1 to 3 octal chars
1992 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001993 // Make a string that can hold onto the initial zero char,
1994 // up to 3 octal digits, and a terminating NULL.
1995 char oct_str[5] = { 0, 0, 0, 0, 0 };
1996
1997 int i;
1998 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1999 oct_str[i] = p[i];
2000
2001 // We don't want to consume the last octal character since
2002 // the main for loop will do this for us, so we advance p by
2003 // one less than i (even if i is zero)
2004 p += i - 1;
2005 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2006 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002007 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002008 char octal_char = octal_value;
2009 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00002010 }
Greg Clayton1b654882010-09-19 02:33:57 +00002011 }
2012 break;
2013
2014 case 'x':
2015 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00002016 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002017 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002018 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00002019
Greg Clayton0603aa92010-10-04 01:05:56 +00002020 // Make a string that can hold onto two hex chars plus a
2021 // NULL terminator
2022 char hex_str[3] = { 0,0,0 };
2023 hex_str[0] = *p;
2024 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002025 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002026 ++p; // Skip the first of the two hex chars
2027 hex_str[1] = *p;
2028 }
2029
2030 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2031 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002032 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00002033 }
2034 else
2035 {
2036 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00002037 }
2038 break;
2039
2040 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00002041 // Just desensitize any other character by just printing what
2042 // came after the '\'
2043 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00002044 break;
2045
2046 }
2047
2048 }
2049 }
2050 if (end)
2051 *end = p;
2052 return success;
2053}
2054
2055#pragma mark Debugger::SettingsController
2056
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002057//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002058// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002059//--------------------------------------------------
2060
Greg Clayton1b654882010-09-19 02:33:57 +00002061Debugger::SettingsController::SettingsController () :
Greg Clayton4d122c42011-09-17 08:33:22 +00002062 UserSettingsController ("", UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002063{
Caroline Tice91123da2010-09-08 17:48:55 +00002064 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
2065 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002066}
2067
Greg Clayton1b654882010-09-19 02:33:57 +00002068Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002069{
2070}
2071
2072
Greg Clayton4d122c42011-09-17 08:33:22 +00002073InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00002074Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002075{
Greg Claytondbe54502010-11-19 03:46:01 +00002076 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00002077 false, instance_name);
Greg Clayton4d122c42011-09-17 08:33:22 +00002078 InstanceSettingsSP new_settings_sp (new_settings);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002079 return new_settings_sp;
2080}
2081
Greg Clayton1b654882010-09-19 02:33:57 +00002082#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002083//--------------------------------------------------
2084// class DebuggerInstanceSettings
2085//--------------------------------------------------
2086
Greg Claytona7015092010-09-18 01:14:36 +00002087DebuggerInstanceSettings::DebuggerInstanceSettings
2088(
2089 UserSettingsController &owner,
2090 bool live_instance,
2091 const char *name
2092) :
Greg Clayton85851dd2010-12-04 00:10:17 +00002093 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00002094 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002095 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00002096 m_frame_format (),
2097 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002098 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002099 m_use_external_editor (false),
2100 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002101{
Caroline Ticef20e8232010-09-09 18:26:37 +00002102 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2103 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
2104 // 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 +00002105 // The same is true of CreateInstanceName().
2106
2107 if (GetInstanceName() == InstanceSettings::InvalidName())
2108 {
2109 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
2110 m_owner.RegisterInstanceSettings (this);
2111 }
Caroline Ticef20e8232010-09-09 18:26:37 +00002112
2113 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002114 {
Greg Clayton4d122c42011-09-17 08:33:22 +00002115 const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002116 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002117 }
2118}
2119
2120DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00002121 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002122 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00002123 m_frame_format (rhs.m_frame_format),
2124 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002125 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002126 m_use_external_editor (rhs.m_use_external_editor),
2127 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002128{
Greg Clayton4d122c42011-09-17 08:33:22 +00002129 const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002130 CopyInstanceSettings (pending_settings, false);
2131 m_owner.RemovePendingSettings (m_instance_name);
2132}
2133
2134DebuggerInstanceSettings::~DebuggerInstanceSettings ()
2135{
2136}
2137
2138DebuggerInstanceSettings&
2139DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
2140{
2141 if (this != &rhs)
2142 {
Greg Clayton1b654882010-09-19 02:33:57 +00002143 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002144 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00002145 m_frame_format = rhs.m_frame_format;
2146 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002147 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002148 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002149 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002150 }
2151
2152 return *this;
2153}
2154
Greg Clayton1b654882010-09-19 02:33:57 +00002155bool
2156DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
2157{
2158 bool valid = false;
2159
2160 // Verify we have a value string.
2161 if (value == NULL || value[0] == '\0')
2162 {
Greg Clayton86edbf42011-10-26 00:56:27 +00002163 err.SetErrorString ("missing value, can't set terminal width without a value");
Greg Clayton1b654882010-09-19 02:33:57 +00002164 }
2165 else
2166 {
2167 char *end = NULL;
2168 const uint32_t width = ::strtoul (value, &end, 0);
2169
Johnny Chenea9fc182010-09-20 16:36:43 +00002170 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00002171 {
Johnny Chen433d7742010-09-20 17:04:41 +00002172 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00002173 valid = true;
2174 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002175 err.SetErrorString ("invalid term-width value; value must be between 10 and 1024");
Greg Clayton1b654882010-09-19 02:33:57 +00002176 }
2177 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002178 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value);
Greg Clayton1b654882010-09-19 02:33:57 +00002179 }
2180
2181 return valid;
2182}
2183
2184
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002185void
2186DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2187 const char *index_value,
2188 const char *value,
2189 const ConstString &instance_name,
2190 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00002191 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002192 Error &err,
2193 bool pending)
2194{
Greg Clayton0603aa92010-10-04 01:05:56 +00002195
2196 if (var_name == TermWidthVarName())
2197 {
2198 if (ValidTermWidthValue (value, err))
2199 {
2200 m_term_width = ::strtoul (value, NULL, 0);
2201 }
2202 }
2203 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002204 {
Caroline Tice101c7c22010-09-09 06:25:08 +00002205 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002206 if (!pending)
2207 {
Caroline Tice49e27372010-09-07 18:35:40 +00002208 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2209 // strip off the brackets before passing it to BroadcastPromptChange.
2210
2211 std::string tmp_instance_name (instance_name.AsCString());
2212 if ((tmp_instance_name[0] == '[')
2213 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
2214 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
2215 ConstString new_name (tmp_instance_name.c_str());
2216
2217 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002218 }
2219 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002220 else if (var_name == GetFrameFormatName())
2221 {
2222 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
2223 }
2224 else if (var_name == GetThreadFormatName())
2225 {
2226 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
2227 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002228 else if (var_name == ScriptLangVarName())
2229 {
2230 bool success;
2231 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
2232 &success);
2233 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002234 else if (var_name == UseExternalEditorVarName ())
2235 {
Greg Clayton385aa282011-04-22 03:55:06 +00002236 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00002237 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002238 else if (var_name == AutoConfirmName ())
2239 {
Greg Clayton385aa282011-04-22 03:55:06 +00002240 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00002241 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002242}
2243
Caroline Tice12cecd72010-09-20 21:37:42 +00002244bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002245DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2246 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00002247 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00002248 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002249{
2250 if (var_name == PromptVarName())
2251 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002252 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002253
2254 }
2255 else if (var_name == ScriptLangVarName())
2256 {
2257 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
2258 }
Caroline Tice101c7c22010-09-09 06:25:08 +00002259 else if (var_name == TermWidthVarName())
2260 {
2261 StreamString width_str;
2262 width_str.Printf ("%d", m_term_width);
2263 value.AppendString (width_str.GetData());
2264 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002265 else if (var_name == GetFrameFormatName ())
2266 {
2267 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
2268 }
2269 else if (var_name == GetThreadFormatName ())
2270 {
2271 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
2272 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002273 else if (var_name == UseExternalEditorVarName())
2274 {
2275 if (m_use_external_editor)
2276 value.AppendString ("true");
2277 else
2278 value.AppendString ("false");
2279 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002280 else if (var_name == AutoConfirmName())
2281 {
2282 if (m_auto_confirm_on)
2283 value.AppendString ("true");
2284 else
2285 value.AppendString ("false");
2286 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002287 else
Caroline Tice12cecd72010-09-20 21:37:42 +00002288 {
2289 if (err)
2290 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2291 return false;
2292 }
2293 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002294}
2295
2296void
Greg Clayton4d122c42011-09-17 08:33:22 +00002297DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002298 bool pending)
2299{
2300 if (new_settings.get() == NULL)
2301 return;
2302
2303 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
2304
2305 m_prompt = new_debugger_settings->m_prompt;
2306 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00002307 {
2308 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2309 // strip off the brackets before passing it to BroadcastPromptChange.
2310
2311 std::string tmp_instance_name (m_instance_name.AsCString());
2312 if ((tmp_instance_name[0] == '[')
2313 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
2314 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
2315 ConstString new_name (tmp_instance_name.c_str());
2316
2317 BroadcastPromptChange (new_name, m_prompt.c_str());
2318 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002319 m_frame_format = new_debugger_settings->m_frame_format;
2320 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002321 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002322 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002323 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002324 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002325}
2326
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002327
2328bool
2329DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
2330{
2331 std::string tmp_prompt;
2332
2333 if (new_prompt != NULL)
2334 {
2335 tmp_prompt = new_prompt ;
2336 int len = tmp_prompt.size();
2337 if (len > 1
2338 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
2339 && (tmp_prompt[len-1] == tmp_prompt[0]))
2340 {
2341 tmp_prompt = tmp_prompt.substr(1,len-2);
2342 }
2343 len = tmp_prompt.size();
2344 if (tmp_prompt[len-1] != ' ')
2345 tmp_prompt.append(" ");
2346 }
2347 EventSP new_event_sp;
2348 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
2349 new EventDataBytes (tmp_prompt.c_str())));
2350
2351 if (instance_name.GetLength() != 0)
2352 {
2353 // Set prompt for a particular instance.
2354 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
2355 if (dbg != NULL)
2356 {
2357 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
2358 }
2359 }
2360
2361 return true;
2362}
2363
2364const ConstString
2365DebuggerInstanceSettings::CreateInstanceName ()
2366{
2367 static int instance_count = 1;
2368 StreamString sstr;
2369
2370 sstr.Printf ("debugger_%d", instance_count);
2371 ++instance_count;
2372
2373 const ConstString ret_val (sstr.GetData());
2374
2375 return ret_val;
2376}
2377
2378const ConstString &
2379DebuggerInstanceSettings::PromptVarName ()
2380{
2381 static ConstString prompt_var_name ("prompt");
2382
2383 return prompt_var_name;
2384}
2385
2386const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00002387DebuggerInstanceSettings::GetFrameFormatName ()
2388{
2389 static ConstString prompt_var_name ("frame-format");
2390
2391 return prompt_var_name;
2392}
2393
2394const ConstString &
2395DebuggerInstanceSettings::GetThreadFormatName ()
2396{
2397 static ConstString prompt_var_name ("thread-format");
2398
2399 return prompt_var_name;
2400}
2401
2402const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002403DebuggerInstanceSettings::ScriptLangVarName ()
2404{
2405 static ConstString script_lang_var_name ("script-lang");
2406
2407 return script_lang_var_name;
2408}
2409
Caroline Tice101c7c22010-09-09 06:25:08 +00002410const ConstString &
2411DebuggerInstanceSettings::TermWidthVarName ()
2412{
2413 static ConstString term_width_var_name ("term-width");
2414
2415 return term_width_var_name;
2416}
2417
Caroline Ticedaccaa92010-09-20 20:44:43 +00002418const ConstString &
2419DebuggerInstanceSettings::UseExternalEditorVarName ()
2420{
2421 static ConstString use_external_editor_var_name ("use-external-editor");
2422
2423 return use_external_editor_var_name;
2424}
2425
Jim Ingham3bcdb292010-10-04 22:44:14 +00002426const ConstString &
2427DebuggerInstanceSettings::AutoConfirmName ()
2428{
2429 static ConstString use_external_editor_var_name ("auto-confirm");
2430
2431 return use_external_editor_var_name;
2432}
2433
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002434//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002435// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002436//--------------------------------------------------
2437
2438
2439SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002440Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002441{
2442 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00002443 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
2444 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002445 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
2446};
2447
Greg Claytonbb562b12010-10-04 02:44:26 +00002448#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00002449#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002450
Greg Clayton0603aa92010-10-04 01:05:56 +00002451#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2452 "{, ${frame.pc}}"\
2453 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00002454 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00002455 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00002456 "\\n"
2457
Greg Clayton315d2ca2010-11-02 01:53:21 +00002458//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2459// "{, ${frame.pc}}"\
2460// MODULE_WITH_FUNC\
2461// FILE_AND_LINE\
2462// "{, stop reason = ${thread.stop-reason}}"\
2463// "{, name = ${thread.name}}"\
2464// "{, queue = ${thread.queue}}"\
2465// "\\n"
2466
Greg Clayton0603aa92010-10-04 01:05:56 +00002467#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
2468 MODULE_WITH_FUNC\
2469 FILE_AND_LINE\
2470 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002471
2472SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002473Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002474{
Greg Clayton0603aa92010-10-04 01:05:56 +00002475// NAME Setting variable type Default Enum Init'd Hidden Help
2476// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00002477{ "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 +00002478{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00002479{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
2480{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002481{ "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 +00002482{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
2483{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002484{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002485};