<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jun 11, 2012, at 7:39 PM, Sean Silva wrote:</div><blockquote type="cite">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</blockquote><div><br></div>I had found that - and sadly, it doesn't do what I need to do.</div><div>In particular, I don't see how to get a coff_section from a section_iterator (and llvm-objdump doesn't do that, either)</div><div><br></div><div>At the moment, I want to read the section characteristics and the raw data.</div><div>I guess I can use the index-based calls rather than the iterator-based ones. (One-based? Really?)</div><div><br></div><div>Seems like a shame, though. Why have two different sets of functionality here?</div><div><br></div><div>Thanks, though.</div><div><br></div><div>-- Marshall</div><div><br></div><div><br></div><div><blockquote type="cite"><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-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">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><font class="Apple-style-span" color="#888888"><br></font></blockquote></div></div>
</blockquote></div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">-- Marshall<br><br>Marshall Clow     Idio Software   <<a href="mailto:mclow.lists@gmail.com">mailto: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</span>
</div>
<br></body></html>