Created
July 24, 2017 12:39
-
-
Save cjsmeele/b9e7541791172042bb34fff79cf5c77d to your computer and use it in GitHub Desktop.
Attach GDB to a spawned program matching a certain name within ~100ms
This file contains 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
#!/usr/bin/env perl | |
use 5.12.0; | |
use warnings; | |
my $pname = $ARGV[0] // die "usage: $0 NAME\n"; | |
for (my $i = 0;; ++$i) { | |
state @pids; | |
chomp(my @new_pids = `pgrep $pname`); | |
if ($i and @new_pids > @pids) { | |
my ($new) = grep { my $a = $_; not grep {$_ == $a} @pids } @new_pids; | |
say "$new spawned! attaching gdb...\n"; | |
exec "gdb", "attach", $new; | |
} | |
@pids = @new_pids; | |
select undef, undef, undef, 0.1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment