Commit | Line | Data |
---|---|---|
ef7f180d AM |
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 | ||
d89151ba AM |
12 | import java.util.Objects; |
13 | ||
ef7f180d AM |
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 | */ | |
522dff53 | 21 | public class UstDebugInfoBinaryFile implements Comparable<UstDebugInfoBinaryFile> { |
ef7f180d | 22 | |
dc78189a MK |
23 | private final String fFilePath; |
24 | private final String fBuildId; | |
d89151ba | 25 | private final boolean fIsPic; |
dc78189a | 26 | private final String fToString; |
ef7f180d AM |
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). | |
d89151ba AM |
35 | * @param isPic |
36 | * If the binary is position-independent or not | |
ef7f180d | 37 | */ |
d89151ba | 38 | public UstDebugInfoBinaryFile(String filePath, String buildId, boolean isPic) { |
dc78189a MK |
39 | fFilePath = filePath; |
40 | fBuildId = buildId; | |
d89151ba AM |
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$ | |
ef7f180d AM |
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() { | |
dc78189a | 54 | return fFilePath; |
ef7f180d AM |
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() { | |
dc78189a | 66 | return fBuildId; |
ef7f180d AM |
67 | } |
68 | ||
d89151ba AM |
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 | ||
ef7f180d AM |
83 | @Override |
84 | public String toString() { | |
dc78189a | 85 | return fToString; |
ef7f180d AM |
86 | } |
87 | ||
88 | @Override | |
89 | public boolean equals(@Nullable Object obj) { | |
71788f49 | 90 | if (!(obj instanceof UstDebugInfoBinaryFile)) { |
ef7f180d AM |
91 | return false; |
92 | } | |
93 | UstDebugInfoBinaryFile other = (UstDebugInfoBinaryFile) obj; | |
d89151ba AM |
94 | return (fFilePath.equals(other.fFilePath) && |
95 | fBuildId.equals(other.fBuildId) && | |
96 | fIsPic == other.fIsPic); | |
ef7f180d AM |
97 | } |
98 | ||
99 | @Override | |
100 | public int hashCode() { | |
d89151ba | 101 | return Objects.hash(fBuildId, fFilePath, fIsPic); |
ef7f180d AM |
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 | } | |
dc78189a | 113 | return fFilePath.compareTo(o.fFilePath); |
ef7f180d AM |
114 | } |
115 | } |