Skip to content

Commit

Permalink
Merge pull request #1895 from nadongguri/nadongguri/new_arg_for_oct
Browse files Browse the repository at this point in the history
Support new octal argument format ("o") for file mode (0755).
Convert the autoargs to use octal format in related functions
like chmod(2).

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Mar 6, 2024
2 parents 11cbefa + c8a2c89 commit 3d12c1c
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 30 deletions.
1 change: 1 addition & 0 deletions cmds/replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ void get_argspec_string(struct uftrace_task_reader *task, char *args, size_t len
/* fall through */
case ARG_FMT_SINT:
case ARG_FMT_HEX:
case ARG_FMT_OCT:
idx = ffs(spec->size) - 1;
break;
case ARG_FMT_UINT:
Expand Down
5 changes: 3 additions & 2 deletions doc/ko/uftrace-live.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ uftrace 는 함수의 인자와 반환값을 각각 `-A`/`\--argument` 와 `-R`/
<int_spec> := "arg" N [ "/" <format> [ <size> ] ] [ "%" ( <reg> | <stack> ) ]
<float_spec> := "fparg" N [ "/" ( <size> | "80" ) ] [ "%" ( <reg> | <stack> ) ]
<ret_spec> := "retval" [ "/" <format> [ <size> ] ]
<format> := "d" | "i" | "u" | "x" | "s" | "c" | "f" | "S" | "p"
<format> := "d" | "i" | "u" | "x" | "o" | "s" | "c" | "f" | "S" | "p"
<size> := "8" | "16" | "32" | "64"
<reg> := <arch-specific register name> # "rdi", "xmm0", "r0", ...
<stack> := "stack" [ "+" ] <offset>
Expand All @@ -573,7 +573,8 @@ argN 은 정수형 인자를, fpargN 은 부동소수점형 인자를 위한 표
간주하고 소수점형에 대해서는 'double'형으로 간주한다.

"i" 형식은 signed 정수형으로, "u" 형식은 unsigned 으로 출력한다.
두 형식 모두 10 진수가 출력되는 한편 "x" 형식은 16 진수로 출력되게 한다.
두 형식 모두 10 진수가 출력되는 한편 "x" 형식은 16 진수로, "o" 형식은 8진수로
출력되게 한다.
"s" 는 null 을 제외한 문자열 출력을 위한 형식이고, "c" 는 단일 문자를 위한
형식이다. "f" 형식은 부동 소수점을 출력하는데, (일반적으로) 반환값에서만 의미를
가진다.
Expand Down
5 changes: 3 additions & 2 deletions doc/ko/uftrace-record.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ uftrace 는 함수의 인자와 반환값을 각각 `-A`/`\--argument` 와 `-R`/
<int_spec> := "arg" N [ "/" <format> [ <size> ] ] [ "%" ( <reg> | <stack> ) ]
<float_spec> := "fparg" N [ "/" ( <size> | "80" ) ] [ "%" ( <reg> | <stack> ) ]
<ret_spec> := "retval" [ "/" <format> [ <size> ] ]
<format> := "d" | "i" | "u" | "x" | "s" | "c" | "f" | "S" | "p"
<format> := "d" | "i" | "u" | "x" | "o" | "s" | "c" | "f" | "S" | "p"
<size> := "8" | "16" | "32" | "64"
<reg> := <arch-specific register name> # "rdi", "xmm0", "r0", ...
<stack> := "stack" [ "+" ] <offset>
Expand All @@ -490,7 +490,8 @@ argN 은 정수형 인자를, fpargN 은 부동소수점형 인자를 위한 표
간주하고 소수점형에 대해서는 'double'형으로 간주한다.

"i" 형식은 signed 정수형으로, "u" 형식은 unsigned 으로 출력한다.
두 형식 모두 10 진수가 출력되는 한편 "x" 형식은 16 진수로 출력되게 한다.
두 형식 모두 10 진수가 출력되는 한편 "x" 형식은 16 진수로, "o" 형식은 8진수로
출력되게 한다.
"s" 는 null 을 제외한 문자열 출력을 위한 형식이고, "c" 는 단일 문자를 위한
형식이다. "f" 형식은 부동 소수점을 출력하는데, (일반적으로) 반환값에서만 의미를
가진다.
Expand Down
7 changes: 4 additions & 3 deletions doc/uftrace-live.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ The syntax is very similar to that of triggers:
<int_spec> := "arg" N [ "/" <format> [ <size> ] ] [ "%" ( <reg> | <stack> ) ]
<float_spec> := "fparg" N [ "/" ( <size> | "80" ) ] [ "%" ( <reg> | <stack> ) ]
<ret_spec> := "retval" [ "/" <format> [ <size> ] ]
<format> := "d" | "i" | "u" | "x" | "s" | "c" | "f" | "S" | "p"
<format> := "d" | "i" | "u" | "x" | "o" | "s" | "c" | "f" | "S" | "p"
<size> := "8" | "16" | "32" | "64"
<reg> := <arch-specific register name> # "rdi", "xmm0", "r0", ...
<stack> := "stack" [ "+" ] <offset>
Expand All @@ -631,8 +631,9 @@ values. The "d" format or without format field, uftrace treats them as
'long int' type for integers and 'double' for floating-point numbers.
The "i" format makes it signed integer type and "u" format is for unsigned
type. Both are printed as decimal while "x" format makes it printed as
hexadecimal. The "s" format is for null-terminated string type and "c" format
is for character type. The "f" format is for floating-point type and is
hexadecimal, and "o" format makes it printed as octal. The "s" format is for
null-terminated string type and "c" format is for character type.
The "f" format is for floating-point type and is
meaningful only for return value (generally). Note that fpargN doesn't take
the format field since it's always floating-point. The "S" format is for
std::string, but it only supports libstdc++ library as of yet. Finally,
Expand Down
7 changes: 4 additions & 3 deletions doc/uftrace-record.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ The syntax is very similar to that of triggers:
<int_spec> := "arg" N [ "/" <format> [ <size> ] ] [ "%" ( <reg> | <stack> ) ]
<float_spec> := "fparg" N [ "/" ( <size> | "80" ) ] [ "%" ( <reg> | <stack> ) ]
<ret_spec> := "retval" [ "/" <format> [ <size> ] ]
<format> := "d" | "i" | "u" | "x" | "s" | "c" | "f" | "S" | "p"
<format> := "d" | "i" | "u" | "x" | "o" | "s" | "c" | "f" | "S" | "p"
<size> := "8" | "16" | "32" | "64"
<reg> := <arch-specific register name> # "rdi", "xmm0", "r0", ...
<stack> := "stack" [ "+" ] <offset>
Expand All @@ -539,8 +539,9 @@ values. The "d" format or without format field, uftrace treats them as
'long int' type for integers and 'double' for floating-point numbers.
The "i" format makes it signed integer type and "u" format is for unsigned
type. Both are printed as decimal while "x" format makes it printed as
hexadecimal. The "s" format is for null-terminated string type and "c" format
is for character type. The "f" format is for floating-point type and is
hexadecimal, and "o" format makes it printed as octal. The "s" format is for
null-terminated string type and "c" format is for character type.
The "f" format is for floating-point type and is
meaningful only for return value (generally). Note that fpargN doesn't take
the format field since it's always floating-point. The "S" format is for
std::string, but it only supports libstdc++ library as of yet. Finally,
Expand Down
2 changes: 1 addition & 1 deletion doc/uftrace.html
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@
<int_spec> := "arg" N [ "/" <format> [ <size> ] ] [ "%" ( <reg> | <stack> ) ]
<float_spec> := "fparg" N [ "/" ( <size> | "80" ) ] [ "%" ( <reg> | <stack> ) ]
<ret_spec> := "retval" [ "/" <format> [ <size> ] ]
<format> := "d" | "i" | "u" | "x" | "s" | "c" | "f" | "S" | "p"
<format> := "d" | "i" | "u" | "x" | "o" | "s" | "c" | "f" | "S" | "p"
<size> := "8" | "16" | "32" | "64"
<reg> := <arch-specific register name> # "rdi", "xmm0", "r0", ...
<stack> := "stack" [ "+" ] <offset>
Expand Down
6 changes: 5 additions & 1 deletion misc/gen-autoargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"Lmid_t", "FILE", "in_addr_t",
]

artifitial_type = [ "funcptr_t" ]
artifitial_type = [ "funcptr_t", "oct_mode_t" ]

pointer = "*"
reference = "&"
Expand Down Expand Up @@ -192,6 +192,8 @@ def make_uftrace_retval_format(ctype, funcname):
retval_format += "retval/u"
elif ctype == "funcptr_t":
retval_format += "retval/p"
elif ctype == "oct_mode_t":
retval_format += "retval/o"
elif ctype == "off64_t":
retval_format += "retval/d64"
elif ctype.startswith('enum'):
Expand Down Expand Up @@ -240,6 +242,8 @@ def make_uftrace_args_format(args, funcname):
args_format += "arg%d/u" % i
elif arg == "funcptr_t":
args_format += "arg%d/p" % i
elif arg == "oct_mode_t":
args_format += "arg%d/o" % i
elif arg == "off64_t":
args_format += "arg%d/d64" % i
elif arg.startswith('enum'):
Expand Down
16 changes: 5 additions & 11 deletions misc/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,18 +499,12 @@ int stat(const char *pathname, void *statbuf);
int fstat(int fd, void *statbuf);
int lstat(const char *pathname, void *statbuf);

enum uft_mode {
mod_777 = 0777, mod_755 = 0755, mod_666 = 0666, mod_644 = 0644,
mod_400 = 0400, mod_600 = 0600, mod_660 = 0660, mod_640 = 0640,
mod_444 = 0444, mod_022 = 0022, mod_440 = 0440, mod_222 = 0222,
mod_111 = 0111, mod_011 = 0011, mod_033 = 0033, mod_077 = 0077,
};
int chmod(const char *pathname, enum uft_mode mode);
int fchmod(int fd, enum uft_mode mode);
void umask(enum uft_mode mask);
int chmod(const char *pathname, oct_mode_t mode);
int fchmod(int fd, oct_mode_t mode);
void umask(oct_mode_t mask);

int creat(const char *file, enum uft_mode mode);
int creat64(const char *file, enum uft_mode mode);
int creat(const char *file, oct_mode_t mode);
int creat64(const char *file, oct_mode_t mode);

#include <unistd.h>
int isatty(int fd);
Expand Down
14 changes: 14 additions & 0 deletions tests/s-arg-oct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

int main(void)
{
const char *pathname = "bar.foo";

creat(pathname, 0755);
chmod(pathname, 0777);
unlink(pathname);

return 0;
}
17 changes: 17 additions & 0 deletions tests/t288_arg_oct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

from runtest import TestBase

class TestCase(TestBase):
def __init__(self):
TestBase.__init__(self, 'arg-oct', result="""
# DURATION TID FUNCTION
[1587104] | main() {
120.272 us [1587104] | creat("bar.foo", 0755) = 4;
3.210 us [1587104] | chmod("bar.foo", 0777) = 0;
6.350 us [1587104] | unlink("bar.foo") = 0;
131.752 us [1587104] | } /* main */
""")

def setup(self):
self.option = '-F main -a'
3 changes: 3 additions & 0 deletions utils/argspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ struct uftrace_arg_spec *parse_argspec(char *str, struct uftrace_filter_setting
case 'x':
fmt = ARG_FMT_HEX;
break;
case 'o':
fmt = ARG_FMT_OCT;
break;
case 's':
fmt = ARG_FMT_STR;
break;
Expand Down
3 changes: 2 additions & 1 deletion utils/argspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum uftrace_arg_format {
ARG_FMT_SINT,
ARG_FMT_UINT,
ARG_FMT_HEX,
ARG_FMT_OCT,
ARG_FMT_STR,
ARG_FMT_CHAR,
ARG_FMT_FLOAT,
Expand All @@ -26,7 +27,7 @@ enum uftrace_arg_format {
#define ARG_TYPE_STACK 3

/* should match with uftrace_arg_format above */
#define ARG_SPEC_CHARS "diuxscfSpet"
#define ARG_SPEC_CHARS "diuxoscfSpet"

/**
* uftrace_arg_spec contains arguments and return value info.
Expand Down
11 changes: 5 additions & 6 deletions utils/auto-args.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ static char *auto_enum_list =
"enum uft_prctl_op {PR_SET_PDEATHSIG = 1, PR_GET_PDEATHSIG, PR_GET_DUMPABLE, PR_SET_DUMPABLE,PR_GET_UNALIGN = 5, PR_SET_UNALIGN, PR_GET_KEEPCAPS, PR_SET_KEEPCAPS,PR_GET_FPEMU = 9, PR_SET_FPEMU, PR_GET_FPEXC, PR_SET_FPEXC,PR_GET_TIMING = 13, PR_SET_TIMING, PR_SET_NAME, PR_GET_NAME,PR_GET_ENDIAN = 19, PR_SET_ENDIAN, PR_GET_SECCOMP, PR_SET_SECCOMP,PR_CAPBSET_READ = 23, PR_CAPBSET_DROP, PR_GET_TSC, PR_SET_TSC,PR_GET_SECUREBITS = 27, PR_SET_SECUREBITS, PR_SET_TIMERSLACK, PR_GET_TIMERSLACK,PR_TASK_PERF_EVENTS_DISABLE = 31, PR_TASK_PERF_EVENTS_ENABLE,PR_MCE_KILL = 33, PR_MCE_KILL_GET, PR_SET_MM,PR_SET_CHILD_SUBREAPER = 36, PR_GET_CHILD_SUBREAPER,PR_SET_NO_NEW_PRIVS = 38, PR_GET_NO_NEW_PRIVS, PR_GET_TID_ADDRESS,PR_SET_THP_DISABLE = 41, PR_GET_THP_DISABLE,PR_MPX_ENABLE_MANAGEMENT = 43, PR_MPX_DISABLE_MANAGEMENT,PR_SET_FP_MODE = 45, PR_GET_FP_MODE, PR_CAP_AMBIENT,};"
"enum uft_epoll_op { EPOLL_CTL_ADD = 1, EPOLL_CTL_DEL, EPOLL_CTL_MOD };"
"enum uft_locale {LC_TYPE = 0, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES,LC_ALL, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT,LC_IDENTIFICATION,};"
"enum uft_mode {mod_777 = 0777, mod_755 = 0755, mod_666 = 0666, mod_644 = 0644,mod_400 = 0400, mod_600 = 0600, mod_660 = 0660, mod_640 = 0640,mod_444 = 0444, mod_022 = 0022, mod_440 = 0440, mod_222 = 0222,mod_111 = 0111, mod_011 = 0011, mod_033 = 0033, mod_077 = 0077,};"
"enum uft_clockid_t {CLOCK_REALTIME = 0,CLOCK_MONOTONIC,CLOCK_PROCESS_CPUTIME_ID,CLOCK_THREAD_CPUTIME_ID,CLOCK_MONOTONIC_RAW,CLOCK_REALTIME_COARSE,CLOCK_MONOTONIC_COARSE,CLOCK_BOOTTIME,CLOCK_REALTIME_ALARM,CLOCK_BOOTTIME_ALARM,CLOCK_TAI = 11,};"
;

Expand Down Expand Up @@ -231,11 +230,11 @@ static char *auto_args_list =
"stat@arg1/s,arg2/p;"
"fstat@arg1/d32,arg2/p;"
"lstat@arg1/s,arg2/p;"
"chmod@arg1/s,arg2/e:uft_mode;"
"fchmod@arg1/d32,arg2/e:uft_mode;"
"umask@arg1/e:uft_mode;"
"creat@arg1/s,arg2/e:uft_mode;"
"creat64@arg1/s,arg2/e:uft_mode;"
"chmod@arg1/s,arg2/o;"
"fchmod@arg1/d32,arg2/o;"
"umask@arg1/o;"
"creat@arg1/s,arg2/o;"
"creat64@arg1/s,arg2/o;"
"isatty@arg1/d32;"
"setuid@arg1/i32;"
"setgid@arg1/i32;"
Expand Down

0 comments on commit 3d12c1c

Please sign in to comment.