[20241105]跟踪library cache lock library cache pin使用gdb(11g)2.txt

news/2024/11/6 20:22:42/文章来源:https://www.cnblogs.com/lfree/p/18530945
[20241105]跟踪library cache lock library cache pin使用gdb(11g)2.txt

--//前一段时间写的使用gdb跟踪library cache lock/library cache pin的脚本。

--//我看过以前的笔记,当时测试过链接https://nenadnoveljic.com/blog/library-cache-lock-debugger/,我的测试在11g是失败.
--//今天有空再次尝试,确实不成功,不过有了前面测试的经验,可以很容易写成11g的gdb监测脚本.

1.环境:
SCOTT@book> @ ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.测试gdb脚本:
--//我直接给出gdb脚本,一些细节忽略,主要讲解比较麻烦,就是在gdb下设置kgllkal,kglpnal断点.然后使用info register查看寄存器内
--//容,然后获取该执行语句的sql_id,hash_value值,继续退出,然后执行:

@ sharepool/shp4 <sql_id> 0

--//然后查看KGLHDADR的值,对比就知道那个寄存器保存的是对象句柄地址,测试结果对应的寄存器是rsi,至于mode我仅仅猜测是寄存器
--//rdx.这样稍微改改11g的监测脚本就可以写成.
--//里面的偏移量很容易确定,直接opeek 地址 长度 1,看看偏移地址在那里就可以了,11g我的测试结果在0x1a8 = 424.

$ cat lkpn11g.gdb
set pagination off
#set print repeats 0
#set print elements 0
set logging file /tmp/lkpn.log
set logging overwrite on
set logging on
set $lk  = 0
set $pn  = 0
set $lock  = 0

#break kgllkal if $rdx==3
#break kgllkal if ( $rdx==3 && $rsi==0x00000000670C9E58 )
#break kgllkal if $rsi==0x00000000670C9E58
break kgllkal
commands
 silent
 printf "kgllkal count %02d -- handle address: %016x, mode: %d ", ++$lk ,$rsi ,$rdx
 echo kglnaobj address:
 x/s $rsi+0x1a8
 c
 end

#break kglpnal if $rcx==3
break kglpnal
commands
 silent
 printf "kglpnal count %02d -- handle address: %016x, mode: %d ", ++$pn ,$rsi ,$rdx
 echo kglnaobj address:
 x/s $rsi+0x1a8
 c
 end

3.测试:
--//session 1:
SCOTT@book> @ spid
==============================
SID                           : 18
SERIAL#                       : 44459
PROCESS                       : 65221
SERVER                        : DEDICATED
SPID                          : 65222
PID                           : 25
P_SERIAL#                     : 96
KILL_COMMAND                  : alter system kill session '18,44459' immediate;
PL/SQL procedure successfully completed.
--//执行desc dept以及Select * from dept where deptno=20;(开头S大小)多次避免递归调用。

--//window 1:
$ rlgdb -f -p  65222 -x lkpn11g.gdb
..
0x000000379a00da70 in __read_nocancel () from /lib64/libpthread.so.0
Breakpoint 1 at 0x983da94
Breakpoint 2 at 0x9839f5c

--//session 1:
SCOTT@book> select * from dept where deptno=12;
no rows selected

--//window 1:
(gdb) c
Continuing.
kgllkal count 01 -- handle address: 000000007bcb6f50, mode: 1 kglnaobj address:0x7bcb70f8:       "select * from dept where deptno=12"
kglpnal count 01 -- handle address: 000000007bcb6f50, mode: 2 kglnaobj address:0x7bcb70f8:       "select * from dept where deptno=12"
kgllkal count 02 -- handle address: 000000007e3371e0, mode: 2 kglnaobj address:0x7e337388:       "bookSYS"
kgllkal count 03 -- handle address: 000000007c19ee50, mode: 2 kglnaobj address:0x7c19eff8:       "2710e6f2 1d05c1f$BUILD$"
--//怎么中间出现1个空格。~~~~~~~~~~~~~
kgllkal count 04 -- handle address: 000000007cb51930, mode: 1 kglnaobj address:0x7cb51ad8:       ""
kglpnal count 02 -- handle address: 000000007cb51930, mode: 3 kglnaobj address:0x7cb51ad8:       ""
kgllkal count 05 -- handle address: 000000007e3371e0, mode: 2 kglnaobj address:0x7e337388:       "bookSYS"
kgllkal count 06 -- handle address: 000000007bcec280, mode: 1 kglnaobj address:0x7bcec428:       "fa4ab910ef98d2aa2710e6f21d05c1fChild:0"
kglpnal count 03 -- handle address: 000000007bcec280, mode: 3 kglnaobj address:0x7bcec428:       "fa4ab910ef98d2aa2710e6f21d05c1fChild:0"
kgllkal count 07 -- handle address: 000000007bcfc0a0, mode: 1 kglnaobj address:0x7bcfc248:       "SCOTT"
kgllkal count 08 -- handle address: 000000007e3371e0, mode: 2 kglnaobj address:0x7e337388:       "bookSYS"
kgllkal count 09 -- handle address: 000000007d2defd0, mode: 2 kglnaobj address:0x7d2df178:       "DEPTSCOTT"
kglpnal count 04 -- handle address: 000000007d2defd0, mode: 2 kglnaobj address:0x7d2df178:       "DEPTSCOTT"
kgllkal count 10 -- handle address: 000000007da13e58, mode: 1 kglnaobj address:0x7da14000:       "\220\021"
kgllkal count 11 -- handle address: 000000007ef0a260, mode: 2 kglnaobj address:0x7ef0a408:       "ICOL$SYS\bz骪177"
kglpnal count 05 -- handle address: 000000007ef0a260, mode: 2 kglnaobj address:0x7ef0a408:       "ICOL$SYS\bz骪177"
--//以上第1次执行,有2个空是子游标句柄,对象内容在父游标句柄里面,有时候取到乱码也是正常的.

kgllkal count 12 -- handle address: 000000007bcb6f50, mode: 1 kglnaobj address:0x7bcb70f8:       "select * from dept where deptno=12"
kgllkal count 13 -- handle address: 000000007cb51930, mode: 1 kglnaobj address:0x7cb51ad8:       ""
kgllkal count 14 -- handle address: 000000007d2defd0, mode: 2 kglnaobj address:0x7d2df178:       "DEPTSCOTT"
kglpnal count 06 -- handle address: 000000007d2defd0, mode: 2 kglnaobj address:0x7d2df178:       "DEPTSCOTT"
--//以上第2次执行

kgllkal count 15 -- handle address: 000000007bcb6f50, mode: 1 kglnaobj address:0x7bcb70f8:       "select * from dept where deptno=12"
kgllkal count 16 -- handle address: 000000007cb51930, mode: 1 kglnaobj address:0x7cb51ad8:       ""
--//以上第3次执行

--//以上第4次执行,没有任何输出,光标已经cache.
SYS@book> @ sharepool/shp4 2f476y80x0r0z 0
HANDLE_TYPE            KGLHDADR         KGLHDPAR         C40                                        KGLHDLMD   KGLHDPMD   KGLHDIVC KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16   N0_6_16        N20   KGLNAHSH KGLOBT03        KGLOBT09
---------------------- ---------------- ---------------- ---------------------------------------- ---------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
child handle address   000000007CB51930 000000007BCB6F50 select * from dept where deptno=12                0          0          0 000000007CA23A58 000000007C8693C0       4528      12144       3067     19739      19739   30432287 2f476y80x0r0z          0
parent handle address  000000007BCB6F50 000000007BCB6F50 select * from dept where deptno=12                0          0          0 000000007CB39AD0 00                     4720          0          0      4720       4720   30432287 2f476y80x0r0z      65535

--//下划线的对象有一点点奇怪中间有空格.
SYS@book> @ sharepool/shp4z 000000007c19ee50 0
HANDLE_TYPE            KGLHDADR         KGLHDPAR         C40                                        KGLHDLMD   KGLHDPMD   KGLHDIVC KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16   N0_6_16        N20   KGLNAHSH KGLOBT03        KGLOBT09
---------------------- ---------------- ---------------- ---------------------------------------- ---------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
parent handle address  000000007C19EE50 000000007C19EE50 $BUILD$.2710e6f2 1d05c1f                          0          0          0 00               00                        0          0          0         0          0  438406682                        0
--//hash_value=438406682

SYS@book> select * from v$db_object_cache where hash_value=438406682
  2   @pr
==============================
OWNER                         : $BUILD$
NAME                          : 2710e6f2 1d05c1f
DB_LINK                       :
NAMESPACE                     : SQL AREA BUILD
TYPE                          : CURSOR
SHARABLE_MEM                  : 0
LOADS                         : 0
EXECUTIONS                    : 0
LOCKS                         : 0
PINS                          : 0
KEPT                          : NO
CHILD_LATCH                   : 101914
INVALIDATIONS                 : 0
HASH_VALUE                    : 438406682
LOCK_MODE                     : NONE
PIN_MODE                      : NONE
STATUS                        : UNKOWN
TIMESTAMP                     :
PREVIOUS_TIMESTAMP            :
LOCKED_TOTAL                  : 1
PINNED_TOTAL                  : 0
PROPERTY                      :
FULL_HASH_VALUE               : 6837047da7fa359a5549f81b1a218e1a
PL/SQL procedure successfully completed.
--//才发现11g下v$db_object_cache视图显示的字段太少。

SYS@book> select name,dump(name ,16) c70 from v$db_object_cache where hash_value=438406682;
NAME                                     C70
---------------------------------------- ----------------------------------------------------------------------
2710e6f2 1d05c1f                         Typ=1 Len=16: 32,37,31,30,65,36,66,32,20,31,64,30,35,63,31,66
--//确实有1个空格.0x20.

$ sql_idz.sh "select * from dept where deptno=12\0" 3
sql_text = select * from dept where deptno=12\0
full_hash_value(16) = FA4AB910EF98D2AA2710E6F201D05C1F
xxxxx_matching_signature(10) = 2815003694193466399 or  21261747767903018015
hash_value(10) = 30432287 or hash_value(16) = 01D05C1F
sql_id(32) = 2f476y80x0r0z
sql_id(32) = 2f476y80x0r0z
sql_id(32) = 2f476y80x0r0z

--//对象2710e6f2 1d05c1f$BUILD$的来源是sql语句的FULL_HASH_VALUE的16进制的后16位2710E6F201D05C1F,分开2部分是
--//2710E6F2,01D05C1F,oracle设计有点奇葩,01D05C1F前面的0变成空格吗?看看FULL_HASH_VALUE计算是否正确.

--//kgllkal count 06 -- handle address: 000000007bcec280, mode: 1 kglnaobj address:0x7bcec428:       "fa4ab910ef98d2aa2710e6f21d05c1fChild:0"
--//full_hash_value(16) = FA4AB910EF98D2AA2710E6F201D05C1F
fa4ab910ef98d2aa2710e6f21d05c1f
fa4ab910ef98d2aa2710e6f201d05c1f
--//对象fa4ab910ef98d2aa2710e6f21d05c1fChild:0 也是丢失0.

SYS@book> @ nmsp 'SQL AREA BUILD' -1
@ nmsp table -1
@ nmsp '' 74  or @ nmsp '' 0x4a|x4a
KGLSTDSC                                                           KGLSTIDN KGLSTIDN_HEX
---------------------------------------------------------------- ---------- ------------
SQL AREA BUILD                                                           82 52
--//命名空间82,16进制0x52.

$ sql_idz.sh '2710e6f2 1d05c1f.$BUILD$\x52\0\0\0' 3
sql_text = 2710e6f2 1d05c1f.$BUILD$\x52\0\0\0
full_hash_value(16) = 6837047DA7FA359A5549F81B1A218E1A
xxxxx_matching_signature(10) = 6145715961809964570 or  24592460035519516186
hash_value(10) = 438406682 or hash_value(16) = 1A218E1A
sql_id(32) = 5akgs3cd233hu
sql_id(32) = 5akgs3cd233hu
sql_id(32) = 5akgs3cd233hu
--//确实使用空格计算的.full_hash_value(16) = 6837047DA7FA359A5549F81B1A218E1A与前面的使用如下语句的查询结果一致。
--//select * from v$db_object_cache where hash_value=438406682

kgllkal count 73 -- handle address: 000000007be33760, mode: 1 kglnaobj address:0x7be33908:       "select * from dept where deptno=15"
kglpnal count 29 -- handle address: 000000007be33760, mode: 2 kglnaobj address:0x7be33908:       "select * from dept where deptno=15"
kgllkal count 74 -- handle address: 000000007e3371e0, mode: 2 kglnaobj address:0x7e337388:       "bookSYS"
kgllkal count 75 -- handle address: 000000007cab2918, mode: 2 kglnaobj address:0x7cab2ac0:       " c3ba9c9ee26d7a6$BUILD$"   --//空格再次出现。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kgllkal count 76 -- handle address: 000000007db6e0d0, mode: 1 kglnaobj address:0x7db6e278:       "\220\021" -//乱码
kglpnal count 30 -- handle address: 000000007db6e0d0, mode: 3 kglnaobj address:0x7db6e278:       "\220\021"
kgllkal count 77 -- handle address: 000000007e3371e0, mode: 2 kglnaobj address:0x7e337388:       "bookSYS"
kgllkal count 78 -- handle address: 000000007c9cd2c8, mode: 1 kglnaobj address:0x7c9cd470:       "f2afd967b55d9efac3ba9c9ee26d7a6Child:0"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kglpnal count 31 -- handle address: 000000007c9cd2c8, mode: 3 kglnaobj address:0x7c9cd470:       "f2afd967b55d9efac3ba9c9ee26d7a6Child:0"
kgllkal count 79 -- handle address: 000000007bcfc0a0, mode: 1 kglnaobj address:0x7bcfc248:       "SCOTT"
kgllkal count 80 -- handle address: 000000007e3371e0, mode: 2 kglnaobj address:0x7e337388:       "bookSYS"
kgllkal count 81 -- handle address: 000000007d2defd0, mode: 2 kglnaobj address:0x7d2df178:       "DEPTSCOTT"
kglpnal count 32 -- handle address: 000000007d2defd0, mode: 2 kglnaobj address:0x7d2df178:       "DEPTSCOTT"

$ sql_idz.sh "select * from dept where deptno=15\0" 3
sql_text = select * from dept where deptno=15\0
full_hash_value(16) = F2AFD967B55D9EFA0C3BA9C9EE26D7A6
xxxxx_matching_signature(10) = 881484836830107558 or  19328228910539659174
hash_value(10) = 3995522982 or hash_value(16) = EE26D7A6
sql_id(32) = 0sfx9t7r2dpx6
sql_id(32) =  sfx9t7r2dpx6
sql_id(32) =  sfx9t7r2dpx6
--//视乎11g下有一些不能理解的地方,开头的0变成空格.
--//f2afd967b55d9efac3ba9c9ee26d7a6 长度31也去掉0.
--//F2AFD967B55D9EFA0C3BA9C9EE26D7A6 长度32.
--//这里的0是字符'0',不是chr(0),oracle 11g为什么要这样设计变成空格呢?不理解。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/827833.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

『模拟赛』NOIP2024加赛2

『模拟赛记录』NOIP2024加赛2Rank 一直烂,什么时候触底反弹(A. 新的阶乘 赛时觉得线筛一遍同时统计每个质数的指数就做完了,然后本机怎么跑不进 1s,卡常卡了半个小时,最后没 T,但是 vector 炸了,70pts。 可以换思路考虑,赛时一直没转换过来。对于每个质数枚举其倍数统计…

矩阵求导 d(A*X)/dX

矩阵求导 d(A*X)/dX简单矩阵求导 $\frac{ \part (A \times X) }{ \part X }=A$。证明如下,自行体会。 感谢 https://www.cnblogs.com/sunny99/ sumoier对本文的帮助

学习笔记(二十六):资源分类与访问(Resources)

概述: 应用开发中使用的各类资源文件,需要放入特定子目录中存储管理。 资源目录的示例如下所示, base目录、限定词目录、rawfile目录、resfile目录称为资源目录;element、media、profile称为资源组目录。resources |---base | |---element | | |---string.json | |…

java微服务的异常

1.依赖异常须知: 【 如果项目的结构是单个模块的,需要给每个单个模块添加起步依赖 spring-boot-starter-parent,指定版本 】 【 如果项目的结构是子父模块的,只需要给父模块添加起步依赖 spring-boot-starter-parent,指定版本,所有子模块引入父模块就行 】配置文件你指定…

C# WebSocket的简单使用【使用Fleck实现】

有bug,不推荐使用 有bug,不推荐使用 有bug,不推荐使用2.WebSocketHelper 新建 WebSocketHelper.csusing Fleck;namespace WebSocket {internal class WebSocketHelper{//客户端url以及其对应的Socket对象字典IDictionary<string, IWebSocketConnection> dic_Sockets =…

第三十五讲:为什么临时表可以重名?

创建临时表,一部分为了优化查询,join在临时表里查询出结果后导入到正常表中,他也支持多session的查询优化,更重要一点是在session会话关闭后,临时表会自动销毁。嗯就这样 另外分清他和内存表的区别 内存表一定是从memory引擎创建的,临时表可以由memory引擎创建第三十五讲…

如何理解shell命令 cd $(dirname $0)

如何理解shell命令 cd $(dirname $0)-CSDN博客

对C++程序使用输入输出重定向

一般来说,在Visual Studio使用文件重定向有三种方法: 方法一:通过命令行参数实现 项目→属性→配置属性→调试→命令参数然后就在这里加上你的命令行参数 比如我有这样一段程序: #include <iostream> #include <fstream> #include "Sales_item.h"int…

红米k70怎么设置「短信通知」在锁屏时隐藏内容,不锁屏时不隐藏内容

红米 K70 设置短信通知在锁屏时隐藏内容、不锁屏时不隐藏内容,可以按照以下步骤进行操作:打开手机设置:在主屏幕上找到并点击 “设置” 图标,进入手机设置页面。 进入通知与控制中心:在设置页面中,找到并点击 “通知与控制中心” 选项。 选择锁屏通知:在通知与控制中心页…

c语言中声明数组时, 元素个数必须使用常量表达式

001、[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c ## 测试程序 #include <stdio.h>int main(void) {int var1 = 5; // 初始化一个变量var1int array1[var1] = {3,5,8,4,9}; // 初始化数组return 0; } [root@PC1 test]# gcc test.c …

图的基本操作

目录1.图2.图的结构体定义3.图的初始化4.添加顶点、删除顶点4.1添加顶点4.2删除顶点5.添加边、删除边5.1添加边5.2删除边6.打印图7.main函数 在生命旅途中,我们就像是一个个节点,被无数看不见的边相连。每一次的相识与相离,都在这张巨大的网络图中留下独特的印记。 1.图 图(…

正态分布

正态分布 1 标准正态分布 1.1概率密度函数 \[f(x) = \frac{1}{\sqrt{2\pi}}e^{-\frac{x^2}{2}} \]1.2 累计分布函数 \[F(x) = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^{x}e^{-\frac{t^2}{2}}dt \] 2 (一般)正态分布 2.1 概率密度函数 \[f(x) = \frac{1}{\sqrt{2\pi\sigma…