blob: f81173e2d9d791e359a320a374d4a2a40d1dde18 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Debugger.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Greg Clayton4a33d312011-06-23 17:59:56 +000010#include "lldb/Core/Debugger.h"
11
12#include <map>
13
Enrico Granata4becb372011-06-29 22:27:15 +000014#include "clang/AST/DeclCXX.h"
15#include "clang/AST/Type.h"
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/lldb-private.h"
18#include "lldb/Core/ConnectionFileDescriptor.h"
Greg Clayton4a33d312011-06-23 17:59:56 +000019#include "lldb/Core/FormatManager.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/InputReader.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000021#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/State.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000023#include "lldb/Core/StreamAsynchronousIO.h"
Greg Clayton1b654882010-09-19 02:33:57 +000024#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/Timer.h"
Enrico Granata4becb372011-06-29 22:27:15 +000026#include "lldb/Core/ValueObject.h"
Greg Claytona3406612011-02-07 23:24:47 +000027#include "lldb/Host/Terminal.h"
Greg Clayton66111032010-06-23 01:19:29 +000028#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Target/TargetList.h"
30#include "lldb/Target/Process.h"
Greg Clayton1b654882010-09-19 02:33:57 +000031#include "lldb/Target/RegisterContext.h"
32#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Target/Thread.h"
34
35
36using namespace lldb;
37using namespace lldb_private;
38
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039
Greg Clayton1b654882010-09-19 02:33:57 +000040static uint32_t g_shared_debugger_refcount = 0;
Caroline Ticeebc1bb22010-06-30 16:22:25 +000041static lldb::user_id_t g_unique_id = 1;
42
Greg Clayton1b654882010-09-19 02:33:57 +000043#pragma mark Static Functions
44
45static Mutex &
46GetDebuggerListMutex ()
47{
48 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
49 return g_mutex;
50}
51
52typedef std::vector<DebuggerSP> DebuggerList;
53
54static DebuggerList &
55GetDebuggerList()
56{
57 // hide the static debugger list inside a singleton accessor to avoid
58 // global init contructors
59 static DebuggerList g_list;
60 return g_list;
61}
62
63
64#pragma mark Debugger
65
Greg Clayton99d0faf2010-11-18 23:32:35 +000066UserSettingsControllerSP &
67Debugger::GetSettingsController ()
68{
69 static UserSettingsControllerSP g_settings_controller;
70 return g_settings_controller;
71}
72
Caroline Tice2f88aad2011-01-14 00:29:16 +000073int
74Debugger::TestDebuggerRefCount ()
75{
76 return g_shared_debugger_refcount;
77}
78
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079void
80Debugger::Initialize ()
81{
Greg Clayton66111032010-06-23 01:19:29 +000082 if (g_shared_debugger_refcount == 0)
Greg Clayton99d0faf2010-11-18 23:32:35 +000083 {
Greg Claytondbe54502010-11-19 03:46:01 +000084 lldb_private::Initialize();
Greg Clayton99d0faf2010-11-18 23:32:35 +000085 }
Greg Clayton66111032010-06-23 01:19:29 +000086 g_shared_debugger_refcount++;
Greg Clayton99d0faf2010-11-18 23:32:35 +000087
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088}
89
90void
91Debugger::Terminate ()
92{
Greg Clayton66111032010-06-23 01:19:29 +000093 if (g_shared_debugger_refcount > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094 {
Greg Clayton66111032010-06-23 01:19:29 +000095 g_shared_debugger_refcount--;
96 if (g_shared_debugger_refcount == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097 {
Greg Claytondbe54502010-11-19 03:46:01 +000098 lldb_private::WillTerminate();
99 lldb_private::Terminate();
Caroline Tice6760a512011-01-17 21:55:19 +0000100
101 // Clear our master list of debugger objects
102 Mutex::Locker locker (GetDebuggerListMutex ());
103 GetDebuggerList().clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105 }
106}
107
Caroline Tice20bd37f2011-03-10 22:14:10 +0000108void
109Debugger::SettingsInitialize ()
110{
111 static bool g_initialized = false;
112
113 if (!g_initialized)
114 {
115 g_initialized = true;
116 UserSettingsControllerSP &usc = GetSettingsController();
117 usc.reset (new SettingsController);
118 UserSettingsController::InitializeSettingsController (usc,
119 SettingsController::global_settings_table,
120 SettingsController::instance_settings_table);
121 // Now call SettingsInitialize for each settings 'child' of Debugger
122 Target::SettingsInitialize ();
123 }
124}
125
126void
127Debugger::SettingsTerminate ()
128{
129
130 // Must call SettingsTerminate() for each settings 'child' of Debugger, before terminating the Debugger's
131 // Settings.
132
133 Target::SettingsTerminate ();
134
135 // Now terminate the Debugger Settings.
136
137 UserSettingsControllerSP &usc = GetSettingsController();
138 UserSettingsController::FinalizeSettingsController (usc);
139 usc.reset();
140}
141
Greg Clayton66111032010-06-23 01:19:29 +0000142DebuggerSP
143Debugger::CreateInstance ()
144{
145 DebuggerSP debugger_sp (new Debugger);
146 // Scope for locker
147 {
148 Mutex::Locker locker (GetDebuggerListMutex ());
149 GetDebuggerList().push_back(debugger_sp);
150 }
151 return debugger_sp;
152}
153
Caroline Ticee02657b2011-01-22 01:02:07 +0000154void
155Debugger::Destroy (lldb::DebuggerSP &debugger_sp)
156{
157 if (debugger_sp.get() == NULL)
158 return;
159
160 Mutex::Locker locker (GetDebuggerListMutex ());
161 DebuggerList &debugger_list = GetDebuggerList ();
162 DebuggerList::iterator pos, end = debugger_list.end();
163 for (pos = debugger_list.begin (); pos != end; ++pos)
164 {
165 if ((*pos).get() == debugger_sp.get())
166 {
167 debugger_list.erase (pos);
168 return;
169 }
170 }
171
172}
173
Greg Clayton66111032010-06-23 01:19:29 +0000174lldb::DebuggerSP
175Debugger::GetSP ()
176{
177 lldb::DebuggerSP debugger_sp;
178
179 Mutex::Locker locker (GetDebuggerListMutex ());
180 DebuggerList &debugger_list = GetDebuggerList();
181 DebuggerList::iterator pos, end = debugger_list.end();
182 for (pos = debugger_list.begin(); pos != end; ++pos)
183 {
184 if ((*pos).get() == this)
185 {
186 debugger_sp = *pos;
187 break;
188 }
189 }
190 return debugger_sp;
191}
192
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000193lldb::DebuggerSP
194Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name)
195{
196 lldb::DebuggerSP debugger_sp;
197
198 Mutex::Locker locker (GetDebuggerListMutex ());
199 DebuggerList &debugger_list = GetDebuggerList();
200 DebuggerList::iterator pos, end = debugger_list.end();
201
202 for (pos = debugger_list.begin(); pos != end; ++pos)
203 {
204 if ((*pos).get()->m_instance_name == instance_name)
205 {
206 debugger_sp = *pos;
207 break;
208 }
209 }
210 return debugger_sp;
211}
Greg Clayton66111032010-06-23 01:19:29 +0000212
213TargetSP
214Debugger::FindTargetWithProcessID (lldb::pid_t pid)
215{
216 lldb::TargetSP target_sp;
217 Mutex::Locker locker (GetDebuggerListMutex ());
218 DebuggerList &debugger_list = GetDebuggerList();
219 DebuggerList::iterator pos, end = debugger_list.end();
220 for (pos = debugger_list.begin(); pos != end; ++pos)
221 {
222 target_sp = (*pos)->GetTargetList().FindTargetWithProcessID (pid);
223 if (target_sp)
224 break;
225 }
226 return target_sp;
227}
228
229
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230Debugger::Debugger () :
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000231 UserID (g_unique_id++),
Greg Claytondbe54502010-11-19 03:46:01 +0000232 DebuggerInstanceSettings (*GetSettingsController()),
Greg Claytond46c87a2010-12-04 02:39:47 +0000233 m_input_comm("debugger.input"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234 m_input_file (),
235 m_output_file (),
236 m_error_file (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237 m_target_list (),
Greg Claytonded470d2011-03-19 01:12:21 +0000238 m_platform_list (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000239 m_listener ("lldb.Debugger"),
240 m_source_manager (),
Greg Clayton66111032010-06-23 01:19:29 +0000241 m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000242 m_input_reader_stack (),
Greg Clayton4957bf62010-09-30 21:49:03 +0000243 m_input_reader_data ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244{
Greg Clayton66111032010-06-23 01:19:29 +0000245 m_command_interpreter_ap->Initialize ();
Greg Claytonded470d2011-03-19 01:12:21 +0000246 // Always add our default platform to the platform list
247 PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
248 assert (default_platform_sp.get());
249 m_platform_list.Append (default_platform_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250}
251
252Debugger::~Debugger ()
253{
Caroline Tice3d6086f2010-12-20 18:35:50 +0000254 CleanUpInputReaders();
Greg Clayton66111032010-06-23 01:19:29 +0000255 int num_targets = m_target_list.GetNumTargets();
256 for (int i = 0; i < num_targets; i++)
257 {
258 ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
259 if (process_sp)
260 process_sp->Destroy();
261 }
262 DisconnectInput();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263}
264
265
266bool
Greg Claytonfc3f0272011-05-29 04:06:55 +0000267Debugger::GetCloseInputOnEOF () const
268{
269 return m_input_comm.GetCloseOnEOF();
270}
271
272void
273Debugger::SetCloseInputOnEOF (bool b)
274{
275 m_input_comm.SetCloseOnEOF(b);
276}
277
278bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279Debugger::GetAsyncExecution ()
280{
Greg Clayton66111032010-06-23 01:19:29 +0000281 return !m_command_interpreter_ap->GetSynchronous();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282}
283
284void
285Debugger::SetAsyncExecution (bool async_execution)
286{
Greg Clayton66111032010-06-23 01:19:29 +0000287 m_command_interpreter_ap->SetSynchronous (!async_execution);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000288}
289
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290
291void
292Debugger::SetInputFileHandle (FILE *fh, bool tranfer_ownership)
293{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000294 File &in_file = GetInputFile();
295 in_file.SetStream (fh, tranfer_ownership);
296 if (in_file.IsValid() == false)
297 in_file.SetStream (stdin, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298
299 // Disconnect from any old connection if we had one
300 m_input_comm.Disconnect ();
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000301 m_input_comm.SetConnection (new ConnectionFileDescriptor (in_file.GetDescriptor(), true));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302 m_input_comm.SetReadThreadBytesReceivedCallback (Debugger::DispatchInputCallback, this);
303
304 Error error;
305 if (m_input_comm.StartReadThread (&error) == false)
306 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000307 File &err_file = GetErrorFile();
308
309 err_file.Printf ("error: failed to main input read thread: %s", error.AsCString() ? error.AsCString() : "unkown error");
310 exit(1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312}
313
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314void
315Debugger::SetOutputFileHandle (FILE *fh, bool tranfer_ownership)
316{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000317 File &out_file = GetOutputFile();
318 out_file.SetStream (fh, tranfer_ownership);
319 if (out_file.IsValid() == false)
320 out_file.SetStream (stdout, false);
Caroline Tice2f88aad2011-01-14 00:29:16 +0000321
322 GetCommandInterpreter().GetScriptInterpreter()->ResetOutputFileHandle (fh);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323}
324
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325void
326Debugger::SetErrorFileHandle (FILE *fh, bool tranfer_ownership)
327{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000328 File &err_file = GetErrorFile();
329 err_file.SetStream (fh, tranfer_ownership);
330 if (err_file.IsValid() == false)
331 err_file.SetStream (stderr, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332}
333
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000334ExecutionContext
Jim Ingham2976d002010-08-26 21:32:51 +0000335Debugger::GetSelectedExecutionContext ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336{
337 ExecutionContext exe_ctx;
338 exe_ctx.Clear();
339
Jim Ingham2976d002010-08-26 21:32:51 +0000340 lldb::TargetSP target_sp = GetSelectedTarget();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341 exe_ctx.target = target_sp.get();
342
343 if (target_sp)
344 {
345 exe_ctx.process = target_sp->GetProcessSP().get();
346 if (exe_ctx.process && exe_ctx.process->IsRunning() == false)
347 {
Jim Ingham2976d002010-08-26 21:32:51 +0000348 exe_ctx.thread = exe_ctx.process->GetThreadList().GetSelectedThread().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349 if (exe_ctx.thread == NULL)
350 exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
351 if (exe_ctx.thread)
352 {
Jim Ingham2976d002010-08-26 21:32:51 +0000353 exe_ctx.frame = exe_ctx.thread->GetSelectedFrame().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354 if (exe_ctx.frame == NULL)
355 exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex (0).get();
356 }
357 }
358 }
359 return exe_ctx;
360
361}
362
Caroline Ticeb44880c2011-02-10 01:15:13 +0000363InputReaderSP
364Debugger::GetCurrentInputReader ()
365{
366 InputReaderSP reader_sp;
367
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000368 if (!m_input_reader_stack.IsEmpty())
Caroline Ticeb44880c2011-02-10 01:15:13 +0000369 {
370 // Clear any finished readers from the stack
371 while (CheckIfTopInputReaderIsDone()) ;
372
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000373 if (!m_input_reader_stack.IsEmpty())
374 reader_sp = m_input_reader_stack.Top();
Caroline Ticeb44880c2011-02-10 01:15:13 +0000375 }
376
377 return reader_sp;
378}
379
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380void
381Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
382{
Caroline Ticeefed6132010-11-19 20:47:54 +0000383 if (bytes_len > 0)
384 ((Debugger *)baton)->DispatchInput ((char *)bytes, bytes_len);
385 else
386 ((Debugger *)baton)->DispatchInputEndOfFile ();
387}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388
389
390void
391Debugger::DispatchInput (const char *bytes, size_t bytes_len)
392{
Caroline Ticeefed6132010-11-19 20:47:54 +0000393 if (bytes == NULL || bytes_len == 0)
394 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395
396 WriteToDefaultReader (bytes, bytes_len);
397}
398
399void
Caroline Ticeefed6132010-11-19 20:47:54 +0000400Debugger::DispatchInputInterrupt ()
401{
402 m_input_reader_data.clear();
403
Caroline Ticeb44880c2011-02-10 01:15:13 +0000404 InputReaderSP reader_sp (GetCurrentInputReader ());
405 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000406 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000407 reader_sp->Notify (eInputReaderInterrupt);
Caroline Ticeefed6132010-11-19 20:47:54 +0000408
Caroline Ticeb44880c2011-02-10 01:15:13 +0000409 // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
Caroline Ticeefed6132010-11-19 20:47:54 +0000410 while (CheckIfTopInputReaderIsDone ()) ;
411 }
412}
413
414void
415Debugger::DispatchInputEndOfFile ()
416{
417 m_input_reader_data.clear();
418
Caroline Ticeb44880c2011-02-10 01:15:13 +0000419 InputReaderSP reader_sp (GetCurrentInputReader ());
420 if (reader_sp)
Caroline Ticeefed6132010-11-19 20:47:54 +0000421 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000422 reader_sp->Notify (eInputReaderEndOfFile);
Caroline Ticeefed6132010-11-19 20:47:54 +0000423
Caroline Ticeb44880c2011-02-10 01:15:13 +0000424 // 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 +0000425 while (CheckIfTopInputReaderIsDone ()) ;
426 }
427}
428
429void
Caroline Tice3d6086f2010-12-20 18:35:50 +0000430Debugger::CleanUpInputReaders ()
431{
432 m_input_reader_data.clear();
433
Caroline Ticeb44880c2011-02-10 01:15:13 +0000434 // 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 +0000435 while (m_input_reader_stack.GetSize() > 1)
Caroline Tice3d6086f2010-12-20 18:35:50 +0000436 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000437 InputReaderSP reader_sp (GetCurrentInputReader ());
Caroline Tice3d6086f2010-12-20 18:35:50 +0000438 if (reader_sp)
439 {
440 reader_sp->Notify (eInputReaderEndOfFile);
441 reader_sp->SetIsDone (true);
442 }
443 }
444}
445
446void
Caroline Tice969ed3d2011-05-02 20:41:46 +0000447Debugger::NotifyTopInputReader (InputReaderAction notification)
448{
449 InputReaderSP reader_sp (GetCurrentInputReader());
450 if (reader_sp)
451 {
452 reader_sp->Notify (notification);
453
454 // Flush out any input readers that are done.
455 while (CheckIfTopInputReaderIsDone ())
456 /* Do nothing. */;
457 }
458}
459
Caroline Tice9088b062011-05-09 23:06:58 +0000460bool
461Debugger::InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp)
462{
Caroline Ticed61c10b2011-06-16 16:27:19 +0000463 InputReaderSP top_reader_sp (GetCurrentInputReader());
Caroline Tice9088b062011-05-09 23:06:58 +0000464
Caroline Ticed61c10b2011-06-16 16:27:19 +0000465 return (reader_sp.get() == top_reader_sp.get());
Caroline Tice9088b062011-05-09 23:06:58 +0000466}
467
468
Caroline Tice969ed3d2011-05-02 20:41:46 +0000469void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len)
471{
472 if (bytes && bytes_len)
473 m_input_reader_data.append (bytes, bytes_len);
474
475 if (m_input_reader_data.empty())
476 return;
477
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000478 while (!m_input_reader_stack.IsEmpty() && !m_input_reader_data.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 // Get the input reader from the top of the stack
Caroline Ticeb44880c2011-02-10 01:15:13 +0000481 InputReaderSP reader_sp (GetCurrentInputReader ());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482 if (!reader_sp)
483 break;
484
Greg Clayton471b31c2010-07-20 22:52:08 +0000485 size_t bytes_handled = reader_sp->HandleRawBytes (m_input_reader_data.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486 m_input_reader_data.size());
487 if (bytes_handled)
488 {
489 m_input_reader_data.erase (0, bytes_handled);
490 }
491 else
492 {
493 // No bytes were handled, we might not have reached our
494 // granularity, just return and wait for more data
495 break;
496 }
497 }
498
Caroline Ticeb44880c2011-02-10 01:15:13 +0000499 // Flush out any input readers that are done.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500 while (CheckIfTopInputReaderIsDone ())
501 /* Do nothing. */;
502
503}
504
505void
506Debugger::PushInputReader (const InputReaderSP& reader_sp)
507{
508 if (!reader_sp)
509 return;
Caroline Ticeb44880c2011-02-10 01:15:13 +0000510
511 // Deactivate the old top reader
512 InputReaderSP top_reader_sp (GetCurrentInputReader ());
513
514 if (top_reader_sp)
515 top_reader_sp->Notify (eInputReaderDeactivate);
516
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000517 m_input_reader_stack.Push (reader_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518 reader_sp->Notify (eInputReaderActivate);
519 ActivateInputReader (reader_sp);
520}
521
522bool
523Debugger::PopInputReader (const lldb::InputReaderSP& pop_reader_sp)
524{
525 bool result = false;
526
527 // The reader on the stop of the stack is done, so let the next
528 // read on the stack referesh its prompt and if there is one...
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000529 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000531 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000532 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533
534 if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
535 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000536 m_input_reader_stack.Pop ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537 reader_sp->Notify (eInputReaderDeactivate);
538 reader_sp->Notify (eInputReaderDone);
539 result = true;
540
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000541 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 {
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000543 reader_sp = m_input_reader_stack.Top();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544 if (reader_sp)
545 {
546 ActivateInputReader (reader_sp);
547 reader_sp->Notify (eInputReaderReactivate);
548 }
549 }
550 }
551 }
552 return result;
553}
554
555bool
556Debugger::CheckIfTopInputReaderIsDone ()
557{
558 bool result = false;
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000559 if (!m_input_reader_stack.IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560 {
Caroline Ticeb44880c2011-02-10 01:15:13 +0000561 // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
Caroline Ticed5a0a01b2011-06-02 19:18:55 +0000562 InputReaderSP reader_sp(m_input_reader_stack.Top());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563
564 if (reader_sp && reader_sp->IsDone())
565 {
566 result = true;
567 PopInputReader (reader_sp);
568 }
569 }
570 return result;
571}
572
573void
574Debugger::ActivateInputReader (const InputReaderSP &reader_sp)
575{
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000576 int input_fd = m_input_file.GetFile().GetDescriptor();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000578 if (input_fd >= 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579 {
Greg Clayton51b1e2d2011-02-09 01:08:52 +0000580 Terminal tty(input_fd);
Greg Claytona3406612011-02-07 23:24:47 +0000581
582 tty.SetEcho(reader_sp->GetEcho());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583
Greg Claytona3406612011-02-07 23:24:47 +0000584 switch (reader_sp->GetGranularity())
585 {
586 case eInputReaderGranularityByte:
587 case eInputReaderGranularityWord:
588 tty.SetCanonical (false);
589 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000590
Greg Claytona3406612011-02-07 23:24:47 +0000591 case eInputReaderGranularityLine:
592 case eInputReaderGranularityAll:
593 tty.SetCanonical (true);
594 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595
Greg Claytona3406612011-02-07 23:24:47 +0000596 default:
597 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000598 }
599 }
600}
Greg Clayton66111032010-06-23 01:19:29 +0000601
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000602StreamSP
603Debugger::GetAsyncOutputStream ()
604{
605 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
606 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
607}
608
609StreamSP
610Debugger::GetAsyncErrorStream ()
611{
612 return StreamSP (new StreamAsynchronousIO (GetCommandInterpreter(),
613 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
614}
615
Caroline Ticeebc1bb22010-06-30 16:22:25 +0000616DebuggerSP
617Debugger::FindDebuggerWithID (lldb::user_id_t id)
618{
619 lldb::DebuggerSP debugger_sp;
620
621 Mutex::Locker locker (GetDebuggerListMutex ());
622 DebuggerList &debugger_list = GetDebuggerList();
623 DebuggerList::iterator pos, end = debugger_list.end();
624 for (pos = debugger_list.begin(); pos != end; ++pos)
625 {
626 if ((*pos).get()->GetID() == id)
627 {
628 debugger_sp = *pos;
629 break;
630 }
631 }
632 return debugger_sp;
633}
Caroline Tice3df9a8d2010-09-04 00:03:46 +0000634
Greg Clayton1b654882010-09-19 02:33:57 +0000635static void
636TestPromptFormats (StackFrame *frame)
637{
638 if (frame == NULL)
639 return;
640
641 StreamString s;
642 const char *prompt_format =
643 "{addr = '${addr}'\n}"
644 "{process.id = '${process.id}'\n}"
645 "{process.name = '${process.name}'\n}"
646 "{process.file.basename = '${process.file.basename}'\n}"
647 "{process.file.fullpath = '${process.file.fullpath}'\n}"
648 "{thread.id = '${thread.id}'\n}"
649 "{thread.index = '${thread.index}'\n}"
650 "{thread.name = '${thread.name}'\n}"
651 "{thread.queue = '${thread.queue}'\n}"
652 "{thread.stop-reason = '${thread.stop-reason}'\n}"
653 "{target.arch = '${target.arch}'\n}"
654 "{module.file.basename = '${module.file.basename}'\n}"
655 "{module.file.fullpath = '${module.file.fullpath}'\n}"
656 "{file.basename = '${file.basename}'\n}"
657 "{file.fullpath = '${file.fullpath}'\n}"
658 "{frame.index = '${frame.index}'\n}"
659 "{frame.pc = '${frame.pc}'\n}"
660 "{frame.sp = '${frame.sp}'\n}"
661 "{frame.fp = '${frame.fp}'\n}"
662 "{frame.flags = '${frame.flags}'\n}"
663 "{frame.reg.rdi = '${frame.reg.rdi}'\n}"
664 "{frame.reg.rip = '${frame.reg.rip}'\n}"
665 "{frame.reg.rsp = '${frame.reg.rsp}'\n}"
666 "{frame.reg.rbp = '${frame.reg.rbp}'\n}"
667 "{frame.reg.rflags = '${frame.reg.rflags}'\n}"
668 "{frame.reg.xmm0 = '${frame.reg.xmm0}'\n}"
669 "{frame.reg.carp = '${frame.reg.carp}'\n}"
670 "{function.id = '${function.id}'\n}"
671 "{function.name = '${function.name}'\n}"
672 "{function.addr-offset = '${function.addr-offset}'\n}"
673 "{function.line-offset = '${function.line-offset}'\n}"
674 "{function.pc-offset = '${function.pc-offset}'\n}"
675 "{line.file.basename = '${line.file.basename}'\n}"
676 "{line.file.fullpath = '${line.file.fullpath}'\n}"
677 "{line.number = '${line.number}'\n}"
678 "{line.start-addr = '${line.start-addr}'\n}"
679 "{line.end-addr = '${line.end-addr}'\n}"
680;
681
682 SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
683 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000684 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton1b654882010-09-19 02:33:57 +0000685 const char *end = NULL;
686 if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
687 {
688 printf("%s\n", s.GetData());
689 }
690 else
691 {
692 printf ("error: at '%s'\n", end);
693 printf ("what we got: %s\n", s.GetData());
694 }
695}
696
Enrico Granata9fc19442011-07-06 02:13:41 +0000697// #define VERBOSE_FORMATPROMPT_OUTPUT
698#ifdef VERBOSE_FORMATPROMPT_OUTPUT
699#define IFERROR_PRINT_IT if (error.Fail()) \
700{ \
701 printf("ERROR: %s\n",error.AsCString("unknown")); \
702 break; \
703}
704#else // IFERROR_PRINT_IT
705#define IFERROR_PRINT_IT if (error.Fail()) \
706break;
707#endif // IFERROR_PRINT_IT
708
709static bool
710ScanFormatDescriptor(const char* var_name_begin,
711 const char* var_name_end,
712 const char** var_name_final,
713 const char** percent_position,
714 lldb::Format* custom_format,
715 ValueObject::ValueObjectRepresentationStyle* val_obj_display)
716{
717 *percent_position = ::strchr(var_name_begin,'%');
Greg Clayton34132752011-07-06 04:07:21 +0000718 if (!*percent_position || *percent_position > var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +0000719 *var_name_final = var_name_end;
720 else
721 {
722 *var_name_final = *percent_position;
723 char* format_name = new char[var_name_end-*var_name_final]; format_name[var_name_end-*var_name_final-1] = '\0';
724 memcpy(format_name, *var_name_final+1, var_name_end-*var_name_final-1);
725 if ( !FormatManager::GetFormatFromCString(format_name,
726 true,
727 *custom_format) )
728 {
729 // if this is an @ sign, print ObjC description
Greg Clayton34132752011-07-06 04:07:21 +0000730 if (*format_name == '@')
Enrico Granata9fc19442011-07-06 02:13:41 +0000731 *val_obj_display = ValueObject::eDisplayLanguageSpecific;
732 // if this is a V, print the value using the default format
Greg Clayton34132752011-07-06 04:07:21 +0000733 if (*format_name == 'V')
Enrico Granata9fc19442011-07-06 02:13:41 +0000734 *val_obj_display = ValueObject::eDisplayValue;
735 }
736 // a good custom format tells us to print the value using it
737 else
738 *val_obj_display = ValueObject::eDisplayValue;
739 delete format_name;
740 }
741 return true;
742}
743
744static bool
745ScanBracketedRange(const char* var_name_begin,
746 const char* var_name_end,
747 const char* var_name_final,
748 const char** open_bracket_position,
749 const char** separator_position,
750 const char** close_bracket_position,
751 const char** var_name_final_if_array_range,
752 int64_t* index_lower,
753 int64_t* index_higher)
754{
755 *open_bracket_position = ::strchr(var_name_begin,'[');
Greg Clayton34132752011-07-06 04:07:21 +0000756 if (*open_bracket_position && *open_bracket_position < var_name_final)
Enrico Granata9fc19442011-07-06 02:13:41 +0000757 {
758 *separator_position = ::strchr(*open_bracket_position,'-'); // might be NULL if this is a simple var[N] bitfield
759 *close_bracket_position = ::strchr(*open_bracket_position,']');
760 // as usual, we assume that [] will come before %
761 //printf("trying to expand a []\n");
762 *var_name_final_if_array_range = *open_bracket_position;
Greg Clayton34132752011-07-06 04:07:21 +0000763 if (*close_bracket_position - *open_bracket_position == 1)
Enrico Granata9fc19442011-07-06 02:13:41 +0000764 {
765 *index_lower = 0;
766 }
767 else if (*separator_position == NULL || *separator_position > var_name_end)
768 {
769 char *end = NULL;
770 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
771 *index_higher = *index_lower;
772 //printf("got to read low=%d high same\n",bitfield_lower);
773 }
Greg Clayton34132752011-07-06 04:07:21 +0000774 else if (*close_bracket_position && *close_bracket_position < var_name_end)
Enrico Granata9fc19442011-07-06 02:13:41 +0000775 {
776 char *end = NULL;
777 *index_lower = ::strtoul (*open_bracket_position+1, &end, 0);
778 *index_higher = ::strtoul (*separator_position+1, &end, 0);
779 //printf("got to read low=%d high=%d\n",bitfield_lower,bitfield_higher);
780 }
781 else
782 return false;
783 if (*index_lower > *index_higher && *index_higher > 0)
784 {
785 int temp = *index_lower;
786 *index_lower = *index_higher;
787 *index_higher = temp;
788 }
789 }
790 return true;
791}
792
793
794static ValueObjectSP
795ExpandExpressionPath(ValueObject* vobj,
796 StackFrame* frame,
797 bool* do_deref_pointer,
798 const char* var_name_begin,
799 const char* var_name_final,
800 Error& error)
801{
802
803 StreamString sstring;
804 VariableSP var_sp;
805
Greg Clayton34132752011-07-06 04:07:21 +0000806 if (*do_deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +0000807 sstring.PutChar('*');
Greg Clayton34132752011-07-06 04:07:21 +0000808 else if (vobj->IsDereferenceOfParent() && ClangASTContext::IsPointerType(vobj->GetParent()->GetClangType()) && !vobj->IsArrayItemForPointer())
Enrico Granata9fc19442011-07-06 02:13:41 +0000809 {
810 sstring.PutChar('*');
811 *do_deref_pointer = true;
812 }
813
814 vobj->GetExpressionPath(sstring, true, ValueObject::eHonorPointers);
815#ifdef VERBOSE_FORMATPROMPT_OUTPUT
816 printf("name to expand in phase 0: %s\n",sstring.GetData());
817#endif //VERBOSE_FORMATPROMPT_OUTPUT
818 sstring.PutRawBytes(var_name_begin+3, var_name_final-var_name_begin-3);
819#ifdef VERBOSE_FORMATPROMPT_OUTPUT
820 printf("name to expand in phase 1: %s\n",sstring.GetData());
821#endif //VERBOSE_FORMATPROMPT_OUTPUT
822 std::string name = std::string(sstring.GetData());
823 ValueObjectSP target = frame->GetValueForVariableExpressionPath (name.c_str(),
824 eNoDynamicValues,
825 0,
826 var_sp,
827 error);
828 return target;
829}
830
831static ValueObjectSP
832ExpandIndexedExpression(ValueObject* vobj,
833 uint32_t index,
834 StackFrame* frame,
835 Error error)
836{
837 ValueObjectSP item;
838 bool is_array = ClangASTContext::IsArrayType(vobj->GetClangType());
839
Greg Clayton34132752011-07-06 04:07:21 +0000840 if (is_array)
Enrico Granata9fc19442011-07-06 02:13:41 +0000841 return vobj->GetChildAtIndex(index, true);
842 else
843 {
844 const char* ptr_deref_format = "%s[%d]";
845 char* ptr_deref_buffer = new char[1024];
846 StreamString expr_path_string;
847 vobj->GetExpressionPath(expr_path_string, true, ValueObject::eHonorPointers);
848 const char* expr_path = expr_path_string.GetData();
849#ifdef VERBOSE_FORMATPROMPT_OUTPUT
850 printf("name to deref in phase 0: %s\n",expr_path);
851#endif //VERBOSE_FORMATPROMPT_OUTPUT
852 ::sprintf(ptr_deref_buffer, ptr_deref_format, expr_path, index);
853#ifdef VERBOSE_FORMATPROMPT_OUTPUT
854 printf("name to deref in phase 1: %s\n",ptr_deref_buffer);
855#endif //VERBOSE_FORMATPROMPT_OUTPUT
856 lldb::VariableSP var_sp;
857 item = frame->GetValueForVariableExpressionPath (ptr_deref_buffer,
858 eNoDynamicValues,
859 0,
860 var_sp,
861 error);
862 delete ptr_deref_buffer;
863 }
864 return item;
865}
866
Greg Clayton1b654882010-09-19 02:33:57 +0000867bool
868Debugger::FormatPrompt
869(
870 const char *format,
871 const SymbolContext *sc,
872 const ExecutionContext *exe_ctx,
873 const Address *addr,
874 Stream &s,
Enrico Granata4becb372011-06-29 22:27:15 +0000875 const char **end,
876 ValueObject* vobj
Greg Clayton1b654882010-09-19 02:33:57 +0000877)
878{
Enrico Granata4becb372011-06-29 22:27:15 +0000879 ValueObject* realvobj = NULL; // makes it super-easy to parse pointers
Greg Clayton1b654882010-09-19 02:33:57 +0000880 bool success = true;
881 const char *p;
882 for (p = format; *p != '\0'; ++p)
883 {
Greg Clayton34132752011-07-06 04:07:21 +0000884 if (realvobj)
Enrico Granata4becb372011-06-29 22:27:15 +0000885 {
886 vobj = realvobj;
887 realvobj = NULL;
888 }
Greg Clayton1b654882010-09-19 02:33:57 +0000889 size_t non_special_chars = ::strcspn (p, "${}\\");
890 if (non_special_chars > 0)
891 {
892 if (success)
893 s.Write (p, non_special_chars);
894 p += non_special_chars;
895 }
896
897 if (*p == '\0')
898 {
899 break;
900 }
901 else if (*p == '{')
902 {
903 // Start a new scope that must have everything it needs if it is to
904 // to make it into the final output stream "s". If you want to make
905 // a format that only prints out the function or symbol name if there
906 // is one in the symbol context you can use:
907 // "{function =${function.name}}"
908 // The first '{' starts a new scope that end with the matching '}' at
909 // the end of the string. The contents "function =${function.name}"
910 // will then be evaluated and only be output if there is a function
911 // or symbol with a valid name.
912 StreamString sub_strm;
913
914 ++p; // Skip the '{'
915
Enrico Granata4becb372011-06-29 22:27:15 +0000916 if (FormatPrompt (p, sc, exe_ctx, addr, sub_strm, &p, vobj))
Greg Clayton1b654882010-09-19 02:33:57 +0000917 {
918 // The stream had all it needed
919 s.Write(sub_strm.GetData(), sub_strm.GetSize());
920 }
921 if (*p != '}')
922 {
923 success = false;
924 break;
925 }
926 }
927 else if (*p == '}')
928 {
929 // End of a enclosing scope
930 break;
931 }
932 else if (*p == '$')
933 {
934 // We have a prompt variable to print
935 ++p;
936 if (*p == '{')
937 {
938 ++p;
939 const char *var_name_begin = p;
940 const char *var_name_end = ::strchr (p, '}');
941
942 if (var_name_end && var_name_begin < var_name_end)
943 {
944 // if we have already failed to parse, skip this variable
945 if (success)
946 {
947 const char *cstr = NULL;
948 Address format_addr;
949 bool calculate_format_addr_function_offset = false;
950 // Set reg_kind and reg_num to invalid values
951 RegisterKind reg_kind = kNumRegisterKinds;
952 uint32_t reg_num = LLDB_INVALID_REGNUM;
953 FileSpec format_file_spec;
Greg Claytone0d378b2011-03-24 21:19:54 +0000954 const RegisterInfo *reg_info = NULL;
Greg Clayton1b654882010-09-19 02:33:57 +0000955 RegisterContext *reg_ctx = NULL;
Enrico Granata9fc19442011-07-06 02:13:41 +0000956 bool do_deref_pointer = false;
Greg Clayton1b654882010-09-19 02:33:57 +0000957
958 // Each variable must set success to true below...
959 bool var_success = false;
960 switch (var_name_begin[0])
961 {
Enrico Granata4becb372011-06-29 22:27:15 +0000962 case '*':
963 {
Greg Clayton34132752011-07-06 04:07:21 +0000964 if (!vobj)
965 break;
Enrico Granata9fc19442011-07-06 02:13:41 +0000966 do_deref_pointer = true;
967 var_name_begin++;
Enrico Granata4becb372011-06-29 22:27:15 +0000968 }
Greg Clayton34132752011-07-06 04:07:21 +0000969 // Fall through...
970
Enrico Granata4becb372011-06-29 22:27:15 +0000971 case 'v':
972 {
Greg Clayton34132752011-07-06 04:07:21 +0000973 ValueObject::ValueObjectRepresentationStyle val_obj_display = ValueObject::eDisplaySummary;
974 ValueObject* target = NULL;
975 lldb::Format custom_format = eFormatInvalid;
976 const char* var_name_final = NULL;
977 const char* var_name_final_if_array_range = NULL;
978 const char* close_bracket_position = NULL;
979 int64_t index_lower = -1;
980 int64_t index_higher = -1;
981 bool is_array_range = false;
982 if (!vobj) break;
983 // simplest case ${var}, just print vobj's value
984 if (::strncmp (var_name_begin, "var}", strlen("var}")) == 0)
Enrico Granata4becb372011-06-29 22:27:15 +0000985 {
Greg Clayton34132752011-07-06 04:07:21 +0000986 target = vobj;
987 val_obj_display = ValueObject::eDisplayValue;
988 }
989 else if (::strncmp(var_name_begin,"var%",strlen("var%")) == 0)
990 {
991 // this is a variable with some custom format applied to it
992 const char* percent_position;
993 target = vobj;
994 val_obj_display = ValueObject::eDisplayValue;
995 ScanFormatDescriptor (var_name_begin,
996 var_name_end,
997 &var_name_final,
998 &percent_position,
999 &custom_format,
1000 &val_obj_display);
1001 }
1002 // this is ${var.something} or multiple .something nested
1003 else if (::strncmp (var_name_begin, "var", strlen("var")) == 0)
1004 {
1005
1006 const char* percent_position;
1007 ScanFormatDescriptor (var_name_begin,
1008 var_name_end,
1009 &var_name_final,
1010 &percent_position,
1011 &custom_format,
1012 &val_obj_display);
1013
1014 const char* open_bracket_position;
1015 const char* separator_position;
1016 ScanBracketedRange (var_name_begin,
1017 var_name_end,
1018 var_name_final,
1019 &open_bracket_position,
1020 &separator_position,
1021 &close_bracket_position,
1022 &var_name_final_if_array_range,
1023 &index_lower,
1024 &index_higher);
1025
1026 Error error;
1027 target = ExpandExpressionPath (vobj,
1028 exe_ctx->frame,
1029 &do_deref_pointer,
1030 var_name_begin,
1031 var_name_final,
1032 error).get();
1033
1034 if (error.Fail() || !target)
Enrico Granata9fc19442011-07-06 02:13:41 +00001035 {
Greg Clayton34132752011-07-06 04:07:21 +00001036#ifdef VERBOSE_FORMATPROMPT_OUTPUT
1037 printf("ERROR: %s\n",error.AsCString("unknown"));
1038#endif //VERBOSE_FORMATPROMPT_OUTPUT
1039 if (var_name_final_if_array_range)
1040 {
1041 target = ExpandExpressionPath(vobj,
1042 exe_ctx->frame,
1043 &do_deref_pointer,
1044 var_name_begin,
1045 var_name_final_if_array_range,
1046 error).get();
1047 }
1048
1049 IFERROR_PRINT_IT
1050 else
1051 is_array_range = true;
Enrico Granata9fc19442011-07-06 02:13:41 +00001052 }
1053
Greg Clayton34132752011-07-06 04:07:21 +00001054 do_deref_pointer = false; // I have honored the request to deref
1055
Enrico Granata4becb372011-06-29 22:27:15 +00001056 }
Greg Clayton34132752011-07-06 04:07:21 +00001057 else
Enrico Granata9fc19442011-07-06 02:13:41 +00001058 break;
Enrico Granata9fc19442011-07-06 02:13:41 +00001059
Greg Clayton34132752011-07-06 04:07:21 +00001060 if (do_deref_pointer)
Enrico Granata9fc19442011-07-06 02:13:41 +00001061 {
Greg Clayton34132752011-07-06 04:07:21 +00001062 // I have not deref-ed yet, let's do it
1063 // this happens when we are not going through GetValueForVariableExpressionPath
1064 // to get to the target ValueObject
Enrico Granata9fc19442011-07-06 02:13:41 +00001065 Error error;
Greg Clayton34132752011-07-06 04:07:21 +00001066 target = target->Dereference(error).get();
Enrico Granata9fc19442011-07-06 02:13:41 +00001067 IFERROR_PRINT_IT
Greg Clayton34132752011-07-06 04:07:21 +00001068 do_deref_pointer = false;
Enrico Granata9fc19442011-07-06 02:13:41 +00001069 }
Greg Clayton34132752011-07-06 04:07:21 +00001070
1071 if (!is_array_range)
1072 var_success = target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1073 else
1074 {
1075 bool is_array = ClangASTContext::IsArrayType(vobj->GetClangType());
1076 bool is_pointer = ClangASTContext::IsPointerType(vobj->GetClangType());
1077
1078 if (!is_array && !is_pointer)
1079 break;
1080
1081 char* special_directions = NULL;
1082 if (close_bracket_position && (var_name_end-close_bracket_position > 1))
1083 {
1084 int base_len = var_name_end-close_bracket_position;
1085 special_directions = new char[8+base_len];
1086 special_directions[0] = '$';
1087 special_directions[1] = '{';
1088 special_directions[2] = 'v';
1089 special_directions[3] = 'a';
1090 special_directions[4] = 'r';
1091 memcpy(special_directions+5, close_bracket_position+1, base_len);
1092 special_directions[base_len+7] = '\0';
1093#ifdef VERBOSE_FORMATPROMPT_OUTPUT
1094 printf("%s\n",special_directions);
1095#endif //VERBOSE_FORMATPROMPT_OUTPUT
1096 }
1097
1098 // let us display items index_lower thru index_higher of this array
1099 s.PutChar('[');
1100 var_success = true;
1101
1102 if (index_higher < 0)
1103 index_higher = vobj->GetNumChildren() - 1;
1104
1105 for (;index_lower<=index_higher;index_lower++)
1106 {
1107 Error error;
1108 ValueObject* item = ExpandIndexedExpression(vobj,
1109 index_lower,
1110 exe_ctx->frame,
1111 error).get();
1112
1113
1114 IFERROR_PRINT_IT
1115 if (!special_directions)
1116 var_success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1117 else
1118 var_success &= FormatPrompt(special_directions, sc, exe_ctx, addr, s, NULL, item);
1119
1120 if (index_lower < index_higher)
1121 s.PutChar(',');
1122 }
1123 s.PutChar(']');
1124 }
Enrico Granata4becb372011-06-29 22:27:15 +00001125 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001126 break;
Greg Clayton1b654882010-09-19 02:33:57 +00001127 case 'a':
1128 if (::strncmp (var_name_begin, "addr}", strlen("addr}")) == 0)
1129 {
1130 if (addr && addr->IsValid())
1131 {
1132 var_success = true;
1133 format_addr = *addr;
1134 }
1135 }
1136 break;
1137
1138 case 'p':
1139 if (::strncmp (var_name_begin, "process.", strlen("process.")) == 0)
1140 {
1141 if (exe_ctx && exe_ctx->process != NULL)
1142 {
1143 var_name_begin += ::strlen ("process.");
1144 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1145 {
1146 s.Printf("%i", exe_ctx->process->GetID());
1147 var_success = true;
1148 }
1149 else if ((::strncmp (var_name_begin, "name}", strlen("name}")) == 0) ||
1150 (::strncmp (var_name_begin, "file.basename}", strlen("file.basename}")) == 0) ||
1151 (::strncmp (var_name_begin, "file.fullpath}", strlen("file.fullpath}")) == 0))
1152 {
1153 ModuleSP exe_module_sp (exe_ctx->process->GetTarget().GetExecutableModule());
1154 if (exe_module_sp)
1155 {
1156 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
1157 {
1158 format_file_spec.GetFilename() = exe_module_sp->GetFileSpec().GetFilename();
1159 var_success = format_file_spec;
1160 }
1161 else
1162 {
1163 format_file_spec = exe_module_sp->GetFileSpec();
1164 var_success = format_file_spec;
1165 }
1166 }
1167 }
1168 }
1169 }
1170 break;
1171
1172 case 't':
1173 if (::strncmp (var_name_begin, "thread.", strlen("thread.")) == 0)
1174 {
1175 if (exe_ctx && exe_ctx->thread)
1176 {
1177 var_name_begin += ::strlen ("thread.");
1178 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1179 {
1180 s.Printf("0x%4.4x", exe_ctx->thread->GetID());
1181 var_success = true;
1182 }
1183 else if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1184 {
1185 s.Printf("%u", exe_ctx->thread->GetIndexID());
1186 var_success = true;
1187 }
1188 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1189 {
1190 cstr = exe_ctx->thread->GetName();
1191 var_success = cstr && cstr[0];
1192 if (var_success)
1193 s.PutCString(cstr);
1194 }
1195 else if (::strncmp (var_name_begin, "queue}", strlen("queue}")) == 0)
1196 {
1197 cstr = exe_ctx->thread->GetQueueName();
1198 var_success = cstr && cstr[0];
1199 if (var_success)
1200 s.PutCString(cstr);
1201 }
1202 else if (::strncmp (var_name_begin, "stop-reason}", strlen("stop-reason}")) == 0)
1203 {
Jim Inghamb15bfc72010-10-20 00:39:53 +00001204 StopInfoSP stop_info_sp = exe_ctx->thread->GetStopInfo ();
1205 if (stop_info_sp)
Greg Clayton1b654882010-09-19 02:33:57 +00001206 {
Jim Inghamb15bfc72010-10-20 00:39:53 +00001207 cstr = stop_info_sp->GetDescription();
Greg Clayton1b654882010-09-19 02:33:57 +00001208 if (cstr && cstr[0])
1209 {
1210 s.PutCString(cstr);
1211 var_success = true;
1212 }
1213 }
1214 }
1215 }
1216 }
1217 else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
1218 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001219 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1220 if (target)
Greg Clayton1b654882010-09-19 02:33:57 +00001221 {
Greg Clayton1b654882010-09-19 02:33:57 +00001222 var_name_begin += ::strlen ("target.");
1223 if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
1224 {
1225 ArchSpec arch (target->GetArchitecture ());
1226 if (arch.IsValid())
1227 {
Greg Clayton64195a22011-02-23 00:35:02 +00001228 s.PutCString (arch.GetArchitectureName());
Greg Clayton1b654882010-09-19 02:33:57 +00001229 var_success = true;
1230 }
1231 }
1232 }
1233 }
1234 break;
1235
1236
1237 case 'm':
1238 if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
1239 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001240 if (sc && sc->module_sp.get())
Greg Clayton1b654882010-09-19 02:33:57 +00001241 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001242 Module *module = sc->module_sp.get();
Greg Clayton1b654882010-09-19 02:33:57 +00001243 var_name_begin += ::strlen ("module.");
1244
1245 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1246 {
1247 if (module->GetFileSpec())
1248 {
1249 var_name_begin += ::strlen ("file.");
1250
1251 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1252 {
1253 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
1254 var_success = format_file_spec;
1255 }
1256 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1257 {
1258 format_file_spec = module->GetFileSpec();
1259 var_success = format_file_spec;
1260 }
1261 }
1262 }
1263 }
1264 }
1265 break;
1266
1267
1268 case 'f':
1269 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1270 {
1271 if (sc && sc->comp_unit != NULL)
1272 {
1273 var_name_begin += ::strlen ("file.");
1274
1275 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1276 {
1277 format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
1278 var_success = format_file_spec;
1279 }
1280 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1281 {
1282 format_file_spec = *sc->comp_unit;
1283 var_success = format_file_spec;
1284 }
1285 }
1286 }
1287 else if (::strncmp (var_name_begin, "frame.", strlen("frame.")) == 0)
1288 {
1289 if (exe_ctx && exe_ctx->frame)
1290 {
1291 var_name_begin += ::strlen ("frame.");
1292 if (::strncmp (var_name_begin, "index}", strlen("index}")) == 0)
1293 {
1294 s.Printf("%u", exe_ctx->frame->GetFrameIndex());
1295 var_success = true;
1296 }
1297 else if (::strncmp (var_name_begin, "pc}", strlen("pc}")) == 0)
1298 {
1299 reg_kind = eRegisterKindGeneric;
1300 reg_num = LLDB_REGNUM_GENERIC_PC;
1301 var_success = true;
1302 }
1303 else if (::strncmp (var_name_begin, "sp}", strlen("sp}")) == 0)
1304 {
1305 reg_kind = eRegisterKindGeneric;
1306 reg_num = LLDB_REGNUM_GENERIC_SP;
1307 var_success = true;
1308 }
1309 else if (::strncmp (var_name_begin, "fp}", strlen("fp}")) == 0)
1310 {
1311 reg_kind = eRegisterKindGeneric;
1312 reg_num = LLDB_REGNUM_GENERIC_FP;
1313 var_success = true;
1314 }
1315 else if (::strncmp (var_name_begin, "flags}", strlen("flags}")) == 0)
1316 {
1317 reg_kind = eRegisterKindGeneric;
1318 reg_num = LLDB_REGNUM_GENERIC_FLAGS;
1319 var_success = true;
1320 }
1321 else if (::strncmp (var_name_begin, "reg.", strlen ("reg.")) == 0)
1322 {
Greg Clayton5ccbd292011-01-06 22:15:06 +00001323 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001324 if (reg_ctx)
1325 {
1326 var_name_begin += ::strlen ("reg.");
1327 if (var_name_begin < var_name_end)
1328 {
1329 std::string reg_name (var_name_begin, var_name_end);
1330 reg_info = reg_ctx->GetRegisterInfoByName (reg_name.c_str());
1331 if (reg_info)
1332 var_success = true;
1333 }
1334 }
1335 }
1336 }
1337 }
1338 else if (::strncmp (var_name_begin, "function.", strlen("function.")) == 0)
1339 {
1340 if (sc && (sc->function != NULL || sc->symbol != NULL))
1341 {
1342 var_name_begin += ::strlen ("function.");
1343 if (::strncmp (var_name_begin, "id}", strlen("id}")) == 0)
1344 {
1345 if (sc->function)
1346 s.Printf("function{0x%8.8x}", sc->function->GetID());
1347 else
1348 s.Printf("symbol[%u]", sc->symbol->GetID());
1349
1350 var_success = true;
1351 }
1352 else if (::strncmp (var_name_begin, "name}", strlen("name}")) == 0)
1353 {
1354 if (sc->function)
1355 cstr = sc->function->GetName().AsCString (NULL);
1356 else if (sc->symbol)
1357 cstr = sc->symbol->GetName().AsCString (NULL);
1358 if (cstr)
1359 {
1360 s.PutCString(cstr);
Greg Clayton0d9c9932010-10-04 17:26:49 +00001361
1362 if (sc->block)
1363 {
1364 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1365 if (inline_block)
1366 {
1367 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1368 if (inline_info)
1369 {
1370 s.PutCString(" [inlined] ");
1371 inline_info->GetName().Dump(&s);
1372 }
1373 }
1374 }
Greg Clayton1b654882010-09-19 02:33:57 +00001375 var_success = true;
1376 }
1377 }
1378 else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
1379 {
1380 var_success = addr != NULL;
1381 if (var_success)
1382 {
1383 format_addr = *addr;
1384 calculate_format_addr_function_offset = true;
1385 }
1386 }
1387 else if (::strncmp (var_name_begin, "line-offset}", strlen("line-offset}")) == 0)
1388 {
1389 var_success = sc->line_entry.range.GetBaseAddress().IsValid();
1390 if (var_success)
1391 {
1392 format_addr = sc->line_entry.range.GetBaseAddress();
1393 calculate_format_addr_function_offset = true;
1394 }
1395 }
1396 else if (::strncmp (var_name_begin, "pc-offset}", strlen("pc-offset}")) == 0)
1397 {
1398 var_success = exe_ctx->frame;
1399 if (var_success)
1400 {
1401 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1402 calculate_format_addr_function_offset = true;
1403 }
1404 }
1405 }
1406 }
1407 break;
1408
1409 case 'l':
1410 if (::strncmp (var_name_begin, "line.", strlen("line.")) == 0)
1411 {
1412 if (sc && sc->line_entry.IsValid())
1413 {
1414 var_name_begin += ::strlen ("line.");
1415 if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
1416 {
1417 var_name_begin += ::strlen ("file.");
1418
1419 if (::strncmp (var_name_begin, "basename}", strlen("basename}")) == 0)
1420 {
1421 format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
1422 var_success = format_file_spec;
1423 }
1424 else if (::strncmp (var_name_begin, "fullpath}", strlen("fullpath}")) == 0)
1425 {
1426 format_file_spec = sc->line_entry.file;
1427 var_success = format_file_spec;
1428 }
1429 }
1430 else if (::strncmp (var_name_begin, "number}", strlen("number}")) == 0)
1431 {
1432 var_success = true;
1433 s.Printf("%u", sc->line_entry.line);
1434 }
1435 else if ((::strncmp (var_name_begin, "start-addr}", strlen("start-addr}")) == 0) ||
1436 (::strncmp (var_name_begin, "end-addr}", strlen("end-addr}")) == 0))
1437 {
1438 var_success = sc && sc->line_entry.range.GetBaseAddress().IsValid();
1439 if (var_success)
1440 {
1441 format_addr = sc->line_entry.range.GetBaseAddress();
1442 if (var_name_begin[0] == 'e')
1443 format_addr.Slide (sc->line_entry.range.GetByteSize());
1444 }
1445 }
1446 }
1447 }
1448 break;
1449 }
1450
1451 if (var_success)
1452 {
1453 // If format addr is valid, then we need to print an address
1454 if (reg_num != LLDB_INVALID_REGNUM)
1455 {
1456 // We have a register value to display...
1457 if (reg_num == LLDB_REGNUM_GENERIC_PC && reg_kind == eRegisterKindGeneric)
1458 {
1459 format_addr = exe_ctx->frame->GetFrameCodeAddress();
1460 }
1461 else
1462 {
1463 if (reg_ctx == NULL)
Greg Clayton5ccbd292011-01-06 22:15:06 +00001464 reg_ctx = exe_ctx->frame->GetRegisterContext().get();
Greg Clayton1b654882010-09-19 02:33:57 +00001465
1466 if (reg_ctx)
1467 {
1468 if (reg_kind != kNumRegisterKinds)
1469 reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
1470 reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_num);
1471 var_success = reg_info != NULL;
1472 }
1473 }
1474 }
1475
1476 if (reg_info != NULL)
1477 {
Greg Clayton7349bd92011-05-09 20:18:18 +00001478 RegisterValue reg_value;
1479 var_success = reg_ctx->ReadRegister (reg_info, reg_value);
1480 if (var_success)
Greg Clayton1b654882010-09-19 02:33:57 +00001481 {
Greg Clayton9a8fa912011-05-15 04:12:07 +00001482 reg_value.Dump(&s, reg_info, false, false, eFormatDefault);
Greg Clayton1b654882010-09-19 02:33:57 +00001483 }
1484 }
1485
1486 if (format_file_spec)
1487 {
1488 s << format_file_spec;
1489 }
1490
1491 // If format addr is valid, then we need to print an address
1492 if (format_addr.IsValid())
1493 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001494 var_success = false;
1495
Greg Clayton1b654882010-09-19 02:33:57 +00001496 if (calculate_format_addr_function_offset)
1497 {
1498 Address func_addr;
Greg Clayton1b654882010-09-19 02:33:57 +00001499
Greg Clayton0603aa92010-10-04 01:05:56 +00001500 if (sc)
1501 {
1502 if (sc->function)
Greg Clayton0d9c9932010-10-04 17:26:49 +00001503 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001504 func_addr = sc->function->GetAddressRange().GetBaseAddress();
Greg Clayton0d9c9932010-10-04 17:26:49 +00001505 if (sc->block)
1506 {
1507 // Check to make sure we aren't in an inline
1508 // function. If we are, use the inline block
1509 // range that contains "format_addr" since
1510 // blocks can be discontiguous.
1511 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1512 AddressRange inline_range;
1513 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
1514 func_addr = inline_range.GetBaseAddress();
1515 }
1516 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001517 else if (sc->symbol && sc->symbol->GetAddressRangePtr())
1518 func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
1519 }
1520
1521 if (func_addr.IsValid())
Greg Clayton1b654882010-09-19 02:33:57 +00001522 {
1523 if (func_addr.GetSection() == format_addr.GetSection())
1524 {
1525 addr_t func_file_addr = func_addr.GetFileAddress();
1526 addr_t addr_file_addr = format_addr.GetFileAddress();
1527 if (addr_file_addr > func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001528 s.Printf(" + %llu", addr_file_addr - func_file_addr);
Greg Clayton1b654882010-09-19 02:33:57 +00001529 else if (addr_file_addr < func_file_addr)
Greg Clayton1b654882010-09-19 02:33:57 +00001530 s.Printf(" - %llu", func_file_addr - addr_file_addr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001531 var_success = true;
Greg Clayton1b654882010-09-19 02:33:57 +00001532 }
1533 else
Greg Clayton0603aa92010-10-04 01:05:56 +00001534 {
1535 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
1536 if (target)
1537 {
1538 addr_t func_load_addr = func_addr.GetLoadAddress (target);
1539 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
1540 if (addr_load_addr > func_load_addr)
1541 s.Printf(" + %llu", addr_load_addr - func_load_addr);
1542 else if (addr_load_addr < func_load_addr)
1543 s.Printf(" - %llu", func_load_addr - addr_load_addr);
1544 var_success = true;
1545 }
1546 }
Greg Clayton1b654882010-09-19 02:33:57 +00001547 }
1548 }
1549 else
1550 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001551 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
Greg Clayton1b654882010-09-19 02:33:57 +00001552 addr_t vaddr = LLDB_INVALID_ADDRESS;
Greg Clayton0603aa92010-10-04 01:05:56 +00001553 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
1554 vaddr = format_addr.GetLoadAddress (target);
Greg Clayton1b654882010-09-19 02:33:57 +00001555 if (vaddr == LLDB_INVALID_ADDRESS)
1556 vaddr = format_addr.GetFileAddress ();
1557
1558 if (vaddr != LLDB_INVALID_ADDRESS)
Greg Clayton0603aa92010-10-04 01:05:56 +00001559 {
Greg Clayton514487e2011-02-15 21:59:32 +00001560 int addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
Greg Clayton35f1a0d2010-11-19 04:16:11 +00001561 if (addr_width == 0)
1562 addr_width = 16;
1563 s.Printf("0x%*.*llx", addr_width, addr_width, vaddr);
Greg Clayton0603aa92010-10-04 01:05:56 +00001564 var_success = true;
1565 }
Greg Clayton1b654882010-09-19 02:33:57 +00001566 }
1567 }
1568 }
1569
1570 if (var_success == false)
1571 success = false;
1572 }
1573 p = var_name_end;
1574 }
1575 else
1576 break;
1577 }
1578 else
1579 {
1580 // We got a dollar sign with no '{' after it, it must just be a dollar sign
1581 s.PutChar(*p);
1582 }
1583 }
1584 else if (*p == '\\')
1585 {
1586 ++p; // skip the slash
1587 switch (*p)
1588 {
1589 case 'a': s.PutChar ('\a'); break;
1590 case 'b': s.PutChar ('\b'); break;
1591 case 'f': s.PutChar ('\f'); break;
1592 case 'n': s.PutChar ('\n'); break;
1593 case 'r': s.PutChar ('\r'); break;
1594 case 't': s.PutChar ('\t'); break;
1595 case 'v': s.PutChar ('\v'); break;
1596 case '\'': s.PutChar ('\''); break;
1597 case '\\': s.PutChar ('\\'); break;
1598 case '0':
1599 // 1 to 3 octal chars
1600 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001601 // Make a string that can hold onto the initial zero char,
1602 // up to 3 octal digits, and a terminating NULL.
1603 char oct_str[5] = { 0, 0, 0, 0, 0 };
1604
1605 int i;
1606 for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
1607 oct_str[i] = p[i];
1608
1609 // We don't want to consume the last octal character since
1610 // the main for loop will do this for us, so we advance p by
1611 // one less than i (even if i is zero)
1612 p += i - 1;
1613 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
1614 if (octal_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001615 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001616 char octal_char = octal_value;
1617 s.Write (&octal_char, 1);
Greg Clayton1b654882010-09-19 02:33:57 +00001618 }
Greg Clayton1b654882010-09-19 02:33:57 +00001619 }
1620 break;
1621
1622 case 'x':
1623 // hex number in the format
Greg Clayton0603aa92010-10-04 01:05:56 +00001624 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001625 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001626 ++p; // Skip the 'x'
Greg Clayton1b654882010-09-19 02:33:57 +00001627
Greg Clayton0603aa92010-10-04 01:05:56 +00001628 // Make a string that can hold onto two hex chars plus a
1629 // NULL terminator
1630 char hex_str[3] = { 0,0,0 };
1631 hex_str[0] = *p;
1632 if (isxdigit(p[1]))
Greg Clayton1b654882010-09-19 02:33:57 +00001633 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001634 ++p; // Skip the first of the two hex chars
1635 hex_str[1] = *p;
1636 }
1637
1638 unsigned long hex_value = strtoul (hex_str, NULL, 16);
1639 if (hex_value <= UINT8_MAX)
Greg Clayton1b654882010-09-19 02:33:57 +00001640 s.PutChar (hex_value);
Greg Clayton0603aa92010-10-04 01:05:56 +00001641 }
1642 else
1643 {
1644 s.PutChar('x');
Greg Clayton1b654882010-09-19 02:33:57 +00001645 }
1646 break;
1647
1648 default:
Greg Clayton0603aa92010-10-04 01:05:56 +00001649 // Just desensitize any other character by just printing what
1650 // came after the '\'
1651 s << *p;
Greg Clayton1b654882010-09-19 02:33:57 +00001652 break;
1653
1654 }
1655
1656 }
1657 }
1658 if (end)
1659 *end = p;
1660 return success;
1661}
1662
Greg Clayton4a33d312011-06-23 17:59:56 +00001663
1664static FormatManager&
1665GetFormatManager() {
1666 static FormatManager g_format_manager;
1667 return g_format_manager;
1668}
1669
1670bool
Enrico Granata4becb372011-06-29 22:27:15 +00001671Debugger::ValueFormats::Get(ValueObject& vobj, ValueFormat::SharedPointer &entry)
Greg Clayton4a33d312011-06-23 17:59:56 +00001672{
Enrico Granata4becb372011-06-29 22:27:15 +00001673 return GetFormatManager().Value().Get(vobj,entry);
Greg Clayton4a33d312011-06-23 17:59:56 +00001674}
1675
1676void
Enrico Granata4becb372011-06-29 22:27:15 +00001677Debugger::ValueFormats::Add(const ConstString &type, const ValueFormat::SharedPointer &entry)
Greg Clayton4a33d312011-06-23 17:59:56 +00001678{
Enrico Granata4becb372011-06-29 22:27:15 +00001679 GetFormatManager().Value().Add(type.AsCString(),entry);
Greg Clayton4a33d312011-06-23 17:59:56 +00001680}
1681
1682bool
Enrico Granata4becb372011-06-29 22:27:15 +00001683Debugger::ValueFormats::Delete(const ConstString &type)
Greg Clayton4a33d312011-06-23 17:59:56 +00001684{
Enrico Granata4becb372011-06-29 22:27:15 +00001685 return GetFormatManager().Value().Delete(type.AsCString());
Greg Clayton4a33d312011-06-23 17:59:56 +00001686}
1687
1688void
Enrico Granata4becb372011-06-29 22:27:15 +00001689Debugger::ValueFormats::Clear()
Greg Clayton4a33d312011-06-23 17:59:56 +00001690{
Enrico Granata4becb372011-06-29 22:27:15 +00001691 GetFormatManager().Value().Clear();
1692}
1693
1694void
Enrico Granata0a3958e2011-07-02 00:25:22 +00001695Debugger::ValueFormats::LoopThrough(ValueFormat::ValueCallback callback, void* callback_baton)
Enrico Granata4becb372011-06-29 22:27:15 +00001696{
1697 GetFormatManager().Value().LoopThrough(callback, callback_baton);
1698}
1699
1700uint32_t
1701Debugger::ValueFormats::GetCurrentRevision()
1702{
1703 return GetFormatManager().GetCurrentRevision();
1704}
1705
Enrico Granata0a3958e2011-07-02 00:25:22 +00001706uint32_t
1707Debugger::ValueFormats::GetCount()
1708{
1709 return GetFormatManager().Value().GetCount();
1710}
Enrico Granata4becb372011-06-29 22:27:15 +00001711
1712bool
1713Debugger::SummaryFormats::Get(ValueObject& vobj, SummaryFormat::SharedPointer &entry)
1714{
1715 return GetFormatManager().Summary().Get(vobj,entry);
1716}
1717
1718void
1719Debugger::SummaryFormats::Add(const ConstString &type, const SummaryFormat::SharedPointer &entry)
1720{
1721 GetFormatManager().Summary().Add(type.AsCString(),entry);
1722}
1723
1724bool
1725Debugger::SummaryFormats::Delete(const ConstString &type)
1726{
1727 return GetFormatManager().Summary().Delete(type.AsCString());
1728}
1729
1730void
1731Debugger::SummaryFormats::Clear()
1732{
1733 GetFormatManager().Summary().Clear();
1734}
1735
1736void
Enrico Granata0a3958e2011-07-02 00:25:22 +00001737Debugger::SummaryFormats::LoopThrough(SummaryFormat::SummaryCallback callback, void* callback_baton)
Enrico Granata4becb372011-06-29 22:27:15 +00001738{
1739 GetFormatManager().Summary().LoopThrough(callback, callback_baton);
1740}
1741
1742uint32_t
1743Debugger::SummaryFormats::GetCurrentRevision()
1744{
1745 return GetFormatManager().GetCurrentRevision();
Greg Clayton4a33d312011-06-23 17:59:56 +00001746}
1747
Enrico Granata0a3958e2011-07-02 00:25:22 +00001748uint32_t
1749Debugger::SummaryFormats::GetCount()
1750{
1751 return GetFormatManager().Summary().GetCount();
1752}
1753
1754bool
1755Debugger::RegexSummaryFormats::Get(ValueObject& vobj, SummaryFormat::SharedPointer &entry)
1756{
1757 return GetFormatManager().RegexSummary().Get(vobj,entry);
1758}
1759
1760void
1761Debugger::RegexSummaryFormats::Add(const lldb::RegularExpressionSP &type, const SummaryFormat::SharedPointer &entry)
1762{
1763 GetFormatManager().RegexSummary().Add(type,entry);
1764}
1765
1766bool
1767Debugger::RegexSummaryFormats::Delete(const ConstString &type)
1768{
1769 return GetFormatManager().RegexSummary().Delete(type.AsCString());
1770}
1771
1772void
1773Debugger::RegexSummaryFormats::Clear()
1774{
1775 GetFormatManager().RegexSummary().Clear();
1776}
1777
1778void
1779Debugger::RegexSummaryFormats::LoopThrough(SummaryFormat::RegexSummaryCallback callback, void* callback_baton)
1780{
1781 GetFormatManager().RegexSummary().LoopThrough(callback, callback_baton);
1782}
1783
1784uint32_t
1785Debugger::RegexSummaryFormats::GetCurrentRevision()
1786{
1787 return GetFormatManager().GetCurrentRevision();
1788}
1789
1790uint32_t
1791Debugger::RegexSummaryFormats::GetCount()
1792{
1793 return GetFormatManager().RegexSummary().GetCount();
1794}
1795
Greg Clayton1b654882010-09-19 02:33:57 +00001796#pragma mark Debugger::SettingsController
1797
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001798//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00001799// class Debugger::SettingsController
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001800//--------------------------------------------------
1801
Greg Clayton1b654882010-09-19 02:33:57 +00001802Debugger::SettingsController::SettingsController () :
Caroline Tice101c7c22010-09-09 06:25:08 +00001803 UserSettingsController ("", lldb::UserSettingsControllerSP())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001804{
Caroline Tice91123da2010-09-08 17:48:55 +00001805 m_default_settings.reset (new DebuggerInstanceSettings (*this, false,
1806 InstanceSettings::GetDefaultName().AsCString()));
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001807}
1808
Greg Clayton1b654882010-09-19 02:33:57 +00001809Debugger::SettingsController::~SettingsController ()
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001810{
1811}
1812
1813
1814lldb::InstanceSettingsSP
Greg Clayton1b654882010-09-19 02:33:57 +00001815Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001816{
Greg Claytondbe54502010-11-19 03:46:01 +00001817 DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
Caroline Tice91123da2010-09-08 17:48:55 +00001818 false, instance_name);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001819 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1820 return new_settings_sp;
1821}
1822
Greg Clayton1b654882010-09-19 02:33:57 +00001823#pragma mark DebuggerInstanceSettings
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001824//--------------------------------------------------
1825// class DebuggerInstanceSettings
1826//--------------------------------------------------
1827
Greg Claytona7015092010-09-18 01:14:36 +00001828DebuggerInstanceSettings::DebuggerInstanceSettings
1829(
1830 UserSettingsController &owner,
1831 bool live_instance,
1832 const char *name
1833) :
Greg Clayton85851dd2010-12-04 00:10:17 +00001834 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytona7015092010-09-18 01:14:36 +00001835 m_term_width (80),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001836 m_prompt (),
Greg Clayton0603aa92010-10-04 01:05:56 +00001837 m_frame_format (),
1838 m_thread_format (),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001839 m_script_lang (),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001840 m_use_external_editor (false),
1841 m_auto_confirm_on (false)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001842{
Caroline Ticef20e8232010-09-09 18:26:37 +00001843 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1844 // until the vtables for DebuggerInstanceSettings are properly set up, i.e. AFTER all the initializers.
1845 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
Caroline Tice9e41c152010-09-16 19:05:55 +00001846 // The same is true of CreateInstanceName().
1847
1848 if (GetInstanceName() == InstanceSettings::InvalidName())
1849 {
1850 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1851 m_owner.RegisterInstanceSettings (this);
1852 }
Caroline Ticef20e8232010-09-09 18:26:37 +00001853
1854 if (live_instance)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001855 {
1856 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1857 CopyInstanceSettings (pending_settings, false);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001858 }
1859}
1860
1861DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
Greg Clayton99d0faf2010-11-18 23:32:35 +00001862 InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001863 m_prompt (rhs.m_prompt),
Greg Clayton0603aa92010-10-04 01:05:56 +00001864 m_frame_format (rhs.m_frame_format),
1865 m_thread_format (rhs.m_thread_format),
Caroline Ticedaccaa92010-09-20 20:44:43 +00001866 m_script_lang (rhs.m_script_lang),
Jim Ingham3bcdb292010-10-04 22:44:14 +00001867 m_use_external_editor (rhs.m_use_external_editor),
1868 m_auto_confirm_on(rhs.m_auto_confirm_on)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001869{
1870 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1871 CopyInstanceSettings (pending_settings, false);
1872 m_owner.RemovePendingSettings (m_instance_name);
1873}
1874
1875DebuggerInstanceSettings::~DebuggerInstanceSettings ()
1876{
1877}
1878
1879DebuggerInstanceSettings&
1880DebuggerInstanceSettings::operator= (const DebuggerInstanceSettings &rhs)
1881{
1882 if (this != &rhs)
1883 {
Greg Clayton1b654882010-09-19 02:33:57 +00001884 m_term_width = rhs.m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001885 m_prompt = rhs.m_prompt;
Greg Clayton0603aa92010-10-04 01:05:56 +00001886 m_frame_format = rhs.m_frame_format;
1887 m_thread_format = rhs.m_thread_format;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001888 m_script_lang = rhs.m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00001889 m_use_external_editor = rhs.m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00001890 m_auto_confirm_on = rhs.m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001891 }
1892
1893 return *this;
1894}
1895
Greg Clayton1b654882010-09-19 02:33:57 +00001896bool
1897DebuggerInstanceSettings::ValidTermWidthValue (const char *value, Error err)
1898{
1899 bool valid = false;
1900
1901 // Verify we have a value string.
1902 if (value == NULL || value[0] == '\0')
1903 {
1904 err.SetErrorString ("Missing value. Can't set terminal width without a value.\n");
1905 }
1906 else
1907 {
1908 char *end = NULL;
1909 const uint32_t width = ::strtoul (value, &end, 0);
1910
Johnny Chenea9fc182010-09-20 16:36:43 +00001911 if (end && end[0] == '\0')
Greg Clayton1b654882010-09-19 02:33:57 +00001912 {
Johnny Chen433d7742010-09-20 17:04:41 +00001913 if (width >= 10 && width <= 1024)
Greg Clayton1b654882010-09-19 02:33:57 +00001914 valid = true;
1915 else
1916 err.SetErrorString ("Invalid term-width value; value must be between 10 and 1024.\n");
1917 }
1918 else
1919 err.SetErrorStringWithFormat ("'%s' is not a valid unsigned integer string.\n", value);
1920 }
1921
1922 return valid;
1923}
1924
1925
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001926void
1927DebuggerInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1928 const char *index_value,
1929 const char *value,
1930 const ConstString &instance_name,
1931 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:54 +00001932 VarSetOperationType op,
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001933 Error &err,
1934 bool pending)
1935{
Greg Clayton0603aa92010-10-04 01:05:56 +00001936
1937 if (var_name == TermWidthVarName())
1938 {
1939 if (ValidTermWidthValue (value, err))
1940 {
1941 m_term_width = ::strtoul (value, NULL, 0);
1942 }
1943 }
1944 else if (var_name == PromptVarName())
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001945 {
Caroline Tice101c7c22010-09-09 06:25:08 +00001946 UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001947 if (!pending)
1948 {
Caroline Tice49e27372010-09-07 18:35:40 +00001949 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
1950 // strip off the brackets before passing it to BroadcastPromptChange.
1951
1952 std::string tmp_instance_name (instance_name.AsCString());
1953 if ((tmp_instance_name[0] == '[')
1954 && (tmp_instance_name[instance_name.GetLength() - 1] == ']'))
1955 tmp_instance_name = tmp_instance_name.substr (1, instance_name.GetLength() - 2);
1956 ConstString new_name (tmp_instance_name.c_str());
1957
1958 BroadcastPromptChange (new_name, m_prompt.c_str());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001959 }
1960 }
Greg Clayton0603aa92010-10-04 01:05:56 +00001961 else if (var_name == GetFrameFormatName())
1962 {
1963 UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
1964 }
1965 else if (var_name == GetThreadFormatName())
1966 {
1967 UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
1968 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001969 else if (var_name == ScriptLangVarName())
1970 {
1971 bool success;
1972 m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
1973 &success);
1974 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00001975 else if (var_name == UseExternalEditorVarName ())
1976 {
Greg Clayton385aa282011-04-22 03:55:06 +00001977 UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, false, err);
Caroline Ticedaccaa92010-09-20 20:44:43 +00001978 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00001979 else if (var_name == AutoConfirmName ())
1980 {
Greg Clayton385aa282011-04-22 03:55:06 +00001981 UserSettingsController::UpdateBooleanVariable (op, m_auto_confirm_on, value, false, err);
Jim Ingham3bcdb292010-10-04 22:44:14 +00001982 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001983}
1984
Caroline Tice12cecd72010-09-20 21:37:42 +00001985bool
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001986DebuggerInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1987 const ConstString &var_name,
Caroline Ticedaccaa92010-09-20 20:44:43 +00001988 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:42 +00001989 Error *err)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001990{
1991 if (var_name == PromptVarName())
1992 {
Greg Clayton0603aa92010-10-04 01:05:56 +00001993 value.AppendString (m_prompt.c_str(), m_prompt.size());
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001994
1995 }
1996 else if (var_name == ScriptLangVarName())
1997 {
1998 value.AppendString (ScriptInterpreter::LanguageToString (m_script_lang).c_str());
1999 }
Caroline Tice101c7c22010-09-09 06:25:08 +00002000 else if (var_name == TermWidthVarName())
2001 {
2002 StreamString width_str;
2003 width_str.Printf ("%d", m_term_width);
2004 value.AppendString (width_str.GetData());
2005 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002006 else if (var_name == GetFrameFormatName ())
2007 {
2008 value.AppendString(m_frame_format.c_str(), m_frame_format.size());
2009 }
2010 else if (var_name == GetThreadFormatName ())
2011 {
2012 value.AppendString(m_thread_format.c_str(), m_thread_format.size());
2013 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002014 else if (var_name == UseExternalEditorVarName())
2015 {
2016 if (m_use_external_editor)
2017 value.AppendString ("true");
2018 else
2019 value.AppendString ("false");
2020 }
Jim Ingham3bcdb292010-10-04 22:44:14 +00002021 else if (var_name == AutoConfirmName())
2022 {
2023 if (m_auto_confirm_on)
2024 value.AppendString ("true");
2025 else
2026 value.AppendString ("false");
2027 }
Caroline Ticedaccaa92010-09-20 20:44:43 +00002028 else
Caroline Tice12cecd72010-09-20 21:37:42 +00002029 {
2030 if (err)
2031 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2032 return false;
2033 }
2034 return true;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002035}
2036
2037void
2038DebuggerInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
2039 bool pending)
2040{
2041 if (new_settings.get() == NULL)
2042 return;
2043
2044 DebuggerInstanceSettings *new_debugger_settings = (DebuggerInstanceSettings *) new_settings.get();
2045
2046 m_prompt = new_debugger_settings->m_prompt;
2047 if (!pending)
Caroline Tice49e27372010-09-07 18:35:40 +00002048 {
2049 // 'instance_name' is actually (probably) in the form '[<instance_name>]'; if so, we need to
2050 // strip off the brackets before passing it to BroadcastPromptChange.
2051
2052 std::string tmp_instance_name (m_instance_name.AsCString());
2053 if ((tmp_instance_name[0] == '[')
2054 && (tmp_instance_name[m_instance_name.GetLength() - 1] == ']'))
2055 tmp_instance_name = tmp_instance_name.substr (1, m_instance_name.GetLength() - 2);
2056 ConstString new_name (tmp_instance_name.c_str());
2057
2058 BroadcastPromptChange (new_name, m_prompt.c_str());
2059 }
Greg Clayton0603aa92010-10-04 01:05:56 +00002060 m_frame_format = new_debugger_settings->m_frame_format;
2061 m_thread_format = new_debugger_settings->m_thread_format;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002062 m_term_width = new_debugger_settings->m_term_width;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002063 m_script_lang = new_debugger_settings->m_script_lang;
Caroline Ticedaccaa92010-09-20 20:44:43 +00002064 m_use_external_editor = new_debugger_settings->m_use_external_editor;
Jim Ingham3bcdb292010-10-04 22:44:14 +00002065 m_auto_confirm_on = new_debugger_settings->m_auto_confirm_on;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002066}
2067
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002068
2069bool
2070DebuggerInstanceSettings::BroadcastPromptChange (const ConstString &instance_name, const char *new_prompt)
2071{
2072 std::string tmp_prompt;
2073
2074 if (new_prompt != NULL)
2075 {
2076 tmp_prompt = new_prompt ;
2077 int len = tmp_prompt.size();
2078 if (len > 1
2079 && (tmp_prompt[0] == '\'' || tmp_prompt[0] == '"')
2080 && (tmp_prompt[len-1] == tmp_prompt[0]))
2081 {
2082 tmp_prompt = tmp_prompt.substr(1,len-2);
2083 }
2084 len = tmp_prompt.size();
2085 if (tmp_prompt[len-1] != ' ')
2086 tmp_prompt.append(" ");
2087 }
2088 EventSP new_event_sp;
2089 new_event_sp.reset (new Event(CommandInterpreter::eBroadcastBitResetPrompt,
2090 new EventDataBytes (tmp_prompt.c_str())));
2091
2092 if (instance_name.GetLength() != 0)
2093 {
2094 // Set prompt for a particular instance.
2095 Debugger *dbg = Debugger::FindDebuggerWithInstanceName (instance_name).get();
2096 if (dbg != NULL)
2097 {
2098 dbg->GetCommandInterpreter().BroadcastEvent (new_event_sp);
2099 }
2100 }
2101
2102 return true;
2103}
2104
2105const ConstString
2106DebuggerInstanceSettings::CreateInstanceName ()
2107{
2108 static int instance_count = 1;
2109 StreamString sstr;
2110
2111 sstr.Printf ("debugger_%d", instance_count);
2112 ++instance_count;
2113
2114 const ConstString ret_val (sstr.GetData());
2115
2116 return ret_val;
2117}
2118
2119const ConstString &
2120DebuggerInstanceSettings::PromptVarName ()
2121{
2122 static ConstString prompt_var_name ("prompt");
2123
2124 return prompt_var_name;
2125}
2126
2127const ConstString &
Greg Clayton0603aa92010-10-04 01:05:56 +00002128DebuggerInstanceSettings::GetFrameFormatName ()
2129{
2130 static ConstString prompt_var_name ("frame-format");
2131
2132 return prompt_var_name;
2133}
2134
2135const ConstString &
2136DebuggerInstanceSettings::GetThreadFormatName ()
2137{
2138 static ConstString prompt_var_name ("thread-format");
2139
2140 return prompt_var_name;
2141}
2142
2143const ConstString &
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002144DebuggerInstanceSettings::ScriptLangVarName ()
2145{
2146 static ConstString script_lang_var_name ("script-lang");
2147
2148 return script_lang_var_name;
2149}
2150
Caroline Tice101c7c22010-09-09 06:25:08 +00002151const ConstString &
2152DebuggerInstanceSettings::TermWidthVarName ()
2153{
2154 static ConstString term_width_var_name ("term-width");
2155
2156 return term_width_var_name;
2157}
2158
Caroline Ticedaccaa92010-09-20 20:44:43 +00002159const ConstString &
2160DebuggerInstanceSettings::UseExternalEditorVarName ()
2161{
2162 static ConstString use_external_editor_var_name ("use-external-editor");
2163
2164 return use_external_editor_var_name;
2165}
2166
Jim Ingham3bcdb292010-10-04 22:44:14 +00002167const ConstString &
2168DebuggerInstanceSettings::AutoConfirmName ()
2169{
2170 static ConstString use_external_editor_var_name ("auto-confirm");
2171
2172 return use_external_editor_var_name;
2173}
2174
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002175//--------------------------------------------------
Greg Clayton1b654882010-09-19 02:33:57 +00002176// SettingsController Variable Tables
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002177//--------------------------------------------------
2178
2179
2180SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002181Debugger::SettingsController::global_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002182{
2183 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
Caroline Tice101c7c22010-09-09 06:25:08 +00002184 // The Debugger level global table should always be empty; all Debugger settable variables should be instance
2185 // variables.
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002186 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
2187};
2188
Greg Claytonbb562b12010-10-04 02:44:26 +00002189#define MODULE_WITH_FUNC "{ ${module.file.basename}{`${function.name}${function.pc-offset}}}"
Greg Clayton0603aa92010-10-04 01:05:56 +00002190#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002191
Greg Clayton0603aa92010-10-04 01:05:56 +00002192#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2193 "{, ${frame.pc}}"\
2194 MODULE_WITH_FUNC\
Greg Claytoncf4b9072010-10-04 17:04:23 +00002195 FILE_AND_LINE\
Greg Clayton0603aa92010-10-04 01:05:56 +00002196 "{, stop reason = ${thread.stop-reason}}"\
Greg Clayton0603aa92010-10-04 01:05:56 +00002197 "\\n"
2198
Greg Clayton315d2ca2010-11-02 01:53:21 +00002199//#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
2200// "{, ${frame.pc}}"\
2201// MODULE_WITH_FUNC\
2202// FILE_AND_LINE\
2203// "{, stop reason = ${thread.stop-reason}}"\
2204// "{, name = ${thread.name}}"\
2205// "{, queue = ${thread.queue}}"\
2206// "\\n"
2207
Greg Clayton0603aa92010-10-04 01:05:56 +00002208#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
2209 MODULE_WITH_FUNC\
2210 FILE_AND_LINE\
2211 "\\n"
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002212
2213SettingEntry
Greg Clayton1b654882010-09-19 02:33:57 +00002214Debugger::SettingsController::instance_settings_table[] =
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002215{
Greg Clayton0603aa92010-10-04 01:05:56 +00002216// NAME Setting variable type Default Enum Init'd Hidden Help
2217// ======================= ======================= ====================== ==== ====== ====== ======================
Greg Clayton0603aa92010-10-04 01:05:56 +00002218{ "frame-format", eSetVarTypeString, DEFAULT_FRAME_FORMAT, NULL, false, false, "The default frame format string to use when displaying thread information." },
Greg Clayton54180392010-10-22 21:15:00 +00002219{ "prompt", eSetVarTypeString, "(lldb) ", NULL, false, false, "The debugger command line prompt displayed for the user." },
Jim Ingham3bcdb292010-10-04 22:44:14 +00002220{ "script-lang", eSetVarTypeString, "python", NULL, false, false, "The script language to be used for evaluating user-written scripts." },
2221{ "term-width", eSetVarTypeInt, "80" , NULL, false, false, "The maximum number of columns to use for displaying text." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002222{ "thread-format", eSetVarTypeString, DEFAULT_THREAD_FORMAT, NULL, false, false, "The default thread format string to use when displaying thread information." },
Jim Ingham06e827c2010-11-11 19:26:09 +00002223{ "use-external-editor", eSetVarTypeBoolean, "false", NULL, false, false, "Whether to use an external editor or not." },
2224{ "auto-confirm", eSetVarTypeBoolean, "false", NULL, false, false, "If true all confirmation prompts will receive their default reply." },
Greg Clayton0603aa92010-10-04 01:05:56 +00002225{ NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL }
Caroline Tice3df9a8d2010-09-04 00:03:46 +00002226};