blob: 060e579eadc1977740634647519e5f198fd3344b [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{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000159 static UserSettingsControllerSP g_settings_controller_sp;
160 if (!g_settings_controller_sp)
161 {
162 g_settings_controller_sp.reset (new Debugger::SettingsController);
163
164 // The first shared pointer to Debugger::SettingsController in
165 // g_settings_controller_sp must be fully created above so that
166 // the DebuggerInstanceSettings can use a weak_ptr to refer back
167 // to the master setttings controller
168 InstanceSettingsSP default_instance_settings_sp (new DebuggerInstanceSettings (g_settings_controller_sp,
169 false,
170 InstanceSettings::GetDefaultName().AsCString()));
171 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
172 }
173 return g_settings_controller_sp;
Greg Clayton99d0faf2010-11-18 23:32:35 +0000174}
175
Caroline Tice2f88aad2011-01-14 00:29:16 +0000176int
177Debugger::TestDebuggerRefCount ()
178{
179 return g_shared_debugger_refcount;
180}
181
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182void
183Debugger::Initialize ()
184{
Greg Clayton66111032010-06-23 01:19:29 +0000185 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +0000186 {
Greg Claytondbe54502010-11-19 03:46:01 +0000187 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000188 }
Greg Clayton66111032010-06-23 01:19:29 +0000189 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +0000190
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191}
192
193void
194Debugger::Terminate ()
195{
Greg Clayton66111032010-06-23 01:19:29 +0000196 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197 {
Greg Clayton66111032010-06-23 01:19:29 +0000198 g_shared_debugger_refcount--;
199 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200 {
Greg Claytondbe54502010-11-19 03:46:01 +0000201 lldb_private::WillTerminate();
202 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000203
204 // Clear our master list of debugger objects
205 Mutex::Locker locker (GetDebuggerListMutex ());
206 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208 }
209}
210
Caroline Tice20bd37f2011-03-10 22:14:10 +0000211void
212Debugger::SettingsInitialize ()
213{
214 static bool g_initialized = false;
215
216 if (!g_initialized)
217 {
218 g_initialized = true;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000219 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Caroline Tice20bd37f2011-03-10 22:14:10 +0000220 SettingsController::global_settings_table,
221 SettingsController::instance_settings_table);
222 // Now call SettingsInitialize for each settings 'child' of Debugger
223 Target::SettingsInitialize ();
224 }
225}
226
227void
228Debugger::SettingsTerminate ()
229{
230
231 // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
232 // Settings.
233
234 Target::SettingsTerminate ();
235
236 // Now terminate the Debugger Settings.
237
238 UserSettingsControllerSP &usc = GetSettingsController();
239 UserSettingsController::FinalizeSettingsController (usc);
240 usc.reset();
241}
242
Greg Clayton66111032010-06-23 01:19:29 +0000243DebuggerSP
244Debugger::CreateInstance ()
245{
246 DebuggerSP debugger_sp (new Debugger);
247 // Scope for locker
248 {
249 Mutex::Locker locker (GetDebuggerListMutex ());
250 GetDebuggerList().push_back(debugger_sp);
251 }
252 return debugger_sp;
253}
254
Caroline Ticee02657b2011-01-22 01:02:07 +0000255void
Greg Clayton4d122c42011-09-17 08:33:22 +0000256Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000257{
258 if (debugger_sp.get() == NULL)
259 return;
260
Jim Ingham8314c522011-09-15 21:36:42 +0000261 debugger_sp->Clear();
262
Caroline Ticee02657b2011-01-22 01:02:07 +0000263 Mutex::Locker locker (GetDebuggerListMutex ());
264 DebuggerList &debugger_list = GetDebuggerList ();
265 DebuggerList::iterator pos, end = debugger_list.end();
266 for (pos = debugger_list.begin (); pos != end; ++pos)
267 {
268 if ((*pos).get() == debugger_sp.get())
269 {
270 debugger_list.erase (pos);
271 return;
272 }
273 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000274}
275
Greg Clayton4d122c42011-09-17 08:33:22 +0000276DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000277Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
278{
Greg Clayton4d122c42011-09-17 08:33:22 +0000279 DebuggerSP debugger_sp;
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000280
281 Mutex::Locker locker (GetDebuggerListMutex ());
282 DebuggerList &debugger_list = GetDebuggerList();
283 DebuggerList::iterator pos, end = debugger_list.end();
284
285 for (pos = debugger_list.begin(); pos != end; ++pos)
286 {
287 if ((*pos).get()->m_instance_name == instance_name)
288 {
289 debugger_sp = *pos;
290 break;
291 }
292 }
293 return debugger_sp;
294}
Greg Clayton66111032010-06-23 01:19:29 +0000295
296TargetSP
297Debugger::FindTargetWithProcessID (lldb::pid_t pid)
298{
Greg Clayton4d122c42011-09-17 08:33:22 +0000299 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000300 Mutex::Locker locker (GetDebuggerListMutex ());
301 DebuggerList &debugger_list = GetDebuggerList();
302 DebuggerList::iterator pos, end = debugger_list.end();
303 for (pos = debugger_list.begin(); pos != end; ++pos)
304 {
305 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
306 if (target_sp)
307 break;
308 }
309 return target_sp;
310}
311
Greg Claytone4e45922011-11-16 05:37:56 +0000312TargetSP
313Debugger::FindTargetWithProcess (Process *process)
314{
315 TargetSP target_sp;
316 Mutex::Locker locker (GetDebuggerListMutex ());
317 DebuggerList &debugger_list = GetDebuggerList();
318 DebuggerList::iterator pos, end = debugger_list.end();
319 for (pos = debugger_list.begin(); pos != end; ++pos)
320 {
321 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
322 if (target_sp)
323 break;
324 }
325 return target_sp;
326}
327
Greg Clayton66111032010-06-23 01:19:29 +0000328
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000330 UserID (g_unique_id++),
Greg Claytonb9556ac2012-01-30 07:41:31 +0000331 DebuggerInstanceSettings (GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000332 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333 m_input_file (),
334 m_output_file (),
335 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336 m_target_list (),
Greg Claytonded470d2011-03-19 01:12:21 +0000337 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000338 m_listener ("lldb.Debugger"),
Jim Inghame37d6052011-09-13 00:29:56 +0000339 m_source_manager(*this),
340 m_source_file_cache(),
Greg Clayton66111032010-06-23 01:19:29 +0000341 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000342 m_input_reader_stack (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000343 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344{
Greg Clayton66111032010-06-23 01:19:29 +0000345 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000346 // Always add our default platform to the platform list
347 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
348 assert (default_platform_sp.get());
349 m_platform_list.Append (default_platform_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000350}
351
352Debugger::~Debugger ()
353{
Jim Ingham8314c522011-09-15 21:36:42 +0000354 Clear();
355}
356
357void
358Debugger::Clear()
359{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000360 CleanUpInputReaders();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000361 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000362 int num_targets = m_target_list.GetNumTargets();
363 for (int i = 0; i < num_targets; i++)
364 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000365 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
366 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000367 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000368 ProcessSP process_sp (target_sp->GetProcessSP());
369 if (process_sp)
370 {
371 if (process_sp->GetShouldDetach())
372 process_sp->Detach();
373 }
374 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000375 }
Greg Clayton66111032010-06-23 01:19:29 +0000376 }
377 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378
Jim Ingham8314c522011-09-15 21:36:42 +0000379}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380
381bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000382Debugger::GetCloseInputOnEOF () const
383{
384 return m_input_comm.GetCloseOnEOF();
385}
386
387void
388Debugger::SetCloseInputOnEOF (bool b)
389{
390 m_input_comm.SetCloseOnEOF(b);
391}
392
393bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394Debugger::GetAsyncExecution ()
395{
Greg Clayton66111032010-06-23 01:19:29 +0000396 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397}
398
399void
400Debugger::SetAsyncExecution (bool async_execution)
401{
Greg Clayton66111032010-06-23 01:19:29 +0000402 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403}
404
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405
406void
407Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
408{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000409 File &in_file = GetInputFile();
410 in_file.SetStream (fh, tranfer_ownership);
411 if (in_file.IsValid() == false)
412 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413
414 // Disconnect from any old connection if we had one
415 m_input_comm.Disconnect ();
Greg Clayton32720b52012-01-14 20:47:38 +0000416 // Pass false as the second argument to ConnectionFileDescriptor below because
417 // our "in_file" above will already take ownership if requested and we don't
418 // want to objects trying to own and close a file descriptor.
419 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
421
422 Error error;
423 if (m_input_comm.StartReadThread (&error) == false)
424 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000425 File &err_file = GetErrorFile();
426
427 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
428 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430}
431
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432void
433Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
434{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000435 File &out_file = GetOutputFile();
436 out_file.SetStream (fh, tranfer_ownership);
437 if (out_file.IsValid() == false)
438 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000439
440 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441}
442
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443void
444Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
445{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000446 File &err_file = GetErrorFile();
447 err_file.SetStream (fh, tranfer_ownership);
448 if (err_file.IsValid() == false)
449 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450}
451
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000453Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454{
455 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000456 TargetSP target_sp(GetSelectedTarget());
457 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458
459 if (target_sp)
460 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000461 ProcessSP process_sp (target_sp->GetProcessSP());
462 exe_ctx.SetProcessSP (process_sp);
463 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000465 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
466 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000468 exe_ctx.SetThreadSP (thread_sp);
469 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
470 if (exe_ctx.GetFramePtr() == NULL)
471 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 }
473 }
474 }
475 return exe_ctx;
476
477}
478
Caroline Ticeb44880c2011-02-10 01:15:13 +0000479InputReaderSP
480Debugger::GetCurrentInputReader ()
481{
482 InputReaderSP reader_sp;
483
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000484 if (!m_input_reader_stack.IsEmpty())
Caroline Ticeb44880c2011-02-10 01:15:13 +0000485 {
486 // Clear any finished readers from the stack
487 while (CheckIfTopInputReaderIsDone()) ;
488
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000489 if (!m_input_reader_stack.IsEmpty())
490 reader_sp = m_input_reader_stack.Top();
Caroline Ticeb44880c2011-02-10 01:15:13 +0000491 }
492
493 return reader_sp;
494}
495
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496void
497Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
498{
Caroline Ticeefed6132010-11-19 20:47:54 +0000499 if (bytes_len > 0)
500 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
501 else
502 ((Debugger *)baton)->DispatchInputEndOfFile ();
503}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504
505
506void
507Debugger::DispatchInput (const char *bytes, size_t bytes_len)
508{
Caroline Ticeefed6132010-11-19 20:47:54 +0000509 if (bytes == NULL || bytes_len == 0)
510 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511
512 WriteToDefaultReader (bytes, bytes_len);
513}
514
515void
Caroline Ticeefed6132010-11-19 20:47:54 +0000516Debugger::DispatchInputInterrupt ()
517{
518 m_input_reader_data.clear();
519
Caroline Ticeb44880c2011-02-10 01:15:13 +0000520 InputReaderSP reader_sp (GetCurrentInputReader ());
521 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000522 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000523 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000524
Caroline Ticeb44880c2011-02-10 01:15:13 +0000525 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000526 while (CheckIfTopInputReaderIsDone ()) ;
527 }
528}
529
530void
531Debugger::DispatchInputEndOfFile ()
532{
533 m_input_reader_data.clear();
534
Caroline Ticeb44880c2011-02-10 01:15:13 +0000535 InputReaderSP reader_sp (GetCurrentInputReader ());
536 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000537 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000538 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000539
Caroline Ticeb44880c2011-02-10 01:15:13 +0000540 // 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 +0000541 while (CheckIfTopInputReaderIsDone ()) ;
542 }
543}
544
545void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000546Debugger::CleanUpInputReaders ()
547{
548 m_input_reader_data.clear();
549
Caroline Ticeb44880c2011-02-10 01:15:13 +0000550 // 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 +0000551 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000552 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000553 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000554 if (reader_sp)
555 {
556 reader_sp->Notify (eInputReaderEndOfFile);
557 reader_sp->SetIsDone (true);
558 }
559 }
560}
561
562void
Caroline Tice969ed3d2011-05-02 20:41:46 +0000563Debugger::NotifyTopInputReader (InputReaderAction notification)
564{
565 InputReaderSP reader_sp (GetCurrentInputReader());
566 if (reader_sp)
567 {
568 reader_sp->Notify (notification);
569
570 // Flush out any input readers that are done.
571 while (CheckIfTopInputReaderIsDone ())
572 /* Do nothing. */;
573 }
574}
575
Caroline Tice9088b062011-05-09 23:06:58 +0000576bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000577Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp)
Caroline Tice9088b062011-05-09 23:06:58 +0000578{
Caroline Ticed61c10b2011-06-16 16:27:19 +0000579 InputReaderSP top_reader_sp (GetCurrentInputReader());
Caroline Tice9088b062011-05-09 23:06:58 +0000580
Caroline Ticed61c10b2011-06-16 16:27:19 +0000581 return (reader_sp.get() == top_reader_sp.get());
Caroline Tice9088b062011-05-09 23:06:58 +0000582}
583
584
Caroline Tice969ed3d2011-05-02 20:41:46 +0000585void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
587{
588 if (bytes && bytes_len)
589 m_input_reader_data.append (bytes, bytes_len);
590
591 if (m_input_reader_data.empty())
592 return;
593
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000594 while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000597 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000598 if (!reader_sp)
599 break;
600
Greg Clayton471b31c2010-07-20 22:52:08 +0000601 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000602 m_input_reader_data.size());
603 if (bytes_handled)
604 {
605 m_input_reader_data.erase (0, bytes_handled);
606 }
607 else
608 {
609 // No bytes were handled, we might not have reached our
610 // granularity, just return and wait for more data
611 break;
612 }
613 }
614
Caroline Ticeb44880c2011-02-10 01:15:13 +0000615 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000616 while (CheckIfTopInputReaderIsDone ())
617 /* Do nothing. */;
618
619}
620
621void
622Debugger::PushInputReader (const InputReaderSP& reader_sp)
623{
624 if (!reader_sp)
625 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000626
627 // Deactivate the old top reader
628 InputReaderSP top_reader_sp (GetCurrentInputReader ());
629
630 if (top_reader_sp)
631 top_reader_sp->Notify (eInputReaderDeactivate);
632
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000633 m_input_reader_stack.Push (reader_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000634 reader_sp->Notify (eInputReaderActivate);
635 ActivateInputReader (reader_sp);
636}
637
638bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000639Debugger::PopInputReader (const InputReaderSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640{
641 bool result = false;
642
643 // The reader on the stop of the stack is done, so let the next
644 // read on the stack referesh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000645 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000647 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000648 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649
650 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
651 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000652 m_input_reader_stack.Pop ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653 reader_sp->Notify (eInputReaderDeactivate);
654 reader_sp->Notify (eInputReaderDone);
655 result = true;
656
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000657 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000658 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000659 reader_sp = m_input_reader_stack.Top();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660 if (reader_sp)
661 {
662 ActivateInputReader (reader_sp);
663 reader_sp->Notify (eInputReaderReactivate);
664 }
665 }
666 }
667 }
668 return result;
669}
670
671bool
672Debugger::CheckIfTopInputReaderIsDone ()
673{
674 bool result = false;
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000675 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000677 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000678 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679
680 if (reader_sp && reader_sp->IsDone())
681 {
682 result = true;
683 PopInputReader (reader_sp);
684 }
685 }
686 return result;
687}
688
689void
690Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
691{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000692 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000694 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000696 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000697
698 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000699
Greg Claytona3406612011-02-07 23:24:47 +0000700 switch (reader_sp->GetGranularity())
701 {
702 case eInputReaderGranularityByte:
703 case eInputReaderGranularityWord:
704 tty.SetCanonical (false);
705 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706
Greg Claytona3406612011-02-07 23:24:47 +0000707 case eInputReaderGranularityLine:
708 case eInputReaderGranularityAll:
709 tty.SetCanonical (true);
710 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711
Greg Claytona3406612011-02-07 23:24:47 +0000712 default:
713 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 }
715 }
716}
Greg Clayton66111032010-06-23 01:19:29 +0000717
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000718StreamSP
719Debugger::GetAsyncOutputStream ()
720{
721 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
722 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
723}
724
725StreamSP
726Debugger::GetAsyncErrorStream ()
727{
728 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
729 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
730}
731
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000732DebuggerSP
733Debugger::FindDebuggerWithID (lldb::user_id_t id)
734{
Greg Clayton4d122c42011-09-17 08:33:22 +0000735 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000736
737 Mutex::Locker locker (GetDebuggerListMutex ());
738 DebuggerList &debugger_list = GetDebuggerList();
739 DebuggerList::iterator pos, end = debugger_list.end();
740 for (pos = debugger_list.begin(); pos != end; ++pos)
741 {
742 if ((*pos).get()->GetID() == id)
743 {
744 debugger_sp = *pos;
745 break;
746 }
747 }
748 return debugger_sp;
749}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000750
Greg Clayton1b654882010-09-19 02:33:57 +0000751static void
752TestPromptFormats (StackFrame *frame)
753{
754 if (frame == NULL)
755 return;
756
757 StreamString s;
758 const char *prompt_format =
759 "{addr = '${addr}'\n}"
760 "{process.id = '${process.id}'\n}"
761 "{process.name = '${process.name}'\n}"
762 "{process.file.basename = '${process.file.basename}'\n}"
763 "{process.file.fullpath = '${process.file.fullpath}'\n}"
764 "{thread.id = '${thread.id}'\n}"
765 "{thread.index = '${thread.index}'\n}"
766 "{thread.name = '${thread.name}'\n}"
767 "{thread.queue = '${thread.queue}'\n}"
768 "{thread.stop-reason = '${thread.stop-reason}'\n}"
769 "{target.arch = '${target.arch}'\n}"
770 "{module.file.basename = '${module.file.basename}'\n}"
771 "{module.file.fullpath = '${module.file.fullpath}'\n}"
772 "{file.basename = '${file.basename}'\n}"
773 "{file.fullpath = '${file.fullpath}'\n}"
774 "{frame.index = '${frame.index}'\n}"
775 "{frame.pc = '${frame.pc}'\n}"
776 "{frame.sp = '${frame.sp}'\n}"
777 "{frame.fp = '${frame.fp}'\n}"
778 "{frame.flags = '${frame.flags}'\n}"
779 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
780 "{frame.reg.rip = '${frame.reg.rip}'\n}"
781 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
782 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
783 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
784 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
785 "{frame.reg.carp = '${frame.reg.carp}'\n}"
786 "{function.id = '${function.id}'\n}"
787 "{function.name = '${function.name}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +0000788 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +0000789 "{function.addr-offset = '${function.addr-offset}'\n}"
790 "{function.line-offset = '${function.line-offset}'\n}"
791 "{function.pc-offset = '${function.pc-offset}'\n}"
792 "{line.file.basename = '${line.file.basename}'\n}"
793 "{line.file.fullpath = '${line.file.fullpath}'\n}"
794 "{line.number = '${line.number}'\n}"
795 "{line.start-addr = '${line.start-addr}'\n}"
796 "{line.end-addr = '${line.end-addr}'\n}"
797;
798
799 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
800 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000801 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000802 const char *end = NULL;
803 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
804 {
805 printf("%s\n", s.GetData());
806 }
807 else
808 {
809 printf ("error: at '%s'\n", end);
810 printf ("what we got: %s\n", s.GetData());
811 }
812}
813
Enrico Granata9fc19442011-07-06 02:13:41 +0000814static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000815ScanFormatDescriptor (const char* var_name_begin,
816 const char* var_name_end,
817 const char** var_name_final,
818 const char** percent_position,
Greg Clayton4d122c42011-09-17 08:33:22 +0000819 Format* custom_format,
Enrico Granatadc940732011-08-23 00:32:52 +0000820 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
Enrico Granata9fc19442011-07-06 02:13:41 +0000821{
Enrico Granatae992a082011-07-22 17:03:19 +0000822 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000823 *percent_position = ::strchr(var_name_begin,'%');
Greg Clayton34132752011-07-06 04:07:21 +0000824 if (!*percent_position || *percent_position > var_name_end)
Enrico Granatae992a082011-07-22 17:03:19 +0000825 {
826 if (log)
827 log->Printf("no format descriptor in string, skipping");
Enrico Granata9fc19442011-07-06 02:13:41 +0000828 *var_name_final = var_name_end;
Enrico Granatae992a082011-07-22 17:03:19 +0000829 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000830 else
831 {
832 *var_name_final = *percent_position;
833 char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0';
834 memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1);
Enrico Granatae992a082011-07-22 17:03:19 +0000835 if (log)
836 log->Printf("parsing %s as a format descriptor", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000837 if ( !FormatManager::GetFormatFromCString(format_name,
838 true,
839 *custom_format) )
840 {
Enrico Granatae992a082011-07-22 17:03:19 +0000841 if (log)
842 log->Printf("%s is an unknown format", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000843 // if this is an @ sign, print ObjC description
Greg Clayton34132752011-07-06 04:07:21 +0000844 if (*format_name == '@')
Enrico Granata9fc19442011-07-06 02:13:41 +0000845 *val_obj_display = ValueObject::eDisplayLanguageSpecific;
846 // if this is a V, print the value using the default format
Enrico Granatae992a082011-07-22 17:03:19 +0000847 else if (*format_name == 'V')
Enrico Granata9fc19442011-07-06 02:13:41 +0000848 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatad55546b2011-07-22 00:16:08 +0000849 // if this is an L, print the location of the value
Enrico Granatae992a082011-07-22 17:03:19 +0000850 else if (*format_name == 'L')
Enrico Granataf2bbf712011-07-15 02:26:42 +0000851 *val_obj_display = ValueObject::eDisplayLocation;
Enrico Granatad55546b2011-07-22 00:16:08 +0000852 // if this is an S, print the summary after all
Enrico Granatae992a082011-07-22 17:03:19 +0000853 else if (*format_name == 'S')
Enrico Granatad55546b2011-07-22 00:16:08 +0000854 *val_obj_display = ValueObject::eDisplaySummary;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000855 else if (*format_name == '#')
856 *val_obj_display = ValueObject::eDisplayChildrenCount;
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000857 else if (*format_name == 'T')
858 *val_obj_display = ValueObject::eDisplayType;
Enrico Granatae992a082011-07-22 17:03:19 +0000859 else if (log)
860 log->Printf("%s is an error, leaving the previous value alone", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000861 }
862 // a good custom format tells us to print the value using it
863 else
Enrico Granatae992a082011-07-22 17:03:19 +0000864 {
865 if (log)
866 log->Printf("will display value for this VO");
Enrico Granata9fc19442011-07-06 02:13:41 +0000867 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatae992a082011-07-22 17:03:19 +0000868 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000869 delete format_name;
870 }
Enrico Granatae992a082011-07-22 17:03:19 +0000871 if (log)
872 log->Printf("final format description outcome: custom_format = %d, val_obj_display = %d",
873 *custom_format,
874 *val_obj_display);
Enrico Granata9fc19442011-07-06 02:13:41 +0000875 return true;
876}
877
878static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000879ScanBracketedRange (const char* var_name_begin,
880 const char* var_name_end,
881 const char* var_name_final,
882 const char** open_bracket_position,
883 const char** separator_position,
884 const char** close_bracket_position,
885 const char** var_name_final_if_array_range,
886 int64_t* index_lower,
887 int64_t* index_higher)
Enrico Granata9fc19442011-07-06 02:13:41 +0000888{
Enrico Granatae992a082011-07-22 17:03:19 +0000889 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000890 *open_bracket_position = ::strchr(var_name_begin,'[');
Greg Clayton34132752011-07-06 04:07:21 +0000891 if (*open_bracket_position && *open_bracket_position < var_name_final)
Enrico Granata9fc19442011-07-06 02:13:41 +0000892 {
893 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
894 *close_bracket_position = ::strchr(*open_bracket_position,']');
895 // as usual, we assume that [] will come before %
896 //printf("trying to expand a []\n");
897 *var_name_final_if_array_range = *open_bracket_position;
Greg Clayton34132752011-07-06 04:07:21 +0000898 if (*close_bracket_position - *open_bracket_position == 1)
Enrico Granata9fc19442011-07-06 02:13:41 +0000899 {
Enrico Granatae992a082011-07-22 17:03:19 +0000900 if (log)
901 log->Printf("[] detected.. going from 0 to end of data");
Enrico Granata9fc19442011-07-06 02:13:41 +0000902 *index_lower = 0;
903 }
904 else if (*separator_position == NULL || *separator_position > var_name_end)
905 {
906 char *end = NULL;
907 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
908 *index_higher = *index_lower;
Enrico Granatae992a082011-07-22 17:03:19 +0000909 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000910 log->Printf("[%lld] detected, high index is same", *index_lower);
Enrico Granata9fc19442011-07-06 02:13:41 +0000911 }
Greg Clayton34132752011-07-06 04:07:21 +0000912 else if (*close_bracket_position && *close_bracket_position < var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +0000913 {
914 char *end = NULL;
915 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
916 *index_higher = ::strtoul (*separator_position+1, &end, 0);
Enrico Granatae992a082011-07-22 17:03:19 +0000917 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000918 log->Printf("[%lld-%lld] detected", *index_lower, *index_higher);
Enrico Granata9fc19442011-07-06 02:13:41 +0000919 }
920 else
Enrico Granatae992a082011-07-22 17:03:19 +0000921 {
922 if (log)
923 log->Printf("expression is erroneous, cannot extract indices out of it");
Enrico Granata9fc19442011-07-06 02:13:41 +0000924 return false;
Enrico Granatae992a082011-07-22 17:03:19 +0000925 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000926 if (*index_lower > *index_higher && *index_higher > 0)
927 {
Enrico Granatae992a082011-07-22 17:03:19 +0000928 if (log)
929 log->Printf("swapping indices");
Enrico Granata9fc19442011-07-06 02:13:41 +0000930 int temp = *index_lower;
931 *index_lower = *index_higher;
932 *index_higher = temp;
933 }
934 }
Enrico Granatae992a082011-07-22 17:03:19 +0000935 else if (log)
936 log->Printf("no bracketed range, skipping entirely");
Enrico Granata9fc19442011-07-06 02:13:41 +0000937 return true;
938}
939
940
941static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000942ExpandExpressionPath (ValueObject* valobj,
943 StackFrame* frame,
944 bool* do_deref_pointer,
945 const char* var_name_begin,
946 const char* var_name_final,
947 Error& error)
Enrico Granata9fc19442011-07-06 02:13:41 +0000948{
Enrico Granatae992a082011-07-22 17:03:19 +0000949 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000950 StreamString sstring;
951 VariableSP var_sp;
952
Greg Clayton34132752011-07-06 04:07:21 +0000953 if (*do_deref_pointer)
Enrico Granatae992a082011-07-22 17:03:19 +0000954 {
955 if (log)
956 log->Printf("been told to deref_pointer by caller");
Enrico Granata9fc19442011-07-06 02:13:41 +0000957 sstring.PutChar('*');
Enrico Granatae992a082011-07-22 17:03:19 +0000958 }
Enrico Granatac482a192011-08-17 22:13:59 +0000959 else if (valobj->IsDereferenceOfParent() && ClangASTContext::IsPointerType(valobj->GetParent()->GetClangType()) && !valobj->IsArrayItemForPointer())
Enrico Granata9fc19442011-07-06 02:13:41 +0000960 {
Enrico Granatae992a082011-07-22 17:03:19 +0000961 if (log)
962 log->Printf("decided to deref_pointer myself");
Enrico Granata9fc19442011-07-06 02:13:41 +0000963 sstring.PutChar('*');
964 *do_deref_pointer = true;
965 }
966
Enrico Granatac482a192011-08-17 22:13:59 +0000967 valobj->GetExpressionPath(sstring, true, ValueObject::eHonorPointers);
Enrico Granatae992a082011-07-22 17:03:19 +0000968 if (log)
969 log->Printf("expression path to expand in phase 0: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000970 sstring.PutRawBytes(var_name_begin+3, var_name_final-var_name_begin-3);
Enrico Granatae992a082011-07-22 17:03:19 +0000971 if (log)
972 log->Printf("expression path to expand in phase 1: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000973 std::string name = std::string(sstring.GetData());
974 ValueObjectSP target = frame->GetValueForVariableExpressionPath (name.c_str(),
975 eNoDynamicValues,
976 0,
977 var_sp,
978 error);
979 return target;
980}
981
982static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000983ExpandIndexedExpression (ValueObject* valobj,
984 uint32_t index,
985 StackFrame* frame,
986 bool deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +0000987{
Enrico Granatae992a082011-07-22 17:03:19 +0000988 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000989 const char* ptr_deref_format = "[%d]";
990 std::auto_ptr<char> ptr_deref_buffer(new char[10]);
991 ::sprintf(ptr_deref_buffer.get(), ptr_deref_format, index);
Enrico Granatae992a082011-07-22 17:03:19 +0000992 if (log)
993 log->Printf("name to deref: %s",ptr_deref_buffer.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000994 const char* first_unparsed;
995 ValueObject::GetValueForExpressionPathOptions options;
996 ValueObject::ExpressionPathEndResultType final_value_type;
997 ValueObject::ExpressionPathScanEndReason reason_to_stop;
998 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eDereference : ValueObject::eNothing);
Enrico Granatac482a192011-08-17 22:13:59 +0000999 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001000 &first_unparsed,
1001 &reason_to_stop,
1002 &final_value_type,
1003 options,
1004 &what_next);
1005 if (!item)
1006 {
Enrico Granatae992a082011-07-22 17:03:19 +00001007 if (log)
1008 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1009 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001010 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001011 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001012 else
1013 {
Enrico Granatae992a082011-07-22 17:03:19 +00001014 if (log)
1015 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1016 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001017 first_unparsed, reason_to_stop, final_value_type);
Enrico Granata9fc19442011-07-06 02:13:41 +00001018 }
1019 return item;
1020}
1021
Greg Clayton1b654882010-09-19 02:33:57 +00001022bool
1023Debugger::FormatPrompt
1024(
1025 const char *format,
1026 const SymbolContext *sc,
1027 const ExecutionContext *exe_ctx,
1028 const Address *addr,
1029 Stream &s,
Enrico Granata4becb372011-06-29 22:27:15 +00001030 const char **end,
Enrico Granatac482a192011-08-17 22:13:59 +00001031 ValueObject* valobj
Greg Clayton1b654882010-09-19 02:33:57 +00001032)
1033{
Enrico Granatac482a192011-08-17 22:13:59 +00001034 ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers
Greg Clayton1b654882010-09-19 02:33:57 +00001035 bool success = true;
1036 const char *p;
Enrico Granatae992a082011-07-22 17:03:19 +00001037 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Greg Clayton1b654882010-09-19 02:33:57 +00001038 for (p = format; *p != '\0'; ++p)
1039 {
Enrico Granatac482a192011-08-17 22:13:59 +00001040 if (realvalobj)
Enrico Granata4becb372011-06-29 22:27:15 +00001041 {
Enrico Granatac482a192011-08-17 22:13:59 +00001042 valobj = realvalobj;
1043 realvalobj = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00001044 }
Greg Clayton1b654882010-09-19 02:33:57 +00001045 size_t non_special_chars = ::strcspn (p, "${}\\");
1046 if (non_special_chars > 0)
1047 {
1048 if (success)
1049 s.Write (p, non_special_chars);
1050 p += non_special_chars;
1051 }
1052
1053 if (*p == '\0')
1054 {
1055 break;
1056 }
1057 else if (*p == '{')
1058 {
1059 // Start a new scope that must have everything it needs if it is to
1060 // to make it into the final output stream "s". If you want to make
1061 // a format that only prints out the function or symbol name if there
1062 // is one in the symbol context you can use:
1063 // "{function =${function.name}}"
1064 // The first '{' starts a new scope that end with the matching '}' at
1065 // the end of the string. The contents "function =${function.name}"
1066 // will then be evaluated and only be output if there is a function
1067 // or symbol with a valid name.
1068 StreamString sub_strm;
1069
1070 ++p; // Skip the '{'
1071
Enrico Granatac482a192011-08-17 22:13:59 +00001072 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
Greg Clayton1b654882010-09-19 02:33:57 +00001073 {
1074 // The stream had all it needed
1075 s.Write(sub_strm.GetData(), sub_strm.GetSize());
1076 }
1077 if (*p != '}')
1078 {
1079 success = false;
1080 break;
1081 }
1082 }
1083 else if (*p == '}')
1084 {
1085 // End of a enclosing scope
1086 break;
1087 }
1088 else if (*p == '$')
1089 {
1090 // We have a prompt variable to print
1091 ++p;
1092 if (*p == '{')
1093 {
1094 ++p;
1095 const char *var_name_begin = p;
1096 const char *var_name_end = ::strchr (p, '}');
1097
1098 if (var_name_end && var_name_begin < var_name_end)
1099 {
1100 // if we have already failed to parse, skip this variable
1101 if (success)
1102 {
1103 const char *cstr = NULL;
1104 Address format_addr;
1105 bool calculate_format_addr_function_offset = false;
1106 // Set reg_kind and reg_num to invalid values
1107 RegisterKind reg_kind = kNumRegisterKinds;
1108 uint32_t reg_num = LLDB_INVALID_REGNUM;
1109 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +00001110 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00001111 RegisterContext *reg_ctx = NULL;
Enrico Granata9fc19442011-07-06 02:13:41 +00001112 bool do_deref_pointer = false;
Enrico Granatae992a082011-07-22 17:03:19 +00001113 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eEndOfString;
1114 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::ePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001115
Greg Clayton1b654882010-09-19 02:33:57 +00001116 // Each variable must set success to true below...
1117 bool var_success = false;
1118 switch (var_name_begin[0])
1119 {
Enrico Granata4becb372011-06-29 22:27:15 +00001120 case '*':
Enrico Granata4becb372011-06-29 22:27:15 +00001121 case 'v':
Enrico Granata6f3533f2011-07-29 19:53:35 +00001122 case 's':
Enrico Granata4becb372011-06-29 22:27:15 +00001123 {
Enrico Granatac482a192011-08-17 22:13:59 +00001124 if (!valobj)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001125 break;
1126
Enrico Granatac3e320a2011-08-02 17:27:39 +00001127 if (log)
1128 log->Printf("initial string: %s",var_name_begin);
1129
Enrico Granata6f3533f2011-07-29 19:53:35 +00001130 // check for *var and *svar
1131 if (*var_name_begin == '*')
1132 {
1133 do_deref_pointer = true;
1134 var_name_begin++;
1135 }
Enrico Granatac3e320a2011-08-02 17:27:39 +00001136
1137 if (log)
1138 log->Printf("initial string: %s",var_name_begin);
1139
Enrico Granata6f3533f2011-07-29 19:53:35 +00001140 if (*var_name_begin == 's')
1141 {
Greg Clayton4d122c42011-09-17 08:33:22 +00001142 valobj = valobj->GetSyntheticValue(eUseSyntheticFilter).get();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001143 var_name_begin++;
1144 }
1145
Enrico Granatac3e320a2011-08-02 17:27:39 +00001146 if (log)
1147 log->Printf("initial string: %s",var_name_begin);
1148
Enrico Granata6f3533f2011-07-29 19:53:35 +00001149 // should be a 'v' by now
1150 if (*var_name_begin != 'v')
1151 break;
1152
Enrico Granatac3e320a2011-08-02 17:27:39 +00001153 if (log)
1154 log->Printf("initial string: %s",var_name_begin);
1155
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001156 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
1157 ValueObject::eDereference : ValueObject::eNothing);
1158 ValueObject::GetValueForExpressionPathOptions options;
Enrico Granata8c9d3562011-08-11 17:08:01 +00001159 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren();
Greg Clayton34132752011-07-06 04:07:21 +00001160 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eDisplaySummary;
1161 ValueObject* target = NULL;
Greg Clayton4d122c42011-09-17 08:33:22 +00001162 Format custom_format = eFormatInvalid;
Greg Clayton34132752011-07-06 04:07:21 +00001163 const char* var_name_final = NULL;
1164 const char* var_name_final_if_array_range = NULL;
1165 const char* close_bracket_position = NULL;
1166 int64_t index_lower = -1;
1167 int64_t index_higher = -1;
1168 bool is_array_range = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001169 const char* first_unparsed;
Enrico Granata85933ed2011-08-18 16:38:26 +00001170 bool was_plain_var = false;
1171 bool was_var_format = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001172
Enrico Granatac482a192011-08-17 22:13:59 +00001173 if (!valobj) break;
1174 // simplest case ${var}, just print valobj's value
Greg Clayton34132752011-07-06 04:07:21 +00001175 if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0)
Enrico Granata4becb372011-06-29 22:27:15 +00001176 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001177 was_plain_var = true;
Enrico Granatac482a192011-08-17 22:13:59 +00001178 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001179 val_obj_display = ValueObject::eDisplayValue;
1180 }
1181 else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0)
1182 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001183 was_var_format = true;
Greg Clayton34132752011-07-06 04:07:21 +00001184 // this is a variable with some custom format applied to it
1185 const char* percent_position;
Enrico Granatac482a192011-08-17 22:13:59 +00001186 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001187 val_obj_display = ValueObject::eDisplayValue;
1188 ScanFormatDescriptor (var_name_begin,
1189 var_name_end,
1190 &var_name_final,
1191 &percent_position,
1192 &custom_format,
1193 &val_obj_display);
1194 }
1195 // this is ${var.something} or multiple .something nested
1196 else if (::strncmp (var_name_begin, "var", strlen("var")) == 0)
1197 {
1198
1199 const char* percent_position;
1200 ScanFormatDescriptor (var_name_begin,
1201 var_name_end,
1202 &var_name_final,
1203 &percent_position,
1204 &custom_format,
1205 &val_obj_display);
1206
1207 const char* open_bracket_position;
1208 const char* separator_position;
1209 ScanBracketedRange (var_name_begin,
1210 var_name_end,
1211 var_name_final,
1212 &open_bracket_position,
1213 &separator_position,
1214 &close_bracket_position,
1215 &var_name_final_if_array_range,
1216 &index_lower,
1217 &index_higher);
1218
1219 Error error;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001220
1221 std::auto_ptr<char> expr_path(new char[var_name_final-var_name_begin-1]);
1222 ::memset(expr_path.get(), 0, var_name_final-var_name_begin-1);
1223 memcpy(expr_path.get(), var_name_begin+3,var_name_final-var_name_begin-3);
1224
Enrico Granatae992a082011-07-22 17:03:19 +00001225 if (log)
1226 log->Printf("symbol to expand: %s",expr_path.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001227
Enrico Granatac482a192011-08-17 22:13:59 +00001228 target = valobj->GetValueForExpressionPath(expr_path.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001229 &first_unparsed,
1230 &reason_to_stop,
1231 &final_value_type,
1232 options,
1233 &what_next).get();
1234
1235 if (!target)
Enrico Granata9fc19442011-07-06 02:13:41 +00001236 {
Enrico Granatae992a082011-07-22 17:03:19 +00001237 if (log)
1238 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1239 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001240 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001241 break;
Enrico Granata9fc19442011-07-06 02:13:41 +00001242 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001243 else
1244 {
Enrico Granatae992a082011-07-22 17:03:19 +00001245 if (log)
1246 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1247 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001248 first_unparsed, reason_to_stop, final_value_type);
1249 }
Enrico Granata4becb372011-06-29 22:27:15 +00001250 }
Greg Clayton34132752011-07-06 04:07:21 +00001251 else
Enrico Granata9fc19442011-07-06 02:13:41 +00001252 break;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001253
1254 is_array_range = (final_value_type == ValueObject::eBoundedRange ||
1255 final_value_type == ValueObject::eUnboundedRange);
1256
1257 do_deref_pointer = (what_next == ValueObject::eDereference);
Enrico Granata9fc19442011-07-06 02:13:41 +00001258
Enrico Granataa7187d02011-07-06 19:27:11 +00001259 if (do_deref_pointer && !is_array_range)
Enrico Granata9fc19442011-07-06 02:13:41 +00001260 {
Greg Clayton34132752011-07-06 04:07:21 +00001261 // I have not deref-ed yet, let's do it
1262 // this happens when we are not going through GetValueForVariableExpressionPath
1263 // to get to the target ValueObject
Enrico Granata9fc19442011-07-06 02:13:41 +00001264 Error error;
Greg Clayton34132752011-07-06 04:07:21 +00001265 target = target->Dereference(error).get();
Enrico Granatadc940732011-08-23 00:32:52 +00001266 if (error.Fail())
1267 {
1268 if (log)
1269 log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
1270 break;
1271 }
Greg Clayton34132752011-07-06 04:07:21 +00001272 do_deref_pointer = false;
Enrico Granata9fc19442011-07-06 02:13:41 +00001273 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001274
Enrico Granata85933ed2011-08-18 16:38:26 +00001275 // TODO use flags for these
Enrico Granataf4efecd2011-07-12 22:56:10 +00001276 bool is_array = ClangASTContext::IsArrayType(target->GetClangType());
1277 bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType());
Enrico Granata85933ed2011-08-18 16:38:26 +00001278 bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType());
Enrico Granataf4efecd2011-07-12 22:56:10 +00001279
1280 if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eDisplayValue) // this should be wrong, but there are some exceptions
1281 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001282 StreamString str_temp;
Enrico Granatae992a082011-07-22 17:03:19 +00001283 if (log)
1284 log->Printf("I am into array || pointer && !range");
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001285
1286 if (target->HasSpecialCasesForPrintableRepresentation(val_obj_display,
1287 custom_format))
Enrico Granata85933ed2011-08-18 16:38:26 +00001288 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001289 // try to use the special cases
1290 var_success = target->DumpPrintableRepresentation(str_temp,
1291 val_obj_display,
1292 custom_format);
1293 if (log)
1294 log->Printf("special cases did%s match", var_success ? "" : "n't");
1295
1296 // should not happen
1297 if (!var_success)
1298 s << "<invalid usage of pointer value as object>";
1299 else
1300 s << str_temp.GetData();
Enrico Granata85933ed2011-08-18 16:38:26 +00001301 var_success = true;
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001302 break;
Enrico Granata85933ed2011-08-18 16:38:26 +00001303 }
1304 else
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001305 {
Enrico Granata88da35f2011-08-23 21:26:09 +00001306 if (was_plain_var) // if ${var}
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001307 {
1308 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1309 }
Enrico Granata88da35f2011-08-23 21:26:09 +00001310 else if (is_pointer) // if pointer, value is the address stored
1311 {
1312 var_success = target->GetPrintableRepresentation(s,
1313 val_obj_display,
1314 custom_format);
1315 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001316 else
1317 {
1318 s << "<invalid usage of pointer value as object>";
1319 }
1320 var_success = true;
1321 break;
1322 }
1323 }
1324
1325 // if directly trying to print ${var}, and this is an aggregate, display a nice
1326 // type @ location message
1327 if (is_aggregate && was_plain_var)
1328 {
1329 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1330 var_success = true;
Enrico Granata85933ed2011-08-18 16:38:26 +00001331 break;
1332 }
1333
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001334 // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it
1335 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eDisplayValue)))
Enrico Granata85933ed2011-08-18 16:38:26 +00001336 {
1337 s << "<invalid use of aggregate type>";
1338 var_success = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001339 break;
1340 }
Greg Clayton34132752011-07-06 04:07:21 +00001341
1342 if (!is_array_range)
Enrico Granatae992a082011-07-22 17:03:19 +00001343 {
1344 if (log)
1345 log->Printf("dumping ordinary printable output");
Greg Clayton34132752011-07-06 04:07:21 +00001346 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
Enrico Granatae992a082011-07-22 17:03:19 +00001347 }
Greg Clayton34132752011-07-06 04:07:21 +00001348 else
Enrico Granatae992a082011-07-22 17:03:19 +00001349 {
1350 if (log)
1351 log->Printf("checking if I can handle as array");
Greg Clayton34132752011-07-06 04:07:21 +00001352 if (!is_array && !is_pointer)
1353 break;
Enrico Granatae992a082011-07-22 17:03:19 +00001354 if (log)
1355 log->Printf("handle as array");
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001356 const char* special_directions = NULL;
1357 StreamString special_directions_writer;
Greg Clayton34132752011-07-06 04:07:21 +00001358 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1359 {
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001360 ConstString additional_data;
1361 additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1);
1362 special_directions_writer.Printf("${%svar%s}",
1363 do_deref_pointer ? "*" : "",
1364 additional_data.GetCString());
1365 special_directions = special_directions_writer.GetData();
Greg Clayton34132752011-07-06 04:07:21 +00001366 }
1367
1368 // let us display items index_lower thru index_higher of this array
1369 s.PutChar('[');
1370 var_success = true;
1371
1372 if (index_higher < 0)
Enrico Granatac482a192011-08-17 22:13:59 +00001373 index_higher = valobj->GetNumChildren() - 1;
Greg Clayton34132752011-07-06 04:07:21 +00001374
Enrico Granata22c55d12011-08-12 02:00:06 +00001375 uint32_t max_num_children = target->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
1376
Greg Clayton34132752011-07-06 04:07:21 +00001377 for (;index_lower<=index_higher;index_lower++)
1378 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001379 ValueObject* item = ExpandIndexedExpression (target,
1380 index_lower,
1381 exe_ctx->GetFramePtr(),
1382 false).get();
Greg Clayton34132752011-07-06 04:07:21 +00001383
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001384 if (!item)
1385 {
Enrico Granatae992a082011-07-22 17:03:19 +00001386 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001387 log->Printf("ERROR in getting child item at index %lld", index_lower);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001388 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001389 else
1390 {
Enrico Granatae992a082011-07-22 17:03:19 +00001391 if (log)
1392 log->Printf("special_directions for child item: %s",special_directions);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001393 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001394
Greg Clayton34132752011-07-06 04:07:21 +00001395 if (!special_directions)
1396 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1397 else
1398 var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
1399
Enrico Granata22c55d12011-08-12 02:00:06 +00001400 if (--max_num_children == 0)
1401 {
1402 s.PutCString(", ...");
1403 break;
1404 }
1405
Greg Clayton34132752011-07-06 04:07:21 +00001406 if (index_lower < index_higher)
1407 s.PutChar(',');
1408 }
1409 s.PutChar(']');
1410 }
Enrico Granata4becb372011-06-29 22:27:15 +00001411 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001412 break;
Greg Clayton1b654882010-09-19 02:33:57 +00001413 case 'a':
1414 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
1415 {
1416 if (addr && addr->IsValid())
1417 {
1418 var_success = true;
1419 format_addr = *addr;
1420 }
1421 }
Greg Clayton5a314712011-10-14 07:41:33 +00001422 else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0)
1423 {
1424 var_success = true;
1425 var_name_begin += strlen("ansi."); // Skip the "ansi."
1426 if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0)
1427 {
1428 var_name_begin += strlen("fg."); // Skip the "fg."
1429 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1430 {
1431 s.Printf ("%s%s%s",
1432 lldb_utility::ansi::k_escape_start,
1433 lldb_utility::ansi::k_fg_black,
1434 lldb_utility::ansi::k_escape_end);
1435 }
1436 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1437 {
1438 s.Printf ("%s%s%s",
1439 lldb_utility::ansi::k_escape_start,
1440 lldb_utility::ansi::k_fg_red,
1441 lldb_utility::ansi::k_escape_end);
1442 }
1443 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1444 {
1445 s.Printf ("%s%s%s",
1446 lldb_utility::ansi::k_escape_start,
1447 lldb_utility::ansi::k_fg_green,
1448 lldb_utility::ansi::k_escape_end);
1449 }
1450 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1451 {
1452 s.Printf ("%s%s%s",
1453 lldb_utility::ansi::k_escape_start,
1454 lldb_utility::ansi::k_fg_yellow,
1455 lldb_utility::ansi::k_escape_end);
1456 }
1457 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1458 {
1459 s.Printf ("%s%s%s",
1460 lldb_utility::ansi::k_escape_start,
1461 lldb_utility::ansi::k_fg_blue,
1462 lldb_utility::ansi::k_escape_end);
1463 }
1464 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1465 {
1466 s.Printf ("%s%s%s",
1467 lldb_utility::ansi::k_escape_start,
1468 lldb_utility::ansi::k_fg_purple,
1469 lldb_utility::ansi::k_escape_end);
1470 }
1471 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1472 {
1473 s.Printf ("%s%s%s",
1474 lldb_utility::ansi::k_escape_start,
1475 lldb_utility::ansi::k_fg_cyan,
1476 lldb_utility::ansi::k_escape_end);
1477 }
1478 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1479 {
1480 s.Printf ("%s%s%s",
1481 lldb_utility::ansi::k_escape_start,
1482 lldb_utility::ansi::k_fg_white,
1483 lldb_utility::ansi::k_escape_end);
1484 }
1485 else
1486 {
1487 var_success = false;
1488 }
1489 }
1490 else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0)
1491 {
1492 var_name_begin += strlen("bg."); // Skip the "bg."
1493 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1494 {
1495 s.Printf ("%s%s%s",
1496 lldb_utility::ansi::k_escape_start,
1497 lldb_utility::ansi::k_bg_black,
1498 lldb_utility::ansi::k_escape_end);
1499 }
1500 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1501 {
1502 s.Printf ("%s%s%s",
1503 lldb_utility::ansi::k_escape_start,
1504 lldb_utility::ansi::k_bg_red,
1505 lldb_utility::ansi::k_escape_end);
1506 }
1507 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1508 {
1509 s.Printf ("%s%s%s",
1510 lldb_utility::ansi::k_escape_start,
1511 lldb_utility::ansi::k_bg_green,
1512 lldb_utility::ansi::k_escape_end);
1513 }
1514 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1515 {
1516 s.Printf ("%s%s%s",
1517 lldb_utility::ansi::k_escape_start,
1518 lldb_utility::ansi::k_bg_yellow,
1519 lldb_utility::ansi::k_escape_end);
1520 }
1521 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1522 {
1523 s.Printf ("%s%s%s",
1524 lldb_utility::ansi::k_escape_start,
1525 lldb_utility::ansi::k_bg_blue,
1526 lldb_utility::ansi::k_escape_end);
1527 }
1528 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1529 {
1530 s.Printf ("%s%s%s",
1531 lldb_utility::ansi::k_escape_start,
1532 lldb_utility::ansi::k_bg_purple,
1533 lldb_utility::ansi::k_escape_end);
1534 }
1535 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1536 {
1537 s.Printf ("%s%s%s",
1538 lldb_utility::ansi::k_escape_start,
1539 lldb_utility::ansi::k_bg_cyan,
1540 lldb_utility::ansi::k_escape_end);
1541 }
1542 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1543 {
1544 s.Printf ("%s%s%s",
1545 lldb_utility::ansi::k_escape_start,
1546 lldb_utility::ansi::k_bg_white,
1547 lldb_utility::ansi::k_escape_end);
1548 }
1549 else
1550 {
1551 var_success = false;
1552 }
1553 }
1554 else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0)
1555 {
1556 s.Printf ("%s%s%s",
1557 lldb_utility::ansi::k_escape_start,
1558 lldb_utility::ansi::k_ctrl_normal,
1559 lldb_utility::ansi::k_escape_end);
1560 }
1561 else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0)
1562 {
1563 s.Printf ("%s%s%s",
1564 lldb_utility::ansi::k_escape_start,
1565 lldb_utility::ansi::k_ctrl_bold,
1566 lldb_utility::ansi::k_escape_end);
1567 }
1568 else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0)
1569 {
1570 s.Printf ("%s%s%s",
1571 lldb_utility::ansi::k_escape_start,
1572 lldb_utility::ansi::k_ctrl_faint,
1573 lldb_utility::ansi::k_escape_end);
1574 }
1575 else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0)
1576 {
1577 s.Printf ("%s%s%s",
1578 lldb_utility::ansi::k_escape_start,
1579 lldb_utility::ansi::k_ctrl_italic,
1580 lldb_utility::ansi::k_escape_end);
1581 }
1582 else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0)
1583 {
1584 s.Printf ("%s%s%s",
1585 lldb_utility::ansi::k_escape_start,
1586 lldb_utility::ansi::k_ctrl_underline,
1587 lldb_utility::ansi::k_escape_end);
1588 }
1589 else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0)
1590 {
1591 s.Printf ("%s%s%s",
1592 lldb_utility::ansi::k_escape_start,
1593 lldb_utility::ansi::k_ctrl_slow_blink,
1594 lldb_utility::ansi::k_escape_end);
1595 }
1596 else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0)
1597 {
1598 s.Printf ("%s%s%s",
1599 lldb_utility::ansi::k_escape_start,
1600 lldb_utility::ansi::k_ctrl_fast_blink,
1601 lldb_utility::ansi::k_escape_end);
1602 }
1603 else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0)
1604 {
1605 s.Printf ("%s%s%s",
1606 lldb_utility::ansi::k_escape_start,
1607 lldb_utility::ansi::k_ctrl_negative,
1608 lldb_utility::ansi::k_escape_end);
1609 }
1610 else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0)
1611 {
1612 s.Printf ("%s%s%s",
1613 lldb_utility::ansi::k_escape_start,
1614 lldb_utility::ansi::k_ctrl_conceal,
1615 lldb_utility::ansi::k_escape_end);
1616
1617 }
1618 else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0)
1619 {
1620 s.Printf ("%s%s%s",
1621 lldb_utility::ansi::k_escape_start,
1622 lldb_utility::ansi::k_ctrl_crossed_out,
1623 lldb_utility::ansi::k_escape_end);
1624 }
1625 else
1626 {
1627 var_success = false;
1628 }
1629 }
Greg Clayton1b654882010-09-19 02:33:57 +00001630 break;
1631
1632 case 'p':
1633 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
1634 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001635 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001636 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001637 Process *process = exe_ctx->GetProcessPtr();
1638 if (process)
Greg Clayton1b654882010-09-19 02:33:57 +00001639 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001640 var_name_begin += ::strlen ("process.");
1641 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001642 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001643 s.Printf("%llu", process->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001644 var_success = true;
1645 }
1646 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
1647 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
1648 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
1649 {
1650 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1651 if (exe_module)
Greg Clayton1b654882010-09-19 02:33:57 +00001652 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001653 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1654 {
1655 format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
1656 var_success = format_file_spec;
1657 }
1658 else
1659 {
1660 format_file_spec = exe_module->GetFileSpec();
1661 var_success = format_file_spec;
1662 }
Greg Clayton1b654882010-09-19 02:33:57 +00001663 }
1664 }
1665 }
Greg Claytonc14ee322011-09-22 04:58:26 +00001666 }
Greg Clayton1b654882010-09-19 02:33:57 +00001667 }
1668 break;
1669
1670 case 't':
1671 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
1672 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001673 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001674 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001675 Thread *thread = exe_ctx->GetThreadPtr();
1676 if (thread)
Greg Clayton1b654882010-09-19 02:33:57 +00001677 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001678 var_name_begin += ::strlen ("thread.");
1679 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001680 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001681 s.Printf("0x%4.4llx", thread->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001682 var_success = true;
1683 }
1684 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1685 {
1686 s.Printf("%u", thread->GetIndexID());
1687 var_success = true;
1688 }
1689 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1690 {
1691 cstr = thread->GetName();
1692 var_success = cstr && cstr[0];
1693 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001694 s.PutCString(cstr);
Greg Claytonc14ee322011-09-22 04:58:26 +00001695 }
1696 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
1697 {
1698 cstr = thread->GetQueueName();
1699 var_success = cstr && cstr[0];
1700 if (var_success)
1701 s.PutCString(cstr);
1702 }
1703 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
1704 {
1705 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1706 if (stop_info_sp)
1707 {
1708 cstr = stop_info_sp->GetDescription();
1709 if (cstr && cstr[0])
1710 {
1711 s.PutCString(cstr);
1712 var_success = true;
1713 }
Greg Clayton1b654882010-09-19 02:33:57 +00001714 }
1715 }
Jim Ingham73ca05a2011-12-17 01:35:57 +00001716 else if (::strncmp (var_name_begin, "return-value}", strlen("return-value}")) == 0)
1717 {
1718 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1719 if (stop_info_sp)
1720 {
1721 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1722 if (return_valobj_sp)
1723 {
Jim Inghamef651602011-12-22 19:12:40 +00001724 ValueObject::DumpValueObjectOptions dump_options;
1725 ValueObject::DumpValueObject (s, return_valobj_sp.get(), dump_options);
1726 var_success = true;
Jim Ingham73ca05a2011-12-17 01:35:57 +00001727 }
1728 }
1729 }
Greg Clayton1b654882010-09-19 02:33:57 +00001730 }
1731 }
1732 }
1733 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
1734 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001735 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1736 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +00001737 {
Greg Clayton1b654882010-09-19 02:33:57 +00001738 var_name_begin += ::strlen ("target.");
1739 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
1740 {
1741 ArchSpec arch (target->GetArchitecture ());
1742 if (arch.IsValid())
1743 {
Greg Clayton64195a22011-02-23 00:35:02 +00001744 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +00001745 var_success = true;
1746 }
1747 }
1748 }
1749 }
1750 break;
1751
1752
1753 case 'm':
1754 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
1755 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001756 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +00001757 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001758 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +00001759 var_name_begin += ::strlen ("module.");
1760
1761 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1762 {
1763 if (module->GetFileSpec())
1764 {
1765 var_name_begin += ::strlen ("file.");
1766
1767 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1768 {
1769 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
1770 var_success = format_file_spec;
1771 }
1772 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1773 {
1774 format_file_spec = module->GetFileSpec();
1775 var_success = format_file_spec;
1776 }
1777 }
1778 }
1779 }
1780 }
1781 break;
1782
1783
1784 case 'f':
1785 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1786 {
1787 if (sc && sc->comp_unit != NULL)
1788 {
1789 var_name_begin += ::strlen ("file.");
1790
1791 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1792 {
1793 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
1794 var_success = format_file_spec;
1795 }
1796 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1797 {
1798 format_file_spec = *sc->comp_unit;
1799 var_success = format_file_spec;
1800 }
1801 }
1802 }
1803 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
1804 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001805 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001806 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001807 StackFrame *frame = exe_ctx->GetFramePtr();
1808 if (frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001809 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001810 var_name_begin += ::strlen ("frame.");
1811 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001812 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001813 s.Printf("%u", frame->GetFrameIndex());
1814 var_success = true;
1815 }
1816 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
1817 {
1818 reg_kind = eRegisterKindGeneric;
1819 reg_num = LLDB_REGNUM_GENERIC_PC;
1820 var_success = true;
1821 }
1822 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
1823 {
1824 reg_kind = eRegisterKindGeneric;
1825 reg_num = LLDB_REGNUM_GENERIC_SP;
1826 var_success = true;
1827 }
1828 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
1829 {
1830 reg_kind = eRegisterKindGeneric;
1831 reg_num = LLDB_REGNUM_GENERIC_FP;
1832 var_success = true;
1833 }
1834 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
1835 {
1836 reg_kind = eRegisterKindGeneric;
1837 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
1838 var_success = true;
1839 }
1840 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
1841 {
1842 reg_ctx = frame->GetRegisterContext().get();
1843 if (reg_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001844 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001845 var_name_begin += ::strlen ("reg.");
1846 if (var_name_begin < var_name_end)
1847 {
1848 std::string reg_name (var_name_begin, var_name_end);
1849 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
1850 if (reg_info)
1851 var_success = true;
1852 }
Greg Clayton1b654882010-09-19 02:33:57 +00001853 }
1854 }
1855 }
1856 }
1857 }
1858 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
1859 {
1860 if (sc && (sc->function != NULL || sc->symbol != NULL))
1861 {
1862 var_name_begin += ::strlen ("function.");
1863 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1864 {
1865 if (sc->function)
Greg Clayton81c22f62011-10-19 18:09:39 +00001866 s.Printf("function{0x%8.8llx}", sc->function->GetID());
Greg Clayton1b654882010-09-19 02:33:57 +00001867 else
1868 s.Printf("symbol[%u]", sc->symbol->GetID());
1869
1870 var_success = true;
1871 }
1872 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1873 {
1874 if (sc->function)
1875 cstr = sc->function->GetName().AsCString (NULL);
1876 else if (sc->symbol)
1877 cstr = sc->symbol->GetName().AsCString (NULL);
1878 if (cstr)
1879 {
1880 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001881
1882 if (sc->block)
1883 {
1884 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1885 if (inline_block)
1886 {
1887 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1888 if (inline_info)
1889 {
1890 s.PutCString(" [inlined] ");
1891 inline_info->GetName().Dump(&s);
1892 }
1893 }
1894 }
Greg Clayton1b654882010-09-19 02:33:57 +00001895 var_success = true;
1896 }
1897 }
Greg Clayton6d3dbf52012-01-13 08:39:16 +00001898 else if (::strncmp (var_name_begin, "name-with-args}", strlen("name-with-args}")) == 0)
1899 {
1900 // Print the function name with arguments in it
1901
1902 if (sc->function)
1903 {
1904 var_success = true;
1905 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
1906 cstr = sc->function->GetName().AsCString (NULL);
1907 if (cstr)
1908 {
1909 const InlineFunctionInfo *inline_info = NULL;
1910 VariableListSP variable_list_sp;
1911 bool get_function_vars = true;
1912 if (sc->block)
1913 {
1914 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1915
1916 if (inline_block)
1917 {
1918 get_function_vars = false;
1919 inline_info = sc->block->GetInlinedFunctionInfo();
1920 if (inline_info)
1921 variable_list_sp = inline_block->GetBlockVariableList (true);
1922 }
1923 }
1924
1925 if (get_function_vars)
1926 {
1927 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
1928 }
1929
1930 if (inline_info)
1931 {
1932 s.PutCString (cstr);
1933 s.PutCString (" [inlined] ");
1934 cstr = inline_info->GetName().GetCString();
1935 }
1936
1937 VariableList args;
1938 if (variable_list_sp)
1939 {
1940 const size_t num_variables = variable_list_sp->GetSize();
1941 for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
1942 {
1943 VariableSP var_sp (variable_list_sp->GetVariableAtIndex(var_idx));
1944 if (var_sp->GetScope() == eValueTypeVariableArgument)
1945 args.AddVariable (var_sp);
1946 }
1947
1948 }
1949 if (args.GetSize() > 0)
1950 {
1951 const char *open_paren = strchr (cstr, '(');
1952 const char *close_paren = NULL;
1953 if (open_paren)
1954 close_paren = strchr (open_paren, ')');
1955
1956 if (open_paren)
1957 s.Write(cstr, open_paren - cstr + 1);
1958 else
1959 {
1960 s.PutCString (cstr);
1961 s.PutChar ('(');
1962 }
Greg Clayton5b6889b2012-01-18 21:56:18 +00001963 const size_t num_args = args.GetSize();
Greg Clayton6d3dbf52012-01-13 08:39:16 +00001964 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
1965 {
1966 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
1967 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
1968 const char *var_name = var_value_sp->GetName().GetCString();
1969 const char *var_value = var_value_sp->GetValueAsCString();
1970 if (var_value_sp->GetError().Success())
1971 {
1972 if (arg_idx > 0)
1973 s.PutCString (", ");
1974 s.Printf ("%s=%s", var_name, var_value);
1975 }
1976 }
1977
1978 if (close_paren)
1979 s.PutCString (close_paren);
1980 else
1981 s.PutChar(')');
1982
1983 }
1984 else
1985 {
1986 s.PutCString(cstr);
1987 }
1988 }
1989 }
1990 else if (sc->symbol)
1991 {
1992 cstr = sc->symbol->GetName().AsCString (NULL);
1993 if (cstr)
1994 {
1995 s.PutCString(cstr);
1996 var_success = true;
1997 }
1998 }
1999 }
Greg Clayton1b654882010-09-19 02:33:57 +00002000 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
2001 {
2002 var_success = addr != NULL;
2003 if (var_success)
2004 {
2005 format_addr = *addr;
2006 calculate_format_addr_function_offset = true;
2007 }
2008 }
2009 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
2010 {
2011 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
2012 if (var_success)
2013 {
2014 format_addr = sc->line_entry.range.GetBaseAddress();
2015 calculate_format_addr_function_offset = true;
2016 }
2017 }
2018 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
2019 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002020 StackFrame *frame = exe_ctx->GetFramePtr();
2021 var_success = frame != NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00002022 if (var_success)
2023 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002024 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002025 calculate_format_addr_function_offset = true;
2026 }
2027 }
2028 }
2029 }
2030 break;
2031
2032 case 'l':
2033 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
2034 {
2035 if (sc && sc->line_entry.IsValid())
2036 {
2037 var_name_begin += ::strlen ("line.");
2038 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
2039 {
2040 var_name_begin += ::strlen ("file.");
2041
2042 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
2043 {
2044 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
2045 var_success = format_file_spec;
2046 }
2047 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
2048 {
2049 format_file_spec = sc->line_entry.file;
2050 var_success = format_file_spec;
2051 }
2052 }
2053 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
2054 {
2055 var_success = true;
2056 s.Printf("%u", sc->line_entry.line);
2057 }
2058 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
2059 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
2060 {
2061 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
2062 if (var_success)
2063 {
2064 format_addr = sc->line_entry.range.GetBaseAddress();
2065 if (var_name_begin[0] == 'e')
2066 format_addr.Slide (sc->line_entry.range.GetByteSize());
2067 }
2068 }
2069 }
2070 }
2071 break;
2072 }
2073
2074 if (var_success)
2075 {
2076 // If format addr is valid, then we need to print an address
2077 if (reg_num != LLDB_INVALID_REGNUM)
2078 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002079 StackFrame *frame = exe_ctx->GetFramePtr();
Greg Clayton1b654882010-09-19 02:33:57 +00002080 // We have a register value to display...
2081 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
2082 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002083 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002084 }
2085 else
2086 {
2087 if (reg_ctx == NULL)
Greg Claytonc14ee322011-09-22 04:58:26 +00002088 reg_ctx = frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00002089
2090 if (reg_ctx)
2091 {
2092 if (reg_kind != kNumRegisterKinds)
2093 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
2094 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
2095 var_success = reg_info != NULL;
2096 }
2097 }
2098 }
2099
2100 if (reg_info != NULL)
2101 {
Greg Clayton7349bd92011-05-09 20:18:18 +00002102 RegisterValue reg_value;
2103 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
2104 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00002105 {
Greg Clayton9a8fa912011-05-15 04:12:07 +00002106 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
Greg Clayton1b654882010-09-19 02:33:57 +00002107 }
2108 }
2109
2110 if (format_file_spec)
2111 {
2112 s << format_file_spec;
2113 }
2114
2115 // If format addr is valid, then we need to print an address
2116 if (format_addr.IsValid())
2117 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002118 var_success = false;
2119
Greg Clayton1b654882010-09-19 02:33:57 +00002120 if (calculate_format_addr_function_offset)
2121 {
2122 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00002123
Greg Clayton0603aa92010-10-04 01:05:56 +00002124 if (sc)
2125 {
2126 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00002127 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002128 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00002129 if (sc->block)
2130 {
2131 // Check to make sure we aren't in an inline
2132 // function. If we are, use the inline block
2133 // range that contains "format_addr" since
2134 // blocks can be discontiguous.
2135 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2136 AddressRange inline_range;
2137 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
2138 func_addr = inline_range.GetBaseAddress();
2139 }
2140 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002141 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
2142 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
2143 }
2144
2145 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00002146 {
2147 if (func_addr.GetSection() == format_addr.GetSection())
2148 {
2149 addr_t func_file_addr = func_addr.GetFileAddress();
2150 addr_t addr_file_addr = format_addr.GetFileAddress();
2151 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002152 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00002153 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002154 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002155 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00002156 }
2157 else
Greg Clayton0603aa92010-10-04 01:05:56 +00002158 {
2159 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2160 if (target)
2161 {
2162 addr_t func_load_addr = func_addr.GetLoadAddress (target);
2163 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
2164 if (addr_load_addr > func_load_addr)
2165 s.Printf(" + %llu", addr_load_addr - func_load_addr);
2166 else if (addr_load_addr < func_load_addr)
2167 s.Printf(" - %llu", func_load_addr - addr_load_addr);
2168 var_success = true;
2169 }
2170 }
Greg Clayton1b654882010-09-19 02:33:57 +00002171 }
2172 }
2173 else
2174 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002175 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00002176 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00002177 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
2178 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00002179 if (vaddr == LLDB_INVALID_ADDRESS)
2180 vaddr = format_addr.GetFileAddress ();
2181
2182 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00002183 {
Greg Clayton514487e2011-02-15 21:59:32 +00002184 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00002185 if (addr_width == 0)
2186 addr_width = 16;
2187 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002188 var_success = true;
2189 }
Greg Clayton1b654882010-09-19 02:33:57 +00002190 }
2191 }
2192 }
2193
2194 if (var_success == false)
2195 success = false;
2196 }
2197 p = var_name_end;
2198 }
2199 else
2200 break;
2201 }
2202 else
2203 {
2204 // We got a dollar sign with no '{' after it, it must just be a dollar sign
2205 s.PutChar(*p);
2206 }
2207 }
2208 else if (*p == '\\')
2209 {
2210 ++p; // skip the slash
2211 switch (*p)
2212 {
2213 case 'a': s.PutChar ('\a'); break;
2214 case 'b': s.PutChar ('\b'); break;
2215 case 'f': s.PutChar ('\f'); break;
2216 case 'n': s.PutChar ('\n'); break;
2217 case 'r': s.PutChar ('\r'); break;
2218 case 't': s.PutChar ('\t'); break;
2219 case 'v': s.PutChar ('\v'); break;
2220 case '\'': s.PutChar ('\''); break;
2221 case '\\': s.PutChar ('\\'); break;
2222 case '0':
2223 // 1 to 3 octal chars
2224 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002225 // Make a string that can hold onto the initial zero char,
2226 // up to 3 octal digits, and a terminating NULL.
2227 char oct_str[5] = { 0, 0, 0, 0, 0 };
2228
2229 int i;
2230 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
2231 oct_str[i] = p[i];
2232
2233 // We don't want to consume the last octal character since
2234 // the main for loop will do this for us, so we advance p by
2235 // one less than i (even if i is zero)
2236 p += i - 1;
2237 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2238 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002239 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002240 char octal_char = octal_value;
2241 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00002242 }
Greg Clayton1b654882010-09-19 02:33:57 +00002243 }
2244 break;
2245
2246 case 'x':
2247 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00002248 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002249 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002250 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00002251
Greg Clayton0603aa92010-10-04 01:05:56 +00002252 // Make a string that can hold onto two hex chars plus a
2253 // NULL terminator
2254 char hex_str[3] = { 0,0,0 };
2255 hex_str[0] = *p;
2256 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002257 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002258 ++p; // Skip the first of the two hex chars
2259 hex_str[1] = *p;
2260 }
2261
2262 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2263 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002264 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00002265 }
2266 else
2267 {
2268 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00002269 }
2270 break;
2271
2272 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00002273 // Just desensitize any other character by just printing what
2274 // came after the '\'
2275 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00002276 break;
2277
2278 }
2279
2280 }
2281 }
2282 if (end)
2283 *end = p;
2284 return success;
2285}
2286
2287#pragma mark Debugger::SettingsController
2288
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002289//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002290// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002291//--------------------------------------------------
2292
Greg Clayton1b654882010-09-19 02:33:57 +00002293Debugger::SettingsController::SettingsController () :
Greg Clayton4d122c42011-09-17 08:33:22 +00002294 UserSettingsController ("", UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002295{
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002296}
2297
Greg Clayton1b654882010-09-19 02:33:57 +00002298Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002299{
2300}
2301
2302
Greg Clayton4d122c42011-09-17 08:33:22 +00002303InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00002304Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002305{
Greg Claytonb9556ac2012-01-30 07:41:31 +00002306 InstanceSettingsSP new_settings_sp (new DebuggerInstanceSettings (GetSettingsController(),
2307 false,
2308 instance_name));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002309 return new_settings_sp;
2310}
2311
Greg Clayton1b654882010-09-19 02:33:57 +00002312#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002313//--------------------------------------------------
2314// class DebuggerInstanceSettings
2315//--------------------------------------------------
2316
Greg Claytona7015092010-09-18 01:14:36 +00002317DebuggerInstanceSettings::DebuggerInstanceSettings
2318(
Greg Claytonb9556ac2012-01-30 07:41:31 +00002319 const UserSettingsControllerSP &m_owner_sp,
Greg Claytona7015092010-09-18 01:14:36 +00002320 bool live_instance,
2321 const char *name
2322) :
Greg Claytonb9556ac2012-01-30 07:41:31 +00002323 InstanceSettings (m_owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00002324 m_term_width (80),
Greg Claytone372b982011-11-21 21:44:34 +00002325 m_stop_source_before_count (3),
2326 m_stop_source_after_count (3),
2327 m_stop_disassembly_count (4),
2328 m_stop_disassembly_display (eStopDisassemblyTypeNoSource),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002329 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00002330 m_frame_format (),
2331 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002332 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002333 m_use_external_editor (false),
2334 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002335{
Caroline Ticef20e8232010-09-09 18:26:37 +00002336 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2337 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
2338 // 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 +00002339 // The same is true of CreateInstanceName().
2340
2341 if (GetInstanceName() == InstanceSettings::InvalidName())
2342 {
2343 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Claytonb9556ac2012-01-30 07:41:31 +00002344 m_owner_sp->RegisterInstanceSettings (this);
Caroline Tice9e41c152010-09-16 19:05:55 +00002345 }
Caroline Ticef20e8232010-09-09 18:26:37 +00002346
2347 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002348 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00002349 const InstanceSettingsSP &pending_settings = m_owner_sp->FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002350 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002351 }
2352}
2353
2354DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Claytonb9556ac2012-01-30 07:41:31 +00002355 InstanceSettings (Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002356 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00002357 m_frame_format (rhs.m_frame_format),
2358 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002359 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002360 m_use_external_editor (rhs.m_use_external_editor),
2361 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002362{
Greg Claytonb9556ac2012-01-30 07:41:31 +00002363 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2364 if (owner_sp)
2365 {
2366 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
2367 owner_sp->RemovePendingSettings (m_instance_name);
2368 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002369}
2370
2371DebuggerInstanceSettings::~DebuggerInstanceSettings ()
2372{
2373}
2374
2375DebuggerInstanceSettings&
2376DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
2377{
2378 if (this != &rhs)
2379 {
Greg Clayton1b654882010-09-19 02:33:57 +00002380 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002381 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00002382 m_frame_format = rhs.m_frame_format;
2383 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002384 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002385 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002386 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002387 }
2388
2389 return *this;
2390}
2391
Greg Clayton1b654882010-09-19 02:33:57 +00002392bool
2393DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
2394{
2395 bool valid = false;
2396
2397 // Verify we have a value string.
2398 if (value == NULL || value[0] == '\0')
2399 {
Greg Clayton86edbf42011-10-26 00:56:27 +00002400 err.SetErrorString ("missing value, can't set terminal width without a value");
Greg Clayton1b654882010-09-19 02:33:57 +00002401 }
2402 else
2403 {
2404 char *end = NULL;
2405 const uint32_t width = ::strtoul (value, &end, 0);
2406
Johnny Chenea9fc182010-09-20 16:36:43 +00002407 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00002408 {
Johnny Chen433d7742010-09-20 17:04:41 +00002409 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00002410 valid = true;
2411 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002412 err.SetErrorString ("invalid term-width value; value must be between 10 and 1024");
Greg Clayton1b654882010-09-19 02:33:57 +00002413 }
2414 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002415 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value);
Greg Clayton1b654882010-09-19 02:33:57 +00002416 }
2417
2418 return valid;
2419}
2420
2421
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002422void
2423DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2424 const char *index_value,
2425 const char *value,
2426 const ConstString &instance_name,
2427 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00002428 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002429 Error &err,
2430 bool pending)
2431{
Greg Clayton0603aa92010-10-04 01:05:56 +00002432
2433 if (var_name == TermWidthVarName())
2434 {
2435 if (ValidTermWidthValue (value, err))
2436 {
2437 m_term_width = ::strtoul (value, NULL, 0);
2438 }
2439 }
2440 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002441 {
Caroline Tice101c7c22010-09-09 06:25:08 +00002442 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002443 if (!pending)
2444 {
Caroline Tice49e27372010-09-07 18:35:40 +00002445 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2446 // strip off the brackets before passing it to BroadcastPromptChange.
2447
2448 std::string tmp_instance_name (instance_name.AsCString());
2449 if ((tmp_instance_name[0] == '[')
2450 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
2451 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
2452 ConstString new_name (tmp_instance_name.c_str());
2453
2454 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002455 }
2456 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002457 else if (var_name == GetFrameFormatName())
2458 {
2459 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
2460 }
2461 else if (var_name == GetThreadFormatName())
2462 {
2463 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
2464 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002465 else if (var_name == ScriptLangVarName())
2466 {
2467 bool success;
2468 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
2469 &success);
2470 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002471 else if (var_name == UseExternalEditorVarName ())
2472 {
Greg Clayton385aa282011-04-22 03:55:06 +00002473 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00002474 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002475 else if (var_name == AutoConfirmName ())
2476 {
Greg Clayton385aa282011-04-22 03:55:06 +00002477 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00002478 }
Greg Claytone372b982011-11-21 21:44:34 +00002479 else if (var_name == StopSourceContextBeforeName ())
2480 {
2481 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2482 if (new_value != UINT32_MAX)
2483 m_stop_source_before_count = new_value;
2484 else
2485 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextAfterName ().GetCString());
2486 }
2487 else if (var_name == StopSourceContextAfterName ())
2488 {
2489 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2490 if (new_value != UINT32_MAX)
2491 m_stop_source_after_count = new_value;
2492 else
2493 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextBeforeName ().GetCString());
2494 }
2495 else if (var_name == StopDisassemblyCountName ())
2496 {
2497 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2498 if (new_value != UINT32_MAX)
2499 m_stop_disassembly_count = new_value;
2500 else
2501 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopDisassemblyCountName ().GetCString());
2502 }
2503 else if (var_name == StopDisassemblyDisplayName ())
2504 {
2505 int new_value;
2506 UserSettingsController::UpdateEnumVariable (g_show_disassembly_enum_values, &new_value, value, err);
2507 if (err.Success())
2508 m_stop_disassembly_display = (StopDisassemblyType)new_value;
2509 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002510}
2511
Caroline Tice12cecd72010-09-20 21:37:42 +00002512bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002513DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2514 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00002515 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00002516 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002517{
2518 if (var_name == PromptVarName())
2519 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002520 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002521
2522 }
2523 else if (var_name == ScriptLangVarName())
2524 {
2525 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
2526 }
Caroline Tice101c7c22010-09-09 06:25:08 +00002527 else if (var_name == TermWidthVarName())
2528 {
2529 StreamString width_str;
Greg Claytone372b982011-11-21 21:44:34 +00002530 width_str.Printf ("%u", m_term_width);
Caroline Tice101c7c22010-09-09 06:25:08 +00002531 value.AppendString (width_str.GetData());
2532 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002533 else if (var_name == GetFrameFormatName ())
2534 {
2535 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
2536 }
2537 else if (var_name == GetThreadFormatName ())
2538 {
2539 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
2540 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002541 else if (var_name == UseExternalEditorVarName())
2542 {
2543 if (m_use_external_editor)
2544 value.AppendString ("true");
2545 else
2546 value.AppendString ("false");
2547 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002548 else if (var_name == AutoConfirmName())
2549 {
2550 if (m_auto_confirm_on)
2551 value.AppendString ("true");
2552 else
2553 value.AppendString ("false");
2554 }
Greg Claytone372b982011-11-21 21:44:34 +00002555 else if (var_name == StopSourceContextAfterName ())
2556 {
2557 StreamString strm;
2558 strm.Printf ("%u", m_stop_source_before_count);
2559 value.AppendString (strm.GetData());
2560 }
2561 else if (var_name == StopSourceContextBeforeName ())
2562 {
2563 StreamString strm;
2564 strm.Printf ("%u", m_stop_source_after_count);
2565 value.AppendString (strm.GetData());
2566 }
2567 else if (var_name == StopDisassemblyCountName ())
2568 {
2569 StreamString strm;
2570 strm.Printf ("%u", m_stop_disassembly_count);
2571 value.AppendString (strm.GetData());
2572 }
2573 else if (var_name == StopDisassemblyDisplayName ())
2574 {
2575 if (m_stop_disassembly_display >= eStopDisassemblyTypeNever && m_stop_disassembly_display <= eStopDisassemblyTypeAlways)
2576 value.AppendString (g_show_disassembly_enum_values[m_stop_disassembly_display].string_value);
2577 else
2578 value.AppendString ("<invalid>");
2579 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002580 else
Caroline Tice12cecd72010-09-20 21:37:42 +00002581 {
2582 if (err)
2583 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2584 return false;
2585 }
2586 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002587}
2588
2589void
Greg Clayton4d122c42011-09-17 08:33:22 +00002590DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002591 bool pending)
2592{
2593 if (new_settings.get() == NULL)
2594 return;
2595
2596 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
2597
2598 m_prompt = new_debugger_settings->m_prompt;
2599 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00002600 {
2601 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2602 // strip off the brackets before passing it to BroadcastPromptChange.
2603
2604 std::string tmp_instance_name (m_instance_name.AsCString());
2605 if ((tmp_instance_name[0] == '[')
2606 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
2607 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
2608 ConstString new_name (tmp_instance_name.c_str());
2609
2610 BroadcastPromptChange (new_name, m_prompt.c_str());
2611 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002612 m_frame_format = new_debugger_settings->m_frame_format;
2613 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002614 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002615 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002616 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002617 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002618}
2619
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002620
2621bool
2622DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
2623{
2624 std::string tmp_prompt;
2625
2626 if (new_prompt != NULL)
2627 {
2628 tmp_prompt = new_prompt ;
2629 int len = tmp_prompt.size();
2630 if (len > 1
2631 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
2632 && (tmp_prompt[len-1] == tmp_prompt[0]))
2633 {
2634 tmp_prompt = tmp_prompt.substr(1,len-2);
2635 }
2636 len = tmp_prompt.size();
2637 if (tmp_prompt[len-1] != ' ')
2638 tmp_prompt.append(" ");
2639 }
2640 EventSP new_event_sp;
2641 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
2642 new EventDataBytes (tmp_prompt.c_str())));
2643
2644 if (instance_name.GetLength() != 0)
2645 {
2646 // Set prompt for a particular instance.
2647 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
2648 if (dbg != NULL)
2649 {
2650 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
2651 }
2652 }
2653
2654 return true;
2655}
2656
2657const ConstString
2658DebuggerInstanceSettings::CreateInstanceName ()
2659{
2660 static int instance_count = 1;
2661 StreamString sstr;
2662
2663 sstr.Printf ("debugger_%d", instance_count);
2664 ++instance_count;
2665
2666 const ConstString ret_val (sstr.GetData());
2667
2668 return ret_val;
2669}
2670
Jim Ingham3bcdb292010-10-04 22:44:14 +00002671
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002672//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002673// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002674//--------------------------------------------------
2675
2676
2677SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002678Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002679{
2680 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00002681 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
2682 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002683 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
2684};
2685
Greg Claytonbb562b12010-10-04 02:44:26 +00002686#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00002687#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002688
Greg Clayton0603aa92010-10-04 01:05:56 +00002689#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2690 "{, ${frame.pc}}"\
2691 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00002692 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00002693 "{, stop reason = ${thread.stop-reason}}"\
Jim Inghamef651602011-12-22 19:12:40 +00002694 "{\\nReturn value: ${thread.return-value}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00002695 "\\n"
2696
Greg Clayton315d2ca2010-11-02 01:53:21 +00002697//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2698// "{, ${frame.pc}}"\
2699// MODULE_WITH_FUNC\
2700// FILE_AND_LINE\
2701// "{, stop reason = ${thread.stop-reason}}"\
2702// "{, name = ${thread.name}}"\
2703// "{, queue = ${thread.queue}}"\
2704// "\\n"
2705
Greg Clayton0603aa92010-10-04 01:05:56 +00002706#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
2707 MODULE_WITH_FUNC\
2708 FILE_AND_LINE\
2709 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002710
2711SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002712Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002713{
Greg Clayton0603aa92010-10-04 01:05:56 +00002714// NAME Setting variable type Default Enum Init'd Hidden Help
2715// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00002716{ "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 +00002717{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00002718{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
2719{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002720{ "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 +00002721{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
2722{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
2723{ "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." },
2724{ "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." },
2725{ "stop-disassembly-count", eSetVarTypeInt, "0", NULL, false, false, "The number of disassembly lines to show when displaying a stopped context." },
2726{ "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 +00002727{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002728};