WinDbg - 명령어 내에서 환경 변수 사용법
아쉽게도 WinDbg의 표현식에서 환경 변수를 사용할 수는 없습니다.
그래서, .load와 같은 명령어를 사용할 때 (윈도우 명령행처럼) 환경 변수를 이용하면 오류가 발생합니다.
0:00> .load "%USERPROFILE%\\.dotnet\\sos\\sos.dll"
The call to LoadLibrary(%USERPROFILE%\.dotnet\sos\sos.dll) failed, Win32 error 0n2
"The system cannot find the file specified."
...[생략]...
위의 결과에도 나오지만, "%USERPROFILE%"을 환경 변수로 인식하는 것이 아니라 경로명 자체로 인식하기 때문입니다.
대신, 우회하는 방법이 하나 있긴 한데요, "as" 명령어를 이용해,
as, aS (Set Alias)
; https://learn.microsoft.com/en-us/windows-hardware/drivers/debuggercmds/as--as--set-alias-
이렇게 WinDbg 변수로 정의할 수 있습니다.
// https://community.osr.com/t/how-to-nest-if-token/39299/5
0:014> as /e MyEnvVar USERPROFILE
그럼, 다음과 같이 각종 WinDbg 명령에서 사용할 수 있습니다.
0:014> .echo ${MyEnvVar}
C:\Users\testusr
0:014> .load ${MyEnvVar}\.dotnet\sos\sos.dll
0:014> .chain
Extension DLL search Path:
...[생략]...
Extension DLL chain:
C:\Users\testusr\.dotnet\sos\sos.dll: image 9,0,12,7501 @Commit: a651406e39038aef1dbc7c8097b52953284dba27, API 2.0.0, built Sat Jan 25 17:30:17 2025
[path: C:\Users\testusr\.dotnet\sos\sos.dll]
kdexts: image 10.0.27793.1000, API 1.0.0,
...[생략]...
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]