3

In some debuggers this is called "setting a trap" on a variable. What I want to do is trigger a breakpoint on any statement that changes the object. Or changes a property of the object.

I have an NSMutableDictionary that gets a value/key added to it but I can't find any statement that could be doing that.

4

2 に答える 2

7

ウォッチポイントを設定できます(ここから):

Set a watchpoint on a variable when it is written to.
(lldb) watchpoint set variable -w write global_var
(lldb) watch set var -w write global_var
(gdb) watch global_var
Set a watchpoint on a memory location when it is written into. The size of the region to watch for defaults to the pointer size if no '-x byte_size' is specified. This command takes raw input, evaluated as an expression returning an unsigned integer pointing to the start of the region, after the '--' option terminator.
(lldb) watchpoint set expression -w write -- my_ptr
(lldb) watch set exp -w write -- my_ptr
(gdb) watch -location g_char_ptr
Set a condition on a watchpoint.
(lldb) watch set var -w write global
(lldb) watchpoint modify -c '(global==5)'
(lldb) c
...
(lldb) bt
* thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1
frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16
frame #1: 0x0000000100000eac a.out`main + 108 at main.cpp:25
frame #2: 0x00007fff8ac9c7e1 libdyld.dylib`start + 1
(lldb) frame var global
(int32_t) global = 5
List all watchpoints.
(lldb) watchpoint list
(lldb) watch l
(gdb) info break
Delete a watchpoint.
(lldb) watchpoint delete 1
(lldb) watch del 1
(gdb) delete 1
于 2012-09-09T19:01:13.853 に答える
3

ウォッチポイントは、メモリ内のアドレスへの書き込みを追跡するために使用されます (デフォルトの動作)。オブジェクトがメモリ内のどこにあるか (オブジェクトへのポインタがある) を知っていて、関心のあるオブジェクトへのオフセットを知っている場合、それがウォッチポイントの目的です。たとえば、単純な C の例では、次の場合:

struct info
{
   int a;
   int b;
   int c;
};

int main()
{
   struct info variable = {5, 10, 20};
   variable.a += 5;  // put a breakpoint on this line, run to the breakpoint
   variable.b += 5;
   variable.c += 5;
   return variable.a + variable.b + variable.c;
}

のブレークポイントに到達したら、次のvariable.aようにします。

(lldb) wa se va variable.c
(lldb) continue

また、プログラムがvariable.c変更されると一時停止します。(私は、完全な "watch set variable" コマンドをわざわざ入力しませんでした)。

たとえば、のような複雑なオブジェクトではNSMutableDictionary、ウォッチポイントが必要なことを行うとは思いません。NSMutableDictionaryウォッチポイントを設定するメモリの単語 (または複数の単語) を知るには、オブジェクト レイアウトの実装の詳細を知る必要があります。

于 2012-09-23T10:18:39.237 に答える