blob: d6c2dc2e086524748df7d24a4477d843abde323f [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- Target.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
10#include "lldb/Target/Target.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Breakpoint/BreakpointResolver.h"
17#include "lldb/Breakpoint/BreakpointResolverAddress.h"
18#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
19#include "lldb/Breakpoint/BreakpointResolverName.h"
Greg Clayton427f2902010-12-14 02:59:59 +000020#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021#include "lldb/Core/Event.h"
22#include "lldb/Core/Log.h"
Caroline Tice4a348082011-05-02 20:41:46 +000023#include "lldb/Core/StreamAsynchronousIO.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Core/StreamString.h"
Greg Clayton427f2902010-12-14 02:59:59 +000025#include "lldb/Core/Timer.h"
26#include "lldb/Core/ValueObject.h"
Greg Claytonf15996e2011-04-07 22:46:35 +000027#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028#include "lldb/Host/Host.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000029#include "lldb/Interpreter/CommandInterpreter.h"
30#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031#include "lldb/lldb-private-log.h"
32#include "lldb/Symbol/ObjectFile.h"
33#include "lldb/Target/Process.h"
Greg Clayton427f2902010-12-14 02:59:59 +000034#include "lldb/Target/StackFrame.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000035#include "lldb/Target/Thread.h"
36#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000037
38using namespace lldb;
39using namespace lldb_private;
40
41//----------------------------------------------------------------------
42// Target constructor
43//----------------------------------------------------------------------
Greg Clayton24bc5d92011-03-30 18:16:51 +000044Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
45 Broadcaster ("lldb.target"),
46 ExecutionContextScope (),
Greg Claytonc0c1b0c2010-11-19 03:46:01 +000047 TargetInstanceSettings (*GetSettingsController()),
Greg Clayton63094e02010-06-23 01:19:29 +000048 m_debugger (debugger),
Greg Clayton24bc5d92011-03-30 18:16:51 +000049 m_platform_sp (platform_sp),
Greg Claytonbdcda462010-12-20 20:49:23 +000050 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton24bc5d92011-03-30 18:16:51 +000051 m_arch (target_arch),
52 m_images (),
Greg Claytoneea26402010-09-14 23:36:40 +000053 m_section_load_list (),
Chris Lattner24943d22010-06-08 16:52:24 +000054 m_breakpoint_list (false),
55 m_internal_breakpoint_list (true),
Johnny Chen9a3c2a52011-09-06 20:05:25 +000056 m_watchpoint_location_list (),
Greg Clayton24bc5d92011-03-30 18:16:51 +000057 m_process_sp (),
58 m_search_filter_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000059 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton427f2902010-12-14 02:59:59 +000060 m_scratch_ast_context_ap (NULL),
Jim Inghamd60d94a2011-03-11 03:53:59 +000061 m_persistent_variables (),
Jim Inghamcc637462011-09-13 00:29:56 +000062 m_source_manager(*this),
Greg Clayton24bc5d92011-03-30 18:16:51 +000063 m_stop_hooks (),
Jim Ingham3613ae12011-05-12 02:06:14 +000064 m_stop_hook_next_id (0),
65 m_suppress_stop_hooks (false)
Chris Lattner24943d22010-06-08 16:52:24 +000066{
Greg Clayton49ce6822010-10-31 03:01:06 +000067 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
68 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
69 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
70
Greg Claytone005f2c2010-11-06 01:53:30 +000071 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000072 if (log)
73 log->Printf ("%p Target::Target()", this);
74}
75
76//----------------------------------------------------------------------
77// Destructor
78//----------------------------------------------------------------------
79Target::~Target()
80{
Greg Claytone005f2c2010-11-06 01:53:30 +000081 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000082 if (log)
83 log->Printf ("%p Target::~Target()", this);
84 DeleteCurrentProcess ();
85}
86
87void
Caroline Tice7826c882010-10-26 03:11:13 +000088Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner24943d22010-06-08 16:52:24 +000089{
Greg Clayton3fed8b92010-10-08 00:21:05 +000090// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Tice7826c882010-10-26 03:11:13 +000091 if (description_level != lldb::eDescriptionLevelBrief)
92 {
93 s->Indent();
94 s->PutCString("Target\n");
95 s->IndentMore();
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000096 m_images.Dump(s);
97 m_breakpoint_list.Dump(s);
98 m_internal_breakpoint_list.Dump(s);
99 s->IndentLess();
Caroline Tice7826c882010-10-26 03:11:13 +0000100 }
101 else
102 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000103 Module *exe_module = GetExecutableModulePointer();
104 if (exe_module)
105 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham53fe9cc2011-05-12 01:12:28 +0000106 else
107 s->PutCString ("No executable module.");
Caroline Tice7826c882010-10-26 03:11:13 +0000108 }
Chris Lattner24943d22010-06-08 16:52:24 +0000109}
110
111void
112Target::DeleteCurrentProcess ()
113{
114 if (m_process_sp.get())
115 {
Greg Clayton49480b12010-09-14 23:52:43 +0000116 m_section_load_list.Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000117 if (m_process_sp->IsAlive())
118 m_process_sp->Destroy();
Jim Ingham88fa7bd2011-02-16 17:54:55 +0000119
120 m_process_sp->Finalize();
Chris Lattner24943d22010-06-08 16:52:24 +0000121
122 // Do any cleanup of the target we need to do between process instances.
123 // NB It is better to do this before destroying the process in case the
124 // clean up needs some help from the process.
125 m_breakpoint_list.ClearAllBreakpointSites();
126 m_internal_breakpoint_list.ClearAllBreakpointSites();
Johnny Chen6c43c122011-09-15 20:54:25 +0000127 m_watchpoint_location_list.ClearAllWatchpointLocations();
Chris Lattner24943d22010-06-08 16:52:24 +0000128 m_process_sp.reset();
129 }
130}
131
132const lldb::ProcessSP &
133Target::CreateProcess (Listener &listener, const char *plugin_name)
134{
135 DeleteCurrentProcess ();
136 m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
137 return m_process_sp;
138}
139
140const lldb::ProcessSP &
141Target::GetProcessSP () const
142{
143 return m_process_sp;
144}
145
146lldb::TargetSP
147Target::GetSP()
148{
Greg Clayton987c7eb2011-09-17 08:33:22 +0000149 // This object contains an instrusive ref count base class so we can
150 // easily make a shared pointer to this object
151 return TargetSP(this);
Chris Lattner24943d22010-06-08 16:52:24 +0000152}
153
Greg Clayton153ccd72011-08-10 02:10:13 +0000154void
155Target::Destroy()
156{
157 Mutex::Locker locker (m_mutex);
158 DeleteCurrentProcess ();
159 m_platform_sp.reset();
160 m_arch.Clear();
161 m_images.Clear();
162 m_section_load_list.Clear();
163 const bool notify = false;
164 m_breakpoint_list.RemoveAll(notify);
165 m_internal_breakpoint_list.RemoveAll(notify);
166 m_last_created_breakpoint.reset();
167 m_search_filter_sp.reset();
168 m_image_search_paths.Clear(notify);
169 m_scratch_ast_context_ap.reset();
170 m_persistent_variables.Clear();
171 m_stop_hooks.clear();
172 m_stop_hook_next_id = 0;
173 m_suppress_stop_hooks = false;
174}
175
176
Chris Lattner24943d22010-06-08 16:52:24 +0000177BreakpointList &
178Target::GetBreakpointList(bool internal)
179{
180 if (internal)
181 return m_internal_breakpoint_list;
182 else
183 return m_breakpoint_list;
184}
185
186const BreakpointList &
187Target::GetBreakpointList(bool internal) const
188{
189 if (internal)
190 return m_internal_breakpoint_list;
191 else
192 return m_breakpoint_list;
193}
194
195BreakpointSP
196Target::GetBreakpointByID (break_id_t break_id)
197{
198 BreakpointSP bp_sp;
199
200 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
201 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
202 else
203 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
204
205 return bp_sp;
206}
207
208BreakpointSP
209Target::CreateBreakpoint (const FileSpec *containingModule, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
210{
211 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
212 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
213 return CreateBreakpoint (filter_sp, resolver_sp, internal);
214}
215
216
217BreakpointSP
Greg Clayton33ed1702010-08-24 00:45:41 +0000218Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000219{
Chris Lattner24943d22010-06-08 16:52:24 +0000220 Address so_addr;
221 // Attempt to resolve our load address if possible, though it is ok if
222 // it doesn't resolve to section/offset.
223
Greg Clayton33ed1702010-08-24 00:45:41 +0000224 // Try and resolve as a load address if possible
Greg Claytoneea26402010-09-14 23:36:40 +0000225 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton33ed1702010-08-24 00:45:41 +0000226 if (!so_addr.IsValid())
227 {
228 // The address didn't resolve, so just set this as an absolute address
229 so_addr.SetOffset (addr);
230 }
231 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner24943d22010-06-08 16:52:24 +0000232 return bp_sp;
233}
234
235BreakpointSP
236Target::CreateBreakpoint (Address &addr, bool internal)
237{
238 TargetSP target_sp = this->GetSP();
239 SearchFilterSP filter_sp(new SearchFilter (target_sp));
240 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
241 return CreateBreakpoint (filter_sp, resolver_sp, internal);
242}
243
244BreakpointSP
Greg Clayton7dd98df2011-07-12 17:06:17 +0000245Target::CreateBreakpoint (const FileSpec *containingModule,
246 const char *func_name,
247 uint32_t func_name_type_mask,
248 bool internal,
249 LazyBool skip_prologue)
Chris Lattner24943d22010-06-08 16:52:24 +0000250{
Greg Clayton12bec712010-06-28 21:30:43 +0000251 BreakpointSP bp_sp;
252 if (func_name)
253 {
254 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000255
256 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
257 func_name,
258 func_name_type_mask,
259 Breakpoint::Exact,
260 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Greg Clayton12bec712010-06-28 21:30:43 +0000261 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
262 }
263 return bp_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000264}
265
266
267SearchFilterSP
268Target::GetSearchFilterForModule (const FileSpec *containingModule)
269{
270 SearchFilterSP filter_sp;
271 lldb::TargetSP target_sp = this->GetSP();
272 if (containingModule != NULL)
273 {
274 // TODO: We should look into sharing module based search filters
275 // across many breakpoints like we do for the simple target based one
276 filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
277 }
278 else
279 {
280 if (m_search_filter_sp.get() == NULL)
281 m_search_filter_sp.reset (new SearchFilter (target_sp));
282 filter_sp = m_search_filter_sp;
283 }
284 return filter_sp;
285}
286
287BreakpointSP
Greg Clayton7dd98df2011-07-12 17:06:17 +0000288Target::CreateBreakpoint (const FileSpec *containingModule,
289 RegularExpression &func_regex,
290 bool internal,
291 LazyBool skip_prologue)
Chris Lattner24943d22010-06-08 16:52:24 +0000292{
293 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000294 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
295 func_regex,
296 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner24943d22010-06-08 16:52:24 +0000297
298 return CreateBreakpoint (filter_sp, resolver_sp, internal);
299}
300
301BreakpointSP
302Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
303{
304 BreakpointSP bp_sp;
305 if (filter_sp && resolver_sp)
306 {
307 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
308 resolver_sp->SetBreakpoint (bp_sp.get());
309
310 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000311 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000312 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000313 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000314
Greg Claytone005f2c2010-11-06 01:53:30 +0000315 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000316 if (log)
317 {
318 StreamString s;
319 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
320 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
321 }
322
Chris Lattner24943d22010-06-08 16:52:24 +0000323 bp_sp->ResolveBreakpoint();
324 }
Jim Inghamd1686902010-10-14 23:45:03 +0000325
326 if (!internal && bp_sp)
327 {
328 m_last_created_breakpoint = bp_sp;
329 }
330
Chris Lattner24943d22010-06-08 16:52:24 +0000331 return bp_sp;
332}
333
Johnny Chen87ff53b2011-09-14 00:26:03 +0000334// See also WatchpointLocation::SetWatchpointType(uint32_t type) and
335// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen34bbf852011-09-12 23:38:44 +0000336WatchpointLocationSP
337Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type)
338{
Johnny Chen5b2fc572011-09-14 20:23:45 +0000339 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
340 if (log)
341 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
342 __FUNCTION__, addr, size, type);
343
Johnny Chen34bbf852011-09-12 23:38:44 +0000344 WatchpointLocationSP wp_loc_sp;
Johnny Chen61286a52011-09-13 18:30:59 +0000345 bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
346 if (!process_is_valid)
347 return wp_loc_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000348 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chen34bbf852011-09-12 23:38:44 +0000349 return wp_loc_sp;
Johnny Chen9bf11992011-09-13 01:15:36 +0000350
Johnny Chen87ff53b2011-09-14 00:26:03 +0000351 // Currently we only support one watchpoint location per address, with total
352 // number of watchpoint locations limited by the hardware which the inferior
353 // is running on.
Johnny Chen69b6ec82011-09-13 23:29:31 +0000354 WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr);
355 if (matched_sp)
356 {
Johnny Chen5b2fc572011-09-14 20:23:45 +0000357 size_t old_size = matched_sp->GetByteSize();
Johnny Chen69b6ec82011-09-13 23:29:31 +0000358 uint32_t old_type =
Johnny Chen5b2fc572011-09-14 20:23:45 +0000359 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
360 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000361 // Return the existing watchpoint location if both size and type match.
362 if (size == old_size && type == old_type) {
363 wp_loc_sp = matched_sp;
364 wp_loc_sp->SetEnabled(false);
365 } else {
366 // Nil the matched watchpoint location; we will be creating a new one.
367 m_process_sp->DisableWatchpoint(matched_sp.get());
368 m_watchpoint_location_list.Remove(matched_sp->GetID());
369 }
Johnny Chen69b6ec82011-09-13 23:29:31 +0000370 }
371
Johnny Chen22a56cc2011-09-14 22:20:15 +0000372 if (!wp_loc_sp) {
373 WatchpointLocation *new_loc = new WatchpointLocation(addr, size);
374 if (!new_loc) {
375 printf("WatchpointLocation ctor failed, out of memory?\n");
376 return wp_loc_sp;
377 }
378 new_loc->SetWatchpointType(type);
379 wp_loc_sp.reset(new_loc);
380 m_watchpoint_location_list.Add(wp_loc_sp);
381 }
Johnny Chen5b2fc572011-09-14 20:23:45 +0000382
Johnny Chen5b2fc572011-09-14 20:23:45 +0000383 Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000384 if (log)
385 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
386 __FUNCTION__,
387 rc.Success() ? "succeeded" : "failed",
388 wp_loc_sp->GetID());
389
Johnny Chen22a56cc2011-09-14 22:20:15 +0000390 if (rc.Fail()) wp_loc_sp.reset();
Johnny Chen9bf11992011-09-13 01:15:36 +0000391 return wp_loc_sp;
Johnny Chen34bbf852011-09-12 23:38:44 +0000392}
393
Chris Lattner24943d22010-06-08 16:52:24 +0000394void
395Target::RemoveAllBreakpoints (bool internal_also)
396{
Greg Claytone005f2c2010-11-06 01:53:30 +0000397 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000398 if (log)
399 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
400
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000401 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000402 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000403 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000404
405 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000406}
407
408void
409Target::DisableAllBreakpoints (bool internal_also)
410{
Greg Claytone005f2c2010-11-06 01:53:30 +0000411 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000412 if (log)
413 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
414
415 m_breakpoint_list.SetEnabledAll (false);
416 if (internal_also)
417 m_internal_breakpoint_list.SetEnabledAll (false);
418}
419
420void
421Target::EnableAllBreakpoints (bool internal_also)
422{
Greg Claytone005f2c2010-11-06 01:53:30 +0000423 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000424 if (log)
425 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
426
427 m_breakpoint_list.SetEnabledAll (true);
428 if (internal_also)
429 m_internal_breakpoint_list.SetEnabledAll (true);
430}
431
432bool
433Target::RemoveBreakpointByID (break_id_t break_id)
434{
Greg Claytone005f2c2010-11-06 01:53:30 +0000435 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000436 if (log)
437 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
438
439 if (DisableBreakpointByID (break_id))
440 {
441 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000442 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000443 else
Jim Inghamd1686902010-10-14 23:45:03 +0000444 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000445 if (m_last_created_breakpoint)
446 {
447 if (m_last_created_breakpoint->GetID() == break_id)
448 m_last_created_breakpoint.reset();
449 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000450 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000451 }
Chris Lattner24943d22010-06-08 16:52:24 +0000452 return true;
453 }
454 return false;
455}
456
457bool
458Target::DisableBreakpointByID (break_id_t break_id)
459{
Greg Claytone005f2c2010-11-06 01:53:30 +0000460 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000461 if (log)
462 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
463
464 BreakpointSP bp_sp;
465
466 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
467 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
468 else
469 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
470 if (bp_sp)
471 {
472 bp_sp->SetEnabled (false);
473 return true;
474 }
475 return false;
476}
477
478bool
479Target::EnableBreakpointByID (break_id_t break_id)
480{
Greg Claytone005f2c2010-11-06 01:53:30 +0000481 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000482 if (log)
483 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
484 __FUNCTION__,
485 break_id,
486 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
487
488 BreakpointSP bp_sp;
489
490 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
491 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
492 else
493 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
494
495 if (bp_sp)
496 {
497 bp_sp->SetEnabled (true);
498 return true;
499 }
500 return false;
501}
502
503ModuleSP
504Target::GetExecutableModule ()
505{
Greg Clayton5beb99d2011-08-11 02:48:45 +0000506 return m_images.GetModuleAtIndex(0);
507}
508
509Module*
510Target::GetExecutableModulePointer ()
511{
512 return m_images.GetModulePointerAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000513}
514
515void
516Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
517{
518 m_images.Clear();
519 m_scratch_ast_context_ap.reset();
520
521 if (executable_sp.get())
522 {
523 Timer scoped_timer (__PRETTY_FUNCTION__,
524 "Target::SetExecutableModule (executable = '%s/%s')",
525 executable_sp->GetFileSpec().GetDirectory().AsCString(),
526 executable_sp->GetFileSpec().GetFilename().AsCString());
527
528 m_images.Append(executable_sp); // The first image is our exectuable file
529
Jim Ingham7508e732010-08-09 23:31:02 +0000530 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000531 if (!m_arch.IsValid())
532 m_arch = executable_sp->GetArchitecture();
Jim Ingham7508e732010-08-09 23:31:02 +0000533
Chris Lattner24943d22010-06-08 16:52:24 +0000534 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +0000535 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Jim Inghamfdf24ef2011-09-08 22:13:49 +0000536 // Let's find the file & line for main and set the default source file from there.
537 if (!m_source_manager.DefaultFileAndLineSet())
538 {
539 SymbolContextList sc_list;
540 uint32_t num_matches;
541 ConstString main_name("main");
542 bool symbols_okay = false; // Force it to be a debug symbol.
543 bool append = false;
544 num_matches = executable_sp->FindFunctions (main_name, eFunctionNameTypeBase, symbols_okay, append, sc_list);
545 for (uint32_t idx = 0; idx < num_matches; idx++)
546 {
547 SymbolContext sc;
548 sc_list.GetContextAtIndex(idx, sc);
549 if (sc.line_entry.file)
550 {
551 m_source_manager.SetDefaultFileAndLine(sc.line_entry.file, sc.line_entry.line);
552 break;
553 }
554 }
555 }
Chris Lattner24943d22010-06-08 16:52:24 +0000556
557 if (executable_objfile)
558 {
559 executable_objfile->GetDependentModules(dependent_files);
560 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
561 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000562 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
563 FileSpec platform_dependent_file_spec;
564 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000565 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +0000566 else
567 platform_dependent_file_spec = dependent_file_spec;
568
569 ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec,
Greg Clayton24bc5d92011-03-30 18:16:51 +0000570 m_arch));
Chris Lattner24943d22010-06-08 16:52:24 +0000571 if (image_module_sp.get())
572 {
Chris Lattner24943d22010-06-08 16:52:24 +0000573 ObjectFile *objfile = image_module_sp->GetObjectFile();
574 if (objfile)
575 objfile->GetDependentModules(dependent_files);
576 }
577 }
578 }
579
Chris Lattner24943d22010-06-08 16:52:24 +0000580 }
Caroline Tice1ebef442010-09-27 00:30:10 +0000581
582 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +0000583}
584
585
Jim Ingham7508e732010-08-09 23:31:02 +0000586bool
587Target::SetArchitecture (const ArchSpec &arch_spec)
588{
Greg Clayton24bc5d92011-03-30 18:16:51 +0000589 if (m_arch == arch_spec)
Jim Ingham7508e732010-08-09 23:31:02 +0000590 {
591 // If we're setting the architecture to our current architecture, we
592 // don't need to do anything.
593 return true;
594 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000595 else if (!m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +0000596 {
597 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000598 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000599 return true;
600 }
601 else
602 {
603 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton24bc5d92011-03-30 18:16:51 +0000604 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000605 ModuleSP executable_sp = GetExecutableModule ();
606 m_images.Clear();
607 m_scratch_ast_context_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +0000608 // Need to do something about unsetting breakpoints.
609
610 if (executable_sp)
611 {
612 FileSpec exec_file_spec = executable_sp->GetFileSpec();
613 Error error = ModuleList::GetSharedModule(exec_file_spec,
614 arch_spec,
615 NULL,
616 NULL,
617 0,
618 executable_sp,
619 NULL,
620 NULL);
621
622 if (!error.Fail() && executable_sp)
623 {
624 SetExecutableModule (executable_sp, true);
625 return true;
626 }
627 else
628 {
629 return false;
630 }
631 }
632 else
633 {
634 return false;
635 }
636 }
637}
Chris Lattner24943d22010-06-08 16:52:24 +0000638
Chris Lattner24943d22010-06-08 16:52:24 +0000639void
640Target::ModuleAdded (ModuleSP &module_sp)
641{
642 // A module is being added to this target for the first time
643 ModuleList module_list;
644 module_list.Append(module_sp);
645 ModulesDidLoad (module_list);
646}
647
648void
649Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
650{
Jim Ingham3b8a6052011-08-03 01:00:06 +0000651 // A module is replacing an already added module
Chris Lattner24943d22010-06-08 16:52:24 +0000652 ModuleList module_list;
653 module_list.Append (old_module_sp);
654 ModulesDidUnload (module_list);
655 module_list.Clear ();
656 module_list.Append (new_module_sp);
657 ModulesDidLoad (module_list);
658}
659
660void
661Target::ModulesDidLoad (ModuleList &module_list)
662{
663 m_breakpoint_list.UpdateBreakpoints (module_list, true);
664 // TODO: make event data that packages up the module_list
665 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
666}
667
668void
669Target::ModulesDidUnload (ModuleList &module_list)
670{
671 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000672
673 // Remove the images from the target image list
674 m_images.Remove(module_list);
675
Chris Lattner24943d22010-06-08 16:52:24 +0000676 // TODO: make event data that packages up the module_list
677 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
678}
679
680size_t
Greg Clayton26100dc2011-01-07 01:57:07 +0000681Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
682{
683 const Section *section = addr.GetSection();
684 if (section && section->GetModule())
685 {
686 ObjectFile *objfile = section->GetModule()->GetObjectFile();
687 if (objfile)
688 {
689 size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
690 addr.GetOffset(),
691 dst,
692 dst_len);
693 if (bytes_read > 0)
694 return bytes_read;
695 else
696 error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
697 }
698 else
699 {
700 error.SetErrorString("address isn't from a object file");
701 }
702 }
703 else
704 {
705 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
706 }
707 return 0;
708}
709
710size_t
Enrico Granata91544802011-09-06 19:20:51 +0000711Target::ReadMemory (const Address& addr,
712 bool prefer_file_cache,
713 void *dst,
714 size_t dst_len,
715 Error &error,
716 lldb::addr_t *load_addr_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +0000717{
Chris Lattner24943d22010-06-08 16:52:24 +0000718 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +0000719
Enrico Granata91544802011-09-06 19:20:51 +0000720 // if we end up reading this from process memory, we will fill this
721 // with the actual load address
722 if (load_addr_ptr)
723 *load_addr_ptr = LLDB_INVALID_ADDRESS;
724
Greg Clayton70436352010-06-30 23:03:03 +0000725 bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
726
Greg Clayton26100dc2011-01-07 01:57:07 +0000727 size_t bytes_read = 0;
Greg Clayton9b82f862011-07-11 05:12:02 +0000728
729 addr_t load_addr = LLDB_INVALID_ADDRESS;
730 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton889fbd02011-03-26 19:14:58 +0000731 Address resolved_addr;
732 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +0000733 {
Greg Clayton7dd98df2011-07-12 17:06:17 +0000734 if (m_section_load_list.IsEmpty())
Greg Clayton9b82f862011-07-11 05:12:02 +0000735 {
Greg Clayton7dd98df2011-07-12 17:06:17 +0000736 // No sections are loaded, so we must assume we are not running
737 // yet and anything we are given is a file address.
738 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
739 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +0000740 }
Greg Clayton70436352010-06-30 23:03:03 +0000741 else
Greg Clayton9b82f862011-07-11 05:12:02 +0000742 {
Greg Clayton7dd98df2011-07-12 17:06:17 +0000743 // We have at least one section loaded. This can be becuase
744 // we have manually loaded some sections with "target modules load ..."
745 // or because we have have a live process that has sections loaded
746 // through the dynamic loader
747 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
748 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +0000749 }
Greg Clayton70436352010-06-30 23:03:03 +0000750 }
Greg Clayton889fbd02011-03-26 19:14:58 +0000751 if (!resolved_addr.IsValid())
752 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +0000753
Greg Clayton9b82f862011-07-11 05:12:02 +0000754
Greg Clayton26100dc2011-01-07 01:57:07 +0000755 if (prefer_file_cache)
756 {
757 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
758 if (bytes_read > 0)
759 return bytes_read;
760 }
Greg Clayton70436352010-06-30 23:03:03 +0000761
762 if (process_is_valid)
763 {
Greg Clayton9b82f862011-07-11 05:12:02 +0000764 if (load_addr == LLDB_INVALID_ADDRESS)
765 load_addr = resolved_addr.GetLoadAddress (this);
766
Greg Clayton70436352010-06-30 23:03:03 +0000767 if (load_addr == LLDB_INVALID_ADDRESS)
768 {
769 if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
770 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
771 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
772 resolved_addr.GetFileAddress());
773 else
774 error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
775 }
776 else
777 {
Greg Clayton26100dc2011-01-07 01:57:07 +0000778 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +0000779 if (bytes_read != dst_len)
780 {
781 if (error.Success())
782 {
783 if (bytes_read == 0)
Greg Clayton70436352010-06-30 23:03:03 +0000784 error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000785 else
Greg Clayton70436352010-06-30 23:03:03 +0000786 error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000787 }
788 }
Greg Clayton70436352010-06-30 23:03:03 +0000789 if (bytes_read)
Enrico Granata91544802011-09-06 19:20:51 +0000790 {
791 if (load_addr_ptr)
792 *load_addr_ptr = load_addr;
Greg Clayton70436352010-06-30 23:03:03 +0000793 return bytes_read;
Enrico Granata91544802011-09-06 19:20:51 +0000794 }
Greg Clayton70436352010-06-30 23:03:03 +0000795 // If the address is not section offset we have an address that
796 // doesn't resolve to any address in any currently loaded shared
797 // libaries and we failed to read memory so there isn't anything
798 // more we can do. If it is section offset, we might be able to
799 // read cached memory from the object file.
800 if (!resolved_addr.IsSectionOffset())
801 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000802 }
Chris Lattner24943d22010-06-08 16:52:24 +0000803 }
Greg Clayton70436352010-06-30 23:03:03 +0000804
Greg Clayton9b82f862011-07-11 05:12:02 +0000805 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +0000806 {
Greg Clayton26100dc2011-01-07 01:57:07 +0000807 // If we didn't already try and read from the object file cache, then
808 // try it after failing to read from the process.
809 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +0000810 }
811 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000812}
813
Greg Clayton7dd98df2011-07-12 17:06:17 +0000814size_t
815Target::ReadScalarIntegerFromMemory (const Address& addr,
816 bool prefer_file_cache,
817 uint32_t byte_size,
818 bool is_signed,
819 Scalar &scalar,
820 Error &error)
821{
822 uint64_t uval;
823
824 if (byte_size <= sizeof(uval))
825 {
826 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
827 if (bytes_read == byte_size)
828 {
829 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
830 uint32_t offset = 0;
831 if (byte_size <= 4)
832 scalar = data.GetMaxU32 (&offset, byte_size);
833 else
834 scalar = data.GetMaxU64 (&offset, byte_size);
835
836 if (is_signed)
837 scalar.SignExtend(byte_size * 8);
838 return bytes_read;
839 }
840 }
841 else
842 {
843 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
844 }
845 return 0;
846}
847
848uint64_t
849Target::ReadUnsignedIntegerFromMemory (const Address& addr,
850 bool prefer_file_cache,
851 size_t integer_byte_size,
852 uint64_t fail_value,
853 Error &error)
854{
855 Scalar scalar;
856 if (ReadScalarIntegerFromMemory (addr,
857 prefer_file_cache,
858 integer_byte_size,
859 false,
860 scalar,
861 error))
862 return scalar.ULongLong(fail_value);
863 return fail_value;
864}
865
866bool
867Target::ReadPointerFromMemory (const Address& addr,
868 bool prefer_file_cache,
869 Error &error,
870 Address &pointer_addr)
871{
872 Scalar scalar;
873 if (ReadScalarIntegerFromMemory (addr,
874 prefer_file_cache,
875 m_arch.GetAddressByteSize(),
876 false,
877 scalar,
878 error))
879 {
880 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
881 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
882 {
883 if (m_section_load_list.IsEmpty())
884 {
885 // No sections are loaded, so we must assume we are not running
886 // yet and anything we are given is a file address.
887 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
888 }
889 else
890 {
891 // We have at least one section loaded. This can be becuase
892 // we have manually loaded some sections with "target modules load ..."
893 // or because we have have a live process that has sections loaded
894 // through the dynamic loader
895 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
896 }
897 // We weren't able to resolve the pointer value, so just return
898 // an address with no section
899 if (!pointer_addr.IsValid())
900 pointer_addr.SetOffset (pointer_vm_addr);
901 return true;
902
903 }
904 }
905 return false;
906}
Chris Lattner24943d22010-06-08 16:52:24 +0000907
908ModuleSP
909Target::GetSharedModule
910(
911 const FileSpec& file_spec,
912 const ArchSpec& arch,
Greg Clayton0467c782011-02-04 18:53:10 +0000913 const lldb_private::UUID *uuid_ptr,
Chris Lattner24943d22010-06-08 16:52:24 +0000914 const ConstString *object_name,
915 off_t object_offset,
916 Error *error_ptr
917)
918{
919 // Don't pass in the UUID so we can tell if we have a stale value in our list
920 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
921 bool did_create_module = false;
922 ModuleSP module_sp;
923
Chris Lattner24943d22010-06-08 16:52:24 +0000924 Error error;
925
Greg Clayton24bc5d92011-03-30 18:16:51 +0000926 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner24943d22010-06-08 16:52:24 +0000927 if (m_image_search_paths.GetSize())
928 {
929 FileSpec transformed_spec;
930 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
931 {
932 transformed_spec.GetFilename() = file_spec.GetFilename();
933 error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
934 }
935 }
936
Greg Clayton24bc5d92011-03-30 18:16:51 +0000937 // The platform is responsible for finding and caching an appropriate
938 // module in the shared module cache.
939 if (m_platform_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000940 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000941 FileSpec platform_file_spec;
942 error = m_platform_sp->GetSharedModule (file_spec,
943 arch,
944 uuid_ptr,
945 object_name,
946 object_offset,
947 module_sp,
948 &old_module_sp,
949 &did_create_module);
950 }
951 else
952 {
953 error.SetErrorString("no platform is currently set");
Chris Lattner24943d22010-06-08 16:52:24 +0000954 }
955
Greg Clayton24bc5d92011-03-30 18:16:51 +0000956 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner24943d22010-06-08 16:52:24 +0000957 if (module_sp)
958 {
959 m_images.Append (module_sp);
960 if (did_create_module)
961 {
962 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
963 ModuleUpdated(old_module_sp, module_sp);
964 else
965 ModuleAdded(module_sp);
966 }
967 }
968 if (error_ptr)
969 *error_ptr = error;
970 return module_sp;
971}
972
973
974Target *
975Target::CalculateTarget ()
976{
977 return this;
978}
979
980Process *
981Target::CalculateProcess ()
982{
983 return NULL;
984}
985
986Thread *
987Target::CalculateThread ()
988{
989 return NULL;
990}
991
992StackFrame *
993Target::CalculateStackFrame ()
994{
995 return NULL;
996}
997
998void
Greg Claytona830adb2010-10-04 01:05:56 +0000999Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001000{
1001 exe_ctx.target = this;
1002 exe_ctx.process = NULL; // Do NOT fill in process...
1003 exe_ctx.thread = NULL;
1004 exe_ctx.frame = NULL;
1005}
1006
1007PathMappingList &
1008Target::GetImageSearchPathList ()
1009{
1010 return m_image_search_paths;
1011}
1012
1013void
1014Target::ImageSearchPathsChanged
1015(
1016 const PathMappingList &path_list,
1017 void *baton
1018)
1019{
1020 Target *target = (Target *)baton;
Greg Clayton5beb99d2011-08-11 02:48:45 +00001021 ModuleSP exe_module_sp (target->GetExecutableModule());
1022 if (exe_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001023 {
Greg Clayton5beb99d2011-08-11 02:48:45 +00001024 target->m_images.Clear();
1025 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +00001026 }
1027}
1028
1029ClangASTContext *
1030Target::GetScratchClangASTContext()
1031{
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001032 // Now see if we know the target triple, and if so, create our scratch AST context:
1033 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid())
1034 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Chris Lattner24943d22010-06-08 16:52:24 +00001035 return m_scratch_ast_context_ap.get();
1036}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001037
Greg Clayton990de7b2010-11-18 23:32:35 +00001038void
Caroline Tice2a456812011-03-10 22:14:10 +00001039Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +00001040{
Greg Clayton990de7b2010-11-18 23:32:35 +00001041 UserSettingsControllerSP &usc = GetSettingsController();
1042 usc.reset (new SettingsController);
1043 UserSettingsController::InitializeSettingsController (usc,
1044 SettingsController::global_settings_table,
1045 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001046
1047 // Now call SettingsInitialize() on each 'child' setting of Target
1048 Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001049}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001050
Greg Clayton990de7b2010-11-18 23:32:35 +00001051void
Caroline Tice2a456812011-03-10 22:14:10 +00001052Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001053{
Caroline Tice2a456812011-03-10 22:14:10 +00001054
1055 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1056
1057 Process::SettingsTerminate ();
1058
1059 // Now terminate Target Settings.
1060
Greg Clayton990de7b2010-11-18 23:32:35 +00001061 UserSettingsControllerSP &usc = GetSettingsController();
1062 UserSettingsController::FinalizeSettingsController (usc);
1063 usc.reset();
1064}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001065
Greg Clayton990de7b2010-11-18 23:32:35 +00001066UserSettingsControllerSP &
1067Target::GetSettingsController ()
1068{
1069 static UserSettingsControllerSP g_settings_controller;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001070 return g_settings_controller;
1071}
1072
1073ArchSpec
1074Target::GetDefaultArchitecture ()
1075{
Greg Clayton940b1032011-02-23 00:35:02 +00001076 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1077
1078 if (settings_controller_sp)
1079 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1080 return ArchSpec();
Caroline Tice5bc8c972010-09-20 20:44:43 +00001081}
1082
1083void
Greg Clayton940b1032011-02-23 00:35:02 +00001084Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001085{
Greg Clayton940b1032011-02-23 00:35:02 +00001086 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1087
1088 if (settings_controller_sp)
1089 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001090}
1091
Greg Claytona830adb2010-10-04 01:05:56 +00001092Target *
1093Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1094{
1095 // The target can either exist in the "process" of ExecutionContext, or in
1096 // the "target_sp" member of SymbolContext. This accessor helper function
1097 // will get the target from one of these locations.
1098
1099 Target *target = NULL;
1100 if (sc_ptr != NULL)
1101 target = sc_ptr->target_sp.get();
1102 if (target == NULL)
1103 {
1104 if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL)
1105 target = &exe_ctx_ptr->process->GetTarget();
1106 }
1107 return target;
1108}
1109
1110
Caroline Tice1ebef442010-09-27 00:30:10 +00001111void
1112Target::UpdateInstanceName ()
1113{
1114 StreamString sstr;
1115
Greg Clayton5beb99d2011-08-11 02:48:45 +00001116 Module *exe_module = GetExecutableModulePointer();
1117 if (exe_module)
Caroline Tice1ebef442010-09-27 00:30:10 +00001118 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00001119 sstr.Printf ("%s_%s",
Greg Clayton5beb99d2011-08-11 02:48:45 +00001120 exe_module->GetFileSpec().GetFilename().AsCString(),
1121 exe_module->GetArchitecture().GetArchitectureName());
1122 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
Caroline Tice1ebef442010-09-27 00:30:10 +00001123 }
1124}
1125
Sean Callanan77e93942010-10-29 00:29:03 +00001126const char *
1127Target::GetExpressionPrefixContentsAsCString ()
1128{
Greg Claytonff44ab42011-04-23 02:04:55 +00001129 if (m_expr_prefix_contents_sp)
1130 return (const char *)m_expr_prefix_contents_sp->GetBytes();
1131 return NULL;
Sean Callanan77e93942010-10-29 00:29:03 +00001132}
1133
Greg Clayton427f2902010-12-14 02:59:59 +00001134ExecutionResults
1135Target::EvaluateExpression
1136(
1137 const char *expr_cstr,
1138 StackFrame *frame,
Sean Callanan47dc4572011-09-15 02:13:07 +00001139 lldb_private::ExecutionPolicy execution_policy,
Greg Clayton427f2902010-12-14 02:59:59 +00001140 bool unwind_on_error,
Sean Callanan6a925532011-01-13 08:53:35 +00001141 bool keep_in_memory,
Jim Ingham10de7d12011-05-04 03:43:18 +00001142 lldb::DynamicValueType use_dynamic,
Greg Clayton427f2902010-12-14 02:59:59 +00001143 lldb::ValueObjectSP &result_valobj_sp
1144)
1145{
1146 ExecutionResults execution_results = eExecutionSetupError;
1147
1148 result_valobj_sp.reset();
Jim Ingham3613ae12011-05-12 02:06:14 +00001149
1150 // We shouldn't run stop hooks in expressions.
1151 // Be sure to reset this if you return anywhere within this function.
1152 bool old_suppress_value = m_suppress_stop_hooks;
1153 m_suppress_stop_hooks = true;
Greg Clayton427f2902010-12-14 02:59:59 +00001154
1155 ExecutionContext exe_ctx;
1156 if (frame)
1157 {
1158 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001159 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +00001160 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granataf6698502011-08-09 01:04:56 +00001161 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1162 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham10de7d12011-05-04 03:43:18 +00001163 lldb::VariableSP var_sp;
1164 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1165 use_dynamic,
1166 expr_path_options,
1167 var_sp,
1168 error);
Greg Clayton427f2902010-12-14 02:59:59 +00001169 }
1170 else if (m_process_sp)
1171 {
1172 m_process_sp->CalculateExecutionContext(exe_ctx);
1173 }
1174 else
1175 {
1176 CalculateExecutionContext(exe_ctx);
1177 }
1178
1179 if (result_valobj_sp)
1180 {
1181 execution_results = eExecutionCompleted;
1182 // We got a result from the frame variable expression path above...
1183 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1184
1185 lldb::ValueObjectSP const_valobj_sp;
1186
1187 // Check in case our value is already a constant value
1188 if (result_valobj_sp->GetIsConstant())
1189 {
1190 const_valobj_sp = result_valobj_sp;
1191 const_valobj_sp->SetName (persistent_variable_name);
1192 }
1193 else
Jim Inghame41494a2011-04-16 00:01:13 +00001194 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001195 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +00001196 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001197 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001198 if (dynamic_sp)
1199 result_valobj_sp = dynamic_sp;
1200 }
1201
Jim Inghamfa3a16a2011-03-31 00:19:25 +00001202 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Inghame41494a2011-04-16 00:01:13 +00001203 }
Greg Clayton427f2902010-12-14 02:59:59 +00001204
Sean Callanan6a925532011-01-13 08:53:35 +00001205 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1206
Greg Clayton427f2902010-12-14 02:59:59 +00001207 result_valobj_sp = const_valobj_sp;
1208
Sean Callanan6a925532011-01-13 08:53:35 +00001209 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1210 assert (clang_expr_variable_sp.get());
1211
1212 // Set flags and live data as appropriate
1213
1214 const Value &result_value = live_valobj_sp->GetValue();
1215
1216 switch (result_value.GetValueType())
1217 {
1218 case Value::eValueTypeHostAddress:
1219 case Value::eValueTypeFileAddress:
1220 // we don't do anything with these for now
1221 break;
1222 case Value::eValueTypeScalar:
1223 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1224 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1225 break;
1226 case Value::eValueTypeLoadAddress:
1227 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1228 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1229 break;
1230 }
Greg Clayton427f2902010-12-14 02:59:59 +00001231 }
1232 else
1233 {
1234 // Make sure we aren't just trying to see the value of a persistent
1235 // variable (something like "$0")
Greg Claytona875b642011-01-09 21:07:35 +00001236 lldb::ClangExpressionVariableSP persistent_var_sp;
1237 // Only check for persistent variables the expression starts with a '$'
1238 if (expr_cstr[0] == '$')
1239 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1240
Greg Clayton427f2902010-12-14 02:59:59 +00001241 if (persistent_var_sp)
1242 {
1243 result_valobj_sp = persistent_var_sp->GetValueObject ();
1244 execution_results = eExecutionCompleted;
1245 }
1246 else
1247 {
1248 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan47dc4572011-09-15 02:13:07 +00001249
Greg Clayton427f2902010-12-14 02:59:59 +00001250 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan47dc4572011-09-15 02:13:07 +00001251 execution_policy,
Sean Callanan6a925532011-01-13 08:53:35 +00001252 unwind_on_error,
Greg Clayton427f2902010-12-14 02:59:59 +00001253 expr_cstr,
1254 prefix,
1255 result_valobj_sp);
1256 }
1257 }
Jim Ingham3613ae12011-05-12 02:06:14 +00001258
1259 m_suppress_stop_hooks = old_suppress_value;
1260
Greg Clayton427f2902010-12-14 02:59:59 +00001261 return execution_results;
1262}
1263
Greg Claytonc0fa5332011-05-22 22:46:53 +00001264lldb::addr_t
1265Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1266{
1267 addr_t code_addr = load_addr;
1268 switch (m_arch.GetMachine())
1269 {
1270 case llvm::Triple::arm:
1271 case llvm::Triple::thumb:
1272 switch (addr_class)
1273 {
1274 case eAddressClassData:
1275 case eAddressClassDebug:
1276 return LLDB_INVALID_ADDRESS;
1277
1278 case eAddressClassUnknown:
1279 case eAddressClassInvalid:
1280 case eAddressClassCode:
1281 case eAddressClassCodeAlternateISA:
1282 case eAddressClassRuntime:
1283 // Check if bit zero it no set?
1284 if ((code_addr & 1ull) == 0)
1285 {
1286 // Bit zero isn't set, check if the address is a multiple of 2?
1287 if (code_addr & 2ull)
1288 {
1289 // The address is a multiple of 2 so it must be thumb, set bit zero
1290 code_addr |= 1ull;
1291 }
1292 else if (addr_class == eAddressClassCodeAlternateISA)
1293 {
1294 // We checked the address and the address claims to be the alternate ISA
1295 // which means thumb, so set bit zero.
1296 code_addr |= 1ull;
1297 }
1298 }
1299 break;
1300 }
1301 break;
1302
1303 default:
1304 break;
1305 }
1306 return code_addr;
1307}
1308
1309lldb::addr_t
1310Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1311{
1312 addr_t opcode_addr = load_addr;
1313 switch (m_arch.GetMachine())
1314 {
1315 case llvm::Triple::arm:
1316 case llvm::Triple::thumb:
1317 switch (addr_class)
1318 {
1319 case eAddressClassData:
1320 case eAddressClassDebug:
1321 return LLDB_INVALID_ADDRESS;
1322
1323 case eAddressClassInvalid:
1324 case eAddressClassUnknown:
1325 case eAddressClassCode:
1326 case eAddressClassCodeAlternateISA:
1327 case eAddressClassRuntime:
1328 opcode_addr &= ~(1ull);
1329 break;
1330 }
1331 break;
1332
1333 default:
1334 break;
1335 }
1336 return opcode_addr;
1337}
1338
Jim Inghamd60d94a2011-03-11 03:53:59 +00001339lldb::user_id_t
1340Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1341{
1342 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
1343 new_hook_sp.reset (new StopHook(GetSP(), new_uid));
1344 m_stop_hooks[new_uid] = new_hook_sp;
1345 return new_uid;
1346}
1347
1348bool
1349Target::RemoveStopHookByID (lldb::user_id_t user_id)
1350{
1351 size_t num_removed;
1352 num_removed = m_stop_hooks.erase (user_id);
1353 if (num_removed == 0)
1354 return false;
1355 else
1356 return true;
1357}
1358
1359void
1360Target::RemoveAllStopHooks ()
1361{
1362 m_stop_hooks.clear();
1363}
1364
1365Target::StopHookSP
1366Target::GetStopHookByID (lldb::user_id_t user_id)
1367{
1368 StopHookSP found_hook;
1369
1370 StopHookCollection::iterator specified_hook_iter;
1371 specified_hook_iter = m_stop_hooks.find (user_id);
1372 if (specified_hook_iter != m_stop_hooks.end())
1373 found_hook = (*specified_hook_iter).second;
1374 return found_hook;
1375}
1376
1377bool
1378Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1379{
1380 StopHookCollection::iterator specified_hook_iter;
1381 specified_hook_iter = m_stop_hooks.find (user_id);
1382 if (specified_hook_iter == m_stop_hooks.end())
1383 return false;
1384
1385 (*specified_hook_iter).second->SetIsActive (active_state);
1386 return true;
1387}
1388
1389void
1390Target::SetAllStopHooksActiveState (bool active_state)
1391{
1392 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1393 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1394 {
1395 (*pos).second->SetIsActive (active_state);
1396 }
1397}
1398
1399void
1400Target::RunStopHooks ()
1401{
Jim Ingham3613ae12011-05-12 02:06:14 +00001402 if (m_suppress_stop_hooks)
1403 return;
1404
Jim Inghamd60d94a2011-03-11 03:53:59 +00001405 if (!m_process_sp)
1406 return;
1407
1408 if (m_stop_hooks.empty())
1409 return;
1410
1411 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1412
1413 // If there aren't any active stop hooks, don't bother either:
1414 bool any_active_hooks = false;
1415 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1416 {
1417 if ((*pos).second->IsActive())
1418 {
1419 any_active_hooks = true;
1420 break;
1421 }
1422 }
1423 if (!any_active_hooks)
1424 return;
1425
1426 CommandReturnObject result;
1427
1428 std::vector<ExecutionContext> exc_ctx_with_reasons;
1429 std::vector<SymbolContext> sym_ctx_with_reasons;
1430
1431 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1432 size_t num_threads = cur_threadlist.GetSize();
1433 for (size_t i = 0; i < num_threads; i++)
1434 {
1435 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1436 if (cur_thread_sp->ThreadStoppedForAReason())
1437 {
1438 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1439 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1440 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1441 }
1442 }
1443
1444 // If no threads stopped for a reason, don't run the stop-hooks.
1445 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1446 if (num_exe_ctx == 0)
1447 return;
1448
Jim Inghame5ed8e92011-06-02 23:58:26 +00001449 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1450 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001451
1452 bool keep_going = true;
1453 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00001454 bool print_hook_header;
1455 bool print_thread_header;
1456
1457 if (num_exe_ctx == 1)
1458 print_thread_header = false;
1459 else
1460 print_thread_header = true;
1461
1462 if (m_stop_hooks.size() == 1)
1463 print_hook_header = false;
1464 else
1465 print_hook_header = true;
1466
Jim Inghamd60d94a2011-03-11 03:53:59 +00001467 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1468 {
1469 // result.Clear();
1470 StopHookSP cur_hook_sp = (*pos).second;
1471 if (!cur_hook_sp->IsActive())
1472 continue;
1473
1474 bool any_thread_matched = false;
1475 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1476 {
1477 if ((cur_hook_sp->GetSpecifier () == NULL
1478 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1479 && (cur_hook_sp->GetThreadSpecifier() == NULL
1480 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].thread)))
1481 {
1482 if (!hooks_ran)
1483 {
Jim Inghamc54840c2011-03-22 01:47:27 +00001484 result.AppendMessage("\n** Stop Hooks **");
Jim Inghamd60d94a2011-03-11 03:53:59 +00001485 hooks_ran = true;
1486 }
Jim Inghamc54840c2011-03-22 01:47:27 +00001487 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001488 {
1489 result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID());
1490 any_thread_matched = true;
1491 }
1492
Jim Inghamc54840c2011-03-22 01:47:27 +00001493 if (print_thread_header)
1494 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].thread->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001495
1496 bool stop_on_continue = true;
1497 bool stop_on_error = true;
1498 bool echo_commands = false;
1499 bool print_results = true;
1500 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001501 &exc_ctx_with_reasons[i],
1502 stop_on_continue,
1503 stop_on_error,
1504 echo_commands,
1505 print_results,
1506 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00001507
1508 // If the command started the target going again, we should bag out of
1509 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00001510 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1511 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001512 {
1513 result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID());
1514 keep_going = false;
1515 }
1516 }
1517 }
1518 }
1519 if (hooks_ran)
1520 result.AppendMessage ("\n** End Stop Hooks **\n");
Caroline Tice4a348082011-05-02 20:41:46 +00001521
1522 result.GetImmediateOutputStream()->Flush();
1523 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00001524}
1525
Greg Claytonbbea1332011-07-08 00:48:09 +00001526bool
1527Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
1528{
1529 bool changed = false;
1530 if (module)
1531 {
1532 ObjectFile *object_file = module->GetObjectFile();
1533 if (object_file)
1534 {
1535 SectionList *section_list = object_file->GetSectionList ();
1536 if (section_list)
1537 {
1538 // All sections listed in the dyld image info structure will all
1539 // either be fixed up already, or they will all be off by a single
1540 // slide amount that is determined by finding the first segment
1541 // that is at file offset zero which also has bytes (a file size
1542 // that is greater than zero) in the object file.
1543
1544 // Determine the slide amount (if any)
1545 const size_t num_sections = section_list->GetSize();
1546 size_t sect_idx = 0;
1547 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1548 {
1549 // Iterate through the object file sections to find the
1550 // first section that starts of file offset zero and that
1551 // has bytes in the file...
1552 Section *section = section_list->GetSectionAtIndex (sect_idx).get();
1553 if (section)
1554 {
1555 if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
1556 changed = true;
1557 }
1558 }
1559 }
1560 }
1561 }
1562 return changed;
1563}
1564
1565
Jim Inghamd60d94a2011-03-11 03:53:59 +00001566//--------------------------------------------------------------
1567// class Target::StopHook
1568//--------------------------------------------------------------
1569
1570
1571Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1572 UserID (uid),
1573 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00001574 m_commands (),
1575 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001576 m_thread_spec_ap(NULL),
1577 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001578{
1579}
1580
1581Target::StopHook::StopHook (const StopHook &rhs) :
1582 UserID (rhs.GetID()),
1583 m_target_sp (rhs.m_target_sp),
1584 m_commands (rhs.m_commands),
1585 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001586 m_thread_spec_ap (NULL),
1587 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001588{
1589 if (rhs.m_thread_spec_ap.get() != NULL)
1590 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1591}
1592
1593
1594Target::StopHook::~StopHook ()
1595{
1596}
1597
1598void
1599Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
1600{
1601 m_thread_spec_ap.reset (specifier);
1602}
1603
1604
1605void
1606Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
1607{
1608 int indent_level = s->GetIndentLevel();
1609
1610 s->SetIndentLevel(indent_level + 2);
1611
1612 s->Printf ("Hook: %d\n", GetID());
1613 if (m_active)
1614 s->Indent ("State: enabled\n");
1615 else
1616 s->Indent ("State: disabled\n");
1617
1618 if (m_specifier_sp)
1619 {
1620 s->Indent();
1621 s->PutCString ("Specifier:\n");
1622 s->SetIndentLevel (indent_level + 4);
1623 m_specifier_sp->GetDescription (s, level);
1624 s->SetIndentLevel (indent_level + 2);
1625 }
1626
1627 if (m_thread_spec_ap.get() != NULL)
1628 {
1629 StreamString tmp;
1630 s->Indent("Thread:\n");
1631 m_thread_spec_ap->GetDescription (&tmp, level);
1632 s->SetIndentLevel (indent_level + 4);
1633 s->Indent (tmp.GetData());
1634 s->PutCString ("\n");
1635 s->SetIndentLevel (indent_level + 2);
1636 }
1637
1638 s->Indent ("Commands: \n");
1639 s->SetIndentLevel (indent_level + 4);
1640 uint32_t num_commands = m_commands.GetSize();
1641 for (uint32_t i = 0; i < num_commands; i++)
1642 {
1643 s->Indent(m_commands.GetStringAtIndex(i));
1644 s->PutCString ("\n");
1645 }
1646 s->SetIndentLevel (indent_level);
1647}
1648
1649
Caroline Tice5bc8c972010-09-20 20:44:43 +00001650//--------------------------------------------------------------
1651// class Target::SettingsController
1652//--------------------------------------------------------------
1653
1654Target::SettingsController::SettingsController () :
1655 UserSettingsController ("target", Debugger::GetSettingsController()),
1656 m_default_architecture ()
1657{
1658 m_default_settings.reset (new TargetInstanceSettings (*this, false,
1659 InstanceSettings::GetDefaultName().AsCString()));
1660}
1661
1662Target::SettingsController::~SettingsController ()
1663{
1664}
1665
1666lldb::InstanceSettingsSP
1667Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1668{
Greg Claytonc0c1b0c2010-11-19 03:46:01 +00001669 TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1670 false,
1671 instance_name);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001672 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1673 return new_settings_sp;
1674}
1675
Caroline Tice5bc8c972010-09-20 20:44:43 +00001676
Jim Inghame41494a2011-04-16 00:01:13 +00001677#define TSC_DEFAULT_ARCH "default-arch"
1678#define TSC_EXPR_PREFIX "expr-prefix"
Jim Inghame41494a2011-04-16 00:01:13 +00001679#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
Greg Clayton17cd9952011-04-22 03:55:06 +00001680#define TSC_SKIP_PROLOGUE "skip-prologue"
Greg Claytonff44ab42011-04-23 02:04:55 +00001681#define TSC_SOURCE_MAP "source-map"
Enrico Granata018921d2011-08-12 02:00:06 +00001682#define TSC_MAX_CHILDREN "max-children-count"
Enrico Granata91544802011-09-06 19:20:51 +00001683#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
Greg Claytond284b662011-02-18 01:44:25 +00001684
1685
1686static const ConstString &
1687GetSettingNameForDefaultArch ()
1688{
1689 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytond284b662011-02-18 01:44:25 +00001690 return g_const_string;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001691}
1692
Greg Claytond284b662011-02-18 01:44:25 +00001693static const ConstString &
1694GetSettingNameForExpressionPrefix ()
1695{
1696 static ConstString g_const_string (TSC_EXPR_PREFIX);
1697 return g_const_string;
1698}
1699
1700static const ConstString &
Jim Inghame41494a2011-04-16 00:01:13 +00001701GetSettingNameForPreferDynamicValue ()
1702{
1703 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
1704 return g_const_string;
1705}
1706
Greg Claytonff44ab42011-04-23 02:04:55 +00001707static const ConstString &
1708GetSettingNameForSourcePathMap ()
1709{
1710 static ConstString g_const_string (TSC_SOURCE_MAP);
1711 return g_const_string;
1712}
Greg Claytond284b662011-02-18 01:44:25 +00001713
Greg Clayton17cd9952011-04-22 03:55:06 +00001714static const ConstString &
1715GetSettingNameForSkipPrologue ()
1716{
1717 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
1718 return g_const_string;
1719}
1720
Enrico Granata018921d2011-08-12 02:00:06 +00001721static const ConstString &
1722GetSettingNameForMaxChildren ()
1723{
1724 static ConstString g_const_string (TSC_MAX_CHILDREN);
1725 return g_const_string;
1726}
Greg Clayton17cd9952011-04-22 03:55:06 +00001727
Enrico Granata91544802011-09-06 19:20:51 +00001728static const ConstString &
1729GetSettingNameForMaxStringSummaryLength ()
1730{
1731 static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
1732 return g_const_string;
1733}
Greg Clayton17cd9952011-04-22 03:55:06 +00001734
Caroline Tice5bc8c972010-09-20 20:44:43 +00001735bool
1736Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
1737 const char *index_value,
1738 const char *value,
1739 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00001740 const VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00001741 Error&err)
1742{
Greg Claytond284b662011-02-18 01:44:25 +00001743 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00001744 {
Greg Claytonf15996e2011-04-07 22:46:35 +00001745 m_default_architecture.SetTriple (value, NULL);
Greg Clayton940b1032011-02-23 00:35:02 +00001746 if (!m_default_architecture.IsValid())
1747 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001748 }
1749 return true;
1750}
1751
1752
1753bool
1754Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
1755 StringList &value,
1756 Error &err)
1757{
Greg Claytond284b662011-02-18 01:44:25 +00001758 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00001759 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00001760 // If the arch is invalid (the default), don't show a string for it
1761 if (m_default_architecture.IsValid())
Greg Clayton940b1032011-02-23 00:35:02 +00001762 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Tice5bc8c972010-09-20 20:44:43 +00001763 return true;
1764 }
1765 else
1766 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1767
1768 return false;
1769}
1770
1771//--------------------------------------------------------------
1772// class TargetInstanceSettings
1773//--------------------------------------------------------------
1774
Greg Clayton638351a2010-12-04 00:10:17 +00001775TargetInstanceSettings::TargetInstanceSettings
1776(
1777 UserSettingsController &owner,
1778 bool live_instance,
1779 const char *name
1780) :
Greg Claytond284b662011-02-18 01:44:25 +00001781 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytonff44ab42011-04-23 02:04:55 +00001782 m_expr_prefix_file (),
1783 m_expr_prefix_contents_sp (),
Jim Ingham10de7d12011-05-04 03:43:18 +00001784 m_prefer_dynamic_value (2),
Greg Claytonff44ab42011-04-23 02:04:55 +00001785 m_skip_prologue (true, true),
Enrico Granata018921d2011-08-12 02:00:06 +00001786 m_source_map (NULL, NULL),
Enrico Granata91544802011-09-06 19:20:51 +00001787 m_max_children_display(256),
1788 m_max_strlen_length(1024)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001789{
1790 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1791 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
1792 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1793 // This is true for CreateInstanceName() too.
1794
1795 if (GetInstanceName () == InstanceSettings::InvalidName())
1796 {
1797 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1798 m_owner.RegisterInstanceSettings (this);
1799 }
1800
1801 if (live_instance)
1802 {
1803 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1804 CopyInstanceSettings (pending_settings,false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001805 }
1806}
1807
1808TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Claytonff44ab42011-04-23 02:04:55 +00001809 InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
1810 m_expr_prefix_file (rhs.m_expr_prefix_file),
1811 m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp),
1812 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
1813 m_skip_prologue (rhs.m_skip_prologue),
Enrico Granata018921d2011-08-12 02:00:06 +00001814 m_source_map (rhs.m_source_map),
Enrico Granata91544802011-09-06 19:20:51 +00001815 m_max_children_display(rhs.m_max_children_display),
1816 m_max_strlen_length(rhs.m_max_strlen_length)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001817{
1818 if (m_instance_name != InstanceSettings::GetDefaultName())
1819 {
1820 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1821 CopyInstanceSettings (pending_settings,false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001822 }
1823}
1824
1825TargetInstanceSettings::~TargetInstanceSettings ()
1826{
1827}
1828
1829TargetInstanceSettings&
1830TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
1831{
1832 if (this != &rhs)
1833 {
1834 }
1835
1836 return *this;
1837}
1838
Caroline Tice5bc8c972010-09-20 20:44:43 +00001839void
1840TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1841 const char *index_value,
1842 const char *value,
1843 const ConstString &instance_name,
1844 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00001845 VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00001846 Error &err,
1847 bool pending)
1848{
Greg Claytond284b662011-02-18 01:44:25 +00001849 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00001850 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001851 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
1852 if (err.Success())
Sean Callanan77e93942010-10-29 00:29:03 +00001853 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001854 switch (op)
Sean Callanan77e93942010-10-29 00:29:03 +00001855 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001856 default:
1857 break;
1858 case eVarSetOperationAssign:
1859 case eVarSetOperationAppend:
Sean Callanan77e93942010-10-29 00:29:03 +00001860 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001861 if (!m_expr_prefix_file.GetCurrentValue().Exists())
1862 {
1863 err.SetErrorToGenericError ();
1864 err.SetErrorStringWithFormat ("%s does not exist.\n", value);
1865 return;
1866 }
1867
1868 m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
1869
1870 if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0)
1871 {
1872 err.SetErrorStringWithFormat ("Couldn't read data from '%s'\n", value);
1873 m_expr_prefix_contents_sp.reset();
1874 }
Sean Callanan77e93942010-10-29 00:29:03 +00001875 }
Greg Claytonff44ab42011-04-23 02:04:55 +00001876 break;
1877 case eVarSetOperationClear:
1878 m_expr_prefix_contents_sp.reset();
Sean Callanan77e93942010-10-29 00:29:03 +00001879 }
Sean Callanan77e93942010-10-29 00:29:03 +00001880 }
1881 }
Jim Inghame41494a2011-04-16 00:01:13 +00001882 else if (var_name == GetSettingNameForPreferDynamicValue())
1883 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001884 int new_value;
1885 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
1886 if (err.Success())
1887 m_prefer_dynamic_value = new_value;
Greg Clayton17cd9952011-04-22 03:55:06 +00001888 }
1889 else if (var_name == GetSettingNameForSkipPrologue())
1890 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001891 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
1892 }
Enrico Granata018921d2011-08-12 02:00:06 +00001893 else if (var_name == GetSettingNameForMaxChildren())
1894 {
1895 bool ok;
1896 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
1897 if (ok)
1898 m_max_children_display = new_value;
1899 }
Enrico Granata91544802011-09-06 19:20:51 +00001900 else if (var_name == GetSettingNameForMaxStringSummaryLength())
1901 {
1902 bool ok;
1903 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
1904 if (ok)
1905 m_max_strlen_length = new_value;
1906 }
Greg Claytonff44ab42011-04-23 02:04:55 +00001907 else if (var_name == GetSettingNameForSourcePathMap ())
1908 {
1909 switch (op)
1910 {
1911 case eVarSetOperationReplace:
1912 case eVarSetOperationInsertBefore:
1913 case eVarSetOperationInsertAfter:
1914 case eVarSetOperationRemove:
1915 default:
1916 break;
1917 case eVarSetOperationAssign:
1918 m_source_map.Clear(true);
1919 // Fall through to append....
1920 case eVarSetOperationAppend:
1921 {
1922 Args args(value);
1923 const uint32_t argc = args.GetArgumentCount();
1924 if (argc & 1 || argc == 0)
1925 {
1926 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
1927 }
1928 else
1929 {
1930 char resolved_new_path[PATH_MAX];
1931 FileSpec file_spec;
1932 const char *old_path;
1933 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
1934 {
1935 const char *new_path = args.GetArgumentAtIndex(idx+1);
1936 assert (new_path); // We have an even number of paths, this shouldn't happen!
1937
1938 file_spec.SetFile(new_path, true);
1939 if (file_spec.Exists())
1940 {
1941 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
1942 {
1943 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
1944 return;
1945 }
1946 }
1947 else
1948 {
1949 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
1950 return;
1951 }
1952 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
1953 }
1954 }
1955 }
1956 break;
1957
1958 case eVarSetOperationClear:
1959 m_source_map.Clear(true);
1960 break;
1961 }
Jim Inghame41494a2011-04-16 00:01:13 +00001962 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00001963}
1964
1965void
Greg Claytond284b662011-02-18 01:44:25 +00001966TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001967{
Sean Callanan77e93942010-10-29 00:29:03 +00001968 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
1969
1970 if (!new_settings_ptr)
1971 return;
1972
Greg Claytonff44ab42011-04-23 02:04:55 +00001973 m_expr_prefix_file = new_settings_ptr->m_expr_prefix_file;
1974 m_expr_prefix_contents_sp = new_settings_ptr->m_expr_prefix_contents_sp;
1975 m_prefer_dynamic_value = new_settings_ptr->m_prefer_dynamic_value;
1976 m_skip_prologue = new_settings_ptr->m_skip_prologue;
Enrico Granata018921d2011-08-12 02:00:06 +00001977 m_max_children_display = new_settings_ptr->m_max_children_display;
Enrico Granata91544802011-09-06 19:20:51 +00001978 m_max_strlen_length = new_settings_ptr->m_max_strlen_length;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001979}
1980
Caroline Ticebcb5b452010-09-20 21:37:42 +00001981bool
Caroline Tice5bc8c972010-09-20 20:44:43 +00001982TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1983 const ConstString &var_name,
1984 StringList &value,
Caroline Ticebcb5b452010-09-20 21:37:42 +00001985 Error *err)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001986{
Greg Claytond284b662011-02-18 01:44:25 +00001987 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00001988 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001989 char path[PATH_MAX];
1990 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
1991 if (path_len > 0)
1992 value.AppendString (path, path_len);
Sean Callanan77e93942010-10-29 00:29:03 +00001993 }
Jim Inghame41494a2011-04-16 00:01:13 +00001994 else if (var_name == GetSettingNameForPreferDynamicValue())
1995 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001996 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Inghame41494a2011-04-16 00:01:13 +00001997 }
Greg Clayton17cd9952011-04-22 03:55:06 +00001998 else if (var_name == GetSettingNameForSkipPrologue())
1999 {
2000 if (m_skip_prologue)
2001 value.AppendString ("true");
2002 else
2003 value.AppendString ("false");
2004 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002005 else if (var_name == GetSettingNameForSourcePathMap ())
2006 {
2007 }
Enrico Granata018921d2011-08-12 02:00:06 +00002008 else if (var_name == GetSettingNameForMaxChildren())
2009 {
2010 StreamString count_str;
2011 count_str.Printf ("%d", m_max_children_display);
2012 value.AppendString (count_str.GetData());
2013 }
Enrico Granata91544802011-09-06 19:20:51 +00002014 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2015 {
2016 StreamString count_str;
2017 count_str.Printf ("%d", m_max_strlen_length);
2018 value.AppendString (count_str.GetData());
2019 }
Sean Callanan77e93942010-10-29 00:29:03 +00002020 else
2021 {
2022 if (err)
2023 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2024 return false;
2025 }
2026
2027 return true;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002028}
2029
2030const ConstString
2031TargetInstanceSettings::CreateInstanceName ()
2032{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002033 StreamString sstr;
Caroline Tice1ebef442010-09-27 00:30:10 +00002034 static int instance_count = 1;
2035
Caroline Tice5bc8c972010-09-20 20:44:43 +00002036 sstr.Printf ("target_%d", instance_count);
2037 ++instance_count;
2038
2039 const ConstString ret_val (sstr.GetData());
2040 return ret_val;
2041}
2042
2043//--------------------------------------------------
2044// Target::SettingsController Variable Tables
2045//--------------------------------------------------
Jim Ingham10de7d12011-05-04 03:43:18 +00002046OptionEnumValueElement
2047TargetInstanceSettings::g_dynamic_value_types[] =
2048{
Greg Clayton577fbc32011-05-30 00:39:48 +00002049{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2050{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2051{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham10de7d12011-05-04 03:43:18 +00002052{ 0, NULL, NULL }
2053};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002054
2055SettingEntry
2056Target::SettingsController::global_settings_table[] =
2057{
Greg Claytond284b662011-02-18 01:44:25 +00002058 // var-name var-type default enum init'd hidden help-text
2059 // ================= ================== =========== ==== ====== ====== =========================================================================
2060 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
2061 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
2062};
2063
Caroline Tice5bc8c972010-09-20 20:44:43 +00002064SettingEntry
2065Target::SettingsController::instance_settings_table[] =
2066{
Enrico Granata91544802011-09-06 19:20:51 +00002067 // var-name var-type default enum init'd hidden help-text
2068 // ================= ================== =============== ======================= ====== ====== =========================================================================
2069 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
2070 { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
2071 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
2072 { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
2073 { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
2074 { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." },
2075 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002076};