Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dudikeleti committed Nov 7, 2023
1 parent 47b684a commit 204bbf8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 57 deletions.
38 changes: 19 additions & 19 deletions tracer/src/Datadog.Trace/Debugger/Symbols/SymbolExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private SourcePdbInfo GetClassSourcePdbInfo(Model.Scope[]? allScopes)
string? classSourceFile = null;
if (allScopes == null)
{
return new SourcePdbInfo { StartLine = classStartLine, EndLine = classEndLine, Path = classSourceFile };
return new SourcePdbInfo { StartLine = UnknownMethodStartLine, EndLine = UnknownMethodEndLine, Path = classSourceFile };
}

for (int i = 0; i < allScopes.Length; i++)
Expand Down Expand Up @@ -515,12 +515,12 @@ protected virtual Model.Scope CreateMethodScope(TypeDefinition type, MethodDefin
private Model.Scope[]? GetClosureScopes(TypeDefinition typeDef, MethodDefinition methodDef)
{
Model.Scope[]? closureMethods = null;
int index = 0;
try
{
var nestedTypes = typeDef.GetNestedTypes();
var methods = typeDef.GetMethods();
closureMethods = ArrayPool<Model.Scope>.Shared.Rent(methods.Count + (nestedTypes.Length * 2));
int index = 0;

for (int i = 0; i < nestedTypes.Length; i++)
{
Expand Down Expand Up @@ -571,23 +571,6 @@ protected virtual Model.Scope CreateMethodScope(TypeDefinition type, MethodDefin
}

return closureScopes;

void PopulateClosureMethod(MethodDefinition generatedMethod, TypeDefinition ownerType)
{
var closureMethodScope = CreateMethodScopeForGeneratedMethod(methodDef, generatedMethod, ownerType);
if (closureMethodScope.HasValue)
{
if (index < closureMethods.Length)
{
closureMethods[index] = closureMethodScope.Value;
index++;
}
else
{
Log.Warning("Not enough space for all closure methods");
}
}
}
}
finally
{
Expand All @@ -596,6 +579,23 @@ void PopulateClosureMethod(MethodDefinition generatedMethod, TypeDefinition owne
ArrayPool<Model.Scope>.Shared.Return(closureMethods);
}
}

void PopulateClosureMethod(MethodDefinition generatedMethod, TypeDefinition ownerType)
{
var closureMethodScope = CreateMethodScopeForGeneratedMethod(methodDef, generatedMethod, ownerType);
if (closureMethodScope.HasValue)
{
if (index < closureMethods.Length)
{
closureMethods[index] = closureMethodScope.Value;
index++;
}
else
{
Log.Warning("Not enough space for all closure methods");
}
}
}
}

protected virtual Model.Scope? CreateMethodScopeForGeneratedMethod(MethodDefinition method, MethodDefinition generatedMethod, TypeDefinition nestedType)
Expand Down
83 changes: 46 additions & 37 deletions tracer/src/Datadog.Trace/Debugger/Symbols/SymbolPdbExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,54 +184,63 @@ protected override Model.Scope CreateMethodScope(TypeDefinition type, MethodDefi
var nestedType = MetadataReader.GetTypeDefinition(nestedHandle);
var fields = nestedType.GetFields();
int index = 0;
var added = ArrayPool<string>.Shared.Rent(fields.Count);
foreach (var fieldHandle in fields)
string[]? added = null;
try
{
if (fieldHandle.IsNil)
added = ArrayPool<string>.Shared.Rent(fields.Count);
foreach (var fieldHandle in fields)
{
continue;
}
if (fieldHandle.IsNil)
{
continue;
}

var field = MetadataReader.GetFieldDefinition(fieldHandle);
if (field.Name.IsNil)
{
continue;
}
var field = MetadataReader.GetFieldDefinition(fieldHandle);
if (field.Name.IsNil)
{
continue;
}

var fieldName = MetadataReader.GetString(field.Name);
var fieldNameAsSpan = Datadog.Trace.VendoredMicrosoftCode.System.MemoryExtensions.AsSpan(fieldName);
if (Datadog.Trace.VendoredMicrosoftCode.System.MemoryExtensions.IndexOf(fieldNameAsSpan, generatedClassPrefix, StringComparison.Ordinal) == 0)
{
continue;
}
var fieldName = MetadataReader.GetString(field.Name);
var fieldNameAsSpan = Datadog.Trace.VendoredMicrosoftCode.System.MemoryExtensions.AsSpan(fieldName);
if (Datadog.Trace.VendoredMicrosoftCode.System.MemoryExtensions.IndexOf(fieldNameAsSpan, generatedClassPrefix, StringComparison.Ordinal) == 0)
{
continue;
}

bool contains = false;
for (int j = 0; j < added.Length; j++)
{
if (added[j] == fieldName)
bool contains = false;
for (int j = 0; j < added.Length; j++)
{
contains = true;
break;
if (added[j] == fieldName)
{
contains = true;
break;
}
}
}

if (contains)
{
continue;
}
if (contains)
{
continue;
}

added[index] = fieldName;
localsSymbol.Add(new Symbol
added[index] = fieldName;
localsSymbol.Add(new Symbol
{
Name = fieldName,
Type = field.DecodeSignature(new TypeProvider(false), 0),
SymbolType = SymbolType.Local,
Line = local.Line
});
index++;
}
}
finally
{
if (added != null)
{
Name = fieldName,
Type = field.DecodeSignature(new TypeProvider(false), 0),
SymbolType = SymbolType.Local,
Line = local.Line
});
index++;
ArrayPool<string>.Shared.Return(added, true);
}
}

ArrayPool<string>.Shared.Return(added, true);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion tracer/src/Datadog.Trace/Debugger/Symbols/SymbolsUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private async Task ProcessItemAsync(Assembly assembly)

if (_cancellationToken.IsCancellationRequested)
{
_assemblySemaphore.Release();
return;
}

Expand Down Expand Up @@ -227,7 +228,15 @@ private int SerializeClass(Model.Scope classScope, StringBuilder sb)
}

var symbolAsString = JsonConvert.SerializeObject(classScope, _jsonSerializerSettings);
sb.Append(symbolAsString);

try
{
sb.Append(symbolAsString);
}
catch (ArgumentOutOfRangeException)
{
return 0;
}

return Encoding.UTF8.GetByteCount(symbolAsString);
}
Expand Down

0 comments on commit 204bbf8

Please sign in to comment.