This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC] Let "gcore" command accept a suffix argument
- From: Joel Brobecker <brobecker at adacore dot com>
- To: Hui Zhu <teawater at gmail dot com>
- Cc: Stan Shebs <stanshebs at earthlink dot net>, Tom Tromey <tromey at redhat dot com>, Stan Shebs <stan at codesourcery dot com>, Michael Snyder <msnyder at vmware dot com>, gdb-patches ml <gdb-patches at sourceware dot org>
- Date: Wed, 6 Jan 2010 11:57:57 +0400
- Subject: Re: [RFC] Let "gcore" command accept a suffix argument
- References: <daef60380912120033r1ac03f1ao1f995381db879c82@mail.gmail.com> <m3zl5lscsu.fsf@fleche.redhat.com> <daef60380912141756h1eab3217o4364857729fd799b@mail.gmail.com> <m3d42gniwn.fsf@fleche.redhat.com> <daef60380912151957t312f3497l1e4022ce3dd8cbc4@mail.gmail.com> <4B29018C.6060307@codesourcery.com> <m31vioaxv0.fsf@fleche.redhat.com> <4B3BEDCC.9040103@earthlink.net> <daef60381001040642h2e8b3919u221f61d43b23d395@mail.gmail.com> <daef60381001052257q2068a8fbmaacd026b8d5cef49@mail.gmail.com>
> 2010-01-06 Hui Zhu <teawater@gmail.com>
> * printcmd.c (ctype.h): New include.
> (eval_command): New function.
> (_initialize_printcmd): New command "eval".
This is looking interesting :). A few comments:
* what is the exact semantics of the eval command? I looked at
the implementation, and I'm not I understand, or what I understand
does not necessarily makes sense to me.
So, in plain English first, what is the eval command expected
to do, in particular, what parts and how will the command translate
in the argument that gets passed.
* implementation-wise:
> +#define CMDSIZE 1024
> + char cmd[CMDSIZE + 1];
The GNU Coding Standard explicitly recommend against hard-coded
arbitrary limitations like these. In particular, your implementation
seems to just silently truncate the result if the user uses
an argument whose result does not fit in your CMDSIZE.
I think the implementation should allow for the argument to grow
to any size.
> + if (strlen (eval_begin))
> + {
> + value = parse_and_eval (eval_begin);
> +
> + switch (TYPE_CODE (value_type (value)))
> + {
> + case TYPE_CODE_ARRAY:
> + LA_GET_STRING (value, &buffer, &length,
> + &char_type, &la_encoding);
> + break;
> + case TYPE_CODE_INT:
> + buffer = plongest (value_as_long (value));
> + length = strlen (buffer);
> + break;
> + default:
> + buffer = eval_begin;
> + length = exp - eval_begin;
> + break;
> + }
> +
> + if (length > CMDSIZE - (cmdp - cmd))
> + length = CMDSIZE - (cmdp - cmd);
> + memcpy (cmdp, buffer, length);
> + cmdp += length;
I think you should print "value_print" instead of doing the printing
yourself. Your implementation is missing a lot of other cases that
you need to handle (eg: TYPE_CODE_RANGE, just to mention one).
--
Joel