Bug 575368 - Exception when opening GCov coverage files on Cygwin GCC
- in some cases (especially with optimization), inlined code will
show up in the TAG_LINES whereby another source file will be
referenced and we will add 0, source index to the lineno info
- fix SourceFile.createLines() to keep track of when the source index
switches and use a local SourceFile instance to access the correct
lines ArrayList
- add a new method initializeLines() to SourceFile to ensure that the
ArrayList gets sets up at least once
- change CovManager.processCovFiles() to pass allSrcs to
the SourceFile.createFiles() method so it can access any source
file it needs to
Change-Id: I733061c1e91db2a81ad1703c99b998f73bd315d4
Reviewed-on: https://git.eclipse.org/r/c/linuxtools/org.eclipse.linuxtools/+/184549
Tested-by: Linux Tools Bot <linuxtools-bot@eclipse.org>
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
diff --git a/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/CovManager.java b/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/CovManager.java
index 153a76b..e670652 100644
--- a/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/CovManager.java
+++ b/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/CovManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2018 STMicroelectronics and others.
+ * Copyright (c) 2009, 2021 STMicroelectronics and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -185,7 +185,7 @@
// allocate lines
for (SourceFile sourceFile : allSrcs) {
- sourceFile.createLines();
+ sourceFile.createLines(allSrcs);
}
// add line counts
diff --git a/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/SourceFile.java b/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/SourceFile.java
index 9ebbdd6..7edd2d4 100644
--- a/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/SourceFile.java
+++ b/gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/parser/SourceFile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2019 STMicroelectronics and others.
+ * Copyright (c) 2009, 2021 STMicroelectronics and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -102,23 +102,41 @@
return index;
}
- public void createLines() {
- int n = getNumLines();
- lines.ensureCapacity(n);
- for (int j = 0; j < n; j++) {
- lines.add(new Line());
- }
+ public void initializeLines() {
+ if (lines.isEmpty()) {
+ int n = getNumLines();
+ lines.ensureCapacity(n);
+ for (int j = 0; j < n; j++) {
+ lines.add(new Line());
+ }
+ }
+ }
+
+ public void createLines(ArrayList<SourceFile> allSrcs) {
+ initializeLines();
+ SourceFile source = this;
for (GcnoFunction fn : getFnctns()) {
for (Block b : fn.getFunctionBlocks()) {
long[] blockLines = b.getEncoding();
if (blockLines == null) {
continue;
}
- for (int i = 2; i < blockLines.length; ++i) {
+ for (int i = 0; i < blockLines.length; ++i) {
long lineno = blockLines[i];
+ if (lineno == 0) {
+ if (i < blockLines.length - 2) {
+ long sourceIndex = blockLines[i + 1];
+ if (sourceIndex != 0) {
+ source = allSrcs.get((int) (sourceIndex - 1));
+ source.initializeLines();
+ lineno = blockLines[i + 2];
+ i += 2;
+ }
+ }
+ }
if (lineno == 0)
break;
- Line line = lines.get((int) lineno);
+ Line line = source.getLines().get((int) lineno);
line.addBlock(b);
}
}