printing every message information

203 views
Skip to first unread message

ben...@gmail.com

unread,
Sep 27, 2017, 12:24:58 PM9/27/17
to chromium-mojo
Hello,
I'm very new to the chromium open-source project and I'm trying to make my first steps in the code. 
I've read about Mojo, the message pipes and some related information, and now I try to get to know the message types and what really happens behind the scenes by running the code and debugging it (on Mac). 
May you help me to know what my entry point should be if I want to simply print some information about any message which is being written to and read from a mojo-messages-pipe.
Furthermore, how can I print some useful and meaningful information about a mojo message? (a sort of a "stringish" name/type/content/param)

I tried the file src/mojo/public/cpp/bindings/lib/message.cc, and the functions `ReadMessage` and `WriteMessageHeader`, but I don't really know what I should print in order to get some message-specific information.
I also could see that those 2 functions are called tones of times per second, so if you can help me filter out some irrelevant messages it would be great (I want messages about things like a click, a redirect, a render complete, and not mouse move and staff like that)

Ken Rockot

unread,
Sep 27, 2017, 12:40:10 PM9/27/17
to ben...@gmail.com, chromium-mojo
On Wed, Sep 27, 2017 at 9:24 AM, <ben...@gmail.com> wrote:
Hello,
I'm very new to the chromium open-source project and I'm trying to make my first steps in the code. 
I've read about Mojo, the message pipes and some related information, and now I try to get to know the message types and what really happens behind the scenes by running the code and debugging it (on Mac). 
May you help me to know what my entry point should be if I want to simply print some information about any message which is being written to and read from a mojo-messages-pipe.

There is not any single point where all message pipes are read, and the low layer where actual IPC takes place (i.e. bits move from one process to another and you could in theory filter all inbound or outbound traffic) has no comprehension of specific mojom interfaces or even the message encoding mojom interfaces use. It would be quite difficult to watch the IPC boundary and parse out any meaningful notion of which interfaces are sending which messages.
 
Furthermore, how can I print some useful and meaningful information about a mojo message? (a sort of a "stringish" name/type/content/param)  
 

I tried the file src/mojo/public/cpp/bindings/lib/message.cc, and the functions `ReadMessage` and `WriteMessageHeader`, but I don't really know what I should print in order to get some message-specific information.
I also could see that those 2 functions are called tones of times per second, so if you can help me filter out some irrelevant messages it would be great (I want messages about things like a click, a redirect, a render complete, and not mouse move and staff like that)

Right, the meaning of any given mojom message is essentially contextual and determined by the generated code sending or receiving it.

Probably the most straightforward thing to do would be to modify the generated code for interfaces. For example, this bit of a Jinja template stamps out the code for initial message decoding on any given interface bound by a C++ receiver: https://cs.chromium.org/chromium/src/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl?rcl=cbdf643f13cacd3491febd0cd146b2b1158a27d4&l=360

If inside the templated case block you added something like:

  LOG(ERROR) << "{{method.name}}";

you would start to see logs for every mojo message received by every C++-bound interface pipe.

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-mojo+unsubscribe@chromium.org.
To post to this group, send email to chromi...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/b9a11cb5-d68c-4fe7-872d-a8e7b7488a48%40chromium.org.

Ken Rockot

unread,
Sep 27, 2017, 12:40:51 PM9/27/17
to ben...@gmail.com, chromium-mojo
On Wed, Sep 27, 2017 at 9:24 AM, <ben...@gmail.com> wrote:
Hello,
I'm very new to the chromium open-source project and I'm trying to make my first steps in the code. 
I've read about Mojo, the message pipes and some related information, and now I try to get to know the message types and what really happens behind the scenes by running the code and debugging it (on Mac). 
May you help me to know what my entry point should be if I want to simply print some information about any message which is being written to and read from a mojo-messages-pipe.
Furthermore, how can I print some useful and meaningful information about a mojo message? (a sort of a "stringish" name/type/content/param)

There is not any single point where all message pipes are read, and the low layer where actual IPC takes place (i.e. bits move from one process to another and you could in theory filter all inbound or outbound traffic) has no comprehension of specific mojom interfaces or even the message encoding mojom interfaces use. It would be quite difficult to watch the IPC boundary and parse out any meaningful notion of which interfaces are sending which messages.
 
I tried the file src/mojo/public/cpp/bindings/lib/message.cc, and the functions `ReadMessage` and `WriteMessageHeader`, but I don't really know what I should print in order to get some message-specific information.
I also could see that those 2 functions are called tones of times per second, so if you can help me filter out some irrelevant messages it would be great (I want messages about things like a click, a redirect, a render complete, and not mouse move and staff like that)

Dave Tapuska

unread,
Sep 27, 2017, 12:44:57 PM9/27/17
to Ken Rockot, ben...@gmail.com, chromium-mojo
If you are new to chromium development you might get familiar with chrome://tracing first as there is visualization of some of the IPCs (at least for input types you can follow them across the processes).

dave.

ben...@gmail.com

unread,
Sep 28, 2017, 7:17:03 AM9/28/17
to chromium-mojo, ben...@gmail.com, roc...@google.com
Thank for your helpful reply! I tried your suggestion which sounds and feels right for me. I put in the file you gave as an example (interface_definition.tmpl) the following code:
{%- for method in interface.methods %}
LOG(ERROR) << "[debug] name printing: {{method.name}}";
{%- endfor %}
 
And I get errors when I try to log the method names.

gen/components/contextual_search/common/overlay_page_notifier_service.mojom.cc:32:1: error: expected unqualified-id
LOG(ERROR) << "[debug] name printing: NotifyIsContextualSearchOverlay";
^
../../base/logging.h:420:23: note: expanded from macro 'LOG'
#define LOG(severity) LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity))
                      ^
../../base/logging.h:408:3: note: expanded from macro 'LAZY_STREAM'
  !(condition) ? (void) 0 : ::logging::LogMessageVoidify() & (stream)
  ^ 

I can't figure out what "error: expected unqualified-id" is caused by...
Any suggestions? 
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.

Colin Blundell

unread,
Sep 28, 2017, 9:06:07 AM9/28/17
to ben...@gmail.com, chromium-mojo, roc...@google.com
Look at where your LOG statements are in the generated code. My guess is that you inserted them in a location in the template where the compiler then doesn't expect to see a statement like that in the generated code.

In general, if you're mucking with a code generator, going back and forth between the generator script and the generated code will help you debug most problems with the code generation.

Ken Rockot

unread,
Sep 28, 2017, 11:59:03 AM9/28/17
to Colin Blundell, Ben Amsalem, chromium-mojo
Note that you can easily inspect the generated C++ code by looking at the path (relative to your output dir) in the error message. That should make the generated syntax error more obvious.

You may also want docs for Jinja2 in case you're running into some surprising whitespace stripping behavior or something like that.

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-mojo+unsubscribe@chromium.org.

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-mojo+unsubscribe@chromium.org.

To post to this group, send email to chromi...@chromium.org.

ben...@gmail.com

unread,
Oct 1, 2017, 11:00:52 AM10/1/17
to chromium-mojo, blun...@chromium.org, ben...@gmail.com, roc...@google.com
OK, I really did a stupid mistake placing the LOG statement in a random line of the template (misunderstood the concept of Jinja2 templates).
Now I got it and I assume it should be placed inside a function, but I still have no clue which exactly. 
Can I find the documentation for that template's functions so I can find out which function is invoked when a message is read?  

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.
To post to this group, send email to chromi...@chromium.org.

ben...@gmail.com

unread,
Oct 1, 2017, 11:16:17 AM10/1/17
to chromium-mojo, ben...@gmail.com
A different thought on the same topic: Any way I can print the something that represents the mojo message buffer? 
The mojo::Message::ReadMessage function gets a MessagePipeHandle and somehow initializes a new Message object (I tried to figure out how by browsing the code, but couldn't). Can someone tell how this message is supposed to look in the memory? Any known format? Anyway I can print the full message buffer and analyze it? (this time I don't want any meaningful strings or names, so I hope I can leave the templates and the generated code)

Colin Blundell

unread,
Oct 2, 2017, 1:57:39 AM10/2/17
to ben...@gmail.com, chromium-mojo, blun...@chromium.org, Ken Rockot
I believe that Ken linked to an appropriate function in his initial reply upthread.

Yuzhu Shen

unread,
Oct 2, 2017, 1:22:36 PM10/2/17
to ben...@gmail.com, chromium-mojo
On Sun, Oct 1, 2017 at 8:16 AM, <ben...@gmail.com> wrote:
A different thought on the same topic: Any way I can print the something that represents the mojo message buffer? 
The mojo::Message::ReadMessage function gets a MessagePipeHandle and somehow initializes a new Message object (I tried to figure out how by browsing the code, but couldn't). Can someone tell how this message is supposed to look in the memory? Any known format? Anyway I can print the full message buffer and analyze it? (this time I don't want any meaningful strings or names, so I hope I can leave the templates and the generated code)



On Wednesday, September 27, 2017 at 7:24:58 PM UTC+3, ben...@gmail.com wrote:
Hello,
I'm very new to the chromium open-source project and I'm trying to make my first steps in the code. 
I've read about Mojo, the message pipes and some related information, and now I try to get to know the message types and what really happens behind the scenes by running the code and debugging it (on Mac). 
May you help me to know what my entry point should be if I want to simply print some information about any message which is being written to and read from a mojo-messages-pipe.
Furthermore, how can I print some useful and meaningful information about a mojo message? (a sort of a "stringish" name/type/content/param)

I tried the file src/mojo/public/cpp/bindings/lib/message.cc, and the functions `ReadMessage` and `WriteMessageHeader`, but I don't really know what I should print in order to get some message-specific information.
I also could see that those 2 functions are called tones of times per second, so if you can help me filter out some irrelevant messages it would be great (I want messages about things like a click, a redirect, a render complete, and not mouse move and staff like that)

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-mojo+unsubscribe@chromium.org.

To post to this group, send email to chromi...@chromium.org.
Reply all
Reply to author
Forward
0 new messages