[llvm-commits] [llvm] r173537 - Add DIContext::getLineInfoForAddressRange() function and test. This function allows a caller to obtain a table of line information for a function using the function's address and size.

NAKAMURA Takumi geek4civic at gmail.com
Fri Jan 25 17:48:34 PST 2013


2013/1/26 Andrew Kaylor <andrew.kaylor at intel.com>:
> Author: akaylor
> Date: Fri Jan 25 18:28:05 2013
> New Revision: 173537
>
> URL: http://llvm.org/viewvc/llvm-project?rev=173537&view=rev
> Log:
> Add DIContext::getLineInfoForAddressRange() function and test.  This function allows a caller to obtain a table of line information for a function using the function's address and size.
>
> Added:
>     llvm/trunk/test/DebugInfo/Inputs/test-parameters.o   (with props)
> Modified:
>     llvm/trunk/include/llvm/DebugInfo/DIContext.h
>     llvm/trunk/lib/DebugInfo/DWARFContext.cpp
>     llvm/trunk/lib/DebugInfo/DWARFContext.h
>     llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp
>     llvm/trunk/lib/DebugInfo/DWARFDebugLine.h
>     llvm/trunk/test/DebugInfo/debuglineinfo.test
>     llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp

> Modified: llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp?rev=173537&r1=173536&r2=173537&view=diff
> ==============================================================================
> --- llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp (original)
> +++ llvm/trunk/lib/DebugInfo/DWARFDebugLine.cpp Fri Jan 25 18:28:05 2013
> @@ -525,6 +525,81 @@ DWARFDebugLine::LineTable::lookupAddress
>  }
>
>  bool
> +DWARFDebugLine::LineTable::lookupAddressRange(uint64_t address,
> +                                       uint64_t size,
> +                                       std::vector<uint32_t>& result) const {
> +  if (Sequences.empty())
> +    return false;
> +  uint64_t end_addr = address + size;
> +  // First, find an instruction sequence containing the given address.
> +  DWARFDebugLine::Sequence sequence;
> +  sequence.LowPC = address;
> +  SequenceIter first_seq = Sequences.begin();
> +  SequenceIter last_seq = Sequences.end();
> +  SequenceIter seq_pos = std::lower_bound(first_seq, last_seq, sequence,
> +      DWARFDebugLine::Sequence::orderByLowPC);
> +  if (seq_pos == last_seq || seq_pos->LowPC != address) {
> +    if (seq_pos == first_seq)
> +      return false;
> +    seq_pos--;
> +  }
> +  if (!seq_pos->containsPC(address))
> +    return false;
> +
> +  SequenceIter start_pos = seq_pos;
> +
> +  // Add the rows from the first sequence to the vector, starting with the
> +  // index we just calculated
> +
> +  while (seq_pos != last_seq && seq_pos->LowPC < end_addr) {
> +    DWARFDebugLine::Sequence cur_seq = *seq_pos;
> +    uint32_t first_row_index;
> +    uint32_t last_row_index;
> +    if (seq_pos == start_pos) {
> +      // For the first sequence, we need to find which row in the sequence is the
> +      // first in our range. Rows are stored in a vector, so we may use
> +      // arithmetical operations with iterators.
> +      DWARFDebugLine::Row row;
> +      row.Address = address;
> +      RowIter first_row = Rows.begin() + cur_seq.FirstRowIndex;
> +      RowIter last_row = Rows.begin() + cur_seq.LastRowIndex;
> +      RowIter row_pos = std::upper_bound(first_row, last_row, row,
> +                                         DWARFDebugLine::Row::orderByAddress);
> +      // The 'row_pos' iterator references the first row that is greater than
> +      // our start address. Unless that's the first row, we want to start at
> +      // the row before that.
> +      first_row_index = cur_seq.FirstRowIndex + (row_pos - first_row);
> +      if (row_pos != first_row)
> +        --first_row_index;
> +    } else
> +      first_row_index = cur_seq.FirstRowIndex;
> +
> +    // For the last sequence in our range, we need to figure out the last row in
> +    // range.  For all other sequences we can go to the end of the sequence.
> +    if (cur_seq.HighPC > end_addr) {
> +      DWARFDebugLine::Row row;
> +      row.Address = end_addr;
> +      RowIter first_row = Rows.begin() + cur_seq.FirstRowIndex;
> +      RowIter last_row = Rows.begin() + cur_seq.LastRowIndex;
> +      RowIter row_pos = std::upper_bound(first_row, last_row, row,
> +                                         DWARFDebugLine::Row::orderByAddress);
> +      // The 'row_pos' iterator references the first row that is greater than
> +      // our end address.  The row before that is the last row we want.
> +      last_row_index = cur_seq.FirstRowIndex + (row_pos - first_row) - 1;
> +    } else
> +      // Contrary to what you might expect, DWARFDebugLine::SequenceLastRowIndex
> +      // isn't a valid index within the current sequence.  It's that plus one.
> +      last_row_index = cur_seq.LastRowIndex - 1;
> +
> +    for (uint32_t i = first_row_index; i <= last_row_index; ++i) {
> +      result.push_back(i);
> +    }
> +
> +    ++seq_pos;
> +  }

Did you forget "return true;"? Fixed in r173552.

> +}

...Takumi



More information about the llvm-commits mailing list