* Debugging jitted code
@ 2016-08-29 22:26 Jan Vrany
2016-08-30 19:51 ` Jan Vrany
0 siblings, 1 reply; 2+ messages in thread
From: Jan Vrany @ 2016-08-29 22:26 UTC (permalink / raw)
To: gdb
Hi all,Â
I'd like to debug jitted code using GDB and it's jit interface.Â
The code is generated by LLVM's MCJIT the jitter generates DWARF
debug info using LLVM's DIBuilder. I'd expect GDB to make use of
this info, but all I can see is name of the jitted function.Â
GDB seems not to be aware of all the rest such as filenames andÂ
line numbers.Â
Below you may find more details - I just try to give as much
information as possible:
I run x86_64 Linux and compiled most recent GDB myself:
gdb --version
GNU gdb (GDB) 7.12.50.20160829-git
Copyright (C) 2016 Free Software Foundation, Inc.
...
I'm using most recent LLVM 4.0 compiled from SVN tree,Â
if that matters.Â
To me it looks like the in-memory object ELF file generated byÂ
LLVM is fine and contain all the DWARF info. I checked this
by breaking on '__jit_debug_register_code'. Then I used gdb's
dump command:
(gdb) p * JITCodeEntry
$1 = {next_entry = 0x13bbcc0, prev_entry = 0x0, symfile_addr =
0x1442850 "\177ELF\002\001\001", symfile_size = 2960}
(gdb) dump binary memory /tmp/m.o 0x1442850 (0x1442850 + 2960)
and the used objdump /tmp/m.o to look what's inside. LooksÂ
good to me:
jv@sao:~/Projects/gdb/sources1/gdb$ objdump -x /tmp/m.oÂ
/tmp/m.o:Â Â Â Â Â file format elf64-x86-64
/tmp/m.o
architecture: i386:x86-64, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x0000000000000000
Sections:
Idx Name          Size      VMA               LMA               File
off  Algn
 0
.text         000001e4  0000000028000210  0000000028000210  00000040  2
**4
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
 1
.data         00000008  00000000013ba788  00000000013ba788  00000228  2
**3
                  CONTENTS, ALLOC, LOAD, DATA
 2
.debug_str    0000009a  0000000000000000  0000000000000000  00000230  2
**0
                  CONTENTS, READONLY, DEBUGGING
 3
.debug_loc    00000000  0000000000000000  0000000000000000  000002ca  2
**0
                  CONTENTS, READONLY, DEBUGGING
 4 .debug_abbrev
00000010  0000000000000000  0000000000000000  000002ca  2**0
                  CONTENTS, READONLY, DEBUGGING
 5
.debug_info   0000001e  0000000000000000  0000000000000000  000002da  2
**0
                  CONTENTS, RELOC, READONLY, DEBUGGING
 6 .debug_ranges
00000000Â Â 0000000000000000Â Â 0000000000000000Â Â 000002f8Â Â 2**0
                  CONTENTS, READONLY, DEBUGGING
 7 .debug_macinfo
00000001Â Â 0000000000000000Â Â 0000000000000000Â Â 000002f8Â Â 2**0
                  CONTENTS, READONLY, DEBUGGING
 8 .note.GNU-stack
00000000Â Â 0000000000000000Â Â 0000000000000000Â Â 000002f9Â Â 2**0
                  CONTENTS, READONLY
 9
.eh_frame     00000040  00000000013df908  00000000013df908  00000300  2
**3
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
 10
.debug_line   0000005e  0000000000000000  0000000000000000  00000340  2
**0
                  CONTENTS, RELOC, READONLY, DEBUGGING
...rest ommited...
0x28000210 is address of the beginning of generatedÂ
machine code.Â
By quick look at jit.c, jit_bfd_try_read_symtab(), line ~ 941
it looks that gdb only reads / considers .text, .data and .eh_frame
sections, ignoring the rest including those containing DWARD debugÂ
info. This confuses me a little, but I have a very little knowledge
of DWARF / GDB internals.Â
I'd appreciate if anyone can shed a bit of a light into this.Â
It'd be really cool if I can see source line numbers or even
print variable names for jitted code from GDB.
Thanks a lot!Â
Best, Jan
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Debugging jitted code
2016-08-29 22:26 Debugging jitted code Jan Vrany
@ 2016-08-30 19:51 ` Jan Vrany
0 siblings, 0 replies; 2+ messages in thread
From: Jan Vrany @ 2016-08-30 19:51 UTC (permalink / raw)
To: gdb
Hi all,Â
just for the record: the problem was, of course, in
my code. Due to an unspotted change in LLVM, there
was a missing DIE for the function itself (DW_TAG_Subprogram).Â
Once fixed, it started to work as expected.Â
Many thanks to Keith Seitz for his comment, it saved me a
lot of time! Thanks a lot!
Jan
On Mon, 2016-08-29 at 23:26 +0100, Jan Vrany wrote:
> Hi all,Â
>
> I'd like to debug jitted code using GDB and it's jit interface.Â
> The code is generated by LLVM's MCJIT the jitter generates DWARF
> debug info using LLVM's DIBuilder. I'd expect GDB to make use of
> this info, but all I can see is name of the jitted function.Â
> GDB seems not to be aware of all the rest such as filenames andÂ
> line numbers.Â
>
> Below you may find more details - I just try to give as much
> information as possible:
>
> I run x86_64 Linux and compiled most recent GDB myself:
> gdb --version
> GNU gdb (GDB) 7.12.50.20160829-git
> Copyright (C) 2016 Free Software Foundation, Inc.
> ...
>
> I'm using most recent LLVM 4.0 compiled from SVN tree,Â
> if that matters.Â
>
> To me it looks like the in-memory object ELF file generated byÂ
> LLVM is fine and contain all the DWARF info. I checked this
> by breaking on '__jit_debug_register_code'. Then I used gdb's
> dump command:
>
> (gdb) p * JITCodeEntry
> $1 = {next_entry = 0x13bbcc0, prev_entry = 0x0, symfile_addr =
> 0x1442850 "\177ELF\002\001\001", symfile_size = 2960}
> (gdb) dump binary memory /tmp/m.o 0x1442850 (0x1442850 + 2960)
>
> and the used objdump /tmp/m.o to look what's inside. LooksÂ
> good to me:
>
> jv@sao:~/Projects/gdb/sources1/gdb$ objdump -x /tmp/m.oÂ
>
> /tmp/m.o:Â Â Â Â Â file format elf64-x86-64
> /tmp/m.o
> architecture: i386:x86-64, flags 0x00000011:
> HAS_RELOC, HAS_SYMS
> start address 0x0000000000000000
>
> Sections:
> Idx Name          Size      VMA               LMA               File
> off  Algn
> Â 0
> .text         000001e4  0000000028000210  0000000028000210  00000040Â
> Â 2
> **4
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
> Â 1
> .data         00000008  00000000013ba788  00000000013ba788  00000228Â
> Â 2
> **3
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, ALLOC, LOAD, DATA
> Â 2
> .debug_str    0000009a  0000000000000000  0000000000000000  00000230Â
> Â 2
> **0
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, READONLY, DEBUGGING
> Â 3
> .debug_loc    00000000  0000000000000000  0000000000000000  000002caÂ
> Â 2
> **0
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, READONLY, DEBUGGING
> Â 4 .debug_abbrev
> 00000010  0000000000000000  0000000000000000  000002ca  2**0
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, READONLY, DEBUGGING
> Â 5
> .debug_info   0000001e  0000000000000000  0000000000000000  000002daÂ
> Â 2
> **0
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, RELOC, READONLY, DEBUGGING
> Â 6 .debug_ranges
> 00000000Â Â 0000000000000000Â Â 0000000000000000Â Â 000002f8Â Â 2**0
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, READONLY, DEBUGGING
> Â 7 .debug_macinfo
> 00000001Â Â 0000000000000000Â Â 0000000000000000Â Â 000002f8Â Â 2**0
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, READONLY, DEBUGGING
> Â 8 .note.GNU-stack
> 00000000Â Â 0000000000000000Â Â 0000000000000000Â Â 000002f9Â Â 2**0
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, READONLY
> Â 9
> .eh_frame     00000040  00000000013df908  00000000013df908  00000300Â
> Â 2
> **3
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
> Â 10
> .debug_line   0000005e  0000000000000000  0000000000000000  00000340Â
> Â 2
> **0
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â CONTENTS, RELOC, READONLY, DEBUGGING
>
> ...rest ommited...
>
> 0x28000210 is address of the beginning of generatedÂ
> machine code.Â
>
> By quick look at jit.c, jit_bfd_try_read_symtab(), line ~ 941
> it looks that gdb only reads / considers .text, .data and .eh_frame
> sections, ignoring the rest including those containing DWARD debugÂ
> info. This confuses me a little, but I have a very little knowledge
> of DWARF / GDB internals.Â
>
> I'd appreciate if anyone can shed a bit of a light into this.Â
> It'd be really cool if I can see source line numbers or even
> print variable names for jitted code from GDB.
>
> Thanks a lot!Â
>
> Best, Jan
>
>
>
>
>
>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-30 19:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-29 22:26 Debugging jitted code Jan Vrany
2016-08-30 19:51 ` Jan Vrany
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox