This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Implement $_version; for auto-load commands in ~/.gdbinit


On Tue, Aug 21, 2012 at 7:49 AM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> Hi,
>
> it was requested by Eli in mail:
>         Re: GDB 7.5: Problems with the auto-load safe-path feature
>         http://sourceware.org/ml/gdb-patches/2012-08/msg00508.html
>         D:\usr\eli/.gdbinit:1: Error in sourced command file: "on" or "off" expected.
>
> IIRC it was already discussed even in the past.
>
> One solution would be some new mode where errors are only printed and script
> execution does not stop there.
>
> I have implemented a way to explicitly check for GDB version instead.

There is already gdb.VERSION in the Python API, but I guess $_version
could be useful to access for those without Python.

> No regressions on {x86_64,x86_64-m32,i686}-fedora18-linux-gnu.
>
>
> Thanks,
> Jan
>
>
> gdb/
> 2012-08-21  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
>         * top.c (init_main): New variables val, type, version_count, version_i
>         and version_a.  Create internal variable $_version.
>         * valarith.c (value_logical_not): Return 0 for lval_internalvar in
>         c_style_arrays being of type TYPE_CODE_ARRAY.
>
> gdb/testsuite/
> 2012-08-21  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
>         * gdb.base/default.exp (show convenience): Cope with array types.
>         ($_version works without inferior, $_version is >= 7): New tests.
>
> gdb/doc/
> 2012-08-21  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
>         * gdb.texinfo (Convenience Vars): New item $_version with new anchor
>         Convenience variable $_version.
>         (Auto-loading safe path): Make two references to $_version.
>
> diff --git a/gdb/top.c b/gdb/top.c
> index 8251d1b..2d1a8cf 100644
> --- a/gdb/top.c
> +++ b/gdb/top.c
> @@ -1574,6 +1574,11 @@ set_gdb_datadir (char *args, int from_tty, struct cmd_list_element *c)
>  static void
>  init_main (void)
>  {
> +  struct value *val;
> +  struct type *type;
> +  int version_count, version_i;
> +  unsigned version_a[4];
> +
>    /* Initialize the prompt to a simple "(gdb) " prompt or to whatever
>       the DEFAULT_PROMPT is.  */
>    set_prompt (DEFAULT_PROMPT);
> @@ -1681,6 +1686,25 @@ When set, GDB uses the specified path to search for data files."),
>                             set_gdb_datadir, NULL,
>                             &setlist,
>                             &showlist);
> +
> +  /* Set up the $_version array.  */
> +  version_count = sscanf (version, "%u.%u.%u.%u", &version_a[0], &version_a[1],
> +                         &version_a[2], &version_a[3]);
> +  if (version_count < 2)
> +    internal_error (__FILE__, __LINE__, _("Cannot parse GDB version \"%s\"!"),
> +                   version);
> +  type = create_range_type (NULL, builtin_type (target_gdbarch)->builtin_int,
> +                           0, version_count - 1);
> +  type = create_array_type (NULL,
> +                           builtin_type (target_gdbarch)->builtin_long,
> +                           type);
> +  val = allocate_value (type);
> +  for (version_i = 0; version_i < version_count; version_i++)
> +    pack_long ((value_contents_writeable (val)
> +               + TYPE_LENGTH (TYPE_TARGET_TYPE (type)) * version_i),
> +              TYPE_TARGET_TYPE (type),
> +              version_a[version_i]);
> +  set_internalvar (lookup_internalvar ("_version"), val);
>  }

If there are concerns of $_version decaying to a pointer if the
current language is C, may it should be a vector.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]