2010-11-05 22:31:30 +08:00
|
|
|
/* OpenCL language support for GDB, the GNU debugger.
|
2019-01-01 14:01:51 +08:00
|
|
|
Copyright (C) 2010-2019 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)
|
|
|
|
{
|
Introduce a gdb_ref_ptr specialization for struct value
struct value is internally reference counted and so, while it also has
some ownership rules unique to it, it makes sense to use a gdb_ref_ptr
when managing it automatically.
This patch removes the existing unique_ptr specialization in favor of
a reference-counted pointer. It also introduces two other
clarifications:
1. Rename value_free to value_decref, which I think is more in line
with what the function actually does; and
2. Change release_value to return a gdb_ref_ptr. This change allows
us to remove the confusing release_value_or_incref function,
primarily by making it much simpler to reason about the result of
release_value.
gdb/ChangeLog
2018-04-06 Tom Tromey <tom@tromey.com>
* varobj.c (varobj_clear_saved_item)
(update_dynamic_varobj_children, install_new_value, ~varobj):
Update.
* value.h (value_incref): Move declaration earlier.
(value_decref): Rename from value_free.
(struct value_ref_policy): New.
(value_ref_ptr): New typedef.
(struct value_deleter): Remove.
(gdb_value_up): Remove typedef.
(release_value): Change return type.
(release_value_or_incref): Remove.
* value.c (set_value_parent): Update.
(value_incref): Change return type.
(value_decref): Rename from value_free.
(value_free_to_mark, free_all_values, free_value_chain): Update.
(release_value): Return value_ref_ptr.
(release_value_or_incref): Remove.
(record_latest_value, set_internalvar, clear_internalvar):
Update.
* stack.c (info_frame_command): Don't call value_free.
* python/py-value.c (valpy_dealloc, valpy_new)
(value_to_value_object): Update.
* printcmd.c (do_examine): Update.
* opencl-lang.c (lval_func_free_closure): Update.
* mi/mi-main.c (register_changed_p): Don't call value_free.
* mep-tdep.c (mep_frame_prev_register): Don't call value_free.
* m88k-tdep.c (m88k_frame_prev_register): Don't call value_free.
* m68hc11-tdep.c (m68hc11_frame_prev_register): Don't call
value_free.
* guile/scm-value.c (vlscm_free_value_smob)
(vlscm_scm_from_value): Update.
* frame.c (frame_register_unwind, frame_unwind_register_signed)
(frame_unwind_register_unsigned, get_frame_register_bytes)
(put_frame_register_bytes): Don't call value_free.
* findvar.c (address_from_register): Don't call value_free.
* dwarf2read.c (dwarf2_compute_name): Don't call value_free.
* dwarf2loc.c (entry_data_value_free_closure)
(value_of_dwarf_reg_entry, free_pieced_value_closure)
(dwarf2_evaluate_loc_desc_full): Update.
* breakpoint.c (update_watchpoint, breakpoint_init_inferior)
(~bpstats, bpstats, bpstat_clear_actions, watchpoint_check)
(~watchpoint, watch_command_1)
(invalidate_bp_value_on_memory_change): Update.
* alpha-tdep.c (alpha_register_to_value): Don't call value_free.
2018-04-04 07:45:21 +08:00
|
|
|
value_decref (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,
|
|
|
|
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 */
|
problem looking up some symbols when they have a linkage name
This patch fixes a known failure in gdb.ada/maint_with_ada.exp
(maintenance check-psymtabs). Another way to witness the same
issue is by considering the following Ada declarations...
type Wrapper is record
A : Integer;
end record;
u00045 : constant Wrapper := (A => 16#060287af#);
pragma Export (C, u00045, "symada__cS");
... which declares a variable name "u00045" but with a linkage
name which is "symada__cS". This variable is a record with one
component, the Ada equivalent of a struct with one field in C.
Trying to print that variable's value currently yields:
(gdb) p /x <symada__cS>
'symada(char, signed)' has unknown type; cast it to its declared type
This indicates that GDB was only able to find the minimal symbol,
but not the full symbol. The expected output is:
(gdb) print /x <symada__cS>
$1 = (a => 0x60287af)
The error message gives a hint about what's happening: We processed
the symbol through gdb_demangle, which in the case of this particular
symbol name, ends up matching the C++ naming scheme. As a result,
the demangler transforms our symbol name into 'symada(char, signed)',
thus breaking Ada lookups.
This patch fixes the issue by first introducing a new language_defn
attribute called la_store_sym_names_in_linkage_form_p, which is a boolean
to be set to true for the few languages that do not want their symbols
to have their names stored in demangled form, and false otherwise.
We then use this language attribute to skip the call to gdb_demangle
for all languages whose la_store_sym_names_in_linkage_form_p is true.
In terms of the selection of languages for which the new attribute
is set to true, the selection errs on the side of preserving the
existing behavior, and only changes the behavior for the languages
where we are certain storing symbol names in demangling form is not
needed. It is conceivable that other languages might be in the same
situation, but I not knowing in detail the symbol name enconding
strategy, I decided to play it safe and let other language maintainers
potentially adjust their language if it makes sense to do so.
gdb/ChangeLog:
PR gdb/22670
* dwarf2read.c (dwarf2_physname): Do not return the demangled
symbol name if the CU's language stores symbol names in linkage
format.
* language.h (struct language_defn)
<la_store_sym_names_in_linkage_form_p>: New field. Adjust
all instances of this struct.
gdb/testsuite/ChangeLog:
* gdb.ada/maint_with_ada.exp: Remove PR gdb/22670 setup_kfail.
* gdb.ada/notcplusplus: New testcase.
* gdb.base/c-linkage-name.c: New file.
* gdb.base/c-linkage-name.exp: New testcase.
Tested on x86_64-linux.
This also passes AdaCore's internal GDB testsuite.
2018-03-27 21:57:16 +08:00
|
|
|
false, /* la_store_sym_names_in_linkage_form_p */
|
2010-11-05 22:31:30 +08:00
|
|
|
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,
|
Introduce lookup_name_info and generalize Ada's FULL/WILD name matching
Summary:
- This is preparation for supporting wild name matching on C++ too.
- This is also preparation for TAB-completion fixes.
- Makes symbol name matching (think strcmp_iw) be based on a per-language method.
- Merges completion and non-completion name comparison (think
language_ops::la_get_symbol_name_cmp generalized).
- Avoid re-hashing lookup name multiple times
- Centralizes preparing a name for lookup (Ada name encoding / C++ Demangling),
both completion and non-completion.
- Fixes Ada latent bug with verbatim name matches in expressions
- Makes ada-lang.c use common|symtab.c completion code a bit more.
Ada's wild matching basically means that
"(gdb) break foo"
will find all methods named "foo" in all packages. Translating to
C++, it's roughly the same as saying that "break klass::method" sets
breakpoints on all "klass::method" methods of all classes, no matter
the namespace. A following patch will teach GDB about fullname vs
wild matching for C++ too. This patch is preparatory work to get
there.
Another idea here is to do symbol name matching based on the symbol
language's algorithm. I.e., avoid dependency on current language set.
This allows for example doing
(gdb) b foo::bar< int > (<tab>
and having gdb name match the C++ symbols correctly even if the
current language is C or Assembly (or Rust, or Ada, or ...), which can
easily happen if you step into an Assembly/C runtime library frame.
By encapsulating all the information related to a lookup name in a
class, we can also cache hash computation for a given language in the
lookup name object, to avoid recomputing it over and over.
Similarly, because we don't really know upfront which languages the
lookup name will be matched against, for each language we store the
lookup name transformed into a search name. E.g., for C++, that means
demangling the name. But for Ada, it means encoding the name. This
actually forces us to centralize all the different lookup name
encoding in a central place, resulting in clearer code, IMO. See
e.g., the new ada_lookup_name_info class.
The lookup name -> symbol search name computation is also done only
once per language.
The old language->la_get_symbol_name_cmp / symbol_name_cmp_ftype are
generalized to work with both completion, and normal symbol look up.
At some point early on, I had separate completion vs non-completion
language vector entry points, but a single method ends up being better
IMO for simplifying things -- the more we merge the completion /
non-completion name lookup code paths, the less changes for bugs
causing completion vs normal lookup finding different symbols.
The ada-lex.l change is necessary because when doing
(gdb) p <UpperCase>
then the name that is passed to write_ write_var_or_type ->
ada_lookup_symbol_list misses the "<>", i.e., it's just "UpperCase",
and we end up doing a wild match against "UpperCase" lowercased by
ada_lookup_name_info's constructor. I.e., "uppercase" wouldn't ever
match "UpperCase", and the symbol lookup fails.
This wouldn't cause any regression in the testsuite, but I added a new
test that would pass before the patch and fail after, if it weren't
for that fix.
This is latent bug that happens to go unnoticed because that
particular path was inconsistent with the rest of Ada symbol lookup by
not lowercasing the lookup name.
Ada's symbol_completion_add is deleted, replaced by using common
code's completion_list_add_name. To make the latter work for Ada, we
needed to add a new output parameter, because Ada wants to return back
a custom completion candidates that are not the symbol name.
With this patch, minimal symbol demangled name hashing is made
consistent with regular symbol hashing. I.e., it now goes via the
language vector's search_name_hash method too, as I had suggested in a
previous patch.
dw2_expand_symtabs_matching / .gdb_index symbol names were a
challenge. The problem is that we have no way to telling what is the
language of each symbol name found in the index, until we expand the
corresponding full symbol, which is off course what we're trying to
avoid. Language information is simply not considered in the index
format... Since the symbol name hashing and comparison routines are
per-language, we now have a problem. The patch sorts this out by
matching each name against all languages. This is inneficient, and
indeed slows down completion several times. E.g., with:
$ cat script.cmd
set pagination off
set $count = 0
while $count < 400
complete b string_prin
printf "count = %d\n", $count
set $count = $count + 1
end
$ time gdb --batch -q ./gdb-with-index -ex "source script-string_printf.cmd"
I get, before patch (-O2, x86-64):
real 0m1.773s
user 0m1.737s
sys 0m0.040s
While after patch (-O2, x86-64):
real 0m9.843s
user 0m9.482s
sys 0m0.034s
However, the following patch will optimize this, and will actually
make this use case faster compared to the "before patch" above:
real 0m1.321s
user 0m1.285s
sys 0m0.039s
gdb/ChangeLog:
2017-11-08 Pedro Alves <palves@redhat.com>
* ada-lang.c (ada_encode): Rename to ..
(ada_encode_1): ... this. Add throw_errors parameter and handle
it.
(ada_encode): Reimplement.
(match_name): Delete, folded into full_name.
(resolve_subexp): No longer pass the encoded name to
ada_lookup_symbol_list.
(should_use_wild_match): Delete.
(name_match_type_from_name): New.
(ada_lookup_simple_minsym): Use lookup_name_info and the
language's symbol_name_matcher_ftype.
(add_symbols_from_enclosing_procs, ada_add_local_symbols)
(ada_add_block_renamings): Adjust to use lookup_name_info.
(ada_lookup_name): New.
(add_nonlocal_symbols, ada_add_all_symbols)
(ada_lookup_symbol_list_worker, ada_lookup_symbol_list)
(ada_iterate_over_symbols): Adjust to use lookup_name_info.
(ada_name_for_lookup): Delete.
(ada_lookup_encoded_symbol): Construct a verbatim name.
(wild_match): Reverse sense of return type. Use bool.
(full_match): Reverse sense of return type. Inline bits of old
match_name here.
(ada_add_block_symbols): Adjust to use lookup_name_info.
(symbol_completion_match): Delete, folded into...
(ada_lookup_name_info::matches): ... .this new method.
(symbol_completion_add): Delete.
(ada_collect_symbol_completion_matches): Add name_match_type
parameter. Adjust to use lookup_name_info and
completion_list_add_name.
(get_var_value, ada_add_global_exceptions): Adjust to use
lookup_name_info.
(ada_get_symbol_name_cmp): Delete.
(do_wild_match, do_full_match): New functions.
(ada_lookup_name_info::ada_lookup_name_info): New method.
(ada_symbol_name_matches, ada_get_symbol_name_matcher): New
functions.
(ada_language_defn): Install ada_get_symbol_name_matcher.
* ada-lex.l (processId): If name starts with '<', copy it
verbatim.
* block.c (block_iter_match_step, block_iter_match_first)
(block_iter_match_next, block_lookup_symbol)
(block_lookup_symbol_primary, block_find_symbol): Adjust to use
lookup_name_info.
* block.h (block_iter_match_first, block_iter_match_next)
(ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use lookup_name_info.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Adjust comments to
refer to la_get_symbol_name_matcher.
* completer.c (complete_files_symbols)
(collect_explicit_location_matches, symbol_completer): Pass a
symbol_name_match_type down.
* completer.h (class completion_match, completion_match_result):
New classes.
(completion_tracker::reset_completion_match_result): New method.
(completion_tracker::m_completion_match_result): New field.
* cp-support.c (make_symbol_overload_list_block): Adjust to use
lookup_name_info.
(cp_fq_symbol_name_matches, cp_get_symbol_name_matcher): New
functions.
* cp-support.h (cp_get_symbol_name_matcher): New declaration.
* d-lang.c: Adjust comments to refer to
la_get_symbol_name_matcher.
* dictionary.c (dict_vector) <iter_match_first, iter_match_next>:
Adjust to use lookup_name_info.
(dict_iter_match_first, dict_iter_match_next)
(iter_match_first_hashed, iter_match_next_hashed)
(iter_match_first_linear, iter_match_next_linear): Adjust to work
with a lookup_name_info.
* dictionary.h (dict_iter_match_first, dict_iter_match_next):
Likewise.
* dwarf2read.c (dw2_lookup_symbol): Adjust to use lookup_name_info.
(dw2_map_matching_symbols): Adjust to use symbol_name_match_type.
(gdb_index_symbol_name_matcher): New class.
(dw2_expand_symtabs_matching) Adjust to use lookup_name_info and
gdb_index_symbol_name_matcher. Accept a NULL symbol_matcher.
* f-lang.c (f_collect_symbol_completion_matches): Adjust to work
with a symbol_name_match_type.
(f_language_defn): Adjust comments to refer to
la_get_symbol_name_matcher.
* go-lang.c (go_language_defn): Adjust comments to refer to
la_get_symbol_name_matcher.
* language.c (default_symbol_name_matcher)
(language_get_symbol_name_matcher): New functions.
(unknown_language_defn, auto_language_defn): Adjust comments to
refer to la_get_symbol_name_matcher.
* language.h (symbol_name_cmp_ftype): Delete.
(language_defn) <la_collect_symbol_completion_matches>: Add match
type parameter.
<la_get_symbol_name_cmp>: Delete field.
<la_get_symbol_name_matcher>: New field.
<la_iterate_over_symbols>: Adjust to use lookup_name_info.
(default_symbol_name_matcher, language_get_symbol_name_matcher):
Declare.
* linespec.c (iterate_over_all_matching_symtabs)
(iterate_over_file_blocks): Adjust to use lookup_name_info.
(find_methods): Add language parameter, and use lookup_name_info
and the language's symbol_name_matcher_ftype.
(linespec_complete_function): Adjust.
(lookup_prefix_sym): Use lookup_name_info.
(add_all_symbol_names_from_pspace): Adjust.
(find_superclass_methods): Add language parameter and pass it
down.
(find_method): Pass symbol language down.
(find_linespec_symbols): Don't demangle or Ada encode here.
(search_minsyms_for_name): Add lookup_name_info parameter.
(add_matching_symbols_to_info): Add name_match_type parameter.
Use lookup_name_info.
* m2-lang.c (m2_language_defn): Adjust comments to refer to
la_get_symbol_name_matcher.
* minsyms.c: Include <algorithm>.
(add_minsym_to_demangled_hash_table): Remove table parameter and
add objfile parameter. Use search_name_hash, and add language to
demangled languages vector.
(struct found_minimal_symbols): New struct.
(lookup_minimal_symbol_mangled, lookup_minimal_symbol_demangled):
New functions.
(lookup_minimal_symbol): Adjust to use them. Don't canonicalize
input names here. Use lookup_name_info instead. Lookup up
demangled names once for each language in the demangled names
vector.
(iterate_over_minimal_symbols): Use lookup_name_info. Lookup up
demangled names once for each language in the demangled names
vector.
(build_minimal_symbol_hash_tables): Adjust.
* minsyms.h (iterate_over_minimal_symbols): Adjust to pass down a
lookup_name_info.
* objc-lang.c (objc_language_defn): Adjust comment to refer to
la_get_symbol_name_matcher.
* objfiles.h: Include <vector>.
(objfile_per_bfd_storage) <demangled_hash_languages>: New field.
* opencl-lang.c (opencl_language_defn): Adjust comment to refer to
la_get_symbol_name_matcher.
* p-lang.c (pascal_language_defn): Adjust comment to refer to
la_get_symbol_name_matcher.
* psymtab.c (psym_lookup_symbol): Use lookup_name_info.
(match_partial_symbol): Use symbol_name_match_type,
lookup_name_info and psymbol_name_matches.
(lookup_partial_symbol): Use lookup_name_info.
(map_block): Use symbol_name_match_type and lookup_name_info.
(psym_map_matching_symbols): Use symbol_name_match_type.
(psymbol_name_matches): New.
(recursively_search_psymtabs): Use lookup_name_info and
psymbol_name_matches. Rename 'kind' parameter to 'domain'.
(psym_expand_symtabs_matching): Use lookup_name_info. Rename
'kind' parameter to 'domain'.
* rust-lang.c (rust_language_defn): Adjust comment to refer to
la_get_symbol_name_matcher.
* symfile-debug.c (debug_qf_map_matching_symbols)
(debug_qf_map_matching_symbols): Use symbol_name_match_type.
(debug_qf_expand_symtabs_matching): Use lookup_name_info.
* symfile.c (expand_symtabs_matching): Use lookup_name_info.
* symfile.h (quick_symbol_functions) <map_matching_symbols>:
Adjust to use symbol_name_match_type.
<expand_symtabs_matching>: Adjust to use lookup_name_info.
(expand_symtabs_matching): Adjust to use lookup_name_info.
* symmisc.c (maintenance_expand_symtabs): Use
lookup_name_info::match_any ().
* symtab.c (symbol_matches_search_name): New.
(eq_symbol_entry): Adjust to use lookup_name_info and the
language's matcher.
(demangle_for_lookup_info::demangle_for_lookup_info): New.
(lookup_name_info::match_any): New.
(iterate_over_symbols, search_symbols): Use lookup_name_info.
(compare_symbol_name): Add language, lookup_name_info and
completion_match_result parameters, and use them.
(completion_list_add_name): Make extern. Add language and
lookup_name_info parameters. Use them.
(completion_list_add_symbol, completion_list_add_msymbol)
(completion_list_objc_symbol): Add lookup_name_info parameters and
adjust. Pass down language.
(completion_list_add_fields): Add lookup_name_info parameters and
adjust. Pass down language.
(add_symtab_completions): Add lookup_name_info parameters and
adjust.
(default_collect_symbol_completion_matches_break_on): Add
name_match_type parameter, and use it. Use lookup_name_info.
(default_collect_symbol_completion_matches)
(collect_symbol_completion_matches): Add name_match_type
parameter, and pass it down.
(collect_symbol_completion_matches_type): Adjust.
(collect_file_symbol_completion_matches): Add name_match_type
parameter, and use lookup_name_info.
* symtab.h: Include <string> and "common/gdb_optional.h".
(enum class symbol_name_match_type): New.
(class ada_lookup_name_info): New.
(struct demangle_for_lookup_info): New.
(class lookup_name_info): New.
(symbol_name_matcher_ftype): New.
(SYMBOL_MATCHES_SEARCH_NAME): Use symbol_matches_search_name.
(symbol_matches_search_name): Declare.
(MSYMBOL_MATCHES_SEARCH_NAME): Delete.
(default_collect_symbol_completion_matches)
(collect_symbol_completion_matches)
(collect_file_symbol_completion_matches): Add name_match_type
parameter.
(iterate_over_symbols): Use lookup_name_info.
(completion_list_add_name): Declare.
* utils.c (enum class strncmp_iw_mode): Moved to utils.h.
(strncmp_iw_with_mode): Now extern.
* utils.h (enum class strncmp_iw_mode): Moved from utils.c.
(strncmp_iw_with_mode): Declare.
gdb/testsuite/ChangeLog:
2017-11-08 Pedro Alves <palves@redhat.com>
* gdb.ada/complete.exp (p <Exported_Capitalized>): New test.
(p Exported_Capitalized): New test.
(p exported_capitalized): New test.
2017-11-08 22:22:32 +08:00
|
|
|
NULL, /* la_get_symbol_name_matcher */
|
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,
|
Per-language symbol name hashing algorithm
Currently, we have a mess of symbol name hashing/comparison routines.
There's msymbol_hash for mangled names, and dict_hash and
msymbol_hash_iw for demangled names. Then there's strcmp_iw,
strcmp_iw_ordered and Ada's full_match/wild_match, which all have to
agree with the hashing routines. That's why dict_hash is really about
Ada names. From the inconsistency department, minimal symbol hashing
doesn't go via dict_hash, so Ada's wild matching can't ever work with
minimal symbols.
This patch starts fixing this, by doing two things:
#1 - adds a language vector method to let each language decide how to
compute a symbol name hash.
#2 - makes dictionaries know the language of the symbols they hold,
and then use the dictionaries language to decide which hashing
method to use.
For now, this is just scaffolding, since all languages install the
default method. The series will make C++ install its own hashing
method later on, and will add per-language symbol name comparison
routines too.
This patch was originally based on a patch that Keith wrote for the
libcc1/C++ WIP support.
gdb/ChangeLog:
2017-11-08 Keith Seitz <keiths@redhat.com>
Pedro Alves <palves@redhat.com>
* ada-lang.c (ada_language_defn): Install
default_search_name_hash.
* buildsym.c (struct buildsym_compunit): <language>: New field.
(finish_block_internal): Pass language when creating dictionaries.
(start_buildsym_compunit, start_symtab): New language parameters.
Use them.
(restart_symtab): Pass down compilation unit's language.
* buildsym.h (enum language): Forward declare.
(start_symtab): New 'language' parameter.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Install
default_search_name_hash.
* coffread.c (coff_start_symtab): Adjust.
* d-lang.c (d_language_defn): Install default_search_name_hash.
* dbxread.c (struct symloc): Add 'pst_language' field.
(PST_LANGUAGE): Define.
(start_psymtab, read_ofile_symtab): Use it.
(process_one_symbol): New 'language' parameter. Pass it down.
* dictionary.c (struct dictionary) <language>: New field.
(DICT_LANGUAGE): Define.
(dict_create_hashed, dict_create_hashed_expandable)
(dict_create_linear, dict_create_linear_expandable): New parameter
'language'. Set the dictionary's language.
(iter_match_first_hashed): Adjust to rename.
(insert_symbol_hashed): Assert we don't see mismatching
languages. Adjust to rename.
(dict_hash): Rename to ...
(default_search_name_hash): ... this and make extern.
* dictionary.h (struct language_defn): Forward declare.
(dict_create_hashed): New parameter 'language'.
* dwarf2read.c (dwarf2_start_symtab): Pass down language.
* f-lang.c (f_language_defn): Install default_search_name_hash.
* go-lang.c (go_language_defn): Install default_search_name_hash.
* jit.c (finalize_symtab): Pass compunit's language to dictionary
creation.
* language.c (unknown_language_defn, auto_language_defn):
* language.h (language_defn::la_search_name_hash): New field.
(default_search_name_hash): Declare.
* m2-lang.c (m2_language_defn): Install default_search_name_hash.
* mdebugread.c (new_block): New parameter 'language'.
* mdebugread.c (parse_symbol): Pass symbol language to block
allocation.
(psymtab_to_symtab_1): Pass down language.
(new_symtab): Pass compunit's language to block allocation.
* objc-lang.c (objc_language_defn): Install
default_search_name_hash.
* opencl-lang.c (opencl_language_defn):
* p-lang.c (pascal_language_defn): Install
default_search_name_hash.
* rust-lang.c (rust_language_defn): Install
default_search_name_hash.
* stabsread.h (enum language): Forward declare.
(process_one_symbol): Add 'language' parameter.
* symtab.c (search_name_hash): New function.
* symtab.h (search_name_hash): Declare.
* xcoffread.c (read_xcoff_symtab): Pass language to start_symtab.
2017-11-08 23:07:56 +08:00
|
|
|
default_search_name_hash,
|
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,
|
2019-03-27 03:34:06 +08:00
|
|
|
NULL,
|
2019-04-10 06:06:41 +08:00
|
|
|
c_is_string_type_p,
|
2019-03-27 03:34:06 +08:00
|
|
|
"{...}" /* la_struct_too_deep_ellipsis */
|
2010-11-05 22:31:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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]
|
2017-09-28 01:02:00 +08:00
|
|
|
= arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
|
2010-11-05 22:31:30 +08:00
|
|
|
|
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);
|
|
|
|
}
|