blob: d917530ad0d0f5907cfeac3c7e12bdb78b967837 [file] [log] [blame]
Johnny Chenebd63b22011-07-16 21:15:39 +00001//===-- SWIG Interface for SBTarget -----------------------------*- 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
10namespace lldb {
11
12%feature("docstring",
13"Represents the target program running under the debugger.
14
Johnny Chenecd4feb2011-10-14 00:42:25 +000015SBTarget supports module, breakpoint, and watchpoint iterations. For example,
Johnny Chenebd63b22011-07-16 21:15:39 +000016
17 for m in target.module_iter():
18 print m
19
20produces:
21
22(x86_64) /Volumes/data/lldb/svn/trunk/test/python_api/lldbutil/iter/a.out
23(x86_64) /usr/lib/dyld
24(x86_64) /usr/lib/libstdc++.6.dylib
25(x86_64) /usr/lib/libSystem.B.dylib
26(x86_64) /usr/lib/system/libmathCommon.A.dylib
27(x86_64) /usr/lib/libSystem.B.dylib(__commpage)
28
29and,
30
31 for b in target.breakpoint_iter():
32 print b
33
34produces:
35
36SBBreakpoint: id = 1, file ='main.cpp', line = 66, locations = 1
Johnny Chen092bd152011-09-27 01:19:20 +000037SBBreakpoint: id = 2, file ='main.cpp', line = 85, locations = 1
38
39and,
40
Johnny Chenecd4feb2011-10-14 00:42:25 +000041 for wp_loc in target.watchpoint_iter():
Johnny Chen092bd152011-09-27 01:19:20 +000042 print wp_loc
43
44produces:
45
Johnny Chenecd4feb2011-10-14 00:42:25 +000046Watchpoint 1: addr = 0x1034ca048 size = 4 state = enabled type = rw
Johnny Chen092bd152011-09-27 01:19:20 +000047 declare @ '/Volumes/data/lldb/svn/trunk/test/python_api/watchpoint/main.c:12'
Johnny Chenecd4feb2011-10-14 00:42:25 +000048 hw_index = 0 hit_count = 2 ignore_count = 0"
Johnny Chenc3fba812011-07-18 20:13:38 +000049) SBTarget;
Johnny Chenebd63b22011-07-16 21:15:39 +000050class SBTarget
51{
Johnny Chenebd63b22011-07-16 21:15:39 +000052public:
53 //------------------------------------------------------------------
54 // Broadcaster bits.
55 //------------------------------------------------------------------
56 enum
57 {
58 eBroadcastBitBreakpointChanged = (1 << 0),
59 eBroadcastBitModulesLoaded = (1 << 1),
60 eBroadcastBitModulesUnloaded = (1 << 2)
61 };
62
63 //------------------------------------------------------------------
64 // Constructors
65 //------------------------------------------------------------------
66 SBTarget ();
67
68 SBTarget (const lldb::SBTarget& rhs);
69
Johnny Chenebd63b22011-07-16 21:15:39 +000070 //------------------------------------------------------------------
71 // Destructor
72 //------------------------------------------------------------------
73 ~SBTarget();
74
75 bool
76 IsValid() const;
77
78 lldb::SBProcess
79 GetProcess ();
80
81 %feature("docstring", "
82 //------------------------------------------------------------------
83 /// Launch a new process.
84 ///
85 /// Launch a new process by spawning a new process using the
86 /// target object's executable module's file as the file to launch.
87 /// Arguments are given in \a argv, and the environment variables
88 /// are in \a envp. Standard input and output files can be
89 /// optionally re-directed to \a stdin_path, \a stdout_path, and
90 /// \a stderr_path.
91 ///
92 /// @param[in] listener
93 /// An optional listener that will receive all process events.
94 /// If \a listener is valid then \a listener will listen to all
95 /// process events. If not valid, then this target's debugger
96 /// (SBTarget::GetDebugger()) will listen to all process events.
97 ///
98 /// @param[in] argv
99 /// The argument array.
100 ///
101 /// @param[in] envp
102 /// The environment array.
103 ///
104 /// @param[in] launch_flags
105 /// Flags to modify the launch (@see lldb::LaunchFlags)
106 ///
107 /// @param[in] stdin_path
108 /// The path to use when re-directing the STDIN of the new
109 /// process. If all stdXX_path arguments are NULL, a pseudo
110 /// terminal will be used.
111 ///
112 /// @param[in] stdout_path
113 /// The path to use when re-directing the STDOUT of the new
114 /// process. If all stdXX_path arguments are NULL, a pseudo
115 /// terminal will be used.
116 ///
117 /// @param[in] stderr_path
118 /// The path to use when re-directing the STDERR of the new
119 /// process. If all stdXX_path arguments are NULL, a pseudo
120 /// terminal will be used.
121 ///
122 /// @param[in] working_directory
123 /// The working directory to have the child process run in
124 ///
125 /// @param[in] launch_flags
126 /// Some launch options specified by logical OR'ing
127 /// lldb::LaunchFlags enumeration values together.
128 ///
129 /// @param[in] stop_at_endtry
130 /// If false do not stop the inferior at the entry point.
131 ///
132 /// @param[out]
133 /// An error object. Contains the reason if there is some failure.
134 ///
135 /// @return
136 /// A process object for the newly created process.
137 //------------------------------------------------------------------
138
139 For example,
140
141 process = target.Launch(self.dbg.GetListener(), None, None,
142 None, '/tmp/stdout.txt', None,
143 None, 0, False, error)
144
145 launches a new process by passing nothing for both the args and the envs
146 and redirect the standard output of the inferior to the /tmp/stdout.txt
147 file. It does not specify a working directory so that the debug server
148 will use its idea of what the current working directory is for the
149 inferior. Also, we ask the debugger not to stop the inferior at the
150 entry point. If no breakpoint is specified for the inferior, it should
151 run to completion if no user interaction is required.
152 ") Launch;
153 lldb::SBProcess
154 Launch (SBListener &listener,
155 char const **argv,
156 char const **envp,
157 const char *stdin_path,
158 const char *stdout_path,
159 const char *stderr_path,
160 const char *working_directory,
161 uint32_t launch_flags, // See LaunchFlags
162 bool stop_at_entry,
163 lldb::SBError& error);
164
165 %feature("docstring", "
166 //------------------------------------------------------------------
167 /// Launch a new process with sensible defaults.
168 ///
169 /// @param[in] argv
170 /// The argument array.
171 ///
172 /// @param[in] envp
173 /// The environment array.
174 ///
175 /// @param[in] working_directory
176 /// The working directory to have the child process run in
177 ///
178 /// Default: listener
179 /// Set to the target's debugger (SBTarget::GetDebugger())
180 ///
181 /// Default: launch_flags
182 /// Empty launch flags
183 ///
184 /// Default: stdin_path
185 /// Default: stdout_path
186 /// Default: stderr_path
187 /// A pseudo terminal will be used.
188 ///
189 /// @return
190 /// A process object for the newly created process.
191 //------------------------------------------------------------------
192
193 For example,
194
195 process = target.LaunchSimple(['X', 'Y', 'Z'], None, os.getcwd())
196
197 launches a new process by passing 'X', 'Y', 'Z' as the args to the
198 executable.
199 ") LaunchSimple;
200 lldb::SBProcess
201 LaunchSimple (const char **argv,
202 const char **envp,
203 const char *working_directory);
204
205 %feature("docstring", "
206 //------------------------------------------------------------------
207 /// Attach to process with pid.
208 ///
209 /// @param[in] listener
210 /// An optional listener that will receive all process events.
211 /// If \a listener is valid then \a listener will listen to all
212 /// process events. If not valid, then this target's debugger
213 /// (SBTarget::GetDebugger()) will listen to all process events.
214 ///
215 /// @param[in] pid
216 /// The process ID to attach to.
217 ///
218 /// @param[out]
219 /// An error explaining what went wrong if attach fails.
220 ///
221 /// @return
222 /// A process object for the attached process.
223 //------------------------------------------------------------------
224 ") AttachToProcessWithID;
225 lldb::SBProcess
226 AttachToProcessWithID (SBListener &listener,
227 lldb::pid_t pid,
228 lldb::SBError& error);
229
230 %feature("docstring", "
231 //------------------------------------------------------------------
232 /// Attach to process with name.
233 ///
234 /// @param[in] listener
235 /// An optional listener that will receive all process events.
236 /// If \a listener is valid then \a listener will listen to all
237 /// process events. If not valid, then this target's debugger
238 /// (SBTarget::GetDebugger()) will listen to all process events.
239 ///
240 /// @param[in] name
241 /// Basename of process to attach to.
242 ///
243 /// @param[in] wait_for
244 /// If true wait for a new instance of 'name' to be launched.
245 ///
246 /// @param[out]
247 /// An error explaining what went wrong if attach fails.
248 ///
249 /// @return
250 /// A process object for the attached process.
251 //------------------------------------------------------------------
252 ") AttachToProcessWithName;
253 lldb::SBProcess
254 AttachToProcessWithName (SBListener &listener,
255 const char *name,
256 bool wait_for,
257 lldb::SBError& error);
258
259 %feature("docstring", "
260 //------------------------------------------------------------------
261 /// Connect to a remote debug server with url.
262 ///
263 /// @param[in] listener
264 /// An optional listener that will receive all process events.
265 /// If \a listener is valid then \a listener will listen to all
266 /// process events. If not valid, then this target's debugger
267 /// (SBTarget::GetDebugger()) will listen to all process events.
268 ///
269 /// @param[in] url
270 /// The url to connect to, e.g., 'connect://localhost:12345'.
271 ///
272 /// @param[in] plugin_name
273 /// The plugin name to be used; can be NULL.
274 ///
275 /// @param[out]
276 /// An error explaining what went wrong if the connect fails.
277 ///
278 /// @return
279 /// A process object for the connected process.
280 //------------------------------------------------------------------
281 ") ConnectRemote;
282 lldb::SBProcess
283 ConnectRemote (SBListener &listener,
284 const char *url,
285 const char *plugin_name,
286 SBError& error);
287
288 lldb::SBFileSpec
289 GetExecutable ();
290
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000291 bool
292 AddModule (lldb::SBModule &module);
293
294 lldb::SBModule
295 AddModule (const char *path,
296 const char *triple,
297 const char *uuid);
298
Johnny Chenebd63b22011-07-16 21:15:39 +0000299 uint32_t
300 GetNumModules () const;
301
302 lldb::SBModule
303 GetModuleAtIndex (uint32_t idx);
304
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000305 bool
306 RemoveModule (lldb::SBModule module);
307
Johnny Chenebd63b22011-07-16 21:15:39 +0000308 lldb::SBDebugger
309 GetDebugger() const;
310
311 lldb::SBModule
312 FindModule (const lldb::SBFileSpec &file_spec);
313
Greg Clayton1b925202012-01-29 06:07:39 +0000314 lldb::ByteOrder
315 GetByteOrder ();
316
317 uint32_t
318 GetAddressByteSize();
319
320 const char *
321 GetTriple ();
322
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000323 lldb::SBError
324 SetSectionLoadAddress (lldb::SBSection section,
325 lldb::addr_t section_base_addr);
326
327 lldb::SBError
328 ClearSectionLoadAddress (lldb::SBSection section);
329
330 lldb::SBError
331 SetModuleLoadAddress (lldb::SBModule module,
332 int64_t sections_offset);
333
334 lldb::SBError
335 ClearModuleLoadAddress (lldb::SBModule module);
336
Johnny Chenebd63b22011-07-16 21:15:39 +0000337 %feature("docstring", "
338 //------------------------------------------------------------------
339 /// Find functions by name.
340 ///
341 /// @param[in] name
342 /// The name of the function we are looking for.
343 ///
344 /// @param[in] name_type_mask
345 /// A logical OR of one or more FunctionNameType enum bits that
346 /// indicate what kind of names should be used when doing the
347 /// lookup. Bits include fully qualified names, base names,
348 /// C++ methods, or ObjC selectors.
349 /// See FunctionNameType for more details.
350 ///
351 /// @param[in] append
352 /// If true, any matches will be appended to \a sc_list, else
353 /// matches replace the contents of \a sc_list.
354 ///
355 /// @param[out] sc_list
356 /// A symbol context list that gets filled in with all of the
357 /// matches.
358 ///
359 /// @return
360 /// The number of matches added to \a sc_list.
361 //------------------------------------------------------------------
362 ") FindFunctions;
363 uint32_t
364 FindFunctions (const char *name,
365 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
366 bool append,
367 lldb::SBSymbolContextList& sc_list);
Enrico Granata979e20d2011-07-29 19:53:35 +0000368
369 lldb::SBType
370 FindFirstType (const char* type);
371
372 lldb::SBTypeList
373 FindTypes (const char* type);
Johnny Chenebd63b22011-07-16 21:15:39 +0000374
Jim Inghamcc637462011-09-13 00:29:56 +0000375 lldb::SBSourceManager
376 GetSourceManager ();
377
Johnny Chenebd63b22011-07-16 21:15:39 +0000378 %feature("docstring", "
379 //------------------------------------------------------------------
380 /// Find global and static variables by name.
381 ///
382 /// @param[in] name
383 /// The name of the global or static variable we are looking
384 /// for.
385 ///
386 /// @param[in] max_matches
387 /// Allow the number of matches to be limited to \a max_matches.
388 ///
389 /// @return
390 /// A list of matched variables in an SBValueList.
391 //------------------------------------------------------------------
392 ") FindGlobalVariables;
393 lldb::SBValueList
394 FindGlobalVariables (const char *name,
395 uint32_t max_matches);
396
397 void
398 Clear ();
399
Greg Claytona3955062011-07-22 16:46:35 +0000400 lldb::SBAddress
401 ResolveLoadAddress (lldb::addr_t vm_addr);
Johnny Chenebd63b22011-07-16 21:15:39 +0000402
403 SBSymbolContext
404 ResolveSymbolContextForAddress (const SBAddress& addr,
405 uint32_t resolve_scope);
406
407 lldb::SBBreakpoint
408 BreakpointCreateByLocation (const char *file, uint32_t line);
409
410 lldb::SBBreakpoint
411 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
412
413 lldb::SBBreakpoint
414 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
415
416 lldb::SBBreakpoint
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000417 BreakpointCreateByName (const char *symbol_name,
418 uint32_t func_name_type, // Logical OR one or more FunctionNameType enum bits
419 const SBFileSpecList &module_list,
420 const SBFileSpecList &comp_unit_list);
421
422 lldb::SBBreakpoint
Johnny Chenebd63b22011-07-16 21:15:39 +0000423 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
424
425 lldb::SBBreakpoint
Jim Ingham03c8ee52011-09-21 01:17:13 +0000426 BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name = NULL);
427
428 lldb::SBBreakpoint
Johnny Chenebd63b22011-07-16 21:15:39 +0000429 BreakpointCreateByAddress (addr_t address);
430
431 uint32_t
432 GetNumBreakpoints () const;
433
434 lldb::SBBreakpoint
435 GetBreakpointAtIndex (uint32_t idx) const;
436
437 bool
438 BreakpointDelete (break_id_t break_id);
439
440 lldb::SBBreakpoint
441 FindBreakpointByID (break_id_t break_id);
442
443 bool
444 EnableAllBreakpoints ();
445
446 bool
447 DisableAllBreakpoints ();
448
449 bool
450 DeleteAllBreakpoints ();
451
Johnny Chen092bd152011-09-27 01:19:20 +0000452 uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000453 GetNumWatchpoints () const;
454
455 lldb::SBWatchpoint
456 GetWatchpointAtIndex (uint32_t idx) const;
457
Johnny Chen092bd152011-09-27 01:19:20 +0000458 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000459 DeleteWatchpoint (lldb::watch_id_t watch_id);
460
461 lldb::SBWatchpoint
462 FindWatchpointByID (lldb::watch_id_t watch_id);
463
Johnny Chen092bd152011-09-27 01:19:20 +0000464 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000465 EnableAllWatchpoints ();
466
Johnny Chen092bd152011-09-27 01:19:20 +0000467 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000468 DisableAllWatchpoints ();
469
Johnny Chen092bd152011-09-27 01:19:20 +0000470 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000471 DeleteAllWatchpoints ();
472
473 lldb::SBWatchpoint
474 WatchAddress (lldb::addr_t addr,
475 size_t size,
476 bool read,
477 bool write);
478
Johnny Chen092bd152011-09-27 01:19:20 +0000479
Johnny Chenebd63b22011-07-16 21:15:39 +0000480 lldb::SBBroadcaster
481 GetBroadcaster () const;
Sean Callananef1f6902011-12-14 23:49:37 +0000482
483 lldb::SBInstructionList
484 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
485
Johnny Chenebd63b22011-07-16 21:15:39 +0000486 bool
Greg Clayton96154be2011-11-13 06:57:31 +0000487 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
Greg Clayton1b925202012-01-29 06:07:39 +0000488
489 %pythoncode %{
Greg Claytonb302dff2012-02-01 08:09:32 +0000490 class modules_access(object):
491 '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.'''
492 def __init__(self, sbtarget):
493 self.sbtarget = sbtarget
494
495 def __len__(self):
496 if self.sbtarget:
497 return self.sbtarget.GetNumModules()
498 return 0
499
500 def __getitem__(self, key):
501 num_modules = self.sbtarget.GetNumModules()
502 if type(key) is int:
503 if key < num_modules:
504 return self.sbtarget.GetModuleAtIndex(key)
505 elif type(key) is str:
506 if key.find('/') == -1:
507 for idx in range(num_modules):
508 module = self.sbtarget.GetModuleAtIndex(idx)
509 if module.file.basename == key:
510 return module
511 else:
512 for idx in range(num_modules):
513 module = self.sbtarget.GetModuleAtIndex(idx)
514 if module.file.fullpath == key:
515 return module
516 # See if the string is a UUID
517 the_uuid = uuid.UUID(key)
518 if the_uuid:
519 for idx in range(num_modules):
520 module = self.sbtarget.GetModuleAtIndex(idx)
521 if module.uuid == the_uuid:
522 return module
523 elif type(key) is uuid.UUID:
524 for idx in range(num_modules):
525 module = self.sbtarget.GetModuleAtIndex(idx)
526 if module.uuid == key:
527 return module
528 elif type(key) is re.SRE_Pattern:
529 matching_modules = []
530 for idx in range(num_modules):
531 module = self.sbtarget.GetModuleAtIndex(idx)
532 re_match = key.search(module.path.fullpath)
533 if re_match:
534 matching_modules.append(module)
535 return matching_modules
536 else:
537 print "error: unsupported item type: %s" % type(key)
538 return None
539
540 def get_modules_access_object(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000541 '''An accessor function that returns a modules_access() object which allows lazy module access from a lldb.SBTarget object.'''
Greg Claytonb302dff2012-02-01 08:09:32 +0000542 return self.modules_access (self)
543
544 def get_modules_array(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000545 '''An accessor function that returns a list() that contains all modules in a lldb.SBTarget object.'''
Greg Claytonb302dff2012-02-01 08:09:32 +0000546 modules = []
547 for idx in range(self.GetNumModules()):
548 modules.append(self.GetModuleAtIndex(idx))
549 return modules
550
551 __swig_getmethods__["modules"] = get_modules_array
552 if _newclass: x = property(get_modules_array, None)
553
554 __swig_getmethods__["module"] = get_modules_access_object
555 if _newclass: x = property(get_modules_access_object, None)
556
Greg Clayton1b925202012-01-29 06:07:39 +0000557 __swig_getmethods__["process"] = GetProcess
558 if _newclass: x = property(GetProcess, None)
559
560 __swig_getmethods__["executable"] = GetExecutable
561 if _newclass: x = property(GetExecutable, None)
562
563 __swig_getmethods__["debugger"] = GetDebugger
564 if _newclass: x = property(GetDebugger, None)
565
Greg Clayton1b925202012-01-29 06:07:39 +0000566 __swig_getmethods__["num_breakpoints"] = GetNumBreakpoints
567 if _newclass: x = property(GetNumBreakpoints, None)
568
569 __swig_getmethods__["num_watchpoints"] = GetNumWatchpoints
570 if _newclass: x = property(GetNumWatchpoints, None)
571
572 __swig_getmethods__["broadcaster"] = GetBroadcaster
573 if _newclass: x = property(GetBroadcaster, None)
574
575 __swig_getmethods__["byte_order"] = GetByteOrder
576 if _newclass: x = property(GetByteOrder, None)
577
578 __swig_getmethods__["addr_size"] = GetAddressByteSize
579 if _newclass: x = property(GetAddressByteSize, None)
580
581 __swig_getmethods__["triple"] = GetTriple
582 if _newclass: x = property(GetTriple, None)
583 %}
584
Johnny Chenebd63b22011-07-16 21:15:39 +0000585};
586
587} // namespace lldb