[xsd-users] gdb macros for generated classes

Bill Pringlemeir bpringle at sympatico.ca
Wed Oct 14 12:32:04 EDT 2009


On 13 Oct 2009, boris at codesynthesis.com wrote:

> Adam Chase <adam.chase1 at gmail.com> writes:

>> I am trying to debug some code that uses xsd generated C++ classes and
>> would like to be able to print out their contents.

>> Are there any gdb macros that I can use to do so?

> I am not aware of anything like this. Printing of the content of any
> generated class would require a specific macro for each class. I don't 
> think this would scale. On the other hand, I can see how macros for 
> printing the container templates (one, optional, sequence) that are
> used by the generated code could be useful. This could be similar to
> the macros used to print STL containers.

There are some gdb environment values that will pretty print classes,
display/not display the vtable, etc. You can traverse many of the
values by using brackets and the confounded 'x_' member (afair).  It
is not necessary to use casts and doing so will generally give you
errors about the value not be available.

I had considered writing some macros and it *seems* that you could do
this with gdb.  I would guess that you have some complex type with say
an int, a string, and a restriction.  When you print this type, you
just get a bunch of,

   p  = {{ DOM:type int, x_}, { DOM:type string, x_}, { DOM:type string, x_}} 

I think you want,

   p = { 21, "foo", "bar" };

The above is not the exact output from gdb... but I think it covers
the dilemma?  The p in this case has three instances of the 'one'
type.  For users of XSD, the machinery of one, optional, sequence are
not usually too relevant.  Usually you need access to the data binding
values to debug an application layer problem.

These are rightfully hidden following good OO practices, but this
obfuscates debugging.  People might not wish to include debug printing
as this isn't needed in production.  Core dumps from production
environments may not have this, making intermittent problems difficult
to trace if this is the mechanism used.

All of the information is available in gdb.  In the above example,
there are many brackets, 'x_', '->', '.' and '*' which can get from
one form to the next.

fwiw,
Bill Pringlemeir.



More information about the xsd-users mailing list