簡體   English   中英

GDB python Breakpoint類接口和條件斷點

[英]GDB python Breakpoint class interface and conditional breakpoints

我正在使用GDB Python接口來處理斷點

import gdb
class MyBP(gdb.Breakpoint):
    def stop(self):
        print("stop called "+str(self.hit_count))
        return True
bp = MyBP("test.c:22")

這按預期工作。 “ stop”方法返回后,hit_count增加。

現在,當我想使用條件斷點時:

bp.condition="some_value==2"

它沒有按預期工作。 無論條件是true還是false,始終執行stop方法。 如果stop方法返回“ True”,則斷點將僅在條件也為true時才暫停程序。 Stop方法返回且條件成立后,hit_count增加。

因此,似乎GDB僅在調用Stop方法之后才應用條件檢查。

如何確保僅在條件成立時才調用Stop方法?

如何確保僅在條件成立時才調用Stop方法?

目前,您還不能。 請參閱gdb/breakpoint.c bpstat_check_breakpoint_conditions()

相關部分:

  /* Evaluate extension language breakpoints that have a "stop" method
     implemented.  */
  bs->stop = breakpoint_ext_lang_cond_says_stop (b);

  ...
          condition_result = breakpoint_cond_eval (cond);
  ...
  if (cond && !condition_result)
    {
      bs->stop = 0;
    }
  else if (b->ignore_count > 0)
    {
      ...
      ++(b->hit_count);
      ...
    }

因此,始終在評估條件之前調用python stop方法。 但是,如果您想用源語言編寫表達式,則可以使用python實現條件,例如使用gdb.parse_and_eval

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM