From d1e66431613ad092aa91770f52a2a2e5dede5a23 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 15 Sep 2010 20:17:11 +0000 Subject: Expand the family of debug print functions for displaying DOH types. Provide gdb support for calling these. Document improved debugging experience. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12221 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/error.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'Source/Swig/error.c') diff --git a/Source/Swig/error.c b/Source/Swig/error.c index fa82ad8d9..5dfcf605b 100644 --- a/Source/Swig/error.c +++ b/Source/Swig/error.c @@ -284,6 +284,41 @@ static String *format_filename(const_String_or_char_ptr filename) { return formatted_filename; } +/* ----------------------------------------------------------------------------- + * Swig_stringify_with_location() + * + * Return a string representation of any DOH object with line and file location + * information in the appropriate error message format. The string representation + * is enclosed within [] brackets after the line and file information. + * ----------------------------------------------------------------------------- */ + +String *Swig_stringify_with_location(DOH *object) { + String *str = NewStringEmpty(); + + if (!init_fmt) + Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); + + if (object) { + int line = Getline(object); + String *formatted_filename = format_filename(Getfile(object)); + if (line > 0) { + Printf(str, diag_line_fmt, formatted_filename, line); + } else { + Printf(str, diag_eof_fmt, formatted_filename); + } + if (Len(object) == 0) { + Printf(str, "[EMPTY]"); + } else { + Printf(str, "[%s]", object); + } + Delete(formatted_filename); + } else { + Printf(str, "[NULL]"); + } + + return str; +} + /* ----------------------------------------------------------------------------- * Swig_diagnostic() * -- cgit v1.2.1