首页 > 编程知识 正文

oracle账户被锁定(gdb查看调用栈信息)

时间:2023-05-04 09:52:49 阅读:68499 作者:4667

本案例演示了如何利用gdb调试死锁问题,在多线程场景中使用gdb调试多线程死锁

调试过程:

1 .为了再现死锁现象,自己写了死锁demo

[root@localhost迷路的刺猬] #./deadlock thread _ routine _ two : lockmutextwothread _ routine _ one : lockmutexonethone

[ root @ localhost~] # pstack usage 3360堆栈处理- id [ root @ localhost~] # PS-ef|grep deadlock|grep-vgreproot 000 pstack14759#在此,您可以向进程中的一个主线程添加两个子线程,以确定是否可以多次挂起。 如果线程堆栈仍然存在,则此线程为thread3(thread0x7f0e 309 c 0700 (lwp 14760 ) )0x 0007 f0e 30 d9C4 edin _ _ lll _ lock _ wait ) 可基本确认已固定lib64的10x 00007 f0e 30 d 97 dcb in _ l _ lock _ 883 (from/lib 64/libpthread.so.0 # 20x 00007 f0e 30 d 97 c98 in pthread _ mutex _ loor 3x 000000000400940 in thread _ routine _ one (arg=0x0) at/opt/test gdb/40x 0007 f0e 30 d 95dd d libpthread.so.0 # 50x 00007 f0e 30 abeeadinclone () from/lib 64/libc.so.6 thread0x7f0e 301 BF f f0x 00007 f0e 30 d9C4 edin _ lll _ lock _ wait (from/lib 64/libpthread.so.0 # 10x 0007 f0e 30 d 97 dcb in _ l _ lock )120x 00007 libpthread.so.0 # 30x 00000004009 CBI nthread _ routine deadlock.c :42 # 40x 00007 f0e 30 d 95dd 5in start _ thread () from 50x 0007 f0e 30 abeeadinclone libc.so.6 thread1(thread0x 7f 0e 311 b 3740 (lwp 14759 ) ) : #0x 0007 f0e 30 d 96 f 47 in pthread _ joread libb 64 10x 000000000400 a 85 in main (at/opt/test gdb/src/deadlock.c :69 (root@localhost ) ) (root @ localhost迷路的刺猬) ) ) 652 gdb调试正在运行的进程GNUgdb(gdb ) reresed Ee软件基础, Inc.licensegplv 3: gnugplversion3orla ter http://GNU.org/licenses/GPL.htmlthisisfreeesoftware 3360 youarefreeetochangeandrandrd otheextentpermittedbylaw.type ' show copying ' and ' show warranty ' for details.thisgdbwasconfiguredas ' x86 _ 65306;

-redhat-linux-gnu".For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>...Reading symbols from /opt/testgdb/迷路的小刺猬/deadLock...done.Attaching to program: /opt/testgdb/迷路的小刺猬/deadLock, process 14759Reading symbols from /lib64/libpthread.so.0...(no debugging symbols found)...done.[New LWP 14761][New LWP 14760][Thread debugging using libthread_db enabled]Using host libthread_db library "/lib64/libthread_db.so.1".Loaded symbols for /lib64/libpthread.so.0Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.Loaded symbols for /lib64/libc.so.6Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.Loaded symbols for /lib64/ld-linux-x86-64.so.20x00007f0e30d96f47 in pthread_join () from /lib64/libpthread.so.0Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7.x86_64(gdb) info thread #打印线程信息,可以看到线程 2 3都在等待加锁 Id Target Id Frame 3 Thread 0x7f0e309c0700 (LWP 14760) "deadLock" 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0 2 Thread 0x7f0e301bf700 (LWP 14761) "deadLock" 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0* 1 Thread 0x7f0e311b3740 (LWP 14759) "deadLock" 0x00007f0e30d96f47 in pthread_join () from /lib64/libpthread.so.0(gdb) Id Target Id Frame 3 Thread 0x7f0e309c0700 (LWP 14760) "deadLock" 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0 2 Thread 0x7f0e301bf700 (LWP 14761) "deadLock" 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0* 1 Thread 0x7f0e311b3740 (LWP 14759) "deadLock" 0x00007f0e30d96f47 in pthread_join () from /lib64/libpthread.so.0(gdb) Id Target Id Frame 3 Thread 0x7f0e309c0700 (LWP 14760) "deadLock" 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0 2 Thread 0x7f0e301bf700 (LWP 14761) "deadLock" 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0* 1 Thread 0x7f0e311b3740 (LWP 14759) "deadLock" 0x00007f0e30d96f47 in pthread_join () from /lib64/libpthread.so.0(gdb) thread 2 #切换到编号为2的线程[Switching to thread 2 (Thread 0x7f0e301bf700 (LWP 14761))]#0 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0(gdb) bt #打印线程堆栈#0 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0#1 0x00007f0e30d97dcb in _L_lock_883 () from /lib64/libpthread.so.0#2 0x00007f0e30d97c98 in pthread_mutex_lock () from /lib64/libpthread.so.0#3 0x00000000004009cb in thread_routine_two (arg=0x0) at /opt/testgdb/src/deadLock.c:42#4 0x00007f0e30d95dd5 in start_thread () from /lib64/libpthread.so.0#5 0x00007f0e30abeead in clone () from /lib64/libc.so.6(gdb) f 3 #打印堆栈信息编号为3的位置的代码#3 0x00000000004009cb in thread_routine_two (arg=0x0) at /opt/testgdb/src/deadLock.c:4242 pthread_mutex_lock(&gMutex1);(gdb) thread 3[Switching to thread 3 (Thread 0x7f0e309c0700 (LWP 14760))]#0 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0(gdb) bt#0 0x00007f0e30d9c4ed in __lll_lock_wait () from /lib64/libpthread.so.0#1 0x00007f0e30d97dcb in _L_lock_883 () from /lib64/libpthread.so.0#2 0x00007f0e30d97c98 in pthread_mutex_lock () from /lib64/libpthread.so.0#3 0x0000000000400940 in thread_routine_one (arg=0x0) at /opt/testgdb/src/deadLock.c:19#4 0x00007f0e30d95dd5 in start_thread () from /lib64/libpthread.so.0#5 0x00007f0e30abeead in clone () from /lib64/libc.so.6(gdb) f 3 #在这里查看了线程2 3的堆栈信息再结合代码,很轻松就判断出来是死锁的问题#3 0x0000000000400940 in thread_routine_one (arg=0x0) at /opt/testgdb/src/deadLock.c:1919 pthread_mutex_lock(&gMutex2);(gdb) quitA debugging session is active.Inferior 1 [process 14759] will be detached.Quit anyway? (y or n) yDetaching from program: /opt/testgdb/迷路的小刺猬/deadLock, process 14759[root@localhost 迷路的小刺猬]#

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。