tracefile: opening file relative to file descriptor of openat.

This commit is contained in:
Ole Tange 2020-09-11 13:57:43 +02:00
parent c3abe9e996
commit ba8eee5953
2 changed files with 27 additions and 5 deletions

View file

@ -19,3 +19,6 @@ mkdir -p t/1/2/3
parallel -vj1 doit \
::: '' -l -u \
::: tt/tt/../tt/test.img `pwd`/tt/tt/../tt/test.img t/1/../1/2/3/test.img `pwd`/t/1/../1/2/3/test.img | grep test.img
# opening file relative to file descriptor of openat
tracefile lscpu | grep /sys/devices/system/cpu/cpu0/cache/index0/level

View file

@ -266,17 +266,36 @@ while(<IN>) {
# [pid 30817] stat("t/tar.gz", {st_mode=S_IFREG|0644, st_size=140853248, ...}) = 0
# openat(AT_FDCWD, "/tmp/a", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3
if(/^(\[[^]]+\])? # Match pid
\s*([^\" ]+) # function
\s*([^\" ]+) # function e.g. openat
[(] # (
[^"]* # E.g. AT_FDCWD
([^",]*) # E.g. AT_FDCWD or 4
[^"]* # E.g. ,
" # "
(([^\\"]|\\[\\"nt])*) # content of string with \n \" \t \\
"(.*)/x) # Rest
"(.*)/x) # Rest
{
# Matches the strace structure for a file
my $function = $2;
my $file = shell_unquote($3);
my $addinfo = $5;
my $first_arg = $3;
my $file = shell_unquote($4);
my $addinfo = $6;
if($function eq "openat"
or
$function eq "faccessat") {
# openat(AT_FDCWD, "/sys/devices/system/cpu", O_RDONLY|O_CLOEXEC) = 4
# openat(4, "kernel_max", O_RDONLY|O_CLOEXEC) = 5
# faccessat(4, "cpu0/cache/index4", F_OK) = -1 ENOENT
# openat can open a file descriptor
# openat/faccessat can open relative to a file descriptor
$addinfo =~ /= (-?\d+)(\s[^=]*)?$/ || die $addinfo,$_;
my $fd = $1;
if($first_arg eq "AT_FDCWD") {
$fd{$fd} = $file;
} elsif($first_arg =~ /^\d+$/) {
$file = $fd{$first_arg}."/".$file;
} else { die $first_arg,$_; }
$fd{$fd} = $file;
}
# Relative to $dir
$file =~ s:^([^/]):$dir/$1:;
$file =~ s:/\./:/:g; # /./ => /