2012-09-09 4 views
3

일부 디버거에서는이를 변수에 "트랩 설정"이라고합니다. 내가하고 싶은 것은 객체를 변경하는 모든 명령문에서 중단 점을 트리거하는 것입니다. 또는 객체의 속성을 변경합니다.Xcode 4/lldb에서 개체 (또는 간단한 변수)를 변경하는 내용을 어떻게 알 수 있습니까?

값/키가 추가 된 NSMutableDictionary가 있는데이를 수행 할 수있는 명령문을 찾을 수 없습니다.

+0

gdb 및 lldb에서 * watchpoint *라고합니다 - watchpoint를 설정하고 사용하는 방법은 온라인 도움말을 참조하십시오. –

답변

5

당신은 (here에서) 감시 점을 설정할 수는 :

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 
+0

당신이 인용 한 글은 정말로 분명하지 않습니다. 당신이주는 링크는 많은 도움이되지만, 객체를 보는 방법에 대한 설명이나 예제가 없습니다 (단순 변수 만). 여러 가지 형태의 watch 명령을 실험 해본 결과,'watch set exp -w write - & testString'을 사용하여 NSString을 볼 수 있지만 NSMutableDictionary를 신뢰성있게 감시하는 watch 명령 구문을 찾을 수 없다는 것을 알게되었습니다. 원래의 질문이었습니다. – RobertL

+0

@RobertL 내장 도움말 이외에 lldb에 많은 문서가 있다고 생각하지 않습니다. – trojanfoe

+0

네, 그렇습니다. 그리고 기본 제공 도움말은 명령 구문을 생각 나게하기위한 것으로 보이지만 아무것도 설명하지는 않습니다. 튜토리얼 스타일의 문서가 결국 개발 될 것입니다. 그때까지 우리는 실험을하거나 기다려야합니다. 또한, 나는 lldb에 의해 받아 들여지는 몇몇 watch 서술문이 실제로 런타임에 충돌을 일으킨다는 것을 발견했다. 아마 시간이 갈수록 향상 될 것입니다. (거절 당하거나 충돌하지 말 것). – RobertL

3

감시 점 메모리에 주소 쓰기 (기본 동작)을 추적하는 데 사용됩니다. 오브젝트가 메모리에 어디에 있는지 (포인터가 있음) 알고 있고, 오브젝트에 대한 오프셋을 알고 있다면, 그것이 워치 포인트입니다. 당신은 예를 들어, 간단한 C의 예에서, 경우 :

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

을 그리고 variable.c이 수정 된 경우 프로그램이 일시 중지됩니다 :

당신이 variable.a에 중단 점에있어 일단
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; 
} 

는 않습니다. (나는 완전한 "watch set variable"명령을 타이핑하지 않았다.)

예를 들어, NSMutableDictionary과 같은 복잡한 개체를 사용하면 워치 포인트가 필요한 것을 수행하지 않을 것이라고 생각합니다. 와치 포인트를 설정할 메모리의 단어 (또는 단어)를 파악하려면 객체 레이아웃 NSMutableDictionary의 구현 세부 사항을 알아야합니다.