If you haven't already found it, you should look inside tools/llvm-objdump/llvm-objdump.cpp, which is an easy-to-follow example of how these APIs work<div><br></div><div>--Sean Silva.<br><br><div class="gmail_quote">On Mon, Jun 11, 2012 at 5:41 PM, Marshall Clow <span dir="ltr"><<a href="mailto:mclow.lists@gmail.com" target="_blank">mclow.lists@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So, I'm trying to use this file to look inside COFF files.<br>
Got the header. OK.<br>
<br>
Now I want to look at the sections.<br>
Look, there's a section iterator. I can use that!<br>
<br>
So, I write:<br>
for (llvm::object::section_iterator iter = Obj.begin_sections (); iter != Obj.end_sections(); ++iter )<br>
<br>
and it doesn't compile. There's no ++ for section iterators.<br>
Apparently, you're supposed to write.<br>
for (llvm::object::section_iterator iter = Obj.begin_sections (); iter != Obj.end_sections(); iter.increment(ec))<br>
Srsly?<br>
[ And - how do I go from a section_iterator to a coff_section ? ]<br>
<br>
While I'm puzzling over that, I look some more, and I see:<br>
error_code getSection(int32_t index, const coff_section *&Res) const;<br>
<br>
Cool. (A bit weird; why a signed index?, but whatever)<br>
So I write:<br>
const llvm::object::coff_section *sect;<br>
for (std::size_t i = 0; i < NumSections; ++i)<br>
Obj.getSection(i, sect);<br>
<br>
And my program dies with a segmentation fault.<br>
Turns out that sect == NULL.<br>
More looking, I see that the sections are numbered 1 … N, not 0 ... N-1<br>
<br>
Now I'm really really confused. Why?<br>
<br>
BTW - patch attached to add pre-increment to llvm::content_iterator (which is the template base for section_iterator, etc)<br>
<span class="HOEnZb"><font color="#888888"><br>
-- Marshall<br>
<br>
<br>
</font></span><br><br>
<br>
-- Marshall<br>
<br>
Marshall Clow Idio Software <mailto:<a href="mailto:mclow.lists@gmail.com">mclow.lists@gmail.com</a>><br>
<br>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).<br>
-- Yu Suzuki<br>
<br>
<br>_______________________________________________<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></blockquote></div><br></div>