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
This commit is contained in:
William S Fulton 2010-09-15 20:17:11 +00:00
commit d1e6643161
13 changed files with 421 additions and 47 deletions

View file

@ -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

View file

@ -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) {
@ -378,6 +379,26 @@ static DOH *Hash_keys(DOH *so) {
return keys;
}
/* -----------------------------------------------------------------------------
* 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()
*
@ -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;
}

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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

View file

@ -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"

View file

@ -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()
*

View file

@ -527,7 +527,6 @@ String *Swig_string_schemify(String *s) {
return ns;
}
/* -----------------------------------------------------------------------------
* Swig_string_typecode()
*

View file

@ -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 -- */