Skip to content

Commit

Permalink
Merge pull request microsoft#319 from Microsoft/detectarch
Browse files Browse the repository at this point in the history
Query debugger for target architecture instead of relying on launch o…
  • Loading branch information
paulmaybee committed May 16, 2016
2 parents b503d28 + bfd9e60 commit 20e71a9
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 28 deletions.
5 changes: 5 additions & 0 deletions src/MICore/CommandFactories/MICommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ public virtual void DecodeExceptionReceivedProperties(Results miExceptionResult,

#region Helpers

public virtual Task<TargetArchitecture> GetTargetArchitecture()
{
return Task.FromResult(TargetArchitecture.Unknown);
}

#endregion

#region Other
Expand Down
33 changes: 33 additions & 0 deletions src/MICore/CommandFactories/gdb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,38 @@ public override async Task<Results> BreakWatch(string address, uint size, Result
}

public override bool SupportsDataBreakpoints { get { return true; } }

public override async Task<TargetArchitecture> GetTargetArchitecture()
{
string cmd = "show architecture";
var result = await _debugger.ConsoleCmdAsync(cmd);
using (StringReader stringReader = new StringReader(result))
{
while (true)
{
string resultLine = stringReader.ReadLine();
if (resultLine == null)
break;

if (resultLine.IndexOf("x86-64", StringComparison.OrdinalIgnoreCase) >= 0)
{
return TargetArchitecture.X64;
}
else if (resultLine.IndexOf("i386", StringComparison.OrdinalIgnoreCase) >= 0)
{
return TargetArchitecture.X86;
}
else if (resultLine.IndexOf("arm64", StringComparison.OrdinalIgnoreCase) >= 0)
{
return TargetArchitecture.ARM64;
}
else if (resultLine.IndexOf("arm", StringComparison.OrdinalIgnoreCase) >= 0)
{
return TargetArchitecture.ARM;
}
}
}
return TargetArchitecture.Unknown;
}
}
}
38 changes: 38 additions & 0 deletions src/MICore/CommandFactories/lldb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,43 @@ public override Task EnableTargetAsyncOption()
// lldb-mi doesn't support target-async mode, and doesn't seem to need to
return Task.FromResult((object)null);
}

public override async Task<TargetArchitecture> GetTargetArchitecture()
{
string cmd = "platform status";
var result = await _debugger.ConsoleCmdAsync(cmd);
using (StringReader stringReader = new StringReader(result))
{
while (true)
{
string resultLine = stringReader.ReadLine();
if (resultLine == null)
break;

if (resultLine.IndexOf("Triple:", StringComparison.OrdinalIgnoreCase) >= 0)
{
if (resultLine.IndexOf("x86_64", StringComparison.OrdinalIgnoreCase) >= 0)
{
return TargetArchitecture.X64;
}
else if (resultLine.IndexOf("x86", StringComparison.OrdinalIgnoreCase) >= 0)
{
return TargetArchitecture.X86;
}
else if (resultLine.IndexOf("aarch64", StringComparison.OrdinalIgnoreCase) >= 0)
{
return TargetArchitecture.ARM64;
}
else if (resultLine.IndexOf("arm", StringComparison.OrdinalIgnoreCase) >= 0)
{
return TargetArchitecture.ARM;
}
break;
}
}
}
return TargetArchitecture.Unknown;
}

}
}
5 changes: 4 additions & 1 deletion src/MICore/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,11 @@ public void Init(ITransport transport, LaunchOptions options)
FlushBreakStateData();

_transport.Init(this, options, Logger);
}

switch (options.TargetArchitecture)
public void SetTargetArch(TargetArchitecture arch)
{
switch (arch)
{
case TargetArchitecture.ARM:
MaxInstructionSize = 4;
Expand Down
2 changes: 1 addition & 1 deletion src/MICore/LaunchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ protected void InitializeCommonOptions(Xml.LaunchOptions.BaseLaunchOptions sourc
}
}

if (this.TargetArchitecture == TargetArchitecture.Unknown)
if (this.TargetArchitecture == TargetArchitecture.Unknown && source.TargetArchitectureSpecified)
{
this.TargetArchitecture = ConvertTargetArchitectureAttribute(source.TargetArchitecture);
}
Expand Down
2 changes: 1 addition & 1 deletion src/MICore/LaunchOptions.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
</xs:sequence>
</xs:complexType>
<xs:attributeGroup name="CommonAttributes">
<xs:attribute name="TargetArchitecture" use="required" type="TargetArchitecture"/>
<xs:attribute name="TargetArchitecture" use="optional" type="TargetArchitecture"/>
<xs:attribute name="AbsolutePrefixSOLibSearchPath" type="xs:string" use="optional">
<xs:annotation>
<xs:documentation>Absolute prefix for directories to search for shared library symbols</xs:documentation>
Expand Down
88 changes: 64 additions & 24 deletions src/MICore/LaunchOptions.xsd.types.designer.desktop.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 4.0.30319.17020
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

//
//This source code was auto-generated by MonoXSD
//
// This source code was auto-generated by xsd, Version=4.6.81.0.
//
namespace MICore.Xml.LaunchOptions {
using System.Xml.Serialization;


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
Expand Down Expand Up @@ -47,6 +48,8 @@ public partial class AndroidLaunchOptions {

private TargetArchitecture targetArchitectureField;

private bool targetArchitectureFieldSpecified;

private string absolutePrefixSOLibSearchPathField;

private string additionalSOLibSearchPathField;
Expand Down Expand Up @@ -201,6 +204,17 @@ public TargetArchitecture TargetArchitecture {
}
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool TargetArchitectureSpecified {
get {
return this.targetArchitectureFieldSpecified;
}
set {
this.targetArchitectureFieldSpecified = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string AbsolutePrefixSOLibSearchPath {
Expand Down Expand Up @@ -259,7 +273,7 @@ public bool WaitDynamicLibLoad {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014")]
public enum TargetArchitecture {
Expand Down Expand Up @@ -308,7 +322,7 @@ public enum TargetArchitecture {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014")]
public enum MIMode {
Expand All @@ -324,7 +338,7 @@ public enum MIMode {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
Expand Down Expand Up @@ -372,7 +386,7 @@ public string Value1 {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
Expand Down Expand Up @@ -433,7 +447,7 @@ public string Value {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
Expand Down Expand Up @@ -462,6 +476,8 @@ public partial class BaseLaunchOptions {

private TargetArchitecture targetArchitectureField;

private bool targetArchitectureFieldSpecified;

private string absolutePrefixSOLibSearchPathField;

private string additionalSOLibSearchPathField;
Expand Down Expand Up @@ -596,6 +612,17 @@ public TargetArchitecture TargetArchitecture {
}
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool TargetArchitectureSpecified {
get {
return this.targetArchitectureFieldSpecified;
}
set {
this.targetArchitectureFieldSpecified = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string AbsolutePrefixSOLibSearchPath {
Expand Down Expand Up @@ -654,7 +681,7 @@ public bool WaitDynamicLibLoad {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014")]
public enum BaseLaunchOptionsLaunchCompleteCommand {
Expand All @@ -672,7 +699,7 @@ public enum BaseLaunchOptionsLaunchCompleteCommand {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
Expand All @@ -694,6 +721,8 @@ public partial class IOSLaunchOptions {

private TargetArchitecture targetArchitectureField;

private bool targetArchitectureFieldSpecified;

private string absolutePrefixSOLibSearchPathField;

private string additionalSOLibSearchPathField;
Expand Down Expand Up @@ -785,6 +814,17 @@ public TargetArchitecture TargetArchitecture {
}
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool TargetArchitectureSpecified {
get {
return this.targetArchitectureFieldSpecified;
}
set {
this.targetArchitectureFieldSpecified = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string AbsolutePrefixSOLibSearchPath {
Expand Down Expand Up @@ -843,7 +883,7 @@ public bool WaitDynamicLibLoad {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014")]
public enum IOSLaunchOptionsIOSDebugTarget {
Expand All @@ -856,7 +896,7 @@ public enum IOSLaunchOptionsIOSDebugTarget {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014")]
public enum IOSLaunchOptionsSecure {
Expand All @@ -869,7 +909,7 @@ public enum IOSLaunchOptionsSecure {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
Expand Down Expand Up @@ -1100,7 +1140,7 @@ public bool ExternalConsoleSpecified {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
Expand Down Expand Up @@ -1136,7 +1176,7 @@ public string PipeArguments {
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "0.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
Expand Down
14 changes: 14 additions & 0 deletions src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,20 @@ public async Task Initialize(HostWaitLoop waitLoop, CancellationToken token)
}
}

var arch = await MICommandFactory.GetTargetArchitecture();
if (arch == TargetArchitecture.Unknown)
{
if (LaunchOptions.TargetArchitecture != TargetArchitecture.Unknown)
{
arch = LaunchOptions.TargetArchitecture;
}
else
{
WriteOutput(ResourceStrings.Warning_UsingDefaultArchitecture);
arch = TargetArchitecture.X64; // use as default
}
}
SetTargetArch(arch);

success = true;
}
Expand Down
11 changes: 10 additions & 1 deletion src/MIDebugEngine/ResourceStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 20e71a9

Please sign in to comment.