Imported Upstream version 5.18.0.142

Former-commit-id: 7467d4b717762eeaf652d77f1486dd11ffb1ff1f
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-10-09 08:20:59 +00:00
parent e52655b4dc
commit 0abdbe5a7d
1547 changed files with 93792 additions and 47893 deletions

View File

@@ -3,6 +3,7 @@ using System.Reflection;
using Mono.Debugger;
using Mono.Cecil;
using System.Collections.Generic;
using System.IO;
namespace Mono.Debugger.Soft
{
@@ -15,8 +16,13 @@ namespace Mono.Debugger.Soft
AssemblyName aname;
AssemblyDefinition meta;
AppDomainMirror domain;
byte[] metadata_blob;
bool? isDynamic;
byte[] pdb_blob;
Dictionary<string, long> typeCacheIgnoreCase = new Dictionary<string, long> (StringComparer.InvariantCultureIgnoreCase);
Dictionary<string, long> typeCache = new Dictionary<string, long> ();
Dictionary<uint, long> tokenTypeCache = new Dictionary<uint, long> ();
Dictionary<uint, long> tokenMethodCache = new Dictionary<uint, long> ();
internal AssemblyMirror (VirtualMachine vm, long id) : base (vm, id) {
}
@@ -118,7 +124,9 @@ namespace Mono.Debugger.Soft
*/
public AssemblyDefinition Metadata {
get {
return meta;
if (meta != null)
return meta;
return null;
}
set {
if (value.MainModule.Name != ManifestModule.Name)
@@ -128,5 +136,83 @@ namespace Mono.Debugger.Soft
meta = value;
}
}
// Read assembly metadata from the debuggee
// Since protocol version 2.47
public AssemblyDefinition GetMetadata () {
if (IsDynamic)
throw new NotSupportedException ();
using (var ms = new MemoryStream (GetMetadataBlob ()))
return meta = AssemblyDefinition.ReadAssembly (ms);
}
public byte[] GetMetadataBlob () {
if (metadata_blob != null)
return metadata_blob;
vm.CheckProtocolVersion (2, 47);
return metadata_blob = vm.conn.Assembly_GetMetadataBlob (id);
}
public bool IsDynamic {
get {
if (isDynamic.HasValue)
return isDynamic.Value;
vm.CheckProtocolVersion (2, 47);
isDynamic = vm.conn.Assembly_IsDynamic (id);
return isDynamic.Value;
}
}
public bool HasPdb {
get {
return pdb_blob != null;
}
}
public bool HasFetchedPdb { get; private set; }
public byte[] GetPdbBlob () {
if (HasFetchedPdb)
return pdb_blob;
vm.CheckProtocolVersion (2, 47);
var blob = vm.conn.Assembly_GetPdbBlob (id);
if (blob != null && blob.Length > 0) {
pdb_blob = blob;
}
HasFetchedPdb = true;
return pdb_blob;
}
public TypeMirror GetType (uint token) {
vm.CheckProtocolVersion (2, 47);
if (IsDynamic)
throw new NotSupportedException ();
long typeId;
if (!tokenTypeCache.TryGetValue (token, out typeId)) {
typeId = vm.conn.Assembly_GetType (id, token);
tokenTypeCache.Add (token, typeId);
}
return vm.GetType (typeId);
}
public MethodMirror GetMethod (uint token) {
vm.CheckProtocolVersion (2, 47);
if (IsDynamic)
throw new NotSupportedException ();
long methodId;
if (!tokenMethodCache.TryGetValue (token, out methodId)) {
methodId = vm.conn.Assembly_GetMethod (id, token);
tokenMethodCache.Add (token, methodId);
}
return vm.GetMethod (methodId);
}
}
}

View File

@@ -420,7 +420,7 @@ namespace Mono.Debugger.Soft
* with newer runtimes, and vice versa.
*/
internal const int MAJOR_VERSION = 2;
internal const int MINOR_VERSION = 46;
internal const int MINOR_VERSION = 47;
enum WPSuspendPolicy {
NONE = 0,
@@ -534,7 +534,12 @@ namespace Mono.Debugger.Soft
GET_OBJECT = 4,
GET_TYPE = 5,
GET_NAME = 6,
GET_DOMAIN = 7
GET_DOMAIN = 7,
GET_METADATA_BLOB = 8,
GET_IS_DYNAMIC = 9,
GET_PDB_BLOB = 10,
GET_TYPE_FROM_TOKEN = 11,
GET_METHOD_FROM_TOKEN = 12
}
enum CmdModule {
@@ -648,6 +653,17 @@ namespace Mono.Debugger.Soft
return packet [offset++];
}
static byte[] decode_bytes (byte[] packet, ref int offset, int length)
{
if (length + offset > packet.Length)
throw new ArgumentOutOfRangeException ();
var bytes = new byte[length];
Array.Copy (packet, offset, bytes, 0, length);
offset += length;
return bytes;
}
static int decode_short (byte[] packet, ref int offset) {
int res = ((int)packet [offset] << 8) | (int)packet [offset + 1];
offset += 2;
@@ -895,6 +911,15 @@ namespace Mono.Debugger.Soft
res [i] = ReadId ();
return res;
}
public byte[] ReadByteArray () {
var length = ReadInt ();
return decode_bytes (packet, ref offset, length);
}
public bool ReadBool () {
return ReadByte () != 0;
}
}
class PacketWriter {
@@ -2135,6 +2160,26 @@ namespace Mono.Debugger.Soft
internal long Assembly_GetIdDomain (long id) {
return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
}
internal byte[] Assembly_GetMetadataBlob (long id) {
return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_METADATA_BLOB, new PacketWriter ().WriteId (id)).ReadByteArray ();
}
internal bool Assembly_IsDynamic (long id) {
return SendReceive (CommandSet.ASSEMBLY, (int) CmdAssembly.GET_IS_DYNAMIC, new PacketWriter ().WriteId (id)).ReadBool ();
}
internal byte[] Assembly_GetPdbBlob (long id) {
return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_PDB_BLOB, new PacketWriter ().WriteId (id)).ReadByteArray ();
}
internal long Assembly_GetType (long id, uint token) {
return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_TYPE_FROM_TOKEN, new PacketWriter ().WriteId (id).WriteInt ((int)token)).ReadId ();
}
internal long Assembly_GetMethod (long id, uint token) {
return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_METHOD_FROM_TOKEN, new PacketWriter ().WriteId (id).WriteInt ((int)token)).ReadId ();
}
/*
* TYPE

View File

@@ -522,43 +522,65 @@ namespace Mono.Debugger.Soft
Dictionary <long, ObjectMirror> objects;
object objects_lock = new object ();
internal T GetObject<T> (long id, long domain_id, long type_id) where T : ObjectMirror {
// Return a mirror if it exists
// Does not call into the debuggee
internal T TryGetObject<T> (long id) where T : ObjectMirror {
lock (objects_lock) {
if (objects == null)
objects = new Dictionary <long, ObjectMirror> ();
ObjectMirror obj;
if (!objects.TryGetValue (id, out obj)) {
/*
* Obtain the domain/type of the object to determine the type of
* object we need to create.
*/
if (domain_id == 0 || type_id == 0) {
if (conn.Version.AtLeast (2, 5)) {
var info = conn.Object_GetInfo (id);
domain_id = info.domain_id;
type_id = info.type_id;
} else {
if (domain_id == 0)
domain_id = conn.Object_GetDomain (id);
if (type_id == 0)
type_id = conn.Object_GetType (id);
}
}
AppDomainMirror d = GetDomain (domain_id);
TypeMirror t = GetType (type_id);
if (t.Assembly == d.Corlib && t.Namespace == "System.Threading" && t.Name == "Thread")
obj = new ThreadMirror (this, id, t, d);
else if (t.Assembly == d.Corlib && t.Namespace == "System" && t.Name == "String")
obj = new StringMirror (this, id, t, d);
else if (typeof (T) == typeof (ArrayMirror))
obj = new ArrayMirror (this, id, t, d);
else
obj = new ObjectMirror (this, id, t, d);
objects [id] = obj;
}
objects.TryGetValue (id, out obj);
return (T)obj;
}
}
internal T GetObject<T> (long id, long domain_id, long type_id) where T : ObjectMirror {
ObjectMirror obj = null;
lock (objects_lock) {
if (objects == null)
objects = new Dictionary <long, ObjectMirror> ();
objects.TryGetValue (id, out obj);
}
if (obj == null) {
/*
* Obtain the domain/type of the object to determine the type of
* object we need to create. Do this outside the lock.
*/
if (domain_id == 0 || type_id == 0) {
if (conn.Version.AtLeast (2, 5)) {
var info = conn.Object_GetInfo (id);
domain_id = info.domain_id;
type_id = info.type_id;
} else {
if (domain_id == 0)
domain_id = conn.Object_GetDomain (id);
if (type_id == 0)
type_id = conn.Object_GetType (id);
}
}
AppDomainMirror d = GetDomain (domain_id);
TypeMirror t = GetType (type_id);
if (t.Assembly == d.Corlib && t.Namespace == "System.Threading" && t.Name == "Thread")
obj = new ThreadMirror (this, id, t, d);
else if (t.Assembly == d.Corlib && t.Namespace == "System" && t.Name == "String")
obj = new StringMirror (this, id, t, d);
else if (typeof (T) == typeof (ArrayMirror))
obj = new ArrayMirror (this, id, t, d);
else
obj = new ObjectMirror (this, id, t, d);
// Publish
lock (objects_lock) {
ObjectMirror prev_obj;
if (objects.TryGetValue (id, out prev_obj))
obj = prev_obj;
else
objects [id] = obj;
}
}
return (T)obj;
}
internal T GetObject<T> (long id) where T : ObjectMirror {
@@ -573,6 +595,10 @@ namespace Mono.Debugger.Soft
return GetObject <ThreadMirror> (id);
}
internal ThreadMirror TryGetThread (long id) {
return TryGetObject <ThreadMirror> (id);
}
Dictionary <long, FieldInfoMirror> fields;
object fields_lock = new object ();
@@ -736,7 +762,11 @@ namespace Mono.Debugger.Soft
l.Add (new ThreadStartEvent (vm, req_id, id));
break;
case EventType.ThreadDeath:
vm.GetThread (id).InvalidateFrames ();
// Avoid calling GetThread () since it might call into the debuggee
// and we can't do that in the event handler
var thread = vm.TryGetThread (id);
if (thread != null)
thread.InvalidateFrames ();
vm.InvalidateThreadCache ();
l.Add (new ThreadDeathEvent (vm, req_id, id));
break;

View File

@@ -1 +1 @@
de430ae354a18c8538fb43b6356a1a9c91226072
7de7a22a0ef9acbae4274e23f83698cd8a31f7da