Skip to content

Commit 068e179

Browse files
authored
[lldb][swig] Support SBFileSpec::GetPath (llvm#162964)
# Summary `SBFileSpec::GetPath(char *dst_path, size_t dst_len)` contains `char*` type argument. Need to handle this for python. Fortunately there're already similar definitions we can reuse. # Test Plan Start the freshly built lldb and run the following code ``` $ lldb (lldb) script Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D. >>> debugger = lldb.SBDebugger.Create() >>> debugger.SetAsync (False) >>> target = debugger.CreateTarget("~/tmp/hello") >>> target.IsValid() True >>> breakpoint = target.BreakpointCreateByName('main', 'hello') >>> breakpoint.GetNumLocations() 1 >>> process = target.LaunchSimple (None, None, os.getcwd()) >>> process.IsValid() True >>> thread = process.GetThreadAtIndex(0) >>> frame = thread.GetFrameAtIndex(0) >>> line = frame.GetLineEntry() # Important line below >>> file = line.GetFileSpec().GetPath(1024) # Important line above >>> print(file) /home/wanyi/tmp/main.cpp ``` ## Before this change ``` $ lldb (lldb) script Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D. >>> debugger = lldb.SBDebugger.Create() >>> debugger.SetAsync (False) >>> target = debugger.CreateTarget("~/tmp/hello") >>> target.IsValid() True >>> breakpoint = target.BreakpointCreateByName('main', 'hello') >>> breakpoint.GetNumLocations() 1 >>> process = target.LaunchSimple (None, None, os.getcwd()) >>> process.IsValid() True >>> thread = process.GetThreadAtIndex(0) >>> frame = thread.GetFrameAtIndex(0) >>> line = frame.GetLineEntry() >>> file = line.GetFileSpec().GetPath(1024) Traceback (most recent call last): File "<console>", line 1, in <module> TypeError: SBFileSpec.GetPath() missing 1 required positional argument: 'dst_len' >>> print(file) Traceback (most recent call last): File "<console>", line 1, in <module> NameError: name 'file' is not defined ```
1 parent 7905ec3 commit 068e179

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lldb/bindings/python/python-typemaps.swig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ AND call SWIG_fail at the same time, because it will result in a double free.
233233
}
234234

235235

236+
// For lldb::SBFileSpec::GetPath
237+
%typemap(in) (char *dst_path, size_t dst_len) = (char *dst_or_null, size_t dst_len);
238+
%typemap(argout) (char *dst_path, size_t dst_len) = (char *dst_or_null, size_t dst_len);
239+
240+
236241
// typemap for an outgoing buffer
237242
// See also SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len).
238243
// Ditto for SBProcess::PutSTDIN(const char *src, size_t src_len).

lldb/test/API/python_api/default-constructor/sb_filespec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ def fuzz_obj(obj):
1010
obj.ResolveExecutableLocation()
1111
obj.GetFilename()
1212
obj.GetDirectory()
13-
obj.GetPath(None, 0)
13+
obj.GetPath(1)
1414
obj.GetDescription(lldb.SBStream())

0 commit comments

Comments
 (0)