summaryrefslogtreecommitdiff
path: root/gdb/typeprint.c
diff options
context:
space:
mode:
authorThiago Jung Bauermann <bauerman@br.ibm.com>2009-02-05 12:16:24 +0000
committerThiago Jung Bauermann <bauerman@br.ibm.com>2009-02-05 12:16:24 +0000
commitd01d94ef3114c8490d919d04efb3ed9772e8c2e6 (patch)
treec792c71c35701570d57fe418b7f9c1762c62ab82 /gdb/typeprint.c
parent7d5dabc5616e1677a35e38d0813caa04aba3419d (diff)
downloadgdb-d01d94ef3114c8490d919d04efb3ed9772e8c2e6.tar.gz
2009-02-05 Thiago Jung Bauermann <bauerman@br.ibm.com>
* language.h (language_dfn): Add la_get_string member. (LA_GET_STRING): New macro. (default_get_string): New prototype. * language.c (default_get_string): New function. (unknown_language_defn, auto_language_defn, local_language_defn): Use default_get_string for la_get_string. * c-lang.c (c_get_string): New function. (c_language_defn, cplus_language_defn, asm_language_defn): Use c_get_string for la_get_string. (minimal_language_defn): Likewise * ada-lang.c (ada_language_defn): Likewise. * f-lang.c (f_language_defn): Use default_get_string for la_get_string. * jv-lang.c (java_language_defn): Likewise. * m2-lang.c (m2_language_defn): Likewise. * objc-lang.c (objc_language_defn): Likewise. * p-lang.c (p_language_defn): Likewise. * scm-lang.c (scm_language_defn): Likewise. * typeprint.c (type_to_string): New function. * value.h (type_to_string): New prototype. * valprint.c (val_print_string): Factor out code for reading string from the inferior into its own function. Put 2 spaces after period in comments. (read_string): New function. * valprint.h (read_string): New prototype.
Diffstat (limited to 'gdb/typeprint.c')
-rw-r--r--gdb/typeprint.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 678aaa1d737..1f824faafb2 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -33,6 +33,7 @@
#include "cp-abi.h"
#include "typeprint.h"
#include "gdb_string.h"
+#include "exceptions.h"
#include "valprint.h"
#include <errno.h>
@@ -78,6 +79,34 @@ type_print (struct type *type, char *varstring, struct ui_file *stream,
LA_PRINT_TYPE (type, varstring, stream, show, 0);
}
+/* Print TYPE to a string, returning it. The caller is responsible for
+ freeing the string. */
+
+char *
+type_to_string (struct type *type)
+{
+ char *s = NULL;
+ long dummy;
+ struct ui_file *stb;
+ struct cleanup *old_chain;
+ volatile struct gdb_exception except;
+
+ stb = mem_fileopen ();
+ old_chain = make_cleanup_ui_file_delete (stb);
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ type_print (type, "", stb, -1);
+ s = ui_file_xstrdup (stb, &dummy);
+ }
+ if (except.reason < 0)
+ s = NULL;
+
+ do_cleanups (old_chain);
+
+ return s;
+}
+
/* Print type of EXP, or last thing in value history if EXP == NULL.
show is passed to type_print. */