aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.compile
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2014-05-14 14:35:45 -0600
committerJan Kratochvil <jan.kratochvil@redhat.com>2014-12-12 22:28:44 +0100
commitbb2ec1b34e7cc8d8602512235016e74b800dac3b (patch)
tree6fb368ff4d35c37a24d434d5d7348d8dd8850ca7 /gdb/testsuite/gdb.compile
parenta2658febe2016f875ffb70287904b01013bcca75 (diff)
downloadgdb-bb2ec1b34e7cc8d8602512235016e74b800dac3b.zip
gdb-bb2ec1b34e7cc8d8602512235016e74b800dac3b.tar.gz
gdb-bb2ec1b34e7cc8d8602512235016e74b800dac3b.tar.bz2
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.
Diffstat (limited to 'gdb/testsuite/gdb.compile')
-rw-r--r--gdb/testsuite/gdb.compile/Makefile.in21
-rw-r--r--gdb/testsuite/gdb.compile/compile-constvar.S95
-rw-r--r--gdb/testsuite/gdb.compile/compile-constvar.c18
-rw-r--r--gdb/testsuite/gdb.compile/compile-mod.c26
-rw-r--r--gdb/testsuite/gdb.compile/compile-nodebug.c24
-rw-r--r--gdb/testsuite/gdb.compile/compile-ops.c37
-rw-r--r--gdb/testsuite/gdb.compile/compile-ops.exp424
-rw-r--r--gdb/testsuite/gdb.compile/compile-setjmp-mod.c46
-rw-r--r--gdb/testsuite/gdb.compile/compile-setjmp.c24
-rw-r--r--gdb/testsuite/gdb.compile/compile-setjmp.exp34
-rw-r--r--gdb/testsuite/gdb.compile/compile-shlib.c26
-rw-r--r--gdb/testsuite/gdb.compile/compile-tls.c40
-rw-r--r--gdb/testsuite/gdb.compile/compile-tls.exp42
-rw-r--r--gdb/testsuite/gdb.compile/compile.c130
-rw-r--r--gdb/testsuite/gdb.compile/compile.exp357
15 files changed, 1344 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.compile/Makefile.in b/gdb/testsuite/gdb.compile/Makefile.in
new file mode 100644
index 0000000..6a1a895
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/Makefile.in
@@ -0,0 +1,21 @@
+VPATH = @srcdir@
+srcdir = @srcdir@
+
+EXECUTABLES = \
+ chan handcall hello integers methods package \
+ strings types unsafe
+
+all info install-info dvi install uninstall installcheck check:
+ @echo "Nothing to be done for $@..."
+
+clean mostlyclean:
+ -find . -name '*.o' -print | xargs rm -f
+ -find . -name '*.ali' -print | xargs rm -f
+ -rm -f *~ a.out
+ -rm -f *.dwo *.dwp
+ -rm -f core core.coremaker coremaker.core corefile $(EXECUTABLES)
+
+distclean maintainer-clean realclean: clean
+ -rm -f Makefile config.status config.log
+ -rm -f *-init.exp gdb.log gdb.sum
+ -rm -fr *.log summary detail *.plog *.sum *.psum site.*
diff --git a/gdb/testsuite/gdb.compile/compile-constvar.S b/gdb/testsuite/gdb.compile/compile-constvar.S
new file mode 100644
index 0000000..55d81bc
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-constvar.S
@@ -0,0 +1,95 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+// gcc -o gdb.base/compile-constvar.S -dA -S -g gdb.base/compile-constvar.c
+
+ .file "compile-constvar.c"
+ .file 1 "gdb.base/compile-constvar.c"
+ .section .debug_info,"",@progbits
+.Ldebug_info0:
+ .long .Lend-.Lstart # Length of Compilation Unit Info
+.Lstart:
+ .value 0x4 # DWARF version number
+ .long .Ldebug_abbrev0 # Offset Into Abbrev. Section
+ .byte 0x8 # Pointer Size (in bytes)
+ .uleb128 0x1 # (DIE (0xb) DW_TAG_compile_unit)
+ .long .LASF0 # DW_AT_producer: "GNU C 4.8.2 20131212 (Red Hat 4.8.2-7) -mtune=generic -march=x86-64 -g"
+ .byte 0x1 # DW_AT_language
+ .long .LASF1 # DW_AT_name: "gdb.base/compile-constvar.c"
+ .long .LASF2 # DW_AT_comp_dir: "/home/jkratoch/redhat/gdb-gdbjit/gdb/testsuite"
+ .uleb128 0x2 # (DIE (0x1d) DW_TAG_variable)
+ .long .LASF3 # DW_AT_name: "constvar"
+ .long .Linttype-.Ldebug_info0 # DW_AT_type
+ # DW_AT_external
+ .byte 0x3 # DW_AT_const_value
+.Linttype:
+ .uleb128 0x3 # (DIE (0x32) DW_TAG_base_type)
+ .byte 0x4 # DW_AT_byte_size
+ .byte 0x5 # DW_AT_encoding
+ .ascii "int\0" # DW_AT_name
+ .byte 0 # end of children of DIE 0xb
+.Lend:
+ .section .debug_abbrev,"",@progbits
+.Ldebug_abbrev0:
+ .uleb128 0x1 # (abbrev code)
+ .uleb128 0x11 # (TAG: DW_TAG_compile_unit)
+ .byte 0x1 # DW_children_yes
+ .uleb128 0x25 # (DW_AT_producer)
+ .uleb128 0xe # (DW_FORM_strp)
+ .uleb128 0x13 # (DW_AT_language)
+ .uleb128 0xb # (DW_FORM_data1)
+ .uleb128 0x3 # (DW_AT_name)
+ .uleb128 0xe # (DW_FORM_strp)
+ .uleb128 0x1b # (DW_AT_comp_dir)
+ .uleb128 0xe # (DW_FORM_strp)
+ .byte 0
+ .byte 0
+ .uleb128 0x2 # (abbrev code)
+ .uleb128 0x34 # (TAG: DW_TAG_variable)
+ .byte 0 # DW_children_no
+ .uleb128 0x3 # (DW_AT_name)
+ .uleb128 0xe # (DW_FORM_strp)
+ .uleb128 0x49 # (DW_AT_type)
+ .uleb128 0x13 # (DW_FORM_ref4)
+ .uleb128 0x3f # (DW_AT_external)
+ .uleb128 0x19 # (DW_FORM_flag_present)
+ .uleb128 0x1c # (DW_AT_const_value)
+ .uleb128 0xb # (DW_FORM_data1)
+ .byte 0
+ .byte 0
+ .uleb128 0x3 # (abbrev code)
+ .uleb128 0x24 # (TAG: DW_TAG_base_type)
+ .byte 0 # DW_children_no
+ .uleb128 0xb # (DW_AT_byte_size)
+ .uleb128 0xb # (DW_FORM_data1)
+ .uleb128 0x3e # (DW_AT_encoding)
+ .uleb128 0xb # (DW_FORM_data1)
+ .uleb128 0x3 # (DW_AT_name)
+ .uleb128 0x8 # (DW_FORM_string)
+ .byte 0
+ .byte 0
+ .byte 0
+ .section .debug_str,"MS",@progbits,1
+.LASF1:
+ .string "gdb.base/compile-constvar.c"
+.LASF3:
+ .string "constvar"
+.LASF2:
+ .string ""
+.LASF0:
+ .string "GNU C 4.8.2 20131212 (Red Hat 4.8.2-7) -mtune=generic -march=x86-64 -g"
+ .ident "GCC: (GNU) 4.8.2 20131212 (Red Hat 4.8.2-7)"
diff --git a/gdb/testsuite/gdb.compile/compile-constvar.c b/gdb/testsuite/gdb.compile/compile-constvar.c
new file mode 100644
index 0000000..3820b43
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-constvar.c
@@ -0,0 +1,18 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+int constvar = 5;
diff --git a/gdb/testsuite/gdb.compile/compile-mod.c b/gdb/testsuite/gdb.compile/compile-mod.c
new file mode 100644
index 0000000..a6dbc32
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-mod.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+// Make 'globalvar' lookup working.
+#pragma GCC user_expression
+
+void
+_gdb_expr (void)
+{
+ globalvar = 3;
+ globalvar += 4;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-nodebug.c b/gdb/testsuite/gdb.compile/compile-nodebug.c
new file mode 100644
index 0000000..4cc8bb3
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-nodebug.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+int
+func_nodebug (int neg)
+{
+ return -neg;
+}
+
+int unresolved = 20;
diff --git a/gdb/testsuite/gdb.compile/compile-ops.c b/gdb/testsuite/gdb.compile/compile-ops.c
new file mode 100644
index 0000000..4474814
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-ops.c
@@ -0,0 +1,37 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2011-2014 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 <http://www.gnu.org/licenses/>. */
+
+int value = 0xdeadf00d;
+int *ptr = &value;
+
+asm (".section \".text\"");
+asm (".balign 8");
+asm ("func_start: .globl func_start");
+
+static void
+func (void)
+{
+}
+
+asm ("func_end: .globl func_end");
+
+int
+main (void)
+{
+ func ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-ops.exp b/gdb/testsuite/gdb.compile/compile-ops.exp
new file mode 100644
index 0000000..c295836
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-ops.exp
@@ -0,0 +1,424 @@
+# Copyright 2014 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 <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]} {
+ untested "could not find libcc1 shared library"
+ 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."
diff --git a/gdb/testsuite/gdb.compile/compile-setjmp-mod.c b/gdb/testsuite/gdb.compile/compile-setjmp-mod.c
new file mode 100644
index 0000000..8a1c413
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-setjmp-mod.c
@@ -0,0 +1,46 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+// Make 'done' lookup working.
+#pragma GCC user_expression
+
+static void
+foo ()
+{
+ jmp_buf env;
+
+ switch (setjmp (env))
+ {
+ case 2:
+ done = 1;
+ return;
+ case 0:
+ longjmp (env, 2);
+ break;
+ }
+ abort ();
+}
+
+void
+_gdb_expr (void)
+{
+ foo ();
+}
diff --git a/gdb/testsuite/gdb.compile/compile-setjmp.c b/gdb/testsuite/gdb.compile/compile-setjmp.c
new file mode 100644
index 0000000..c462f48
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-setjmp.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+static int done;
+
+int
+main (void)
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-setjmp.exp b/gdb/testsuite/gdb.compile/compile-setjmp.exp
new file mode 100644
index 0000000..557c1f0
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-setjmp.exp
@@ -0,0 +1,34 @@
+# Copyright 2014 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 <http://www.gnu.org/licenses/>.
+
+standard_testfile .c compile-setjmp-mod.c
+
+if { [prepare_for_testing ${testfile}.exp $testfile] } {
+ return -1
+}
+
+if ![runto_main] {
+ return -1
+}
+
+if {[skip_compile_feature_tests]} {
+ untested "could not find libcc1 shared library"
+ return -1
+}
+
+gdb_test_no_output "compile file -r ${srcdir}/${subdir}/$srcfile2" \
+ "compile file -r"
+
+gdb_test "p done" " = 1"
diff --git a/gdb/testsuite/gdb.compile/compile-shlib.c b/gdb/testsuite/gdb.compile/compile-shlib.c
new file mode 100644
index 0000000..6181af2
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-shlib.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+extern int globalvar;
+
+int shlibvar = 10;
+
+void
+shlib_func (void)
+{
+ globalvar = 1;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-tls.c b/gdb/testsuite/gdb.compile/compile-tls.c
new file mode 100644
index 0000000..6e08a30
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-tls.c
@@ -0,0 +1,40 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+#include <pthread.h>
+
+__thread int global_scope;
+
+static __thread int static_scope;
+
+int foo ()
+{
+ /* Ensure we link against pthreads even with --as-needed. */
+ pthread_testcancel();
+ return 27;
+}
+
+int
+main (void)
+{
+ static __thread int local_scope;
+
+ /* break-here */
+ foo ();
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.compile/compile-tls.exp b/gdb/testsuite/gdb.compile/compile-tls.exp
new file mode 100644
index 0000000..e9613f5
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile-tls.exp
@@ -0,0 +1,42 @@
+# Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+standard_testfile .c
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
+ executable {debug}] != "" } {
+ return -1
+}
+
+clean_restart ${binfile}
+if ![runto_main] then {
+ fail "Can't run to main"
+ return 0
+}
+
+if {[skip_compile_feature_tests]} {
+ untested "could not find libcc1 shared library"
+ return -1
+}
+
+gdb_test "compile code local_scope = 1" \
+ "warning: .* compiled code."
+gdb_test "print local_scope" " = 1"
+gdb_test "compile code static_scope = 2" \
+ "warning: .* compiled code."
+gdb_test "print static_scope" " = 2"
+gdb_test "compile code global_scope = 3" \
+ "warning: .* compiled code."
+gdb_test "print global_scope" " = 3"
diff --git a/gdb/testsuite/gdb.compile/compile.c b/gdb/testsuite/gdb.compile/compile.c
new file mode 100644
index 0000000..b48acab
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile.c
@@ -0,0 +1,130 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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 <http://www.gnu.org/licenses/>. */
+
+#define SOME_MACRO 23
+#define ARG_MACRO(X, Y) ((X) + (Y) - 1)
+
+
+enum enum_type {
+ ONE = 1,
+ TWO = 2
+};
+
+typedef int v4 __attribute__ ((vector_size (16)));
+
+union union_type;
+
+struct struct_type {
+ char charfield;
+ unsigned char ucharfield;
+ short shortfield;
+ unsigned short ushortfield;
+ int intfield;
+ unsigned int uintfield;
+ unsigned int bitfield : 3;
+ long longfield;
+ unsigned long ulongfield;
+ enum enum_type enumfield;
+ float floatfield;
+ double doublefield;
+ const union union_type *ptrfield;
+ struct struct_type *selffield;
+ int arrayfield[5];
+ _Complex double complexfield;
+ _Bool boolfield;
+ v4 vectorfield;
+};
+
+typedef int inttypedef;
+
+union union_type {
+ int intfield;
+ inttypedef typedeffield;
+};
+
+/* volatile provides some coverage of the conversion code. */
+volatile struct struct_type struct_object;
+
+union union_type union_object;
+
+
+enum ulonger_enum_type {
+ REALLY_MINUS_1 = -1UL,
+};
+
+enum ulonger_enum_type ulonger;
+
+enum longer_enum_type {
+ MINUS_1 = -1,
+ FORCE_TO_LONG = 1L << ((8 * sizeof (long)) - 2)
+};
+
+enum longer_enum_type longer;
+
+int globalvar = 10;
+
+static void
+func_static (int addend)
+{
+ globalvar += addend;
+}
+
+void
+func_global (int subtrahend)
+{
+ globalvar -= subtrahend;
+}
+
+void
+no_args_or_locals (void)
+{
+ /* no_args_or_locals breakpoint */
+}
+
+int *intptr;
+int globalshadow = 10;
+static int staticshadow = 20;
+int externed = 7;
+
+int
+main (void)
+{
+ int localvar = 50;
+ int shadowed = 51;
+ int bound = 3;
+ int unresolved = 10;
+ int globalshadow = 100;
+ int staticshadow = 200;
+ int externed = 9;
+ int f = 0;
+
+ static int static_local = 77000;
+
+ {
+ int another_local = 7;
+ int shadowed = 52;
+ extern int unresolved;
+ extern int externed;
+
+ int vla[bound];
+
+ func_static (0); /* break-here */
+ no_args_or_locals ();
+ }
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp
new file mode 100644
index 0000000..d0dd791
--- /dev/null
+++ b/gdb/testsuite/gdb.compile/compile.exp
@@ -0,0 +1,357 @@
+# Copyright 2014 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 <http://www.gnu.org/licenses/>.
+
+standard_testfile .c compile-shlib.c compile-constvar.S compile-nodebug.c
+
+get_compiler_info
+set options {}
+if [test_compiler_info gcc*] {
+ lappend options additional_flags=-g3
+}
+
+if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
+ verbose "Skipping x86_64 LOC_CONST test."
+ set srcfile3 ""
+}
+
+set srcfilesoptions [list ${srcfile} ${options}]
+if { $srcfile3 != "" } {
+ lappend srcfilesoptions $srcfile3 ${options}
+}
+lappend srcfilesoptions $srcfile4 "nodebug"
+if { [eval build_executable_from_specs ${testfile}.exp $testfile {$options} ${srcfilesoptions}] } {
+ return -1
+}
+
+clean_restart ${testfile}
+
+#
+# Test command without an running inferior.
+#
+gdb_test "compile code int i=2;" \
+ "The program must be running for the compile command to work.*" \
+ "Test compile code command without running inferior"
+
+gdb_test "compile int i=2;" \
+ "The program must be running for the compile command to work.*" \
+ "Test compile command without running inferior"
+
+gdb_test "compile file -r ${srcdir}/${subdir}/${testfile}-mod.c" \
+ "The program must be running for the compile command to work.*" \
+ "Test compile file command without running inferior"
+
+if ![runto_main] {
+ return -1
+}
+
+if {[skip_compile_feature_tests]} {
+ untested "could not find libcc1 shared library"
+ return -1
+}
+
+#
+# Test delimiter for code, and arguments.
+#
+
+gdb_test_no_output "compile -- f = 10" \
+ "Test abbreviations and code delimiter"
+
+gdb_test "compile f = 10;" ".*= 10;: No such file.*" \
+ "Test abbreviations and code collision"
+
+gdb_test_no_output "compile -r -- _gdb_expr(){int i = 5;}" \
+ "Test delimiter with -r"
+
+gdb_test_no_output "compile -raw -- _gdb_expr(){int i = 5;}" \
+ "Test delimiter with -raw"
+
+gdb_test "compile -- -r _gdb_expr(){int i = 5;}" \
+ ".* error: 'r' undeclared \\(first use in this function\\).*" \
+ "Test delimiter with -r after it"
+
+gdb_test "p globalvar" " = 10" "expect 10"
+
+gdb_test_no_output "compile code globalvar = 11" \
+ "set variable without trailing semicolon"
+gdb_test "p globalvar" " = 11" "check variable without trailing semicolon"
+
+gdb_test_no_output "compile code globalvar = SOME_MACRO;" \
+ "set variable from macro"
+gdb_test "p globalvar" " = 23" "expect 23"
+
+gdb_test_no_output "compile code globalvar = ARG_MACRO(0, 0);" \
+ "set variable from function-like macro"
+gdb_test "p globalvar" " = -1" "expect -1"
+
+gdb_test_no_output "compile code globalvar = 42;" "set variable"
+gdb_test "p globalvar" " = 42" "expect 42"
+
+gdb_test_no_output "compile code globalvar *= 2;" "modify variable"
+gdb_test "p globalvar" " = 84" "expect 84"
+
+gdb_test_multiple "compile code" "compile code multiline 1" { -re "\r\n>$" {} }
+gdb_test_multiple "globalvar = 10;" "compile code multiline 2" { -re "\r\n>$" {} }
+gdb_test_multiple "globalvar *= 2;" "compile code multiline 3" { -re "\r\n>$" {} }
+gdb_test_no_output "end" "compile code multiline 4"
+gdb_test "p globalvar" " = 20" "expect 20"
+
+gdb_test_no_output "compile file -r ${srcdir}/${subdir}/${testfile}-mod.c" \
+ "use external source file"
+gdb_test "p globalvar" " = 7" "expect 7"
+
+gdb_test_no_output "compile code func_static (2);" "call static function"
+gdb_test "p globalvar" " = 9" "expect 9"
+gdb_test_no_output "compile code func_global (1);" "call global function"
+gdb_test "p globalvar" " = 8" "expect 8"
+
+gdb_test_no_output \
+ "compile code globalvar = (sizeof (ulonger) == sizeof (long))" \
+ "compute size of ulonger"
+gdb_test "p globalvar" " = 1" "check size of ulonger"
+gdb_test_no_output \
+ "compile code globalvar = (sizeof (longer) == sizeof (long))" \
+ "compute size of longer"
+gdb_test "p globalvar" " = 1" "check size of longer"
+gdb_test_no_output "compile code globalvar = MINUS_1"
+gdb_test "p globalvar" " = -1" "check MINUS_1"
+
+gdb_test_no_output "compile code globalvar = static_local"
+gdb_test "p globalvar" " = 77000" "check static_local"
+
+gdb_test_no_output "compile code static int staticvar = 5; intptr = &staticvar" \
+ "keep jit in memory"
+gdb_test "p *intptr" " = 5" "expect 5"
+
+gdb_test "compile code func_doesnotexist ();" "warning: Could not find symbol \"func_doesnotexist\" for .*"
+
+gdb_test "compile code *(volatile int *) 0 = 0;" \
+ "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB remains in the frame where the signal was received\\.\r\n.*" \
+ "compile code segfault first"
+gdb_test "bt" \
+ "\r\n#0 \[^\r\n\]* in _gdb_expr \[^\r\n\]*\r\n#1 <function called from gdb>\r\n.*"
+
+set test "p/x \$pc"
+set infcall_pc 0
+gdb_test_multiple $test $test {
+ -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
+ set infcall_pc $expect_out(1,string)
+ pass $test
+ }
+}
+
+gdb_test "info sym $infcall_pc" "\r\n_gdb_expr .*" "info sym found"
+gdb_test "return" "\r\n#0 main .*" "return" \
+ "Make _gdb_expr return now\\? \\(y or n\\) " "y"
+gdb_test "info sym $infcall_pc" "\r\nNo symbol matches .*" "info sym not found"
+
+gdb_test_no_output "set unwindonsignal on"
+gdb_test "compile code *(volatile int *) 0 = 0;" \
+ "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB has restored the context to what it was before the call\\.\r\n.*" \
+ "compile code segfault second"
+
+gdb_breakpoint [gdb_get_line_number "break-here"]
+gdb_continue_to_breakpoint "break-here" ".* break-here .*"
+
+gdb_test "p localvar" " = 50" "expect localvar 50"
+
+gdb_test_no_output "compile code localvar = 12;" "set localvar"
+gdb_test "p localvar" " = 12" "expect 12"
+
+gdb_test_no_output "compile code localvar *= 2;" "modify localvar"
+gdb_test "p localvar" " = 24" "expect 24"
+
+gdb_test_no_output "compile code localvar = shadowed" \
+ "test shadowing"
+gdb_test "p localvar" " = 52" "expect 52"
+
+gdb_test_no_output "compile code localvar = externed"
+gdb_test "p localvar" " = 7" "test extern in inner scope"
+
+gdb_test_no_output "compile code vla\[2\] = 7"
+gdb_test "p vla\[2\]" " = 7"
+gdb_test_no_output \
+ "compile code localvar = (sizeof (vla) == bound * sizeof (vla\[0\]))"
+gdb_test "p localvar" " = 1"
+
+#
+# Test setting fields and also many different types.
+#
+
+gdb_test_no_output "compile code struct_object.selffield = &struct_object"
+gdb_test "print struct_object.selffield == &struct_object" " = 1"
+
+gdb_test_no_output "compile code struct_object.charfield = 1"
+gdb_test "print struct_object.charfield" " = 1 '\\\\001'"
+gdb_test_no_output "compile code struct_object.ucharfield = 1"
+gdb_test "print struct_object.ucharfield" " = 1 '\\\\001'"
+
+foreach {field value} {
+ shortfield -5
+ ushortfield 5
+ intfield -7
+ uintfield 7
+ bitfield 2
+ longfield -9
+ ulongfield 9
+ enumfield ONE
+ floatfield 1
+ doublefield 2
+} {
+ gdb_test_no_output "compile code struct_object.$field = $value"
+ gdb_test "print struct_object.$field" " = $value"
+}
+
+gdb_test_no_output "compile code struct_object.arrayfield\[2\] = 7"
+gdb_test "print struct_object.arrayfield" \
+ " = \\{0, 0, 7, 0, 0\\}"
+
+gdb_test_no_output "compile code struct_object.complexfield = 7 + 5i"
+gdb_test "print struct_object.complexfield" " = 7 \\+ 5 \\* I"
+
+gdb_test_no_output "compile code struct_object.boolfield = 1"
+gdb_test "print struct_object.boolfield" " = true"
+
+gdb_test_no_output "compile code struct_object.vectorfield\[2\] = 7"
+gdb_test "print struct_object.vectorfield" \
+ " = \\{0, 0, 7, 0\\}"
+
+gdb_test_no_output "compile code union_object.typedeffield = 7"
+gdb_test "print union_object.typedeffield" " = 7"
+gdb_test "print union_object.intfield" " = 7"
+
+
+# LOC_UNRESOLVED tests.
+
+gdb_test "print unresolved" " = 20"
+gdb_test "compile code globalvar = unresolved;"
+gdb_test "print globalvar" " = 20" "print unresolved value"
+
+# Test shadowing with global and static variables.
+
+gdb_test_no_output "compile code globalshadow += 1;"
+gdb_test "print globalshadow" " = 101"
+gdb_test_no_output "compile code extern int globalshadow; globalshadow += 5;"
+gdb_test "print 'compile.c'::globalshadow" " = 15"
+gdb_test "print globalshadow" " = 101" "print globalshadow second time"
+gdb_test_no_output "compile code staticshadow += 2;"
+gdb_test "print staticshadow" " = 202"
+# "extern int staticshadow;" cannot access static variable.
+
+# Raw code cannot refer to locals.
+# As it references global variable we need the #pragma.
+# For #pragma we need multiline input.
+gdb_test_multiple "compile code -r" "compile code -r multiline 1" { -re "\r\n>$" {} }
+gdb_test_multiple "#pragma GCC user_expression" "compile code -r multiline 2" { -re "\r\n>$" {} }
+gdb_test_multiple "void _gdb_expr(void) { globalshadow = 77000; }" "compile code -r multiline 3" { -re "\r\n>$" {} }
+gdb_test_no_output "end" "compile code -r multiline 4"
+gdb_test "print 'compile.c'::globalshadow" " = 77000" \
+ "check globalshadow with -r"
+
+#
+# Test the case where the registers structure would not normally have
+# any fields.
+#
+
+gdb_breakpoint [gdb_get_line_number "no_args_or_locals breakpoint"]
+gdb_continue_to_breakpoint "no_args_or_locals"
+
+gdb_test_no_output "compile code globalvar = 77;" "set variable to 77"
+gdb_test "p globalvar" " = 77" "expect 77"
+
+
+# Test reference to minimal_symbol, not (full) symbol.
+
+gdb_test_no_output "compile code globalvar = func_nodebug (75);" \
+ "call func_nodebug"
+gdb_test "p globalvar" " = -75" "expect -75"
+gdb_test_no_output \
+ "compile code int (*funcp) (int) = func_nodebug; globalvar = funcp (76);" \
+ "call func_nodebug indirectly"
+gdb_test "p globalvar" " = -76" "expect -76"
+
+
+# Test compiled module memory protection.
+
+gdb_test_no_output "set debug compile on"
+gdb_test "compile code static const int readonly = 1; *(int *) &readonly = 2;" \
+ "The program being debugged was signaled while in a function called from GDB\\.\r\nGDB has restored the context to what it was before the call\\.\r\n.*"
+gdb_test_no_output "set debug compile off"
+
+
+#
+# Some simple coverage tests.
+#
+
+gdb_test "show debug compile" "Compile debugging is .*"
+gdb_test "show compile-args" \
+ "Compile command command-line arguments are .*"
+gdb_test "compile code -z" "Unknown argument.*"
+
+gdb_test "set lang java" \
+ "Warning: the current language does not match this frame."
+gdb_test "compile code globalvar" "No compiler support for this language\."
+gdb_test_no_output "set lang auto"
+
+gdb_test_no_output "compile code union union_type newdecl_u"
+gdb_test_no_output "compile code struct struct_type newdecl_s"
+gdb_test_no_output "compile code inttypedef newdecl_i"
+
+gdb_test "compile file" \
+ "You must provide a filename for this command.*" \
+ "Test compile file without a filename"
+gdb_test "compile file -r" \
+ "You must provide a filename with the raw option set.*" \
+ "Test compile file and raw option without a filename"
+gdb_test "compile file -z" \
+ "Unknown argument.*" \
+ "Test compile file with unknown argument"
+
+
+# LOC_CONST tests.
+
+if { $srcfile3 != "" } {
+ gdb_test "p constvar" " = 3"
+ gdb_test "info addr constvar" {Symbol "constvar" is constant\.}
+
+ gdb_test "compile code globalvar = constvar;"
+ gdb_test "print globalvar" " = 3" "print constvar value"
+} else {
+ untested "print constvar value"
+}
+
+# Shared library tests.
+
+if {[skip_shlib_tests]} {
+ untested "skipping shlib tests"
+ return;
+}
+
+set libbin [standard_output_file ${testfile}-shlib.so]
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile2} $libbin {debug}] != ""
+ || [build_executable $testfile ${testfile}-shlib $srcfile \
+ [list debug ldflags=$libbin]] == -1 } {
+ return -1
+}
+
+clean_restart ${testfile}-shlib
+if ![runto_main] {
+ return -1
+}
+
+gdb_test_no_output "compile code shlib_func ();" "call shared library function"
+gdb_test "p globalvar" " = 1" "expect 1"
+
+gdb_test_no_output "compile code shlibvar += 5;" "modify shared library variable"
+gdb_test "p shlibvar" " = 15" "expect 15"