gdb跟踪oracle内部函数调用
linux版本
[oracle@ykcdb01 ~]$ lsb_release -a
LSB Version: :core-3.0-amd64:core-3.0-ia32:core-3.0-noarch:graphics-3.0-amd64:graphics-3.0-ia32:graphics-3.0-noarch
Distributor ID: RedHatEnterpriseAS
Description: Red Hat Enterprise Linux AS release 4 (Nahant Update 7)
Release: 4
Codename: NahantUpdate7
oracle版本 11.2.0.1.0
GDB
info functions
显示调试涉及源码文件中所有的函数名、参数名
gdb -batch -x t.g > tt
批量执行gdb命令文件 执行各命令后退出 所有输出内容存入文件tt
t.g文件内容类似如下:
attach 12413
bt
info functions
跟踪方法论
strace -p 12413
linux上使用strace跟踪某个进程的系统调用
跟踪oracle内部调用的方法
先用strace挂接某个oracle后台进程,然后在sqlplus中执行一个sql,此时观察,会发现输出很多系统调用:
注意为了保证调用深度,最好执行sql前先把buffer进行flush;
alter system flush buffer_cache;
select count(*) from yc_t ;
getrusage(RUSAGE_SELF, {ru_utime={0, 49992}, ru_stime={0, 29995}, ...}) = 0
times({tms_utime=4, tms_stime=2, tms_cutime=0, tms_cstime=0}) = 485883876
getrusage(RUSAGE_SELF, {ru_utime={0, 49992}, ru_stime={0, 29995}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
times({tms_utime=5, tms_stime=2, tms_cutime=0, tms_cstime=0}) = 485883876
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
times({tms_utime=5, tms_stime=2, tms_cutime=0, tms_cstime=0}) = 485883876
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
times({tms_utime=5, tms_stime=2, tms_cutime=0, tms_cstime=0}) = 485883876
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
times({tms_utime=5, tms_stime=2, tms_cutime=0, tms_cstime=0}) = 485883876
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 50992}, ru_stime={0, 29995}, ...}) = 0
pread(11, "\20\242\0\0\260\\A\0\266\32109$\f\1\4\21\237\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8192, 731250688) = 8192
pread(11, "\6\242\0\0\261\\A\0\204\32109$\f\2\4\253\25\0\0\1\0\0\0\376v\1\0~\32109"..., 57344, 731258880) = 57344
pread(11, "\6\242\0\0\270\\A\0\204\32109$\f\2\4\224\10\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 731316224) = 65536
pread(11, "\6\242\0\0\300\\A\0\214\32109$\f\2\4\354\376\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 731381760) = 65536
pread(11, "\6\242\0\0\310\\A\0\214\32109$\f\2\4\303\374\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 731447296) = 65536
pread(11, "\6\242\0\0\320\\A\0\214\32109$\f\2\4\33T\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 731512832) = 65536
pread(11, "\6\242\0\0\330\\A\0\214\32109$\f\2\4&\212\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 731578368) = 65536
pread(11, "\6\242\0\0\340\\A\0\224\32109$\f\2\4\323,\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 731643904) = 65536
pread(11, "\6\242\0\0\350\\A\0\224\32109$\f\2\4U\257\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 731709440) = 65536
pread(11, "\6\242\0\0\360\\A\0\224\32109$\f\2\4\262C\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 731774976) = 65536
pread(11, "\6\242\0\0\370\\A\0\224\32109$\f\2\4\233C\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 731840512) = 65536
pread(11, "\6\242\0\0\200bA\0\234\32109$\f\2\4\274\30\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 743440384) = 65536
pread(11, "\6\242\0\0\210bA\0\234\32109$\f\2\4\243+\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 743505920) = 65536
pread(11, "\6\242\0\0\220bA\0\234\32109$\f\2\4\231a\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 743571456) = 65536
pread(11, "\6\242\0\0\230bA\0\234\32109$\f\2\4-\27\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 743636992) = 65536
pread(11, "\6\242\0\0\240bA\0\244\32109$\f\2\4\347\301\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 743702528) = 65536
pread(11, "\6\242\0\0\250bA\0\244\32109$\f\2\4\7\375\0\0\1\0\0\0\376v\1\0~\32109"..., 65536, 743768064) = 65536
pread(11, "\6\242\0\0\0cA\0\244\32109$\f\2\4Y\255\0\0\1\0\0\0\376v\1\0~\32109"..., 1048576, 744488960) = 1048576
pread(11, "\6\242\0\0\200cA\0\246\32109$\f\2\0042Y\0\0\1\0\0\0\376v\1\0~\32109"..., 1048576, 745537536) = 1048576
pread(11, "\6\242\0\0\0dA\0\250\32109$\f\2\4\\\253\0\0\1\0\0\0\376v\1\0~\32109"..., 1048576, 746586112) = 1048576
pread(11, "\6\242\0\0\200dA\0\252\32109$\f\2\4?D\0\0\1\0\0\0\376v\1\0~\32109"..., 1048576, 747634688) = 1048576
pread(11, "\6\242\0\0\0eA\0\254\32109$\f\2\0042a\0\0\1\0\0\0\376v\1\0~\32109"..., 1048576, 748683264) = 1048576
pread(11, "\6\242\0\0\200eA\0\256\32109$\f\2\4\261\t\0\0\1\0\0\0\376v\1\0~\32109"..., 1048576, 749731840) = 1048576
pread(11, "\6\242\0\0\0fA\0\260\32109$\f\2\4J\374\0\0\1\0\0\0\376v\1\0~\32109"..., 1048576, 750780416) = 1048576
pread(11, "\6\242\0\0\200fA\0\262\32109$\f\2\4\345o\0\0\1\0\0\0\376v\1\0~\32109"..., 90112, 751828992) = 90112
getrusage(RUSAGE_SELF, {ru_utime={0, 70989}, ru_stime={0, 40993}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 70989}, ru_stime={0, 40993}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 70989}, ru_stime={0, 40993}, ...}) = 0
times({tms_utime=7, tms_stime=4, tms_cutime=0, tms_cstime=0}) = 485883880
write(12, "\1x\0\0\6\0\0\0\0\0\20\27\0\0\0:\20\2751g\225\t\27\10U|\302\310\257;\220x"..., 376) = 376
read(9, "\0\25\0\0\6\0\0\0\0\0\3\5\24\1\0\0\0\17\0\0\0", 8208) = 21
getrusage(RUSAGE_SELF, {ru_utime={0, 70989}, ru_stime={0, 40993}, ...}) = 0
times({tms_utime=7, tms_stime=4, tms_cutime=0, tms_cstime=0}) = 485883880
getrusage(RUSAGE_SELF, {ru_utime={0, 70989}, ru_stime={0, 40993}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 70989}, ru_stime={0, 40993}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 70989}, ru_stime={0, 40993}, ...}) = 0
times({tms_utime=7, tms_stime=4, tms_cutime=0, tms_cstime=0}) = 485883880
write(12, "\0\254\0\0\6\0\0\0\0\0\4\1\0\0\0\21\0\1\1\0\0\0{\5\0\0\0\0\1\0\0\0"..., 172) = 172
分析上面显示的系统调用,会发现比较多的是times,初步分析是因timed_statistics参数打开进行的运行时间收集,
随后在gdb中设置断点 br times,执行c继续,系统会在times时停下了,然后bt观察frame情况,此时会发现,随着
陆续执行到后续的times断点,bt的输出的函数栈逐渐增多,此时通过s命令,可以进入函数内部执行,发现更多调用函数;
使用info all-register命令可以显示寄存器信息,间接可以查看函数调用参数,
rdi/edi是第一个参数, rsi/esi是第二个参数
rsi 0x2acf2e 2805550 ----第二个参数
rdi 0x7fff1c577028 140733668880424 ----第一个参数
利用第一个参数rdi=0x7fff1c577028,显示内存中32个字节。
(gdb) x/32 0x7fff1c577028
kslwtbctx为加等待事件函数;