<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 3, 2017, at 1:47 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, May 3, 2017 at 1:43 PM Greg Clayton via Phabricator <<a href="mailto:reviews@reviews.llvm.org" class="">reviews@reviews.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">clayborg added a comment.<br class="">
<br class="">
One thing to clarify:<br class="">
<br class="">
  std::vector<RangeInfoType> DieRangeInfos;<br class="">
<br class="">
is a vector that only gets as deep as the DIE depth. It doesn't get every range for every function, block, or inlined function, it just has a stack of ranges for the _current_ DIE depth.<br class=""></blockquote><div class=""><br class="">Which is part of what I'm confused by - I wouldn't expect to see/don't understand why there's any code that special-cases subprograms here. They don't seem special to me.<br class=""></div></div></div></div></blockquote><div><br class=""></div>They are special because they are top level functions. DW_TAG_subprogram appear at any depth and their parent isn't always a DW_TAG_compile_unit. So we might have DWARF like:</div><div><br class=""></div><div>0x0000000b: DW_TAG_compile_unit [1] *<br class="">             DW_AT_low_pc( 0x0000000000001000 )</div><div>             DW_AT_high_pc( 0x0000000000003000 )</div><div>             DW_AT_name( "/tmp/main.c" )</div><div><br class="">0x00000020:     DW_TAG_subprogram [2] *</div><div>                 DW_AT_name( "main" )</div><div>                 DW_AT_low_pc( 0x0000000000001000 )</div><div>                 DW_AT_high_pc( 0x0000000000002000 )</div><div><br class="">0x00000035:         DW_TAG_lexical_block [3]  </div><div>                     DW_AT_low_pc( 0x0000000000001100 )</div><div>                     DW_AT_high_pc( 0x0000000000001200 )</div><div><br class="">0x00000046:         NULL<br class=""><br class="">0x00000047:     DW_TAG_class_type [4] *</div><div>                 DW_AT_low_pc( 0x0000000000001000 )</div><div>                 DW_AT_name( "Foo" )</div><div><br class="">0x00000054:         DW_TAG_subprogram [2] *</div><div>                     DW_AT_name( "Bar" )</div><div>                     DW_AT_low_pc( 0x0000000000002000 )</div><div>                     DW_AT_high_pc( 0x0000000000003000 )</div><div><br class="">0x00000069:             DW_TAG_lexical_block [3]  </div><div>                         DW_AT_low_pc( 0x0000000000002100 )</div><div>                         DW_AT_high_pc( 0x0000000000002200 )</div><div><br class="">0x0000007a:             NULL<br class=""><br class="">0x0000007b:         NULL<br class=""><br class="">0x0000007c:     NULL<br class=""><br class=""></div><div>When visiting the DW_TAG_subprogram at 0x00000020 we would do:</div><div><br class=""></div><div>Depth = Die.getDepth(); // depth will be 1</div><div>if (!DieRangeInfos[0].Ranges.empty())</div><div>  assert(DieRangeInfos[0].Contains(DieRangeInfos[Depth].Ranges)</div><div><br class=""></div><div>since 0x00000020 is at depth 1</div><div><br class=""></div><div>Our DieRangeInfos stack would be:</div><div><br class=""></div><div>DieRangeInfos[0] = DW_TAG_compile_unit [0x0000000000001000 - 0x0000000000003000)</div><div>DieRangeInfos[1] = DW_TAG_subprogram   [0x0000000000001000 - 0x0000000000002000)</div><div><br class=""></div><div>When visiting the DW_TAG_lexical_block at 0x00000035 we would only check:</div><div><br class=""></div><div>assert(DieRangeInfos[Depth-1].Contains(DieRangeInfos[Depth].Ranges))</div><div><br class=""></div><div><div>Our DieRangeInfos stack would be:</div><div><br class=""></div><div>DieRangeInfos[0] = DW_TAG_compile_unit [0x0000000000001000 - 0x0000000000003000)</div><div><div>DieRangeInfos[1] = DW_TAG_subprogram   [0x0000000000001000 - 0x0000000000002000)</div><div class=""><div>DieRangeInfos[2] = DW_TAG_lexical_block[0x0000000000001100 - 0x0000000000001200)</div></div><div class=""><br class=""></div><div class="">When visiting 0x00000054 we would again check against the compile units ranges:</div><div class=""><br class=""></div><div class=""><div>Depth = Die.getDepth(); // depth will be 2</div><div>if (!DieRangeInfos[0].Ranges.empty())</div><div>  assert(DieRangeInfos[0].Contains(DieRangeInfos[Depth].Ranges)</div></div><div class=""><br class=""></div></div></div><div><div>DieRangeInfos[0] = DW_TAG_compile_unit [0x0000000000001000 - 0x0000000000003000)</div><div><div>DieRangeInfos[1] = DW_TAG_class_type</div><div class=""><div>DieRangeInfos[2] = DW_TAG_subprogram   [0x0000000000002000 - 0x0000000000003000)</div></div><div class=""><br class=""></div><div class="">Then visiting 0x00000069 we do:</div><div class=""><br class=""></div><div class=""><div>assert(DieRangeInfos[Depth-1].Contains(DieRangeInfos[Depth].Ranges))</div></div><div class=""><br class=""></div></div></div><div><div>DieRangeInfos[0] = DW_TAG_compile_unit [0x0000000000001000 - 0x0000000000003000)</div><div><div>DieRangeInfos[1] = DW_TAG_class_type</div><div class=""><div>DieRangeInfos[2] = DW_TAG_subprogram   [0x0000000000002000 - 0x0000000000003000)</div></div><div class=""><div class=""><div>DieRangeInfos[3] = DW_TAG_lexical_block[0x0000000000002100 - 0x0000000000002200)</div></div></div><div class=""><br class=""></div><div class=""><br class=""></div></div><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_quote"><div class="">I'd expect an algorithm that starts at the CU DIE and looks for any DIE that has ranges. It wouldn't need special cases for any tag types.<br class=""></div></div></div></blockquote><br class=""></div><div>You only need to verify your range against something your parent. For some, like a DW_TAG_subprogram, it must be in the DW_TAG_compile_unit only if it has ranges. For DW_TAG_lexical_block and DW_TAG_inlined_subroutine, they MUST be in their parents if their ranges are valid.</div><div><br class=""></div><div>It is also possible in other languages to have functions declared inside of functions. In that case you want to only verify against your parent and stop at the DW_TAG_subprogram level. You could have a stack like:</div><div><br class=""></div><div><br class=""></div><div><div>DieRangeInfos[0] = DW_TAG_compile_unit [0x0000000000001000 - 0x0000000000003000)</div><div><div>DieRangeInfos[1] = DW_TAG_subprogram   [0x0000000000001000 - 0x0000000000002000)</div><div class=""><div>DieRangeInfos[2] = DW_TAG_lexical_block[0x0000000000001100 - 0x0000000000001200)</div></div><div class=""><div>DieRangeInfos[3] = DW_TAG_subprogram   [0x0000000000003000 - 0x0000000000004000)</div><div class=""></div></div></div></div><div><div class=""><div>DieRangeInfos[4] = DW_TAG_lexical_block[0x0000000000003100 - 0x0000000000003200)</div></div><div><br class=""></div><div>You would only want to see if:</div><div>- [4] is in [3]</div><div>- [2] is in [1]</div><div>- [3] and [1] are in [0]</div><div><br class=""></div><div>Make sense?</div><div class=""><br class=""></div><div class=""></div></div></body></html>