Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:15:21+00:00 2026-05-31T20:15:21+00:00

I suspect the answer is probably no, but just in case, is there a

  • 0

I suspect the answer is probably “no”, but just in case, is there a way to add data to the traced event when using return_trace()?

E.g.

1> erlang:trace(all, true, [call]).
...
2> MatchSpec = dbg:fun2ms(fun([Num1, Num2]) when Num1 < Num2 -> 
                     return_trace(), message({event_name, neg_sub_event}); 
                   (_) -> 
                     return_trace(), message({event_name, sub_event}) end).
...
3> erlang:trace_pattern({mod, sub, 2}, MatchSpec, [local]).
...
4> flush().
ok
5> spawn(mod, sub, [4, 5]).
...
6> flush().
Shell got {trace,<0.64.0>,call,
             {mod,sub,[4,5]},
             {event_name,neg_sub_event}}
Shell got {trace,<0.64.0>,return_from,{mod,sub,2},-1}
ok
7> spawn(mod, sub, [6, 5]).
...
8> flush().
Shell got {trace,<0.67.0>,call,{mod,sub,[6,5]},{event_name,sub_event}}
Shell got {trace,<0.67.0>,return_from,{mod,sub,2},1}
ok

I just came up with the example without really thinking about it… in this case I could figure out whether it’s a neg_sub_event or a sub_event from the return value included in a return_from trace… but the point is that I would like to include {event_name, Name} not only when a call event fires, but also when a return_from event is generated.

Is this even possible?

Thanks.

Edit

This is why I can’t simply receive a ‘return_from’ trace and say “ok, so this ‘return_from’ trace must correspond to the last ‘call’ trace I received. Therefore, this ‘return_from’ trace must have the event_name of the last ‘call’ trace I received”:

Consider 2 processes A and B. Both call function F1 which is being traced with a specification which states that in one case (e.g. F1 is called with an argument of 10), the ‘call’ trace generated should have an event_name of “is_ten” and a return_trace() should be generated after the call trace is. Therefore, the process receiving the trace messages would receive:

{trace, Pid, call, {Mod, Fun, Args}, {event_name, is_ten}}

when F1 is called with an argument of 10, and

{trace, Pid, return_from, {Mod, Fun, Arity}, ReturnVal}

when F1, called with an argument of 10, is evaluated and returns.

Another specification placed on F1 (via the match spec used in erlang:trace_pattern/3) is that, for e.g., when F1 is called with an argument of 20, the ‘call’ trace generated should have an event_name of “is_twenty” and a return_trace() should be generated after the call trace is. Therefore, the process receiving the trace messages would receive:

{trace, Pid, call, {Mod, Fun, Args}, {event_name, is_twenty}}

when F1 is called with an argument of 20, and

{trace, Pid, return_from, {Mod, Fun, Arity}, ReturnVal}

when F1, called with an argument of 20, is evaluated and returns.

Now if A starts evaluating F1 (with arg 10), generates a ‘call’ trace, is preempted, B starts evaluating F1 (with arg 20), generates a ‘call’ trace, is preempted, A finishes evaluating F1, and generates a ‘return_from’ trace, the process receiving the trace messages would receive:

{trace, Pid, call, {Mod, Fun, Args}, {event_name, is_ten}}
{trace, Pid, call, {Mod, Fun, Args}, {event_name, is_twenty}}
{trace, Pid, return_from, {Mod, Fun, Arity}, ReturnVal}

At this stage, if the process receiving the trace messages assumes that every ‘return_from’ trace message corresponds to the latest ‘call’ message receive, it will assign the event_name of ‘is_twenty’ to the return_from message when in fact it should be ‘is_ten’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:15:22+00:00Added an answer on May 31, 2026 at 8:15 pm

    No. You can only add extra information in a trace ‘call’ using message(Data) in MatchSpec. Furthermore, when writing the body of a specification, you can add a return_trace(). This will generate a ‘return_from’ trace message when the function being traced returns, BUT, unlike the trace message which is sent when the function in question is being called, you cannot add extra information to the trace message which is sent when the function in question returns.

    E.g.

    dbg:fun2ms(fun([Num1, Num2]) when Num1 < Num2 -> 
                     return_trace(), message({event_name, neg_sub_event}); 
                   (_) -> 
                     message({event_name, sub_event}) end).
    

    The match specification generated above, when applied to the function mod:sub/2 using erlang:trace_pattern({mod, sub, 2}, MatchSpec, [local]), will generate the following trace events (when the traced processes have the flag ‘call’ turned on using erlang:trace/3):

    {trace, Pid, call, {Mod, Fun, Args}, {event_name, neg_sub_event}}
    

    and

    {trace, Pid, return_from, {Mod, Fun, Arity}, ReturnVal}
    

    when mod:sub/2 is called with Num1 and Num2 such that Num1 < Num2.
    In all other cases, the generated trace would be:

    {trace, Pid, call, {Mod, Fun, Args}, {event_name, sub_event}}
    

    Therefore, you cannot add extra info like “{event_name, Name}” to a ‘return_from’ trace because there is no way of specifying this in a match specification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suspect there's probably an easy answer to this I'm just not seeing, but
I am creating a shared library using gcc and suspect that there may be
Just as in title. Is suspect it is, but I couldn't find it anywhere
I suspect the answer is no, but is it possible to do something like
I suspect the answer's a pretty definite no, but given the following html and
I suspect the answer is no, but I want to check. If I have
I suspect this answer is in SO but I cannot find it. Some reports
I suspect this applies to general ASP.Net too but I am not sure. If
One day I suspect I'll have to learn hadoop and transfer all this data
I've notice an issue - it feels like a bug but I suspect a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.