Skip to content

Commit

Permalink
Replace individual linesrc calls with srcfiles, allowing libdwarf to …
Browse files Browse the repository at this point in the history
…allocate once and us to do lookups by index rather than strcmp.
  • Loading branch information
wrwilliams committed Oct 31, 2016
1 parent 8bb77b2 commit 74febd6
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions symtabAPI/src/Object-elf.C
Expand Up @@ -4324,14 +4324,18 @@ void Object::parseLineInfoForCU(Dwarf_Die cuDIE, LineInformation* li_for_module)
}

assert( status == DW_DLV_OK );
char** srcfiles;
Dwarf_Signed fileCount;

status = dwarf_srcfiles(cuDIE, &srcfiles, &fileCount, NULL);
/* The 'lines' returned are actually interval markers; the code
generated from lineNo runs from lineAddr up to but not including
the lineAddr of the next line. */
bool isPreviousValid = false;
Dwarf_Unsigned previousLineNo = 0;
Dwarf_Signed previousLineColumn = 0;
Dwarf_Addr previousLineAddr = 0x0;
char * previousLineSource = NULL;
Dwarf_Unsigned previousLineSource = NULL;

Offset baseAddr = getBaseAddress();

Expand Down Expand Up @@ -4371,8 +4375,10 @@ void Object::parseLineInfoForCU(Dwarf_Die cuDIE, LineInformation* li_for_module)


char * lineSource;
status = dwarf_linesrc( lineBuffer[i], & lineSource, NULL );
Dwarf_Unsigned srcfileindex;
status = dwarf_line_srcfileno(lineBuffer[i], &srcfileindex, NULL);
if ( status != DW_DLV_OK ) { continue; }
lineSource = srcfiles[srcfileindex];

Dwarf_Bool isEndOfSequence;
status = dwarf_lineendsequence( lineBuffer[i], & isEndOfSequence, NULL );
Expand All @@ -4383,26 +4389,20 @@ void Object::parseLineInfoForCU(Dwarf_Die cuDIE, LineInformation* li_for_module)
/* If we're talking about the same (source file, line number) tuple,
and it isn't the end of the sequence, we can coalesce the range.
(The end of sequence marker marks discontinuities in the ranges.) */
if ( lineNo == previousLineNo && strcmp( lineSource, previousLineSource ) == 0
if ( lineNo == previousLineNo && ( srcfileindex == previousLineSource )
&& ! isEndOfSequence )
{
/* Don't update the prev* values; just keep going until we hit the end of
a sequence or new sourcefile. */
continue;
} /* end if we can coalesce this range */

char *canonicalLineSource;
char *canonicalLineSource = srcfiles[previousLineSource];
if (truncateLineFilenames) {
canonicalLineSource = strrchr( previousLineSource, '/' );
if( canonicalLineSource == NULL ) { canonicalLineSource = previousLineSource; }
canonicalLineSource = strrchr( srcfiles[previousLineSource], '/' );
if( canonicalLineSource == NULL ) { canonicalLineSource = srcfiles[previousLineSource]; }
else { ++canonicalLineSource; }
}
else {
canonicalLineSource = previousLineSource;
}




Dyninst::Offset startAddrToUse = previousLineAddr;
Dyninst::Offset endAddrToUse = lineAddr;
Expand All @@ -4428,9 +4428,8 @@ void Object::parseLineInfoForCU(Dwarf_Die cuDIE, LineInformation* li_for_module)
isPreviousValid = false;
}
else {
if( isPreviousValid ) { dwarf_dealloc( dbg, previousLineSource, DW_DLA_STRING ); }
previousLineNo = lineNo;
previousLineSource = lineSource;
previousLineSource = srcfileindex;
previousLineAddr = lineAddr;
previousLineColumn = lineOff;

Expand All @@ -4440,6 +4439,11 @@ void Object::parseLineInfoForCU(Dwarf_Die cuDIE, LineInformation* li_for_module)

/* Free this CU's source lines. */
dwarf_srclines_dealloc(dbg, lineBuffer, lineCount);
for(int i = 0; i < fileCount; ++i)
{
dwarf_dealloc(dbg, srcfiles[i], DW_DLA_STRING);
}
dwarf_dealloc(dbg, srcfiles, DW_DLA_LIST);
}


Expand Down

0 comments on commit 74febd6

Please sign in to comment.