<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 1, 2014 at 10:59 AM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">+cfe-dev, bcc: llvm-dev<br>
<div class=""><br>
> On 2014-Jun-30, at 23:17, Matthias Goldhoorn <<a href="mailto:matthias.goldhoorn@uni-bremen.de">matthias.goldhoorn@uni-bremen.de</a>> wrote:<br>
><br>
> Dear dev's,<br>
> first sorry for this "user" question here, but i don't found a llvm-user Mailinglist. I hope it is okay to ask here.<br>
<br>
</div>This looks related to the clang API, so it probably belongs on cfe-dev<br>
[1], although cfe-users [2] is another possibility.<br>
<br>
[1]: <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
[2]: <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users</a><br>
<div><div class="h5"><br>
><br>
> Hi search for a way to dump the memory layout of a class/structure/datatype with clang (x64 primary target).<br>
> I have a simple application based on [1].<br></div></div></blockquote><div><br></div><div>Is Clang's -fdump-record-layouts flag sufficient for your needs?</div><div><div><br></div><div>$ cat t.cpp</div><div>struct A {</div>
<div> char a;</div><div> int b;</div><div>};</div><div>int x[sizeof(struct A)];</div><div><br></div><div>$ clang -c t.cpp -Xclang -fdump-record-layouts</div><div><br></div><div>*** Dumping AST Record Layout</div><div> 0 | struct A</div>
<div> 0 | char a</div><div> 4 | int b</div><div> | [sizeof=8, align=4</div><div> | nvsize=8, nvalign=4]</div></div><div><br></div><div>It's an undocumented -cc1 option so you have to escape it with -Xclang, and you need to use 'sizeof(MyStruct)' in the source code somewhere, but it's good for answering quick questions.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5">
> I also added this function<br>
><br>
><br>
> bool VisitFieldDecl(FieldDecl *F)<br>
> {<br>
> F->dump();<br>
> std::cerr << F->getQualifiedNameAsString() << " " << F->getBitWidthValue(*Context) << " " << std::endl;<br>
> F->dump() ;<br>
> std::cerr << "-----------------------------------------" << std::endl;<br>
> return true;<br>
> }<br>
><br>
><br>
> Unfortunately getBitWidthValue also returns zero for my types.<br>
><br>
> I need the complete memory-layout recursively for each class and all nested types. Including sizes/offsets.<br>
><br>
> Maybe the AST is the wrong place, and i need a other hook to start, can you give me some hints?<br>
><br>
> [1]: <a href="http://clang.llvm.org/docs/RAVFrontendAction.html" target="_blank">http://clang.llvm.org/docs/RAVFrontendAction.html</a><br>
><br>
> --<br>
> Dipl.-Inf. Matthias Goldhoorn<br>
> Space and Underwater Robotic<br>
><br>
> Universität Bremen<br>
> FB 3 - Mathematik und Informatik<br>
> AG Robotik<br>
> Robert-Hooke-Straße 5<br>
> 28359 Bremen, Germany<br>
><br>
> Tel.: <a href="tel:%2B49%20421%20178%2045-4193" value="+49421178454193">+49 421 178 45-4193</a><br>
> Zentrale: <a href="tel:%2B49%20421%20178%2045-6550" value="+49421178456550">+49 421 178 45-6550</a><br>
> Fax: <a href="tel:%2B49%20421%20178%2045-4150" value="+49421178454150">+49 421 178 45-4150</a><br>
> E-Mail:<br>
> <a href="mailto:matthias.goldhoorn@uni-bremen.de">matthias.goldhoorn@uni-bremen.de</a><br>
><br>
><br>
> Weitere Informationen:<br>
> <a href="http://www.informatik.uni-bremen.de/robotik" target="_blank">http://www.informatik.uni-bremen.de/robotik</a><br>
</div></div>> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>