RFC add "convenience functions" to gdb

Tom Tromey tromey@redhat.com
Sat Mar 8 20:24:00 GMT 2008


>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Tom> So, this evening I spent some time adding a new "convenience
Tom> function" facility to gdb.

I added a new convenience function, "show".  This lets you get at any
gdb "set/show" value in an expression.  Mostly, I think, this kind of
thing is useful for conditions in commands.

I've appended the new function, so folks can see it.  I could prepare
a new patch if anybody cares.

After writing this I started thinking that it sure would be nice to
have a host-side string type, plus a regex-matching operator.  Then
$(caller-matches ...) could be rewritten like:

    break func if $(caller-name) =~ $"callerfunction"

I use $"..." to denote a host string.

After this it would be pretty simple to start allowing scripting
access to all kinds of interesting state: string-valued set/show
variables, the exe name, the names of functions up and down the stack,
types, syscalls (whatever happened to that "catch syscall" patch?) --
anything we can think of.

So, I started implementing host strings... but I dunno.  Is it worth
doing?  Maybe python will solve all the problems -- since what I
really want is a nice, normal, complete programming language with
access to gdb state.

In fact maybe we only need *one* convenience function, $(python ...).

Tom

/* Return the value of a 'set/show' variable.  Integer-ish variables
   are returned as integers, others as strings.  */
static struct value *
show_fn (char *arg)
{
  struct cmd_list_element *alias, *prefix, *cmd;
  char *newarg;

  newarg = concat ("show ", arg, (char *) NULL);
  make_cleanup (free, newarg);

  if (! lookup_cmd_composition (newarg, &alias, &prefix, &cmd))
    error ("could not find variable `%s'", arg);
  if (! cmd->var)
    error ("`%s' is not a variable", arg);
  switch (cmd->var_type)
    {
    case var_string:
    case var_string_noescape:
    case var_optional_filename:
    case var_filename:
    case var_enum:
      error ("gdb-internal string type not yet implemented");

    case var_boolean:
      return value_from_longest (builtin_type_bool, * (int *) cmd->var);

    case var_auto_boolean:
      {
	enum auto_boolean ab = * (enum auto_boolean *) cmd->var;
	return value_from_longest (builtin_type_int,
				   (ab == AUTO_BOOLEAN_TRUE ? 1
				    : (ab == AUTO_BOOLEAN_FALSE ? 0
				       : -1)));
      }

    case var_integer:
    case var_uinteger:
    case var_zinteger:
      return value_from_longest (builtin_type_int, * (int *) cmd->var);
    }

  error ("programmer error: unhandled type");
}



More information about the Gdb-patches mailing list