Stream: general

Topic: Debugging with GDB


LeSeulArtichaut (May 21 2020 at 20:35, on Zulip):

@RalfJ Would you mind helping me a little? Do I need to compile rustc to debug it with GDB? Inside of GDB, what should I do?

LeSeulArtichaut (May 21 2020 at 20:36, on Zulip):

I just installed it and tested it with my hello world program (the one and only)

LeSeulArtichaut (May 21 2020 at 20:36, on Zulip):

So at least I won't have to bother you with MacOS permissions and certificates and stuff :D

RalfJ (May 21 2020 at 20:44, on Zulip):

yeah I can only tell you how it works on Linux :P

RalfJ (May 21 2020 at 20:45, on Zulip):

so I assume you have a command rustc <arguments> that is the culprit

RalfJ (May 21 2020 at 20:45, on Zulip):

if you have been using cargo to reproduce so far you'll have to distill this to a rustc command first

RalfJ (May 21 2020 at 20:46, on Zulip):

then I would do gdb rustc, after which a prompt opens. in that prompt you do run <rustc argument>, which starts rustc. then you wait until you think it is in the endless/looooong loop you want to capture.

RalfJ (May 21 2020 at 20:46, on Zulip):

then you do Ctrl-C, and do bt to print the backtrace, and copy-paste that

LeSeulArtichaut (May 21 2020 at 20:48, on Zulip):

Oh it's that simple? :D

simulacrum (May 21 2020 at 20:49, on Zulip):

well if you get a backtrace successfully doing that

simulacrum (May 21 2020 at 20:49, on Zulip):

it may not work :)

LeSeulArtichaut (May 21 2020 at 20:49, on Zulip):

:frown:

RalfJ (May 21 2020 at 20:50, on Zulip):

this works pretty reliably for me...

RalfJ (May 21 2020 at 20:50, on Zulip):

okay if rustc does work off the main thread you might have to thread apply all bt and find the right backtrace

RalfJ (May 21 2020 at 20:50, on Zulip):

(the exact command for this might be slightly different)

LeSeulArtichaut (May 21 2020 at 20:50, on Zulip):

I got a [New Thread 0xe03 of process 1445] message

LeSeulArtichaut (May 21 2020 at 20:50, on Zulip):

So I guess it started in another thread?

RalfJ (May 21 2020 at 20:50, on Zulip):

yeah thats just gdb telling you a thread started, but it should go on after that

LeSeulArtichaut (May 21 2020 at 20:51, on Zulip):

Let's let it run for 5 minutes or so

RalfJ (May 21 2020 at 20:51, on Zulip):

eh

RalfJ (May 21 2020 at 20:51, on Zulip):

wow you are patient^^

RalfJ (May 21 2020 at 20:51, on Zulip):

so in the bug report, did it stop producing LOG output at some point?

LeSeulArtichaut (May 21 2020 at 20:51, on Zulip):

I think it did

RalfJ (May 21 2020 at 20:52, on Zulip):

how long did that take?

LeSeulArtichaut (May 21 2020 at 20:52, on Zulip):

But I think it was only set to debug INFO level

LeSeulArtichaut (May 21 2020 at 20:52, on Zulip):

Errrr

LeSeulArtichaut (May 21 2020 at 20:52, on Zulip):

Let me find that out

RalfJ (May 21 2020 at 20:52, on Zulip):

probably best thing is to run gdb with the RUSTC_LOG env var and then wait until the output stops

LeSeulArtichaut (May 21 2020 at 20:52, on Zulip):

Alright

LeSeulArtichaut (May 21 2020 at 20:53, on Zulip):

Hmm, doing Ctrl+C doesn't seem to work

RalfJ (May 21 2020 at 20:53, on Zulip):

Ctrl-C should get you to the gdb prompt

RalfJ (May 21 2020 at 20:53, on Zulip):

then quit quits gdb

LeSeulArtichaut (May 21 2020 at 20:53, on Zulip):

But it doesn't :eyes:

RalfJ (May 21 2020 at 20:53, on Zulip):

well that's... weird

RalfJ (May 21 2020 at 20:53, on Zulip):

I blame macOS :P

LeSeulArtichaut (May 21 2020 at 20:53, on Zulip):

That's worrying :D

RalfJ (May 21 2020 at 20:54, on Zulip):

https://superuser.com/questions/789796/what-is-the-terminal-command-other-than-ctrl-c-to-exit-a-running-node-js-progr

RalfJ (May 21 2020 at 20:54, on Zulip):

no idea if that makes any sense

RalfJ (May 21 2020 at 20:54, on Zulip):

does "command + ." do anything?^^

LeSeulArtichaut (May 21 2020 at 20:55, on Zulip):

Doesn't seem like it

LeSeulArtichaut (May 21 2020 at 20:55, on Zulip):

Well MacOS is just another UNIX system

LeSeulArtichaut (May 21 2020 at 20:55, on Zulip):

Ctrl-C works

RalfJ (May 21 2020 at 20:56, on Zulip):

some other places of the internet suggest using lldb instead

RalfJ (May 21 2020 at 20:56, on Zulip):

I never used that but I presume it is mostly compatible with gdb...

LeSeulArtichaut (May 21 2020 at 20:57, on Zulip):

Oh wow, Ctrl-Z got me:

[1]  + 1440 suspended  gdb rustc src/main.rs
LeSeulArtichaut (May 21 2020 at 20:57, on Zulip):

But no gdb prompt though :P

RalfJ (May 21 2020 at 20:57, on Zulip):

yah Ctrl-Z would send the entire thing to the background

RalfJ (May 21 2020 at 20:57, on Zulip):

but now you can kill %1 :D

LeSeulArtichaut (May 21 2020 at 20:58, on Zulip):

I mean I can also close my terminal

LeSeulArtichaut (May 21 2020 at 20:58, on Zulip):

But that won't help

RalfJ (May 21 2020 at 20:58, on Zulip):

right but that above kills the first background process

simulacrum (May 21 2020 at 20:58, on Zulip):

@RalfJ I've heard reports that on some platforms gdb is .. less than ideal, and sometimes just doesn't give backtraces

LeSeulArtichaut (May 21 2020 at 20:59, on Zulip):

Let's try with lldb then I guess

RalfJ (May 21 2020 at 20:59, on Zulip):

:+1:

RalfJ (May 21 2020 at 21:00, on Zulip):

and set RUSTC_LOG so you can see when the log stops moving

LeSeulArtichaut (May 21 2020 at 21:02, on Zulip):

Oh right

LeSeulArtichaut (May 21 2020 at 21:02, on Zulip):

export RUSTC_LOG=rustc

XAMPPRocky (May 21 2020 at 21:03, on Zulip):

Yeah I don’t recommend gdb on macOS, you’re going to run into a bunch of problems. I still haven’t figured out how to correctly enable it without permanently disabling system integrity protection. All the guides are out of date or wrong.

LeSeulArtichaut (May 21 2020 at 21:04, on Zulip):

:thinking:

(lldb) target create rustc
Current executable set to 'rustc' (x86_64).
(lldb) run +nightly src/main.rs
Process 1712 launched: '/Users/tous/.cargo/bin/rustc' (x86_64)
Process 1712 stopped
* thread #2, stop reason = exec
    frame #0: 0x000000010026a000 dyld`_dyld_start
dyld`_dyld_start:
->  0x10026a000 <+0>: popq   %rdi
    0x10026a001 <+1>: pushq  $0x0
    0x10026a003 <+3>: movq   %rsp, %rbp
    0x10026a006 <+6>: andq   $-0x10, %rsp
Target 0: (rustc) stopped.
RalfJ (May 21 2020 at 21:04, on Zulip):

oh... we probably need to move one wrapper down

RalfJ (May 21 2020 at 21:04, on Zulip):

rustc here is still the rustup wrapper

LeSeulArtichaut (May 21 2020 at 21:05, on Zulip):

So I want to use the path to the binary?

RalfJ (May 21 2020 at 21:05, on Zulip):

the actual rustc binary is somewhere in... ~/.rustup/toolchains

RalfJ (May 21 2020 at 21:05, on Zulip):

so you want to use lldb ~/.rustup/toolchains/nightly/... or so

LeSeulArtichaut (May 21 2020 at 21:06, on Zulip):

Yeah, it works

LeSeulArtichaut (May 21 2020 at 21:06, on Zulip):

And already stopped at LEAVING(0) main (unwinding = false)

LeSeulArtichaut (May 21 2020 at 21:07, on Zulip):

Here's what I get:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x00007fff6ce289f6 libsystem_kernel.dylib`__ulock_wait + 10
    frame #1: 0x00007fff6ceef385 libsystem_pthread.dylib`_pthread_join + 323
    frame #2: 0x0000000106eebe90 libstd-0f45f03d2da49250.dylib`std::sys::unix::thread::Thread::join::he4b5475ec86f3950 + 16
    frame #3: 0x000000010048f8f6 librustc_driver-e74b82e42afdd3af.dylib`std::thread::JoinHandle$LT$T$GT$::join::hb00ce852782dd91f + 54
    frame #4: 0x00000001004d4899 librustc_driver-e74b82e42afdd3af.dylib`rustc_interface::util::spawn_thread_pool::h5019077c47c5b3d4 + 537
    frame #5: 0x00000001004b83df librustc_driver-e74b82e42afdd3af.dylib`rustc_driver::run_compiler::hec7ed5e1b2ad17c0 + 7663
    frame #6: 0x00000001004f9b48 librustc_driver-e74b82e42afdd3af.dylib`_$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hc5599978260bb5a2 + 120
    frame #7: 0x00000001004be432 librustc_driver-e74b82e42afdd3af.dylib`rustc_driver::catch_with_exit_code::h8593be9703207610 + 18
    frame #8: 0x00000001004bf58b librustc_driver-e74b82e42afdd3af.dylib`rustc_driver::main::hddcc79ad40e9575f + 43
    frame #9: 0x0000000100000cde rustc`rustc_binary::main::heca050561af94105 + 14
    frame #10: 0x0000000100000d16 rustc`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h3c5158dd276dd7dc + 6
    frame #11: 0x0000000106eddc69 libstd-0f45f03d2da49250.dylib`std::rt::lang_start_internal::heec5cb3c6d314455 + 441
    frame #12: 0x0000000100000d09 rustc`main + 41
    frame #13: 0x0000000100000cc4 rustc`start + 52
LeSeulArtichaut (May 21 2020 at 21:08, on Zulip):

I guess I need to navigate through the threads, right?

RalfJ (May 21 2020 at 21:08, on Zulip):

yeah thats the main thread

RalfJ (May 21 2020 at 21:08, on Zulip):

and its not helpful

RalfJ (May 21 2020 at 21:08, on Zulip):

also ugh why doesn't it resolve the symbols :/

LeSeulArtichaut (May 21 2020 at 21:08, on Zulip):

How would you proceed on GDB?

RalfJ (May 21 2020 at 21:08, on Zulip):

thread apply all bt

LeSeulArtichaut (May 21 2020 at 21:08, on Zulip):

LLDB seems very similar

RalfJ (May 21 2020 at 21:08, on Zulip):

then you get the backtraces of all threads

RalfJ (May 21 2020 at 21:09, on Zulip):

(I should also note that we are going through more than 80% of my gdb knowledge here. I am not a gdb guru, I just know how to do this one thing.^^)

LeSeulArtichaut (May 21 2020 at 21:09, on Zulip):

Doesn't work on lldb unfortunately

LeSeulArtichaut (May 21 2020 at 21:09, on Zulip):
(lldb) thread list
Process 1738 stopped
* thread #1: tid = 0x5179, 0x00007fff6ce289f6 libsystem_kernel.dylib`__ulock_wait + 10, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  thread #2: tid = 0x5194, 0x0000000102f320d4 librustc_driver-e74b82e42afdd3af.dylib`_$LT$rustc_mir..interpret..intern..InternVisitor$LT$M$GT$$u20$as$u20$rustc_mir..interpret..visitor..ValueVisitor$LT$M$GT$$GT$::visit_value::h37ced94f75053e5e + 1236, name = 'rustc'
````
LeSeulArtichaut (May 21 2020 at 21:10, on Zulip):

Any useful info in there?

RalfJ (May 21 2020 at 21:10, on Zulip):

https://lldb.llvm.org/use/map.html

LeSeulArtichaut (May 21 2020 at 21:10, on Zulip):

Thread 2 seems suspicious :D

RalfJ (May 21 2020 at 21:10, on Zulip):

looks like the lldb thing is bt all

LeSeulArtichaut (May 21 2020 at 21:11, on Zulip):

Yeah that works

RalfJ (May 21 2020 at 21:11, on Zulip):

:tada:

LeSeulArtichaut (May 21 2020 at 21:11, on Zulip):

Raw output is too large for Zulip though :laughing:

RalfJ (May 21 2020 at 21:11, on Zulip):

lol

RalfJ (May 21 2020 at 21:11, on Zulip):

just put it in the GH issue (in <details> like you did with the log)

RalfJ (May 21 2020 at 21:12, on Zulip):

I need to get to sleep anyway ;)

simulacrum (May 21 2020 at 21:12, on Zulip):

gist, please, though

RalfJ (May 21 2020 at 21:13, on Zulip):

or that

LeSeulArtichaut (May 21 2020 at 21:13, on Zulip):

RalfJ said:

I need to get to sleep anyway ;)

Goodnight then!

LeSeulArtichaut (May 21 2020 at 21:13, on Zulip):

Thanks a whole lot for the help

RalfJ (May 21 2020 at 21:13, on Zulip):

simulacrum said:

gist, please, though

any reason to prefer that over the foldable <details> thing?

RalfJ (May 21 2020 at 21:13, on Zulip):

@LeSeulArtichaut thank you for looking into this issue :)

simulacrum (May 21 2020 at 21:19, on Zulip):

Yeah, <details> won't fold in ~all email clients I'm aware of

simulacrum (May 21 2020 at 21:19, on Zulip):

so you end up with a very long email

simulacrum (May 21 2020 at 21:19, on Zulip):

not to mention that it's a pain to scroll in github's ui, I'd much rather firefox's plain text view or w/e

LeSeulArtichaut (May 21 2020 at 21:23, on Zulip):

Created a gist

LeSeulArtichaut (May 21 2020 at 21:23, on Zulip):

Last frame is:

frame #0: 0x0000000102f320d4 librustc_driver-e74b82e42afdd3af.dylib`_$LT$rustc_mir..interpret..intern..InternVisitor$LT$M$GT$$u20$as$u20$rustc_mir..interpret..visitor..ValueVisitor$LT$M$GT$$GT$::visit_value::h37ced94f75053e5e + 1236
LeSeulArtichaut (May 21 2020 at 21:24, on Zulip):

So I think this is definitely a const-eval problem?

Santiago Pastorino (May 21 2020 at 21:28, on Zulip):

@LeSeulArtichaut btw, this is a nice thing to better document on Rustc Dev Guide :)

LeSeulArtichaut (May 21 2020 at 21:29, on Zulip):

I was also thinking that :D

Santiago Pastorino (May 21 2020 at 21:30, on Zulip):

I had the idea of gathering a bunch of chapters we have an create a complete introspection section

Santiago Pastorino (May 21 2020 at 21:31, on Zulip):

plus some new content probably

RalfJ (May 22 2020 at 19:57, on Zulip):

simulacrum said:

Yeah, <details> won't fold in ~all email clients I'm aware of

it folds in thunderbird, FWIW, so I wasnt aware.^^

Last update: May 29 2020 at 16:55UTC