diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2010-09-15 20:17:11 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2010-09-15 20:17:11 +0000 |
commit | d1e66431613ad092aa91770f52a2a2e5dede5a23 (patch) | |
tree | d11dd0c6cc3534939135a2d70409f3fa60db7ba1 /Source | |
parent | a202bf98183f8ef66d83d3c75e22078bcfdc4922 (diff) | |
download | swig-d1e66431613ad092aa91770f52a2a2e5dede5a23.tar.gz |
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
Diffstat (limited to 'Source')
-rw-r--r-- | Source/DOH/doh.h | 4 | ||||
-rw-r--r-- | Source/DOH/hash.c | 53 | ||||
-rw-r--r-- | Source/DOH/list.c | 2 | ||||
-rw-r--r-- | Source/Modules/lang.cxx | 2 | ||||
-rw-r--r-- | Source/Modules/swigmod.h | 9 | ||||
-rw-r--r-- | Source/Modules/utils.cxx | 113 | ||||
-rw-r--r-- | Source/Swig/error.c | 35 | ||||
-rw-r--r-- | Source/Swig/misc.c | 1 | ||||
-rw-r--r-- | Source/Swig/swig.h | 4 |
9 files changed, 208 insertions, 15 deletions
diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h index e46d103de..6fa352547 100644 --- a/Source/DOH/doh.h +++ b/Source/DOH/doh.h @@ -267,6 +267,8 @@ extern int DohIsSequence(const DOH *obj); extern int DohIsString(const DOH *obj); extern int DohIsFile(const DOH *obj); +extern void DohSetMaxHashExpand(int count); +extern int DohGetMaxHashExpand(void); extern void DohSetmark(DOH *obj, int x); extern int DohGetmark(DOH *obj); @@ -424,6 +426,8 @@ extern void DohMemoryDebug(void); #define SplitLines DohSplitLines #define Setmark DohSetmark #define Getmark DohGetmark +#define SetMaxHashExpand DohSetMaxHashExpand +#define GetMaxHashExpand DohGetMaxHashExpand #define None DohNone #define Call DohCall #define First DohFirst diff --git a/Source/DOH/hash.c b/Source/DOH/hash.c index 87f8e3c40..48afd2e54 100644 --- a/Source/DOH/hash.c +++ b/Source/DOH/hash.c @@ -42,6 +42,7 @@ typedef struct KeyValue { } KeyValue; static KeyValue *root = 0; +static int max_expand = 1; /* Find or create a key in the interned key table */ static DOH *find_key(DOH *doh_c) { @@ -379,6 +380,26 @@ static DOH *Hash_keys(DOH *so) { } /* ----------------------------------------------------------------------------- + * DohSetMaxHashExpand() + * + * Controls how many Hash objects are displayed in full in Hash_str + * ----------------------------------------------------------------------------- */ + +void DohSetMaxHashExpand(int count) { + max_expand = count; +} + +/* ----------------------------------------------------------------------------- + * DohGetMaxHashExpand() + * + * Returns how many Hash objects are displayed in full in Hash_str + * ----------------------------------------------------------------------------- */ + +int DohGetMaxHashExpand(void) { + return max_expand; +} + +/* ----------------------------------------------------------------------------- * Hash_str() * * Create a string representation of a hash table (mainly for debugging). @@ -388,7 +409,8 @@ static DOH *Hash_str(DOH *ho) { int i, j; HashNode *n; DOH *s; - static int indent = 4; + static int expanded = 0; + static const char *tab = " "; Hash *h = (Hash *) ObjData(ho); s = NewStringEmpty(); @@ -396,22 +418,35 @@ static DOH *Hash_str(DOH *ho) { Printf(s, "Hash(0x%x)", ho); return s; } + if (expanded >= max_expand) { + /* replace each hash attribute with a '.' */ + Printf(s, "Hash(0x%x) {", ho); + for (i = 0; i < h->hashsize; i++) { + n = h->hashtable[i]; + while (n) { + Putc('.', s); + n = n->next; + } + } + Putc('}', s); + return s; + } ObjSetMark(ho, 1); - Printf(s, "Hash {\n"); + Printf(s, "Hash(0x%x) {\n", ho); for (i = 0; i < h->hashsize; i++) { n = h->hashtable[i]; while (n) { - for (j = 0; j < indent; j++) - Putc(' ', s); - indent += 4; + for (j = 0; j < expanded + 1; j++) + Printf(s, tab); + expanded += 1; Printf(s, "'%s' : %s, \n", n->key, n->object); - indent -= 4; + expanded -= 1; n = n->next; } } - for (j = 0; j < (indent - 4); j++) - Putc(' ', s); - Printf(s, "}\n"); + for (j = 0; j < expanded; j++) + Printf(s, tab); + Printf(s, "}"); ObjSetMark(ho, 0); return s; } diff --git a/Source/DOH/list.c b/Source/DOH/list.c index a08cadb5a..d5b532409 100644 --- a/Source/DOH/list.c +++ b/Source/DOH/list.c @@ -252,7 +252,7 @@ static DOH *List_str(DOH *lo) { if ((i + 1) < l->nitems) Printf(s, ", "); } - Printf(s, " ]\n"); + Printf(s, " ]"); ObjSetMark(lo, 0); return s; } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index e28fcbb89..6ec0463fa 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -52,7 +52,7 @@ extern "C" { return all_protected_mode; } void Language_replace_special_variables(String *method, String *tm, Parm *parm) { - Language::instance()->replaceSpecialVariables(method, tm, parm); + Language::instance()->replaceSpecialVariables(method, tm, parm); } } diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index b0b488d6f..d3074105f 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -380,9 +380,15 @@ void Wrapper_fast_dispatch_mode_set(int); void Wrapper_cast_dispatch_mode_set(int); void Wrapper_naturalvar_mode_set(int); - void clean_overloaded(Node *n); +extern "C" { + const char *Swig_to_string(DOH *object, int count = -1); + const char *Swig_to_string_with_location(DOH *object, int count = -1); + void Swig_print(DOH *object, int count = -1); + void Swig_print_with_location(DOH *object, int count = -1); +} + /* Contracts */ void Swig_contracts(Node *n); @@ -395,5 +401,4 @@ void Swig_browser(Node *n, int); void Swig_default_allocators(Node *n); void Swig_process_types(Node *n); - #endif diff --git a/Source/Modules/utils.cxx b/Source/Modules/utils.cxx index 3fe7a2709..13a504bcf 100644 --- a/Source/Modules/utils.cxx +++ b/Source/Modules/utils.cxx @@ -100,3 +100,116 @@ void clean_overloaded(Node *n) { Delattr(n, "sym:overloaded"); } } + +/* ----------------------------------------------------------------------------- + * Swig_set_max_hash_expand() + * + * Controls how many Hash objects are displayed when displaying nested Hash objects. + * Makes DohSetMaxHashExpand an externally callable function (for debugger). + * ----------------------------------------------------------------------------- */ + +void Swig_set_max_hash_expand(int count) { + SetMaxHashExpand(count); +} + +extern "C" { + +/* ----------------------------------------------------------------------------- + * Swig_get_max_hash_expand() + * + * Returns how many Hash objects are displayed when displaying nested Hash objects. + * Makes DohGetMaxHashExpand an externally callable function (for debugger). + * ----------------------------------------------------------------------------- */ + +int Swig_get_max_hash_expand() { + return GetMaxHashExpand(); +} + +/* ----------------------------------------------------------------------------- + * Swig_to_doh_string() + * + * DOH version of Swig_to_string() + * ----------------------------------------------------------------------------- */ + +static String *Swig_to_doh_string(DOH *object, int count) { + int old_count = Swig_get_max_hash_expand(); + if (count >= 0) + Swig_set_max_hash_expand(count); + + String *debug_string = object ? NewStringf("%s", object) : NewString("NULL"); + + Swig_set_max_hash_expand(old_count); + return debug_string; +} + +/* ----------------------------------------------------------------------------- + * Swig_to_doh_string_with_location() + * + * DOH version of Swig_to_string_with_location() + * ----------------------------------------------------------------------------- */ + +static String *Swig_to_doh_string_with_location(DOH *object, int count) { + int old_count = Swig_get_max_hash_expand(); + if (count >= 0) + Swig_set_max_hash_expand(count); + + String *debug_string = Swig_stringify_with_location(object); + + Swig_set_max_hash_expand(old_count); + return debug_string; +} + +/* ----------------------------------------------------------------------------- + * Swig_to_string() + * + * Swig debug - return C string representation of any DOH type. + * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0 + * Note: leaks memory. + * ----------------------------------------------------------------------------- */ + +const char *Swig_to_string(DOH *object, int count) { + return Char(Swig_to_doh_string(object, count)); +} + +/* ----------------------------------------------------------------------------- + * Swig_to_string_with_location() + * + * Swig debug - return C string representation of any DOH type, within [] brackets + * for Hash and List types, prefixed by line and file information. + * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0 + * Note: leaks memory. + * ----------------------------------------------------------------------------- */ + +const char *Swig_to_string_with_location(DOH *object, int count) { + return Char(Swig_to_doh_string_with_location(object, count)); +} + +/* ----------------------------------------------------------------------------- + * Swig_print() + * + * Swig debug - display string representation of any DOH type. + * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0 + * ----------------------------------------------------------------------------- */ + +void Swig_print(DOH *object, int count) { + String *output = Swig_to_doh_string(object, count); + Printf(stdout, "%s\n", output); + Delete(output); +} + +/* ----------------------------------------------------------------------------- + * Swig_to_string_with_location() + * + * Swig debug - display string representation of any DOH type, within [] brackets + * for Hash and List types, prefixed by line and file information. + * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0 + * ----------------------------------------------------------------------------- */ + +void Swig_print_with_location(DOH *object, int count) { + String *output = Swig_to_doh_string_with_location(object, count); + Printf(stdout, "%s\n", output); + Delete(output); +} + +} // extern "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 @@ -285,6 +285,41 @@ static String *format_filename(const_String_or_char_ptr 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() * * Issue a diagnostic message on stdout. diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 2105f0c51..a57c7cf33 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -527,7 +527,6 @@ String *Swig_string_schemify(String *s) { return ns; } - /* ----------------------------------------------------------------------------- * Swig_string_typecode() * diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index f90a5ffb1..021c5611f 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -319,7 +319,6 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern String *Swig_string_lower(String *s); extern String *Swig_string_upper(String *s); extern String *Swig_string_title(String *s); - extern void Swig_init(void); extern int Swig_value_wrapper_mode(int mode); @@ -334,6 +333,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern int Swig_warn_count(void); extern void Swig_error_msg_format(ErrorMessageFormat format); extern void Swig_diagnostic(const_String_or_char_ptr filename, int line, const char *fmt, ...); + extern String *Swig_stringify_with_location(DOH *object); /* --- C Wrappers --- */ extern String *Swig_cparm_name(Parm *p, int i); @@ -408,6 +408,8 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern void Wrapper_director_protected_mode_set(int); extern void Wrapper_all_protected_mode_set(int); extern void Language_replace_special_variables(String *method, String *tm, Parm *parm); + extern void Swig_print(DOH *object, int count); + extern void Swig_print_with_location(DOH *object, int count); /* -- template init -- */ |