ust.core: add NON-NLS to toString of UstDebugInfoBinaryFile
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / 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.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 * @author Alexandre Montplaisir
22 * @noreference Meant to be used internally by the analysis only
23 */
24 public class UstDebugInfoBinaryFile implements Comparable<UstDebugInfoBinaryFile> {
25
26 private final String fFilePath;
27 private final @Nullable String fBuildId;
28 private final @Nullable String fDebugLink;
29 private final boolean fIsPic;
30
31 /**
32 * Constructor
33 *
34 * @param filePath
35 * The binary's path on the filesystem.
36 * @param buildId
37 * The binary's unique buildID (in base16 form).
38 * @param debugLink
39 * Path to the binary's separate debug info.
40 * @param isPic
41 * Whether the code in the binary is position-independent.
42 */
43 public UstDebugInfoBinaryFile(String filePath, @Nullable String buildId,
44 @Nullable String debugLink, boolean isPic) {
45 fFilePath = filePath;
46 fBuildId = buildId;
47 fDebugLink = debugLink;
48 fIsPic = isPic;
49 }
50
51 /**
52 * Get the file's path, as was referenced to in the trace.
53 *
54 * @return The file path
55 */
56 public String getFilePath() {
57 return fFilePath;
58 }
59
60 /**
61 * Get the build ID of the binary. It should be a unique identifier.
62 *
63 * On Unix systems, you can use <pre>eu-readelf -n [binary]</pre> to get
64 * this ID.
65 *
66 * @return The file's build ID, or null if the file has no build ID..
67 */
68 public @Nullable String getBuildId() {
69 return fBuildId;
70 }
71
72 /**
73 * Get the path to the separate debug info of this binary.
74 *
75 * @return The path to the separate debug info, or null if the file has no
76 * separate debug info.
77 */
78 public @Nullable String getDebugLink() {
79 return fDebugLink;
80 }
81
82 /**
83 * Return whether the given file (binary or library) is Position-Independent
84 * Code or not.
85 *
86 * This indicates whether the symbols in the ELF are absolute or relative to
87 * the runtime base address, and determines which address we need to pass to
88 * 'addr2line'.
89 *
90 * @return Whether this file is position-independent or not
91 */
92 public boolean isPic() {
93 return fIsPic;
94 }
95
96 @Override
97 public String toString() {
98 return com.google.common.base.Objects.toStringHelper(this)
99 .add("path", fFilePath) //$NON-NLS-1$
100 .add("build_id", fBuildId) //$NON-NLS-1$
101 .add("debug_link", fDebugLink) //$NON-NLS-1$
102 .add("is_pic", fIsPic) //$NON-NLS-1$
103 .toString();
104 }
105
106 @Override
107 public int hashCode() {
108 return Objects.hash(fFilePath, fBuildId, fDebugLink, fIsPic);
109 }
110
111 @Override
112 public boolean equals(@Nullable Object obj) {
113 if (this == obj) {
114 return true;
115 }
116 if (obj == null) {
117 return false;
118 }
119 if (!(getClass().equals(obj.getClass()))) {
120 return false;
121 }
122
123 UstDebugInfoBinaryFile other = (UstDebugInfoBinaryFile) obj;
124
125 return Objects.equals(fFilePath, other.fFilePath) &&
126 Objects.equals(fBuildId, other.fBuildId) &&
127 Objects.equals(fDebugLink, other.fDebugLink) &&
128 fIsPic == other.fIsPic;
129 }
130
131 /**
132 * Used for sorting. Sorts by using alphabetical order of the file
133 * paths.
134 */
135 @Override
136 public int compareTo(@Nullable UstDebugInfoBinaryFile o) {
137 if (o == null) {
138 return 1;
139 }
140 return fFilePath.compareTo(o.fFilePath);
141 }
142 }
This page took 0.03495 seconds and 5 git commands to generate.