FW: [請益] 如何追查可能因MutilThtread下stackover
※ [本文轉錄自 C_and_CPP 看板 #1alCn-OQ ]
作者: tanted (為何世界會那麼不單純) 看板: C_and_CPP
標題: [問題] 如何追查可能因MutilThtread下stackover
時間: Sun Jul 23 14:45:15 2023
開發平台(Platform): (Ex: Win10, Linux, ...)
linux openwrt
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
gcc
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
傳入參數被莫名的修改
某個API 如下
CfaIfmNotifyInterfacStat (u4IfIndex, u1AdminStatus,
&u1OperStatus, u1IsFromMib,
u1IsRegToIp,
&IfInfo)) != CFA_SUCCESS)
傳入時的值:
u4IfIndex=43 , u1AdminStatus=1, &u1OperStatus=(UINT1 *) 0xb1e0256f
進入API後值卻變成
https://upload.cc/i1/2023/07/23/ZnvhDF.jpg
u4IfIndex=0, u1AdminStatus=0 , pu1InOperStatus=0x0,
前面4個參數都被變成0
請問各位網友其會被修改到的原因
是不是因為Mutil thread 所造成 其值被其他thread StackOverflow 修改
但由於thread 眾多 各位網友是不是有甚麼的方式或tool
能介紹給我 去debug 找出是哪個thread 哪段code 所造成
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 106.1.107.225 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1690094718.A.61A.html
※ 發信站: 批踢踢實業坊(ptt.cc)
※ 轉錄者: tanted (106.1.107.225 臺灣), 07/23/2023 14:55:45
推
07/23 15:02,
9月前
, 1F
07/23 15:02, 1F
上面所講的值 u4IfIndex=43 , u1AdminStatus=1 就是由 gdb print 印出來的
→
07/23 15:04,
9月前
, 2F
07/23 15:04, 2F
→
07/23 15:32,
9月前
, 3F
07/23 15:32, 3F
→
07/23 16:00,
9月前
, 4F
07/23 16:00, 4F
→
07/23 16:01,
9月前
, 5F
07/23 16:01, 5F
基本上 pu1InOperStatus這是pointer
pu1InOperStatus=0x0(null)
API 用到它 整隻程式就 crash了
※ 編輯: tanted (106.1.107.225 臺灣), 07/23/2023 16:08:58
→
07/23 16:04,
9月前
, 6F
07/23 16:04, 6F
※ 編輯: tanted (106.1.107.225 臺灣), 07/23/2023 16:09:33
→
07/23 16:13,
9月前
, 7F
07/23 16:13, 7F
→
07/23 16:14,
9月前
, 8F
07/23 16:14, 8F
推
07/23 16:48,
9月前
, 9F
07/23 16:48, 9F
→
07/23 16:50,
9月前
, 10F
07/23 16:50, 10F
難點 要監看是local variable 進入API後來才能監看
※ 編輯: tanted (106.1.107.225 臺灣), 07/23/2023 17:29:20
→
07/23 18:54,
9月前
, 11F
07/23 18:54, 11F
推
07/23 18:56,
9月前
, 12F
07/23 18:56, 12F
→
07/23 18:59,
9月前
, 13F
07/23 18:59, 13F
其實上層有個變數 也叫u4IfIndex 和API 宣告的參數名字也叫u4IfIndex
上層 變數 u4IfIndex 的值是沒被改到 但API裡變數u4IfIndex的值被改到
目前 其實是這樣認為的
"原本thread 在進入 function,cpu 因context switch 換到其他的thread
而這個thread buff 沒有處理好 Overflow 蓋掉原本thread 的 stack buff"
※ 編輯: tanted (106.1.107.225 臺灣), 07/23/2023 19:27:24
推
07/24 00:54,
9月前
, 14F
07/24 00:54, 14F
→
07/24 00:54,
9月前
, 15F
07/24 00:54, 15F
→
07/24 01:01,
9月前
, 16F
07/24 01:01, 16F
推
07/24 19:35,
9月前
, 17F
07/24 19:35, 17F
→
07/24 19:35,
9月前
, 18F
07/24 19:35, 18F
→
07/24 19:35,
9月前
, 19F
07/24 19:35, 19F
→
07/24 21:18,
9月前
, 20F
07/24 21:18, 20F
→
07/24 21:18,
9月前
, 21F
07/24 21:18, 21F
推
07/24 21:32,
9月前
, 22F
07/24 21:32, 22F
→
07/24 21:34,
9月前
, 23F
07/24 21:34, 23F
感謝C_C++版的 LPH66 給提示的
後來我開始推測可能是進入API後
前面4個變數給記憶體位置可能是不可寫入
也就說從頭到位 變數的值未被修改過
也沒有被其他thread 修改
從一開始進入這個API 就產生segment fault
https://upload.cc/i1/2023/07/24/oJ6wfn.jpg
u4IfIndex 的記憶體位置 是 0xaa303f9c
查看 thread map
https://upload.cc/i1/2023/07/24/2bNjEW.jpg
右上圖圈選 得知 0xaa303f9 的確在不可存取記憶空間
目前推測會造成這樣原因
因為我們code 分成三個部分 在build
可能帶的最佳化選項 -O 後面數字都不一樣所造成
※ 編輯: tanted (106.1.107.225 臺灣), 07/24/2023 21:59:37
→
07/24 22:00,
9月前
, 24F
07/24 22:00, 24F