{"id":16,"date":"2009-11-19T03:58:00","date_gmt":"2009-11-19T11:58:00","guid":{"rendered":"http:\/\/samueldotj.com\/blog\/?p=16"},"modified":"2013-09-04T14:48:29","modified_gmt":"2013-09-04T21:48:29","slug":"size-of-all-structures-in-your-program","status":"publish","type":"post","link":"http:\/\/samueldotj.com\/blog\/size-of-all-structures-in-your-program\/","title":{"rendered":"Size of all data structures in a C program"},"content":{"rendered":"<p>There are some cases when you want to find <strong>size<\/strong> of <strong>all data structures<\/strong> in your program\/project. For a given program it is easy because we can manually calculate or put a <em>printf <\/em><em>sizeof<\/em>() to calculate a few structures.  But for a project with few hundred files it is difficult. There is noway AFAIK in gcc to dump all the structure sizes while it compiles.<\/p>\n<p>Here is a way todo it using <strong>DWARF<\/strong> debugging info if you are using gnu compiler tools. Compile your project output file with <b>-g<\/b> option, this will generate debugging information in your program. Then run <strong>objdump<\/strong> to dump the debug info. This debugging information contains all the information about your program, filter the output for &#8220;<strong>DW_TAG_structure_type<\/strong>&#8221; and you will get only structure information.<\/p>\n<p>Here is how I did it:<br \/>\n[shell]<br \/>\nobjdump -W kernel.debug.reloc > debug.info<br \/>\ngrep -e &#8220;DW_TAG_structure_type&#8221; debug.info &#8211;after-context=5 &#8211;mmap > structs.txt<br \/>\n[\/shell]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are some cases when you want to find size of all data structures in your program\/project. For a given program it is easy because we can manually calculate or put a printf sizeof() to calculate a few structures. But for a project with few hundred files it is difficult. There is noway AFAIK in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,18,9],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-c","category-debugger","category-gcc"],"_links":{"self":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":3,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":192,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions\/192"}],"wp:attachment":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}