2009-08-05 53 views
2

如何在Xcode中添加條件斷點? 我嘗試設置一個斷點,然後進入「編輯斷點」如何在Xcode中添加條件斷點

我想休息的時候字節爲0

所以我的狀態添加「字節== 0」,但它從來沒有打破。

然後我嘗試 '(字節== 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. 

回答

6

GDB使用條件斷點從Xcode是有點挑剔。我經常發現自己避開的條件斷點功能,只添加如下代碼:

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

我把一個普通的斷點在NSLog的聲明。

+0

是的,這正是我所做的。 – Neil 2009-08-05 04:22:36

1

因此,我在條件中添加'字節== 0',但它從不中斷。

那麼,也許這是因爲字節從來沒有0?

您是否嘗試在斷點之前將字節設置爲0,以確保字節爲0?

我試圖

int bytes = 0; 
// Breakpoint here 

,當我有狀態字節== 0斷點停止,但不是當我有狀態字節== 1。

所以這就是爲什麼我要假設你的情況是字節0從不

1

我建議NSAssert宏。 這是被廣泛使用的,並且是條件中斷的標準方式。 作爲一個例子,這段代碼中止字節的代碼執行爲零。

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

注意前面的條件是通過條件。 (不是失敗的情況)

如果您使用默認的Xcode項目配置,則僅在Debug版本中編譯斷言代碼。它們將在Release版本中清除。有關條件編譯的更多信息,請查閱Xcode項目設置條目其他C標誌NS_BLOCK_ASSERTIONS。 (-DNS_BLOCK_ASSERTIONS-D是編譯器標記