From 738671f06f6b08a35f411834490bf792bc50dd34 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Mon, 9 Jan 2017 13:39:27 -0800 Subject: [PATCH] Fix some compile print errors. Includes new code header, test corrections, using NULL for the name of anonymous types, and some other little cleanups. --- gdb/compile/compile-c-support.c | 20 +++---- gdb/compile/compile-cplus-templates.c | 2 +- gdb/compile/compile-cplus-types.c | 53 ++++++------------- .../gdb.compile/cp-simple-anonymous.exp | 6 +-- .../gdb.compile/cp-simple-member.exp | 4 +- 5 files changed, 32 insertions(+), 53 deletions(-) diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c index 5c931bdc566..1ee90ef0f53 100644 --- a/gdb/compile/compile-c-support.c +++ b/gdb/compile/compile-c-support.c @@ -451,6 +451,7 @@ struct cplus_add_code_header case COMPILE_I_PRINT_VALUE_SCOPE: fputs_unfiltered ( "#include \n" + "#include \n" "void " GCC_FE_WRAPPER_FUNCTION " (struct " @@ -486,15 +487,16 @@ struct cplus_add_input { case COMPILE_I_PRINT_ADDRESS_SCOPE: case COMPILE_I_PRINT_VALUE_SCOPE: - fprintf_unfiltered (buf, - "auto " COMPILE_I_EXPR_VAL " = %s;\n" - "decltype (%s) *" COMPILE_I_EXPR_PTR_TYPE ";\n" - "std::memcpy (" COMPILE_I_PRINT_OUT_ARG ", %s" - COMPILE_I_EXPR_VAL ",\n" - "sizeof (*" COMPILE_I_EXPR_PTR_TYPE "));\n" - ,input, input, - (type == COMPILE_I_PRINT_ADDRESS_SCOPE - ? "&" : "")); + fprintf_unfiltered + (buf, + "auto " COMPILE_I_EXPR_VAL " = %s;\n" + "decltype (" COMPILE_I_EXPR_VAL ") *" COMPILE_I_EXPR_PTR_TYPE ";\n" + "std::memcpy (" COMPILE_I_PRINT_OUT_ARG ", %s (" + COMPILE_I_EXPR_VAL "),\n" + "sizeof (" COMPILE_I_EXPR_VAL "));\n" + ,input, + (type == COMPILE_I_PRINT_ADDRESS_SCOPE + ? "std::__addressof" : "")); break; default: diff --git a/gdb/compile/compile-cplus-templates.c b/gdb/compile/compile-cplus-templates.c index 0dd03c440f6..f1922f932cf 100644 --- a/gdb/compile/compile-cplus-templates.c +++ b/gdb/compile/compile-cplus-templates.c @@ -635,7 +635,7 @@ void compile_cplus_instance::maybe_define_new_class_template (struct type *type, const char *decl_name) { - if (TYPE_N_TEMPLATE_ARGUMENTS (type) == 0) + if (TYPE_N_TEMPLATE_ARGUMENTS (type) == 0 || decl_name == NULL) return; std::string generic (compute_class_template_generic (decl_name, type)); diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index b313d5caf21..973ea5a6ee3 100644 --- a/gdb/compile/compile-cplus-types.c +++ b/gdb/compile/compile-cplus-types.c @@ -583,14 +583,11 @@ ccp_convert_typedef (compile_cplus_instance *instance, if (scope.nested_type () != GCC_TYPE_NONE) return scope.nested_type (); - struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); char *name = NULL; + struct cleanup *cleanups = make_cleanup (free_current_contents, &name); if (TYPE_NAME (type) != NULL) - { - name = cp_func_name (TYPE_NAME (type)); - make_cleanup (xfree, name); - } + name = cp_func_name (TYPE_NAME (type)); /* Make sure the scope for this type has been pushed. */ instance->enter_scope (scope); @@ -1300,26 +1297,12 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance, { const char *filename = NULL; /* !!keiths: FIXME */ unsigned short line = 0; + char *name = NULL; + struct cleanup *back_to = make_cleanup (free_current_contents, &name); /* Get the decl name of this type. */ - std::string name; if (TYPE_NAME (type) != NULL) - { - char *str = decl_name (TYPE_NAME (type)); - - name = str; - xfree (str); - } - else - { - if (TYPE_CODE (type) == TYPE_CODE_STRUCT) - { - name = (TYPE_DECLARED_CLASS (type) ? "anonymous class" - : "anonymous struct"); - } - else - name = "anonymous union"; - } + name = decl_name (TYPE_NAME (type)); /* First things first: If this type has any templates in it, make sure that we collect default arguments and get those types defined BEFORE @@ -1328,7 +1311,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance, /* If this is a new template class, make sure the generic has been seen and defined. */ - instance->maybe_define_new_class_template (type, name.c_str ()); + instance->maybe_define_new_class_template (type, name); instance->emit_class_template_decls (); /* Create a new scope for TYPE. */ @@ -1356,7 +1339,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance, { const char *what = TYPE_DECLARED_CLASS (type) ? "struct" : "class"; - resuld = instance->new_decl (what, name.c_str (), + resuld = instance->new_decl (what, name, GCC_CP_SYMBOL_CLASS | nested_access | (TYPE_DECLARED_CLASS (type) ? GCC_CP_FLAG_CLASS_NOFLAG @@ -1366,7 +1349,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance, else { gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION); - resuld = instance->new_decl ("union", name.c_str (), + resuld = instance->new_decl ("union", name, GCC_CP_SYMBOL_UNION | nested_access, 0, NULL, 0, filename, line); } @@ -1403,7 +1386,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance, } } - result = instance->start_class_definition (name.c_str (), resuld, &bases, + result = instance->start_class_definition (name, resuld, &bases, filename, line); xfree (bases.flags); xfree (bases.elements); @@ -1412,7 +1395,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance, { gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION); result - = instance->start_class_definition (name.c_str (), resuld, NULL, + = instance->start_class_definition (name, resuld, NULL, filename, line); } @@ -1428,10 +1411,11 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance, ccp_convert_struct_or_union_members (instance, type, result); /* All finished. */ - instance->finish_record_or_union (name.c_str (), TYPE_LENGTH (type)); + instance->finish_record_or_union (name, TYPE_LENGTH (type)); /* Pop all scopes. */ instance->leave_scope (); + do_cleanups (back_to); return result; } @@ -1445,10 +1429,8 @@ ccp_convert_enum (compile_cplus_instance *instance, struct type *type, { int i; gcc_type int_type; - char *name = NULL; const char *filename = NULL; unsigned short line = 0; - struct cleanup *cleanups; /* !!keiths: This does not appear to work. GCC complains about being unable to convert enum values from '(MyEnum)0' to 'int'. */ int scoped_enum_p = /*TYPE_DECLARED_CLASS (type) ? TRUE :*/ FALSE; @@ -1463,16 +1445,11 @@ ccp_convert_enum (compile_cplus_instance *instance, struct type *type, return scope.nested_type (); } - /* Create an empty cleanup chain. */ - cleanups = make_cleanup (null_cleanup, NULL); + char *name = NULL; + struct cleanup *cleanups = make_cleanup (free_current_contents, &name); if (TYPE_NAME (type) != NULL) - { - name = cp_func_name (TYPE_NAME (type)); - make_cleanup (xfree, name); - } - else - name = "anonymous enum"; + name = cp_func_name (TYPE_NAME (type)); /* Push all scopes. */ instance->enter_scope (scope); diff --git a/gdb/testsuite/gdb.compile/cp-simple-anonymous.exp b/gdb/testsuite/gdb.compile/cp-simple-anonymous.exp index 46db50f1d93..6ee1fbad25a 100644 --- a/gdb/testsuite/gdb.compile/cp-simple-anonymous.exp +++ b/gdb/testsuite/gdb.compile/cp-simple-anonymous.exp @@ -44,12 +44,12 @@ gdb_continue_to_breakpoint "testing location" # Reminder, "var" is an integer; all these types get converted to `int'. CompileExpression::new "var" -CompileExpression::test "anon_e" 3 +CompileExpression::test "anon_e" {(3|GHI)} CompileExpression::test "anon_u.aa" {97( 'a')?} CompileExpression::test "anon_s.len" 11 CompileExpression::test "a.u.b" 0 CompileExpression::test "a.s.len" 5 -CompileExpression::test "a.e" 10 +CompileExpression::test "a.e" {(10|A::AA)} CompileExpression::test "(*anon_s.ptr == 'a')" (1|true) CompileExpression::test "(*a.s.ptr != 'h')" (0|false) -CompileExpression::test "A::BB" 11 +CompileExpression::test "A::BB" {(11|A::BB)} diff --git a/gdb/testsuite/gdb.compile/cp-simple-member.exp b/gdb/testsuite/gdb.compile/cp-simple-member.exp index 5d759bcf17f..7fd734d8d00 100644 --- a/gdb/testsuite/gdb.compile/cp-simple-member.exp +++ b/gdb/testsuite/gdb.compile/cp-simple-member.exp @@ -46,9 +46,9 @@ CompileExpression::new "var" CompileExpression::test "a.public_" 1 CompileExpression::test "a.protected_" {(21|N::AB)} CompileExpression::test "a.private_" 3 -CompileExpression::test "A::s_public_" 10 +CompileExpression::test "A::s_public_" {(10|E_A)} CompileExpression::test "A::s_protected_" {(20|N::AA)} -CompileExpression::test "A::s_private_" 12 +CompileExpression::test "A::s_private_" {(12|E_C)} CompileExpression::test "A::ATYPE i = 10; var = i;" 10 -explicit CompileExpression::test "get_values (a)" 85 CompileExpression::test "myenum me = E_B; var = me;" 11 -explicit -- 2.47.3