diff --git a/cpp_python_debug/core/gdb_controller.py b/cpp_python_debug/core/gdb_controller.py index 64521f2..4eda605 100644 --- a/cpp_python_debug/core/gdb_controller.py +++ b/cpp_python_debug/core/gdb_controller.py @@ -8,7 +8,7 @@ import wexpect import logging import json # For parsing JSON output from the GDB script (though not directly used in this file after changes) import time -from typing import Optional, Dict, Any # For type hinting +from typing import Optional, Dict, Any, List # For type hinting logger = logging.getLogger(__name__) @@ -136,6 +136,134 @@ class GDBSession: if self.child and self.child.isalive(): self.child.close() self.child = None raise # RILANCIA L'ECCEZIONE ORIGINALE + + def list_functions(self, regex_filter: Optional[str] = None, timeout: int = DEFAULT_GDB_OPERATION_TIMEOUT) -> List[str]: + """ + Lists functions known to GDB, optionally filtered by a regex. + + Args: + regex_filter: Optional regex to filter function names. + timeout: Timeout for the GDB command. + + Returns: + A list of function name strings. Returns an empty list on error or if no functions match. + """ + if not self.child or not self.child.isalive(): + logger.error("GDB session not active, cannot list functions.") + return [] + + command = "info functions" + if regex_filter: + command += f" {regex_filter.strip()}" + + logger.info(f"Requesting GDB function list with command: '{command}'") + functions: List[str] = [] + try: + output = self.send_cmd(command, expect_prompt=True, timeout=timeout) + # L'output di 'info functions' può essere complesso. + # Esempio: + # File my_source.cpp: + # 123: void MyClass::myMethod(int); + # 456: int anotherFunction(); + # Non-debugging symbols: + # 0x00401000 _start + # 0x004010a0 __do_global_dtors_aux + # + # Cerchiamo di estrarre nomi di funzioni che sembrano validi identificatori C/C++ + # Questo regex cerca identificatori che possono includere :: e