[GSOC 2014][PATCH 3/4] JSON: Add basic support for syscalls in io.c
Dmitry V. Levin
ldv at altlinux.org
Fri Jun 27 02:02:40 UTC 2014
Hi YangMin,
On Thu, Jun 19, 2014 at 12:29:49AM +0800, Zhu YangMin wrote:
> The basic means that all the arguments are simply wrapped in
> a string value even for those complicated arguments printed by
> specific functions such as printflags(). We need to do more work
> to change those functions to be more like JSON-style.
>
> * io.c(sys_read, sys_write, sys_readv, sys_writev,
> sys_pread, sys_pwrite, sys_preadv, sys_pwritev,
> sys_sendfile, sys_sendfile64, sys_tee, sys_splice,
> sys_vmsplice, sys_ioctl): Modified to use the hook
> framework to support printing in JSON format. Note: The
> support of ioctl() is very limited and need to be improved.
Thanks for these examples. Let's have a look at the first one:
> int
> sys_read(struct tcb *tcp)
> {
> JSON_BEGIN_META_MODE;
>
> if (entering(tcp)) {
> JSON_META( printfd(tcp, tcp->u_arg[0]); );
> tprints(", ");
>
> json_event(1, EVENT_ARG | SEPARATOR);
> } else {
> json_type_event first;
>
> if (syserror(tcp)) {
> tprintf("%#lx", tcp->u_arg[1]);
> first = EVENT_ERROR;
> }
> else {
> JSON_META( printstr(tcp, tcp->u_arg[1], tcp->u_rval) );
> first = EVENT_ARG;
> }
> tprintf(", %lu", tcp->u_arg[2]);
>
> json_event(2, first | SEPARATOR, EVENT_ARG);
> }
> return 0;
> }
Well, compared to the original code, it looks rather complicated.
I thought it could be something easier to read, for example,
int
sys_read(struct tcb *tcp)
{
if (entering(tcp)) {
print_args_open();
print_arg_fd(tcp->u_arg[0]);
} else {
if (syserror(tcp))
print_arg_fmt("%#lx", tcp->u_arg[1]);
else
print_arg_str_at(tcp->u_arg[1], tcp->u_rval);
print_arg_fmt("%lu", tcp->u_arg[2]);
print_args_close();
}
return 0;
}
That is, with all JSON related details hidden from syscall parsers.
What do you think?
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20140627/e7bce4a0/attachment.bin>
More information about the Strace-devel
mailing list