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 | ||
12 | import org.eclipse.jdt.annotation.Nullable; | |
13 | ||
14 | /** | |
15 | * Wrapper class to reference to a particular binary, which can be an | |
16 | * executable or library. It contains both the complete file path (at the | |
17 | * time the trace was taken) and the build ID of the binary. | |
18 | */ | |
19 | public final class UstDebugInfoBinaryFile implements Comparable<UstDebugInfoBinaryFile> { | |
20 | ||
21 | private final String filePath; | |
22 | private final String buildId; | |
23 | private final String toString; | |
24 | ||
25 | /** | |
26 | * Constructor | |
27 | * | |
28 | * @param filePath | |
29 | * The binary's path on the filesystem | |
30 | * @param buildId | |
31 | * The binary's unique buildID (in base16 form). | |
32 | */ | |
33 | public UstDebugInfoBinaryFile(String filePath, String buildId) { | |
34 | this.filePath = filePath; | |
35 | this.buildId = buildId; | |
36 | this.toString = new String(filePath + " (" + buildId + ')'); //$NON-NLS-1$ | |
37 | } | |
38 | ||
39 | /** | |
40 | * Get the file's path, as was referenced to in the trace. | |
41 | * | |
42 | * @return The file path | |
43 | */ | |
44 | public String getFilePath() { | |
45 | return filePath; | |
46 | } | |
47 | ||
48 | /** | |
49 | * Get the build ID of the binary. It should be a unique identifier. | |
50 | * | |
51 | * On Unix systems, you can use <pre>eu-readelf -n [binary]</pre> to get | |
52 | * this ID. | |
53 | * | |
54 | * @return The file's build ID. | |
55 | */ | |
56 | public String getBuildId() { | |
57 | return buildId; | |
58 | } | |
59 | ||
60 | @Override | |
61 | public String toString() { | |
62 | return toString; | |
63 | } | |
64 | ||
65 | @Override | |
66 | public boolean equals(@Nullable Object obj) { | |
67 | if (obj == null || !(obj instanceof UstDebugInfoBinaryFile)) { | |
68 | return false; | |
69 | } | |
70 | UstDebugInfoBinaryFile other = (UstDebugInfoBinaryFile) obj; | |
71 | if (this.filePath == other.filePath && | |
72 | this.buildId == other.buildId) { | |
73 | return true; | |
74 | } | |
75 | return false; | |
76 | } | |
77 | ||
78 | @Override | |
79 | public int hashCode() { | |
80 | final int prime = 31; | |
81 | int result = 1; | |
82 | result = prime * result + buildId.hashCode(); | |
83 | result = prime * result + filePath.hashCode(); | |
84 | return result; | |
85 | } | |
86 | ||
87 | /** | |
88 | * Used for sorting. Sorts by using alphabetical order of the file | |
89 | * paths. | |
90 | */ | |
91 | @Override | |
92 | public int compareTo(@Nullable UstDebugInfoBinaryFile o) { | |
93 | if (o == null) { | |
94 | return 1; | |
95 | } | |
96 | return this.filePath.compareTo(o.filePath); | |
97 | } | |
98 | } |