SourceAddress do_lookup(TargetAddress address, int start_pos, int end_pos)
{
if (end_pos - start_pos >= 4) {
int middle_pos = (start_pos + end_pos) / 2;
LineNumber middle = (LineNumber) addresses [middle_pos];
TargetAddress maddr = comp_unit.dwarf.GetAddress (middle.Offset);
if (address < maddr)
return do_lookup (address, start_pos, middle_pos);
else
return do_lookup (address, middle_pos, end_pos);
}
TargetAddress next_address;
if (end_pos == addresses.Length)
next_address = comp_unit.EndAddress;
else {
LineNumber end_line = addresses [end_pos];
next_address = comp_unit.dwarf.GetAddress (end_line.Offset);
}
for (int i = end_pos-1; i >= start_pos; i--) {
LineNumber line = addresses [i];
int range = (int) (next_address - address);
next_address = comp_unit.dwarf.GetAddress (line.Offset);
if (next_address > address)
continue;
int offset = (int) (address - next_address);
FileEntry file = (FileEntry) source_files [line.File - 1];
return new SourceAddress (
file.File, null, line.Line, offset, range);
}
return null;
}