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

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