how to dump easy-to-read structures from within C programs
Author |
Message |
Banibrata Dut #1 / 6
|
 how to dump easy-to-read structures from within C programs
hi, is there a way (apart from the ph2c or something), to programmatically dump the structure contents, in a format that closely resembles the actual structure, which could itself be composed of structures and sub-structures, i.e. in a manner the de{*filter*}s display, without writing my code for it ?? i know i must be wishing for too much... actually my structures are too big and too many to handcode their debug prints... thanks, bd
|
Tue, 22 Nov 2005 15:38:43 GMT |
|
 |
Richard B #2 / 6
|
 how to dump easy-to-read structures from within C programs
Quote:
> is there a way (apart from the ph2c or something), to > programmatically dump the structure contents, in a > format that closely resembles the actual structure, > which could itself be composed of structures and sub-structures, > i.e. in a manner the de{*filter*}s display, without writing > my code for it ??
Not defined by the Standard, no. There's no telling what your particular compiler might not provide, but ISO C, and therefore comp.lang.c, cannot tell you what individual compilers do beyond the call of the Standard. You'll have to read your manual or ask in a compiler-specific group. Richard
|
Tue, 22 Nov 2005 16:57:02 GMT |
|
 |
Thomas Matthew #3 / 6
|
 how to dump easy-to-read structures from within C programs
Quote:
> hi, > is there a way (apart from the ph2c or something), to > programmatically dump the structure contents, in a > format that closely resembles the actual structure, > which could itself be composed of structures and sub-structures, > i.e. in a manner the de{*filter*}s display, without writing > my code for it ?? > i know i must be wishing for too much... actually my > structures are too big and too many to handcode their > debug prints... > thanks, > bd
You could write a function that prints out a structure in human readable (and descriptive) form. If the structure is contained in another structure, call the function. Look at your de{*filter*}; perhaps it has the ability. -- Thomas Matthews C++ newsgroup welcome message: http://www.*-*-*.com/ ~shiva/welcome.txt C++ Faq: http://www.*-*-*.com/ ++-faq-lite C Faq: http://www.*-*-*.com/ ~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: http://www.*-*-*.com/ ++/faq.html Other sites: http://www.*-*-*.com/ -- C++ STL Library book
|
Tue, 22 Nov 2005 22:19:30 GMT |
|
 |
Richard Heathfiel #4 / 6
|
 how to dump easy-to-read structures from within C programs
Quote:
> hi, > is there a way (apart from the ph2c or something), to > programmatically dump the structure contents, in a > format that closely resembles the actual structure, > which could itself be composed of structures and sub-structures, > i.e. in a manner the de{*filter*}s display, without writing > my code for it ??
No way to do this is provided directly by the C language, but there is nothing to stop you writing code for it except time, skill, and enthusiasm. Quote: > i know i must be wishing for too much... actually my > structures are too big and too many to handcode their > debug prints...
The trick is to do them as you go along. :-) --
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999. C FAQ: http://www.*-*-*.com/ ~scs/C-faq/top.html K&R answers, C books, etc: http://www.*-*-*.com/
|
Wed, 23 Nov 2005 02:04:26 GMT |
|
 |
Banibrata Dut #5 / 6
|
 how to dump easy-to-read structures from within C programs
hi, Quote: > > i know i must be wishing for too much... actually my > > structures are too big and too many to handcode their > > debug prints... > The trick is to do them as you go along. :-)
i agree with all of you, but in a realistic software development environment, we need to deal with code written by others, who maynot have taken care to make their code very easy to debug... of course, writing the function that prints out every field and subfiled is the way to go, but was hoping to find some kludgy trick that might have made my life easier. it seems that ph2c came closest to what i wanted to do...
|
Wed, 23 Nov 2005 07:05:51 GMT |
|
 |
E. Gibbo #6 / 6
|
 how to dump easy-to-read structures from within C programs
Quote:
>hi, >is there a way (apart from the ph2c or something), to >programmatically dump the structure contents, in a >format that closely resembles the actual structure, >which could itself be composed of structures and sub-structures, >i.e. in a manner the de{*filter*}s display, without writing >my code for it ?? >i know i must be wishing for too much... actually my >structures are too big and too many to handcode their >debug prints...
The de{*filter*}, or some other tool that can analyze the source code, is the way to go here. Once C code is compiled, all the "interesting" information such as names of struct fields is lost. Be glad of this. The only thing you can do with structs if you don't have the ability to analyze the source code or write specialized "print methods" for each struct, is to print the raw bytes. The one piece of info you have is the size of the struct, in bytes, so without any other knowledge you can print the raw contents (including, possibly, irrelevant padding bytes). Sounds like you want something more friendly than a hex dump, though. There are tons of tools out there to help with this kind of "source code browsing" -- starting with your de{*filter*}. Frankly, if your source code is reasonably uniform so that you don't have a lot of hairy special cases to handle, you can probably write a simple tool yourself, in C or some other (off-topic) language such as Perl, to generate the source code of a "print method" for each type of struct in your header files, in a day or less. Try it! --Ben --
|
Tue, 06 Dec 2005 14:30:32 GMT |
|
|
|