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 | */ | |
522dff53 | 19 | public class UstDebugInfoBinaryFile implements Comparable<UstDebugInfoBinaryFile> { |
ef7f180d | 20 | |
dc78189a MK |
21 | private final String fFilePath; |
22 | private final String fBuildId; | |
23 | private final String fToString; | |
ef7f180d AM |
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) { | |
dc78189a MK |
34 | fFilePath = filePath; |
35 | fBuildId = buildId; | |
36 | fToString = new String(filePath + " (" + buildId + ')'); //$NON-NLS-1$ | |
ef7f180d AM |
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() { | |
dc78189a | 45 | return fFilePath; |
ef7f180d AM |
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() { | |
dc78189a | 57 | return fBuildId; |
ef7f180d AM |
58 | } |
59 | ||
60 | @Override | |
61 | public String toString() { | |
dc78189a | 62 | return fToString; |
ef7f180d AM |
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; | |
dc78189a MK |
71 | return (fFilePath == other.fFilePath && |
72 | fBuildId == other.fBuildId); | |
ef7f180d AM |
73 | } |
74 | ||
75 | @Override | |
76 | public int hashCode() { | |
77 | final int prime = 31; | |
78 | int result = 1; | |
dc78189a MK |
79 | result = prime * result + fBuildId.hashCode(); |
80 | result = prime * result + fFilePath.hashCode(); | |
ef7f180d AM |
81 | return result; |
82 | } | |
83 | ||
84 | /** | |
85 | * Used for sorting. Sorts by using alphabetical order of the file | |
86 | * paths. | |
87 | */ | |
88 | @Override | |
89 | public int compareTo(@Nullable UstDebugInfoBinaryFile o) { | |
90 | if (o == null) { | |
91 | return 1; | |
92 | } | |
dc78189a | 93 | return fFilePath.compareTo(o.fFilePath); |
ef7f180d AM |
94 | } |
95 | } |