日期:2014-05-16  浏览次数:20466 次

dbg 工具使用

主要步骤自己记下

dbg:tracer()

dbg:p(Pid,Flags)

Flags?can be a single atom, or a list of flags. The available flags are:

s (send)

Traces the messages the process sends.

r (receive)

Traces the messages the process receives.

m (messages)

Traces the messages the process receives and sends.

c (call)

Traces global function calls for the process according to the trace patterns set in the system (see tp/2).

p (procs)

Traces process related events to the process.

?

官方文档http://www.erlang.org/doc/man/dbg.html

测试的例子

Eshell V5.7.4 ?(abort with ^G)

2> ls ? ? ? ? ? ? ? ? ? ?

2> ().

.test_dbg.erl.swp ? ? test_dbg.beam ? ? ? ? test_dbg.erl ? ? ? ? ?

test_dbg.erl~ ? ? ? ??

ok

3> Pid = test_dbg:test().

<0.38.0>

4> dbg:tracer().

{ok,<0.40.0>}

5> dbg:p(Pid,[m,proces]).

{error,{bad_flags,[proces]}}

6> Pid.

<0.38.0>

7> dbg:p(Pid,[m,procs]).?

{ok,[{matched,nonode@nohost,1}]}

8> test_dbg:send(Pid).

(<0.38.0>) << {<0.35.0>,test}

(<0.38.0>) <0.35.0> ! returnok

returnok

(<0.38.0>) exit normal

9> test_dbg:send(Pid).

timeout

10> f(),Pid = test_dbg:test().

<0.48.0>

11> test_dbg:send(Pid). ? ? ??

returnok

12> f(),Pid = test_dbg:test().

<0.51.0>

13> dbg:p(Pid,[m,procs]). ? ??

{ok,[{matched,nonode@nohost,1}]}

14> test_dbg:send(Pid). ? ? ??

(<0.51.0>) << {<0.35.0>,test}

(<0.51.0>) <0.35.0> ! returnok

(<0.51.0>) exit normal

returnok

15> dbg:p(Pid,[call... ??

{ok,[{matched,nonode@nohost,0,{no_proc,<0.51.0>}}]}

16> f(),Pid = test_dbg:test().

<0.56.0>

17> dbg:p(Pid,[call]). ? ? ? ?

{ok,[{matched,nonode@nohost,1}]}

18> test_dbg:send(Pid). ? ? ??

returnok

19> f(),Pid = test_dbg:test().

<0.60.0>

20> dbg:p(Pid,[s]). ? ? ? ? ??

{ok,[{matched,nonode@nohost,1}]}

21> test_dbg:send(Pid). ? ? ??

(<0.60.0>) <0.35.0> ! returnok

returnok

22> dbg:p(Pid,[r]). ? ?

{ok,[{matched,nonode@nohost,0,{no_proc,<0.60.0>}}]}

23> f(),Pid = test_dbg:test().

<0.65.0>

24> dbg:p(Pid,[r]). ? ? ? ? ??

{ok,[{matched,nonode@nohost,1}]}

25> test_dbg:send(Pid). ? ? ??

returnok

26> (<0.65.0>) << {<0.35.0>,test}

?

26> f(),Pid = test_dbg:test().

<0.69.0>

27> dbg:p(Pid,[m]). ? ? ? ? ??

{ok,[{matched,nonode@nohost,1}]}

28> test_dbg:send(Pid). ? ? ??

(<0.69.0>) << {<0.35.0>,test}

(<0.69.0>) <0.35.0> ! returnok

returnok

29> f(),Pid = test_dbg:test().

<0.73.0>

30> dbg:p(Pid,[c]). ? ? ? ? ??

{ok,[{matched,nonode@nohost,1}