From 6b1747cd135ff9859fceb6043179b1ef94363996 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 21 Nov 2018 11:55:12 +0000 Subject: invoke_xmethod & array_view This replaces more pointer+length with gdb::array_view. This time, around invoke_xmethod, and then propagating the fallout around, which inevitably leaks to the overload resolution code. There are several places in the code that want to grab a slice of an array, by advancing the array pointer, and decreasing the length pointer. This patch introduces a pair of new gdb::array_view::slice(...) methods to make that convenient and clear. Unit test included. gdb/ChangeLog: 2018-11-21 Pedro Alves * common/array-view.h (array_view::splice(size_type, size_t)): New. (array_view::splice(size_type)): New. * eval.c (eval_call, evaluate_funcall): Adjust to use array_view. * extension.c (xmethod_worker::get_arg_types): Adjust to return an std::vector. (xmethod_worker::get_result_type): Adjust to use gdb::array_view. * extension.h: Include "common/array-view.h". (xmethod_worker::invoke): Adjust to use gdb::array_view. (xmethod_worker::get_arg_types): Adjust to return an std::vector. (xmethod_worker::get_result_type): Adjust to use gdb::array_view. (xmethod_worker::do_get_arg_types): Adjust to use std::vector. (xmethod_worker::do_get_result_type): Adjust to use gdb::array_view. * gdbtypes.c (rank_function): Adjust to use gdb::array_view. * gdbtypes.h: Include "common/array-view.h". (rank_function): Adjust to use gdb::array_view. * python/py-xmethods.c (python_xmethod_worker::invoke) (python_xmethod_worker::do_get_arg_types) (python_xmethod_worker::do_get_result_type) (python_xmethod_worker::invoke): Adjust to new interfaces. * valarith.c (value_user_defined_cpp_op, value_user_defined_op) (value_x_binop, value_x_unop): Adjust to use gdb::array_view. * valops.c (find_overload_match, find_oload_champ_namespace) (find_oload_champ_namespace_loop, find_oload_champ): Adjust to use gdb:array_view and the new xmethod_worker interfaces. * value.c (result_type_of_xmethod, call_xmethod): Adjust to use gdb::array_view. * value.h (find_overload_match, result_type_of_xmethod) (call_xmethod): Adjust to use gdb::array_view. * unittests/array-view-selftests.c: Add slicing tests. --- gdb/unittests/array-view-selftests.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'gdb/unittests/array-view-selftests.c') diff --git a/gdb/unittests/array-view-selftests.c b/gdb/unittests/array-view-selftests.c index 74defa1..746062c 100644 --- a/gdb/unittests/array-view-selftests.c +++ b/gdb/unittests/array-view-selftests.c @@ -496,6 +496,28 @@ run_tests () for (size_t i = 0; i < len; i++) SELF_CHECK (view[i] == data[i]); } + + /* Test slicing. */ + { + gdb_byte data[] = {0x55, 0x66, 0x77, 0x88, 0x99}; + gdb::array_view view = data; + + { + auto slc = view.slice (1, 3); + SELF_CHECK (slc.data () == data + 1); + SELF_CHECK (slc.size () == 3); + SELF_CHECK (slc[0] == data[1]); + SELF_CHECK (slc[0] == view[1]); + } + + { + auto slc = view.slice (2); + SELF_CHECK (slc.data () == data + 2); + SELF_CHECK (slc.size () == 3); + SELF_CHECK (slc[0] == view[2]); + SELF_CHECK (slc[0] == data[2]); + } + } } } /* namespace array_view_tests */ -- cgit v1.1