8000 [lldb][swig] Support SBFileSpec::GetPath by kusmour · Pull Request #162964 · llvm/llvm-project · GitHub
[go: up one dir, main page]

Skip to content

Conversation

kusmour
Copy link
Contributor
@kusmour kusmour commented Oct 11, 2025

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

@kusmour kusmour requested a review from JDevlieghere as a code owner October 11, 2025 03:46
@llvmbot llvmbot added the lldb label Oct 11, 2025
@kusmour kusmour requested review from aperez and clayborg October 11, 2025 03:46
@llvmbot
Copy link
Member
llvmbot commented Oct 11, 2025

@llvm/pr-subscribers-lldb

Author: Wanyi (kusmour)

Changes

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.
&gt;&gt;&gt; debugger = lldb.SBDebugger.Create()
&gt;&gt;&gt; debugger.SetAsync (False)
&gt;&gt;&gt; target = debugger.CreateTarget("~/tmp/hello")
&gt;&gt;&gt; target.IsValid()
True
&gt;&gt;&gt; breakpoint = target.BreakpointCreateByName('main', 'hello')
&gt;&gt;&gt; breakpoint.GetNumLocations()
1
&gt;&gt;&gt; process = target.LaunchSimple (None, None, os.getcwd())
&gt;&gt;&gt; process.IsValid()
True
&gt;&gt;&gt; thread = process.GetThreadAtIndex(0)
&gt;&gt;&gt; frame = thread.GetFrameAtIndex(0)
&gt;&gt;&gt; line = frame.GetLineEntry()

# Important line below
&gt;&gt;&gt; file = line.GetFileSpec().GetPath(1024)
# Important line above

&gt;&gt;&gt; print(file)
/home/wanyi/tmp/main.cpp

Before this change

$ lldb
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
&gt;&gt;&gt; debugger = lldb.SBDebugger.Create()
&gt;&gt;&gt; debugger.SetAsync (False)
&gt;&gt;&gt; target = debugger.CreateTarget("~/tmp/hello")
&gt;&gt;&gt; target.IsValid()
True
&gt;&gt;&gt; breakpoint = target.BreakpointCreateByName('main', 'hello')
&gt;&gt;&gt; breakpoint.GetNumLocations()
1
&gt;&gt;&gt; process = target.LaunchSimple (None, None, os.getcwd())
&gt;&gt;&gt; process.IsValid()
True
&gt;&gt;&gt; thread = process.GetThreadAtIndex(0)
&gt;&gt;&gt; frame = thread.GetFrameAtIndex(0)
&gt;&gt;&gt; line = frame.GetLineEntry()
&gt;&gt;&gt; file = line.GetFileSpec().GetPath(1024)
Traceback (most recent call last):
  File "&lt;console&gt;", line 1, in &lt;module&gt;
TypeError: SBFileSpec.GetPath() missing 1 required positional argument: 'dst_len'
&gt;&gt;&gt; print(file)
Traceback (most recent call last):
  File "&lt;console&gt;", line 1, in &lt;module&gt;
NameError: name 'file' is not defined

Full diff: https://github.com/llvm/llvm-project/pull/162964.diff

1 Files Affected:

  • (modified) lldb/bindings/python/python-typemaps.swig (+5)
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).

@kusmour kusmour force-pushed the swig_for_SBFileSpec_GetPath branch from be744ba to 40e9056 Compare October 11, 2025 03:52
@kusmour kusmour force-pushed the swig_for_SBFileSpec_GetPath branch from 40e9056 to 4f0b1a8 Compare October 11, 2025 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0