Created
January 21, 2022 15:55
-
-
Save vmx/483dc2702f530c49f1b24fb1580fb6c3 to your computer and use it in GitHub Desktop.
Make GDB skip Rust's standard library files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script defines a command called `skiprustc` which skips all Rust | |
# standard library source files when debugging. Just drop this file into your | |
# `~/.gdbinit.d` directory. | |
# In order to enable it automatically whenever you debug Rust, you can add | |
# this hook to your `.gdbinit`: | |
# | |
# define hookpost-run | |
# skiprustc | |
# end | |
# | |
# This script is heavily based on on | |
# https://stackoverflow.com/questions/6219223/can-i-prevent-debugger-from-stepping-into-boost-or-stl-header-files/42721326#42721326 | |
# hence it is license under | |
# SPDX-License-Identifier: CC-BY-SA-4.0 | |
import gdb | |
# get all sources loadable by gdb | |
def get_sources(): | |
sources = [] | |
for line in gdb.execute('info sources',to_string=True).splitlines(): | |
if line.startswith("/"): | |
sources += [source.strip() for source in line.split(",")] | |
return sources | |
# skip files of which the (absolute) path begins with 'dir' | |
def skip_dir(dir): | |
sources = get_sources() | |
for source in sources: | |
if source.startswith(dir): | |
gdb.execute('skip file %s' % source, to_string=True) | |
class SkipRustcSources(gdb.Command): | |
def __init__(self): | |
super(self.__class__, self).__init__( | |
'skiprustc', | |
gdb.COMMAND_USER | |
) | |
def invoke(self, argument, from_tty): | |
# Only enable it if we are debugging Rust | |
if 'rust' in gdb.execute('show language', to_string=True): | |
argv = gdb.string_to_argv(argument) | |
if argv: | |
gdb.write('Does not take any arguments.\n') | |
else: | |
skip_dir("/rustc") | |
SkipRustcSources() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment