lttng: Make use of "is_pic" event field in debug info analysis
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / internal / lttng2 / ust / core / analysis / debuginfo / UstDebugInfoBinaryFile.java
1 /*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo;
11
12 import java.util.Objects;
13
14 import org.eclipse.jdt.annotation.Nullable;
15
16 /**
17 * Wrapper class to reference to a particular binary, which can be an
18 * executable or library. It contains both the complete file path (at the
19 * time the trace was taken) and the build ID of the binary.
20 */
21 public class UstDebugInfoBinaryFile implements Comparable<UstDebugInfoBinaryFile> {
22
23 private final String fFilePath;
24 private final String fBuildId;
25 private final boolean fIsPic;
26 private final String fToString;
27
28 /**
29 * Constructor
30 *
31 * @param filePath
32 * The binary's path on the filesystem
33 * @param buildId
34 * The binary's unique buildID (in base16 form).
35 * @param isPic
36 * If the binary is position-independent or not
37 */
38 public UstDebugInfoBinaryFile(String filePath, String buildId, boolean isPic) {
39 fFilePath = filePath;
40 fBuildId = buildId;
41 fIsPic = isPic;
42
43 fToString = filePath + " (" + //$NON-NLS-1$
44 (fIsPic ? "PIC" : "non-PIC") + //$NON-NLS-1$ //$NON-NLS-2$
45 ", " + buildId + ')'; //$NON-NLS-1$
46 }
47
48 /**
49 * Get the file's path, as was referenced to in the trace.
50 *
51 * @return The file path
52 */
53 public String getFilePath() {
54 return fFilePath;
55 }
56
57 /**
58 * Get the build ID of the binary. It should be a unique identifier.
59 *
60 * On Unix systems, you can use <pre>eu-readelf -n [binary]</pre> to get
61 * this ID.
62 *
63 * @return The file's build ID.
64 */
65 public String getBuildId() {
66 return fBuildId;
67 }
68
69 /**
70 * Return whether the given file (binary or library) is Position-Independent
71 * Code or not.
72 *
73 * This indicates whether the symbols in the ELF are absolute or relative to
74 * the runtime base address, and determines which address we need to pass to
75 * 'addr2line'.
76 *
77 * @return Whether this file is position-independent or not
78 */
79 public boolean isPic() {
80 return fIsPic;
81 }
82
83 @Override
84 public String toString() {
85 return fToString;
86 }
87
88 @Override
89 public boolean equals(@Nullable Object obj) {
90 if (!(obj instanceof UstDebugInfoBinaryFile)) {
91 return false;
92 }
93 UstDebugInfoBinaryFile other = (UstDebugInfoBinaryFile) obj;
94 return (fFilePath.equals(other.fFilePath) &&
95 fBuildId.equals(other.fBuildId) &&
96 fIsPic == other.fIsPic);
97 }
98
99 @Override
100 public int hashCode() {
101 return Objects.hash(fBuildId, fFilePath, fIsPic);
102 }
103
104 /**
105 * Used for sorting. Sorts by using alphabetical order of the file
106 * paths.
107 */
108 @Override
109 public int compareTo(@Nullable UstDebugInfoBinaryFile o) {
110 if (o == null) {
111 return 1;
112 }
113 return fFilePath.compareTo(o.fFilePath);
114 }
115 }
This page took 0.0392 seconds and 5 git commands to generate.