代码之家  ›  专栏  ›  技术社区  ›  n179911

如何在Xcode中添加条件断点

  •  2
  • n179911  · 技术社区  · 16 年前

    如何在Xcode中添加条件断点? 我尝试设置断点,然后转到“编辑断点”

    当字节为0时,我想中断。

    所以我在条件中添加了“bytes==0”,但它从不中断。

    然后我尝试将'(bytes==0)'作为我的条件,gdb崩溃:

    bool SharedMemory::Map(size_t bytes) {
      if (mapped_file_ == -1)
        return false;
    
      cout 
    
    
    gdb stack crawl at point of internal error:
    [ 0 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (align_down+0x0) [0x122300]
    [ 1 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (wrap_here+0x0) [0x1225f8]
    [ 2 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (prepare_threads_before_run+0x270) [0x185320]
    [ 3 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (macosx_child_resume+0x263) [0x17e85d]
    [ 4 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (resume+0x323) [0x6973d]
    [ 5 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (keep_going+0x122) [0x69a01]
    [ 6 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (handle_inferior_event+0x3338) [0x6cd4a]
    [ 7 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (fetch_inferior_event+0x125) [0x6cfa8]
    [ 8 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (inferior_event_handler+0xd0) [0x8216c]
    [ 9 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (handle_file_event+0x159) [0x80055]
    [ 10 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (process_event+0x81) [0x7fc22]
    [ 11 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (gdb_do_one_event+0x46a) [0x80ae5]
    LEAK: 918 RenderObject
    LEAK: 1 Page
    LEAK: 3 Frame
    LEAK: 7 SubresourceLoader
    LEAK: 95 CachedResource
    LEAK: 2000 WebCoreNode
    [ 12 ] /Developer/usr/libexec/gdb/gdb-i386-apple-darwin (catch_errors+0x4d) [0x7abe2]
    /SourceCache/gdb/gdb-966/src/gdb/macosx/macosx-nat-infthread.c:321: internal-error: assertion failure in function "prepare_threads_before_run": tp != NULL
    
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    
    The Debugger has exited with status 1.The Debugger has exited with status 1.
    
    
    3 回复  |  直到 14 年前
        1
  •  6
  •   Matt Bridges    16 年前

    使用Xcode中的条件断点的gdb有点挑剔。我经常发现自己避开了条件断点特性,只是添加了如下代码:

    if (bytes == 0) {
        NSLog(@"here");
    }
    

    我会在nslog语句中放置一个普通的断点。

        2
  •  1
  •   Erik B    14 年前

    所以我在条件中添加了“bytes==0”,但它从不中断。

    好吧,也许那是因为字节永远不是0?

    是否在断点前尝试将字节设置为0,以便确定字节为0?

    我试过

    int bytes = 0;
    // Breakpoint here
    

    当条件bytes==0时断点停止,但当条件bytes==1时断点停止。

    所以这就是为什么我必须假设,在你的例子中,字节永远不是0。

        3
  •  1
  •   eonil    14 年前

    我建议 NSAssert 宏。 这是广泛使用的,也是有条件中断的标准方法。 例如,此代码中止字节为零的代码执行。

    NSAssert(bytes!=0,@"here");
    

    注意前面的条件是通过条件。(不是失败条件)

    如果您使用的是默认的Xcode项目配置,那么断言代码只在调试版本中编译。它们将在发布版本中清除。有关条件编译的详细信息,请参阅xcode项目设置项 其他C标志 NS_BLOCK_ASSERTIONS . ( -DNS_BLOCK_ASSERTIONS ) -D 是编译器标志

    推荐文章