gdb: attach to process

501 views
Skip to first unread message

Thiago Farina

unread,
Mar 6, 2015, 5:52:57 PM3/6/15
to Chromium-dev, Lei Zhang, Bruce Dawson
Hi,

I'm trying to use gdb to attach to a renderer process, and I would like how others have been doing as well.

So far I did:

In one terminal window:
$ ninja -C out/Debug content_shell
$ out/Debug/content_shell --no-sandbox --renderer-startup-dialog
# The output was something like:
# 22824:22824:0306/193347:1124504976507:ERROR:child_process.cc(132)] Renderer (22824) paused waiting for debugger to attach. Send SIGUSR1 to unpause.

In another terminal window:
$ gdb out/Debug/content_shell 22824
# then gdb starts throwing a bunch of "Reading symbols from ..."
# until it stops at
(gdb)

After that what should I do?

Btw, I also tried lldb, but it is unusable on Linux.

In lldb what I got was:
$ lldb
(lldb) process attach --pid 22824
Process 22824 stopped
* thread #1: tid = 22824, 0x00007fbbd63b75d0 libpthread.so.0`__libc_pause + 16, name = 'content_shell', stop reason = trace
    frame #0: 0x00007fbbd63b75d0 libpthread.so.0`__libc_pause + 16
libpthread.so.0`__libc_pause:
->  0x7fbbd63b75d0 <+16>: cmpq   $-0xfff, %rax
    0x7fbbd63b75d6 <+22>: jae    0x7fbbd63b7609            ; <+73>
    0x7fbbd63b75d8 <+24>: retq   

libpthread.so.0`???:
    0x7fbbd63b75d9 <+25>: subq   $0x8, %rsp

Executable module set to "/home/tfarina/chromium/src/out/Debug/content_shell".
Architecture set to: x86_64-unknown-linux-unknown.


-- 
Thiago Farina

Daniel Cheng

unread,
Mar 6, 2015, 5:55:18 PM3/6/15
to tfa...@chromium.org, Chromium-dev, Lei Zhang, Bruce Dawson

Set your breakpoints and what not in gdb, then use signal SIGUSR1 in gdb to resume execution.


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Nico Weber

unread,
Mar 6, 2015, 5:55:32 PM3/6/15
to Thiago Farina, Chromium-dev, Lei Zhang, Bruce Dawson
Hit 'c', then enter. (Or set breakpoints first, and then hit 'c'.)

There are gdb tutorials available on an internet of your choice.

--

Chris Harrelson

unread,
Mar 6, 2015, 6:08:02 PM3/6/15
to Daniel Cheng, Thiago Farina, Chromium-dev, Lei Zhang, Bruce Dawson
I just use --single-process and run the binary directly within gdb. Does that work for your use case?

Chris

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

Thiago Farina

unread,
Mar 6, 2015, 6:15:37 PM3/6/15
to Chris Harrelson, Daniel Cheng, Chromium-dev, Lei Zhang, Bruce Dawson
On Fri, Mar 6, 2015 at 8:07 PM, Chris Harrelson <chri...@chromium.org> wrote:
I just use --single-process and run the binary directly within gdb. Does that work for your use case?



So I want to debug using something that is actually tested and recommended and thus --renderer-startup-dialog seems to be the way to go.

--
Thiago Farina

Chris Harrelson

unread,
Mar 6, 2015, 6:18:44 PM3/6/15
to Thiago Farina, Daniel Cheng, Chromium-dev, Lei Zhang, Bruce Dawson
But if it works it's simpler, so it's what I try first. :)

Also, it doesn't really work very well for out/Debug/chrome, just out/Debug/content_shell. My go-to commandline is

cgdb --args ./out/Debug/content_shell --single-process

Thiago Farina

unread,
Mar 6, 2015, 6:20:54 PM3/6/15
to Daniel Cheng, Chromium-dev, Lei Zhang, Bruce Dawson
On Fri, Mar 6, 2015 at 7:54 PM, Daniel Cheng <dch...@chromium.org> wrote:

Set your breakpoints and what not in gdb, then use signal SIGUSR1 in gdb to resume execution.

 Thanks Daniel!

Doing that worked.

(gdb) b content/renderer/render_thread_impl.cc:1002
Breakpoint 1 at 0x7fbbe0273590: file ../../content/renderer/render_thread_impl.cc, line 1002.
(gdb) signal SIGUSR1
Continuing with signal SIGUSR1.
[New Thread 0x7fbbcd5d1700 (LWP 26755)]
[New Thread 0x7fbbccdd0700 (LWP 26763)]

Breakpoint 1, content::RenderThreadImpl::EnsureWebKitInitialized (
    this=0x1522b376bc20)
    at ../../content/renderer/render_thread_impl.cc:1002
1002  blink::initialize(blink_platform_impl_.get());

-- 
Thiago Farina

Nasko Oskov

unread,
Mar 6, 2015, 7:52:21 PM3/6/15
to Thiago Farina, Daniel Cheng, Chromium-dev, Lei Zhang, Bruce Dawson
I personally use --renderer-cmd-prefix, which starts a new terminal for each renderer I want to debug. To make it more manageable, I'd suggest reading a couple of sections of the Linux debugging document:
* Choosing which renderers to debug - let's you quickly bail out if the specific renderer is of no interest to be debugged
* Selective breakpoints - let's you automate lots of the manual tasks in getting to the point of interest.

--

Stefan Zager

unread,
Mar 6, 2015, 7:57:58 PM3/6/15
to na...@chromium.org, Thiago Farina, Daniel Cheng, Chromium-dev, Lei Zhang, Bruce Dawson
+1 for --renderer-cmd-prefix, that does the trick for me.

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

Haojian Wu

unread,
Mar 6, 2015, 10:34:16 PM3/6/15
to Thiago Farina, Daniel Cheng, Chromium-dev, Lei Zhang, Bruce Dawson
On Sat, Mar 7, 2015 at 7:20 AM, Thiago Farina <tfa...@chromium.org> wrote:

(gdb) b content/renderer/render_thread_impl.cc:1002
Breakpoint 1 at 0x7fbbe0273590: file ../../content/renderer/render_thread_impl.cc, line 1002.

BTW, is there any more convenient way to set breakpoint? Typing the whole file path for setting each breakpoint is quite troublesome.

Jeremy Roman

unread,
Mar 6, 2015, 11:03:36 PM3/6/15
to hoke...@gmail.com, Thiago Farina, Daniel Cheng, Chromium-dev, Lei Zhang, Bruce Dawson
You should only need the basename; since there is no other render_frame_impl.cc, it should do the right thing.

FWIW, I usually don't care about process startup, so I generally start with "out/Debug/chrome --no-sandbox --disable-hang-monitor", grab the renderer PID from the task manager, then use "gdb [pid]", set breakpoints, and continue.

As another option, Steve Kobes recently posted another way to debug a renderer (with a script landed in Blink): https://groups.google.com/a/chromium.org/d/msg/blink-dev/XyE1DeqMPpg/Bao3H2_bLi4J

--

Thiago Farina

unread,
Mar 7, 2015, 5:13:12 PM3/7/15
to Jeremy Roman, Haojian Wu, Daniel Cheng, Chromium-dev, Lei Zhang, Bruce Dawson, Steve Kobes
On Sat, Mar 7, 2015 at 1:03 AM, Jeremy Roman <jbr...@chromium.org> wrote:
You should only need the basename; since there is no other render_frame_impl.cc, it should do the right thing.

FWIW, I usually don't care about process startup, so I generally start with "out/Debug/chrome --no-sandbox --disable-hang-monitor", grab the renderer PID from the task manager, then use "gdb [pid]", set breakpoints, and continue.

As another option, Steve Kobes recently posted another way to debug a renderer (with a script landed in Blink): https://groups.google.com/a/chromium.org/d/msg/blink-dev/XyE1DeqMPpg/Bao3H2_bLi4J

Thanks Jeremy. Steve's script does exactly what I was trying to do manually (with the upside of having to open two terminal windows).
 
--
Thiago Farina
Reply all
Reply to author
Forward
0 new messages