aboutsummaryrefslogtreecommitdiff
path: root/gdb/doc
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-03-14 13:58:58 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-04-01 21:41:49 +0100
commit8bdc16587e26100282094c8eaa8e83180ba57afd (patch)
tree5e18b77acd219a53d4ac482fd56e060d05927964 /gdb/doc
parentc29705b71a8ec966478c0dc4712194a95291c6de (diff)
downloadgdb-8bdc16587e26100282094c8eaa8e83180ba57afd.zip
gdb-8bdc16587e26100282094c8eaa8e83180ba57afd.tar.gz
gdb-8bdc16587e26100282094c8eaa8e83180ba57afd.tar.bz2
gdb: Add $_cimag and $_creal internal functions
Add two new internal functions $_cimag and $_creal that extract the imaginary and real parts of a complex value. These internal functions can take a complex value of any type 'float complex', 'double complex', or 'long double complex' and return a suitable floating point value 'float', 'double', or 'long double'. So we can now do this: (gdb) p z1 $1 = 1.5 + 4.5 * I (gdb) p $_cimag (z1) $4 = 4.5 (gdb) p $_creal (z1) $4 = 1.5 The components of a complex value are not strictly named types in DWARF, as the complex type is itself the base type. However, once we are able to extract the components it makes sense to be able to ask what the type of these components is and get a sensible answer back, rather than the error we would currently get. Currently GDB says: (gdb) ptype z1 type = complex double (gdb) p $_cimag (z1) $4 = 4.5 (gdb) ptype $ type = <invalid type code 9> With the changes in dwarf2read.c, GDB now says: (gdb) ptype z1 type = complex double (gdb) p $_cimag (z1) $4 = 4.5 (gdb) ptype $ type = double Which seems to make more sense. gdb/ChangeLog: * NEWS: Mention new internal functions. * dwarf2read.c (dwarf2_init_complex_target_type): New function. (read_base_type): Use dwarf2_init_complex_target_type. * value.c (creal_internal_fn): New function. (cimag_internal_fn): New function. (_initialize_values): Register new internal functions. gdb/doc/ChangeLog: * gdb.texinfo (Convenience Funs): Document '$_creal' and '$_cimag'. gdb/testsuite/ChangeLog: * gdb.base/complex-parts.c: New file. * gdb.base/complex-parts.exp: New file.
Diffstat (limited to 'gdb/doc')
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo11
2 files changed, 16 insertions, 0 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index c0d5aac..ea5fafd 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-01 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.texinfo (Convenience Funs): Document '$_creal' and
+ '$_cimag'.
+
2019-03-30 Eli Zaretskii <eliz@gnu.org>
* gdb.texinfo (Convenience Vars): Document $_gdb_major and
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index bb958cf..f410d02 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -11401,6 +11401,17 @@ an enumerated type:
Visiting node of type NODE_INTEGER
@end smallexample
+@item $_cimag(@var{value})
+@itemx $_creal(@var{value})
+@findex $_cimag@r{, convenience function}
+@findex $_creal@r{, convenience function}
+Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
+the complex number @var{value}.
+
+The type of the imaginary or real part depends on the type of the
+complex number, e.g., using @code{$_cimag} on a @code{float complex}
+will return an imaginary part of type @code{float}.
+
@end table
@value{GDBN} provides the ability to list and get help on