blob: 77f85724a391edefe10b822aaacac6e7d2e511cf [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Greg Clayton4a33d312011-06-23 17:59:56 +000010#include "lldb/Core/Debugger.h"
11
12#include <map>
13
Enrico Granata4becb372011-06-29 22:27:15 +000014#include "clang/AST/DeclCXX.h"
15#include "clang/AST/Type.h"
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/lldb-private.h"
18#include "lldb/Core/ConnectionFileDescriptor.h"
Greg Clayton4a33d312011-06-23 17:59:56 +000019#include "lldb/Core/FormatManager.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/InputReader.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000021#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000023#include "lldb/Core/StreamAsynchronousIO.h"
Greg Clayton1b654882010-09-19 02:33:57 +000024#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000026#include "lldb/Core/ValueObject.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000027#include "lldb/Core/ValueObjectVariable.h"
Greg Claytona3406612011-02-07 23:24:47 +000028#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000029#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000030#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Target/TargetList.h"
32#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000033#include "lldb/Target/RegisterContext.h"
34#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000036#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037
38using namespace lldb;
39using namespace lldb_private;
40
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041
Greg Clayton1b654882010-09-19 02:33:57 +000042static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000043static lldb::user_id_t g_unique_id = 1;
44
Greg Clayton1b654882010-09-19 02:33:57 +000045#pragma mark Static Functions
46
47static Mutex &
48GetDebuggerListMutex ()
49{
50 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
51 return g_mutex;
52}
53
54typedef std::vector<DebuggerSP> DebuggerList;
55
56static DebuggerList &
57GetDebuggerList()
58{
59 // hide the static debugger list inside a singleton accessor to avoid
60 // global init contructors
61 static DebuggerList g_list;
62 return g_list;
63}
64
65
Greg Claytone372b982011-11-21 21:44:34 +000066static const ConstString &
67PromptVarName ()
68{
69 static ConstString g_const_string ("prompt");
70 return g_const_string;
71}
72
73static const ConstString &
74GetFrameFormatName ()
75{
76 static ConstString g_const_string ("frame-format");
77 return g_const_string;
78}
79
80static const ConstString &
81GetThreadFormatName ()
82{
83 static ConstString g_const_string ("thread-format");
84 return g_const_string;
85}
86
87static const ConstString &
88ScriptLangVarName ()
89{
90 static ConstString g_const_string ("script-lang");
91 return g_const_string;
92}
93
94static const ConstString &
95TermWidthVarName ()
96{
97 static ConstString g_const_string ("term-width");
98 return g_const_string;
99}
100
101static const ConstString &
102UseExternalEditorVarName ()
103{
104 static ConstString g_const_string ("use-external-editor");
105 return g_const_string;
106}
107
108static const ConstString &
109AutoConfirmName ()
110{
111 static ConstString g_const_string ("auto-confirm");
112 return g_const_string;
113}
114
115static const ConstString &
116StopSourceContextBeforeName ()
117{
118 static ConstString g_const_string ("stop-line-count-before");
119 return g_const_string;
120}
121
122static const ConstString &
123StopSourceContextAfterName ()
124{
125 static ConstString g_const_string ("stop-line-count-after");
126 return g_const_string;
127}
128
129static const ConstString &
130StopDisassemblyCountName ()
131{
132 static ConstString g_const_string ("stop-disassembly-count");
133 return g_const_string;
134}
135
136static const ConstString &
137StopDisassemblyDisplayName ()
138{
139 static ConstString g_const_string ("stop-disassembly-display");
140 return g_const_string;
141}
142
143OptionEnumValueElement
144DebuggerInstanceSettings::g_show_disassembly_enum_values[] =
145{
146 { eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
147 { eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
148 { eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
149 { 0, NULL, NULL }
150};
151
152
153
Greg Clayton1b654882010-09-19 02:33:57 +0000154#pragma mark Debugger
155
Greg Clayton99d0faf2010-11-18 23:32:35 +0000156UserSettingsControllerSP &
157Debugger::GetSettingsController ()
158{
159 static UserSettingsControllerSP g_settings_controller;
160 return g_settings_controller;
161}
162
Caroline Tice2f88aad2011-01-14 00:29:16 +0000163int
164Debugger::TestDebuggerRefCount ()
165{
166 return g_shared_debugger_refcount;
167}
168
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169void
170Debugger::Initialize ()
171{
Greg Clayton66111032010-06-23 01:19:29 +0000172 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +0000173 {
Greg Claytondbe54502010-11-19 03:46:01 +0000174 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +0000175 }
Greg Clayton66111032010-06-23 01:19:29 +0000176 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +0000177
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178}
179
180void
181Debugger::Terminate ()
182{
Greg Clayton66111032010-06-23 01:19:29 +0000183 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184 {
Greg Clayton66111032010-06-23 01:19:29 +0000185 g_shared_debugger_refcount--;
186 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000187 {
Greg Claytondbe54502010-11-19 03:46:01 +0000188 lldb_private::WillTerminate();
189 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000190
191 // Clear our master list of debugger objects
192 Mutex::Locker locker (GetDebuggerListMutex ());
193 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 }
196}
197
Caroline Tice20bd37f2011-03-10 22:14:10 +0000198void
199Debugger::SettingsInitialize ()
200{
201 static bool g_initialized = false;
202
203 if (!g_initialized)
204 {
205 g_initialized = true;
206 UserSettingsControllerSP &usc = GetSettingsController();
207 usc.reset (new SettingsController);
208 UserSettingsController::InitializeSettingsController (usc,
209 SettingsController::global_settings_table,
210 SettingsController::instance_settings_table);
211 // Now call SettingsInitialize for each settings 'child' of Debugger
212 Target::SettingsInitialize ();
213 }
214}
215
216void
217Debugger::SettingsTerminate ()
218{
219
220 // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
221 // Settings.
222
223 Target::SettingsTerminate ();
224
225 // Now terminate the Debugger Settings.
226
227 UserSettingsControllerSP &usc = GetSettingsController();
228 UserSettingsController::FinalizeSettingsController (usc);
229 usc.reset();
230}
231
Greg Clayton66111032010-06-23 01:19:29 +0000232DebuggerSP
233Debugger::CreateInstance ()
234{
235 DebuggerSP debugger_sp (new Debugger);
236 // Scope for locker
237 {
238 Mutex::Locker locker (GetDebuggerListMutex ());
239 GetDebuggerList().push_back(debugger_sp);
240 }
241 return debugger_sp;
242}
243
Caroline Ticee02657b2011-01-22 01:02:07 +0000244void
Greg Clayton4d122c42011-09-17 08:33:22 +0000245Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000246{
247 if (debugger_sp.get() == NULL)
248 return;
249
Jim Ingham8314c522011-09-15 21:36:42 +0000250 debugger_sp->Clear();
251
Caroline Ticee02657b2011-01-22 01:02:07 +0000252 Mutex::Locker locker (GetDebuggerListMutex ());
253 DebuggerList &debugger_list = GetDebuggerList ();
254 DebuggerList::iterator pos, end = debugger_list.end();
255 for (pos = debugger_list.begin (); pos != end; ++pos)
256 {
257 if ((*pos).get() == debugger_sp.get())
258 {
259 debugger_list.erase (pos);
260 return;
261 }
262 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000263}
264
Greg Clayton4d122c42011-09-17 08:33:22 +0000265DebuggerSP
Greg Clayton66111032010-06-23 01:19:29 +0000266Debugger::GetSP ()
267{
Greg Clayton4d122c42011-09-17 08:33:22 +0000268 // This object contains an instrusive ref count base class so we can
269 // easily make a shared pointer to this object
270 return DebuggerSP (this);
Greg Clayton66111032010-06-23 01:19:29 +0000271}
272
Greg Clayton4d122c42011-09-17 08:33:22 +0000273DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000274Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
275{
Greg Clayton4d122c42011-09-17 08:33:22 +0000276 DebuggerSP debugger_sp;
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000277
278 Mutex::Locker locker (GetDebuggerListMutex ());
279 DebuggerList &debugger_list = GetDebuggerList();
280 DebuggerList::iterator pos, end = debugger_list.end();
281
282 for (pos = debugger_list.begin(); pos != end; ++pos)
283 {
284 if ((*pos).get()->m_instance_name == instance_name)
285 {
286 debugger_sp = *pos;
287 break;
288 }
289 }
290 return debugger_sp;
291}
Greg Clayton66111032010-06-23 01:19:29 +0000292
293TargetSP
294Debugger::FindTargetWithProcessID (lldb::pid_t pid)
295{
Greg Clayton4d122c42011-09-17 08:33:22 +0000296 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000297 Mutex::Locker locker (GetDebuggerListMutex ());
298 DebuggerList &debugger_list = GetDebuggerList();
299 DebuggerList::iterator pos, end = debugger_list.end();
300 for (pos = debugger_list.begin(); pos != end; ++pos)
301 {
302 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
303 if (target_sp)
304 break;
305 }
306 return target_sp;
307}
308
Greg Claytone4e45922011-11-16 05:37:56 +0000309TargetSP
310Debugger::FindTargetWithProcess (Process *process)
311{
312 TargetSP target_sp;
313 Mutex::Locker locker (GetDebuggerListMutex ());
314 DebuggerList &debugger_list = GetDebuggerList();
315 DebuggerList::iterator pos, end = debugger_list.end();
316 for (pos = debugger_list.begin(); pos != end; ++pos)
317 {
318 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
319 if (target_sp)
320 break;
321 }
322 return target_sp;
323}
324
Greg Clayton66111032010-06-23 01:19:29 +0000325
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000326Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000327 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000328 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000329 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000330 m_input_file (),
331 m_output_file (),
332 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333 m_target_list (),
Greg Claytonded470d2011-03-19 01:12:21 +0000334 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335 m_listener ("lldb.Debugger"),
Jim Inghame37d6052011-09-13 00:29:56 +0000336 m_source_manager(*this),
337 m_source_file_cache(),
Greg Clayton66111032010-06-23 01:19:29 +0000338 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000339 m_input_reader_stack (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000340 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341{
Greg Clayton66111032010-06-23 01:19:29 +0000342 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000343 // Always add our default platform to the platform list
344 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
345 assert (default_platform_sp.get());
346 m_platform_list.Append (default_platform_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347}
348
349Debugger::~Debugger ()
350{
Jim Ingham8314c522011-09-15 21:36:42 +0000351 Clear();
352}
353
354void
355Debugger::Clear()
356{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000357 CleanUpInputReaders();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000358 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000359 int num_targets = m_target_list.GetNumTargets();
360 for (int i = 0; i < num_targets; i++)
361 {
362 ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
363 if (process_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000364 {
Greg Claytone24c4ac2011-11-17 04:46:02 +0000365 if (process_sp->GetShouldDetach())
Jim Ingham8314c522011-09-15 21:36:42 +0000366 process_sp->Detach();
367 else
368 process_sp->Destroy();
369 }
Greg Clayton66111032010-06-23 01:19:29 +0000370 }
371 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372
Jim Ingham8314c522011-09-15 21:36:42 +0000373}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374
375bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000376Debugger::GetCloseInputOnEOF () const
377{
378 return m_input_comm.GetCloseOnEOF();
379}
380
381void
382Debugger::SetCloseInputOnEOF (bool b)
383{
384 m_input_comm.SetCloseOnEOF(b);
385}
386
387bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388Debugger::GetAsyncExecution ()
389{
Greg Clayton66111032010-06-23 01:19:29 +0000390 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000391}
392
393void
394Debugger::SetAsyncExecution (bool async_execution)
395{
Greg Clayton66111032010-06-23 01:19:29 +0000396 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397}
398
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399
400void
401Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
402{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000403 File &in_file = GetInputFile();
404 in_file.SetStream (fh, tranfer_ownership);
405 if (in_file.IsValid() == false)
406 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407
408 // Disconnect from any old connection if we had one
409 m_input_comm.Disconnect ();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000410 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), true));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
412
413 Error error;
414 if (m_input_comm.StartReadThread (&error) == false)
415 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000416 File &err_file = GetErrorFile();
417
418 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
419 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421}
422
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423void
424Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
425{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000426 File &out_file = GetOutputFile();
427 out_file.SetStream (fh, tranfer_ownership);
428 if (out_file.IsValid() == false)
429 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000430
431 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432}
433
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434void
435Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
436{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000437 File &err_file = GetErrorFile();
438 err_file.SetStream (fh, tranfer_ownership);
439 if (err_file.IsValid() == false)
440 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441}
442
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000444Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445{
446 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000447 TargetSP target_sp(GetSelectedTarget());
448 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449
450 if (target_sp)
451 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000452 ProcessSP process_sp (target_sp->GetProcessSP());
453 exe_ctx.SetProcessSP (process_sp);
454 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000456 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
457 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000459 exe_ctx.SetThreadSP (thread_sp);
460 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
461 if (exe_ctx.GetFramePtr() == NULL)
462 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463 }
464 }
465 }
466 return exe_ctx;
467
468}
469
Caroline Ticeb44880c2011-02-10 01:15:13 +0000470InputReaderSP
471Debugger::GetCurrentInputReader ()
472{
473 InputReaderSP reader_sp;
474
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000475 if (!m_input_reader_stack.IsEmpty())
Caroline Ticeb44880c2011-02-10 01:15:13 +0000476 {
477 // Clear any finished readers from the stack
478 while (CheckIfTopInputReaderIsDone()) ;
479
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000480 if (!m_input_reader_stack.IsEmpty())
481 reader_sp = m_input_reader_stack.Top();
Caroline Ticeb44880c2011-02-10 01:15:13 +0000482 }
483
484 return reader_sp;
485}
486
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487void
488Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
489{
Caroline Ticeefed6132010-11-19 20:47:54 +0000490 if (bytes_len > 0)
491 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
492 else
493 ((Debugger *)baton)->DispatchInputEndOfFile ();
494}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495
496
497void
498Debugger::DispatchInput (const char *bytes, size_t bytes_len)
499{
Caroline Ticeefed6132010-11-19 20:47:54 +0000500 if (bytes == NULL || bytes_len == 0)
501 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502
503 WriteToDefaultReader (bytes, bytes_len);
504}
505
506void
Caroline Ticeefed6132010-11-19 20:47:54 +0000507Debugger::DispatchInputInterrupt ()
508{
509 m_input_reader_data.clear();
510
Caroline Ticeb44880c2011-02-10 01:15:13 +0000511 InputReaderSP reader_sp (GetCurrentInputReader ());
512 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000513 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000514 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000515
Caroline Ticeb44880c2011-02-10 01:15:13 +0000516 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000517 while (CheckIfTopInputReaderIsDone ()) ;
518 }
519}
520
521void
522Debugger::DispatchInputEndOfFile ()
523{
524 m_input_reader_data.clear();
525
Caroline Ticeb44880c2011-02-10 01:15:13 +0000526 InputReaderSP reader_sp (GetCurrentInputReader ());
527 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000528 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000529 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000530
Caroline Ticeb44880c2011-02-10 01:15:13 +0000531 // 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 +0000532 while (CheckIfTopInputReaderIsDone ()) ;
533 }
534}
535
536void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000537Debugger::CleanUpInputReaders ()
538{
539 m_input_reader_data.clear();
540
Caroline Ticeb44880c2011-02-10 01:15:13 +0000541 // 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 +0000542 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000543 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000544 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000545 if (reader_sp)
546 {
547 reader_sp->Notify (eInputReaderEndOfFile);
548 reader_sp->SetIsDone (true);
549 }
550 }
551}
552
553void
Caroline Tice969ed3d2011-05-02 20:41:46 +0000554Debugger::NotifyTopInputReader (InputReaderAction notification)
555{
556 InputReaderSP reader_sp (GetCurrentInputReader());
557 if (reader_sp)
558 {
559 reader_sp->Notify (notification);
560
561 // Flush out any input readers that are done.
562 while (CheckIfTopInputReaderIsDone ())
563 /* Do nothing. */;
564 }
565}
566
Caroline Tice9088b062011-05-09 23:06:58 +0000567bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000568Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp)
Caroline Tice9088b062011-05-09 23:06:58 +0000569{
Caroline Ticed61c10b2011-06-16 16:27:19 +0000570 InputReaderSP top_reader_sp (GetCurrentInputReader());
Caroline Tice9088b062011-05-09 23:06:58 +0000571
Caroline Ticed61c10b2011-06-16 16:27:19 +0000572 return (reader_sp.get() == top_reader_sp.get());
Caroline Tice9088b062011-05-09 23:06:58 +0000573}
574
575
Caroline Tice969ed3d2011-05-02 20:41:46 +0000576void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
578{
579 if (bytes && bytes_len)
580 m_input_reader_data.append (bytes, bytes_len);
581
582 if (m_input_reader_data.empty())
583 return;
584
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000585 while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000588 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589 if (!reader_sp)
590 break;
591
Greg Clayton471b31c2010-07-20 22:52:08 +0000592 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593 m_input_reader_data.size());
594 if (bytes_handled)
595 {
596 m_input_reader_data.erase (0, bytes_handled);
597 }
598 else
599 {
600 // No bytes were handled, we might not have reached our
601 // granularity, just return and wait for more data
602 break;
603 }
604 }
605
Caroline Ticeb44880c2011-02-10 01:15:13 +0000606 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000607 while (CheckIfTopInputReaderIsDone ())
608 /* Do nothing. */;
609
610}
611
612void
613Debugger::PushInputReader (const InputReaderSP& reader_sp)
614{
615 if (!reader_sp)
616 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000617
618 // Deactivate the old top reader
619 InputReaderSP top_reader_sp (GetCurrentInputReader ());
620
621 if (top_reader_sp)
622 top_reader_sp->Notify (eInputReaderDeactivate);
623
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000624 m_input_reader_stack.Push (reader_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625 reader_sp->Notify (eInputReaderActivate);
626 ActivateInputReader (reader_sp);
627}
628
629bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000630Debugger::PopInputReader (const InputReaderSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000631{
632 bool result = false;
633
634 // The reader on the stop of the stack is done, so let the next
635 // read on the stack referesh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000636 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000638 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000639 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640
641 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
642 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000643 m_input_reader_stack.Pop ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000644 reader_sp->Notify (eInputReaderDeactivate);
645 reader_sp->Notify (eInputReaderDone);
646 result = true;
647
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000648 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000650 reader_sp = m_input_reader_stack.Top();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000651 if (reader_sp)
652 {
653 ActivateInputReader (reader_sp);
654 reader_sp->Notify (eInputReaderReactivate);
655 }
656 }
657 }
658 }
659 return result;
660}
661
662bool
663Debugger::CheckIfTopInputReaderIsDone ()
664{
665 bool result = false;
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000666 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000668 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000669 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670
671 if (reader_sp && reader_sp->IsDone())
672 {
673 result = true;
674 PopInputReader (reader_sp);
675 }
676 }
677 return result;
678}
679
680void
681Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
682{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000683 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000685 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000686 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000687 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000688
689 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000690
Greg Claytona3406612011-02-07 23:24:47 +0000691 switch (reader_sp->GetGranularity())
692 {
693 case eInputReaderGranularityByte:
694 case eInputReaderGranularityWord:
695 tty.SetCanonical (false);
696 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697
Greg Claytona3406612011-02-07 23:24:47 +0000698 case eInputReaderGranularityLine:
699 case eInputReaderGranularityAll:
700 tty.SetCanonical (true);
701 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000702
Greg Claytona3406612011-02-07 23:24:47 +0000703 default:
704 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705 }
706 }
707}
Greg Clayton66111032010-06-23 01:19:29 +0000708
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000709StreamSP
710Debugger::GetAsyncOutputStream ()
711{
712 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
713 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
714}
715
716StreamSP
717Debugger::GetAsyncErrorStream ()
718{
719 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
720 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
721}
722
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000723DebuggerSP
724Debugger::FindDebuggerWithID (lldb::user_id_t id)
725{
Greg Clayton4d122c42011-09-17 08:33:22 +0000726 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000727
728 Mutex::Locker locker (GetDebuggerListMutex ());
729 DebuggerList &debugger_list = GetDebuggerList();
730 DebuggerList::iterator pos, end = debugger_list.end();
731 for (pos = debugger_list.begin(); pos != end; ++pos)
732 {
733 if ((*pos).get()->GetID() == id)
734 {
735 debugger_sp = *pos;
736 break;
737 }
738 }
739 return debugger_sp;
740}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000741
Greg Clayton1b654882010-09-19 02:33:57 +0000742static void
743TestPromptFormats (StackFrame *frame)
744{
745 if (frame == NULL)
746 return;
747
748 StreamString s;
749 const char *prompt_format =
750 "{addr = '${addr}'\n}"
751 "{process.id = '${process.id}'\n}"
752 "{process.name = '${process.name}'\n}"
753 "{process.file.basename = '${process.file.basename}'\n}"
754 "{process.file.fullpath = '${process.file.fullpath}'\n}"
755 "{thread.id = '${thread.id}'\n}"
756 "{thread.index = '${thread.index}'\n}"
757 "{thread.name = '${thread.name}'\n}"
758 "{thread.queue = '${thread.queue}'\n}"
759 "{thread.stop-reason = '${thread.stop-reason}'\n}"
760 "{target.arch = '${target.arch}'\n}"
761 "{module.file.basename = '${module.file.basename}'\n}"
762 "{module.file.fullpath = '${module.file.fullpath}'\n}"
763 "{file.basename = '${file.basename}'\n}"
764 "{file.fullpath = '${file.fullpath}'\n}"
765 "{frame.index = '${frame.index}'\n}"
766 "{frame.pc = '${frame.pc}'\n}"
767 "{frame.sp = '${frame.sp}'\n}"
768 "{frame.fp = '${frame.fp}'\n}"
769 "{frame.flags = '${frame.flags}'\n}"
770 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
771 "{frame.reg.rip = '${frame.reg.rip}'\n}"
772 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
773 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
774 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
775 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
776 "{frame.reg.carp = '${frame.reg.carp}'\n}"
777 "{function.id = '${function.id}'\n}"
778 "{function.name = '${function.name}'\n}"
779 "{function.addr-offset = '${function.addr-offset}'\n}"
780 "{function.line-offset = '${function.line-offset}'\n}"
781 "{function.pc-offset = '${function.pc-offset}'\n}"
782 "{line.file.basename = '${line.file.basename}'\n}"
783 "{line.file.fullpath = '${line.file.fullpath}'\n}"
784 "{line.number = '${line.number}'\n}"
785 "{line.start-addr = '${line.start-addr}'\n}"
786 "{line.end-addr = '${line.end-addr}'\n}"
787;
788
789 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
790 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000791 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000792 const char *end = NULL;
793 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
794 {
795 printf("%s\n", s.GetData());
796 }
797 else
798 {
799 printf ("error: at '%s'\n", end);
800 printf ("what we got: %s\n", s.GetData());
801 }
802}
803
Enrico Granata9fc19442011-07-06 02:13:41 +0000804static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000805ScanFormatDescriptor (const char* var_name_begin,
806 const char* var_name_end,
807 const char** var_name_final,
808 const char** percent_position,
Greg Clayton4d122c42011-09-17 08:33:22 +0000809 Format* custom_format,
Enrico Granatadc940732011-08-23 00:32:52 +0000810 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
Enrico Granata9fc19442011-07-06 02:13:41 +0000811{
Enrico Granatae992a082011-07-22 17:03:19 +0000812 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000813 *percent_position = ::strchr(var_name_begin,'%');
Greg Clayton34132752011-07-06 04:07:21 +0000814 if (!*percent_position || *percent_position > var_name_end)
Enrico Granatae992a082011-07-22 17:03:19 +0000815 {
816 if (log)
817 log->Printf("no format descriptor in string, skipping");
Enrico Granata9fc19442011-07-06 02:13:41 +0000818 *var_name_final = var_name_end;
Enrico Granatae992a082011-07-22 17:03:19 +0000819 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000820 else
821 {
822 *var_name_final = *percent_position;
823 char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0';
824 memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1);
Enrico Granatae992a082011-07-22 17:03:19 +0000825 if (log)
826 log->Printf("parsing %s as a format descriptor", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000827 if ( !FormatManager::GetFormatFromCString(format_name,
828 true,
829 *custom_format) )
830 {
Enrico Granatae992a082011-07-22 17:03:19 +0000831 if (log)
832 log->Printf("%s is an unknown format", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000833 // if this is an @ sign, print ObjC description
Greg Clayton34132752011-07-06 04:07:21 +0000834 if (*format_name == '@')
Enrico Granata9fc19442011-07-06 02:13:41 +0000835 *val_obj_display = ValueObject::eDisplayLanguageSpecific;
836 // if this is a V, print the value using the default format
Enrico Granatae992a082011-07-22 17:03:19 +0000837 else if (*format_name == 'V')
Enrico Granata9fc19442011-07-06 02:13:41 +0000838 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatad55546b2011-07-22 00:16:08 +0000839 // if this is an L, print the location of the value
Enrico Granatae992a082011-07-22 17:03:19 +0000840 else if (*format_name == 'L')
Enrico Granataf2bbf712011-07-15 02:26:42 +0000841 *val_obj_display = ValueObject::eDisplayLocation;
Enrico Granatad55546b2011-07-22 00:16:08 +0000842 // if this is an S, print the summary after all
Enrico Granatae992a082011-07-22 17:03:19 +0000843 else if (*format_name == 'S')
Enrico Granatad55546b2011-07-22 00:16:08 +0000844 *val_obj_display = ValueObject::eDisplaySummary;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000845 else if (*format_name == '#')
846 *val_obj_display = ValueObject::eDisplayChildrenCount;
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000847 else if (*format_name == 'T')
848 *val_obj_display = ValueObject::eDisplayType;
Enrico Granatae992a082011-07-22 17:03:19 +0000849 else if (log)
850 log->Printf("%s is an error, leaving the previous value alone", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000851 }
852 // a good custom format tells us to print the value using it
853 else
Enrico Granatae992a082011-07-22 17:03:19 +0000854 {
855 if (log)
856 log->Printf("will display value for this VO");
Enrico Granata9fc19442011-07-06 02:13:41 +0000857 *val_obj_display = ValueObject::eDisplayValue;
Enrico Granatae992a082011-07-22 17:03:19 +0000858 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000859 delete format_name;
860 }
Enrico Granatae992a082011-07-22 17:03:19 +0000861 if (log)
862 log->Printf("final format description outcome: custom_format = %d, val_obj_display = %d",
863 *custom_format,
864 *val_obj_display);
Enrico Granata9fc19442011-07-06 02:13:41 +0000865 return true;
866}
867
868static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000869ScanBracketedRange (const char* var_name_begin,
870 const char* var_name_end,
871 const char* var_name_final,
872 const char** open_bracket_position,
873 const char** separator_position,
874 const char** close_bracket_position,
875 const char** var_name_final_if_array_range,
876 int64_t* index_lower,
877 int64_t* index_higher)
Enrico Granata9fc19442011-07-06 02:13:41 +0000878{
Enrico Granatae992a082011-07-22 17:03:19 +0000879 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000880 *open_bracket_position = ::strchr(var_name_begin,'[');
Greg Clayton34132752011-07-06 04:07:21 +0000881 if (*open_bracket_position && *open_bracket_position < var_name_final)
Enrico Granata9fc19442011-07-06 02:13:41 +0000882 {
883 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
884 *close_bracket_position = ::strchr(*open_bracket_position,']');
885 // as usual, we assume that [] will come before %
886 //printf("trying to expand a []\n");
887 *var_name_final_if_array_range = *open_bracket_position;
Greg Clayton34132752011-07-06 04:07:21 +0000888 if (*close_bracket_position - *open_bracket_position == 1)
Enrico Granata9fc19442011-07-06 02:13:41 +0000889 {
Enrico Granatae992a082011-07-22 17:03:19 +0000890 if (log)
891 log->Printf("[] detected.. going from 0 to end of data");
Enrico Granata9fc19442011-07-06 02:13:41 +0000892 *index_lower = 0;
893 }
894 else if (*separator_position == NULL || *separator_position > var_name_end)
895 {
896 char *end = NULL;
897 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
898 *index_higher = *index_lower;
Enrico Granatae992a082011-07-22 17:03:19 +0000899 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000900 log->Printf("[%lld] detected, high index is same", *index_lower);
Enrico Granata9fc19442011-07-06 02:13:41 +0000901 }
Greg Clayton34132752011-07-06 04:07:21 +0000902 else if (*close_bracket_position && *close_bracket_position < var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +0000903 {
904 char *end = NULL;
905 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
906 *index_higher = ::strtoul (*separator_position+1, &end, 0);
Enrico Granatae992a082011-07-22 17:03:19 +0000907 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000908 log->Printf("[%lld-%lld] detected", *index_lower, *index_higher);
Enrico Granata9fc19442011-07-06 02:13:41 +0000909 }
910 else
Enrico Granatae992a082011-07-22 17:03:19 +0000911 {
912 if (log)
913 log->Printf("expression is erroneous, cannot extract indices out of it");
Enrico Granata9fc19442011-07-06 02:13:41 +0000914 return false;
Enrico Granatae992a082011-07-22 17:03:19 +0000915 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000916 if (*index_lower > *index_higher && *index_higher > 0)
917 {
Enrico Granatae992a082011-07-22 17:03:19 +0000918 if (log)
919 log->Printf("swapping indices");
Enrico Granata9fc19442011-07-06 02:13:41 +0000920 int temp = *index_lower;
921 *index_lower = *index_higher;
922 *index_higher = temp;
923 }
924 }
Enrico Granatae992a082011-07-22 17:03:19 +0000925 else if (log)
926 log->Printf("no bracketed range, skipping entirely");
Enrico Granata9fc19442011-07-06 02:13:41 +0000927 return true;
928}
929
930
931static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000932ExpandExpressionPath (ValueObject* valobj,
933 StackFrame* frame,
934 bool* do_deref_pointer,
935 const char* var_name_begin,
936 const char* var_name_final,
937 Error& error)
Enrico Granata9fc19442011-07-06 02:13:41 +0000938{
Enrico Granatae992a082011-07-22 17:03:19 +0000939 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000940 StreamString sstring;
941 VariableSP var_sp;
942
Greg Clayton34132752011-07-06 04:07:21 +0000943 if (*do_deref_pointer)
Enrico Granatae992a082011-07-22 17:03:19 +0000944 {
945 if (log)
946 log->Printf("been told to deref_pointer by caller");
Enrico Granata9fc19442011-07-06 02:13:41 +0000947 sstring.PutChar('*');
Enrico Granatae992a082011-07-22 17:03:19 +0000948 }
Enrico Granatac482a192011-08-17 22:13:59 +0000949 else if (valobj->IsDereferenceOfParent() && ClangASTContext::IsPointerType(valobj->GetParent()->GetClangType()) && !valobj->IsArrayItemForPointer())
Enrico Granata9fc19442011-07-06 02:13:41 +0000950 {
Enrico Granatae992a082011-07-22 17:03:19 +0000951 if (log)
952 log->Printf("decided to deref_pointer myself");
Enrico Granata9fc19442011-07-06 02:13:41 +0000953 sstring.PutChar('*');
954 *do_deref_pointer = true;
955 }
956
Enrico Granatac482a192011-08-17 22:13:59 +0000957 valobj->GetExpressionPath(sstring, true, ValueObject::eHonorPointers);
Enrico Granatae992a082011-07-22 17:03:19 +0000958 if (log)
959 log->Printf("expression path to expand in phase 0: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000960 sstring.PutRawBytes(var_name_begin+3, var_name_final-var_name_begin-3);
Enrico Granatae992a082011-07-22 17:03:19 +0000961 if (log)
962 log->Printf("expression path to expand in phase 1: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +0000963 std::string name = std::string(sstring.GetData());
964 ValueObjectSP target = frame->GetValueForVariableExpressionPath (name.c_str(),
965 eNoDynamicValues,
966 0,
967 var_sp,
968 error);
969 return target;
970}
971
972static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000973ExpandIndexedExpression (ValueObject* valobj,
974 uint32_t index,
975 StackFrame* frame,
976 bool deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +0000977{
Enrico Granatae992a082011-07-22 17:03:19 +0000978 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000979 const char* ptr_deref_format = "[%d]";
980 std::auto_ptr<char> ptr_deref_buffer(new char[10]);
981 ::sprintf(ptr_deref_buffer.get(), ptr_deref_format, index);
Enrico Granatae992a082011-07-22 17:03:19 +0000982 if (log)
983 log->Printf("name to deref: %s",ptr_deref_buffer.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000984 const char* first_unparsed;
985 ValueObject::GetValueForExpressionPathOptions options;
986 ValueObject::ExpressionPathEndResultType final_value_type;
987 ValueObject::ExpressionPathScanEndReason reason_to_stop;
988 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eDereference : ValueObject::eNothing);
Enrico Granatac482a192011-08-17 22:13:59 +0000989 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000990 &first_unparsed,
991 &reason_to_stop,
992 &final_value_type,
993 options,
994 &what_next);
995 if (!item)
996 {
Enrico Granatae992a082011-07-22 17:03:19 +0000997 if (log)
998 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
999 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001000 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001001 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001002 else
1003 {
Enrico Granatae992a082011-07-22 17:03:19 +00001004 if (log)
1005 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1006 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001007 first_unparsed, reason_to_stop, final_value_type);
Enrico Granata9fc19442011-07-06 02:13:41 +00001008 }
1009 return item;
1010}
1011
Greg Clayton1b654882010-09-19 02:33:57 +00001012bool
1013Debugger::FormatPrompt
1014(
1015 const char *format,
1016 const SymbolContext *sc,
1017 const ExecutionContext *exe_ctx,
1018 const Address *addr,
1019 Stream &s,
Enrico Granata4becb372011-06-29 22:27:15 +00001020 const char **end,
Enrico Granatac482a192011-08-17 22:13:59 +00001021 ValueObject* valobj
Greg Clayton1b654882010-09-19 02:33:57 +00001022)
1023{
Enrico Granatac482a192011-08-17 22:13:59 +00001024 ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers
Greg Clayton1b654882010-09-19 02:33:57 +00001025 bool success = true;
1026 const char *p;
Enrico Granatae992a082011-07-22 17:03:19 +00001027 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Greg Clayton1b654882010-09-19 02:33:57 +00001028 for (p = format; *p != '\0'; ++p)
1029 {
Enrico Granatac482a192011-08-17 22:13:59 +00001030 if (realvalobj)
Enrico Granata4becb372011-06-29 22:27:15 +00001031 {
Enrico Granatac482a192011-08-17 22:13:59 +00001032 valobj = realvalobj;
1033 realvalobj = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00001034 }
Greg Clayton1b654882010-09-19 02:33:57 +00001035 size_t non_special_chars = ::strcspn (p, "${}\\");
1036 if (non_special_chars > 0)
1037 {
1038 if (success)
1039 s.Write (p, non_special_chars);
1040 p += non_special_chars;
1041 }
1042
1043 if (*p == '\0')
1044 {
1045 break;
1046 }
1047 else if (*p == '{')
1048 {
1049 // Start a new scope that must have everything it needs if it is to
1050 // to make it into the final output stream "s". If you want to make
1051 // a format that only prints out the function or symbol name if there
1052 // is one in the symbol context you can use:
1053 // "{function =${function.name}}"
1054 // The first '{' starts a new scope that end with the matching '}' at
1055 // the end of the string. The contents "function =${function.name}"
1056 // will then be evaluated and only be output if there is a function
1057 // or symbol with a valid name.
1058 StreamString sub_strm;
1059
1060 ++p; // Skip the '{'
1061
Enrico Granatac482a192011-08-17 22:13:59 +00001062 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
Greg Clayton1b654882010-09-19 02:33:57 +00001063 {
1064 // The stream had all it needed
1065 s.Write(sub_strm.GetData(), sub_strm.GetSize());
1066 }
1067 if (*p != '}')
1068 {
1069 success = false;
1070 break;
1071 }
1072 }
1073 else if (*p == '}')
1074 {
1075 // End of a enclosing scope
1076 break;
1077 }
1078 else if (*p == '$')
1079 {
1080 // We have a prompt variable to print
1081 ++p;
1082 if (*p == '{')
1083 {
1084 ++p;
1085 const char *var_name_begin = p;
1086 const char *var_name_end = ::strchr (p, '}');
1087
1088 if (var_name_end && var_name_begin < var_name_end)
1089 {
1090 // if we have already failed to parse, skip this variable
1091 if (success)
1092 {
1093 const char *cstr = NULL;
1094 Address format_addr;
1095 bool calculate_format_addr_function_offset = false;
1096 // Set reg_kind and reg_num to invalid values
1097 RegisterKind reg_kind = kNumRegisterKinds;
1098 uint32_t reg_num = LLDB_INVALID_REGNUM;
1099 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +00001100 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00001101 RegisterContext *reg_ctx = NULL;
Enrico Granata9fc19442011-07-06 02:13:41 +00001102 bool do_deref_pointer = false;
Enrico Granatae992a082011-07-22 17:03:19 +00001103 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eEndOfString;
1104 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::ePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001105
Greg Clayton1b654882010-09-19 02:33:57 +00001106 // Each variable must set success to true below...
1107 bool var_success = false;
1108 switch (var_name_begin[0])
1109 {
Enrico Granata4becb372011-06-29 22:27:15 +00001110 case '*':
Enrico Granata4becb372011-06-29 22:27:15 +00001111 case 'v':
Enrico Granata6f3533f2011-07-29 19:53:35 +00001112 case 's':
Enrico Granata4becb372011-06-29 22:27:15 +00001113 {
Enrico Granatac482a192011-08-17 22:13:59 +00001114 if (!valobj)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001115 break;
1116
Enrico Granatac3e320a2011-08-02 17:27:39 +00001117 if (log)
1118 log->Printf("initial string: %s",var_name_begin);
1119
Enrico Granata6f3533f2011-07-29 19:53:35 +00001120 // check for *var and *svar
1121 if (*var_name_begin == '*')
1122 {
1123 do_deref_pointer = true;
1124 var_name_begin++;
1125 }
Enrico Granatac3e320a2011-08-02 17:27:39 +00001126
1127 if (log)
1128 log->Printf("initial string: %s",var_name_begin);
1129
Enrico Granata6f3533f2011-07-29 19:53:35 +00001130 if (*var_name_begin == 's')
1131 {
Greg Clayton4d122c42011-09-17 08:33:22 +00001132 valobj = valobj->GetSyntheticValue(eUseSyntheticFilter).get();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001133 var_name_begin++;
1134 }
1135
Enrico Granatac3e320a2011-08-02 17:27:39 +00001136 if (log)
1137 log->Printf("initial string: %s",var_name_begin);
1138
Enrico Granata6f3533f2011-07-29 19:53:35 +00001139 // should be a 'v' by now
1140 if (*var_name_begin != 'v')
1141 break;
1142
Enrico Granatac3e320a2011-08-02 17:27:39 +00001143 if (log)
1144 log->Printf("initial string: %s",var_name_begin);
1145
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001146 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
1147 ValueObject::eDereference : ValueObject::eNothing);
1148 ValueObject::GetValueForExpressionPathOptions options;
Enrico Granata8c9d3562011-08-11 17:08:01 +00001149 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren();
Greg Clayton34132752011-07-06 04:07:21 +00001150 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eDisplaySummary;
1151 ValueObject* target = NULL;
Greg Clayton4d122c42011-09-17 08:33:22 +00001152 Format custom_format = eFormatInvalid;
Greg Clayton34132752011-07-06 04:07:21 +00001153 const char* var_name_final = NULL;
1154 const char* var_name_final_if_array_range = NULL;
1155 const char* close_bracket_position = NULL;
1156 int64_t index_lower = -1;
1157 int64_t index_higher = -1;
1158 bool is_array_range = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001159 const char* first_unparsed;
Enrico Granata85933ed2011-08-18 16:38:26 +00001160 bool was_plain_var = false;
1161 bool was_var_format = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001162
Enrico Granatac482a192011-08-17 22:13:59 +00001163 if (!valobj) break;
1164 // simplest case ${var}, just print valobj's value
Greg Clayton34132752011-07-06 04:07:21 +00001165 if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0)
Enrico Granata4becb372011-06-29 22:27:15 +00001166 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001167 was_plain_var = true;
Enrico Granatac482a192011-08-17 22:13:59 +00001168 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001169 val_obj_display = ValueObject::eDisplayValue;
1170 }
1171 else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0)
1172 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001173 was_var_format = true;
Greg Clayton34132752011-07-06 04:07:21 +00001174 // this is a variable with some custom format applied to it
1175 const char* percent_position;
Enrico Granatac482a192011-08-17 22:13:59 +00001176 target = valobj;
Greg Clayton34132752011-07-06 04:07:21 +00001177 val_obj_display = ValueObject::eDisplayValue;
1178 ScanFormatDescriptor (var_name_begin,
1179 var_name_end,
1180 &var_name_final,
1181 &percent_position,
1182 &custom_format,
1183 &val_obj_display);
1184 }
1185 // this is ${var.something} or multiple .something nested
1186 else if (::strncmp (var_name_begin, "var", strlen("var")) == 0)
1187 {
1188
1189 const char* percent_position;
1190 ScanFormatDescriptor (var_name_begin,
1191 var_name_end,
1192 &var_name_final,
1193 &percent_position,
1194 &custom_format,
1195 &val_obj_display);
1196
1197 const char* open_bracket_position;
1198 const char* separator_position;
1199 ScanBracketedRange (var_name_begin,
1200 var_name_end,
1201 var_name_final,
1202 &open_bracket_position,
1203 &separator_position,
1204 &close_bracket_position,
1205 &var_name_final_if_array_range,
1206 &index_lower,
1207 &index_higher);
1208
1209 Error error;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001210
1211 std::auto_ptr<char> expr_path(new char[var_name_final-var_name_begin-1]);
1212 ::memset(expr_path.get(), 0, var_name_final-var_name_begin-1);
1213 memcpy(expr_path.get(), var_name_begin+3,var_name_final-var_name_begin-3);
1214
Enrico Granatae992a082011-07-22 17:03:19 +00001215 if (log)
1216 log->Printf("symbol to expand: %s",expr_path.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001217
Enrico Granatac482a192011-08-17 22:13:59 +00001218 target = valobj->GetValueForExpressionPath(expr_path.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001219 &first_unparsed,
1220 &reason_to_stop,
1221 &final_value_type,
1222 options,
1223 &what_next).get();
1224
1225 if (!target)
Enrico Granata9fc19442011-07-06 02:13:41 +00001226 {
Enrico Granatae992a082011-07-22 17:03:19 +00001227 if (log)
1228 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1229 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001230 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001231 break;
Enrico Granata9fc19442011-07-06 02:13:41 +00001232 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001233 else
1234 {
Enrico Granatae992a082011-07-22 17:03:19 +00001235 if (log)
1236 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1237 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001238 first_unparsed, reason_to_stop, final_value_type);
1239 }
Enrico Granata4becb372011-06-29 22:27:15 +00001240 }
Greg Clayton34132752011-07-06 04:07:21 +00001241 else
Enrico Granata9fc19442011-07-06 02:13:41 +00001242 break;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001243
1244 is_array_range = (final_value_type == ValueObject::eBoundedRange ||
1245 final_value_type == ValueObject::eUnboundedRange);
1246
1247 do_deref_pointer = (what_next == ValueObject::eDereference);
Enrico Granata9fc19442011-07-06 02:13:41 +00001248
Enrico Granataa7187d02011-07-06 19:27:11 +00001249 if (do_deref_pointer && !is_array_range)
Enrico Granata9fc19442011-07-06 02:13:41 +00001250 {
Greg Clayton34132752011-07-06 04:07:21 +00001251 // I have not deref-ed yet, let's do it
1252 // this happens when we are not going through GetValueForVariableExpressionPath
1253 // to get to the target ValueObject
Enrico Granata9fc19442011-07-06 02:13:41 +00001254 Error error;
Greg Clayton34132752011-07-06 04:07:21 +00001255 target = target->Dereference(error).get();
Enrico Granatadc940732011-08-23 00:32:52 +00001256 if (error.Fail())
1257 {
1258 if (log)
1259 log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
1260 break;
1261 }
Greg Clayton34132752011-07-06 04:07:21 +00001262 do_deref_pointer = false;
Enrico Granata9fc19442011-07-06 02:13:41 +00001263 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001264
Enrico Granata85933ed2011-08-18 16:38:26 +00001265 // TODO use flags for these
Enrico Granataf4efecd2011-07-12 22:56:10 +00001266 bool is_array = ClangASTContext::IsArrayType(target->GetClangType());
1267 bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType());
Enrico Granata85933ed2011-08-18 16:38:26 +00001268 bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType());
Enrico Granataf4efecd2011-07-12 22:56:10 +00001269
1270 if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eDisplayValue) // this should be wrong, but there are some exceptions
1271 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001272 StreamString str_temp;
Enrico Granatae992a082011-07-22 17:03:19 +00001273 if (log)
1274 log->Printf("I am into array || pointer && !range");
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001275
1276 if (target->HasSpecialCasesForPrintableRepresentation(val_obj_display,
1277 custom_format))
Enrico Granata85933ed2011-08-18 16:38:26 +00001278 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001279 // try to use the special cases
1280 var_success = target->DumpPrintableRepresentation(str_temp,
1281 val_obj_display,
1282 custom_format);
1283 if (log)
1284 log->Printf("special cases did%s match", var_success ? "" : "n't");
1285
1286 // should not happen
1287 if (!var_success)
1288 s << "<invalid usage of pointer value as object>";
1289 else
1290 s << str_temp.GetData();
Enrico Granata85933ed2011-08-18 16:38:26 +00001291 var_success = true;
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001292 break;
Enrico Granata85933ed2011-08-18 16:38:26 +00001293 }
1294 else
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001295 {
Enrico Granata88da35f2011-08-23 21:26:09 +00001296 if (was_plain_var) // if ${var}
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001297 {
1298 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1299 }
Enrico Granata88da35f2011-08-23 21:26:09 +00001300 else if (is_pointer) // if pointer, value is the address stored
1301 {
1302 var_success = target->GetPrintableRepresentation(s,
1303 val_obj_display,
1304 custom_format);
1305 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001306 else
1307 {
1308 s << "<invalid usage of pointer value as object>";
1309 }
1310 var_success = true;
1311 break;
1312 }
1313 }
1314
1315 // if directly trying to print ${var}, and this is an aggregate, display a nice
1316 // type @ location message
1317 if (is_aggregate && was_plain_var)
1318 {
1319 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1320 var_success = true;
Enrico Granata85933ed2011-08-18 16:38:26 +00001321 break;
1322 }
1323
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001324 // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it
1325 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eDisplayValue)))
Enrico Granata85933ed2011-08-18 16:38:26 +00001326 {
1327 s << "<invalid use of aggregate type>";
1328 var_success = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001329 break;
1330 }
Greg Clayton34132752011-07-06 04:07:21 +00001331
1332 if (!is_array_range)
Enrico Granatae992a082011-07-22 17:03:19 +00001333 {
1334 if (log)
1335 log->Printf("dumping ordinary printable output");
Greg Clayton34132752011-07-06 04:07:21 +00001336 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
Enrico Granatae992a082011-07-22 17:03:19 +00001337 }
Greg Clayton34132752011-07-06 04:07:21 +00001338 else
Enrico Granatae992a082011-07-22 17:03:19 +00001339 {
1340 if (log)
1341 log->Printf("checking if I can handle as array");
Greg Clayton34132752011-07-06 04:07:21 +00001342 if (!is_array && !is_pointer)
1343 break;
Enrico Granatae992a082011-07-22 17:03:19 +00001344 if (log)
1345 log->Printf("handle as array");
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001346 const char* special_directions = NULL;
1347 StreamString special_directions_writer;
Greg Clayton34132752011-07-06 04:07:21 +00001348 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1349 {
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001350 ConstString additional_data;
1351 additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1);
1352 special_directions_writer.Printf("${%svar%s}",
1353 do_deref_pointer ? "*" : "",
1354 additional_data.GetCString());
1355 special_directions = special_directions_writer.GetData();
Greg Clayton34132752011-07-06 04:07:21 +00001356 }
1357
1358 // let us display items index_lower thru index_higher of this array
1359 s.PutChar('[');
1360 var_success = true;
1361
1362 if (index_higher < 0)
Enrico Granatac482a192011-08-17 22:13:59 +00001363 index_higher = valobj->GetNumChildren() - 1;
Greg Clayton34132752011-07-06 04:07:21 +00001364
Enrico Granata22c55d12011-08-12 02:00:06 +00001365 uint32_t max_num_children = target->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
1366
Greg Clayton34132752011-07-06 04:07:21 +00001367 for (;index_lower<=index_higher;index_lower++)
1368 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001369 ValueObject* item = ExpandIndexedExpression (target,
1370 index_lower,
1371 exe_ctx->GetFramePtr(),
1372 false).get();
Greg Clayton34132752011-07-06 04:07:21 +00001373
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001374 if (!item)
1375 {
Enrico Granatae992a082011-07-22 17:03:19 +00001376 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001377 log->Printf("ERROR in getting child item at index %lld", index_lower);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001378 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001379 else
1380 {
Enrico Granatae992a082011-07-22 17:03:19 +00001381 if (log)
1382 log->Printf("special_directions for child item: %s",special_directions);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001383 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001384
Greg Clayton34132752011-07-06 04:07:21 +00001385 if (!special_directions)
1386 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1387 else
1388 var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
1389
Enrico Granata22c55d12011-08-12 02:00:06 +00001390 if (--max_num_children == 0)
1391 {
1392 s.PutCString(", ...");
1393 break;
1394 }
1395
Greg Clayton34132752011-07-06 04:07:21 +00001396 if (index_lower < index_higher)
1397 s.PutChar(',');
1398 }
1399 s.PutChar(']');
1400 }
Enrico Granata4becb372011-06-29 22:27:15 +00001401 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001402 break;
Greg Clayton1b654882010-09-19 02:33:57 +00001403 case 'a':
1404 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
1405 {
1406 if (addr && addr->IsValid())
1407 {
1408 var_success = true;
1409 format_addr = *addr;
1410 }
1411 }
Greg Clayton5a314712011-10-14 07:41:33 +00001412 else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0)
1413 {
1414 var_success = true;
1415 var_name_begin += strlen("ansi."); // Skip the "ansi."
1416 if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0)
1417 {
1418 var_name_begin += strlen("fg."); // Skip the "fg."
1419 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1420 {
1421 s.Printf ("%s%s%s",
1422 lldb_utility::ansi::k_escape_start,
1423 lldb_utility::ansi::k_fg_black,
1424 lldb_utility::ansi::k_escape_end);
1425 }
1426 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1427 {
1428 s.Printf ("%s%s%s",
1429 lldb_utility::ansi::k_escape_start,
1430 lldb_utility::ansi::k_fg_red,
1431 lldb_utility::ansi::k_escape_end);
1432 }
1433 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1434 {
1435 s.Printf ("%s%s%s",
1436 lldb_utility::ansi::k_escape_start,
1437 lldb_utility::ansi::k_fg_green,
1438 lldb_utility::ansi::k_escape_end);
1439 }
1440 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1441 {
1442 s.Printf ("%s%s%s",
1443 lldb_utility::ansi::k_escape_start,
1444 lldb_utility::ansi::k_fg_yellow,
1445 lldb_utility::ansi::k_escape_end);
1446 }
1447 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1448 {
1449 s.Printf ("%s%s%s",
1450 lldb_utility::ansi::k_escape_start,
1451 lldb_utility::ansi::k_fg_blue,
1452 lldb_utility::ansi::k_escape_end);
1453 }
1454 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1455 {
1456 s.Printf ("%s%s%s",
1457 lldb_utility::ansi::k_escape_start,
1458 lldb_utility::ansi::k_fg_purple,
1459 lldb_utility::ansi::k_escape_end);
1460 }
1461 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1462 {
1463 s.Printf ("%s%s%s",
1464 lldb_utility::ansi::k_escape_start,
1465 lldb_utility::ansi::k_fg_cyan,
1466 lldb_utility::ansi::k_escape_end);
1467 }
1468 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1469 {
1470 s.Printf ("%s%s%s",
1471 lldb_utility::ansi::k_escape_start,
1472 lldb_utility::ansi::k_fg_white,
1473 lldb_utility::ansi::k_escape_end);
1474 }
1475 else
1476 {
1477 var_success = false;
1478 }
1479 }
1480 else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0)
1481 {
1482 var_name_begin += strlen("bg."); // Skip the "bg."
1483 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1484 {
1485 s.Printf ("%s%s%s",
1486 lldb_utility::ansi::k_escape_start,
1487 lldb_utility::ansi::k_bg_black,
1488 lldb_utility::ansi::k_escape_end);
1489 }
1490 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1491 {
1492 s.Printf ("%s%s%s",
1493 lldb_utility::ansi::k_escape_start,
1494 lldb_utility::ansi::k_bg_red,
1495 lldb_utility::ansi::k_escape_end);
1496 }
1497 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1498 {
1499 s.Printf ("%s%s%s",
1500 lldb_utility::ansi::k_escape_start,
1501 lldb_utility::ansi::k_bg_green,
1502 lldb_utility::ansi::k_escape_end);
1503 }
1504 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1505 {
1506 s.Printf ("%s%s%s",
1507 lldb_utility::ansi::k_escape_start,
1508 lldb_utility::ansi::k_bg_yellow,
1509 lldb_utility::ansi::k_escape_end);
1510 }
1511 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1512 {
1513 s.Printf ("%s%s%s",
1514 lldb_utility::ansi::k_escape_start,
1515 lldb_utility::ansi::k_bg_blue,
1516 lldb_utility::ansi::k_escape_end);
1517 }
1518 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1519 {
1520 s.Printf ("%s%s%s",
1521 lldb_utility::ansi::k_escape_start,
1522 lldb_utility::ansi::k_bg_purple,
1523 lldb_utility::ansi::k_escape_end);
1524 }
1525 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1526 {
1527 s.Printf ("%s%s%s",
1528 lldb_utility::ansi::k_escape_start,
1529 lldb_utility::ansi::k_bg_cyan,
1530 lldb_utility::ansi::k_escape_end);
1531 }
1532 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1533 {
1534 s.Printf ("%s%s%s",
1535 lldb_utility::ansi::k_escape_start,
1536 lldb_utility::ansi::k_bg_white,
1537 lldb_utility::ansi::k_escape_end);
1538 }
1539 else
1540 {
1541 var_success = false;
1542 }
1543 }
1544 else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0)
1545 {
1546 s.Printf ("%s%s%s",
1547 lldb_utility::ansi::k_escape_start,
1548 lldb_utility::ansi::k_ctrl_normal,
1549 lldb_utility::ansi::k_escape_end);
1550 }
1551 else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0)
1552 {
1553 s.Printf ("%s%s%s",
1554 lldb_utility::ansi::k_escape_start,
1555 lldb_utility::ansi::k_ctrl_bold,
1556 lldb_utility::ansi::k_escape_end);
1557 }
1558 else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0)
1559 {
1560 s.Printf ("%s%s%s",
1561 lldb_utility::ansi::k_escape_start,
1562 lldb_utility::ansi::k_ctrl_faint,
1563 lldb_utility::ansi::k_escape_end);
1564 }
1565 else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0)
1566 {
1567 s.Printf ("%s%s%s",
1568 lldb_utility::ansi::k_escape_start,
1569 lldb_utility::ansi::k_ctrl_italic,
1570 lldb_utility::ansi::k_escape_end);
1571 }
1572 else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0)
1573 {
1574 s.Printf ("%s%s%s",
1575 lldb_utility::ansi::k_escape_start,
1576 lldb_utility::ansi::k_ctrl_underline,
1577 lldb_utility::ansi::k_escape_end);
1578 }
1579 else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0)
1580 {
1581 s.Printf ("%s%s%s",
1582 lldb_utility::ansi::k_escape_start,
1583 lldb_utility::ansi::k_ctrl_slow_blink,
1584 lldb_utility::ansi::k_escape_end);
1585 }
1586 else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0)
1587 {
1588 s.Printf ("%s%s%s",
1589 lldb_utility::ansi::k_escape_start,
1590 lldb_utility::ansi::k_ctrl_fast_blink,
1591 lldb_utility::ansi::k_escape_end);
1592 }
1593 else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0)
1594 {
1595 s.Printf ("%s%s%s",
1596 lldb_utility::ansi::k_escape_start,
1597 lldb_utility::ansi::k_ctrl_negative,
1598 lldb_utility::ansi::k_escape_end);
1599 }
1600 else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0)
1601 {
1602 s.Printf ("%s%s%s",
1603 lldb_utility::ansi::k_escape_start,
1604 lldb_utility::ansi::k_ctrl_conceal,
1605 lldb_utility::ansi::k_escape_end);
1606
1607 }
1608 else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0)
1609 {
1610 s.Printf ("%s%s%s",
1611 lldb_utility::ansi::k_escape_start,
1612 lldb_utility::ansi::k_ctrl_crossed_out,
1613 lldb_utility::ansi::k_escape_end);
1614 }
1615 else
1616 {
1617 var_success = false;
1618 }
1619 }
Greg Clayton1b654882010-09-19 02:33:57 +00001620 break;
1621
1622 case 'p':
1623 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
1624 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001625 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001626 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001627 Process *process = exe_ctx->GetProcessPtr();
1628 if (process)
Greg Clayton1b654882010-09-19 02:33:57 +00001629 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001630 var_name_begin += ::strlen ("process.");
1631 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001632 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001633 s.Printf("%llu", process->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001634 var_success = true;
1635 }
1636 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
1637 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
1638 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
1639 {
1640 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1641 if (exe_module)
Greg Clayton1b654882010-09-19 02:33:57 +00001642 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001643 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1644 {
1645 format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
1646 var_success = format_file_spec;
1647 }
1648 else
1649 {
1650 format_file_spec = exe_module->GetFileSpec();
1651 var_success = format_file_spec;
1652 }
Greg Clayton1b654882010-09-19 02:33:57 +00001653 }
1654 }
1655 }
Greg Claytonc14ee322011-09-22 04:58:26 +00001656 }
Greg Clayton1b654882010-09-19 02:33:57 +00001657 }
1658 break;
1659
1660 case 't':
1661 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
1662 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001663 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001664 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001665 Thread *thread = exe_ctx->GetThreadPtr();
1666 if (thread)
Greg Clayton1b654882010-09-19 02:33:57 +00001667 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001668 var_name_begin += ::strlen ("thread.");
1669 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001670 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001671 s.Printf("0x%4.4llx", thread->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001672 var_success = true;
1673 }
1674 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1675 {
1676 s.Printf("%u", thread->GetIndexID());
1677 var_success = true;
1678 }
1679 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1680 {
1681 cstr = thread->GetName();
1682 var_success = cstr && cstr[0];
1683 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001684 s.PutCString(cstr);
Greg Claytonc14ee322011-09-22 04:58:26 +00001685 }
1686 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
1687 {
1688 cstr = thread->GetQueueName();
1689 var_success = cstr && cstr[0];
1690 if (var_success)
1691 s.PutCString(cstr);
1692 }
1693 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
1694 {
1695 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1696 if (stop_info_sp)
1697 {
1698 cstr = stop_info_sp->GetDescription();
1699 if (cstr && cstr[0])
1700 {
1701 s.PutCString(cstr);
1702 var_success = true;
1703 }
Greg Clayton1b654882010-09-19 02:33:57 +00001704 }
1705 }
Jim Ingham73ca05a2011-12-17 01:35:57 +00001706 else if (::strncmp (var_name_begin, "return-value}", strlen("return-value}")) == 0)
1707 {
1708 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1709 if (stop_info_sp)
1710 {
1711 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1712 if (return_valobj_sp)
1713 {
Jim Inghamef651602011-12-22 19:12:40 +00001714 ValueObject::DumpValueObjectOptions dump_options;
1715 ValueObject::DumpValueObject (s, return_valobj_sp.get(), dump_options);
1716 var_success = true;
Jim Ingham73ca05a2011-12-17 01:35:57 +00001717 }
1718 }
1719 }
Greg Clayton1b654882010-09-19 02:33:57 +00001720 }
1721 }
1722 }
1723 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
1724 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001725 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1726 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +00001727 {
Greg Clayton1b654882010-09-19 02:33:57 +00001728 var_name_begin += ::strlen ("target.");
1729 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
1730 {
1731 ArchSpec arch (target->GetArchitecture ());
1732 if (arch.IsValid())
1733 {
Greg Clayton64195a22011-02-23 00:35:02 +00001734 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +00001735 var_success = true;
1736 }
1737 }
1738 }
1739 }
1740 break;
1741
1742
1743 case 'm':
1744 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
1745 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001746 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +00001747 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001748 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +00001749 var_name_begin += ::strlen ("module.");
1750
1751 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1752 {
1753 if (module->GetFileSpec())
1754 {
1755 var_name_begin += ::strlen ("file.");
1756
1757 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1758 {
1759 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
1760 var_success = format_file_spec;
1761 }
1762 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1763 {
1764 format_file_spec = module->GetFileSpec();
1765 var_success = format_file_spec;
1766 }
1767 }
1768 }
1769 }
1770 }
1771 break;
1772
1773
1774 case 'f':
1775 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1776 {
1777 if (sc && sc->comp_unit != NULL)
1778 {
1779 var_name_begin += ::strlen ("file.");
1780
1781 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1782 {
1783 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
1784 var_success = format_file_spec;
1785 }
1786 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1787 {
1788 format_file_spec = *sc->comp_unit;
1789 var_success = format_file_spec;
1790 }
1791 }
1792 }
1793 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
1794 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001795 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001796 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001797 StackFrame *frame = exe_ctx->GetFramePtr();
1798 if (frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001799 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001800 var_name_begin += ::strlen ("frame.");
1801 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001802 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001803 s.Printf("%u", frame->GetFrameIndex());
1804 var_success = true;
1805 }
1806 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
1807 {
1808 reg_kind = eRegisterKindGeneric;
1809 reg_num = LLDB_REGNUM_GENERIC_PC;
1810 var_success = true;
1811 }
1812 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
1813 {
1814 reg_kind = eRegisterKindGeneric;
1815 reg_num = LLDB_REGNUM_GENERIC_SP;
1816 var_success = true;
1817 }
1818 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
1819 {
1820 reg_kind = eRegisterKindGeneric;
1821 reg_num = LLDB_REGNUM_GENERIC_FP;
1822 var_success = true;
1823 }
1824 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
1825 {
1826 reg_kind = eRegisterKindGeneric;
1827 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
1828 var_success = true;
1829 }
1830 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
1831 {
1832 reg_ctx = frame->GetRegisterContext().get();
1833 if (reg_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001834 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001835 var_name_begin += ::strlen ("reg.");
1836 if (var_name_begin < var_name_end)
1837 {
1838 std::string reg_name (var_name_begin, var_name_end);
1839 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
1840 if (reg_info)
1841 var_success = true;
1842 }
Greg Clayton1b654882010-09-19 02:33:57 +00001843 }
1844 }
1845 }
1846 }
1847 }
1848 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
1849 {
1850 if (sc && (sc->function != NULL || sc->symbol != NULL))
1851 {
1852 var_name_begin += ::strlen ("function.");
1853 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1854 {
1855 if (sc->function)
Greg Clayton81c22f62011-10-19 18:09:39 +00001856 s.Printf("function{0x%8.8llx}", sc->function->GetID());
Greg Clayton1b654882010-09-19 02:33:57 +00001857 else
1858 s.Printf("symbol[%u]", sc->symbol->GetID());
1859
1860 var_success = true;
1861 }
1862 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1863 {
1864 if (sc->function)
1865 cstr = sc->function->GetName().AsCString (NULL);
1866 else if (sc->symbol)
1867 cstr = sc->symbol->GetName().AsCString (NULL);
1868 if (cstr)
1869 {
1870 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001871
1872 if (sc->block)
1873 {
1874 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1875 if (inline_block)
1876 {
1877 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1878 if (inline_info)
1879 {
1880 s.PutCString(" [inlined] ");
1881 inline_info->GetName().Dump(&s);
1882 }
1883 }
1884 }
Greg Clayton1b654882010-09-19 02:33:57 +00001885 var_success = true;
1886 }
1887 }
Greg Clayton6d3dbf52012-01-13 08:39:16 +00001888 else if (::strncmp (var_name_begin, "name-with-args}", strlen("name-with-args}")) == 0)
1889 {
1890 // Print the function name with arguments in it
1891
1892 if (sc->function)
1893 {
1894 var_success = true;
1895 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
1896 cstr = sc->function->GetName().AsCString (NULL);
1897 if (cstr)
1898 {
1899 const InlineFunctionInfo *inline_info = NULL;
1900 VariableListSP variable_list_sp;
1901 bool get_function_vars = true;
1902 if (sc->block)
1903 {
1904 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1905
1906 if (inline_block)
1907 {
1908 get_function_vars = false;
1909 inline_info = sc->block->GetInlinedFunctionInfo();
1910 if (inline_info)
1911 variable_list_sp = inline_block->GetBlockVariableList (true);
1912 }
1913 }
1914
1915 if (get_function_vars)
1916 {
1917 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
1918 }
1919
1920 if (inline_info)
1921 {
1922 s.PutCString (cstr);
1923 s.PutCString (" [inlined] ");
1924 cstr = inline_info->GetName().GetCString();
1925 }
1926
1927 VariableList args;
1928 if (variable_list_sp)
1929 {
1930 const size_t num_variables = variable_list_sp->GetSize();
1931 for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
1932 {
1933 VariableSP var_sp (variable_list_sp->GetVariableAtIndex(var_idx));
1934 if (var_sp->GetScope() == eValueTypeVariableArgument)
1935 args.AddVariable (var_sp);
1936 }
1937
1938 }
1939 if (args.GetSize() > 0)
1940 {
1941 const char *open_paren = strchr (cstr, '(');
1942 const char *close_paren = NULL;
1943 if (open_paren)
1944 close_paren = strchr (open_paren, ')');
1945
1946 if (open_paren)
1947 s.Write(cstr, open_paren - cstr + 1);
1948 else
1949 {
1950 s.PutCString (cstr);
1951 s.PutChar ('(');
1952 }
1953 const size_t num_args = variable_list_sp->GetSize();
1954 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
1955 {
1956 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
1957 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
1958 const char *var_name = var_value_sp->GetName().GetCString();
1959 const char *var_value = var_value_sp->GetValueAsCString();
1960 if (var_value_sp->GetError().Success())
1961 {
1962 if (arg_idx > 0)
1963 s.PutCString (", ");
1964 s.Printf ("%s=%s", var_name, var_value);
1965 }
1966 }
1967
1968 if (close_paren)
1969 s.PutCString (close_paren);
1970 else
1971 s.PutChar(')');
1972
1973 }
1974 else
1975 {
1976 s.PutCString(cstr);
1977 }
1978 }
1979 }
1980 else if (sc->symbol)
1981 {
1982 cstr = sc->symbol->GetName().AsCString (NULL);
1983 if (cstr)
1984 {
1985 s.PutCString(cstr);
1986 var_success = true;
1987 }
1988 }
1989 }
Greg Clayton1b654882010-09-19 02:33:57 +00001990 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1991 {
1992 var_success = addr != NULL;
1993 if (var_success)
1994 {
1995 format_addr = *addr;
1996 calculate_format_addr_function_offset = true;
1997 }
1998 }
1999 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
2000 {
2001 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
2002 if (var_success)
2003 {
2004 format_addr = sc->line_entry.range.GetBaseAddress();
2005 calculate_format_addr_function_offset = true;
2006 }
2007 }
2008 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
2009 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002010 StackFrame *frame = exe_ctx->GetFramePtr();
2011 var_success = frame != NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00002012 if (var_success)
2013 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002014 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002015 calculate_format_addr_function_offset = true;
2016 }
2017 }
2018 }
2019 }
2020 break;
2021
2022 case 'l':
2023 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
2024 {
2025 if (sc && sc->line_entry.IsValid())
2026 {
2027 var_name_begin += ::strlen ("line.");
2028 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
2029 {
2030 var_name_begin += ::strlen ("file.");
2031
2032 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
2033 {
2034 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
2035 var_success = format_file_spec;
2036 }
2037 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
2038 {
2039 format_file_spec = sc->line_entry.file;
2040 var_success = format_file_spec;
2041 }
2042 }
2043 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
2044 {
2045 var_success = true;
2046 s.Printf("%u", sc->line_entry.line);
2047 }
2048 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
2049 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
2050 {
2051 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
2052 if (var_success)
2053 {
2054 format_addr = sc->line_entry.range.GetBaseAddress();
2055 if (var_name_begin[0] == 'e')
2056 format_addr.Slide (sc->line_entry.range.GetByteSize());
2057 }
2058 }
2059 }
2060 }
2061 break;
2062 }
2063
2064 if (var_success)
2065 {
2066 // If format addr is valid, then we need to print an address
2067 if (reg_num != LLDB_INVALID_REGNUM)
2068 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002069 StackFrame *frame = exe_ctx->GetFramePtr();
Greg Clayton1b654882010-09-19 02:33:57 +00002070 // We have a register value to display...
2071 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
2072 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002073 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002074 }
2075 else
2076 {
2077 if (reg_ctx == NULL)
Greg Claytonc14ee322011-09-22 04:58:26 +00002078 reg_ctx = frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00002079
2080 if (reg_ctx)
2081 {
2082 if (reg_kind != kNumRegisterKinds)
2083 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
2084 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
2085 var_success = reg_info != NULL;
2086 }
2087 }
2088 }
2089
2090 if (reg_info != NULL)
2091 {
Greg Clayton7349bd92011-05-09 20:18:18 +00002092 RegisterValue reg_value;
2093 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
2094 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00002095 {
Greg Clayton9a8fa912011-05-15 04:12:07 +00002096 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
Greg Clayton1b654882010-09-19 02:33:57 +00002097 }
2098 }
2099
2100 if (format_file_spec)
2101 {
2102 s << format_file_spec;
2103 }
2104
2105 // If format addr is valid, then we need to print an address
2106 if (format_addr.IsValid())
2107 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002108 var_success = false;
2109
Greg Clayton1b654882010-09-19 02:33:57 +00002110 if (calculate_format_addr_function_offset)
2111 {
2112 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00002113
Greg Clayton0603aa92010-10-04 01:05:56 +00002114 if (sc)
2115 {
2116 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00002117 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002118 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00002119 if (sc->block)
2120 {
2121 // Check to make sure we aren't in an inline
2122 // function. If we are, use the inline block
2123 // range that contains "format_addr" since
2124 // blocks can be discontiguous.
2125 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2126 AddressRange inline_range;
2127 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
2128 func_addr = inline_range.GetBaseAddress();
2129 }
2130 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002131 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
2132 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
2133 }
2134
2135 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00002136 {
2137 if (func_addr.GetSection() == format_addr.GetSection())
2138 {
2139 addr_t func_file_addr = func_addr.GetFileAddress();
2140 addr_t addr_file_addr = format_addr.GetFileAddress();
2141 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002142 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00002143 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002144 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002145 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00002146 }
2147 else
Greg Clayton0603aa92010-10-04 01:05:56 +00002148 {
2149 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2150 if (target)
2151 {
2152 addr_t func_load_addr = func_addr.GetLoadAddress (target);
2153 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
2154 if (addr_load_addr > func_load_addr)
2155 s.Printf(" + %llu", addr_load_addr - func_load_addr);
2156 else if (addr_load_addr < func_load_addr)
2157 s.Printf(" - %llu", func_load_addr - addr_load_addr);
2158 var_success = true;
2159 }
2160 }
Greg Clayton1b654882010-09-19 02:33:57 +00002161 }
2162 }
2163 else
2164 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002165 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00002166 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00002167 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
2168 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00002169 if (vaddr == LLDB_INVALID_ADDRESS)
2170 vaddr = format_addr.GetFileAddress ();
2171
2172 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00002173 {
Greg Clayton514487e2011-02-15 21:59:32 +00002174 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00002175 if (addr_width == 0)
2176 addr_width = 16;
2177 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002178 var_success = true;
2179 }
Greg Clayton1b654882010-09-19 02:33:57 +00002180 }
2181 }
2182 }
2183
2184 if (var_success == false)
2185 success = false;
2186 }
2187 p = var_name_end;
2188 }
2189 else
2190 break;
2191 }
2192 else
2193 {
2194 // We got a dollar sign with no '{' after it, it must just be a dollar sign
2195 s.PutChar(*p);
2196 }
2197 }
2198 else if (*p == '\\')
2199 {
2200 ++p; // skip the slash
2201 switch (*p)
2202 {
2203 case 'a': s.PutChar ('\a'); break;
2204 case 'b': s.PutChar ('\b'); break;
2205 case 'f': s.PutChar ('\f'); break;
2206 case 'n': s.PutChar ('\n'); break;
2207 case 'r': s.PutChar ('\r'); break;
2208 case 't': s.PutChar ('\t'); break;
2209 case 'v': s.PutChar ('\v'); break;
2210 case '\'': s.PutChar ('\''); break;
2211 case '\\': s.PutChar ('\\'); break;
2212 case '0':
2213 // 1 to 3 octal chars
2214 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002215 // Make a string that can hold onto the initial zero char,
2216 // up to 3 octal digits, and a terminating NULL.
2217 char oct_str[5] = { 0, 0, 0, 0, 0 };
2218
2219 int i;
2220 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
2221 oct_str[i] = p[i];
2222
2223 // We don't want to consume the last octal character since
2224 // the main for loop will do this for us, so we advance p by
2225 // one less than i (even if i is zero)
2226 p += i - 1;
2227 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2228 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002229 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002230 char octal_char = octal_value;
2231 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00002232 }
Greg Clayton1b654882010-09-19 02:33:57 +00002233 }
2234 break;
2235
2236 case 'x':
2237 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00002238 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002239 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002240 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00002241
Greg Clayton0603aa92010-10-04 01:05:56 +00002242 // Make a string that can hold onto two hex chars plus a
2243 // NULL terminator
2244 char hex_str[3] = { 0,0,0 };
2245 hex_str[0] = *p;
2246 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002247 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002248 ++p; // Skip the first of the two hex chars
2249 hex_str[1] = *p;
2250 }
2251
2252 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2253 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002254 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00002255 }
2256 else
2257 {
2258 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00002259 }
2260 break;
2261
2262 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00002263 // Just desensitize any other character by just printing what
2264 // came after the '\'
2265 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00002266 break;
2267
2268 }
2269
2270 }
2271 }
2272 if (end)
2273 *end = p;
2274 return success;
2275}
2276
2277#pragma mark Debugger::SettingsController
2278
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002279//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002280// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002281//--------------------------------------------------
2282
Greg Clayton1b654882010-09-19 02:33:57 +00002283Debugger::SettingsController::SettingsController () :
Greg Clayton4d122c42011-09-17 08:33:22 +00002284 UserSettingsController ("", UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002285{
Caroline Tice91123da2010-09-08 17:48:55 +00002286 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
2287 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002288}
2289
Greg Clayton1b654882010-09-19 02:33:57 +00002290Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002291{
2292}
2293
2294
Greg Clayton4d122c42011-09-17 08:33:22 +00002295InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00002296Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002297{
Greg Claytondbe54502010-11-19 03:46:01 +00002298 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00002299 false, instance_name);
Greg Clayton4d122c42011-09-17 08:33:22 +00002300 InstanceSettingsSP new_settings_sp (new_settings);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002301 return new_settings_sp;
2302}
2303
Greg Clayton1b654882010-09-19 02:33:57 +00002304#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002305//--------------------------------------------------
2306// class DebuggerInstanceSettings
2307//--------------------------------------------------
2308
Greg Claytona7015092010-09-18 01:14:36 +00002309DebuggerInstanceSettings::DebuggerInstanceSettings
2310(
2311 UserSettingsController &owner,
2312 bool live_instance,
2313 const char *name
2314) :
Greg Clayton85851dd2010-12-04 00:10:17 +00002315 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00002316 m_term_width (80),
Greg Claytone372b982011-11-21 21:44:34 +00002317 m_stop_source_before_count (3),
2318 m_stop_source_after_count (3),
2319 m_stop_disassembly_count (4),
2320 m_stop_disassembly_display (eStopDisassemblyTypeNoSource),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002321 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00002322 m_frame_format (),
2323 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002324 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002325 m_use_external_editor (false),
2326 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002327{
Caroline Ticef20e8232010-09-09 18:26:37 +00002328 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2329 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
2330 // 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 +00002331 // The same is true of CreateInstanceName().
2332
2333 if (GetInstanceName() == InstanceSettings::InvalidName())
2334 {
2335 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
2336 m_owner.RegisterInstanceSettings (this);
2337 }
Caroline Ticef20e8232010-09-09 18:26:37 +00002338
2339 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002340 {
Greg Clayton4d122c42011-09-17 08:33:22 +00002341 const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002342 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002343 }
2344}
2345
2346DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00002347 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002348 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00002349 m_frame_format (rhs.m_frame_format),
2350 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002351 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002352 m_use_external_editor (rhs.m_use_external_editor),
2353 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002354{
Greg Clayton4d122c42011-09-17 08:33:22 +00002355 const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002356 CopyInstanceSettings (pending_settings, false);
2357 m_owner.RemovePendingSettings (m_instance_name);
2358}
2359
2360DebuggerInstanceSettings::~DebuggerInstanceSettings ()
2361{
2362}
2363
2364DebuggerInstanceSettings&
2365DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
2366{
2367 if (this != &rhs)
2368 {
Greg Clayton1b654882010-09-19 02:33:57 +00002369 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002370 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00002371 m_frame_format = rhs.m_frame_format;
2372 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002373 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002374 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002375 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002376 }
2377
2378 return *this;
2379}
2380
Greg Clayton1b654882010-09-19 02:33:57 +00002381bool
2382DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
2383{
2384 bool valid = false;
2385
2386 // Verify we have a value string.
2387 if (value == NULL || value[0] == '\0')
2388 {
Greg Clayton86edbf42011-10-26 00:56:27 +00002389 err.SetErrorString ("missing value, can't set terminal width without a value");
Greg Clayton1b654882010-09-19 02:33:57 +00002390 }
2391 else
2392 {
2393 char *end = NULL;
2394 const uint32_t width = ::strtoul (value, &end, 0);
2395
Johnny Chenea9fc182010-09-20 16:36:43 +00002396 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00002397 {
Johnny Chen433d7742010-09-20 17:04:41 +00002398 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00002399 valid = true;
2400 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002401 err.SetErrorString ("invalid term-width value; value must be between 10 and 1024");
Greg Clayton1b654882010-09-19 02:33:57 +00002402 }
2403 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002404 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value);
Greg Clayton1b654882010-09-19 02:33:57 +00002405 }
2406
2407 return valid;
2408}
2409
2410
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002411void
2412DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2413 const char *index_value,
2414 const char *value,
2415 const ConstString &instance_name,
2416 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00002417 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002418 Error &err,
2419 bool pending)
2420{
Greg Clayton0603aa92010-10-04 01:05:56 +00002421
2422 if (var_name == TermWidthVarName())
2423 {
2424 if (ValidTermWidthValue (value, err))
2425 {
2426 m_term_width = ::strtoul (value, NULL, 0);
2427 }
2428 }
2429 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002430 {
Caroline Tice101c7c22010-09-09 06:25:08 +00002431 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002432 if (!pending)
2433 {
Caroline Tice49e27372010-09-07 18:35:40 +00002434 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2435 // strip off the brackets before passing it to BroadcastPromptChange.
2436
2437 std::string tmp_instance_name (instance_name.AsCString());
2438 if ((tmp_instance_name[0] == '[')
2439 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
2440 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
2441 ConstString new_name (tmp_instance_name.c_str());
2442
2443 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002444 }
2445 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002446 else if (var_name == GetFrameFormatName())
2447 {
2448 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
2449 }
2450 else if (var_name == GetThreadFormatName())
2451 {
2452 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
2453 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002454 else if (var_name == ScriptLangVarName())
2455 {
2456 bool success;
2457 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
2458 &success);
2459 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002460 else if (var_name == UseExternalEditorVarName ())
2461 {
Greg Clayton385aa282011-04-22 03:55:06 +00002462 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00002463 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002464 else if (var_name == AutoConfirmName ())
2465 {
Greg Clayton385aa282011-04-22 03:55:06 +00002466 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00002467 }
Greg Claytone372b982011-11-21 21:44:34 +00002468 else if (var_name == StopSourceContextBeforeName ())
2469 {
2470 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2471 if (new_value != UINT32_MAX)
2472 m_stop_source_before_count = new_value;
2473 else
2474 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextAfterName ().GetCString());
2475 }
2476 else if (var_name == StopSourceContextAfterName ())
2477 {
2478 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2479 if (new_value != UINT32_MAX)
2480 m_stop_source_after_count = new_value;
2481 else
2482 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextBeforeName ().GetCString());
2483 }
2484 else if (var_name == StopDisassemblyCountName ())
2485 {
2486 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2487 if (new_value != UINT32_MAX)
2488 m_stop_disassembly_count = new_value;
2489 else
2490 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopDisassemblyCountName ().GetCString());
2491 }
2492 else if (var_name == StopDisassemblyDisplayName ())
2493 {
2494 int new_value;
2495 UserSettingsController::UpdateEnumVariable (g_show_disassembly_enum_values, &new_value, value, err);
2496 if (err.Success())
2497 m_stop_disassembly_display = (StopDisassemblyType)new_value;
2498 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002499}
2500
Caroline Tice12cecd72010-09-20 21:37:42 +00002501bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002502DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2503 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00002504 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00002505 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002506{
2507 if (var_name == PromptVarName())
2508 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002509 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002510
2511 }
2512 else if (var_name == ScriptLangVarName())
2513 {
2514 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
2515 }
Caroline Tice101c7c22010-09-09 06:25:08 +00002516 else if (var_name == TermWidthVarName())
2517 {
2518 StreamString width_str;
Greg Claytone372b982011-11-21 21:44:34 +00002519 width_str.Printf ("%u", m_term_width);
Caroline Tice101c7c22010-09-09 06:25:08 +00002520 value.AppendString (width_str.GetData());
2521 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002522 else if (var_name == GetFrameFormatName ())
2523 {
2524 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
2525 }
2526 else if (var_name == GetThreadFormatName ())
2527 {
2528 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
2529 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002530 else if (var_name == UseExternalEditorVarName())
2531 {
2532 if (m_use_external_editor)
2533 value.AppendString ("true");
2534 else
2535 value.AppendString ("false");
2536 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002537 else if (var_name == AutoConfirmName())
2538 {
2539 if (m_auto_confirm_on)
2540 value.AppendString ("true");
2541 else
2542 value.AppendString ("false");
2543 }
Greg Claytone372b982011-11-21 21:44:34 +00002544 else if (var_name == StopSourceContextAfterName ())
2545 {
2546 StreamString strm;
2547 strm.Printf ("%u", m_stop_source_before_count);
2548 value.AppendString (strm.GetData());
2549 }
2550 else if (var_name == StopSourceContextBeforeName ())
2551 {
2552 StreamString strm;
2553 strm.Printf ("%u", m_stop_source_after_count);
2554 value.AppendString (strm.GetData());
2555 }
2556 else if (var_name == StopDisassemblyCountName ())
2557 {
2558 StreamString strm;
2559 strm.Printf ("%u", m_stop_disassembly_count);
2560 value.AppendString (strm.GetData());
2561 }
2562 else if (var_name == StopDisassemblyDisplayName ())
2563 {
2564 if (m_stop_disassembly_display >= eStopDisassemblyTypeNever && m_stop_disassembly_display <= eStopDisassemblyTypeAlways)
2565 value.AppendString (g_show_disassembly_enum_values[m_stop_disassembly_display].string_value);
2566 else
2567 value.AppendString ("<invalid>");
2568 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002569 else
Caroline Tice12cecd72010-09-20 21:37:42 +00002570 {
2571 if (err)
2572 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2573 return false;
2574 }
2575 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002576}
2577
2578void
Greg Clayton4d122c42011-09-17 08:33:22 +00002579DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002580 bool pending)
2581{
2582 if (new_settings.get() == NULL)
2583 return;
2584
2585 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
2586
2587 m_prompt = new_debugger_settings->m_prompt;
2588 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00002589 {
2590 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2591 // strip off the brackets before passing it to BroadcastPromptChange.
2592
2593 std::string tmp_instance_name (m_instance_name.AsCString());
2594 if ((tmp_instance_name[0] == '[')
2595 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
2596 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
2597 ConstString new_name (tmp_instance_name.c_str());
2598
2599 BroadcastPromptChange (new_name, m_prompt.c_str());
2600 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002601 m_frame_format = new_debugger_settings->m_frame_format;
2602 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002603 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002604 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002605 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002606 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002607}
2608
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002609
2610bool
2611DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
2612{
2613 std::string tmp_prompt;
2614
2615 if (new_prompt != NULL)
2616 {
2617 tmp_prompt = new_prompt ;
2618 int len = tmp_prompt.size();
2619 if (len > 1
2620 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
2621 && (tmp_prompt[len-1] == tmp_prompt[0]))
2622 {
2623 tmp_prompt = tmp_prompt.substr(1,len-2);
2624 }
2625 len = tmp_prompt.size();
2626 if (tmp_prompt[len-1] != ' ')
2627 tmp_prompt.append(" ");
2628 }
2629 EventSP new_event_sp;
2630 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
2631 new EventDataBytes (tmp_prompt.c_str())));
2632
2633 if (instance_name.GetLength() != 0)
2634 {
2635 // Set prompt for a particular instance.
2636 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
2637 if (dbg != NULL)
2638 {
2639 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
2640 }
2641 }
2642
2643 return true;
2644}
2645
2646const ConstString
2647DebuggerInstanceSettings::CreateInstanceName ()
2648{
2649 static int instance_count = 1;
2650 StreamString sstr;
2651
2652 sstr.Printf ("debugger_%d", instance_count);
2653 ++instance_count;
2654
2655 const ConstString ret_val (sstr.GetData());
2656
2657 return ret_val;
2658}
2659
Jim Ingham3bcdb292010-10-04 22:44:14 +00002660
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002661//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002662// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002663//--------------------------------------------------
2664
2665
2666SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002667Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002668{
2669 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00002670 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
2671 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002672 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
2673};
2674
Greg Claytonbb562b12010-10-04 02:44:26 +00002675#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00002676#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002677
Greg Clayton0603aa92010-10-04 01:05:56 +00002678#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2679 "{, ${frame.pc}}"\
2680 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00002681 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00002682 "{, stop reason = ${thread.stop-reason}}"\
Jim Inghamef651602011-12-22 19:12:40 +00002683 "{\\nReturn value: ${thread.return-value}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00002684 "\\n"
2685
Greg Clayton315d2ca2010-11-02 01:53:21 +00002686//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2687// "{, ${frame.pc}}"\
2688// MODULE_WITH_FUNC\
2689// FILE_AND_LINE\
2690// "{, stop reason = ${thread.stop-reason}}"\
2691// "{, name = ${thread.name}}"\
2692// "{, queue = ${thread.queue}}"\
2693// "\\n"
2694
Greg Clayton0603aa92010-10-04 01:05:56 +00002695#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
2696 MODULE_WITH_FUNC\
2697 FILE_AND_LINE\
2698 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002699
2700SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002701Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002702{
Greg Clayton0603aa92010-10-04 01:05:56 +00002703// NAME Setting variable type Default Enum Init'd Hidden Help
2704// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00002705{ "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 +00002706{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00002707{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
2708{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002709{ "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 +00002710{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
2711{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
2712{ "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." },
2713{ "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." },
2714{ "stop-disassembly-count", eSetVarTypeInt, "0", NULL, false, false, "The number of disassembly lines to show when displaying a stopped context." },
2715{ "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 +00002716{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002717};