`
langzhe
  • 浏览: 279221 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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}]}

31> test_dbg:send(Pid).       

returnok

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

<0.77.0>

33> test_dbg:send(Pid).       

returnok

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

<0.80.0>

35> dbg:p(Pid,[p]).           

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

36> test_dbg:send(Pid).       

(<0.80.0>) exit normal

returnok

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

<0.84.0>

38> dbg:p(Pid,[sos]).         

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

39> test_dbg:send(Pid).       

returnok

40> dbg:p(Pid,[sos]).  

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

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

<0.89.0>

42> dbg:p(Pid,[all]).         

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

43> test_dbg:send(Pid).       

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

(<0.89.0>) in {test_dbg,hello,0}

(<0.89.0>) <0.35.0> ! returnok

(<0.89.0>) exit normal

returnok

44> dbg:p(Pid,[clear]).

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

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

<0.94.0>

46> dbg:p(Pid,[clear]).       

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

47> test_dbg:send(Pid).       

returnok

48> dbg:get_tracer().  

{ok,<0.41.0>}

49> dbg:get_tracer().

{ok,<0.41.0>}

50> dbg:get_tracer().

{ok,<0.41.0>}

51> dbg:t

tp/2                  tp/3                  tp/4                  

tpl/2                 tpl/3                 tpl/4                 

trace_client/2        trace_client/3        trace_port/2          

trace_port_control/1  trace_port_control/2  tracer/0              

tracer/2              tracer/3              transform_flags/1     

 

51> dbg:tp

tp/2   tp/3   tp/4   tpl/2  tpl/3  tpl/4  

51> dbg:tp(test_dbg,[])

51> .

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

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

<0.102.0>

53> test_dbg:send(Pid).       

returnok

54> dbg:get_tracer().         

{ok,<0.41.0>}

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

<0.106.0>

56> dbg:p(Pid,[all]).         

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

57> dbg:tp(test_dbg,[])       

57> .

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

58> test_dbg:send(Pid).       

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

(<0.106.0>) in {test_dbg,hello,0}

(<0.106.0>) <0.35.0> ! returnok

(<0.106.0>) exit normal

returnok

59> dbg:get_tracer().         

{ok,<0.41.0>}

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

<0.112.0>

61> dbg:p(Pid,[]).            

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

62> dbg:tp(test_dbgs,[])      

62> .

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

63> test_dbg:send(Pid).       

returnok

64> test_dbg:send(Pid).       

timeout


 

 1 -module(test_dbg).
  2 -export([send/1, test/0, hello/0]).
  3 
  4 test() ->
  5     Pid = spawn(?MODULE, hello, []),
  6     Pid.
  7 
  8 send(Pid) ->
  9     Pid ! {self(),test},
 10     loop().
 11 
 12 hello() ->
 13     receive 
 14         {P,test} ->
 15             P ! returnok
 16     end,
 17     ok.
 18 loop() ->
 19     receive 
 20         T ->
 21             T
 22     after 11 ->
 23         timeout
 24     end.                                                                         
"test_dbg.erl" 24L, 341C 已写入                                    24,8         全部
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics