aboutsummaryrefslogtreecommitdiff
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
authorPiyush Jaiswal <piyushjais98@gmail.com>2025-09-03 17:39:32 -0700
committerGitHub <noreply@github.com>2025-09-03 17:39:32 -0700
commitdb3054a169e8452f301a637dbb2487b040fe2676 (patch)
treecc4897c03eac943172914825ef535a29443c2377 /lldb/packages/Python/lldbsuite/test
parentaa02206fcd7ff5ff04a1c04fad9d1507cece1168 (diff)
downloadllvm-db3054a169e8452f301a637dbb2487b040fe2676.zip
llvm-db3054a169e8452f301a637dbb2487b040fe2676.tar.gz
llvm-db3054a169e8452f301a637dbb2487b040fe2676.tar.bz2
[lldb-dap] Add `--no-lldbinit` as a CLI flag (#156131)
TLDR ---------- This PR adds `--no-lldbinit` as a new CLI flag to the `lldb-dap` Motivation ----------- Rcently Users reported being unable to control `.lldbinit` file sourcing when debugging through VS Code. https://github.com/llvm/llvm-project/issues/155802. VS Code extensions cannot easily inject custom parameters into the DAP initialize request. Adding `--no-lldbinit` as a CLI flag solves this problem by allowing the decision to skip `.lldbinit` files to be made at debugger startup, before any initialization requests are processed. VS Code extensions can control this behavior by specifying the flag through `debugAdapterArgs` or similar mechanisms in launch configurations. ``` { "type": <extension-type>, "request": "launch", "name": "Debug with --no-lldbinit", "program": "${workspaceFolder}/your-program", "debugAdapterArgs": ["--no-lldbinit"] } ``` Summary ---------- This PR introduces a new command-line flag `--no-lldbinit` (with alias `-x`) to `lldb-dap`. The flag prevents automatic parsing of `.lldbinit` files during debugger initialization, giving users control over whether their LLDB initialization scripts are loaded. ### Key Changes: 1. **CLI Option Definition** (`Options.td`): Added the `--no-lldbinit` flag with `-x` alias 2. **Core Implementation** (`DAP.cpp`): Added support for storing and using the no-lldbinit flag 3. **Initialization Handler** (`InitializeRequestHandler.cpp`): Modified to respect the flag during debugger initialization 4. **Main Tool** (`lldb-dap.cpp`): Added argument parsing for the new flag 5. **Test Infrastructure** (`dap_server.py & lldbdap_testcase.py`): Enhanced test framework to support additional arguments Test Plan --------- ### New Test Coverage (`TestDAP_launch.py`) **Test Method:** `test_no_lldbinit_flag()` **Test Strategy:** 1. **Setup**: Creates a temporary `.lldbinit` file with specific settings that would normally be loaded 2. **Execution**: Launches lldb-dap with the `--no-lldbinit` flag 3. **Verification**: Confirms that the settings from `.lldbinit` are NOT applied, proving the flag works correctly **Test Environment:** * Uses a temporary home directory with a custom `.lldbinit` file * Sets specific LLDB settings (`stop-disassembly-display never`, `target.x86-disassembly-flavor intel`) * Launches debug adapter with `--no-lldbinit` flag via `additional_args` parameter **Validation Approach:** * Executes `settings show stop-disassembly-display` command during initialization * Verifies the output does NOT contain "never" (which would indicate `.lldbinit` was sourced) * Confirms that initialization commands are still executed properly ### Testing Infrastructure Enhancements **File Modifications:** * `dap_server.py`: Enhanced to accept `additional_args` parameter for passing extra CLI flags * `lldbdap_testcase.py`: Updated `build_and_create_debug_adapter()` method to support additional arguments and environment variables ### Unit Test Integration **Unit Test Updates** (`DAPTest.cpp`): * Added initialization of the new flag in test setup to ensure consistent test behavior **Test Run** <img width="1759" height="1373" alt="Screenshot 2025-08-29 at 5 56 18 PM" src="https://github.com/user-attachments/assets/769b319a-5009-4ade-aff8-c5f548b38123" /> --------- Co-authored-by: Piyush Jaiswal <piyushjais@meta.com>
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py11
-rw-r--r--lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py5
2 files changed, 14 insertions, 2 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 0608ac3..66aa070 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -1490,12 +1490,17 @@ class DebugAdapterServer(DebugCommunication):
init_commands: list[str] = [],
log_file: Optional[TextIO] = None,
env: Optional[dict[str, str]] = None,
+ additional_args: list[str] = [],
):
self.process = None
self.connection = None
if executable is not None:
process, connection = DebugAdapterServer.launch(
- executable=executable, connection=connection, env=env, log_file=log_file
+ executable=executable,
+ connection=connection,
+ env=env,
+ log_file=log_file,
+ additional_args=additional_args,
)
self.process = process
self.connection = connection
@@ -1528,6 +1533,7 @@ class DebugAdapterServer(DebugCommunication):
env: Optional[dict[str, str]] = None,
log_file: Optional[TextIO] = None,
connection: Optional[str] = None,
+ additional_args: list[str] = [],
) -> tuple[subprocess.Popen, Optional[str]]:
adapter_env = os.environ.copy()
if env is not None:
@@ -1537,6 +1543,9 @@ class DebugAdapterServer(DebugCommunication):
adapter_env["LLDBDAP_LOG"] = log_file
args = [executable]
+ # Add additional arguments first (like --no-lldbinit)
+ args.extend(additional_args)
+
if connection is not None:
args.append("--connection")
args.append(connection)
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index b28a787..fffd4c2 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -21,6 +21,7 @@ class DAPTestCaseBase(TestBase):
self,
lldbDAPEnv: Optional[dict[str, str]] = None,
connection: Optional[str] = None,
+ additional_args: Optional[list[str]] = None,
):
"""Create the Visual Studio Code debug adapter"""
self.assertTrue(
@@ -33,15 +34,17 @@ class DAPTestCaseBase(TestBase):
init_commands=self.setUpCommands(),
log_file=log_file_path,
env=lldbDAPEnv,
+ additional_args=additional_args or [],
)
def build_and_create_debug_adapter(
self,
lldbDAPEnv: Optional[dict[str, str]] = None,
dictionary: Optional[dict] = None,
+ additional_args: Optional[list[str]] = None,
):
self.build(dictionary=dictionary)
- self.create_debug_adapter(lldbDAPEnv)
+ self.create_debug_adapter(lldbDAPEnv, additional_args=additional_args)
def build_and_create_debug_adapter_for_attach(self):
"""Variant of build_and_create_debug_adapter that builds a uniquely