old-cross-binutils/gdb/testsuite/gdb.compile/compile-ops.exp

425 lines
6.3 KiB
Text
Raw Normal View History

# Copyright 2014-2015 Free Software Foundation, Inc.
the "compile" command This final patch adds the new "compile" command and subcommands, and all the machinery needed to make it work. A shared library supplied by gcc is used for all communications with gcc. Types and most aspects of symbols are provided directly by gdb to the compiler using this library. gdb provides some information about the user's code using plain text. Macros are emitted this way, and DWARF location expressions (and bounds for VLA) are compiled to C code. This hybrid approach was taken because, on the one hand, it is better to provide global declarations and such on demand; but on the other hand, for local variables, translating DWARF location expressions to C was much simpler than exporting a full compiler API to gdb -- the same result, only easier to implement, understand, and debug. In the ordinary mode, the user's expression is wrapped in a dummy function. After compilation, gdb inserts the resulting object code into the inferior, then calls this function. Access to local variables is provided by noting which registers are used by location expressions, and passing a structure of register values into the function. Writes to registers are supported by copying out these values after the function returns. This approach was taken so that we could eventually implement other more interesting features based on this same infrastructure; for example, we're planning to investigate inferior-side breakpoint conditions. gdb/ChangeLog 2014-12-12 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> Tom Tromey <tromey@redhat.com> * NEWS: Update. * symtab.h (struct symbol_computed_ops) <generate_c_location>: New field. * p-lang.c (pascal_language_defn): Update. * opencl-lang.c (opencl_language_defn): Update. * objc-lang.c (objc_language_defn): Update. * m2-lang.c (m2_language_defn): Update. * language.h (struct language_defn) <la_get_compile_instance, la_compute_program>: New fields. * language.c (unknown_language_defn, auto_language_defn) (local_language_defn): Update. * jv-lang.c (java_language_defn): Update. * go-lang.c (go_language_defn): Update. * f-lang.c (f_language_defn): Update. * dwarf2loc.h (dwarf2_compile_property_to_c): Declare. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): New functions. (dwarf2_locexpr_funcs, dwarf2_loclist_funcs): Update. * defs.h (enum compile_i_scope_types): New. (enum command_control_type) <compile_control>: New constant. (struct command_line) <control_u>: New field. * d-lang.c (d_language_defn): Update. * compile/compile.c: New file. * compile/compile-c-support.c: New file. * compile/compile-c-symbols.c: New file. * compile/compile-c-types.c: New file. * compile/compile.h: New file. * compile/compile-internal.h: New file. * compile/compile-loc2c.c: New file. * compile/compile-object-load.c: New file. * compile/compile-object-load.h: New file. * compile/compile-object-run.c: New file. * compile/compile-object-run.h: New file. * cli/cli-script.c (multi_line_command_p, print_command_lines) (execute_control_command, process_next_line) (recurse_read_control_structure): Handle compile_control. * c-lang.h (c_get_compile_context, c_compute_program): Declare. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Update. * ada-lang.c (ada_language_defn): Update. * Makefile.in (SUBDIR_GCC_COMPILE_OBS, SUBDIR_GCC_COMPILE_SRCS): New variables. (SFILES): Add SUBDIR_GCC_COMPILE_SRCS. (HFILES_NO_SRCDIR): Add compile.h. (COMMON_OBS): Add SUBDIR_GCC_COMPILE_OBS. (INIT_FILES): Add SUBDIR_GCC_COMPILE_SRCS. (compile.o, compile-c-types.o, compile-c-symbols.o) (compile-object-load.o, compile-object-run.o, compile-loc2c.o) (compile-c-support.o): New targets. gdb/doc/ChangeLog 2014-12-12 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.texinfo (Altering): Update. (Compiling and Injecting Code): New node. gdb/testsuite/ChangeLog 2014-12-12 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> Tom Tromey <tromey@redhat.com> * configure.ac: Add gdb.compile/. * configure: Regenerate. * gdb.compile/Makefile.in: New file. * gdb.compile/compile-ops.exp: New file. * gdb.compile/compile-ops.c: New file. * gdb.compile/compile-tls.c: New file. * gdb.compile/compile-tls.exp: New file. * gdb.compile/compile-constvar.S: New file. * gdb.compile/compile-constvar.c: New file. * gdb.compile/compile-mod.c: New file. * gdb.compile/compile-nodebug.c: New file. * gdb.compile/compile-setjmp-mod.c: New file. * gdb.compile/compile-setjmp.c: New file. * gdb.compile/compile-setjmp.exp: New file. * gdb.compile/compile-shlib.c: New file. * gdb.compile/compile.c: New file. * gdb.compile/compile.exp: New file. * lib/gdb.exp (skip_compile_feature_tests): New proc.
2014-05-14 20:35:45 +00:00
# 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 <http://www.gnu.org/licenses/>.
# Some coverage testing of DWARF operators for the compiler
# integration.
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
if {![dwarf2_support]} {
return 0
}
standard_testfile .c gdbjit-ops.S
#
# A port of the pr10770.c test code to the DWARF assembler format.
#
set assert_tos_non0 {
bra 3
skip -3
}
set assert_tos_0 [subst {
lit0
eq
$assert_tos_non0
}]
set program [subst {
lit0
nop
$assert_tos_0
lit1
const1u 1
eq
$assert_tos_non0
lit16
const2u 16
eq
$assert_tos_non0
lit31
const4u 31
ne
$assert_tos_0
lit1
neg
const1s -1
eq
$assert_tos_non0
lit16
neg
const2s -16
ne
$assert_tos_0
lit31
const4s -31
neg
ne
$assert_tos_0
lit7
dup
plus_uconst 2
lit9
eq
$assert_tos_non0
lit7
eq
$assert_tos_non0
lit20
lit1
drop
lit20
eq
$assert_tos_non0
lit17
lit19
over
lit17
eq
$assert_tos_non0
lit19
eq
$assert_tos_non0
lit17
eq
$assert_tos_non0
lit1
lit2
lit3
lit4
pick 2
lit2
eq
$assert_tos_non0
lit4
eq
$assert_tos_non0
lit3
eq
$assert_tos_non0
pick 0
lit2
eq
$assert_tos_non0
lit2
eq
$assert_tos_non0
lit1
eq
$assert_tos_non0
lit6
lit12
swap
lit6
eq
$assert_tos_non0
lit12
eq
$assert_tos_non0
lit7
lit8
lit9
rot
lit8
eq
$assert_tos_non0
lit7
eq
$assert_tos_non0
lit9
eq
$assert_tos_non0
lit7
abs
lit7
eq
$assert_tos_non0
const1s -123
abs
const1u 123
eq
$assert_tos_non0
lit3
lit6
and
lit2
eq
$assert_tos_non0
lit3
lit6
or
lit7
eq
$assert_tos_non0
lit17
lit2
minus
lit15
eq
$assert_tos_non0
# Divide is signed truncating toward zero.
const1s -6
const1s -2
div
lit3
eq
$assert_tos_non0
const1s -7
const1s 3
div
const1s -2
eq
$assert_tos_non0
# Modulo is unsigned.
const1s -6
const1s -4
mod
const1s -6
eq
$assert_tos_non0
const1s -6
lit4
mod
lit2
eq
$assert_tos_non0
lit6
const1s -4
mod
lit6
eq
$assert_tos_non0
# Signed modulo can be implemented using 'over over div mul minus'.
const1s -6
const1s -4
over
over
div
mul
minus
const1s -2
eq
$assert_tos_non0
const1s -7
lit3
over
over
div
mul
minus
const1s -1
eq
$assert_tos_non0
lit7
const1s -3
over
over
div
mul
minus
lit1
eq
$assert_tos_non0
lit16
lit31
plus_uconst 1
mul
const2u 512
eq
$assert_tos_non0
lit5
not
lit31
and
lit26
eq
$assert_tos_non0
lit12
lit31
plus
const1u 43
eq
$assert_tos_non0
const1s -6
lit2
plus
const1s -4
eq
$assert_tos_non0
const1s -6
plus_uconst 3
const1s -3
eq
$assert_tos_non0
lit16
lit4
shl
const2u 256
eq
$assert_tos_non0
lit16
lit3
shr
lit2
eq
$assert_tos_non0
const1s -16
lit3
shra
const1s -2
eq
$assert_tos_non0
lit3
lit6
xor
lit5
eq
$assert_tos_non0
lit3
lit6
le
$assert_tos_non0
lit3
lit3
le
$assert_tos_non0
lit6
lit3
le
$assert_tos_0
lit3
lit6
lt
$assert_tos_non0
lit3
lit3
lt
$assert_tos_0
lit6
lit3
lt
$assert_tos_0
lit3
lit6
ge
$assert_tos_0
lit3
lit3
ge
$assert_tos_non0
lit6
lit3
ge
$assert_tos_non0
lit3
lit6
gt
$assert_tos_0
lit3
lit3
gt
$assert_tos_0
lit6
lit3
gt
$assert_tos_non0
const1s -6
lit1
shr
lit0
gt
$assert_tos_non0
const1s -6
lit1
shra
lit0
lt
$assert_tos_non0
# Finally some result.
addr ptr
}]
# Make some DWARF for the test.
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
# Creating a CU with 4-byte addresses lets this test link on both
# 32- and 64-bit machines.
cu { addr_size 4 } {
declare_labels int_label
extern func_start func_end ptr
compile_unit {
{name file1.txt}
{language @DW_LANG_C}
{low_pc func_start addr}
{high_pc func_end addr}
} {
global program
int_label: base_type {
{name int}
{byte_size 4 sdata}
{encoding @DW_ATE_signed}
}
subprogram {
{external 1 flag}
{name func}
{low_pc func_start addr}
{high_pc func_end addr}
} {
formal_parameter {
{name param}
{variable_parameter 1 flag}
{type :$int_label}
{location $program SPECIAL_expr}
}
formal_parameter {
{name optimized_out}
{variable_parameter 1 flag}
{type :$int_label}
}
}
}
}
}
if { [prepare_for_testing ${testfile}.exp ${testfile} \
[list $srcfile $asm_file] {nodebug}] } {
return -1
}
if ![runto func] {
return -1
}
if {[skip_compile_feature_tests]} {
Fix MinGW compilation On Sun, 14 Dec 2014 07:00:28 +0100, Yao Qi wrote: The build on mingw host is broken because mingw has no mkdtemp. ../../../git/gdb/compile/compile.c: In function 'get_compile_file_tempdir': ../../../git/gdb/compile/compile.c:194:3: error: implicit declaration of function 'mkdtemp' [-Werror=implicit-function-declaration] tempdir_name = mkdtemp (tname); ^ ../../../git/gdb/compile/compile.c:194:16: error: assignment makes pointer from integer without a cast [-Werror] tempdir_name = mkdtemp (tname); ^ cc1: all warnings being treated as errors In the end I have managed to test it by Wine myself: $ wine build_win32/gdb/gdb.exe -q build_win32/gdb/gdb.exe -ex start -ex 'compile code 1' -ex 'set confirm no' -ex quit [...] Temporary breakpoint 1, main (argc=1, argv=0x241418) at ../../gdb/gdb.c:29 29 args.argc = argc; Could not load libcc1.so: Module not found. Even if it managed to load libcc1.so (it needs host-dependent name libcc1.dll) then it would soon end up at least on: default_infcall_mmap: error (_("This target does not support inferior memory allocation by mmap.")); As currently there is only: linux-tdep.c: set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap); While one could debug Linux targets from MS-Windows host I find it somehow overcomplicated now when we are trying to get it running at least on native Linux x86*. The 'compile' project needs a larger port effort to run on MS-Windows. gdb/ChangeLog 2014-12-17 Jan Kratochvil <jan.kratochvil@redhat.com> Fix MinGW compilation. * compile/compile.c (get_compile_file_tempdir): Call error if !HAVE_MKDTEMP. * config.in: Regenerate. * configure: Regenerate. * configure.ac (AC_CHECK_FUNCS): Add mkdtemp. gdb/testsuite/ChangeLog 2014-12-17 Jan Kratochvil <jan.kratochvil@redhat.com> Fix MinGW compilation. * gdb.compile/compile-ops.exp: Update untested message if !skip_compile_feature_tests. * gdb.compile/compile-setjmp.exp: Likewise. * gdb.compile/compile-tls.exp: Likewise. * gdb.compile/compile.exp: Likewise. * lib/gdb.exp (skip_compile_feature_tests): Check also "Command not supported on this host".
2014-12-17 19:09:02 +00:00
untested "compile command not supported (could not find libcc1 shared library?)"
the "compile" command This final patch adds the new "compile" command and subcommands, and all the machinery needed to make it work. A shared library supplied by gcc is used for all communications with gcc. Types and most aspects of symbols are provided directly by gdb to the compiler using this library. gdb provides some information about the user's code using plain text. Macros are emitted this way, and DWARF location expressions (and bounds for VLA) are compiled to C code. This hybrid approach was taken because, on the one hand, it is better to provide global declarations and such on demand; but on the other hand, for local variables, translating DWARF location expressions to C was much simpler than exporting a full compiler API to gdb -- the same result, only easier to implement, understand, and debug. In the ordinary mode, the user's expression is wrapped in a dummy function. After compilation, gdb inserts the resulting object code into the inferior, then calls this function. Access to local variables is provided by noting which registers are used by location expressions, and passing a structure of register values into the function. Writes to registers are supported by copying out these values after the function returns. This approach was taken so that we could eventually implement other more interesting features based on this same infrastructure; for example, we're planning to investigate inferior-side breakpoint conditions. gdb/ChangeLog 2014-12-12 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> Tom Tromey <tromey@redhat.com> * NEWS: Update. * symtab.h (struct symbol_computed_ops) <generate_c_location>: New field. * p-lang.c (pascal_language_defn): Update. * opencl-lang.c (opencl_language_defn): Update. * objc-lang.c (objc_language_defn): Update. * m2-lang.c (m2_language_defn): Update. * language.h (struct language_defn) <la_get_compile_instance, la_compute_program>: New fields. * language.c (unknown_language_defn, auto_language_defn) (local_language_defn): Update. * jv-lang.c (java_language_defn): Update. * go-lang.c (go_language_defn): Update. * f-lang.c (f_language_defn): Update. * dwarf2loc.h (dwarf2_compile_property_to_c): Declare. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): New functions. (dwarf2_locexpr_funcs, dwarf2_loclist_funcs): Update. * defs.h (enum compile_i_scope_types): New. (enum command_control_type) <compile_control>: New constant. (struct command_line) <control_u>: New field. * d-lang.c (d_language_defn): Update. * compile/compile.c: New file. * compile/compile-c-support.c: New file. * compile/compile-c-symbols.c: New file. * compile/compile-c-types.c: New file. * compile/compile.h: New file. * compile/compile-internal.h: New file. * compile/compile-loc2c.c: New file. * compile/compile-object-load.c: New file. * compile/compile-object-load.h: New file. * compile/compile-object-run.c: New file. * compile/compile-object-run.h: New file. * cli/cli-script.c (multi_line_command_p, print_command_lines) (execute_control_command, process_next_line) (recurse_read_control_structure): Handle compile_control. * c-lang.h (c_get_compile_context, c_compute_program): Declare. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Update. * ada-lang.c (ada_language_defn): Update. * Makefile.in (SUBDIR_GCC_COMPILE_OBS, SUBDIR_GCC_COMPILE_SRCS): New variables. (SFILES): Add SUBDIR_GCC_COMPILE_SRCS. (HFILES_NO_SRCDIR): Add compile.h. (COMMON_OBS): Add SUBDIR_GCC_COMPILE_OBS. (INIT_FILES): Add SUBDIR_GCC_COMPILE_SRCS. (compile.o, compile-c-types.o, compile-c-symbols.o) (compile-object-load.o, compile-object-run.o, compile-loc2c.o) (compile-c-support.o): New targets. gdb/doc/ChangeLog 2014-12-12 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.texinfo (Altering): Update. (Compiling and Injecting Code): New node. gdb/testsuite/ChangeLog 2014-12-12 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> Tom Tromey <tromey@redhat.com> * configure.ac: Add gdb.compile/. * configure: Regenerate. * gdb.compile/Makefile.in: New file. * gdb.compile/compile-ops.exp: New file. * gdb.compile/compile-ops.c: New file. * gdb.compile/compile-tls.c: New file. * gdb.compile/compile-tls.exp: New file. * gdb.compile/compile-constvar.S: New file. * gdb.compile/compile-constvar.c: New file. * gdb.compile/compile-mod.c: New file. * gdb.compile/compile-nodebug.c: New file. * gdb.compile/compile-setjmp-mod.c: New file. * gdb.compile/compile-setjmp.c: New file. * gdb.compile/compile-setjmp.exp: New file. * gdb.compile/compile-shlib.c: New file. * gdb.compile/compile.c: New file. * gdb.compile/compile.exp: New file. * lib/gdb.exp (skip_compile_feature_tests): New proc.
2014-05-14 20:35:45 +00:00
return -1
}
# If we have a bug, this will hang.
gdb_test_no_output "compile code param"
# We can't access optimized-out variables, but their presence should
# not affect compilations that don't refer to them.
gdb_test "compile code optimized_out" \
".*optimized out.*Compilation failed."