Skip to content

[lldb][scripts] Fix bugs in framework fix script #145961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

chelcassanova
Copy link
Contributor

The script used to fix up LLDB's header for use in the macOS framework contained 2 bugs that this commit addreses:

  1. The output contents were appended to the output file multiple times instead of only being written once.
  2. The script was not considering LLDB includes that were not from the SB API.

This commit addresses and fixes both of these bugs and updates the corresponding test to match.

@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)

Changes

The script used to fix up LLDB's header for use in the macOS framework contained 2 bugs that this commit addreses:

  1. The output contents were appended to the output file multiple times instead of only being written once.
  2. The script was not considering LLDB includes that were not from the SB API.

This commit addresses and fixes both of these bugs and updates the corresponding test to match.


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

3 Files Affected:

  • (modified) lldb/scripts/framework-header-fix.py (+2-2)
  • (modified) lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h (+1)
  • (modified) lldb/test/Shell/Scripts/TestFrameworkFixScript.test (+1)
diff --git a/lldb/scripts/framework-header-fix.py b/lldb/scripts/framework-header-fix.py
index 9528fdb7e30bd..883c56d3dddc3 100755
--- a/lldb/scripts/framework-header-fix.py
+++ b/lldb/scripts/framework-header-fix.py
@@ -20,7 +20,7 @@
 
 # Main header regexes
 INCLUDE_FILENAME_REGEX = re.compile(
-    r'#include "lldb/API/(?P<include_filename>.*){0,1}"'
+    r'#include "lldb/(API/){0,1}(?P<include_filename>.*){0,1}"'
 )
 
 # RPC header regexes
@@ -70,7 +70,7 @@ def modify_main_includes(input_file_path, output_file_path):
                     r"#include <LLDB/" + match.group("include_filename") + ">",
                     file_buffer,
                 )
-                output_file.write(file_buffer)
+            output_file.write(file_buffer)
 
 
 def remove_guards(output_file_path, unifdef_path, unifdef_guards):
diff --git a/lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h b/lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h
index fecc69687cd74..a15dd9d2a942e 100644
--- a/lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h
+++ b/lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h
@@ -6,6 +6,7 @@
 // e.g. #include "lldb/API/SBDefines.h" -> #include <LLDB/SBDefines.h>
 #include "lldb/API/SBDefines.h"
 #include "lldb/API/SBModule.h"
+#include "lldb/lldb-types.h"
 
 // Any include guards specified at the command line must be removed.
 #ifndef SWIG
diff --git a/lldb/test/Shell/Scripts/TestFrameworkFixScript.test b/lldb/test/Shell/Scripts/TestFrameworkFixScript.test
index e90c3bdfc5adb..5c48b796efda4 100644
--- a/lldb/test/Shell/Scripts/TestFrameworkFixScript.test
+++ b/lldb/test/Shell/Scripts/TestFrameworkFixScript.test
@@ -9,3 +9,4 @@ RUN: cat %t/Outputs/SBAddress.h | FileCheck %s
 # e.g. #include "lldb/API/SBDefines.h" -> #include <LLDB/SBDefines.h>
 CHECK: #include <LLDB/SBDefines.h>
 CHECK: #include <LLDB/SBModule.h>
+CHECK: #include <LLDB/lldb-types.h>

@@ -20,7 +20,7 @@

# Main header regexes
INCLUDE_FILENAME_REGEX = re.compile(
r'#include "lldb/API/(?P<include_filename>.*){0,1}"'
r'#include "lldb/(API/){0,1}(?P<include_filename>.*){0,1}"'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on regex but would it make sense to use ? here instead of {0,1}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such that we have r'#include "lldb/(API/)?(?P<include_filename>.*){0,1}"' instead of r'#include "lldb/(API/){0,1}(?P<include_filename>.*){0,1}"'. I just tried it and the test still works, updating the patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be worth updating all other instances of {0,1}

The script used to fix up LLDB's header for use in the macOS framework
contained 2 bugs that this commit addresss:

1. The output contents were appended to the output file multiple times
   instead of only being written once.
2. The script was not considering LLDB includes that were *not* from the
   SB API.

This commit address and fixes both of these bugs and updates the
corresponding test to match.
@chelcassanova chelcassanova force-pushed the fix-framework-fix-python-script branch from d45694a to 7382a6a Compare June 26, 2025 20:35
@chelcassanova chelcassanova merged commit c73e5e3 into llvm:main Jun 26, 2025
7 checks passed
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
The script used to fix up LLDB's header for use in the macOS framework
contained 2 bugs that this commit addreses:

1. The output contents were appended to the output file multiple times
instead of only being written once.
2. The script was not considering LLDB includes that were *not* from the
SB API.

This commit addresses and fixes both of these bugs and updates the
corresponding test to match.
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.

4 participants