1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

lldb: Remove -break-insert hack for absolute path for lldb 4.0

Change-Id: I098e088874d95d9f9cd08e315d059dc00b2c809c
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
This commit is contained in:
Marc-Andre Laperle 2017-03-16 21:48:44 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent efcff25e64
commit 2b302b9688
3 changed files with 116 additions and 14 deletions

View file

@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2017 Ericsson.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.llvm.dsf.lldb.core.internal;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.llvm.dsf.lldb.core.internal.launching.LLDBLaunch;
import org.eclipse.debug.core.ILaunch;
/**
* Constants related to traits of LLDB.
*
* A trait describe what LLDB can or cannot do. This is used to create a mapping
* between LLDB versions and what they can do so that the code can do the proper
* thing. For example, earlier versions would not be able to work with
* breakpoints inserted with a full path. The trait
* {@link #BROKEN_BREAKPOINT_INSERT_FULL_PATH_LLVM_BUG_28709} was introduced
* because of bug https://llvm.org/bugs/show_bug.cgi?id=28709
*
* The code can call {@link #isTraitOf(DsfSession)} to know whether or know the
* session (i.e. running LLDB) has that trait.
*
* @noimplement This interface is not intended to be implemented by clients.
* @noreference This enum is not intended to be referenced by clients.
*/
public enum LLDBTrait {
/**
* Trait for LLDBs affected by https://llvm.org/bugs/show_bug.cgi?id=28709.
* Inserting a breakpoint with full path would not work.
* TODO: Remove for versions < 4.0.0 eventually
*/
BROKEN_BREAKPOINT_INSERT_FULL_PATH_LLVM_BUG_28709;
/**
* Returns whether or not the given session has this trait.
*
* @param session the debug session
* @return true if the given session has this trait for the LLDB, false otherwise
*/
public boolean isTraitOf(DsfSession session) {
Object launch = session.getModelAdapter(ILaunch.class);
if (!(launch instanceof LLDBLaunch)) {
LLDBCorePlugin.log(
"Could not determine if session has LLDB trait " + this + " because launch is of unexpected type " //$NON-NLS-1$ //$NON-NLS-2$
+ launch.getClass() + ". Some features might not work as expected.", //$NON-NLS-1$
new Throwable());
return false;
}
LLDBLaunch lldbLaunch = (LLDBLaunch) launch;
return lldbLaunch.hasTrait(this);
}
}

View file

@ -14,6 +14,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -22,6 +24,7 @@ import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
import org.eclipse.cdt.llvm.dsf.lldb.core.ILLDBDebugPreferenceConstants;
import org.eclipse.cdt.llvm.dsf.lldb.core.ILLDBLaunchConfigurationConstants;
import org.eclipse.cdt.llvm.dsf.lldb.core.internal.ILLDBConstants;
import org.eclipse.cdt.llvm.dsf.lldb.core.internal.LLDBTrait;
import org.eclipse.cdt.llvm.dsf.lldb.core.internal.LLDBCorePlugin;
import org.eclipse.cdt.utils.CommandLineUtil;
import org.eclipse.cdt.utils.spawner.ProcessFactory;
@ -51,6 +54,7 @@ public class LLDBLaunch extends GdbLaunch {
private IntegerTuple fLldbVersion;
private IntegerTuple fLldbRevision;
private Set<LLDBTrait> fTraits;
/**
* Constructs a launch.
@ -183,6 +187,7 @@ public class LLDBLaunch extends GdbLaunch {
detailedException));
}
}
computeTraits();
} catch (IOException e) {
// Since we can't use lldb-mi for version checking, we try to use
// the lldb executable but it's possible that it's not there at all
@ -206,6 +211,27 @@ public class LLDBLaunch extends GdbLaunch {
}
}
private void computeTraits() {
if (fTraits == null) {
fTraits = new HashSet<>();
// Here are some LLDB/Xcode version mappings
// 360.1.65 => Xcode 8.1.0
// 360.1.70 => Xcode 8.2.1, 8.2.0
// 370.0.30 => Xcode 8.3.0 Beta 4
//
// Note that a LLDB built from source on macOS can report the same
// Apple-style version even for different LLDB/Clang-style version
// For example, 3.9.1 and 4.0.0 both report 360.99.0, how
// inconvenient! But this will only affect people building it from
// source, not LLDB included in Xcode.
if (fLldbVersion != null && fLldbVersion.compareTo(new IntegerTuple(4, 0, 0)) < 0 || fLldbRevision != null && fLldbRevision.compareTo(new IntegerTuple(370, 0, 30)) < 0) {
fTraits.add(LLDBTrait.BROKEN_BREAKPOINT_INSERT_FULL_PATH_LLVM_BUG_28709);
}
}
}
/**
* Read from the specified stream and return what was read.
*
@ -375,4 +401,15 @@ public class LLDBLaunch extends GdbLaunch {
}
return path.toOSString();
}
/**
* Returns whether or not the LLDB use by this launch has the given trait.
*
* @param trait
* the trait to check
* @return if the launch has this trait for the LLDB, false otherwise
*/
public boolean hasTrait (LLDBTrait trait) {
return fTraits.contains(trait);
}
}

View file

@ -13,6 +13,7 @@ import java.util.Map;
import org.eclipse.cdt.dsf.debug.service.IBreakpoints;
import org.eclipse.cdt.dsf.gdb.service.GDBBreakpoints_7_4;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.llvm.dsf.lldb.core.internal.LLDBTrait;
import org.eclipse.core.runtime.Path;
/**
@ -35,6 +36,7 @@ public class LLDBBreakpoints extends GDBBreakpoints_7_4 {
@Override
protected String formatLocation(Map<String, Object> attributes) {
if (LLDBTrait.BROKEN_BREAKPOINT_INSERT_FULL_PATH_LLVM_BUG_28709.isTraitOf(getSession())) {
// FIXME: ***Big hack*** lldb-mi's -breakpoint-insert doesn't handle
// locations that look like absolute paths (leading /). This will have
// to be fixed upstream because the work-around is not ideal: we only
@ -45,8 +47,12 @@ public class LLDBBreakpoints extends GDBBreakpoints_7_4 {
return adjustDebuggerPath(location);
}
return super.formatLocation(attributes);
}
@Override
public String adjustDebuggerPath(String originalPath) {
if (LLDBTrait.BROKEN_BREAKPOINT_INSERT_FULL_PATH_LLVM_BUG_28709.isTraitOf(getSession())) {
// FIXME: See also #formatLocation for hack explanation. This one needs
// to be overridden for moveToLine, runToLine and stepIntoSelection
// (Once this hack is removed, they should be tested).
@ -54,6 +60,8 @@ public class LLDBBreakpoints extends GDBBreakpoints_7_4 {
if (path.isAbsolute()) {
return path.lastSegment();
}
}
return super.adjustDebuggerPath(originalPath);
}
}