From: Tom Tromey Date: Mon, 14 Dec 2020 16:43:20 +0000 (-0700) Subject: Do not manually dissect OP_TYPE operations X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a6f3c8a1a8353424f00946f073e11c321119a719;p=binutils-gdb.git Do not manually dissect OP_TYPE operations Some code in GDB will examine the structure of an expression to see if it starts with OP_TYPE, and then proceed to extract the type by hand. There is no need to do this dissection manually. evaluate_type does the same thing via an "allowed" API. This patch changes such code to use evaluate_type. In two cases this simplifies the code. Regression tested on x86-64 Fedora 28. gdb/ChangeLog 2020-12-14 Tom Tromey * dtrace-probe.c (dtrace_process_dof_probe): Use value_type. * typeprint.c (whatis_exp): Always use evaluate_type. (maintenance_print_type): Likewise. Simplify. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e15d6958cbf..0bf7d511f82 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-12-14 Tom Tromey + + * dtrace-probe.c (dtrace_process_dof_probe): Use value_type. + * typeprint.c (whatis_exp): Always use evaluate_type. + (maintenance_print_type): Likewise. Simplify. + 2020-12-14 Tom Tromey * dictionary.c (language_defn::search_name_hash): Ignore "B". diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c index 1d150fb25b9..3ea047fce80 100644 --- a/gdb/dtrace-probe.c +++ b/gdb/dtrace-probe.c @@ -493,7 +493,7 @@ dtrace_process_dof_probe (struct objfile *objfile, } if (expr != NULL && expr.get ()->elts[0].opcode == OP_TYPE) - type = expr.get ()->elts[1].type; + type = value_type (evaluate_type (expr.get ())); args.emplace_back (type, std::move (type_str), std::move (expr)); } diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 47019a23aed..2f671d9c80f 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -490,10 +490,12 @@ whatis_exp (const char *exp, int show) "whatis" prints the type of the expression without stripping any typedef level. "ptype" always strips all levels of typedefs. */ + val = evaluate_type (expr.get ()); + type = value_type (val); + if (show == -1 && expr->elts[0].opcode == OP_TYPE) { /* The user expression names a type directly. */ - type = expr->elts[1].type; /* If this is a typedef, then find its immediate target. Use check_typedef to resolve stubs, but ignore its result @@ -506,14 +508,6 @@ whatis_exp (const char *exp, int show) value to fetch the dynamic type from. */ val = NULL; } - else - { - /* The user expression names a type indirectly by naming an - object or expression of that type. Find that - indirectly-named type. */ - val = evaluate_type (expr.get ()); - type = value_type (val); - } } else { @@ -684,28 +678,14 @@ print_type_fixed_point (struct type *type, struct ui_file *stream) void maintenance_print_type (const char *type_name, int from_tty) { - struct value *val; - struct type *type; - if (type_name != NULL) { expression_up expr = parse_expression (type_name); - if (expr->elts[0].opcode == OP_TYPE) - { - /* The user expression names a type directly, just use that type. */ - type = expr->elts[1].type; - } - else - { - /* The user expression may name a type indirectly by naming an - object of that type. Find that indirectly named type. */ - val = evaluate_type (expr.get ()); - type = value_type (val); - } - if (type != NULL) - { - recursive_dump_type (type, 0); - } + struct value *val = evaluate_type (expr.get ()); + struct type *type = value_type (val); + + if (type != nullptr) + recursive_dump_type (type, 0); } }