blob: 6bb68db42f1c97b7dca590812a27d458346b8c80 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Greg Clayton4a33d312011-06-23 17:59:56 +000010#include "lldb/Core/Debugger.h"
11
12#include <map>
13
Enrico Granata4becb372011-06-29 22:27:15 +000014#include "clang/AST/DeclCXX.h"
15#include "clang/AST/Type.h"
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/lldb-private.h"
18#include "lldb/Core/ConnectionFileDescriptor.h"
Greg Clayton4a33d312011-06-23 17:59:56 +000019#include "lldb/Core/FormatManager.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/InputReader.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000021#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000023#include "lldb/Core/StreamAsynchronousIO.h"
Jim Ingham228063c2012-02-21 02:23:08 +000024#include "lldb/Core/StreamCallback.h"
Greg Clayton1b654882010-09-19 02:33:57 +000025#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000027#include "lldb/Core/ValueObject.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000028#include "lldb/Core/ValueObjectVariable.h"
Greg Claytona3406612011-02-07 23:24:47 +000029#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000030#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000031#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Target/TargetList.h"
33#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000034#include "lldb/Target/RegisterContext.h"
35#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000037#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038
39using namespace lldb;
40using namespace lldb_private;
41
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042
Greg Clayton1b654882010-09-19 02:33:57 +000043static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000044static lldb::user_id_t g_unique_id = 1;
45
Greg Clayton1b654882010-09-19 02:33:57 +000046#pragma mark Static Functions
47
48static Mutex &
49GetDebuggerListMutex ()
50{
51 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
52 return g_mutex;
53}
54
55typedef std::vector<DebuggerSP> DebuggerList;
56
57static DebuggerList &
58GetDebuggerList()
59{
60 // hide the static debugger list inside a singleton accessor to avoid
61 // global init contructors
62 static DebuggerList g_list;
63 return g_list;
64}
65
66
Greg Claytone372b982011-11-21 21:44:34 +000067static const ConstString &
68PromptVarName ()
69{
70 static ConstString g_const_string ("prompt");
71 return g_const_string;
72}
73
74static const ConstString &
75GetFrameFormatName ()
76{
77 static ConstString g_const_string ("frame-format");
78 return g_const_string;
79}
80
81static const ConstString &
82GetThreadFormatName ()
83{
84 static ConstString g_const_string ("thread-format");
85 return g_const_string;
86}
87
88static const ConstString &
89ScriptLangVarName ()
90{
91 static ConstString g_const_string ("script-lang");
92 return g_const_string;
93}
94
95static const ConstString &
96TermWidthVarName ()
97{
98 static ConstString g_const_string ("term-width");
99 return g_const_string;
100}
101
102static const ConstString &
103UseExternalEditorVarName ()
104{
105 static ConstString g_const_string ("use-external-editor");
106 return g_const_string;
107}
108
109static const ConstString &
110AutoConfirmName ()
111{
112 static ConstString g_const_string ("auto-confirm");
113 return g_const_string;
114}
115
116static const ConstString &
117StopSourceContextBeforeName ()
118{
119 static ConstString g_const_string ("stop-line-count-before");
120 return g_const_string;
121}
122
123static const ConstString &
124StopSourceContextAfterName ()
125{
126 static ConstString g_const_string ("stop-line-count-after");
127 return g_const_string;
128}
129
130static const ConstString &
131StopDisassemblyCountName ()
132{
133 static ConstString g_const_string ("stop-disassembly-count");
134 return g_const_string;
135}
136
137static const ConstString &
138StopDisassemblyDisplayName ()
139{
140 static ConstString g_const_string ("stop-disassembly-display");
141 return g_const_string;
142}
143
144OptionEnumValueElement
145DebuggerInstanceSettings::g_show_disassembly_enum_values[] =
146{
147 { eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
148 { eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
149 { eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
150 { 0, NULL, NULL }
151};
152
153
154
Greg Clayton1b654882010-09-19 02:33:57 +0000155#pragma mark Debugger
156
Greg Clayton99d0faf2010-11-18 23:32:35 +0000157UserSettingsControllerSP &
158Debugger::GetSettingsController ()
159{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000160 static UserSettingsControllerSP g_settings_controller_sp;
161 if (!g_settings_controller_sp)
162 {
163 g_settings_controller_sp.reset (new Debugger::SettingsController);
164
165 // The first shared pointer to Debugger::SettingsController in
166 // g_settings_controller_sp must be fully created above so that
167 // the DebuggerInstanceSettings can use a weak_ptr to refer back
168 // to the master setttings controller
169 InstanceSettingsSP default_instance_settings_sp (new DebuggerInstanceSettings (g_settings_controller_sp,
170 false,
171 InstanceSettings::GetDefaultName().AsCString()));
172 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
173 }
174 return g_settings_controller_sp;
Greg Clayton99d0faf2010-11-18 23:32:35 +0000175}
176
Caroline Tice2f88aad2011-01-14 00:29:16 +0000177int
178Debugger::TestDebuggerRefCount ()
179{
180 return g_shared_debugger_refcount;
181}
182
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183void
184Debugger::Initialize ()
185{
Greg Claytonc15f55e2012-03-30 20:53:46 +0000186 if (g_shared_debugger_refcount++ == 0)
Greg Claytondbe54502010-11-19 03:46:01 +0000187 lldb_private::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000188}
189
190void
191Debugger::Terminate ()
192{
Greg Clayton66111032010-06-23 01:19:29 +0000193 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194 {
Greg Clayton66111032010-06-23 01:19:29 +0000195 g_shared_debugger_refcount--;
196 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197 {
Greg Claytondbe54502010-11-19 03:46:01 +0000198 lldb_private::WillTerminate();
199 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000200
201 // Clear our master list of debugger objects
202 Mutex::Locker locker (GetDebuggerListMutex ());
203 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 }
206}
207
Caroline Tice20bd37f2011-03-10 22:14:10 +0000208void
209Debugger::SettingsInitialize ()
210{
211 static bool g_initialized = false;
212
213 if (!g_initialized)
214 {
215 g_initialized = true;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000216 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Caroline Tice20bd37f2011-03-10 22:14:10 +0000217 SettingsController::global_settings_table,
218 SettingsController::instance_settings_table);
219 // Now call SettingsInitialize for each settings 'child' of Debugger
220 Target::SettingsInitialize ();
221 }
222}
223
224void
225Debugger::SettingsTerminate ()
226{
227
228 // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
229 // Settings.
230
231 Target::SettingsTerminate ();
232
233 // Now terminate the Debugger Settings.
234
235 UserSettingsControllerSP &usc = GetSettingsController();
236 UserSettingsController::FinalizeSettingsController (usc);
237 usc.reset();
238}
239
Greg Clayton66111032010-06-23 01:19:29 +0000240DebuggerSP
Jim Ingham228063c2012-02-21 02:23:08 +0000241Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
Greg Clayton66111032010-06-23 01:19:29 +0000242{
Jim Ingham228063c2012-02-21 02:23:08 +0000243 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
Greg Claytonc15f55e2012-03-30 20:53:46 +0000244 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000245 {
246 Mutex::Locker locker (GetDebuggerListMutex ());
247 GetDebuggerList().push_back(debugger_sp);
248 }
249 return debugger_sp;
250}
251
Caroline Ticee02657b2011-01-22 01:02:07 +0000252void
Greg Clayton4d122c42011-09-17 08:33:22 +0000253Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000254{
255 if (debugger_sp.get() == NULL)
256 return;
257
Jim Ingham8314c522011-09-15 21:36:42 +0000258 debugger_sp->Clear();
259
Greg Claytonc15f55e2012-03-30 20:53:46 +0000260 if (g_shared_debugger_refcount > 0)
Caroline Ticee02657b2011-01-22 01:02:07 +0000261 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000262 Mutex::Locker locker (GetDebuggerListMutex ());
263 DebuggerList &debugger_list = GetDebuggerList ();
264 DebuggerList::iterator pos, end = debugger_list.end();
265 for (pos = debugger_list.begin (); pos != end; ++pos)
Caroline Ticee02657b2011-01-22 01:02:07 +0000266 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000267 if ((*pos).get() == debugger_sp.get())
268 {
269 debugger_list.erase (pos);
270 return;
271 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000272 }
273 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000274}
275
Greg Clayton4d122c42011-09-17 08:33:22 +0000276DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000277Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
278{
Greg Clayton4d122c42011-09-17 08:33:22 +0000279 DebuggerSP debugger_sp;
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000280
Greg Claytonc15f55e2012-03-30 20:53:46 +0000281 if (g_shared_debugger_refcount > 0)
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000282 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000283 Mutex::Locker locker (GetDebuggerListMutex ());
284 DebuggerList &debugger_list = GetDebuggerList();
285 DebuggerList::iterator pos, end = debugger_list.end();
286
287 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000288 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000289 if ((*pos).get()->m_instance_name == instance_name)
290 {
291 debugger_sp = *pos;
292 break;
293 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000294 }
295 }
296 return debugger_sp;
297}
Greg Clayton66111032010-06-23 01:19:29 +0000298
299TargetSP
300Debugger::FindTargetWithProcessID (lldb::pid_t pid)
301{
Greg Clayton4d122c42011-09-17 08:33:22 +0000302 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000303 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000304 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000305 Mutex::Locker locker (GetDebuggerListMutex ());
306 DebuggerList &debugger_list = GetDebuggerList();
307 DebuggerList::iterator pos, end = debugger_list.end();
308 for (pos = debugger_list.begin(); pos != end; ++pos)
309 {
310 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
311 if (target_sp)
312 break;
313 }
Greg Clayton66111032010-06-23 01:19:29 +0000314 }
315 return target_sp;
316}
317
Greg Claytone4e45922011-11-16 05:37:56 +0000318TargetSP
319Debugger::FindTargetWithProcess (Process *process)
320{
321 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000322 if (g_shared_debugger_refcount > 0)
Greg Claytone4e45922011-11-16 05:37:56 +0000323 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000324 Mutex::Locker locker (GetDebuggerListMutex ());
325 DebuggerList &debugger_list = GetDebuggerList();
326 DebuggerList::iterator pos, end = debugger_list.end();
327 for (pos = debugger_list.begin(); pos != end; ++pos)
328 {
329 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
330 if (target_sp)
331 break;
332 }
Greg Claytone4e45922011-11-16 05:37:56 +0000333 }
334 return target_sp;
335}
336
Greg Clayton66111032010-06-23 01:19:29 +0000337
Jim Ingham228063c2012-02-21 02:23:08 +0000338Debugger::Debugger (lldb::LogOutputCallback log_callback, void *baton) :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000339 UserID (g_unique_id++),
Greg Claytonb9556ac2012-01-30 07:41:31 +0000340 DebuggerInstanceSettings (GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000341 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000342 m_input_file (),
343 m_output_file (),
344 m_error_file (),
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000345 m_target_list (*this),
Greg Claytonded470d2011-03-19 01:12:21 +0000346 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347 m_listener ("lldb.Debugger"),
Jim Inghame37d6052011-09-13 00:29:56 +0000348 m_source_manager(*this),
349 m_source_file_cache(),
Greg Clayton66111032010-06-23 01:19:29 +0000350 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000351 m_input_reader_stack (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000352 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000353{
Jim Ingham228063c2012-02-21 02:23:08 +0000354 if (log_callback)
355 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000356 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000357 // Always add our default platform to the platform list
358 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
359 assert (default_platform_sp.get());
360 m_platform_list.Append (default_platform_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361}
362
363Debugger::~Debugger ()
364{
Jim Ingham8314c522011-09-15 21:36:42 +0000365 Clear();
366}
367
368void
369Debugger::Clear()
370{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000371 CleanUpInputReaders();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000372 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000373 int num_targets = m_target_list.GetNumTargets();
374 for (int i = 0; i < num_targets; i++)
375 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000376 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
377 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000378 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000379 ProcessSP process_sp (target_sp->GetProcessSP());
380 if (process_sp)
381 {
382 if (process_sp->GetShouldDetach())
383 process_sp->Detach();
384 }
385 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000386 }
Greg Clayton66111032010-06-23 01:19:29 +0000387 }
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000388 BroadcasterManager::Clear ();
Greg Clayton66111032010-06-23 01:19:29 +0000389 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390
Jim Ingham8314c522011-09-15 21:36:42 +0000391}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392
393bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000394Debugger::GetCloseInputOnEOF () const
395{
396 return m_input_comm.GetCloseOnEOF();
397}
398
399void
400Debugger::SetCloseInputOnEOF (bool b)
401{
402 m_input_comm.SetCloseOnEOF(b);
403}
404
405bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000406Debugger::GetAsyncExecution ()
407{
Greg Clayton66111032010-06-23 01:19:29 +0000408 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409}
410
411void
412Debugger::SetAsyncExecution (bool async_execution)
413{
Greg Clayton66111032010-06-23 01:19:29 +0000414 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415}
416
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417
418void
419Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
420{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000421 File &in_file = GetInputFile();
422 in_file.SetStream (fh, tranfer_ownership);
423 if (in_file.IsValid() == false)
424 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425
426 // Disconnect from any old connection if we had one
427 m_input_comm.Disconnect ();
Greg Clayton32720b52012-01-14 20:47:38 +0000428 // Pass false as the second argument to ConnectionFileDescriptor below because
429 // our "in_file" above will already take ownership if requested and we don't
430 // want to objects trying to own and close a file descriptor.
431 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
433
434 Error error;
435 if (m_input_comm.StartReadThread (&error) == false)
436 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000437 File &err_file = GetErrorFile();
438
439 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
440 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442}
443
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444void
445Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
446{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000447 File &out_file = GetOutputFile();
448 out_file.SetStream (fh, tranfer_ownership);
449 if (out_file.IsValid() == false)
450 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000451
452 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453}
454
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455void
456Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
457{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000458 File &err_file = GetErrorFile();
459 err_file.SetStream (fh, tranfer_ownership);
460 if (err_file.IsValid() == false)
461 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462}
463
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000465Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466{
467 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000468 TargetSP target_sp(GetSelectedTarget());
469 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470
471 if (target_sp)
472 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000473 ProcessSP process_sp (target_sp->GetProcessSP());
474 exe_ctx.SetProcessSP (process_sp);
475 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000477 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
478 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000480 exe_ctx.SetThreadSP (thread_sp);
481 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
482 if (exe_ctx.GetFramePtr() == NULL)
483 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484 }
485 }
486 }
487 return exe_ctx;
488
489}
490
Caroline Ticeb44880c2011-02-10 01:15:13 +0000491InputReaderSP
492Debugger::GetCurrentInputReader ()
493{
494 InputReaderSP reader_sp;
495
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000496 if (!m_input_reader_stack.IsEmpty())
Caroline Ticeb44880c2011-02-10 01:15:13 +0000497 {
498 // Clear any finished readers from the stack
499 while (CheckIfTopInputReaderIsDone()) ;
500
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000501 if (!m_input_reader_stack.IsEmpty())
502 reader_sp = m_input_reader_stack.Top();
Caroline Ticeb44880c2011-02-10 01:15:13 +0000503 }
504
505 return reader_sp;
506}
507
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508void
509Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
510{
Caroline Ticeefed6132010-11-19 20:47:54 +0000511 if (bytes_len > 0)
512 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
513 else
514 ((Debugger *)baton)->DispatchInputEndOfFile ();
515}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516
517
518void
519Debugger::DispatchInput (const char *bytes, size_t bytes_len)
520{
Caroline Ticeefed6132010-11-19 20:47:54 +0000521 if (bytes == NULL || bytes_len == 0)
522 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523
524 WriteToDefaultReader (bytes, bytes_len);
525}
526
527void
Caroline Ticeefed6132010-11-19 20:47:54 +0000528Debugger::DispatchInputInterrupt ()
529{
530 m_input_reader_data.clear();
531
Caroline Ticeb44880c2011-02-10 01:15:13 +0000532 InputReaderSP reader_sp (GetCurrentInputReader ());
533 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000534 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000535 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000536
Caroline Ticeb44880c2011-02-10 01:15:13 +0000537 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000538 while (CheckIfTopInputReaderIsDone ()) ;
539 }
540}
541
542void
543Debugger::DispatchInputEndOfFile ()
544{
545 m_input_reader_data.clear();
546
Caroline Ticeb44880c2011-02-10 01:15:13 +0000547 InputReaderSP reader_sp (GetCurrentInputReader ());
548 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000549 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000550 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000551
Caroline Ticeb44880c2011-02-10 01:15:13 +0000552 // 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 +0000553 while (CheckIfTopInputReaderIsDone ()) ;
554 }
555}
556
557void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000558Debugger::CleanUpInputReaders ()
559{
560 m_input_reader_data.clear();
561
Caroline Ticeb44880c2011-02-10 01:15:13 +0000562 // 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 +0000563 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000564 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000565 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000566 if (reader_sp)
567 {
568 reader_sp->Notify (eInputReaderEndOfFile);
569 reader_sp->SetIsDone (true);
570 }
571 }
572}
573
574void
Caroline Tice969ed3d2011-05-02 20:41:46 +0000575Debugger::NotifyTopInputReader (InputReaderAction notification)
576{
577 InputReaderSP reader_sp (GetCurrentInputReader());
578 if (reader_sp)
579 {
580 reader_sp->Notify (notification);
581
582 // Flush out any input readers that are done.
583 while (CheckIfTopInputReaderIsDone ())
584 /* Do nothing. */;
585 }
586}
587
Caroline Tice9088b062011-05-09 23:06:58 +0000588bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000589Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp)
Caroline Tice9088b062011-05-09 23:06:58 +0000590{
Caroline Ticed61c10b2011-06-16 16:27:19 +0000591 InputReaderSP top_reader_sp (GetCurrentInputReader());
Caroline Tice9088b062011-05-09 23:06:58 +0000592
Caroline Ticed61c10b2011-06-16 16:27:19 +0000593 return (reader_sp.get() == top_reader_sp.get());
Caroline Tice9088b062011-05-09 23:06:58 +0000594}
595
596
Caroline Tice969ed3d2011-05-02 20:41:46 +0000597void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000598Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
599{
600 if (bytes && bytes_len)
601 m_input_reader_data.append (bytes, bytes_len);
602
603 if (m_input_reader_data.empty())
604 return;
605
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000606 while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000607 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000608 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000609 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610 if (!reader_sp)
611 break;
612
Greg Clayton471b31c2010-07-20 22:52:08 +0000613 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614 m_input_reader_data.size());
615 if (bytes_handled)
616 {
617 m_input_reader_data.erase (0, bytes_handled);
618 }
619 else
620 {
621 // No bytes were handled, we might not have reached our
622 // granularity, just return and wait for more data
623 break;
624 }
625 }
626
Caroline Ticeb44880c2011-02-10 01:15:13 +0000627 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628 while (CheckIfTopInputReaderIsDone ())
629 /* Do nothing. */;
630
631}
632
633void
634Debugger::PushInputReader (const InputReaderSP& reader_sp)
635{
636 if (!reader_sp)
637 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000638
639 // Deactivate the old top reader
640 InputReaderSP top_reader_sp (GetCurrentInputReader ());
641
642 if (top_reader_sp)
643 top_reader_sp->Notify (eInputReaderDeactivate);
644
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000645 m_input_reader_stack.Push (reader_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646 reader_sp->Notify (eInputReaderActivate);
647 ActivateInputReader (reader_sp);
648}
649
650bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000651Debugger::PopInputReader (const InputReaderSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652{
653 bool result = false;
654
655 // The reader on the stop of the stack is done, so let the next
656 // read on the stack referesh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000657 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000658 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000659 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000660 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000661
662 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
663 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000664 m_input_reader_stack.Pop ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 reader_sp->Notify (eInputReaderDeactivate);
666 reader_sp->Notify (eInputReaderDone);
667 result = true;
668
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000669 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000671 reader_sp = m_input_reader_stack.Top();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672 if (reader_sp)
673 {
674 ActivateInputReader (reader_sp);
675 reader_sp->Notify (eInputReaderReactivate);
676 }
677 }
678 }
679 }
680 return result;
681}
682
683bool
684Debugger::CheckIfTopInputReaderIsDone ()
685{
686 bool result = false;
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000687 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000688 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000689 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000690 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691
692 if (reader_sp && reader_sp->IsDone())
693 {
694 result = true;
695 PopInputReader (reader_sp);
696 }
697 }
698 return result;
699}
700
701void
702Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
703{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000704 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000706 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000707 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000708 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000709
710 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711
Greg Claytona3406612011-02-07 23:24:47 +0000712 switch (reader_sp->GetGranularity())
713 {
714 case eInputReaderGranularityByte:
715 case eInputReaderGranularityWord:
716 tty.SetCanonical (false);
717 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718
Greg Claytona3406612011-02-07 23:24:47 +0000719 case eInputReaderGranularityLine:
720 case eInputReaderGranularityAll:
721 tty.SetCanonical (true);
722 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000723
Greg Claytona3406612011-02-07 23:24:47 +0000724 default:
725 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000726 }
727 }
728}
Greg Clayton66111032010-06-23 01:19:29 +0000729
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000730StreamSP
731Debugger::GetAsyncOutputStream ()
732{
733 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
734 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
735}
736
737StreamSP
738Debugger::GetAsyncErrorStream ()
739{
740 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
741 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
742}
743
Enrico Granata061858c2012-02-15 02:34:21 +0000744uint32_t
745Debugger::GetNumDebuggers()
746{
Greg Claytonc15f55e2012-03-30 20:53:46 +0000747 if (g_shared_debugger_refcount > 0)
748 {
749 Mutex::Locker locker (GetDebuggerListMutex ());
750 return GetDebuggerList().size();
751 }
752 return 0;
Enrico Granata061858c2012-02-15 02:34:21 +0000753}
754
755lldb::DebuggerSP
756Debugger::GetDebuggerAtIndex (uint32_t index)
757{
758 DebuggerSP debugger_sp;
759
Greg Claytonc15f55e2012-03-30 20:53:46 +0000760 if (g_shared_debugger_refcount > 0)
761 {
762 Mutex::Locker locker (GetDebuggerListMutex ());
763 DebuggerList &debugger_list = GetDebuggerList();
Enrico Granata061858c2012-02-15 02:34:21 +0000764
Greg Claytonc15f55e2012-03-30 20:53:46 +0000765 if (index < debugger_list.size())
766 debugger_sp = debugger_list[index];
767 }
768
Enrico Granata061858c2012-02-15 02:34:21 +0000769 return debugger_sp;
770}
771
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000772DebuggerSP
773Debugger::FindDebuggerWithID (lldb::user_id_t id)
774{
Greg Clayton4d122c42011-09-17 08:33:22 +0000775 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000776
Greg Claytonc15f55e2012-03-30 20:53:46 +0000777 if (g_shared_debugger_refcount > 0)
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000778 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000779 Mutex::Locker locker (GetDebuggerListMutex ());
780 DebuggerList &debugger_list = GetDebuggerList();
781 DebuggerList::iterator pos, end = debugger_list.end();
782 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000783 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000784 if ((*pos).get()->GetID() == id)
785 {
786 debugger_sp = *pos;
787 break;
788 }
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000789 }
790 }
791 return debugger_sp;
792}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000793
Greg Clayton1b654882010-09-19 02:33:57 +0000794static void
795TestPromptFormats (StackFrame *frame)
796{
797 if (frame == NULL)
798 return;
799
800 StreamString s;
801 const char *prompt_format =
802 "{addr = '${addr}'\n}"
803 "{process.id = '${process.id}'\n}"
804 "{process.name = '${process.name}'\n}"
805 "{process.file.basename = '${process.file.basename}'\n}"
806 "{process.file.fullpath = '${process.file.fullpath}'\n}"
807 "{thread.id = '${thread.id}'\n}"
808 "{thread.index = '${thread.index}'\n}"
809 "{thread.name = '${thread.name}'\n}"
810 "{thread.queue = '${thread.queue}'\n}"
811 "{thread.stop-reason = '${thread.stop-reason}'\n}"
812 "{target.arch = '${target.arch}'\n}"
813 "{module.file.basename = '${module.file.basename}'\n}"
814 "{module.file.fullpath = '${module.file.fullpath}'\n}"
815 "{file.basename = '${file.basename}'\n}"
816 "{file.fullpath = '${file.fullpath}'\n}"
817 "{frame.index = '${frame.index}'\n}"
818 "{frame.pc = '${frame.pc}'\n}"
819 "{frame.sp = '${frame.sp}'\n}"
820 "{frame.fp = '${frame.fp}'\n}"
821 "{frame.flags = '${frame.flags}'\n}"
822 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
823 "{frame.reg.rip = '${frame.reg.rip}'\n}"
824 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
825 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
826 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
827 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
828 "{frame.reg.carp = '${frame.reg.carp}'\n}"
829 "{function.id = '${function.id}'\n}"
830 "{function.name = '${function.name}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +0000831 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +0000832 "{function.addr-offset = '${function.addr-offset}'\n}"
833 "{function.line-offset = '${function.line-offset}'\n}"
834 "{function.pc-offset = '${function.pc-offset}'\n}"
835 "{line.file.basename = '${line.file.basename}'\n}"
836 "{line.file.fullpath = '${line.file.fullpath}'\n}"
837 "{line.number = '${line.number}'\n}"
838 "{line.start-addr = '${line.start-addr}'\n}"
839 "{line.end-addr = '${line.end-addr}'\n}"
840;
841
842 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
843 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000844 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000845 const char *end = NULL;
846 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
847 {
848 printf("%s\n", s.GetData());
849 }
850 else
851 {
852 printf ("error: at '%s'\n", end);
853 printf ("what we got: %s\n", s.GetData());
854 }
855}
856
Enrico Granata9fc19442011-07-06 02:13:41 +0000857static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000858ScanFormatDescriptor (const char* var_name_begin,
859 const char* var_name_end,
860 const char** var_name_final,
861 const char** percent_position,
Greg Clayton4d122c42011-09-17 08:33:22 +0000862 Format* custom_format,
Enrico Granatadc940732011-08-23 00:32:52 +0000863 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
Enrico Granata9fc19442011-07-06 02:13:41 +0000864{
Enrico Granatae992a082011-07-22 17:03:19 +0000865 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000866 *percent_position = ::strchr(var_name_begin,'%');
Greg Clayton34132752011-07-06 04:07:21 +0000867 if (!*percent_position || *percent_position > var_name_end)
Enrico Granatae992a082011-07-22 17:03:19 +0000868 {
869 if (log)
870 log->Printf("no format descriptor in string, skipping");
Enrico Granata9fc19442011-07-06 02:13:41 +0000871 *var_name_final = var_name_end;
Enrico Granatae992a082011-07-22 17:03:19 +0000872 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000873 else
874 {
875 *var_name_final = *percent_position;
876 char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0';
877 memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1);
Enrico Granatae992a082011-07-22 17:03:19 +0000878 if (log)
879 log->Printf("parsing %s as a format descriptor", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000880 if ( !FormatManager::GetFormatFromCString(format_name,
881 true,
882 *custom_format) )
883 {
Enrico Granatae992a082011-07-22 17:03:19 +0000884 if (log)
885 log->Printf("%s is an unknown format", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000886 // if this is an @ sign, print ObjC description
Greg Clayton34132752011-07-06 04:07:21 +0000887 if (*format_name == '@')
Enrico Granata86cc9822012-03-19 22:58:49 +0000888 *val_obj_display = ValueObject::eValueObjectRepresentationStyleLanguageSpecific;
Enrico Granata9fc19442011-07-06 02:13:41 +0000889 // if this is a V, print the value using the default format
Enrico Granatae992a082011-07-22 17:03:19 +0000890 else if (*format_name == 'V')
Enrico Granata86cc9822012-03-19 22:58:49 +0000891 *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Enrico Granatad55546b2011-07-22 00:16:08 +0000892 // if this is an L, print the location of the value
Enrico Granatae992a082011-07-22 17:03:19 +0000893 else if (*format_name == 'L')
Enrico Granata86cc9822012-03-19 22:58:49 +0000894 *val_obj_display = ValueObject::eValueObjectRepresentationStyleLocation;
Enrico Granatad55546b2011-07-22 00:16:08 +0000895 // if this is an S, print the summary after all
Enrico Granatae992a082011-07-22 17:03:19 +0000896 else if (*format_name == 'S')
Enrico Granata86cc9822012-03-19 22:58:49 +0000897 *val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000898 else if (*format_name == '#')
Enrico Granata86cc9822012-03-19 22:58:49 +0000899 *val_obj_display = ValueObject::eValueObjectRepresentationStyleChildrenCount;
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000900 else if (*format_name == 'T')
Enrico Granata86cc9822012-03-19 22:58:49 +0000901 *val_obj_display = ValueObject::eValueObjectRepresentationStyleType;
Enrico Granatae992a082011-07-22 17:03:19 +0000902 else if (log)
903 log->Printf("%s is an error, leaving the previous value alone", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +0000904 }
905 // a good custom format tells us to print the value using it
906 else
Enrico Granatae992a082011-07-22 17:03:19 +0000907 {
908 if (log)
909 log->Printf("will display value for this VO");
Enrico Granata86cc9822012-03-19 22:58:49 +0000910 *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Enrico Granatae992a082011-07-22 17:03:19 +0000911 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000912 delete format_name;
913 }
Enrico Granatae992a082011-07-22 17:03:19 +0000914 if (log)
915 log->Printf("final format description outcome: custom_format = %d, val_obj_display = %d",
916 *custom_format,
917 *val_obj_display);
Enrico Granata9fc19442011-07-06 02:13:41 +0000918 return true;
919}
920
921static bool
Enrico Granatadc940732011-08-23 00:32:52 +0000922ScanBracketedRange (const char* var_name_begin,
923 const char* var_name_end,
924 const char* var_name_final,
925 const char** open_bracket_position,
926 const char** separator_position,
927 const char** close_bracket_position,
928 const char** var_name_final_if_array_range,
929 int64_t* index_lower,
930 int64_t* index_higher)
Enrico Granata9fc19442011-07-06 02:13:41 +0000931{
Enrico Granatae992a082011-07-22 17:03:19 +0000932 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000933 *open_bracket_position = ::strchr(var_name_begin,'[');
Greg Clayton34132752011-07-06 04:07:21 +0000934 if (*open_bracket_position && *open_bracket_position < var_name_final)
Enrico Granata9fc19442011-07-06 02:13:41 +0000935 {
936 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
937 *close_bracket_position = ::strchr(*open_bracket_position,']');
938 // as usual, we assume that [] will come before %
939 //printf("trying to expand a []\n");
940 *var_name_final_if_array_range = *open_bracket_position;
Greg Clayton34132752011-07-06 04:07:21 +0000941 if (*close_bracket_position - *open_bracket_position == 1)
Enrico Granata9fc19442011-07-06 02:13:41 +0000942 {
Enrico Granatae992a082011-07-22 17:03:19 +0000943 if (log)
944 log->Printf("[] detected.. going from 0 to end of data");
Enrico Granata9fc19442011-07-06 02:13:41 +0000945 *index_lower = 0;
946 }
947 else if (*separator_position == NULL || *separator_position > var_name_end)
948 {
949 char *end = NULL;
950 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
951 *index_higher = *index_lower;
Enrico Granatae992a082011-07-22 17:03:19 +0000952 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000953 log->Printf("[%lld] detected, high index is same", *index_lower);
Enrico Granata9fc19442011-07-06 02:13:41 +0000954 }
Greg Clayton34132752011-07-06 04:07:21 +0000955 else if (*close_bracket_position && *close_bracket_position < var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +0000956 {
957 char *end = NULL;
958 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
959 *index_higher = ::strtoul (*separator_position+1, &end, 0);
Enrico Granatae992a082011-07-22 17:03:19 +0000960 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000961 log->Printf("[%lld-%lld] detected", *index_lower, *index_higher);
Enrico Granata9fc19442011-07-06 02:13:41 +0000962 }
963 else
Enrico Granatae992a082011-07-22 17:03:19 +0000964 {
965 if (log)
966 log->Printf("expression is erroneous, cannot extract indices out of it");
Enrico Granata9fc19442011-07-06 02:13:41 +0000967 return false;
Enrico Granatae992a082011-07-22 17:03:19 +0000968 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000969 if (*index_lower > *index_higher && *index_higher > 0)
970 {
Enrico Granatae992a082011-07-22 17:03:19 +0000971 if (log)
972 log->Printf("swapping indices");
Enrico Granata9fc19442011-07-06 02:13:41 +0000973 int temp = *index_lower;
974 *index_lower = *index_higher;
975 *index_higher = temp;
976 }
977 }
Enrico Granatae992a082011-07-22 17:03:19 +0000978 else if (log)
979 log->Printf("no bracketed range, skipping entirely");
Enrico Granata9fc19442011-07-06 02:13:41 +0000980 return true;
981}
982
983
984static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +0000985ExpandExpressionPath (ValueObject* valobj,
986 StackFrame* frame,
987 bool* do_deref_pointer,
988 const char* var_name_begin,
989 const char* var_name_final,
990 Error& error)
Enrico Granata9fc19442011-07-06 02:13:41 +0000991{
Enrico Granatae992a082011-07-22 17:03:19 +0000992 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +0000993 StreamString sstring;
994 VariableSP var_sp;
995
Greg Clayton34132752011-07-06 04:07:21 +0000996 if (*do_deref_pointer)
Enrico Granatae992a082011-07-22 17:03:19 +0000997 {
998 if (log)
999 log->Printf("been told to deref_pointer by caller");
Enrico Granata9fc19442011-07-06 02:13:41 +00001000 sstring.PutChar('*');
Enrico Granatae992a082011-07-22 17:03:19 +00001001 }
Enrico Granatac482a192011-08-17 22:13:59 +00001002 else if (valobj->IsDereferenceOfParent() && ClangASTContext::IsPointerType(valobj->GetParent()->GetClangType()) && !valobj->IsArrayItemForPointer())
Enrico Granata9fc19442011-07-06 02:13:41 +00001003 {
Enrico Granatae992a082011-07-22 17:03:19 +00001004 if (log)
1005 log->Printf("decided to deref_pointer myself");
Enrico Granata9fc19442011-07-06 02:13:41 +00001006 sstring.PutChar('*');
1007 *do_deref_pointer = true;
1008 }
1009
Enrico Granata86cc9822012-03-19 22:58:49 +00001010 valobj->GetExpressionPath(sstring, true, ValueObject::eGetExpressionPathFormatHonorPointers);
Enrico Granatae992a082011-07-22 17:03:19 +00001011 if (log)
1012 log->Printf("expression path to expand in phase 0: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +00001013 sstring.PutRawBytes(var_name_begin+3, var_name_final-var_name_begin-3);
Enrico Granatae992a082011-07-22 17:03:19 +00001014 if (log)
1015 log->Printf("expression path to expand in phase 1: %s",sstring.GetData());
Enrico Granata9fc19442011-07-06 02:13:41 +00001016 std::string name = std::string(sstring.GetData());
1017 ValueObjectSP target = frame->GetValueForVariableExpressionPath (name.c_str(),
1018 eNoDynamicValues,
1019 0,
1020 var_sp,
1021 error);
1022 return target;
1023}
1024
1025static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +00001026ExpandIndexedExpression (ValueObject* valobj,
1027 uint32_t index,
1028 StackFrame* frame,
1029 bool deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +00001030{
Enrico Granatae992a082011-07-22 17:03:19 +00001031 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001032 const char* ptr_deref_format = "[%d]";
1033 std::auto_ptr<char> ptr_deref_buffer(new char[10]);
1034 ::sprintf(ptr_deref_buffer.get(), ptr_deref_format, index);
Enrico Granatae992a082011-07-22 17:03:19 +00001035 if (log)
1036 log->Printf("name to deref: %s",ptr_deref_buffer.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001037 const char* first_unparsed;
1038 ValueObject::GetValueForExpressionPathOptions options;
1039 ValueObject::ExpressionPathEndResultType final_value_type;
1040 ValueObject::ExpressionPathScanEndReason reason_to_stop;
Enrico Granata86cc9822012-03-19 22:58:49 +00001041 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
Enrico Granatac482a192011-08-17 22:13:59 +00001042 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001043 &first_unparsed,
1044 &reason_to_stop,
1045 &final_value_type,
1046 options,
1047 &what_next);
1048 if (!item)
1049 {
Enrico Granatae992a082011-07-22 17:03:19 +00001050 if (log)
1051 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1052 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001053 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001054 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001055 else
1056 {
Enrico Granatae992a082011-07-22 17:03:19 +00001057 if (log)
1058 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1059 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001060 first_unparsed, reason_to_stop, final_value_type);
Enrico Granata9fc19442011-07-06 02:13:41 +00001061 }
1062 return item;
1063}
1064
Greg Clayton1b654882010-09-19 02:33:57 +00001065bool
1066Debugger::FormatPrompt
1067(
1068 const char *format,
1069 const SymbolContext *sc,
1070 const ExecutionContext *exe_ctx,
1071 const Address *addr,
1072 Stream &s,
Enrico Granata4becb372011-06-29 22:27:15 +00001073 const char **end,
Enrico Granatac482a192011-08-17 22:13:59 +00001074 ValueObject* valobj
Greg Clayton1b654882010-09-19 02:33:57 +00001075)
1076{
Enrico Granatac482a192011-08-17 22:13:59 +00001077 ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers
Greg Clayton1b654882010-09-19 02:33:57 +00001078 bool success = true;
1079 const char *p;
Enrico Granatae992a082011-07-22 17:03:19 +00001080 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Greg Clayton1b654882010-09-19 02:33:57 +00001081 for (p = format; *p != '\0'; ++p)
1082 {
Enrico Granatac482a192011-08-17 22:13:59 +00001083 if (realvalobj)
Enrico Granata4becb372011-06-29 22:27:15 +00001084 {
Enrico Granatac482a192011-08-17 22:13:59 +00001085 valobj = realvalobj;
1086 realvalobj = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00001087 }
Greg Clayton1b654882010-09-19 02:33:57 +00001088 size_t non_special_chars = ::strcspn (p, "${}\\");
1089 if (non_special_chars > 0)
1090 {
1091 if (success)
1092 s.Write (p, non_special_chars);
1093 p += non_special_chars;
1094 }
1095
1096 if (*p == '\0')
1097 {
1098 break;
1099 }
1100 else if (*p == '{')
1101 {
1102 // Start a new scope that must have everything it needs if it is to
1103 // to make it into the final output stream "s". If you want to make
1104 // a format that only prints out the function or symbol name if there
1105 // is one in the symbol context you can use:
1106 // "{function =${function.name}}"
1107 // The first '{' starts a new scope that end with the matching '}' at
1108 // the end of the string. The contents "function =${function.name}"
1109 // will then be evaluated and only be output if there is a function
1110 // or symbol with a valid name.
1111 StreamString sub_strm;
1112
1113 ++p; // Skip the '{'
1114
Enrico Granatac482a192011-08-17 22:13:59 +00001115 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
Greg Clayton1b654882010-09-19 02:33:57 +00001116 {
1117 // The stream had all it needed
1118 s.Write(sub_strm.GetData(), sub_strm.GetSize());
1119 }
1120 if (*p != '}')
1121 {
1122 success = false;
1123 break;
1124 }
1125 }
1126 else if (*p == '}')
1127 {
1128 // End of a enclosing scope
1129 break;
1130 }
1131 else if (*p == '$')
1132 {
1133 // We have a prompt variable to print
1134 ++p;
1135 if (*p == '{')
1136 {
1137 ++p;
1138 const char *var_name_begin = p;
1139 const char *var_name_end = ::strchr (p, '}');
1140
1141 if (var_name_end && var_name_begin < var_name_end)
1142 {
1143 // if we have already failed to parse, skip this variable
1144 if (success)
1145 {
1146 const char *cstr = NULL;
1147 Address format_addr;
1148 bool calculate_format_addr_function_offset = false;
1149 // Set reg_kind and reg_num to invalid values
1150 RegisterKind reg_kind = kNumRegisterKinds;
1151 uint32_t reg_num = LLDB_INVALID_REGNUM;
1152 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +00001153 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00001154 RegisterContext *reg_ctx = NULL;
Enrico Granata9fc19442011-07-06 02:13:41 +00001155 bool do_deref_pointer = false;
Enrico Granata86cc9822012-03-19 22:58:49 +00001156 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
1157 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001158
Greg Clayton1b654882010-09-19 02:33:57 +00001159 // Each variable must set success to true below...
1160 bool var_success = false;
1161 switch (var_name_begin[0])
1162 {
Enrico Granata4becb372011-06-29 22:27:15 +00001163 case '*':
Enrico Granata4becb372011-06-29 22:27:15 +00001164 case 'v':
Enrico Granata6f3533f2011-07-29 19:53:35 +00001165 case 's':
Enrico Granata4becb372011-06-29 22:27:15 +00001166 {
Enrico Granatac482a192011-08-17 22:13:59 +00001167 if (!valobj)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001168 break;
1169
Enrico Granatac3e320a2011-08-02 17:27:39 +00001170 if (log)
1171 log->Printf("initial string: %s",var_name_begin);
1172
Enrico Granata6f3533f2011-07-29 19:53:35 +00001173 // check for *var and *svar
1174 if (*var_name_begin == '*')
1175 {
1176 do_deref_pointer = true;
1177 var_name_begin++;
1178 }
Enrico Granatac3e320a2011-08-02 17:27:39 +00001179
1180 if (log)
1181 log->Printf("initial string: %s",var_name_begin);
1182
Enrico Granata6f3533f2011-07-29 19:53:35 +00001183 if (*var_name_begin == 's')
1184 {
Enrico Granatac5bc4122012-03-27 02:35:13 +00001185 if (!valobj->IsSynthetic())
1186 valobj = valobj->GetSyntheticValue().get();
Enrico Granata86cc9822012-03-19 22:58:49 +00001187 if (!valobj)
1188 break;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001189 var_name_begin++;
1190 }
1191
Enrico Granatac3e320a2011-08-02 17:27:39 +00001192 if (log)
1193 log->Printf("initial string: %s",var_name_begin);
1194
Enrico Granata6f3533f2011-07-29 19:53:35 +00001195 // should be a 'v' by now
1196 if (*var_name_begin != 'v')
1197 break;
1198
Enrico Granatac3e320a2011-08-02 17:27:39 +00001199 if (log)
1200 log->Printf("initial string: %s",var_name_begin);
1201
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001202 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
Enrico Granata86cc9822012-03-19 22:58:49 +00001203 ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001204 ValueObject::GetValueForExpressionPathOptions options;
Enrico Granata8c9d3562011-08-11 17:08:01 +00001205 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001206 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary;
Greg Clayton34132752011-07-06 04:07:21 +00001207 ValueObject* target = NULL;
Greg Clayton4d122c42011-09-17 08:33:22 +00001208 Format custom_format = eFormatInvalid;
Greg Clayton34132752011-07-06 04:07:21 +00001209 const char* var_name_final = NULL;
1210 const char* var_name_final_if_array_range = NULL;
1211 const char* close_bracket_position = NULL;
1212 int64_t index_lower = -1;
1213 int64_t index_higher = -1;
1214 bool is_array_range = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001215 const char* first_unparsed;
Enrico Granata85933ed2011-08-18 16:38:26 +00001216 bool was_plain_var = false;
1217 bool was_var_format = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001218
Enrico Granatac482a192011-08-17 22:13:59 +00001219 if (!valobj) break;
1220 // simplest case ${var}, just print valobj's value
Greg Clayton34132752011-07-06 04:07:21 +00001221 if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0)
Enrico Granata4becb372011-06-29 22:27:15 +00001222 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001223 was_plain_var = true;
Enrico Granatac482a192011-08-17 22:13:59 +00001224 target = valobj;
Enrico Granata86cc9822012-03-19 22:58:49 +00001225 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Greg Clayton34132752011-07-06 04:07:21 +00001226 }
1227 else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0)
1228 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001229 was_var_format = true;
Greg Clayton34132752011-07-06 04:07:21 +00001230 // this is a variable with some custom format applied to it
1231 const char* percent_position;
Enrico Granatac482a192011-08-17 22:13:59 +00001232 target = valobj;
Enrico Granata86cc9822012-03-19 22:58:49 +00001233 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Greg Clayton34132752011-07-06 04:07:21 +00001234 ScanFormatDescriptor (var_name_begin,
1235 var_name_end,
1236 &var_name_final,
1237 &percent_position,
1238 &custom_format,
1239 &val_obj_display);
1240 }
1241 // this is ${var.something} or multiple .something nested
1242 else if (::strncmp (var_name_begin, "var", strlen("var")) == 0)
1243 {
1244
1245 const char* percent_position;
1246 ScanFormatDescriptor (var_name_begin,
1247 var_name_end,
1248 &var_name_final,
1249 &percent_position,
1250 &custom_format,
1251 &val_obj_display);
1252
1253 const char* open_bracket_position;
1254 const char* separator_position;
1255 ScanBracketedRange (var_name_begin,
1256 var_name_end,
1257 var_name_final,
1258 &open_bracket_position,
1259 &separator_position,
1260 &close_bracket_position,
1261 &var_name_final_if_array_range,
1262 &index_lower,
1263 &index_higher);
1264
1265 Error error;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001266
1267 std::auto_ptr<char> expr_path(new char[var_name_final-var_name_begin-1]);
1268 ::memset(expr_path.get(), 0, var_name_final-var_name_begin-1);
1269 memcpy(expr_path.get(), var_name_begin+3,var_name_final-var_name_begin-3);
1270
Enrico Granatae992a082011-07-22 17:03:19 +00001271 if (log)
1272 log->Printf("symbol to expand: %s",expr_path.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001273
Enrico Granatac482a192011-08-17 22:13:59 +00001274 target = valobj->GetValueForExpressionPath(expr_path.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001275 &first_unparsed,
1276 &reason_to_stop,
1277 &final_value_type,
1278 options,
1279 &what_next).get();
1280
1281 if (!target)
Enrico Granata9fc19442011-07-06 02:13:41 +00001282 {
Enrico Granatae992a082011-07-22 17:03:19 +00001283 if (log)
1284 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1285 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001286 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001287 break;
Enrico Granata9fc19442011-07-06 02:13:41 +00001288 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001289 else
1290 {
Enrico Granatae992a082011-07-22 17:03:19 +00001291 if (log)
1292 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1293 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001294 first_unparsed, reason_to_stop, final_value_type);
1295 }
Enrico Granata4becb372011-06-29 22:27:15 +00001296 }
Greg Clayton34132752011-07-06 04:07:21 +00001297 else
Enrico Granata9fc19442011-07-06 02:13:41 +00001298 break;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001299
Enrico Granata86cc9822012-03-19 22:58:49 +00001300 is_array_range = (final_value_type == ValueObject::eExpressionPathEndResultTypeBoundedRange ||
1301 final_value_type == ValueObject::eExpressionPathEndResultTypeUnboundedRange);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001302
Enrico Granata86cc9822012-03-19 22:58:49 +00001303 do_deref_pointer = (what_next == ValueObject::eExpressionPathAftermathDereference);
Enrico Granata9fc19442011-07-06 02:13:41 +00001304
Enrico Granataa7187d02011-07-06 19:27:11 +00001305 if (do_deref_pointer && !is_array_range)
Enrico Granata9fc19442011-07-06 02:13:41 +00001306 {
Greg Clayton34132752011-07-06 04:07:21 +00001307 // I have not deref-ed yet, let's do it
1308 // this happens when we are not going through GetValueForVariableExpressionPath
1309 // to get to the target ValueObject
Enrico Granata9fc19442011-07-06 02:13:41 +00001310 Error error;
Greg Clayton34132752011-07-06 04:07:21 +00001311 target = target->Dereference(error).get();
Enrico Granatadc940732011-08-23 00:32:52 +00001312 if (error.Fail())
1313 {
1314 if (log)
1315 log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
1316 break;
1317 }
Greg Clayton34132752011-07-06 04:07:21 +00001318 do_deref_pointer = false;
Enrico Granata9fc19442011-07-06 02:13:41 +00001319 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001320
Enrico Granata85933ed2011-08-18 16:38:26 +00001321 // TODO use flags for these
Enrico Granataf4efecd2011-07-12 22:56:10 +00001322 bool is_array = ClangASTContext::IsArrayType(target->GetClangType());
1323 bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType());
Enrico Granata85933ed2011-08-18 16:38:26 +00001324 bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType());
Enrico Granataf4efecd2011-07-12 22:56:10 +00001325
Enrico Granata86cc9822012-03-19 22:58:49 +00001326 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 +00001327 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001328 StreamString str_temp;
Enrico Granatae992a082011-07-22 17:03:19 +00001329 if (log)
1330 log->Printf("I am into array || pointer && !range");
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001331
Enrico Granata86cc9822012-03-19 22:58:49 +00001332 if (target->HasSpecialPrintableRepresentation(val_obj_display,
1333 custom_format))
Enrico Granata85933ed2011-08-18 16:38:26 +00001334 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001335 // try to use the special cases
1336 var_success = target->DumpPrintableRepresentation(str_temp,
1337 val_obj_display,
1338 custom_format);
1339 if (log)
1340 log->Printf("special cases did%s match", var_success ? "" : "n't");
1341
1342 // should not happen
1343 if (!var_success)
1344 s << "<invalid usage of pointer value as object>";
1345 else
1346 s << str_temp.GetData();
Enrico Granata85933ed2011-08-18 16:38:26 +00001347 var_success = true;
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001348 break;
Enrico Granata85933ed2011-08-18 16:38:26 +00001349 }
1350 else
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001351 {
Enrico Granata88da35f2011-08-23 21:26:09 +00001352 if (was_plain_var) // if ${var}
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001353 {
1354 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1355 }
Enrico Granata88da35f2011-08-23 21:26:09 +00001356 else if (is_pointer) // if pointer, value is the address stored
1357 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001358 var_success = target->DumpPrintableRepresentation(s,
Enrico Granata88da35f2011-08-23 21:26:09 +00001359 val_obj_display,
Enrico Granata86cc9822012-03-19 22:58:49 +00001360 custom_format,
1361 ValueObject::ePrintableRepresentationSpecialCasesDisable);
Enrico Granata88da35f2011-08-23 21:26:09 +00001362 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001363 else
1364 {
1365 s << "<invalid usage of pointer value as object>";
1366 }
1367 var_success = true;
1368 break;
1369 }
1370 }
1371
1372 // if directly trying to print ${var}, and this is an aggregate, display a nice
1373 // type @ location message
1374 if (is_aggregate && was_plain_var)
1375 {
1376 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1377 var_success = true;
Enrico Granata85933ed2011-08-18 16:38:26 +00001378 break;
1379 }
1380
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001381 // 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 +00001382 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)))
Enrico Granata85933ed2011-08-18 16:38:26 +00001383 {
1384 s << "<invalid use of aggregate type>";
1385 var_success = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001386 break;
1387 }
Greg Clayton34132752011-07-06 04:07:21 +00001388
1389 if (!is_array_range)
Enrico Granatae992a082011-07-22 17:03:19 +00001390 {
1391 if (log)
1392 log->Printf("dumping ordinary printable output");
Greg Clayton34132752011-07-06 04:07:21 +00001393 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
Enrico Granatae992a082011-07-22 17:03:19 +00001394 }
Greg Clayton34132752011-07-06 04:07:21 +00001395 else
Enrico Granatae992a082011-07-22 17:03:19 +00001396 {
1397 if (log)
1398 log->Printf("checking if I can handle as array");
Greg Clayton34132752011-07-06 04:07:21 +00001399 if (!is_array && !is_pointer)
1400 break;
Enrico Granatae992a082011-07-22 17:03:19 +00001401 if (log)
1402 log->Printf("handle as array");
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001403 const char* special_directions = NULL;
1404 StreamString special_directions_writer;
Greg Clayton34132752011-07-06 04:07:21 +00001405 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1406 {
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001407 ConstString additional_data;
1408 additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1);
1409 special_directions_writer.Printf("${%svar%s}",
1410 do_deref_pointer ? "*" : "",
1411 additional_data.GetCString());
1412 special_directions = special_directions_writer.GetData();
Greg Clayton34132752011-07-06 04:07:21 +00001413 }
1414
1415 // let us display items index_lower thru index_higher of this array
1416 s.PutChar('[');
1417 var_success = true;
1418
1419 if (index_higher < 0)
Enrico Granatac482a192011-08-17 22:13:59 +00001420 index_higher = valobj->GetNumChildren() - 1;
Greg Clayton34132752011-07-06 04:07:21 +00001421
Greg Claytoncc4d0142012-02-17 07:49:44 +00001422 uint32_t max_num_children = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00001423
Greg Clayton34132752011-07-06 04:07:21 +00001424 for (;index_lower<=index_higher;index_lower++)
1425 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001426 ValueObject* item = ExpandIndexedExpression (target,
1427 index_lower,
1428 exe_ctx->GetFramePtr(),
1429 false).get();
Greg Clayton34132752011-07-06 04:07:21 +00001430
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001431 if (!item)
1432 {
Enrico Granatae992a082011-07-22 17:03:19 +00001433 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001434 log->Printf("ERROR in getting child item at index %lld", index_lower);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001435 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001436 else
1437 {
Enrico Granatae992a082011-07-22 17:03:19 +00001438 if (log)
1439 log->Printf("special_directions for child item: %s",special_directions);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001440 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001441
Greg Clayton34132752011-07-06 04:07:21 +00001442 if (!special_directions)
1443 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1444 else
1445 var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
1446
Enrico Granata22c55d12011-08-12 02:00:06 +00001447 if (--max_num_children == 0)
1448 {
1449 s.PutCString(", ...");
1450 break;
1451 }
1452
Greg Clayton34132752011-07-06 04:07:21 +00001453 if (index_lower < index_higher)
1454 s.PutChar(',');
1455 }
1456 s.PutChar(']');
1457 }
Enrico Granata4becb372011-06-29 22:27:15 +00001458 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001459 break;
Greg Clayton1b654882010-09-19 02:33:57 +00001460 case 'a':
1461 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
1462 {
1463 if (addr && addr->IsValid())
1464 {
1465 var_success = true;
1466 format_addr = *addr;
1467 }
1468 }
Greg Clayton5a314712011-10-14 07:41:33 +00001469 else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0)
1470 {
1471 var_success = true;
1472 var_name_begin += strlen("ansi."); // Skip the "ansi."
1473 if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0)
1474 {
1475 var_name_begin += strlen("fg."); // Skip the "fg."
1476 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1477 {
1478 s.Printf ("%s%s%s",
1479 lldb_utility::ansi::k_escape_start,
1480 lldb_utility::ansi::k_fg_black,
1481 lldb_utility::ansi::k_escape_end);
1482 }
1483 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1484 {
1485 s.Printf ("%s%s%s",
1486 lldb_utility::ansi::k_escape_start,
1487 lldb_utility::ansi::k_fg_red,
1488 lldb_utility::ansi::k_escape_end);
1489 }
1490 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1491 {
1492 s.Printf ("%s%s%s",
1493 lldb_utility::ansi::k_escape_start,
1494 lldb_utility::ansi::k_fg_green,
1495 lldb_utility::ansi::k_escape_end);
1496 }
1497 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1498 {
1499 s.Printf ("%s%s%s",
1500 lldb_utility::ansi::k_escape_start,
1501 lldb_utility::ansi::k_fg_yellow,
1502 lldb_utility::ansi::k_escape_end);
1503 }
1504 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1505 {
1506 s.Printf ("%s%s%s",
1507 lldb_utility::ansi::k_escape_start,
1508 lldb_utility::ansi::k_fg_blue,
1509 lldb_utility::ansi::k_escape_end);
1510 }
1511 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1512 {
1513 s.Printf ("%s%s%s",
1514 lldb_utility::ansi::k_escape_start,
1515 lldb_utility::ansi::k_fg_purple,
1516 lldb_utility::ansi::k_escape_end);
1517 }
1518 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1519 {
1520 s.Printf ("%s%s%s",
1521 lldb_utility::ansi::k_escape_start,
1522 lldb_utility::ansi::k_fg_cyan,
1523 lldb_utility::ansi::k_escape_end);
1524 }
1525 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1526 {
1527 s.Printf ("%s%s%s",
1528 lldb_utility::ansi::k_escape_start,
1529 lldb_utility::ansi::k_fg_white,
1530 lldb_utility::ansi::k_escape_end);
1531 }
1532 else
1533 {
1534 var_success = false;
1535 }
1536 }
1537 else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0)
1538 {
1539 var_name_begin += strlen("bg."); // Skip the "bg."
1540 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1541 {
1542 s.Printf ("%s%s%s",
1543 lldb_utility::ansi::k_escape_start,
1544 lldb_utility::ansi::k_bg_black,
1545 lldb_utility::ansi::k_escape_end);
1546 }
1547 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1548 {
1549 s.Printf ("%s%s%s",
1550 lldb_utility::ansi::k_escape_start,
1551 lldb_utility::ansi::k_bg_red,
1552 lldb_utility::ansi::k_escape_end);
1553 }
1554 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1555 {
1556 s.Printf ("%s%s%s",
1557 lldb_utility::ansi::k_escape_start,
1558 lldb_utility::ansi::k_bg_green,
1559 lldb_utility::ansi::k_escape_end);
1560 }
1561 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1562 {
1563 s.Printf ("%s%s%s",
1564 lldb_utility::ansi::k_escape_start,
1565 lldb_utility::ansi::k_bg_yellow,
1566 lldb_utility::ansi::k_escape_end);
1567 }
1568 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1569 {
1570 s.Printf ("%s%s%s",
1571 lldb_utility::ansi::k_escape_start,
1572 lldb_utility::ansi::k_bg_blue,
1573 lldb_utility::ansi::k_escape_end);
1574 }
1575 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1576 {
1577 s.Printf ("%s%s%s",
1578 lldb_utility::ansi::k_escape_start,
1579 lldb_utility::ansi::k_bg_purple,
1580 lldb_utility::ansi::k_escape_end);
1581 }
1582 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1583 {
1584 s.Printf ("%s%s%s",
1585 lldb_utility::ansi::k_escape_start,
1586 lldb_utility::ansi::k_bg_cyan,
1587 lldb_utility::ansi::k_escape_end);
1588 }
1589 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1590 {
1591 s.Printf ("%s%s%s",
1592 lldb_utility::ansi::k_escape_start,
1593 lldb_utility::ansi::k_bg_white,
1594 lldb_utility::ansi::k_escape_end);
1595 }
1596 else
1597 {
1598 var_success = false;
1599 }
1600 }
1601 else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0)
1602 {
1603 s.Printf ("%s%s%s",
1604 lldb_utility::ansi::k_escape_start,
1605 lldb_utility::ansi::k_ctrl_normal,
1606 lldb_utility::ansi::k_escape_end);
1607 }
1608 else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0)
1609 {
1610 s.Printf ("%s%s%s",
1611 lldb_utility::ansi::k_escape_start,
1612 lldb_utility::ansi::k_ctrl_bold,
1613 lldb_utility::ansi::k_escape_end);
1614 }
1615 else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0)
1616 {
1617 s.Printf ("%s%s%s",
1618 lldb_utility::ansi::k_escape_start,
1619 lldb_utility::ansi::k_ctrl_faint,
1620 lldb_utility::ansi::k_escape_end);
1621 }
1622 else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0)
1623 {
1624 s.Printf ("%s%s%s",
1625 lldb_utility::ansi::k_escape_start,
1626 lldb_utility::ansi::k_ctrl_italic,
1627 lldb_utility::ansi::k_escape_end);
1628 }
1629 else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0)
1630 {
1631 s.Printf ("%s%s%s",
1632 lldb_utility::ansi::k_escape_start,
1633 lldb_utility::ansi::k_ctrl_underline,
1634 lldb_utility::ansi::k_escape_end);
1635 }
1636 else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0)
1637 {
1638 s.Printf ("%s%s%s",
1639 lldb_utility::ansi::k_escape_start,
1640 lldb_utility::ansi::k_ctrl_slow_blink,
1641 lldb_utility::ansi::k_escape_end);
1642 }
1643 else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0)
1644 {
1645 s.Printf ("%s%s%s",
1646 lldb_utility::ansi::k_escape_start,
1647 lldb_utility::ansi::k_ctrl_fast_blink,
1648 lldb_utility::ansi::k_escape_end);
1649 }
1650 else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0)
1651 {
1652 s.Printf ("%s%s%s",
1653 lldb_utility::ansi::k_escape_start,
1654 lldb_utility::ansi::k_ctrl_negative,
1655 lldb_utility::ansi::k_escape_end);
1656 }
1657 else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0)
1658 {
1659 s.Printf ("%s%s%s",
1660 lldb_utility::ansi::k_escape_start,
1661 lldb_utility::ansi::k_ctrl_conceal,
1662 lldb_utility::ansi::k_escape_end);
1663
1664 }
1665 else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0)
1666 {
1667 s.Printf ("%s%s%s",
1668 lldb_utility::ansi::k_escape_start,
1669 lldb_utility::ansi::k_ctrl_crossed_out,
1670 lldb_utility::ansi::k_escape_end);
1671 }
1672 else
1673 {
1674 var_success = false;
1675 }
1676 }
Greg Clayton1b654882010-09-19 02:33:57 +00001677 break;
1678
1679 case 'p':
1680 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
1681 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001682 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001683 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001684 Process *process = exe_ctx->GetProcessPtr();
1685 if (process)
Greg Clayton1b654882010-09-19 02:33:57 +00001686 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001687 var_name_begin += ::strlen ("process.");
1688 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001689 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001690 s.Printf("%llu", process->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001691 var_success = true;
1692 }
1693 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
1694 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
1695 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
1696 {
1697 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1698 if (exe_module)
Greg Clayton1b654882010-09-19 02:33:57 +00001699 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001700 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1701 {
1702 format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
1703 var_success = format_file_spec;
1704 }
1705 else
1706 {
1707 format_file_spec = exe_module->GetFileSpec();
1708 var_success = format_file_spec;
1709 }
Greg Clayton1b654882010-09-19 02:33:57 +00001710 }
1711 }
1712 }
Greg Claytonc14ee322011-09-22 04:58:26 +00001713 }
Greg Clayton1b654882010-09-19 02:33:57 +00001714 }
1715 break;
1716
1717 case 't':
1718 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
1719 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001720 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001721 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001722 Thread *thread = exe_ctx->GetThreadPtr();
1723 if (thread)
Greg Clayton1b654882010-09-19 02:33:57 +00001724 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001725 var_name_begin += ::strlen ("thread.");
1726 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001727 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001728 s.Printf("0x%4.4llx", thread->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001729 var_success = true;
1730 }
1731 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1732 {
1733 s.Printf("%u", thread->GetIndexID());
1734 var_success = true;
1735 }
1736 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1737 {
1738 cstr = thread->GetName();
1739 var_success = cstr && cstr[0];
1740 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001741 s.PutCString(cstr);
Greg Claytonc14ee322011-09-22 04:58:26 +00001742 }
1743 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
1744 {
1745 cstr = thread->GetQueueName();
1746 var_success = cstr && cstr[0];
1747 if (var_success)
1748 s.PutCString(cstr);
1749 }
1750 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
1751 {
1752 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1753 if (stop_info_sp)
1754 {
1755 cstr = stop_info_sp->GetDescription();
1756 if (cstr && cstr[0])
1757 {
1758 s.PutCString(cstr);
1759 var_success = true;
1760 }
Greg Clayton1b654882010-09-19 02:33:57 +00001761 }
1762 }
Jim Ingham73ca05a2011-12-17 01:35:57 +00001763 else if (::strncmp (var_name_begin, "return-value}", strlen("return-value}")) == 0)
1764 {
1765 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1766 if (stop_info_sp)
1767 {
1768 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1769 if (return_valobj_sp)
1770 {
Jim Inghamef651602011-12-22 19:12:40 +00001771 ValueObject::DumpValueObjectOptions dump_options;
1772 ValueObject::DumpValueObject (s, return_valobj_sp.get(), dump_options);
1773 var_success = true;
Jim Ingham73ca05a2011-12-17 01:35:57 +00001774 }
1775 }
1776 }
Greg Clayton1b654882010-09-19 02:33:57 +00001777 }
1778 }
1779 }
1780 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
1781 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001782 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1783 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +00001784 {
Greg Clayton1b654882010-09-19 02:33:57 +00001785 var_name_begin += ::strlen ("target.");
1786 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
1787 {
1788 ArchSpec arch (target->GetArchitecture ());
1789 if (arch.IsValid())
1790 {
Greg Clayton64195a22011-02-23 00:35:02 +00001791 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +00001792 var_success = true;
1793 }
1794 }
1795 }
1796 }
1797 break;
1798
1799
1800 case 'm':
1801 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
1802 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001803 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +00001804 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001805 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +00001806 var_name_begin += ::strlen ("module.");
1807
1808 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1809 {
1810 if (module->GetFileSpec())
1811 {
1812 var_name_begin += ::strlen ("file.");
1813
1814 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1815 {
1816 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
1817 var_success = format_file_spec;
1818 }
1819 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1820 {
1821 format_file_spec = module->GetFileSpec();
1822 var_success = format_file_spec;
1823 }
1824 }
1825 }
1826 }
1827 }
1828 break;
1829
1830
1831 case 'f':
1832 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1833 {
1834 if (sc && sc->comp_unit != NULL)
1835 {
1836 var_name_begin += ::strlen ("file.");
1837
1838 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1839 {
1840 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
1841 var_success = format_file_spec;
1842 }
1843 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1844 {
1845 format_file_spec = *sc->comp_unit;
1846 var_success = format_file_spec;
1847 }
1848 }
1849 }
1850 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
1851 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001852 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001853 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001854 StackFrame *frame = exe_ctx->GetFramePtr();
1855 if (frame)
Greg Clayton1b654882010-09-19 02:33:57 +00001856 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001857 var_name_begin += ::strlen ("frame.");
1858 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001859 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001860 s.Printf("%u", frame->GetFrameIndex());
1861 var_success = true;
1862 }
1863 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
1864 {
1865 reg_kind = eRegisterKindGeneric;
1866 reg_num = LLDB_REGNUM_GENERIC_PC;
1867 var_success = true;
1868 }
1869 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
1870 {
1871 reg_kind = eRegisterKindGeneric;
1872 reg_num = LLDB_REGNUM_GENERIC_SP;
1873 var_success = true;
1874 }
1875 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
1876 {
1877 reg_kind = eRegisterKindGeneric;
1878 reg_num = LLDB_REGNUM_GENERIC_FP;
1879 var_success = true;
1880 }
1881 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
1882 {
1883 reg_kind = eRegisterKindGeneric;
1884 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
1885 var_success = true;
1886 }
1887 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
1888 {
1889 reg_ctx = frame->GetRegisterContext().get();
1890 if (reg_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001891 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001892 var_name_begin += ::strlen ("reg.");
1893 if (var_name_begin < var_name_end)
1894 {
1895 std::string reg_name (var_name_begin, var_name_end);
1896 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
1897 if (reg_info)
1898 var_success = true;
1899 }
Greg Clayton1b654882010-09-19 02:33:57 +00001900 }
1901 }
1902 }
1903 }
1904 }
1905 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
1906 {
1907 if (sc && (sc->function != NULL || sc->symbol != NULL))
1908 {
1909 var_name_begin += ::strlen ("function.");
1910 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1911 {
1912 if (sc->function)
Greg Clayton81c22f62011-10-19 18:09:39 +00001913 s.Printf("function{0x%8.8llx}", sc->function->GetID());
Greg Clayton1b654882010-09-19 02:33:57 +00001914 else
1915 s.Printf("symbol[%u]", sc->symbol->GetID());
1916
1917 var_success = true;
1918 }
1919 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1920 {
1921 if (sc->function)
1922 cstr = sc->function->GetName().AsCString (NULL);
1923 else if (sc->symbol)
1924 cstr = sc->symbol->GetName().AsCString (NULL);
1925 if (cstr)
1926 {
1927 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001928
1929 if (sc->block)
1930 {
1931 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1932 if (inline_block)
1933 {
1934 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1935 if (inline_info)
1936 {
1937 s.PutCString(" [inlined] ");
1938 inline_info->GetName().Dump(&s);
1939 }
1940 }
1941 }
Greg Clayton1b654882010-09-19 02:33:57 +00001942 var_success = true;
1943 }
1944 }
Greg Clayton6d3dbf52012-01-13 08:39:16 +00001945 else if (::strncmp (var_name_begin, "name-with-args}", strlen("name-with-args}")) == 0)
1946 {
1947 // Print the function name with arguments in it
1948
1949 if (sc->function)
1950 {
1951 var_success = true;
1952 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
1953 cstr = sc->function->GetName().AsCString (NULL);
1954 if (cstr)
1955 {
1956 const InlineFunctionInfo *inline_info = NULL;
1957 VariableListSP variable_list_sp;
1958 bool get_function_vars = true;
1959 if (sc->block)
1960 {
1961 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1962
1963 if (inline_block)
1964 {
1965 get_function_vars = false;
1966 inline_info = sc->block->GetInlinedFunctionInfo();
1967 if (inline_info)
1968 variable_list_sp = inline_block->GetBlockVariableList (true);
1969 }
1970 }
1971
1972 if (get_function_vars)
1973 {
1974 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
1975 }
1976
1977 if (inline_info)
1978 {
1979 s.PutCString (cstr);
1980 s.PutCString (" [inlined] ");
1981 cstr = inline_info->GetName().GetCString();
1982 }
1983
1984 VariableList args;
1985 if (variable_list_sp)
1986 {
1987 const size_t num_variables = variable_list_sp->GetSize();
1988 for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
1989 {
1990 VariableSP var_sp (variable_list_sp->GetVariableAtIndex(var_idx));
1991 if (var_sp->GetScope() == eValueTypeVariableArgument)
1992 args.AddVariable (var_sp);
1993 }
1994
1995 }
1996 if (args.GetSize() > 0)
1997 {
1998 const char *open_paren = strchr (cstr, '(');
1999 const char *close_paren = NULL;
2000 if (open_paren)
2001 close_paren = strchr (open_paren, ')');
2002
2003 if (open_paren)
2004 s.Write(cstr, open_paren - cstr + 1);
2005 else
2006 {
2007 s.PutCString (cstr);
2008 s.PutChar ('(');
2009 }
Greg Clayton5b6889b2012-01-18 21:56:18 +00002010 const size_t num_args = args.GetSize();
Greg Clayton6d3dbf52012-01-13 08:39:16 +00002011 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
2012 {
2013 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
2014 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
2015 const char *var_name = var_value_sp->GetName().GetCString();
2016 const char *var_value = var_value_sp->GetValueAsCString();
2017 if (var_value_sp->GetError().Success())
2018 {
2019 if (arg_idx > 0)
2020 s.PutCString (", ");
2021 s.Printf ("%s=%s", var_name, var_value);
2022 }
2023 }
2024
2025 if (close_paren)
2026 s.PutCString (close_paren);
2027 else
2028 s.PutChar(')');
2029
2030 }
2031 else
2032 {
2033 s.PutCString(cstr);
2034 }
2035 }
2036 }
2037 else if (sc->symbol)
2038 {
2039 cstr = sc->symbol->GetName().AsCString (NULL);
2040 if (cstr)
2041 {
2042 s.PutCString(cstr);
2043 var_success = true;
2044 }
2045 }
2046 }
Greg Clayton1b654882010-09-19 02:33:57 +00002047 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
2048 {
2049 var_success = addr != NULL;
2050 if (var_success)
2051 {
2052 format_addr = *addr;
2053 calculate_format_addr_function_offset = true;
2054 }
2055 }
2056 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
2057 {
2058 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
2059 if (var_success)
2060 {
2061 format_addr = sc->line_entry.range.GetBaseAddress();
2062 calculate_format_addr_function_offset = true;
2063 }
2064 }
2065 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
2066 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002067 StackFrame *frame = exe_ctx->GetFramePtr();
2068 var_success = frame != NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00002069 if (var_success)
2070 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002071 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002072 calculate_format_addr_function_offset = true;
2073 }
2074 }
2075 }
2076 }
2077 break;
2078
2079 case 'l':
2080 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
2081 {
2082 if (sc && sc->line_entry.IsValid())
2083 {
2084 var_name_begin += ::strlen ("line.");
2085 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
2086 {
2087 var_name_begin += ::strlen ("file.");
2088
2089 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
2090 {
2091 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
2092 var_success = format_file_spec;
2093 }
2094 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
2095 {
2096 format_file_spec = sc->line_entry.file;
2097 var_success = format_file_spec;
2098 }
2099 }
2100 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
2101 {
2102 var_success = true;
2103 s.Printf("%u", sc->line_entry.line);
2104 }
2105 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
2106 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
2107 {
2108 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
2109 if (var_success)
2110 {
2111 format_addr = sc->line_entry.range.GetBaseAddress();
2112 if (var_name_begin[0] == 'e')
2113 format_addr.Slide (sc->line_entry.range.GetByteSize());
2114 }
2115 }
2116 }
2117 }
2118 break;
2119 }
2120
2121 if (var_success)
2122 {
2123 // If format addr is valid, then we need to print an address
2124 if (reg_num != LLDB_INVALID_REGNUM)
2125 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002126 StackFrame *frame = exe_ctx->GetFramePtr();
Greg Clayton1b654882010-09-19 02:33:57 +00002127 // We have a register value to display...
2128 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
2129 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002130 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002131 }
2132 else
2133 {
2134 if (reg_ctx == NULL)
Greg Claytonc14ee322011-09-22 04:58:26 +00002135 reg_ctx = frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00002136
2137 if (reg_ctx)
2138 {
2139 if (reg_kind != kNumRegisterKinds)
2140 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
2141 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
2142 var_success = reg_info != NULL;
2143 }
2144 }
2145 }
2146
2147 if (reg_info != NULL)
2148 {
Greg Clayton7349bd92011-05-09 20:18:18 +00002149 RegisterValue reg_value;
2150 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
2151 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00002152 {
Greg Clayton9a8fa912011-05-15 04:12:07 +00002153 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
Greg Clayton1b654882010-09-19 02:33:57 +00002154 }
2155 }
2156
2157 if (format_file_spec)
2158 {
2159 s << format_file_spec;
2160 }
2161
2162 // If format addr is valid, then we need to print an address
2163 if (format_addr.IsValid())
2164 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002165 var_success = false;
2166
Greg Clayton1b654882010-09-19 02:33:57 +00002167 if (calculate_format_addr_function_offset)
2168 {
2169 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00002170
Greg Clayton0603aa92010-10-04 01:05:56 +00002171 if (sc)
2172 {
2173 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00002174 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002175 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00002176 if (sc->block)
2177 {
2178 // Check to make sure we aren't in an inline
2179 // function. If we are, use the inline block
2180 // range that contains "format_addr" since
2181 // blocks can be discontiguous.
2182 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2183 AddressRange inline_range;
2184 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
2185 func_addr = inline_range.GetBaseAddress();
2186 }
2187 }
Greg Claytone7612132012-03-07 21:03:09 +00002188 else if (sc->symbol && sc->symbol->ValueIsAddress())
2189 func_addr = sc->symbol->GetAddress();
Greg Clayton0603aa92010-10-04 01:05:56 +00002190 }
2191
2192 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00002193 {
2194 if (func_addr.GetSection() == format_addr.GetSection())
2195 {
2196 addr_t func_file_addr = func_addr.GetFileAddress();
2197 addr_t addr_file_addr = format_addr.GetFileAddress();
2198 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002199 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00002200 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002201 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002202 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00002203 }
2204 else
Greg Clayton0603aa92010-10-04 01:05:56 +00002205 {
2206 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2207 if (target)
2208 {
2209 addr_t func_load_addr = func_addr.GetLoadAddress (target);
2210 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
2211 if (addr_load_addr > func_load_addr)
2212 s.Printf(" + %llu", addr_load_addr - func_load_addr);
2213 else if (addr_load_addr < func_load_addr)
2214 s.Printf(" - %llu", func_load_addr - addr_load_addr);
2215 var_success = true;
2216 }
2217 }
Greg Clayton1b654882010-09-19 02:33:57 +00002218 }
2219 }
2220 else
2221 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002222 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00002223 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00002224 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
2225 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00002226 if (vaddr == LLDB_INVALID_ADDRESS)
2227 vaddr = format_addr.GetFileAddress ();
2228
2229 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00002230 {
Greg Clayton514487e2011-02-15 21:59:32 +00002231 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00002232 if (addr_width == 0)
2233 addr_width = 16;
2234 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002235 var_success = true;
2236 }
Greg Clayton1b654882010-09-19 02:33:57 +00002237 }
2238 }
2239 }
2240
2241 if (var_success == false)
2242 success = false;
2243 }
2244 p = var_name_end;
2245 }
2246 else
2247 break;
2248 }
2249 else
2250 {
2251 // We got a dollar sign with no '{' after it, it must just be a dollar sign
2252 s.PutChar(*p);
2253 }
2254 }
2255 else if (*p == '\\')
2256 {
2257 ++p; // skip the slash
2258 switch (*p)
2259 {
2260 case 'a': s.PutChar ('\a'); break;
2261 case 'b': s.PutChar ('\b'); break;
2262 case 'f': s.PutChar ('\f'); break;
2263 case 'n': s.PutChar ('\n'); break;
2264 case 'r': s.PutChar ('\r'); break;
2265 case 't': s.PutChar ('\t'); break;
2266 case 'v': s.PutChar ('\v'); break;
2267 case '\'': s.PutChar ('\''); break;
2268 case '\\': s.PutChar ('\\'); break;
2269 case '0':
2270 // 1 to 3 octal chars
2271 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002272 // Make a string that can hold onto the initial zero char,
2273 // up to 3 octal digits, and a terminating NULL.
2274 char oct_str[5] = { 0, 0, 0, 0, 0 };
2275
2276 int i;
2277 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
2278 oct_str[i] = p[i];
2279
2280 // We don't want to consume the last octal character since
2281 // the main for loop will do this for us, so we advance p by
2282 // one less than i (even if i is zero)
2283 p += i - 1;
2284 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2285 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002286 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002287 char octal_char = octal_value;
2288 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00002289 }
Greg Clayton1b654882010-09-19 02:33:57 +00002290 }
2291 break;
2292
2293 case 'x':
2294 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00002295 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002296 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002297 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00002298
Greg Clayton0603aa92010-10-04 01:05:56 +00002299 // Make a string that can hold onto two hex chars plus a
2300 // NULL terminator
2301 char hex_str[3] = { 0,0,0 };
2302 hex_str[0] = *p;
2303 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002304 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002305 ++p; // Skip the first of the two hex chars
2306 hex_str[1] = *p;
2307 }
2308
2309 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2310 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002311 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00002312 }
2313 else
2314 {
2315 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00002316 }
2317 break;
2318
2319 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00002320 // Just desensitize any other character by just printing what
2321 // came after the '\'
2322 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00002323 break;
2324
2325 }
2326
2327 }
2328 }
2329 if (end)
2330 *end = p;
2331 return success;
2332}
2333
Jim Ingham228063c2012-02-21 02:23:08 +00002334void
2335Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
2336{
Jim Ingham4f02b222012-02-22 22:49:20 +00002337 // For simplicity's sake, I am not going to deal with how to close down any
2338 // open logging streams, I just redirect everything from here on out to the
2339 // callback.
Jim Ingham228063c2012-02-21 02:23:08 +00002340 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
2341}
2342
2343bool
2344Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
2345{
2346 Log::Callbacks log_callbacks;
2347
2348 StreamSP log_stream_sp;
2349 if (m_log_callback_stream_sp != NULL)
2350 {
2351 log_stream_sp = m_log_callback_stream_sp;
2352 // For now when using the callback mode you always get thread & timestamp.
2353 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
2354 }
2355 else if (log_file == NULL || *log_file == '\0')
2356 {
2357 log_stream_sp.reset(new StreamFile(GetOutputFile().GetDescriptor(), false));
2358 }
2359 else
2360 {
2361 LogStreamMap::iterator pos = m_log_streams.find(log_file);
2362 if (pos == m_log_streams.end())
2363 {
2364 log_stream_sp.reset (new StreamFile (log_file));
2365 m_log_streams[log_file] = log_stream_sp;
2366 }
2367 else
2368 log_stream_sp = pos->second;
2369 }
2370 assert (log_stream_sp.get());
2371
2372 if (log_options == 0)
2373 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
2374
2375 if (Log::GetLogChannelCallbacks (channel, log_callbacks))
2376 {
2377 log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream);
2378 return true;
2379 }
2380 else
2381 {
2382 LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel));
2383 if (log_channel_sp)
2384 {
2385 if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories))
2386 {
2387 return true;
2388 }
2389 else
2390 {
2391 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
2392 return false;
2393 }
2394 }
2395 else
2396 {
2397 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
2398 return false;
2399 }
2400 }
2401 return false;
2402}
2403
Greg Clayton1b654882010-09-19 02:33:57 +00002404#pragma mark Debugger::SettingsController
2405
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002406//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002407// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002408//--------------------------------------------------
2409
Greg Clayton1b654882010-09-19 02:33:57 +00002410Debugger::SettingsController::SettingsController () :
Greg Clayton4d122c42011-09-17 08:33:22 +00002411 UserSettingsController ("", UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002412{
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002413}
2414
Greg Clayton1b654882010-09-19 02:33:57 +00002415Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002416{
2417}
2418
2419
Greg Clayton4d122c42011-09-17 08:33:22 +00002420InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00002421Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002422{
Greg Claytonb9556ac2012-01-30 07:41:31 +00002423 InstanceSettingsSP new_settings_sp (new DebuggerInstanceSettings (GetSettingsController(),
2424 false,
2425 instance_name));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002426 return new_settings_sp;
2427}
2428
Greg Clayton1b654882010-09-19 02:33:57 +00002429#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002430//--------------------------------------------------
2431// class DebuggerInstanceSettings
2432//--------------------------------------------------
2433
Greg Claytona7015092010-09-18 01:14:36 +00002434DebuggerInstanceSettings::DebuggerInstanceSettings
2435(
Greg Claytonb9556ac2012-01-30 07:41:31 +00002436 const UserSettingsControllerSP &m_owner_sp,
Greg Claytona7015092010-09-18 01:14:36 +00002437 bool live_instance,
2438 const char *name
2439) :
Greg Claytonb9556ac2012-01-30 07:41:31 +00002440 InstanceSettings (m_owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00002441 m_term_width (80),
Greg Claytone372b982011-11-21 21:44:34 +00002442 m_stop_source_before_count (3),
2443 m_stop_source_after_count (3),
2444 m_stop_disassembly_count (4),
2445 m_stop_disassembly_display (eStopDisassemblyTypeNoSource),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002446 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00002447 m_frame_format (),
2448 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002449 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002450 m_use_external_editor (false),
2451 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002452{
Caroline Ticef20e8232010-09-09 18:26:37 +00002453 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2454 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
2455 // 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 +00002456 // The same is true of CreateInstanceName().
2457
2458 if (GetInstanceName() == InstanceSettings::InvalidName())
2459 {
2460 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Claytonb9556ac2012-01-30 07:41:31 +00002461 m_owner_sp->RegisterInstanceSettings (this);
Caroline Tice9e41c152010-09-16 19:05:55 +00002462 }
Caroline Ticef20e8232010-09-09 18:26:37 +00002463
2464 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002465 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00002466 const InstanceSettingsSP &pending_settings = m_owner_sp->FindPendingSettings (m_instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002467 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002468 }
2469}
2470
2471DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Claytonb9556ac2012-01-30 07:41:31 +00002472 InstanceSettings (Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002473 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00002474 m_frame_format (rhs.m_frame_format),
2475 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00002476 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00002477 m_use_external_editor (rhs.m_use_external_editor),
2478 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002479{
Greg Claytonb9556ac2012-01-30 07:41:31 +00002480 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2481 if (owner_sp)
2482 {
2483 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
2484 owner_sp->RemovePendingSettings (m_instance_name);
2485 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002486}
2487
2488DebuggerInstanceSettings::~DebuggerInstanceSettings ()
2489{
2490}
2491
2492DebuggerInstanceSettings&
2493DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
2494{
2495 if (this != &rhs)
2496 {
Greg Clayton1b654882010-09-19 02:33:57 +00002497 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002498 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00002499 m_frame_format = rhs.m_frame_format;
2500 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002501 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002502 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002503 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002504 }
2505
2506 return *this;
2507}
2508
Greg Clayton1b654882010-09-19 02:33:57 +00002509bool
2510DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
2511{
2512 bool valid = false;
2513
2514 // Verify we have a value string.
2515 if (value == NULL || value[0] == '\0')
2516 {
Greg Clayton86edbf42011-10-26 00:56:27 +00002517 err.SetErrorString ("missing value, can't set terminal width without a value");
Greg Clayton1b654882010-09-19 02:33:57 +00002518 }
2519 else
2520 {
2521 char *end = NULL;
2522 const uint32_t width = ::strtoul (value, &end, 0);
2523
Johnny Chenea9fc182010-09-20 16:36:43 +00002524 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00002525 {
Johnny Chen433d7742010-09-20 17:04:41 +00002526 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00002527 valid = true;
2528 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002529 err.SetErrorString ("invalid term-width value; value must be between 10 and 1024");
Greg Clayton1b654882010-09-19 02:33:57 +00002530 }
2531 else
Greg Clayton86edbf42011-10-26 00:56:27 +00002532 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value);
Greg Clayton1b654882010-09-19 02:33:57 +00002533 }
2534
2535 return valid;
2536}
2537
2538
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002539void
2540DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2541 const char *index_value,
2542 const char *value,
2543 const ConstString &instance_name,
2544 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00002545 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002546 Error &err,
2547 bool pending)
2548{
Greg Clayton0603aa92010-10-04 01:05:56 +00002549
2550 if (var_name == TermWidthVarName())
2551 {
2552 if (ValidTermWidthValue (value, err))
2553 {
2554 m_term_width = ::strtoul (value, NULL, 0);
2555 }
2556 }
2557 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002558 {
Caroline Tice101c7c22010-09-09 06:25:08 +00002559 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002560 if (!pending)
2561 {
Caroline Tice49e27372010-09-07 18:35:40 +00002562 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2563 // strip off the brackets before passing it to BroadcastPromptChange.
2564
2565 std::string tmp_instance_name (instance_name.AsCString());
2566 if ((tmp_instance_name[0] == '[')
2567 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
2568 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
2569 ConstString new_name (tmp_instance_name.c_str());
2570
2571 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002572 }
2573 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002574 else if (var_name == GetFrameFormatName())
2575 {
2576 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
2577 }
2578 else if (var_name == GetThreadFormatName())
2579 {
2580 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
2581 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002582 else if (var_name == ScriptLangVarName())
2583 {
2584 bool success;
2585 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
2586 &success);
2587 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002588 else if (var_name == UseExternalEditorVarName ())
2589 {
Greg Clayton385aa282011-04-22 03:55:06 +00002590 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00002591 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002592 else if (var_name == AutoConfirmName ())
2593 {
Greg Clayton385aa282011-04-22 03:55:06 +00002594 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00002595 }
Greg Claytone372b982011-11-21 21:44:34 +00002596 else if (var_name == StopSourceContextBeforeName ())
2597 {
2598 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2599 if (new_value != UINT32_MAX)
2600 m_stop_source_before_count = new_value;
2601 else
2602 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextAfterName ().GetCString());
2603 }
2604 else if (var_name == StopSourceContextAfterName ())
2605 {
2606 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2607 if (new_value != UINT32_MAX)
2608 m_stop_source_after_count = new_value;
2609 else
2610 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextBeforeName ().GetCString());
2611 }
2612 else if (var_name == StopDisassemblyCountName ())
2613 {
2614 uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2615 if (new_value != UINT32_MAX)
2616 m_stop_disassembly_count = new_value;
2617 else
2618 err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopDisassemblyCountName ().GetCString());
2619 }
2620 else if (var_name == StopDisassemblyDisplayName ())
2621 {
2622 int new_value;
2623 UserSettingsController::UpdateEnumVariable (g_show_disassembly_enum_values, &new_value, value, err);
2624 if (err.Success())
2625 m_stop_disassembly_display = (StopDisassemblyType)new_value;
2626 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002627}
2628
Caroline Tice12cecd72010-09-20 21:37:42 +00002629bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002630DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2631 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00002632 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00002633 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002634{
2635 if (var_name == PromptVarName())
2636 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002637 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002638
2639 }
2640 else if (var_name == ScriptLangVarName())
2641 {
2642 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
2643 }
Caroline Tice101c7c22010-09-09 06:25:08 +00002644 else if (var_name == TermWidthVarName())
2645 {
2646 StreamString width_str;
Greg Claytone372b982011-11-21 21:44:34 +00002647 width_str.Printf ("%u", m_term_width);
Caroline Tice101c7c22010-09-09 06:25:08 +00002648 value.AppendString (width_str.GetData());
2649 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002650 else if (var_name == GetFrameFormatName ())
2651 {
2652 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
2653 }
2654 else if (var_name == GetThreadFormatName ())
2655 {
2656 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
2657 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002658 else if (var_name == UseExternalEditorVarName())
2659 {
2660 if (m_use_external_editor)
2661 value.AppendString ("true");
2662 else
2663 value.AppendString ("false");
2664 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002665 else if (var_name == AutoConfirmName())
2666 {
2667 if (m_auto_confirm_on)
2668 value.AppendString ("true");
2669 else
2670 value.AppendString ("false");
2671 }
Greg Claytone372b982011-11-21 21:44:34 +00002672 else if (var_name == StopSourceContextAfterName ())
2673 {
2674 StreamString strm;
2675 strm.Printf ("%u", m_stop_source_before_count);
2676 value.AppendString (strm.GetData());
2677 }
2678 else if (var_name == StopSourceContextBeforeName ())
2679 {
2680 StreamString strm;
2681 strm.Printf ("%u", m_stop_source_after_count);
2682 value.AppendString (strm.GetData());
2683 }
2684 else if (var_name == StopDisassemblyCountName ())
2685 {
2686 StreamString strm;
2687 strm.Printf ("%u", m_stop_disassembly_count);
2688 value.AppendString (strm.GetData());
2689 }
2690 else if (var_name == StopDisassemblyDisplayName ())
2691 {
2692 if (m_stop_disassembly_display >= eStopDisassemblyTypeNever && m_stop_disassembly_display <= eStopDisassemblyTypeAlways)
2693 value.AppendString (g_show_disassembly_enum_values[m_stop_disassembly_display].string_value);
2694 else
2695 value.AppendString ("<invalid>");
2696 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002697 else
Caroline Tice12cecd72010-09-20 21:37:42 +00002698 {
2699 if (err)
2700 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2701 return false;
2702 }
2703 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002704}
2705
2706void
Greg Clayton4d122c42011-09-17 08:33:22 +00002707DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002708 bool pending)
2709{
2710 if (new_settings.get() == NULL)
2711 return;
2712
2713 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
2714
2715 m_prompt = new_debugger_settings->m_prompt;
2716 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00002717 {
2718 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2719 // strip off the brackets before passing it to BroadcastPromptChange.
2720
2721 std::string tmp_instance_name (m_instance_name.AsCString());
2722 if ((tmp_instance_name[0] == '[')
2723 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
2724 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
2725 ConstString new_name (tmp_instance_name.c_str());
2726
2727 BroadcastPromptChange (new_name, m_prompt.c_str());
2728 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002729 m_frame_format = new_debugger_settings->m_frame_format;
2730 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002731 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002732 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002733 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002734 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002735}
2736
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002737
2738bool
2739DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
2740{
2741 std::string tmp_prompt;
2742
2743 if (new_prompt != NULL)
2744 {
2745 tmp_prompt = new_prompt ;
2746 int len = tmp_prompt.size();
2747 if (len > 1
2748 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
2749 && (tmp_prompt[len-1] == tmp_prompt[0]))
2750 {
2751 tmp_prompt = tmp_prompt.substr(1,len-2);
2752 }
2753 len = tmp_prompt.size();
2754 if (tmp_prompt[len-1] != ' ')
2755 tmp_prompt.append(" ");
2756 }
2757 EventSP new_event_sp;
2758 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
2759 new EventDataBytes (tmp_prompt.c_str())));
2760
2761 if (instance_name.GetLength() != 0)
2762 {
2763 // Set prompt for a particular instance.
2764 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
2765 if (dbg != NULL)
2766 {
2767 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
2768 }
2769 }
2770
2771 return true;
2772}
2773
2774const ConstString
2775DebuggerInstanceSettings::CreateInstanceName ()
2776{
2777 static int instance_count = 1;
2778 StreamString sstr;
2779
2780 sstr.Printf ("debugger_%d", instance_count);
2781 ++instance_count;
2782
2783 const ConstString ret_val (sstr.GetData());
2784
2785 return ret_val;
2786}
2787
Jim Ingham3bcdb292010-10-04 22:44:14 +00002788
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002789//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002790// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002791//--------------------------------------------------
2792
2793
2794SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002795Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002796{
2797 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00002798 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
2799 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002800 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
2801};
2802
Greg Claytonbb562b12010-10-04 02:44:26 +00002803#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00002804#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002805
Greg Clayton0603aa92010-10-04 01:05:56 +00002806#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2807 "{, ${frame.pc}}"\
2808 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00002809 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00002810 "{, stop reason = ${thread.stop-reason}}"\
Jim Inghamef651602011-12-22 19:12:40 +00002811 "{\\nReturn value: ${thread.return-value}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00002812 "\\n"
2813
Greg Clayton315d2ca2010-11-02 01:53:21 +00002814//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2815// "{, ${frame.pc}}"\
2816// MODULE_WITH_FUNC\
2817// FILE_AND_LINE\
2818// "{, stop reason = ${thread.stop-reason}}"\
2819// "{, name = ${thread.name}}"\
2820// "{, queue = ${thread.queue}}"\
2821// "\\n"
2822
Greg Clayton0603aa92010-10-04 01:05:56 +00002823#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
2824 MODULE_WITH_FUNC\
2825 FILE_AND_LINE\
2826 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002827
2828SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002829Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002830{
Greg Clayton0603aa92010-10-04 01:05:56 +00002831// NAME Setting variable type Default Enum Init'd Hidden Help
2832// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00002833{ "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 +00002834{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00002835{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
2836{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002837{ "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 +00002838{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
2839{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
2840{ "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." },
2841{ "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." },
2842{ "stop-disassembly-count", eSetVarTypeInt, "0", NULL, false, false, "The number of disassembly lines to show when displaying a stopped context." },
2843{ "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 +00002844{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002845};