Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

(시리즈 글이 6개 있습니다.)
Linux: 6. getenv, setenv가 언어/운영체제마다 호환이 안 되는 문제
; https://www.sysnet.pe.kr/2/0/11846

Linux: 11. 리눅스의 환경 변수 관련 함수 정리 - putenv, setenv, unsetenv
; https://www.sysnet.pe.kr/2/0/11915

Linux: 66. 리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (gdb)
; https://www.sysnet.pe.kr/2/0/13496

Linux: 80. 리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (lldb)
; https://www.sysnet.pe.kr/2/0/13745

Linux: 81. Linux - PATH 환경변수의 적용 규칙
; https://www.sysnet.pe.kr/2/0/13753

Linux: 104. Linux - COLUMNS 환경변수가 언제나 80으로 설정되는 환경
; https://www.sysnet.pe.kr/2/0/13811




리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (lldb)

지난 글에서는 gdb를 예로 들었었는데요,

리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (gdb)
; https://www.sysnet.pe.kr/2/0/13496

이번에는 lldb 환경으로 살펴보겠습니다. 관련해서 검색해,

How to show an environment variable (that I did not set) in lldb?
; https://stackoverflow.com/questions/74449340/how-to-show-an-environment-variable-that-i-did-not-set-in-lldb

답변에 실린 명령어를 수행했더니 이런 결과가 나옵니다.

(lldb) expr int idx = 0; while (1) { char *str = ((char **)environ)[idx]; if (str == (char *) NULL) break; else printf("%d: %s\n", idx++, str); }

error: Multiple internal symbols found for 'environ'
id = {0x0000031a}, range = [0x0000007ff7fff338-0x0000007ff7fff340), name="environ"
id = {0x000031e7}, range = [0x0000007ff7c47298-0x0000007ff7c472a0), name="environ"
error: :1:48: use of undeclared identifier 'environ'
    1 | int idx = 0; while (1) { char *str = ((char **)environ)[idx]; if (str == (char *) NULL) break; else printf("%d: %s\n", idx++, str); }
      |                           

environ이라는 심벌로 2개가 있다는 건데요, 실제로 어떤 값을 가지고 있는지 둘 다 확인해 봤는데,

(lldb) memory read 0x0000007ff7fff338 0x0000007ff7fff340
...[생략 - 쓰레기 값 출력]...
(lldb) memory read 0x0000007ff7c47298 0x0000007ff7c472a0
...[생략 - 쓰레기 값 출력]...

모두 깨진 출력이 나왔습니다. 사실 메모리 범위만 해도 2개 모두 8바이트이기 때문에 환경변수가 아님을 짐작게 합니다.

그렇다면 뭐가 잘못됐을까요? ^^ 전에 gdb를 했던 경험으로 아마도 변수 이름이 "environ"이 아닌 "__environ"이 맞을 듯합니다. 그래서 다시 명령어를 실행해 보면,

(lldb) expr int idx = 0; while (1) { char *str = ((char **)__environ)[idx]; if (str == (char *) NULL) break; else printf("%d: %s\n", idx++, str); }
0: XDG_SESSION_TYPE=tty
1: LESSOPEN=| /usr/bin/lesspipe %s
2: TERM=xterm-256color
3: SHELL=/bin/bash
...[생략]...
29: DOTNET_BUNDLE_EXTRACT_BASE_DIR=/home/testusr/.cache/dotnet_bundle_extract
30: LESSCLOSE=/usr/bin/lesspipe %s %s

잘 나오는군요. ^^

(마이크로소프트가 procdump 말고 procexp를 리눅스 버전으로 만들었으면 좋겠습니다. ^^ UI가 있어 까다롭겠지만!)




찾다 보니 이런 글도 있습니다.

How to read environment variables of a process
; https://unix.stackexchange.com/questions/29128/how-to-read-environment-variables-of-a-process

echo '...'로 명령어를 gdb에 전달해 곧바로 결과를 얻을 수 있는 방법을 소개하고 있는데요, 가령 dotnet 프로세스라면 다음과 같이 내릴 수 있습니다.

// "p" == print, getenv 함수 호출

$ echo 'p (char *) getenv("PWD")' | gdb --quiet -p $(pidof dotnet) | sed -n 's/.*"\(.*\)"$/\1/p'

그나저나... 위의 명령어도 마찬가지지만, 리눅스에서의 어떤 '방법'이라고 하는 것들을 볼 때마다 느끼는 건데요, 딱히 외워지지는 않고 매번 찾아보게 되는 유형들이 대부분인 듯합니다. ^^;




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







[최초 등록일: ]
[최종 수정일: 9/28/2024]

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

비밀번호

댓글 작성자
 




... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13541정성태1/29/20249611VS.NET IDE: 188. launchSettings.json의 useSSL 옵션
13540정성태1/29/20249499Linux: 69. 리눅스 - "Docker Desktop for Windows" Container 환경에서 IPv6 Loopback Address 바인딩 오류
13539정성태1/26/20249306개발 환경 구성: 703. Visual Studio - launchSettings.json을 이용한 HTTP/HTTPS 포트 바인딩
13538정성태1/25/20249902닷넷: 2211. C# - NonGC(FOH) 영역에 .NET 개체를 생성파일 다운로드1
13537정성태1/24/202410693닷넷: 2210. C# - Native 메모리에 .NET 개체를 생성파일 다운로드1
13536정성태1/23/202410306닷넷: 2209. .NET 8 - NonGC Heap / FOH (Frozen Object Heap) [1]
13535정성태1/22/202410731닷넷: 2208. C# - GCHandle 구조체의 메모리 분석
13534정성태1/21/202410140닷넷: 2207. C# - SQL Server DB를 bacpac으로 Export/Import파일 다운로드1
13533정성태1/18/202410122닷넷: 2206. C# - TCP KeepAlive의 서버 측 구현파일 다운로드1
13532정성태1/17/202410175닷넷: 2205. C# - SuperSimpleTcp 사용 시 주의할 점파일 다운로드1
13531정성태1/16/202410556닷넷: 2204. C# - TCP KeepAlive에 새로 추가된 Retry 옵션파일 다운로드1
13530정성태1/15/20249835닷넷: 2203. C# - Python과의 AES 암호화 연동파일 다운로드1
13529정성태1/15/202410035닷넷: 2202. C# - PublishAot의 glibc에 대한 정적 링킹하는 방법
13528정성태1/14/202410196Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/202410286오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/202410613닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
13525정성태1/13/20249751오류 유형: 891. Visual Studio - Web Application을 실행하지 못하는 IISExpress
13524정성태1/12/20249780오류 유형: 890. 한국투자증권 KIS Developers OpenAPI - GW라우팅 중 오류가 발생했습니다.
13523정성태1/12/20249768오류 유형: 889. Visual Studio - error : A project with that name is already opened in the solution.
13522정성태1/11/202410613닷넷: 2200. C# - HttpClient.PostAsJsonAsync 호출 시 "Transfer-Encoding: chunked" 대신 "Content-Length" 헤더 처리
13521정성태1/11/202410258닷넷: 2199. C# - 한국투자증권 KIS Developers OpenAPI의 WebSocket Ping, Pong 처리
13520정성태1/10/20249930오류 유형: 888. C# - Unable to resolve service for type 'Microsoft.Extensions.ObjectPool.ObjectPool`....' [1]
13519정성태1/10/20249639닷넷: 2198. C# - Reflection을 이용한 ClientWebSocket의 Ping 호출파일 다운로드1
13518정성태1/9/202410368닷넷: 2197. C# - ClientWebSocket의 Ping, Pong 처리
13517정성태1/8/20249502스크립트: 63. Python - 공개 패키지를 이용한 위성 이미지 생성 (pystac_client, odc.stac)
13516정성태1/7/20249662닷넷: 2196. IIS - AppPool의 "Disable Overlapped Recycle" 옵션의 부작용
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...