blob: ad6b86f044b0f8c099532c05d863fcdabb26bebc [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
Enrico Granata061858c2012-02-15 02:34:21 +0000732uint32_t
733Debugger::GetNumDebuggers()
734{
735 Mutex::Locker locker (GetDebuggerListMutex ());
736 return GetDebuggerList().size();
737}
738
739lldb::DebuggerSP
740Debugger::GetDebuggerAtIndex (uint32_t index)
741{
742 DebuggerSP debugger_sp;
743
744 Mutex::Locker locker (GetDebuggerListMutex ());
745 DebuggerList &debugger_list = GetDebuggerList();
746
747 if (index < debugger_list.size())
748 debugger_sp = debugger_list[index];
749
750 return debugger_sp;
751}
752
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000753DebuggerSP
754Debugger::FindDebuggerWithID (lldb::user_id_t id)
755{
Greg Clayton4d122c42011-09-17 08:33:22 +0000756 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000757
758 Mutex::Locker locker (GetDebuggerListMutex ());
759 DebuggerList &debugger_list = GetDebuggerList();
760 DebuggerList::iterator pos, end = debugger_list.end();
761 for (pos = debugger_list.begin(); pos != end; ++pos)
762 {
763 if ((*pos).get()->GetID() == id)
764 {
765 debugger_sp = *pos;
766 break;
767 }
768 }
769 return debugger_sp;
770}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000771
Greg Clayton1b654882010-09-19 02:33:57 +0000772static void
773TestPromptFormats (StackFrame *frame)
774{
775 if (frame == NULL)
776 return;
777
778 StreamString s;
779 const char *prompt_format =
780 "{addr = '${addr}'\n}"
781 "{process.id = '${process.id}'\n}"
782 "{process.name = '${process.name}'\n}"
783 "{process.file.basename = '${process.file.basename}'\n}"
784 "{process.file.fullpath = '${process.file.fullpath}'\n}"
785 "{thread.id = '${thread.id}'\n}"
786 "{thread.index = '${thread.index}'\n}"
787 "{thread.name = '${thread.name}'\n}"
788 "{thread.queue = '${thread.queue}'\n}"
789 "{thread.stop-reason = '${thread.stop-reason}'\n}"
790 "{target.arch = '${target.arch}'\n}"
791 "{module.file.basename = '${module.file.basename}'\n}"
792 "{module.file.fullpath = '${module.file.fullpath}'\n}"
793 "{file.basename = '${file.basename}'\n}"
794 "{file.fullpath = '${file.fullpath}'\n}"
795 "{frame.index = '${frame.index}'\n}"
796 "{frame.pc = '${frame.pc}'\n}"
797 "{frame.sp = '${frame.sp}'\n}"
798 "{frame.fp = '${frame.fp}'\n}"
799 "{frame.flags = '${frame.flags}'\n}"
800 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
801 "{frame.reg.rip = '${frame.reg.rip}'\n}"
802 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
803 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
804 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
805 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
806 "{frame.reg.carp = '${frame.reg.carp}'\n}"
807 "{function.id = '${function.id}'\n}"
808 "{function.name = '${function.name}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +0000809 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +0000810 "{function.addr-offset = '${function.addr-offset}'\n}"
811 "{function.line-offset = '${function.line-offset}'\n}"
812 "{function.pc-offset = '${function.pc-offset}'\n}"
813 "{line.file.basename = '${line.file.basename}'\n}"
814 "{line.file.fullpath = '${line.file.fullpath}'\n}"
815 "{line.number = '${line.number}'\n}"
816 "{line.start-addr = '${line.start-addr}'\n}"
817 "{line.end-addr = '${line.end-addr}'\n}"
818;
819
820 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
821 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000822 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000823 const char *end = NULL;
824 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
825 {
826 printf("%s\n", s.GetData());
827 }
828 else
829 {
830 printf ("error: at '%s'\n", end);
831 printf ("what we got: %s\n", s.GetData());
832 }
833}
834
Enrico Granata9fc19442011-07-06 02:13:41 +0000835static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000836ScanFormatDescriptor (const char* var_name_begin,
837 const char* var_name_end,
838 const char** var_name_final,
839 const char** percent_position,
Greg Clayton4d122c42011-09-17 08:33:22 +0000840 Format* custom_format,
Enrico Granatadc940732011-08-23 00:32:52 +0000841 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
Enrico Granata9fc19442011-07-06 02:13:41 +0000842{
Enrico Granatae992a082011-07-22 17:03:19 +0000843 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000844 *percent_position = ::strchr(var_name_begin,'%');
Greg Clayton34132752011-07-06 04:07:21 +0000845 if (!*percent_position || *percent_position > var_name_end)
Enrico Granatae992a082011-07-22 17:03:19 +0000846 {
847 if (log)
848 log->Printf("no format descriptor in string, skipping");
Enrico Granata9fc19442011-07-06 02:13:41 +0000849 *var_name_final = var_name_end;
Enrico Granatae992a082011-07-22 17:03:19 +0000850 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000851 else
852 {
853 *var_name_final = *percent_position;
854 char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0';
855 memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1);
Enrico Granatae992a082011-07-22 17:03:19 +0000856 if (log)
857 log->Printf("parsing %s as a format descriptor", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000858 if ( !FormatManager::GetFormatFromCString(format_name,
859 true,
860 *custom_format) )
861 {
Enrico Granatae992a082011-07-22 17:03:19 +0000862 if (log)
863 log->Printf("%s is an unknown format", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000864 // if this is an @ sign, print ObjC description
Greg Clayton34132752011-07-06 04:07:21 +0000865 if (*format_name == '@')
Enrico Granata9fc19442011-07-06 02:13:41 +0000866 *val_obj_display = ValueObject::eDisplayLanguageSpecific;
867 // if this is a V, print the value using the default format
Enrico Granatae992a082011-07-22 17:03:19 +0000868 else if (*format_name == 'V')
Enrico Granata9fc19442011-07-06 02:13:41 +0000869 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatad55546b2011-07-22 00:16:08 +0000870 // if this is an L, print the location of the value
Enrico Granatae992a082011-07-22 17:03:19 +0000871 else if (*format_name == 'L')
Enrico Granataf2bbf712011-07-15 02:26:42 +0000872 *val_obj_display = ValueObject::eDisplayLocation;
Enrico Granatad55546b2011-07-22 00:16:08 +0000873 // if this is an S, print the summary after all
Enrico Granatae992a082011-07-22 17:03:19 +0000874 else if (*format_name == 'S')
Enrico Granatad55546b2011-07-22 00:16:08 +0000875 *val_obj_display = ValueObject::eDisplaySummary;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000876 else if (*format_name == '#')
877 *val_obj_display = ValueObject::eDisplayChildrenCount;
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000878 else if (*format_name == 'T')
879 *val_obj_display = ValueObject::eDisplayType;
Enrico Granatae992a082011-07-22 17:03:19 +0000880 else if (log)
881 log->Printf("%s is an error, leaving the previous value alone", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000882 }
883 // a good custom format tells us to print the value using it
884 else
Enrico Granatae992a082011-07-22 17:03:19 +0000885 {
886 if (log)
887 log->Printf("will display value for this VO");
Enrico Granata9fc19442011-07-06 02:13:41 +0000888 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatae992a082011-07-22 17:03:19 +0000889 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000890 delete format_name;
891 }
Enrico Granatae992a082011-07-22 17:03:19 +0000892 if (log)
893 log->Printf("final format description outcome: custom_format = %d, val_obj_display = %d",
894 *custom_format,
895 *val_obj_display);
Enrico Granata9fc19442011-07-06 02:13:41 +0000896 return true;
897}
898
899static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000900ScanBracketedRange (const char* var_name_begin,
901 const char* var_name_end,
902 const char* var_name_final,
903 const char** open_bracket_position,
904 const char** separator_position,
905 const char** close_bracket_position,
906 const char** var_name_final_if_array_range,
907 int64_t* index_lower,
908 int64_t* index_higher)
Enrico Granata9fc19442011-07-06 02:13:41 +0000909{
Enrico Granatae992a082011-07-22 17:03:19 +0000910 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000911 *open_bracket_position = ::strchr(var_name_begin,'[');
Greg Clayton34132752011-07-06 04:07:21 +0000912 if (*open_bracket_position && *open_bracket_position < var_name_final)
Enrico Granata9fc19442011-07-06 02:13:41 +0000913 {
914 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
915 *close_bracket_position = ::strchr(*open_bracket_position,']');
916 // as usual, we assume that [] will come before %
917 //printf("trying to expand a []\n");
918 *var_name_final_if_array_range = *open_bracket_position;
Greg Clayton34132752011-07-06 04:07:21 +0000919 if (*close_bracket_position - *open_bracket_position == 1)
Enrico Granata9fc19442011-07-06 02:13:41 +0000920 {
Enrico Granatae992a082011-07-22 17:03:19 +0000921 if (log)
922 log->Printf("[] detected.. going from 0 to end of data");
Enrico Granata9fc19442011-07-06 02:13:41 +0000923 *index_lower = 0;
924 }
925 else if (*separator_position == NULL || *separator_position > var_name_end)
926 {
927 char *end = NULL;
928 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
929 *index_higher = *index_lower;
Enrico Granatae992a082011-07-22 17:03:19 +0000930 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000931 log->Printf("[%lld] detected, high index is same", *index_lower);
Enrico Granata9fc19442011-07-06 02:13:41 +0000932 }
Greg Clayton34132752011-07-06 04:07:21 +0000933 else if (*close_bracket_position && *close_bracket_position < var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +0000934 {
935 char *end = NULL;
936 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
937 *index_higher = ::strtoul (*separator_position+1, &end, 0);
Enrico Granatae992a082011-07-22 17:03:19 +0000938 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000939 log->Printf("[%lld-%lld] detected", *index_lower, *index_higher);
Enrico Granata9fc19442011-07-06 02:13:41 +0000940 }
941 else
Enrico Granatae992a082011-07-22 17:03:19 +0000942 {
943 if (log)
944 log->Printf("expression is erroneous, cannot extract indices out of it");
Enrico Granata9fc19442011-07-06 02:13:41 +0000945 return false;
Enrico Granatae992a082011-07-22 17:03:19 +0000946 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000947 if (*index_lower > *index_higher && *index_higher > 0)
948 {
Enrico Granatae992a082011-07-22 17:03:19 +0000949 if (log)
950 log->Printf("swapping indices");
Enrico Granata9fc19442011-07-06 02:13:41 +0000951 int temp = *index_lower;
952 *index_lower = *index_higher;
953 *index_higher = temp;
954 }
955 }
Enrico Granatae992a082011-07-22 17:03:19 +0000956 else if (log)
957 log->Printf("no bracketed range, skipping entirely");
Enrico Granata9fc19442011-07-06 02:13:41 +0000958 return true;
959}
960
961
962static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000963ExpandExpressionPath (ValueObject* valobj,
964 StackFrame* frame,
965 bool* do_deref_pointer,
966 const char* var_name_begin,
967 const char* var_name_final,
968 Error& error)
Enrico Granata9fc19442011-07-06 02:13:41 +0000969{
Enrico Granatae992a082011-07-22 17:03:19 +0000970 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000971 StreamString sstring;
972 VariableSP var_sp;
973
Greg Clayton34132752011-07-06 04:07:21 +0000974 if (*do_deref_pointer)
Enrico Granatae992a082011-07-22 17:03:19 +0000975 {
976 if (log)
977 log->Printf("been told to deref_pointer by caller");
Enrico Granata9fc19442011-07-06 02:13:41 +0000978 sstring.PutChar('*');
Enrico Granatae992a082011-07-22 17:03:19 +0000979 }
Enrico Granatac482a192011-08-17 22:13:59 +0000980 else if (valobj->IsDereferenceOfParent() && ClangASTContext::IsPointerType(valobj->GetParent()->GetClangType()) && !valobj->IsArrayItemForPointer())
Enrico Granata9fc19442011-07-06 02:13:41 +0000981 {
Enrico Granatae992a082011-07-22 17:03:19 +0000982 if (log)
983 log->Printf("decided to deref_pointer myself");
Enrico Granata9fc19442011-07-06 02:13:41 +0000984 sstring.PutChar('*');
985 *do_deref_pointer = true;
986 }
987
Enrico Granatac482a192011-08-17 22:13:59 +0000988 valobj->GetExpressionPath(sstring, true, ValueObject::eHonorPointers);
Enrico Granatae992a082011-07-22 17:03:19 +0000989 if (log)
990 log->Printf("expression path to expand in phase 0: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000991 sstring.PutRawBytes(var_name_begin+3, var_name_final-var_name_begin-3);
Enrico Granatae992a082011-07-22 17:03:19 +0000992 if (log)
993 log->Printf("expression path to expand in phase 1: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000994 std::string name = std::string(sstring.GetData());
995 ValueObjectSP target = frame->GetValueForVariableExpressionPath (name.c_str(),
996 eNoDynamicValues,
997 0,
998 var_sp,
999 error);
1000 return target;
1001}
1002
1003static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +00001004ExpandIndexedExpression (ValueObject* valobj,
1005 uint32_t index,
1006 StackFrame* frame,
1007 bool deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +00001008{
Enrico Granatae992a082011-07-22 17:03:19 +00001009 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001010 const char* ptr_deref_format = "[%d]";
1011 std::auto_ptr<char> ptr_deref_buffer(new char[10]);
1012 ::sprintf(ptr_deref_buffer.get(), ptr_deref_format, index);
Enrico Granatae992a082011-07-22 17:03:19 +00001013 if (log)
1014 log->Printf("name to deref: %s",ptr_deref_buffer.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001015 const char* first_unparsed;
1016 ValueObject::GetValueForExpressionPathOptions options;
1017 ValueObject::ExpressionPathEndResultType final_value_type;
1018 ValueObject::ExpressionPathScanEndReason reason_to_stop;
1019 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eDereference : ValueObject::eNothing);
Enrico Granatac482a192011-08-17 22:13:59 +00001020 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001021 &first_unparsed,
1022 &reason_to_stop,
1023 &final_value_type,
1024 options,
1025 &what_next);
1026 if (!item)
1027 {
Enrico Granatae992a082011-07-22 17:03:19 +00001028 if (log)
1029 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1030 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001031 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001032 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001033 else
1034 {
Enrico Granatae992a082011-07-22 17:03:19 +00001035 if (log)
1036 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1037 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001038 first_unparsed, reason_to_stop, final_value_type);
Enrico Granata9fc19442011-07-06 02:13:41 +00001039 }
1040 return item;
1041}
1042
Greg Clayton1b654882010-09-19 02:33:57 +00001043bool
1044Debugger::FormatPrompt
1045(
1046 const char *format,
1047 const SymbolContext *sc,
1048 const ExecutionContext *exe_ctx,
1049 const Address *addr,
1050 Stream &s,
Enrico Granata4becb372011-06-29 22:27:15 +00001051 const char **end,
Enrico Granatac482a192011-08-17 22:13:59 +00001052 ValueObject* valobj
Greg Clayton1b654882010-09-19 02:33:57 +00001053)
1054{
Enrico Granatac482a192011-08-17 22:13:59 +00001055 ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers
Greg Clayton1b654882010-09-19 02:33:57 +00001056 bool success = true;
1057 const char *p;
Enrico Granatae992a082011-07-22 17:03:19 +00001058 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Greg Clayton1b654882010-09-19 02:33:57 +00001059 for (p = format; *p != '\0'; ++p)
1060 {
Enrico Granatac482a192011-08-17 22:13:59 +00001061 if (realvalobj)
Enrico Granata4becb372011-06-29 22:27:15 +00001062 {
Enrico Granatac482a192011-08-17 22:13:59 +00001063 valobj = realvalobj;
1064 realvalobj = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00001065 }
Greg Clayton1b654882010-09-19 02:33:57 +00001066 size_t non_special_chars = ::strcspn (p, "${}\\");
1067 if (non_special_chars > 0)
1068 {
1069 if (success)
1070 s.Write (p, non_special_chars);
1071 p += non_special_chars;
1072 }
1073
1074 if (*p == '\0')
1075 {
1076 break;
1077 }
1078 else if (*p == '{')
1079 {
1080 // Start a new scope that must have everything it needs if it is to
1081 // to make it into the final output stream "s". If you want to make
1082 // a format that only prints out the function or symbol name if there
1083 // is one in the symbol context you can use:
1084 // "{function =${function.name}}"
1085 // The first '{' starts a new scope that end with the matching '}' at
1086 // the end of the string. The contents "function =${function.name}"
1087 // will then be evaluated and only be output if there is a function
1088 // or symbol with a valid name.
1089 StreamString sub_strm;
1090
1091 ++p; // Skip the '{'
1092
Enrico Granatac482a192011-08-17 22:13:59 +00001093 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
Greg Clayton1b654882010-09-19 02:33:57 +00001094 {
1095 // The stream had all it needed
1096 s.Write(sub_strm.GetData(), sub_strm.GetSize());
1097 }
1098 if (*p != '}')
1099 {
1100 success = false;
1101 break;
1102 }
1103 }
1104 else if (*p == '}')
1105 {
1106 // End of a enclosing scope
1107 break;
1108 }
1109 else if (*p == '$')
1110 {
1111 // We have a prompt variable to print
1112 ++p;
1113 if (*p == '{')
1114 {
1115 ++p;
1116 const char *var_name_begin = p;
1117 const char *var_name_end = ::strchr (p, '}');
1118
1119 if (var_name_end && var_name_begin < var_name_end)
1120 {
1121 // if we have already failed to parse, skip this variable
1122 if (success)
1123 {
1124 const char *cstr = NULL;
1125 Address format_addr;
1126 bool calculate_format_addr_function_offset = false;
1127 // Set reg_kind and reg_num to invalid values
1128 RegisterKind reg_kind = kNumRegisterKinds;
1129 uint32_t reg_num = LLDB_INVALID_REGNUM;
1130 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +00001131 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00001132 RegisterContext *reg_ctx = NULL;
Enrico Granata9fc19442011-07-06 02:13:41 +00001133 bool do_deref_pointer = false;
Enrico Granatae992a082011-07-22 17:03:19 +00001134 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eEndOfString;
1135 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::ePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001136
Greg Clayton1b654882010-09-19 02:33:57 +00001137 // Each variable must set success to true below...
1138 bool var_success = false;
1139 switch (var_name_begin[0])
1140 {
Enrico Granata4becb372011-06-29 22:27:15 +00001141 case '*':
Enrico Granata4becb372011-06-29 22:27:15 +00001142 case 'v':
Enrico Granata6f3533f2011-07-29 19:53:35 +00001143 case 's':
Enrico Granata4becb372011-06-29 22:27:15 +00001144 {
Enrico Granatac482a192011-08-17 22:13:59 +00001145 if (!valobj)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001146 break;
1147
Enrico Granatac3e320a2011-08-02 17:27:39 +00001148 if (log)
1149 log->Printf("initial string: %s",var_name_begin);
1150
Enrico Granata6f3533f2011-07-29 19:53:35 +00001151 // check for *var and *svar
1152 if (*var_name_begin == '*')
1153 {
1154 do_deref_pointer = true;
1155 var_name_begin++;
1156 }
Enrico Granatac3e320a2011-08-02 17:27:39 +00001157
1158 if (log)
1159 log->Printf("initial string: %s",var_name_begin);
1160
Enrico Granata6f3533f2011-07-29 19:53:35 +00001161 if (*var_name_begin == 's')
1162 {
Greg Clayton4d122c42011-09-17 08:33:22 +00001163 valobj = valobj->GetSyntheticValue(eUseSyntheticFilter).get();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001164 var_name_begin++;
1165 }
1166
Enrico Granatac3e320a2011-08-02 17:27:39 +00001167 if (log)
1168 log->Printf("initial string: %s",var_name_begin);
1169
Enrico Granata6f3533f2011-07-29 19:53:35 +00001170 // should be a 'v' by now
1171 if (*var_name_begin != 'v')
1172 break;
1173
Enrico Granatac3e320a2011-08-02 17:27:39 +00001174 if (log)
1175 log->Printf("initial string: %s",var_name_begin);
1176
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001177 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
1178 ValueObject::eDereference : ValueObject::eNothing);
1179 ValueObject::GetValueForExpressionPathOptions options;
Enrico Granata8c9d3562011-08-11 17:08:01 +00001180 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren();
Greg Clayton34132752011-07-06 04:07:21 +00001181 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eDisplaySummary;
1182 ValueObject* target = NULL;
Greg Clayton4d122c42011-09-17 08:33:22 +00001183 Format custom_format = eFormatInvalid;
Greg Clayton34132752011-07-06 04:07:21 +00001184 const char* var_name_final = NULL;
1185 const char* var_name_final_if_array_range = NULL;
1186 const char* close_bracket_position = NULL;
1187 int64_t index_lower = -1;
1188 int64_t index_higher = -1;
1189 bool is_array_range = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001190 const char* first_unparsed;
Enrico Granata85933ed2011-08-18 16:38:26 +00001191 bool was_plain_var = false;
1192 bool was_var_format = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001193
Enrico Granatac482a192011-08-17 22:13:59 +00001194 if (!valobj) break;
1195 // simplest case ${var}, just print valobj's value
Greg Clayton34132752011-07-06 04:07:21 +00001196 if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0)
Enrico Granata4becb372011-06-29 22:27:15 +00001197 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001198 was_plain_var = true;
Enrico Granatac482a192011-08-17 22:13:59 +00001199 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001200 val_obj_display = ValueObject::eDisplayValue;
1201 }
1202 else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0)
1203 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001204 was_var_format = true;
Greg Clayton34132752011-07-06 04:07:21 +00001205 // this is a variable with some custom format applied to it
1206 const char* percent_position;
Enrico Granatac482a192011-08-17 22:13:59 +00001207 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001208 val_obj_display = ValueObject::eDisplayValue;
1209 ScanFormatDescriptor (var_name_begin,
1210 var_name_end,
1211 &var_name_final,
1212 &percent_position,
1213 &custom_format,
1214 &val_obj_display);
1215 }
1216 // this is ${var.something} or multiple .something nested
1217 else if (::strncmp (var_name_begin, "var", strlen("var")) == 0)
1218 {
1219
1220 const char* percent_position;
1221 ScanFormatDescriptor (var_name_begin,
1222 var_name_end,
1223 &var_name_final,
1224 &percent_position,
1225 &custom_format,
1226 &val_obj_display);
1227
1228 const char* open_bracket_position;
1229 const char* separator_position;
1230 ScanBracketedRange (var_name_begin,
1231 var_name_end,
1232 var_name_final,
1233 &open_bracket_position,
1234 &separator_position,
1235 &close_bracket_position,
1236 &var_name_final_if_array_range,
1237 &index_lower,
1238 &index_higher);
1239
1240 Error error;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001241
1242 std::auto_ptr<char> expr_path(new char[var_name_final-var_name_begin-1]);
1243 ::memset(expr_path.get(), 0, var_name_final-var_name_begin-1);
1244 memcpy(expr_path.get(), var_name_begin+3,var_name_final-var_name_begin-3);
1245
Enrico Granatae992a082011-07-22 17:03:19 +00001246 if (log)
1247 log->Printf("symbol to expand: %s",expr_path.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001248
Enrico Granatac482a192011-08-17 22:13:59 +00001249 target = valobj->GetValueForExpressionPath(expr_path.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001250 &first_unparsed,
1251 &reason_to_stop,
1252 &final_value_type,
1253 options,
1254 &what_next).get();
1255
1256 if (!target)
Enrico Granata9fc19442011-07-06 02:13:41 +00001257 {
Enrico Granatae992a082011-07-22 17:03:19 +00001258 if (log)
1259 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1260 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001261 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001262 break;
Enrico Granata9fc19442011-07-06 02:13:41 +00001263 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001264 else
1265 {
Enrico Granatae992a082011-07-22 17:03:19 +00001266 if (log)
1267 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1268 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001269 first_unparsed, reason_to_stop, final_value_type);
1270 }
Enrico Granata4becb372011-06-29 22:27:15 +00001271 }
Greg Clayton34132752011-07-06 04:07:21 +00001272 else
Enrico Granata9fc19442011-07-06 02:13:41 +00001273 break;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001274
1275 is_array_range = (final_value_type == ValueObject::eBoundedRange ||
1276 final_value_type == ValueObject::eUnboundedRange);
1277
1278 do_deref_pointer = (what_next == ValueObject::eDereference);
Enrico Granata9fc19442011-07-06 02:13:41 +00001279
Enrico Granataa7187d02011-07-06 19:27:11 +00001280 if (do_deref_pointer && !is_array_range)
Enrico Granata9fc19442011-07-06 02:13:41 +00001281 {
Greg Clayton34132752011-07-06 04:07:21 +00001282 // I have not deref-ed yet, let's do it
1283 // this happens when we are not going through GetValueForVariableExpressionPath
1284 // to get to the target ValueObject
Enrico Granata9fc19442011-07-06 02:13:41 +00001285 Error error;
Greg Clayton34132752011-07-06 04:07:21 +00001286 target = target->Dereference(error).get();
Enrico Granatadc940732011-08-23 00:32:52 +00001287 if (error.Fail())
1288 {
1289 if (log)
1290 log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
1291 break;
1292 }
Greg Clayton34132752011-07-06 04:07:21 +00001293 do_deref_pointer = false;
Enrico Granata9fc19442011-07-06 02:13:41 +00001294 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001295
Enrico Granata85933ed2011-08-18 16:38:26 +00001296 // TODO use flags for these
Enrico Granataf4efecd2011-07-12 22:56:10 +00001297 bool is_array = ClangASTContext::IsArrayType(target->GetClangType());
1298 bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType());
Enrico Granata85933ed2011-08-18 16:38:26 +00001299 bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType());
Enrico Granataf4efecd2011-07-12 22:56:10 +00001300
1301 if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eDisplayValue) // this should be wrong, but there are some exceptions
1302 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001303 StreamString str_temp;
Enrico Granatae992a082011-07-22 17:03:19 +00001304 if (log)
1305 log->Printf("I am into array || pointer && !range");
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001306
1307 if (target->HasSpecialCasesForPrintableRepresentation(val_obj_display,
1308 custom_format))
Enrico Granata85933ed2011-08-18 16:38:26 +00001309 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001310 // try to use the special cases
1311 var_success = target->DumpPrintableRepresentation(str_temp,
1312 val_obj_display,
1313 custom_format);
1314 if (log)
1315 log->Printf("special cases did%s match", var_success ? "" : "n't");
1316
1317 // should not happen
1318 if (!var_success)
1319 s << "<invalid usage of pointer value as object>";
1320 else
1321 s << str_temp.GetData();
Enrico Granata85933ed2011-08-18 16:38:26 +00001322 var_success = true;
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001323 break;
Enrico Granata85933ed2011-08-18 16:38:26 +00001324 }
1325 else
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001326 {
Enrico Granata88da35f2011-08-23 21:26:09 +00001327 if (was_plain_var) // if ${var}
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001328 {
1329 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1330 }
Enrico Granata88da35f2011-08-23 21:26:09 +00001331 else if (is_pointer) // if pointer, value is the address stored
1332 {
1333 var_success = target->GetPrintableRepresentation(s,
1334 val_obj_display,
1335 custom_format);
1336 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001337 else
1338 {
1339 s << "<invalid usage of pointer value as object>";
1340 }
1341 var_success = true;
1342 break;
1343 }
1344 }
1345
1346 // if directly trying to print ${var}, and this is an aggregate, display a nice
1347 // type @ location message
1348 if (is_aggregate && was_plain_var)
1349 {
1350 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1351 var_success = true;
Enrico Granata85933ed2011-08-18 16:38:26 +00001352 break;
1353 }
1354
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001355 // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it
1356 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eDisplayValue)))
Enrico Granata85933ed2011-08-18 16:38:26 +00001357 {
1358 s << "<invalid use of aggregate type>";
1359 var_success = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001360 break;
1361 }
Greg Clayton34132752011-07-06 04:07:21 +00001362
1363 if (!is_array_range)
Enrico Granatae992a082011-07-22 17:03:19 +00001364 {
1365 if (log)
1366 log->Printf("dumping ordinary printable output");
Greg Clayton34132752011-07-06 04:07:21 +00001367 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
Enrico Granatae992a082011-07-22 17:03:19 +00001368 }
Greg Clayton34132752011-07-06 04:07:21 +00001369 else
Enrico Granatae992a082011-07-22 17:03:19 +00001370 {
1371 if (log)
1372 log->Printf("checking if I can handle as array");
Greg Clayton34132752011-07-06 04:07:21 +00001373 if (!is_array && !is_pointer)
1374 break;
Enrico Granatae992a082011-07-22 17:03:19 +00001375 if (log)
1376 log->Printf("handle as array");
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001377 const char* special_directions = NULL;
1378 StreamString special_directions_writer;
Greg Clayton34132752011-07-06 04:07:21 +00001379 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1380 {
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001381 ConstString additional_data;
1382 additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1);
1383 special_directions_writer.Printf("${%svar%s}",
1384 do_deref_pointer ? "*" : "",
1385 additional_data.GetCString());
1386 special_directions = special_directions_writer.GetData();
Greg Clayton34132752011-07-06 04:07:21 +00001387 }
1388
1389 // let us display items index_lower thru index_higher of this array
1390 s.PutChar('[');
1391 var_success = true;
1392
1393 if (index_higher < 0)
Enrico Granatac482a192011-08-17 22:13:59 +00001394 index_higher = valobj->GetNumChildren() - 1;
Greg Clayton34132752011-07-06 04:07:21 +00001395
Enrico Granata22c55d12011-08-12 02:00:06 +00001396 uint32_t max_num_children = target->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
1397
Greg Clayton34132752011-07-06 04:07:21 +00001398 for (;index_lower<=index_higher;index_lower++)
1399 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001400 ValueObject* item = ExpandIndexedExpression (target,
1401 index_lower,
1402 exe_ctx->GetFramePtr(),
1403 false).get();
Greg Clayton34132752011-07-06 04:07:21 +00001404
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001405 if (!item)
1406 {
Enrico Granatae992a082011-07-22 17:03:19 +00001407 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001408 log->Printf("ERROR in getting child item at index %lld", index_lower);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001409 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001410 else
1411 {
Enrico Granatae992a082011-07-22 17:03:19 +00001412 if (log)
1413 log->Printf("special_directions for child item: %s",special_directions);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001414 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001415
Greg Clayton34132752011-07-06 04:07:21 +00001416 if (!special_directions)
1417 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1418 else
1419 var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
1420
Enrico Granata22c55d12011-08-12 02:00:06 +00001421 if (--max_num_children == 0)
1422 {
1423 s.PutCString(", ...");
1424 break;
1425 }
1426
Greg Clayton34132752011-07-06 04:07:21 +00001427 if (index_lower < index_higher)
1428 s.PutChar(',');
1429 }
1430 s.PutChar(']');
1431 }
Enrico Granata4becb372011-06-29 22:27:15 +00001432 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001433 break;
Greg Clayton1b654882010-09-19 02:33:57 +00001434 case 'a':
1435 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
1436 {
1437 if (addr && addr->IsValid())
1438 {
1439 var_success = true;
1440 format_addr = *addr;
1441 }
1442 }
Greg Clayton5a314712011-10-14 07:41:33 +00001443 else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0)
1444 {
1445 var_success = true;
1446 var_name_begin += strlen("ansi."); // Skip the "ansi."
1447 if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0)
1448 {
1449 var_name_begin += strlen("fg."); // Skip the "fg."
1450 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1451 {
1452 s.Printf ("%s%s%s",
1453 lldb_utility::ansi::k_escape_start,
1454 lldb_utility::ansi::k_fg_black,
1455 lldb_utility::ansi::k_escape_end);
1456 }
1457 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1458 {
1459 s.Printf ("%s%s%s",
1460 lldb_utility::ansi::k_escape_start,
1461 lldb_utility::ansi::k_fg_red,
1462 lldb_utility::ansi::k_escape_end);
1463 }
1464 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1465 {
1466 s.Printf ("%s%s%s",
1467 lldb_utility::ansi::k_escape_start,
1468 lldb_utility::ansi::k_fg_green,
1469 lldb_utility::ansi::k_escape_end);
1470 }
1471 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1472 {
1473 s.Printf ("%s%s%s",
1474 lldb_utility::ansi::k_escape_start,
1475 lldb_utility::ansi::k_fg_yellow,
1476 lldb_utility::ansi::k_escape_end);
1477 }
1478 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1479 {
1480 s.Printf ("%s%s%s",
1481 lldb_utility::ansi::k_escape_start,
1482 lldb_utility::ansi::k_fg_blue,
1483 lldb_utility::ansi::k_escape_end);
1484 }
1485 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1486 {
1487 s.Printf ("%s%s%s",
1488 lldb_utility::ansi::k_escape_start,
1489 lldb_utility::ansi::k_fg_purple,
1490 lldb_utility::ansi::k_escape_end);
1491 }
1492 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1493 {
1494 s.Printf ("%s%s%s",
1495 lldb_utility::ansi::k_escape_start,
1496 lldb_utility::ansi::k_fg_cyan,
1497 lldb_utility::ansi::k_escape_end);
1498 }
1499 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1500 {
1501 s.Printf ("%s%s%s",
1502 lldb_utility::ansi::k_escape_start,
1503 lldb_utility::ansi::k_fg_white,
1504 lldb_utility::ansi::k_escape_end);
1505 }
1506 else
1507 {
1508 var_success = false;
1509 }
1510 }
1511 else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0)
1512 {
1513 var_name_begin += strlen("bg."); // Skip the "bg."
1514 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1515 {
1516 s.Printf ("%s%s%s",
1517 lldb_utility::ansi::k_escape_start,
1518 lldb_utility::ansi::k_bg_black,
1519 lldb_utility::ansi::k_escape_end);
1520 }
1521 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1522 {
1523 s.Printf ("%s%s%s",
1524 lldb_utility::ansi::k_escape_start,
1525 lldb_utility::ansi::k_bg_red,
1526 lldb_utility::ansi::k_escape_end);
1527 }
1528 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1529 {
1530 s.Printf ("%s%s%s",
1531 lldb_utility::ansi::k_escape_start,
1532 lldb_utility::ansi::k_bg_green,
1533 lldb_utility::ansi::k_escape_end);
1534 }
1535 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1536 {
1537 s.Printf ("%s%s%s",
1538 lldb_utility::ansi::k_escape_start,
1539 lldb_utility::ansi::k_bg_yellow,
1540 lldb_utility::ansi::k_escape_end);
1541 }
1542 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1543 {
1544 s.Printf ("%s%s%s",
1545 lldb_utility::ansi::k_escape_start,
1546 lldb_utility::ansi::k_bg_blue,
1547 lldb_utility::ansi::k_escape_end);
1548 }
1549 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1550 {
1551 s.Printf ("%s%s%s",
1552 lldb_utility::ansi::k_escape_start,
1553 lldb_utility::ansi::k_bg_purple,
1554 lldb_utility::ansi::k_escape_end);
1555 }
1556 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1557 {
1558 s.Printf ("%s%s%s",
1559 lldb_utility::ansi::k_escape_start,
1560 lldb_utility::ansi::k_bg_cyan,
1561 lldb_utility::ansi::k_escape_end);
1562 }
1563 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1564 {
1565 s.Printf ("%s%s%s",
1566 lldb_utility::ansi::k_escape_start,
1567 lldb_utility::ansi::k_bg_white,
1568 lldb_utility::ansi::k_escape_end);
1569 }
1570 else
1571 {
1572 var_success = false;
1573 }
1574 }
1575 else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0)
1576 {
1577 s.Printf ("%s%s%s",
1578 lldb_utility::ansi::k_escape_start,
1579 lldb_utility::ansi::k_ctrl_normal,
1580 lldb_utility::ansi::k_escape_end);
1581 }
1582 else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0)
1583 {
1584 s.Printf ("%s%s%s",
1585 lldb_utility::ansi::k_escape_start,
1586 lldb_utility::ansi::k_ctrl_bold,
1587 lldb_utility::ansi::k_escape_end);
1588 }
1589 else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0)
1590 {
1591 s.Printf ("%s%s%s",
1592 lldb_utility::ansi::k_escape_start,
1593 lldb_utility::ansi::k_ctrl_faint,
1594 lldb_utility::ansi::k_escape_end);
1595 }
1596 else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0)
1597 {
1598 s.Printf ("%s%s%s",
1599 lldb_utility::ansi::k_escape_start,
1600 lldb_utility::ansi::k_ctrl_italic,
1601 lldb_utility::ansi::k_escape_end);
1602 }
1603 else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0)
1604 {
1605 s.Printf ("%s%s%s",
1606 lldb_utility::ansi::k_escape_start,
1607 lldb_utility::ansi::k_ctrl_underline,
1608 lldb_utility::ansi::k_escape_end);
1609 }
1610 else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0)
1611 {
1612 s.Printf ("%s%s%s",
1613 lldb_utility::ansi::k_escape_start,
1614 lldb_utility::ansi::k_ctrl_slow_blink,
1615 lldb_utility::ansi::k_escape_end);
1616 }
1617 else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0)
1618 {
1619 s.Printf ("%s%s%s",
1620 lldb_utility::ansi::k_escape_start,
1621 lldb_utility::ansi::k_ctrl_fast_blink,
1622 lldb_utility::ansi::k_escape_end);
1623 }
1624 else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0)
1625 {
1626 s.Printf ("%s%s%s",
1627 lldb_utility::ansi::k_escape_start,
1628 lldb_utility::ansi::k_ctrl_negative,
1629 lldb_utility::ansi::k_escape_end);
1630 }
1631 else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0)
1632 {
1633 s.Printf ("%s%s%s",
1634 lldb_utility::ansi::k_escape_start,
1635 lldb_utility::ansi::k_ctrl_conceal,
1636 lldb_utility::ansi::k_escape_end);
1637
1638 }
1639 else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0)
1640 {
1641 s.Printf ("%s%s%s",
1642 lldb_utility::ansi::k_escape_start,
1643 lldb_utility::ansi::k_ctrl_crossed_out,
1644 lldb_utility::ansi::k_escape_end);
1645 }
1646 else
1647 {
1648 var_success = false;
1649 }
1650 }
Greg Clayton1b654882010-09-19 02:33:57 +00001651 break;
1652
1653 case 'p':
1654 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
1655 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001656 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001657 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001658 Process *process = exe_ctx->GetProcessPtr();
1659 if (process)
Greg Clayton1b654882010-09-19 02:33:57 +00001660 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001661 var_name_begin += ::strlen ("process.");
1662 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001663 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001664 s.Printf("%llu", process->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001665 var_success = true;
1666 }
1667 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
1668 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
1669 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
1670 {
1671 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1672 if (exe_module)
Greg Clayton1b654882010-09-19 02:33:57 +00001673 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001674 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1675 {
1676 format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
1677 var_success = format_file_spec;
1678 }
1679 else
1680 {
1681 format_file_spec = exe_module->GetFileSpec();
1682 var_success = format_file_spec;
1683 }
Greg Clayton1b654882010-09-19 02:33:57 +00001684 }
1685 }
1686 }
Greg Claytonc14ee322011-09-22 04:58:26 +00001687 }
Greg Clayton1b654882010-09-19 02:33:57 +00001688 }
1689 break;
1690
1691 case 't':
1692 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
1693 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001694 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001695 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001696 Thread *thread = exe_ctx->GetThreadPtr();
1697 if (thread)
Greg Clayton1b654882010-09-19 02:33:57 +00001698 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001699 var_name_begin += ::strlen ("thread.");
1700 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001701 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001702 s.Printf("0x%4.4llx", thread->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001703 var_success = true;
1704 }
1705 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1706 {
1707 s.Printf("%u", thread->GetIndexID());
1708 var_success = true;
1709 }
1710 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1711 {
1712 cstr = thread->GetName();
1713 var_success = cstr && cstr[0];
1714 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001715 s.PutCString(cstr);
Greg Claytonc14ee322011-09-22 04:58:26 +00001716 }
1717 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
1718 {
1719 cstr = thread->GetQueueName();
1720 var_success = cstr && cstr[0];
1721 if (var_success)
1722 s.PutCString(cstr);
1723 }
1724 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
1725 {
1726 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1727 if (stop_info_sp)
1728 {
1729 cstr = stop_info_sp->GetDescription();
1730 if (cstr && cstr[0])
1731 {
1732 s.PutCString(cstr);
1733 var_success = true;
1734 }
Greg Clayton1b654882010-09-19 02:33:57 +00001735 }
1736 }
Jim Ingham73ca05a2011-12-17 01:35:57 +00001737 else if (::strncmp (var_name_begin, "return-value}", strlen("return-value}")) == 0)
1738 {
1739 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1740 if (stop_info_sp)
1741 {
1742 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1743 if (return_valobj_sp)
1744 {
Jim Inghamef651602011-12-22 19:12:40 +00001745 ValueObject::DumpValueObjectOptions dump_options;
1746 ValueObject::DumpValueObject (s, return_valobj_sp.get(), dump_options);
1747 var_success = true;
Jim Ingham73ca05a2011-12-17 01:35:57 +00001748 }
1749 }
1750 }
Greg Clayton1b654882010-09-19 02:33:57 +00001751 }
1752 }
1753 }
1754 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
1755 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001756 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1757 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +00001758 {
Greg Clayton1b654882010-09-19 02:33:57 +00001759 var_name_begin += ::strlen ("target.");
1760 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
1761 {
1762 ArchSpec arch (target->GetArchitecture ());
1763 if (arch.IsValid())
1764 {
Greg Clayton64195a22011-02-23 00:35:02 +00001765 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +00001766 var_success = true;
1767 }
1768 }
1769 }
1770 }
1771 break;
1772
1773
1774 case 'm':
1775 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
1776 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001777 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +00001778 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001779 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +00001780 var_name_begin += ::strlen ("module.");
1781
1782 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1783 {
1784 if (module->GetFileSpec())
1785 {
1786 var_name_begin += ::strlen ("file.");
1787
1788 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1789 {
1790 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
1791 var_success = format_file_spec;
1792 }
1793 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1794 {
1795 format_file_spec = module->GetFileSpec();
1796 var_success = format_file_spec;
1797 }
1798 }
1799 }
1800 }
1801 }
1802 break;
1803
1804
1805 case 'f':
1806 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1807 {
1808 if (sc && sc->comp_unit != NULL)
1809 {
1810 var_name_begin += ::strlen ("file.");
1811
1812 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1813 {
1814 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
1815 var_success = format_file_spec;
1816 }
1817 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1818 {
1819 format_file_spec = *sc->comp_unit;
1820 var_success = format_file_spec;
1821 }
1822 }
1823 }
1824 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
1825 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001826 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001827 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001828 StackFrame *frame = exe_ctx->GetFramePtr();
1829 if (frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001830 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001831 var_name_begin += ::strlen ("frame.");
1832 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001833 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001834 s.Printf("%u", frame->GetFrameIndex());
1835 var_success = true;
1836 }
1837 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
1838 {
1839 reg_kind = eRegisterKindGeneric;
1840 reg_num = LLDB_REGNUM_GENERIC_PC;
1841 var_success = true;
1842 }
1843 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
1844 {
1845 reg_kind = eRegisterKindGeneric;
1846 reg_num = LLDB_REGNUM_GENERIC_SP;
1847 var_success = true;
1848 }
1849 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
1850 {
1851 reg_kind = eRegisterKindGeneric;
1852 reg_num = LLDB_REGNUM_GENERIC_FP;
1853 var_success = true;
1854 }
1855 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
1856 {
1857 reg_kind = eRegisterKindGeneric;
1858 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
1859 var_success = true;
1860 }
1861 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
1862 {
1863 reg_ctx = frame->GetRegisterContext().get();
1864 if (reg_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001865 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001866 var_name_begin += ::strlen ("reg.");
1867 if (var_name_begin < var_name_end)
1868 {
1869 std::string reg_name (var_name_begin, var_name_end);
1870 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
1871 if (reg_info)
1872 var_success = true;
1873 }
Greg Clayton1b654882010-09-19 02:33:57 +00001874 }
1875 }
1876 }
1877 }
1878 }
1879 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
1880 {
1881 if (sc && (sc->function != NULL || sc->symbol != NULL))
1882 {
1883 var_name_begin += ::strlen ("function.");
1884 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1885 {
1886 if (sc->function)
Greg Clayton81c22f62011-10-19 18:09:39 +00001887 s.Printf("function{0x%8.8llx}", sc->function->GetID());
Greg Clayton1b654882010-09-19 02:33:57 +00001888 else
1889 s.Printf("symbol[%u]", sc->symbol->GetID());
1890
1891 var_success = true;
1892 }
1893 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1894 {
1895 if (sc->function)
1896 cstr = sc->function->GetName().AsCString (NULL);
1897 else if (sc->symbol)
1898 cstr = sc->symbol->GetName().AsCString (NULL);
1899 if (cstr)
1900 {
1901 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001902
1903 if (sc->block)
1904 {
1905 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1906 if (inline_block)
1907 {
1908 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1909 if (inline_info)
1910 {
1911 s.PutCString(" [inlined] ");
1912 inline_info->GetName().Dump(&s);
1913 }
1914 }
1915 }
Greg Clayton1b654882010-09-19 02:33:57 +00001916 var_success = true;
1917 }
1918 }
Greg Clayton6d3dbf52012-01-13 08:39:16 +00001919 else if (::strncmp (var_name_begin, "name-with-args}", strlen("name-with-args}")) == 0)
1920 {
1921 // Print the function name with arguments in it
1922
1923 if (sc->function)
1924 {
1925 var_success = true;
1926 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
1927 cstr = sc->function->GetName().AsCString (NULL);
1928 if (cstr)
1929 {
1930 const InlineFunctionInfo *inline_info = NULL;
1931 VariableListSP variable_list_sp;
1932 bool get_function_vars = true;
1933 if (sc->block)
1934 {
1935 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1936
1937 if (inline_block)
1938 {
1939 get_function_vars = false;
1940 inline_info = sc->block->GetInlinedFunctionInfo();
1941 if (inline_info)
1942 variable_list_sp = inline_block->GetBlockVariableList (true);
1943 }
1944 }
1945
1946 if (get_function_vars)
1947 {
1948 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
1949 }
1950
1951 if (inline_info)
1952 {
1953 s.PutCString (cstr);
1954 s.PutCString (" [inlined] ");
1955 cstr = inline_info->GetName().GetCString();
1956 }
1957
1958 VariableList args;
1959 if (variable_list_sp)
1960 {
1961 const size_t num_variables = variable_list_sp->GetSize();
1962 for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
1963 {
1964 VariableSP var_sp (variable_list_sp->GetVariableAtIndex(var_idx));
1965 if (var_sp->GetScope() == eValueTypeVariableArgument)
1966 args.AddVariable (var_sp);
1967 }
1968
1969 }
1970 if (args.GetSize() > 0)
1971 {
1972 const char *open_paren = strchr (cstr, '(');
1973 const char *close_paren = NULL;
1974 if (open_paren)
1975 close_paren = strchr (open_paren, ')');
1976
1977 if (open_paren)
1978 s.Write(cstr, open_paren - cstr + 1);
1979 else
1980 {
1981 s.PutCString (cstr);
1982 s.PutChar ('(');
1983 }
Greg Clayton5b6889b2012-01-18 21:56:18 +00001984 const size_t num_args = args.GetSize();
Greg Clayton6d3dbf52012-01-13 08:39:16 +00001985 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
1986 {
1987 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
1988 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
1989 const char *var_name = var_value_sp->GetName().GetCString();
1990 const char *var_value = var_value_sp->GetValueAsCString();
1991 if (var_value_sp->GetError().Success())
1992 {
1993 if (arg_idx > 0)
1994 s.PutCString (", ");
1995 s.Printf ("%s=%s", var_name, var_value);
1996 }
1997 }
1998
1999 if (close_paren)
2000 s.PutCString (close_paren);
2001 else
2002 s.PutChar(')');
2003
2004 }
2005 else
2006 {
2007 s.PutCString(cstr);
2008 }
2009 }
2010 }
2011 else if (sc->symbol)
2012 {
2013 cstr = sc->symbol->GetName().AsCString (NULL);
2014 if (cstr)
2015 {
2016 s.PutCString(cstr);
2017 var_success = true;
2018 }
2019 }
2020 }
Greg Clayton1b654882010-09-19 02:33:57 +00002021 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
2022 {
2023 var_success = addr != NULL;
2024 if (var_success)
2025 {
2026 format_addr = *addr;
2027 calculate_format_addr_function_offset = true;
2028 }
2029 }
2030 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
2031 {
2032 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
2033 if (var_success)
2034 {
2035 format_addr = sc->line_entry.range.GetBaseAddress();
2036 calculate_format_addr_function_offset = true;
2037 }
2038 }
2039 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
2040 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002041 StackFrame *frame = exe_ctx->GetFramePtr();
2042 var_success = frame != NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00002043 if (var_success)
2044 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002045 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002046 calculate_format_addr_function_offset = true;
2047 }
2048 }
2049 }
2050 }
2051 break;
2052
2053 case 'l':
2054 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
2055 {
2056 if (sc && sc->line_entry.IsValid())
2057 {
2058 var_name_begin += ::strlen ("line.");
2059 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
2060 {
2061 var_name_begin += ::strlen ("file.");
2062
2063 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
2064 {
2065 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
2066 var_success = format_file_spec;
2067 }
2068 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
2069 {
2070 format_file_spec = sc->line_entry.file;
2071 var_success = format_file_spec;
2072 }
2073 }
2074 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
2075 {
2076 var_success = true;
2077 s.Printf("%u", sc->line_entry.line);
2078 }
2079 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
2080 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
2081 {
2082 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
2083 if (var_success)
2084 {
2085 format_addr = sc->line_entry.range.GetBaseAddress();
2086 if (var_name_begin[0] == 'e')
2087 format_addr.Slide (sc->line_entry.range.GetByteSize());
2088 }
2089 }
2090 }
2091 }
2092 break;
2093 }
2094
2095 if (var_success)
2096 {
2097 // If format addr is valid, then we need to print an address
2098 if (reg_num != LLDB_INVALID_REGNUM)
2099 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002100 StackFrame *frame = exe_ctx->GetFramePtr();
Greg Clayton1b654882010-09-19 02:33:57 +00002101 // We have a register value to display...
2102 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
2103 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002104 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002105 }
2106 else
2107 {
2108 if (reg_ctx == NULL)
Greg Claytonc14ee322011-09-22 04:58:26 +00002109 reg_ctx = frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00002110
2111 if (reg_ctx)
2112 {
2113 if (reg_kind != kNumRegisterKinds)
2114 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
2115 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
2116 var_success = reg_info != NULL;
2117 }
2118 }
2119 }
2120
2121 if (reg_info != NULL)
2122 {
Greg Clayton7349bd92011-05-09 20:18:18 +00002123 RegisterValue reg_value;
2124 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
2125 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00002126 {
Greg Clayton9a8fa912011-05-15 04:12:07 +00002127 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
Greg Clayton1b654882010-09-19 02:33:57 +00002128 }
2129 }
2130
2131 if (format_file_spec)
2132 {
2133 s << format_file_spec;
2134 }
2135
2136 // If format addr is valid, then we need to print an address
2137 if (format_addr.IsValid())
2138 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002139 var_success = false;
2140
Greg Clayton1b654882010-09-19 02:33:57 +00002141 if (calculate_format_addr_function_offset)
2142 {
2143 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00002144
Greg Clayton0603aa92010-10-04 01:05:56 +00002145 if (sc)
2146 {
2147 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00002148 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002149 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00002150 if (sc->block)
2151 {
2152 // Check to make sure we aren't in an inline
2153 // function. If we are, use the inline block
2154 // range that contains "format_addr" since
2155 // blocks can be discontiguous.
2156 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2157 AddressRange inline_range;
2158 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
2159 func_addr = inline_range.GetBaseAddress();
2160 }
2161 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002162 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
2163 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
2164 }
2165
2166 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00002167 {
2168 if (func_addr.GetSection() == format_addr.GetSection())
2169 {
2170 addr_t func_file_addr = func_addr.GetFileAddress();
2171 addr_t addr_file_addr = format_addr.GetFileAddress();
2172 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002173 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00002174 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002175 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002176 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00002177 }
2178 else
Greg Clayton0603aa92010-10-04 01:05:56 +00002179 {
2180 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2181 if (target)
2182 {
2183 addr_t func_load_addr = func_addr.GetLoadAddress (target);
2184 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
2185 if (addr_load_addr > func_load_addr)
2186 s.Printf(" + %llu", addr_load_addr - func_load_addr);
2187 else if (addr_load_addr < func_load_addr)
2188 s.Printf(" - %llu", func_load_addr - addr_load_addr);
2189 var_success = true;
2190 }
2191 }
Greg Clayton1b654882010-09-19 02:33:57 +00002192 }
2193 }
2194 else
2195 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002196 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00002197 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00002198 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
2199 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00002200 if (vaddr == LLDB_INVALID_ADDRESS)
2201 vaddr = format_addr.GetFileAddress ();
2202
2203 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00002204 {
Greg Clayton514487e2011-02-15 21:59:32 +00002205 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00002206 if (addr_width == 0)
2207 addr_width = 16;
2208 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002209 var_success = true;
2210 }
Greg Clayton1b654882010-09-19 02:33:57 +00002211 }
2212 }
2213 }
2214
2215 if (var_success == false)
2216 success = false;
2217 }
2218 p = var_name_end;
2219 }
2220 else
2221 break;
2222 }
2223 else
2224 {
2225 // We got a dollar sign with no '{' after it, it must just be a dollar sign
2226 s.PutChar(*p);
2227 }
2228 }
2229 else if (*p == '\\')
2230 {
2231 ++p; // skip the slash
2232 switch (*p)
2233 {
2234 case 'a': s.PutChar ('\a'); break;
2235 case 'b': s.PutChar ('\b'); break;
2236 case 'f': s.PutChar ('\f'); break;
2237 case 'n': s.PutChar ('\n'); break;
2238 case 'r': s.PutChar ('\r'); break;
2239 case 't': s.PutChar ('\t'); break;
2240 case 'v': s.PutChar ('\v'); break;
2241 case '\'': s.PutChar ('\''); break;
2242 case '\\': s.PutChar ('\\'); break;
2243 case '0':
2244 // 1 to 3 octal chars
2245 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002246 // Make a string that can hold onto the initial zero char,
2247 // up to 3 octal digits, and a terminating NULL.
2248 char oct_str[5] = { 0, 0, 0, 0, 0 };
2249
2250 int i;
2251 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
2252 oct_str[i] = p[i];
2253
2254 // We don't want to consume the last octal character since
2255 // the main for loop will do this for us, so we advance p by
2256 // one less than i (even if i is zero)
2257 p += i - 1;
2258 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2259 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002260 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002261 char octal_char = octal_value;
2262 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00002263 }
Greg Clayton1b654882010-09-19 02:33:57 +00002264 }
2265 break;
2266
2267 case 'x':
2268 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00002269 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002270 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002271 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00002272
Greg Clayton0603aa92010-10-04 01:05:56 +00002273 // Make a string that can hold onto two hex chars plus a
2274 // NULL terminator
2275 char hex_str[3] = { 0,0,0 };
2276 hex_str[0] = *p;
2277 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002278 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002279 ++p; // Skip the first of the two hex chars
2280 hex_str[1] = *p;
2281 }
2282
2283 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2284 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002285 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00002286 }
2287 else
2288 {
2289 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00002290 }
2291 break;
2292
2293 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00002294 // Just desensitize any other character by just printing what
2295 // came after the '\'
2296 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00002297 break;
2298
2299 }
2300
2301 }
2302 }
2303 if (end)
2304 *end = p;
2305 return success;
2306}
2307
2308#pragma mark Debugger::SettingsController
2309
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002310//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002311// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002312//--------------------------------------------------
2313
Greg Clayton1b654882010-09-19 02:33:57 +00002314Debugger::SettingsController::SettingsController () :
Greg Clayton4d122c42011-09-17 08:33:22 +00002315 UserSettingsController ("", UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002316{
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002317}
2318
Greg Clayton1b654882010-09-19 02:33:57 +00002319Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002320{
2321}
2322
2323
Greg Clayton4d122c42011-09-17 08:33:22 +00002324InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00002325Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002326{
Greg Claytonb9556ac2012-01-30 07:41:31 +00002327 InstanceSettingsSP new_settings_sp (new DebuggerInstanceSettings (GetSettingsController(),
2328 false,
2329 instance_name));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002330 return new_settings_sp;
2331}
2332
Greg Clayton1b654882010-09-19 02:33:57 +00002333#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002334//--------------------------------------------------
2335// class DebuggerInstanceSettings
2336//--------------------------------------------------
2337
Greg Claytona7015092010-09-18 01:14:36 +00002338DebuggerInstanceSettings::DebuggerInstanceSettings
2339(
Greg Claytonb9556ac2012-01-30 07:41:31 +00002340 const UserSettingsControllerSP &m_owner_sp,
Greg Claytona7015092010-09-18 01:14:36 +00002341 bool live_instance,
2342 const char *name
2343) :
Greg Claytonb9556ac2012-01-30 07:41:31 +00002344 InstanceSettings (m_owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00002345 m_term_width (80),
Greg Claytone372b982011-11-21 21:44:34 +00002346 m_stop_source_before_count (3),
2347 m_stop_source_after_count (3),
2348 m_stop_disassembly_count (4),
2349 m_stop_disassembly_display (eStopDisassemblyTypeNoSource),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002350 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00002351 m_frame_format (),
2352 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002353 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002354 m_use_external_editor (false),
2355 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002356{
Caroline Ticef20e8232010-09-09 18:26:37 +00002357 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2358 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
2359 // 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 +00002360 // The same is true of CreateInstanceName().
2361
2362 if (GetInstanceName() == InstanceSettings::InvalidName())
2363 {
2364 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Claytonb9556ac2012-01-30 07:41:31 +00002365 m_owner_sp->RegisterInstanceSettings (this);
Caroline Tice9e41c152010-09-16 19:05:55 +00002366 }
Caroline Ticef20e8232010-09-09 18:26:37 +00002367
2368 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002369 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00002370 const InstanceSettingsSP &pending_settings = m_owner_sp->FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002371 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002372 }
2373}
2374
2375DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Claytonb9556ac2012-01-30 07:41:31 +00002376 InstanceSettings (Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002377 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00002378 m_frame_format (rhs.m_frame_format),
2379 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002380 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002381 m_use_external_editor (rhs.m_use_external_editor),
2382 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002383{
Greg Claytonb9556ac2012-01-30 07:41:31 +00002384 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2385 if (owner_sp)
2386 {
2387 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
2388 owner_sp->RemovePendingSettings (m_instance_name);
2389 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002390}
2391
2392DebuggerInstanceSettings::~DebuggerInstanceSettings ()
2393{
2394}
2395
2396DebuggerInstanceSettings&
2397DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
2398{
2399 if (this != &rhs)
2400 {
Greg Clayton1b654882010-09-19 02:33:57 +00002401 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002402 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00002403 m_frame_format = rhs.m_frame_format;
2404 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002405 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002406 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002407 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002408 }
2409
2410 return *this;
2411}
2412
Greg Clayton1b654882010-09-19 02:33:57 +00002413bool
2414DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
2415{
2416 bool valid = false;
2417
2418 // Verify we have a value string.
2419 if (value == NULL || value[0] == '\0')
2420 {
Greg Clayton86edbf42011-10-26 00:56:27 +00002421 err.SetErrorString ("missing value, can't set terminal width without a value");
Greg Clayton1b654882010-09-19 02:33:57 +00002422 }
2423 else
2424 {
2425 char *end = NULL;
2426 const uint32_t width = ::strtoul (value, &end, 0);
2427
Johnny Chenea9fc182010-09-20 16:36:43 +00002428 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00002429 {
Johnny Chen433d7742010-09-20 17:04:41 +00002430 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00002431 valid = true;
2432 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002433 err.SetErrorString ("invalid term-width value; value must be between 10 and 1024");
Greg Clayton1b654882010-09-19 02:33:57 +00002434 }
2435 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002436 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value);
Greg Clayton1b654882010-09-19 02:33:57 +00002437 }
2438
2439 return valid;
2440}
2441
2442
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002443void
2444DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2445 const char *index_value,
2446 const char *value,
2447 const ConstString &instance_name,
2448 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00002449 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002450 Error &err,
2451 bool pending)
2452{
Greg Clayton0603aa92010-10-04 01:05:56 +00002453
2454 if (var_name == TermWidthVarName())
2455 {
2456 if (ValidTermWidthValue (value, err))
2457 {
2458 m_term_width = ::strtoul (value, NULL, 0);
2459 }
2460 }
2461 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002462 {
Caroline Tice101c7c22010-09-09 06:25:08 +00002463 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002464 if (!pending)
2465 {
Caroline Tice49e27372010-09-07 18:35:40 +00002466 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2467 // strip off the brackets before passing it to BroadcastPromptChange.
2468
2469 std::string tmp_instance_name (instance_name.AsCString());
2470 if ((tmp_instance_name[0] == '[')
2471 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
2472 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
2473 ConstString new_name (tmp_instance_name.c_str());
2474
2475 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002476 }
2477 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002478 else if (var_name == GetFrameFormatName())
2479 {
2480 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
2481 }
2482 else if (var_name == GetThreadFormatName())
2483 {
2484 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
2485 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002486 else if (var_name == ScriptLangVarName())
2487 {
2488 bool success;
2489 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
2490 &success);
2491 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002492 else if (var_name == UseExternalEditorVarName ())
2493 {
Greg Clayton385aa282011-04-22 03:55:06 +00002494 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00002495 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002496 else if (var_name == AutoConfirmName ())
2497 {
Greg Clayton385aa282011-04-22 03:55:06 +00002498 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00002499 }
Greg Claytone372b982011-11-21 21:44:34 +00002500 else if (var_name == StopSourceContextBeforeName ())
2501 {
2502 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2503 if (new_value != UINT32_MAX)
2504 m_stop_source_before_count = new_value;
2505 else
2506 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextAfterName ().GetCString());
2507 }
2508 else if (var_name == StopSourceContextAfterName ())
2509 {
2510 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2511 if (new_value != UINT32_MAX)
2512 m_stop_source_after_count = new_value;
2513 else
2514 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextBeforeName ().GetCString());
2515 }
2516 else if (var_name == StopDisassemblyCountName ())
2517 {
2518 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2519 if (new_value != UINT32_MAX)
2520 m_stop_disassembly_count = new_value;
2521 else
2522 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopDisassemblyCountName ().GetCString());
2523 }
2524 else if (var_name == StopDisassemblyDisplayName ())
2525 {
2526 int new_value;
2527 UserSettingsController::UpdateEnumVariable (g_show_disassembly_enum_values, &new_value, value, err);
2528 if (err.Success())
2529 m_stop_disassembly_display = (StopDisassemblyType)new_value;
2530 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002531}
2532
Caroline Tice12cecd72010-09-20 21:37:42 +00002533bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002534DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2535 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00002536 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00002537 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002538{
2539 if (var_name == PromptVarName())
2540 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002541 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002542
2543 }
2544 else if (var_name == ScriptLangVarName())
2545 {
2546 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
2547 }
Caroline Tice101c7c22010-09-09 06:25:08 +00002548 else if (var_name == TermWidthVarName())
2549 {
2550 StreamString width_str;
Greg Claytone372b982011-11-21 21:44:34 +00002551 width_str.Printf ("%u", m_term_width);
Caroline Tice101c7c22010-09-09 06:25:08 +00002552 value.AppendString (width_str.GetData());
2553 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002554 else if (var_name == GetFrameFormatName ())
2555 {
2556 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
2557 }
2558 else if (var_name == GetThreadFormatName ())
2559 {
2560 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
2561 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002562 else if (var_name == UseExternalEditorVarName())
2563 {
2564 if (m_use_external_editor)
2565 value.AppendString ("true");
2566 else
2567 value.AppendString ("false");
2568 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002569 else if (var_name == AutoConfirmName())
2570 {
2571 if (m_auto_confirm_on)
2572 value.AppendString ("true");
2573 else
2574 value.AppendString ("false");
2575 }
Greg Claytone372b982011-11-21 21:44:34 +00002576 else if (var_name == StopSourceContextAfterName ())
2577 {
2578 StreamString strm;
2579 strm.Printf ("%u", m_stop_source_before_count);
2580 value.AppendString (strm.GetData());
2581 }
2582 else if (var_name == StopSourceContextBeforeName ())
2583 {
2584 StreamString strm;
2585 strm.Printf ("%u", m_stop_source_after_count);
2586 value.AppendString (strm.GetData());
2587 }
2588 else if (var_name == StopDisassemblyCountName ())
2589 {
2590 StreamString strm;
2591 strm.Printf ("%u", m_stop_disassembly_count);
2592 value.AppendString (strm.GetData());
2593 }
2594 else if (var_name == StopDisassemblyDisplayName ())
2595 {
2596 if (m_stop_disassembly_display >= eStopDisassemblyTypeNever && m_stop_disassembly_display <= eStopDisassemblyTypeAlways)
2597 value.AppendString (g_show_disassembly_enum_values[m_stop_disassembly_display].string_value);
2598 else
2599 value.AppendString ("<invalid>");
2600 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002601 else
Caroline Tice12cecd72010-09-20 21:37:42 +00002602 {
2603 if (err)
2604 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2605 return false;
2606 }
2607 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002608}
2609
2610void
Greg Clayton4d122c42011-09-17 08:33:22 +00002611DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002612 bool pending)
2613{
2614 if (new_settings.get() == NULL)
2615 return;
2616
2617 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
2618
2619 m_prompt = new_debugger_settings->m_prompt;
2620 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00002621 {
2622 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2623 // strip off the brackets before passing it to BroadcastPromptChange.
2624
2625 std::string tmp_instance_name (m_instance_name.AsCString());
2626 if ((tmp_instance_name[0] == '[')
2627 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
2628 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
2629 ConstString new_name (tmp_instance_name.c_str());
2630
2631 BroadcastPromptChange (new_name, m_prompt.c_str());
2632 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002633 m_frame_format = new_debugger_settings->m_frame_format;
2634 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002635 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002636 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002637 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002638 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002639}
2640
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002641
2642bool
2643DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
2644{
2645 std::string tmp_prompt;
2646
2647 if (new_prompt != NULL)
2648 {
2649 tmp_prompt = new_prompt ;
2650 int len = tmp_prompt.size();
2651 if (len > 1
2652 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
2653 && (tmp_prompt[len-1] == tmp_prompt[0]))
2654 {
2655 tmp_prompt = tmp_prompt.substr(1,len-2);
2656 }
2657 len = tmp_prompt.size();
2658 if (tmp_prompt[len-1] != ' ')
2659 tmp_prompt.append(" ");
2660 }
2661 EventSP new_event_sp;
2662 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
2663 new EventDataBytes (tmp_prompt.c_str())));
2664
2665 if (instance_name.GetLength() != 0)
2666 {
2667 // Set prompt for a particular instance.
2668 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
2669 if (dbg != NULL)
2670 {
2671 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
2672 }
2673 }
2674
2675 return true;
2676}
2677
2678const ConstString
2679DebuggerInstanceSettings::CreateInstanceName ()
2680{
2681 static int instance_count = 1;
2682 StreamString sstr;
2683
2684 sstr.Printf ("debugger_%d", instance_count);
2685 ++instance_count;
2686
2687 const ConstString ret_val (sstr.GetData());
2688
2689 return ret_val;
2690}
2691
Jim Ingham3bcdb292010-10-04 22:44:14 +00002692
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002693//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002694// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002695//--------------------------------------------------
2696
2697
2698SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002699Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002700{
2701 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00002702 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
2703 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002704 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
2705};
2706
Greg Claytonbb562b12010-10-04 02:44:26 +00002707#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00002708#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002709
Greg Clayton0603aa92010-10-04 01:05:56 +00002710#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2711 "{, ${frame.pc}}"\
2712 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00002713 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00002714 "{, stop reason = ${thread.stop-reason}}"\
Jim Inghamef651602011-12-22 19:12:40 +00002715 "{\\nReturn value: ${thread.return-value}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00002716 "\\n"
2717
Greg Clayton315d2ca2010-11-02 01:53:21 +00002718//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2719// "{, ${frame.pc}}"\
2720// MODULE_WITH_FUNC\
2721// FILE_AND_LINE\
2722// "{, stop reason = ${thread.stop-reason}}"\
2723// "{, name = ${thread.name}}"\
2724// "{, queue = ${thread.queue}}"\
2725// "\\n"
2726
Greg Clayton0603aa92010-10-04 01:05:56 +00002727#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
2728 MODULE_WITH_FUNC\
2729 FILE_AND_LINE\
2730 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002731
2732SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002733Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002734{
Greg Clayton0603aa92010-10-04 01:05:56 +00002735// NAME Setting variable type Default Enum Init'd Hidden Help
2736// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00002737{ "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 +00002738{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00002739{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
2740{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002741{ "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 +00002742{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
2743{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
2744{ "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." },
2745{ "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." },
2746{ "stop-disassembly-count", eSetVarTypeInt, "0", NULL, false, false, "The number of disassembly lines to show when displaying a stopped context." },
2747{ "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 +00002748{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002749};