From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: dje@google.com, gdb-patches@sourceware.org
Subject: Re: [PATCH/RFA] Introduce new $_isvoid() convenience function
Date: Fri, 13 Sep 2013 17:45:00 -0000 [thread overview]
Message-ID: <m31u4s39be.fsf@redhat.com> (raw)
In-Reply-To: <83a9jhi3h0.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 13 Sep 2013 10:29:47 +0300")
On Friday, September 13 2013, Eli Zaretskii wrote:
>> diff --git a/gdb/NEWS b/gdb/NEWS
>> index ad97f6f..e58d6ce 100644
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>> @@ -3,6 +3,9 @@
>>
>> *** Changes since GDB 7.6
>>
>> +* New convenience function "$_isvoid", to check whether an expression
>> + is void.
>
> This is OK, but please add a sentence explaining what is a "void
> expression". This is not something GDB users will automatically know
> or understand.
Right, I have added a sentence explaining both on the NEWS and on
gdb.texinfo. Please take a look and see if it is OK.
>> +
>> * The "maintenance print objfiles" command now takes an optional regexp.
>>
>> * The "catch syscall" command now works on arm*-linux* targets.
>> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
>> index b6ba239..70d580f 100644
>> --- a/gdb/doc/gdb.texinfo
>> +++ b/gdb/doc/gdb.texinfo
>> @@ -9829,6 +9829,18 @@ Returns the length of string @var{str}.
>>
>> @end table
>>
>> +These functions do not require @value{GDBN} to be configured with
>> +@code{Python} support, which means that they are always available.
>
> I'd prefer to describe functions that don't need Python before those
> that do, not after.
Reordered.
>
>> +@table @code
>> +
>> +@item $_isvoid (@var{expr})
>> +@findex $_isvoid@r{, convenience function}
>> +Return one if the expression @code{expr} is void. Otherwise it
> ^^^^^^^^^^^
> @var{expr}.
Fixed.
> And please put here an explanation of what is a void expression,
> preferably more detailed than what you will have in NEWS. AFAICS, we
> never explain that anywhere in the manual.
Done that. Please tell me what you think.
> And now a question about this feature: what will use of this function
> do in versions of GDB before 7.7?
I am not sure I understood your question. Do you want to know what will
happen when the user calls a non-existent $_isvoid convenience function?
(gdb) p $_isvoid ($var)
You can't do that without a process to debug.
(gdb) p $_isvoid (a)
You can't do that without a process to debug.
(gdb) start
Temporary breakpoint 1 at 0x4004a7: file 1.c, line 12.
Starting program: /home/sergio/work/src/git/isvoid/build-64/a.out
Temporary breakpoint 1, main () at 1.c:12
12 return 0;
(gdb) p $_isvoid ($var)
Invalid data type for function to be called.
(gdb) p $_isvoid (a)
Invalid data type for function to be called.
(gdb) p $_isvoid (1)
Invalid data type for function to be called.
Is this what you wanted to know? IOW, the user won't be able to call
this function from inside his/her script on a GDB prior to 7.7.
Thanks,
--
Sergio
gdb/
2013-09-13 Sergio Durigan Junior <sergiodj@redhat.com>
* NEWS: Mention new convenience function $_isvoid.
* value.c (isvoid_internal_fn): New function.
(_initialize_values): Add new convenience function $_isvoid.
gdb/doc/
2013-09-13 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.texinfo (Convenience Functions): Mention new convenience
function $_isvoid.
gdb/testsuite/
2013-09-13 Sergio Durigan Junior <sergiodj@redhat.com>
* gdb.base/gdbvars.c (foo_void): New function.
(foo_int): Likewise.
* gdb.base/gdbvars.exp (test_convenience_functions): New
function. Call it.
diff --git a/gdb/NEWS b/gdb/NEWS
index ad97f6f..35aaf41 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,11 @@
*** Changes since GDB 7.6
+* New convenience function "$_isvoid", to check whether an expression
+ is void. A void expression is an expression where the type of the
+ result is `void'; for example, when calling a function whose return
+ type is `void'.
+
* The "maintenance print objfiles" command now takes an optional regexp.
* The "catch syscall" command now works on arm*-linux* targets.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index b6ba239..a5705e4 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -9800,6 +9800,42 @@ function can be used in an expression just like an ordinary function;
however, a convenience function is implemented internally to
@value{GDBN}.
+These functions do not require @value{GDBN} to be configured with
+@code{Python} support, which means that they are always available.
+
+@table @code
+
+@item $_isvoid (@var{expr})
+@findex $_isvoid@r{, convenience function}
+Return one if the expression @var{expr} is void. Otherwise it
+returns zero.
+
+A void expression is an expression where the type of the result is
+`void'. For example, given the following function:
+
+@smallexample
+void
+foo (void)
+@{
+@}
+@end smallexample
+
+The result of calling it inside @value{GDBN} is `void':
+
+@smallexample
+(@value{GDBP}) print foo ()
+$1 = void
+(@value{GDBP}) print $_isvoid (foo ())
+$2 = 1
+(@value{GDBP}) set $v = foo ()
+(@value{GDBP}) print $v
+$3 = void
+(@value{GDBP}) print $_isvoid ($v)
+$4 = 1
+@end smallexample
+
+@end table
+
These functions require @value{GDBN} to be configured with
@code{Python} support.
diff --git a/gdb/testsuite/gdb.base/gdbvars.c b/gdb/testsuite/gdb.base/gdbvars.c
index aa3b4d8..352a76b 100644
--- a/gdb/testsuite/gdb.base/gdbvars.c
+++ b/gdb/testsuite/gdb.base/gdbvars.c
@@ -4,6 +4,17 @@ typedef void *ptr;
ptr p = &p;
+static void
+foo_void (void)
+{
+}
+
+static int
+foo_int (void)
+{
+ return 0;
+}
+
int
main ()
{
diff --git a/gdb/testsuite/gdb.base/gdbvars.exp b/gdb/testsuite/gdb.base/gdbvars.exp
index 23a6758..85aaca0 100644
--- a/gdb/testsuite/gdb.base/gdbvars.exp
+++ b/gdb/testsuite/gdb.base/gdbvars.exp
@@ -54,6 +54,34 @@ proc test_convenience_variables {} {
"Print contents of uninitialized convenience variable"
}
+proc test_convenience_functions {} {
+ gdb_test "print \$_isvoid" " = <internal function _isvoid>" \
+ "Print internal function \$_isvoid"
+
+ gdb_test "print \$isvoid_foo" " = void" \
+ "Print void convenience variable"
+
+ gdb_test "print \$_isvoid (\$isvoid_foo)" " = 1" \
+ "Check whether void convenience variable is void"
+
+ gdb_test_no_output "set \$isvoid_foo = 1" \
+ "Set void convenience variable to 1"
+
+ gdb_test "print \$_isvoid (\$isvoid_foo)" " = 0" \
+ "Check whether non-void convenience variable is void"
+
+ # For the next test, we need the inferior to be running.
+ if { ![runto_main] } {
+ return -1
+ }
+
+ gdb_test "print \$_isvoid (foo_void ())" " = 1" \
+ "Check whether void function is void"
+
+ gdb_test "print \$_isvoid (foo_int ())" " = 0" \
+ "Check whether non-void function is void"
+}
+
proc test_value_history {} {
global gdb_prompt
@@ -114,4 +142,5 @@ gdb_test_no_output "set print sevenbit-strings"
test_value_history
test_convenience_variables
+test_convenience_functions
test_with_program
diff --git a/gdb/value.c b/gdb/value.c
index 42a8d2f..edbfc70 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3584,6 +3584,23 @@ value_fetch_lazy (struct value *val)
return 0;
}
+/* Implementation of the convenience function $_isvoid. */
+
+static struct value *
+isvoid_internal_fn (struct gdbarch *gdbarch,
+ const struct language_defn *language,
+ void *cookie, int argc, struct value **argv)
+{
+ int ret;
+
+ if (argc != 1)
+ error (_("You must provide one parameter for $_isvoid."));
+
+ ret = TYPE_CODE (value_type (argv[0])) == TYPE_CODE_VOID;
+
+ return value_from_longest (builtin_type (gdbarch)->builtin_int, ret);
+}
+
void
_initialize_values (void)
{
@@ -3616,4 +3633,10 @@ VARIABLE is already initialized."));
add_prefix_cmd ("function", no_class, function_command, _("\
Placeholder command for showing help on convenience functions."),
&functionlist, "function ", 0, &cmdlist);
+
+ add_internal_function ("_isvoid", _("\
+Check whether an expression is void.\n\
+Usage: $_isvoid (expression)\n\
+Return 1 if the expression is void, zero otherwise."),
+ isvoid_internal_fn, NULL);
}
next prev parent reply other threads:[~2013-09-13 17:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-12 20:11 Sergio Durigan Junior
2013-09-12 23:59 ` Doug Evans
2013-09-13 6:42 ` Sergio Durigan Junior
2013-09-13 7:30 ` Eli Zaretskii
2013-09-13 17:45 ` Sergio Durigan Junior [this message]
2013-09-13 19:33 ` Eli Zaretskii
2013-09-13 19:41 ` Sergio Durigan Junior
2013-09-13 19:47 ` Eli Zaretskii
2013-09-13 21:17 ` Sergio Durigan Junior
2013-09-14 7:00 ` Eli Zaretskii
2013-09-16 17:19 ` Sergio Durigan Junior
2013-09-16 17:23 ` Doug Evans
2013-09-16 17:47 ` Sergio Durigan Junior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m31u4s39be.fsf@redhat.com \
--to=sergiodj@redhat.com \
--cc=dje@google.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox