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