Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8518e9f
checkpoint
lambdageek Mar 28, 2024
12aef6d
add old tooling notes
lambdageek Mar 28, 2024
1eff4d0
add an emitter
lambdageek Apr 1, 2024
22e217b
checkpoint read in the directory header
lambdageek Apr 1, 2024
dd9279d
checkpoint plausible-looking offsets
lambdageek Apr 2, 2024
492af29
checkpoint: field stuff is working
lambdageek Apr 3, 2024
459d124
checkpoint json
lambdageek Apr 3, 2024
28f8256
contract parsing
lambdageek Apr 3, 2024
418739d
refactor
lambdageek Apr 3, 2024
1c1524d
indirect pointer value support
lambdageek Apr 3, 2024
34e852e
move sample to tool dir
lambdageek Apr 3, 2024
e48e709
Take baselines from the docs/design/datacontracts/data dir
lambdageek Apr 3, 2024
0e8c60e
Add README
lambdageek Apr 3, 2024
cd4f0f0
fix BE
lambdageek Apr 3, 2024
b6b079e
hook up cdac-build-tool to the coreclr build; export DotNetRuntimeCon…
lambdageek Apr 4, 2024
a9b0d7f
try fix win-x86 build warning
lambdageek Apr 4, 2024
dbf0557
paths
lambdageek Apr 4, 2024
74433f1
vebose
lambdageek Apr 4, 2024
ea441b6
fix typo; fixes win32
lambdageek Apr 5, 2024
787b836
cleanup; add contracts.txt
lambdageek Apr 5, 2024
e015e83
add diagram to README
lambdageek Apr 5, 2024
0354723
move implementation notes
lambdageek Apr 5, 2024
da038f3
better verbose output from ObjectFileScraper
lambdageek Apr 5, 2024
f64b548
turn off whole program optimizations for data-descriptor.obj
lambdageek Apr 5, 2024
2e29a10
C++-ify and add real Thread offsets
lambdageek Apr 6, 2024
58162a3
no C99 designated initializers in C++ until C++20
lambdageek Apr 8, 2024
4bb51bf
build data descriptor after core runtime
lambdageek Apr 8, 2024
9700e29
fix gcc build
lambdageek Apr 8, 2024
3f22c7c
fix typo
lambdageek Apr 8, 2024
4aae511
simplify ObjectFileScraper
lambdageek Apr 8, 2024
60738ef
more dependencies
lambdageek Apr 8, 2024
c0dab90
try fix source build
lambdageek Apr 8, 2024
84eaa3b
remove fixme; document
lambdageek Apr 8, 2024
86e5258
Merge commit 'origin/main^' into cdac-contract-tool
lambdageek Apr 9, 2024
cc658c9
invoke 'dotnet cmake-build-tool.dll' instead of 'dotnet run --project'
lambdageek Apr 9, 2024
39fe70d
clean up macro boilerplate
lambdageek Apr 9, 2024
5064deb
platform flags
lambdageek Apr 9, 2024
74000bc
turn off verbose output
lambdageek Apr 9, 2024
76c27bc
can't use constexpr function in coreclr
lambdageek Apr 9, 2024
270fe21
Code review fixups
lambdageek Apr 12, 2024
84e0800
Rename "aux data" to "pointer data"
lambdageek Apr 12, 2024
51da4e3
rename "data-descriptor" to "datadescriptor"
lambdageek Apr 12, 2024
b26f3ac
simplify linking
lambdageek Apr 12, 2024
8f9d1a7
cdac-build-tool don't build dotnet tool; turn on analyzers
lambdageek Apr 12, 2024
87b79b3
update README
lambdageek Apr 12, 2024
b33ad07
rationalize naming; update docs; add some inline comments
lambdageek Apr 12, 2024
c39e6f4
rm whitespace
lambdageek Apr 12, 2024
5ef8428
renamce cdac.h to cdacoffsets.h
lambdageek Apr 12, 2024
9f381be
comments
lambdageek Apr 12, 2024
443f83b
fixup README
lambdageek Apr 12, 2024
9fc2b26
hex offsets; improved formatting
lambdageek Apr 12, 2024
024c566
don't throw in ParseContracts; add line numbers to errors
lambdageek Apr 12, 2024
b0f1f40
spelling
lambdageek Apr 12, 2024
2852d8d
Update README.md
lambdageek Apr 12, 2024
2429bd8
change input format for contracts to jsonc
lambdageek Apr 16, 2024
18a863e
add custom JsonConverter instances for the compact json representation
lambdageek Apr 16, 2024
a49e5e6
code review changes
lambdageek Apr 16, 2024
1f5ba44
inline comments into the data-descriptor-blob C code
lambdageek Apr 16, 2024
2decea4
cleanup
lambdageek Apr 16, 2024
ce18bee
comments and markdown
lambdageek Apr 16, 2024
e143998
Apply suggestions from code review
lambdageek Apr 17, 2024
08cf75d
simplify; bug fix - PointerDataCount include placeholder
lambdageek Apr 17, 2024
0d4d40d
fixup docs
lambdageek Apr 17, 2024
94c56ea
Merge remote-tracking branch 'origin/main' into cdac-contract-tool
lambdageek Apr 18, 2024
3d49b70
Update src/coreclr/tools/cdac-build-tool/JsonConverter/GlobalModelJso…
lambdageek Apr 18, 2024
f845c41
one more set of feedback changes
lambdageek Apr 18, 2024
64430cf
maybe no live ILLink ?
lambdageek Apr 18, 2024
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
change input format for contracts to jsonc
  • Loading branch information
lambdageek committed Apr 16, 2024
commit 2429bd81ddd95df86c7befa16c227ba35d4a0b1b
2 changes: 1 addition & 1 deletion src/coreclr/debug/runtimeinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if("${CDAC_BUILD_TOOL_BINARY_PATH}" STREQUAL "" OR NOT EXISTS "${CDAC_BUILD_TOOL
message(FATAL_ERROR "No cdac-build-tool set or ${CDAC_BUILD_TOOL_BINARY_PATH} does not exist")
endif()

set(CONTRACT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/contracts.txt")
set(CONTRACT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/contracts.jsonc")

# generate the contract descriptor by running cdac-build-tool
# n.b. this just uses `dotnet` from the PATH. InitializeDotNetCli adds the apropropriate directory
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/debug/runtimeinfo/contracts.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//algorithmic contracts for coreclr
// The format of this file is: JSON with comments
// {
// "CONTRACT NAME": VERSION,
// ...
// }
// CONTRACT NAME is an arbitrary string, VERSION is an integer
//
// cdac-build-tool can take multiple "-c contract_file" arguments
// so to conditionally include contracts, put additional contracts in a separate file
{
"SOSBreakingChangeVersion": 1 // example contract: "runtime exports an SOS breaking change version global"
}

10 changes: 0 additions & 10 deletions src/coreclr/debug/runtimeinfo/contracts.txt

This file was deleted.

30 changes: 8 additions & 22 deletions src/coreclr/tools/cdac-build-tool/ContractReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.IO;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -15,35 +16,20 @@ public partial class ContractReader
{
private readonly DataDescriptorModel.Builder _builder;

private static readonly JsonSerializerOptions s_jsonSerializerOptions = new() { PropertyNameCaseInsensitive = false, ReadCommentHandling = JsonCommentHandling.Skip };

public ContractReader(DataDescriptorModel.Builder builder)
{
_builder = builder;
}

public async Task<bool> ParseContracts(string contractFilePath, CancellationToken token = default)
{
var s = File.OpenRead(contractFilePath);
using var reader = new StreamReader(s, System.Text.Encoding.UTF8);
uint lineNum = 0;
while (true)
{
var line = await reader.ReadLineAsync(token).ConfigureAwait(false);
lineNum++;
if (line == null)
{
break;
}
if (BlankOrCommentRegex().Match(line) is { Success: true })
{
continue;
}
if (!TryParseContractLine(line, out string? contract, out int version))
{
Console.Error.WriteLine($"{contractFilePath}:{lineNum}: Invalid contract line: {line}");
return false;
}
_builder.AddOrUpdateContract(contract, version);
}
string? contents = await File.ReadAllTextAsync(contractFilePath, token).ConfigureAwait(false);
var contractCollectionModel = JsonSerializer.Deserialize<DataDescriptorModel.ContractCollectionModel>(contents, s_jsonSerializerOptions);
if (contractCollectionModel is null)
return false;
_builder.AddOrupdateContracts(contractCollectionModel);
return true;
}
public bool TryParseContractLine(string line, [NotNullWhen(true)] out string? contract, out int version)
Expand Down
37 changes: 28 additions & 9 deletions src/coreclr/tools/cdac-build-tool/DataDescriptorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.DotNet.Diagnostics.DataContract.BuildTool;

Expand All @@ -14,9 +16,9 @@ public class DataDescriptorModel
public string Baseline { get; }
public IReadOnlyDictionary<string, TypeModel> Types { get; }
public IReadOnlyDictionary<string, GlobalModel> Globals { get; }
public IReadOnlyDictionary<string, ContractModel> Contracts { get; }
public ContractCollectionModel Contracts { get; }
public uint PlatformFlags { get; }
private DataDescriptorModel(string baseline, IReadOnlyDictionary<string, TypeModel> types, IReadOnlyDictionary<string, GlobalModel> globals, IReadOnlyDictionary<string, ContractModel> contracts, uint platformFlags)
private DataDescriptorModel(string baseline, IReadOnlyDictionary<string, TypeModel> types, IReadOnlyDictionary<string, GlobalModel> globals, ContractCollectionModel contracts, uint platformFlags)
{
Baseline = baseline;
Types = types;
Expand Down Expand Up @@ -131,12 +133,8 @@ public string ToJson()
}
}
w.WriteEndObject();
w.WriteStartObject("contracts");
foreach (var (contractName, contract) in Contracts)
{
w.WriteNumber(contractName, contract.Version);
}
w.WriteEndObject();
w.WritePropertyName("contracts");
JsonSerializer.Serialize(w, Contracts);
w.WriteEndObject();
w.Flush();
}
Expand Down Expand Up @@ -202,6 +200,14 @@ public void AddOrUpdateContract(string name, int version)
contract.Version = version;
}

public void AddOrupdateContracts(IEnumerable<KeyValuePair<string, ContractModel>> contracts)
{
foreach (var (name, contract) in contracts)
{
AddOrUpdateContract(name, contract.Version);
}
}

public void SetBaseline(string baseline)
{
if (_baseline != string.Empty && _baseline != baseline)
Expand Down Expand Up @@ -258,7 +264,7 @@ public DataDescriptorModel Build()
{
contracts[contractName] = contractBuilder.Build();
}
return new DataDescriptorModel(_baseline, types, globals, contracts, PlatformFlags);
return new DataDescriptorModel(_baseline, types, globals, new ContractCollectionModel(contracts), PlatformFlags);
}
}

Expand Down Expand Up @@ -409,6 +415,19 @@ public readonly struct GlobalModel
public GlobalValue Value { get; init; }
}

[JsonConverter(typeof(JsonConverter.ContractCollectionModelJsonConverter))]
public class ContractCollectionModel : IEnumerable<KeyValuePair<string, ContractModel>>
{
public IReadOnlyDictionary<string, ContractModel> Contracts { get; }
public ContractCollectionModel(IReadOnlyDictionary<string, ContractModel> contracts)
{
Contracts = contracts;
}

public IEnumerator<KeyValuePair<string, ContractModel>> GetEnumerator() => Contracts.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

public readonly struct ContractModel
{
public int Version { get; init; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.DotNet.Diagnostics.DataContract.BuildTool;

namespace Microsoft.DotNet.Diagnostics.DataContract.JsonConverter;

/// <summary>
/// Parses or serializes contracts in the "compact" JSON format: as a single
/// object for the whole collection where each contract name is a property name and
/// the value is the version number.
/// </summary>
public class ContractCollectionModelJsonConverter : JsonConverter<DataDescriptorModel.ContractCollectionModel>
{
public override DataDescriptorModel.ContractCollectionModel Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Dictionary<string, DataDescriptorModel.ContractBuilder> contracts = new();
if (reader.TokenType != JsonTokenType.StartObject)
{
throw new JsonException();
}
while (reader.Read())
{
switch (reader.TokenType)
{
case JsonTokenType.EndObject:
var builtContracts = contracts.Select((kvp) => (kvp.Key, kvp.Value.Build()));
return new DataDescriptorModel.ContractCollectionModel(builtContracts.ToDictionary());
case JsonTokenType.PropertyName:
string? propertyName = reader.GetString();
if (propertyName is null)
{
throw new JsonException();
}
reader.Read();
int version = reader.GetInt32();
contracts.Add(propertyName, new DataDescriptorModel.ContractBuilder { Version = version });
break;
case JsonTokenType.Comment:
break;
default:
throw new JsonException();
}
}
throw new JsonException();
}

public override void Write(Utf8JsonWriter writer, DataDescriptorModel.ContractCollectionModel value, JsonSerializerOptions options)
{
writer.WriteStartObject();
foreach (var (name, contract) in value.Contracts)
{
writer.WriteNumber(name, contract.Version);

}
writer.WriteEndObject();
}
}