Inspecting a process's binaries

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Inspecting a process's binaries

Roger Lipscombe-2
I can get a list of binaries for a process with process_info(Pid,
binary), which returns {binary, [{Id, Size, NRefs},...]}.

Given the Id (which looks like 140327404952984, for example), can I
find out what's *in* that binary?

Context: I've got a custom supervisor process; when I get a list of
binaries, it has a number of ~1.5KB binaries associated with it, which
is a bit of a surprise, because I can't see where they'd have come
from (it's only invoked via gen_server:call, from another node, so I
don't see how it'd be holding sub-binaries, for example).
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Inspecting a process's binaries

Lukas Larsson-8
Hello,

On Mon, Dec 18, 2017 at 3:29 PM, Roger Lipscombe <[hidden email]> wrote:
I can get a list of binaries for a process with process_info(Pid,
binary), which returns {binary, [{Id, Size, NRefs},...]}.

Given the Id (which looks like 140327404952984, for example), can I
find out what's *in* that binary?

It is not possible without looking under the hood in the VM. The ID is a an 'Binary *', so if you attach to the process using gdb and issue

(gdb) p *(Binary*)(140327404952984)

You should get some information about what the binary is. The same can of course be done from a core file if you have the ID.

Lukas

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Inspecting a process's binaries

Max Lapshin-2
so a very dirty bad nif that will inspect arbitrary memory space will help here?

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Inspecting a process's binaries

Lukas Larsson-8
On Thu, Dec 21, 2017 at 2:29 PM, Max Lapshin <[hidden email]> wrote:
so a very dirty bad nif that will inspect arbitrary memory space will help here?

Yes indeed a nif could do that. It would be possible to change process_info(pid, binary) call to return the payload of the binary that is referenced.

However that makes it very easy to by mistake keep all the binaries live forever because they are referenced in the shell history :/

Eshell V9.2  (abort with ^G)

1> erlang:process_info(whereis(binary_problem), binary).

[ list of permanent binary problems .... ]


Though with the correct documentation NOTE WARNING DANGER, I can see it being a useful debugging tool.

Lukas

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions