'carlton_dictionary-branch'.
Cherrypick from master 2002-10-11 13:53:33 UTC Daniel Jacobowitz <drow@false.org> ' * Makefile.am: Run dep-am.':
bfd/elf32-sh64-lin.c
bfd/elf64-sh64-lin.c
bfd/simple.c
gdb/disasm.c
gdb/disasm.h
gdb/testsuite/gdb.c++/casts.cc
gdb/testsuite/gdb.c++/casts.exp
gdb/testsuite/gdb.mi/mi1-return.exp
gdb/testsuite/gdb.mi/mi1-stack.exp
--- /dev/null
+/* Hitachi SH specific support for 64-bit Linux
+ Copyright 2000 Free Software Foundation, Inc.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+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 2 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, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#define TARGET_BIG_SYM bfd_elf32_sh64blin_vec
+#define TARGET_BIG_NAME "elf32-sh64big-linux"
+#define TARGET_LITTLE_SYM bfd_elf32_sh64lin_vec
+#define TARGET_LITTLE_NAME "elf32-sh64-linux"
+#define ELF_ARCH bfd_arch_sh
+#define ELF_MACHINE_CODE EM_SH
+#define ELF_MAXPAGESIZE 0x10000
+#define elf_symbol_leading_char 0
+
+#include "elf32-sh64.c"
--- /dev/null
+/* Hitachi SH specific support for 64-bit Linux
+ Copyright 2002 Free Software Foundation, Inc.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+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 2 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, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#define TARGET_BIG_SYM bfd_elf64_sh64blin_vec
+#define TARGET_BIG_NAME "elf64-sh64big-linux"
+#define TARGET_LITTLE_SYM bfd_elf64_sh64lin_vec
+#define TARGET_LITTLE_NAME "elf64-sh64-linux"
+#define ELF_ARCH bfd_arch_sh
+#define ELF_MACHINE_CODE EM_SH
+#define ELF_MAXPAGESIZE 0x10000
+#define elf_symbol_leading_char 0
+
+#include "elf64-sh64.c"
--- /dev/null
+/* simple.c -- BFD simple client routines
+ Copyright 2002
+ Free Software Foundation, Inc.
+ Contributed by MontaVista Software, Inc.
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include "bfd.h"
+#include "sysdep.h"
+#include "libbfd.h"
+#include "bfdlink.h"
+
+static boolean
+simple_dummy_warning (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
+ const char *warning ATTRIBUTE_UNUSED,
+ const char *symbol ATTRIBUTE_UNUSED,
+ bfd *abfd ATTRIBUTE_UNUSED,
+ asection *section ATTRIBUTE_UNUSED,
+ bfd_vma address ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
+static boolean
+simple_dummy_undefined_symbol (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
+ const char *name ATTRIBUTE_UNUSED,
+ bfd *abfd ATTRIBUTE_UNUSED,
+ asection *section ATTRIBUTE_UNUSED,
+ bfd_vma address ATTRIBUTE_UNUSED,
+ boolean fatal ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
+static boolean
+simple_dummy_reloc_overflow (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
+ const char *name ATTRIBUTE_UNUSED,
+ const char *reloc_name ATTRIBUTE_UNUSED,
+ bfd_vma addend ATTRIBUTE_UNUSED,
+ bfd *abfd ATTRIBUTE_UNUSED,
+ asection *section ATTRIBUTE_UNUSED,
+ bfd_vma address ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
+static boolean
+simple_dummy_reloc_dangerous (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
+ const char *message ATTRIBUTE_UNUSED,
+ bfd *abfd ATTRIBUTE_UNUSED,
+ asection *section ATTRIBUTE_UNUSED,
+ bfd_vma address ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
+static boolean
+simple_dummy_unattached_reloc (struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
+ const char *name ATTRIBUTE_UNUSED,
+ bfd *abfd ATTRIBUTE_UNUSED,
+ asection *section ATTRIBUTE_UNUSED,
+ bfd_vma address ATTRIBUTE_UNUSED)
+{
+ return true;
+}
+
+/*
+FUNCTION
+ bfd_simple_relocate_secton
+
+SYNOPSIS
+ bfd_byte *bfd_simple_get_relocated_section_contents (bfd *abfd, asection *sec, bfd_byte *outbuf);
+
+DESCRIPTION
+ Returns the relocated contents of section @var{sec}. Only symbols
+ from @var{abfd} and the output offsets assigned to sections in
+ @var{abfd} are used. The result will be stored at @var{outbuf}
+ or allocated with @code{bfd_malloc} if @var{outbuf} is @code{NULL}.
+
+ Generally all sections in @var{abfd} should have their
+ @code{output_section} pointing back to the original section.
+
+ Returns @code{NULL} on a fatal error; ignores errors applying
+ particular relocations.
+*/
+
+bfd_byte *
+bfd_simple_get_relocated_section_contents (bfd *abfd, asection *sec,
+ bfd_byte *outbuf)
+{
+ struct bfd_link_info link_info;
+ struct bfd_link_order link_order;
+ struct bfd_link_callbacks callbacks;
+ bfd_byte *contents, *data;
+ int storage_needed, number_of_symbols;
+ asymbol **symbol_table;
+
+ /* In order to use bfd_get_relocated_section_contents, we need
+ to forge some data structures that it expects. */
+
+ /* Fill in the bare minimum number of fields for our purposes. */
+ memset (&link_info, 0, sizeof (link_info));
+ link_info.input_bfds = abfd;
+
+ link_info.hash = bfd_link_hash_table_create (abfd);
+ link_info.callbacks = &callbacks;
+ callbacks.warning = simple_dummy_warning;
+ callbacks.undefined_symbol = simple_dummy_undefined_symbol;
+ callbacks.reloc_overflow = simple_dummy_reloc_overflow;
+ callbacks.reloc_dangerous = simple_dummy_reloc_dangerous;
+ callbacks.unattached_reloc = simple_dummy_unattached_reloc;
+
+ memset (&link_order, 0, sizeof (link_order));
+ link_order.next = NULL;
+ link_order.type = bfd_indirect_link_order;
+ link_order.offset = 0;
+ link_order.size = bfd_section_size (abfd, sec);
+ link_order.u.indirect.section = sec;
+
+ data = NULL;
+ if (outbuf == NULL)
+ {
+ data = bfd_malloc (bfd_section_size (abfd, sec));
+ if (data == NULL)
+ return NULL;
+ outbuf = data;
+ }
+ bfd_link_add_symbols (abfd, &link_info);
+
+ storage_needed = bfd_get_symtab_upper_bound (abfd);
+ symbol_table = (asymbol **) bfd_malloc (storage_needed);
+ number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
+
+ contents = bfd_get_relocated_section_contents (abfd,
+ &link_info,
+ &link_order,
+ outbuf,
+ 0,
+ symbol_table);
+ if (contents == NULL && data != NULL)
+ free (data);
+
+ /* Foul hack to prevent bfd_section_size aborts. This flag only controls
+ that macro (and the related size macros), selecting between _raw_size
+ and _cooked_size. Debug sections won't change size while we're only
+ relocating. There may be trouble here someday if it tries to run
+ relaxation unexpectedly, so make sure. */
+ BFD_ASSERT (sec->_raw_size == sec->_cooked_size);
+ sec->reloc_done = 0;
+
+ bfd_link_hash_table_free (abfd, link_info.hash);
+
+ return contents;
+}
--- /dev/null
+/* Disassemble support for GDB.
+ Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "defs.h"
+#include "target.h"
+#include "value.h"
+#include "ui-out.h"
+#include "gdb_string.h"
+
+#include "disasm.h"
+
+/* Disassemble functions.
+ FIXME: We should get rid of all the duplicate code in gdb that does
+ the same thing: disassemble_command() and the gdbtk variation. */
+
+/* This Structure is used to store line number information.
+ We need a different sort of line table from the normal one cuz we can't
+ depend upon implicit line-end pc's for lines to do the
+ reordering in this function. */
+
+struct dis_line_entry
+{
+ int line;
+ CORE_ADDR start_pc;
+ CORE_ADDR end_pc;
+};
+
+/* This variable determines where memory used for disassembly is read from. */
+int gdb_disassemble_from_exec = -1;
+
+/* This is the memory_read_func for gdb_disassemble when we are
+ disassembling from the exec file. */
+static int
+gdb_dis_asm_read_memory (bfd_vma memaddr, bfd_byte * myaddr,
+ unsigned int len, disassemble_info * info)
+{
+ extern struct target_ops exec_ops;
+ int res;
+
+ errno = 0;
+ res = xfer_memory (memaddr, myaddr, len, 0, 0, &exec_ops);
+
+ if (res == len)
+ return 0;
+ else if (errno == 0)
+ return EIO;
+ else
+ return errno;
+}
+
+static int
+compare_lines (const PTR mle1p, const PTR mle2p)
+{
+ struct dis_line_entry *mle1, *mle2;
+ int val;
+
+ mle1 = (struct dis_line_entry *) mle1p;
+ mle2 = (struct dis_line_entry *) mle2p;
+
+ val = mle1->line - mle2->line;
+
+ if (val != 0)
+ return val;
+
+ return mle1->start_pc - mle2->start_pc;
+}
+
+static int
+dump_insns (struct ui_out *uiout, disassemble_info * di,
+ CORE_ADDR low, CORE_ADDR high,
+ int how_many, struct ui_stream *stb)
+{
+ int num_displayed = 0;
+ CORE_ADDR pc;
+
+ /* parts of the symbolic representation of the address */
+ int unmapped;
+ char *filename = NULL;
+ char *name = NULL;
+ int offset;
+ int line;
+
+ for (pc = low; pc < high;)
+ {
+ QUIT;
+ if (how_many >= 0)
+ {
+ if (num_displayed >= how_many)
+ break;
+ else
+ num_displayed++;
+ }
+ ui_out_tuple_begin (uiout, NULL);
+ ui_out_field_core_addr (uiout, "address", pc);
+
+ if (!build_address_symbolic (pc, 0, &name, &offset, &filename,
+ &line, &unmapped))
+ {
+ /* We don't care now about line, filename and
+ unmapped. But we might in the future. */
+ ui_out_text (uiout, " <");
+ ui_out_field_string (uiout, "func-name", name);
+ ui_out_text (uiout, "+");
+ ui_out_field_int (uiout, "offset", offset);
+ ui_out_text (uiout, ">:\t");
+ }
+ if (filename != NULL)
+ xfree (filename);
+ if (name != NULL)
+ xfree (name);
+
+ ui_file_rewind (stb->stream);
+ pc += TARGET_PRINT_INSN (pc, di);
+ ui_out_field_stream (uiout, "inst", stb);
+ ui_file_rewind (stb->stream);
+ ui_out_tuple_end (uiout);
+ ui_out_text (uiout, "\n");
+ }
+ return num_displayed;
+}
+
+/* The idea here is to present a source-O-centric view of a
+ function to the user. This means that things are presented
+ in source order, with (possibly) out of order assembly
+ immediately following. */
+static void
+do_mixed_source_and_assembly (struct ui_out *uiout,
+ struct disassemble_info *di, int nlines,
+ struct linetable_entry *le,
+ CORE_ADDR low, CORE_ADDR high,
+ struct symtab *symtab,
+ int how_many, struct ui_stream *stb)
+{
+ int newlines = 0;
+ struct dis_line_entry *mle;
+ struct symtab_and_line sal;
+ int i;
+ int out_of_order = 0;
+ int next_line = 0;
+ CORE_ADDR pc;
+ int num_displayed = 0;
+
+ mle = (struct dis_line_entry *) alloca (nlines
+ * sizeof (struct dis_line_entry));
+
+ /* Copy linetable entries for this function into our data
+ structure, creating end_pc's and setting out_of_order as
+ appropriate. */
+
+ /* First, skip all the preceding functions. */
+
+ for (i = 0; i < nlines - 1 && le[i].pc < low; i++);
+
+ /* Now, copy all entries before the end of this function. */
+
+ for (; i < nlines - 1 && le[i].pc < high; i++)
+ {
+ if (le[i].line == le[i + 1].line && le[i].pc == le[i + 1].pc)
+ continue; /* Ignore duplicates */
+
+ /* Skip any end-of-function markers. */
+ if (le[i].line == 0)
+ continue;
+
+ mle[newlines].line = le[i].line;
+ if (le[i].line > le[i + 1].line)
+ out_of_order = 1;
+ mle[newlines].start_pc = le[i].pc;
+ mle[newlines].end_pc = le[i + 1].pc;
+ newlines++;
+ }
+
+ /* If we're on the last line, and it's part of the function,
+ then we need to get the end pc in a special way. */
+
+ if (i == nlines - 1 && le[i].pc < high)
+ {
+ mle[newlines].line = le[i].line;
+ mle[newlines].start_pc = le[i].pc;
+ sal = find_pc_line (le[i].pc, 0);
+ mle[newlines].end_pc = sal.end;
+ newlines++;
+ }
+
+ /* Now, sort mle by line #s (and, then by addresses within
+ lines). */
+
+ if (out_of_order)
+ qsort (mle, newlines, sizeof (struct dis_line_entry), compare_lines);
+
+ /* Now, for each line entry, emit the specified lines (unless
+ they have been emitted before), followed by the assembly code
+ for that line. */
+
+ ui_out_list_begin (uiout, "asm_insns");
+
+ for (i = 0; i < newlines; i++)
+ {
+ int close_list = 1;
+ /* Print out everything from next_line to the current line. */
+ if (mle[i].line >= next_line)
+ {
+ if (next_line != 0)
+ {
+ /* Just one line to print. */
+ if (next_line == mle[i].line)
+ {
+ ui_out_tuple_begin (uiout, "src_and_asm_line");
+ print_source_lines (symtab, next_line, mle[i].line + 1, 0);
+ }
+ else
+ {
+ /* Several source lines w/o asm instructions associated. */
+ for (; next_line < mle[i].line; next_line++)
+ {
+ ui_out_tuple_begin (uiout, "src_and_asm_line");
+ print_source_lines (symtab, next_line, next_line + 1,
+ 0);
+ ui_out_list_begin (uiout, "line_asm_insn");
+ ui_out_list_end (uiout);
+ ui_out_tuple_end (uiout);
+ }
+ /* Print the last line and leave list open for
+ asm instructions to be added. */
+ ui_out_tuple_begin (uiout, "src_and_asm_line");
+ print_source_lines (symtab, next_line, mle[i].line + 1, 0);
+ }
+ }
+ else
+ {
+ ui_out_tuple_begin (uiout, "src_and_asm_line");
+ print_source_lines (symtab, mle[i].line, mle[i].line + 1, 0);
+ }
+
+ next_line = mle[i].line + 1;
+ ui_out_list_begin (uiout, "line_asm_insn");
+ /* Don't close the list if the lines are not in order. */
+ if (i < (newlines - 1) && mle[i + 1].line <= mle[i].line)
+ close_list = 0;
+ }
+
+ num_displayed += dump_insns (uiout, di, mle[i].start_pc, mle[i].end_pc,
+ how_many, stb);
+ if (close_list)
+ {
+ ui_out_list_end (uiout);
+ ui_out_tuple_end (uiout);
+ ui_out_text (uiout, "\n");
+ close_list = 0;
+ }
+ if (how_many >= 0)
+ if (num_displayed >= how_many)
+ break;
+ }
+ ui_out_list_end (uiout);
+}
+
+
+static void
+do_assembly_only (struct ui_out *uiout, disassemble_info * di,
+ CORE_ADDR low, CORE_ADDR high,
+ int how_many, struct ui_stream *stb)
+{
+ int num_displayed = 0;
+
+ ui_out_list_begin (uiout, "asm_insns");
+
+ num_displayed = dump_insns (uiout, di, low, high, how_many, stb);
+
+ ui_out_list_end (uiout);
+}
+
+void
+gdb_disassembly (struct ui_out *uiout,
+ char *file_string,
+ int line_num,
+ int mixed_source_and_assembly,
+ int how_many, CORE_ADDR low, CORE_ADDR high)
+{
+ static disassemble_info di;
+ static int di_initialized;
+ /* To collect the instruction outputted from opcodes. */
+ static struct ui_stream *stb = NULL;
+ struct symtab *symtab = NULL;
+ struct linetable_entry *le = NULL;
+ int nlines = -1;
+
+ if (!di_initialized)
+ {
+ /* We don't add a cleanup for this, because the allocation of
+ the stream is done once only for each gdb run, and we need to
+ keep it around until the end. Hopefully there won't be any
+ errors in the init code below, that make this function bail
+ out. */
+ stb = ui_out_stream_new (uiout);
+ INIT_DISASSEMBLE_INFO_NO_ARCH (di, stb->stream,
+ (fprintf_ftype) fprintf_unfiltered);
+ di.flavour = bfd_target_unknown_flavour;
+ di.memory_error_func = dis_asm_memory_error;
+ di.print_address_func = dis_asm_print_address;
+ di_initialized = 1;
+ }
+
+ di.mach = TARGET_PRINT_INSN_INFO->mach;
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
+ di.endian = BFD_ENDIAN_BIG;
+ else
+ di.endian = BFD_ENDIAN_LITTLE;
+
+ /* If gdb_disassemble_from_exec == -1, then we use the following heuristic to
+ determine whether or not to do disassembly from target memory or from the
+ exec file:
+
+ If we're debugging a local process, read target memory, instead of the
+ exec file. This makes disassembly of functions in shared libs work
+ correctly. Also, read target memory if we are debugging native threads.
+
+ Else, we're debugging a remote process, and should disassemble from the
+ exec file for speed. However, this is no good if the target modifies its
+ code (for relocation, or whatever). */
+
+ if (gdb_disassemble_from_exec == -1)
+ {
+ if (strcmp (target_shortname, "child") == 0
+ || strcmp (target_shortname, "procfs") == 0
+ || strcmp (target_shortname, "vxprocess") == 0
+ || strstr (target_shortname, "-threads") != NULL)
+ gdb_disassemble_from_exec = 0; /* It's a child process, read inferior mem */
+ else
+ gdb_disassemble_from_exec = 1; /* It's remote, read the exec file */
+ }
+
+ if (gdb_disassemble_from_exec)
+ di.read_memory_func = gdb_dis_asm_read_memory;
+ else
+ di.read_memory_func = dis_asm_read_memory;
+
+ /* Assume symtab is valid for whole PC range */
+ symtab = find_pc_symtab (low);
+
+ if (symtab != NULL && symtab->linetable != NULL)
+ {
+ /* Convert the linetable to a bunch of my_line_entry's. */
+ le = symtab->linetable->item;
+ nlines = symtab->linetable->nitems;
+ }
+
+ if (!mixed_source_and_assembly || nlines <= 0
+ || symtab == NULL || symtab->linetable == NULL)
+ do_assembly_only (uiout, &di, low, high, how_many, stb);
+
+ else if (mixed_source_and_assembly)
+ do_mixed_source_and_assembly (uiout, &di, nlines, le, low,
+ high, symtab, how_many, stb);
+
+ gdb_flush (gdb_stdout);
+}
--- /dev/null
+/* Disassemble support for GDB.
+ Copyright 2002 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef DISASM_H
+#define DISASM_H
+
+extern void gdb_disassembly (struct ui_out *uiout,
+ char *file_string,
+ int line_num,
+ int mixed_source_and_assembly,
+ int how_many, CORE_ADDR low, CORE_ADDR high);
+#endif
--- /dev/null
+struct A
+{
+ int a;
+ A (int aa): a (aa) {}
+};
+
+struct B: public A
+{
+ int b;
+ B (int aa, int bb): A (aa), b(bb) {}
+};
+
+int
+main (int argc, char **argv)
+{
+ A *a = new B(42, 1729);
+ B *b = (B *) a;
+
+ return 0; /* breakpoint spot: casts.exp: 1 */
+}
--- /dev/null
+# Copyright 2002 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+# This file is part of the gdb testsuite
+
+# Test casting, especially between class types or pointer-to-class
+# types.
+
+# This file is part of the gdb testsuite
+
+if $tracelevel then {
+ strace $tracelevel
+ }
+
+#
+# test running programs
+#
+
+set prms_id 0
+set bug_id 0
+
+if { [skip_cplus_tests] } { continue }
+
+set testfile "casts"
+set srcfile ${testfile}.cc
+set binfile ${objdir}/${subdir}/${testfile}
+
+if [get_compiler_info ${binfile} "c++"] {
+ return -1;
+}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+gdb_test "break [gdb_get_line_number "casts.exp: 1"]" \
+ "Breakpoint.*at.* file .*" \
+ ""
+
+gdb_test "run" "Breakpoint .* at casts.cc" ""
+
+# Casting a pointer to a base class to a pointer to a derived class
+# should yield the entire derived class. Until August 2002, GDB got
+# the enclosing type on `(B *) a' wrong: while the value's static type
+# was `B *', as it should be, the enclosing type (which is supposed to
+# be the dynamic type) was `A *'. It's senseless to have a static
+# type derived from the dynamic type; it should be the other way
+# 'round. Dereferencing this oddly typed pointer yielded a value in
+# which only the base class's members were initialized, since GDB uses
+# the enclosing type to decide how many bytes to read. Members from
+# the derived class were garbage, from GDB's address space.
+gdb_test "print * (B *) a" ".* = {<A> = {a = 42}, b = 1729}" \
+ "cast base class pointer to derived class pointer"
+
+# Check also that we get the same results from letting the compiler do
+# the dereference.
+gdb_test "print * b" ".* = {<A> = {a = 42}, b = 1729}" \
+ "let compiler cast base class pointer to derived class pointer"
--- /dev/null
+# Copyright 1999, 2000 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+# Test Machine interface (MI) operations
+# Verify that, using the MI, we can run a simple program and perform
+# exec-return.
+
+# The goal is not to
+# test gdb functionality, which is done by other tests, but to verify
+# the correct output response to MI operations.
+#
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi1"
+
+gdb_exit
+if [mi_gdb_start] {
+ continue
+}
+
+set testfile "basics"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+proc test_running_to_callee4 {} {
+ global mi_gdb_prompt
+ global hex
+
+ mi_gdb_test "200-break-insert callee4" \
+ "200\\^done,bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"8\",times=\"0\"\}" \
+ "break-insert operation"
+
+ mi_run_cmd
+
+ gdb_expect {
+ -re "000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"callee4\",args=\\\[\\\],file=\".*basics.c\",line=\"8\"\}\r\n$mi_gdb_prompt$" {
+ pass "run to callee4"
+ }
+ -re ".*$mi_gdb_prompt$" {
+ fail "run to callee4 (2)"
+ }
+ timeout {
+ fail "run to callee4 (timeout)"
+ }
+ }
+
+ mi_gdb_test "205-break-delete" \
+ "205\\^done.*" \
+ "delete all breakpoints"
+
+}
+
+proc test_return_simple {} {
+ global mi_gdb_prompt
+ global hex
+
+ send_gdb "111-exec-return\n"
+ gdb_expect {
+ -re "111\\^done,frame=\{level=\"0\",addr=\"$hex\",func=\"callee3\",args=\\\[.*\\\],file=\".*basics.c\",line=\"18\"\}\r\n$mi_gdb_prompt$" {pass "return from callee4 now"}
+ -re ".*\r\n$mi_gdb_prompt$" { fail "return from callee4 now" }
+ timeout { fail "return from callee4 now (timeout)"
+ }
+ }
+}
+
+test_running_to_callee4
+test_return_simple
+
+mi_gdb_exit
+return 0
--- /dev/null
+# Copyright 2000 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+#
+# Test essential Machine interface (MI) operations
+#
+# Verify that stack commands work.
+
+# The goal is not to test gdb functionality, which is done by other tests,
+# but to verify the correct output response to MI operations.
+#
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi1"
+
+gdb_exit
+if [mi_gdb_start] {
+ continue
+}
+
+set testfile "basics"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+
+mi_gdb_test "200-break-insert callee4" \
+ "200\\^done,bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"8\",times=\"0\"\}" \
+ "break-insert operation"
+
+mi_run_cmd
+# The running part has been checked already by mi_run_cmd
+gdb_expect {
+ -re "\[\r\n\]*000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"callee4\",args=\\\[\\\],file=\".*basics.c\",line=\"8\"\}\r\n$mi_gdb_prompt$" {
+ pass "run to callee4"
+ }
+ -re ".*$mi_gdb_prompt$" {fail "run to callee4 (2)"}
+ timeout {fail "run to callee4 (timeout 2)"}
+}
+
+
+proc test_stack_frame_listing {} {
+ global mi_gdb_prompt
+ global hex
+
+ # Obtain a stack trace
+ # Tests:
+ # -stack-list-frames
+ # -stack-list-frames 1 1
+ # -stack-list-frames 1 3
+
+ mi_gdb_test "231-stack-list-frames" \
+ "231\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"8\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\},frame=\{level=\"4\",addr=\"$hex\",func=\"main\",.*\}\\\]" \
+ "stack frame listing"
+ mi_gdb_test "232-stack-list-frames 1 1" \
+ "232\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\}\\\]" \
+ "stack frame listing 1 1"
+ mi_gdb_test "233-stack-list-frames 1 3" \
+ "233\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\}\\\]" \
+ "stack frame listing 1 3"
+
+ mi_gdb_test "234-stack-list-frames 1" \
+ "234\\^error,msg=\"mi_cmd_stack_list_frames: Usage.*FRAME_LOW FRAME_HIGH.*\"" \
+ "stack frame listing wrong"
+}
+
+proc test_stack_args_listing {} {
+ global mi_gdb_prompt
+ global hex
+
+ # Obtain lists for args for the stack frames
+ # Tests:
+ # -stack-list-arguments 0
+ # -stack-list-arguments 0 1 1
+ # -stack-list-arguments 0 1 3
+ # -stack-list-arguments 1
+ # -stack-list-arguments 1 1 1
+ # -stack-list-arguments 1 1 3
+ # -stack-list-arguments
+
+ mi_gdb_test "231-stack-list-arguments 0" \
+ "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
+ "stack args listing 0"
+
+ mi_gdb_test "232-stack-list-arguments 0 1 1" \
+ "232\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\}\\\]" \
+ "stack args listing 0 1 1"
+
+ mi_gdb_test "233-stack-list-arguments 0 1 3" \
+ "233\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\}\\\]" \
+ "stack args listing 0 1 3"
+
+ mi_gdb_test "231-stack-list-arguments 1" \
+ "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
+ "stack args listing 1"
+
+ mi_gdb_test "232-stack-list-arguments 1 1 1" \
+ "232\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
+ "stack args listing 1 1 1"
+
+ mi_gdb_test "233-stack-list-arguments 1 1 3" \
+ "233\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\}\\\]" \
+ "stack args listing 1 1 3"
+
+ mi_gdb_test "234-stack-list-arguments" \
+ "234\\^error,msg=\"mi_cmd_stack_list_args: Usage.*PRINT_VALUES.*FRAME_LOW FRAME_HIGH.*\"" \
+ "stack args listing wrong"
+}
+
+proc test_stack_info_depth {} {
+ global mi_gdb_prompt
+ global hex
+
+ # Obtain depth of stack
+ # Tests:
+ # -stack-info-depth
+ # -stack-info-depth 3
+ # -stack-info-depth 99
+
+ mi_gdb_test "231-stack-info-depth" \
+ "231\\^done,depth=\"5\"" \
+ "stack info-depth"
+
+ mi_gdb_test "231-stack-info-depth 3" \
+ "231\\^done,depth=\"3\"" \
+ "stack info-depth 3"
+
+ mi_gdb_test "231-stack-info-depth 99" \
+ "231\\^done,depth=\"5\"" \
+ "stack info-depth 99"
+
+ mi_gdb_test "231-stack-info-depth 99 99" \
+ "231\\^error,msg=\"mi_cmd_stack_info_depth: Usage: .MAX_DEPTH.\"" \
+ "stack info-depth wrong usage"
+}
+
+proc test_stack_locals_listing {} {
+ global mi_gdb_prompt
+ global hex
+
+ # Obtain lists for locals for the stack frames
+ # Tests:
+ # -stack-list-locals 0
+ # -stack-list-locals 1
+ # -stack-list-arguments
+
+ mi_gdb_test "232-stack-list-locals 0" \
+ "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\"\\\]" \
+ "stack locals listing 0"
+
+# step until A, B, C, have some reasonable values.
+send_gdb "-exec-next 3\n"
+gdb_expect {
+ -re "\\^running\r\n${mi_gdb_prompt}\\*stopped,reason=\"end-stepping-range\",thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"callee4\",args=\\\[\\\],file=\".*basics.c\",line=\"13\"\}\r\n$mi_gdb_prompt$" {
+ pass "next's in callee4"
+ }
+ timeout { fail "next in callee4 (timeout)" }
+}
+
+ mi_gdb_test "232-stack-list-locals 1" \
+ "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\}\\\]" \
+ "stack locals listing 1"
+
+ mi_gdb_test "234-stack-list-locals" \
+ "234\\^error,msg=\"mi_cmd_stack_list_locals: Usage.*PRINT_VALUES.*\"" \
+ "stack locals listing wrong"
+
+ mi_gdb_test "232-stack-select-frame 1" \
+ "232\\^done" \
+ "stack select frame 1"
+
+ mi_gdb_test "232-stack-list-locals 1" \
+ "232\\^done,locals=\\\[\\\]" \
+ "stack locals listing for new frame"
+
+# this should be a no-op
+
+ mi_gdb_test "232-stack-select-frame" \
+ "232\\^done" \
+ "stack select same frame"
+
+ mi_gdb_test "232-stack-list-locals 1" \
+ "232\\^done,locals=\\\[\\\]" \
+ "stack locals for same frame (level 1)"
+
+}
+
+test_stack_frame_listing
+test_stack_args_listing
+test_stack_locals_listing
+test_stack_info_depth
+
+
+mi_gdb_exit
+return 0