Skip to content
Merged
Show file tree
Hide file tree
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
Removed checking custom attributes in the runtime each time the break…
…point is set and moved it to the constructor which is more efficient.
  • Loading branch information
ilonatommy committed Nov 3, 2021
commit 8c44faefae2a04e0e6c8420e6198aaeb49381359
13 changes: 13 additions & 0 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ internal class MethodInfo
internal LocalScopeHandleCollection localScopes;
public bool IsStatic() => (methodDef.Attributes & MethodAttributes.Static) != 0;
public int IsAsync { get; set; }
public bool IsHiddenFromDebugger { get; }
public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle, int token, SourceFile source, TypeInfo type, MetadataReader asmMetadataReader, MetadataReader pdbMetadataReader)
{
this.IsAsync = -1;
Expand Down Expand Up @@ -363,6 +364,18 @@ public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle,

StartLocation = new SourceLocation(this, start);
EndLocation = new SourceLocation(this, end);

foreach (var cattr in methodDef.GetCustomAttributes())
{
var ctorHandle = asmMetadataReader.GetCustomAttribute(cattr).Constructor;
if (ctorHandle.Kind == HandleKind.MemberReference)
{
var container = asmMetadataReader.GetMemberReference((MemberReferenceHandle)ctorHandle).Parent;
var name = asmMetadataReader.GetString(asmMetadataReader.GetTypeReference((TypeReferenceHandle)container).Name);
if (name == "DebuggerHiddenAttribute")
this.IsHiddenFromDebugger = true;
}
}
}
localScopes = pdbMetadataReader.GetLocalScopes(methodDefHandle);
}
Expand Down
8 changes: 4 additions & 4 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,10 +1153,6 @@ private async Task<Breakpoint> SetMonoBreakpoint(SessionId sessionId, string req
var assembly_id = await SdbHelper.GetAssemblyId(sessionId, asm_name, token);
var methodId = await SdbHelper.GetMethodIdByToken(sessionId, assembly_id, method_token, token);
var breakpoint_id = await SdbHelper.SetBreakpoint(sessionId, methodId, il_offset, token);
var type_id = await SdbHelper.GetTypeIdFromToken(sessionId, assembly_id, method_token, token);
var isHidden = await SdbHelper.GetDebuggerHiddenAttribute(sessionId, type_id, token);
if (isHidden)
return bp;

if (breakpoint_id > 0)
{
Expand Down Expand Up @@ -1305,6 +1301,10 @@ private async Task SetBreakpoint(SessionId sessionId, DebugStore store, Breakpoi
{
SourceLocation loc = sourceId.First();
req.Method = loc.CliLocation.Method;
if (req.Method.IsHiddenFromDebugger)
{
continue;
}

Breakpoint bp = await SetMonoBreakpoint(sessionId, req.Id, loc, req.Condition, token);

Expand Down
45 changes: 0 additions & 45 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,32 +1327,6 @@ internal async Task<MonoBinaryReader> GetCAttrsFromType(SessionId sessionId, int
return null;
}

internal async Task<IEnumerable<string>> GetCAttrsFromMethod(SessionId sessionId, int typeId, CancellationToken token)
{
var customAttributeNames = new List<string>();
var invokeParams = new MemoryStream();
var invokeParamsWriter = new MonoBinaryWriter(invokeParams);
var commandParams = new MemoryStream();
var commandParamsWriter = new MonoBinaryWriter(commandParams);
commandParamsWriter.Write(typeId);
commandParamsWriter.Write(0);
var retDebuggerCmdReader = await SendDebuggerAgentCommand<CmdMethod>(sessionId, CmdMethod.GetCattrs, commandParams, token);
var count = retDebuggerCmdReader.ReadInt32();
if (count == 0)
return customAttributeNames;
for (int i = 0; i < count; i++)
{
var methodId = retDebuggerCmdReader.ReadInt32();
commandParams = new MemoryStream();
commandParamsWriter = new MonoBinaryWriter(commandParams);
commandParamsWriter.Write(methodId);
var retDebuggerCmdReader2 = await SendDebuggerAgentCommand<CmdMethod>(sessionId, CmdMethod.GetDeclaringType, commandParams, token);
var customAttributeTypeId = retDebuggerCmdReader2.ReadInt32();
customAttributeNames.Add(await GetTypeName(sessionId, customAttributeTypeId, token));
}
return customAttributeNames;
}

public async Task<int> GetAssemblyFromType(SessionId sessionId, int type_id, CancellationToken token)
{
var commandParams = new MemoryStream();
Expand All @@ -1368,25 +1342,6 @@ public async Task<int> GetAssemblyFromType(SessionId sessionId, int type_id, Can
return retDebuggerCmdReader.ReadInt32();
}

public async Task<bool> GetDebuggerHiddenAttribute(SessionId sessionId, int type_id, CancellationToken token)
{
string expr = "";
try
{

var customMethodAttributes = await GetCAttrsFromMethod(sessionId, type_id, token);
if (customMethodAttributes.Any(a => a == "System.Diagnostics.DebuggerHiddenAttribute"))
{
return true;
}
}
catch (Exception)
{
logger.LogDebug($"Could not evaluate DebuggerHiddenAttribute - {expr}");
}
return false;
}

public async Task<string> GetValueFromDebuggerDisplayAttribute(SessionId sessionId, int objectId, int typeId, CancellationToken token)
{
string expr = "";
Expand Down