Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rework the swaping reading logic
  • Loading branch information
lewing committed Nov 10, 2021
commit 51a6551dcd71a5be90b57535acaba310e5965020
54 changes: 15 additions & 39 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.CodeAnalysis.CSharp;
using System.Reflection;
using System.Text;
using System.Runtime.CompilerServices;

namespace Microsoft.WebAssembly.Diagnostics
{
Expand Down Expand Up @@ -407,48 +408,25 @@ public override string ReadString()

return new string(Encoding.UTF8.GetChars(value, 0, valueLen));
}
public unsafe long ReadLong()
{
Span<byte> data = stackalloc byte[8];
Read(data);

long ret;
SwapForBE(new Span<byte>(&ret, 8), data);
return ret;
}

// SDB encodes these as 4 bytes
public override sbyte ReadSByte() => (sbyte)ReadInt32();
public byte ReadUByte() => (byte)ReadUInt32();
public ushort ReadUShort() => (ushort)ReadUInt32();
public override unsafe int ReadInt32() => Read<int>();

public override unsafe int ReadInt32()
{
Span<byte> data = stackalloc byte[4];
Read(data);
public override unsafe double ReadDouble() => Read<double>();
public override unsafe uint ReadUInt32() => Read<uint>();
public override unsafe float ReadSingle() => Read<float>();
public override unsafe ulong ReadUInt64() => Read<ulong>();
public override unsafe long ReadInt64() => Read<long>();

int ret;
SwapForBE(new Span<byte>(&ret, 4), data);
return ret;
}

public override unsafe double ReadDouble()
protected unsafe T Read<T>() where T : struct
{
Span<byte> data = stackalloc byte[8];
Span<byte> data = stackalloc byte[Unsafe.SizeOf<T>()];
T ret = default;
Read(data);

double ret;
SwapForBE(new Span<byte>(&ret, 8), data);
return ret;
}

public override unsafe uint ReadUInt32()
{
Span<byte> data = stackalloc byte[4];
Read(data);

uint ret;
SwapForBE(new Span<byte>(&ret, 4), data);
SwapForBE(new Span<byte>(Unsafe.AsPointer(ref ret), data.Length), data);
return ret;
}
}
Expand Down Expand Up @@ -1710,7 +1688,7 @@ public async Task<JObject> CreateJObjectForPtr(SessionId sessionId, ElementType
{
string type;
string value;
long valueAddress = retDebuggerCmdReader.ReadLong();
long valueAddress = retDebuggerCmdReader.ReadInt64();
var typeId = retDebuggerCmdReader.ReadInt32();
var className = "";
if (etype == ElementType.FnPtr)
Expand Down Expand Up @@ -1921,7 +1899,7 @@ public async Task<JObject> CreateJObjectForVariableValue(SessionId sessionId, Mo
}
case ElementType.R4:
{
float value = BitConverter.Int32BitsToSingle(retDebuggerCmdReader.ReadInt32());
float value = retDebuggerCmdReader.ReadSingle();
ret = CreateJObjectForNumber<float>(value);
break;
}
Expand All @@ -1933,15 +1911,13 @@ public async Task<JObject> CreateJObjectForVariableValue(SessionId sessionId, Mo
}
case ElementType.I8:
{
long value = retDebuggerCmdReader.ReadLong();
long value = retDebuggerCmdReader.ReadInt64();
ret = CreateJObjectForNumber<long>(value);
break;
}
case ElementType.U8:
{
ulong high = (ulong) retDebuggerCmdReader.ReadInt32();
ulong low = (ulong) retDebuggerCmdReader.ReadInt32();
var value = ((high << 32) | low);
ulong value = retDebuggerCmdReader.ReadUInt64();
ret = CreateJObjectForNumber<ulong>(value);
break;
}
Expand Down