<div dir="ltr">(I'll leave this for a bit to let Adrian and others chime in, hopefully)<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Aug 8, 2017 at 1:40 AM George Rimar <<a href="mailto:grimar@accesssoftek.com">grimar@accesssoftek.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p><span style="color:rgb(33,33,33);font-size:12pt">>Too much/slow? I'd be surprised if it was very expensive to do a single loop over the sections (~hundreds of sections in an object file? Fewer in a linked executable), >maybe lazily (when the first
range is rendered) - it'd only happen once for the whole dump run (& add a lookup in the resulting map for each range entry dumping - >which, yeah, that's something, but still). dwarfdump's an interactive/user-focussed tool, it probably takes longer to print
things to the terminal than most of this >computation. (& longer still for the user to read it, etc)</span><br>
</p>
<p><span style="color:rgb(33,33,33);font-size:12pt"><br>
</span></p>
</div><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><p><span style="color:rgb(33,33,33);font-size:12pt">May be. What I was mean by "too much" is that I have feeling that scaning over all sections</span></p>
<p><font color="#212121">anyways should be not neccessary for printing nice output here. I don't see the reasons for additional code compliction.</font></p></div></blockquote><div><br>The reason is to make the output simpler/easier to read - omitting information that's not adding value where possible. It's certainly the benefit isn't worth the extra complexity, but I imagine it's not too bad.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p><font color="#212121">There are probably 2 possible cases:</font></p>
<p><font color="#212121">Print ".<a href="http://section.name" target="_blank">section.name</a> [index]" or "[index] .<a href="http://section.name" target="_blank">section.name</a>". For latter case we do not need to scan over all sections to</font></p>
<p><font color="#212121">columnize the "[index]" as we can just use total amount of sections to calculate padding. So why not to use this form ?</font></p></div></blockquote><div>I think that form's probably OK for the cases where the index is helpful (though does feel a bit convoluted/awkward, putting the index before the name)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div dir="ltr">
<div class="gmail_quote">
<div> </div>
<div><span style="font-size:12pt">>>I would not omit something dependent on third conditions too, because it makes logic of output unclear for</span><span style="font-size:12pt">people that are not familar with tool. ("Why it prints >>section index for
"foo" and does not for "bar" ? BUUUG !")</span></div></div></div></div></div></div><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote">
<div>><br>
>Not sure it'd be particulary bug-like if the section numbers were only shown when the section names were ambiguous. Given two examples it would seem fairly >clear to me, I think, that the numbers were added to disambiguate two sections with the same name.<br>
<br>
</div>
</div></div></div></div></div><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote"><div>If somebody going to parse tool's output then it is easier to have <span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">consistent</span> format.<br></div></div></div></div></div></div></blockquote><div><br>This info's probably not ideal for tool consumption anyway - the ranges are multi-line output, embedded within the DWARF DIE dumping, etc. & we have nice APIs to use instead :)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote"><div>
</div>
<div>Also (I'll show below) it can be not convinent or impossible to search for a section by name in a section table, </div>
<div>so if we are going to print <span style="font-size:12pt">section index at least </span><span style="font-size:12pt">in some cases, I think it worth then to print it in all cases</span><span style="font-size:12pt">.</span></div></div></div></div></div></div></blockquote><div><br>Sure - that's why I was suggesting that the indexes be omitted only when the section name is unambiguous (hence the need to walk all the sections up-front to count how many times each name appears).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote">
<div><br>
</div>
</div>
<div class="gmail_quote"></div></div></div></div></div><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote">>>Also I think often I am looking for section number in readelf/objdump/other tools,
<div>><br>
>Really? That surprises me - why are the section numbers of interest to you? For myself I'm usually interested in the section name.</div>
<div><br>
</div>
</div></div></div></div></div><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote"><div>Ah, section name is often a final point of interest for sure, but numbers are very important to have. See:</div>
<div><br>
</div>
<div>When I do readelf -a for some file and look at symbol table, I see section index "1" for "main",<br>
</div>
<div>using it's index then I can look into section table.<br>
</div>
<div>
<div>Symbol table '.symtab' contains 16 entries:</div>
<div> Num: Value Size Type Bind Vis Ndx Name</div>
<div> 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND </div>
<div> 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS main.c<br>
</div>
<div>....<br>
</div>
<div> 13: 0000000000000000 21 FUNC GLOBAL DEFAULT 1 main<br>
</div>
<div><br>
<span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">But if we would have only name here, like:</span><br>
</div>
<div><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">13:
0000000000000000 21 FUNC GLOBAL DEFAULT ".text.foobar" main</span><br>
</span></div>
<div><br>
</div>
It would be harder or impossible to find it by name in section table.</div>
<div>For example, below is output of following:<br>
</div>
<div>ar -x libclangAnalysis.a <br>
readelf -a ReachableCode.cpp.o<br>
</div>
<div><br>
</div>
<div>
<div>Section Headers:</div>
<div> [Nr] Name Type Address Offset</div>
<div> Size EntSize Flags Link Info Align</div>
<div> [ 0] NULL 0000000000000000 00000000</div>
<div> 0000000000000000 0000000000000000 0 0 0</div>
<div> [ 1] .strtab STRTAB 0000000000000000 003e8080</div>
<div> 00000000000094e9 0000000000000000 0 0 1</div>
<div> [ 2] .text PROGBITS 0000000000000000 00000040</div>
<div> 0000000000002c96 0000000000000000 AX 0 0 16</div>
<div> [ 3] .rela.text RELA 0000000000000000 002a7818</div>
<div> 0000000000001c38 0000000000000018 1486 2 8</div>
<div> [ 4] .group GROUP 0000000000000000 0029ede0</div>
<div> 0000000000000008 0000000000000004 1486 1136 4</div>
<div> [ 5] .text PROGBITS 0000000000000000 00002ce0</div>
<div> 0000000000000011 0000000000000000 AXG 0 0 16</div>
<div> [ 6] .group GROUP 0000000000000000 0029ede8</div>
<div> 000000000000000c 0000000000000004 1486 968 4</div>
<div> [ 7] .text PROGBITS 0000000000000000 00002d00</div>
<div> 00000000000000a7 0000000000000000 AXG 0 0 16<br>
</div>
<div><~1500 the same sections here skpped.><br>
</div>
.....</div>
<div><br>
</div>
<div>As you can see section name can be not enough.<br>
</div></div></div></div></div></div><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote">
<div><br>
</div>
<div><br>
</div>
<div>>I'd skip printing it entirely if it's empty. 'Section: ""' doesn't seem helpful.<br>
><br>
</div>
<div>>I think printing it on the same line without the "Section: " prefix, as it was in your first version, is probably better when it is per-line.<br>
><br>
</div>
<div>>I guess maybe you're optimizing this for the case where some set of ranges share the same section (so it prints a "Section: "x"" header and then all the ranges in >that section? (or all the ranges in that section that are contiguous until another section
change?)? Though I don't see a test case for that (multiple sections, some >ranges next to each other in the same section).<br>
></div>
<div><br>
</div>
</div></div></div></div></div><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote"><div>You earlier wrote: "<span style="color:rgb(70,76,92);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">& what about omitting the
name or putting it somewhere else (like at the start on a separate line) if every entry is in the same section? (which will be the case for all ranges except the compile_unit ranges, most likely)</span>", so that is what I tried to implement.<br>
</div></div></div></div></div></div><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote">
<div><br>
>But I don't think that's a scenario we realy need to optimize for - it's going to be pretty rare that a list contains both multiple sections and distinct ranges in the >same section. (function/scope ranges will contain ranegs all from the same section and
CU ranges will /mostly/ contain all ranges from distinct sections - except in >cases of nodebug functions putting holes in the range)<br>
<br>
</div></div></div></div></div></div><div dir="ltr" style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div dir="ltr"><div class="gmail_quote">
George.<br>
</div></div></div></div></div></blockquote></div></div>