blob: 58a546b54c79f140d1f2897d7b968d9975e75ea1 [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 ///
Johnny Chenebd63b22011-07-16 21:15:39 +0000351 /// @return
Greg Clayton7dd5c512012-02-06 01:44:54 +0000352 /// A lldb::SBSymbolContextList that gets filled in with all of
353 /// the symbol contexts for all the matches.
Johnny Chenebd63b22011-07-16 21:15:39 +0000354 //------------------------------------------------------------------
355 ") FindFunctions;
Greg Clayton7dd5c512012-02-06 01:44:54 +0000356 lldb::SBSymbolContextList
Johnny Chenebd63b22011-07-16 21:15:39 +0000357 FindFunctions (const char *name,
Greg Clayton7dd5c512012-02-06 01:44:54 +0000358 uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
Enrico Granata979e20d2011-07-29 19:53:35 +0000359
360 lldb::SBType
361 FindFirstType (const char* type);
362
363 lldb::SBTypeList
364 FindTypes (const char* type);
Johnny Chenebd63b22011-07-16 21:15:39 +0000365
Jim Inghamcc637462011-09-13 00:29:56 +0000366 lldb::SBSourceManager
367 GetSourceManager ();
368
Johnny Chenebd63b22011-07-16 21:15:39 +0000369 %feature("docstring", "
370 //------------------------------------------------------------------
371 /// Find global and static variables by name.
372 ///
373 /// @param[in] name
374 /// The name of the global or static variable we are looking
375 /// for.
376 ///
377 /// @param[in] max_matches
378 /// Allow the number of matches to be limited to \a max_matches.
379 ///
380 /// @return
381 /// A list of matched variables in an SBValueList.
382 //------------------------------------------------------------------
383 ") FindGlobalVariables;
384 lldb::SBValueList
385 FindGlobalVariables (const char *name,
386 uint32_t max_matches);
387
388 void
389 Clear ();
390
Greg Claytona3955062011-07-22 16:46:35 +0000391 lldb::SBAddress
392 ResolveLoadAddress (lldb::addr_t vm_addr);
Johnny Chenebd63b22011-07-16 21:15:39 +0000393
394 SBSymbolContext
395 ResolveSymbolContextForAddress (const SBAddress& addr,
396 uint32_t resolve_scope);
397
398 lldb::SBBreakpoint
399 BreakpointCreateByLocation (const char *file, uint32_t line);
400
401 lldb::SBBreakpoint
402 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
403
404 lldb::SBBreakpoint
405 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
406
407 lldb::SBBreakpoint
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000408 BreakpointCreateByName (const char *symbol_name,
409 uint32_t func_name_type, // Logical OR one or more FunctionNameType enum bits
410 const SBFileSpecList &module_list,
411 const SBFileSpecList &comp_unit_list);
412
413 lldb::SBBreakpoint
Johnny Chenebd63b22011-07-16 21:15:39 +0000414 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
415
416 lldb::SBBreakpoint
Jim Ingham03c8ee52011-09-21 01:17:13 +0000417 BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name = NULL);
418
419 lldb::SBBreakpoint
Johnny Chenebd63b22011-07-16 21:15:39 +0000420 BreakpointCreateByAddress (addr_t address);
421
422 uint32_t
423 GetNumBreakpoints () const;
424
425 lldb::SBBreakpoint
426 GetBreakpointAtIndex (uint32_t idx) const;
427
428 bool
429 BreakpointDelete (break_id_t break_id);
430
431 lldb::SBBreakpoint
432 FindBreakpointByID (break_id_t break_id);
433
434 bool
435 EnableAllBreakpoints ();
436
437 bool
438 DisableAllBreakpoints ();
439
440 bool
441 DeleteAllBreakpoints ();
442
Johnny Chen092bd152011-09-27 01:19:20 +0000443 uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000444 GetNumWatchpoints () const;
445
446 lldb::SBWatchpoint
447 GetWatchpointAtIndex (uint32_t idx) const;
448
Johnny Chen092bd152011-09-27 01:19:20 +0000449 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000450 DeleteWatchpoint (lldb::watch_id_t watch_id);
451
452 lldb::SBWatchpoint
453 FindWatchpointByID (lldb::watch_id_t watch_id);
454
Johnny Chen092bd152011-09-27 01:19:20 +0000455 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000456 EnableAllWatchpoints ();
457
Johnny Chen092bd152011-09-27 01:19:20 +0000458 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000459 DisableAllWatchpoints ();
460
Johnny Chen092bd152011-09-27 01:19:20 +0000461 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000462 DeleteAllWatchpoints ();
463
464 lldb::SBWatchpoint
465 WatchAddress (lldb::addr_t addr,
466 size_t size,
467 bool read,
468 bool write);
469
Johnny Chen092bd152011-09-27 01:19:20 +0000470
Johnny Chenebd63b22011-07-16 21:15:39 +0000471 lldb::SBBroadcaster
472 GetBroadcaster () const;
Sean Callananef1f6902011-12-14 23:49:37 +0000473
474 lldb::SBInstructionList
475 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
476
Johnny Chenebd63b22011-07-16 21:15:39 +0000477 bool
Greg Clayton96154be2011-11-13 06:57:31 +0000478 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
Greg Clayton1b925202012-01-29 06:07:39 +0000479
480 %pythoncode %{
Greg Claytonb302dff2012-02-01 08:09:32 +0000481 class modules_access(object):
482 '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.'''
483 def __init__(self, sbtarget):
484 self.sbtarget = sbtarget
485
486 def __len__(self):
487 if self.sbtarget:
488 return self.sbtarget.GetNumModules()
489 return 0
490
491 def __getitem__(self, key):
492 num_modules = self.sbtarget.GetNumModules()
493 if type(key) is int:
494 if key < num_modules:
495 return self.sbtarget.GetModuleAtIndex(key)
496 elif type(key) is str:
497 if key.find('/') == -1:
498 for idx in range(num_modules):
499 module = self.sbtarget.GetModuleAtIndex(idx)
500 if module.file.basename == key:
501 return module
502 else:
503 for idx in range(num_modules):
504 module = self.sbtarget.GetModuleAtIndex(idx)
505 if module.file.fullpath == key:
506 return module
507 # See if the string is a UUID
508 the_uuid = uuid.UUID(key)
509 if the_uuid:
510 for idx in range(num_modules):
511 module = self.sbtarget.GetModuleAtIndex(idx)
512 if module.uuid == the_uuid:
513 return module
514 elif type(key) is uuid.UUID:
515 for idx in range(num_modules):
516 module = self.sbtarget.GetModuleAtIndex(idx)
517 if module.uuid == key:
518 return module
519 elif type(key) is re.SRE_Pattern:
520 matching_modules = []
521 for idx in range(num_modules):
522 module = self.sbtarget.GetModuleAtIndex(idx)
523 re_match = key.search(module.path.fullpath)
524 if re_match:
525 matching_modules.append(module)
526 return matching_modules
527 else:
528 print "error: unsupported item type: %s" % type(key)
529 return None
530
531 def get_modules_access_object(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000532 '''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 +0000533 return self.modules_access (self)
534
535 def get_modules_array(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000536 '''An accessor function that returns a list() that contains all modules in a lldb.SBTarget object.'''
Greg Claytonb302dff2012-02-01 08:09:32 +0000537 modules = []
538 for idx in range(self.GetNumModules()):
539 modules.append(self.GetModuleAtIndex(idx))
540 return modules
541
542 __swig_getmethods__["modules"] = get_modules_array
543 if _newclass: x = property(get_modules_array, None)
544
545 __swig_getmethods__["module"] = get_modules_access_object
546 if _newclass: x = property(get_modules_access_object, None)
547
Greg Clayton1b925202012-01-29 06:07:39 +0000548 __swig_getmethods__["process"] = GetProcess
549 if _newclass: x = property(GetProcess, None)
550
551 __swig_getmethods__["executable"] = GetExecutable
552 if _newclass: x = property(GetExecutable, None)
553
554 __swig_getmethods__["debugger"] = GetDebugger
555 if _newclass: x = property(GetDebugger, None)
556
Greg Clayton1b925202012-01-29 06:07:39 +0000557 __swig_getmethods__["num_breakpoints"] = GetNumBreakpoints
558 if _newclass: x = property(GetNumBreakpoints, None)
559
560 __swig_getmethods__["num_watchpoints"] = GetNumWatchpoints
561 if _newclass: x = property(GetNumWatchpoints, None)
562
563 __swig_getmethods__["broadcaster"] = GetBroadcaster
564 if _newclass: x = property(GetBroadcaster, None)
565
566 __swig_getmethods__["byte_order"] = GetByteOrder
567 if _newclass: x = property(GetByteOrder, None)
568
569 __swig_getmethods__["addr_size"] = GetAddressByteSize
570 if _newclass: x = property(GetAddressByteSize, None)
571
572 __swig_getmethods__["triple"] = GetTriple
573 if _newclass: x = property(GetTriple, None)
574 %}
575
Johnny Chenebd63b22011-07-16 21:15:39 +0000576};
577
578} // namespace lldb