blob: 72449efb4c376685ba8e8c07c7bd918a09d05864 [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 Clayton6d3dbf52012-01-13 08:39:16 +000027#include "lldb/Core/ValueObjectVariable.h"
Greg Claytona3406612011-02-07 23:24:47 +000028#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000029#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000030#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Target/TargetList.h"
32#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000033#include "lldb/Target/RegisterContext.h"
34#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000036#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037
38using namespace lldb;
39using namespace lldb_private;
40
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041
Greg Clayton1b654882010-09-19 02:33:57 +000042static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000043static lldb::user_id_t g_unique_id = 1;
44
Greg Clayton1b654882010-09-19 02:33:57 +000045#pragma mark Static Functions
46
47static Mutex &
48GetDebuggerListMutex ()
49{
50 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
51 return g_mutex;
52}
53
54typedef std::vector<DebuggerSP> DebuggerList;
55
56static DebuggerList &
57GetDebuggerList()
58{
59 // hide the static debugger list inside a singleton accessor to avoid
60 // global init contructors
61 static DebuggerList g_list;
62 return g_list;
63}
64
65
Greg Claytone372b982011-11-21 21:44:34 +000066static const ConstString &
67PromptVarName ()
68{
69 static ConstString g_const_string ("prompt");
70 return g_const_string;
71}
72
73static const ConstString &
74GetFrameFormatName ()
75{
76 static ConstString g_const_string ("frame-format");
77 return g_const_string;
78}
79
80static const ConstString &
81GetThreadFormatName ()
82{
83 static ConstString g_const_string ("thread-format");
84 return g_const_string;
85}
86
87static const ConstString &
88ScriptLangVarName ()
89{
90 static ConstString g_const_string ("script-lang");
91 return g_const_string;
92}
93
94static const ConstString &
95TermWidthVarName ()
96{
97 static ConstString g_const_string ("term-width");
98 return g_const_string;
99}
100
101static const ConstString &
102UseExternalEditorVarName ()
103{
104 static ConstString g_const_string ("use-external-editor");
105 return g_const_string;
106}
107
108static const ConstString &
109AutoConfirmName ()
110{
111 static ConstString g_const_string ("auto-confirm");
112 return g_const_string;
113}
114
115static const ConstString &
116StopSourceContextBeforeName ()
117{
118 static ConstString g_const_string ("stop-line-count-before");
119 return g_const_string;
120}
121
122static const ConstString &
123StopSourceContextAfterName ()
124{
125 static ConstString g_const_string ("stop-line-count-after");
126 return g_const_string;
127}
128
129static const ConstString &
130StopDisassemblyCountName ()
131{
132 static ConstString g_const_string ("stop-disassembly-count");
133 return g_const_string;
134}
135
136static const ConstString &
137StopDisassemblyDisplayName ()
138{
139 static ConstString g_const_string ("stop-disassembly-display");
140 return g_const_string;
141}
142
143OptionEnumValueElement
144DebuggerInstanceSettings::g_show_disassembly_enum_values[] =
145{
146 { eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
147 { eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
148 { eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
149 { 0, NULL, NULL }
150};
151
152
153
Greg Clayton1b654882010-09-19 02:33:57 +0000154#pragma mark Debugger
155
Greg Clayton99d0faf2010-11-18 23:32:35 +0000156UserSettingsControllerSP &
157Debugger::GetSettingsController ()
158{
159 static UserSettingsControllerSP g_settings_controller;
160 return g_settings_controller;
161}
162
Caroline Tice2f88aad2011-01-14 00:29:16 +0000163int
164Debugger::TestDebuggerRefCount ()
165{
166 return g_shared_debugger_refcount;
167}
168
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169void
170Debugger::Initialize ()
171{
Greg Clayton66111032010-06-23 01:19:29 +0000172 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +0000173 {
Greg Claytondbe54502010-11-19 03:46:01 +0000174 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000175 }
Greg Clayton66111032010-06-23 01:19:29 +0000176 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +0000177
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178}
179
180void
181Debugger::Terminate ()
182{
Greg Clayton66111032010-06-23 01:19:29 +0000183 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184 {
Greg Clayton66111032010-06-23 01:19:29 +0000185 g_shared_debugger_refcount--;
186 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000187 {
Greg Claytondbe54502010-11-19 03:46:01 +0000188 lldb_private::WillTerminate();
189 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000190
191 // Clear our master list of debugger objects
192 Mutex::Locker locker (GetDebuggerListMutex ());
193 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 }
196}
197
Caroline Tice20bd37f2011-03-10 22:14:10 +0000198void
199Debugger::SettingsInitialize ()
200{
201 static bool g_initialized = false;
202
203 if (!g_initialized)
204 {
205 g_initialized = true;
206 UserSettingsControllerSP &usc = GetSettingsController();
207 usc.reset (new SettingsController);
208 UserSettingsController::InitializeSettingsController (usc,
209 SettingsController::global_settings_table,
210 SettingsController::instance_settings_table);
211 // Now call SettingsInitialize for each settings 'child' of Debugger
212 Target::SettingsInitialize ();
213 }
214}
215
216void
217Debugger::SettingsTerminate ()
218{
219
220 // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
221 // Settings.
222
223 Target::SettingsTerminate ();
224
225 // Now terminate the Debugger Settings.
226
227 UserSettingsControllerSP &usc = GetSettingsController();
228 UserSettingsController::FinalizeSettingsController (usc);
229 usc.reset();
230}
231
Greg Clayton66111032010-06-23 01:19:29 +0000232DebuggerSP
233Debugger::CreateInstance ()
234{
235 DebuggerSP debugger_sp (new Debugger);
236 // Scope for locker
237 {
238 Mutex::Locker locker (GetDebuggerListMutex ());
239 GetDebuggerList().push_back(debugger_sp);
240 }
241 return debugger_sp;
242}
243
Caroline Ticee02657b2011-01-22 01:02:07 +0000244void
Greg Clayton4d122c42011-09-17 08:33:22 +0000245Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000246{
247 if (debugger_sp.get() == NULL)
248 return;
249
Jim Ingham8314c522011-09-15 21:36:42 +0000250 debugger_sp->Clear();
251
Caroline Ticee02657b2011-01-22 01:02:07 +0000252 Mutex::Locker locker (GetDebuggerListMutex ());
253 DebuggerList &debugger_list = GetDebuggerList ();
254 DebuggerList::iterator pos, end = debugger_list.end();
255 for (pos = debugger_list.begin (); pos != end; ++pos)
256 {
257 if ((*pos).get() == debugger_sp.get())
258 {
259 debugger_list.erase (pos);
260 return;
261 }
262 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000263}
264
Greg Clayton4d122c42011-09-17 08:33:22 +0000265DebuggerSP
Greg Clayton66111032010-06-23 01:19:29 +0000266Debugger::GetSP ()
267{
Greg Clayton4d122c42011-09-17 08:33:22 +0000268 // This object contains an instrusive ref count base class so we can
269 // easily make a shared pointer to this object
270 return DebuggerSP (this);
Greg Clayton66111032010-06-23 01:19:29 +0000271}
272
Greg Clayton4d122c42011-09-17 08:33:22 +0000273DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000274Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
275{
Greg Clayton4d122c42011-09-17 08:33:22 +0000276 DebuggerSP debugger_sp;
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000277
278 Mutex::Locker locker (GetDebuggerListMutex ());
279 DebuggerList &debugger_list = GetDebuggerList();
280 DebuggerList::iterator pos, end = debugger_list.end();
281
282 for (pos = debugger_list.begin(); pos != end; ++pos)
283 {
284 if ((*pos).get()->m_instance_name == instance_name)
285 {
286 debugger_sp = *pos;
287 break;
288 }
289 }
290 return debugger_sp;
291}
Greg Clayton66111032010-06-23 01:19:29 +0000292
293TargetSP
294Debugger::FindTargetWithProcessID (lldb::pid_t pid)
295{
Greg Clayton4d122c42011-09-17 08:33:22 +0000296 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000297 Mutex::Locker locker (GetDebuggerListMutex ());
298 DebuggerList &debugger_list = GetDebuggerList();
299 DebuggerList::iterator pos, end = debugger_list.end();
300 for (pos = debugger_list.begin(); pos != end; ++pos)
301 {
302 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
303 if (target_sp)
304 break;
305 }
306 return target_sp;
307}
308
Greg Claytone4e45922011-11-16 05:37:56 +0000309TargetSP
310Debugger::FindTargetWithProcess (Process *process)
311{
312 TargetSP target_sp;
313 Mutex::Locker locker (GetDebuggerListMutex ());
314 DebuggerList &debugger_list = GetDebuggerList();
315 DebuggerList::iterator pos, end = debugger_list.end();
316 for (pos = debugger_list.begin(); pos != end; ++pos)
317 {
318 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
319 if (target_sp)
320 break;
321 }
322 return target_sp;
323}
324
Greg Clayton66111032010-06-23 01:19:29 +0000325
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000326Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000327 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000328 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000329 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000330 m_input_file (),
331 m_output_file (),
332 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333 m_target_list (),
Greg Claytonded470d2011-03-19 01:12:21 +0000334 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335 m_listener ("lldb.Debugger"),
Jim Inghame37d6052011-09-13 00:29:56 +0000336 m_source_manager(*this),
337 m_source_file_cache(),
Greg Clayton66111032010-06-23 01:19:29 +0000338 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000339 m_input_reader_stack (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000340 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341{
Greg Clayton66111032010-06-23 01:19:29 +0000342 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000343 // Always add our default platform to the platform list
344 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
345 assert (default_platform_sp.get());
346 m_platform_list.Append (default_platform_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347}
348
349Debugger::~Debugger ()
350{
Jim Ingham8314c522011-09-15 21:36:42 +0000351 Clear();
352}
353
354void
355Debugger::Clear()
356{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000357 CleanUpInputReaders();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000358 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000359 int num_targets = m_target_list.GetNumTargets();
360 for (int i = 0; i < num_targets; i++)
361 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000362 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
363 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000364 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000365 ProcessSP process_sp (target_sp->GetProcessSP());
366 if (process_sp)
367 {
368 if (process_sp->GetShouldDetach())
369 process_sp->Detach();
370 }
371 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000372 }
Greg Clayton66111032010-06-23 01:19:29 +0000373 }
374 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375
Jim Ingham8314c522011-09-15 21:36:42 +0000376}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377
378bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000379Debugger::GetCloseInputOnEOF () const
380{
381 return m_input_comm.GetCloseOnEOF();
382}
383
384void
385Debugger::SetCloseInputOnEOF (bool b)
386{
387 m_input_comm.SetCloseOnEOF(b);
388}
389
390bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000391Debugger::GetAsyncExecution ()
392{
Greg Clayton66111032010-06-23 01:19:29 +0000393 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394}
395
396void
397Debugger::SetAsyncExecution (bool async_execution)
398{
Greg Clayton66111032010-06-23 01:19:29 +0000399 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400}
401
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402
403void
404Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
405{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000406 File &in_file = GetInputFile();
407 in_file.SetStream (fh, tranfer_ownership);
408 if (in_file.IsValid() == false)
409 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410
411 // Disconnect from any old connection if we had one
412 m_input_comm.Disconnect ();
Greg Clayton32720b52012-01-14 20:47:38 +0000413 // Pass false as the second argument to ConnectionFileDescriptor below because
414 // our "in_file" above will already take ownership if requested and we don't
415 // want to objects trying to own and close a file descriptor.
416 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
418
419 Error error;
420 if (m_input_comm.StartReadThread (&error) == false)
421 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000422 File &err_file = GetErrorFile();
423
424 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
425 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427}
428
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429void
430Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
431{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000432 File &out_file = GetOutputFile();
433 out_file.SetStream (fh, tranfer_ownership);
434 if (out_file.IsValid() == false)
435 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000436
437 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438}
439
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440void
441Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
442{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000443 File &err_file = GetErrorFile();
444 err_file.SetStream (fh, tranfer_ownership);
445 if (err_file.IsValid() == false)
446 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447}
448
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000450Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451{
452 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000453 TargetSP target_sp(GetSelectedTarget());
454 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455
456 if (target_sp)
457 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000458 ProcessSP process_sp (target_sp->GetProcessSP());
459 exe_ctx.SetProcessSP (process_sp);
460 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000461 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000462 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
463 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000465 exe_ctx.SetThreadSP (thread_sp);
466 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
467 if (exe_ctx.GetFramePtr() == NULL)
468 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469 }
470 }
471 }
472 return exe_ctx;
473
474}
475
Caroline Ticeb44880c2011-02-10 01:15:13 +0000476InputReaderSP
477Debugger::GetCurrentInputReader ()
478{
479 InputReaderSP reader_sp;
480
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000481 if (!m_input_reader_stack.IsEmpty())
Caroline Ticeb44880c2011-02-10 01:15:13 +0000482 {
483 // Clear any finished readers from the stack
484 while (CheckIfTopInputReaderIsDone()) ;
485
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000486 if (!m_input_reader_stack.IsEmpty())
487 reader_sp = m_input_reader_stack.Top();
Caroline Ticeb44880c2011-02-10 01:15:13 +0000488 }
489
490 return reader_sp;
491}
492
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493void
494Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
495{
Caroline Ticeefed6132010-11-19 20:47:54 +0000496 if (bytes_len > 0)
497 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
498 else
499 ((Debugger *)baton)->DispatchInputEndOfFile ();
500}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501
502
503void
504Debugger::DispatchInput (const char *bytes, size_t bytes_len)
505{
Caroline Ticeefed6132010-11-19 20:47:54 +0000506 if (bytes == NULL || bytes_len == 0)
507 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508
509 WriteToDefaultReader (bytes, bytes_len);
510}
511
512void
Caroline Ticeefed6132010-11-19 20:47:54 +0000513Debugger::DispatchInputInterrupt ()
514{
515 m_input_reader_data.clear();
516
Caroline Ticeb44880c2011-02-10 01:15:13 +0000517 InputReaderSP reader_sp (GetCurrentInputReader ());
518 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000519 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000520 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000521
Caroline Ticeb44880c2011-02-10 01:15:13 +0000522 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000523 while (CheckIfTopInputReaderIsDone ()) ;
524 }
525}
526
527void
528Debugger::DispatchInputEndOfFile ()
529{
530 m_input_reader_data.clear();
531
Caroline Ticeb44880c2011-02-10 01:15:13 +0000532 InputReaderSP reader_sp (GetCurrentInputReader ());
533 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000534 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000535 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000536
Caroline Ticeb44880c2011-02-10 01:15:13 +0000537 // 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 +0000538 while (CheckIfTopInputReaderIsDone ()) ;
539 }
540}
541
542void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000543Debugger::CleanUpInputReaders ()
544{
545 m_input_reader_data.clear();
546
Caroline Ticeb44880c2011-02-10 01:15:13 +0000547 // 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 +0000548 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000549 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000550 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000551 if (reader_sp)
552 {
553 reader_sp->Notify (eInputReaderEndOfFile);
554 reader_sp->SetIsDone (true);
555 }
556 }
557}
558
559void
Caroline Tice969ed3d2011-05-02 20:41:46 +0000560Debugger::NotifyTopInputReader (InputReaderAction notification)
561{
562 InputReaderSP reader_sp (GetCurrentInputReader());
563 if (reader_sp)
564 {
565 reader_sp->Notify (notification);
566
567 // Flush out any input readers that are done.
568 while (CheckIfTopInputReaderIsDone ())
569 /* Do nothing. */;
570 }
571}
572
Caroline Tice9088b062011-05-09 23:06:58 +0000573bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000574Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp)
Caroline Tice9088b062011-05-09 23:06:58 +0000575{
Caroline Ticed61c10b2011-06-16 16:27:19 +0000576 InputReaderSP top_reader_sp (GetCurrentInputReader());
Caroline Tice9088b062011-05-09 23:06:58 +0000577
Caroline Ticed61c10b2011-06-16 16:27:19 +0000578 return (reader_sp.get() == top_reader_sp.get());
Caroline Tice9088b062011-05-09 23:06:58 +0000579}
580
581
Caroline Tice969ed3d2011-05-02 20:41:46 +0000582void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
584{
585 if (bytes && bytes_len)
586 m_input_reader_data.append (bytes, bytes_len);
587
588 if (m_input_reader_data.empty())
589 return;
590
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000591 while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000592 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000594 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595 if (!reader_sp)
596 break;
597
Greg Clayton471b31c2010-07-20 22:52:08 +0000598 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599 m_input_reader_data.size());
600 if (bytes_handled)
601 {
602 m_input_reader_data.erase (0, bytes_handled);
603 }
604 else
605 {
606 // No bytes were handled, we might not have reached our
607 // granularity, just return and wait for more data
608 break;
609 }
610 }
611
Caroline Ticeb44880c2011-02-10 01:15:13 +0000612 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000613 while (CheckIfTopInputReaderIsDone ())
614 /* Do nothing. */;
615
616}
617
618void
619Debugger::PushInputReader (const InputReaderSP& reader_sp)
620{
621 if (!reader_sp)
622 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000623
624 // Deactivate the old top reader
625 InputReaderSP top_reader_sp (GetCurrentInputReader ());
626
627 if (top_reader_sp)
628 top_reader_sp->Notify (eInputReaderDeactivate);
629
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000630 m_input_reader_stack.Push (reader_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000631 reader_sp->Notify (eInputReaderActivate);
632 ActivateInputReader (reader_sp);
633}
634
635bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000636Debugger::PopInputReader (const InputReaderSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637{
638 bool result = false;
639
640 // The reader on the stop of the stack is done, so let the next
641 // read on the stack referesh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000642 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000643 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000644 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000645 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646
647 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
648 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000649 m_input_reader_stack.Pop ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000650 reader_sp->Notify (eInputReaderDeactivate);
651 reader_sp->Notify (eInputReaderDone);
652 result = true;
653
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000654 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000656 reader_sp = m_input_reader_stack.Top();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000657 if (reader_sp)
658 {
659 ActivateInputReader (reader_sp);
660 reader_sp->Notify (eInputReaderReactivate);
661 }
662 }
663 }
664 }
665 return result;
666}
667
668bool
669Debugger::CheckIfTopInputReaderIsDone ()
670{
671 bool result = false;
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000672 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000674 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000675 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676
677 if (reader_sp && reader_sp->IsDone())
678 {
679 result = true;
680 PopInputReader (reader_sp);
681 }
682 }
683 return result;
684}
685
686void
687Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
688{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000689 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000690
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000691 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000693 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000694
695 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696
Greg Claytona3406612011-02-07 23:24:47 +0000697 switch (reader_sp->GetGranularity())
698 {
699 case eInputReaderGranularityByte:
700 case eInputReaderGranularityWord:
701 tty.SetCanonical (false);
702 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000703
Greg Claytona3406612011-02-07 23:24:47 +0000704 case eInputReaderGranularityLine:
705 case eInputReaderGranularityAll:
706 tty.SetCanonical (true);
707 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708
Greg Claytona3406612011-02-07 23:24:47 +0000709 default:
710 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711 }
712 }
713}
Greg Clayton66111032010-06-23 01:19:29 +0000714
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000715StreamSP
716Debugger::GetAsyncOutputStream ()
717{
718 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
719 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
720}
721
722StreamSP
723Debugger::GetAsyncErrorStream ()
724{
725 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
726 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
727}
728
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000729DebuggerSP
730Debugger::FindDebuggerWithID (lldb::user_id_t id)
731{
Greg Clayton4d122c42011-09-17 08:33:22 +0000732 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000733
734 Mutex::Locker locker (GetDebuggerListMutex ());
735 DebuggerList &debugger_list = GetDebuggerList();
736 DebuggerList::iterator pos, end = debugger_list.end();
737 for (pos = debugger_list.begin(); pos != end; ++pos)
738 {
739 if ((*pos).get()->GetID() == id)
740 {
741 debugger_sp = *pos;
742 break;
743 }
744 }
745 return debugger_sp;
746}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000747
Greg Clayton1b654882010-09-19 02:33:57 +0000748static void
749TestPromptFormats (StackFrame *frame)
750{
751 if (frame == NULL)
752 return;
753
754 StreamString s;
755 const char *prompt_format =
756 "{addr = '${addr}'\n}"
757 "{process.id = '${process.id}'\n}"
758 "{process.name = '${process.name}'\n}"
759 "{process.file.basename = '${process.file.basename}'\n}"
760 "{process.file.fullpath = '${process.file.fullpath}'\n}"
761 "{thread.id = '${thread.id}'\n}"
762 "{thread.index = '${thread.index}'\n}"
763 "{thread.name = '${thread.name}'\n}"
764 "{thread.queue = '${thread.queue}'\n}"
765 "{thread.stop-reason = '${thread.stop-reason}'\n}"
766 "{target.arch = '${target.arch}'\n}"
767 "{module.file.basename = '${module.file.basename}'\n}"
768 "{module.file.fullpath = '${module.file.fullpath}'\n}"
769 "{file.basename = '${file.basename}'\n}"
770 "{file.fullpath = '${file.fullpath}'\n}"
771 "{frame.index = '${frame.index}'\n}"
772 "{frame.pc = '${frame.pc}'\n}"
773 "{frame.sp = '${frame.sp}'\n}"
774 "{frame.fp = '${frame.fp}'\n}"
775 "{frame.flags = '${frame.flags}'\n}"
776 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
777 "{frame.reg.rip = '${frame.reg.rip}'\n}"
778 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
779 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
780 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
781 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
782 "{frame.reg.carp = '${frame.reg.carp}'\n}"
783 "{function.id = '${function.id}'\n}"
784 "{function.name = '${function.name}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +0000785 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +0000786 "{function.addr-offset = '${function.addr-offset}'\n}"
787 "{function.line-offset = '${function.line-offset}'\n}"
788 "{function.pc-offset = '${function.pc-offset}'\n}"
789 "{line.file.basename = '${line.file.basename}'\n}"
790 "{line.file.fullpath = '${line.file.fullpath}'\n}"
791 "{line.number = '${line.number}'\n}"
792 "{line.start-addr = '${line.start-addr}'\n}"
793 "{line.end-addr = '${line.end-addr}'\n}"
794;
795
796 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
797 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000798 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000799 const char *end = NULL;
800 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
801 {
802 printf("%s\n", s.GetData());
803 }
804 else
805 {
806 printf ("error: at '%s'\n", end);
807 printf ("what we got: %s\n", s.GetData());
808 }
809}
810
Enrico Granata9fc19442011-07-06 02:13:41 +0000811static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000812ScanFormatDescriptor (const char* var_name_begin,
813 const char* var_name_end,
814 const char** var_name_final,
815 const char** percent_position,
Greg Clayton4d122c42011-09-17 08:33:22 +0000816 Format* custom_format,
Enrico Granatadc940732011-08-23 00:32:52 +0000817 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
Enrico Granata9fc19442011-07-06 02:13:41 +0000818{
Enrico Granatae992a082011-07-22 17:03:19 +0000819 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000820 *percent_position = ::strchr(var_name_begin,'%');
Greg Clayton34132752011-07-06 04:07:21 +0000821 if (!*percent_position || *percent_position > var_name_end)
Enrico Granatae992a082011-07-22 17:03:19 +0000822 {
823 if (log)
824 log->Printf("no format descriptor in string, skipping");
Enrico Granata9fc19442011-07-06 02:13:41 +0000825 *var_name_final = var_name_end;
Enrico Granatae992a082011-07-22 17:03:19 +0000826 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000827 else
828 {
829 *var_name_final = *percent_position;
830 char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0';
831 memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1);
Enrico Granatae992a082011-07-22 17:03:19 +0000832 if (log)
833 log->Printf("parsing %s as a format descriptor", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000834 if ( !FormatManager::GetFormatFromCString(format_name,
835 true,
836 *custom_format) )
837 {
Enrico Granatae992a082011-07-22 17:03:19 +0000838 if (log)
839 log->Printf("%s is an unknown format", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000840 // if this is an @ sign, print ObjC description
Greg Clayton34132752011-07-06 04:07:21 +0000841 if (*format_name == '@')
Enrico Granata9fc19442011-07-06 02:13:41 +0000842 *val_obj_display = ValueObject::eDisplayLanguageSpecific;
843 // if this is a V, print the value using the default format
Enrico Granatae992a082011-07-22 17:03:19 +0000844 else if (*format_name == 'V')
Enrico Granata9fc19442011-07-06 02:13:41 +0000845 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatad55546b2011-07-22 00:16:08 +0000846 // if this is an L, print the location of the value
Enrico Granatae992a082011-07-22 17:03:19 +0000847 else if (*format_name == 'L')
Enrico Granataf2bbf712011-07-15 02:26:42 +0000848 *val_obj_display = ValueObject::eDisplayLocation;
Enrico Granatad55546b2011-07-22 00:16:08 +0000849 // if this is an S, print the summary after all
Enrico Granatae992a082011-07-22 17:03:19 +0000850 else if (*format_name == 'S')
Enrico Granatad55546b2011-07-22 00:16:08 +0000851 *val_obj_display = ValueObject::eDisplaySummary;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000852 else if (*format_name == '#')
853 *val_obj_display = ValueObject::eDisplayChildrenCount;
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000854 else if (*format_name == 'T')
855 *val_obj_display = ValueObject::eDisplayType;
Enrico Granatae992a082011-07-22 17:03:19 +0000856 else if (log)
857 log->Printf("%s is an error, leaving the previous value alone", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000858 }
859 // a good custom format tells us to print the value using it
860 else
Enrico Granatae992a082011-07-22 17:03:19 +0000861 {
862 if (log)
863 log->Printf("will display value for this VO");
Enrico Granata9fc19442011-07-06 02:13:41 +0000864 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatae992a082011-07-22 17:03:19 +0000865 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000866 delete format_name;
867 }
Enrico Granatae992a082011-07-22 17:03:19 +0000868 if (log)
869 log->Printf("final format description outcome: custom_format = %d, val_obj_display = %d",
870 *custom_format,
871 *val_obj_display);
Enrico Granata9fc19442011-07-06 02:13:41 +0000872 return true;
873}
874
875static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000876ScanBracketedRange (const char* var_name_begin,
877 const char* var_name_end,
878 const char* var_name_final,
879 const char** open_bracket_position,
880 const char** separator_position,
881 const char** close_bracket_position,
882 const char** var_name_final_if_array_range,
883 int64_t* index_lower,
884 int64_t* index_higher)
Enrico Granata9fc19442011-07-06 02:13:41 +0000885{
Enrico Granatae992a082011-07-22 17:03:19 +0000886 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000887 *open_bracket_position = ::strchr(var_name_begin,'[');
Greg Clayton34132752011-07-06 04:07:21 +0000888 if (*open_bracket_position && *open_bracket_position < var_name_final)
Enrico Granata9fc19442011-07-06 02:13:41 +0000889 {
890 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
891 *close_bracket_position = ::strchr(*open_bracket_position,']');
892 // as usual, we assume that [] will come before %
893 //printf("trying to expand a []\n");
894 *var_name_final_if_array_range = *open_bracket_position;
Greg Clayton34132752011-07-06 04:07:21 +0000895 if (*close_bracket_position - *open_bracket_position == 1)
Enrico Granata9fc19442011-07-06 02:13:41 +0000896 {
Enrico Granatae992a082011-07-22 17:03:19 +0000897 if (log)
898 log->Printf("[] detected.. going from 0 to end of data");
Enrico Granata9fc19442011-07-06 02:13:41 +0000899 *index_lower = 0;
900 }
901 else if (*separator_position == NULL || *separator_position > var_name_end)
902 {
903 char *end = NULL;
904 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
905 *index_higher = *index_lower;
Enrico Granatae992a082011-07-22 17:03:19 +0000906 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000907 log->Printf("[%lld] detected, high index is same", *index_lower);
Enrico Granata9fc19442011-07-06 02:13:41 +0000908 }
Greg Clayton34132752011-07-06 04:07:21 +0000909 else if (*close_bracket_position && *close_bracket_position < var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +0000910 {
911 char *end = NULL;
912 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
913 *index_higher = ::strtoul (*separator_position+1, &end, 0);
Enrico Granatae992a082011-07-22 17:03:19 +0000914 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000915 log->Printf("[%lld-%lld] detected", *index_lower, *index_higher);
Enrico Granata9fc19442011-07-06 02:13:41 +0000916 }
917 else
Enrico Granatae992a082011-07-22 17:03:19 +0000918 {
919 if (log)
920 log->Printf("expression is erroneous, cannot extract indices out of it");
Enrico Granata9fc19442011-07-06 02:13:41 +0000921 return false;
Enrico Granatae992a082011-07-22 17:03:19 +0000922 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000923 if (*index_lower > *index_higher && *index_higher > 0)
924 {
Enrico Granatae992a082011-07-22 17:03:19 +0000925 if (log)
926 log->Printf("swapping indices");
Enrico Granata9fc19442011-07-06 02:13:41 +0000927 int temp = *index_lower;
928 *index_lower = *index_higher;
929 *index_higher = temp;
930 }
931 }
Enrico Granatae992a082011-07-22 17:03:19 +0000932 else if (log)
933 log->Printf("no bracketed range, skipping entirely");
Enrico Granata9fc19442011-07-06 02:13:41 +0000934 return true;
935}
936
937
938static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000939ExpandExpressionPath (ValueObject* valobj,
940 StackFrame* frame,
941 bool* do_deref_pointer,
942 const char* var_name_begin,
943 const char* var_name_final,
944 Error& error)
Enrico Granata9fc19442011-07-06 02:13:41 +0000945{
Enrico Granatae992a082011-07-22 17:03:19 +0000946 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000947 StreamString sstring;
948 VariableSP var_sp;
949
Greg Clayton34132752011-07-06 04:07:21 +0000950 if (*do_deref_pointer)
Enrico Granatae992a082011-07-22 17:03:19 +0000951 {
952 if (log)
953 log->Printf("been told to deref_pointer by caller");
Enrico Granata9fc19442011-07-06 02:13:41 +0000954 sstring.PutChar('*');
Enrico Granatae992a082011-07-22 17:03:19 +0000955 }
Enrico Granatac482a192011-08-17 22:13:59 +0000956 else if (valobj->IsDereferenceOfParent() && ClangASTContext::IsPointerType(valobj->GetParent()->GetClangType()) && !valobj->IsArrayItemForPointer())
Enrico Granata9fc19442011-07-06 02:13:41 +0000957 {
Enrico Granatae992a082011-07-22 17:03:19 +0000958 if (log)
959 log->Printf("decided to deref_pointer myself");
Enrico Granata9fc19442011-07-06 02:13:41 +0000960 sstring.PutChar('*');
961 *do_deref_pointer = true;
962 }
963
Enrico Granatac482a192011-08-17 22:13:59 +0000964 valobj->GetExpressionPath(sstring, true, ValueObject::eHonorPointers);
Enrico Granatae992a082011-07-22 17:03:19 +0000965 if (log)
966 log->Printf("expression path to expand in phase 0: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000967 sstring.PutRawBytes(var_name_begin+3, var_name_final-var_name_begin-3);
Enrico Granatae992a082011-07-22 17:03:19 +0000968 if (log)
969 log->Printf("expression path to expand in phase 1: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000970 std::string name = std::string(sstring.GetData());
971 ValueObjectSP target = frame->GetValueForVariableExpressionPath (name.c_str(),
972 eNoDynamicValues,
973 0,
974 var_sp,
975 error);
976 return target;
977}
978
979static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000980ExpandIndexedExpression (ValueObject* valobj,
981 uint32_t index,
982 StackFrame* frame,
983 bool deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +0000984{
Enrico Granatae992a082011-07-22 17:03:19 +0000985 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000986 const char* ptr_deref_format = "[%d]";
987 std::auto_ptr<char> ptr_deref_buffer(new char[10]);
988 ::sprintf(ptr_deref_buffer.get(), ptr_deref_format, index);
Enrico Granatae992a082011-07-22 17:03:19 +0000989 if (log)
990 log->Printf("name to deref: %s",ptr_deref_buffer.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000991 const char* first_unparsed;
992 ValueObject::GetValueForExpressionPathOptions options;
993 ValueObject::ExpressionPathEndResultType final_value_type;
994 ValueObject::ExpressionPathScanEndReason reason_to_stop;
995 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eDereference : ValueObject::eNothing);
Enrico Granatac482a192011-08-17 22:13:59 +0000996 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000997 &first_unparsed,
998 &reason_to_stop,
999 &final_value_type,
1000 options,
1001 &what_next);
1002 if (!item)
1003 {
Enrico Granatae992a082011-07-22 17:03:19 +00001004 if (log)
1005 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1006 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001007 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001008 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001009 else
1010 {
Enrico Granatae992a082011-07-22 17:03:19 +00001011 if (log)
1012 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1013 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001014 first_unparsed, reason_to_stop, final_value_type);
Enrico Granata9fc19442011-07-06 02:13:41 +00001015 }
1016 return item;
1017}
1018
Greg Clayton1b654882010-09-19 02:33:57 +00001019bool
1020Debugger::FormatPrompt
1021(
1022 const char *format,
1023 const SymbolContext *sc,
1024 const ExecutionContext *exe_ctx,
1025 const Address *addr,
1026 Stream &s,
Enrico Granata4becb372011-06-29 22:27:15 +00001027 const char **end,
Enrico Granatac482a192011-08-17 22:13:59 +00001028 ValueObject* valobj
Greg Clayton1b654882010-09-19 02:33:57 +00001029)
1030{
Enrico Granatac482a192011-08-17 22:13:59 +00001031 ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers
Greg Clayton1b654882010-09-19 02:33:57 +00001032 bool success = true;
1033 const char *p;
Enrico Granatae992a082011-07-22 17:03:19 +00001034 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Greg Clayton1b654882010-09-19 02:33:57 +00001035 for (p = format; *p != '\0'; ++p)
1036 {
Enrico Granatac482a192011-08-17 22:13:59 +00001037 if (realvalobj)
Enrico Granata4becb372011-06-29 22:27:15 +00001038 {
Enrico Granatac482a192011-08-17 22:13:59 +00001039 valobj = realvalobj;
1040 realvalobj = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00001041 }
Greg Clayton1b654882010-09-19 02:33:57 +00001042 size_t non_special_chars = ::strcspn (p, "${}\\");
1043 if (non_special_chars > 0)
1044 {
1045 if (success)
1046 s.Write (p, non_special_chars);
1047 p += non_special_chars;
1048 }
1049
1050 if (*p == '\0')
1051 {
1052 break;
1053 }
1054 else if (*p == '{')
1055 {
1056 // Start a new scope that must have everything it needs if it is to
1057 // to make it into the final output stream "s". If you want to make
1058 // a format that only prints out the function or symbol name if there
1059 // is one in the symbol context you can use:
1060 // "{function =${function.name}}"
1061 // The first '{' starts a new scope that end with the matching '}' at
1062 // the end of the string. The contents "function =${function.name}"
1063 // will then be evaluated and only be output if there is a function
1064 // or symbol with a valid name.
1065 StreamString sub_strm;
1066
1067 ++p; // Skip the '{'
1068
Enrico Granatac482a192011-08-17 22:13:59 +00001069 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
Greg Clayton1b654882010-09-19 02:33:57 +00001070 {
1071 // The stream had all it needed
1072 s.Write(sub_strm.GetData(), sub_strm.GetSize());
1073 }
1074 if (*p != '}')
1075 {
1076 success = false;
1077 break;
1078 }
1079 }
1080 else if (*p == '}')
1081 {
1082 // End of a enclosing scope
1083 break;
1084 }
1085 else if (*p == '$')
1086 {
1087 // We have a prompt variable to print
1088 ++p;
1089 if (*p == '{')
1090 {
1091 ++p;
1092 const char *var_name_begin = p;
1093 const char *var_name_end = ::strchr (p, '}');
1094
1095 if (var_name_end && var_name_begin < var_name_end)
1096 {
1097 // if we have already failed to parse, skip this variable
1098 if (success)
1099 {
1100 const char *cstr = NULL;
1101 Address format_addr;
1102 bool calculate_format_addr_function_offset = false;
1103 // Set reg_kind and reg_num to invalid values
1104 RegisterKind reg_kind = kNumRegisterKinds;
1105 uint32_t reg_num = LLDB_INVALID_REGNUM;
1106 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +00001107 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00001108 RegisterContext *reg_ctx = NULL;
Enrico Granata9fc19442011-07-06 02:13:41 +00001109 bool do_deref_pointer = false;
Enrico Granatae992a082011-07-22 17:03:19 +00001110 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eEndOfString;
1111 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::ePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001112
Greg Clayton1b654882010-09-19 02:33:57 +00001113 // Each variable must set success to true below...
1114 bool var_success = false;
1115 switch (var_name_begin[0])
1116 {
Enrico Granata4becb372011-06-29 22:27:15 +00001117 case '*':
Enrico Granata4becb372011-06-29 22:27:15 +00001118 case 'v':
Enrico Granata6f3533f2011-07-29 19:53:35 +00001119 case 's':
Enrico Granata4becb372011-06-29 22:27:15 +00001120 {
Enrico Granatac482a192011-08-17 22:13:59 +00001121 if (!valobj)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001122 break;
1123
Enrico Granatac3e320a2011-08-02 17:27:39 +00001124 if (log)
1125 log->Printf("initial string: %s",var_name_begin);
1126
Enrico Granata6f3533f2011-07-29 19:53:35 +00001127 // check for *var and *svar
1128 if (*var_name_begin == '*')
1129 {
1130 do_deref_pointer = true;
1131 var_name_begin++;
1132 }
Enrico Granatac3e320a2011-08-02 17:27:39 +00001133
1134 if (log)
1135 log->Printf("initial string: %s",var_name_begin);
1136
Enrico Granata6f3533f2011-07-29 19:53:35 +00001137 if (*var_name_begin == 's')
1138 {
Greg Clayton4d122c42011-09-17 08:33:22 +00001139 valobj = valobj->GetSyntheticValue(eUseSyntheticFilter).get();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001140 var_name_begin++;
1141 }
1142
Enrico Granatac3e320a2011-08-02 17:27:39 +00001143 if (log)
1144 log->Printf("initial string: %s",var_name_begin);
1145
Enrico Granata6f3533f2011-07-29 19:53:35 +00001146 // should be a 'v' by now
1147 if (*var_name_begin != 'v')
1148 break;
1149
Enrico Granatac3e320a2011-08-02 17:27:39 +00001150 if (log)
1151 log->Printf("initial string: %s",var_name_begin);
1152
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001153 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
1154 ValueObject::eDereference : ValueObject::eNothing);
1155 ValueObject::GetValueForExpressionPathOptions options;
Enrico Granata8c9d3562011-08-11 17:08:01 +00001156 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren();
Greg Clayton34132752011-07-06 04:07:21 +00001157 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eDisplaySummary;
1158 ValueObject* target = NULL;
Greg Clayton4d122c42011-09-17 08:33:22 +00001159 Format custom_format = eFormatInvalid;
Greg Clayton34132752011-07-06 04:07:21 +00001160 const char* var_name_final = NULL;
1161 const char* var_name_final_if_array_range = NULL;
1162 const char* close_bracket_position = NULL;
1163 int64_t index_lower = -1;
1164 int64_t index_higher = -1;
1165 bool is_array_range = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001166 const char* first_unparsed;
Enrico Granata85933ed2011-08-18 16:38:26 +00001167 bool was_plain_var = false;
1168 bool was_var_format = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001169
Enrico Granatac482a192011-08-17 22:13:59 +00001170 if (!valobj) break;
1171 // simplest case ${var}, just print valobj's value
Greg Clayton34132752011-07-06 04:07:21 +00001172 if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0)
Enrico Granata4becb372011-06-29 22:27:15 +00001173 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001174 was_plain_var = true;
Enrico Granatac482a192011-08-17 22:13:59 +00001175 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001176 val_obj_display = ValueObject::eDisplayValue;
1177 }
1178 else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0)
1179 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001180 was_var_format = true;
Greg Clayton34132752011-07-06 04:07:21 +00001181 // this is a variable with some custom format applied to it
1182 const char* percent_position;
Enrico Granatac482a192011-08-17 22:13:59 +00001183 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001184 val_obj_display = ValueObject::eDisplayValue;
1185 ScanFormatDescriptor (var_name_begin,
1186 var_name_end,
1187 &var_name_final,
1188 &percent_position,
1189 &custom_format,
1190 &val_obj_display);
1191 }
1192 // this is ${var.something} or multiple .something nested
1193 else if (::strncmp (var_name_begin, "var", strlen("var")) == 0)
1194 {
1195
1196 const char* percent_position;
1197 ScanFormatDescriptor (var_name_begin,
1198 var_name_end,
1199 &var_name_final,
1200 &percent_position,
1201 &custom_format,
1202 &val_obj_display);
1203
1204 const char* open_bracket_position;
1205 const char* separator_position;
1206 ScanBracketedRange (var_name_begin,
1207 var_name_end,
1208 var_name_final,
1209 &open_bracket_position,
1210 &separator_position,
1211 &close_bracket_position,
1212 &var_name_final_if_array_range,
1213 &index_lower,
1214 &index_higher);
1215
1216 Error error;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001217
1218 std::auto_ptr<char> expr_path(new char[var_name_final-var_name_begin-1]);
1219 ::memset(expr_path.get(), 0, var_name_final-var_name_begin-1);
1220 memcpy(expr_path.get(), var_name_begin+3,var_name_final-var_name_begin-3);
1221
Enrico Granatae992a082011-07-22 17:03:19 +00001222 if (log)
1223 log->Printf("symbol to expand: %s",expr_path.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001224
Enrico Granatac482a192011-08-17 22:13:59 +00001225 target = valobj->GetValueForExpressionPath(expr_path.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001226 &first_unparsed,
1227 &reason_to_stop,
1228 &final_value_type,
1229 options,
1230 &what_next).get();
1231
1232 if (!target)
Enrico Granata9fc19442011-07-06 02:13:41 +00001233 {
Enrico Granatae992a082011-07-22 17:03:19 +00001234 if (log)
1235 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1236 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001237 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001238 break;
Enrico Granata9fc19442011-07-06 02:13:41 +00001239 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001240 else
1241 {
Enrico Granatae992a082011-07-22 17:03:19 +00001242 if (log)
1243 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1244 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001245 first_unparsed, reason_to_stop, final_value_type);
1246 }
Enrico Granata4becb372011-06-29 22:27:15 +00001247 }
Greg Clayton34132752011-07-06 04:07:21 +00001248 else
Enrico Granata9fc19442011-07-06 02:13:41 +00001249 break;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001250
1251 is_array_range = (final_value_type == ValueObject::eBoundedRange ||
1252 final_value_type == ValueObject::eUnboundedRange);
1253
1254 do_deref_pointer = (what_next == ValueObject::eDereference);
Enrico Granata9fc19442011-07-06 02:13:41 +00001255
Enrico Granataa7187d02011-07-06 19:27:11 +00001256 if (do_deref_pointer && !is_array_range)
Enrico Granata9fc19442011-07-06 02:13:41 +00001257 {
Greg Clayton34132752011-07-06 04:07:21 +00001258 // I have not deref-ed yet, let's do it
1259 // this happens when we are not going through GetValueForVariableExpressionPath
1260 // to get to the target ValueObject
Enrico Granata9fc19442011-07-06 02:13:41 +00001261 Error error;
Greg Clayton34132752011-07-06 04:07:21 +00001262 target = target->Dereference(error).get();
Enrico Granatadc940732011-08-23 00:32:52 +00001263 if (error.Fail())
1264 {
1265 if (log)
1266 log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
1267 break;
1268 }
Greg Clayton34132752011-07-06 04:07:21 +00001269 do_deref_pointer = false;
Enrico Granata9fc19442011-07-06 02:13:41 +00001270 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001271
Enrico Granata85933ed2011-08-18 16:38:26 +00001272 // TODO use flags for these
Enrico Granataf4efecd2011-07-12 22:56:10 +00001273 bool is_array = ClangASTContext::IsArrayType(target->GetClangType());
1274 bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType());
Enrico Granata85933ed2011-08-18 16:38:26 +00001275 bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType());
Enrico Granataf4efecd2011-07-12 22:56:10 +00001276
1277 if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eDisplayValue) // this should be wrong, but there are some exceptions
1278 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001279 StreamString str_temp;
Enrico Granatae992a082011-07-22 17:03:19 +00001280 if (log)
1281 log->Printf("I am into array || pointer && !range");
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001282
1283 if (target->HasSpecialCasesForPrintableRepresentation(val_obj_display,
1284 custom_format))
Enrico Granata85933ed2011-08-18 16:38:26 +00001285 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001286 // try to use the special cases
1287 var_success = target->DumpPrintableRepresentation(str_temp,
1288 val_obj_display,
1289 custom_format);
1290 if (log)
1291 log->Printf("special cases did%s match", var_success ? "" : "n't");
1292
1293 // should not happen
1294 if (!var_success)
1295 s << "<invalid usage of pointer value as object>";
1296 else
1297 s << str_temp.GetData();
Enrico Granata85933ed2011-08-18 16:38:26 +00001298 var_success = true;
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001299 break;
Enrico Granata85933ed2011-08-18 16:38:26 +00001300 }
1301 else
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001302 {
Enrico Granata88da35f2011-08-23 21:26:09 +00001303 if (was_plain_var) // if ${var}
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001304 {
1305 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1306 }
Enrico Granata88da35f2011-08-23 21:26:09 +00001307 else if (is_pointer) // if pointer, value is the address stored
1308 {
1309 var_success = target->GetPrintableRepresentation(s,
1310 val_obj_display,
1311 custom_format);
1312 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001313 else
1314 {
1315 s << "<invalid usage of pointer value as object>";
1316 }
1317 var_success = true;
1318 break;
1319 }
1320 }
1321
1322 // if directly trying to print ${var}, and this is an aggregate, display a nice
1323 // type @ location message
1324 if (is_aggregate && was_plain_var)
1325 {
1326 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1327 var_success = true;
Enrico Granata85933ed2011-08-18 16:38:26 +00001328 break;
1329 }
1330
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001331 // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it
1332 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eDisplayValue)))
Enrico Granata85933ed2011-08-18 16:38:26 +00001333 {
1334 s << "<invalid use of aggregate type>";
1335 var_success = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001336 break;
1337 }
Greg Clayton34132752011-07-06 04:07:21 +00001338
1339 if (!is_array_range)
Enrico Granatae992a082011-07-22 17:03:19 +00001340 {
1341 if (log)
1342 log->Printf("dumping ordinary printable output");
Greg Clayton34132752011-07-06 04:07:21 +00001343 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
Enrico Granatae992a082011-07-22 17:03:19 +00001344 }
Greg Clayton34132752011-07-06 04:07:21 +00001345 else
Enrico Granatae992a082011-07-22 17:03:19 +00001346 {
1347 if (log)
1348 log->Printf("checking if I can handle as array");
Greg Clayton34132752011-07-06 04:07:21 +00001349 if (!is_array && !is_pointer)
1350 break;
Enrico Granatae992a082011-07-22 17:03:19 +00001351 if (log)
1352 log->Printf("handle as array");
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001353 const char* special_directions = NULL;
1354 StreamString special_directions_writer;
Greg Clayton34132752011-07-06 04:07:21 +00001355 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1356 {
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001357 ConstString additional_data;
1358 additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1);
1359 special_directions_writer.Printf("${%svar%s}",
1360 do_deref_pointer ? "*" : "",
1361 additional_data.GetCString());
1362 special_directions = special_directions_writer.GetData();
Greg Clayton34132752011-07-06 04:07:21 +00001363 }
1364
1365 // let us display items index_lower thru index_higher of this array
1366 s.PutChar('[');
1367 var_success = true;
1368
1369 if (index_higher < 0)
Enrico Granatac482a192011-08-17 22:13:59 +00001370 index_higher = valobj->GetNumChildren() - 1;
Greg Clayton34132752011-07-06 04:07:21 +00001371
Enrico Granata22c55d12011-08-12 02:00:06 +00001372 uint32_t max_num_children = target->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
1373
Greg Clayton34132752011-07-06 04:07:21 +00001374 for (;index_lower<=index_higher;index_lower++)
1375 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001376 ValueObject* item = ExpandIndexedExpression (target,
1377 index_lower,
1378 exe_ctx->GetFramePtr(),
1379 false).get();
Greg Clayton34132752011-07-06 04:07:21 +00001380
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001381 if (!item)
1382 {
Enrico Granatae992a082011-07-22 17:03:19 +00001383 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001384 log->Printf("ERROR in getting child item at index %lld", index_lower);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001385 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001386 else
1387 {
Enrico Granatae992a082011-07-22 17:03:19 +00001388 if (log)
1389 log->Printf("special_directions for child item: %s",special_directions);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001390 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001391
Greg Clayton34132752011-07-06 04:07:21 +00001392 if (!special_directions)
1393 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1394 else
1395 var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
1396
Enrico Granata22c55d12011-08-12 02:00:06 +00001397 if (--max_num_children == 0)
1398 {
1399 s.PutCString(", ...");
1400 break;
1401 }
1402
Greg Clayton34132752011-07-06 04:07:21 +00001403 if (index_lower < index_higher)
1404 s.PutChar(',');
1405 }
1406 s.PutChar(']');
1407 }
Enrico Granata4becb372011-06-29 22:27:15 +00001408 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001409 break;
Greg Clayton1b654882010-09-19 02:33:57 +00001410 case 'a':
1411 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
1412 {
1413 if (addr && addr->IsValid())
1414 {
1415 var_success = true;
1416 format_addr = *addr;
1417 }
1418 }
Greg Clayton5a314712011-10-14 07:41:33 +00001419 else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0)
1420 {
1421 var_success = true;
1422 var_name_begin += strlen("ansi."); // Skip the "ansi."
1423 if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0)
1424 {
1425 var_name_begin += strlen("fg."); // Skip the "fg."
1426 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1427 {
1428 s.Printf ("%s%s%s",
1429 lldb_utility::ansi::k_escape_start,
1430 lldb_utility::ansi::k_fg_black,
1431 lldb_utility::ansi::k_escape_end);
1432 }
1433 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1434 {
1435 s.Printf ("%s%s%s",
1436 lldb_utility::ansi::k_escape_start,
1437 lldb_utility::ansi::k_fg_red,
1438 lldb_utility::ansi::k_escape_end);
1439 }
1440 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1441 {
1442 s.Printf ("%s%s%s",
1443 lldb_utility::ansi::k_escape_start,
1444 lldb_utility::ansi::k_fg_green,
1445 lldb_utility::ansi::k_escape_end);
1446 }
1447 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1448 {
1449 s.Printf ("%s%s%s",
1450 lldb_utility::ansi::k_escape_start,
1451 lldb_utility::ansi::k_fg_yellow,
1452 lldb_utility::ansi::k_escape_end);
1453 }
1454 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1455 {
1456 s.Printf ("%s%s%s",
1457 lldb_utility::ansi::k_escape_start,
1458 lldb_utility::ansi::k_fg_blue,
1459 lldb_utility::ansi::k_escape_end);
1460 }
1461 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1462 {
1463 s.Printf ("%s%s%s",
1464 lldb_utility::ansi::k_escape_start,
1465 lldb_utility::ansi::k_fg_purple,
1466 lldb_utility::ansi::k_escape_end);
1467 }
1468 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1469 {
1470 s.Printf ("%s%s%s",
1471 lldb_utility::ansi::k_escape_start,
1472 lldb_utility::ansi::k_fg_cyan,
1473 lldb_utility::ansi::k_escape_end);
1474 }
1475 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1476 {
1477 s.Printf ("%s%s%s",
1478 lldb_utility::ansi::k_escape_start,
1479 lldb_utility::ansi::k_fg_white,
1480 lldb_utility::ansi::k_escape_end);
1481 }
1482 else
1483 {
1484 var_success = false;
1485 }
1486 }
1487 else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0)
1488 {
1489 var_name_begin += strlen("bg."); // Skip the "bg."
1490 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1491 {
1492 s.Printf ("%s%s%s",
1493 lldb_utility::ansi::k_escape_start,
1494 lldb_utility::ansi::k_bg_black,
1495 lldb_utility::ansi::k_escape_end);
1496 }
1497 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1498 {
1499 s.Printf ("%s%s%s",
1500 lldb_utility::ansi::k_escape_start,
1501 lldb_utility::ansi::k_bg_red,
1502 lldb_utility::ansi::k_escape_end);
1503 }
1504 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1505 {
1506 s.Printf ("%s%s%s",
1507 lldb_utility::ansi::k_escape_start,
1508 lldb_utility::ansi::k_bg_green,
1509 lldb_utility::ansi::k_escape_end);
1510 }
1511 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1512 {
1513 s.Printf ("%s%s%s",
1514 lldb_utility::ansi::k_escape_start,
1515 lldb_utility::ansi::k_bg_yellow,
1516 lldb_utility::ansi::k_escape_end);
1517 }
1518 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1519 {
1520 s.Printf ("%s%s%s",
1521 lldb_utility::ansi::k_escape_start,
1522 lldb_utility::ansi::k_bg_blue,
1523 lldb_utility::ansi::k_escape_end);
1524 }
1525 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1526 {
1527 s.Printf ("%s%s%s",
1528 lldb_utility::ansi::k_escape_start,
1529 lldb_utility::ansi::k_bg_purple,
1530 lldb_utility::ansi::k_escape_end);
1531 }
1532 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1533 {
1534 s.Printf ("%s%s%s",
1535 lldb_utility::ansi::k_escape_start,
1536 lldb_utility::ansi::k_bg_cyan,
1537 lldb_utility::ansi::k_escape_end);
1538 }
1539 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1540 {
1541 s.Printf ("%s%s%s",
1542 lldb_utility::ansi::k_escape_start,
1543 lldb_utility::ansi::k_bg_white,
1544 lldb_utility::ansi::k_escape_end);
1545 }
1546 else
1547 {
1548 var_success = false;
1549 }
1550 }
1551 else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0)
1552 {
1553 s.Printf ("%s%s%s",
1554 lldb_utility::ansi::k_escape_start,
1555 lldb_utility::ansi::k_ctrl_normal,
1556 lldb_utility::ansi::k_escape_end);
1557 }
1558 else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0)
1559 {
1560 s.Printf ("%s%s%s",
1561 lldb_utility::ansi::k_escape_start,
1562 lldb_utility::ansi::k_ctrl_bold,
1563 lldb_utility::ansi::k_escape_end);
1564 }
1565 else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0)
1566 {
1567 s.Printf ("%s%s%s",
1568 lldb_utility::ansi::k_escape_start,
1569 lldb_utility::ansi::k_ctrl_faint,
1570 lldb_utility::ansi::k_escape_end);
1571 }
1572 else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0)
1573 {
1574 s.Printf ("%s%s%s",
1575 lldb_utility::ansi::k_escape_start,
1576 lldb_utility::ansi::k_ctrl_italic,
1577 lldb_utility::ansi::k_escape_end);
1578 }
1579 else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0)
1580 {
1581 s.Printf ("%s%s%s",
1582 lldb_utility::ansi::k_escape_start,
1583 lldb_utility::ansi::k_ctrl_underline,
1584 lldb_utility::ansi::k_escape_end);
1585 }
1586 else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0)
1587 {
1588 s.Printf ("%s%s%s",
1589 lldb_utility::ansi::k_escape_start,
1590 lldb_utility::ansi::k_ctrl_slow_blink,
1591 lldb_utility::ansi::k_escape_end);
1592 }
1593 else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0)
1594 {
1595 s.Printf ("%s%s%s",
1596 lldb_utility::ansi::k_escape_start,
1597 lldb_utility::ansi::k_ctrl_fast_blink,
1598 lldb_utility::ansi::k_escape_end);
1599 }
1600 else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0)
1601 {
1602 s.Printf ("%s%s%s",
1603 lldb_utility::ansi::k_escape_start,
1604 lldb_utility::ansi::k_ctrl_negative,
1605 lldb_utility::ansi::k_escape_end);
1606 }
1607 else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0)
1608 {
1609 s.Printf ("%s%s%s",
1610 lldb_utility::ansi::k_escape_start,
1611 lldb_utility::ansi::k_ctrl_conceal,
1612 lldb_utility::ansi::k_escape_end);
1613
1614 }
1615 else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0)
1616 {
1617 s.Printf ("%s%s%s",
1618 lldb_utility::ansi::k_escape_start,
1619 lldb_utility::ansi::k_ctrl_crossed_out,
1620 lldb_utility::ansi::k_escape_end);
1621 }
1622 else
1623 {
1624 var_success = false;
1625 }
1626 }
Greg Clayton1b654882010-09-19 02:33:57 +00001627 break;
1628
1629 case 'p':
1630 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
1631 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001632 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001633 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001634 Process *process = exe_ctx->GetProcessPtr();
1635 if (process)
Greg Clayton1b654882010-09-19 02:33:57 +00001636 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001637 var_name_begin += ::strlen ("process.");
1638 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001639 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001640 s.Printf("%llu", process->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001641 var_success = true;
1642 }
1643 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
1644 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
1645 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
1646 {
1647 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1648 if (exe_module)
Greg Clayton1b654882010-09-19 02:33:57 +00001649 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001650 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1651 {
1652 format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
1653 var_success = format_file_spec;
1654 }
1655 else
1656 {
1657 format_file_spec = exe_module->GetFileSpec();
1658 var_success = format_file_spec;
1659 }
Greg Clayton1b654882010-09-19 02:33:57 +00001660 }
1661 }
1662 }
Greg Claytonc14ee322011-09-22 04:58:26 +00001663 }
Greg Clayton1b654882010-09-19 02:33:57 +00001664 }
1665 break;
1666
1667 case 't':
1668 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
1669 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001670 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001671 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001672 Thread *thread = exe_ctx->GetThreadPtr();
1673 if (thread)
Greg Clayton1b654882010-09-19 02:33:57 +00001674 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001675 var_name_begin += ::strlen ("thread.");
1676 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001677 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001678 s.Printf("0x%4.4llx", thread->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001679 var_success = true;
1680 }
1681 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1682 {
1683 s.Printf("%u", thread->GetIndexID());
1684 var_success = true;
1685 }
1686 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1687 {
1688 cstr = thread->GetName();
1689 var_success = cstr && cstr[0];
1690 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001691 s.PutCString(cstr);
Greg Claytonc14ee322011-09-22 04:58:26 +00001692 }
1693 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
1694 {
1695 cstr = thread->GetQueueName();
1696 var_success = cstr && cstr[0];
1697 if (var_success)
1698 s.PutCString(cstr);
1699 }
1700 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
1701 {
1702 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1703 if (stop_info_sp)
1704 {
1705 cstr = stop_info_sp->GetDescription();
1706 if (cstr && cstr[0])
1707 {
1708 s.PutCString(cstr);
1709 var_success = true;
1710 }
Greg Clayton1b654882010-09-19 02:33:57 +00001711 }
1712 }
Jim Ingham73ca05a2011-12-17 01:35:57 +00001713 else if (::strncmp (var_name_begin, "return-value}", strlen("return-value}")) == 0)
1714 {
1715 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1716 if (stop_info_sp)
1717 {
1718 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1719 if (return_valobj_sp)
1720 {
Jim Inghamef651602011-12-22 19:12:40 +00001721 ValueObject::DumpValueObjectOptions dump_options;
1722 ValueObject::DumpValueObject (s, return_valobj_sp.get(), dump_options);
1723 var_success = true;
Jim Ingham73ca05a2011-12-17 01:35:57 +00001724 }
1725 }
1726 }
Greg Clayton1b654882010-09-19 02:33:57 +00001727 }
1728 }
1729 }
1730 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
1731 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001732 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1733 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +00001734 {
Greg Clayton1b654882010-09-19 02:33:57 +00001735 var_name_begin += ::strlen ("target.");
1736 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
1737 {
1738 ArchSpec arch (target->GetArchitecture ());
1739 if (arch.IsValid())
1740 {
Greg Clayton64195a22011-02-23 00:35:02 +00001741 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +00001742 var_success = true;
1743 }
1744 }
1745 }
1746 }
1747 break;
1748
1749
1750 case 'm':
1751 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
1752 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001753 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +00001754 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001755 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +00001756 var_name_begin += ::strlen ("module.");
1757
1758 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1759 {
1760 if (module->GetFileSpec())
1761 {
1762 var_name_begin += ::strlen ("file.");
1763
1764 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1765 {
1766 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
1767 var_success = format_file_spec;
1768 }
1769 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1770 {
1771 format_file_spec = module->GetFileSpec();
1772 var_success = format_file_spec;
1773 }
1774 }
1775 }
1776 }
1777 }
1778 break;
1779
1780
1781 case 'f':
1782 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1783 {
1784 if (sc && sc->comp_unit != NULL)
1785 {
1786 var_name_begin += ::strlen ("file.");
1787
1788 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1789 {
1790 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
1791 var_success = format_file_spec;
1792 }
1793 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1794 {
1795 format_file_spec = *sc->comp_unit;
1796 var_success = format_file_spec;
1797 }
1798 }
1799 }
1800 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
1801 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001802 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001803 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001804 StackFrame *frame = exe_ctx->GetFramePtr();
1805 if (frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001806 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001807 var_name_begin += ::strlen ("frame.");
1808 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001809 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001810 s.Printf("%u", frame->GetFrameIndex());
1811 var_success = true;
1812 }
1813 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
1814 {
1815 reg_kind = eRegisterKindGeneric;
1816 reg_num = LLDB_REGNUM_GENERIC_PC;
1817 var_success = true;
1818 }
1819 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
1820 {
1821 reg_kind = eRegisterKindGeneric;
1822 reg_num = LLDB_REGNUM_GENERIC_SP;
1823 var_success = true;
1824 }
1825 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
1826 {
1827 reg_kind = eRegisterKindGeneric;
1828 reg_num = LLDB_REGNUM_GENERIC_FP;
1829 var_success = true;
1830 }
1831 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
1832 {
1833 reg_kind = eRegisterKindGeneric;
1834 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
1835 var_success = true;
1836 }
1837 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
1838 {
1839 reg_ctx = frame->GetRegisterContext().get();
1840 if (reg_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001841 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001842 var_name_begin += ::strlen ("reg.");
1843 if (var_name_begin < var_name_end)
1844 {
1845 std::string reg_name (var_name_begin, var_name_end);
1846 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
1847 if (reg_info)
1848 var_success = true;
1849 }
Greg Clayton1b654882010-09-19 02:33:57 +00001850 }
1851 }
1852 }
1853 }
1854 }
1855 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
1856 {
1857 if (sc && (sc->function != NULL || sc->symbol != NULL))
1858 {
1859 var_name_begin += ::strlen ("function.");
1860 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1861 {
1862 if (sc->function)
Greg Clayton81c22f62011-10-19 18:09:39 +00001863 s.Printf("function{0x%8.8llx}", sc->function->GetID());
Greg Clayton1b654882010-09-19 02:33:57 +00001864 else
1865 s.Printf("symbol[%u]", sc->symbol->GetID());
1866
1867 var_success = true;
1868 }
1869 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1870 {
1871 if (sc->function)
1872 cstr = sc->function->GetName().AsCString (NULL);
1873 else if (sc->symbol)
1874 cstr = sc->symbol->GetName().AsCString (NULL);
1875 if (cstr)
1876 {
1877 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001878
1879 if (sc->block)
1880 {
1881 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1882 if (inline_block)
1883 {
1884 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1885 if (inline_info)
1886 {
1887 s.PutCString(" [inlined] ");
1888 inline_info->GetName().Dump(&s);
1889 }
1890 }
1891 }
Greg Clayton1b654882010-09-19 02:33:57 +00001892 var_success = true;
1893 }
1894 }
Greg Clayton6d3dbf52012-01-13 08:39:16 +00001895 else if (::strncmp (var_name_begin, "name-with-args}", strlen("name-with-args}")) == 0)
1896 {
1897 // Print the function name with arguments in it
1898
1899 if (sc->function)
1900 {
1901 var_success = true;
1902 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
1903 cstr = sc->function->GetName().AsCString (NULL);
1904 if (cstr)
1905 {
1906 const InlineFunctionInfo *inline_info = NULL;
1907 VariableListSP variable_list_sp;
1908 bool get_function_vars = true;
1909 if (sc->block)
1910 {
1911 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1912
1913 if (inline_block)
1914 {
1915 get_function_vars = false;
1916 inline_info = sc->block->GetInlinedFunctionInfo();
1917 if (inline_info)
1918 variable_list_sp = inline_block->GetBlockVariableList (true);
1919 }
1920 }
1921
1922 if (get_function_vars)
1923 {
1924 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
1925 }
1926
1927 if (inline_info)
1928 {
1929 s.PutCString (cstr);
1930 s.PutCString (" [inlined] ");
1931 cstr = inline_info->GetName().GetCString();
1932 }
1933
1934 VariableList args;
1935 if (variable_list_sp)
1936 {
1937 const size_t num_variables = variable_list_sp->GetSize();
1938 for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
1939 {
1940 VariableSP var_sp (variable_list_sp->GetVariableAtIndex(var_idx));
1941 if (var_sp->GetScope() == eValueTypeVariableArgument)
1942 args.AddVariable (var_sp);
1943 }
1944
1945 }
1946 if (args.GetSize() > 0)
1947 {
1948 const char *open_paren = strchr (cstr, '(');
1949 const char *close_paren = NULL;
1950 if (open_paren)
1951 close_paren = strchr (open_paren, ')');
1952
1953 if (open_paren)
1954 s.Write(cstr, open_paren - cstr + 1);
1955 else
1956 {
1957 s.PutCString (cstr);
1958 s.PutChar ('(');
1959 }
1960 const size_t num_args = variable_list_sp->GetSize();
1961 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
1962 {
1963 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
1964 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
1965 const char *var_name = var_value_sp->GetName().GetCString();
1966 const char *var_value = var_value_sp->GetValueAsCString();
1967 if (var_value_sp->GetError().Success())
1968 {
1969 if (arg_idx > 0)
1970 s.PutCString (", ");
1971 s.Printf ("%s=%s", var_name, var_value);
1972 }
1973 }
1974
1975 if (close_paren)
1976 s.PutCString (close_paren);
1977 else
1978 s.PutChar(')');
1979
1980 }
1981 else
1982 {
1983 s.PutCString(cstr);
1984 }
1985 }
1986 }
1987 else if (sc->symbol)
1988 {
1989 cstr = sc->symbol->GetName().AsCString (NULL);
1990 if (cstr)
1991 {
1992 s.PutCString(cstr);
1993 var_success = true;
1994 }
1995 }
1996 }
Greg Clayton1b654882010-09-19 02:33:57 +00001997 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1998 {
1999 var_success = addr != NULL;
2000 if (var_success)
2001 {
2002 format_addr = *addr;
2003 calculate_format_addr_function_offset = true;
2004 }
2005 }
2006 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
2007 {
2008 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
2009 if (var_success)
2010 {
2011 format_addr = sc->line_entry.range.GetBaseAddress();
2012 calculate_format_addr_function_offset = true;
2013 }
2014 }
2015 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
2016 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002017 StackFrame *frame = exe_ctx->GetFramePtr();
2018 var_success = frame != NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00002019 if (var_success)
2020 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002021 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002022 calculate_format_addr_function_offset = true;
2023 }
2024 }
2025 }
2026 }
2027 break;
2028
2029 case 'l':
2030 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
2031 {
2032 if (sc && sc->line_entry.IsValid())
2033 {
2034 var_name_begin += ::strlen ("line.");
2035 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
2036 {
2037 var_name_begin += ::strlen ("file.");
2038
2039 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
2040 {
2041 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
2042 var_success = format_file_spec;
2043 }
2044 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
2045 {
2046 format_file_spec = sc->line_entry.file;
2047 var_success = format_file_spec;
2048 }
2049 }
2050 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
2051 {
2052 var_success = true;
2053 s.Printf("%u", sc->line_entry.line);
2054 }
2055 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
2056 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
2057 {
2058 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
2059 if (var_success)
2060 {
2061 format_addr = sc->line_entry.range.GetBaseAddress();
2062 if (var_name_begin[0] == 'e')
2063 format_addr.Slide (sc->line_entry.range.GetByteSize());
2064 }
2065 }
2066 }
2067 }
2068 break;
2069 }
2070
2071 if (var_success)
2072 {
2073 // If format addr is valid, then we need to print an address
2074 if (reg_num != LLDB_INVALID_REGNUM)
2075 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002076 StackFrame *frame = exe_ctx->GetFramePtr();
Greg Clayton1b654882010-09-19 02:33:57 +00002077 // We have a register value to display...
2078 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
2079 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002080 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002081 }
2082 else
2083 {
2084 if (reg_ctx == NULL)
Greg Claytonc14ee322011-09-22 04:58:26 +00002085 reg_ctx = frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00002086
2087 if (reg_ctx)
2088 {
2089 if (reg_kind != kNumRegisterKinds)
2090 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
2091 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
2092 var_success = reg_info != NULL;
2093 }
2094 }
2095 }
2096
2097 if (reg_info != NULL)
2098 {
Greg Clayton7349bd92011-05-09 20:18:18 +00002099 RegisterValue reg_value;
2100 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
2101 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00002102 {
Greg Clayton9a8fa912011-05-15 04:12:07 +00002103 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
Greg Clayton1b654882010-09-19 02:33:57 +00002104 }
2105 }
2106
2107 if (format_file_spec)
2108 {
2109 s << format_file_spec;
2110 }
2111
2112 // If format addr is valid, then we need to print an address
2113 if (format_addr.IsValid())
2114 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002115 var_success = false;
2116
Greg Clayton1b654882010-09-19 02:33:57 +00002117 if (calculate_format_addr_function_offset)
2118 {
2119 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00002120
Greg Clayton0603aa92010-10-04 01:05:56 +00002121 if (sc)
2122 {
2123 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00002124 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002125 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00002126 if (sc->block)
2127 {
2128 // Check to make sure we aren't in an inline
2129 // function. If we are, use the inline block
2130 // range that contains "format_addr" since
2131 // blocks can be discontiguous.
2132 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2133 AddressRange inline_range;
2134 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
2135 func_addr = inline_range.GetBaseAddress();
2136 }
2137 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002138 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
2139 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
2140 }
2141
2142 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00002143 {
2144 if (func_addr.GetSection() == format_addr.GetSection())
2145 {
2146 addr_t func_file_addr = func_addr.GetFileAddress();
2147 addr_t addr_file_addr = format_addr.GetFileAddress();
2148 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002149 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00002150 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002151 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002152 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00002153 }
2154 else
Greg Clayton0603aa92010-10-04 01:05:56 +00002155 {
2156 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2157 if (target)
2158 {
2159 addr_t func_load_addr = func_addr.GetLoadAddress (target);
2160 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
2161 if (addr_load_addr > func_load_addr)
2162 s.Printf(" + %llu", addr_load_addr - func_load_addr);
2163 else if (addr_load_addr < func_load_addr)
2164 s.Printf(" - %llu", func_load_addr - addr_load_addr);
2165 var_success = true;
2166 }
2167 }
Greg Clayton1b654882010-09-19 02:33:57 +00002168 }
2169 }
2170 else
2171 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002172 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00002173 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00002174 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
2175 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00002176 if (vaddr == LLDB_INVALID_ADDRESS)
2177 vaddr = format_addr.GetFileAddress ();
2178
2179 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00002180 {
Greg Clayton514487e2011-02-15 21:59:32 +00002181 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00002182 if (addr_width == 0)
2183 addr_width = 16;
2184 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002185 var_success = true;
2186 }
Greg Clayton1b654882010-09-19 02:33:57 +00002187 }
2188 }
2189 }
2190
2191 if (var_success == false)
2192 success = false;
2193 }
2194 p = var_name_end;
2195 }
2196 else
2197 break;
2198 }
2199 else
2200 {
2201 // We got a dollar sign with no '{' after it, it must just be a dollar sign
2202 s.PutChar(*p);
2203 }
2204 }
2205 else if (*p == '\\')
2206 {
2207 ++p; // skip the slash
2208 switch (*p)
2209 {
2210 case 'a': s.PutChar ('\a'); break;
2211 case 'b': s.PutChar ('\b'); break;
2212 case 'f': s.PutChar ('\f'); break;
2213 case 'n': s.PutChar ('\n'); break;
2214 case 'r': s.PutChar ('\r'); break;
2215 case 't': s.PutChar ('\t'); break;
2216 case 'v': s.PutChar ('\v'); break;
2217 case '\'': s.PutChar ('\''); break;
2218 case '\\': s.PutChar ('\\'); break;
2219 case '0':
2220 // 1 to 3 octal chars
2221 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002222 // Make a string that can hold onto the initial zero char,
2223 // up to 3 octal digits, and a terminating NULL.
2224 char oct_str[5] = { 0, 0, 0, 0, 0 };
2225
2226 int i;
2227 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
2228 oct_str[i] = p[i];
2229
2230 // We don't want to consume the last octal character since
2231 // the main for loop will do this for us, so we advance p by
2232 // one less than i (even if i is zero)
2233 p += i - 1;
2234 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2235 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002236 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002237 char octal_char = octal_value;
2238 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00002239 }
Greg Clayton1b654882010-09-19 02:33:57 +00002240 }
2241 break;
2242
2243 case 'x':
2244 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00002245 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002246 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002247 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00002248
Greg Clayton0603aa92010-10-04 01:05:56 +00002249 // Make a string that can hold onto two hex chars plus a
2250 // NULL terminator
2251 char hex_str[3] = { 0,0,0 };
2252 hex_str[0] = *p;
2253 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002254 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002255 ++p; // Skip the first of the two hex chars
2256 hex_str[1] = *p;
2257 }
2258
2259 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2260 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002261 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00002262 }
2263 else
2264 {
2265 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00002266 }
2267 break;
2268
2269 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00002270 // Just desensitize any other character by just printing what
2271 // came after the '\'
2272 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00002273 break;
2274
2275 }
2276
2277 }
2278 }
2279 if (end)
2280 *end = p;
2281 return success;
2282}
2283
2284#pragma mark Debugger::SettingsController
2285
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002286//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002287// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002288//--------------------------------------------------
2289
Greg Clayton1b654882010-09-19 02:33:57 +00002290Debugger::SettingsController::SettingsController () :
Greg Clayton4d122c42011-09-17 08:33:22 +00002291 UserSettingsController ("", UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002292{
Caroline Tice91123da2010-09-08 17:48:55 +00002293 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
2294 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002295}
2296
Greg Clayton1b654882010-09-19 02:33:57 +00002297Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002298{
2299}
2300
2301
Greg Clayton4d122c42011-09-17 08:33:22 +00002302InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00002303Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002304{
Greg Claytondbe54502010-11-19 03:46:01 +00002305 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00002306 false, instance_name);
Greg Clayton4d122c42011-09-17 08:33:22 +00002307 InstanceSettingsSP new_settings_sp (new_settings);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002308 return new_settings_sp;
2309}
2310
Greg Clayton1b654882010-09-19 02:33:57 +00002311#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002312//--------------------------------------------------
2313// class DebuggerInstanceSettings
2314//--------------------------------------------------
2315
Greg Claytona7015092010-09-18 01:14:36 +00002316DebuggerInstanceSettings::DebuggerInstanceSettings
2317(
2318 UserSettingsController &owner,
2319 bool live_instance,
2320 const char *name
2321) :
Greg Clayton85851dd2010-12-04 00:10:17 +00002322 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00002323 m_term_width (80),
Greg Claytone372b982011-11-21 21:44:34 +00002324 m_stop_source_before_count (3),
2325 m_stop_source_after_count (3),
2326 m_stop_disassembly_count (4),
2327 m_stop_disassembly_display (eStopDisassemblyTypeNoSource),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002328 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00002329 m_frame_format (),
2330 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002331 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002332 m_use_external_editor (false),
2333 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002334{
Caroline Ticef20e8232010-09-09 18:26:37 +00002335 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2336 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
2337 // 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 +00002338 // The same is true of CreateInstanceName().
2339
2340 if (GetInstanceName() == InstanceSettings::InvalidName())
2341 {
2342 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
2343 m_owner.RegisterInstanceSettings (this);
2344 }
Caroline Ticef20e8232010-09-09 18:26:37 +00002345
2346 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002347 {
Greg Clayton4d122c42011-09-17 08:33:22 +00002348 const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002349 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002350 }
2351}
2352
2353DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00002354 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002355 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00002356 m_frame_format (rhs.m_frame_format),
2357 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002358 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002359 m_use_external_editor (rhs.m_use_external_editor),
2360 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002361{
Greg Clayton4d122c42011-09-17 08:33:22 +00002362 const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002363 CopyInstanceSettings (pending_settings, false);
2364 m_owner.RemovePendingSettings (m_instance_name);
2365}
2366
2367DebuggerInstanceSettings::~DebuggerInstanceSettings ()
2368{
2369}
2370
2371DebuggerInstanceSettings&
2372DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
2373{
2374 if (this != &rhs)
2375 {
Greg Clayton1b654882010-09-19 02:33:57 +00002376 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002377 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00002378 m_frame_format = rhs.m_frame_format;
2379 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002380 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002381 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002382 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002383 }
2384
2385 return *this;
2386}
2387
Greg Clayton1b654882010-09-19 02:33:57 +00002388bool
2389DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
2390{
2391 bool valid = false;
2392
2393 // Verify we have a value string.
2394 if (value == NULL || value[0] == '\0')
2395 {
Greg Clayton86edbf42011-10-26 00:56:27 +00002396 err.SetErrorString ("missing value, can't set terminal width without a value");
Greg Clayton1b654882010-09-19 02:33:57 +00002397 }
2398 else
2399 {
2400 char *end = NULL;
2401 const uint32_t width = ::strtoul (value, &end, 0);
2402
Johnny Chenea9fc182010-09-20 16:36:43 +00002403 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00002404 {
Johnny Chen433d7742010-09-20 17:04:41 +00002405 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00002406 valid = true;
2407 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002408 err.SetErrorString ("invalid term-width value; value must be between 10 and 1024");
Greg Clayton1b654882010-09-19 02:33:57 +00002409 }
2410 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002411 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value);
Greg Clayton1b654882010-09-19 02:33:57 +00002412 }
2413
2414 return valid;
2415}
2416
2417
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002418void
2419DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2420 const char *index_value,
2421 const char *value,
2422 const ConstString &instance_name,
2423 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00002424 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002425 Error &err,
2426 bool pending)
2427{
Greg Clayton0603aa92010-10-04 01:05:56 +00002428
2429 if (var_name == TermWidthVarName())
2430 {
2431 if (ValidTermWidthValue (value, err))
2432 {
2433 m_term_width = ::strtoul (value, NULL, 0);
2434 }
2435 }
2436 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002437 {
Caroline Tice101c7c22010-09-09 06:25:08 +00002438 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002439 if (!pending)
2440 {
Caroline Tice49e27372010-09-07 18:35:40 +00002441 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2442 // strip off the brackets before passing it to BroadcastPromptChange.
2443
2444 std::string tmp_instance_name (instance_name.AsCString());
2445 if ((tmp_instance_name[0] == '[')
2446 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
2447 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
2448 ConstString new_name (tmp_instance_name.c_str());
2449
2450 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002451 }
2452 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002453 else if (var_name == GetFrameFormatName())
2454 {
2455 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
2456 }
2457 else if (var_name == GetThreadFormatName())
2458 {
2459 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
2460 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002461 else if (var_name == ScriptLangVarName())
2462 {
2463 bool success;
2464 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
2465 &success);
2466 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002467 else if (var_name == UseExternalEditorVarName ())
2468 {
Greg Clayton385aa282011-04-22 03:55:06 +00002469 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00002470 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002471 else if (var_name == AutoConfirmName ())
2472 {
Greg Clayton385aa282011-04-22 03:55:06 +00002473 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00002474 }
Greg Claytone372b982011-11-21 21:44:34 +00002475 else if (var_name == StopSourceContextBeforeName ())
2476 {
2477 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2478 if (new_value != UINT32_MAX)
2479 m_stop_source_before_count = new_value;
2480 else
2481 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextAfterName ().GetCString());
2482 }
2483 else if (var_name == StopSourceContextAfterName ())
2484 {
2485 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2486 if (new_value != UINT32_MAX)
2487 m_stop_source_after_count = new_value;
2488 else
2489 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextBeforeName ().GetCString());
2490 }
2491 else if (var_name == StopDisassemblyCountName ())
2492 {
2493 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2494 if (new_value != UINT32_MAX)
2495 m_stop_disassembly_count = new_value;
2496 else
2497 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopDisassemblyCountName ().GetCString());
2498 }
2499 else if (var_name == StopDisassemblyDisplayName ())
2500 {
2501 int new_value;
2502 UserSettingsController::UpdateEnumVariable (g_show_disassembly_enum_values, &new_value, value, err);
2503 if (err.Success())
2504 m_stop_disassembly_display = (StopDisassemblyType)new_value;
2505 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002506}
2507
Caroline Tice12cecd72010-09-20 21:37:42 +00002508bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002509DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2510 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00002511 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00002512 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002513{
2514 if (var_name == PromptVarName())
2515 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002516 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002517
2518 }
2519 else if (var_name == ScriptLangVarName())
2520 {
2521 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
2522 }
Caroline Tice101c7c22010-09-09 06:25:08 +00002523 else if (var_name == TermWidthVarName())
2524 {
2525 StreamString width_str;
Greg Claytone372b982011-11-21 21:44:34 +00002526 width_str.Printf ("%u", m_term_width);
Caroline Tice101c7c22010-09-09 06:25:08 +00002527 value.AppendString (width_str.GetData());
2528 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002529 else if (var_name == GetFrameFormatName ())
2530 {
2531 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
2532 }
2533 else if (var_name == GetThreadFormatName ())
2534 {
2535 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
2536 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002537 else if (var_name == UseExternalEditorVarName())
2538 {
2539 if (m_use_external_editor)
2540 value.AppendString ("true");
2541 else
2542 value.AppendString ("false");
2543 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002544 else if (var_name == AutoConfirmName())
2545 {
2546 if (m_auto_confirm_on)
2547 value.AppendString ("true");
2548 else
2549 value.AppendString ("false");
2550 }
Greg Claytone372b982011-11-21 21:44:34 +00002551 else if (var_name == StopSourceContextAfterName ())
2552 {
2553 StreamString strm;
2554 strm.Printf ("%u", m_stop_source_before_count);
2555 value.AppendString (strm.GetData());
2556 }
2557 else if (var_name == StopSourceContextBeforeName ())
2558 {
2559 StreamString strm;
2560 strm.Printf ("%u", m_stop_source_after_count);
2561 value.AppendString (strm.GetData());
2562 }
2563 else if (var_name == StopDisassemblyCountName ())
2564 {
2565 StreamString strm;
2566 strm.Printf ("%u", m_stop_disassembly_count);
2567 value.AppendString (strm.GetData());
2568 }
2569 else if (var_name == StopDisassemblyDisplayName ())
2570 {
2571 if (m_stop_disassembly_display >= eStopDisassemblyTypeNever && m_stop_disassembly_display <= eStopDisassemblyTypeAlways)
2572 value.AppendString (g_show_disassembly_enum_values[m_stop_disassembly_display].string_value);
2573 else
2574 value.AppendString ("<invalid>");
2575 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002576 else
Caroline Tice12cecd72010-09-20 21:37:42 +00002577 {
2578 if (err)
2579 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2580 return false;
2581 }
2582 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002583}
2584
2585void
Greg Clayton4d122c42011-09-17 08:33:22 +00002586DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002587 bool pending)
2588{
2589 if (new_settings.get() == NULL)
2590 return;
2591
2592 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
2593
2594 m_prompt = new_debugger_settings->m_prompt;
2595 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00002596 {
2597 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2598 // strip off the brackets before passing it to BroadcastPromptChange.
2599
2600 std::string tmp_instance_name (m_instance_name.AsCString());
2601 if ((tmp_instance_name[0] == '[')
2602 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
2603 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
2604 ConstString new_name (tmp_instance_name.c_str());
2605
2606 BroadcastPromptChange (new_name, m_prompt.c_str());
2607 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002608 m_frame_format = new_debugger_settings->m_frame_format;
2609 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002610 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002611 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002612 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002613 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002614}
2615
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002616
2617bool
2618DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
2619{
2620 std::string tmp_prompt;
2621
2622 if (new_prompt != NULL)
2623 {
2624 tmp_prompt = new_prompt ;
2625 int len = tmp_prompt.size();
2626 if (len > 1
2627 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
2628 && (tmp_prompt[len-1] == tmp_prompt[0]))
2629 {
2630 tmp_prompt = tmp_prompt.substr(1,len-2);
2631 }
2632 len = tmp_prompt.size();
2633 if (tmp_prompt[len-1] != ' ')
2634 tmp_prompt.append(" ");
2635 }
2636 EventSP new_event_sp;
2637 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
2638 new EventDataBytes (tmp_prompt.c_str())));
2639
2640 if (instance_name.GetLength() != 0)
2641 {
2642 // Set prompt for a particular instance.
2643 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
2644 if (dbg != NULL)
2645 {
2646 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
2647 }
2648 }
2649
2650 return true;
2651}
2652
2653const ConstString
2654DebuggerInstanceSettings::CreateInstanceName ()
2655{
2656 static int instance_count = 1;
2657 StreamString sstr;
2658
2659 sstr.Printf ("debugger_%d", instance_count);
2660 ++instance_count;
2661
2662 const ConstString ret_val (sstr.GetData());
2663
2664 return ret_val;
2665}
2666
Jim Ingham3bcdb292010-10-04 22:44:14 +00002667
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002668//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002669// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002670//--------------------------------------------------
2671
2672
2673SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002674Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002675{
2676 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00002677 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
2678 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002679 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
2680};
2681
Greg Claytonbb562b12010-10-04 02:44:26 +00002682#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00002683#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002684
Greg Clayton0603aa92010-10-04 01:05:56 +00002685#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2686 "{, ${frame.pc}}"\
2687 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00002688 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00002689 "{, stop reason = ${thread.stop-reason}}"\
Jim Inghamef651602011-12-22 19:12:40 +00002690 "{\\nReturn value: ${thread.return-value}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00002691 "\\n"
2692
Greg Clayton315d2ca2010-11-02 01:53:21 +00002693//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2694// "{, ${frame.pc}}"\
2695// MODULE_WITH_FUNC\
2696// FILE_AND_LINE\
2697// "{, stop reason = ${thread.stop-reason}}"\
2698// "{, name = ${thread.name}}"\
2699// "{, queue = ${thread.queue}}"\
2700// "\\n"
2701
Greg Clayton0603aa92010-10-04 01:05:56 +00002702#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
2703 MODULE_WITH_FUNC\
2704 FILE_AND_LINE\
2705 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002706
2707SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002708Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002709{
Greg Clayton0603aa92010-10-04 01:05:56 +00002710// NAME Setting variable type Default Enum Init'd Hidden Help
2711// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00002712{ "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 +00002713{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00002714{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
2715{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002716{ "thread-format", eSetVarTypeString, DEFAULT_THREAD_FORMAT, NULL, false, false, "The default thread format string to use when displaying thread information." },
Greg Claytone372b982011-11-21 21:44:34 +00002717{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
2718{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
2719{ "stop-line-count-before",eSetVarTypeInt, "3", NULL, false, false, "The number of sources lines to display that come before the current source line when displaying a stopped context." },
2720{ "stop-line-count-after", eSetVarTypeInt, "3", NULL, false, false, "The number of sources lines to display that come after the current source line when displaying a stopped context." },
2721{ "stop-disassembly-count", eSetVarTypeInt, "0", NULL, false, false, "The number of disassembly lines to show when displaying a stopped context." },
2722{ "stop-disassembly-display", eSetVarTypeEnum, "no-source", g_show_disassembly_enum_values, false, false, "Control when to display disassembly when displaying a stopped context." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002723{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002724};