我是Erlang的新手,但似乎很快就遇到了一堵砖墙。 我正在尝试正确使用erlang:trace / 3及其同类群。这里 是我的示例程序:
-module(seg_fault).
-export([start/0]).
simple_tracer() ->
io:format("enter"),
receive
_ -> io:format("msg"), simple_tracer
end.
start() ->
Simple = spawn(fun simple_tracer/0),
erlang:trace_pattern({'_','_','_'}, true, [local]),
erlang:trace(self(),
true,
[send,
'receive',
procs,
ports,
garbage_collection,
monotonic_timestamp,
set_on_first_spawn,
set_on_first_link,
call,
return_to,
{tracer, Simple},
arity]),
math:sqrt(2),
math:sqrt(3),
erlang:trace_delivered(self()),
receive
{trace_delivered, _, _} -> undefined
end,
erlang:trace(self(),false,[all]),
io:format("complete!").
我在Ubuntu 14.04机器上,这是我的工作站。这是什么 当我使用'erlc'和'erl'
运行它时会发生[ericu-destroyer-of-worlds] ~$ erlc ./seg_fault.erl
seg_fault.erl:27: Warning: the result of the expression is ignored
(suppress the warning by assigning the expression to the _ variable)
seg_fault.erl:28: Warning: the result of the expression is ignored
(suppress the warning by assigning the expression to the _ variable)
[ericu-destroyer-of-worlds] ~$ erl
Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [smp:8:8]
[async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.0 (abort with ^G)
1> seg_fault:start().
entermsgSegmentation fault
看起来我的进程应该开始接收跟踪消息 并获得一个没有问题的消息。但是,这个过程崩溃了 第二次调用erlang:trace / 3,如何设置为false。我的理解是 这应该只关闭当前进程的跟踪,由...标识 自()。
我使用较旧版本的Erlang
运行相同的代码root@ba8246924352:/# erlc ./seg_fault.erl
seg_fault.erl:27: Warning: the result of the expression is ignored
(suppress the warning by assigning the expression to the _ variable)
seg_fault.erl:28: Warning: the result of the expression is ignored
(suppress the warning by assigning the expression to the _ variable)
root@ba8246924352:/# erl
Erlang/OTP 18 [erts-7.3.1] [source] [64-bit] [smp:8:8]
[async-threads:10] [hipe] [kernel-poll:false]
Eshell V7.3.1 (abort with ^G)
1> seg_fault:start().
entermsgcomplete!ok
这个旧版本似乎运行得很好。这是一个问题 Erlang或者我使用erlang时出错:trace / 3?如果有的话 我可以提供的其他数据可以帮助解决这个问题 问题,请告诉我。
更新
我仍然不知道发生了什么,但我注意到如果我使用来自文件而不是终端的输入,则erlang不会崩溃
[ericu-destroyer-of-worlds] ~$ cat erl.in
seg_fault:start().
[ericu-destroyer-of-worlds] ~$ erl < ~/erl.in
Eshell V8.0 (abort with ^G)
1> entermsgcomplete!ok
2> *** Terminating erlang (nonode@nohost)
[ericu-destroyer-of-worlds] ~$ erl
Erlang/OTP 19 [erts-8.0] [source-6dc93c1] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.0 (abort with ^G)
1> seg_fault:start().
entermsgSegmentation fault
我在使用GDB运行时能够重现seg故障。我没有优化和调试符号就构建了Erlang OTP 19。
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) file ./bin/x86_64-unknown-linux-gnu/erlexec
Reading symbols from ./bin/x86_64-unknown-linux-gnu/erlexec...done.
(gdb) run
Starting program: /home/ericu/builds/otp_src_19.0/bin/x86_64-unknown-linux-gnu/erlexec
process 3251 is executing new program: /home/ericu/builds/otp_src_19.0/bin/x86_64-unknown-linux-gnu/beam.smp
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffb50ff700 (LWP 3255)]
[New Thread 0x7fffb3abf700 (LWP 3256)]
[New Thread 0x7ffff7ff7700 (LWP 3257)]
[New Thread 0x7fffb516e700 (LWP 3258)]
[New Thread 0x7fffb3f30700 (LWP 3259)]
[New Thread 0x7fffb32be700 (LWP 3260)]
[New Thread 0x7fffb317f700 (LWP 3261)]
[New Thread 0x7fffb315d700 (LWP 3262)]
[New Thread 0x7fffb313b700 (LWP 3263)]
[New Thread 0x7fffb3119700 (LWP 3264)]
[New Thread 0x7fffb30f7700 (LWP 3265)]
[New Thread 0x7fffb30d5700 (LWP 3266)]
[New Thread 0x7fffb2e3f700 (LWP 3268)]
[New Thread 0x7fffb263e700 (LWP 3269)]
[New Thread 0x7fffb1e3d700 (LWP 3270)]
[New Thread 0x7fffb163c700 (LWP 3271)]
[New Thread 0x7fffb0c3b700 (LWP 3272)]
[New Thread 0x7fff7bfff700 (LWP 3273)]
[New Thread 0x7fff7b7fe700 (LWP 3274)]
[New Thread 0x7fff7abbf700 (LWP 3275)]
[New Thread 0x7fff7a3be700 (LWP 3276)]
Erlang/OTP 19 [erts-8.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.0 (abort with ^G)
1> seg_fault:start().
entermsg
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffb2e3f700 (LWP 3268)]
0x00000000004c4a85 in lookup_tracer_nif (tracer=18446744073709551611) at beam/erl_trace.c:2763
2763 tnif_tmpl.module = ERTS_TRACER_MODULE(tracer);
(gdb) bt
#0 0x00000000004c4a85 in lookup_tracer_nif (tracer=18446744073709551611) at beam/erl_trace.c:2763
#1 0x00000000004c4f00 in send_to_tracer_nif_raw (c_p=0x7fffb5380400, tracee=0x7fffb5380400, tracer=18446744073709551611, tracee_flags=0, t_p_id=1992864826275, tnif=0x0,
topt=TRACE_FUN_T_CALL, tag=32331, msg=140735234699146, extra=0, pam_result=75) at beam/erl_trace.c:2844
#2 0x00000000004c5340 in send_to_tracer_nif (c_p=0x7fffb5380400, t_p=0x7fffb5380400, t_p_id=1992864826275, tnif=0x0, topt=TRACE_FUN_T_CALL, tag=32331, msg=140735234699146, extra=0,
pam_result=75) at beam/erl_trace.c:2923
#3 0x00000000004c073c in erts_trace_return_to (p=0x7fffb5380400, pc=0x7fffb2ea3758) at beam/erl_trace.c:1028
#4 0x000000000046ad27 in erts_bif_trace (bif_index=129, p=0x7fffb5380400, args=0x7fffb5ec00c0, I=0x7fffb2ea3758) at beam/beam_bp.c:868
#5 0x00000000004ba0cd in wrap_erts_internal_trace_3 (p=0x7fffb5380400, args=0x7fffb5ec00c0, I=0x7fffb2ea3758) at x86_64-unknown-linux-gnu/erl_bif_wrap.c:723
#6 0x0000000000440057 in process_main () at beam/beam_emu.c:2849
#7 0x000000000051e63d in sched_thread_func (vesdp=0x7fffb3e04240) at beam/erl_process.c:8153
#8 0x00000000006b8787 in thr_wrapper (vtwd=0x7fffffffd060) at pthread/ethread.c:114
#9 0x00007ffff7278184 in start_thread (arg=0x7fffb2e3f700) at pthread_create.c:312
#10 0x00007ffff6d9d37d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
(gdb)
基于erts_trace_return_to
的存在,它正在尝试在崩溃时传递跟踪元组。