blob: 3a2da84578d5fc6f86d9f217d6fdcd3f2a2610fb [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Greg Clayton4a33d312011-06-23 17:59:56 +000010#include "lldb/Core/Debugger.h"
11
12#include <map>
13
Enrico Granata4becb372011-06-29 22:27:15 +000014#include "clang/AST/DeclCXX.h"
15#include "clang/AST/Type.h"
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/lldb-private.h"
18#include "lldb/Core/ConnectionFileDescriptor.h"
Enrico Granataa777dc22012-05-08 21:49:57 +000019#include "lldb/Core/DataVisualization.h"
Greg Clayton4a33d312011-06-23 17:59:56 +000020#include "lldb/Core/FormatManager.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/InputReader.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000022#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000024#include "lldb/Core/StreamAsynchronousIO.h"
Jim Ingham228063c2012-02-21 02:23:08 +000025#include "lldb/Core/StreamCallback.h"
Greg Clayton1b654882010-09-19 02:33:57 +000026#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000028#include "lldb/Core/ValueObject.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000029#include "lldb/Core/ValueObjectVariable.h"
Greg Claytona3406612011-02-07 23:24:47 +000030#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000031#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000032#include "lldb/Interpreter/OptionValueSInt64.h"
33#include "lldb/Interpreter/OptionValueString.h"
Greg Clayton6d3dbf52012-01-13 08:39:16 +000034#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Target/TargetList.h"
36#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000037#include "lldb/Target/RegisterContext.h"
38#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Target/Thread.h"
Greg Clayton5a314712011-10-14 07:41:33 +000040#include "lldb/Utility/AnsiTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041
42using namespace lldb;
43using namespace lldb_private;
44
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045
Greg Clayton1b654882010-09-19 02:33:57 +000046static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000047static lldb::user_id_t g_unique_id = 1;
48
Greg Clayton1b654882010-09-19 02:33:57 +000049#pragma mark Static Functions
50
51static Mutex &
52GetDebuggerListMutex ()
53{
54 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
55 return g_mutex;
56}
57
58typedef std::vector<DebuggerSP> DebuggerList;
59
60static DebuggerList &
61GetDebuggerList()
62{
63 // hide the static debugger list inside a singleton accessor to avoid
64 // global init contructors
65 static DebuggerList g_list;
66 return g_list;
67}
Greg Clayton67cc0632012-08-22 17:17:09 +000068//
69//
70//static const ConstString &
71//PromptVarName ()
72//{
73// static ConstString g_const_string ("prompt");
74// return g_const_string;
75//}
76//
77//static const ConstString &
78//GetNotifyVoidName ()
79//{
80// static ConstString g_const_string ("notify-void");
81// return g_const_string;
82//}
83//
84//static const ConstString &
85//GetFrameFormatName ()
86//{
87// static ConstString g_const_string ("frame-format");
88// return g_const_string;
89//}
90//
91//static const ConstString &
92//GetThreadFormatName ()
93//{
94// static ConstString g_const_string ("thread-format");
95// return g_const_string;
96//}
97//
98//static const ConstString &
99//ScriptLangVarName ()
100//{
101// static ConstString g_const_string ("script-lang");
102// return g_const_string;
103//}
104//
105//static const ConstString &
106//TermWidthVarName ()
107//{
108// static ConstString g_const_string ("term-width");
109// return g_const_string;
110//}
111//
112//static const ConstString &
113//UseExternalEditorVarName ()
114//{
115// static ConstString g_const_string ("use-external-editor");
116// return g_const_string;
117//}
118//
119//static const ConstString &
120//AutoConfirmName ()
121//{
122// static ConstString g_const_string ("auto-confirm");
123// return g_const_string;
124//}
125//
126//static const ConstString &
127//StopSourceContextBeforeName ()
128//{
129// static ConstString g_const_string ("stop-line-count-before");
130// return g_const_string;
131//}
132//
133//static const ConstString &
134//StopSourceContextAfterName ()
135//{
136// static ConstString g_const_string ("stop-line-count-after");
137// return g_const_string;
138//}
139//
140//static const ConstString &
141//StopDisassemblyCountName ()
142//{
143// static ConstString g_const_string ("stop-disassembly-count");
144// return g_const_string;
145//}
146//
147//static const ConstString &
148//StopDisassemblyDisplayName ()
149//{
150// static ConstString g_const_string ("stop-disassembly-display");
151// return g_const_string;
152//}
Greg Claytone372b982011-11-21 21:44:34 +0000153
154OptionEnumValueElement
Greg Clayton67cc0632012-08-22 17:17:09 +0000155g_show_disassembly_enum_values[] =
Greg Claytone372b982011-11-21 21:44:34 +0000156{
Greg Clayton67cc0632012-08-22 17:17:09 +0000157 { Debugger::eStopDisassemblyTypeNever, "never", "Never show disassembly when displaying a stop context."},
158 { Debugger::eStopDisassemblyTypeNoSource, "no-source", "Show disassembly when there is no source information, or the source file is missing when displaying a stop context."},
159 { Debugger::eStopDisassemblyTypeAlways, "always", "Always show disassembly when displaying a stop context."},
Greg Claytone372b982011-11-21 21:44:34 +0000160 { 0, NULL, NULL }
161};
162
Greg Clayton67cc0632012-08-22 17:17:09 +0000163OptionEnumValueElement
164g_language_enumerators[] =
165{
166 { eScriptLanguageNone, "none", "Disable scripting languages."},
167 { eScriptLanguagePython, "python", "Select python as the default scripting language."},
168 { eScriptLanguageDefault, "default", "Select the lldb default as the default scripting language."},
169};
Greg Claytone372b982011-11-21 21:44:34 +0000170
Greg Clayton67cc0632012-08-22 17:17:09 +0000171#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}"
172#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
173
174#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
175 "{, ${frame.pc}}"\
176 MODULE_WITH_FUNC\
177 FILE_AND_LINE\
178 "{, stop reason = ${thread.stop-reason}}"\
179 "{\\nReturn value: ${thread.return-value}}"\
180 "\\n"
181
182#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
183 MODULE_WITH_FUNC\
184 FILE_AND_LINE\
185 "\\n"
186
187
188
189PropertyDefinition
190g_instance_settings_table[] =
191{
192{ "auto-confirm", OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true all confirmation prompts will receive their default reply." },
193{ "frame-format", OptionValue::eTypeString , true, 0 , DEFAULT_FRAME_FORMAT, NULL, "The default frame format string to use when displaying stack frame information for threads." },
194{ "notify-void", OptionValue::eTypeBoolean, true, false, NULL, NULL, "Notify the user explicitly if an expression returns void (default: false)." },
195{ "prompt", OptionValue::eTypeString , true, 0 , "(lldb) ", NULL, "The debugger command line prompt displayed for the user." },
196{ "script-lang", OptionValue::eTypeEnum , true, eScriptLanguagePython, NULL, g_language_enumerators, "The script language to be used for evaluating user-written scripts." },
197{ "stop-disassembly-count", OptionValue::eTypeSInt64 , true, 4 , NULL, NULL, "The number of disassembly lines to show when displaying a stopped context." },
198{ "stop-disassembly-display", OptionValue::eTypeEnum , true, Debugger::eStopDisassemblyTypeNoSource, NULL, g_show_disassembly_enum_values, "Control when to display disassembly when displaying a stopped context." },
199{ "stop-line-count-after", OptionValue::eTypeSInt64 , true, 3 , NULL, NULL, "The number of sources lines to display that come after the current source line when displaying a stopped context." },
200{ "stop-line-count-before", OptionValue::eTypeSInt64 , true, 3 , NULL, NULL, "The number of sources lines to display that come before the current source line when displaying a stopped context." },
201{ "term-width", OptionValue::eTypeSInt64 , true, 80 , NULL, NULL, "The maximum number of columns to use for displaying text." },
202{ "thread-format", OptionValue::eTypeString , true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
203{ "use-external-editor", OptionValue::eTypeBoolean, true, false, NULL, NULL, "Whether to use an external editor or not." },
204{ NULL, OptionValue::eTypeInvalid, true, 0 , NULL, NULL, NULL }
205};
206
207enum
208{
209 ePropertyAutoConfirm = 0,
210 ePropertyFrameFormat,
211 ePropertyNotiftVoid,
212 ePropertyPrompt,
213 ePropertyScriptLanguage,
214 ePropertyStopDisassemblyCount,
215 ePropertyStopDisassemblyDisplay,
216 ePropertyStopLineCountAfter,
217 ePropertyStopLineCountBefore,
218 ePropertyTerminalWidth,
219 ePropertyThreadFormat,
220 ePropertyUseExternalEditor
221};
222
223//
224//const char *
225//Debugger::GetFrameFormat() const
226//{
227// return m_properties_sp->GetFrameFormat();
228//}
229//const char *
230//Debugger::GetThreadFormat() const
231//{
232// return m_properties_sp->GetThreadFormat();
233//}
234//
235bool
236Debugger::GetAutoConfirm () const
237{
238 const uint32_t idx = ePropertyAutoConfirm;
239 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_instance_settings_table[idx].default_uint_value != 0);
240}
241
242const char *
243Debugger::GetFrameFormat() const
244{
245 const uint32_t idx = ePropertyFrameFormat;
246 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_instance_settings_table[idx].default_cstr_value);
247}
248
249bool
250Debugger::GetNotifyVoid () const
251{
252 const uint32_t idx = ePropertyNotiftVoid;
253 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_instance_settings_table[idx].default_uint_value != 0);
254}
255
256const char *
257Debugger::GetPrompt() const
258{
259 const uint32_t idx = ePropertyPrompt;
260 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_instance_settings_table[idx].default_cstr_value);
261}
262
263void
264Debugger::SetPrompt(const char *p)
265{
266 const uint32_t idx = ePropertyPrompt;
267 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
268 const char *new_prompt = GetPrompt();
269 EventSP prompt_change_event_sp (new Event(CommandInterpreter::eBroadcastBitResetPrompt, new EventDataBytes (new_prompt)));;
270 GetCommandInterpreter().BroadcastEvent (prompt_change_event_sp);
271}
272
273const char *
274Debugger::GetThreadFormat() const
275{
276 const uint32_t idx = ePropertyThreadFormat;
277 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, g_instance_settings_table[idx].default_cstr_value);
278}
279
280lldb::ScriptLanguage
281Debugger::GetScriptLanguage() const
282{
283 const uint32_t idx = ePropertyScriptLanguage;
284 return (lldb::ScriptLanguage)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_instance_settings_table[idx].default_uint_value);
285}
286
287bool
288Debugger::SetScriptLanguage (lldb::ScriptLanguage script_lang)
289{
290 const uint32_t idx = ePropertyScriptLanguage;
291 return m_collection_sp->SetPropertyAtIndexAsEnumeration (NULL, idx, script_lang);
292}
293
294uint32_t
295Debugger::GetTerminalWidth () const
296{
297 const uint32_t idx = ePropertyTerminalWidth;
298 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_instance_settings_table[idx].default_uint_value);
299}
300
301bool
302Debugger::SetTerminalWidth (uint32_t term_width)
303{
304 const uint32_t idx = ePropertyTerminalWidth;
305 return m_collection_sp->SetPropertyAtIndexAsSInt64 (NULL, idx, term_width);
306}
307
308bool
309Debugger::GetUseExternalEditor () const
310{
311 const uint32_t idx = ePropertyUseExternalEditor;
312 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_instance_settings_table[idx].default_uint_value != 0);
313}
314
315bool
316Debugger::SetUseExternalEditor (bool b)
317{
318 const uint32_t idx = ePropertyUseExternalEditor;
319 return m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
320}
321
322uint32_t
323Debugger::GetStopSourceLineCount (bool before) const
324{
325 const uint32_t idx = before ? ePropertyStopLineCountBefore : ePropertyStopLineCountAfter;
326 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_instance_settings_table[idx].default_uint_value);
327}
328
329Debugger::StopDisassemblyType
330Debugger::GetStopDisassemblyDisplay () const
331{
332 const uint32_t idx = ePropertyStopDisassemblyDisplay;
333 return (Debugger::StopDisassemblyType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_instance_settings_table[idx].default_uint_value);
334}
335
336uint32_t
337Debugger::GetDisassemblyLineCount () const
338{
339 const uint32_t idx = ePropertyStopDisassemblyCount;
340 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_instance_settings_table[idx].default_uint_value);
341}
Greg Claytone372b982011-11-21 21:44:34 +0000342
Greg Clayton1b654882010-09-19 02:33:57 +0000343#pragma mark Debugger
344
Greg Clayton67cc0632012-08-22 17:17:09 +0000345//const DebuggerPropertiesSP &
346//Debugger::GetSettings() const
347//{
348// return m_properties_sp;
349//}
350//
Greg Clayton99d0faf2010-11-18 23:32:35 +0000351
Caroline Tice2f88aad2011-01-14 00:29:16 +0000352int
353Debugger::TestDebuggerRefCount ()
354{
355 return g_shared_debugger_refcount;
356}
357
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358void
359Debugger::Initialize ()
360{
Greg Claytonc15f55e2012-03-30 20:53:46 +0000361 if (g_shared_debugger_refcount++ == 0)
Greg Claytondbe54502010-11-19 03:46:01 +0000362 lldb_private::Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000363}
364
365void
366Debugger::Terminate ()
367{
Greg Clayton66111032010-06-23 01:19:29 +0000368 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000369 {
Greg Clayton66111032010-06-23 01:19:29 +0000370 g_shared_debugger_refcount--;
371 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372 {
Greg Claytondbe54502010-11-19 03:46:01 +0000373 lldb_private::WillTerminate();
374 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000375
376 // Clear our master list of debugger objects
377 Mutex::Locker locker (GetDebuggerListMutex ());
378 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380 }
381}
382
Caroline Tice20bd37f2011-03-10 22:14:10 +0000383void
384Debugger::SettingsInitialize ()
385{
Greg Clayton67cc0632012-08-22 17:17:09 +0000386// static bool g_initialized = false;
387//
388// if (!g_initialized)
389// {
390// g_initialized = true;
391// UserSettingsController::InitializeSettingsController (GetSettingsController(),
392// SettingsController::global_settings_table,
393// SettingsController::instance_settings_table);
394// // Now call SettingsInitialize for each settings 'child' of Debugger
395// Target::SettingsInitialize ();
396// }
Caroline Tice20bd37f2011-03-10 22:14:10 +0000397}
398
399void
400Debugger::SettingsTerminate ()
401{
Greg Clayton67cc0632012-08-22 17:17:09 +0000402//
403// // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
404// // Settings.
405//
406// Target::SettingsTerminate ();
407//
408// // Now terminate the Debugger Settings.
409//
410// UserSettingsControllerSP &usc = GetSettingsController();
411// UserSettingsController::FinalizeSettingsController (usc);
412// usc.reset();
Caroline Tice20bd37f2011-03-10 22:14:10 +0000413}
414
Greg Clayton66111032010-06-23 01:19:29 +0000415DebuggerSP
Jim Ingham228063c2012-02-21 02:23:08 +0000416Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton)
Greg Clayton66111032010-06-23 01:19:29 +0000417{
Jim Ingham228063c2012-02-21 02:23:08 +0000418 DebuggerSP debugger_sp (new Debugger(log_callback, baton));
Greg Claytonc15f55e2012-03-30 20:53:46 +0000419 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000420 {
421 Mutex::Locker locker (GetDebuggerListMutex ());
422 GetDebuggerList().push_back(debugger_sp);
423 }
424 return debugger_sp;
425}
426
Caroline Ticee02657b2011-01-22 01:02:07 +0000427void
Greg Clayton4d122c42011-09-17 08:33:22 +0000428Debugger::Destroy (DebuggerSP &debugger_sp)
Caroline Ticee02657b2011-01-22 01:02:07 +0000429{
430 if (debugger_sp.get() == NULL)
431 return;
432
Jim Ingham8314c522011-09-15 21:36:42 +0000433 debugger_sp->Clear();
434
Greg Claytonc15f55e2012-03-30 20:53:46 +0000435 if (g_shared_debugger_refcount > 0)
Caroline Ticee02657b2011-01-22 01:02:07 +0000436 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000437 Mutex::Locker locker (GetDebuggerListMutex ());
438 DebuggerList &debugger_list = GetDebuggerList ();
439 DebuggerList::iterator pos, end = debugger_list.end();
440 for (pos = debugger_list.begin (); pos != end; ++pos)
Caroline Ticee02657b2011-01-22 01:02:07 +0000441 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000442 if ((*pos).get() == debugger_sp.get())
443 {
444 debugger_list.erase (pos);
445 return;
446 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000447 }
448 }
Caroline Ticee02657b2011-01-22 01:02:07 +0000449}
450
Greg Clayton4d122c42011-09-17 08:33:22 +0000451DebuggerSP
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000452Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
453{
Greg Clayton4d122c42011-09-17 08:33:22 +0000454 DebuggerSP debugger_sp;
Greg Clayton67cc0632012-08-22 17:17:09 +0000455 // TODO: SETTINGS
456// if (g_shared_debugger_refcount > 0)
457// {
458// Mutex::Locker locker (GetDebuggerListMutex ());
459// DebuggerList &debugger_list = GetDebuggerList();
460// DebuggerList::iterator pos, end = debugger_list.end();
461//
462// for (pos = debugger_list.begin(); pos != end; ++pos)
463// {
464// if ((*pos).get()->m_instance_name == instance_name)
465// {
466// debugger_sp = *pos;
467// break;
468// }
469// }
470// }
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000471 return debugger_sp;
472}
Greg Clayton66111032010-06-23 01:19:29 +0000473
474TargetSP
475Debugger::FindTargetWithProcessID (lldb::pid_t pid)
476{
Greg Clayton4d122c42011-09-17 08:33:22 +0000477 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000478 if (g_shared_debugger_refcount > 0)
Greg Clayton66111032010-06-23 01:19:29 +0000479 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000480 Mutex::Locker locker (GetDebuggerListMutex ());
481 DebuggerList &debugger_list = GetDebuggerList();
482 DebuggerList::iterator pos, end = debugger_list.end();
483 for (pos = debugger_list.begin(); pos != end; ++pos)
484 {
485 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
486 if (target_sp)
487 break;
488 }
Greg Clayton66111032010-06-23 01:19:29 +0000489 }
490 return target_sp;
491}
492
Greg Claytone4e45922011-11-16 05:37:56 +0000493TargetSP
494Debugger::FindTargetWithProcess (Process *process)
495{
496 TargetSP target_sp;
Greg Claytonc15f55e2012-03-30 20:53:46 +0000497 if (g_shared_debugger_refcount > 0)
Greg Claytone4e45922011-11-16 05:37:56 +0000498 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000499 Mutex::Locker locker (GetDebuggerListMutex ());
500 DebuggerList &debugger_list = GetDebuggerList();
501 DebuggerList::iterator pos, end = debugger_list.end();
502 for (pos = debugger_list.begin(); pos != end; ++pos)
503 {
504 target_sp = (*pos)->GetTargetList().FindTargetWithProcess (process);
505 if (target_sp)
506 break;
507 }
Greg Claytone4e45922011-11-16 05:37:56 +0000508 }
509 return target_sp;
510}
511
Jim Ingham228063c2012-02-21 02:23:08 +0000512Debugger::Debugger (lldb::LogOutputCallback log_callback, void *baton) :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000513 UserID (g_unique_id++),
Greg Clayton67cc0632012-08-22 17:17:09 +0000514 Properties(OptionValuePropertiesSP(new OptionValueProperties())),
Greg Claytond46c87a2010-12-04 02:39:47 +0000515 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516 m_input_file (),
517 m_output_file (),
518 m_error_file (),
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000519 m_target_list (*this),
Greg Claytonded470d2011-03-19 01:12:21 +0000520 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521 m_listener ("lldb.Debugger"),
Jim Inghame37d6052011-09-13 00:29:56 +0000522 m_source_manager(*this),
523 m_source_file_cache(),
Greg Clayton66111032010-06-23 01:19:29 +0000524 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000525 m_input_reader_stack (),
Greg Clayton67cc0632012-08-22 17:17:09 +0000526 m_input_reader_data (),
527 m_instance_name()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000528{
Greg Clayton67cc0632012-08-22 17:17:09 +0000529 char instance_cstr[256];
530 snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID());
531 m_instance_name.SetCString(instance_cstr);
Jim Ingham228063c2012-02-21 02:23:08 +0000532 if (log_callback)
533 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
Greg Clayton66111032010-06-23 01:19:29 +0000534 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000535 // Always add our default platform to the platform list
536 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
537 assert (default_platform_sp.get());
538 m_platform_list.Append (default_platform_sp, true);
Greg Clayton67cc0632012-08-22 17:17:09 +0000539
540 m_collection_sp->Initialize (g_instance_settings_table);
541 m_collection_sp->AppendProperty (ConstString("target"),
542 ConstString("Settings specify to debugging targets."),
543 true,
544 Target::GetGlobalProperties()->GetValueProperties());
545 OptionValueSInt64 *term_width = m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64 (NULL, ePropertyTerminalWidth);
546 term_width->SetMinimumValue(10);
547 term_width->SetMaximumValue(1024);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548}
549
550Debugger::~Debugger ()
551{
Jim Ingham8314c522011-09-15 21:36:42 +0000552 Clear();
553}
554
555void
556Debugger::Clear()
557{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000558 CleanUpInputReaders();
Greg Clayton1ed54f52011-10-01 00:45:15 +0000559 m_listener.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000560 int num_targets = m_target_list.GetNumTargets();
561 for (int i = 0; i < num_targets; i++)
562 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000563 TargetSP target_sp (m_target_list.GetTargetAtIndex (i));
564 if (target_sp)
Jim Ingham8314c522011-09-15 21:36:42 +0000565 {
Greg Claytonccbc08e2012-01-14 17:04:19 +0000566 ProcessSP process_sp (target_sp->GetProcessSP());
567 if (process_sp)
568 {
569 if (process_sp->GetShouldDetach())
570 process_sp->Detach();
571 }
572 target_sp->Destroy();
Jim Ingham8314c522011-09-15 21:36:42 +0000573 }
Greg Clayton66111032010-06-23 01:19:29 +0000574 }
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000575 BroadcasterManager::Clear ();
Greg Clayton0d69a3a2012-05-16 00:11:54 +0000576
577 // Close the input file _before_ we close the input read communications class
578 // as it does NOT own the input file, our m_input_file does.
579 GetInputFile().Close ();
580 // Now that we have closed m_input_file, we can now tell our input communication
581 // class to close down. Its read thread should quickly exit after we close
582 // the input file handle above.
583 m_input_comm.Clear ();
Jim Ingham8314c522011-09-15 21:36:42 +0000584}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585
586bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000587Debugger::GetCloseInputOnEOF () const
588{
589 return m_input_comm.GetCloseOnEOF();
590}
591
592void
593Debugger::SetCloseInputOnEOF (bool b)
594{
595 m_input_comm.SetCloseOnEOF(b);
596}
597
598bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599Debugger::GetAsyncExecution ()
600{
Greg Clayton66111032010-06-23 01:19:29 +0000601 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000602}
603
604void
605Debugger::SetAsyncExecution (bool async_execution)
606{
Greg Clayton66111032010-06-23 01:19:29 +0000607 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000608}
609
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610
611void
612Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
613{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000614 File &in_file = GetInputFile();
615 in_file.SetStream (fh, tranfer_ownership);
616 if (in_file.IsValid() == false)
617 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000618
619 // Disconnect from any old connection if we had one
620 m_input_comm.Disconnect ();
Greg Clayton32720b52012-01-14 20:47:38 +0000621 // Pass false as the second argument to ConnectionFileDescriptor below because
622 // our "in_file" above will already take ownership if requested and we don't
623 // want to objects trying to own and close a file descriptor.
624 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
626
627 Error error;
628 if (m_input_comm.StartReadThread (&error) == false)
629 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000630 File &err_file = GetErrorFile();
631
632 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
633 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000634 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000635}
636
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637void
638Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
639{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000640 File &out_file = GetOutputFile();
641 out_file.SetStream (fh, tranfer_ownership);
642 if (out_file.IsValid() == false)
643 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000644
645 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646}
647
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648void
649Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
650{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000651 File &err_file = GetErrorFile();
652 err_file.SetStream (fh, tranfer_ownership);
653 if (err_file.IsValid() == false)
654 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655}
656
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000657ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000658Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659{
660 ExecutionContext exe_ctx;
Greg Claytonc14ee322011-09-22 04:58:26 +0000661 TargetSP target_sp(GetSelectedTarget());
662 exe_ctx.SetTargetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663
664 if (target_sp)
665 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000666 ProcessSP process_sp (target_sp->GetProcessSP());
667 exe_ctx.SetProcessSP (process_sp);
668 if (process_sp && process_sp->IsRunning() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000670 ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread());
671 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000673 exe_ctx.SetThreadSP (thread_sp);
674 exe_ctx.SetFrameSP (thread_sp->GetSelectedFrame());
675 if (exe_ctx.GetFramePtr() == NULL)
676 exe_ctx.SetFrameSP (thread_sp->GetStackFrameAtIndex (0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 }
678 }
679 }
680 return exe_ctx;
681
682}
683
Caroline Ticeb44880c2011-02-10 01:15:13 +0000684InputReaderSP
685Debugger::GetCurrentInputReader ()
686{
687 InputReaderSP reader_sp;
688
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000689 if (!m_input_reader_stack.IsEmpty())
Caroline Ticeb44880c2011-02-10 01:15:13 +0000690 {
691 // Clear any finished readers from the stack
692 while (CheckIfTopInputReaderIsDone()) ;
693
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000694 if (!m_input_reader_stack.IsEmpty())
695 reader_sp = m_input_reader_stack.Top();
Caroline Ticeb44880c2011-02-10 01:15:13 +0000696 }
697
698 return reader_sp;
699}
700
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000701void
702Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
703{
Caroline Ticeefed6132010-11-19 20:47:54 +0000704 if (bytes_len > 0)
705 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
706 else
707 ((Debugger *)baton)->DispatchInputEndOfFile ();
708}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709
710
711void
712Debugger::DispatchInput (const char *bytes, size_t bytes_len)
713{
Caroline Ticeefed6132010-11-19 20:47:54 +0000714 if (bytes == NULL || bytes_len == 0)
715 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000716
717 WriteToDefaultReader (bytes, bytes_len);
718}
719
720void
Caroline Ticeefed6132010-11-19 20:47:54 +0000721Debugger::DispatchInputInterrupt ()
722{
723 m_input_reader_data.clear();
724
Caroline Ticeb44880c2011-02-10 01:15:13 +0000725 InputReaderSP reader_sp (GetCurrentInputReader ());
726 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000727 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000728 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000729
Caroline Ticeb44880c2011-02-10 01:15:13 +0000730 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000731 while (CheckIfTopInputReaderIsDone ()) ;
732 }
733}
734
735void
736Debugger::DispatchInputEndOfFile ()
737{
738 m_input_reader_data.clear();
739
Caroline Ticeb44880c2011-02-10 01:15:13 +0000740 InputReaderSP reader_sp (GetCurrentInputReader ());
741 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000742 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000743 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000744
Caroline Ticeb44880c2011-02-10 01:15:13 +0000745 // 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 +0000746 while (CheckIfTopInputReaderIsDone ()) ;
747 }
748}
749
750void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000751Debugger::CleanUpInputReaders ()
752{
753 m_input_reader_data.clear();
754
Caroline Ticeb44880c2011-02-10 01:15:13 +0000755 // 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 +0000756 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000757 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000758 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000759 if (reader_sp)
760 {
761 reader_sp->Notify (eInputReaderEndOfFile);
762 reader_sp->SetIsDone (true);
763 }
764 }
765}
766
767void
Caroline Tice969ed3d2011-05-02 20:41:46 +0000768Debugger::NotifyTopInputReader (InputReaderAction notification)
769{
770 InputReaderSP reader_sp (GetCurrentInputReader());
771 if (reader_sp)
772 {
773 reader_sp->Notify (notification);
774
775 // Flush out any input readers that are done.
776 while (CheckIfTopInputReaderIsDone ())
777 /* Do nothing. */;
778 }
779}
780
Caroline Tice9088b062011-05-09 23:06:58 +0000781bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000782Debugger::InputReaderIsTopReader (const InputReaderSP& reader_sp)
Caroline Tice9088b062011-05-09 23:06:58 +0000783{
Caroline Ticed61c10b2011-06-16 16:27:19 +0000784 InputReaderSP top_reader_sp (GetCurrentInputReader());
Caroline Tice9088b062011-05-09 23:06:58 +0000785
Caroline Ticed61c10b2011-06-16 16:27:19 +0000786 return (reader_sp.get() == top_reader_sp.get());
Caroline Tice9088b062011-05-09 23:06:58 +0000787}
788
789
Caroline Tice969ed3d2011-05-02 20:41:46 +0000790void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
792{
793 if (bytes && bytes_len)
794 m_input_reader_data.append (bytes, bytes_len);
795
796 if (m_input_reader_data.empty())
797 return;
798
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000799 while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000800 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000802 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803 if (!reader_sp)
804 break;
805
Greg Clayton471b31c2010-07-20 22:52:08 +0000806 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807 m_input_reader_data.size());
808 if (bytes_handled)
809 {
810 m_input_reader_data.erase (0, bytes_handled);
811 }
812 else
813 {
814 // No bytes were handled, we might not have reached our
815 // granularity, just return and wait for more data
816 break;
817 }
818 }
819
Caroline Ticeb44880c2011-02-10 01:15:13 +0000820 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821 while (CheckIfTopInputReaderIsDone ())
822 /* Do nothing. */;
823
824}
825
826void
827Debugger::PushInputReader (const InputReaderSP& reader_sp)
828{
829 if (!reader_sp)
830 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000831
832 // Deactivate the old top reader
833 InputReaderSP top_reader_sp (GetCurrentInputReader ());
834
835 if (top_reader_sp)
836 top_reader_sp->Notify (eInputReaderDeactivate);
837
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000838 m_input_reader_stack.Push (reader_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000839 reader_sp->Notify (eInputReaderActivate);
840 ActivateInputReader (reader_sp);
841}
842
843bool
Greg Clayton4d122c42011-09-17 08:33:22 +0000844Debugger::PopInputReader (const InputReaderSP& pop_reader_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000845{
846 bool result = false;
847
848 // The reader on the stop of the stack is done, so let the next
849 // read on the stack referesh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000850 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000852 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000853 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854
855 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
856 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000857 m_input_reader_stack.Pop ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 reader_sp->Notify (eInputReaderDeactivate);
859 reader_sp->Notify (eInputReaderDone);
860 result = true;
861
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000862 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000864 reader_sp = m_input_reader_stack.Top();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000865 if (reader_sp)
866 {
867 ActivateInputReader (reader_sp);
868 reader_sp->Notify (eInputReaderReactivate);
869 }
870 }
871 }
872 }
873 return result;
874}
875
876bool
877Debugger::CheckIfTopInputReaderIsDone ()
878{
879 bool result = false;
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000880 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000881 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000882 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000883 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000884
885 if (reader_sp && reader_sp->IsDone())
886 {
887 result = true;
888 PopInputReader (reader_sp);
889 }
890 }
891 return result;
892}
893
894void
895Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
896{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000897 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000898
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000899 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000901 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000902
903 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000904
Greg Claytona3406612011-02-07 23:24:47 +0000905 switch (reader_sp->GetGranularity())
906 {
907 case eInputReaderGranularityByte:
908 case eInputReaderGranularityWord:
909 tty.SetCanonical (false);
910 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911
Greg Claytona3406612011-02-07 23:24:47 +0000912 case eInputReaderGranularityLine:
913 case eInputReaderGranularityAll:
914 tty.SetCanonical (true);
915 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000916
Greg Claytona3406612011-02-07 23:24:47 +0000917 default:
918 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000919 }
920 }
921}
Greg Clayton66111032010-06-23 01:19:29 +0000922
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000923StreamSP
924Debugger::GetAsyncOutputStream ()
925{
926 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
927 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
928}
929
930StreamSP
931Debugger::GetAsyncErrorStream ()
932{
933 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
934 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
935}
936
Enrico Granata061858c2012-02-15 02:34:21 +0000937uint32_t
938Debugger::GetNumDebuggers()
939{
Greg Claytonc15f55e2012-03-30 20:53:46 +0000940 if (g_shared_debugger_refcount > 0)
941 {
942 Mutex::Locker locker (GetDebuggerListMutex ());
943 return GetDebuggerList().size();
944 }
945 return 0;
Enrico Granata061858c2012-02-15 02:34:21 +0000946}
947
948lldb::DebuggerSP
949Debugger::GetDebuggerAtIndex (uint32_t index)
950{
951 DebuggerSP debugger_sp;
952
Greg Claytonc15f55e2012-03-30 20:53:46 +0000953 if (g_shared_debugger_refcount > 0)
954 {
955 Mutex::Locker locker (GetDebuggerListMutex ());
956 DebuggerList &debugger_list = GetDebuggerList();
Enrico Granata061858c2012-02-15 02:34:21 +0000957
Greg Claytonc15f55e2012-03-30 20:53:46 +0000958 if (index < debugger_list.size())
959 debugger_sp = debugger_list[index];
960 }
961
Enrico Granata061858c2012-02-15 02:34:21 +0000962 return debugger_sp;
963}
964
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000965DebuggerSP
966Debugger::FindDebuggerWithID (lldb::user_id_t id)
967{
Greg Clayton4d122c42011-09-17 08:33:22 +0000968 DebuggerSP debugger_sp;
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000969
Greg Claytonc15f55e2012-03-30 20:53:46 +0000970 if (g_shared_debugger_refcount > 0)
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000971 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000972 Mutex::Locker locker (GetDebuggerListMutex ());
973 DebuggerList &debugger_list = GetDebuggerList();
974 DebuggerList::iterator pos, end = debugger_list.end();
975 for (pos = debugger_list.begin(); pos != end; ++pos)
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000976 {
Greg Claytonc15f55e2012-03-30 20:53:46 +0000977 if ((*pos).get()->GetID() == id)
978 {
979 debugger_sp = *pos;
980 break;
981 }
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000982 }
983 }
984 return debugger_sp;
985}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000986
Greg Clayton1b654882010-09-19 02:33:57 +0000987static void
988TestPromptFormats (StackFrame *frame)
989{
990 if (frame == NULL)
991 return;
992
993 StreamString s;
994 const char *prompt_format =
995 "{addr = '${addr}'\n}"
996 "{process.id = '${process.id}'\n}"
997 "{process.name = '${process.name}'\n}"
998 "{process.file.basename = '${process.file.basename}'\n}"
999 "{process.file.fullpath = '${process.file.fullpath}'\n}"
1000 "{thread.id = '${thread.id}'\n}"
1001 "{thread.index = '${thread.index}'\n}"
1002 "{thread.name = '${thread.name}'\n}"
1003 "{thread.queue = '${thread.queue}'\n}"
1004 "{thread.stop-reason = '${thread.stop-reason}'\n}"
1005 "{target.arch = '${target.arch}'\n}"
1006 "{module.file.basename = '${module.file.basename}'\n}"
1007 "{module.file.fullpath = '${module.file.fullpath}'\n}"
1008 "{file.basename = '${file.basename}'\n}"
1009 "{file.fullpath = '${file.fullpath}'\n}"
1010 "{frame.index = '${frame.index}'\n}"
1011 "{frame.pc = '${frame.pc}'\n}"
1012 "{frame.sp = '${frame.sp}'\n}"
1013 "{frame.fp = '${frame.fp}'\n}"
1014 "{frame.flags = '${frame.flags}'\n}"
1015 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
1016 "{frame.reg.rip = '${frame.reg.rip}'\n}"
1017 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
1018 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
1019 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
1020 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
1021 "{frame.reg.carp = '${frame.reg.carp}'\n}"
1022 "{function.id = '${function.id}'\n}"
1023 "{function.name = '${function.name}'\n}"
Greg Claytonccbc08e2012-01-14 17:04:19 +00001024 "{function.name-with-args = '${function.name-with-args}'\n}"
Greg Clayton1b654882010-09-19 02:33:57 +00001025 "{function.addr-offset = '${function.addr-offset}'\n}"
1026 "{function.line-offset = '${function.line-offset}'\n}"
1027 "{function.pc-offset = '${function.pc-offset}'\n}"
1028 "{line.file.basename = '${line.file.basename}'\n}"
1029 "{line.file.fullpath = '${line.file.fullpath}'\n}"
1030 "{line.number = '${line.number}'\n}"
1031 "{line.start-addr = '${line.start-addr}'\n}"
1032 "{line.end-addr = '${line.end-addr}'\n}"
1033;
1034
1035 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
1036 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +00001037 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +00001038 const char *end = NULL;
1039 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
1040 {
1041 printf("%s\n", s.GetData());
1042 }
1043 else
1044 {
1045 printf ("error: at '%s'\n", end);
1046 printf ("what we got: %s\n", s.GetData());
1047 }
1048}
1049
Enrico Granata9fc19442011-07-06 02:13:41 +00001050static bool
Enrico Granatadc940732011-08-23 00:32:52 +00001051ScanFormatDescriptor (const char* var_name_begin,
1052 const char* var_name_end,
1053 const char** var_name_final,
1054 const char** percent_position,
Greg Clayton4d122c42011-09-17 08:33:22 +00001055 Format* custom_format,
Enrico Granatadc940732011-08-23 00:32:52 +00001056 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
Enrico Granata9fc19442011-07-06 02:13:41 +00001057{
Enrico Granatae992a082011-07-22 17:03:19 +00001058 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +00001059 *percent_position = ::strchr(var_name_begin,'%');
Greg Clayton34132752011-07-06 04:07:21 +00001060 if (!*percent_position || *percent_position > var_name_end)
Enrico Granatae992a082011-07-22 17:03:19 +00001061 {
1062 if (log)
1063 log->Printf("no format descriptor in string, skipping");
Enrico Granata9fc19442011-07-06 02:13:41 +00001064 *var_name_final = var_name_end;
Enrico Granatae992a082011-07-22 17:03:19 +00001065 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001066 else
1067 {
1068 *var_name_final = *percent_position;
1069 char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0';
1070 memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1);
Enrico Granatae992a082011-07-22 17:03:19 +00001071 if (log)
1072 log->Printf("parsing %s as a format descriptor", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +00001073 if ( !FormatManager::GetFormatFromCString(format_name,
1074 true,
1075 *custom_format) )
1076 {
Enrico Granatae992a082011-07-22 17:03:19 +00001077 if (log)
1078 log->Printf("%s is an unknown format", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +00001079 // if this is an @ sign, print ObjC description
Greg Clayton34132752011-07-06 04:07:21 +00001080 if (*format_name == '@')
Enrico Granata86cc9822012-03-19 22:58:49 +00001081 *val_obj_display = ValueObject::eValueObjectRepresentationStyleLanguageSpecific;
Enrico Granata9fc19442011-07-06 02:13:41 +00001082 // if this is a V, print the value using the default format
Enrico Granatae992a082011-07-22 17:03:19 +00001083 else if (*format_name == 'V')
Enrico Granata86cc9822012-03-19 22:58:49 +00001084 *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Enrico Granatad55546b2011-07-22 00:16:08 +00001085 // if this is an L, print the location of the value
Enrico Granatae992a082011-07-22 17:03:19 +00001086 else if (*format_name == 'L')
Enrico Granata86cc9822012-03-19 22:58:49 +00001087 *val_obj_display = ValueObject::eValueObjectRepresentationStyleLocation;
Enrico Granatad55546b2011-07-22 00:16:08 +00001088 // if this is an S, print the summary after all
Enrico Granatae992a082011-07-22 17:03:19 +00001089 else if (*format_name == 'S')
Enrico Granata86cc9822012-03-19 22:58:49 +00001090 *val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary;
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001091 else if (*format_name == '#')
Enrico Granata86cc9822012-03-19 22:58:49 +00001092 *val_obj_display = ValueObject::eValueObjectRepresentationStyleChildrenCount;
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001093 else if (*format_name == 'T')
Enrico Granata86cc9822012-03-19 22:58:49 +00001094 *val_obj_display = ValueObject::eValueObjectRepresentationStyleType;
Enrico Granatae992a082011-07-22 17:03:19 +00001095 else if (log)
1096 log->Printf("%s is an error, leaving the previous value alone", format_name);
Enrico Granata9fc19442011-07-06 02:13:41 +00001097 }
1098 // a good custom format tells us to print the value using it
1099 else
Enrico Granatae992a082011-07-22 17:03:19 +00001100 {
1101 if (log)
1102 log->Printf("will display value for this VO");
Enrico Granata86cc9822012-03-19 22:58:49 +00001103 *val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Enrico Granatae992a082011-07-22 17:03:19 +00001104 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001105 delete format_name;
1106 }
Enrico Granatae992a082011-07-22 17:03:19 +00001107 if (log)
1108 log->Printf("final format description outcome: custom_format = %d, val_obj_display = %d",
1109 *custom_format,
1110 *val_obj_display);
Enrico Granata9fc19442011-07-06 02:13:41 +00001111 return true;
1112}
1113
1114static bool
Enrico Granatadc940732011-08-23 00:32:52 +00001115ScanBracketedRange (const char* var_name_begin,
1116 const char* var_name_end,
1117 const char* var_name_final,
1118 const char** open_bracket_position,
1119 const char** separator_position,
1120 const char** close_bracket_position,
1121 const char** var_name_final_if_array_range,
1122 int64_t* index_lower,
1123 int64_t* index_higher)
Enrico Granata9fc19442011-07-06 02:13:41 +00001124{
Enrico Granatae992a082011-07-22 17:03:19 +00001125 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata9fc19442011-07-06 02:13:41 +00001126 *open_bracket_position = ::strchr(var_name_begin,'[');
Greg Clayton34132752011-07-06 04:07:21 +00001127 if (*open_bracket_position && *open_bracket_position < var_name_final)
Enrico Granata9fc19442011-07-06 02:13:41 +00001128 {
1129 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
1130 *close_bracket_position = ::strchr(*open_bracket_position,']');
1131 // as usual, we assume that [] will come before %
1132 //printf("trying to expand a []\n");
1133 *var_name_final_if_array_range = *open_bracket_position;
Greg Clayton34132752011-07-06 04:07:21 +00001134 if (*close_bracket_position - *open_bracket_position == 1)
Enrico Granata9fc19442011-07-06 02:13:41 +00001135 {
Enrico Granatae992a082011-07-22 17:03:19 +00001136 if (log)
1137 log->Printf("[] detected.. going from 0 to end of data");
Enrico Granata9fc19442011-07-06 02:13:41 +00001138 *index_lower = 0;
1139 }
1140 else if (*separator_position == NULL || *separator_position > var_name_end)
1141 {
1142 char *end = NULL;
1143 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
1144 *index_higher = *index_lower;
Enrico Granatae992a082011-07-22 17:03:19 +00001145 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001146 log->Printf("[%lld] detected, high index is same", *index_lower);
Enrico Granata9fc19442011-07-06 02:13:41 +00001147 }
Greg Clayton34132752011-07-06 04:07:21 +00001148 else if (*close_bracket_position && *close_bracket_position < var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +00001149 {
1150 char *end = NULL;
1151 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
1152 *index_higher = ::strtoul (*separator_position+1, &end, 0);
Enrico Granatae992a082011-07-22 17:03:19 +00001153 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001154 log->Printf("[%lld-%lld] detected", *index_lower, *index_higher);
Enrico Granata9fc19442011-07-06 02:13:41 +00001155 }
1156 else
Enrico Granatae992a082011-07-22 17:03:19 +00001157 {
1158 if (log)
1159 log->Printf("expression is erroneous, cannot extract indices out of it");
Enrico Granata9fc19442011-07-06 02:13:41 +00001160 return false;
Enrico Granatae992a082011-07-22 17:03:19 +00001161 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001162 if (*index_lower > *index_higher && *index_higher > 0)
1163 {
Enrico Granatae992a082011-07-22 17:03:19 +00001164 if (log)
1165 log->Printf("swapping indices");
Enrico Granata9fc19442011-07-06 02:13:41 +00001166 int temp = *index_lower;
1167 *index_lower = *index_higher;
1168 *index_higher = temp;
1169 }
1170 }
Enrico Granatae992a082011-07-22 17:03:19 +00001171 else if (log)
1172 log->Printf("no bracketed range, skipping entirely");
Enrico Granata9fc19442011-07-06 02:13:41 +00001173 return true;
1174}
1175
Enrico Granata9fc19442011-07-06 02:13:41 +00001176static ValueObjectSP
Enrico Granatadc940732011-08-23 00:32:52 +00001177ExpandIndexedExpression (ValueObject* valobj,
1178 uint32_t index,
1179 StackFrame* frame,
1180 bool deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +00001181{
Enrico Granatae992a082011-07-22 17:03:19 +00001182 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001183 const char* ptr_deref_format = "[%d]";
1184 std::auto_ptr<char> ptr_deref_buffer(new char[10]);
1185 ::sprintf(ptr_deref_buffer.get(), ptr_deref_format, index);
Enrico Granatae992a082011-07-22 17:03:19 +00001186 if (log)
1187 log->Printf("name to deref: %s",ptr_deref_buffer.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001188 const char* first_unparsed;
1189 ValueObject::GetValueForExpressionPathOptions options;
1190 ValueObject::ExpressionPathEndResultType final_value_type;
1191 ValueObject::ExpressionPathScanEndReason reason_to_stop;
Enrico Granata86cc9822012-03-19 22:58:49 +00001192 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
Enrico Granatac482a192011-08-17 22:13:59 +00001193 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001194 &first_unparsed,
1195 &reason_to_stop,
1196 &final_value_type,
1197 options,
1198 &what_next);
1199 if (!item)
1200 {
Enrico Granatae992a082011-07-22 17:03:19 +00001201 if (log)
1202 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1203 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001204 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001205 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001206 else
1207 {
Enrico Granatae992a082011-07-22 17:03:19 +00001208 if (log)
1209 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1210 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001211 first_unparsed, reason_to_stop, final_value_type);
Enrico Granata9fc19442011-07-06 02:13:41 +00001212 }
1213 return item;
1214}
1215
Greg Clayton1b654882010-09-19 02:33:57 +00001216bool
1217Debugger::FormatPrompt
1218(
1219 const char *format,
1220 const SymbolContext *sc,
1221 const ExecutionContext *exe_ctx,
1222 const Address *addr,
1223 Stream &s,
Enrico Granata4becb372011-06-29 22:27:15 +00001224 const char **end,
Enrico Granatac482a192011-08-17 22:13:59 +00001225 ValueObject* valobj
Greg Clayton1b654882010-09-19 02:33:57 +00001226)
1227{
Enrico Granatac482a192011-08-17 22:13:59 +00001228 ValueObject* realvalobj = NULL; // makes it super-easy to parse pointers
Greg Clayton1b654882010-09-19 02:33:57 +00001229 bool success = true;
1230 const char *p;
Enrico Granatae992a082011-07-22 17:03:19 +00001231 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Greg Clayton1b654882010-09-19 02:33:57 +00001232 for (p = format; *p != '\0'; ++p)
1233 {
Enrico Granatac482a192011-08-17 22:13:59 +00001234 if (realvalobj)
Enrico Granata4becb372011-06-29 22:27:15 +00001235 {
Enrico Granatac482a192011-08-17 22:13:59 +00001236 valobj = realvalobj;
1237 realvalobj = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00001238 }
Greg Clayton1b654882010-09-19 02:33:57 +00001239 size_t non_special_chars = ::strcspn (p, "${}\\");
1240 if (non_special_chars > 0)
1241 {
1242 if (success)
1243 s.Write (p, non_special_chars);
1244 p += non_special_chars;
1245 }
1246
1247 if (*p == '\0')
1248 {
1249 break;
1250 }
1251 else if (*p == '{')
1252 {
1253 // Start a new scope that must have everything it needs if it is to
1254 // to make it into the final output stream "s". If you want to make
1255 // a format that only prints out the function or symbol name if there
1256 // is one in the symbol context you can use:
1257 // "{function =${function.name}}"
1258 // The first '{' starts a new scope that end with the matching '}' at
1259 // the end of the string. The contents "function =${function.name}"
1260 // will then be evaluated and only be output if there is a function
1261 // or symbol with a valid name.
1262 StreamString sub_strm;
1263
1264 ++p; // Skip the '{'
1265
Enrico Granatac482a192011-08-17 22:13:59 +00001266 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, valobj))
Greg Clayton1b654882010-09-19 02:33:57 +00001267 {
1268 // The stream had all it needed
1269 s.Write(sub_strm.GetData(), sub_strm.GetSize());
1270 }
1271 if (*p != '}')
1272 {
1273 success = false;
1274 break;
1275 }
1276 }
1277 else if (*p == '}')
1278 {
1279 // End of a enclosing scope
1280 break;
1281 }
1282 else if (*p == '$')
1283 {
1284 // We have a prompt variable to print
1285 ++p;
1286 if (*p == '{')
1287 {
1288 ++p;
1289 const char *var_name_begin = p;
1290 const char *var_name_end = ::strchr (p, '}');
1291
1292 if (var_name_end && var_name_begin < var_name_end)
1293 {
1294 // if we have already failed to parse, skip this variable
1295 if (success)
1296 {
1297 const char *cstr = NULL;
1298 Address format_addr;
1299 bool calculate_format_addr_function_offset = false;
1300 // Set reg_kind and reg_num to invalid values
1301 RegisterKind reg_kind = kNumRegisterKinds;
1302 uint32_t reg_num = LLDB_INVALID_REGNUM;
1303 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +00001304 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00001305 RegisterContext *reg_ctx = NULL;
Enrico Granata9fc19442011-07-06 02:13:41 +00001306 bool do_deref_pointer = false;
Enrico Granata86cc9822012-03-19 22:58:49 +00001307 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
1308 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001309
Greg Clayton1b654882010-09-19 02:33:57 +00001310 // Each variable must set success to true below...
1311 bool var_success = false;
1312 switch (var_name_begin[0])
1313 {
Enrico Granata4becb372011-06-29 22:27:15 +00001314 case '*':
Enrico Granata4becb372011-06-29 22:27:15 +00001315 case 'v':
Enrico Granata6f3533f2011-07-29 19:53:35 +00001316 case 's':
Enrico Granata4becb372011-06-29 22:27:15 +00001317 {
Enrico Granatac482a192011-08-17 22:13:59 +00001318 if (!valobj)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001319 break;
1320
Enrico Granatac3e320a2011-08-02 17:27:39 +00001321 if (log)
1322 log->Printf("initial string: %s",var_name_begin);
1323
Enrico Granata6f3533f2011-07-29 19:53:35 +00001324 // check for *var and *svar
1325 if (*var_name_begin == '*')
1326 {
1327 do_deref_pointer = true;
1328 var_name_begin++;
1329 }
Enrico Granatac3e320a2011-08-02 17:27:39 +00001330
1331 if (log)
1332 log->Printf("initial string: %s",var_name_begin);
1333
Enrico Granata6f3533f2011-07-29 19:53:35 +00001334 if (*var_name_begin == 's')
1335 {
Enrico Granatac5bc4122012-03-27 02:35:13 +00001336 if (!valobj->IsSynthetic())
1337 valobj = valobj->GetSyntheticValue().get();
Enrico Granata86cc9822012-03-19 22:58:49 +00001338 if (!valobj)
1339 break;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001340 var_name_begin++;
1341 }
1342
Enrico Granatac3e320a2011-08-02 17:27:39 +00001343 if (log)
1344 log->Printf("initial string: %s",var_name_begin);
1345
Enrico Granata6f3533f2011-07-29 19:53:35 +00001346 // should be a 'v' by now
1347 if (*var_name_begin != 'v')
1348 break;
1349
Enrico Granatac3e320a2011-08-02 17:27:39 +00001350 if (log)
1351 log->Printf("initial string: %s",var_name_begin);
1352
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001353 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
Enrico Granata86cc9822012-03-19 22:58:49 +00001354 ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001355 ValueObject::GetValueForExpressionPathOptions options;
Enrico Granata8c9d3562011-08-11 17:08:01 +00001356 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().DoAllowSyntheticChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001357 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eValueObjectRepresentationStyleSummary;
Greg Clayton34132752011-07-06 04:07:21 +00001358 ValueObject* target = NULL;
Greg Clayton4d122c42011-09-17 08:33:22 +00001359 Format custom_format = eFormatInvalid;
Greg Clayton34132752011-07-06 04:07:21 +00001360 const char* var_name_final = NULL;
1361 const char* var_name_final_if_array_range = NULL;
1362 const char* close_bracket_position = NULL;
1363 int64_t index_lower = -1;
1364 int64_t index_higher = -1;
1365 bool is_array_range = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001366 const char* first_unparsed;
Enrico Granata85933ed2011-08-18 16:38:26 +00001367 bool was_plain_var = false;
1368 bool was_var_format = false;
Enrico Granataa777dc22012-05-08 21:49:57 +00001369 bool was_var_indexed = false;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001370
Enrico Granatac482a192011-08-17 22:13:59 +00001371 if (!valobj) break;
1372 // simplest case ${var}, just print valobj's value
Greg Clayton34132752011-07-06 04:07:21 +00001373 if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0)
Enrico Granata4becb372011-06-29 22:27:15 +00001374 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001375 was_plain_var = true;
Enrico Granatac482a192011-08-17 22:13:59 +00001376 target = valobj;
Enrico Granata86cc9822012-03-19 22:58:49 +00001377 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Greg Clayton34132752011-07-06 04:07:21 +00001378 }
1379 else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0)
1380 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001381 was_var_format = true;
Greg Clayton34132752011-07-06 04:07:21 +00001382 // this is a variable with some custom format applied to it
1383 const char* percent_position;
Enrico Granatac482a192011-08-17 22:13:59 +00001384 target = valobj;
Enrico Granata86cc9822012-03-19 22:58:49 +00001385 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
Greg Clayton34132752011-07-06 04:07:21 +00001386 ScanFormatDescriptor (var_name_begin,
1387 var_name_end,
1388 &var_name_final,
1389 &percent_position,
1390 &custom_format,
1391 &val_obj_display);
1392 }
1393 // this is ${var.something} or multiple .something nested
1394 else if (::strncmp (var_name_begin, "var", strlen("var")) == 0)
1395 {
Enrico Granataa777dc22012-05-08 21:49:57 +00001396 if (::strncmp(var_name_begin, "var[", strlen("var[")) == 0)
1397 was_var_indexed = true;
Greg Clayton34132752011-07-06 04:07:21 +00001398 const char* percent_position;
1399 ScanFormatDescriptor (var_name_begin,
1400 var_name_end,
1401 &var_name_final,
1402 &percent_position,
1403 &custom_format,
1404 &val_obj_display);
1405
1406 const char* open_bracket_position;
1407 const char* separator_position;
1408 ScanBracketedRange (var_name_begin,
1409 var_name_end,
1410 var_name_final,
1411 &open_bracket_position,
1412 &separator_position,
1413 &close_bracket_position,
1414 &var_name_final_if_array_range,
1415 &index_lower,
1416 &index_higher);
1417
1418 Error error;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001419
1420 std::auto_ptr<char> expr_path(new char[var_name_final-var_name_begin-1]);
1421 ::memset(expr_path.get(), 0, var_name_final-var_name_begin-1);
1422 memcpy(expr_path.get(), var_name_begin+3,var_name_final-var_name_begin-3);
1423
Enrico Granatae992a082011-07-22 17:03:19 +00001424 if (log)
1425 log->Printf("symbol to expand: %s",expr_path.get());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001426
Enrico Granatac482a192011-08-17 22:13:59 +00001427 target = valobj->GetValueForExpressionPath(expr_path.get(),
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001428 &first_unparsed,
1429 &reason_to_stop,
1430 &final_value_type,
1431 options,
1432 &what_next).get();
1433
1434 if (!target)
Enrico Granata9fc19442011-07-06 02:13:41 +00001435 {
Enrico Granatae992a082011-07-22 17:03:19 +00001436 if (log)
1437 log->Printf("ERROR: unparsed portion = %s, why stopping = %d,"
1438 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001439 first_unparsed, reason_to_stop, final_value_type);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001440 break;
Enrico Granata9fc19442011-07-06 02:13:41 +00001441 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001442 else
1443 {
Enrico Granatae992a082011-07-22 17:03:19 +00001444 if (log)
1445 log->Printf("ALL RIGHT: unparsed portion = %s, why stopping = %d,"
1446 " final_value_type %d",
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001447 first_unparsed, reason_to_stop, final_value_type);
1448 }
Enrico Granata4becb372011-06-29 22:27:15 +00001449 }
Greg Clayton34132752011-07-06 04:07:21 +00001450 else
Enrico Granata9fc19442011-07-06 02:13:41 +00001451 break;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001452
Enrico Granata86cc9822012-03-19 22:58:49 +00001453 is_array_range = (final_value_type == ValueObject::eExpressionPathEndResultTypeBoundedRange ||
1454 final_value_type == ValueObject::eExpressionPathEndResultTypeUnboundedRange);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001455
Enrico Granata86cc9822012-03-19 22:58:49 +00001456 do_deref_pointer = (what_next == ValueObject::eExpressionPathAftermathDereference);
Enrico Granata9fc19442011-07-06 02:13:41 +00001457
Enrico Granataa7187d02011-07-06 19:27:11 +00001458 if (do_deref_pointer && !is_array_range)
Enrico Granata9fc19442011-07-06 02:13:41 +00001459 {
Greg Clayton34132752011-07-06 04:07:21 +00001460 // I have not deref-ed yet, let's do it
1461 // this happens when we are not going through GetValueForVariableExpressionPath
1462 // to get to the target ValueObject
Enrico Granata9fc19442011-07-06 02:13:41 +00001463 Error error;
Greg Clayton34132752011-07-06 04:07:21 +00001464 target = target->Dereference(error).get();
Enrico Granatadc940732011-08-23 00:32:52 +00001465 if (error.Fail())
1466 {
1467 if (log)
1468 log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
1469 break;
1470 }
Greg Clayton34132752011-07-06 04:07:21 +00001471 do_deref_pointer = false;
Enrico Granata9fc19442011-07-06 02:13:41 +00001472 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001473
Enrico Granataa777dc22012-05-08 21:49:57 +00001474 // <rdar://problem/11338654>
1475 // we do not want to use the summary for a bitfield of type T:n
1476 // if we were originally dealing with just a T - that would get
1477 // us into an endless recursion
1478 if (target->IsBitfield() && was_var_indexed)
1479 {
1480 // TODO: check for a (T:n)-specific summary - we should still obey that
1481 StreamString bitfield_name;
1482 bitfield_name.Printf("%s:%d", target->GetTypeName().AsCString(), target->GetBitfieldBitSize());
1483 lldb::TypeNameSpecifierImplSP type_sp(new TypeNameSpecifierImpl(bitfield_name.GetData(),false));
1484 if (!DataVisualization::GetSummaryForType(type_sp))
1485 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
1486 }
1487
Enrico Granata85933ed2011-08-18 16:38:26 +00001488 // TODO use flags for these
Enrico Granataf4efecd2011-07-12 22:56:10 +00001489 bool is_array = ClangASTContext::IsArrayType(target->GetClangType());
1490 bool is_pointer = ClangASTContext::IsPointerType(target->GetClangType());
Enrico Granata85933ed2011-08-18 16:38:26 +00001491 bool is_aggregate = ClangASTContext::IsAggregateType(target->GetClangType());
Enrico Granataf4efecd2011-07-12 22:56:10 +00001492
Enrico Granata86cc9822012-03-19 22:58:49 +00001493 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 +00001494 {
Enrico Granata85933ed2011-08-18 16:38:26 +00001495 StreamString str_temp;
Enrico Granatae992a082011-07-22 17:03:19 +00001496 if (log)
1497 log->Printf("I am into array || pointer && !range");
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001498
Enrico Granata86cc9822012-03-19 22:58:49 +00001499 if (target->HasSpecialPrintableRepresentation(val_obj_display,
1500 custom_format))
Enrico Granata85933ed2011-08-18 16:38:26 +00001501 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001502 // try to use the special cases
1503 var_success = target->DumpPrintableRepresentation(str_temp,
1504 val_obj_display,
1505 custom_format);
1506 if (log)
1507 log->Printf("special cases did%s match", var_success ? "" : "n't");
1508
1509 // should not happen
1510 if (!var_success)
1511 s << "<invalid usage of pointer value as object>";
1512 else
1513 s << str_temp.GetData();
Enrico Granata85933ed2011-08-18 16:38:26 +00001514 var_success = true;
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001515 break;
Enrico Granata85933ed2011-08-18 16:38:26 +00001516 }
1517 else
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001518 {
Enrico Granata88da35f2011-08-23 21:26:09 +00001519 if (was_plain_var) // if ${var}
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001520 {
1521 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1522 }
Enrico Granata88da35f2011-08-23 21:26:09 +00001523 else if (is_pointer) // if pointer, value is the address stored
1524 {
Greg Clayton23f59502012-07-17 03:23:13 +00001525 target->DumpPrintableRepresentation (s,
1526 val_obj_display,
1527 custom_format,
1528 ValueObject::ePrintableRepresentationSpecialCasesDisable);
Enrico Granata88da35f2011-08-23 21:26:09 +00001529 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001530 else
1531 {
1532 s << "<invalid usage of pointer value as object>";
1533 }
1534 var_success = true;
1535 break;
1536 }
1537 }
1538
1539 // if directly trying to print ${var}, and this is an aggregate, display a nice
1540 // type @ location message
1541 if (is_aggregate && was_plain_var)
1542 {
1543 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
1544 var_success = true;
Enrico Granata85933ed2011-08-18 16:38:26 +00001545 break;
1546 }
1547
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001548 // 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 +00001549 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)))
Enrico Granata85933ed2011-08-18 16:38:26 +00001550 {
1551 s << "<invalid use of aggregate type>";
1552 var_success = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001553 break;
1554 }
Greg Clayton34132752011-07-06 04:07:21 +00001555
1556 if (!is_array_range)
Enrico Granatae992a082011-07-22 17:03:19 +00001557 {
1558 if (log)
1559 log->Printf("dumping ordinary printable output");
Greg Clayton34132752011-07-06 04:07:21 +00001560 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
Enrico Granatae992a082011-07-22 17:03:19 +00001561 }
Greg Clayton34132752011-07-06 04:07:21 +00001562 else
Enrico Granatae992a082011-07-22 17:03:19 +00001563 {
1564 if (log)
1565 log->Printf("checking if I can handle as array");
Greg Clayton34132752011-07-06 04:07:21 +00001566 if (!is_array && !is_pointer)
1567 break;
Enrico Granatae992a082011-07-22 17:03:19 +00001568 if (log)
1569 log->Printf("handle as array");
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001570 const char* special_directions = NULL;
1571 StreamString special_directions_writer;
Greg Clayton34132752011-07-06 04:07:21 +00001572 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1573 {
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001574 ConstString additional_data;
1575 additional_data.SetCStringWithLength(close_bracket_position+1, var_name_end-close_bracket_position-1);
1576 special_directions_writer.Printf("${%svar%s}",
1577 do_deref_pointer ? "*" : "",
1578 additional_data.GetCString());
1579 special_directions = special_directions_writer.GetData();
Greg Clayton34132752011-07-06 04:07:21 +00001580 }
1581
1582 // let us display items index_lower thru index_higher of this array
1583 s.PutChar('[');
1584 var_success = true;
1585
1586 if (index_higher < 0)
Enrico Granatac482a192011-08-17 22:13:59 +00001587 index_higher = valobj->GetNumChildren() - 1;
Greg Clayton34132752011-07-06 04:07:21 +00001588
Greg Claytoncc4d0142012-02-17 07:49:44 +00001589 uint32_t max_num_children = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00001590
Greg Clayton34132752011-07-06 04:07:21 +00001591 for (;index_lower<=index_higher;index_lower++)
1592 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001593 ValueObject* item = ExpandIndexedExpression (target,
1594 index_lower,
1595 exe_ctx->GetFramePtr(),
1596 false).get();
Greg Clayton34132752011-07-06 04:07:21 +00001597
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001598 if (!item)
1599 {
Enrico Granatae992a082011-07-22 17:03:19 +00001600 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +00001601 log->Printf("ERROR in getting child item at index %lld", index_lower);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001602 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001603 else
1604 {
Enrico Granatae992a082011-07-22 17:03:19 +00001605 if (log)
1606 log->Printf("special_directions for child item: %s",special_directions);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001607 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001608
Greg Clayton34132752011-07-06 04:07:21 +00001609 if (!special_directions)
1610 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1611 else
1612 var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
1613
Enrico Granata22c55d12011-08-12 02:00:06 +00001614 if (--max_num_children == 0)
1615 {
1616 s.PutCString(", ...");
1617 break;
1618 }
1619
Greg Clayton34132752011-07-06 04:07:21 +00001620 if (index_lower < index_higher)
1621 s.PutChar(',');
1622 }
1623 s.PutChar(']');
1624 }
Enrico Granata4becb372011-06-29 22:27:15 +00001625 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001626 break;
Greg Clayton1b654882010-09-19 02:33:57 +00001627 case 'a':
1628 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
1629 {
1630 if (addr && addr->IsValid())
1631 {
1632 var_success = true;
1633 format_addr = *addr;
1634 }
1635 }
Greg Clayton5a314712011-10-14 07:41:33 +00001636 else if (::strncmp (var_name_begin, "ansi.", strlen("ansi.")) == 0)
1637 {
1638 var_success = true;
1639 var_name_begin += strlen("ansi."); // Skip the "ansi."
1640 if (::strncmp (var_name_begin, "fg.", strlen("fg.")) == 0)
1641 {
1642 var_name_begin += strlen("fg."); // Skip the "fg."
1643 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1644 {
1645 s.Printf ("%s%s%s",
1646 lldb_utility::ansi::k_escape_start,
1647 lldb_utility::ansi::k_fg_black,
1648 lldb_utility::ansi::k_escape_end);
1649 }
1650 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1651 {
1652 s.Printf ("%s%s%s",
1653 lldb_utility::ansi::k_escape_start,
1654 lldb_utility::ansi::k_fg_red,
1655 lldb_utility::ansi::k_escape_end);
1656 }
1657 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1658 {
1659 s.Printf ("%s%s%s",
1660 lldb_utility::ansi::k_escape_start,
1661 lldb_utility::ansi::k_fg_green,
1662 lldb_utility::ansi::k_escape_end);
1663 }
1664 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1665 {
1666 s.Printf ("%s%s%s",
1667 lldb_utility::ansi::k_escape_start,
1668 lldb_utility::ansi::k_fg_yellow,
1669 lldb_utility::ansi::k_escape_end);
1670 }
1671 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1672 {
1673 s.Printf ("%s%s%s",
1674 lldb_utility::ansi::k_escape_start,
1675 lldb_utility::ansi::k_fg_blue,
1676 lldb_utility::ansi::k_escape_end);
1677 }
1678 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1679 {
1680 s.Printf ("%s%s%s",
1681 lldb_utility::ansi::k_escape_start,
1682 lldb_utility::ansi::k_fg_purple,
1683 lldb_utility::ansi::k_escape_end);
1684 }
1685 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1686 {
1687 s.Printf ("%s%s%s",
1688 lldb_utility::ansi::k_escape_start,
1689 lldb_utility::ansi::k_fg_cyan,
1690 lldb_utility::ansi::k_escape_end);
1691 }
1692 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1693 {
1694 s.Printf ("%s%s%s",
1695 lldb_utility::ansi::k_escape_start,
1696 lldb_utility::ansi::k_fg_white,
1697 lldb_utility::ansi::k_escape_end);
1698 }
1699 else
1700 {
1701 var_success = false;
1702 }
1703 }
1704 else if (::strncmp (var_name_begin, "bg.", strlen("bg.")) == 0)
1705 {
1706 var_name_begin += strlen("bg."); // Skip the "bg."
1707 if (::strncmp (var_name_begin, "black}", strlen("black}")) == 0)
1708 {
1709 s.Printf ("%s%s%s",
1710 lldb_utility::ansi::k_escape_start,
1711 lldb_utility::ansi::k_bg_black,
1712 lldb_utility::ansi::k_escape_end);
1713 }
1714 else if (::strncmp (var_name_begin, "red}", strlen("red}")) == 0)
1715 {
1716 s.Printf ("%s%s%s",
1717 lldb_utility::ansi::k_escape_start,
1718 lldb_utility::ansi::k_bg_red,
1719 lldb_utility::ansi::k_escape_end);
1720 }
1721 else if (::strncmp (var_name_begin, "green}", strlen("green}")) == 0)
1722 {
1723 s.Printf ("%s%s%s",
1724 lldb_utility::ansi::k_escape_start,
1725 lldb_utility::ansi::k_bg_green,
1726 lldb_utility::ansi::k_escape_end);
1727 }
1728 else if (::strncmp (var_name_begin, "yellow}", strlen("yellow}")) == 0)
1729 {
1730 s.Printf ("%s%s%s",
1731 lldb_utility::ansi::k_escape_start,
1732 lldb_utility::ansi::k_bg_yellow,
1733 lldb_utility::ansi::k_escape_end);
1734 }
1735 else if (::strncmp (var_name_begin, "blue}", strlen("blue}")) == 0)
1736 {
1737 s.Printf ("%s%s%s",
1738 lldb_utility::ansi::k_escape_start,
1739 lldb_utility::ansi::k_bg_blue,
1740 lldb_utility::ansi::k_escape_end);
1741 }
1742 else if (::strncmp (var_name_begin, "purple}", strlen("purple}")) == 0)
1743 {
1744 s.Printf ("%s%s%s",
1745 lldb_utility::ansi::k_escape_start,
1746 lldb_utility::ansi::k_bg_purple,
1747 lldb_utility::ansi::k_escape_end);
1748 }
1749 else if (::strncmp (var_name_begin, "cyan}", strlen("cyan}")) == 0)
1750 {
1751 s.Printf ("%s%s%s",
1752 lldb_utility::ansi::k_escape_start,
1753 lldb_utility::ansi::k_bg_cyan,
1754 lldb_utility::ansi::k_escape_end);
1755 }
1756 else if (::strncmp (var_name_begin, "white}", strlen("white}")) == 0)
1757 {
1758 s.Printf ("%s%s%s",
1759 lldb_utility::ansi::k_escape_start,
1760 lldb_utility::ansi::k_bg_white,
1761 lldb_utility::ansi::k_escape_end);
1762 }
1763 else
1764 {
1765 var_success = false;
1766 }
1767 }
1768 else if (::strncmp (var_name_begin, "normal}", strlen ("normal}")) == 0)
1769 {
1770 s.Printf ("%s%s%s",
1771 lldb_utility::ansi::k_escape_start,
1772 lldb_utility::ansi::k_ctrl_normal,
1773 lldb_utility::ansi::k_escape_end);
1774 }
1775 else if (::strncmp (var_name_begin, "bold}", strlen("bold}")) == 0)
1776 {
1777 s.Printf ("%s%s%s",
1778 lldb_utility::ansi::k_escape_start,
1779 lldb_utility::ansi::k_ctrl_bold,
1780 lldb_utility::ansi::k_escape_end);
1781 }
1782 else if (::strncmp (var_name_begin, "faint}", strlen("faint}")) == 0)
1783 {
1784 s.Printf ("%s%s%s",
1785 lldb_utility::ansi::k_escape_start,
1786 lldb_utility::ansi::k_ctrl_faint,
1787 lldb_utility::ansi::k_escape_end);
1788 }
1789 else if (::strncmp (var_name_begin, "italic}", strlen("italic}")) == 0)
1790 {
1791 s.Printf ("%s%s%s",
1792 lldb_utility::ansi::k_escape_start,
1793 lldb_utility::ansi::k_ctrl_italic,
1794 lldb_utility::ansi::k_escape_end);
1795 }
1796 else if (::strncmp (var_name_begin, "underline}", strlen("underline}")) == 0)
1797 {
1798 s.Printf ("%s%s%s",
1799 lldb_utility::ansi::k_escape_start,
1800 lldb_utility::ansi::k_ctrl_underline,
1801 lldb_utility::ansi::k_escape_end);
1802 }
1803 else if (::strncmp (var_name_begin, "slow-blink}", strlen("slow-blink}")) == 0)
1804 {
1805 s.Printf ("%s%s%s",
1806 lldb_utility::ansi::k_escape_start,
1807 lldb_utility::ansi::k_ctrl_slow_blink,
1808 lldb_utility::ansi::k_escape_end);
1809 }
1810 else if (::strncmp (var_name_begin, "fast-blink}", strlen("fast-blink}")) == 0)
1811 {
1812 s.Printf ("%s%s%s",
1813 lldb_utility::ansi::k_escape_start,
1814 lldb_utility::ansi::k_ctrl_fast_blink,
1815 lldb_utility::ansi::k_escape_end);
1816 }
1817 else if (::strncmp (var_name_begin, "negative}", strlen("negative}")) == 0)
1818 {
1819 s.Printf ("%s%s%s",
1820 lldb_utility::ansi::k_escape_start,
1821 lldb_utility::ansi::k_ctrl_negative,
1822 lldb_utility::ansi::k_escape_end);
1823 }
1824 else if (::strncmp (var_name_begin, "conceal}", strlen("conceal}")) == 0)
1825 {
1826 s.Printf ("%s%s%s",
1827 lldb_utility::ansi::k_escape_start,
1828 lldb_utility::ansi::k_ctrl_conceal,
1829 lldb_utility::ansi::k_escape_end);
1830
1831 }
1832 else if (::strncmp (var_name_begin, "crossed-out}", strlen("crossed-out}")) == 0)
1833 {
1834 s.Printf ("%s%s%s",
1835 lldb_utility::ansi::k_escape_start,
1836 lldb_utility::ansi::k_ctrl_crossed_out,
1837 lldb_utility::ansi::k_escape_end);
1838 }
1839 else
1840 {
1841 var_success = false;
1842 }
1843 }
Greg Clayton1b654882010-09-19 02:33:57 +00001844 break;
1845
1846 case 'p':
1847 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
1848 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001849 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001850 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001851 Process *process = exe_ctx->GetProcessPtr();
1852 if (process)
Greg Clayton1b654882010-09-19 02:33:57 +00001853 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001854 var_name_begin += ::strlen ("process.");
1855 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001856 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001857 s.Printf("%llu", process->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001858 var_success = true;
1859 }
1860 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
1861 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
1862 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
1863 {
1864 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1865 if (exe_module)
Greg Clayton1b654882010-09-19 02:33:57 +00001866 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001867 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1868 {
1869 format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
1870 var_success = format_file_spec;
1871 }
1872 else
1873 {
1874 format_file_spec = exe_module->GetFileSpec();
1875 var_success = format_file_spec;
1876 }
Greg Clayton1b654882010-09-19 02:33:57 +00001877 }
1878 }
1879 }
Greg Claytonc14ee322011-09-22 04:58:26 +00001880 }
Greg Clayton1b654882010-09-19 02:33:57 +00001881 }
1882 break;
1883
1884 case 't':
1885 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
1886 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001887 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00001888 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001889 Thread *thread = exe_ctx->GetThreadPtr();
1890 if (thread)
Greg Clayton1b654882010-09-19 02:33:57 +00001891 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001892 var_name_begin += ::strlen ("thread.");
1893 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00001894 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001895 s.Printf("0x%4.4llx", thread->GetID());
Greg Claytonc14ee322011-09-22 04:58:26 +00001896 var_success = true;
1897 }
1898 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1899 {
1900 s.Printf("%u", thread->GetIndexID());
1901 var_success = true;
1902 }
1903 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1904 {
1905 cstr = thread->GetName();
1906 var_success = cstr && cstr[0];
1907 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001908 s.PutCString(cstr);
Greg Claytonc14ee322011-09-22 04:58:26 +00001909 }
1910 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
1911 {
1912 cstr = thread->GetQueueName();
1913 var_success = cstr && cstr[0];
1914 if (var_success)
1915 s.PutCString(cstr);
1916 }
1917 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
1918 {
1919 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1920 if (stop_info_sp)
1921 {
1922 cstr = stop_info_sp->GetDescription();
1923 if (cstr && cstr[0])
1924 {
1925 s.PutCString(cstr);
1926 var_success = true;
1927 }
Greg Clayton1b654882010-09-19 02:33:57 +00001928 }
1929 }
Jim Ingham73ca05a2011-12-17 01:35:57 +00001930 else if (::strncmp (var_name_begin, "return-value}", strlen("return-value}")) == 0)
1931 {
1932 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1933 if (stop_info_sp)
1934 {
1935 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1936 if (return_valobj_sp)
1937 {
Jim Inghamef651602011-12-22 19:12:40 +00001938 ValueObject::DumpValueObjectOptions dump_options;
1939 ValueObject::DumpValueObject (s, return_valobj_sp.get(), dump_options);
1940 var_success = true;
Jim Ingham73ca05a2011-12-17 01:35:57 +00001941 }
1942 }
1943 }
Greg Clayton1b654882010-09-19 02:33:57 +00001944 }
1945 }
1946 }
1947 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
1948 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001949 // TODO: hookup properties
1950// if (!target_properties_sp)
1951// {
1952// Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1953// if (target)
1954// target_properties_sp = target->GetProperties();
1955// }
1956//
1957// if (target_properties_sp)
1958// {
1959// var_name_begin += ::strlen ("target.");
1960// const char *end_property = strchr(var_name_begin, '}');
1961// if (end_property)
1962// {
1963// ConstString property_name(var_name_begin, end_property - var_name_begin);
1964// std::string property_value (target_properties_sp->GetPropertyValue(property_name));
1965// if (!property_value.empty())
1966// {
1967// s.PutCString (property_value.c_str());
1968// var_success = true;
1969// }
1970// }
1971// }
Greg Clayton0603aa92010-10-04 01:05:56 +00001972 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1973 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +00001974 {
Greg Clayton1b654882010-09-19 02:33:57 +00001975 var_name_begin += ::strlen ("target.");
1976 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
1977 {
1978 ArchSpec arch (target->GetArchitecture ());
1979 if (arch.IsValid())
1980 {
Greg Clayton64195a22011-02-23 00:35:02 +00001981 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +00001982 var_success = true;
1983 }
1984 }
Greg Clayton67cc0632012-08-22 17:17:09 +00001985 }
Greg Clayton1b654882010-09-19 02:33:57 +00001986 }
1987 break;
1988
1989
1990 case 'm':
1991 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
1992 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001993 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +00001994 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001995 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +00001996 var_name_begin += ::strlen ("module.");
1997
1998 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1999 {
2000 if (module->GetFileSpec())
2001 {
2002 var_name_begin += ::strlen ("file.");
2003
2004 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
2005 {
2006 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
2007 var_success = format_file_spec;
2008 }
2009 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
2010 {
2011 format_file_spec = module->GetFileSpec();
2012 var_success = format_file_spec;
2013 }
2014 }
2015 }
2016 }
2017 }
2018 break;
2019
2020
2021 case 'f':
2022 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
2023 {
2024 if (sc && sc->comp_unit != NULL)
2025 {
2026 var_name_begin += ::strlen ("file.");
2027
2028 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
2029 {
2030 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
2031 var_success = format_file_spec;
2032 }
2033 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
2034 {
2035 format_file_spec = *sc->comp_unit;
2036 var_success = format_file_spec;
2037 }
2038 }
2039 }
2040 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
2041 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002042 if (exe_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00002043 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002044 StackFrame *frame = exe_ctx->GetFramePtr();
2045 if (frame)
Greg Clayton1b654882010-09-19 02:33:57 +00002046 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002047 var_name_begin += ::strlen ("frame.");
2048 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
Greg Clayton1b654882010-09-19 02:33:57 +00002049 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002050 s.Printf("%u", frame->GetFrameIndex());
2051 var_success = true;
2052 }
2053 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
2054 {
2055 reg_kind = eRegisterKindGeneric;
2056 reg_num = LLDB_REGNUM_GENERIC_PC;
2057 var_success = true;
2058 }
2059 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
2060 {
2061 reg_kind = eRegisterKindGeneric;
2062 reg_num = LLDB_REGNUM_GENERIC_SP;
2063 var_success = true;
2064 }
2065 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
2066 {
2067 reg_kind = eRegisterKindGeneric;
2068 reg_num = LLDB_REGNUM_GENERIC_FP;
2069 var_success = true;
2070 }
2071 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
2072 {
2073 reg_kind = eRegisterKindGeneric;
2074 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
2075 var_success = true;
2076 }
2077 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
2078 {
2079 reg_ctx = frame->GetRegisterContext().get();
2080 if (reg_ctx)
Greg Clayton1b654882010-09-19 02:33:57 +00002081 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002082 var_name_begin += ::strlen ("reg.");
2083 if (var_name_begin < var_name_end)
2084 {
2085 std::string reg_name (var_name_begin, var_name_end);
2086 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
2087 if (reg_info)
2088 var_success = true;
2089 }
Greg Clayton1b654882010-09-19 02:33:57 +00002090 }
2091 }
2092 }
2093 }
2094 }
2095 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
2096 {
2097 if (sc && (sc->function != NULL || sc->symbol != NULL))
2098 {
2099 var_name_begin += ::strlen ("function.");
2100 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
2101 {
2102 if (sc->function)
Greg Clayton81c22f62011-10-19 18:09:39 +00002103 s.Printf("function{0x%8.8llx}", sc->function->GetID());
Greg Clayton1b654882010-09-19 02:33:57 +00002104 else
2105 s.Printf("symbol[%u]", sc->symbol->GetID());
2106
2107 var_success = true;
2108 }
2109 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
2110 {
2111 if (sc->function)
2112 cstr = sc->function->GetName().AsCString (NULL);
2113 else if (sc->symbol)
2114 cstr = sc->symbol->GetName().AsCString (NULL);
2115 if (cstr)
2116 {
2117 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00002118
2119 if (sc->block)
2120 {
2121 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2122 if (inline_block)
2123 {
2124 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
2125 if (inline_info)
2126 {
2127 s.PutCString(" [inlined] ");
2128 inline_info->GetName().Dump(&s);
2129 }
2130 }
2131 }
Greg Clayton1b654882010-09-19 02:33:57 +00002132 var_success = true;
2133 }
2134 }
Greg Clayton6d3dbf52012-01-13 08:39:16 +00002135 else if (::strncmp (var_name_begin, "name-with-args}", strlen("name-with-args}")) == 0)
2136 {
2137 // Print the function name with arguments in it
2138
2139 if (sc->function)
2140 {
2141 var_success = true;
2142 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
2143 cstr = sc->function->GetName().AsCString (NULL);
2144 if (cstr)
2145 {
2146 const InlineFunctionInfo *inline_info = NULL;
2147 VariableListSP variable_list_sp;
2148 bool get_function_vars = true;
2149 if (sc->block)
2150 {
2151 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2152
2153 if (inline_block)
2154 {
2155 get_function_vars = false;
2156 inline_info = sc->block->GetInlinedFunctionInfo();
2157 if (inline_info)
2158 variable_list_sp = inline_block->GetBlockVariableList (true);
2159 }
2160 }
2161
2162 if (get_function_vars)
2163 {
2164 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
2165 }
2166
2167 if (inline_info)
2168 {
2169 s.PutCString (cstr);
2170 s.PutCString (" [inlined] ");
2171 cstr = inline_info->GetName().GetCString();
2172 }
2173
2174 VariableList args;
2175 if (variable_list_sp)
2176 {
2177 const size_t num_variables = variable_list_sp->GetSize();
2178 for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
2179 {
2180 VariableSP var_sp (variable_list_sp->GetVariableAtIndex(var_idx));
2181 if (var_sp->GetScope() == eValueTypeVariableArgument)
2182 args.AddVariable (var_sp);
2183 }
2184
2185 }
2186 if (args.GetSize() > 0)
2187 {
2188 const char *open_paren = strchr (cstr, '(');
2189 const char *close_paren = NULL;
2190 if (open_paren)
2191 close_paren = strchr (open_paren, ')');
2192
2193 if (open_paren)
2194 s.Write(cstr, open_paren - cstr + 1);
2195 else
2196 {
2197 s.PutCString (cstr);
2198 s.PutChar ('(');
2199 }
Greg Clayton5b6889b2012-01-18 21:56:18 +00002200 const size_t num_args = args.GetSize();
Greg Clayton6d3dbf52012-01-13 08:39:16 +00002201 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
2202 {
2203 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
2204 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
2205 const char *var_name = var_value_sp->GetName().GetCString();
2206 const char *var_value = var_value_sp->GetValueAsCString();
2207 if (var_value_sp->GetError().Success())
2208 {
2209 if (arg_idx > 0)
2210 s.PutCString (", ");
2211 s.Printf ("%s=%s", var_name, var_value);
2212 }
2213 }
2214
2215 if (close_paren)
2216 s.PutCString (close_paren);
2217 else
2218 s.PutChar(')');
2219
2220 }
2221 else
2222 {
2223 s.PutCString(cstr);
2224 }
2225 }
2226 }
2227 else if (sc->symbol)
2228 {
2229 cstr = sc->symbol->GetName().AsCString (NULL);
2230 if (cstr)
2231 {
2232 s.PutCString(cstr);
2233 var_success = true;
2234 }
2235 }
2236 }
Greg Clayton1b654882010-09-19 02:33:57 +00002237 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
2238 {
2239 var_success = addr != NULL;
2240 if (var_success)
2241 {
2242 format_addr = *addr;
2243 calculate_format_addr_function_offset = true;
2244 }
2245 }
2246 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
2247 {
2248 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
2249 if (var_success)
2250 {
2251 format_addr = sc->line_entry.range.GetBaseAddress();
2252 calculate_format_addr_function_offset = true;
2253 }
2254 }
2255 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
2256 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002257 StackFrame *frame = exe_ctx->GetFramePtr();
2258 var_success = frame != NULL;
Greg Clayton1b654882010-09-19 02:33:57 +00002259 if (var_success)
2260 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002261 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002262 calculate_format_addr_function_offset = true;
2263 }
2264 }
2265 }
2266 }
2267 break;
2268
2269 case 'l':
2270 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
2271 {
2272 if (sc && sc->line_entry.IsValid())
2273 {
2274 var_name_begin += ::strlen ("line.");
2275 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
2276 {
2277 var_name_begin += ::strlen ("file.");
2278
2279 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
2280 {
2281 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
2282 var_success = format_file_spec;
2283 }
2284 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
2285 {
2286 format_file_spec = sc->line_entry.file;
2287 var_success = format_file_spec;
2288 }
2289 }
2290 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
2291 {
2292 var_success = true;
2293 s.Printf("%u", sc->line_entry.line);
2294 }
2295 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
2296 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
2297 {
2298 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
2299 if (var_success)
2300 {
2301 format_addr = sc->line_entry.range.GetBaseAddress();
2302 if (var_name_begin[0] == 'e')
2303 format_addr.Slide (sc->line_entry.range.GetByteSize());
2304 }
2305 }
2306 }
2307 }
2308 break;
2309 }
2310
2311 if (var_success)
2312 {
2313 // If format addr is valid, then we need to print an address
2314 if (reg_num != LLDB_INVALID_REGNUM)
2315 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002316 StackFrame *frame = exe_ctx->GetFramePtr();
Greg Clayton1b654882010-09-19 02:33:57 +00002317 // We have a register value to display...
2318 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
2319 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002320 format_addr = frame->GetFrameCodeAddress();
Greg Clayton1b654882010-09-19 02:33:57 +00002321 }
2322 else
2323 {
2324 if (reg_ctx == NULL)
Greg Claytonc14ee322011-09-22 04:58:26 +00002325 reg_ctx = frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00002326
2327 if (reg_ctx)
2328 {
2329 if (reg_kind != kNumRegisterKinds)
2330 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
2331 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
2332 var_success = reg_info != NULL;
2333 }
2334 }
2335 }
2336
2337 if (reg_info != NULL)
2338 {
Greg Clayton7349bd92011-05-09 20:18:18 +00002339 RegisterValue reg_value;
2340 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
2341 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00002342 {
Greg Clayton9a8fa912011-05-15 04:12:07 +00002343 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
Greg Clayton1b654882010-09-19 02:33:57 +00002344 }
2345 }
2346
2347 if (format_file_spec)
2348 {
2349 s << format_file_spec;
2350 }
2351
2352 // If format addr is valid, then we need to print an address
2353 if (format_addr.IsValid())
2354 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002355 var_success = false;
2356
Greg Clayton1b654882010-09-19 02:33:57 +00002357 if (calculate_format_addr_function_offset)
2358 {
2359 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00002360
Greg Clayton0603aa92010-10-04 01:05:56 +00002361 if (sc)
2362 {
2363 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00002364 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002365 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00002366 if (sc->block)
2367 {
2368 // Check to make sure we aren't in an inline
2369 // function. If we are, use the inline block
2370 // range that contains "format_addr" since
2371 // blocks can be discontiguous.
2372 Block *inline_block = sc->block->GetContainingInlinedBlock ();
2373 AddressRange inline_range;
2374 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
2375 func_addr = inline_range.GetBaseAddress();
2376 }
2377 }
Greg Claytone7612132012-03-07 21:03:09 +00002378 else if (sc->symbol && sc->symbol->ValueIsAddress())
2379 func_addr = sc->symbol->GetAddress();
Greg Clayton0603aa92010-10-04 01:05:56 +00002380 }
2381
2382 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00002383 {
2384 if (func_addr.GetSection() == format_addr.GetSection())
2385 {
2386 addr_t func_file_addr = func_addr.GetFileAddress();
2387 addr_t addr_file_addr = format_addr.GetFileAddress();
2388 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002389 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00002390 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00002391 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002392 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00002393 }
2394 else
Greg Clayton0603aa92010-10-04 01:05:56 +00002395 {
2396 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
2397 if (target)
2398 {
2399 addr_t func_load_addr = func_addr.GetLoadAddress (target);
2400 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
2401 if (addr_load_addr > func_load_addr)
2402 s.Printf(" + %llu", addr_load_addr - func_load_addr);
2403 else if (addr_load_addr < func_load_addr)
2404 s.Printf(" - %llu", func_load_addr - addr_load_addr);
2405 var_success = true;
2406 }
2407 }
Greg Clayton1b654882010-09-19 02:33:57 +00002408 }
2409 }
2410 else
2411 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002412 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00002413 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00002414 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
2415 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00002416 if (vaddr == LLDB_INVALID_ADDRESS)
2417 vaddr = format_addr.GetFileAddress ();
2418
2419 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00002420 {
Greg Clayton514487e2011-02-15 21:59:32 +00002421 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00002422 if (addr_width == 0)
2423 addr_width = 16;
2424 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00002425 var_success = true;
2426 }
Greg Clayton1b654882010-09-19 02:33:57 +00002427 }
2428 }
2429 }
2430
2431 if (var_success == false)
2432 success = false;
2433 }
2434 p = var_name_end;
2435 }
2436 else
2437 break;
2438 }
2439 else
2440 {
2441 // We got a dollar sign with no '{' after it, it must just be a dollar sign
2442 s.PutChar(*p);
2443 }
2444 }
2445 else if (*p == '\\')
2446 {
2447 ++p; // skip the slash
2448 switch (*p)
2449 {
2450 case 'a': s.PutChar ('\a'); break;
2451 case 'b': s.PutChar ('\b'); break;
2452 case 'f': s.PutChar ('\f'); break;
2453 case 'n': s.PutChar ('\n'); break;
2454 case 'r': s.PutChar ('\r'); break;
2455 case 't': s.PutChar ('\t'); break;
2456 case 'v': s.PutChar ('\v'); break;
2457 case '\'': s.PutChar ('\''); break;
2458 case '\\': s.PutChar ('\\'); break;
2459 case '0':
2460 // 1 to 3 octal chars
2461 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002462 // Make a string that can hold onto the initial zero char,
2463 // up to 3 octal digits, and a terminating NULL.
2464 char oct_str[5] = { 0, 0, 0, 0, 0 };
2465
2466 int i;
2467 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
2468 oct_str[i] = p[i];
2469
2470 // We don't want to consume the last octal character since
2471 // the main for loop will do this for us, so we advance p by
2472 // one less than i (even if i is zero)
2473 p += i - 1;
2474 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2475 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002476 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002477 char octal_char = octal_value;
2478 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00002479 }
Greg Clayton1b654882010-09-19 02:33:57 +00002480 }
2481 break;
2482
2483 case 'x':
2484 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00002485 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002486 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002487 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00002488
Greg Clayton0603aa92010-10-04 01:05:56 +00002489 // Make a string that can hold onto two hex chars plus a
2490 // NULL terminator
2491 char hex_str[3] = { 0,0,0 };
2492 hex_str[0] = *p;
2493 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00002494 {
Greg Clayton0603aa92010-10-04 01:05:56 +00002495 ++p; // Skip the first of the two hex chars
2496 hex_str[1] = *p;
2497 }
2498
2499 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2500 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00002501 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00002502 }
2503 else
2504 {
2505 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00002506 }
2507 break;
2508
2509 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00002510 // Just desensitize any other character by just printing what
2511 // came after the '\'
2512 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00002513 break;
2514
2515 }
2516
2517 }
2518 }
2519 if (end)
2520 *end = p;
2521 return success;
2522}
2523
Jim Ingham228063c2012-02-21 02:23:08 +00002524void
2525Debugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
2526{
Jim Ingham4f02b222012-02-22 22:49:20 +00002527 // For simplicity's sake, I am not going to deal with how to close down any
2528 // open logging streams, I just redirect everything from here on out to the
2529 // callback.
Jim Ingham228063c2012-02-21 02:23:08 +00002530 m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
2531}
2532
2533bool
2534Debugger::EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream)
2535{
2536 Log::Callbacks log_callbacks;
2537
2538 StreamSP log_stream_sp;
Sean Callanan9a028512012-08-09 00:50:26 +00002539 if (m_log_callback_stream_sp)
Jim Ingham228063c2012-02-21 02:23:08 +00002540 {
2541 log_stream_sp = m_log_callback_stream_sp;
2542 // For now when using the callback mode you always get thread & timestamp.
2543 log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
2544 }
2545 else if (log_file == NULL || *log_file == '\0')
2546 {
2547 log_stream_sp.reset(new StreamFile(GetOutputFile().GetDescriptor(), false));
2548 }
2549 else
2550 {
2551 LogStreamMap::iterator pos = m_log_streams.find(log_file);
2552 if (pos == m_log_streams.end())
2553 {
2554 log_stream_sp.reset (new StreamFile (log_file));
2555 m_log_streams[log_file] = log_stream_sp;
2556 }
2557 else
2558 log_stream_sp = pos->second;
2559 }
2560 assert (log_stream_sp.get());
2561
2562 if (log_options == 0)
2563 log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
2564
2565 if (Log::GetLogChannelCallbacks (channel, log_callbacks))
2566 {
2567 log_callbacks.enable (log_stream_sp, log_options, categories, &error_stream);
2568 return true;
2569 }
2570 else
2571 {
2572 LogChannelSP log_channel_sp (LogChannel::FindPlugin (channel));
2573 if (log_channel_sp)
2574 {
2575 if (log_channel_sp->Enable (log_stream_sp, log_options, &error_stream, categories))
2576 {
2577 return true;
2578 }
2579 else
2580 {
2581 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
2582 return false;
2583 }
2584 }
2585 else
2586 {
2587 error_stream.Printf ("Invalid log channel '%s'.\n", channel);
2588 return false;
2589 }
2590 }
2591 return false;
2592}
2593
Greg Clayton1b654882010-09-19 02:33:57 +00002594#pragma mark Debugger::SettingsController
2595
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002596//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002597// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002598//--------------------------------------------------
2599
Greg Clayton67cc0632012-08-22 17:17:09 +00002600//Debugger::SettingsController::SettingsController () :
2601// UserSettingsController ("", UserSettingsControllerSP())
2602//{
2603//}
2604//
2605//Debugger::SettingsController::~SettingsController ()
2606//{
2607//}
2608//
2609//
2610//InstanceSettingsSP
2611//Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
2612//{
2613// InstanceSettingsSP new_settings_sp (new DebuggerInstanceSettings (GetSettingsController(),
2614// false,
2615// instance_name));
2616// return new_settings_sp;
2617//}
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002618
Greg Clayton1b654882010-09-19 02:33:57 +00002619#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002620//--------------------------------------------------
2621// class DebuggerInstanceSettings
2622//--------------------------------------------------
2623
Greg Clayton67cc0632012-08-22 17:17:09 +00002624//DebuggerInstanceSettings::DebuggerInstanceSettings
2625//(
2626// const UserSettingsControllerSP &m_owner_sp,
2627// bool live_instance,
2628// const char *name
2629//) :
2630// InstanceSettings (m_owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
2631// m_term_width (80),
2632// m_stop_source_before_count (3),
2633// m_stop_source_after_count (3),
2634// m_stop_disassembly_count (4),
2635// m_stop_disassembly_display (eStopDisassemblyTypeNoSource),
2636// m_prompt (),
2637// m_frame_format (),
2638// m_thread_format (),
2639// m_script_lang (),
2640// m_use_external_editor (false),
2641// m_auto_confirm_on (false)
2642//{
2643// // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2644// // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
2645// // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
2646// // The same is true of CreateInstanceName().
2647//
2648// if (GetInstanceName() == InstanceSettings::InvalidName())
2649// {
2650// ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
2651// m_owner_sp->RegisterInstanceSettings (this);
2652// }
2653//
2654// if (live_instance)
2655// {
2656// const InstanceSettingsSP &pending_settings = m_owner_sp->FindPendingSettings (m_instance_name);
2657// CopyInstanceSettings (pending_settings, false);
2658// }
2659//}
2660//
2661//DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
2662// InstanceSettings (Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
2663// m_prompt (rhs.m_prompt),
2664// m_frame_format (rhs.m_frame_format),
2665// m_thread_format (rhs.m_thread_format),
2666// m_script_lang (rhs.m_script_lang),
2667// m_use_external_editor (rhs.m_use_external_editor),
2668// m_auto_confirm_on(rhs.m_auto_confirm_on)
2669//{
2670// UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2671// if (owner_sp)
2672// {
2673// CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
2674// owner_sp->RemovePendingSettings (m_instance_name);
2675// }
2676//}
2677//
2678//DebuggerInstanceSettings::~DebuggerInstanceSettings ()
2679//{
2680//}
2681//
2682//DebuggerInstanceSettings&
2683//DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
2684//{
2685// if (this != &rhs)
2686// {
2687// m_term_width = rhs.m_term_width;
2688// m_prompt = rhs.m_prompt;
2689// m_frame_format = rhs.m_frame_format;
2690// m_thread_format = rhs.m_thread_format;
2691// m_script_lang = rhs.m_script_lang;
2692// m_use_external_editor = rhs.m_use_external_editor;
2693// m_auto_confirm_on = rhs.m_auto_confirm_on;
2694// }
2695//
2696// return *this;
2697//}
2698//
2699//bool
2700//DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
2701//{
2702// bool valid = false;
2703//
2704// // Verify we have a value string.
2705// if (value == NULL || value[0] == '\0')
2706// {
2707// err.SetErrorString ("missing value, can't set terminal width without a value");
2708// }
2709// else
2710// {
2711// char *end = NULL;
2712// const uint32_t width = ::strtoul (value, &end, 0);
2713//
2714// if (end && end[0] == '\0')
2715// {
2716// return ValidTermWidthValue (width, err);
2717// }
2718// else
2719// err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value);
2720// }
2721//
2722// return valid;
2723//}
2724//
2725//bool
2726//DebuggerInstanceSettings::ValidTermWidthValue (uint32_t value, Error err)
2727//{
2728// if (value >= 10 && value <= 1024)
2729// return true;
2730// else
2731// {
2732// err.SetErrorString ("invalid term-width value; value must be between 10 and 1024");
2733// return false;
2734// }
2735//}
2736//
2737//void
2738//DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2739// const char *index_value,
2740// const char *value,
2741// const ConstString &instance_name,
2742// const SettingEntry &entry,
2743// VarSetOperationType op,
2744// Error &err,
2745// bool pending)
2746//{
2747//
2748// if (var_name == TermWidthVarName())
2749// {
2750// if (ValidTermWidthValue (value, err))
2751// {
2752// m_term_width = ::strtoul (value, NULL, 0);
2753// }
2754// }
2755// else if (var_name == PromptVarName())
2756// {
2757// UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
2758// if (!pending)
2759// {
2760// // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2761// // strip off the brackets before passing it to BroadcastPromptChange.
2762//
2763// std::string tmp_instance_name (instance_name.AsCString());
2764// if ((tmp_instance_name[0] == '[')
2765// && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
2766// tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
2767// ConstString new_name (tmp_instance_name.c_str());
2768//
2769// BroadcastPromptChange (new_name, m_prompt.c_str());
2770// }
2771// }
2772// else if (var_name == GetFrameFormatName())
2773// {
2774// UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
2775// }
2776// else if (var_name == GetThreadFormatName())
2777// {
2778// UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
2779// }
2780// else if (var_name == ScriptLangVarName())
2781// {
2782// bool success;
2783// m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
2784// &success);
2785// }
2786// else if (var_name == UseExternalEditorVarName ())
2787// {
2788// UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
2789// }
2790// else if (var_name == AutoConfirmName ())
2791// {
2792// UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
2793// }
2794// else if (var_name == StopSourceContextBeforeName ())
2795// {
2796// uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2797// if (new_value != UINT32_MAX)
2798// m_stop_source_before_count = new_value;
2799// else
2800// err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextBeforeName ().GetCString());
2801// }
2802// else if (var_name == StopSourceContextAfterName ())
2803// {
2804// uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2805// if (new_value != UINT32_MAX)
2806// m_stop_source_after_count = new_value;
2807// else
2808// err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextAfterName ().GetCString());
2809// }
2810// else if (var_name == StopDisassemblyCountName ())
2811// {
2812// uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
2813// if (new_value != UINT32_MAX)
2814// m_stop_disassembly_count = new_value;
2815// else
2816// err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopDisassemblyCountName ().GetCString());
2817// }
2818// else if (var_name == StopDisassemblyDisplayName ())
2819// {
2820// int new_value;
2821// UserSettingsController::UpdateEnumVariable (g_show_disassembly_enum_values, &new_value, value, err);
2822// if (err.Success())
2823// m_stop_disassembly_display = (StopDisassemblyType)new_value;
2824// }
2825//}
2826//
2827//bool
2828//DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2829// const ConstString &var_name,
2830// StringList &value,
2831// Error *err)
2832//{
2833// if (var_name == PromptVarName())
2834// {
2835// value.AppendString (m_prompt.c_str(), m_prompt.size());
2836//
2837// }
2838// else if (var_name == ScriptLangVarName())
2839// {
2840// value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
2841// }
2842// else if (var_name == TermWidthVarName())
2843// {
2844// StreamString width_str;
2845// width_str.Printf ("%u", m_term_width);
2846// value.AppendString (width_str.GetData());
2847// }
2848// else if (var_name == GetFrameFormatName ())
2849// {
2850// value.AppendString(m_frame_format.c_str(), m_frame_format.size());
2851// }
2852// else if (var_name == GetThreadFormatName ())
2853// {
2854// value.AppendString(m_thread_format.c_str(), m_thread_format.size());
2855// }
2856// else if (var_name == UseExternalEditorVarName())
2857// {
2858// if (m_use_external_editor)
2859// value.AppendString ("true");
2860// else
2861// value.AppendString ("false");
2862// }
2863// else if (var_name == AutoConfirmName())
2864// {
2865// if (m_auto_confirm_on)
2866// value.AppendString ("true");
2867// else
2868// value.AppendString ("false");
2869// }
2870// else if (var_name == StopSourceContextAfterName ())
2871// {
2872// StreamString strm;
2873// strm.Printf ("%u", m_stop_source_after_count);
2874// value.AppendString (strm.GetData());
2875// }
2876// else if (var_name == StopSourceContextBeforeName ())
2877// {
2878// StreamString strm;
2879// strm.Printf ("%u", m_stop_source_before_count);
2880// value.AppendString (strm.GetData());
2881// }
2882// else if (var_name == StopDisassemblyCountName ())
2883// {
2884// StreamString strm;
2885// strm.Printf ("%u", m_stop_disassembly_count);
2886// value.AppendString (strm.GetData());
2887// }
2888// else if (var_name == StopDisassemblyDisplayName ())
2889// {
2890// if (m_stop_disassembly_display >= eStopDisassemblyTypeNever && m_stop_disassembly_display <= eStopDisassemblyTypeAlways)
2891// value.AppendString (g_show_disassembly_enum_values[m_stop_disassembly_display].string_value);
2892// else
2893// value.AppendString ("<invalid>");
2894// }
2895// else
2896// {
2897// if (err)
2898// err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2899// return false;
2900// }
2901// return true;
2902//}
2903//
2904//void
2905//DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings,
2906// bool pending)
2907//{
2908// if (new_settings.get() == NULL)
2909// return;
2910//
2911// DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
2912//
2913// m_prompt = new_debugger_settings->m_prompt;
2914// if (!pending)
2915// {
2916// // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2917// // strip off the brackets before passing it to BroadcastPromptChange.
2918//
2919// std::string tmp_instance_name (m_instance_name.AsCString());
2920// if ((tmp_instance_name[0] == '[')
2921// && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
2922// tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
2923// ConstString new_name (tmp_instance_name.c_str());
2924//
2925// BroadcastPromptChange (new_name, m_prompt.c_str());
2926// }
2927// m_frame_format = new_debugger_settings->m_frame_format;
2928// m_thread_format = new_debugger_settings->m_thread_format;
2929// m_term_width = new_debugger_settings->m_term_width;
2930// m_script_lang = new_debugger_settings->m_script_lang;
2931// m_use_external_editor = new_debugger_settings->m_use_external_editor;
2932// m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
2933//}
2934//
2935//
2936//bool
2937//DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
2938//{
2939// std::string tmp_prompt;
2940//
2941// if (new_prompt != NULL)
2942// {
2943// tmp_prompt = new_prompt ;
2944// int len = tmp_prompt.size();
2945// if (len > 1
2946// && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
2947// && (tmp_prompt[len-1] == tmp_prompt[0]))
2948// {
2949// tmp_prompt = tmp_prompt.substr(1,len-2);
2950// }
2951// len = tmp_prompt.size();
2952// if (tmp_prompt[len-1] != ' ')
2953// tmp_prompt.append(" ");
2954// }
2955// EventSP new_event_sp;
2956// new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
2957// new EventDataBytes (tmp_prompt.c_str())));
2958//
2959// if (instance_name.GetLength() != 0)
2960// {
2961// // Set prompt for a particular instance.
2962// Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
2963// if (dbg != NULL)
2964// {
2965// dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
2966// }
2967// }
2968//
2969// return true;
2970//}
2971//
2972//const ConstString
2973//DebuggerInstanceSettings::CreateInstanceName ()
2974//{
2975// static int instance_count = 1;
2976// StreamString sstr;
2977//
2978// sstr.Printf ("debugger_%d", instance_count);
2979// ++instance_count;
2980//
2981// const ConstString ret_val (sstr.GetData());
2982//
2983// return ret_val;
2984//}
2985//
2986//
Caroline Tice9e41c152010-09-16 19:05:55 +00002987
Greg Clayton67cc0632012-08-22 17:17:09 +00002988//DebuggerInstanceSettings::DebuggerInstanceSettings
2989//(
2990// const UserSettingsControllerSP &m_owner_sp,
2991// bool live_instance,
2992// const char *name
2993//) :
2994// InstanceSettings (m_owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
2995// m_term_width (80),
2996// m_stop_source_before_count (3),
2997// m_stop_source_after_count (3),
2998// m_stop_disassembly_count (4),
2999// m_stop_disassembly_display (eStopDisassemblyTypeNoSource),
3000// m_prompt (),
3001// m_notify_void (false),
3002// m_frame_format (),
3003// m_thread_format (),
3004// m_script_lang (),
3005// m_use_external_editor (false),
3006// m_auto_confirm_on (false)
3007//{
3008// // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
3009// // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
3010// // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
3011// // The same is true of CreateInstanceName().
3012//
3013// if (GetInstanceName() == InstanceSettings::InvalidName())
3014// {
3015// ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
3016// m_owner_sp->RegisterInstanceSettings (this);
3017// }
3018//
3019// if (live_instance)
3020// {
3021// const InstanceSettingsSP &pending_settings = m_owner_sp->FindPendingSettings (m_instance_name);
3022// CopyInstanceSettings (pending_settings, false);
3023// }
3024//}
3025//
3026//DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
3027// InstanceSettings (Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
3028// m_prompt (rhs.m_prompt),
3029// m_notify_void (rhs.m_notify_void),
3030// m_frame_format (rhs.m_frame_format),
3031// m_thread_format (rhs.m_thread_format),
3032// m_script_lang (rhs.m_script_lang),
3033// m_use_external_editor (rhs.m_use_external_editor),
3034// m_auto_confirm_on(rhs.m_auto_confirm_on)
3035//{
3036// UserSettingsControllerSP owner_sp (m_owner_wp.lock());
3037// if (owner_sp)
3038// {
3039// CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
3040// owner_sp->RemovePendingSettings (m_instance_name);
3041// }
3042//}
3043//
3044//DebuggerInstanceSettings::~DebuggerInstanceSettings ()
3045//{
3046//}
3047//
3048//DebuggerInstanceSettings&
3049//DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
3050//{
3051// if (this != &rhs)
3052// {
3053// m_term_width = rhs.m_term_width;
3054// m_prompt = rhs.m_prompt;
3055// m_notify_void = rhs.m_notify_void;
3056// m_frame_format = rhs.m_frame_format;
3057// m_thread_format = rhs.m_thread_format;
3058// m_script_lang = rhs.m_script_lang;
3059// m_use_external_editor = rhs.m_use_external_editor;
3060// m_auto_confirm_on = rhs.m_auto_confirm_on;
3061// }
3062//
3063// return *this;
3064//}
3065//
3066//bool
3067//DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
3068//{
3069// bool valid = false;
3070//
3071// // Verify we have a value string.
3072// if (value == NULL || value[0] == '\0')
3073// {
3074// err.SetErrorString ("missing value, can't set terminal width without a value");
3075// }
3076// else
3077// {
3078// char *end = NULL;
3079// const uint32_t width = ::strtoul (value, &end, 0);
3080//
3081// if (end && end[0] == '\0')
3082// {
3083// return ValidTermWidthValue (width, err);
3084// }
3085// else
3086// err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string", value);
3087// }
3088//
3089// return valid;
3090//}
3091//
3092//bool
3093//DebuggerInstanceSettings::ValidTermWidthValue (uint32_t value, Error err)
3094//{
3095// if (value >= 10 && value <= 1024)
3096// return true;
3097// else
3098// {
3099// err.SetErrorString ("invalid term-width value; value must be between 10 and 1024");
3100// return false;
3101// }
3102//}
3103//
3104//void
3105//DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
3106// const char *index_value,
3107// const char *value,
3108// const ConstString &instance_name,
3109// const SettingEntry &entry,
3110// VarSetOperationType op,
3111// Error &err,
3112// bool pending)
3113//{
3114//
3115// if (var_name == TermWidthVarName())
3116// {
3117// if (ValidTermWidthValue (value, err))
3118// {
3119// m_term_width = ::strtoul (value, NULL, 0);
3120// }
3121// }
3122// else if (var_name == PromptVarName())
3123// {
3124// UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
3125// if (!pending)
3126// {
3127// // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
3128// // strip off the brackets before passing it to BroadcastPromptChange.
3129//
3130// std::string tmp_instance_name (instance_name.AsCString());
3131// if ((tmp_instance_name[0] == '[')
3132// && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
3133// tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
3134// ConstString new_name (tmp_instance_name.c_str());
3135//
3136// BroadcastPromptChange (new_name, m_prompt.c_str());
3137// }
3138// }
3139// else if (var_name == GetNotifyVoidName())
3140// {
3141// UserSettingsController::UpdateBooleanVariable (op, m_notify_void, value, false, err);
3142// }
3143// else if (var_name == GetFrameFormatName())
3144// {
3145// UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
3146// }
3147// else if (var_name == GetThreadFormatName())
3148// {
3149// UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
3150// }
3151// else if (var_name == ScriptLangVarName())
3152// {
3153// bool success;
3154// m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
3155// &success);
3156// }
3157// else if (var_name == UseExternalEditorVarName ())
3158// {
3159// UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
3160// }
3161// else if (var_name == AutoConfirmName ())
3162// {
3163// UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
3164// }
3165// else if (var_name == StopSourceContextBeforeName ())
3166// {
3167// uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
3168// if (new_value != UINT32_MAX)
3169// m_stop_source_before_count = new_value;
3170// else
3171// err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextBeforeName ().GetCString());
3172// }
3173// else if (var_name == StopSourceContextAfterName ())
3174// {
3175// uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
3176// if (new_value != UINT32_MAX)
3177// m_stop_source_after_count = new_value;
3178// else
3179// err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopSourceContextAfterName ().GetCString());
3180// }
3181// else if (var_name == StopDisassemblyCountName ())
3182// {
3183// uint32_t new_value = Args::StringToUInt32(value, UINT32_MAX, 10, NULL);
3184// if (new_value != UINT32_MAX)
3185// m_stop_disassembly_count = new_value;
3186// else
3187// err.SetErrorStringWithFormat("invalid unsigned string value '%s' for the '%s' setting", value, StopDisassemblyCountName ().GetCString());
3188// }
3189// else if (var_name == StopDisassemblyDisplayName ())
3190// {
3191// int new_value;
3192// UserSettingsController::UpdateEnumVariable (g_show_disassembly_enum_values, &new_value, value, err);
3193// if (err.Success())
3194// m_stop_disassembly_display = (StopDisassemblyType)new_value;
3195// }
3196//}
3197//
3198//bool
3199//DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
3200// const ConstString &var_name,
3201// StringList &value,
3202// Error *err)
3203//{
3204// if (var_name == PromptVarName())
3205// {
3206// value.AppendString (m_prompt.c_str(), m_prompt.size());
3207// }
3208// else if (var_name == GetNotifyVoidName())
3209// {
3210// value.AppendString (m_notify_void ? "true" : "false");
3211// }
3212// else if (var_name == ScriptLangVarName())
3213// {
3214// value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
3215// }
3216// else if (var_name == TermWidthVarName())
3217// {
3218// StreamString width_str;
3219// width_str.Printf ("%u", m_term_width);
3220// value.AppendString (width_str.GetData());
3221// }
3222// else if (var_name == GetFrameFormatName ())
3223// {
3224// value.AppendString(m_frame_format.c_str(), m_frame_format.size());
3225// }
3226// else if (var_name == GetThreadFormatName ())
3227// {
3228// value.AppendString(m_thread_format.c_str(), m_thread_format.size());
3229// }
3230// else if (var_name == UseExternalEditorVarName())
3231// {
3232// if (m_use_external_editor)
3233// value.AppendString ("true");
3234// else
3235// value.AppendString ("false");
3236// }
3237// else if (var_name == AutoConfirmName())
3238// {
3239// if (m_auto_confirm_on)
3240// value.AppendString ("true");
3241// else
3242// value.AppendString ("false");
3243// }
3244// else if (var_name == StopSourceContextAfterName ())
3245// {
3246// StreamString strm;
3247// strm.Printf ("%u", m_stop_source_after_count);
3248// value.AppendString (strm.GetData());
3249// }
3250// else if (var_name == StopSourceContextBeforeName ())
3251// {
3252// StreamString strm;
3253// strm.Printf ("%u", m_stop_source_before_count);
3254// value.AppendString (strm.GetData());
3255// }
3256// else if (var_name == StopDisassemblyCountName ())
3257// {
3258// StreamString strm;
3259// strm.Printf ("%u", m_stop_disassembly_count);
3260// value.AppendString (strm.GetData());
3261// }
3262// else if (var_name == StopDisassemblyDisplayName ())
3263// {
3264// if (m_stop_disassembly_display >= eStopDisassemblyTypeNever && m_stop_disassembly_display <= eStopDisassemblyTypeAlways)
3265// value.AppendString (g_show_disassembly_enum_values[m_stop_disassembly_display].string_value);
3266// else
3267// value.AppendString ("<invalid>");
3268// }
3269// else
3270// {
3271// if (err)
3272// err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
3273// return false;
3274// }
3275// return true;
3276//}
3277//
3278//void
3279//DebuggerInstanceSettings::CopyInstanceSettings (const InstanceSettingsSP &new_settings,
3280// bool pending)
3281//{
3282// if (new_settings.get() == NULL)
3283// return;
3284//
3285// DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
3286//
3287// m_prompt = new_debugger_settings->m_prompt;
3288// if (!pending)
3289// {
3290// // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
3291// // strip off the brackets before passing it to BroadcastPromptChange.
3292//
3293// std::string tmp_instance_name (m_instance_name.AsCString());
3294// if ((tmp_instance_name[0] == '[')
3295// && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
3296// tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
3297// ConstString new_name (tmp_instance_name.c_str());
3298//
3299// BroadcastPromptChange (new_name, m_prompt.c_str());
3300// }
3301// m_notify_void = new_debugger_settings->m_notify_void;
3302// m_frame_format = new_debugger_settings->m_frame_format;
3303// m_thread_format = new_debugger_settings->m_thread_format;
3304// m_term_width = new_debugger_settings->m_term_width;
3305// m_script_lang = new_debugger_settings->m_script_lang;
3306// m_use_external_editor = new_debugger_settings->m_use_external_editor;
3307// m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
3308//}
3309//
3310//
3311//bool
3312//DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
3313//{
3314// std::string tmp_prompt;
3315//
3316// if (new_prompt != NULL)
3317// {
3318// tmp_prompt = new_prompt ;
3319// int len = tmp_prompt.size();
3320// if (len > 1
3321// && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
3322// && (tmp_prompt[len-1] == tmp_prompt[0]))
3323// {
3324// tmp_prompt = tmp_prompt.substr(1,len-2);
3325// }
3326// len = tmp_prompt.size();
3327// if (tmp_prompt[len-1] != ' ')
3328// tmp_prompt.append(" ");
3329// }
3330// EventSP new_event_sp;
3331// new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
3332// new EventDataBytes (tmp_prompt.c_str())));
3333//
3334// if (instance_name.GetLength() != 0)
3335// {
3336// // Set prompt for a particular instance.
3337// Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
3338// if (dbg != NULL)
3339// {
3340// dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
3341// }
3342// }
3343//
3344// return true;
3345//}
3346//
3347//const ConstString
3348//DebuggerInstanceSettings::CreateInstanceName ()
3349//{
3350// static int instance_count = 1;
3351// StreamString sstr;
3352//
3353// sstr.Printf ("debugger_%d", instance_count);
3354// ++instance_count;
3355//
3356// const ConstString ret_val (sstr.GetData());
3357//
3358// return ret_val;
3359//}
3360//
Jim Ingham3bcdb292010-10-04 22:44:14 +00003361
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003362//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00003363// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003364//--------------------------------------------------
3365
Greg Clayton67cc0632012-08-22 17:17:09 +00003366//
3367//SettingEntry
3368//Debugger::SettingsController::global_settings_table[] =
3369//{
3370// //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
3371// // The Debugger level global table should always be empty; all Debugger settable variables should be instance
3372// // variables.
3373// { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
3374//};
Caroline Tice3df9a8d2010-09-04 00:03:46 +00003375
Greg Clayton67cc0632012-08-22 17:17:09 +00003376//SettingEntry
3377//Debugger::SettingsController::instance_settings_table[] =
3378//{
3379//// NAME Setting variable type Default Enum Init'd Hidden Help
3380//// ======================= ======================= ====================== ==== ====== ====== ======================
3381//{ "frame-format", eSetVarTypeString, DEFAULT_FRAME_FORMAT, NULL, false, false, "The default frame format string to use when displaying thread information." },
3382//{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
3383//{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
3384//{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
3385//{ "thread-format", eSetVarTypeString, DEFAULT_THREAD_FORMAT, NULL, false, false, "The default thread format string to use when displaying thread information." },
3386//{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
3387//{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
3388//{ "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." },
3389//{ "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." },
3390//{ "stop-disassembly-count", eSetVarTypeInt, "0", NULL, false, false, "The number of disassembly lines to show when displaying a stopped context." },
3391//{ "stop-disassembly-display", eSetVarTypeEnum, "no-source", g_show_disassembly_enum_values, false, false, "Control when to display disassembly when displaying a stopped context." },
3392//{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
3393//};