Gdb
Overview
리눅스 gdb 사용법 내용 정리.
Basic
gdb 이용시, 보통 다음의 순서로 진행된다.
- gdb 를 core 파일과 같이 실행
- where 명령어로 crash 가 발생했던 스택을 확인.
- frame 명령어로 의심스러운 frame 지정.
- list 명령어로 대략적인 코드 내용 확인
- print 명령어로 variable print.
위의 내용 반복..
(gdb) where #0 0x00007fe87fa6c0c2 in pj_strdup (pool=0x7fe7509ef1e0, dst=0x7fe76d5fca18, src=0x0) at ../include/pj/string_i.h:40 #1 0x00007fe87fa15e84 in pjmedia_sdp_neg_modify_local_offer2 (pool=0x7fe7509ef1e0, neg=0x7fe76da058c0, flags=1, local=0x7fe76dc558a8) at ../src/pjmedia/sdp_neg.c:336 #2 0x00007fe87f9928b0 in pjsip_inv_reinvite (inv=0x7fe76d9551e8, new_contact=0x0, new_offer=0x7fe76dc558a8, p_tdata=0x7fe7aff81ba0) at ../src/pjsip-ua/sip_inv.c:3004 #3 0x00007fe821af5c6c in ast_sip_session_refresh (session=0x7fe76dbbb290, on_request_creation=0x0, on_sdp_creation=0x0, on_response=0x7fe80a9028ae <on_topology_change_response>, method=AST_SIP_SESSION_REFRESH_METHOD_INVITE, generate_new_sdp=1, media_state=0x7fe834cfa590) at res_pjsip_session.c:1750 #4 0x00007fe821af443b in send_delayed_request (session=0x7fe76dbbb290, delay=0x7fe7ee8f97d0) at res_pjsip_session.c:1238 #5 0x00007fe821af479d in invite_terminated (vsession=0x7fe76dbbb290) at res_pjsip_session.c:1337 #6 0x00005582959ce79e in ast_taskprocessor_execute (tps=0x7fe76d9174c0) at taskprocessor.c:1185 #7 0x00005582959d808e in execute_tasks (data=0x7fe76d9174c0) at threadpool.c:1354 #8 0x00005582959ce79e in ast_taskprocessor_execute (tps=0x558298a5ad80) at taskprocessor.c:1185 #9 0x00005582959d5c41 in threadpool_execute (pool=0x558298a55c30) at threadpool.c:367 #10 0x00005582959d78c0 in worker_active (worker=0x7fe7db36acc0) at threadpool.c:1137 #11 0x00005582959d7630 in worker_start (arg=0x7fe7db36acc0) at threadpool.c:1056 #12 0x00005582959e0fd0 in dummy_start (data=0x7fe7db36ad80) at utils.c:1249 #13 0x00007fe87e0fe4a4 in start_thread (arg=0x7fe7aff82700) at pthread_create.c:456 #14 0x00007fe87c9bfd0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97 (gdb) frame 4 #4 0x00007fe821af443b in send_delayed_request (session=0x7fe76dbbb290, delay=0x7fe7ee8f97d0) at res_pjsip_session.c:1238 1238 ast_sip_session_refresh(session, delay->on_request_creation, (gdb) list 1233 session->channel ? ast_channel_name(session->channel) : "", 1234 delayed_method2str(delay->method)); 1235 1236 switch (delay->method) { 1237 case DELAYED_METHOD_INVITE: 1238 ast_sip_session_refresh(session, delay->on_request_creation, 1239 delay->on_sdp_creation, delay->on_response, 1240 AST_SIP_SESSION_REFRESH_METHOD_INVITE, delay->generate_new_sdp, delay->media_state); 1241 /* Ownership of media state transitions to ast_sip_session_refresh */ 1242 delay->media_state = NULL; (gdb) p delay->method $4 = DELAYED_METHOD_INVITE
ETC
Print pretty
strucuture 프린트시, 읽기 쉽게 프린팅이 된다.
(gdb) set print pretty on (gdb) print *dst $2 = { ptr = 0x7fe76d5fcf58 "-\377<l\347\177", slen = 1 } (gdb) set print pretty off (gdb) print *dst $3 = {ptr = 0x7fe76d5fcf58 "-\377<l\347\177", slen = 1}