[Lldb-commits] [lldb] 068e179 - [lldb][swig] Support SBFileSpec::GetPath (#162964)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 13 11:24:16 PDT 2025
Author: Wanyi
Date: 2025-10-13T12:24:12-06:00
New Revision: 068e1796bac5229210f57862862e8995d4b6f009
URL: https://github.com/llvm/llvm-project/commit/068e1796bac5229210f57862862e8995d4b6f009
DIFF: https://github.com/llvm/llvm-project/commit/068e1796bac5229210f57862862e8995d4b6f009.diff
LOG: [lldb][swig] Support SBFileSpec::GetPath (#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
```
Added:
Modified:
lldb/bindings/python/python-typemaps.swig
lldb/test/API/python_api/default-constructor/sb_filespec.py
Removed:
################################################################################
diff --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig
index 88b6cd9ef6b6e..715914fe745f8 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -233,6 +233,11 @@ AND call SWIG_fail at the same time, because it will result in a double free.
}
+// For lldb::SBFileSpec::GetPath
+%typemap(in) (char *dst_path, size_t dst_len) = (char *dst_or_null, size_t dst_len);
+%typemap(argout) (char *dst_path, size_t dst_len) = (char *dst_or_null, size_t dst_len);
+
+
// typemap for an outgoing buffer
// See also SBEvent::SBEvent(uint32_t event, const char *cstr, uint32_t cstr_len).
// Ditto for SBProcess::PutSTDIN(const char *src, size_t src_len).
diff --git a/lldb/test/API/python_api/default-constructor/sb_filespec.py b/lldb/test/API/python_api/default-constructor/sb_filespec.py
index 4ab5c49c37eb5..5dd78b1ace98f 100644
--- a/lldb/test/API/python_api/default-constructor/sb_filespec.py
+++ b/lldb/test/API/python_api/default-constructor/sb_filespec.py
@@ -10,5 +10,5 @@ def fuzz_obj(obj):
obj.ResolveExecutableLocation()
obj.GetFilename()
obj.GetDirectory()
- obj.GetPath(None, 0)
+ obj.GetPath(1)
obj.GetDescription(lldb.SBStream())
More information about the lldb-commits
mailing list