20from contextlib
import contextmanager
23if sys.version_info >= (3, 4):
24 from importlib
import reload
26 from imp
import reload
32import _gdbevents
as events
34sys.modules[
"gdb.events"] = events
88 """Internal function called from GDB to execute all unwinders.
90 Runs each currently enabled unwinder until it finds the one that
91 can unwind given frame.
94 pending_frame: gdb.PendingFrame instance.
99 [0] gdb.UnwindInfo instance
100 [1] Name of unwinder that claimed the frame (type `str`)
102 or None,
if no unwinder has claimed the frame.
105 for unwinder
in objfile.frame_unwinders:
107 unwind_info = unwinder(pending_frame)
108 if unwind_info
is not None:
109 return (unwind_info, unwinder.name)
113 unwind_info = unwinder(pending_frame)
114 if unwind_info
is not None:
115 return (unwind_info, unwinder.name)
117 for unwinder
in frame_unwinders:
119 unwind_info = unwinder(pending_frame)
120 if unwind_info
is not None:
121 return (unwind_info, unwinder.name)
127 """This function is used to replace Python 2's PyRun_SimpleFile.
129 Loads and executes the given file.
131 We could use the runpy module, but its documentation says:
132 "Furthermore, any functions and classes defined by the executed code are
133 not guaranteed to work correctly after a runpy function has returned.
"
135 globals = sys.modules["__main__"].__dict__
139 if not hasattr(globals,
"__file__"):
140 globals[
"__file__"] = filepath
143 with open(filepath,
"rb")
as file:
146 compiled = compile(file.read(), filepath,
"exec")
147 exec(compiled, globals, globals)
150 del globals[
"__file__"]
154PYTHONDIR = os.path.dirname(os.path.dirname(__file__))
160packages = [
"function",
"command",
"printer"]
168 for package
in packages:
169 location = os.path.join(os.path.dirname(__file__), package)
170 if os.path.exists(location):
172 lambda x: x.endswith(
".py")
and x !=
"__init__.py", os.listdir(location)
175 for py_file
in py_files:
177 modname =
"%s.%s.%s" % (__name__, package, py_file[:-3])
179 if modname
in sys.modules:
181 reload(__import__(modname))
185 sys.stderr.write(traceback.format_exc() +
"\n")
192 """Update sys.path, reload gdb and auto-load packages."""
196 sys.path.remove(PYTHONDIR)
199 sys.path.insert(0, dir)
205 reload(__import__(__name__))
210 "Return the current Progspace."
211 return selected_inferior().progspace
215 "Return a sequence of the current program space's objfiles."
220 """solib_name (Long) -> String.\n\
221Return the name of the shared library holding a given address, or None."""
226 "Return the block containing the given pc value, or None."
231 """find_pc_line (pc) -> Symtab_and_line.
232 Return the gdb.Symtab_and_line object corresponding to the pc value."""
237 """Set the GDB parameter NAME to VALUE."""
243 elif isinstance(value, bool):
248 execute(
"set " + name +
" " + str(value), to_string=
True)
253 """Temporarily set the GDB parameter NAME to VALUE.
254 Note that this is a context manager.
"""
255 old_value = parameter(name)
def writelines(self, iterable)
def __init__(self, stream)
def GdbSetPythonDirectory(dir)
def with_parameter(name, value)
def _auto_load_packages()
def _execute_file(filepath)
def set_parameter(name, value)
def _execute_unwinders(pending_frame)