From a85c52f205d9f67ffa4c54197622d98f092db64e Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Mon, 26 Aug 2013 15:28:28 +0000 Subject: [PATCH] 2013-08-26 Raunaq Bathija Ulrich Weigand * xcoffread.c (arrange_linetable): Add fix to correctly handle line tables generated by XLC compiled binaries. --- gdb/ChangeLog | 6 ++++++ gdb/xcoffread.c | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 36bcbd5a86e..923fb89da0e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2013-08-26 Raunaq Bathija + Ulrich Weigand + + * xcoffread.c (arrange_linetable): Add fix to correctly handle + line tables generated by XLC compiled binaries. + 2013-08-23 Doug Evans * symmisc.c (dump_symtab): Delete prototype. diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index afe1554710f..224cba94263 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -437,6 +437,7 @@ arrange_linetable (struct linetable *oldLineTb) struct linetable_entry *fentry; /* function entry vector */ int fentry_size; /* # of function entries */ struct linetable *newLineTb; /* new line table */ + int extra_lines = 0; #define NUM_OF_FUNCTIONS 20 @@ -458,6 +459,12 @@ arrange_linetable (struct linetable *oldLineTb) fentry[function_count].line = ii; fentry[function_count].pc = oldLineTb->item[ii].pc; ++function_count; + + /* If the function was compiled with XLC, we may have to add an + extra line entry later. Reserve space for that. */ + if (ii + 1 < oldLineTb->nitems + && oldLineTb->item[ii].pc != oldLineTb->item[ii + 1].pc) + extra_lines++; } } @@ -474,7 +481,7 @@ arrange_linetable (struct linetable *oldLineTb) newLineTb = (struct linetable *) xmalloc (sizeof (struct linetable) + - (oldLineTb->nitems - function_count) * sizeof (struct linetable_entry)); + (oldLineTb->nitems - function_count + extra_lines) * sizeof (struct linetable_entry)); /* If line table does not start with a function beginning, copy up until a function begin. */ @@ -489,13 +496,26 @@ arrange_linetable (struct linetable *oldLineTb) for (ii = 0; ii < function_count; ++ii) { + /* If the function was compiled with XLC, we may have to add an + extra line to cover the function prologue. */ + jj = fentry[ii].line; + if (jj + 1 < oldLineTb->nitems + && oldLineTb->item[jj].pc != oldLineTb->item[jj + 1].pc) + { + newLineTb->item[newline] = oldLineTb->item[jj]; + newLineTb->item[newline].line = oldLineTb->item[jj + 1].line; + newline++; + } + for (jj = fentry[ii].line + 1; jj < oldLineTb->nitems && oldLineTb->item[jj].line != 0; ++jj, ++newline) newLineTb->item[newline] = oldLineTb->item[jj]; } xfree (fentry); - newLineTb->nitems = oldLineTb->nitems - function_count; + /* The number of items in the line table must include these + extra lines which were added in case of XLC compiled functions. */ + newLineTb->nitems = oldLineTb->nitems - function_count + extra_lines; return newLineTb; } -- 2.30.2