Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 3개 있습니다.)

마이크로소프트의 CoreCLR 프로파일러 리눅스 예제를 Visual Studio F5 원격 디버깅하는 방법

CoreCLR 프로파일러 예제를 리눅스 운영체제에서 빌드해 보고,

마이크로소프트의 CoreCLR 프로파일러 예제 빌드 방법
; https://www.sysnet.pe.kr/2/0/11294

이것을 Visual Studio의 CMake 프로젝트로 변경도 해봤는데요.

마이크로소프트의 CoreCLR 프로파일러 예제를 Visual Studio CMake로 빌드하는 방법
; https://www.sysnet.pe.kr/2/0/11842

F5 디버깅이 안 된다는 것은 차라리 리눅스에서 개발하는 것이 나을 정도이므로 별로 효용성이 없습니다. 하지만, 이 프로젝트를 비주얼 스튜디오의 리눅스 프로젝트로 변경하면,

Visual Studio 2019 - 리눅스 프로젝트를 이용한 공유/실행(so/out) 프로그램 개발 환경 설정
; https://www.sysnet.pe.kr/2/0/11844

F5 디버깅이 가능합니다. 변경 과정도 그다지 어렵지 않습니다. 그냥 리눅스 프로젝트 생성 후 위의 글에 설명한 데로 so 프로젝트로 변경하고 빌드에 필요한 dotnet core include 파일들을 포함하면 됩니다. include 파일들은 vcxproj 파일에 다음과 같은 식으로 일괄 포함하는 것도 가능하지만,

<ItemGroup>
    <ClInclude Include=".\cor\**\*.h" />
</ItemGroup>

일일이 추가해도 상관없습니다. 그다음 리눅스 측에서 빌드할 때 cor 폴더의 header 파일들을 찾을 수 있도록 "C/C++" / "General"의 "Additional Include Directories"에 다음의 4개 폴더를 등록합니다.

./cor/src/inc
./cor/src/pal/inc/rt
./cor/src/pal/inc
./cor/src/pal/prebuilt/inc

실제로 dotnet core 헤더 파일들에는 하위 폴더들이 많은데 프로파일러 예제 빌드로는 저 4개의 폴더만 있으면 됩니다. 그리고 "C/C++" / "Preprocessor"의 "Preprocessor Definitions"에 "BIT64;PAL_STDCPP_COMPAT;PLATFORM_UNIX" 매크로 상수도 추가한 후 경고를 없애기 위해 "C/C++" / "Command Line"의 "Additional Options"에 다음의 옵션도 넣어줍니다.

-Wno-undef -Wno-invalid-noreturn -fms-extensions -Wno-conversion -Wno-pragma-pack -Wno-unused-variable

마지막으로, "C/C++" / "General"의 "C++ Compiler"를 clang++로 변경하면 끝!

(첨부 파일은 이렇게 변경한 프로젝트 파일입니다.)




그럼 F5 디버깅을 해봐야 할 텐데요. 이를 위해 /etc/profile에 CORECLR 관련 환경 변수를 등록하든가,

$ sudo nano /etc/profile
 
export CORECLR_PROFILER={cf0d821e-299b-5307-a3d8-b283c03916dd}
export CORECLR_ENABLE_PROFILING=1
export CORECLR_PROFILER_PATH=~/projects/corprofiler/bin/x64/Debug/libcorprofiler.so

$ sudo source /etc/profile

아니면 프로젝트 속성 창의 "Debugging"에 "Pre-Launch Command"로 다음과 같이 환경 변수를 등록하면 됩니다.

export CORECLR_ENABLE_PROFILING=1; export CORECLR_PROFILER={cf0d821e-299b-5307-a3d8-b283c03916dd};export CORECLR_PROFILER_PATH=libcorprofiler.so;

(위에서는 CORECLR_PROFILER_PATH에 경로를 생략했는데 이렇게 하려면 /etc/ld.so.conf에 경로를 등록해야 합니다.)

그다음 실행 파일을 /usr/bin/dotnet으로, 인자로 닷넷 예제 프로젝트의 빌드된 DLL을 주면,

Program: /usr/bin/dotnet
Program Arguments: webapp.dll
Working Directory: ~/coreapp

이후 비주얼 스튜디오에서 F5 키를 눌러 원격 디버깅을 진행할 수 있습니다. 오~~~ 이제야 개발할 맛이 납니다. ^^




참고로, 기본 프로파일러 예제는 의존성이 많은데요,

$ ldd ~/projects/corprofiler/bin/x64/Debug/libcorprofiler.so
        linux-vdso.so.1 (0x00007ffda3b38000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa7b5cda000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa7b5ac2000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa7b56d1000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa7b5333000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa7b627b000)

다음의 글에 따라 어느 정도 줄이는 것이 가능합니다.

Linux 응용 프로그램의 (C++) so 의존성 줄이기(ReleaseMinDependency)
; https://www.sysnet.pe.kr/2/0/11845

export된 symbol을 보면 재미있는 점이 있는데요.

$ nm ~/projects/corprofiler/bin/x64/Debug/libcorprofiler.so
0000000000011380 V CLSID_CLR_v1_MetaData
0000000000011390 V CLSID_CLR_v2_MetaData
0000000000011470 V CLSID_Cor
0000000000011480 V CLSID_CorMetaDataDispenser
0000000000011490 V CLSID_CorMetaDataDispenserReg
0000000000011330 V CLSID_CorMetaDataDispenserRuntime
00000000000114a0 V CLSID_CorMetaDataReg
0000000000217008 d DW.ref.__gxx_personality_v0
000000000000e410 T DecoderGetOnDiskSize
000000000000e290 T DecoderInit
000000000000e240 T DllCanUnloadNow
000000000000e170 T DllGetClassObject
0000000000217018 D EnterMethodAddress
000000000001419c r GCC_except_table1
...[생략]...

저렇게 윈도우에서의 프로파일러와 유사한 COM 접근 방식을 리눅스에서도 그대로 흉내 내고 있습니다. ^^ 실제로 소스코드를 봐도 vtable 기반 하의 COM 접근 방식을 동일하게 구현하고 있습니다.




dotnet core의 헤더 파일들을 모두 포함시키면 다음과 같은 식의 빌드 오류가 발생할 수 있습니다.

1>  Task "MultiToolTask" skipped, due to false condition; ('%(Midl.ExcludedFromBuild)'!='true' and '$(UseMultiToolTask)' == 'true') was evaluated as (''!='true' and '' == 'true').
1>  Using "MIDL" task from assembly "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Microsoft\VC\v160\Microsoft.Build.CppTasks.Common.dll".
1>  Task "MIDL"
1>    midl.exe  cor\src\inc\clrdata.idl
1>    Tracking command:
1>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Tracker.exe /d "C:\Program Files (x86)\MSBuild\15.0\FileTracker\FileTracker32.dll" /r C:\BUILD_VS_CLR_SAMPLES\CORPROFILER\CORPROFILER\COR\SRC\INC\CLRDATA.IDL /b MSBuildConsole_CancelEvent9ebc403f3abc41d38c14e3110ec31c70  /c midl.exe   cor\src\inc\clrdata.idl
1>    TRACKER : error TRK0005: Failed to locate: "midl.exe". The system cannot find the file specified.
1>

왜냐하면, 포함된 폴더에는 헤더 파일뿐만 아니라 idl, rc, cpp 등의 파일도 있기 때문인데요, 따라서 그 파일들은 빌드에서 제외해야 합니다.




리눅스 프로젝트 빌드 시 다음과 같은 오류가 발생한다면?

1>  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\Linux.targets(151,5): error : Current project architecture 'ARM' is incompatible with the remote system architecture 'x64' ('x64'). Please switch the project architecture to 'x64' in Configuration Manager.

현재 비주얼 스튜디오의 빌드 타겟이 ARM으로 설정되어 있기 때문입니다. x64로 바꿔주면 정상적으로 빌드가 됩니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 3/26/2019]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2019-05-21 03시22분
How to debug .net core 2 app on linux server via visual studio 2017 on windows? [Music no 4]
; http://tomaszjarzynski.pl/how-debug-net-core-2-app-linux-server-via-visual-studio-2017-windows-music-4/

Debugging ASP Core on Linux with Visual Studio 2017
; https://blogs.msdn.microsoft.com/premier_developer/2017/11/10/debugging-asp-core-on-linux-with-visual-studio-2017/
정성태

... 61  62  63  64  65  66  67  68  69  70  71  72  [73]  74  75  ...
NoWriterDateCnt.TitleFile(s)
11817정성태2/17/20199954오류 유형: 514. WinDbg Preview 실행 오류 - Error : DbgX.dll : WindowsDebugger.WindowsDebuggerException: Could not load dbgeng.dll
11816정성태2/17/201912469Windows: 157. 윈도우 스토어 앱(Microsoft Store App)을 명령행에서 직접 실행하는 방법
11815정성태2/14/201911359오류 유형: 513. Visual Studio 2019 - VSIX 설치 시 "The extension cannot be installed to this product due to prerequisites that cannot be resolved." 오류 발생
11814정성태2/12/201910170오류 유형: 512. VM(가상 머신)의 NT 서비스들이 자동 시작되지 않는 문제
11813정성태2/12/201911760.NET Framework: 809. C# - ("Save File Dialog" 등의) 대화 창에 확장 속성을 보이는 방법
11812정성태2/11/20199624오류 유형: 511. Windows Server 2003 VM 부팅 후 로그인 시점에 0xC0000005 BSOD 발생
11811정성태2/11/201913390오류 유형: 510. 서버 운영체제에 NVIDIA GeForce Experience 실행 시 wlanapi.dll 누락 문제
11810정성태2/11/201911455.NET Framework: 808. .NET Profiler - GAC 모듈에서 GAC 비-등록 모듈을 참조하는 경우의 문제
11809정성태2/11/201912960.NET Framework: 807. ClrMD를 이용해 메모리 덤프 파일로부터 특정 인스턴스를 참조하고 있는 소유자 확인
11808정성태2/8/201914022디버깅 기술: 123. windbg - 닷넷 응용 프로그램의 메모리 누수 분석
11807정성태1/29/201912322Windows: 156. 가상 디스크의 용량을 복구 파티션으로 인해 늘리지 못하는 경우 [4]
11806정성태1/29/201912057디버깅 기술: 122. windbg - 덤프 파일로부터 PID와 환경 변수 등의 정보를 구하는 방법
11805정성태1/28/201913908.NET Framework: 806. C# - int []와 object []의 차이로 이해하는 제네릭의 필요성 [4]파일 다운로드1
11804정성태1/24/201911950Windows: 155. diskpart - remove letter 이후 재부팅 시 다시 드라이브 문자가 할당되는 경우
11803정성태1/10/201911449디버깅 기술: 121. windbg - 닷넷 Finalizer 스레드가 멈춰있는 현상
11802정성태1/7/201912819.NET Framework: 805. 두 개의 윈도우를 각각 실행하는 방법(Windows Forms, WPF)파일 다운로드1
11801정성태1/1/201913855개발 환경 구성: 427. Netsh의 네트워크 모니터링 기능 [3]
11800정성태12/28/201813144오류 유형: 509. WCF 호출 오류 메시지 - System.ServiceModel.CommunicationException: Internal Server Error
11799정성태12/19/201813956.NET Framework: 804. WPF(또는 WinForm)에서 UWP UI 구성 요소 사용하는 방법 [3]파일 다운로드1
11798정성태12/19/201813196개발 환경 구성: 426. vcpkg - "Building vcpkg.exe failed. Please ensure you have installed Visual Studio with the Desktop C++ workload and the Windows SDK for Desktop C++"
11797정성태12/19/201810552개발 환경 구성: 425. vcpkg - CMake Error: Problem with archive_write_header(): Can't create '' 빌드 오류
11796정성태12/19/201810208개발 환경 구성: 424. vcpkg - "File does not have expected hash" 오류를 무시하는 방법
11795정성태12/19/201812608Windows: 154. PowerShell - Zone 별로 DNS 레코드 유형 정보 조회 [1]
11794정성태12/16/20189999오류 유형: 508. Get-AzureWebsite : Request to a downlevel service failed.
11793정성태12/16/201811622개발 환경 구성: 423. NuGet 패키지 제작 - Native와 Managed DLL을 분리하는 방법 [1]
11792정성태12/11/201812386Graphics: 34. .NET으로 구현하는 OpenGL (11) - Per-Pixel Lighting파일 다운로드1
... 61  62  63  64  65  66  67  68  69  70  71  72  [73]  74  75  ...