blob: a8e3395093c9eb622b2eeaeecbdd308cbd8a04d0 [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
Jim Ingham5a15e692012-02-16 06:50:00 +000075 static const char *
76 GetBroadcasterClassName ();
77
Johnny Chenebd63b22011-07-16 21:15:39 +000078 bool
79 IsValid() const;
80
81 lldb::SBProcess
82 GetProcess ();
83
84 %feature("docstring", "
85 //------------------------------------------------------------------
86 /// Launch a new process.
87 ///
88 /// Launch a new process by spawning a new process using the
89 /// target object's executable module's file as the file to launch.
90 /// Arguments are given in \a argv, and the environment variables
91 /// are in \a envp. Standard input and output files can be
92 /// optionally re-directed to \a stdin_path, \a stdout_path, and
93 /// \a stderr_path.
94 ///
95 /// @param[in] listener
96 /// An optional listener that will receive all process events.
97 /// If \a listener is valid then \a listener will listen to all
98 /// process events. If not valid, then this target's debugger
99 /// (SBTarget::GetDebugger()) will listen to all process events.
100 ///
101 /// @param[in] argv
102 /// The argument array.
103 ///
104 /// @param[in] envp
105 /// The environment array.
106 ///
107 /// @param[in] launch_flags
108 /// Flags to modify the launch (@see lldb::LaunchFlags)
109 ///
110 /// @param[in] stdin_path
111 /// The path to use when re-directing the STDIN of the new
112 /// process. If all stdXX_path arguments are NULL, a pseudo
113 /// terminal will be used.
114 ///
115 /// @param[in] stdout_path
116 /// The path to use when re-directing the STDOUT of the new
117 /// process. If all stdXX_path arguments are NULL, a pseudo
118 /// terminal will be used.
119 ///
120 /// @param[in] stderr_path
121 /// The path to use when re-directing the STDERR of the new
122 /// process. If all stdXX_path arguments are NULL, a pseudo
123 /// terminal will be used.
124 ///
125 /// @param[in] working_directory
126 /// The working directory to have the child process run in
127 ///
128 /// @param[in] launch_flags
129 /// Some launch options specified by logical OR'ing
130 /// lldb::LaunchFlags enumeration values together.
131 ///
132 /// @param[in] stop_at_endtry
133 /// If false do not stop the inferior at the entry point.
134 ///
135 /// @param[out]
136 /// An error object. Contains the reason if there is some failure.
137 ///
138 /// @return
139 /// A process object for the newly created process.
140 //------------------------------------------------------------------
141
142 For example,
143
144 process = target.Launch(self.dbg.GetListener(), None, None,
145 None, '/tmp/stdout.txt', None,
146 None, 0, False, error)
147
148 launches a new process by passing nothing for both the args and the envs
149 and redirect the standard output of the inferior to the /tmp/stdout.txt
150 file. It does not specify a working directory so that the debug server
151 will use its idea of what the current working directory is for the
152 inferior. Also, we ask the debugger not to stop the inferior at the
153 entry point. If no breakpoint is specified for the inferior, it should
154 run to completion if no user interaction is required.
155 ") Launch;
156 lldb::SBProcess
157 Launch (SBListener &listener,
158 char const **argv,
159 char const **envp,
160 const char *stdin_path,
161 const char *stdout_path,
162 const char *stderr_path,
163 const char *working_directory,
164 uint32_t launch_flags, // See LaunchFlags
165 bool stop_at_entry,
166 lldb::SBError& error);
167
168 %feature("docstring", "
169 //------------------------------------------------------------------
170 /// Launch a new process with sensible defaults.
171 ///
172 /// @param[in] argv
173 /// The argument array.
174 ///
175 /// @param[in] envp
176 /// The environment array.
177 ///
178 /// @param[in] working_directory
179 /// The working directory to have the child process run in
180 ///
181 /// Default: listener
182 /// Set to the target's debugger (SBTarget::GetDebugger())
183 ///
184 /// Default: launch_flags
185 /// Empty launch flags
186 ///
187 /// Default: stdin_path
188 /// Default: stdout_path
189 /// Default: stderr_path
190 /// A pseudo terminal will be used.
191 ///
192 /// @return
193 /// A process object for the newly created process.
194 //------------------------------------------------------------------
195
196 For example,
197
198 process = target.LaunchSimple(['X', 'Y', 'Z'], None, os.getcwd())
199
200 launches a new process by passing 'X', 'Y', 'Z' as the args to the
201 executable.
202 ") LaunchSimple;
203 lldb::SBProcess
204 LaunchSimple (const char **argv,
205 const char **envp,
206 const char *working_directory);
207
208 %feature("docstring", "
209 //------------------------------------------------------------------
210 /// Attach to process with pid.
211 ///
212 /// @param[in] listener
213 /// An optional listener that will receive all process events.
214 /// If \a listener is valid then \a listener will listen to all
215 /// process events. If not valid, then this target's debugger
216 /// (SBTarget::GetDebugger()) will listen to all process events.
217 ///
218 /// @param[in] pid
219 /// The process ID to attach to.
220 ///
221 /// @param[out]
222 /// An error explaining what went wrong if attach fails.
223 ///
224 /// @return
225 /// A process object for the attached process.
226 //------------------------------------------------------------------
227 ") AttachToProcessWithID;
228 lldb::SBProcess
229 AttachToProcessWithID (SBListener &listener,
230 lldb::pid_t pid,
231 lldb::SBError& error);
232
233 %feature("docstring", "
234 //------------------------------------------------------------------
235 /// Attach to process with name.
236 ///
237 /// @param[in] listener
238 /// An optional listener that will receive all process events.
239 /// If \a listener is valid then \a listener will listen to all
240 /// process events. If not valid, then this target's debugger
241 /// (SBTarget::GetDebugger()) will listen to all process events.
242 ///
243 /// @param[in] name
244 /// Basename of process to attach to.
245 ///
246 /// @param[in] wait_for
247 /// If true wait for a new instance of 'name' to be launched.
248 ///
249 /// @param[out]
250 /// An error explaining what went wrong if attach fails.
251 ///
252 /// @return
253 /// A process object for the attached process.
254 //------------------------------------------------------------------
255 ") AttachToProcessWithName;
256 lldb::SBProcess
257 AttachToProcessWithName (SBListener &listener,
258 const char *name,
259 bool wait_for,
260 lldb::SBError& error);
261
262 %feature("docstring", "
263 //------------------------------------------------------------------
264 /// Connect to a remote debug server with url.
265 ///
266 /// @param[in] listener
267 /// An optional listener that will receive all process events.
268 /// If \a listener is valid then \a listener will listen to all
269 /// process events. If not valid, then this target's debugger
270 /// (SBTarget::GetDebugger()) will listen to all process events.
271 ///
272 /// @param[in] url
273 /// The url to connect to, e.g., 'connect://localhost:12345'.
274 ///
275 /// @param[in] plugin_name
276 /// The plugin name to be used; can be NULL.
277 ///
278 /// @param[out]
279 /// An error explaining what went wrong if the connect fails.
280 ///
281 /// @return
282 /// A process object for the connected process.
283 //------------------------------------------------------------------
284 ") ConnectRemote;
285 lldb::SBProcess
286 ConnectRemote (SBListener &listener,
287 const char *url,
288 const char *plugin_name,
289 SBError& error);
290
291 lldb::SBFileSpec
292 GetExecutable ();
293
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000294 bool
295 AddModule (lldb::SBModule &module);
296
297 lldb::SBModule
298 AddModule (const char *path,
299 const char *triple,
300 const char *uuid);
301
Johnny Chenebd63b22011-07-16 21:15:39 +0000302 uint32_t
303 GetNumModules () const;
304
305 lldb::SBModule
306 GetModuleAtIndex (uint32_t idx);
307
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000308 bool
309 RemoveModule (lldb::SBModule module);
310
Johnny Chenebd63b22011-07-16 21:15:39 +0000311 lldb::SBDebugger
312 GetDebugger() const;
313
314 lldb::SBModule
315 FindModule (const lldb::SBFileSpec &file_spec);
316
Greg Clayton1b925202012-01-29 06:07:39 +0000317 lldb::ByteOrder
318 GetByteOrder ();
319
320 uint32_t
321 GetAddressByteSize();
322
323 const char *
324 GetTriple ();
325
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000326 lldb::SBError
327 SetSectionLoadAddress (lldb::SBSection section,
328 lldb::addr_t section_base_addr);
329
330 lldb::SBError
331 ClearSectionLoadAddress (lldb::SBSection section);
332
333 lldb::SBError
334 SetModuleLoadAddress (lldb::SBModule module,
335 int64_t sections_offset);
336
337 lldb::SBError
338 ClearModuleLoadAddress (lldb::SBModule module);
339
Johnny Chenebd63b22011-07-16 21:15:39 +0000340 %feature("docstring", "
341 //------------------------------------------------------------------
342 /// Find functions by name.
343 ///
344 /// @param[in] name
345 /// The name of the function we are looking for.
346 ///
347 /// @param[in] name_type_mask
348 /// A logical OR of one or more FunctionNameType enum bits that
349 /// indicate what kind of names should be used when doing the
350 /// lookup. Bits include fully qualified names, base names,
351 /// C++ methods, or ObjC selectors.
352 /// See FunctionNameType for more details.
353 ///
Johnny Chenebd63b22011-07-16 21:15:39 +0000354 /// @return
Greg Clayton7dd5c512012-02-06 01:44:54 +0000355 /// A lldb::SBSymbolContextList that gets filled in with all of
356 /// the symbol contexts for all the matches.
Johnny Chenebd63b22011-07-16 21:15:39 +0000357 //------------------------------------------------------------------
358 ") FindFunctions;
Greg Clayton7dd5c512012-02-06 01:44:54 +0000359 lldb::SBSymbolContextList
Johnny Chenebd63b22011-07-16 21:15:39 +0000360 FindFunctions (const char *name,
Greg Clayton7dd5c512012-02-06 01:44:54 +0000361 uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
Enrico Granata979e20d2011-07-29 19:53:35 +0000362
363 lldb::SBType
364 FindFirstType (const char* type);
365
366 lldb::SBTypeList
367 FindTypes (const char* type);
Johnny Chenebd63b22011-07-16 21:15:39 +0000368
Jim Inghamcc637462011-09-13 00:29:56 +0000369 lldb::SBSourceManager
370 GetSourceManager ();
371
Johnny Chenebd63b22011-07-16 21:15:39 +0000372 %feature("docstring", "
373 //------------------------------------------------------------------
374 /// Find global and static variables by name.
375 ///
376 /// @param[in] name
377 /// The name of the global or static variable we are looking
378 /// for.
379 ///
380 /// @param[in] max_matches
381 /// Allow the number of matches to be limited to \a max_matches.
382 ///
383 /// @return
384 /// A list of matched variables in an SBValueList.
385 //------------------------------------------------------------------
386 ") FindGlobalVariables;
387 lldb::SBValueList
388 FindGlobalVariables (const char *name,
389 uint32_t max_matches);
390
391 void
392 Clear ();
393
Greg Claytona3955062011-07-22 16:46:35 +0000394 lldb::SBAddress
395 ResolveLoadAddress (lldb::addr_t vm_addr);
Johnny Chenebd63b22011-07-16 21:15:39 +0000396
397 SBSymbolContext
398 ResolveSymbolContextForAddress (const SBAddress& addr,
399 uint32_t resolve_scope);
400
401 lldb::SBBreakpoint
402 BreakpointCreateByLocation (const char *file, uint32_t line);
403
404 lldb::SBBreakpoint
405 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
406
407 lldb::SBBreakpoint
408 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
409
410 lldb::SBBreakpoint
Jim Ingham1fb8a2d2011-10-11 01:18:55 +0000411 BreakpointCreateByName (const char *symbol_name,
412 uint32_t func_name_type, // Logical OR one or more FunctionNameType enum bits
413 const SBFileSpecList &module_list,
414 const SBFileSpecList &comp_unit_list);
415
416 lldb::SBBreakpoint
Johnny Chenebd63b22011-07-16 21:15:39 +0000417 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
418
419 lldb::SBBreakpoint
Jim Ingham03c8ee52011-09-21 01:17:13 +0000420 BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name = NULL);
421
422 lldb::SBBreakpoint
Johnny Chenebd63b22011-07-16 21:15:39 +0000423 BreakpointCreateByAddress (addr_t address);
424
425 uint32_t
426 GetNumBreakpoints () const;
427
428 lldb::SBBreakpoint
429 GetBreakpointAtIndex (uint32_t idx) const;
430
431 bool
432 BreakpointDelete (break_id_t break_id);
433
434 lldb::SBBreakpoint
435 FindBreakpointByID (break_id_t break_id);
436
437 bool
438 EnableAllBreakpoints ();
439
440 bool
441 DisableAllBreakpoints ();
442
443 bool
444 DeleteAllBreakpoints ();
445
Johnny Chen092bd152011-09-27 01:19:20 +0000446 uint32_t
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000447 GetNumWatchpoints () const;
448
449 lldb::SBWatchpoint
450 GetWatchpointAtIndex (uint32_t idx) const;
451
Johnny Chen092bd152011-09-27 01:19:20 +0000452 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000453 DeleteWatchpoint (lldb::watch_id_t watch_id);
454
455 lldb::SBWatchpoint
456 FindWatchpointByID (lldb::watch_id_t watch_id);
457
Johnny Chen092bd152011-09-27 01:19:20 +0000458 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000459 EnableAllWatchpoints ();
460
Johnny Chen092bd152011-09-27 01:19:20 +0000461 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000462 DisableAllWatchpoints ();
463
Johnny Chen092bd152011-09-27 01:19:20 +0000464 bool
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000465 DeleteAllWatchpoints ();
466
467 lldb::SBWatchpoint
468 WatchAddress (lldb::addr_t addr,
469 size_t size,
470 bool read,
471 bool write);
472
Johnny Chen092bd152011-09-27 01:19:20 +0000473
Johnny Chenebd63b22011-07-16 21:15:39 +0000474 lldb::SBBroadcaster
475 GetBroadcaster () const;
Sean Callananef1f6902011-12-14 23:49:37 +0000476
477 lldb::SBInstructionList
478 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
479
Johnny Chenebd63b22011-07-16 21:15:39 +0000480 bool
Greg Clayton96154be2011-11-13 06:57:31 +0000481 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
Greg Clayton1b925202012-01-29 06:07:39 +0000482
483 %pythoncode %{
Greg Claytonb302dff2012-02-01 08:09:32 +0000484 class modules_access(object):
485 '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.'''
486 def __init__(self, sbtarget):
487 self.sbtarget = sbtarget
488
489 def __len__(self):
490 if self.sbtarget:
491 return self.sbtarget.GetNumModules()
492 return 0
493
494 def __getitem__(self, key):
495 num_modules = self.sbtarget.GetNumModules()
496 if type(key) is int:
497 if key < num_modules:
498 return self.sbtarget.GetModuleAtIndex(key)
499 elif type(key) is str:
500 if key.find('/') == -1:
501 for idx in range(num_modules):
502 module = self.sbtarget.GetModuleAtIndex(idx)
503 if module.file.basename == key:
504 return module
505 else:
506 for idx in range(num_modules):
507 module = self.sbtarget.GetModuleAtIndex(idx)
508 if module.file.fullpath == key:
509 return module
510 # See if the string is a UUID
511 the_uuid = uuid.UUID(key)
512 if the_uuid:
513 for idx in range(num_modules):
514 module = self.sbtarget.GetModuleAtIndex(idx)
515 if module.uuid == the_uuid:
516 return module
517 elif type(key) is uuid.UUID:
518 for idx in range(num_modules):
519 module = self.sbtarget.GetModuleAtIndex(idx)
520 if module.uuid == key:
521 return module
522 elif type(key) is re.SRE_Pattern:
523 matching_modules = []
524 for idx in range(num_modules):
525 module = self.sbtarget.GetModuleAtIndex(idx)
526 re_match = key.search(module.path.fullpath)
527 if re_match:
528 matching_modules.append(module)
529 return matching_modules
530 else:
531 print "error: unsupported item type: %s" % type(key)
532 return None
533
534 def get_modules_access_object(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000535 '''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 +0000536 return self.modules_access (self)
537
538 def get_modules_array(self):
Greg Claytonb6a5ba62012-02-03 03:22:53 +0000539 '''An accessor function that returns a list() that contains all modules in a lldb.SBTarget object.'''
Greg Claytonb302dff2012-02-01 08:09:32 +0000540 modules = []
541 for idx in range(self.GetNumModules()):
542 modules.append(self.GetModuleAtIndex(idx))
543 return modules
544
545 __swig_getmethods__["modules"] = get_modules_array
546 if _newclass: x = property(get_modules_array, None)
547
548 __swig_getmethods__["module"] = get_modules_access_object
549 if _newclass: x = property(get_modules_access_object, None)
550
Greg Clayton1b925202012-01-29 06:07:39 +0000551 __swig_getmethods__["process"] = GetProcess
552 if _newclass: x = property(GetProcess, None)
553
554 __swig_getmethods__["executable"] = GetExecutable
555 if _newclass: x = property(GetExecutable, None)
556
557 __swig_getmethods__["debugger"] = GetDebugger
558 if _newclass: x = property(GetDebugger, None)
559
Greg Clayton1b925202012-01-29 06:07:39 +0000560 __swig_getmethods__["num_breakpoints"] = GetNumBreakpoints
561 if _newclass: x = property(GetNumBreakpoints, None)
562
563 __swig_getmethods__["num_watchpoints"] = GetNumWatchpoints
564 if _newclass: x = property(GetNumWatchpoints, None)
565
566 __swig_getmethods__["broadcaster"] = GetBroadcaster
567 if _newclass: x = property(GetBroadcaster, None)
568
569 __swig_getmethods__["byte_order"] = GetByteOrder
570 if _newclass: x = property(GetByteOrder, None)
571
572 __swig_getmethods__["addr_size"] = GetAddressByteSize
573 if _newclass: x = property(GetAddressByteSize, None)
574
575 __swig_getmethods__["triple"] = GetTriple
576 if _newclass: x = property(GetTriple, None)
577 %}
578
Johnny Chenebd63b22011-07-16 21:15:39 +0000579};
580
581} // namespace lldb