λ°μν
π‘ λ³Έ λ¬Έμλ 'gdbλ₯Ό νμ©ν μ€ν μ€μΈ νλ‘μΈμ€ & μ€λ λ λλ²κΉ νκΈ°'μ λν΄ μ 리ν΄λμ κΈμ λλ€.
λ±ν νλ‘μΈμ€κ° μ£½μ κ²μ μλλ° κ³Όλνκ² cpuλ₯Ό μ‘κ³ μκ±°λ(νΉμ μ€λ λ 무ν루ν), νλ‘μΈμ€κ° μ΄μλ μμ§λ§ μλ¬΄λ° μλ΅μ νμ§ μλ(λ°λλ½) κ²½μ°κ° μμ΅λλ€. νΉμ μ΄κ²½μ°μ μ¬μ©νλ gdb λλ²κ±°λ₯Ό μ΄μ©νμ¬ μ€ν μ€μΈ νλ‘μΈμ€μ μ§μ λΆμ΄ νμ¬ μνλ₯Ό 체ν¬νλ λ°©λ²μ μ 리νμμΌλ μ°Έκ³ λΆνλ립λλ€.
1. μ€λ λ/νλ‘μΈμ€ μν νμΈνκΈ°
$ ps -eLf | grep <process name>
UID PID PPID LWP C NLWP STIME TTY TIME CMD
kukuta 11048 1 11048 0 8 10:52 pts/0 00:00:00 <process name>
kukuta 11048 1 11050 1 8 10:52 pts/0 00:00:27 <process name>
kukuta 11048 1 11051 0 8 10:52 pts/0 00:00:19 <process name>
kukuta 11048 1 11052 0 8 10:52 pts/0 00:00:19 <process name>
kukuta 11048 1 11053 0 8 10:52 pts/0 00:00:00 <process name>
kukuta 11048 1 11054 0 8 10:52 pts/0 00:00:00 <process name>
kukuta 11048 1 11055 0 8 10:52 pts/0 00:00:00 <process name>
kukuta 11048 1 11056 0 8 10:52 pts/0 00:00:00 <process name>
- psμ e μ΅μ μ μ 체 νλ‘μΈμ€λ₯Ό μΆλ ₯, Lμ μ€λ λ μν, fλ μΆλ ₯ν μ μλ λͺ¨λ λ΄μ©μ μΆλ ₯νλΌλ μλ―Έμ λλ€.
- μ¬κΈ°μ, LWP(Light Weight Process) μΉΌλΌμ Thread IDλ₯Ό λνλ΄λ κ²μ λλ€.
2. μ€ν μ€μΈ νλ‘μΈμ€ μ κ·ΌνκΈ°
2.1 μ€νμ€μΈ νλ‘μΈμ€μ gdb λ‘ μ κ·ΌνκΈ°(Attaching 'gdb' on running process)
$ gdb -p <pid>
- λ§μΌ μ€ν κΆνμ΄ μΆ©λΆμΉ μλ€λ μλ¬ λ©μμ§κ° λμ€λ©΄ sudoλ‘ μ€νν΄μΌ ν©λλ€.
2.2 μ€λ λμ μν 보기
(gdb) info threads
ββId Target Id Frame
ββ8 Thread 0x7f0ec8fcc700 (LWP 11050) "<process name>" 0x00007f0ecdb81dbd in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
ββ7 Thread 0x7f0ec3fff700 (LWP 11051) "<process name>" 0x00007f0ecdbb69b3 in epoll_wait () from /lib/x86_64-linux-gnu/libc.so.6
ββ6 Thread 0x7f0ec37fe700 (LWP 11052) "<process name>" 0x00007f0ecdbb69b3 in epoll_wait () from /lib/x86_64-linux-gnu/libc.so.6
ββ5 Thread 0x7f0ec2ffd700 (LWP 11053) "<process name>" 0x00007f0ecdbb69b3 in epoll_wait () from /lib/x86_64-linux-gnu/libc.so.6
ββ4 Thread 0x7f0ec27fc700 (LWP 11054) "<process name>" 0x00007f0ecee09d84 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/x86_64-linux-gnu/libpthread.so.0
ββ3 Thread 0x7f0ec1ffb700 (LWP 11055) "<process name>" 0x00007f0ecee09d84 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/x86_64-linux-gnu/libpthread.so.0
ββ2 Thread 0x7f0ec17fa700 (LWP 11056) "<process name>" 0x00007f0ecee09d84 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/x86_64-linux-gnu/libpthread.so.0
* 1 Thread 0x7f0ecf67db00 (LWP 11048) "<process name>" 0x00007f0ecee09d84 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/x86_64-linux-gnu/libpthread.so.0
2.3 λͺ¨λ μ€λ λλ€μ νΈμΆ μ€ν 보기
(gdb) thread apply all bt
2.4 λλ²κ±°κ° λΆμ΄ μλ μ€λ λ λ³κ²½νκΈ°
(gdb) thread <tid>
2.5 μ€λ λμ νΈμΆ μ€ν 보기
(gdb) bt
μ°Έκ³
- [stackoverflow] how-to-attach-a-process-in-gdb: http://stackoverflow.com/questions/14370972/how-to-attach-a-process-in-gdb
- [Tistory] gdb - μ€ν μ€μΈ νλ‘μΈμ€ & μ€λ λ λλ²κΉ νκΈ°: https://kukuta.tistory.com/202
- gdb - breakpoint: http://kukuta.tistory.com/163
- GDB Tutorial: http://kukuta.tistory.com/3
λ°μν