lttng.ust: Tweaks to BinaryCallsite
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / analysis / debuginfo / BinaryCallsite.java
CommitLineData
df993132
AM
1/*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10package org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo;
11
12/**
13 * Object carrying the information about the "binary callsite" corresponding to
14 * an instruction pointer. This consists in:
15 *
16 * <ul>
17 * <li>Binary file</li>
18 * <li>Symbol name</li>
19 * <li>Offset (within the binary)</li>
20 * </ul>
21 *
22 * @author Alexandre Montplaisir
23 * @since 2.0
24 */
25public class BinaryCallsite {
26
27 private final String fBinaryFilePath;
c84cc3cc 28 private final String fBuildId;
df993132 29 private final long fOffset;
1b084865 30 private final boolean fIsPic;
df993132
AM
31
32 /**
33 * Constructor
34 *
35 * @param binaryFilePath
36 * The path to the binary file on disk, as specified in the trace
37 * (may or may not be present on the system opening the trace).
c84cc3cc
AM
38 * @param buildId
39 * The Build-Id of the binary file. This is an unique identifier
40 * for a given object, so it can be used to make sure the file at
41 * the given path is the exact one we expect.
df993132 42 * @param offset
1b084865
AM
43 * The offset of the call site. Its exact meaning will depend on
44 * the value of 'isPic'. This should be ready to be passed as-is
45 * to tools like addr2line.
46 * @param isPic
47 * Indicates if the specified binary is Position-Independant Code
48 * or not. This will indicate if the 'offset' parameter is an
49 * absolute address (if isPic is false), or if it is an offset in
50 * the binary (is isPic is true).
df993132 51 */
1b084865 52 public BinaryCallsite(String binaryFilePath, String buildId, long offset, boolean isPic) {
df993132
AM
53 if (offset < 0) {
54 throw new IllegalArgumentException("Address offset cannot be negative"); //$NON-NLS-1$
55 }
56
57 fBinaryFilePath = binaryFilePath;
c84cc3cc 58 fBuildId = buildId;
df993132 59 fOffset = offset;
1b084865 60 fIsPic = isPic;
df993132
AM
61 }
62
63 /**
64 * Get the binary file's path
65 *
66 * @return The binary file path
67 */
68 public String getBinaryFilePath() {
69 return fBinaryFilePath;
70 }
71
72 /**
c84cc3cc
AM
73 * The build-id of the binary
74 *
75 * @return The build-id
76 */
77 public String getBuildId() {
78 return fBuildId;
79 }
80
df993132
AM
81 /**
82 * Get the address offset within the binary file corresponding to the
83 * instruction pointer.
84 *
85 * @return The address offset
86 */
87 public long getOffset() {
88 return fOffset;
89 }
90
91 @Override
92 public String toString() {
1b084865
AM
93 /*
94 * Output is of the following format:
95 *
96 * For PIC/PIE binaries: /usr/lib/mylib.so+0x123
97 * For non-PIC binaries: /usr/myprogram@0x401234
98 */
99 StringBuilder sb = new StringBuilder()
100 .append(fBinaryFilePath);
101
102 if (fIsPic) {
103 sb.append('+');
104 } else {
105 sb.append('@');
df993132 106 }
1b084865
AM
107
108 sb.append("0x").append(Long.toHexString(fOffset)); //$NON-NLS-1$
df993132
AM
109
110 return sb.toString();
111 }
112}
This page took 0.042523 seconds and 5 git commands to generate.