From 3b2a0cf216646598c8d76c098f1734c9bb5604c7 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Wed, 6 Jul 2011 21:40:17 +0000 Subject: [PATCH] Fix JIT clang-lli regression (unable to read JIT descriptor from memory) 2011-07-06 Paul Pluzhnikov * jit.c (jit_inferior_init): Forward declare. (jit_breakpoint_re_set_internal): Call jit_inferior_init. testsuite/ChangeLog: 2011-07-06 Paul Pluzhnikov * gdb.base/jit-so.exp: New test. * gdb.base/jit-dlmain.c: New file. * gdb.base/jit-main.c: Allow "main" to be elsewhere. --- gdb/ChangeLog | 5 ++ gdb/jit.c | 8 ++ gdb/testsuite/ChangeLog | 6 ++ gdb/testsuite/gdb.base/jit-dlmain.c | 20 +++++ gdb/testsuite/gdb.base/jit-main.c | 6 +- gdb/testsuite/gdb.base/jit-so.exp | 121 ++++++++++++++++++++++++++++ 6 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/jit-dlmain.c create mode 100644 gdb/testsuite/gdb.base/jit-so.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a32302b60a3..1516471e117 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -37,6 +37,11 @@ * reverse.c: Likewise. * s390-tdep.c: Likewise. +2011-07-06 Paul Pluzhnikov + + * jit.c (jit_inferior_init): Forward declare. + (jit_breakpoint_re_set_internal): Call jit_inferior_init. + 2011-07-04 Joel Brobecker * osabi.c (generic_elf_osabi_sniffer): Minor comment reformatting. diff --git a/gdb/jit.c b/gdb/jit.c index be123a542cc..01ac5fa3a0d 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -40,6 +40,9 @@ static const char *const jit_descriptor_name = "__jit_debug_descriptor"; static const struct inferior_data *jit_inferior_data = NULL; +static void +jit_inferior_init (struct gdbarch *gdbarch); + /* Non-zero if we want to see trace of jit level stuff. */ static int jit_debug = 0; @@ -351,6 +354,11 @@ jit_breakpoint_re_set_internal (struct gdbarch *gdbarch, inf_data->breakpoint_addr = SYMBOL_VALUE_ADDRESS (reg_symbol); if (inf_data->breakpoint_addr == 0) return 2; + + /* If we have not read the jit descriptor yet (e.g. because the JITer + itself is in a shared library which just got loaded), do so now. */ + if (inf_data->descriptor_addr == 0) + jit_inferior_init (gdbarch); } else return 0; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 819b0f278d5..6d00d6ccfdf 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -24,6 +24,12 @@ * gdb.base/ifelse.exp: Likewise. * gdb.base/structs.c: Likewise. +2011-07-06 Paul Pluzhnikov + + * gdb.base/jit-so.exp: New test. + * gdb.base/jit-dlmain.c: New file. + * gdb.base/jit-main.c: Allow "main" to be elsewhere. + 2011-07-02 Jan Kratochvil * gdb.cp/m-static.exp: Call get_compiler_info. diff --git a/gdb/testsuite/gdb.base/jit-dlmain.c b/gdb/testsuite/gdb.base/jit-dlmain.c new file mode 100644 index 00000000000..03b8d3cc284 --- /dev/null +++ b/gdb/testsuite/gdb.base/jit-dlmain.c @@ -0,0 +1,20 @@ +#include +#include + +int main (int argc, char *argv[]) +{ + /* jit_libname is updated by jit-so.exp */ + const char *jit_libname = "jit-dlmain-so.so"; + void *h; + int (*p_main) (int, char **); + + h = NULL; /* break here before-dlopen */ + h = dlopen (jit_libname, RTLD_LAZY); + if (h == NULL) return 1; + + p_main = dlsym (h, "jit_dl_main"); + if (p_main == NULL) return 2; + + h = h; /* break here after-dlopen */ + return (*p_main) (argc, argv); +} diff --git a/gdb/testsuite/gdb.base/jit-main.c b/gdb/testsuite/gdb.base/jit-main.c index b20c516b6bc..f5b0ec1b363 100644 --- a/gdb/testsuite/gdb.base/jit-main.c +++ b/gdb/testsuite/gdb.base/jit-main.c @@ -117,8 +117,12 @@ update_locations (const void *const addr, int idx) } } +#ifndef MAIN +#define MAIN main +#endif + int -main (int argc, char *argv[]) +MAIN (int argc, char *argv[]) { /* These variables are here so they can easily be set from jit.exp. */ const char *libname = NULL; diff --git a/gdb/testsuite/gdb.base/jit-so.exp b/gdb/testsuite/gdb.base/jit-so.exp new file mode 100644 index 00000000000..bd0d90813c3 --- /dev/null +++ b/gdb/testsuite/gdb.base/jit-so.exp @@ -0,0 +1,121 @@ +# Copyright 2011 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# The same tests as in jit.exp, but loading JITer itself from a shared +# library. + +if $tracelevel { + strace $tracelevel +} + +if {[skip_shlib_tests]} { + untested jit-so.exp + return -1 +} + +if {[get_compiler_info not-used]} { + warning "Could not get compiler info" + untested jit-so.exp + return 1 +} + +# +# test running programs +# + +set testfile jit-dlmain +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug shlib_load}] != "" } { + untested jit-so.exp + return -1 +} + +set testfile2 jit-main +set srcfile2 ${testfile2}.c +set binfile2 ${objdir}/${subdir}/${testfile2}.so +if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug additional_flags="-DMAIN=jit_dl_main"}] != "" } { + untested jit.exp + return -1 +} + +set solib_testfile "jit-solib" +set solib_srcfile "${srcdir}/${subdir}/${solib_testfile}.c" +set solib_binfile "${objdir}/${subdir}/${solib_testfile}.so" +set solib_binfile_test_msg "OBJDIR/${subdir}/${solib_testfile}.so" + +# Note: compiling without debug info: the library goes through symbol +# renaming by munging on its symbol table, and that wouldn't work for .debug +# sections. Also, output for "info function" changes when debug info is resent. +if { [gdb_compile_shlib ${solib_srcfile} ${solib_binfile} {}] != "" } { + untested jit-so.exp + return -1 +} + +proc one_jit_test {count match_str} { + global verbose testfile srcfile2 binfile2 solib_binfile solib_binfile_test_msg pf_prefix + + set old_pf_prefix $pf_prefix + set pf_prefix "one_jit_test-$count" + + clean_restart $testfile + + # This is just to help debugging when things fail + if {$verbose > 0} { + gdb_test "set debug jit 1" + } + + if { ![runto_main] } { + fail "Can't run to main" + return + } + + gdb_breakpoint [gdb_get_line_number "break here before-dlopen" ] + gdb_continue_to_breakpoint "break here before-dlopen" + # Poke desired values directly into inferior instead of using "set args" + # because "set args" does not work under gdbserver. + gdb_test_no_output "set var jit_libname = \"$binfile2\"" + + gdb_breakpoint [gdb_get_line_number "break here after-dlopen" ] + gdb_continue_to_breakpoint "break here after-dlopen" + + gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 0} $srcfile2]" + gdb_continue_to_breakpoint "break here 0" + + gdb_test_no_output "set var argc = 2" + gdb_test_no_output "set var libname = \"$solib_binfile\"" "set var libname = \"$solib_binfile_test_msg\"" + gdb_test_no_output "set var count = $count" + + gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 1} $srcfile2]" + gdb_continue_to_breakpoint "break here 1" + + gdb_test "info function jit_function" "$match_str" + + # This is just to help debugging when things fail + if {$verbose > 0} { + gdb_test "maintenance print objfiles" + gdb_test "maintenance info break" + } + + gdb_breakpoint "$srcfile2:[gdb_get_line_number {break here 2} $srcfile2]" + gdb_continue_to_breakpoint "break here 2" + # All jit librares must have been unregistered + gdb_test "info function jit_function" \ + "All functions matching regular expression \"jit_function\":" \ + set pf_prefix $old_pf_prefix +} + +one_jit_test 1 "${hex} jit_function_0000" +one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" -- 2.30.2