22from contextlib
import contextmanager
25if sys.version_info >= (3, 4):
26 from importlib
import reload
28 from imp
import reload
34import _gdbevents
as events
36sys.modules[
"gdb.events"] = events
90 """Internal function called from GDB to execute all unwinders.
92 Runs each currently enabled unwinder until it finds the one that
93 can unwind given frame.
96 pending_frame: gdb.PendingFrame instance.
101 [0] gdb.UnwindInfo instance
102 [1] Name of unwinder that claimed the frame (type `str`)
104 or None, if no unwinder has claimed the frame.
107 for unwinder
in objfile.frame_unwinders:
109 unwind_info = unwinder(pending_frame)
110 if unwind_info
is not None:
111 return (unwind_info, unwinder.name)
115 unwind_info = unwinder(pending_frame)
116 if unwind_info
is not None:
117 return (unwind_info, unwinder.name)
119 for unwinder
in frame_unwinders:
121 unwind_info = unwinder(pending_frame)
122 if unwind_info
is not None:
123 return (unwind_info, unwinder.name)
129 """This function is used to replace Python 2's PyRun_SimpleFile.
131 Loads and executes the given file.
133 We could use the runpy module, but its documentation says:
134 "Furthermore, any functions and classes defined by the executed code are
135 not guaranteed to work correctly after a runpy function has returned."
137 globals = sys.modules[
"__main__"].__dict__
141 if not hasattr(globals,
"__file__"):
142 globals[
"__file__"] = filepath
145 with open(filepath,
"rb")
as file:
148 compiled = compile(file.read(), filepath,
"exec")
149 exec(compiled, globals, globals)
152 del globals[
"__file__"]
156PYTHONDIR = os.path.dirname(os.path.dirname(__file__))
162packages = [
"function",
"command",
"printer"]
170 for package
in packages:
171 location = os.path.join(os.path.dirname(__file__), package)
172 if os.path.exists(location):
174 lambda x: x.endswith(
".py")
and x !=
"__init__.py", os.listdir(location)
177 for py_file
in py_files:
179 modname =
"%s.%s.%s" % (__name__, package, py_file[:-3])
181 if modname
in sys.modules:
183 reload(__import__(modname))
187 sys.stderr.write(traceback.format_exc() +
"\n")
194 """Update sys.path, reload gdb and auto-load packages."""
198 sys.path.remove(PYTHONDIR)
201 sys.path.insert(0, dir)
207 reload(__import__(__name__))
212 "Return the current Progspace."
213 return selected_inferior().progspace
217 "Return a sequence of the current program space's objfiles."
222 """solib_name (Long) -> String.\n\
223Return the name of the shared library holding a given address, or None."""
228 "Return the block containing the given pc value, or None."
233 """find_pc_line (pc) -> Symtab_and_line.
234 Return the gdb.Symtab_and_line object corresponding to the pc value."""
239 """Set the GDB parameter NAME to VALUE."""
245 elif isinstance(value, bool):
250 execute(
"set " + name +
" " + str(value), to_string=
True)
255 """Temporarily set the GDB parameter NAME to VALUE.
256 Note that this is a context manager."""
257 old_value = parameter(name)
268 """A helper function that blocks and unblocks signals."""
269 if not hasattr(signal,
"pthread_sigmask"):
273 to_block = {signal.SIGCHLD, signal.SIGINT, signal.SIGALRM, signal.SIGWINCH}
274 old_mask = signal.pthread_sigmask(signal.SIG_BLOCK, to_block)
278 signal.pthread_sigmask(signal.SIG_SETMASK, old_mask)
281class Thread(threading.Thread):
282 """A GDB-specific wrapper around threading.Thread
284 This wrapper ensures that the new thread blocks any signals that
285 must be delivered on GDB's main thread."""
writelines(self, iterable)
GdbSetPythonDirectory(dir)
_execute_unwinders(pending_frame)
with_parameter(name, value)
set_parameter(name, value)