blob: 5fdc2333eb8f4a2e0a8dd61f7c8fc708a7634060 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:241//===-- 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"
Jim Ingham969795f2011-09-21 01:17:1319#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner30fdc8d2010-06-08 16:52:2420#include "lldb/Breakpoint/BreakpointResolverName.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5921#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:2422#include "lldb/Core/Event.h"
23#include "lldb/Core/Log.h"
Caroline Tice969ed3d12011-05-02 20:41:4624#include "lldb/Core/StreamAsynchronousIO.h"
Chris Lattner30fdc8d2010-06-08 16:52:2425#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5926#include "lldb/Core/Timer.h"
27#include "lldb/Core/ValueObject.h"
Greg Claytoneb0103f2011-04-07 22:46:3528#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:2429#include "lldb/Host/Host.h"
Jim Ingham9575d842011-03-11 03:53:5930#include "lldb/Interpreter/CommandInterpreter.h"
31#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner30fdc8d2010-06-08 16:52:2432#include "lldb/lldb-private-log.h"
33#include "lldb/Symbol/ObjectFile.h"
34#include "lldb/Target/Process.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5935#include "lldb/Target/StackFrame.h"
Jim Ingham9575d842011-03-11 03:53:5936#include "lldb/Target/Thread.h"
37#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:2438
39using namespace lldb;
40using namespace lldb_private;
41
42//----------------------------------------------------------------------
43// Target constructor
44//----------------------------------------------------------------------
Greg Clayton32e0a752011-03-30 18:16:5145Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
46 Broadcaster ("lldb.target"),
47 ExecutionContextScope (),
Greg Claytondbe54502010-11-19 03:46:0148 TargetInstanceSettings (*GetSettingsController()),
Greg Clayton66111032010-06-23 01:19:2949 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:5150 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:2351 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:5152 m_arch (target_arch),
53 m_images (),
Greg Claytonf5e56de2010-09-14 23:36:4054 m_section_load_list (),
Chris Lattner30fdc8d2010-06-08 16:52:2455 m_breakpoint_list (false),
56 m_internal_breakpoint_list (true),
Johnny Chen1d6bad02011-09-06 20:05:2557 m_watchpoint_location_list (),
Greg Clayton32e0a752011-03-30 18:16:5158 m_process_sp (),
59 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:2460 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton8b2fe6d2010-12-14 02:59:5961 m_scratch_ast_context_ap (NULL),
Jim Ingham9575d842011-03-11 03:53:5962 m_persistent_variables (),
Jim Inghame37d6052011-09-13 00:29:5663 m_source_manager(*this),
Greg Clayton32e0a752011-03-30 18:16:5164 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:1465 m_stop_hook_next_id (0),
66 m_suppress_stop_hooks (false)
Chris Lattner30fdc8d2010-06-08 16:52:2467{
Greg Claytoncfd1ace2010-10-31 03:01:0668 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
69 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
70 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
71
Greg Clayton2d4edfb2010-11-06 01:53:3072 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2473 if (log)
74 log->Printf ("%p Target::Target()", this);
75}
76
77//----------------------------------------------------------------------
78// Destructor
79//----------------------------------------------------------------------
80Target::~Target()
81{
Greg Clayton2d4edfb2010-11-06 01:53:3082 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2483 if (log)
84 log->Printf ("%p Target::~Target()", this);
85 DeleteCurrentProcess ();
86}
87
88void
Caroline Ticeceb6b132010-10-26 03:11:1389Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:2490{
Greg Clayton89411422010-10-08 00:21:0591// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:1392 if (description_level != lldb::eDescriptionLevelBrief)
93 {
94 s->Indent();
95 s->PutCString("Target\n");
96 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:3597 m_images.Dump(s);
98 m_breakpoint_list.Dump(s);
99 m_internal_breakpoint_list.Dump(s);
100 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:13101 }
102 else
103 {
Greg Claytonaa149cb2011-08-11 02:48:45104 Module *exe_module = GetExecutableModulePointer();
105 if (exe_module)
106 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham48028b62011-05-12 01:12:28107 else
108 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13109 }
Chris Lattner30fdc8d2010-06-08 16:52:24110}
111
112void
113Target::DeleteCurrentProcess ()
114{
115 if (m_process_sp.get())
116 {
Greg Clayton17f69202010-09-14 23:52:43117 m_section_load_list.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24118 if (m_process_sp->IsAlive())
119 m_process_sp->Destroy();
Jim Inghamd0a3e12b2011-02-16 17:54:55120
121 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24122
123 // Do any cleanup of the target we need to do between process instances.
124 // NB It is better to do this before destroying the process in case the
125 // clean up needs some help from the process.
126 m_breakpoint_list.ClearAllBreakpointSites();
127 m_internal_breakpoint_list.ClearAllBreakpointSites();
Johnny Chen86364b42011-09-20 23:28:55128 m_watchpoint_location_list.RemoveAll();
Chris Lattner30fdc8d2010-06-08 16:52:24129 m_process_sp.reset();
130 }
131}
132
133const lldb::ProcessSP &
134Target::CreateProcess (Listener &listener, const char *plugin_name)
135{
136 DeleteCurrentProcess ();
137 m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
138 return m_process_sp;
139}
140
141const lldb::ProcessSP &
142Target::GetProcessSP () const
143{
144 return m_process_sp;
145}
146
147lldb::TargetSP
148Target::GetSP()
149{
Greg Clayton4d122c42011-09-17 08:33:22150 // This object contains an instrusive ref count base class so we can
151 // easily make a shared pointer to this object
152 return TargetSP(this);
Chris Lattner30fdc8d2010-06-08 16:52:24153}
154
Greg Clayton3418c852011-08-10 02:10:13155void
156Target::Destroy()
157{
158 Mutex::Locker locker (m_mutex);
159 DeleteCurrentProcess ();
160 m_platform_sp.reset();
161 m_arch.Clear();
162 m_images.Clear();
163 m_section_load_list.Clear();
164 const bool notify = false;
165 m_breakpoint_list.RemoveAll(notify);
166 m_internal_breakpoint_list.RemoveAll(notify);
167 m_last_created_breakpoint.reset();
168 m_search_filter_sp.reset();
169 m_image_search_paths.Clear(notify);
170 m_scratch_ast_context_ap.reset();
171 m_persistent_variables.Clear();
172 m_stop_hooks.clear();
173 m_stop_hook_next_id = 0;
174 m_suppress_stop_hooks = false;
175}
176
177
Chris Lattner30fdc8d2010-06-08 16:52:24178BreakpointList &
179Target::GetBreakpointList(bool internal)
180{
181 if (internal)
182 return m_internal_breakpoint_list;
183 else
184 return m_breakpoint_list;
185}
186
187const BreakpointList &
188Target::GetBreakpointList(bool internal) const
189{
190 if (internal)
191 return m_internal_breakpoint_list;
192 else
193 return m_breakpoint_list;
194}
195
196BreakpointSP
197Target::GetBreakpointByID (break_id_t break_id)
198{
199 BreakpointSP bp_sp;
200
201 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
202 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
203 else
204 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
205
206 return bp_sp;
207}
208
209BreakpointSP
Jim Ingham969795f2011-09-21 01:17:13210Target::CreateBreakpoint (const FileSpecList *containingModules,
211 const FileSpec &file,
212 RegularExpression &source_regex,
213 bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24214{
Jim Ingham969795f2011-09-21 01:17:13215 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
216 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, file, source_regex));
217 return CreateBreakpoint (filter_sp, resolver_sp, internal);
218}
219
220
221BreakpointSP
222Target::CreateBreakpoint (const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
223{
224 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Chris Lattner30fdc8d2010-06-08 16:52:24225 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
226 return CreateBreakpoint (filter_sp, resolver_sp, internal);
227}
228
229
230BreakpointSP
Greg Clayton1b72fcb2010-08-24 00:45:41231Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24232{
Chris Lattner30fdc8d2010-06-08 16:52:24233 Address so_addr;
234 // Attempt to resolve our load address if possible, though it is ok if
235 // it doesn't resolve to section/offset.
236
Greg Clayton1b72fcb2010-08-24 00:45:41237 // Try and resolve as a load address if possible
Greg Claytonf5e56de2010-09-14 23:36:40238 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41239 if (!so_addr.IsValid())
240 {
241 // The address didn't resolve, so just set this as an absolute address
242 so_addr.SetOffset (addr);
243 }
244 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner30fdc8d2010-06-08 16:52:24245 return bp_sp;
246}
247
248BreakpointSP
249Target::CreateBreakpoint (Address &addr, bool internal)
250{
251 TargetSP target_sp = this->GetSP();
252 SearchFilterSP filter_sp(new SearchFilter (target_sp));
253 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
254 return CreateBreakpoint (filter_sp, resolver_sp, internal);
255}
256
257BreakpointSP
Jim Ingham969795f2011-09-21 01:17:13258Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Claytond16e1e52011-07-12 17:06:17259 const char *func_name,
260 uint32_t func_name_type_mask,
261 bool internal,
262 LazyBool skip_prologue)
Chris Lattner30fdc8d2010-06-08 16:52:24263{
Greg Clayton0c5cd902010-06-28 21:30:43264 BreakpointSP bp_sp;
265 if (func_name)
266 {
Jim Ingham969795f2011-09-21 01:17:13267 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Greg Claytond16e1e52011-07-12 17:06:17268
269 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
270 func_name,
271 func_name_type_mask,
272 Breakpoint::Exact,
273 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Greg Clayton0c5cd902010-06-28 21:30:43274 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
275 }
276 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24277}
278
279
280SearchFilterSP
281Target::GetSearchFilterForModule (const FileSpec *containingModule)
282{
283 SearchFilterSP filter_sp;
284 lldb::TargetSP target_sp = this->GetSP();
285 if (containingModule != NULL)
286 {
287 // TODO: We should look into sharing module based search filters
288 // across many breakpoints like we do for the simple target based one
289 filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
290 }
291 else
292 {
293 if (m_search_filter_sp.get() == NULL)
294 m_search_filter_sp.reset (new SearchFilter (target_sp));
295 filter_sp = m_search_filter_sp;
296 }
297 return filter_sp;
298}
299
Jim Ingham969795f2011-09-21 01:17:13300SearchFilterSP
301Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
302{
303 SearchFilterSP filter_sp;
304 lldb::TargetSP target_sp = this->GetSP();
305 if (containingModules && containingModules->GetSize() != 0)
306 {
307 // TODO: We should look into sharing module based search filters
308 // across many breakpoints like we do for the simple target based one
309 filter_sp.reset (new SearchFilterByModuleList (target_sp, *containingModules));
310 }
311 else
312 {
313 if (m_search_filter_sp.get() == NULL)
314 m_search_filter_sp.reset (new SearchFilter (target_sp));
315 filter_sp = m_search_filter_sp;
316 }
317 return filter_sp;
318}
319
Chris Lattner30fdc8d2010-06-08 16:52:24320BreakpointSP
Jim Ingham969795f2011-09-21 01:17:13321Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Claytond16e1e52011-07-12 17:06:17322 RegularExpression &func_regex,
323 bool internal,
324 LazyBool skip_prologue)
Chris Lattner30fdc8d2010-06-08 16:52:24325{
Jim Ingham969795f2011-09-21 01:17:13326 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Greg Claytond16e1e52011-07-12 17:06:17327 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
328 func_regex,
329 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner30fdc8d2010-06-08 16:52:24330
331 return CreateBreakpoint (filter_sp, resolver_sp, internal);
332}
333
334BreakpointSP
335Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
336{
337 BreakpointSP bp_sp;
338 if (filter_sp && resolver_sp)
339 {
340 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
341 resolver_sp->SetBreakpoint (bp_sp.get());
342
343 if (internal)
Greg Clayton9fed0d82010-07-23 23:33:17344 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24345 else
Greg Clayton9fed0d82010-07-23 23:33:17346 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24347
Greg Clayton2d4edfb2010-11-06 01:53:30348 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24349 if (log)
350 {
351 StreamString s;
352 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
353 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
354 }
355
Chris Lattner30fdc8d2010-06-08 16:52:24356 bp_sp->ResolveBreakpoint();
357 }
Jim Ingham36f3b362010-10-14 23:45:03358
359 if (!internal && bp_sp)
360 {
361 m_last_created_breakpoint = bp_sp;
362 }
363
Chris Lattner30fdc8d2010-06-08 16:52:24364 return bp_sp;
365}
366
Johnny Chen86364b42011-09-20 23:28:55367bool
368Target::ProcessIsValid()
369{
370 return (m_process_sp && m_process_sp->IsAlive());
371}
372
Johnny Chenab9ee762011-09-14 00:26:03373// See also WatchpointLocation::SetWatchpointType(uint32_t type) and
374// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen887062a2011-09-12 23:38:44375WatchpointLocationSP
376Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type)
377{
Johnny Chen0c406372011-09-14 20:23:45378 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
379 if (log)
380 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
381 __FUNCTION__, addr, size, type);
382
Johnny Chen887062a2011-09-12 23:38:44383 WatchpointLocationSP wp_loc_sp;
Johnny Chen86364b42011-09-20 23:28:55384 if (!ProcessIsValid())
Johnny Chen2fd89a02011-09-13 18:30:59385 return wp_loc_sp;
Johnny Chen45e541f2011-09-14 22:20:15386 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chen887062a2011-09-12 23:38:44387 return wp_loc_sp;
Johnny Chen7313a642011-09-13 01:15:36388
Johnny Chenab9ee762011-09-14 00:26:03389 // Currently we only support one watchpoint location per address, with total
390 // number of watchpoint locations limited by the hardware which the inferior
391 // is running on.
Johnny Chen3c532582011-09-13 23:29:31392 WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr);
393 if (matched_sp)
394 {
Johnny Chen0c406372011-09-14 20:23:45395 size_t old_size = matched_sp->GetByteSize();
Johnny Chen3c532582011-09-13 23:29:31396 uint32_t old_type =
Johnny Chen0c406372011-09-14 20:23:45397 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
398 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen45e541f2011-09-14 22:20:15399 // Return the existing watchpoint location if both size and type match.
400 if (size == old_size && type == old_type) {
401 wp_loc_sp = matched_sp;
402 wp_loc_sp->SetEnabled(false);
403 } else {
404 // Nil the matched watchpoint location; we will be creating a new one.
405 m_process_sp->DisableWatchpoint(matched_sp.get());
406 m_watchpoint_location_list.Remove(matched_sp->GetID());
407 }
Johnny Chen3c532582011-09-13 23:29:31408 }
409
Johnny Chen45e541f2011-09-14 22:20:15410 if (!wp_loc_sp) {
411 WatchpointLocation *new_loc = new WatchpointLocation(addr, size);
412 if (!new_loc) {
413 printf("WatchpointLocation ctor failed, out of memory?\n");
414 return wp_loc_sp;
415 }
416 new_loc->SetWatchpointType(type);
417 wp_loc_sp.reset(new_loc);
418 m_watchpoint_location_list.Add(wp_loc_sp);
419 }
Johnny Chen0c406372011-09-14 20:23:45420
Johnny Chen0c406372011-09-14 20:23:45421 Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
Johnny Chen0c406372011-09-14 20:23:45422 if (log)
423 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
424 __FUNCTION__,
425 rc.Success() ? "succeeded" : "failed",
426 wp_loc_sp->GetID());
427
Johnny Chen45e541f2011-09-14 22:20:15428 if (rc.Fail()) wp_loc_sp.reset();
Johnny Chen7313a642011-09-13 01:15:36429 return wp_loc_sp;
Johnny Chen887062a2011-09-12 23:38:44430}
431
Chris Lattner30fdc8d2010-06-08 16:52:24432void
433Target::RemoveAllBreakpoints (bool internal_also)
434{
Greg Clayton2d4edfb2010-11-06 01:53:30435 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24436 if (log)
437 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
438
Greg Clayton9fed0d82010-07-23 23:33:17439 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24440 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17441 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03442
443 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24444}
445
446void
447Target::DisableAllBreakpoints (bool internal_also)
448{
Greg Clayton2d4edfb2010-11-06 01:53:30449 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24450 if (log)
451 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
452
453 m_breakpoint_list.SetEnabledAll (false);
454 if (internal_also)
455 m_internal_breakpoint_list.SetEnabledAll (false);
456}
457
458void
459Target::EnableAllBreakpoints (bool internal_also)
460{
Greg Clayton2d4edfb2010-11-06 01:53:30461 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24462 if (log)
463 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
464
465 m_breakpoint_list.SetEnabledAll (true);
466 if (internal_also)
467 m_internal_breakpoint_list.SetEnabledAll (true);
468}
469
470bool
471Target::RemoveBreakpointByID (break_id_t break_id)
472{
Greg Clayton2d4edfb2010-11-06 01:53:30473 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24474 if (log)
475 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
476
477 if (DisableBreakpointByID (break_id))
478 {
479 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17480 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24481 else
Jim Ingham36f3b362010-10-14 23:45:03482 {
Greg Claytonaa1c5872011-01-24 23:35:47483 if (m_last_created_breakpoint)
484 {
485 if (m_last_created_breakpoint->GetID() == break_id)
486 m_last_created_breakpoint.reset();
487 }
Greg Clayton9fed0d82010-07-23 23:33:17488 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03489 }
Chris Lattner30fdc8d2010-06-08 16:52:24490 return true;
491 }
492 return false;
493}
494
495bool
496Target::DisableBreakpointByID (break_id_t break_id)
497{
Greg Clayton2d4edfb2010-11-06 01:53:30498 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24499 if (log)
500 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
501
502 BreakpointSP bp_sp;
503
504 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
505 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
506 else
507 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
508 if (bp_sp)
509 {
510 bp_sp->SetEnabled (false);
511 return true;
512 }
513 return false;
514}
515
516bool
517Target::EnableBreakpointByID (break_id_t break_id)
518{
Greg Clayton2d4edfb2010-11-06 01:53:30519 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24520 if (log)
521 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
522 __FUNCTION__,
523 break_id,
524 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
525
526 BreakpointSP bp_sp;
527
528 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
529 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
530 else
531 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
532
533 if (bp_sp)
534 {
535 bp_sp->SetEnabled (true);
536 return true;
537 }
538 return false;
539}
540
Johnny Chen86364b42011-09-20 23:28:55541// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
542bool
543Target::RemoveAllWatchpointLocations ()
544{
545 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
546 if (log)
547 log->Printf ("Target::%s\n", __FUNCTION__);
548
549 if (!ProcessIsValid())
550 return false;
551
552 size_t num_watchpoints = m_watchpoint_location_list.GetSize();
553 for (size_t i = 0; i < num_watchpoints; ++i)
554 {
555 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
556 if (!wp_loc_sp)
557 return false;
558
559 Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get());
560 if (rc.Fail())
561 return false;
562 }
563 m_watchpoint_location_list.RemoveAll ();
564 return true; // Success!
565}
566
567// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
568bool
569Target::DisableAllWatchpointLocations ()
570{
571 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
572 if (log)
573 log->Printf ("Target::%s\n", __FUNCTION__);
574
575 if (!ProcessIsValid())
576 return false;
577
578 size_t num_watchpoints = m_watchpoint_location_list.GetSize();
579 for (size_t i = 0; i < num_watchpoints; ++i)
580 {
581 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
582 if (!wp_loc_sp)
583 return false;
584
585 Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get());
586 if (rc.Fail())
587 return false;
588 }
589 m_watchpoint_location_list.SetEnabledAll (false);
590 return true; // Success!
591}
592
593// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
594bool
595Target::EnableAllWatchpointLocations ()
596{
597 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
598 if (log)
599 log->Printf ("Target::%s\n", __FUNCTION__);
600
601 if (!ProcessIsValid())
602 return false;
603
604 size_t num_watchpoints = m_watchpoint_location_list.GetSize();
605 for (size_t i = 0; i < num_watchpoints; ++i)
606 {
607 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
608 if (!wp_loc_sp)
609 return false;
610
611 Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
612 if (rc.Fail())
613 return false;
614 }
615 m_watchpoint_location_list.SetEnabledAll (true);
616 return true; // Success!
617}
618
619// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
620bool
621Target::DisableWatchpointLocationByID (lldb::watch_id_t watch_id)
622{
623 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
624 if (log)
625 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
626
627 if (!ProcessIsValid())
628 return false;
629
630 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id);
631 if (wp_loc_sp)
632 {
633 Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get());
634 if (rc.Fail())
635 return false;
636
637 wp_loc_sp->SetEnabled (false);
638 return true;
639 }
640 return false;
641}
642
643// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
644bool
645Target::EnableWatchpointLocationByID (lldb::watch_id_t watch_id)
646{
647 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
648 if (log)
649 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
650
651 if (!ProcessIsValid())
652 return false;
653
654 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id);
655 if (wp_loc_sp)
656 {
657 Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
658 if (rc.Fail())
659 return false;
660
661 wp_loc_sp->SetEnabled (true);
662 return true;
663 }
664 return false;
665}
666
667// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
668bool
669Target::RemoveWatchpointLocationByID (lldb::watch_id_t watch_id)
670{
671 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
672 if (log)
673 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
674
675 if (DisableWatchpointLocationByID (watch_id))
676 {
677 m_watchpoint_location_list.Remove(watch_id);
678 return true;
679 }
680 return false;
681}
682
Chris Lattner30fdc8d2010-06-08 16:52:24683ModuleSP
684Target::GetExecutableModule ()
685{
Greg Claytonaa149cb2011-08-11 02:48:45686 return m_images.GetModuleAtIndex(0);
687}
688
689Module*
690Target::GetExecutableModulePointer ()
691{
692 return m_images.GetModulePointerAtIndex(0);
Chris Lattner30fdc8d2010-06-08 16:52:24693}
694
695void
696Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
697{
698 m_images.Clear();
699 m_scratch_ast_context_ap.reset();
700
701 if (executable_sp.get())
702 {
703 Timer scoped_timer (__PRETTY_FUNCTION__,
704 "Target::SetExecutableModule (executable = '%s/%s')",
705 executable_sp->GetFileSpec().GetDirectory().AsCString(),
706 executable_sp->GetFileSpec().GetFilename().AsCString());
707
708 m_images.Append(executable_sp); // The first image is our exectuable file
709
Jim Ingham5aee1622010-08-09 23:31:02710 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
Greg Clayton32e0a752011-03-30 18:16:51711 if (!m_arch.IsValid())
712 m_arch = executable_sp->GetArchitecture();
Jim Ingham5aee1622010-08-09 23:31:02713
Chris Lattner30fdc8d2010-06-08 16:52:24714 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15715 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Jim Inghamb7f6b2f2011-09-08 22:13:49716 // Let's find the file & line for main and set the default source file from there.
717 if (!m_source_manager.DefaultFileAndLineSet())
718 {
719 SymbolContextList sc_list;
720 uint32_t num_matches;
721 ConstString main_name("main");
722 bool symbols_okay = false; // Force it to be a debug symbol.
723 bool append = false;
724 num_matches = executable_sp->FindFunctions (main_name, eFunctionNameTypeBase, symbols_okay, append, sc_list);
725 for (uint32_t idx = 0; idx < num_matches; idx++)
726 {
727 SymbolContext sc;
728 sc_list.GetContextAtIndex(idx, sc);
729 if (sc.line_entry.file)
730 {
731 m_source_manager.SetDefaultFileAndLine(sc.line_entry.file, sc.line_entry.line);
732 break;
733 }
734 }
735 }
Chris Lattner30fdc8d2010-06-08 16:52:24736
737 if (executable_objfile)
738 {
739 executable_objfile->GetDependentModules(dependent_files);
740 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
741 {
Greg Claytonded470d2011-03-19 01:12:21742 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
743 FileSpec platform_dependent_file_spec;
744 if (m_platform_sp)
Greg Claytond314e812011-03-23 00:09:55745 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21746 else
747 platform_dependent_file_spec = dependent_file_spec;
748
749 ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec,
Greg Clayton32e0a752011-03-30 18:16:51750 m_arch));
Chris Lattner30fdc8d2010-06-08 16:52:24751 if (image_module_sp.get())
752 {
Chris Lattner30fdc8d2010-06-08 16:52:24753 ObjectFile *objfile = image_module_sp->GetObjectFile();
754 if (objfile)
755 objfile->GetDependentModules(dependent_files);
756 }
757 }
758 }
759
Chris Lattner30fdc8d2010-06-08 16:52:24760 }
Caroline Tice1559a462010-09-27 00:30:10761
762 UpdateInstanceName();
Chris Lattner30fdc8d2010-06-08 16:52:24763}
764
765
Jim Ingham5aee1622010-08-09 23:31:02766bool
767Target::SetArchitecture (const ArchSpec &arch_spec)
768{
Greg Clayton32e0a752011-03-30 18:16:51769 if (m_arch == arch_spec)
Jim Ingham5aee1622010-08-09 23:31:02770 {
771 // If we're setting the architecture to our current architecture, we
772 // don't need to do anything.
773 return true;
774 }
Greg Clayton32e0a752011-03-30 18:16:51775 else if (!m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02776 {
777 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton32e0a752011-03-30 18:16:51778 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02779 return true;
780 }
781 else
782 {
783 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton32e0a752011-03-30 18:16:51784 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02785 ModuleSP executable_sp = GetExecutableModule ();
786 m_images.Clear();
787 m_scratch_ast_context_ap.reset();
Jim Ingham5aee1622010-08-09 23:31:02788 // Need to do something about unsetting breakpoints.
789
790 if (executable_sp)
791 {
792 FileSpec exec_file_spec = executable_sp->GetFileSpec();
793 Error error = ModuleList::GetSharedModule(exec_file_spec,
794 arch_spec,
795 NULL,
796 NULL,
797 0,
798 executable_sp,
799 NULL,
800 NULL);
801
802 if (!error.Fail() && executable_sp)
803 {
804 SetExecutableModule (executable_sp, true);
805 return true;
806 }
807 else
808 {
809 return false;
810 }
811 }
812 else
813 {
814 return false;
815 }
816 }
817}
Chris Lattner30fdc8d2010-06-08 16:52:24818
Chris Lattner30fdc8d2010-06-08 16:52:24819void
820Target::ModuleAdded (ModuleSP &module_sp)
821{
822 // A module is being added to this target for the first time
823 ModuleList module_list;
824 module_list.Append(module_sp);
825 ModulesDidLoad (module_list);
826}
827
828void
829Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
830{
Jim Inghame716ae02011-08-03 01:00:06831 // A module is replacing an already added module
Chris Lattner30fdc8d2010-06-08 16:52:24832 ModuleList module_list;
833 module_list.Append (old_module_sp);
834 ModulesDidUnload (module_list);
835 module_list.Clear ();
836 module_list.Append (new_module_sp);
837 ModulesDidLoad (module_list);
838}
839
840void
841Target::ModulesDidLoad (ModuleList &module_list)
842{
843 m_breakpoint_list.UpdateBreakpoints (module_list, true);
844 // TODO: make event data that packages up the module_list
845 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
846}
847
848void
849Target::ModulesDidUnload (ModuleList &module_list)
850{
851 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Claytona4d78302010-12-06 23:51:26852
853 // Remove the images from the target image list
854 m_images.Remove(module_list);
855
Chris Lattner30fdc8d2010-06-08 16:52:24856 // TODO: make event data that packages up the module_list
857 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
858}
859
860size_t
Greg Claytondb598232011-01-07 01:57:07861Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
862{
863 const Section *section = addr.GetSection();
864 if (section && section->GetModule())
865 {
866 ObjectFile *objfile = section->GetModule()->GetObjectFile();
867 if (objfile)
868 {
869 size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
870 addr.GetOffset(),
871 dst,
872 dst_len);
873 if (bytes_read > 0)
874 return bytes_read;
875 else
876 error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
877 }
878 else
879 {
880 error.SetErrorString("address isn't from a object file");
881 }
882 }
883 else
884 {
885 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
886 }
887 return 0;
888}
889
890size_t
Enrico Granata9128ee2f2011-09-06 19:20:51891Target::ReadMemory (const Address& addr,
892 bool prefer_file_cache,
893 void *dst,
894 size_t dst_len,
895 Error &error,
896 lldb::addr_t *load_addr_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24897{
Chris Lattner30fdc8d2010-06-08 16:52:24898 error.Clear();
Greg Claytondb598232011-01-07 01:57:07899
Enrico Granata9128ee2f2011-09-06 19:20:51900 // if we end up reading this from process memory, we will fill this
901 // with the actual load address
902 if (load_addr_ptr)
903 *load_addr_ptr = LLDB_INVALID_ADDRESS;
904
Greg Claytondb598232011-01-07 01:57:07905 size_t bytes_read = 0;
Greg Claytonc749eb82011-07-11 05:12:02906
907 addr_t load_addr = LLDB_INVALID_ADDRESS;
908 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton357132e2011-03-26 19:14:58909 Address resolved_addr;
910 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03911 {
Greg Claytond16e1e52011-07-12 17:06:17912 if (m_section_load_list.IsEmpty())
Greg Claytonc749eb82011-07-11 05:12:02913 {
Greg Claytond16e1e52011-07-12 17:06:17914 // No sections are loaded, so we must assume we are not running
915 // yet and anything we are given is a file address.
916 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
917 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02918 }
Greg Claytondda4f7b2010-06-30 23:03:03919 else
Greg Claytonc749eb82011-07-11 05:12:02920 {
Greg Claytond16e1e52011-07-12 17:06:17921 // We have at least one section loaded. This can be becuase
922 // we have manually loaded some sections with "target modules load ..."
923 // or because we have have a live process that has sections loaded
924 // through the dynamic loader
925 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
926 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02927 }
Greg Claytondda4f7b2010-06-30 23:03:03928 }
Greg Clayton357132e2011-03-26 19:14:58929 if (!resolved_addr.IsValid())
930 resolved_addr = addr;
Greg Claytondda4f7b2010-06-30 23:03:03931
Greg Claytonc749eb82011-07-11 05:12:02932
Greg Claytondb598232011-01-07 01:57:07933 if (prefer_file_cache)
934 {
935 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
936 if (bytes_read > 0)
937 return bytes_read;
938 }
Greg Claytondda4f7b2010-06-30 23:03:03939
Johnny Chen86364b42011-09-20 23:28:55940 if (ProcessIsValid())
Greg Claytondda4f7b2010-06-30 23:03:03941 {
Greg Claytonc749eb82011-07-11 05:12:02942 if (load_addr == LLDB_INVALID_ADDRESS)
943 load_addr = resolved_addr.GetLoadAddress (this);
944
Greg Claytondda4f7b2010-06-30 23:03:03945 if (load_addr == LLDB_INVALID_ADDRESS)
946 {
947 if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
948 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
949 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
Jason Molenda7e589a62011-09-20 00:26:08950 resolved_addr.GetFileAddress(),
951 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString());
Greg Claytondda4f7b2010-06-30 23:03:03952 else
953 error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
954 }
955 else
956 {
Greg Claytondb598232011-01-07 01:57:07957 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24958 if (bytes_read != dst_len)
959 {
960 if (error.Success())
961 {
962 if (bytes_read == 0)
Greg Claytondda4f7b2010-06-30 23:03:03963 error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24964 else
Greg Claytondda4f7b2010-06-30 23:03:03965 error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24966 }
967 }
Greg Claytondda4f7b2010-06-30 23:03:03968 if (bytes_read)
Enrico Granata9128ee2f2011-09-06 19:20:51969 {
970 if (load_addr_ptr)
971 *load_addr_ptr = load_addr;
Greg Claytondda4f7b2010-06-30 23:03:03972 return bytes_read;
Enrico Granata9128ee2f2011-09-06 19:20:51973 }
Greg Claytondda4f7b2010-06-30 23:03:03974 // If the address is not section offset we have an address that
975 // doesn't resolve to any address in any currently loaded shared
976 // libaries and we failed to read memory so there isn't anything
977 // more we can do. If it is section offset, we might be able to
978 // read cached memory from the object file.
979 if (!resolved_addr.IsSectionOffset())
980 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24981 }
Chris Lattner30fdc8d2010-06-08 16:52:24982 }
Greg Claytondda4f7b2010-06-30 23:03:03983
Greg Claytonc749eb82011-07-11 05:12:02984 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03985 {
Greg Claytondb598232011-01-07 01:57:07986 // If we didn't already try and read from the object file cache, then
987 // try it after failing to read from the process.
988 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03989 }
990 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24991}
992
Greg Claytond16e1e52011-07-12 17:06:17993size_t
994Target::ReadScalarIntegerFromMemory (const Address& addr,
995 bool prefer_file_cache,
996 uint32_t byte_size,
997 bool is_signed,
998 Scalar &scalar,
999 Error &error)
1000{
1001 uint64_t uval;
1002
1003 if (byte_size <= sizeof(uval))
1004 {
1005 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1006 if (bytes_read == byte_size)
1007 {
1008 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1009 uint32_t offset = 0;
1010 if (byte_size <= 4)
1011 scalar = data.GetMaxU32 (&offset, byte_size);
1012 else
1013 scalar = data.GetMaxU64 (&offset, byte_size);
1014
1015 if (is_signed)
1016 scalar.SignExtend(byte_size * 8);
1017 return bytes_read;
1018 }
1019 }
1020 else
1021 {
1022 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1023 }
1024 return 0;
1025}
1026
1027uint64_t
1028Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1029 bool prefer_file_cache,
1030 size_t integer_byte_size,
1031 uint64_t fail_value,
1032 Error &error)
1033{
1034 Scalar scalar;
1035 if (ReadScalarIntegerFromMemory (addr,
1036 prefer_file_cache,
1037 integer_byte_size,
1038 false,
1039 scalar,
1040 error))
1041 return scalar.ULongLong(fail_value);
1042 return fail_value;
1043}
1044
1045bool
1046Target::ReadPointerFromMemory (const Address& addr,
1047 bool prefer_file_cache,
1048 Error &error,
1049 Address &pointer_addr)
1050{
1051 Scalar scalar;
1052 if (ReadScalarIntegerFromMemory (addr,
1053 prefer_file_cache,
1054 m_arch.GetAddressByteSize(),
1055 false,
1056 scalar,
1057 error))
1058 {
1059 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1060 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1061 {
1062 if (m_section_load_list.IsEmpty())
1063 {
1064 // No sections are loaded, so we must assume we are not running
1065 // yet and anything we are given is a file address.
1066 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1067 }
1068 else
1069 {
1070 // We have at least one section loaded. This can be becuase
1071 // we have manually loaded some sections with "target modules load ..."
1072 // or because we have have a live process that has sections loaded
1073 // through the dynamic loader
1074 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1075 }
1076 // We weren't able to resolve the pointer value, so just return
1077 // an address with no section
1078 if (!pointer_addr.IsValid())
1079 pointer_addr.SetOffset (pointer_vm_addr);
1080 return true;
1081
1082 }
1083 }
1084 return false;
1085}
Chris Lattner30fdc8d2010-06-08 16:52:241086
1087ModuleSP
1088Target::GetSharedModule
1089(
1090 const FileSpec& file_spec,
1091 const ArchSpec& arch,
Greg Clayton60830262011-02-04 18:53:101092 const lldb_private::UUID *uuid_ptr,
Chris Lattner30fdc8d2010-06-08 16:52:241093 const ConstString *object_name,
1094 off_t object_offset,
1095 Error *error_ptr
1096)
1097{
1098 // Don't pass in the UUID so we can tell if we have a stale value in our list
1099 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1100 bool did_create_module = false;
1101 ModuleSP module_sp;
1102
Chris Lattner30fdc8d2010-06-08 16:52:241103 Error error;
1104
Greg Clayton32e0a752011-03-30 18:16:511105 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner30fdc8d2010-06-08 16:52:241106 if (m_image_search_paths.GetSize())
1107 {
1108 FileSpec transformed_spec;
1109 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
1110 {
1111 transformed_spec.GetFilename() = file_spec.GetFilename();
1112 error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
1113 }
1114 }
1115
Greg Clayton32e0a752011-03-30 18:16:511116 // The platform is responsible for finding and caching an appropriate
1117 // module in the shared module cache.
1118 if (m_platform_sp)
Chris Lattner30fdc8d2010-06-08 16:52:241119 {
Greg Clayton32e0a752011-03-30 18:16:511120 FileSpec platform_file_spec;
1121 error = m_platform_sp->GetSharedModule (file_spec,
1122 arch,
1123 uuid_ptr,
1124 object_name,
1125 object_offset,
1126 module_sp,
1127 &old_module_sp,
1128 &did_create_module);
1129 }
1130 else
1131 {
1132 error.SetErrorString("no platform is currently set");
Chris Lattner30fdc8d2010-06-08 16:52:241133 }
1134
Greg Clayton32e0a752011-03-30 18:16:511135 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner30fdc8d2010-06-08 16:52:241136 if (module_sp)
1137 {
1138 m_images.Append (module_sp);
1139 if (did_create_module)
1140 {
1141 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1142 ModuleUpdated(old_module_sp, module_sp);
1143 else
1144 ModuleAdded(module_sp);
1145 }
1146 }
1147 if (error_ptr)
1148 *error_ptr = error;
1149 return module_sp;
1150}
1151
1152
1153Target *
1154Target::CalculateTarget ()
1155{
1156 return this;
1157}
1158
1159Process *
1160Target::CalculateProcess ()
1161{
1162 return NULL;
1163}
1164
1165Thread *
1166Target::CalculateThread ()
1167{
1168 return NULL;
1169}
1170
1171StackFrame *
1172Target::CalculateStackFrame ()
1173{
1174 return NULL;
1175}
1176
1177void
Greg Clayton0603aa92010-10-04 01:05:561178Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:241179{
1180 exe_ctx.target = this;
1181 exe_ctx.process = NULL; // Do NOT fill in process...
1182 exe_ctx.thread = NULL;
1183 exe_ctx.frame = NULL;
1184}
1185
1186PathMappingList &
1187Target::GetImageSearchPathList ()
1188{
1189 return m_image_search_paths;
1190}
1191
1192void
1193Target::ImageSearchPathsChanged
1194(
1195 const PathMappingList &path_list,
1196 void *baton
1197)
1198{
1199 Target *target = (Target *)baton;
Greg Claytonaa149cb2011-08-11 02:48:451200 ModuleSP exe_module_sp (target->GetExecutableModule());
1201 if (exe_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:241202 {
Greg Claytonaa149cb2011-08-11 02:48:451203 target->m_images.Clear();
1204 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:241205 }
1206}
1207
1208ClangASTContext *
1209Target::GetScratchClangASTContext()
1210{
Greg Clayton73da2442011-08-03 01:23:551211 // Now see if we know the target triple, and if so, create our scratch AST context:
1212 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid())
1213 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Chris Lattner30fdc8d2010-06-08 16:52:241214 return m_scratch_ast_context_ap.get();
1215}
Caroline Ticedaccaa92010-09-20 20:44:431216
Greg Clayton99d0faf2010-11-18 23:32:351217void
Caroline Tice20bd37f2011-03-10 22:14:101218Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:431219{
Greg Clayton99d0faf2010-11-18 23:32:351220 UserSettingsControllerSP &usc = GetSettingsController();
1221 usc.reset (new SettingsController);
1222 UserSettingsController::InitializeSettingsController (usc,
1223 SettingsController::global_settings_table,
1224 SettingsController::instance_settings_table);
Caroline Tice20bd37f2011-03-10 22:14:101225
1226 // Now call SettingsInitialize() on each 'child' setting of Target
1227 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:351228}
Caroline Ticedaccaa92010-09-20 20:44:431229
Greg Clayton99d0faf2010-11-18 23:32:351230void
Caroline Tice20bd37f2011-03-10 22:14:101231Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:351232{
Caroline Tice20bd37f2011-03-10 22:14:101233
1234 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1235
1236 Process::SettingsTerminate ();
1237
1238 // Now terminate Target Settings.
1239
Greg Clayton99d0faf2010-11-18 23:32:351240 UserSettingsControllerSP &usc = GetSettingsController();
1241 UserSettingsController::FinalizeSettingsController (usc);
1242 usc.reset();
1243}
Caroline Ticedaccaa92010-09-20 20:44:431244
Greg Clayton99d0faf2010-11-18 23:32:351245UserSettingsControllerSP &
1246Target::GetSettingsController ()
1247{
1248 static UserSettingsControllerSP g_settings_controller;
Caroline Ticedaccaa92010-09-20 20:44:431249 return g_settings_controller;
1250}
1251
1252ArchSpec
1253Target::GetDefaultArchitecture ()
1254{
Greg Clayton64195a22011-02-23 00:35:021255 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1256
1257 if (settings_controller_sp)
1258 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1259 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:431260}
1261
1262void
Greg Clayton64195a22011-02-23 00:35:021263Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Ticedaccaa92010-09-20 20:44:431264{
Greg Clayton64195a22011-02-23 00:35:021265 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1266
1267 if (settings_controller_sp)
1268 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Ticedaccaa92010-09-20 20:44:431269}
1270
Greg Clayton0603aa92010-10-04 01:05:561271Target *
1272Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1273{
1274 // The target can either exist in the "process" of ExecutionContext, or in
1275 // the "target_sp" member of SymbolContext. This accessor helper function
1276 // will get the target from one of these locations.
1277
1278 Target *target = NULL;
1279 if (sc_ptr != NULL)
1280 target = sc_ptr->target_sp.get();
1281 if (target == NULL)
1282 {
1283 if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL)
1284 target = &exe_ctx_ptr->process->GetTarget();
1285 }
1286 return target;
1287}
1288
1289
Caroline Tice1559a462010-09-27 00:30:101290void
1291Target::UpdateInstanceName ()
1292{
1293 StreamString sstr;
1294
Greg Claytonaa149cb2011-08-11 02:48:451295 Module *exe_module = GetExecutableModulePointer();
1296 if (exe_module)
Caroline Tice1559a462010-09-27 00:30:101297 {
Greg Clayton307de252010-10-27 02:06:371298 sstr.Printf ("%s_%s",
Greg Claytonaa149cb2011-08-11 02:48:451299 exe_module->GetFileSpec().GetFilename().AsCString(),
1300 exe_module->GetArchitecture().GetArchitectureName());
1301 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
Caroline Tice1559a462010-09-27 00:30:101302 }
1303}
1304
Sean Callanan322f5292010-10-29 00:29:031305const char *
1306Target::GetExpressionPrefixContentsAsCString ()
1307{
Greg Clayton7e14f912011-04-23 02:04:551308 if (m_expr_prefix_contents_sp)
1309 return (const char *)m_expr_prefix_contents_sp->GetBytes();
1310 return NULL;
Sean Callanan322f5292010-10-29 00:29:031311}
1312
Greg Clayton8b2fe6d2010-12-14 02:59:591313ExecutionResults
1314Target::EvaluateExpression
1315(
1316 const char *expr_cstr,
1317 StackFrame *frame,
Sean Callanan3bfdaa22011-09-15 02:13:071318 lldb_private::ExecutionPolicy execution_policy,
Greg Clayton8b2fe6d2010-12-14 02:59:591319 bool unwind_on_error,
Sean Callanan92adcac2011-01-13 08:53:351320 bool keep_in_memory,
Jim Ingham2837b762011-05-04 03:43:181321 lldb::DynamicValueType use_dynamic,
Greg Clayton8b2fe6d2010-12-14 02:59:591322 lldb::ValueObjectSP &result_valobj_sp
1323)
1324{
1325 ExecutionResults execution_results = eExecutionSetupError;
1326
1327 result_valobj_sp.reset();
Jim Ingham6026ca32011-05-12 02:06:141328
1329 // We shouldn't run stop hooks in expressions.
1330 // Be sure to reset this if you return anywhere within this function.
1331 bool old_suppress_value = m_suppress_stop_hooks;
1332 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:591333
1334 ExecutionContext exe_ctx;
1335 if (frame)
1336 {
1337 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton54979cd2010-12-15 05:08:081338 Error error;
Greg Clayton6d5e68e2011-01-20 19:27:181339 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granata27b625e2011-08-09 01:04:561340 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1341 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham2837b762011-05-04 03:43:181342 lldb::VariableSP var_sp;
1343 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1344 use_dynamic,
1345 expr_path_options,
1346 var_sp,
1347 error);
Greg Clayton8b2fe6d2010-12-14 02:59:591348 }
1349 else if (m_process_sp)
1350 {
1351 m_process_sp->CalculateExecutionContext(exe_ctx);
1352 }
1353 else
1354 {
1355 CalculateExecutionContext(exe_ctx);
1356 }
1357
1358 if (result_valobj_sp)
1359 {
1360 execution_results = eExecutionCompleted;
1361 // We got a result from the frame variable expression path above...
1362 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1363
1364 lldb::ValueObjectSP const_valobj_sp;
1365
1366 // Check in case our value is already a constant value
1367 if (result_valobj_sp->GetIsConstant())
1368 {
1369 const_valobj_sp = result_valobj_sp;
1370 const_valobj_sp->SetName (persistent_variable_name);
1371 }
1372 else
Jim Ingham78a685a2011-04-16 00:01:131373 {
Jim Ingham2837b762011-05-04 03:43:181374 if (use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:131375 {
Jim Ingham2837b762011-05-04 03:43:181376 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:131377 if (dynamic_sp)
1378 result_valobj_sp = dynamic_sp;
1379 }
1380
Jim Ingham6035b672011-03-31 00:19:251381 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Ingham78a685a2011-04-16 00:01:131382 }
Greg Clayton8b2fe6d2010-12-14 02:59:591383
Sean Callanan92adcac2011-01-13 08:53:351384 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1385
Greg Clayton8b2fe6d2010-12-14 02:59:591386 result_valobj_sp = const_valobj_sp;
1387
Sean Callanan92adcac2011-01-13 08:53:351388 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1389 assert (clang_expr_variable_sp.get());
1390
1391 // Set flags and live data as appropriate
1392
1393 const Value &result_value = live_valobj_sp->GetValue();
1394
1395 switch (result_value.GetValueType())
1396 {
1397 case Value::eValueTypeHostAddress:
1398 case Value::eValueTypeFileAddress:
1399 // we don't do anything with these for now
1400 break;
1401 case Value::eValueTypeScalar:
1402 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1403 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1404 break;
1405 case Value::eValueTypeLoadAddress:
1406 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1407 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1408 break;
1409 }
Greg Clayton8b2fe6d2010-12-14 02:59:591410 }
1411 else
1412 {
1413 // Make sure we aren't just trying to see the value of a persistent
1414 // variable (something like "$0")
Greg Clayton3e06bd92011-01-09 21:07:351415 lldb::ClangExpressionVariableSP persistent_var_sp;
1416 // Only check for persistent variables the expression starts with a '$'
1417 if (expr_cstr[0] == '$')
1418 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1419
Greg Clayton8b2fe6d2010-12-14 02:59:591420 if (persistent_var_sp)
1421 {
1422 result_valobj_sp = persistent_var_sp->GetValueObject ();
1423 execution_results = eExecutionCompleted;
1424 }
1425 else
1426 {
1427 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan3bfdaa22011-09-15 02:13:071428
Greg Clayton8b2fe6d2010-12-14 02:59:591429 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan3bfdaa22011-09-15 02:13:071430 execution_policy,
Sean Callanan92adcac2011-01-13 08:53:351431 unwind_on_error,
Greg Clayton8b2fe6d2010-12-14 02:59:591432 expr_cstr,
1433 prefix,
1434 result_valobj_sp);
1435 }
1436 }
Jim Ingham6026ca32011-05-12 02:06:141437
1438 m_suppress_stop_hooks = old_suppress_value;
1439
Greg Clayton8b2fe6d2010-12-14 02:59:591440 return execution_results;
1441}
1442
Greg Claytonf3ef3d22011-05-22 22:46:531443lldb::addr_t
1444Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1445{
1446 addr_t code_addr = load_addr;
1447 switch (m_arch.GetMachine())
1448 {
1449 case llvm::Triple::arm:
1450 case llvm::Triple::thumb:
1451 switch (addr_class)
1452 {
1453 case eAddressClassData:
1454 case eAddressClassDebug:
1455 return LLDB_INVALID_ADDRESS;
1456
1457 case eAddressClassUnknown:
1458 case eAddressClassInvalid:
1459 case eAddressClassCode:
1460 case eAddressClassCodeAlternateISA:
1461 case eAddressClassRuntime:
1462 // Check if bit zero it no set?
1463 if ((code_addr & 1ull) == 0)
1464 {
1465 // Bit zero isn't set, check if the address is a multiple of 2?
1466 if (code_addr & 2ull)
1467 {
1468 // The address is a multiple of 2 so it must be thumb, set bit zero
1469 code_addr |= 1ull;
1470 }
1471 else if (addr_class == eAddressClassCodeAlternateISA)
1472 {
1473 // We checked the address and the address claims to be the alternate ISA
1474 // which means thumb, so set bit zero.
1475 code_addr |= 1ull;
1476 }
1477 }
1478 break;
1479 }
1480 break;
1481
1482 default:
1483 break;
1484 }
1485 return code_addr;
1486}
1487
1488lldb::addr_t
1489Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1490{
1491 addr_t opcode_addr = load_addr;
1492 switch (m_arch.GetMachine())
1493 {
1494 case llvm::Triple::arm:
1495 case llvm::Triple::thumb:
1496 switch (addr_class)
1497 {
1498 case eAddressClassData:
1499 case eAddressClassDebug:
1500 return LLDB_INVALID_ADDRESS;
1501
1502 case eAddressClassInvalid:
1503 case eAddressClassUnknown:
1504 case eAddressClassCode:
1505 case eAddressClassCodeAlternateISA:
1506 case eAddressClassRuntime:
1507 opcode_addr &= ~(1ull);
1508 break;
1509 }
1510 break;
1511
1512 default:
1513 break;
1514 }
1515 return opcode_addr;
1516}
1517
Jim Ingham9575d842011-03-11 03:53:591518lldb::user_id_t
1519Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1520{
1521 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
1522 new_hook_sp.reset (new StopHook(GetSP(), new_uid));
1523 m_stop_hooks[new_uid] = new_hook_sp;
1524 return new_uid;
1525}
1526
1527bool
1528Target::RemoveStopHookByID (lldb::user_id_t user_id)
1529{
1530 size_t num_removed;
1531 num_removed = m_stop_hooks.erase (user_id);
1532 if (num_removed == 0)
1533 return false;
1534 else
1535 return true;
1536}
1537
1538void
1539Target::RemoveAllStopHooks ()
1540{
1541 m_stop_hooks.clear();
1542}
1543
1544Target::StopHookSP
1545Target::GetStopHookByID (lldb::user_id_t user_id)
1546{
1547 StopHookSP found_hook;
1548
1549 StopHookCollection::iterator specified_hook_iter;
1550 specified_hook_iter = m_stop_hooks.find (user_id);
1551 if (specified_hook_iter != m_stop_hooks.end())
1552 found_hook = (*specified_hook_iter).second;
1553 return found_hook;
1554}
1555
1556bool
1557Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1558{
1559 StopHookCollection::iterator specified_hook_iter;
1560 specified_hook_iter = m_stop_hooks.find (user_id);
1561 if (specified_hook_iter == m_stop_hooks.end())
1562 return false;
1563
1564 (*specified_hook_iter).second->SetIsActive (active_state);
1565 return true;
1566}
1567
1568void
1569Target::SetAllStopHooksActiveState (bool active_state)
1570{
1571 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1572 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1573 {
1574 (*pos).second->SetIsActive (active_state);
1575 }
1576}
1577
1578void
1579Target::RunStopHooks ()
1580{
Jim Ingham6026ca32011-05-12 02:06:141581 if (m_suppress_stop_hooks)
1582 return;
1583
Jim Ingham9575d842011-03-11 03:53:591584 if (!m_process_sp)
1585 return;
1586
1587 if (m_stop_hooks.empty())
1588 return;
1589
1590 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1591
1592 // If there aren't any active stop hooks, don't bother either:
1593 bool any_active_hooks = false;
1594 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1595 {
1596 if ((*pos).second->IsActive())
1597 {
1598 any_active_hooks = true;
1599 break;
1600 }
1601 }
1602 if (!any_active_hooks)
1603 return;
1604
1605 CommandReturnObject result;
1606
1607 std::vector<ExecutionContext> exc_ctx_with_reasons;
1608 std::vector<SymbolContext> sym_ctx_with_reasons;
1609
1610 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1611 size_t num_threads = cur_threadlist.GetSize();
1612 for (size_t i = 0; i < num_threads; i++)
1613 {
1614 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1615 if (cur_thread_sp->ThreadStoppedForAReason())
1616 {
1617 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1618 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1619 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1620 }
1621 }
1622
1623 // If no threads stopped for a reason, don't run the stop-hooks.
1624 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1625 if (num_exe_ctx == 0)
1626 return;
1627
Jim Ingham5b52f0c2011-06-02 23:58:261628 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1629 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Ingham9575d842011-03-11 03:53:591630
1631 bool keep_going = true;
1632 bool hooks_ran = false;
Jim Ingham381e25b2011-03-22 01:47:271633 bool print_hook_header;
1634 bool print_thread_header;
1635
1636 if (num_exe_ctx == 1)
1637 print_thread_header = false;
1638 else
1639 print_thread_header = true;
1640
1641 if (m_stop_hooks.size() == 1)
1642 print_hook_header = false;
1643 else
1644 print_hook_header = true;
1645
Jim Ingham9575d842011-03-11 03:53:591646 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1647 {
1648 // result.Clear();
1649 StopHookSP cur_hook_sp = (*pos).second;
1650 if (!cur_hook_sp->IsActive())
1651 continue;
1652
1653 bool any_thread_matched = false;
1654 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1655 {
1656 if ((cur_hook_sp->GetSpecifier () == NULL
1657 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1658 && (cur_hook_sp->GetThreadSpecifier() == NULL
1659 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].thread)))
1660 {
1661 if (!hooks_ran)
1662 {
Jim Ingham381e25b2011-03-22 01:47:271663 result.AppendMessage("\n** Stop Hooks **");
Jim Ingham9575d842011-03-11 03:53:591664 hooks_ran = true;
1665 }
Jim Ingham381e25b2011-03-22 01:47:271666 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:591667 {
1668 result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID());
1669 any_thread_matched = true;
1670 }
1671
Jim Ingham381e25b2011-03-22 01:47:271672 if (print_thread_header)
1673 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].thread->GetIndexID());
Jim Ingham9575d842011-03-11 03:53:591674
1675 bool stop_on_continue = true;
1676 bool stop_on_error = true;
1677 bool echo_commands = false;
1678 bool print_results = true;
1679 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton32e0a752011-03-30 18:16:511680 &exc_ctx_with_reasons[i],
1681 stop_on_continue,
1682 stop_on_error,
1683 echo_commands,
1684 print_results,
1685 result);
Jim Ingham9575d842011-03-11 03:53:591686
1687 // If the command started the target going again, we should bag out of
1688 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:511689 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1690 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:591691 {
1692 result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID());
1693 keep_going = false;
1694 }
1695 }
1696 }
1697 }
1698 if (hooks_ran)
1699 result.AppendMessage ("\n** End Stop Hooks **\n");
Caroline Tice969ed3d12011-05-02 20:41:461700
1701 result.GetImmediateOutputStream()->Flush();
1702 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:591703}
1704
Greg Clayton7b242382011-07-08 00:48:091705bool
1706Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
1707{
1708 bool changed = false;
1709 if (module)
1710 {
1711 ObjectFile *object_file = module->GetObjectFile();
1712 if (object_file)
1713 {
1714 SectionList *section_list = object_file->GetSectionList ();
1715 if (section_list)
1716 {
1717 // All sections listed in the dyld image info structure will all
1718 // either be fixed up already, or they will all be off by a single
1719 // slide amount that is determined by finding the first segment
1720 // that is at file offset zero which also has bytes (a file size
1721 // that is greater than zero) in the object file.
1722
1723 // Determine the slide amount (if any)
1724 const size_t num_sections = section_list->GetSize();
1725 size_t sect_idx = 0;
1726 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1727 {
1728 // Iterate through the object file sections to find the
1729 // first section that starts of file offset zero and that
1730 // has bytes in the file...
1731 Section *section = section_list->GetSectionAtIndex (sect_idx).get();
1732 if (section)
1733 {
1734 if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
1735 changed = true;
1736 }
1737 }
1738 }
1739 }
1740 }
1741 return changed;
1742}
1743
1744
Jim Ingham9575d842011-03-11 03:53:591745//--------------------------------------------------------------
1746// class Target::StopHook
1747//--------------------------------------------------------------
1748
1749
1750Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1751 UserID (uid),
1752 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:591753 m_commands (),
1754 m_specifier_sp (),
Stephen Wilson71c21d12011-04-11 19:41:401755 m_thread_spec_ap(NULL),
1756 m_active (true)
Jim Ingham9575d842011-03-11 03:53:591757{
1758}
1759
1760Target::StopHook::StopHook (const StopHook &rhs) :
1761 UserID (rhs.GetID()),
1762 m_target_sp (rhs.m_target_sp),
1763 m_commands (rhs.m_commands),
1764 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilson71c21d12011-04-11 19:41:401765 m_thread_spec_ap (NULL),
1766 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:591767{
1768 if (rhs.m_thread_spec_ap.get() != NULL)
1769 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1770}
1771
1772
1773Target::StopHook::~StopHook ()
1774{
1775}
1776
1777void
1778Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
1779{
1780 m_thread_spec_ap.reset (specifier);
1781}
1782
1783
1784void
1785Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
1786{
1787 int indent_level = s->GetIndentLevel();
1788
1789 s->SetIndentLevel(indent_level + 2);
1790
1791 s->Printf ("Hook: %d\n", GetID());
1792 if (m_active)
1793 s->Indent ("State: enabled\n");
1794 else
1795 s->Indent ("State: disabled\n");
1796
1797 if (m_specifier_sp)
1798 {
1799 s->Indent();
1800 s->PutCString ("Specifier:\n");
1801 s->SetIndentLevel (indent_level + 4);
1802 m_specifier_sp->GetDescription (s, level);
1803 s->SetIndentLevel (indent_level + 2);
1804 }
1805
1806 if (m_thread_spec_ap.get() != NULL)
1807 {
1808 StreamString tmp;
1809 s->Indent("Thread:\n");
1810 m_thread_spec_ap->GetDescription (&tmp, level);
1811 s->SetIndentLevel (indent_level + 4);
1812 s->Indent (tmp.GetData());
1813 s->PutCString ("\n");
1814 s->SetIndentLevel (indent_level + 2);
1815 }
1816
1817 s->Indent ("Commands: \n");
1818 s->SetIndentLevel (indent_level + 4);
1819 uint32_t num_commands = m_commands.GetSize();
1820 for (uint32_t i = 0; i < num_commands; i++)
1821 {
1822 s->Indent(m_commands.GetStringAtIndex(i));
1823 s->PutCString ("\n");
1824 }
1825 s->SetIndentLevel (indent_level);
1826}
1827
1828
Caroline Ticedaccaa92010-09-20 20:44:431829//--------------------------------------------------------------
1830// class Target::SettingsController
1831//--------------------------------------------------------------
1832
1833Target::SettingsController::SettingsController () :
1834 UserSettingsController ("target", Debugger::GetSettingsController()),
1835 m_default_architecture ()
1836{
1837 m_default_settings.reset (new TargetInstanceSettings (*this, false,
1838 InstanceSettings::GetDefaultName().AsCString()));
1839}
1840
1841Target::SettingsController::~SettingsController ()
1842{
1843}
1844
1845lldb::InstanceSettingsSP
1846Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1847{
Greg Claytondbe54502010-11-19 03:46:011848 TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1849 false,
1850 instance_name);
Caroline Ticedaccaa92010-09-20 20:44:431851 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1852 return new_settings_sp;
1853}
1854
Caroline Ticedaccaa92010-09-20 20:44:431855
Jim Ingham78a685a2011-04-16 00:01:131856#define TSC_DEFAULT_ARCH "default-arch"
1857#define TSC_EXPR_PREFIX "expr-prefix"
Jim Ingham78a685a2011-04-16 00:01:131858#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
Greg Clayton385aa282011-04-22 03:55:061859#define TSC_SKIP_PROLOGUE "skip-prologue"
Greg Clayton7e14f912011-04-23 02:04:551860#define TSC_SOURCE_MAP "source-map"
Enrico Granata22c55d12011-08-12 02:00:061861#define TSC_MAX_CHILDREN "max-children-count"
Enrico Granata9128ee2f2011-09-06 19:20:511862#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
Greg Claytonbfe5f3b2011-02-18 01:44:251863
1864
1865static const ConstString &
1866GetSettingNameForDefaultArch ()
1867{
1868 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytonbfe5f3b2011-02-18 01:44:251869 return g_const_string;
Caroline Ticedaccaa92010-09-20 20:44:431870}
1871
Greg Claytonbfe5f3b2011-02-18 01:44:251872static const ConstString &
1873GetSettingNameForExpressionPrefix ()
1874{
1875 static ConstString g_const_string (TSC_EXPR_PREFIX);
1876 return g_const_string;
1877}
1878
1879static const ConstString &
Jim Ingham78a685a2011-04-16 00:01:131880GetSettingNameForPreferDynamicValue ()
1881{
1882 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
1883 return g_const_string;
1884}
1885
Greg Clayton7e14f912011-04-23 02:04:551886static const ConstString &
1887GetSettingNameForSourcePathMap ()
1888{
1889 static ConstString g_const_string (TSC_SOURCE_MAP);
1890 return g_const_string;
1891}
Greg Claytonbfe5f3b2011-02-18 01:44:251892
Greg Clayton385aa282011-04-22 03:55:061893static const ConstString &
1894GetSettingNameForSkipPrologue ()
1895{
1896 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
1897 return g_const_string;
1898}
1899
Enrico Granata22c55d12011-08-12 02:00:061900static const ConstString &
1901GetSettingNameForMaxChildren ()
1902{
1903 static ConstString g_const_string (TSC_MAX_CHILDREN);
1904 return g_const_string;
1905}
Greg Clayton385aa282011-04-22 03:55:061906
Enrico Granata9128ee2f2011-09-06 19:20:511907static const ConstString &
1908GetSettingNameForMaxStringSummaryLength ()
1909{
1910 static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
1911 return g_const_string;
1912}
Greg Clayton385aa282011-04-22 03:55:061913
Caroline Ticedaccaa92010-09-20 20:44:431914bool
1915Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
1916 const char *index_value,
1917 const char *value,
1918 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:541919 const VarSetOperationType op,
Caroline Ticedaccaa92010-09-20 20:44:431920 Error&err)
1921{
Greg Claytonbfe5f3b2011-02-18 01:44:251922 if (var_name == GetSettingNameForDefaultArch())
Caroline Ticedaccaa92010-09-20 20:44:431923 {
Greg Claytoneb0103f2011-04-07 22:46:351924 m_default_architecture.SetTriple (value, NULL);
Greg Clayton64195a22011-02-23 00:35:021925 if (!m_default_architecture.IsValid())
1926 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Ticedaccaa92010-09-20 20:44:431927 }
1928 return true;
1929}
1930
1931
1932bool
1933Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
1934 StringList &value,
1935 Error &err)
1936{
Greg Claytonbfe5f3b2011-02-18 01:44:251937 if (var_name == GetSettingNameForDefaultArch())
Caroline Ticedaccaa92010-09-20 20:44:431938 {
Greg Clayton307de252010-10-27 02:06:371939 // If the arch is invalid (the default), don't show a string for it
1940 if (m_default_architecture.IsValid())
Greg Clayton64195a22011-02-23 00:35:021941 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Ticedaccaa92010-09-20 20:44:431942 return true;
1943 }
1944 else
1945 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1946
1947 return false;
1948}
1949
1950//--------------------------------------------------------------
1951// class TargetInstanceSettings
1952//--------------------------------------------------------------
1953
Greg Clayton85851dd2010-12-04 00:10:171954TargetInstanceSettings::TargetInstanceSettings
1955(
1956 UserSettingsController &owner,
1957 bool live_instance,
1958 const char *name
1959) :
Greg Claytonbfe5f3b2011-02-18 01:44:251960 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Clayton7e14f912011-04-23 02:04:551961 m_expr_prefix_file (),
1962 m_expr_prefix_contents_sp (),
Jim Ingham2837b762011-05-04 03:43:181963 m_prefer_dynamic_value (2),
Greg Clayton7e14f912011-04-23 02:04:551964 m_skip_prologue (true, true),
Enrico Granata22c55d12011-08-12 02:00:061965 m_source_map (NULL, NULL),
Enrico Granata9128ee2f2011-09-06 19:20:511966 m_max_children_display(256),
1967 m_max_strlen_length(1024)
Caroline Ticedaccaa92010-09-20 20:44:431968{
1969 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1970 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
1971 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1972 // This is true for CreateInstanceName() too.
1973
1974 if (GetInstanceName () == InstanceSettings::InvalidName())
1975 {
1976 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1977 m_owner.RegisterInstanceSettings (this);
1978 }
1979
1980 if (live_instance)
1981 {
1982 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1983 CopyInstanceSettings (pending_settings,false);
Caroline Ticedaccaa92010-09-20 20:44:431984 }
1985}
1986
1987TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Clayton7e14f912011-04-23 02:04:551988 InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
1989 m_expr_prefix_file (rhs.m_expr_prefix_file),
1990 m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp),
1991 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
1992 m_skip_prologue (rhs.m_skip_prologue),
Enrico Granata22c55d12011-08-12 02:00:061993 m_source_map (rhs.m_source_map),
Enrico Granata9128ee2f2011-09-06 19:20:511994 m_max_children_display(rhs.m_max_children_display),
1995 m_max_strlen_length(rhs.m_max_strlen_length)
Caroline Ticedaccaa92010-09-20 20:44:431996{
1997 if (m_instance_name != InstanceSettings::GetDefaultName())
1998 {
1999 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
2000 CopyInstanceSettings (pending_settings,false);
Caroline Ticedaccaa92010-09-20 20:44:432001 }
2002}
2003
2004TargetInstanceSettings::~TargetInstanceSettings ()
2005{
2006}
2007
2008TargetInstanceSettings&
2009TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
2010{
2011 if (this != &rhs)
2012 {
2013 }
2014
2015 return *this;
2016}
2017
Caroline Ticedaccaa92010-09-20 20:44:432018void
2019TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2020 const char *index_value,
2021 const char *value,
2022 const ConstString &instance_name,
2023 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:542024 VarSetOperationType op,
Caroline Ticedaccaa92010-09-20 20:44:432025 Error &err,
2026 bool pending)
2027{
Greg Claytonbfe5f3b2011-02-18 01:44:252028 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan322f5292010-10-29 00:29:032029 {
Greg Clayton7e14f912011-04-23 02:04:552030 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
2031 if (err.Success())
Sean Callanan322f5292010-10-29 00:29:032032 {
Greg Clayton7e14f912011-04-23 02:04:552033 switch (op)
Sean Callanan322f5292010-10-29 00:29:032034 {
Greg Clayton7e14f912011-04-23 02:04:552035 default:
2036 break;
2037 case eVarSetOperationAssign:
2038 case eVarSetOperationAppend:
Sean Callanan322f5292010-10-29 00:29:032039 {
Greg Clayton7e14f912011-04-23 02:04:552040 if (!m_expr_prefix_file.GetCurrentValue().Exists())
2041 {
2042 err.SetErrorToGenericError ();
2043 err.SetErrorStringWithFormat ("%s does not exist.\n", value);
2044 return;
2045 }
2046
2047 m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
2048
2049 if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0)
2050 {
2051 err.SetErrorStringWithFormat ("Couldn't read data from '%s'\n", value);
2052 m_expr_prefix_contents_sp.reset();
2053 }
Sean Callanan322f5292010-10-29 00:29:032054 }
Greg Clayton7e14f912011-04-23 02:04:552055 break;
2056 case eVarSetOperationClear:
2057 m_expr_prefix_contents_sp.reset();
Sean Callanan322f5292010-10-29 00:29:032058 }
Sean Callanan322f5292010-10-29 00:29:032059 }
2060 }
Jim Ingham78a685a2011-04-16 00:01:132061 else if (var_name == GetSettingNameForPreferDynamicValue())
2062 {
Jim Ingham2837b762011-05-04 03:43:182063 int new_value;
2064 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
2065 if (err.Success())
2066 m_prefer_dynamic_value = new_value;
Greg Clayton385aa282011-04-22 03:55:062067 }
2068 else if (var_name == GetSettingNameForSkipPrologue())
2069 {
Greg Clayton7e14f912011-04-23 02:04:552070 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
2071 }
Enrico Granata22c55d12011-08-12 02:00:062072 else if (var_name == GetSettingNameForMaxChildren())
2073 {
2074 bool ok;
2075 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2076 if (ok)
2077 m_max_children_display = new_value;
2078 }
Enrico Granata9128ee2f2011-09-06 19:20:512079 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2080 {
2081 bool ok;
2082 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2083 if (ok)
2084 m_max_strlen_length = new_value;
2085 }
Greg Clayton7e14f912011-04-23 02:04:552086 else if (var_name == GetSettingNameForSourcePathMap ())
2087 {
2088 switch (op)
2089 {
2090 case eVarSetOperationReplace:
2091 case eVarSetOperationInsertBefore:
2092 case eVarSetOperationInsertAfter:
2093 case eVarSetOperationRemove:
2094 default:
2095 break;
2096 case eVarSetOperationAssign:
2097 m_source_map.Clear(true);
2098 // Fall through to append....
2099 case eVarSetOperationAppend:
2100 {
2101 Args args(value);
2102 const uint32_t argc = args.GetArgumentCount();
2103 if (argc & 1 || argc == 0)
2104 {
2105 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
2106 }
2107 else
2108 {
2109 char resolved_new_path[PATH_MAX];
2110 FileSpec file_spec;
2111 const char *old_path;
2112 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
2113 {
2114 const char *new_path = args.GetArgumentAtIndex(idx+1);
2115 assert (new_path); // We have an even number of paths, this shouldn't happen!
2116
2117 file_spec.SetFile(new_path, true);
2118 if (file_spec.Exists())
2119 {
2120 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
2121 {
2122 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
2123 return;
2124 }
2125 }
2126 else
2127 {
2128 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
2129 return;
2130 }
2131 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
2132 }
2133 }
2134 }
2135 break;
2136
2137 case eVarSetOperationClear:
2138 m_source_map.Clear(true);
2139 break;
2140 }
Jim Ingham78a685a2011-04-16 00:01:132141 }
Caroline Ticedaccaa92010-09-20 20:44:432142}
2143
2144void
Greg Claytonbfe5f3b2011-02-18 01:44:252145TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Ticedaccaa92010-09-20 20:44:432146{
Sean Callanan322f5292010-10-29 00:29:032147 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
2148
2149 if (!new_settings_ptr)
2150 return;
2151
Greg Clayton7e14f912011-04-23 02:04:552152 m_expr_prefix_file = new_settings_ptr->m_expr_prefix_file;
2153 m_expr_prefix_contents_sp = new_settings_ptr->m_expr_prefix_contents_sp;
2154 m_prefer_dynamic_value = new_settings_ptr->m_prefer_dynamic_value;
2155 m_skip_prologue = new_settings_ptr->m_skip_prologue;
Enrico Granata22c55d12011-08-12 02:00:062156 m_max_children_display = new_settings_ptr->m_max_children_display;
Enrico Granata9128ee2f2011-09-06 19:20:512157 m_max_strlen_length = new_settings_ptr->m_max_strlen_length;
Caroline Ticedaccaa92010-09-20 20:44:432158}
2159
Caroline Tice12cecd72010-09-20 21:37:422160bool
Caroline Ticedaccaa92010-09-20 20:44:432161TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2162 const ConstString &var_name,
2163 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:422164 Error *err)
Caroline Ticedaccaa92010-09-20 20:44:432165{
Greg Claytonbfe5f3b2011-02-18 01:44:252166 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan322f5292010-10-29 00:29:032167 {
Greg Clayton7e14f912011-04-23 02:04:552168 char path[PATH_MAX];
2169 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
2170 if (path_len > 0)
2171 value.AppendString (path, path_len);
Sean Callanan322f5292010-10-29 00:29:032172 }
Jim Ingham78a685a2011-04-16 00:01:132173 else if (var_name == GetSettingNameForPreferDynamicValue())
2174 {
Jim Ingham2837b762011-05-04 03:43:182175 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Ingham78a685a2011-04-16 00:01:132176 }
Greg Clayton385aa282011-04-22 03:55:062177 else if (var_name == GetSettingNameForSkipPrologue())
2178 {
2179 if (m_skip_prologue)
2180 value.AppendString ("true");
2181 else
2182 value.AppendString ("false");
2183 }
Greg Clayton7e14f912011-04-23 02:04:552184 else if (var_name == GetSettingNameForSourcePathMap ())
2185 {
2186 }
Enrico Granata22c55d12011-08-12 02:00:062187 else if (var_name == GetSettingNameForMaxChildren())
2188 {
2189 StreamString count_str;
2190 count_str.Printf ("%d", m_max_children_display);
2191 value.AppendString (count_str.GetData());
2192 }
Enrico Granata9128ee2f2011-09-06 19:20:512193 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2194 {
2195 StreamString count_str;
2196 count_str.Printf ("%d", m_max_strlen_length);
2197 value.AppendString (count_str.GetData());
2198 }
Sean Callanan322f5292010-10-29 00:29:032199 else
2200 {
2201 if (err)
2202 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2203 return false;
2204 }
2205
2206 return true;
Caroline Ticedaccaa92010-09-20 20:44:432207}
2208
2209const ConstString
2210TargetInstanceSettings::CreateInstanceName ()
2211{
Caroline Ticedaccaa92010-09-20 20:44:432212 StreamString sstr;
Caroline Tice1559a462010-09-27 00:30:102213 static int instance_count = 1;
2214
Caroline Ticedaccaa92010-09-20 20:44:432215 sstr.Printf ("target_%d", instance_count);
2216 ++instance_count;
2217
2218 const ConstString ret_val (sstr.GetData());
2219 return ret_val;
2220}
2221
2222//--------------------------------------------------
2223// Target::SettingsController Variable Tables
2224//--------------------------------------------------
Jim Ingham2837b762011-05-04 03:43:182225OptionEnumValueElement
2226TargetInstanceSettings::g_dynamic_value_types[] =
2227{
Greg Clayton5d2fbfe2011-05-30 00:39:482228{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2229{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2230{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham2837b762011-05-04 03:43:182231{ 0, NULL, NULL }
2232};
Caroline Ticedaccaa92010-09-20 20:44:432233
2234SettingEntry
2235Target::SettingsController::global_settings_table[] =
2236{
Greg Claytonbfe5f3b2011-02-18 01:44:252237 // var-name var-type default enum init'd hidden help-text
2238 // ================= ================== =========== ==== ====== ====== =========================================================================
2239 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
2240 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
2241};
2242
Caroline Ticedaccaa92010-09-20 20:44:432243SettingEntry
2244Target::SettingsController::instance_settings_table[] =
2245{
Enrico Granata9128ee2f2011-09-06 19:20:512246 // var-name var-type default enum init'd hidden help-text
2247 // ================= ================== =============== ======================= ====== ====== =========================================================================
2248 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
2249 { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
2250 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
2251 { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
2252 { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
2253 { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." },
2254 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Ticedaccaa92010-09-20 20:44:432255};