Skip to content

[lldb] enable stdin with stdin command #52

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
merged 1 commit into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/idd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ async def execute_debugger_command(self, event: Input.Changed) -> None:
self.parallel_command_bar.value == "exit":
Debugger.terminate()
exit(0)
if self.parallel_command_bar.value != "":

if self.parallel_command_bar.value.startswith("stdin "):
Debugger.insert_stdin(self.parallel_command_bar.value[6:] + "\n")
result = {}

elif self.parallel_command_bar.value != "":
result = Debugger.run_parallel_command(self.parallel_command_bar.value)

self.diff_area1.append([self.parallel_command_bar.value])
Expand All @@ -330,15 +335,20 @@ async def execute_debugger_command(self, event: Input.Changed) -> None:
self.diff_area1.append([self.parallel_command_bar.value])
self.diff_area2.append([self.parallel_command_bar.value])

await self.set_common_command_result(result)
if result:
await self.set_common_command_result(result)

self.parallel_command_bar.value = ""

elif event.control.id == 'base-command-bar':
if self.only_base and (self.base_command_bar.value == "exit" or self.base_command_bar.value == "quit"):
Debugger.terminate()
exit(0)
if self.base_command_bar.value != "":

if self.base_command_bar.value.startswith("stdin "):
Debugger.insert_stdin_single(self.base_command_bar.value[6:] + "\n", "base")

elif self.base_command_bar.value != "":
result = Debugger.run_single_command(self.base_command_bar.value, "base")
self.diff_area1.append([self.base_command_bar.value])
self.diff_area1.append(result)
Expand All @@ -359,7 +369,10 @@ async def execute_debugger_command(self, event: Input.Changed) -> None:
self.base_command_bar.value = ""

elif event.control.id == 'regressed-command-bar':
if self.regressed_command_bar.value != "":
if self.regressed_command_bar.value.startswith("stdin "):
Debugger.insert_stdin_single(self.regressed_command_bar.value[6:] + "\n", "regressed")

elif self.regressed_command_bar.value != "":
result = Debugger.run_single_command(self.regressed_command_bar.value, "regressed")
self.diff_area2.append([self.regressed_command_bar.value])
self.diff_area2.append(result)
Expand Down
23 changes: 23 additions & 0 deletions src/idd/debuggers/lldb/lldb_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
class LLDBGetState:
pass


class LLDBStdin:
def __init__(self, text: str):
self.text = text


class LLDBDebugger:
is_initted = False

Expand Down Expand Up @@ -93,6 +99,9 @@ def get_current_calls(self):
target = self.lldb_instance.GetTargetAtIndex(0)
calls = get_call_instructions(target)
return calls

def insert_stdin(self, text: str):
self.target.GetProcess().PutSTDIN(text)

def terminate(self):
return
Expand All @@ -107,6 +116,8 @@ def run(lldb_args, pipe):
if isinstance(args, LLDBGetState) or isinstance(kwargs, LLDBGetState):
res = lldb.get_state()
pipe.send(res)
elif isinstance(args, LLDBStdin):
lldb.insert_stdin(args.text)
else:
res = lldb.run_single_command(*args, **kwargs)
stdout = lldb.target.GetProcess().GetSTDOUT(1024 * 1024 * 10)
Expand Down Expand Up @@ -157,6 +168,18 @@ def run_parallel_command(self, command):
"regressed": self.regressed_pipe.recv(),
}

def insert_stdin(self, text: str):
text = LLDBStdin(text)
self.base_pipe.send((text, text))
self.regressed_pipe.send((text, text))

def insert_stdin_single(self, text: str, target: str):
text = LLDBStdin(text)
if target == "base":
self.base_pipe.send((text, text))
if target == "regressed":
self.regressed_pipe.send((text, text))

def terminate(self):
terminate_all_IDDGdbController()

Expand Down