http://yong321.freeshell.org/Oracle Function Call List

1. Oracle function call list

If you want to see what other functions a given function calls in software, you can disassemble the function. Inspired by Dennis Yurichev's Oracle function call list, which enumerates all functions in the modules inside $ORACLE_HOME/lib/libserver.a, I generate the function call list from $ORACLE_HOME/bin/oracle, with the script described in theAppendix. The result is

apadrv
1 apaqbdDescendents
1 chnacc
5 dbgdChkEventIntV
5 dbgtCtrl_intEvalCtrlEvent
1 dbgtCtrl_intEvalTraceFilters
1 dbgtGrpB_int
1 dbgtGrpE_int
1 dbgtWrf_int
1 dbkdChkEventRdbmsErr
...

This means adbdrv calls apaqbdDescendents once, dbgdChkEventIntV 5 times, etc.

To-do: search of my function call list result file.

2. Event check list

Unfortunately, the above function call list does not show the arguments passed to each function. One of the most useful functions in Oracle is dbkdChkEventRdbmsErr (probably DB kernel debug check event of RDBMS error), which requires one argument, the RDBMS event number. With a little more effort, we can find what event a given function checks by extracting the argument passed to the said function. The result is

ELMAINT: 37393
GELErase: 37397
Java_oracle_xdb_spi_XDBNamingEnumeration_closeKprbNative: 31150
...
apadrv: 10507
apaqba: 10137
atbadd: 10851
atbadd: 12498
atbadd: 12498
...

This means function ELMAINT will call dbkdChkEventRdbmsErr to check for event 37393, apadrv will check for event 10507, and so forth. Many RDBMS events are recorded or documented in $ORACLE_HOME/rdbms/mesg/oraus.msg and can be retrieved by oerr, e.g.,

$ oerr ora 10507
10507, 00000, "Trace bind equivalence logic"
// *Cause:
// *Action:

This event makes sense because apadrv is the function that "drive(s) the access path selection for a SQL command" according to Bug 5584629 and many others. But be aware that not all events are documented. Event 37393 is one of them; you won't get anything by running oerr ora 37393.

The above output also shows multiple lines for one function atbadd. My program sequentially generates these lines and show the same function name repeatedly, which makes the output of a simple grep command easier to read. In the case of atbadd, it checks RDBMS events 10851, 12498 and 12498 again.

For your convenience, you can search my function-event result file given a function name or an event number:

Enter a function or event number:    Enter a function or event number:

The search result is equivalent to a grep command run against your own result file, e.g. a search for event 10035 ("Write parse failures to alert log file"):

$ grep 10035 oracle_func_evt.txt
kksSetBindType: 10035
...
kksfbc: 10035
...

This means that functions kksSetBindType and kksfbc will check for event 10035. Prefix kks is for "Shared Cursor" according to oradebug doc component or "support for managing shared cursors/ shared sql" according to Doc 175982.1note1, and function kksfbc is to "find bound cursor" according to many bug reports.

3. Summary

Next time you see an Oracle function in the call stack in a trace file, or in the output of pstack pid, and wonder what it does, you can either disassemble it or check your event check list file (see Appendix). But if you want to see what other functions may call this function, the latter is the only option. This of course won't really tell you exactly what the function does, but at least you have one more tool to aid the guesswork.note1

The second part of the work, event check list, is useful in that many events are documented. If a given function happens to check for an RDBMS event, it greatly helps decipher what this function does. In addition, if you're interested in a reverse search, i.e. finding all the functions that check for a specific event, you can do so as well.

Appendix

The code below is run on Linux and generates Oracle function call list:

nm $ORACLE_HOME/bin/oracle | awk '/ [Tt] / {print $3}' | grep -v '\.' > oracle.Txt.nm #extract global and local text symbols

for i in $(<oracle.Txt.nm); do
echo $i
gdb -n -q -ex "disas $i" -ex q $ORACLE_HOME/bin/oracle | perl -nle 'print $1 if /(?:call|jmp)q .+ <([^+>]+)[+\d>]+$/' | sort | uniq -c | grep -w -v "$i$"
done > oracle_func.txt

The nm line extracts global and local text (i.e. code) symbols from oracle binarynote2 and saves them into a file. Then gdb runs against the oracle binary for each symbol i.e. function from the file, and disassembles the function passed in. Perl extracts from the output just the last component on each line enclosed in angle brackets if the line contains callq or jmpq. After sorting and removing duplicates, the final output is stripped of the line with that symbol itself (i.e. ignore the lines that say this function calls itself in its code, which I'm not really interested in). The code will run for many hours, depending on the CPU speed. The output is saved in oracle_func.txt. You could remove | sort | uniq -c after the perl filter line if you don't want to see a summary with call counts.

+ Optimize with named pipes.

To find out what event a function checks, the argument to function dbkdChkEventRdbmsErr must be extracted. The argument can be found in the direct output of disas command in gdb.

(gdb) disas apadrv
Dump of assembler code for function apadrv:
...
0x0000000002a05394 <+6580>: mov $0x290b,%edi
0x0000000002a05399 <+6585>: callq 0xcc13110 <dbkdChkEventRdbmsErr>

According to the x86-64 calling convention used by Linux, the first argument to the function is placed in the 64-bit register rdi, of which edi is the lower 32-bit. In case of function apadrv, the Oracle database event it checks is 0x290b (the value moved into edi) or 10507 in decimal

In order to find the events a given function checks, the following code can be run.

for i in $(<oracle.Txt.nm); do
gdb -n -q -ex "disas $i" -ex q $ORACLE_HOME/bin/oracle | grep -B1 dbkdChkEventRdbmsErr | perl -nle "print '${i}: '.hex(\$1) if /x([0-9a-f]+),\%edi$/"
done > oracle_func_evt.txt

If you wish, you can append | sort | uniq -c to the perl line as done previously so as to remove duplicates and optionally show the count of checking a specific event.

+ Optimize with named pipes.

Notes

[note1] Oracle used to publish the document ORA-600 Lookup Error Categories (Doc ID 175982.1), which you can still find on the Internet. Many function prefixes are listed in the document.
[note2] I exclude the symbols with dot in the names to simplify the work. If you include them, you have to put them in single quotes when passing to the gdb command, e.g.,disas '__intel_new_proc_init.A'. For the 12.1.0.2 oracle binary, there're 58 of them, which all seem to be interanl Intel CPU specific functions, including those like__svml_cbrt2_mask.A related to short vector math library.

GDB---Oracle Function Call List的更多相关文章

  1. oracle function学习1

    oracle function学习基层: 函数就是一个有返回值的过程.  首先 知道oracle 使用限制:      函数调用限制: 1. SQL语句中只能调用存储函数(服务器端),而不能调用客户端 ...

  2. Oracle function real_st_astext,解决ArcSDE中st_astext函数返回字符串结构异常问题

    项目过程中发现在Oracle中调用ArcSDE的st_astext函数返回ST_Geometry类型字段的WKT文本有时空间类型前缀没有返回,例如一个点的经度为113.4,纬度为30.6,调用st_a ...

  3. Oracle Function:TO_CHAR

    Description The Oracle/PLSQL TO_CHAR function converts a number or date to a string.将数字转换为日期或字符串 Syn ...

  4. Oracle Function:COUNT

    Description The Oracle/PLSQL COUNT function returns the count of an expression. The COUNT(*) functio ...

  5. Oracle Function: NVL

    Description The Oracle/PLSQL NVL function lets you substitute a value when a null value is encounter ...

  6. oracle function dtrace

    https://andreynikolaev.wordpress.com/2010/10/28/appetizer-for-dtrace/ Appetizer for DTrace Filed und ...

  7. Oracle Function

    Oracle Sql 中常用函数 小写字母转大写字母:upper(); 大写字母转小写字母:lower(); 字符串截取函数:substr(str,a,b); a,b为整数,str为字符串, 截取字符 ...

  8. Oracle function注释

    create or replace function fn_bookid_get_by_chapterid(inintChapterId in integer, outvarBookId out va ...

  9. Oracle function和procedure

    1.返回值的区别 函数有1个返回值,而存储过程是通过参数返回的,可以有多个或者没有 2. 调用的区别,函数可以在查询语句中直接调用,而存储过程必须单独调用. 函数:一般情况下是用来计算并返回一个计算结 ...

  10. oracle function用法(本文来自百度文库)

    函数调用限制 1.SQL语句中只能调用存储函数(服务器端),而不能调用客户端的函数 2.SQL只能调用带有输入参数,不能带有输出,输入输出函数 3.SQL不能使用PL/SQL的特有数据类型(boole ...

随机推荐

  1. Juniti学习总结

    JUnit简介 JUnit是由 Erich Gamma和Kent Beck编写的一个回归测试框架(regression testing framework).JUnit测试是程序员测试,即所谓白盒测试 ...

  2. Spring Batch的事务-Part 1:基础

    原文 https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/ This is th ...

  3. 在Cubieboard上关闭irqbalance服务避免内存泄漏

    十一一个假期回来,顺手看了看自己的cubieboard运行状态怎么样 aria2正常: btsync正常: samba正常: 很好, 顺手htop一下,已经开机了13天了,CPU使用率4%,内存使用率 ...

  4. 预定义宏_GNUC_ _MSC_VER

    一.预定义__GNUC__宏 1 __GNUC__ 是gcc编译器编译代码时预定义的一个宏.需要针对gcc编写代码时, 可以使用该宏进行条件编译. 2 __GNUC__ 的值表示gcc的版本.需要针对 ...

  5. E2202 Required package 'VclJPG' not found

    xe8 [dcc32 Fatal Error] RaizeComponentsVcl_Design.dpk(40): E2202 Required package 'VclJPG' not found ...

  6. Hadoop应用开发实战案例 第2周

    比如,封面,是一网页,可以看出用户在此网页上,鼠标呈现F形状. 海量Web日志分析 用Hadoop提取KPI统计指标 更详细原文博客:http://blog.fens.me/hadoop-mapred ...

  7. oracle不用tsname文件的时候着怎么办

    oracle\product\10.2.0\client_2\odp.net\PublisherPolicy\Policy.9.2.Oracle.DataAccess.config 找到newVers ...

  8. CodeForces 710B Optimal Point on a Line (数学,求中位数)

    题意:给定n个坐标,问你所有点离哪个近距离和最短. 析:中位数啊,很明显. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240000 ...

  9. gb2312和UTF-8的区别

    GB2312编码大约包含6000多汉字(不包括特殊字符),编码范围为第一位b0-f7,第二位编码范围为a1-fe(第一位为cf时,第二位为a1-d3),计算一下汉字个数为6762个汉字.当然还有其他的 ...

  10. Pongo建立信号基站-实际上还是考中位数

    题目: 要建立一个信号基站服务n个村庄,这n个村庄用平面上的n个点表示.假设基站建立的位置在(X,Y),则它对某个村庄(x,y)的距离为max{|X – x|, |Y – y|}, 其中| |表示绝对 ...