JIT Interface - Issues and testing approach

Tony Simpson agjasimpson@gmail.com
Tue Feb 2 21:45:00 GMT 2016


Hi All,

I've been having some issues with the JIT interface
[https://sourceware.org/gdb/onlinedocs/gdb/JIT-Interface.html]

I need to do a lot of debugging of a Python JIT I'm working on so I
wrote a plugin using the Hook API and symbol API in <gdb/jit-reader.h>
but it doesn't work, specifically (but not extensively):

Pending breakpoints on JIT functions don't trigger;
Pending breakpoints on JIT file:line don't get triggered;
Break points on JIT file:line work after symbols is registered but are
a bit weird (sorry I don't understand what's going on well enough);
The unwind and get frame id functions are never called.

I'm not certain this isn't just the limits of my understanding but one
or all of the following are true, the documentation is insufficient,
the implementation doesn't work.

I tried testing with earlier versions, on 7.4 unwind was called but
all the time which is probably not the right behaviour either, so I
think there has been some regression.

I looked at the existing tests, I'm not comfortable with TCL but it
seems to me that jit-simple.exp is not correctly testing what it says
- claims to test that symbols that move after recompilation are
updated when inferior is rerun.  but it does not assert that the
symbols move and on my system they do not - so not really testing
anything, I find it difficult to workout what the other 2 jit*.exp
tests are doing but I don't think they are testing breakpoints in
JIT'd code, I could be mistaken.

I tried to put together a testcase but I'm not sure my approach is
correct, I've attached the patch - it adds files
gdb/testsuite/gdb.base/jit-fake*.* - I tried using a function as a
surrogate for JIT'd code - I thought it would be easier to maintain
than architecture specific machine code but I worry that it will cause
unrealistic conditions within GDB and also I don't know if GDB is
expected to build on compilers other than gcc which don't have label
pointers?

I'd really appreciate code review or ideas on a better approach or any feedback.

Follows is gdb session testing jit-fake and patch attached, Thanks, Tony

 [tsimpson@mmpc001 gdb.base]$ ~/opt/gdb32/bin/gdb --args  ./jit-fake
GNU gdb (GDB) 7.10.50.20160201-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./jit-fake...done.
(gdb) set breakpoint pending on
(gdb) jit-reader-load
/home/tsimpson/work/binutils-gdb/gdb/testsuite/gdb.base/jit-fake-reader.so
(gdb) break fakefile.c:5
No source file named fakefile.c.
Breakpoint 1 (fakefile.c:5) pending.
(gdb) break fake_function
Function "fake_function" not defined.
Breakpoint 2 (fake_function) pending.
(gdb) info breakpoints
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   <PENDING>  fakefile.c:5
2       breakpoint     keep y   <PENDING>  fake_function
(gdb) break main
Breakpoint 3 at 0x80486a4: file jit-fake.c, line 93.
(gdb) r
Starting program:
/home/tsimpson/work/binutils-gdb/gdb/testsuite/gdb.base/jit-fake

Breakpoint 3, main (argc=1, argv=0xffffdc34) at jit-fake.c:93
93    register_fake("fakefile.c", "fake_function", 1, 7, jit_code_fake());
(gdb) n
JIT-FAKE: jit_code_fake line_1
JIT-FAKE: jit_code_fake line_2
JIT-FAKE: jit_code_fake line_3
JIT-FAKE: jit_code_fake line_4
JIT-FAKE: jit_code_fake line_5
JIT-FAKE: jit_code_fake line_6
JIT-FAKE: jit_code_fake line_7
jit-fake-reader: jit_reader_read_debug_info being called
jit-fake-reader: open symtab for fakefile.c
jit-fake-reader: open block for fake_function 0x8048491->0x804852d
jit-fake-reader: line mapping 1 = 0x8048491
jit-fake-reader: line mapping 2 = 0x80484ab
jit-fake-reader: line mapping 3 = 0x80484c5
jit-fake-reader: line mapping 4 = 0x80484df
jit-fake-reader: line mapping 5 = 0x80484f9
jit-fake-reader: line mapping 6 = 0x8048513
jit-fake-reader: line mapping 7 = 0x804852d
jit-fake-reader: closing symtab
jit-fake-reader: closing object
jit-fake-reader: jit_reader_read_debug_info returning GDB_SUCCESS
94    jit_code_fake();
(gdb) info breakpoints
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   <PENDING>  fakefile.c:5
2       breakpoint     keep y   <PENDING>  fake_function
3       breakpoint     keep y   0x080486a4 in main at jit-fake.c:93
breakpoint already hit 1 time
(gdb) break fakefile.c:5
Breakpoint 4 at 0x80484f9: file fakefile.c, line 5.
(gdb) info breakpoints
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   <PENDING>  fakefile.c:5
2       breakpoint     keep y   <PENDING>  fake_function
3       breakpoint     keep y   0x080486a4 in main at jit-fake.c:93
breakpoint already hit 1 time
4       breakpoint     keep y   0x080484f9 in fake_function at fakefile.c:5
(gdb) n
JIT-FAKE: jit_code_fake line_1
JIT-FAKE: jit_code_fake line_2
JIT-FAKE: jit_code_fake line_3
JIT-FAKE: jit_code_fake line_4

Breakpoint 4, fake_function () at fakefile.c:5
5 fakefile.c: No such file or directory.
(gdb) n
JIT-FAKE: jit_code_fake line_5
6 in fakefile.c
(gdb) n
JIT-FAKE: jit_code_fake line_6
0x0804852d in jit_code_fake ()
(gdb) n
Single stepping until exit from function jit_code_fake,
which has no line number information.
JIT-FAKE: jit_code_fake line_7
main (argc=1, argv=0xffffdc34) at jit-fake.c:95
95    jit_code_fake();
(gdb) n
JIT-FAKE: jit_code_fake line_1
JIT-FAKE: jit_code_fake line_2
JIT-FAKE: jit_code_fake line_3
JIT-FAKE: jit_code_fake line_4

Breakpoint 4, fake_function () at fakefile.c:5
5 fakefile.c: No such file or directory.
(gdb) c
Continuing.
JIT-FAKE: jit_code_fake line_5
JIT-FAKE: jit_code_fake line_6
JIT-FAKE: jit_code_fake line_7
JIT-FAKE: jit_code_fake line_1
JIT-FAKE: jit_code_fake line_2
JIT-FAKE: jit_code_fake line_3
JIT-FAKE: jit_code_fake line_4

Breakpoint 4, fake_function () at fakefile.c:5
5 in fakefile.c
(gdb) c
Continuing.
JIT-FAKE: jit_code_fake line_5
JIT-FAKE: jit_code_fake line_6
JIT-FAKE: jit_code_fake line_7
[Inferior 1 (process 14370) exited normally]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jit-fake.patch
Type: text/x-patch
Size: 8961 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb/attachments/20160202/a2b45373/attachment.bin>


More information about the Gdb mailing list