aboutsummaryrefslogtreecommitdiff
path: root/gdb/doc
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2016-03-10 17:12:30 -0500
committerSimon Marchi <simon.marchi@ericsson.com>2016-03-10 17:12:30 -0500
commitf2f3ccb9f81255fd1b4f877600f39979c2d7ece5 (patch)
treeb716861822a8b7ecd3d643061903298d57b969b8 /gdb/doc
parenta9f02af88d230aabf6771f94a6c401727a865188 (diff)
downloadgdb-f2f3ccb9f81255fd1b4f877600f39979c2d7ece5.zip
gdb-f2f3ccb9f81255fd1b4f877600f39979c2d7ece5.tar.gz
gdb-f2f3ccb9f81255fd1b4f877600f39979c2d7ece5.tar.bz2
Add $_as_string convenience function
This patch is a follow-up to "Add printf format specifier for printing enumerator": https://sourceware.org/ml/gdb-patches/2016-02/msg00144.html Instead of having a solution specific to the printf command, Pedro suggested adding a general purpose function $_as_string() that would cover this use case and more. So, in order to print the textual label of an enum, one can use: (gdb) printf "Visiting node of type %s\n", $_as_string(node) Visiting node of type NODE_INTEGER gdb/ChangeLog: * data-directory/Makefile.in (PYTHON_FILE_LIST): Install gdb/function/as_string.py. * python/lib/gdb/function/as_string.py: New file. * NEWS: Mention the new $_as_string function. gdb/testsuite/ChangeLog: * gdb.python/py-as-string.exp: New file. * gdb.python/py-as-string.c: New file. gdb/doc/ChangeLog: * gdb.texinfo (Convenience Functions): Document $_as_string.
Diffstat (limited to 'gdb/doc')
-rw-r--r--gdb/doc/ChangeLog4
-rw-r--r--gdb/doc/gdb.texinfo13
2 files changed, 17 insertions, 0 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index c9f2afc..3a98647 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2016-03-10 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * gdb.texinfo (Convenience Functions): Document $_as_string.
+
2016-02-23 Doug Evans <dje@google.com>
* gdb.texinfo (Skipping Over Functions and Files): Document new
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 4ec0ec1..0b249f4 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -10760,6 +10760,19 @@ checks all stack frames from the immediate caller to the frame specified
by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
frame specified by @var{number_of_frames}.
+@item $_as_string(@var{value})
+@findex $_as_string@r{, convenience function}
+Return the string representation of @var{value}.
+
+This function is useful to obtain the textual label (enumerator) of an
+enumeration value. For example, assuming the variable @var{node} is of
+an enumerated type:
+
+@smallexample
+(gdb) printf "Visiting node of type %s\n", $_as_string(node)
+Visiting node of type NODE_INTEGER
+@end smallexample
+
@end table
@value{GDBN} provides the ability to list and get help on