2010-11-05 22:31:30 +08:00
|
|
|
/* OpenCL language support for GDB, the GNU debugger.
|
2017-01-01 14:50:51 +08:00
|
|
|
Copyright (C) 2010-2017 Free Software Foundation, Inc.
|
2010-11-05 22:31:30 +08:00
|
|
|
|
|
|
|
Contributed by Ken Werner <ken.werner@de.ibm.com>.
|
|
|
|
|
|
|
|
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 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 "defs.h"
|
|
|
|
#include "gdbtypes.h"
|
|
|
|
#include "symtab.h"
|
|
|
|
#include "expression.h"
|
|
|
|
#include "parser-defs.h"
|
|
|
|
#include "language.h"
|
2013-10-17 21:15:21 +08:00
|
|
|
#include "varobj.h"
|
2010-11-05 22:31:30 +08:00
|
|
|
#include "c-lang.h"
|
|
|
|
|
|
|
|
/* This macro generates enum values from a given type. */
|
|
|
|
|
|
|
|
#define OCL_P_TYPE(TYPE)\
|
|
|
|
opencl_primitive_type_##TYPE,\
|
|
|
|
opencl_primitive_type_##TYPE##2,\
|
|
|
|
opencl_primitive_type_##TYPE##3,\
|
|
|
|
opencl_primitive_type_##TYPE##4,\
|
|
|
|
opencl_primitive_type_##TYPE##8,\
|
|
|
|
opencl_primitive_type_##TYPE##16
|
|
|
|
|
|
|
|
enum opencl_primitive_types {
|
|
|
|
OCL_P_TYPE (char),
|
|
|
|
OCL_P_TYPE (uchar),
|
|
|
|
OCL_P_TYPE (short),
|
|
|
|
OCL_P_TYPE (ushort),
|
|
|
|
OCL_P_TYPE (int),
|
|
|
|
OCL_P_TYPE (uint),
|
|
|
|
OCL_P_TYPE (long),
|
|
|
|
OCL_P_TYPE (ulong),
|
|
|
|
OCL_P_TYPE (half),
|
|
|
|
OCL_P_TYPE (float),
|
|
|
|
OCL_P_TYPE (double),
|
|
|
|
opencl_primitive_type_bool,
|
|
|
|
opencl_primitive_type_unsigned_char,
|
|
|
|
opencl_primitive_type_unsigned_short,
|
|
|
|
opencl_primitive_type_unsigned_int,
|
|
|
|
opencl_primitive_type_unsigned_long,
|
|
|
|
opencl_primitive_type_size_t,
|
|
|
|
opencl_primitive_type_ptrdiff_t,
|
|
|
|
opencl_primitive_type_intptr_t,
|
|
|
|
opencl_primitive_type_uintptr_t,
|
|
|
|
opencl_primitive_type_void,
|
|
|
|
nr_opencl_primitive_types
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct gdbarch_data *opencl_type_data;
|
|
|
|
|
2012-03-01 Pedro Alves <palves@redhat.com>
* amd64-linux-tdep.c (amd64_linux_record_signal): Make static.
* breakpoint.c (create_exception_master_breakpoint, trace_command)
(ftrace_command, strace_command): Make static.
* d-lang.c (_initialize_d_language): Declare.
* dwarf2expr.c (_initialize_dwarf2expr): Declare.
* dwarf2loc.c (_initialize_dwarf2loc):
* dwarf2read.c (process_psymtab_comp_unit): Make static.
* exec.c (exec_get_section_table): Make static.
* i386-linux-tdep.c (i386_linux_record_signal): Make static.
* infcmd.c (ensure_valid_thread, ensure_not_tfind_mode): Make static.
* inferior.c (remove_inferior_command, add_inferior_command)
(clone_inferior_command): Make static.
* linux-nat.c (linux_nat_thread_address_space)
(linux_nat_core_of_thread): Make static.
* linux-tdep.c (_initialize_linux_tdep): Declare.
* objc-lang.c (_initialize_objc_lang): Declare.
* opencl-lang.c (builtin_opencl_type, opencl_language_arch_info):
Make static.
(_initialize_opencl_language): Declare.
* record.c (_initialize_record): Declare.
* remote.c (demand_private_info, remote_get_tib_address)
(remote_supports_cond_tracepoints)
(remote_supports_fast_tracepoints, remote_get_tracepoint_status):
Make static.
* skip.c (_initialize_step_skip): Declare.
* symtab.c (skip_prologue_using_lineinfo): Make static.
* tracepoint.c (delete_trace_state_variable)
(trace_variable_command, delete_trace_variable_command)
(get_uploaded_tsv, find_matching_tracepoint_location)
(find_matching_tsv, create_tsv_from_upload, get_traceframe_info):
Make static.
* value.c (pack_unsigned_long): Make static.
* varobj.c (varobj_ensure_python_env): Make static.
* windows-tdep.c (_initialize_windows_tdep): Declare.
* xml-syscall.c (make_cleanup_free_syscalls_info): Make static.
2012-03-02 05:14:00 +08:00
|
|
|
static struct type **
|
2010-11-05 22:31:30 +08:00
|
|
|
builtin_opencl_type (struct gdbarch *gdbarch)
|
|
|
|
{
|
2015-09-26 02:08:07 +08:00
|
|
|
return (struct type **) gdbarch_data (gdbarch, opencl_type_data);
|
2010-11-05 22:31:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the corresponding OpenCL vector type from the given type code,
|
|
|
|
the length of the element type, the unsigned flag and the amount of
|
|
|
|
elements (N). */
|
|
|
|
|
|
|
|
static struct type *
|
|
|
|
lookup_opencl_vector_type (struct gdbarch *gdbarch, enum type_code code,
|
|
|
|
unsigned int el_length, unsigned int flag_unsigned,
|
|
|
|
int n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned int length;
|
|
|
|
struct type *type = NULL;
|
2011-02-21 23:53:10 +08:00
|
|
|
struct type **types = builtin_opencl_type (gdbarch);
|
2010-11-05 22:31:30 +08:00
|
|
|
|
|
|
|
/* Check if n describes a valid OpenCL vector size (2, 3, 4, 8, 16). */
|
|
|
|
if (n != 2 && n != 3 && n != 4 && n != 8 && n != 16)
|
|
|
|
error (_("Invalid OpenCL vector size: %d"), n);
|
|
|
|
|
|
|
|
/* Triple vectors have the size of a quad vector. */
|
|
|
|
length = (n == 3) ? el_length * 4 : el_length * n;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_opencl_primitive_types; i++)
|
|
|
|
{
|
|
|
|
LONGEST lowb, highb;
|
|
|
|
|
|
|
|
if (TYPE_CODE (types[i]) == TYPE_CODE_ARRAY && TYPE_VECTOR (types[i])
|
|
|
|
&& get_array_bounds (types[i], &lowb, &highb)
|
|
|
|
&& TYPE_CODE (TYPE_TARGET_TYPE (types[i])) == code
|
|
|
|
&& TYPE_UNSIGNED (TYPE_TARGET_TYPE (types[i])) == flag_unsigned
|
|
|
|
&& TYPE_LENGTH (TYPE_TARGET_TYPE (types[i])) == el_length
|
|
|
|
&& TYPE_LENGTH (types[i]) == length
|
|
|
|
&& highb - lowb + 1 == n)
|
|
|
|
{
|
|
|
|
type = types[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns nonzero if the array ARR contains duplicates within
|
|
|
|
the first N elements. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
array_has_dups (int *arr, int n)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
for (j = i + 1; j < n; j++)
|
|
|
|
{
|
|
|
|
if (arr[i] == arr[j])
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The OpenCL component access syntax allows to create lvalues referring to
|
|
|
|
selected elements of an original OpenCL vector in arbitrary order. This
|
|
|
|
structure holds the information to describe such lvalues. */
|
|
|
|
|
|
|
|
struct lval_closure
|
|
|
|
{
|
|
|
|
/* Reference count. */
|
|
|
|
int refc;
|
|
|
|
/* The number of indices. */
|
|
|
|
int n;
|
|
|
|
/* The element indices themselves. */
|
|
|
|
int *indices;
|
|
|
|
/* A pointer to the original value. */
|
|
|
|
struct value *val;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Allocates an instance of struct lval_closure. */
|
|
|
|
|
|
|
|
static struct lval_closure *
|
|
|
|
allocate_lval_closure (int *indices, int n, struct value *val)
|
|
|
|
{
|
2013-12-29 06:31:01 +08:00
|
|
|
struct lval_closure *c = XCNEW (struct lval_closure);
|
2010-11-05 22:31:30 +08:00
|
|
|
|
|
|
|
c->refc = 1;
|
|
|
|
c->n = n;
|
replace XCALLOC with XCNEWVEC or XCNEW
This removes XCALLOC and replaces it either with XCNEWVEC, or, if the
number of elements being requested was 1, with XCNEW.
2014-01-13 Tom Tromey <tromey@redhat.com>
* defs.h (XCALLOC): Remove.
* bcache.c (bcache_xmalloc): Use XCNEW, not XCALLOC.
(print_bcache_statistics): Use XCNEWVEC, not XCALLOC.
* dwarf2loc.c (allocate_piece_closure): Likewise.
* elfread.c (elf_symfile_segments): Likewise.
(elf_symfile_segments): Likewise.
* gdbtypes.c (copy_type_recursive): Likewise.
* i386-tdep.c (i386_gdbarch_init): Use XCNEW, not XCALLOC.
* jit.c (jit_frame_sniffer): Use XCNEWVEC, not XCALLOC.
* minsyms.c (prim_record_minimal_symbol_full): Use XCNEW, not
XCALLOC.
* mt-tdep.c (mt_gdbarch_init): Likewise.
* opencl-lang.c (allocate_lval_closure): Use XCNEWVEC, not
XCALLOC.
* psymtab.c (psymbol_compare): Use XCNEW, not XCALLOC.
* regcache.c (regcache_xmalloc_1): Use XCNEWVEC, not XCALLOC.
* registry.c (registry_alloc_data): Likewise.
* rs6000-tdep.c (rs6000_gdbarch_init): Use XCNEW, not XCALLOC.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* serial.c (serial_fdopen_ops): Likewise.
* solib-aix.c (solib_aix_get_section_offsets): Use XCNEWVEC, not
XCALLOC.
* spu-tdep.c (spu_gdbarch_init): Use XCNEW, not XCALLOC.
* symfile.c (default_symfile_segments): Use XCNEW and XCNEWVEC,
not XCALLOC.
2013-12-29 06:32:27 +08:00
|
|
|
c->indices = XCNEWVEC (int, n);
|
2010-11-05 22:31:30 +08:00
|
|
|
memcpy (c->indices, indices, n * sizeof (int));
|
|
|
|
value_incref (val); /* Increment the reference counter of the value. */
|
|
|
|
c->val = val;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lval_func_read (struct value *v)
|
|
|
|
{
|
|
|
|
struct lval_closure *c = (struct lval_closure *) value_computed_closure (v);
|
|
|
|
struct type *type = check_typedef (value_type (v));
|
|
|
|
struct type *eltype = TYPE_TARGET_TYPE (check_typedef (value_type (c->val)));
|
2016-04-13 03:02:57 +08:00
|
|
|
LONGEST offset = value_offset (v);
|
|
|
|
LONGEST elsize = TYPE_LENGTH (eltype);
|
2010-11-05 22:31:30 +08:00
|
|
|
int n, i, j = 0;
|
|
|
|
LONGEST lowb = 0;
|
|
|
|
LONGEST highb = 0;
|
|
|
|
|
|
|
|
if (TYPE_CODE (type) == TYPE_CODE_ARRAY
|
|
|
|
&& !get_array_bounds (type, &lowb, &highb))
|
|
|
|
error (_("Could not determine the vector bounds"));
|
|
|
|
|
|
|
|
/* Assume elsize aligned offset. */
|
|
|
|
gdb_assert (offset % elsize == 0);
|
|
|
|
offset /= elsize;
|
|
|
|
n = offset + highb - lowb + 1;
|
|
|
|
gdb_assert (n <= c->n);
|
|
|
|
|
|
|
|
for (i = offset; i < n; i++)
|
|
|
|
memcpy (value_contents_raw (v) + j++ * elsize,
|
|
|
|
value_contents (c->val) + c->indices[i] * elsize,
|
|
|
|
elsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lval_func_write (struct value *v, struct value *fromval)
|
|
|
|
{
|
|
|
|
struct value *mark = value_mark ();
|
|
|
|
struct lval_closure *c = (struct lval_closure *) value_computed_closure (v);
|
|
|
|
struct type *type = check_typedef (value_type (v));
|
|
|
|
struct type *eltype = TYPE_TARGET_TYPE (check_typedef (value_type (c->val)));
|
2016-04-13 03:02:57 +08:00
|
|
|
LONGEST offset = value_offset (v);
|
|
|
|
LONGEST elsize = TYPE_LENGTH (eltype);
|
2010-11-05 22:31:30 +08:00
|
|
|
int n, i, j = 0;
|
|
|
|
LONGEST lowb = 0;
|
|
|
|
LONGEST highb = 0;
|
|
|
|
|
|
|
|
if (TYPE_CODE (type) == TYPE_CODE_ARRAY
|
|
|
|
&& !get_array_bounds (type, &lowb, &highb))
|
|
|
|
error (_("Could not determine the vector bounds"));
|
|
|
|
|
|
|
|
/* Assume elsize aligned offset. */
|
|
|
|
gdb_assert (offset % elsize == 0);
|
|
|
|
offset /= elsize;
|
|
|
|
n = offset + highb - lowb + 1;
|
|
|
|
|
|
|
|
/* Since accesses to the fourth component of a triple vector is undefined we
|
|
|
|
just skip writes to the fourth element. Imagine something like this:
|
|
|
|
int3 i3 = (int3)(0, 1, 2);
|
|
|
|
i3.hi.hi = 5;
|
|
|
|
In this case n would be 4 (offset=12/4 + 1) while c->n would be 3. */
|
|
|
|
if (n > c->n)
|
|
|
|
n = c->n;
|
|
|
|
|
|
|
|
for (i = offset; i < n; i++)
|
|
|
|
{
|
|
|
|
struct value *from_elm_val = allocate_value (eltype);
|
|
|
|
struct value *to_elm_val = value_subscript (c->val, c->indices[i]);
|
|
|
|
|
|
|
|
memcpy (value_contents_writeable (from_elm_val),
|
|
|
|
value_contents (fromval) + j++ * elsize,
|
|
|
|
elsize);
|
|
|
|
value_assign (to_elm_val, from_elm_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
value_free_to_mark (mark);
|
|
|
|
}
|
|
|
|
|
2010-11-30 05:18:16 +08:00
|
|
|
/* Return nonzero if bits in V from OFFSET and LENGTH represent a
|
|
|
|
synthetic pointer. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
lval_func_check_synthetic_pointer (const struct value *v,
|
2016-04-13 03:02:57 +08:00
|
|
|
LONGEST offset, int length)
|
2010-11-30 05:18:16 +08:00
|
|
|
{
|
|
|
|
struct lval_closure *c = (struct lval_closure *) value_computed_closure (v);
|
|
|
|
/* Size of the target type in bits. */
|
|
|
|
int elsize =
|
|
|
|
TYPE_LENGTH (TYPE_TARGET_TYPE (check_typedef (value_type (c->val)))) * 8;
|
|
|
|
int startrest = offset % elsize;
|
|
|
|
int start = offset / elsize;
|
|
|
|
int endrest = (offset + length) % elsize;
|
|
|
|
int end = (offset + length) / elsize;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (endrest)
|
|
|
|
end++;
|
|
|
|
|
|
|
|
if (end > c->n)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = start; i < end; i++)
|
|
|
|
{
|
2011-03-01 02:40:31 +08:00
|
|
|
int comp_offset = (i == start) ? startrest : 0;
|
|
|
|
int comp_length = (i == end) ? endrest : elsize;
|
2010-11-30 05:18:16 +08:00
|
|
|
|
|
|
|
if (!value_bits_synthetic_pointer (c->val,
|
2011-03-01 02:40:31 +08:00
|
|
|
c->indices[i] * elsize + comp_offset,
|
|
|
|
comp_length))
|
2010-11-30 05:18:16 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-11-05 22:31:30 +08:00
|
|
|
static void *
|
|
|
|
lval_func_copy_closure (const struct value *v)
|
|
|
|
{
|
|
|
|
struct lval_closure *c = (struct lval_closure *) value_computed_closure (v);
|
|
|
|
|
|
|
|
++c->refc;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lval_func_free_closure (struct value *v)
|
|
|
|
{
|
|
|
|
struct lval_closure *c = (struct lval_closure *) value_computed_closure (v);
|
|
|
|
|
|
|
|
--c->refc;
|
|
|
|
|
|
|
|
if (c->refc == 0)
|
|
|
|
{
|
2011-03-01 02:31:36 +08:00
|
|
|
value_free (c->val); /* Decrement the reference counter of the value. */
|
2010-11-05 22:31:30 +08:00
|
|
|
xfree (c->indices);
|
|
|
|
xfree (c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-14 23:00:20 +08:00
|
|
|
static const struct lval_funcs opencl_value_funcs =
|
2010-11-05 22:31:30 +08:00
|
|
|
{
|
|
|
|
lval_func_read,
|
|
|
|
lval_func_write,
|
gdb/
Display @entry parameter values even for references.
* ada-valprint.c (ada_val_print_1) <TYPE_CODE_REF>: Try also
coerce_ref_if_computed.
* c-valprint.c (c_val_print) <TYPE_CODE_REF>: Likewise.
* dwarf2expr.c (dwarf_block_to_dwarf_reg_deref): New function.
(execute_stack_op) <DW_OP_GNU_entry_value>: Add -1 deref_size to the
existing push_dwarf_reg_entry_value call. Add new detection calling
dwarf_block_to_dwarf_reg_deref. Update the error message.
(ctx_no_push_dwarf_reg_entry_value): New parameter deref_size.
* dwarf2expr.h
(struct dwarf_expr_context_funcs) <push_dwarf_reg_entry_value>: Add new
parameter deref_size, describe it in the comment.
(ctx_no_push_dwarf_reg_entry_value): Add new parameter deref_size.
(dwarf_block_to_dwarf_reg_deref): New declaration.
* dwarf2loc.c (dwarf_entry_parameter_to_value): Add new parameter
deref_size, describe it in the function comment. New variables
data_src and size, fetch the alternative block accoring to DEREF_SIZE.
(dwarf_expr_push_dwarf_reg_entry_value): Add new parameter deref_size,
describe it in the function comment. Fetch the alternative block
accoring to DEREF_SIZE.
(entry_data_value_coerce_ref, entry_data_value_copy_closure)
(entry_data_value_free_closure, entry_data_value_funcs): New.
(value_of_dwarf_reg_entry): New variables checked_type, target_type,
outer_val, target_val, val and addr. Try to fetch and create also
referenced value content.
(pieced_value_funcs): NULL value for coerce_ref.
(needs_dwarf_reg_entry_value): Add new parameter deref_size.
* f-valprint.c (f_val_print) <TYPE_CODE_REF>: Try also
coerce_ref_if_computed.
* opencl-lang.c (opencl_value_funcs): NULL value for coerce_ref.
* p-valprint.c (pascal_val_print) <TYPE_CODE_REF>: Likewise.
* stack.c (read_frame_arg): Compare also dereferenced values.
* value.c (value_computed_funcs): Make the parameter v const, use
value_lval_const for it.
(value_lval_const, coerce_ref_if_computed): New function.
(coerce_ref): New variable retval. Call also coerce_ref_if_computed.
* value.h (struct lval_funcs): New field coerce_ref.
(value_computed_funcs): Make the parameter v const.
(value_lval_const, coerce_ref_if_computed): New declarations.
gdb/testsuite/
Display @entry parameter values even for references.
* gdb.arch/amd64-entry-value.cc (reference, datap, datap_input): New
functions.
(main): New variables regvar, nodatavarp, stackvar1, stackvar2. Call
reference and datap_input.
* gdb.arch/amd64-entry-value.exp (reference, breakhere_reference): New
breakpoints.
(continue to breakpoint: entry_reference: reference)
(entry_reference: bt at entry)
(continue to breakpoint: entry_reference: breakhere_reference)
(entry_reference: bt, entry_reference: ptype regparam)
(entry_reference: p regparam, entry_reference: ptype regparam@entry)
(entry_reference: p regparam@entry, entry_reference: p ®param@entry)
(entry_reference: p regcopy, entry_reference: p nodataparam)
(entry_reference: p nodataparam@entry): New tests.
2011-10-10 03:43:41 +08:00
|
|
|
NULL, /* indirect */
|
|
|
|
NULL, /* coerce_ref */
|
2010-11-30 05:18:16 +08:00
|
|
|
lval_func_check_synthetic_pointer,
|
2010-11-05 22:31:30 +08:00
|
|
|
lval_func_copy_closure,
|
|
|
|
lval_func_free_closure
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Creates a sub-vector from VAL. The elements are selected by the indices of
|
|
|
|
an array with the length of N. Supported values for NOSIDE are
|
|
|
|
EVAL_NORMAL and EVAL_AVOID_SIDE_EFFECTS. */
|
|
|
|
|
|
|
|
static struct value *
|
|
|
|
create_value (struct gdbarch *gdbarch, struct value *val, enum noside noside,
|
|
|
|
int *indices, int n)
|
|
|
|
{
|
|
|
|
struct type *type = check_typedef (value_type (val));
|
|
|
|
struct type *elm_type = TYPE_TARGET_TYPE (type);
|
|
|
|
struct value *ret;
|
|
|
|
|
|
|
|
/* Check if a single component of a vector is requested which means
|
|
|
|
the resulting type is a (primitive) scalar type. */
|
|
|
|
if (n == 1)
|
|
|
|
{
|
|
|
|
if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
|
|
|
ret = value_zero (elm_type, not_lval);
|
|
|
|
else
|
|
|
|
ret = value_subscript (val, indices[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Multiple components of the vector are requested which means the
|
|
|
|
resulting type is a vector as well. */
|
|
|
|
struct type *dst_type =
|
|
|
|
lookup_opencl_vector_type (gdbarch, TYPE_CODE (elm_type),
|
|
|
|
TYPE_LENGTH (elm_type),
|
|
|
|
TYPE_UNSIGNED (elm_type), n);
|
|
|
|
|
|
|
|
if (dst_type == NULL)
|
|
|
|
dst_type = init_vector_type (elm_type, n);
|
|
|
|
|
|
|
|
make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type), dst_type, NULL);
|
|
|
|
|
|
|
|
if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
|
|
|
ret = allocate_value (dst_type);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Check whether to create a lvalue or not. */
|
|
|
|
if (VALUE_LVAL (val) != not_lval && !array_has_dups (indices, n))
|
|
|
|
{
|
|
|
|
struct lval_closure *c = allocate_lval_closure (indices, n, val);
|
|
|
|
ret = allocate_computed_value (dst_type, &opencl_value_funcs, c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ret = allocate_value (dst_type);
|
|
|
|
|
|
|
|
/* Copy src val contents into the destination value. */
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
memcpy (value_contents_writeable (ret)
|
|
|
|
+ (i * TYPE_LENGTH (elm_type)),
|
|
|
|
value_contents (val)
|
|
|
|
+ (indices[i] * TYPE_LENGTH (elm_type)),
|
|
|
|
TYPE_LENGTH (elm_type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OpenCL vector component access. */
|
|
|
|
|
|
|
|
static struct value *
|
|
|
|
opencl_component_ref (struct expression *exp, struct value *val, char *comps,
|
|
|
|
enum noside noside)
|
|
|
|
{
|
|
|
|
LONGEST lowb, highb;
|
|
|
|
int src_len;
|
|
|
|
struct value *v;
|
|
|
|
int indices[16], i;
|
|
|
|
int dst_len;
|
|
|
|
|
|
|
|
if (!get_array_bounds (check_typedef (value_type (val)), &lowb, &highb))
|
|
|
|
error (_("Could not determine the vector bounds"));
|
|
|
|
|
|
|
|
src_len = highb - lowb + 1;
|
|
|
|
|
|
|
|
/* Throw an error if the amount of array elements does not fit a
|
|
|
|
valid OpenCL vector size (2, 3, 4, 8, 16). */
|
|
|
|
if (src_len != 2 && src_len != 3 && src_len != 4 && src_len != 8
|
|
|
|
&& src_len != 16)
|
|
|
|
error (_("Invalid OpenCL vector size"));
|
|
|
|
|
|
|
|
if (strcmp (comps, "lo") == 0 )
|
|
|
|
{
|
|
|
|
dst_len = (src_len == 3) ? 2 : src_len / 2;
|
|
|
|
|
|
|
|
for (i = 0; i < dst_len; i++)
|
|
|
|
indices[i] = i;
|
|
|
|
}
|
|
|
|
else if (strcmp (comps, "hi") == 0)
|
|
|
|
{
|
|
|
|
dst_len = (src_len == 3) ? 2 : src_len / 2;
|
|
|
|
|
|
|
|
for (i = 0; i < dst_len; i++)
|
|
|
|
indices[i] = dst_len + i;
|
|
|
|
}
|
|
|
|
else if (strcmp (comps, "even") == 0)
|
|
|
|
{
|
|
|
|
dst_len = (src_len == 3) ? 2 : src_len / 2;
|
|
|
|
|
|
|
|
for (i = 0; i < dst_len; i++)
|
|
|
|
indices[i] = i*2;
|
|
|
|
}
|
|
|
|
else if (strcmp (comps, "odd") == 0)
|
|
|
|
{
|
|
|
|
dst_len = (src_len == 3) ? 2 : src_len / 2;
|
|
|
|
|
|
|
|
for (i = 0; i < dst_len; i++)
|
|
|
|
indices[i] = i*2+1;
|
|
|
|
}
|
|
|
|
else if (strncasecmp (comps, "s", 1) == 0)
|
|
|
|
{
|
|
|
|
#define HEXCHAR_TO_INT(C) ((C >= '0' && C <= '9') ? \
|
|
|
|
C-'0' : ((C >= 'A' && C <= 'F') ? \
|
|
|
|
C-'A'+10 : ((C >= 'a' && C <= 'f') ? \
|
|
|
|
C-'a'+10 : -1)))
|
|
|
|
|
|
|
|
dst_len = strlen (comps);
|
|
|
|
/* Skip the s/S-prefix. */
|
|
|
|
dst_len--;
|
|
|
|
|
|
|
|
for (i = 0; i < dst_len; i++)
|
|
|
|
{
|
|
|
|
indices[i] = HEXCHAR_TO_INT(comps[i+1]);
|
|
|
|
/* Check if the requested component is invalid or exceeds
|
|
|
|
the vector. */
|
|
|
|
if (indices[i] < 0 || indices[i] >= src_len)
|
|
|
|
error (_("Invalid OpenCL vector component accessor %s"), comps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dst_len = strlen (comps);
|
|
|
|
|
|
|
|
for (i = 0; i < dst_len; i++)
|
|
|
|
{
|
|
|
|
/* x, y, z, w */
|
|
|
|
switch (comps[i])
|
|
|
|
{
|
|
|
|
case 'x':
|
|
|
|
indices[i] = 0;
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
indices[i] = 1;
|
|
|
|
break;
|
|
|
|
case 'z':
|
|
|
|
if (src_len < 3)
|
|
|
|
error (_("Invalid OpenCL vector component accessor %s"), comps);
|
|
|
|
indices[i] = 2;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
if (src_len < 4)
|
|
|
|
error (_("Invalid OpenCL vector component accessor %s"), comps);
|
|
|
|
indices[i] = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error (_("Invalid OpenCL vector component accessor %s"), comps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Throw an error if the amount of requested components does not
|
|
|
|
result in a valid length (1, 2, 3, 4, 8, 16). */
|
|
|
|
if (dst_len != 1 && dst_len != 2 && dst_len != 3 && dst_len != 4
|
|
|
|
&& dst_len != 8 && dst_len != 16)
|
|
|
|
error (_("Invalid OpenCL vector component accessor %s"), comps);
|
|
|
|
|
|
|
|
v = create_value (exp->gdbarch, val, noside, indices, dst_len);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform the unary logical not (!) operation. */
|
|
|
|
|
|
|
|
static struct value *
|
|
|
|
opencl_logical_not (struct expression *exp, struct value *arg)
|
|
|
|
{
|
|
|
|
struct type *type = check_typedef (value_type (arg));
|
|
|
|
struct type *rettype;
|
|
|
|
struct value *ret;
|
|
|
|
|
|
|
|
if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type))
|
|
|
|
{
|
|
|
|
struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
|
|
|
|
LONGEST lowb, highb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!get_array_bounds (type, &lowb, &highb))
|
|
|
|
error (_("Could not determine the vector bounds"));
|
|
|
|
|
|
|
|
/* Determine the resulting type of the operation and allocate the
|
|
|
|
value. */
|
|
|
|
rettype = lookup_opencl_vector_type (exp->gdbarch, TYPE_CODE_INT,
|
|
|
|
TYPE_LENGTH (eltype), 0,
|
|
|
|
highb - lowb + 1);
|
|
|
|
ret = allocate_value (rettype);
|
|
|
|
|
|
|
|
for (i = 0; i < highb - lowb + 1; i++)
|
|
|
|
{
|
|
|
|
/* For vector types, the unary operator shall return a 0 if the
|
|
|
|
value of its operand compares unequal to 0, and -1 (i.e. all bits
|
|
|
|
set) if the value of its operand compares equal to 0. */
|
|
|
|
int tmp = value_logical_not (value_subscript (arg, i)) ? -1 : 0;
|
|
|
|
memset (value_contents_writeable (ret) + i * TYPE_LENGTH (eltype),
|
|
|
|
tmp, TYPE_LENGTH (eltype));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rettype = language_bool_type (exp->language_defn, exp->gdbarch);
|
|
|
|
ret = value_from_longest (rettype, value_logical_not (arg));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform a relational operation on two scalar operands. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
scalar_relop (struct value *val1, struct value *val2, enum exp_opcode op)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case BINOP_EQUAL:
|
|
|
|
ret = value_equal (val1, val2);
|
|
|
|
break;
|
|
|
|
case BINOP_NOTEQUAL:
|
|
|
|
ret = !value_equal (val1, val2);
|
|
|
|
break;
|
|
|
|
case BINOP_LESS:
|
|
|
|
ret = value_less (val1, val2);
|
|
|
|
break;
|
|
|
|
case BINOP_GTR:
|
|
|
|
ret = value_less (val2, val1);
|
|
|
|
break;
|
|
|
|
case BINOP_GEQ:
|
|
|
|
ret = value_less (val2, val1) || value_equal (val1, val2);
|
|
|
|
break;
|
|
|
|
case BINOP_LEQ:
|
|
|
|
ret = value_less (val1, val2) || value_equal (val1, val2);
|
|
|
|
break;
|
|
|
|
case BINOP_LOGICAL_AND:
|
|
|
|
ret = !value_logical_not (val1) && !value_logical_not (val2);
|
|
|
|
break;
|
|
|
|
case BINOP_LOGICAL_OR:
|
|
|
|
ret = !value_logical_not (val1) || !value_logical_not (val2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error (_("Attempt to perform an unsupported operation"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform a relational operation on two vector operands. */
|
|
|
|
|
|
|
|
static struct value *
|
|
|
|
vector_relop (struct expression *exp, struct value *val1, struct value *val2,
|
|
|
|
enum exp_opcode op)
|
|
|
|
{
|
|
|
|
struct value *ret;
|
|
|
|
struct type *type1, *type2, *eltype1, *eltype2, *rettype;
|
|
|
|
int t1_is_vec, t2_is_vec, i;
|
|
|
|
LONGEST lowb1, lowb2, highb1, highb2;
|
|
|
|
|
|
|
|
type1 = check_typedef (value_type (val1));
|
|
|
|
type2 = check_typedef (value_type (val2));
|
|
|
|
|
|
|
|
t1_is_vec = (TYPE_CODE (type1) == TYPE_CODE_ARRAY && TYPE_VECTOR (type1));
|
|
|
|
t2_is_vec = (TYPE_CODE (type2) == TYPE_CODE_ARRAY && TYPE_VECTOR (type2));
|
|
|
|
|
|
|
|
if (!t1_is_vec || !t2_is_vec)
|
|
|
|
error (_("Vector operations are not supported on scalar types"));
|
|
|
|
|
|
|
|
eltype1 = check_typedef (TYPE_TARGET_TYPE (type1));
|
|
|
|
eltype2 = check_typedef (TYPE_TARGET_TYPE (type2));
|
|
|
|
|
|
|
|
if (!get_array_bounds (type1,&lowb1, &highb1)
|
|
|
|
|| !get_array_bounds (type2, &lowb2, &highb2))
|
|
|
|
error (_("Could not determine the vector bounds"));
|
|
|
|
|
|
|
|
/* Check whether the vector types are compatible. */
|
|
|
|
if (TYPE_CODE (eltype1) != TYPE_CODE (eltype2)
|
|
|
|
|| TYPE_LENGTH (eltype1) != TYPE_LENGTH (eltype2)
|
|
|
|
|| TYPE_UNSIGNED (eltype1) != TYPE_UNSIGNED (eltype2)
|
|
|
|
|| lowb1 != lowb2 || highb1 != highb2)
|
|
|
|
error (_("Cannot perform operation on vectors with different types"));
|
|
|
|
|
|
|
|
/* Determine the resulting type of the operation and allocate the value. */
|
|
|
|
rettype = lookup_opencl_vector_type (exp->gdbarch, TYPE_CODE_INT,
|
|
|
|
TYPE_LENGTH (eltype1), 0,
|
|
|
|
highb1 - lowb1 + 1);
|
|
|
|
ret = allocate_value (rettype);
|
|
|
|
|
|
|
|
for (i = 0; i < highb1 - lowb1 + 1; i++)
|
|
|
|
{
|
|
|
|
/* For vector types, the relational, equality and logical operators shall
|
|
|
|
return 0 if the specified relation is false and -1 (i.e. all bits set)
|
|
|
|
if the specified relation is true. */
|
|
|
|
int tmp = scalar_relop (value_subscript (val1, i),
|
|
|
|
value_subscript (val2, i), op) ? -1 : 0;
|
|
|
|
memset (value_contents_writeable (ret) + i * TYPE_LENGTH (eltype1),
|
|
|
|
tmp, TYPE_LENGTH (eltype1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-26 01:16:43 +08:00
|
|
|
/* Perform a cast of ARG into TYPE. There's sadly a lot of duplication in
|
|
|
|
here from valops.c:value_cast, opencl is different only in the
|
|
|
|
behaviour of scalar to vector casting. As far as possibly we're going
|
|
|
|
to try and delegate back to the standard value_cast function. */
|
|
|
|
|
|
|
|
static struct value *
|
|
|
|
opencl_value_cast (struct type *type, struct value *arg)
|
|
|
|
{
|
|
|
|
if (type != value_type (arg))
|
|
|
|
{
|
|
|
|
/* Casting scalar to vector is a special case for OpenCL, scalar
|
|
|
|
is cast to element type of vector then replicated into each
|
|
|
|
element of the vector. First though, we need to work out if
|
|
|
|
this is a scalar to vector cast; code lifted from
|
|
|
|
valops.c:value_cast. */
|
|
|
|
enum type_code code1, code2;
|
|
|
|
struct type *to_type;
|
|
|
|
int scalar;
|
|
|
|
|
|
|
|
to_type = check_typedef (type);
|
|
|
|
|
|
|
|
code1 = TYPE_CODE (to_type);
|
|
|
|
code2 = TYPE_CODE (check_typedef (value_type (arg)));
|
|
|
|
|
|
|
|
if (code2 == TYPE_CODE_REF)
|
|
|
|
code2 = TYPE_CODE (check_typedef (value_type (coerce_ref (arg))));
|
|
|
|
|
|
|
|
scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL
|
|
|
|
|| code2 == TYPE_CODE_CHAR || code2 == TYPE_CODE_FLT
|
|
|
|
|| code2 == TYPE_CODE_DECFLOAT || code2 == TYPE_CODE_ENUM
|
|
|
|
|| code2 == TYPE_CODE_RANGE);
|
|
|
|
|
|
|
|
if (code1 == TYPE_CODE_ARRAY && TYPE_VECTOR (to_type) && scalar)
|
|
|
|
{
|
|
|
|
struct type *eltype;
|
|
|
|
|
|
|
|
/* Cast to the element type of the vector here as
|
|
|
|
value_vector_widen will error if the scalar value is
|
|
|
|
truncated by the cast. To avoid the error, cast (and
|
|
|
|
possibly truncate) here. */
|
|
|
|
eltype = check_typedef (TYPE_TARGET_TYPE (to_type));
|
|
|
|
arg = value_cast (eltype, arg);
|
|
|
|
|
|
|
|
return value_vector_widen (arg, type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Standard cast handler. */
|
|
|
|
arg = value_cast (type, arg);
|
|
|
|
}
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
2010-11-05 22:31:30 +08:00
|
|
|
/* Perform a relational operation on two operands. */
|
|
|
|
|
|
|
|
static struct value *
|
|
|
|
opencl_relop (struct expression *exp, struct value *arg1, struct value *arg2,
|
|
|
|
enum exp_opcode op)
|
|
|
|
{
|
|
|
|
struct value *val;
|
|
|
|
struct type *type1 = check_typedef (value_type (arg1));
|
|
|
|
struct type *type2 = check_typedef (value_type (arg2));
|
|
|
|
int t1_is_vec = (TYPE_CODE (type1) == TYPE_CODE_ARRAY
|
|
|
|
&& TYPE_VECTOR (type1));
|
|
|
|
int t2_is_vec = (TYPE_CODE (type2) == TYPE_CODE_ARRAY
|
|
|
|
&& TYPE_VECTOR (type2));
|
|
|
|
|
|
|
|
if (!t1_is_vec && !t2_is_vec)
|
|
|
|
{
|
|
|
|
int tmp = scalar_relop (arg1, arg2, op);
|
|
|
|
struct type *type =
|
|
|
|
language_bool_type (exp->language_defn, exp->gdbarch);
|
|
|
|
|
|
|
|
val = value_from_longest (type, tmp);
|
|
|
|
}
|
|
|
|
else if (t1_is_vec && t2_is_vec)
|
|
|
|
{
|
|
|
|
val = vector_relop (exp, arg1, arg2, op);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Widen the scalar operand to a vector. */
|
|
|
|
struct value **v = t1_is_vec ? &arg2 : &arg1;
|
|
|
|
struct type *t = t1_is_vec ? type2 : type1;
|
|
|
|
|
|
|
|
if (TYPE_CODE (t) != TYPE_CODE_FLT && !is_integral_type (t))
|
|
|
|
error (_("Argument to operation not a number or boolean."));
|
|
|
|
|
2013-01-26 01:16:43 +08:00
|
|
|
*v = opencl_value_cast (t1_is_vec ? type1 : type2, *v);
|
2010-11-05 22:31:30 +08:00
|
|
|
val = vector_relop (exp, arg1, arg2, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Expression evaluator for the OpenCL. Most operations are delegated to
|
|
|
|
evaluate_subexp_standard; see that function for a description of the
|
|
|
|
arguments. */
|
|
|
|
|
|
|
|
static struct value *
|
|
|
|
evaluate_subexp_opencl (struct type *expect_type, struct expression *exp,
|
|
|
|
int *pos, enum noside noside)
|
|
|
|
{
|
|
|
|
enum exp_opcode op = exp->elts[*pos].opcode;
|
|
|
|
struct value *arg1 = NULL;
|
|
|
|
struct value *arg2 = NULL;
|
|
|
|
struct type *type1, *type2;
|
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
2013-01-26 01:16:43 +08:00
|
|
|
/* Handle assignment and cast operators to support OpenCL-style
|
|
|
|
scalar-to-vector widening. */
|
|
|
|
case BINOP_ASSIGN:
|
|
|
|
(*pos)++;
|
|
|
|
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
type1 = value_type (arg1);
|
|
|
|
arg2 = evaluate_subexp (type1, exp, pos, noside);
|
|
|
|
|
|
|
|
if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
|
|
|
|
return arg1;
|
|
|
|
|
|
|
|
if (deprecated_value_modifiable (arg1)
|
|
|
|
&& VALUE_LVAL (arg1) != lval_internalvar)
|
|
|
|
arg2 = opencl_value_cast (type1, arg2);
|
|
|
|
|
|
|
|
return value_assign (arg1, arg2);
|
|
|
|
|
|
|
|
case UNOP_CAST:
|
|
|
|
type1 = exp->elts[*pos + 1].type;
|
|
|
|
(*pos) += 2;
|
|
|
|
arg1 = evaluate_subexp (type1, exp, pos, noside);
|
|
|
|
|
|
|
|
if (noside == EVAL_SKIP)
|
|
|
|
return value_from_longest (builtin_type (exp->gdbarch)->
|
|
|
|
builtin_int, 1);
|
|
|
|
|
|
|
|
return opencl_value_cast (type1, arg1);
|
|
|
|
|
|
|
|
case UNOP_CAST_TYPE:
|
|
|
|
(*pos)++;
|
|
|
|
arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
|
|
|
|
type1 = value_type (arg1);
|
|
|
|
arg1 = evaluate_subexp (type1, exp, pos, noside);
|
|
|
|
|
|
|
|
if (noside == EVAL_SKIP)
|
|
|
|
return value_from_longest (builtin_type (exp->gdbarch)->
|
|
|
|
builtin_int, 1);
|
|
|
|
|
|
|
|
return opencl_value_cast (type1, arg1);
|
|
|
|
|
2010-11-05 22:31:30 +08:00
|
|
|
/* Handle binary relational and equality operators that are either not
|
|
|
|
or differently defined for GNU vectors. */
|
|
|
|
case BINOP_EQUAL:
|
|
|
|
case BINOP_NOTEQUAL:
|
|
|
|
case BINOP_LESS:
|
|
|
|
case BINOP_GTR:
|
|
|
|
case BINOP_GEQ:
|
|
|
|
case BINOP_LEQ:
|
|
|
|
(*pos)++;
|
|
|
|
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
|
|
|
|
|
|
|
|
if (noside == EVAL_SKIP)
|
|
|
|
return value_from_longest (builtin_type (exp->gdbarch)->
|
|
|
|
builtin_int, 1);
|
|
|
|
|
|
|
|
return opencl_relop (exp, arg1, arg2, op);
|
|
|
|
|
|
|
|
/* Handle the logical unary operator not(!). */
|
|
|
|
case UNOP_LOGICAL_NOT:
|
|
|
|
(*pos)++;
|
|
|
|
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
|
|
|
|
if (noside == EVAL_SKIP)
|
|
|
|
return value_from_longest (builtin_type (exp->gdbarch)->
|
|
|
|
builtin_int, 1);
|
|
|
|
|
|
|
|
return opencl_logical_not (exp, arg1);
|
|
|
|
|
|
|
|
/* Handle the logical operator and(&&) and or(||). */
|
|
|
|
case BINOP_LOGICAL_AND:
|
|
|
|
case BINOP_LOGICAL_OR:
|
|
|
|
(*pos)++;
|
|
|
|
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
|
|
|
|
if (noside == EVAL_SKIP)
|
|
|
|
{
|
2011-03-01 06:49:57 +08:00
|
|
|
evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
2010-11-05 22:31:30 +08:00
|
|
|
|
|
|
|
return value_from_longest (builtin_type (exp->gdbarch)->
|
|
|
|
builtin_int, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* For scalar operations we need to avoid evaluating operands
|
|
|
|
unecessarily. However, for vector operations we always need to
|
|
|
|
evaluate both operands. Unfortunately we only know which of the
|
|
|
|
two cases apply after we know the type of the second operand.
|
|
|
|
Therefore we evaluate it once using EVAL_AVOID_SIDE_EFFECTS. */
|
|
|
|
int oldpos = *pos;
|
|
|
|
|
2011-01-11 04:38:51 +08:00
|
|
|
arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
|
|
|
|
EVAL_AVOID_SIDE_EFFECTS);
|
2010-11-05 22:31:30 +08:00
|
|
|
*pos = oldpos;
|
|
|
|
type1 = check_typedef (value_type (arg1));
|
|
|
|
type2 = check_typedef (value_type (arg2));
|
|
|
|
|
|
|
|
if ((TYPE_CODE (type1) == TYPE_CODE_ARRAY && TYPE_VECTOR (type1))
|
|
|
|
|| (TYPE_CODE (type2) == TYPE_CODE_ARRAY && TYPE_VECTOR (type2)))
|
|
|
|
{
|
|
|
|
arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
|
|
|
|
return opencl_relop (exp, arg1, arg2, op);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* For scalar built-in types, only evaluate the right
|
|
|
|
hand operand if the left hand operand compares
|
|
|
|
unequal(&&)/equal(||) to 0. */
|
|
|
|
int res;
|
|
|
|
int tmp = value_logical_not (arg1);
|
|
|
|
|
|
|
|
if (op == BINOP_LOGICAL_OR)
|
|
|
|
tmp = !tmp;
|
|
|
|
|
|
|
|
arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
|
|
|
|
tmp ? EVAL_SKIP : noside);
|
|
|
|
type1 = language_bool_type (exp->language_defn, exp->gdbarch);
|
|
|
|
|
|
|
|
if (op == BINOP_LOGICAL_AND)
|
|
|
|
res = !tmp && !value_logical_not (arg2);
|
|
|
|
else /* BINOP_LOGICAL_OR */
|
|
|
|
res = tmp || !value_logical_not (arg2);
|
|
|
|
|
|
|
|
return value_from_longest (type1, res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle the ternary selection operator. */
|
|
|
|
case TERNOP_COND:
|
|
|
|
(*pos)++;
|
|
|
|
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
type1 = check_typedef (value_type (arg1));
|
|
|
|
if (TYPE_CODE (type1) == TYPE_CODE_ARRAY && TYPE_VECTOR (type1))
|
|
|
|
{
|
|
|
|
struct value *arg3, *tmp, *ret;
|
|
|
|
struct type *eltype2, *type3, *eltype3;
|
|
|
|
int t2_is_vec, t3_is_vec, i;
|
|
|
|
LONGEST lowb1, lowb2, lowb3, highb1, highb2, highb3;
|
|
|
|
|
|
|
|
arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
arg3 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
type2 = check_typedef (value_type (arg2));
|
|
|
|
type3 = check_typedef (value_type (arg3));
|
|
|
|
t2_is_vec
|
|
|
|
= TYPE_CODE (type2) == TYPE_CODE_ARRAY && TYPE_VECTOR (type2);
|
|
|
|
t3_is_vec
|
|
|
|
= TYPE_CODE (type3) == TYPE_CODE_ARRAY && TYPE_VECTOR (type3);
|
|
|
|
|
|
|
|
/* Widen the scalar operand to a vector if necessary. */
|
|
|
|
if (t2_is_vec || !t3_is_vec)
|
|
|
|
{
|
2013-01-26 01:16:43 +08:00
|
|
|
arg3 = opencl_value_cast (type2, arg3);
|
2010-11-05 22:31:30 +08:00
|
|
|
type3 = value_type (arg3);
|
|
|
|
}
|
|
|
|
else if (!t2_is_vec || t3_is_vec)
|
|
|
|
{
|
2013-01-26 01:16:43 +08:00
|
|
|
arg2 = opencl_value_cast (type3, arg2);
|
2010-11-05 22:31:30 +08:00
|
|
|
type2 = value_type (arg2);
|
|
|
|
}
|
|
|
|
else if (!t2_is_vec || !t3_is_vec)
|
|
|
|
{
|
|
|
|
/* Throw an error if arg2 or arg3 aren't vectors. */
|
|
|
|
error (_("\
|
|
|
|
Cannot perform conditional operation on incompatible types"));
|
|
|
|
}
|
|
|
|
|
|
|
|
eltype2 = check_typedef (TYPE_TARGET_TYPE (type2));
|
|
|
|
eltype3 = check_typedef (TYPE_TARGET_TYPE (type3));
|
|
|
|
|
|
|
|
if (!get_array_bounds (type1, &lowb1, &highb1)
|
|
|
|
|| !get_array_bounds (type2, &lowb2, &highb2)
|
|
|
|
|| !get_array_bounds (type3, &lowb3, &highb3))
|
|
|
|
error (_("Could not determine the vector bounds"));
|
|
|
|
|
|
|
|
/* Throw an error if the types of arg2 or arg3 are incompatible. */
|
|
|
|
if (TYPE_CODE (eltype2) != TYPE_CODE (eltype3)
|
|
|
|
|| TYPE_LENGTH (eltype2) != TYPE_LENGTH (eltype3)
|
|
|
|
|| TYPE_UNSIGNED (eltype2) != TYPE_UNSIGNED (eltype3)
|
|
|
|
|| lowb2 != lowb3 || highb2 != highb3)
|
|
|
|
error (_("\
|
|
|
|
Cannot perform operation on vectors with different types"));
|
|
|
|
|
|
|
|
/* Throw an error if the sizes of arg1 and arg2/arg3 differ. */
|
|
|
|
if (lowb1 != lowb2 || lowb1 != lowb3
|
|
|
|
|| highb1 != highb2 || highb1 != highb3)
|
|
|
|
error (_("\
|
|
|
|
Cannot perform conditional operation on vectors with different sizes"));
|
|
|
|
|
|
|
|
ret = allocate_value (type2);
|
|
|
|
|
|
|
|
for (i = 0; i < highb1 - lowb1 + 1; i++)
|
|
|
|
{
|
|
|
|
tmp = value_logical_not (value_subscript (arg1, i)) ?
|
|
|
|
value_subscript (arg3, i) : value_subscript (arg2, i);
|
|
|
|
memcpy (value_contents_writeable (ret) +
|
|
|
|
i * TYPE_LENGTH (eltype2), value_contents_all (tmp),
|
|
|
|
TYPE_LENGTH (eltype2));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (value_logical_not (arg1))
|
|
|
|
{
|
|
|
|
/* Skip the second operand. */
|
|
|
|
evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
|
|
|
|
|
|
|
|
return evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Skip the third operand. */
|
|
|
|
arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
|
|
|
|
|
|
|
|
return arg2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle STRUCTOP_STRUCT to allow component access on OpenCL vectors. */
|
|
|
|
case STRUCTOP_STRUCT:
|
|
|
|
{
|
|
|
|
int pc = (*pos)++;
|
|
|
|
int tem = longest_to_int (exp->elts[pc + 1].longconst);
|
|
|
|
|
|
|
|
(*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
|
|
|
|
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
|
|
|
type1 = check_typedef (value_type (arg1));
|
|
|
|
|
|
|
|
if (noside == EVAL_SKIP)
|
|
|
|
{
|
|
|
|
return value_from_longest (builtin_type (exp->gdbarch)->
|
|
|
|
builtin_int, 1);
|
|
|
|
}
|
|
|
|
else if (TYPE_CODE (type1) == TYPE_CODE_ARRAY && TYPE_VECTOR (type1))
|
|
|
|
{
|
|
|
|
return opencl_component_ref (exp, arg1, &exp->elts[pc + 2].string,
|
|
|
|
noside);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-14 00:51:52 +08:00
|
|
|
struct value *v = value_struct_elt (&arg1, NULL,
|
|
|
|
&exp->elts[pc + 2].string, NULL,
|
|
|
|
"structure");
|
|
|
|
|
|
|
|
if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
2016-05-24 23:53:58 +08:00
|
|
|
v = value_zero (value_type (v), VALUE_LVAL (v));
|
2013-05-14 00:51:52 +08:00
|
|
|
return v;
|
2010-11-05 22:31:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return evaluate_subexp_c (expect_type, exp, pos, noside);
|
|
|
|
}
|
|
|
|
|
2012-11-30 02:56:23 +08:00
|
|
|
/* Print OpenCL types. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
opencl_print_type (struct type *type, const char *varstring,
|
|
|
|
struct ui_file *stream, int show, int level,
|
|
|
|
const struct type_print_options *flags)
|
|
|
|
{
|
|
|
|
/* We nearly always defer to C type printing, except that vector
|
|
|
|
types are considered primitive in OpenCL, and should always
|
|
|
|
be printed using their TYPE_NAME. */
|
|
|
|
if (show > 0)
|
|
|
|
{
|
2015-07-07 04:05:06 +08:00
|
|
|
type = check_typedef (type);
|
2012-11-30 02:56:23 +08:00
|
|
|
if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type)
|
|
|
|
&& TYPE_NAME (type) != NULL)
|
|
|
|
show = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
c_print_type (type, varstring, stream, show, level, flags);
|
|
|
|
}
|
|
|
|
|
2012-03-01 Pedro Alves <palves@redhat.com>
* amd64-linux-tdep.c (amd64_linux_record_signal): Make static.
* breakpoint.c (create_exception_master_breakpoint, trace_command)
(ftrace_command, strace_command): Make static.
* d-lang.c (_initialize_d_language): Declare.
* dwarf2expr.c (_initialize_dwarf2expr): Declare.
* dwarf2loc.c (_initialize_dwarf2loc):
* dwarf2read.c (process_psymtab_comp_unit): Make static.
* exec.c (exec_get_section_table): Make static.
* i386-linux-tdep.c (i386_linux_record_signal): Make static.
* infcmd.c (ensure_valid_thread, ensure_not_tfind_mode): Make static.
* inferior.c (remove_inferior_command, add_inferior_command)
(clone_inferior_command): Make static.
* linux-nat.c (linux_nat_thread_address_space)
(linux_nat_core_of_thread): Make static.
* linux-tdep.c (_initialize_linux_tdep): Declare.
* objc-lang.c (_initialize_objc_lang): Declare.
* opencl-lang.c (builtin_opencl_type, opencl_language_arch_info):
Make static.
(_initialize_opencl_language): Declare.
* record.c (_initialize_record): Declare.
* remote.c (demand_private_info, remote_get_tib_address)
(remote_supports_cond_tracepoints)
(remote_supports_fast_tracepoints, remote_get_tracepoint_status):
Make static.
* skip.c (_initialize_step_skip): Declare.
* symtab.c (skip_prologue_using_lineinfo): Make static.
* tracepoint.c (delete_trace_state_variable)
(trace_variable_command, delete_trace_variable_command)
(get_uploaded_tsv, find_matching_tracepoint_location)
(find_matching_tsv, create_tsv_from_upload, get_traceframe_info):
Make static.
* value.c (pack_unsigned_long): Make static.
* varobj.c (varobj_ensure_python_env): Make static.
* windows-tdep.c (_initialize_windows_tdep): Declare.
* xml-syscall.c (make_cleanup_free_syscalls_info): Make static.
2012-03-02 05:14:00 +08:00
|
|
|
static void
|
2010-11-05 22:31:30 +08:00
|
|
|
opencl_language_arch_info (struct gdbarch *gdbarch,
|
2011-02-21 23:53:10 +08:00
|
|
|
struct language_arch_info *lai)
|
2010-11-05 22:31:30 +08:00
|
|
|
{
|
2011-02-21 23:53:10 +08:00
|
|
|
struct type **types = builtin_opencl_type (gdbarch);
|
2010-11-05 22:31:30 +08:00
|
|
|
|
2011-02-21 23:53:10 +08:00
|
|
|
/* Copy primitive types vector from gdbarch. */
|
|
|
|
lai->primitive_type_vector = types;
|
2010-11-05 22:31:30 +08:00
|
|
|
|
2011-02-21 23:53:10 +08:00
|
|
|
/* Type of elements of strings. */
|
|
|
|
lai->string_char_type = types [opencl_primitive_type_char];
|
2010-11-05 22:31:30 +08:00
|
|
|
|
|
|
|
/* Specifies the return type of logical and relational operations. */
|
|
|
|
lai->bool_type_symbol = "int";
|
2011-02-21 23:53:10 +08:00
|
|
|
lai->bool_type_default = types [opencl_primitive_type_int];
|
2010-11-05 22:31:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct exp_descriptor exp_descriptor_opencl =
|
|
|
|
{
|
|
|
|
print_subexp_standard,
|
|
|
|
operator_length_standard,
|
|
|
|
operator_check_standard,
|
|
|
|
op_name_standard,
|
|
|
|
dump_subexp_body_standard,
|
|
|
|
evaluate_subexp_opencl
|
|
|
|
};
|
|
|
|
|
Make language_def O(1)
Profiling GDB with the rest of series applied, I saw calls to
language_def showing up high in some runs. The problem is that
language_def is O(N) currently, since walk the languages vector each
time to find the matching language_defn.
IMO, the add_language mechanism is pointless, because "enum language"
implies the core of GDB needs to know about all languages anyway. So
simply make the languages vector array be an array where each
element's index is the corresponding enum language enumerator. Note
that "local_language_defn" is gone along the way. It's just a copy of
"auto", so the new code simply maps one to the other. One fewer place
to update when we need to change the language vector...
Also, a while ago the output of "set language" was made out of order
as side effect of some other change. While I was at it, I made them
sorted again.
gdb/ChangeLog:
2017-07-20 Pedro Alves <palves@redhat.com>
* ada-lang.c (ada_language_defn): Make extern.
(_initialize_ada_language): Remove add_language call.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Make extern.
(_initialize_c_language): Delete.
* completer.c (compare_cstrings): Delete, moved to utils.h.
* d-lang.c (d_language_defn): Make extern.
(_initialize_d_language): Remove add_language calls.
* defs.h (enum language): Add comment.
* f-lang.c (f_language_defn): Make extern.
(_initialize_f_language): Remove add_language call.
* go-lang.c (go_language_defn): Make extern.
(_initialize_go_language): Remove add_language call.
* language.c: Include <algorithm>.
(languages): Redefine as const array.
(languages_size, languages_allocsize, DEFAULT_ALLOCSIZE): Delete.
(set_language_command): Handle "local". Use for-range loop.
(set_language): Remove loop.
(language_enum): Rewrite.
(language_def, language_str): Remove loops.
(add_language): Delete.
(add_set_language_command): New, based on add_languages.
(skip_language_trampoline): Adjust.
(local_language_defn): Delete.
(language_gdbarch_post_init): Adjust.
(_initialize_language): Remove add_language calls. Call
add_set_language_command.
* language.h (add_language): Delete.
(auto_language_defn)
(unknown_language_defn, minimal_language_defn, ada_language_defn)
(asm_language_defn, c_language_defn, cplus_language_defn)
(d_language_defn, f_language_defn, go_language_defn)
(m2_language_defn, objc_language_defn, opencl_language_defn)
(pascal_language_defn, rust_language_defn): Declare.
* m2-lang.c (m2_language_defn): Make extern.
(_initialize_m2_language): Remove add_language call.
* objc-lang.c (objc_language_defn): Make extern.
(_initialize_objc_language): Remove add_language call.
* opencl-lang.c (opencl_language_defn): Make extern.
(_initialize_opencl_language): Remove add_language call.
* p-lang.c (pascal_language_defn): Make extern.
(_initialize_pascal_language): Delete.
* rust-lang.c (rust_language_defn): Make extern.
(_initialize_rust_language): Delete.
* utils.h (compare_cstrings): New static inline function.
gdb/testsuite/ChangeLog:
2017-07-20 Pedro Alves <palves@redhat.com>
* gdb.base/default.exp (set language): Adjust expected output.
2017-07-21 01:28:01 +08:00
|
|
|
extern const struct language_defn opencl_language_defn =
|
2010-11-05 22:31:30 +08:00
|
|
|
{
|
|
|
|
"opencl", /* Language name */
|
2013-10-26 16:00:11 +08:00
|
|
|
"OpenCL C",
|
2010-11-05 22:31:30 +08:00
|
|
|
language_opencl,
|
|
|
|
range_check_off,
|
|
|
|
case_sensitive_on,
|
|
|
|
array_row_major,
|
|
|
|
macro_expansion_c,
|
2016-05-27 00:33:28 +08:00
|
|
|
NULL,
|
2010-11-05 22:31:30 +08:00
|
|
|
&exp_descriptor_opencl,
|
|
|
|
c_parse,
|
Centralize yacc interface names remapping (yyparse, yylex, yyerror, etc)
This factors out all the yy-variables remapping to a single file,
instead of each parser having to do the same, with different prefixes.
With this, a parser just needs to define the prefix they want and
include yy-remap.h, which does the dirty job.
Note this renames the c_error, ada_error, etc. functions. Writing the
remapping pattern as:
#define yyerror GDB_YY_REMAP (error)
instead of:
#define yyerror GDB_YY_REMAP (yyerror)
would have avoided the renaming. However, that would be problematic
if we have a macro 'foo' in scope, when we write:
#define yyfoo GDB_YY_REMAP (foo)
as that would expand 'foo'.
The c_yyerror etc. naming end ups indicating that this is a yacc
related function more clearly, so feels like a good change, anyway.
gdb/ChangeLog:
2016-04-22 Pedro Alves <palves@redhat.com>
* ada-exp.y: Remove all yy symbol remappings.
(GDB_YY_REMAP_PREFIX): Define.
Include "yy-remap.h".
* ada-lang.c (ada_language_defn): Adjust.
* ada-lang.h (ada_error): Rename to ...
(ada_yyerror): ... this.
* c-exp.y: Remove all yy symbol remappings.
(GDB_YY_REMAP_PREFIX): Define.
Include "yy-remap.h".
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Adjust.
* c-lang.h (c_error): Rename to ...
(c_yyerror): ... this.
* d-exp.y: Remove all yy symbol remappings.
(GDB_YY_REMAP_PREFIX): Define.
Include "yy-remap.h".
* d-lang.c (d_language_defn): Adjust.
* d-lang.h (d_error): Rename to ...
(d_yyerror): ... this.
* f-exp.y: Remove all yy symbol remappings.
(GDB_YY_REMAP_PREFIX): Define.
Include "yy-remap.h".
* f-lang.c (f_language_defn): Adjust.
* f-lang.h (f_error): Rename to ...
(f_yyerror): ... this.
* go-exp.y: Remove all yy symbol remappings.
(GDB_YY_REMAP_PREFIX): Define.
Include "yy-remap.h".
* go-lang.c (go_language_defn): Adjust.
* go-lang.h (go_error): Rename to ...
(go_yyerror): ... this.
* jv-exp.y: Remove all yy symbol remappings.
(GDB_YY_REMAP_PREFIX): Define.
Include "yy-remap.h".
* jv-lang.c (java_language_defn): Adjust.
* jv-lang.h (java_error): Rename to ...
(java_yyerror): ... this.
* m2-exp.y: Remove all yy symbol remappings.
(GDB_YY_REMAP_PREFIX): Define.
Include "yy-remap.h".
* m2-lang.c (m2_language_defn): Adjust.
* m2-lang.h (m2_error): Rename to ...
(m2_yyerror): ... this.
* objc-exp.y: Remove all yy symbol remappings.
(GDB_YY_REMAP_PREFIX): Define.
Include "yy-remap.h".
* objc-lang.c (objc_language_defn): Adjust.
* opencl-lang.c (opencl_language_defn): Adjust.
* p-exp.y: Remove all yy symbol remappings.
(GDB_YY_REMAP_PREFIX): Define.
Include "yy-remap.h".
* p-lang.c (pascal_language_defn): Adjust.
* p-lang.h (pascal_error): Rename to ...
(pascal_yyerror): ... this.
* yy-remap.h: New file.
2016-04-22 23:40:33 +08:00
|
|
|
c_yyerror,
|
2010-11-05 22:31:30 +08:00
|
|
|
null_post_parser,
|
|
|
|
c_printchar, /* Print a character constant */
|
|
|
|
c_printstr, /* Function to print string constant */
|
|
|
|
c_emit_char, /* Print a single char */
|
2012-11-30 02:56:23 +08:00
|
|
|
opencl_print_type, /* Print a type using appropriate syntax */
|
2010-11-05 22:31:30 +08:00
|
|
|
c_print_typedef, /* Print a typedef using appropriate syntax */
|
|
|
|
c_val_print, /* Print a value using appropriate syntax */
|
|
|
|
c_value_print, /* Print a top-level value */
|
language-specific read_var_value for Ada renamings
The purpose of this patch is to better support renamings in the
"info locals" command. Consider ...
procedure Foo is
GV : Integer renames Pck.Global_Variable;
begin
Increment (GV); -- STOP
end Foo;
... Pck.Global_Variable is just an integer. After having stopped at
the "STOP" line, "info locals" yields:
(gdb) info locals
gv = <error reading variable gv (Cannot access memory at address 0xffffffffffffffff)>
In reality, two things are happening:
(1) Variable "GV" does not exist, which is normal, since there is
"GV" the renaming of another variable;
(2) But to allow the user access to that renaming the same way
the code has, the compiler produces an artificial variable
whose name encodes the renaming:
gv___XR_pck__global_variable___XE
For practical reasons, the artificial variable itself is given
irrelevant types and addresses.
But the "info locals" command does not act as if it was a short-cut
of "foreach VAR in locals, print VAR". Instead it gets the value of
each VAR directly, which does not work in this case, since the variable
is artificial and needs to be decoded first.
This patch makes the "read_var_value" routine language-specific.
The old implementation of "read_var_value" gets renamed to
"default_read_var_value" and all languages now use it (unchanged
behavior), except for Ada. In Ada, the new function ada_read_var_value
checks if we have a renaming, and if so, evaluates its value, or else
defers to default_read_var_value.
gdb/ChangeLog:
* language.h (struct language_defn): New "method" la_read_var_value.
* findvar.c: #include "language.h".
(default_read_var_value): Renames read_var_value. Rewrite
function description.
(read_var_value): New function.
* value.h (default_read_var_value): Add prototype.
* ada-lang.c (ada_read_renaming_var_value, ada_read_var_value):
New functions.
(ada_language_defn): Add entry for la_read_var_value.
* c-lang.c, d-lang.c, f-lang.c, jv-lang.c, language.c,
* m2-lang.c, objc-lang.c, opencl-lang.c, p-lang.c: Update
language_defn structures to add entry for new la_read_var_value
field.
2012-03-03 03:29:01 +08:00
|
|
|
default_read_var_value, /* la_read_var_value */
|
2010-11-05 22:31:30 +08:00
|
|
|
NULL, /* Language specific skip_trampoline */
|
|
|
|
NULL, /* name_of_this */
|
|
|
|
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
|
|
|
|
basic_lookup_transparent_type,/* lookup_transparent_type */
|
|
|
|
NULL, /* Language specific symbol demangler */
|
2016-05-27 05:04:07 +08:00
|
|
|
NULL,
|
2011-01-11 04:38:51 +08:00
|
|
|
NULL, /* Language specific
|
|
|
|
class_name_from_physname */
|
2010-11-05 22:31:30 +08:00
|
|
|
c_op_print_tab, /* expression operators for printing */
|
|
|
|
1, /* c-style arrays */
|
|
|
|
0, /* String lower bound */
|
|
|
|
default_word_break_characters,
|
Introduce class completion_tracker & rewrite completion<->readline interaction
This patch reworks the whole completion machinery, and prepares it
for later enhancements.
Adds a new "completion_tracker" class that is meant to hold everything
about the state of the current completion operation.
This class now has the responsibility of tracking the list of
completion matches, and checking whether the max completions limit has
been reached. You can look at this as this patch starting out by
C++fying the existing "completion_tracker" in symtab.c (it's just an
htab_t typedef currently), moving it to completer.h/c, and then making
it a class/generalizing/enhancing it.
Unlike with the current tracking, completion_tracker now checks
whether the limit has been reached on each completion match list
insertion. This both simplifies the max-completions handling code
(maybe_add_completion_enum is gone, for example), and is a
prerequisite for follow up patches.
The current completion_tracker is only used for symbol completions,
and the symbol code gets at the current instance via globals. This
patch cleans that up by adding a completion_tracker reference to the
signature of the completion functions, and passing the tracker around
everywhere necessary.
Then, the patch changes how the completion match list is handed over
to readline. Currently, we're using the rl_completion_entry_function
readline entry point, and the patch switches to
rl_attempted_completion_function. A following patch will want to let
GDB itself decide the common completion prefix between all matches
(what readline calls the "lowest common denominator"), instead of
having readline compute it, and that's not possible with the
rl_completion_entry_function entry point. Also,
rl_attempted_completion_function lets GDB hand over the match list to
readline as an array in one go instead of passing down matches one by
one, so from that angle it's a nicer entry point anyway.
Lastly, the patch catches exceptions around the readline entry points,
because we can't let C++ exceptions cross readline. We handle that in
the readline input entry point, but the completion entry point isn't
guarded, so GDB can abort if completion throws. E.g., in current
master:
(gdb) b -function "fun<tab>
terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
Aborted (core dumped)
This patch fixes that. This will be exercised in the new tests added
later on in the series.
gdb/ChangeLog:
2017-07-17 Pedro Alves <palves@redhat.com>
* ada-lang.c (symbol_completion_match): Adjust comments.
(symbol_completion_add): Replace vector parameter with
completion_tracker parameter. Use it.
(ada_make_symbol_completion_list): Rename to...
(ada_collect_symbol_completion_matches): ... this. Add
completion_tracker parameter and use it.
(ada_language_defn): Adjust.
* break-catch-syscall.c (catch_syscall_completer): Adjust
prototype and work with completion_tracker instead of VEC.
* breakpoint.c (condition_completer): Adjust prototype and work
with completion_tracker instead of VEC.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Adjust to renames.
* cli/cli-cmds.c (complete_command): Rework using
completion_tracker. Catch exceptions when completing.
* cli/cli-decode.c (integer_unlimited_completer)
(complete_on_cmdlist, complete_on_enum): Adjust prototype and work
with completion_tracker instead of VEC.
* command.h (struct completion_tracker): Forward declare.
(completer_ftype, completer_handle_brkchars_ftype): Change
types.
(complete_on_cmdlist, complete_on_enum): Adjust.
* completer.c: Include <algorithm>.
(struct gdb_completer_state): New.
(current_completion): New global.
(readline_line_completion_function): Delete.
(noop_completer, filename_completer)
(filename_completer_handle_brkchars, complete_files_symbols)
(linespec_location_completer): Adjust to work with a
completion_tracker instead of a VEC.
(string_or_empty): New.
(collect_explicit_location_matches): Adjust to work with a
completion_tracker instead of a VEC.
(explicit_location_completer): Rename to ...
(complete_explicit_location): ... this and adjust to work with a
completion_tracker instead of a VEC.
(location_completer): Adjust to work with a completion_tracker
instead of a VEC.
(add_struct_fields): Adjust to work with a completion_list instead
of VEC.
(expression_completer): Rename to ...
(complete_expression): ... this and adjust to work with a
completion_tracker instead of a VEC. Use complete_files_symbols.
(expression_completer): Reimplement on top of complete_expression.
(symbol_completer): Adjust to work with a completion_tracker
instead of a VEC.
(enum complete_line_internal_reason): Add describing comments.
(complete_line_internal_normal_command): Adjust to work with a
completion_tracker instead of a VEC.
(complete_line_internal): Rename to ...
(complete_line_internal_1): ... this and adjust to work with a
completion_tracker instead of a VEC. Assert TEXT is NULL in the
handle_brkchars phase.
(new_completion_tracker): Delete.
(complete_line_internal): Reimplement as TRY/CATCH wrapper around
complete_line_internal_1.
(free_completion_tracker): Delete.
(INITIAL_COMPLETION_HTAB_SIZE): New.
(completion_tracker::completion_tracker)
(completion_tracker::~completion_tracker): New.
(maybe_add_completion): Delete.
(completion_tracker::maybe_add_completion)
(completion_tracker::add_completion)
(completion_tracker::add_completions): New.
(throw_max_completions_reached_error): Delete.
(complete_line): Adjust to work with a completion_tracker instead
of a VEC. Don't create a completion_tracker_t or check for max
completions here.
(command_completer, command_completer_handle_brkchars)
(signal_completer, reg_or_group_completer_1)
(reg_or_group_completer, default_completer_handle_brkchars):
Adjust to work with a completion_tracker.
(gdb_completion_word_break_characters_throw): New.
(gdb_completion_word_break_characters): Reimplement.
(line_completion_function): Delete.
(completion_tracker::recompute_lowest_common_denominator)
(expand_preserving_ws)
(completion_tracker::build_completion_result)
(completion_result::completion_result)
(completion_result::completion_result)
(completion_result::~completion_result)
(completion_result::completion_result)
(completion_result::release_match_list, compare_cstrings)
(completion_result::sort_match_list)
(completion_result::reset_match_list)
(gdb_rl_attempted_completion_function_throw)
(gdb_rl_attempted_completion_function): New.
* completer.h (completion_list, struct completion_result)
(class completion_tracker): New.
(complete_line): Add completion_tracker parameter.
(readline_line_completion_function): Delete.
(gdb_rl_attempted_completion_function): New.
(noop_completer, filename_completer, expression_completer)
(location_completer, symbol_completer, command_completer)
(signal_completer, reg_or_group_completer): Update prototypes.
(completion_tracker_t, new_completion_tracker)
(make_cleanup_free_completion_tracker): Delete.
(enum maybe_add_completion_enum): Delete.
(maybe_add_completion): Delete.
(throw_max_completions_reached_error): Delete.
* corefile.c (complete_set_gnutarget): Adjust to work with a
completion_tracker instead of a VEC.
* cp-abi.c (cp_abi_completer): Adjust to work with a
completion_tracker instead of a VEC.
* d-lang.c (d_language_defn): Adjust.
* disasm.c (disassembler_options_completer): Adjust to work with a
completion_tracker instead of a VEC.
* f-lang.c (f_make_symbol_completion_list): Rename to ...
(f_collect_symbol_completion_matches): ... this. Adjust to work
with a completion_tracker instead of a VEC.
(f_language_defn): Adjust.
* go-lang.c (go_language_defn): Adjust.
* guile/scm-cmd.c (cmdscm_add_completion, cmdscm_completer):
Adjust to work with a completion_tracker instead of a VEC.
* infrun.c (handle_completer): Likewise.
* interps.c (interpreter_completer): Likewise.
* interps.h (interpreter_completer): Likewise.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Adjust.
* language.h (language_defn::la_make_symbol_completion_list):
Rename to ...
(language_defn::la_collect_symbol_completion_matches): ... this
and adjust to work with a completion_tracker instead of a VEC.
* m2-lang.c (m2_language_defn): Adjust.
* objc-lang.c (objc_language_defn): Adjust.
* opencl-lang.c (opencl_language_defn): Adjust.
* p-lang.c (pascal_language_defn): Adjust.
* python/py-cmd.c (cmdpy_completer_helper): Handle NULL word.
(cmdpy_completer_handle_brkchars, cmdpy_completer): Adjust to work
with a completion_tracker.
* rust-lang.c (rust_language_defn): Adjust.
* symtab.c (free_completion_list, do_free_completion_list)
(return_val, completion_tracker): Delete.
(completion_list_add_name, completion_list_add_symbol)
(completion_list_add_msymbol, completion_list_objc_symbol)
(completion_list_add_fields, add_symtab_completions): Add
completion_tracker parameter and use it.
(default_make_symbol_completion_list_break_on_1): Rename to...
(default_collect_symbol_completion_matches_break_on): ... this.
Add completion_tracker parameter and use it instead of allocating
a completion tracker here.
(default_make_symbol_completion_list_break_on): Delete old
implementation.
(default_make_symbol_completion_list): Delete.
(default_collect_symbol_completion_matches): New.
(make_symbol_completion_list): Delete.
(collect_symbol_completion_matches): New.
(make_symbol_completion_type): Rename to ...
(collect_symbol_completion_matches_type): ... this. Add
completion_tracker parameter and use it instead of VEC.
(make_file_symbol_completion_list_1): Rename to...
(collect_file_symbol_completion_matches): ... this. Add
completion_tracker parameter and use it instead of VEC.
(make_file_symbol_completion_list): Delete.
(add_filename_to_list): Use completion_list instead of a VEC.
(add_partial_filename_data::list): Now a completion_list.
(make_source_files_completion_list): Work with a completion_list
instead of a VEC.
* symtab.h: Include "completer.h".
(default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_type, make_file_symbol_completion_list)
(make_source_files_completion_list): Delete.
(default_collect_symbol_completion_matches_break_on)
(default_collect_symbol_completion_matches)
(collect_symbol_completion_matches)
(collect_symbol_completion_matches_type)
(collect_file_symbol_completion_matches)
(make_source_files_completion_list): New.
* top.c (init_main): Don't install a rl_completion_entry_function
hook. Install a rl_attempted_completion_function hook instead.
* tui/tui-layout.c (layout_completer): Adjust to work with a
completion_tracker.
* tui/tui-regs.c (tui_reggroup_completer):
* tui/tui-win.c (window_name_completer, focus_completer)
(winheight_completer): Adjust to work with a completion_tracker.
* value.c: Include "completer.h".
(complete_internalvar): Adjust to work with a completion_tracker.
* value.h (complete_internalvar): Likewise.
2017-07-17 21:45:59 +08:00
|
|
|
default_collect_symbol_completion_matches,
|
2010-11-05 22:31:30 +08:00
|
|
|
opencl_language_arch_info,
|
|
|
|
default_print_array_index,
|
|
|
|
default_pass_by_reference,
|
|
|
|
c_get_string,
|
Use watchpoint's language when re-parsing expression
PR rust/21484 notes that watch -location does not work with Rust:
(gdb) watch -location a
syntax error in expression, near `) 0x00007fffffffe0f4'.
update_watchpoint tries to tell gdb that the new expression it creates
has C syntax:
/* The above expression is in C. */
b->language = language_c;
However, update_watchpoint doesn't actually use this language when
re-parsing the expression.
Originally I was going to fix this by saving and restoring the
language in update_watchpoint, but this regressed
gdb.dlang/watch-loc.exp, because the constructed expression actually
has D syntax (specifically the name is not parseable by C).
Next I looked at directly constructing an expression, and not relying
on the parser at all; but it seemed to me that upon a re-set, we'd
want to reparse the type, and there is no existing API to do this
correctly.
So, in the end I made a hook to let each language choose what
expression to use. I made all the languages other than Rust use the C
expression, because that is the status quo ante. However, this is
probably not truly correct. After this patch, at least, it is easy to
correct by someone who knows the language(s) in question.
Regtested by the buildbot.
ChangeLog
2017-05-19 Tom Tromey <tom@tromey.com>
PR rust/21484:
* rust-lang.c (exp_descriptor_rust): New function.
(rust_language_defn): Use it.
* 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_watch_location_expression>: New member.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Update.
* go-lang.c (go_language_defn): Update.
* f-lang.c (f_language_defn): Update.
* d-lang.c (d_language_defn): Update.
* c-lang.h (c_watch_location_expression): Declare.
* c-lang.c (c_watch_location_expression): New function.
(c_language_defn, cplus_language_defn, asm_language_defn)
(minimal_language_defn): Use it.
* breakpoint.c (watch_command_1): Call
la_watch_location_expression.
* ada-lang.c (ada_language_defn): Update.
testsuite/ChangeLog
2017-05-19 Tom Tromey <tom@tromey.com>
PR rust/21484:
* gdb.rust/watch.exp: New file.
* gdb.rust/watch.rs: New file.
2017-05-15 01:12:14 +08:00
|
|
|
c_watch_location_expression,
|
Rename la_get_symbol_name_match_p into la_get_symbol_name_cmp
The la_get_symbol_name_match_p language hook was poorly named, as
it suggested that the function should return nonzero if the names
match, whereas it is the exact opposite. This patch therefore
renames the hook and associated typedef, as well some of the code
that uses that hook.
gdb/ChangeLog:
* language.h (symbol_name_cmp_ftype): Renames
symbol_name_match_p_ftype.
(struct language_defn)[la_get_symbol_name_cmp]: Renames
la_get_symbol_name_match_p.
* ada-lang.c (ada_get_symbol_name_cmp): Renames
ada_get_symbol_name_match_p. Update comment.
(ada_language_defn)[la_get_symbol_name_cmp]: Update value.
* linespec.c (struct symbol_matcher_data)[symbol_name_cmp]:
Renames symbol_name_match_p. Update field type.
(iterate_name_matcher, iterate_over_all_matching_symtabs): Adjust.
* c-lang.c, d-lang.c, f-lang.c, jv-lang.c, m2-lang.c, objc-lang.c,
opencl-lang.c, p-lang.c: Replace "la_get_symbol_name_match_p" by
"la_get_symbol_name_cmp" in comments.
* language.c: Likewise.
2012-02-09 03:54:37 +08:00
|
|
|
NULL, /* la_get_symbol_name_cmp */
|
the "ambiguous linespec" series
gdb
2011-12-06 Joel Brobecker <brobecker@acacore.com>
* language.h (struct language_defn): Add new component
la_symbol_name_compare.
* symfile.h (struct quick_symbol_functions): Update the profile
of parameter "name_matcher" for the expand_symtabs_matching
method. Update the documentation accordingly.
* ada-lang.h (ada_name_for_lookup): Add declaration.
* ada-lang.c (ada_name_for_lookup): New function, extracted out
from ada_iterate_over_symbols.
(ada_iterate_over_symbols): Do not encode symbol name anymore.
(ada_expand_partial_symbol_name): Adjust profile.
(ada_language_defn): Add value for la_symbol_name_compare field.
* linespec.c: #include "ada-lang.h".
(iterate_name_matcher): Add language parameter. Replace call
to strcmp_iw by call to language->la_symbol_name_compare.
(decode_variable): Encode COPY if current language is Ada.
* dwarf2read.c (dw2_expand_symtabs_matching): Adjust profile
of name_matcher parameter. Adjust call to name_matcher.
* psymtab.c (expand_symtabs_matching_via_partial): Likewise.
(expand_partial_symbol_names): Update profile of parameter "fun".
* psymtab.h (expand_partial_symbol_names): Update profile of
parameter "fun".
* symtab.c (demangle_for_lookup): Update function documentation.
(search_symbols_name_matches): Add language parameter.
(expand_partial_symbol_name): Likewise.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Add value for
la_symbol_name_compare field.
* d-lang.c (d_language_defn): Likewise.
* f-lang.c (f_language_defn): Ditto.
* jv-lang.c (java_language_defn): Ditto.
* m2-lang.c (m2_language_defn): Ditto.
* objc-lang.c (objc_language_defn): Ditto.
* opencl-lang.c (opencl_language_defn): Ditto.
* p-lang.c (pascal_language_defn): Ditto.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Ditto.
2011-12-06 Tom Tromey <tromey@redhat.com>
* linespec.c (iterate_over_all_matching_symtabs): Use
LA_ITERATE_OVER_SYMBOLS.
(lookup_prefix_sym, add_matching_symbols_to_info): Likewise.
(find_function_symbols, decode_variable): Remove Ada special
case.
* language.h (struct language_defn) <la_iterate_over_symbols>: New
field.
(LA_ITERATE_OVER_SYMBOLS): New macro.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Update.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Update.
* d-lang.c (d_language_defn): Update.
* f-lang.c (f_language_defn): Update.
* jv-lang.c (java_language_defn): Update.
* m2-lang.c (m2_language_defn): Update.
* objc-lang.c (objc_language_defn): Update.
* opencl-lang.c (opencl_language_defn): Update.
* p-lang.c (pascal_language_defn): Update.
* ada-lang.c (ada_iterate_over_symbols): New function.
(ada_language_defn): Update.
2011-12-06 Tom Tromey <tromey@redhat.com>
Joel Brobecker <brobecker@acacore.com>
PR breakpoints/13105, PR objc/8341, PR objc/8343, PR objc/8366,
PR objc/8535, PR breakpoints/11657, PR breakpoints/11970,
PR breakpoints/12023, PR breakpoints/12334, PR breakpoints/12856,
PR shlibs/8929, PR shlibs/7393:
* python/py-type.c (compare_maybe_null_strings): Rename from
compare_strings.
(check_types_equal): Update.
* utils.c (compare_strings): New function.
* tui/tui-winsource.c (tui_update_breakpoint_info): Update for
location changes.
* tracepoint.c (scope_info): Update.
(trace_find_line_command): Use DECODE_LINE_FUNFIRSTLINE.
* symtab.h (iterate_over_minimal_symbols)
(iterate_over_some_symtabs, iterate_over_symtabs)
(find_pcs_for_symtab_line, iterate_over_symbols)
(demangle_for_lookup): Declare.
(expand_line_sal): Remove.
* symtab.c (iterate_over_some_symtabs, iterate_over_symtabs)
(lookup_symtab_callback): New functions.
(lookup_symtab): Rewrite.
(demangle_for_lookup): New function, extract from
lookup_symbol_in_language.
(lookup_symbol_in_language): Use it.
(iterate_over_symbols): New function.
(find_line_symtab): Update.
(find_pcs_for_symtab_line): New functions.
(find_line_common): Add 'start' argument.
(decode_line_spec): Update. Change argument to 'flags', change
interpretation.
(append_expanded_sal): Remove.
(append_exact_match_to_sals): Remove.
(expand_line_sal): Remove.
* symfile.h (struct quick_symbol_functions) <lookup_symtab>:
Remove.
<map_symtabs_matching_filename>: New field.
* stack.c (func_command): Only look in the current program space.
Use DECODE_LINE_FUNFIRSTLINE.
* source.c (line_info): Set pspace on sal. Check program space in
the loop. Use DECODE_LINE_LIST_MODE.
(select_source_symtab): Use DECODE_LINE_FUNFIRSTLINE.
* solib-target.c: Remove DEF_VEC_I(CORE_ADDR).
* python/python.c (gdbpy_decode_line): Update.
* psymtab.c (partial_map_expand_apply): New function.
(partial_map_symtabs_matching_filename): Rename from
lookup_partial_symbol. Update arguments.
(lookup_symtab_via_partial_symtab): Remove.
(psym_functions): Update.
* objc-lang.h (parse_selector, parse_method): Don't declare.
(find_imps): Update.
* objc-lang.c (parse_selector, parse_method): Now static.
(find_methods): Change arguments. Fill in a vector of symbol
names.
(uniquify_strings): New function.
(find_imps): Change arguments.
* minsyms.c (iterate_over_minimal_symbols): New function.
* linespec.h (enum decode_line_flags): New.
(struct linespec_sals): New.
(struct linespec_result) <canonical>: Remove.
<pre_expanded, addr_string, sals>: New fields.
(destroy_linespec_result, make_cleanup_destroy_linespec_result)
(decode_line_full): Declare.
(decode_line_1): Update.
* linespec.c (struct address_entry, struct linespec_state, struct
collect_info): New types.
(add_sal_to_sals_basic, add_sal_to_sals, hash_address_entry)
(eq_address_entry, maybe_add_address): New functions.
(total_number_of_methods): Remove.
(iterate_name_matcher, iterate_over_all_matching_symtabs): New
functions.
(find_methods): Change arguments. Don't canonicalize input.
Simplify logic.
(add_matching_methods, add_constructors)
(build_canonical_line_spec): Remove.
(filter_results, convert_results_to_lsals): New functions.
(decode_line_2): Change arguments. Rewrite for new data
structures.
(decode_line_internal): Rename from decode_line_1. Change
arguments. Add cleanups. Update for new data structures.
(linespec_state_constructor, linespec_state_destructor)
(decode_line_full, decode_line_1): New functions.
(decode_indirect): Change arguments. Update.
(locate_first_half): Use skip_spaces.
(decode_objc): Change arguments. Update for new data structures.
Simplify logic.
(decode_compound): Change arguments. Add cleanups. Remove
fallback code, replace with error.
(struct decode_compound_collector): New type.
(collect_one_symbol): New function.
(lookup_prefix_sym): Change arguments. Update.
(compare_symbol_name, add_all_symbol_names_from_pspace)
(find_superclass_methods ): New functions.
(find_method): Rewrite.
(struct symtab_collector): New type.
(add_symtabs_to_list, collect_symtabs_from_filename): New
functions.
(symtabs_from_filename): Change API. Rename from
symtab_from_filename.
(collect_function_symbols): New function.
(find_function_symbols): Change API. Rename from
find_function_symbol. Rewrite.
(decode_all_digits): Change arguments. Rewrite.
(decode_dollar): Change arguments. Use decode_variable.
(decode_label): Change arguments. Rewrite.
(collect_symbols): New function.
(minsym_found): Change arguments. Rewrite.
(check_minsym, search_minsyms_for_name)
(add_matching_symbols_to_info): New function.
(decode_variable): Change arguments. Iterate over all symbols.
(symbol_found): Remove.
(symbol_to_sal): New function.
(init_linespec_result, destroy_linespec_result)
(cleanup_linespec_result, make_cleanup_destroy_linespec_result):
New functions.
(decode_digits_list_mode, decode_digits_ordinary): New functions.
* dwarf2read.c (dw2_map_expand_apply): New function.
(dw2_map_symtabs_matching_filename): Rename from
dw2_lookup_symtab. Change arguments.
(dwarf2_gdb_index_functions): Update.
* dwarf2loc.c: Remove DEF_VEC_I(CORE_ADDR).
* defs.h (compare_strings): Declare.
* cli/cli-cmds.c (compare_strings): Move to utils.c.
(edit_command, list_command): Use DECODE_LINE_LIST_MODE. Call
filter_sals.
(compare_symtabs, filter_sals): New functions.
* breakpoint.h (struct bp_location) <line_number, source_file>:
New fields.
(struct breakpoint) <line_number, source_file>: Remove.
<filter>: New field.
* breakpoint.c (print_breakpoint_location, init_raw_breakpoint)
(momentary_breakpoint_from_master, add_location_to_breakpoint):
Update for changes to locations.
(init_breakpoint_sal): Add 'filter' argument. Set 'filter' on
breakpoint.
(create_breakpoint_sal): Add 'filter' argument.
(remove_sal, expand_line_sal_maybe): Remove.
(create_breakpoints_sal): Remove 'sals' argument. Handle
pre-expanded sals and the filter.
(parse_breakpoint_sals): Use decode_line_full.
(check_fast_tracepoint_sals): Use get_sal_arch.
(create_breakpoint): Create a linespec_sals. Update.
(break_range_command): Use decode_line_full. Update.
(until_break_command): Update.
(clear_command): Update match conditions for linespec.c changes.
Use DECODE_LINE_LIST_MODE.
(say_where): Update for changes to locations.
(bp_location_dtor): Free 'source_file'.
(base_breakpoint_dtor): Free 'filter'. Don't free 'source_file'.
(update_static_tracepoint): Update for changes to locations.
(update_breakpoint_locations): Disable ranged breakpoint if too
many locations match. Update.
(addr_string_to_sals): Use decode_line_full. Resolve all sal
PCs.
(breakpoint_re_set_default): Don't call expand_line_sal_maybe.
(decode_line_spec_1): Update. Change argument name to 'flags',
change interpretation.
* block.h (block_containing_function): Declare.
* block.c (block_containing_function): New function.
* skip.c (skip_function_command): Update.
(skip_re_set): Update.
* infcmd.c (jump_command): Use DECODE_LINE_FUNFIRSTLINE.
* mi/mi-main.c (mi_cmd_trace_find): Use DECODE_LINE_FUNFIRSTLINE.
* NEWS: Add entry.
2011-12-06 Tom Tromey <tromey@redhat.com>
* elfread.c (elf_gnu_ifunc_resolver_return_stop): Allow
breakpoint's pspace to be NULL.
* breakpoint.h (struct breakpoint) <pspace>: Update comment.
* breakpoint.c (init_raw_breakpoint): Conditionally set
breakpoint's pspace.
(init_breakpoint_sal): Don't set breakpoint's pspace.
(prepare_re_set_context): Conditionally switch program space.
(addr_string_to_sals): Check executing_startup on location's
program space.
2011-12-06 Tom Tromey <tromey@redhat.com>
* breakpoint.h (enum enable_state) <bp_startup_disabled>: Remove.
* breakpoint.c (should_be_inserted): Explicitly check if program
space is executing startup.
(describe_other_breakpoints): Update.
(disable_breakpoints_before_startup): Change executing_startup
earlier. Remove loop.
(enable_breakpoints_after_startup): Likewise.
(init_breakpoint_sal): Don't use bp_startup_disabled.
(create_breakpoint): Don't use bp_startup_disabled.
(update_global_location_list): Use should_be_inserted.
(bkpt_re_set): Update.
gdb/testsuite
2011-12-06 Joel Brobecker <brobecker@acacore.com>
* gdb.ada/fullname_bp.exp: Add tests for other valid linespecs
involving a fully qualified function name.
2011-12-06 Tom Tromey <tromey@redhat.com>
* gdb.ada/homonym.exp: Add three breakpoint tests.
2011-12-06 Tom Tromey <tromey@redhat.com>
* gdb.base/solib-weak.exp (do_test): Remove kfail.
* gdb.trace/tracecmd.exp: Disable pending breakpoints earlier.
* gdb.objc/objcdecode.exp: Update for output changes.
* gdb.linespec/linespec.exp: New file.
* gdb.linespec/lspec.cc: New file.
* gdb.linespec/lspec.h: New file.
* gdb.linespec/body.h: New file.
* gdb.linespec/base/two/thefile.cc: New file.
* gdb.linespec/base/one/thefile.cc: New file.
* gdb.linespec/Makefile.in: New file.
* gdb.cp/templates.exp (test_template_breakpoints): Update for
output changes.
* gdb.cp/re-set-overloaded.exp: Remove kfail.
* gdb.cp/ovldbreak.exp: Update for output changes. "all" test now
makes one breakpoint.
* gdb.cp/method2.exp (test_break): Update for output changes.
* gdb.cp/mb-templates.exp: Update for output changes.
* gdb.cp/mb-inline.exp: Update for output changes.
* gdb.cp/mb-ctor.exp: Update for output changes.
* gdb.cp/ovsrch.exp: Use fully-qualified names.
* gdb.base/solib-symbol.exp: Run to main later. Breakpoint now
has multiple matches.
* gdb.base/sepdebug.exp: Disable pending breakpoints. Update for
error message change.
* gdb.base/list.exp (test_list_filename_and_number): Update for
error message change.
* gdb.base/break.exp: Disable pending breakpoints. Update for
output changes.
* configure.ac: Add gdb.linespec.
* configure: Rebuild.
* Makefile.in (ALL_SUBDIRS): Add gdb.linespec.
gdb/doc
2011-12-06 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Set Breaks): Update for new behavior.
2011-12-07 02:54:43 +08:00
|
|
|
iterate_over_symbols,
|
2013-10-17 21:15:21 +08:00
|
|
|
&default_varobj_ops,
|
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-15 04:35:45 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2010-11-05 22:31:30 +08:00
|
|
|
LANG_MAGIC
|
|
|
|
};
|
|
|
|
|
|
|
|
static void *
|
|
|
|
build_opencl_types (struct gdbarch *gdbarch)
|
|
|
|
{
|
2011-02-21 23:53:10 +08:00
|
|
|
struct type **types
|
|
|
|
= GDBARCH_OBSTACK_CALLOC (gdbarch, nr_opencl_primitive_types + 1,
|
|
|
|
struct type *);
|
2010-11-05 22:31:30 +08:00
|
|
|
|
|
|
|
/* Helper macro to create strings. */
|
2011-02-02 21:47:06 +08:00
|
|
|
#define OCL_STRING(S) #S
|
2010-11-05 22:31:30 +08:00
|
|
|
/* This macro allocates and assigns the type struct pointers
|
|
|
|
for the vector types. */
|
|
|
|
#define BUILD_OCL_VTYPES(TYPE)\
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_##TYPE##2] \
|
|
|
|
= init_vector_type (types[opencl_primitive_type_##TYPE], 2); \
|
|
|
|
TYPE_NAME (types[opencl_primitive_type_##TYPE##2]) = OCL_STRING(TYPE ## 2); \
|
|
|
|
types[opencl_primitive_type_##TYPE##3] \
|
|
|
|
= init_vector_type (types[opencl_primitive_type_##TYPE], 3); \
|
|
|
|
TYPE_NAME (types[opencl_primitive_type_##TYPE##3]) = OCL_STRING(TYPE ## 3); \
|
|
|
|
TYPE_LENGTH (types[opencl_primitive_type_##TYPE##3]) \
|
|
|
|
= 4 * TYPE_LENGTH (types[opencl_primitive_type_##TYPE]); \
|
|
|
|
types[opencl_primitive_type_##TYPE##4] \
|
|
|
|
= init_vector_type (types[opencl_primitive_type_##TYPE], 4); \
|
|
|
|
TYPE_NAME (types[opencl_primitive_type_##TYPE##4]) = OCL_STRING(TYPE ## 4); \
|
|
|
|
types[opencl_primitive_type_##TYPE##8] \
|
|
|
|
= init_vector_type (types[opencl_primitive_type_##TYPE], 8); \
|
|
|
|
TYPE_NAME (types[opencl_primitive_type_##TYPE##8]) = OCL_STRING(TYPE ## 8); \
|
|
|
|
types[opencl_primitive_type_##TYPE##16] \
|
|
|
|
= init_vector_type (types[opencl_primitive_type_##TYPE], 16); \
|
|
|
|
TYPE_NAME (types[opencl_primitive_type_##TYPE##16]) = OCL_STRING(TYPE ## 16)
|
|
|
|
|
|
|
|
types[opencl_primitive_type_char]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 8, 0, "char");
|
|
|
|
BUILD_OCL_VTYPES (char);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_uchar]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 8, 1, "uchar");
|
|
|
|
BUILD_OCL_VTYPES (uchar);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_short]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 16, 0, "short");
|
|
|
|
BUILD_OCL_VTYPES (short);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_ushort]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 16, 1, "ushort");
|
|
|
|
BUILD_OCL_VTYPES (ushort);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_int]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 32, 0, "int");
|
|
|
|
BUILD_OCL_VTYPES (int);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_uint]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 32, 1, "uint");
|
|
|
|
BUILD_OCL_VTYPES (uint);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_long]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 64, 0, "long");
|
|
|
|
BUILD_OCL_VTYPES (long);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_ulong]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 64, 1, "ulong");
|
|
|
|
BUILD_OCL_VTYPES (ulong);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_half]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_float_type (gdbarch, 16, "half", floatformats_ieee_half);
|
|
|
|
BUILD_OCL_VTYPES (half);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_float]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_float_type (gdbarch, 32, "float", floatformats_ieee_single);
|
|
|
|
BUILD_OCL_VTYPES (float);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_double]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_float_type (gdbarch, 64, "double", floatformats_ieee_double);
|
|
|
|
BUILD_OCL_VTYPES (double);
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_bool]
|
2011-02-16 04:10:13 +08:00
|
|
|
= arch_boolean_type (gdbarch, 8, 1, "bool");
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_unsigned_char]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 8, 1, "unsigned char");
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_unsigned_short]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 16, 1, "unsigned short");
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_unsigned_int]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 32, 1, "unsigned int");
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_unsigned_long]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, 64, 1, "unsigned long");
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_size_t]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "size_t");
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_ptrdiff_t]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 0, "ptrdiff_t");
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_intptr_t]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 0, "intptr_t");
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_uintptr_t]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "uintptr_t");
|
2011-02-21 23:53:10 +08:00
|
|
|
types[opencl_primitive_type_void]
|
2010-11-05 22:31:30 +08:00
|
|
|
= arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
|
|
|
|
|
2011-02-21 23:53:10 +08:00
|
|
|
return types;
|
2010-11-05 22:31:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_initialize_opencl_language (void)
|
|
|
|
{
|
|
|
|
opencl_type_data = gdbarch_data_register_post_init (build_opencl_types);
|
|
|
|
}
|