{"id":2477,"date":"2014-04-25T14:26:07","date_gmt":"2014-04-25T19:26:07","guid":{"rendered":"http:\/\/mikeconley.ca\/blog\/?p=2477"},"modified":"2023-12-20T16:25:12","modified_gmt":"2023-12-20T21:25:12","slug":"electrolysis-debugging-child-processes-of-content-for-make-benefit-glorious-browser-of-firefox","status":"publish","type":"post","link":"https:\/\/mikeconley.ca\/blog\/2014\/04\/25\/electrolysis-debugging-child-processes-of-content-for-make-benefit-glorious-browser-of-firefox\/","title":{"rendered":"Electrolysis: Debugging Child Processes of Content for Make Benefit Glorious Browser of Firefox"},"content":{"rendered":"<p>Here&#8217;s how I&#8217;m currently debugging <a href=\"https:\/\/wiki.mozilla.org\/Electrolysis\">Electrolysis<\/a> stuff on OS X using gdb. It involves multiple terminal windows. I live with that.<\/p>\n<pre># In Terminal Window 1, I execute my Firefox build with MOZ_DEBUG_CHILD_PROCESS=1.\r\n# That environment variable makes it so that the parent process spits out the child\r\n# process ID as soon as it forks out. I also use my e10s profile so as to not muck up\r\n# my default profile.\r\n\r\nMOZ_DEBUG_CHILD_PROCESS=1 .\/mach run -P e10s\r\n\r\n# So, now my Firefox is spawned up and ready to go. I have\r\n# browser.tabs.remote.autostart set to \"true\" in my about:config, which means I'm\r\n# using out-of-process tabs by default. That means that right away, I see the\r\n# child process ID dumped into the console. Maybe you get the same thing if\r\n# browser.tabs.remote.autostart is false. I haven't checked.\r\n\r\nCHILDCHILDCHILDCHILD\r\n  debug me @ 45326\r\n\r\n# ^-- so, this is what comes out in Terminal Window 1.<\/pre>\n<p>So, the next step is to open another terminal window. This one will connect to the parent process.<\/p>\n<pre># Maybe there are smarter ways to find the firefox process ID, but this is what I\r\n# use in my new Terminal Window 2.\r\nps aux | grep firefox\r\n\r\n# And this is what I get back:\r\n\r\nmikeconley\u00a0\u00a0\u00a0\u00a0 45391\u00a0 17.2\u00a0 5.3\u00a0 3985032 883932\u00a0\u00a0 ??\u00a0 S\u00a0\u00a0\u00a0\u00a0 2:39pm\u00a0\u00a0 1:58.71 \/Applications\/FirefoxAurora.app\/Contents\/MacOS\/firefox\r\nmikeconley\u00a0\u00a0\u00a0\u00a0 45322\u00a0\u00a0 0.0\u00a0 0.4\u00a0 3135172\u00a0 69748 s000\u00a0 S+\u00a0\u00a0\u00a0 2:36pm\u00a0\u00a0 0:06.48 \/Users\/mikeconley\/Projects\/mozilla-central\/obj-x86_64-apple-darwin12.5.0\/dist\/Nightly.app\/Contents\/MacOS\/firefox -no-remote -foreground -P e10s\r\nmikeconley\u00a0\u00a0\u00a0\u00a0 45430\u00a0\u00a0 0.0\u00a0 0.0\u00a0 2432768\u00a0\u00a0\u00a0 612 s002\u00a0 R+\u00a0\u00a0\u00a0 2:44pm\u00a0\u00a0 0:00.00 grep firefox\r\nmikeconley\u00a0\u00a0\u00a0\u00a0 44878\u00a0\u00a0 0.0\u00a0 0.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0 0 s000\u00a0 Z\u00a0\u00a0\u00a0 11:46am\u00a0\u00a0 0:00.00 (firefox)\r\n\r\n# That second one is what I want to attach to. I can tell, because the executable\r\n# path lies within my local build's objdir. The first row is my main Firefox I just\r\n# use for work browsing. I definitely don't want to attach to that. The third line\r\n# is just me looking for the process with grep. Not sure what that last one is.\r\n\r\n# I use sudo to attach to the parent because otherwise, OS X complains about permissions\r\n# for process attachment. I attach to the parent like this:\r\n\r\nsudo gdb firefox 45322\r\n\r\n# And now I have a gdb for the parent process. Easy peasy.<\/pre>\n<p>And finally, to debug the child, I open yet another terminal window.<\/p>\n<pre># That process ID that I got from Terminal Window 1 comes into play now.\r\n\r\nsudo gdb firefox 45326\r\n\r\n# Boom - attached to child process now.<\/pre>\n<p>Setting breakpoints for things like TabChild::foo or TabParent::bar can be done like this:<\/p>\n<pre># In Terminal Window 3, attached to the child:\r\n\r\nb mozilla::dom::TabChild::foo\r\n\r\n# In Terminal Window 2, attached to the parent:\r\n\r\nb mozilla::dom::TabParent::bar<\/pre>\n<p>And now we&#8217;re cookin&#8217;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s how I&#8217;m currently debugging Electrolysis stuff on OS X using gdb. It involves multiple terminal windows. I live with that. # In Terminal Window 1, I execute my Firefox build with MOZ_DEBUG_CHILD_PROCESS=1. # That environment variable makes it so that the parent process spits out the child # process ID as soon as it [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5,874,861,79],"tags":[1071,1069,1068,125,1070,35],"class_list":["post-2477","post","type-post","status-publish","format-standard","hentry","category-computer-science","category-firefox-mozilla-2","category-mozilla-2","category-technology","tag-debugging","tag-e10s","tag-electrolysis","tag-firefox","tag-gdb","tag-mozilla"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prmTy-DX","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/2477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/comments?post=2477"}],"version-history":[{"count":2,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/2477\/revisions"}],"predecessor-version":[{"id":2479,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/2477\/revisions\/2479"}],"wp:attachment":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/media?parent=2477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/categories?post=2477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/tags?post=2477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}