blob: 9cefaa30f14ba172bca2544e2fb1b310ae88766e [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"
Enrico Granataa777dc22012-05-08 21:49:57 +000019#include "lldb/Core/DataVisualization.h"
Greg Clayton4a33d312011-06-23 17:59:56 +000020#include "lldb/Core/FormatManager.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/InputReader.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000022#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000024#include "lldb/Core/StreamAsynchronousIO.h"
Jim Ingham228063c2012-02-21 02:23:08 +000025#include "lldb/Core/StreamCallback.h"
Greg Clayton1b654882010-09-19 02:33:57 +000026#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000028#include "lldb/Core/ValueObject.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000029#include "lldb/Core/ValueObjectVariable.h"
Greg Claytona3406612011-02-07 23:24:47 +000030#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000031#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000032#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Target/TargetList.h"
34#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000035#include "lldb/Target/RegisterContext.h"
36#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000038#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039
40using namespace lldb;
41using namespace lldb_private;
42
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043
Greg Clayton1b654882010-09-19 02:33:57 +000044static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000045static lldb::user_id_t g_unique_id = 1;
46
Greg Clayton1b654882010-09-19 02:33:57 +000047#pragma mark Static Functions
48
49static Mutex &
50GetDebuggerListMutex ()
51{
52 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
53 return g_mutex;
54}
55
56typedef std::vector<DebuggerSP> DebuggerList;
57
58static DebuggerList &
59GetDebuggerList()
60{
61 // hide the static debugger list inside a singleton accessor to avoid
62 // global init contructors
63 static DebuggerList g_list;
64 return g_list;
65}
66
67
Greg Claytone372b982011-11-21 21:44:34 +000068static const ConstString &
69PromptVarName ()
70{
71 static ConstString g_const_string ("prompt");
72 return g_const_string;
73}
74
75static const ConstString &
76GetFrameFormatName ()
77{
78 static ConstString g_const_string ("frame-format");
79 return g_const_string;
80}
81
82static const ConstString &
83GetThreadFormatName ()
84{
85 static ConstString g_const_string ("thread-format");
86 return g_const_string;
87}
88
89static const ConstString &
90ScriptLangVarName ()
91{
92 static ConstString g_const_string ("script-lang");
93 return g_const_string;
94}
95
96static const ConstString &
97TermWidthVarName ()
98{
99 static ConstString g_const_string ("term-width");
100 return g_const_string;
101}
102
103static const ConstString &
104UseExternalEditorVarName ()
105{
106 static ConstString g_const_string ("use-external-editor");
107 return g_const_string;
108}
109
110static const ConstString &
111AutoConfirmName ()
112{
113 static ConstString g_const_string ("auto-confirm");
114 return g_const_string;
115}
116
117static const ConstString &
118StopSourceContextBeforeName ()
119{
120 static ConstString g_const_string ("stop-line-count-before");
121 return g_const_string;
122}
123
124static const ConstString &
125StopSourceContextAfterName ()
126{
127 static ConstString g_const_string ("stop-line-count-after");
128 return g_const_string;
129}
130
131static const ConstString &
132StopDisassemblyCountName ()
133{
134 static ConstString g_const_string ("stop-disassembly-count");
135 return g_const_string;
136}
137
138static const ConstString &
139StopDisassemblyDisplayName ()
140{
141 static ConstString g_const_string ("stop-disassembly-display");
142 return g_const_string;
143}
144
145OptionEnumValueElement
146DebuggerInstanceSettings::g_show_disassembly_enum_values[] =
147{
148 { eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
149 { eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
150 { eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
151 { 0, NULL, NULL }
152};
153
154
155
Greg Clayton1b654882010-09-19 02:33:57 +0000156#pragma mark Debugger
157
Greg Clayton99d0faf2010-11-18 23:32:35 +0000158UserSettingsControllerSP &
159Debugger::GetSettingsController ()
160{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000161 static UserSettingsControllerSP g_settings_controller_sp;
162 if (!g_settings_controller_sp)
163 {
164 g_settings_controller_sp.reset (new Debugger::SettingsController);
165
166 // The first shared pointer to Debugger::SettingsController in
167 // g_settings_controller_sp must be fully created above so that
168 // the DebuggerInstanceSettings can use a weak_ptr to refer back
169 // to the master setttings controller
170 InstanceSettingsSP default_instance_settings_sp (new DebuggerInstanceSettings (g_settings_controller_sp,
171 false,
172 InstanceSettings::GetDefaultName().AsCString()));
173 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
174 }
175 return g_settings_controller_sp;
Greg Clayton99d0faf2010-11-18 23:32:35 +0000176}
177
Caroline Tice2f88aad2011-01-14 00:29:16 +0000178int
179Debugger::TestDebuggerRefCount ()
180{
181 return g_shared_debugger_refcount;
182}
183
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184void
185Debugger::Initialize ()
186{
Greg Claytonc15f55e2012-03-30 20:53:46 +0000187 if (g_shared_debugger_refcount++ == 0)
Greg Claytondbe54502010-11-19 03:46:01 +0000188 lldb_private::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189}
190
191void
192Debugger::Terminate ()
193{
Greg Clayton66111032010-06-23 01:19:29 +0000194 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 {
Greg Clayton66111032010-06-23 01:19:29 +0000196 g_shared_debugger_refcount--;
197 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 {
Greg Claytondbe54502010-11-19 03:46:01 +0000199 lldb_private::WillTerminate();
200 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000201
202 // Clear our master list of debugger objects
203 Mutex::Locker locker (GetDebuggerListMutex ());
204 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 }
207}
208
Caroline Tice20bd37f2011-03-10 22:14:10 +0000209void
210Debugger::SettingsInitialize ()
211{
212 static bool g_initialized = false;
213
214 if (!g_initialized)
215 {
216 g_initialized = true;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000217 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Caroline Tice20bd37f2011-03-10 22:14:10 +0000218 SettingsController::global_settings_table,
219 SettingsController::instance_settings_table);
220 // Now call SettingsInitialize for each settings 'child' of Debugger
221 Target::SettingsInitialize ();
222 }
223}
224
225void
226Debugger::SettingsTerminate ()
227{
228
229 // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
230 // Settings.
231
232 Target::SettingsTerminate ();
233
234 // Now terminate the Debugger Settings.
235
236 UserSettingsControllerSP &usc = GetSettingsController();
237 UserSettingsController::FinalizeSettingsController (usc);
238 usc.reset();
239}
240
Greg Clayton66111032010-06-23 01:19:29 +0000241DebuggerSP
Jim Ingham228063c2012-02-21 02:23:08 +0000242Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
Greg Clayton66111032010-06-23 01:19:29 +0000243{
Jim Ingham228063c2012-02-21 02:23:08 +0000244 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
Greg Claytonc15f55e2012-03-30 20:53:46 +0000245 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000246 {
247 Mutex::Locker locker (GetDebuggerListMutex ());
248 GetDebuggerList().push_back(debugger_sp);
249 }
250 return debugger_sp;
251}
252
Caroline Ticee02657b2011-01-22 01:02:07 +0000253void
Greg Clayton4d122c42011-09-17 08:33:22 +0000254Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000255{
256 if (debugger_sp.get() == NULL)
257 return;
258
Jim Ingham8314c522011-09-15 21:36:42 +0000259 debugger_sp->Clear();
260
Greg Claytonc15f55e2012-03-30 20:53:46 +0000261 if (g_shared_debugger_refcount > 0)
Caroline Ticee02657b2011-01-22 01:02:07 +0000262 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000263 Mutex::Locker locker (GetDebuggerListMutex ());
264 DebuggerList &debugger_list = GetDebuggerList ();
265 DebuggerList::iterator pos, end = debugger_list.end();
266 for (pos = debugger_list.begin (); pos != end; ++pos)
Caroline Ticee02657b2011-01-22 01:02:07 +0000267 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000268 if ((*pos).get() == debugger_sp.get())
269 {
270 debugger_list.erase (pos);
271 return;
272 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000273 }
274 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000275}
276
Greg Clayton4d122c42011-09-17 08:33:22 +0000277DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000278Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
279{
Greg Clayton4d122c42011-09-17 08:33:22 +0000280 DebuggerSP debugger_sp;
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000281
Greg Claytonc15f55e2012-03-30 20:53:46 +0000282 if (g_shared_debugger_refcount > 0)
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000283 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000284 Mutex::Locker locker (GetDebuggerListMutex ());
285 DebuggerList &debugger_list = GetDebuggerList();
286 DebuggerList::iterator pos, end = debugger_list.end();
287
288 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000289 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000290 if ((*pos).get()->m_instance_name == instance_name)
291 {
292 debugger_sp = *pos;
293 break;
294 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000295 }
296 }
297 return debugger_sp;
298}
Greg Clayton66111032010-06-23 01:19:29 +0000299
300TargetSP
301Debugger::FindTargetWithProcessID (lldb::pid_t pid)
302{
Greg Clayton4d122c42011-09-17 08:33:22 +0000303 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000304 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000305 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000306 Mutex::Locker locker (GetDebuggerListMutex ());
307 DebuggerList &debugger_list = GetDebuggerList();
308 DebuggerList::iterator pos, end = debugger_list.end();
309 for (pos = debugger_list.begin(); pos != end; ++pos)
310 {
311 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
312 if (target_sp)
313 break;
314 }
Greg Clayton66111032010-06-23 01:19:29 +0000315 }
316 return target_sp;
317}
318
Greg Claytone4e45922011-11-16 05:37:56 +0000319TargetSP
320Debugger::FindTargetWithProcess (Process *process)
321{
322 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000323 if (g_shared_debugger_refcount > 0)
Greg Claytone4e45922011-11-16 05:37:56 +0000324 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000325 Mutex::Locker locker (GetDebuggerListMutex ());
326 DebuggerList &debugger_list = GetDebuggerList();
327 DebuggerList::iterator pos, end = debugger_list.end();
328 for (pos = debugger_list.begin(); pos != end; ++pos)
329 {
330 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
331 if (target_sp)
332 break;
333 }
Greg Claytone4e45922011-11-16 05:37:56 +0000334 }
335 return target_sp;
336}
337
Greg Clayton66111032010-06-23 01:19:29 +0000338
Jim Ingham228063c2012-02-21 02:23:08 +0000339Debugger::Debugger (lldb::LogOutputCallback log_callback, void *baton) :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000340 UserID (g_unique_id++),
Greg Claytonb9556ac2012-01-30 07:41:31 +0000341 DebuggerInstanceSettings (GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000342 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343 m_input_file (),
344 m_output_file (),
345 m_error_file (),
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000346 m_target_list (*this),
Greg Claytonded470d2011-03-19 01:12:21 +0000347 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348 m_listener ("lldb.Debugger"),
Jim Inghame37d6052011-09-13 00:29:56 +0000349 m_source_manager(*this),
350 m_source_file_cache(),
Greg Clayton66111032010-06-23 01:19:29 +0000351 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000352 m_input_reader_stack (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000353 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354{
Jim Ingham228063c2012-02-21 02:23:08 +0000355 if (log_callback)
356 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000357 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000358 // Always add our default platform to the platform list
359 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
360 assert (default_platform_sp.get());
361 m_platform_list.Append (default_platform_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362}
363
364Debugger::~Debugger ()
365{
Jim Ingham8314c522011-09-15 21:36:42 +0000366 Clear();
367}
368
369void
370Debugger::Clear()
371{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000372 CleanUpInputReaders();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000373 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000374 int num_targets = m_target_list.GetNumTargets();
375 for (int i = 0; i < num_targets; i++)
376 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000377 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
378 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000379 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000380 ProcessSP process_sp (target_sp->GetProcessSP());
381 if (process_sp)
382 {
383 if (process_sp->GetShouldDetach())
384 process_sp->Detach();
385 }
386 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000387 }
Greg Clayton66111032010-06-23 01:19:29 +0000388 }
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000389 BroadcasterManager::Clear ();
Greg Clayton0d69a3a2012-05-16 00:11:54 +0000390
391 // Close the input file _before_ we close the input read communications class
392 // as it does NOT own the input file, our m_input_file does.
393 GetInputFile().Close ();
394 // Now that we have closed m_input_file, we can now tell our input communication
395 // class to close down. Its read thread should quickly exit after we close
396 // the input file handle above.
397 m_input_comm.Clear ();
Jim Ingham8314c522011-09-15 21:36:42 +0000398}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399
400bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000401Debugger::GetCloseInputOnEOF () const
402{
403 return m_input_comm.GetCloseOnEOF();
404}
405
406void
407Debugger::SetCloseInputOnEOF (bool b)
408{
409 m_input_comm.SetCloseOnEOF(b);
410}
411
412bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413Debugger::GetAsyncExecution ()
414{
Greg Clayton66111032010-06-23 01:19:29 +0000415 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416}
417
418void
419Debugger::SetAsyncExecution (bool async_execution)
420{
Greg Clayton66111032010-06-23 01:19:29 +0000421 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422}
423
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424
425void
426Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
427{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000428 File &in_file = GetInputFile();
429 in_file.SetStream (fh, tranfer_ownership);
430 if (in_file.IsValid() == false)
431 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432
433 // Disconnect from any old connection if we had one
434 m_input_comm.Disconnect ();
Greg Clayton32720b52012-01-14 20:47:38 +0000435 // Pass false as the second argument to ConnectionFileDescriptor below because
436 // our "in_file" above will already take ownership if requested and we don't
437 // want to objects trying to own and close a file descriptor.
438 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
440
441 Error error;
442 if (m_input_comm.StartReadThread (&error) == false)
443 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000444 File &err_file = GetErrorFile();
445
446 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
447 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449}
450
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451void
452Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
453{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000454 File &out_file = GetOutputFile();
455 out_file.SetStream (fh, tranfer_ownership);
456 if (out_file.IsValid() == false)
457 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000458
459 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460}
461
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462void
463Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
464{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000465 File &err_file = GetErrorFile();
466 err_file.SetStream (fh, tranfer_ownership);
467 if (err_file.IsValid() == false)
468 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469}
470
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000472Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473{
474 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000475 TargetSP target_sp(GetSelectedTarget());
476 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477
478 if (target_sp)
479 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000480 ProcessSP process_sp (target_sp->GetProcessSP());
481 exe_ctx.SetProcessSP (process_sp);
482 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000484 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
485 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000487 exe_ctx.SetThreadSP (thread_sp);
488 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
489 if (exe_ctx.GetFramePtr() == NULL)
490 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491 }
492 }
493 }
494 return exe_ctx;
495
496}
497
Caroline Ticeb44880c2011-02-10 01:15:13 +0000498InputReaderSP
499Debugger::GetCurrentInputReader ()
500{
501 InputReaderSP reader_sp;
502
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000503 if (!m_input_reader_stack.IsEmpty())
Caroline Ticeb44880c2011-02-10 01:15:13 +0000504 {
505 // Clear any finished readers from the stack
506 while (CheckIfTopInputReaderIsDone()) ;
507
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000508 if (!m_input_reader_stack.IsEmpty())
509 reader_sp = m_input_reader_stack.Top();
Caroline Ticeb44880c2011-02-10 01:15:13 +0000510 }
511
512 return reader_sp;
513}
514
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515void
516Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
517{
Caroline Ticeefed6132010-11-19 20:47:54 +0000518 if (bytes_len > 0)
519 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
520 else
521 ((Debugger *)baton)->DispatchInputEndOfFile ();
522}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523
524
525void
526Debugger::DispatchInput (const char *bytes, size_t bytes_len)
527{
Caroline Ticeefed6132010-11-19 20:47:54 +0000528 if (bytes == NULL || bytes_len == 0)
529 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530
531 WriteToDefaultReader (bytes, bytes_len);
532}
533
534void
Caroline Ticeefed6132010-11-19 20:47:54 +0000535Debugger::DispatchInputInterrupt ()
536{
537 m_input_reader_data.clear();
538
Caroline Ticeb44880c2011-02-10 01:15:13 +0000539 InputReaderSP reader_sp (GetCurrentInputReader ());
540 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000541 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000542 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000543
Caroline Ticeb44880c2011-02-10 01:15:13 +0000544 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000545 while (CheckIfTopInputReaderIsDone ()) ;
546 }
547}
548
549void
550Debugger::DispatchInputEndOfFile ()
551{
552 m_input_reader_data.clear();
553
Caroline Ticeb44880c2011-02-10 01:15:13 +0000554 InputReaderSP reader_sp (GetCurrentInputReader ());
555 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000556 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000557 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000558
Caroline Ticeb44880c2011-02-10 01:15:13 +0000559 // 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 +0000560 while (CheckIfTopInputReaderIsDone ()) ;
561 }
562}
563
564void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000565Debugger::CleanUpInputReaders ()
566{
567 m_input_reader_data.clear();
568
Caroline Ticeb44880c2011-02-10 01:15:13 +0000569 // 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 +0000570 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000571 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000572 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000573 if (reader_sp)
574 {
575 reader_sp->Notify (eInputReaderEndOfFile);
576 reader_sp->SetIsDone (true);
577 }
578 }
579}
580
581void
Caroline Tice969ed3d2011-05-02 20:41:46 +0000582Debugger::NotifyTopInputReader (InputReaderAction notification)
583{
584 InputReaderSP reader_sp (GetCurrentInputReader());
585 if (reader_sp)
586 {
587 reader_sp->Notify (notification);
588
589 // Flush out any input readers that are done.
590 while (CheckIfTopInputReaderIsDone ())
591 /* Do nothing. */;
592 }
593}
594
Caroline Tice9088b062011-05-09 23:06:58 +0000595bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000596Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp)
Caroline Tice9088b062011-05-09 23:06:58 +0000597{
Caroline Ticed61c10b2011-06-16 16:27:19 +0000598 InputReaderSP top_reader_sp (GetCurrentInputReader());
Caroline Tice9088b062011-05-09 23:06:58 +0000599
Caroline Ticed61c10b2011-06-16 16:27:19 +0000600 return (reader_sp.get() == top_reader_sp.get());
Caroline Tice9088b062011-05-09 23:06:58 +0000601}
602
603
Caroline Tice969ed3d2011-05-02 20:41:46 +0000604void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000605Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
606{
607 if (bytes && bytes_len)
608 m_input_reader_data.append (bytes, bytes_len);
609
610 if (m_input_reader_data.empty())
611 return;
612
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000613 while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000615 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000616 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000617 if (!reader_sp)
618 break;
619
Greg Clayton471b31c2010-07-20 22:52:08 +0000620 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000621 m_input_reader_data.size());
622 if (bytes_handled)
623 {
624 m_input_reader_data.erase (0, bytes_handled);
625 }
626 else
627 {
628 // No bytes were handled, we might not have reached our
629 // granularity, just return and wait for more data
630 break;
631 }
632 }
633
Caroline Ticeb44880c2011-02-10 01:15:13 +0000634 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000635 while (CheckIfTopInputReaderIsDone ())
636 /* Do nothing. */;
637
638}
639
640void
641Debugger::PushInputReader (const InputReaderSP& reader_sp)
642{
643 if (!reader_sp)
644 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000645
646 // Deactivate the old top reader
647 InputReaderSP top_reader_sp (GetCurrentInputReader ());
648
649 if (top_reader_sp)
650 top_reader_sp->Notify (eInputReaderDeactivate);
651
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000652 m_input_reader_stack.Push (reader_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653 reader_sp->Notify (eInputReaderActivate);
654 ActivateInputReader (reader_sp);
655}
656
657bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000658Debugger::PopInputReader (const InputReaderSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659{
660 bool result = false;
661
662 // The reader on the stop of the stack is done, so let the next
663 // read on the stack referesh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000664 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000666 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000667 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668
669 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
670 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000671 m_input_reader_stack.Pop ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672 reader_sp->Notify (eInputReaderDeactivate);
673 reader_sp->Notify (eInputReaderDone);
674 result = true;
675
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000676 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000678 reader_sp = m_input_reader_stack.Top();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679 if (reader_sp)
680 {
681 ActivateInputReader (reader_sp);
682 reader_sp->Notify (eInputReaderReactivate);
683 }
684 }
685 }
686 }
687 return result;
688}
689
690bool
691Debugger::CheckIfTopInputReaderIsDone ()
692{
693 bool result = false;
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000694 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000696 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000697 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000698
699 if (reader_sp && reader_sp->IsDone())
700 {
701 result = true;
702 PopInputReader (reader_sp);
703 }
704 }
705 return result;
706}
707
708void
709Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
710{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000711 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000713 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000715 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000716
717 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718
Greg Claytona3406612011-02-07 23:24:47 +0000719 switch (reader_sp->GetGranularity())
720 {
721 case eInputReaderGranularityByte:
722 case eInputReaderGranularityWord:
723 tty.SetCanonical (false);
724 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725
Greg Claytona3406612011-02-07 23:24:47 +0000726 case eInputReaderGranularityLine:
727 case eInputReaderGranularityAll:
728 tty.SetCanonical (true);
729 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000730
Greg Claytona3406612011-02-07 23:24:47 +0000731 default:
732 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000733 }
734 }
735}
Greg Clayton66111032010-06-23 01:19:29 +0000736
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000737StreamSP
738Debugger::GetAsyncOutputStream ()
739{
740 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
741 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
742}
743
744StreamSP
745Debugger::GetAsyncErrorStream ()
746{
747 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
748 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
749}
750
Enrico Granata061858c2012-02-15 02:34:21 +0000751uint32_t
752Debugger::GetNumDebuggers()
753{
Greg Claytonc15f55e2012-03-30 20:53:46 +0000754 if (g_shared_debugger_refcount > 0)
755 {
756 Mutex::Locker locker (GetDebuggerListMutex ());
757 return GetDebuggerList().size();
758 }
759 return 0;
Enrico Granata061858c2012-02-15 02:34:21 +0000760}
761
762lldb::DebuggerSP
763Debugger::GetDebuggerAtIndex (uint32_t index)
764{
765 DebuggerSP debugger_sp;
766
Greg Claytonc15f55e2012-03-30 20:53:46 +0000767 if (g_shared_debugger_refcount > 0)
768 {
769 Mutex::Locker locker (GetDebuggerListMutex ());
770 DebuggerList &debugger_list = GetDebuggerList();
Enrico Granata061858c2012-02-15 02:34:21 +0000771
Greg Claytonc15f55e2012-03-30 20:53:46 +0000772 if (index < debugger_list.size())
773 debugger_sp = debugger_list[index];
774 }
775
Enrico Granata061858c2012-02-15 02:34:21 +0000776 return debugger_sp;
777}
778
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000779DebuggerSP
780Debugger::FindDebuggerWithID (lldb::user_id_t id)
781{
Greg Clayton4d122c42011-09-17 08:33:22 +0000782 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000783
Greg Claytonc15f55e2012-03-30 20:53:46 +0000784 if (g_shared_debugger_refcount > 0)
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000785 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000786 Mutex::Locker locker (GetDebuggerListMutex ());
787 DebuggerList &debugger_list = GetDebuggerList();
788 DebuggerList::iterator pos, end = debugger_list.end();
789 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000790 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000791 if ((*pos).get()->GetID() == id)
792 {
793 debugger_sp = *pos;
794 break;
795 }
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000796 }
797 }
798 return debugger_sp;
799}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000800
Greg Clayton1b654882010-09-19 02:33:57 +0000801static void
802TestPromptFormats (StackFrame *frame)
803{
804 if (frame == NULL)
805 return;
806
807 StreamString s;
808 const char *prompt_format =
809 "{addr = '${addr}'\n}"
810 "{process.id = '${process.id}'\n}"
811 "{process.name = '${process.name}'\n}"
812 "{process.file.basename = '${process.file.basename}'\n}"
813 "{process.file.fullpath = '${process.file.fullpath}'\n}"
814 "{thread.id = '${thread.id}'\n}"
815 "{thread.index = '${thread.index}'\n}"
816 "{thread.name = '${thread.name}'\n}"
817 "{thread.queue = '${thread.queue}'\n}"
818 "{thread.stop-reason = '${thread.stop-reason}'\n}"
819 "{target.arch = '${target.arch}'\n}"
820 "{module.file.basename = '${module.file.basename}'\n}"
821 "{module.file.fullpath = '${module.file.fullpath}'\n}"
822 "{file.basename = '${file.basename}'\n}"
823 "{file.fullpath = '${file.fullpath}'\n}"
824 "{frame.index = '${frame.index}'\n}"
825 "{frame.pc = '${frame.pc}'\n}"
826 "{frame.sp = '${frame.sp}'\n}"
827 "{frame.fp = '${frame.fp}'\n}"
828 "{frame.flags = '${frame.flags}'\n}"
829 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
830 "{frame.reg.rip = '${frame.reg.rip}'\n}"
831 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
832 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
833 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
834 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
835 "{frame.reg.carp = '${frame.reg.carp}'\n}"
836 "{function.id = '${function.id}'\n}"
837 "{function.name = '${function.name}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +0000838 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +0000839 "{function.addr-offset = '${function.addr-offset}'\n}"
840 "{function.line-offset = '${function.line-offset}'\n}"
841 "{function.pc-offset = '${function.pc-offset}'\n}"
842 "{line.file.basename = '${line.file.basename}'\n}"
843 "{line.file.fullpath = '${line.file.fullpath}'\n}"
844 "{line.number = '${line.number}'\n}"
845 "{line.start-addr = '${line.start-addr}'\n}"
846 "{line.end-addr = '${line.end-addr}'\n}"
847;
848
849 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
850 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000851 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000852 const char *end = NULL;
853 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
854 {
855 printf("%s\n", s.GetData());
856 }
857 else
858 {
859 printf ("error: at '%s'\n", end);
860 printf ("what we got: %s\n", s.GetData());
861 }
862}
863
Enrico Granata9fc19442011-07-06 02:13:41 +0000864static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000865ScanFormatDescriptor (const char* var_name_begin,
866 const char* var_name_end,
867 const char** var_name_final,
868 const char** percent_position,
Greg Clayton4d122c42011-09-17 08:33:22 +0000869 Format* custom_format,
Enrico Granatadc940732011-08-23 00:32:52 +0000870 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
Enrico Granata9fc19442011-07-06 02:13:41 +0000871{
Enrico Granatae992a082011-07-22 17:03:19 +0000872 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000873 *percent_position = ::strchr(var_name_begin,'%');
Greg Clayton34132752011-07-06 04:07:21 +0000874 if (!*percent_position || *percent_position > var_name_end)
Enrico Granatae992a082011-07-22 17:03:19 +0000875 {
876 if (log)
877 log->Printf("no format descriptor in string, skipping");
Enrico Granata9fc19442011-07-06 02:13:41 +0000878 *var_name_final = var_name_end;
Enrico Granatae992a082011-07-22 17:03:19 +0000879 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000880 else
881 {
882 *var_name_final = *percent_position;
883 char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0';
884 memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1);
Enrico Granatae992a082011-07-22 17:03:19 +0000885 if (log)
886 log->Printf("parsing %s as a format descriptor", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000887 if ( !FormatManager::GetFormatFromCString(format_name,
888 true,
889 *custom_format) )
890 {
Enrico Granatae992a082011-07-22 17:03:19 +0000891 if (log)
892 log->Printf("%s is an unknown format", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000893 // if this is an @ sign, print ObjC description
Greg Clayton34132752011-07-06 04:07:21 +0000894 if (*format_name == '@')
Enrico Granata86cc9822012-03-19 22:58:49 +0000895 *val_obj_display = ValueObject::eValueObjectRepresentationStyleLanguageSpecific;
Enrico Granata9fc19442011-07-06 02:13:41 +0000896 // if this is a V, print the value using the default format
Enrico Granatae992a082011-07-22 17:03:19 +0000897 else if (*format_name == 'V')
Enrico Granata86cc9822012-03-19 22:58:49 +0000898 *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Enrico Granatad55546b2011-07-22 00:16:08 +0000899 // if this is an L, print the location of the value
Enrico Granatae992a082011-07-22 17:03:19 +0000900 else if (*format_name == 'L')
Enrico Granata86cc9822012-03-19 22:58:49 +0000901 *val_obj_display = ValueObject::eValueObjectRepresentationStyleLocation;
Enrico Granatad55546b2011-07-22 00:16:08 +0000902 // if this is an S, print the summary after all
Enrico Granatae992a082011-07-22 17:03:19 +0000903 else if (*format_name == 'S')
Enrico Granata86cc9822012-03-19 22:58:49 +0000904 *val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000905 else if (*format_name == '#')
Enrico Granata86cc9822012-03-19 22:58:49 +0000906 *val_obj_display = ValueObject::eValueObjectRepresentationStyleChildrenCount;
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000907 else if (*format_name == 'T')
Enrico Granata86cc9822012-03-19 22:58:49 +0000908 *val_obj_display = ValueObject::eValueObjectRepresentationStyleType;
Enrico Granatae992a082011-07-22 17:03:19 +0000909 else if (log)
910 log->Printf("%s is an error, leaving the previous value alone", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000911 }
912 // a good custom format tells us to print the value using it
913 else
Enrico Granatae992a082011-07-22 17:03:19 +0000914 {
915 if (log)
916 log->Printf("will display value for this VO");
Enrico Granata86cc9822012-03-19 22:58:49 +0000917 *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Enrico Granatae992a082011-07-22 17:03:19 +0000918 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000919 delete format_name;
920 }
Enrico Granatae992a082011-07-22 17:03:19 +0000921 if (log)
922 log->Printf("final format description outcome: custom_format = %d, val_obj_display = %d",
923 *custom_format,
924 *val_obj_display);
Enrico Granata9fc19442011-07-06 02:13:41 +0000925 return true;
926}
927
928static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000929ScanBracketedRange (const char* var_name_begin,
930 const char* var_name_end,
931 const char* var_name_final,
932 const char** open_bracket_position,
933 const char** separator_position,
934 const char** close_bracket_position,
935 const char** var_name_final_if_array_range,
936 int64_t* index_lower,
937 int64_t* index_higher)
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 *open_bracket_position = ::strchr(var_name_begin,'[');
Greg Clayton34132752011-07-06 04:07:21 +0000941 if (*open_bracket_position && *open_bracket_position < var_name_final)
Enrico Granata9fc19442011-07-06 02:13:41 +0000942 {
943 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
944 *close_bracket_position = ::strchr(*open_bracket_position,']');
945 // as usual, we assume that [] will come before %
946 //printf("trying to expand a []\n");
947 *var_name_final_if_array_range = *open_bracket_position;
Greg Clayton34132752011-07-06 04:07:21 +0000948 if (*close_bracket_position - *open_bracket_position == 1)
Enrico Granata9fc19442011-07-06 02:13:41 +0000949 {
Enrico Granatae992a082011-07-22 17:03:19 +0000950 if (log)
951 log->Printf("[] detected.. going from 0 to end of data");
Enrico Granata9fc19442011-07-06 02:13:41 +0000952 *index_lower = 0;
953 }
954 else if (*separator_position == NULL || *separator_position > var_name_end)
955 {
956 char *end = NULL;
957 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
958 *index_higher = *index_lower;
Enrico Granatae992a082011-07-22 17:03:19 +0000959 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000960 log->Printf("[%lld] detected, high index is same", *index_lower);
Enrico Granata9fc19442011-07-06 02:13:41 +0000961 }
Greg Clayton34132752011-07-06 04:07:21 +0000962 else if (*close_bracket_position && *close_bracket_position < var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +0000963 {
964 char *end = NULL;
965 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
966 *index_higher = ::strtoul (*separator_position+1, &end, 0);
Enrico Granatae992a082011-07-22 17:03:19 +0000967 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000968 log->Printf("[%lld-%lld] detected", *index_lower, *index_higher);
Enrico Granata9fc19442011-07-06 02:13:41 +0000969 }
970 else
Enrico Granatae992a082011-07-22 17:03:19 +0000971 {
972 if (log)
973 log->Printf("expression is erroneous, cannot extract indices out of it");
Enrico Granata9fc19442011-07-06 02:13:41 +0000974 return false;
Enrico Granatae992a082011-07-22 17:03:19 +0000975 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000976 if (*index_lower > *index_higher && *index_higher > 0)
977 {
Enrico Granatae992a082011-07-22 17:03:19 +0000978 if (log)
979 log->Printf("swapping indices");
Enrico Granata9fc19442011-07-06 02:13:41 +0000980 int temp = *index_lower;
981 *index_lower = *index_higher;
982 *index_higher = temp;
983 }
984 }
Enrico Granatae992a082011-07-22 17:03:19 +0000985 else if (log)
986 log->Printf("no bracketed range, skipping entirely");
Enrico Granata9fc19442011-07-06 02:13:41 +0000987 return true;
988}
989
Enrico Granata9fc19442011-07-06 02:13:41 +0000990static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000991ExpandIndexedExpression (ValueObject* valobj,
992 uint32_t index,
993 StackFrame* frame,
994 bool deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +0000995{
Enrico Granatae992a082011-07-22 17:03:19 +0000996 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granatafc7a7f32011-07-08 02:51:01 +0000997 const char* ptr_deref_format = "[%d]";
998 std::auto_ptr<char> ptr_deref_buffer(new char[10]);
999 ::sprintf(ptr_deref_buffer.get(), ptr_deref_format, index);
Enrico Granatae992a082011-07-22 17:03:19 +00001000 if (log)
1001 log->Printf("name to deref: %s",ptr_deref_buffer.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001002 const char* first_unparsed;
1003 ValueObject::GetValueForExpressionPathOptions options;
1004 ValueObject::ExpressionPathEndResultType final_value_type;
1005 ValueObject::ExpressionPathScanEndReason reason_to_stop;
Enrico Granata86cc9822012-03-19 22:58:49 +00001006 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
Enrico Granatac482a192011-08-17 22:13:59 +00001007 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001008 &first_unparsed,
1009 &reason_to_stop,
1010 &final_value_type,
1011 options,
1012 &what_next);
1013 if (!item)
1014 {
Enrico Granatae992a082011-07-22 17:03:19 +00001015 if (log)
1016 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1017 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001018 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001019 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001020 else
1021 {
Enrico Granatae992a082011-07-22 17:03:19 +00001022 if (log)
1023 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1024 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001025 first_unparsed, reason_to_stop, final_value_type);
Enrico Granata9fc19442011-07-06 02:13:41 +00001026 }
1027 return item;
1028}
1029
Greg Clayton1b654882010-09-19 02:33:57 +00001030bool
1031Debugger::FormatPrompt
1032(
1033 const char *format,
1034 const SymbolContext *sc,
1035 const ExecutionContext *exe_ctx,
1036 const Address *addr,
1037 Stream &s,
Enrico Granata4becb372011-06-29 22:27:15 +00001038 const char **end,
Enrico Granatac482a192011-08-17 22:13:59 +00001039 ValueObject* valobj
Greg Clayton1b654882010-09-19 02:33:57 +00001040)
1041{
Enrico Granatac482a192011-08-17 22:13:59 +00001042 ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers
Greg Clayton1b654882010-09-19 02:33:57 +00001043 bool success = true;
1044 const char *p;
Enrico Granatae992a082011-07-22 17:03:19 +00001045 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Greg Clayton1b654882010-09-19 02:33:57 +00001046 for (p = format; *p != '\0'; ++p)
1047 {
Enrico Granatac482a192011-08-17 22:13:59 +00001048 if (realvalobj)
Enrico Granata4becb372011-06-29 22:27:15 +00001049 {
Enrico Granatac482a192011-08-17 22:13:59 +00001050 valobj = realvalobj;
1051 realvalobj = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00001052 }
Greg Clayton1b654882010-09-19 02:33:57 +00001053 size_t non_special_chars = ::strcspn (p, "${}\\");
1054 if (non_special_chars > 0)
1055 {
1056 if (success)
1057 s.Write (p, non_special_chars);
1058 p += non_special_chars;
1059 }
1060
1061 if (*p == '\0')
1062 {
1063 break;
1064 }
1065 else if (*p == '{')
1066 {
1067 // Start a new scope that must have everything it needs if it is to
1068 // to make it into the final output stream "s". If you want to make
1069 // a format that only prints out the function or symbol name if there
1070 // is one in the symbol context you can use:
1071 // "{function =${function.name}}"
1072 // The first '{' starts a new scope that end with the matching '}' at
1073 // the end of the string. The contents "function =${function.name}"
1074 // will then be evaluated and only be output if there is a function
1075 // or symbol with a valid name.
1076 StreamString sub_strm;
1077
1078 ++p; // Skip the '{'
1079
Enrico Granatac482a192011-08-17 22:13:59 +00001080 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
Greg Clayton1b654882010-09-19 02:33:57 +00001081 {
1082 // The stream had all it needed
1083 s.Write(sub_strm.GetData(), sub_strm.GetSize());
1084 }
1085 if (*p != '}')
1086 {
1087 success = false;
1088 break;
1089 }
1090 }
1091 else if (*p == '}')
1092 {
1093 // End of a enclosing scope
1094 break;
1095 }
1096 else if (*p == '$')
1097 {
1098 // We have a prompt variable to print
1099 ++p;
1100 if (*p == '{')
1101 {
1102 ++p;
1103 const char *var_name_begin = p;
1104 const char *var_name_end = ::strchr (p, '}');
1105
1106 if (var_name_end && var_name_begin < var_name_end)
1107 {
1108 // if we have already failed to parse, skip this variable
1109 if (success)
1110 {
1111 const char *cstr = NULL;
1112 Address format_addr;
1113 bool calculate_format_addr_function_offset = false;
1114 // Set reg_kind and reg_num to invalid values
1115 RegisterKind reg_kind = kNumRegisterKinds;
1116 uint32_t reg_num = LLDB_INVALID_REGNUM;
1117 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +00001118 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00001119 RegisterContext *reg_ctx = NULL;
Enrico Granata9fc19442011-07-06 02:13:41 +00001120 bool do_deref_pointer = false;
Enrico Granata86cc9822012-03-19 22:58:49 +00001121 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
1122 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001123
Greg Clayton1b654882010-09-19 02:33:57 +00001124 // Each variable must set success to true below...
1125 bool var_success = false;
1126 switch (var_name_begin[0])
1127 {
Enrico Granata4becb372011-06-29 22:27:15 +00001128 case '*':
Enrico Granata4becb372011-06-29 22:27:15 +00001129 case 'v':
Enrico Granata6f3533f2011-07-29 19:53:35 +00001130 case 's':
Enrico Granata4becb372011-06-29 22:27:15 +00001131 {
Enrico Granatac482a192011-08-17 22:13:59 +00001132 if (!valobj)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001133 break;
1134
Enrico Granatac3e320a2011-08-02 17:27:39 +00001135 if (log)
1136 log->Printf("initial string: %s",var_name_begin);
1137
Enrico Granata6f3533f2011-07-29 19:53:35 +00001138 // check for *var and *svar
1139 if (*var_name_begin == '*')
1140 {
1141 do_deref_pointer = true;
1142 var_name_begin++;
1143 }
Enrico Granatac3e320a2011-08-02 17:27:39 +00001144
1145 if (log)
1146 log->Printf("initial string: %s",var_name_begin);
1147
Enrico Granata6f3533f2011-07-29 19:53:35 +00001148 if (*var_name_begin == 's')
1149 {
Enrico Granatac5bc4122012-03-27 02:35:13 +00001150 if (!valobj->IsSynthetic())
1151 valobj = valobj->GetSyntheticValue().get();
Enrico Granata86cc9822012-03-19 22:58:49 +00001152 if (!valobj)
1153 break;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001154 var_name_begin++;
1155 }
1156
Enrico Granatac3e320a2011-08-02 17:27:39 +00001157 if (log)
1158 log->Printf("initial string: %s",var_name_begin);
1159
Enrico Granata6f3533f2011-07-29 19:53:35 +00001160 // should be a 'v' by now
1161 if (*var_name_begin != 'v')
1162 break;
1163
Enrico Granatac3e320a2011-08-02 17:27:39 +00001164 if (log)
1165 log->Printf("initial string: %s",var_name_begin);
1166
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001167 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
Enrico Granata86cc9822012-03-19 22:58:49 +00001168 ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001169 ValueObject::GetValueForExpressionPathOptions options;
Enrico Granata8c9d3562011-08-11 17:08:01 +00001170 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001171 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary;
Greg Clayton34132752011-07-06 04:07:21 +00001172 ValueObject* target = NULL;
Greg Clayton4d122c42011-09-17 08:33:22 +00001173 Format custom_format = eFormatInvalid;
Greg Clayton34132752011-07-06 04:07:21 +00001174 const char* var_name_final = NULL;
1175 const char* var_name_final_if_array_range = NULL;
1176 const char* close_bracket_position = NULL;
1177 int64_t index_lower = -1;
1178 int64_t index_higher = -1;
1179 bool is_array_range = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001180 const char* first_unparsed;
Enrico Granata85933ed2011-08-18 16:38:26 +00001181 bool was_plain_var = false;
1182 bool was_var_format = false;
Enrico Granataa777dc22012-05-08 21:49:57 +00001183 bool was_var_indexed = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001184
Enrico Granatac482a192011-08-17 22:13:59 +00001185 if (!valobj) break;
1186 // simplest case ${var}, just print valobj's value
Greg Clayton34132752011-07-06 04:07:21 +00001187 if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0)
Enrico Granata4becb372011-06-29 22:27:15 +00001188 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001189 was_plain_var = true;
Enrico Granatac482a192011-08-17 22:13:59 +00001190 target = valobj;
Enrico Granata86cc9822012-03-19 22:58:49 +00001191 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Greg Clayton34132752011-07-06 04:07:21 +00001192 }
1193 else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0)
1194 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001195 was_var_format = true;
Greg Clayton34132752011-07-06 04:07:21 +00001196 // this is a variable with some custom format applied to it
1197 const char* percent_position;
Enrico Granatac482a192011-08-17 22:13:59 +00001198 target = valobj;
Enrico Granata86cc9822012-03-19 22:58:49 +00001199 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Greg Clayton34132752011-07-06 04:07:21 +00001200 ScanFormatDescriptor (var_name_begin,
1201 var_name_end,
1202 &var_name_final,
1203 &percent_position,
1204 &custom_format,
1205 &val_obj_display);
1206 }
1207 // this is ${var.something} or multiple .something nested
1208 else if (::strncmp (var_name_begin, "var", strlen("var")) == 0)
1209 {
Enrico Granataa777dc22012-05-08 21:49:57 +00001210 if (::strncmp(var_name_begin, "var[", strlen("var[")) == 0)
1211 was_var_indexed = true;
Greg Clayton34132752011-07-06 04:07:21 +00001212 const char* percent_position;
1213 ScanFormatDescriptor (var_name_begin,
1214 var_name_end,
1215 &var_name_final,
1216 &percent_position,
1217 &custom_format,
1218 &val_obj_display);
1219
1220 const char* open_bracket_position;
1221 const char* separator_position;
1222 ScanBracketedRange (var_name_begin,
1223 var_name_end,
1224 var_name_final,
1225 &open_bracket_position,
1226 &separator_position,
1227 &close_bracket_position,
1228 &var_name_final_if_array_range,
1229 &index_lower,
1230 &index_higher);
1231
1232 Error error;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001233
1234 std::auto_ptr<char> expr_path(new char[var_name_final-var_name_begin-1]);
1235 ::memset(expr_path.get(), 0, var_name_final-var_name_begin-1);
1236 memcpy(expr_path.get(), var_name_begin+3,var_name_final-var_name_begin-3);
1237
Enrico Granatae992a082011-07-22 17:03:19 +00001238 if (log)
1239 log->Printf("symbol to expand: %s",expr_path.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001240
Enrico Granatac482a192011-08-17 22:13:59 +00001241 target = valobj->GetValueForExpressionPath(expr_path.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001242 &first_unparsed,
1243 &reason_to_stop,
1244 &final_value_type,
1245 options,
1246 &what_next).get();
1247
1248 if (!target)
Enrico Granata9fc19442011-07-06 02:13:41 +00001249 {
Enrico Granatae992a082011-07-22 17:03:19 +00001250 if (log)
1251 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1252 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001253 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001254 break;
Enrico Granata9fc19442011-07-06 02:13:41 +00001255 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001256 else
1257 {
Enrico Granatae992a082011-07-22 17:03:19 +00001258 if (log)
1259 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1260 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001261 first_unparsed, reason_to_stop, final_value_type);
1262 }
Enrico Granata4becb372011-06-29 22:27:15 +00001263 }
Greg Clayton34132752011-07-06 04:07:21 +00001264 else
Enrico Granata9fc19442011-07-06 02:13:41 +00001265 break;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001266
Enrico Granata86cc9822012-03-19 22:58:49 +00001267 is_array_range = (final_value_type == ValueObject::eExpressionPathEndResultTypeBoundedRange ||
1268 final_value_type == ValueObject::eExpressionPathEndResultTypeUnboundedRange);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001269
Enrico Granata86cc9822012-03-19 22:58:49 +00001270 do_deref_pointer = (what_next == ValueObject::eExpressionPathAftermathDereference);
Enrico Granata9fc19442011-07-06 02:13:41 +00001271
Enrico Granataa7187d02011-07-06 19:27:11 +00001272 if (do_deref_pointer && !is_array_range)
Enrico Granata9fc19442011-07-06 02:13:41 +00001273 {
Greg Clayton34132752011-07-06 04:07:21 +00001274 // I have not deref-ed yet, let's do it
1275 // this happens when we are not going through GetValueForVariableExpressionPath
1276 // to get to the target ValueObject
Enrico Granata9fc19442011-07-06 02:13:41 +00001277 Error error;
Greg Clayton34132752011-07-06 04:07:21 +00001278 target = target->Dereference(error).get();
Enrico Granatadc940732011-08-23 00:32:52 +00001279 if (error.Fail())
1280 {
1281 if (log)
1282 log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
1283 break;
1284 }
Greg Clayton34132752011-07-06 04:07:21 +00001285 do_deref_pointer = false;
Enrico Granata9fc19442011-07-06 02:13:41 +00001286 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001287
Enrico Granataa777dc22012-05-08 21:49:57 +00001288 // <rdar://problem/11338654>
1289 // we do not want to use the summary for a bitfield of type T:n
1290 // if we were originally dealing with just a T - that would get
1291 // us into an endless recursion
1292 if (target->IsBitfield() && was_var_indexed)
1293 {
1294 // TODO: check for a (T:n)-specific summary - we should still obey that
1295 StreamString bitfield_name;
1296 bitfield_name.Printf("%s:%d", target->GetTypeName().AsCString(), target->GetBitfieldBitSize());
1297 lldb::TypeNameSpecifierImplSP type_sp(new TypeNameSpecifierImpl(bitfield_name.GetData(),false));
1298 if (!DataVisualization::GetSummaryForType(type_sp))
1299 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
1300 }
1301
Enrico Granata85933ed2011-08-18 16:38:26 +00001302 // TODO use flags for these
Enrico Granataf4efecd2011-07-12 22:56:10 +00001303 bool is_array = ClangASTContext::IsArrayType(target->GetClangType());
1304 bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType());
Enrico Granata85933ed2011-08-18 16:38:26 +00001305 bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType());
Enrico Granataf4efecd2011-07-12 22:56:10 +00001306
Enrico Granata86cc9822012-03-19 22:58:49 +00001307 if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) // this should be wrong, but there are some exceptions
Enrico Granataf4efecd2011-07-12 22:56:10 +00001308 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001309 StreamString str_temp;
Enrico Granatae992a082011-07-22 17:03:19 +00001310 if (log)
1311 log->Printf("I am into array || pointer && !range");
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001312
Enrico Granata86cc9822012-03-19 22:58:49 +00001313 if (target->HasSpecialPrintableRepresentation(val_obj_display,
1314 custom_format))
Enrico Granata85933ed2011-08-18 16:38:26 +00001315 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001316 // try to use the special cases
1317 var_success = target->DumpPrintableRepresentation(str_temp,
1318 val_obj_display,
1319 custom_format);
1320 if (log)
1321 log->Printf("special cases did%s match", var_success ? "" : "n't");
1322
1323 // should not happen
1324 if (!var_success)
1325 s << "<invalid usage of pointer value as object>";
1326 else
1327 s << str_temp.GetData();
Enrico Granata85933ed2011-08-18 16:38:26 +00001328 var_success = true;
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001329 break;
Enrico Granata85933ed2011-08-18 16:38:26 +00001330 }
1331 else
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001332 {
Enrico Granata88da35f2011-08-23 21:26:09 +00001333 if (was_plain_var) // if ${var}
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001334 {
1335 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1336 }
Enrico Granata88da35f2011-08-23 21:26:09 +00001337 else if (is_pointer) // if pointer, value is the address stored
1338 {
Greg Clayton23f59502012-07-17 03:23:13 +00001339 target->DumpPrintableRepresentation (s,
1340 val_obj_display,
1341 custom_format,
1342 ValueObject::ePrintableRepresentationSpecialCasesDisable);
Enrico Granata88da35f2011-08-23 21:26:09 +00001343 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001344 else
1345 {
1346 s << "<invalid usage of pointer value as object>";
1347 }
1348 var_success = true;
1349 break;
1350 }
1351 }
1352
1353 // if directly trying to print ${var}, and this is an aggregate, display a nice
1354 // type @ location message
1355 if (is_aggregate && was_plain_var)
1356 {
1357 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1358 var_success = true;
Enrico Granata85933ed2011-08-18 16:38:26 +00001359 break;
1360 }
1361
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001362 // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it
Enrico Granata86cc9822012-03-19 22:58:49 +00001363 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)))
Enrico Granata85933ed2011-08-18 16:38:26 +00001364 {
1365 s << "<invalid use of aggregate type>";
1366 var_success = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001367 break;
1368 }
Greg Clayton34132752011-07-06 04:07:21 +00001369
1370 if (!is_array_range)
Enrico Granatae992a082011-07-22 17:03:19 +00001371 {
1372 if (log)
1373 log->Printf("dumping ordinary printable output");
Greg Clayton34132752011-07-06 04:07:21 +00001374 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
Enrico Granatae992a082011-07-22 17:03:19 +00001375 }
Greg Clayton34132752011-07-06 04:07:21 +00001376 else
Enrico Granatae992a082011-07-22 17:03:19 +00001377 {
1378 if (log)
1379 log->Printf("checking if I can handle as array");
Greg Clayton34132752011-07-06 04:07:21 +00001380 if (!is_array && !is_pointer)
1381 break;
Enrico Granatae992a082011-07-22 17:03:19 +00001382 if (log)
1383 log->Printf("handle as array");
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001384 const char* special_directions = NULL;
1385 StreamString special_directions_writer;
Greg Clayton34132752011-07-06 04:07:21 +00001386 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1387 {
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001388 ConstString additional_data;
1389 additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1);
1390 special_directions_writer.Printf("${%svar%s}",
1391 do_deref_pointer ? "*" : "",
1392 additional_data.GetCString());
1393 special_directions = special_directions_writer.GetData();
Greg Clayton34132752011-07-06 04:07:21 +00001394 }
1395
1396 // let us display items index_lower thru index_higher of this array
1397 s.PutChar('[');
1398 var_success = true;
1399
1400 if (index_higher < 0)
Enrico Granatac482a192011-08-17 22:13:59 +00001401 index_higher = valobj->GetNumChildren() - 1;
Greg Clayton34132752011-07-06 04:07:21 +00001402
Greg Claytoncc4d0142012-02-17 07:49:44 +00001403 uint32_t max_num_children = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00001404
Greg Clayton34132752011-07-06 04:07:21 +00001405 for (;index_lower<=index_higher;index_lower++)
1406 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001407 ValueObject* item = ExpandIndexedExpression (target,
1408 index_lower,
1409 exe_ctx->GetFramePtr(),
1410 false).get();
Greg Clayton34132752011-07-06 04:07:21 +00001411
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001412 if (!item)
1413 {
Enrico Granatae992a082011-07-22 17:03:19 +00001414 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001415 log->Printf("ERROR in getting child item at index %lld", index_lower);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001416 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001417 else
1418 {
Enrico Granatae992a082011-07-22 17:03:19 +00001419 if (log)
1420 log->Printf("special_directions for child item: %s",special_directions);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001421 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001422
Greg Clayton34132752011-07-06 04:07:21 +00001423 if (!special_directions)
1424 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1425 else
1426 var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
1427
Enrico Granata22c55d12011-08-12 02:00:06 +00001428 if (--max_num_children == 0)
1429 {
1430 s.PutCString(", ...");
1431 break;
1432 }
1433
Greg Clayton34132752011-07-06 04:07:21 +00001434 if (index_lower < index_higher)
1435 s.PutChar(',');
1436 }
1437 s.PutChar(']');
1438 }
Enrico Granata4becb372011-06-29 22:27:15 +00001439 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001440 break;
Greg Clayton1b654882010-09-19 02:33:57 +00001441 case 'a':
1442 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
1443 {
1444 if (addr && addr->IsValid())
1445 {
1446 var_success = true;
1447 format_addr = *addr;
1448 }
1449 }
Greg Clayton5a314712011-10-14 07:41:33 +00001450 else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0)
1451 {
1452 var_success = true;
1453 var_name_begin += strlen("ansi."); // Skip the "ansi."
1454 if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0)
1455 {
1456 var_name_begin += strlen("fg."); // Skip the "fg."
1457 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1458 {
1459 s.Printf ("%s%s%s",
1460 lldb_utility::ansi::k_escape_start,
1461 lldb_utility::ansi::k_fg_black,
1462 lldb_utility::ansi::k_escape_end);
1463 }
1464 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1465 {
1466 s.Printf ("%s%s%s",
1467 lldb_utility::ansi::k_escape_start,
1468 lldb_utility::ansi::k_fg_red,
1469 lldb_utility::ansi::k_escape_end);
1470 }
1471 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1472 {
1473 s.Printf ("%s%s%s",
1474 lldb_utility::ansi::k_escape_start,
1475 lldb_utility::ansi::k_fg_green,
1476 lldb_utility::ansi::k_escape_end);
1477 }
1478 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1479 {
1480 s.Printf ("%s%s%s",
1481 lldb_utility::ansi::k_escape_start,
1482 lldb_utility::ansi::k_fg_yellow,
1483 lldb_utility::ansi::k_escape_end);
1484 }
1485 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1486 {
1487 s.Printf ("%s%s%s",
1488 lldb_utility::ansi::k_escape_start,
1489 lldb_utility::ansi::k_fg_blue,
1490 lldb_utility::ansi::k_escape_end);
1491 }
1492 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1493 {
1494 s.Printf ("%s%s%s",
1495 lldb_utility::ansi::k_escape_start,
1496 lldb_utility::ansi::k_fg_purple,
1497 lldb_utility::ansi::k_escape_end);
1498 }
1499 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1500 {
1501 s.Printf ("%s%s%s",
1502 lldb_utility::ansi::k_escape_start,
1503 lldb_utility::ansi::k_fg_cyan,
1504 lldb_utility::ansi::k_escape_end);
1505 }
1506 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1507 {
1508 s.Printf ("%s%s%s",
1509 lldb_utility::ansi::k_escape_start,
1510 lldb_utility::ansi::k_fg_white,
1511 lldb_utility::ansi::k_escape_end);
1512 }
1513 else
1514 {
1515 var_success = false;
1516 }
1517 }
1518 else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0)
1519 {
1520 var_name_begin += strlen("bg."); // Skip the "bg."
1521 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1522 {
1523 s.Printf ("%s%s%s",
1524 lldb_utility::ansi::k_escape_start,
1525 lldb_utility::ansi::k_bg_black,
1526 lldb_utility::ansi::k_escape_end);
1527 }
1528 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1529 {
1530 s.Printf ("%s%s%s",
1531 lldb_utility::ansi::k_escape_start,
1532 lldb_utility::ansi::k_bg_red,
1533 lldb_utility::ansi::k_escape_end);
1534 }
1535 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1536 {
1537 s.Printf ("%s%s%s",
1538 lldb_utility::ansi::k_escape_start,
1539 lldb_utility::ansi::k_bg_green,
1540 lldb_utility::ansi::k_escape_end);
1541 }
1542 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1543 {
1544 s.Printf ("%s%s%s",
1545 lldb_utility::ansi::k_escape_start,
1546 lldb_utility::ansi::k_bg_yellow,
1547 lldb_utility::ansi::k_escape_end);
1548 }
1549 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1550 {
1551 s.Printf ("%s%s%s",
1552 lldb_utility::ansi::k_escape_start,
1553 lldb_utility::ansi::k_bg_blue,
1554 lldb_utility::ansi::k_escape_end);
1555 }
1556 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1557 {
1558 s.Printf ("%s%s%s",
1559 lldb_utility::ansi::k_escape_start,
1560 lldb_utility::ansi::k_bg_purple,
1561 lldb_utility::ansi::k_escape_end);
1562 }
1563 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1564 {
1565 s.Printf ("%s%s%s",
1566 lldb_utility::ansi::k_escape_start,
1567 lldb_utility::ansi::k_bg_cyan,
1568 lldb_utility::ansi::k_escape_end);
1569 }
1570 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1571 {
1572 s.Printf ("%s%s%s",
1573 lldb_utility::ansi::k_escape_start,
1574 lldb_utility::ansi::k_bg_white,
1575 lldb_utility::ansi::k_escape_end);
1576 }
1577 else
1578 {
1579 var_success = false;
1580 }
1581 }
1582 else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0)
1583 {
1584 s.Printf ("%s%s%s",
1585 lldb_utility::ansi::k_escape_start,
1586 lldb_utility::ansi::k_ctrl_normal,
1587 lldb_utility::ansi::k_escape_end);
1588 }
1589 else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0)
1590 {
1591 s.Printf ("%s%s%s",
1592 lldb_utility::ansi::k_escape_start,
1593 lldb_utility::ansi::k_ctrl_bold,
1594 lldb_utility::ansi::k_escape_end);
1595 }
1596 else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0)
1597 {
1598 s.Printf ("%s%s%s",
1599 lldb_utility::ansi::k_escape_start,
1600 lldb_utility::ansi::k_ctrl_faint,
1601 lldb_utility::ansi::k_escape_end);
1602 }
1603 else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0)
1604 {
1605 s.Printf ("%s%s%s",
1606 lldb_utility::ansi::k_escape_start,
1607 lldb_utility::ansi::k_ctrl_italic,
1608 lldb_utility::ansi::k_escape_end);
1609 }
1610 else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0)
1611 {
1612 s.Printf ("%s%s%s",
1613 lldb_utility::ansi::k_escape_start,
1614 lldb_utility::ansi::k_ctrl_underline,
1615 lldb_utility::ansi::k_escape_end);
1616 }
1617 else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0)
1618 {
1619 s.Printf ("%s%s%s",
1620 lldb_utility::ansi::k_escape_start,
1621 lldb_utility::ansi::k_ctrl_slow_blink,
1622 lldb_utility::ansi::k_escape_end);
1623 }
1624 else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0)
1625 {
1626 s.Printf ("%s%s%s",
1627 lldb_utility::ansi::k_escape_start,
1628 lldb_utility::ansi::k_ctrl_fast_blink,
1629 lldb_utility::ansi::k_escape_end);
1630 }
1631 else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0)
1632 {
1633 s.Printf ("%s%s%s",
1634 lldb_utility::ansi::k_escape_start,
1635 lldb_utility::ansi::k_ctrl_negative,
1636 lldb_utility::ansi::k_escape_end);
1637 }
1638 else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0)
1639 {
1640 s.Printf ("%s%s%s",
1641 lldb_utility::ansi::k_escape_start,
1642 lldb_utility::ansi::k_ctrl_conceal,
1643 lldb_utility::ansi::k_escape_end);
1644
1645 }
1646 else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0)
1647 {
1648 s.Printf ("%s%s%s",
1649 lldb_utility::ansi::k_escape_start,
1650 lldb_utility::ansi::k_ctrl_crossed_out,
1651 lldb_utility::ansi::k_escape_end);
1652 }
1653 else
1654 {
1655 var_success = false;
1656 }
1657 }
Greg Clayton1b654882010-09-19 02:33:57 +00001658 break;
1659
1660 case 'p':
1661 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 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 Process *process = exe_ctx->GetProcessPtr();
1666 if (process)
Greg Clayton1b654882010-09-19 02:33:57 +00001667 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001668 var_name_begin += ::strlen ("process.");
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("%llu", process->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001672 var_success = true;
1673 }
1674 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
1675 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
1676 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
1677 {
1678 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1679 if (exe_module)
Greg Clayton1b654882010-09-19 02:33:57 +00001680 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001681 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1682 {
1683 format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
1684 var_success = format_file_spec;
1685 }
1686 else
1687 {
1688 format_file_spec = exe_module->GetFileSpec();
1689 var_success = format_file_spec;
1690 }
Greg Clayton1b654882010-09-19 02:33:57 +00001691 }
1692 }
1693 }
Greg Claytonc14ee322011-09-22 04:58:26 +00001694 }
Greg Clayton1b654882010-09-19 02:33:57 +00001695 }
1696 break;
1697
1698 case 't':
1699 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
1700 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001701 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001702 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001703 Thread *thread = exe_ctx->GetThreadPtr();
1704 if (thread)
Greg Clayton1b654882010-09-19 02:33:57 +00001705 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001706 var_name_begin += ::strlen ("thread.");
1707 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001708 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001709 s.Printf("0x%4.4llx", thread->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001710 var_success = true;
1711 }
1712 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1713 {
1714 s.Printf("%u", thread->GetIndexID());
1715 var_success = true;
1716 }
1717 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1718 {
1719 cstr = thread->GetName();
1720 var_success = cstr && cstr[0];
1721 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001722 s.PutCString(cstr);
Greg Claytonc14ee322011-09-22 04:58:26 +00001723 }
1724 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
1725 {
1726 cstr = thread->GetQueueName();
1727 var_success = cstr && cstr[0];
1728 if (var_success)
1729 s.PutCString(cstr);
1730 }
1731 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
1732 {
1733 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1734 if (stop_info_sp)
1735 {
1736 cstr = stop_info_sp->GetDescription();
1737 if (cstr && cstr[0])
1738 {
1739 s.PutCString(cstr);
1740 var_success = true;
1741 }
Greg Clayton1b654882010-09-19 02:33:57 +00001742 }
1743 }
Jim Ingham73ca05a2011-12-17 01:35:57 +00001744 else if (::strncmp (var_name_begin, "return-value}", strlen("return-value}")) == 0)
1745 {
1746 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1747 if (stop_info_sp)
1748 {
1749 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1750 if (return_valobj_sp)
1751 {
Jim Inghamef651602011-12-22 19:12:40 +00001752 ValueObject::DumpValueObjectOptions dump_options;
1753 ValueObject::DumpValueObject (s, return_valobj_sp.get(), dump_options);
1754 var_success = true;
Jim Ingham73ca05a2011-12-17 01:35:57 +00001755 }
1756 }
1757 }
Greg Clayton1b654882010-09-19 02:33:57 +00001758 }
1759 }
1760 }
1761 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
1762 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001763 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1764 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +00001765 {
Greg Clayton1b654882010-09-19 02:33:57 +00001766 var_name_begin += ::strlen ("target.");
1767 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
1768 {
1769 ArchSpec arch (target->GetArchitecture ());
1770 if (arch.IsValid())
1771 {
Greg Clayton64195a22011-02-23 00:35:02 +00001772 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +00001773 var_success = true;
1774 }
1775 }
1776 }
1777 }
1778 break;
1779
1780
1781 case 'm':
1782 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
1783 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001784 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +00001785 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001786 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +00001787 var_name_begin += ::strlen ("module.");
1788
1789 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1790 {
1791 if (module->GetFileSpec())
1792 {
1793 var_name_begin += ::strlen ("file.");
1794
1795 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1796 {
1797 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
1798 var_success = format_file_spec;
1799 }
1800 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1801 {
1802 format_file_spec = module->GetFileSpec();
1803 var_success = format_file_spec;
1804 }
1805 }
1806 }
1807 }
1808 }
1809 break;
1810
1811
1812 case 'f':
1813 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1814 {
1815 if (sc && sc->comp_unit != NULL)
1816 {
1817 var_name_begin += ::strlen ("file.");
1818
1819 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1820 {
1821 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
1822 var_success = format_file_spec;
1823 }
1824 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1825 {
1826 format_file_spec = *sc->comp_unit;
1827 var_success = format_file_spec;
1828 }
1829 }
1830 }
1831 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
1832 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001833 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001834 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001835 StackFrame *frame = exe_ctx->GetFramePtr();
1836 if (frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001837 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001838 var_name_begin += ::strlen ("frame.");
1839 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001840 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001841 s.Printf("%u", frame->GetFrameIndex());
1842 var_success = true;
1843 }
1844 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
1845 {
1846 reg_kind = eRegisterKindGeneric;
1847 reg_num = LLDB_REGNUM_GENERIC_PC;
1848 var_success = true;
1849 }
1850 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
1851 {
1852 reg_kind = eRegisterKindGeneric;
1853 reg_num = LLDB_REGNUM_GENERIC_SP;
1854 var_success = true;
1855 }
1856 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
1857 {
1858 reg_kind = eRegisterKindGeneric;
1859 reg_num = LLDB_REGNUM_GENERIC_FP;
1860 var_success = true;
1861 }
1862 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
1863 {
1864 reg_kind = eRegisterKindGeneric;
1865 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
1866 var_success = true;
1867 }
1868 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
1869 {
1870 reg_ctx = frame->GetRegisterContext().get();
1871 if (reg_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001872 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001873 var_name_begin += ::strlen ("reg.");
1874 if (var_name_begin < var_name_end)
1875 {
1876 std::string reg_name (var_name_begin, var_name_end);
1877 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
1878 if (reg_info)
1879 var_success = true;
1880 }
Greg Clayton1b654882010-09-19 02:33:57 +00001881 }
1882 }
1883 }
1884 }
1885 }
1886 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
1887 {
1888 if (sc && (sc->function != NULL || sc->symbol != NULL))
1889 {
1890 var_name_begin += ::strlen ("function.");
1891 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1892 {
1893 if (sc->function)
Greg Clayton81c22f62011-10-19 18:09:39 +00001894 s.Printf("function{0x%8.8llx}", sc->function->GetID());
Greg Clayton1b654882010-09-19 02:33:57 +00001895 else
1896 s.Printf("symbol[%u]", sc->symbol->GetID());
1897
1898 var_success = true;
1899 }
1900 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1901 {
1902 if (sc->function)
1903 cstr = sc->function->GetName().AsCString (NULL);
1904 else if (sc->symbol)
1905 cstr = sc->symbol->GetName().AsCString (NULL);
1906 if (cstr)
1907 {
1908 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001909
1910 if (sc->block)
1911 {
1912 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1913 if (inline_block)
1914 {
1915 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1916 if (inline_info)
1917 {
1918 s.PutCString(" [inlined] ");
1919 inline_info->GetName().Dump(&s);
1920 }
1921 }
1922 }
Greg Clayton1b654882010-09-19 02:33:57 +00001923 var_success = true;
1924 }
1925 }
Greg Clayton6d3dbf52012-01-13 08:39:16 +00001926 else if (::strncmp (var_name_begin, "name-with-args}", strlen("name-with-args}")) == 0)
1927 {
1928 // Print the function name with arguments in it
1929
1930 if (sc->function)
1931 {
1932 var_success = true;
1933 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
1934 cstr = sc->function->GetName().AsCString (NULL);
1935 if (cstr)
1936 {
1937 const InlineFunctionInfo *inline_info = NULL;
1938 VariableListSP variable_list_sp;
1939 bool get_function_vars = true;
1940 if (sc->block)
1941 {
1942 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1943
1944 if (inline_block)
1945 {
1946 get_function_vars = false;
1947 inline_info = sc->block->GetInlinedFunctionInfo();
1948 if (inline_info)
1949 variable_list_sp = inline_block->GetBlockVariableList (true);
1950 }
1951 }
1952
1953 if (get_function_vars)
1954 {
1955 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
1956 }
1957
1958 if (inline_info)
1959 {
1960 s.PutCString (cstr);
1961 s.PutCString (" [inlined] ");
1962 cstr = inline_info->GetName().GetCString();
1963 }
1964
1965 VariableList args;
1966 if (variable_list_sp)
1967 {
1968 const size_t num_variables = variable_list_sp->GetSize();
1969 for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
1970 {
1971 VariableSP var_sp (variable_list_sp->GetVariableAtIndex(var_idx));
1972 if (var_sp->GetScope() == eValueTypeVariableArgument)
1973 args.AddVariable (var_sp);
1974 }
1975
1976 }
1977 if (args.GetSize() > 0)
1978 {
1979 const char *open_paren = strchr (cstr, '(');
1980 const char *close_paren = NULL;
1981 if (open_paren)
1982 close_paren = strchr (open_paren, ')');
1983
1984 if (open_paren)
1985 s.Write(cstr, open_paren - cstr + 1);
1986 else
1987 {
1988 s.PutCString (cstr);
1989 s.PutChar ('(');
1990 }
Greg Clayton5b6889b2012-01-18 21:56:18 +00001991 const size_t num_args = args.GetSize();
Greg Clayton6d3dbf52012-01-13 08:39:16 +00001992 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
1993 {
1994 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
1995 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
1996 const char *var_name = var_value_sp->GetName().GetCString();
1997 const char *var_value = var_value_sp->GetValueAsCString();
1998 if (var_value_sp->GetError().Success())
1999 {
2000 if (arg_idx > 0)
2001 s.PutCString (", ");
2002 s.Printf ("%s=%s", var_name, var_value);
2003 }
2004 }
2005
2006 if (close_paren)
2007 s.PutCString (close_paren);
2008 else
2009 s.PutChar(')');
2010
2011 }
2012 else
2013 {
2014 s.PutCString(cstr);
2015 }
2016 }
2017 }
2018 else if (sc->symbol)
2019 {
2020 cstr = sc->symbol->GetName().AsCString (NULL);
2021 if (cstr)
2022 {
2023 s.PutCString(cstr);
2024 var_success = true;
2025 }
2026 }
2027 }
Greg Clayton1b654882010-09-19 02:33:57 +00002028 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
2029 {
2030 var_success = addr != NULL;
2031 if (var_success)
2032 {
2033 format_addr = *addr;
2034 calculate_format_addr_function_offset = true;
2035 }
2036 }
2037 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
2038 {
2039 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
2040 if (var_success)
2041 {
2042 format_addr = sc->line_entry.range.GetBaseAddress();
2043 calculate_format_addr_function_offset = true;
2044 }
2045 }
2046 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
2047 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002048 StackFrame *frame = exe_ctx->GetFramePtr();
2049 var_success = frame != NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00002050 if (var_success)
2051 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002052 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002053 calculate_format_addr_function_offset = true;
2054 }
2055 }
2056 }
2057 }
2058 break;
2059
2060 case 'l':
2061 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
2062 {
2063 if (sc && sc->line_entry.IsValid())
2064 {
2065 var_name_begin += ::strlen ("line.");
2066 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
2067 {
2068 var_name_begin += ::strlen ("file.");
2069
2070 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
2071 {
2072 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
2073 var_success = format_file_spec;
2074 }
2075 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
2076 {
2077 format_file_spec = sc->line_entry.file;
2078 var_success = format_file_spec;
2079 }
2080 }
2081 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
2082 {
2083 var_success = true;
2084 s.Printf("%u", sc->line_entry.line);
2085 }
2086 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
2087 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
2088 {
2089 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
2090 if (var_success)
2091 {
2092 format_addr = sc->line_entry.range.GetBaseAddress();
2093 if (var_name_begin[0] == 'e')
2094 format_addr.Slide (sc->line_entry.range.GetByteSize());
2095 }
2096 }
2097 }
2098 }
2099 break;
2100 }
2101
2102 if (var_success)
2103 {
2104 // If format addr is valid, then we need to print an address
2105 if (reg_num != LLDB_INVALID_REGNUM)
2106 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002107 StackFrame *frame = exe_ctx->GetFramePtr();
Greg Clayton1b654882010-09-19 02:33:57 +00002108 // We have a register value to display...
2109 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
2110 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002111 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002112 }
2113 else
2114 {
2115 if (reg_ctx == NULL)
Greg Claytonc14ee322011-09-22 04:58:26 +00002116 reg_ctx = frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00002117
2118 if (reg_ctx)
2119 {
2120 if (reg_kind != kNumRegisterKinds)
2121 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
2122 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
2123 var_success = reg_info != NULL;
2124 }
2125 }
2126 }
2127
2128 if (reg_info != NULL)
2129 {
Greg Clayton7349bd92011-05-09 20:18:18 +00002130 RegisterValue reg_value;
2131 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
2132 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00002133 {
Greg Clayton9a8fa912011-05-15 04:12:07 +00002134 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
Greg Clayton1b654882010-09-19 02:33:57 +00002135 }
2136 }
2137
2138 if (format_file_spec)
2139 {
2140 s << format_file_spec;
2141 }
2142
2143 // If format addr is valid, then we need to print an address
2144 if (format_addr.IsValid())
2145 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002146 var_success = false;
2147
Greg Clayton1b654882010-09-19 02:33:57 +00002148 if (calculate_format_addr_function_offset)
2149 {
2150 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00002151
Greg Clayton0603aa92010-10-04 01:05:56 +00002152 if (sc)
2153 {
2154 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00002155 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002156 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00002157 if (sc->block)
2158 {
2159 // Check to make sure we aren't in an inline
2160 // function. If we are, use the inline block
2161 // range that contains "format_addr" since
2162 // blocks can be discontiguous.
2163 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2164 AddressRange inline_range;
2165 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
2166 func_addr = inline_range.GetBaseAddress();
2167 }
2168 }
Greg Claytone7612132012-03-07 21:03:09 +00002169 else if (sc->symbol && sc->symbol->ValueIsAddress())
2170 func_addr = sc->symbol->GetAddress();
Greg Clayton0603aa92010-10-04 01:05:56 +00002171 }
2172
2173 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00002174 {
2175 if (func_addr.GetSection() == format_addr.GetSection())
2176 {
2177 addr_t func_file_addr = func_addr.GetFileAddress();
2178 addr_t addr_file_addr = format_addr.GetFileAddress();
2179 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002180 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00002181 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002182 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002183 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00002184 }
2185 else
Greg Clayton0603aa92010-10-04 01:05:56 +00002186 {
2187 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2188 if (target)
2189 {
2190 addr_t func_load_addr = func_addr.GetLoadAddress (target);
2191 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
2192 if (addr_load_addr > func_load_addr)
2193 s.Printf(" + %llu", addr_load_addr - func_load_addr);
2194 else if (addr_load_addr < func_load_addr)
2195 s.Printf(" - %llu", func_load_addr - addr_load_addr);
2196 var_success = true;
2197 }
2198 }
Greg Clayton1b654882010-09-19 02:33:57 +00002199 }
2200 }
2201 else
2202 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002203 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00002204 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00002205 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
2206 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00002207 if (vaddr == LLDB_INVALID_ADDRESS)
2208 vaddr = format_addr.GetFileAddress ();
2209
2210 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00002211 {
Greg Clayton514487e2011-02-15 21:59:32 +00002212 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00002213 if (addr_width == 0)
2214 addr_width = 16;
2215 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002216 var_success = true;
2217 }
Greg Clayton1b654882010-09-19 02:33:57 +00002218 }
2219 }
2220 }
2221
2222 if (var_success == false)
2223 success = false;
2224 }
2225 p = var_name_end;
2226 }
2227 else
2228 break;
2229 }
2230 else
2231 {
2232 // We got a dollar sign with no '{' after it, it must just be a dollar sign
2233 s.PutChar(*p);
2234 }
2235 }
2236 else if (*p == '\\')
2237 {
2238 ++p; // skip the slash
2239 switch (*p)
2240 {
2241 case 'a': s.PutChar ('\a'); break;
2242 case 'b': s.PutChar ('\b'); break;
2243 case 'f': s.PutChar ('\f'); break;
2244 case 'n': s.PutChar ('\n'); break;
2245 case 'r': s.PutChar ('\r'); break;
2246 case 't': s.PutChar ('\t'); break;
2247 case 'v': s.PutChar ('\v'); break;
2248 case '\'': s.PutChar ('\''); break;
2249 case '\\': s.PutChar ('\\'); break;
2250 case '0':
2251 // 1 to 3 octal chars
2252 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002253 // Make a string that can hold onto the initial zero char,
2254 // up to 3 octal digits, and a terminating NULL.
2255 char oct_str[5] = { 0, 0, 0, 0, 0 };
2256
2257 int i;
2258 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
2259 oct_str[i] = p[i];
2260
2261 // We don't want to consume the last octal character since
2262 // the main for loop will do this for us, so we advance p by
2263 // one less than i (even if i is zero)
2264 p += i - 1;
2265 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2266 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002267 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002268 char octal_char = octal_value;
2269 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00002270 }
Greg Clayton1b654882010-09-19 02:33:57 +00002271 }
2272 break;
2273
2274 case 'x':
2275 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00002276 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002277 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002278 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00002279
Greg Clayton0603aa92010-10-04 01:05:56 +00002280 // Make a string that can hold onto two hex chars plus a
2281 // NULL terminator
2282 char hex_str[3] = { 0,0,0 };
2283 hex_str[0] = *p;
2284 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002285 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002286 ++p; // Skip the first of the two hex chars
2287 hex_str[1] = *p;
2288 }
2289
2290 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2291 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002292 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00002293 }
2294 else
2295 {
2296 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00002297 }
2298 break;
2299
2300 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00002301 // Just desensitize any other character by just printing what
2302 // came after the '\'
2303 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00002304 break;
2305
2306 }
2307
2308 }
2309 }
2310 if (end)
2311 *end = p;
2312 return success;
2313}
2314
Jim Ingham228063c2012-02-21 02:23:08 +00002315void
2316Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
2317{
Jim Ingham4f02b222012-02-22 22:49:20 +00002318 // For simplicity's sake, I am not going to deal with how to close down any
2319 // open logging streams, I just redirect everything from here on out to the
2320 // callback.
Jim Ingham228063c2012-02-21 02:23:08 +00002321 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
2322}
2323
2324bool
2325Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
2326{
2327 Log::Callbacks log_callbacks;
2328
2329 StreamSP log_stream_sp;
2330 if (m_log_callback_stream_sp != NULL)
2331 {
2332 log_stream_sp = m_log_callback_stream_sp;
2333 // For now when using the callback mode you always get thread & timestamp.
2334 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
2335 }
2336 else if (log_file == NULL || *log_file == '\0')
2337 {
2338 log_stream_sp.reset(new StreamFile(GetOutputFile().GetDescriptor(), false));
2339 }
2340 else
2341 {
2342 LogStreamMap::iterator pos = m_log_streams.find(log_file);
2343 if (pos == m_log_streams.end())
2344 {
2345 log_stream_sp.reset (new StreamFile (log_file));
2346 m_log_streams[log_file] = log_stream_sp;
2347 }
2348 else
2349 log_stream_sp = pos->second;
2350 }
2351 assert (log_stream_sp.get());
2352
2353 if (log_options == 0)
2354 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
2355
2356 if (Log::GetLogChannelCallbacks (channel, log_callbacks))
2357 {
2358 log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream);
2359 return true;
2360 }
2361 else
2362 {
2363 LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel));
2364 if (log_channel_sp)
2365 {
2366 if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories))
2367 {
2368 return true;
2369 }
2370 else
2371 {
2372 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
2373 return false;
2374 }
2375 }
2376 else
2377 {
2378 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
2379 return false;
2380 }
2381 }
2382 return false;
2383}
2384
Greg Clayton1b654882010-09-19 02:33:57 +00002385#pragma mark Debugger::SettingsController
2386
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002387//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002388// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002389//--------------------------------------------------
2390
Greg Clayton1b654882010-09-19 02:33:57 +00002391Debugger::SettingsController::SettingsController () :
Greg Clayton4d122c42011-09-17 08:33:22 +00002392 UserSettingsController ("", UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002393{
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002394}
2395
Greg Clayton1b654882010-09-19 02:33:57 +00002396Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002397{
2398}
2399
2400
Greg Clayton4d122c42011-09-17 08:33:22 +00002401InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00002402Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002403{
Greg Claytonb9556ac2012-01-30 07:41:31 +00002404 InstanceSettingsSP new_settings_sp (new DebuggerInstanceSettings (GetSettingsController(),
2405 false,
2406 instance_name));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002407 return new_settings_sp;
2408}
2409
Greg Clayton1b654882010-09-19 02:33:57 +00002410#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002411//--------------------------------------------------
2412// class DebuggerInstanceSettings
2413//--------------------------------------------------
2414
Greg Claytona7015092010-09-18 01:14:36 +00002415DebuggerInstanceSettings::DebuggerInstanceSettings
2416(
Greg Claytonb9556ac2012-01-30 07:41:31 +00002417 const UserSettingsControllerSP &m_owner_sp,
Greg Claytona7015092010-09-18 01:14:36 +00002418 bool live_instance,
2419 const char *name
2420) :
Greg Claytonb9556ac2012-01-30 07:41:31 +00002421 InstanceSettings (m_owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00002422 m_term_width (80),
Greg Claytone372b982011-11-21 21:44:34 +00002423 m_stop_source_before_count (3),
2424 m_stop_source_after_count (3),
2425 m_stop_disassembly_count (4),
2426 m_stop_disassembly_display (eStopDisassemblyTypeNoSource),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002427 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00002428 m_frame_format (),
2429 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002430 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002431 m_use_external_editor (false),
2432 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002433{
Caroline Ticef20e8232010-09-09 18:26:37 +00002434 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2435 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
2436 // 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 +00002437 // The same is true of CreateInstanceName().
2438
2439 if (GetInstanceName() == InstanceSettings::InvalidName())
2440 {
2441 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Claytonb9556ac2012-01-30 07:41:31 +00002442 m_owner_sp->RegisterInstanceSettings (this);
Caroline Tice9e41c152010-09-16 19:05:55 +00002443 }
Caroline Ticef20e8232010-09-09 18:26:37 +00002444
2445 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002446 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00002447 const InstanceSettingsSP &pending_settings = m_owner_sp->FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002448 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002449 }
2450}
2451
2452DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Claytonb9556ac2012-01-30 07:41:31 +00002453 InstanceSettings (Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002454 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00002455 m_frame_format (rhs.m_frame_format),
2456 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002457 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002458 m_use_external_editor (rhs.m_use_external_editor),
2459 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002460{
Greg Claytonb9556ac2012-01-30 07:41:31 +00002461 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2462 if (owner_sp)
2463 {
2464 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
2465 owner_sp->RemovePendingSettings (m_instance_name);
2466 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002467}
2468
2469DebuggerInstanceSettings::~DebuggerInstanceSettings ()
2470{
2471}
2472
2473DebuggerInstanceSettings&
2474DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
2475{
2476 if (this != &rhs)
2477 {
Greg Clayton1b654882010-09-19 02:33:57 +00002478 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002479 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00002480 m_frame_format = rhs.m_frame_format;
2481 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002482 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002483 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002484 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002485 }
2486
2487 return *this;
2488}
2489
Greg Clayton1b654882010-09-19 02:33:57 +00002490bool
2491DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
2492{
2493 bool valid = false;
2494
2495 // Verify we have a value string.
2496 if (value == NULL || value[0] == '\0')
2497 {
Greg Clayton86edbf42011-10-26 00:56:27 +00002498 err.SetErrorString ("missing value, can't set terminal width without a value");
Greg Clayton1b654882010-09-19 02:33:57 +00002499 }
2500 else
2501 {
2502 char *end = NULL;
2503 const uint32_t width = ::strtoul (value, &end, 0);
2504
Johnny Chenea9fc182010-09-20 16:36:43 +00002505 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00002506 {
Jim Ingham57190ba2012-04-26 21:39:32 +00002507 return ValidTermWidthValue (width, err);
Greg Clayton1b654882010-09-19 02:33:57 +00002508 }
2509 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002510 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value);
Greg Clayton1b654882010-09-19 02:33:57 +00002511 }
2512
2513 return valid;
2514}
2515
Jim Ingham57190ba2012-04-26 21:39:32 +00002516bool
2517DebuggerInstanceSettings::ValidTermWidthValue (uint32_t value, Error err)
2518{
2519 if (value >= 10 && value <= 1024)
2520 return true;
2521 else
2522 {
2523 err.SetErrorString ("invalid term-width value; value must be between 10 and 1024");
2524 return false;
2525 }
2526}
Greg Clayton1b654882010-09-19 02:33:57 +00002527
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002528void
2529DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2530 const char *index_value,
2531 const char *value,
2532 const ConstString &instance_name,
2533 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00002534 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002535 Error &err,
2536 bool pending)
2537{
Greg Clayton0603aa92010-10-04 01:05:56 +00002538
2539 if (var_name == TermWidthVarName())
2540 {
2541 if (ValidTermWidthValue (value, err))
2542 {
2543 m_term_width = ::strtoul (value, NULL, 0);
2544 }
2545 }
2546 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002547 {
Caroline Tice101c7c22010-09-09 06:25:08 +00002548 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002549 if (!pending)
2550 {
Caroline Tice49e27372010-09-07 18:35:40 +00002551 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2552 // strip off the brackets before passing it to BroadcastPromptChange.
2553
2554 std::string tmp_instance_name (instance_name.AsCString());
2555 if ((tmp_instance_name[0] == '[')
2556 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
2557 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
2558 ConstString new_name (tmp_instance_name.c_str());
2559
2560 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002561 }
2562 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002563 else if (var_name == GetFrameFormatName())
2564 {
2565 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
2566 }
2567 else if (var_name == GetThreadFormatName())
2568 {
2569 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
2570 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002571 else if (var_name == ScriptLangVarName())
2572 {
2573 bool success;
2574 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
2575 &success);
2576 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002577 else if (var_name == UseExternalEditorVarName ())
2578 {
Greg Clayton385aa282011-04-22 03:55:06 +00002579 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00002580 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002581 else if (var_name == AutoConfirmName ())
2582 {
Greg Clayton385aa282011-04-22 03:55:06 +00002583 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00002584 }
Greg Claytone372b982011-11-21 21:44:34 +00002585 else if (var_name == StopSourceContextBeforeName ())
2586 {
2587 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2588 if (new_value != UINT32_MAX)
2589 m_stop_source_before_count = new_value;
2590 else
Greg Clayton53eb7ad2012-07-11 20:33:48 +00002591 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextBeforeName ().GetCString());
Greg Claytone372b982011-11-21 21:44:34 +00002592 }
2593 else if (var_name == StopSourceContextAfterName ())
2594 {
2595 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2596 if (new_value != UINT32_MAX)
2597 m_stop_source_after_count = new_value;
2598 else
Greg Clayton53eb7ad2012-07-11 20:33:48 +00002599 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextAfterName ().GetCString());
Greg Claytone372b982011-11-21 21:44:34 +00002600 }
2601 else if (var_name == StopDisassemblyCountName ())
2602 {
2603 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2604 if (new_value != UINT32_MAX)
2605 m_stop_disassembly_count = new_value;
2606 else
2607 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopDisassemblyCountName ().GetCString());
2608 }
2609 else if (var_name == StopDisassemblyDisplayName ())
2610 {
2611 int new_value;
2612 UserSettingsController::UpdateEnumVariable (g_show_disassembly_enum_values, &new_value, value, err);
2613 if (err.Success())
2614 m_stop_disassembly_display = (StopDisassemblyType)new_value;
2615 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002616}
2617
Caroline Tice12cecd72010-09-20 21:37:42 +00002618bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002619DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2620 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00002621 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00002622 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002623{
2624 if (var_name == PromptVarName())
2625 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002626 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002627
2628 }
2629 else if (var_name == ScriptLangVarName())
2630 {
2631 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
2632 }
Caroline Tice101c7c22010-09-09 06:25:08 +00002633 else if (var_name == TermWidthVarName())
2634 {
2635 StreamString width_str;
Greg Claytone372b982011-11-21 21:44:34 +00002636 width_str.Printf ("%u", m_term_width);
Caroline Tice101c7c22010-09-09 06:25:08 +00002637 value.AppendString (width_str.GetData());
2638 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002639 else if (var_name == GetFrameFormatName ())
2640 {
2641 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
2642 }
2643 else if (var_name == GetThreadFormatName ())
2644 {
2645 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
2646 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002647 else if (var_name == UseExternalEditorVarName())
2648 {
2649 if (m_use_external_editor)
2650 value.AppendString ("true");
2651 else
2652 value.AppendString ("false");
2653 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002654 else if (var_name == AutoConfirmName())
2655 {
2656 if (m_auto_confirm_on)
2657 value.AppendString ("true");
2658 else
2659 value.AppendString ("false");
2660 }
Greg Claytone372b982011-11-21 21:44:34 +00002661 else if (var_name == StopSourceContextAfterName ())
2662 {
2663 StreamString strm;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00002664 strm.Printf ("%u", m_stop_source_after_count);
Greg Claytone372b982011-11-21 21:44:34 +00002665 value.AppendString (strm.GetData());
2666 }
2667 else if (var_name == StopSourceContextBeforeName ())
2668 {
2669 StreamString strm;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00002670 strm.Printf ("%u", m_stop_source_before_count);
Greg Claytone372b982011-11-21 21:44:34 +00002671 value.AppendString (strm.GetData());
2672 }
2673 else if (var_name == StopDisassemblyCountName ())
2674 {
2675 StreamString strm;
2676 strm.Printf ("%u", m_stop_disassembly_count);
2677 value.AppendString (strm.GetData());
2678 }
2679 else if (var_name == StopDisassemblyDisplayName ())
2680 {
2681 if (m_stop_disassembly_display >= eStopDisassemblyTypeNever && m_stop_disassembly_display <= eStopDisassemblyTypeAlways)
2682 value.AppendString (g_show_disassembly_enum_values[m_stop_disassembly_display].string_value);
2683 else
2684 value.AppendString ("<invalid>");
2685 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002686 else
Caroline Tice12cecd72010-09-20 21:37:42 +00002687 {
2688 if (err)
2689 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2690 return false;
2691 }
2692 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002693}
2694
2695void
Greg Clayton4d122c42011-09-17 08:33:22 +00002696DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002697 bool pending)
2698{
2699 if (new_settings.get() == NULL)
2700 return;
2701
2702 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
2703
2704 m_prompt = new_debugger_settings->m_prompt;
2705 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00002706 {
2707 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2708 // strip off the brackets before passing it to BroadcastPromptChange.
2709
2710 std::string tmp_instance_name (m_instance_name.AsCString());
2711 if ((tmp_instance_name[0] == '[')
2712 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
2713 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
2714 ConstString new_name (tmp_instance_name.c_str());
2715
2716 BroadcastPromptChange (new_name, m_prompt.c_str());
2717 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002718 m_frame_format = new_debugger_settings->m_frame_format;
2719 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002720 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002721 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002722 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002723 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002724}
2725
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002726
2727bool
2728DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
2729{
2730 std::string tmp_prompt;
2731
2732 if (new_prompt != NULL)
2733 {
2734 tmp_prompt = new_prompt ;
2735 int len = tmp_prompt.size();
2736 if (len > 1
2737 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
2738 && (tmp_prompt[len-1] == tmp_prompt[0]))
2739 {
2740 tmp_prompt = tmp_prompt.substr(1,len-2);
2741 }
2742 len = tmp_prompt.size();
2743 if (tmp_prompt[len-1] != ' ')
2744 tmp_prompt.append(" ");
2745 }
2746 EventSP new_event_sp;
2747 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
2748 new EventDataBytes (tmp_prompt.c_str())));
2749
2750 if (instance_name.GetLength() != 0)
2751 {
2752 // Set prompt for a particular instance.
2753 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
2754 if (dbg != NULL)
2755 {
2756 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
2757 }
2758 }
2759
2760 return true;
2761}
2762
2763const ConstString
2764DebuggerInstanceSettings::CreateInstanceName ()
2765{
2766 static int instance_count = 1;
2767 StreamString sstr;
2768
2769 sstr.Printf ("debugger_%d", instance_count);
2770 ++instance_count;
2771
2772 const ConstString ret_val (sstr.GetData());
2773
2774 return ret_val;
2775}
2776
Jim Ingham3bcdb292010-10-04 22:44:14 +00002777
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002778//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002779// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002780//--------------------------------------------------
2781
2782
2783SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002784Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002785{
2786 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00002787 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
2788 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002789 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
2790};
2791
Greg Claytonbb562b12010-10-04 02:44:26 +00002792#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00002793#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002794
Greg Clayton0603aa92010-10-04 01:05:56 +00002795#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2796 "{, ${frame.pc}}"\
2797 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00002798 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00002799 "{, stop reason = ${thread.stop-reason}}"\
Jim Inghamef651602011-12-22 19:12:40 +00002800 "{\\nReturn value: ${thread.return-value}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00002801 "\\n"
2802
Greg Clayton315d2ca2010-11-02 01:53:21 +00002803//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2804// "{, ${frame.pc}}"\
2805// MODULE_WITH_FUNC\
2806// FILE_AND_LINE\
2807// "{, stop reason = ${thread.stop-reason}}"\
2808// "{, name = ${thread.name}}"\
2809// "{, queue = ${thread.queue}}"\
2810// "\\n"
2811
Greg Clayton0603aa92010-10-04 01:05:56 +00002812#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
2813 MODULE_WITH_FUNC\
2814 FILE_AND_LINE\
2815 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002816
2817SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002818Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002819{
Greg Clayton0603aa92010-10-04 01:05:56 +00002820// NAME Setting variable type Default Enum Init'd Hidden Help
2821// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00002822{ "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 +00002823{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00002824{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
2825{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002826{ "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 +00002827{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
2828{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
2829{ "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." },
2830{ "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." },
2831{ "stop-disassembly-count", eSetVarTypeInt, "0", NULL, false, false, "The number of disassembly lines to show when displaying a stopped context." },
2832{ "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 +00002833{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002834};