Skip to content

Commit

Permalink
Revert "address comment"
Browse files Browse the repository at this point in the history
This reverts commit b70e603.
  • Loading branch information
Xinlong-Wu committed Feb 18, 2024
1 parent 8add0d7 commit 95e2f89
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/mono/sample/TestRun/.gdbinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
handle SIGXCPU SIG33 SIG35 SIG36 SIG37 SIG38 SIGPWR nostop print

define mono_backtrace
select-frame 0
set $i = 0
while ($i < $arg0)
set $foo = (char*) mono_pmip ($pc)
if ($foo)
printf "#%d %p in %s\n", $i, $pc, $foo
else
frame
end
up-silently
set $i = $i + 1
end
end

define mono_stack
set $mono_thread = mono_thread_current ()
if ($mono_thread == 0x00)
printf "No mono thread associated with this thread\n"
else
set $ucp = (MonoContext*)malloc (sizeof (MonoContext))
set $ucp->gregs[0] = $pc
set $ucp->gregs[2] = $sp
set $ucp->gregs[8] = $sp
call (void) mono_print_thread_dump ($ucp)
call (void) free ($ucp)
end
end
149 changes: 149 additions & 0 deletions src/mono/sample/TestRun/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
TOP=../../../../
DOTNET:=$(TOP)dotnet.sh
DOTNET_Q_ARGS=--nologo -v:q -consoleloggerparameters:NoSummary

MONO_CONFIG?=Debug
MONO_ARCH=riscv64
TARGET_OS=linux
AOT?=false
QEMU=qemu-riscv64-static
SAMPLE_PATH=/home/wuxinlong/workspace/samples/csharp/getting-started/console-webapiclient
CORE_BASELINE_ROOT=/home/wuxinlong/workspace/runtime/artifacts/tests/coreclr/linux.x64.Debug/Tests/Core_Root
ANY_PATH= /home/wuxinlong/workspace/runtime/artifacts/tests/coreclr/linux.riscv64.Debug/JIT/Directed/Directed_3/Directed_3.dll

GitHubKey=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

#NET_TRACE_PATH=<path-to-trace-of-sample>
#PGO_BINARY_PATH=<path-to-dotnet-pgo-executable>
#MIBC_PROFILE_PATH=<path-to-mibc-for-sample>

MONO_ENV_DEBUG_OPTIONS = "-v --trace=all --break AliasingRetBuf:TestEntryPoint"
MONO_ENV_RUN_OPTIONS="--trace=N:System.AppContext"

build: TestRun.cs
@mcs TestRun.cs

run-baseline: build
COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS=$(MONO_ENV_RUN_OPTIONS) \
$(TOP)artifacts/bin/testhost/net8.0-$(TARGET_OS)-Debug-x64/dotnet TestRun.exe

run-any-baseline:
COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS=$(MONO_ENV_RUN_OPTIONS) \
CORE_ROOT=${CORE_BASELINE_ROOT} \
${CORE_BASELINE_ROOT}/corerun -p System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true $(ANY_PATH)

run: build
@COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS=$(MONO_ENV_RUN_OPTIONS) \
$(QEMU) -L $(TOP)/.tools/rootfs/riscv64/ $(TOP)artifacts/bin/testhost/net9.0-$(TARGET_OS)-Debug-$(MONO_ARCH)/dotnet TestRun.exe

run-any:
COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS=$(MONO_ENV_RUN_OPTIONS) \
${CORE_ROOT}/corerun -p System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true $(ANY_PATH)

run-webapiclient-baseline:
COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS=$(MONO_ENV_RUN_OPTIONS) \
$(TOP)artifacts/bin/testhost/net8.0-$(TARGET_OS)-Debug-x64/dotnet \
$(SAMPLE_PATH)/bin/Debug/net8.0/webapiclient.dll

run-webapiclient:
COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS=$(MONO_ENV_RUN_OPTIONS) \
$(QEMU) -L $(TOP).tools/rootfs/riscv64/ \
$(TOP)artifacts/bin/testhost/net8.0-linux-Debug-riscv64/dotnet \
$(SAMPLE_PATH)/bin/Debug/net8.0/webapiclient.dll

debug: build
COMPlus_DebugWriteToStdErr=1 \
MONO_LOG_LEVEL=debug MONO_LOG_MASK=all \
MONO_ENV_OPTIONS=$(MONO_ENV_DEBUG_OPTIONS) \
$(QEMU) -L $(TOP)/.tools/rootfs/riscv64/ \
-g 12345 \
$(TOP)artifacts/bin/testhost/net8.0-$(TARGET_OS)-Debug-$(MONO_ARCH)/dotnet TestRun.exe &\
gdb-multiarch -ex 'target remote localhost:12345' \
-ex "set sysroot $(TOP).tools/rootfs/riscv64" -ex "set solib-search-path $(TOP)artifacts/bin/testhost/net8.0-linux-Debug-riscv64/shared/Microsoft.NETCore.App/8.0.0" \
-ex "b mini.c:2156" \
$(TOP)artifacts/bin/testhost/net8.0-$(TARGET_OS)-Debug-$(MONO_ARCH)/dotnet

debug-webapiclient:
COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS=$(MONO_ENV_DEBUG_OPTIONS) \
$(QEMU) -L $(TOP)/.tools/rootfs/riscv64/ \
-g 12345 \
$(TOP)artifacts/bin/testhost/net8.0-$(TARGET_OS)-Debug-$(MONO_ARCH)/dotnet \
$(SAMPLE_PATH)/bin/Debug/net8.0/webapiclient.dll &\
gdb-multiarch -ex 'target remote localhost:12345' \
-ex "set sysroot $(TOP).tools/rootfs/riscv64" \
-ex "set solib-search-path $(TOP)artifacts/bin/testhost/net8.0-linux-Debug-riscv64/shared/Microsoft.NETCore.App/8.0.0" \
-ex "b mini.c:2156" \
$(TOP)artifacts/bin/testhost/net8.0-$(TARGET_OS)-Debug-$(MONO_ARCH)/dotnet

debug-any:
COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS=$(MONO_ENV_DEBUG_OPTIONS) \
$(QEMU) -g 12345 \
${CORE_ROOT}/corerun -p System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true $(ANY_PATH) &\
gdb-multiarch -ex 'target remote localhost:12345' \
-iex "add-auto-load-safe-path /home/wuxinlong/workspace/runtime/src/mono/sample/TestRun/" \
-ex "set sysroot $(TOP).tools/rootfs/riscv64" \
-ex "set solib-search-path ${CORE_ROOT}" \
-ex "b mono_break" \
-ex "handle SIGXCPU SIG33 SIG35 SIG36 SIG37 SIG38 SIGPWR print nostop ignore" \
${CORE_ROOT}/corerun

remote_gdb:
gdb-multiarch -ex 'target remote localhost:32427' \
-iex "add-auto-load-safe-path /home/wuxinlong/workspace/runtime/src/mono/sample/TestRun/" \
-ex "set sysroot $(TOP).tools/rootfs/riscv64" \
-ex "set solib-search-path $(TOP)artifacts/bin/testhost/net8.0-linux-Debug-riscv64/shared/Microsoft.NETCore.App/8.0.0" \
-ex "b mini.c:2156" \
-ex "handle SIG35 print nostop ignore" \
${CORE_ROOT}/corerun


debug-any-baseline:
COMPlus_DebugWriteToStdErr=1 \
MONO_ENV_OPTIONS=$(MONO_ENV_DEBUG_OPTIONS) \
gdb \
-ex "set solib-search-path ${CORE_BASELINE_ROOT}" \
--args ${CORE_BASELINE_ROOT}/corerun -p System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true $(ANY_PATH) \
$(ANY_PATH) \

clean:
rm -f *.exe *.exe.mdb

move:
cp /home/wuxinlong/workspace/runtime/artifacts/obj/mono/linux.riscv64.Debug/out/lib/libcoreclr.so /home/wuxinlong/workspace/dotnet-riscv/.dotnet/shared/Microsoft.NETCore.App/8.0.1/libcoreclr.so

# ILGEN_0xf64b7da3:Method_0xcb0b0b48
# 306

# converting method PrimitiveVT.VT1B PrimitiveVT.CallConv3:f2 (PrimitiveVT.VT1A,PrimitiveVT.VT1B)

# COMPlus_DebugWriteToStdErr="1" MONO_LOG_LEVEL="debug" MONO_LOG_MASK="all" COREHOST_TRACE="1" COREHOST_TRACE_VERBOSITY="4" MONO_ENV_OPTIONS="--compile-all --trace=all" qemu-riscv64 -L ../../../..//.tools/rootfs/riscv64/ -g 12345 ../../../../artifacts/bin/testhost/net8.0-Linux-Debug-riscv64/dotnet TestRun.exe

# ROOTFS_DIR="" ./build.sh mono+libs+host -c Debug
# ./build.sh mono+libs+host -c Debug --cross --arch riscv64 --build

# ROOTFS_DIR="" ./build.sh clr.hosts -c Debug

# ROOTFS_DIR="" ./build.sh mono+libs+host -c Debug --ninja /p:KeepNativeSymbols=true
# ./build.sh mono+libs+host+clr.hosts -c Debug --cross --arch riscv64 --ninja /p:KeepNativeSymbols=true --build
# CORT_ROOT=/home/wuxinlong/workspace/runtime/artifacts/tests/coreclr/linux.x64.Debug
# ./build.sh -mono -debug riscv64 -ninja /p:KeepNativeSymbols=true
# ./build.sh clr.hosts --cross --arch riscv64 --ninja /p:KeepNativeSymbols=true



# /home/wuxinlong/workspace/runtime/.tools/rootfs/riscv64/bin/gdb \
# -ex "set sysroot /home/wuxinlong/workspace/runtime/.tools/rootfs/riscv64" \
# -ex "set solib-search-path /home/wuxinlong/workspace/dotnet-riscv/.dotnet/shared/Microsoft.NETCore.App/8.0.1:/home/wuxinlong/workspace/dotnet-riscv/.dotnet/host/fxr/8.0.1"

# MONO_ENV_OPTIONS="-v" qemu-riscv64-static -g 12345 /home/wuxinlong/workspace/dotnet-riscv/.dotnet/dotnet build

# MONO_ENV_OPTIONS="--break Microsoft.Build.Evaluation.ProjectRootElementCache:GetOrLoad --trace=N:Microsoft.Build.Evaluation,-program,-assembly,-wrapper" qemu-riscv64-static -g 12345 /home/wuxinlong/workspace/dotnet-riscv/.dotnet/dotnet /home/wuxinlong/workspace/dotnet-riscv/.dotnet/sdk/8.0.101/MSBuild.dll -consoleloggerparameters:Summary -maxcpucount -restore -verbosity:diag ./HelloWorld.csproj
# /home/wuxinlong/workspace/runtime/.tools/rootfs/riscv64/bin/gdb -ex "target remote localhost:12345" -ex "set sysroot /home/wuxinlong/workspace/runtime/.tools/rootfs/riscv64" -ex "set solib-search-path /home/wuxinlong/workspace/dotnet-riscv/.dotnet/shared/Microsoft.NETCore.App/8.0.1:/home/wuxinlong/workspace/dotnet-riscv/.dotnet/host/fxr/8.0.1" -ex "handle SIGXCPU SIG33 SIG35 SIG36 SIG37 SIG38 SIGPWR print stop ignore" -ex "b mono_break"
23 changes: 23 additions & 0 deletions src/mono/sample/TestRun/TestRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// C# Hello World

using System;

public class Test
{
public static void TestRun()
{
int i;
int len = 50;
var rand = new Random();
while (len != 0)
{
i = rand.Next(0, 1);
len /= 2;
}
}

public static void Main()
{
TestRun();
}
}
61 changes: 61 additions & 0 deletions src/mono/sample/TestRun/TestRun.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<!-- always set SelfContained when running to use Mono on desktop -->
<SelfContained>true</SelfContained>
</PropertyGroup>

<UsingTask TaskName="MonoAOTCompiler"
AssemblyFile="$(MonoAOTCompilerTasksAssemblyPath)" />

<Target Name="AOTCompileApp" Condition="'$(RunAOTCompilation)' == 'true'" AfterTargets="CopyFilesToPublishDirectory">
<PropertyGroup>
<_AotOutputType>Library</_AotOutputType>
<_AotLibraryFormat>Dylib</_AotLibraryFormat>
<UseAotDataFile>false</UseAotDataFile>
</PropertyGroup>

<ItemGroup>
<AotInputAssemblies Include="$(PublishDir)\*.dll" />
</ItemGroup>

<MonoAOTCompiler
CompilerBinaryPath="@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','$(TargetOS)-$(TargetArchitecture.ToLowerInvariant())'))"
OutputType="$(_AotOutputType)"
LibraryFormat="$(_AotLibraryFormat)"
Assemblies="@(AotInputAssemblies)"
OutputDir="$(PublishDir)"
CollectTrimmingEligibleMethods="$(StripILCode)"
TrimmingEligibleMethodsOutputDirectory="$(TrimmingEligibleMethodsOutputDirectory)"
IntermediateOutputPath="$(IntermediateOutputPath)"
UseAotDataFile="$(UseAotDataFile)"
MibcProfilePath="$(MibcProfilePath)"
UseLLVM="$(MonoEnableLLVM)"
LLVMPath="$(MonoAotCrossDir)">
<Output TaskParameter="CompiledAssemblies" ItemName="BundleAssemblies" />
</MonoAOTCompiler>
</Target>

<UsingTask TaskName="ILStrip"
AssemblyFile="$(MonoTargetsTasksAssemblyPath)" />

<Target Name="StripILCode" Condition="'$(StripILCode)' == 'true'" AfterTargets="AOTCompileApp">
<PropertyGroup>
<TrimIndividualMethods>true</TrimIndividualMethods>
</PropertyGroup>

<ILStrip
TrimIndividualMethods="$(TrimIndividualMethods)"
Assemblies="@(BundleAssemblies)">
<Output TaskParameter="TrimmedAssemblies" ItemName="TrimmedAssemblies" />
</ILStrip>

<Copy
SourceFiles="@(TrimmedAssemblies->Metadata('TrimmedAssemblyFileName'))"
DestinationFiles="@(TrimmedAssemblies)"
OverwriteReadOnlyFiles="true"
/>
<Delete Files="@(TrimmedAssemblies->Metadata('TrimmedAssemblyFileName'))" />
</Target>
</Project>
9 changes: 9 additions & 0 deletions src/mono/sample/TestRun/TestRun.runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
}
}
}

0 comments on commit 95e2f89

Please sign in to comment.