From patchwork Mon Apr 6 17:27:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 6021 Received: (qmail 15341 invoked by alias); 6 Apr 2015 17:27:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 15267 invoked by uid 89); 6 Apr 2015 17:27:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_50, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 06 Apr 2015 17:27:05 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 1E50CBBF5A for ; Mon, 6 Apr 2015 17:27:04 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t36HR2Dk017312; Mon, 6 Apr 2015 13:27:02 -0400 Subject: [PATCH v2 5/9] compile: Use -Wall, not -w From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: Phil Muldoon Date: Mon, 06 Apr 2015 19:27:01 +0200 Message-ID: <20150406172701.31404.63576.stgit@host1.jankratochvil.net> In-Reply-To: <20150406172623.31404.58833.stgit@host1.jankratochvil.net> References: <20150406172623.31404.58833.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes Hi, for a reason unknown to me GDB was using -w instead of -Wall for 'compile code'. The problem is later patch for 'compile printf' really needs some warnings to be able to catch for example missing format string parameters: (gdb) compile printf "%d\n" GCC does not seem to be able to cancel -w (there is nothing like -no-w). Besides that I think even 'compile code' can benefit from -Wall. That #ifndef hack in print_one_macro() is not nice but while GCC does not warn for redefinitions like #define MACRO val #define MACRO val together with the GCC build-in macros I haven't found any other way how to prevent the macro-redefinition warnings (when -w is no longer in effect). That new testsuite XFAIL is there as if one changes the struct definition to be compliant with cv-qualifiers (to prevent the warnings): struct struct_type { - struct struct_type *selffield; + volatile struct struct_type *selffield; only then GCC/GDB will hit the crash, described in that GDB PR 18202. Thanks, Jan gdb/ChangeLog 2015-04-05 Jan Kratochvil * compile/compile-c-support.c (print_one_macro): Use #ifndef. (generate_register_struct): Use __gdb_uintptr for TYPE_CODE_PTR. (c_compute_program): Call generate_register_struct after typedefs. * compile/compile-loc2c.c (push, pushf_register_address) (pushf_register): Cast to GCC_UINTPTR. (do_compile_dwarf_expr_to_c): Use unused attribute. Add space after type. Use GCC_UINTPTR instead of void *. Remove excessive cast. (compile_dwarf_expr_to_c): Use GCC_UINTPTR instead of void *. * compile/compile.c (_initialize_compile): Enable warnings for COMPILE_ARGS. gdb/testsuite/ChangeLog 2015-04-05 Jan Kratochvil * gdb.compile/compile-ops.exp: Cast param to void. * gdb.compile/compile.exp: Complete type for _gdb_expr. (compile code struct_object.selffield = &struct_object): Add xfail. --- gdb/compile/compile-c-support.c | 12 +++++++----- gdb/compile/compile-loc2c.c | 22 +++++++++++++--------- gdb/compile/compile.c | 7 +++++-- gdb/testsuite/gdb.compile/compile-ops.exp | 2 +- gdb/testsuite/gdb.compile/compile.exp | 15 ++++++++++----- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c index 1711cda..48a17e2 100644 --- a/gdb/compile/compile-c-support.c +++ b/gdb/compile/compile-c-support.c @@ -131,7 +131,9 @@ print_one_macro (const char *name, const struct macro_definition *macro, if (line == 0) return; - fprintf_filtered (file, "#define %s", name); + /* None of -Wno-builtin-macro-redefined, #undef first + or plain #define of the same value would avoid a warning. */ + fprintf_filtered (file, "#ifndef %s\n# define %s", name, name); if (macro->kind == macro_function_like) { @@ -147,7 +149,7 @@ print_one_macro (const char *name, const struct macro_definition *macro, fputs_filtered (")", file); } - fprintf_filtered (file, " %s\n", macro->replacement); + fprintf_filtered (file, " %s\n#endif\n", macro->replacement); } /* Write macro definitions at PC to FILE. */ @@ -252,7 +254,7 @@ generate_register_struct (struct ui_file *stream, struct gdbarch *gdbarch, switch (TYPE_CODE (regtype)) { case TYPE_CODE_PTR: - fprintf_filtered (stream, "void *%s", regname); + fprintf_filtered (stream, "__gdb_uintptr %s", regname); break; case TYPE_CODE_INT: @@ -340,8 +342,6 @@ c_compute_program (struct compile_instance *inst, expr_block, expr_pc); make_cleanup (xfree, registers_used); - generate_register_struct (buf, gdbarch, registers_used); - fputs_unfiltered ("typedef unsigned int" " __attribute__ ((__mode__(__pointer__)))" " __gdb_uintptr;\n", @@ -363,6 +363,8 @@ c_compute_program (struct compile_instance *inst, " __gdb_int_%s;\n", mode, mode); } + + generate_register_struct (buf, gdbarch, registers_used); } add_code_header (inst->scope, buf); diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c index 6a3615d..6f53814 100644 --- a/gdb/compile/compile-loc2c.c +++ b/gdb/compile/compile-loc2c.c @@ -436,7 +436,8 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size, static void push (int indent, struct ui_file *stream, ULONGEST l) { - fprintfi_filtered (indent, stream, "__gdb_stack[++__gdb_tos] = %s;\n", + fprintfi_filtered (indent, stream, + "__gdb_stack[++__gdb_tos] = (" GCC_UINTPTR ") %s;\n", hex_string (l)); } @@ -520,7 +521,8 @@ pushf_register_address (int indent, struct ui_file *stream, struct cleanup *cleanups = make_cleanup (xfree, regname); registers_used[regnum] = 1; - pushf (indent, stream, "&" COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s", + pushf (indent, stream, + "(" GCC_UINTPTR ") &" COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s", regname); do_cleanups (cleanups); @@ -544,7 +546,8 @@ pushf_register (int indent, struct ui_file *stream, pushf (indent, stream, COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s", regname); else - pushf (indent, stream, COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s + %s", + pushf (indent, stream, + COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s + (" GCC_UINTPTR ") %s", regname, hex_string (offset)); do_cleanups (cleanups); @@ -605,7 +608,8 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream, ++scope; - fprintfi_filtered (indent, stream, "%s%s;\n", type_name, result_name); + fprintfi_filtered (indent, stream, "__attribute__ ((unused)) %s %s;\n", + type_name, result_name); fprintfi_filtered (indent, stream, "{\n"); indent += 2; @@ -899,7 +903,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream, (long) (op_ptr - base)); do_compile_dwarf_expr_to_c (indent, stream, - "void *", fb_name, + GCC_UINTPTR, fb_name, sym, pc, arch, registers_used, addr_size, datastart, datastart + datalen, @@ -1080,7 +1084,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream, "__cfa_%ld", (long) (op_ptr - base)); do_compile_dwarf_expr_to_c (indent, stream, - "void *", cfa_name, + GCC_UINTPTR, cfa_name, sym, pc, arch, registers_used, addr_size, cfa_start, cfa_end, @@ -1117,8 +1121,8 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream, } } - fprintfi_filtered (indent, stream, "%s = (%s) __gdb_stack[__gdb_tos];\n", - result_name, type_name); + fprintfi_filtered (indent, stream, "%s = __gdb_stack[__gdb_tos];\n", + result_name); fprintfi_filtered (indent - 2, stream, "}\n"); do_cleanups (cleanup); @@ -1134,7 +1138,7 @@ compile_dwarf_expr_to_c (struct ui_file *stream, const char *result_name, const gdb_byte *op_ptr, const gdb_byte *op_end, struct dwarf2_per_cu_data *per_cu) { - do_compile_dwarf_expr_to_c (2, stream, "void *", result_name, sym, pc, + do_compile_dwarf_expr_to_c (2, stream, GCC_UINTPTR, result_name, sym, pc, arch, registers_used, addr_size, op_ptr, op_end, NULL, per_cu); } diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 621de66..ab19a5d 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -680,8 +680,11 @@ String quoting is parsed like in shell, for example:\n\ absolute target address. -fPIC is not used at is would require from GDB to generate .got. */ " -fPIE" - /* We don't want warnings. */ - " -w" + /* We want warnings, except for some commonly happening for GDB commands. */ + " -Wall " + " -Wno-implicit-function-declaration" + " -Wno-unused-but-set-variable" + " -Wno-unused-variable" /* Override CU's possible -fstack-protector-strong. */ " -fno-stack-protector" ); diff --git a/gdb/testsuite/gdb.compile/compile-ops.exp b/gdb/testsuite/gdb.compile/compile-ops.exp index 26882bd..0ef3c8d 100644 --- a/gdb/testsuite/gdb.compile/compile-ops.exp +++ b/gdb/testsuite/gdb.compile/compile-ops.exp @@ -416,7 +416,7 @@ if {[skip_compile_feature_tests]} { } # If we have a bug, this will hang. -gdb_test_no_output "compile code param" +gdb_test_no_output "compile code (void) param" # We can't access optimized-out variables, but their presence should # not affect compilations that don't refer to them. diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp index dc09770..abe5e9b 100644 --- a/gdb/testsuite/gdb.compile/compile.exp +++ b/gdb/testsuite/gdb.compile/compile.exp @@ -71,13 +71,13 @@ gdb_test_no_output "compile -- f = 10" \ gdb_test "compile f = 10;" ".*= 10;: No such file.*" \ "Test abbreviations and code collision" -gdb_test_no_output "compile -r -- _gdb_expr(){int i = 5;}" \ +gdb_test_no_output "compile -r -- void _gdb_expr(){int i = 5;}" \ "Test delimiter with -r" -gdb_test_no_output "compile -raw -- _gdb_expr(){int i = 5;}" \ +gdb_test_no_output "compile -raw -- void _gdb_expr(){int i = 5;}" \ "Test delimiter with -raw" -gdb_test "compile -- -r _gdb_expr(){int i = 5;}" \ +gdb_test "compile -- -r void _gdb_expr(){int i = 5;}" \ ".* error: 'r' undeclared \\(first use in this function\\).*" \ "Test delimiter with -r after it" @@ -189,7 +189,12 @@ gdb_test "p localvar" " = 1" # Test setting fields and also many different types. # -gdb_test_no_output "compile code struct_object.selffield = &struct_object" +set test "compile code struct_object.selffield = &struct_object" +gdb_test_multiple $test $test { + -re "gdb command line:1:25: warning: assignment discards 'volatile' qualifier from pointer target type \\\[-Wdiscarded-qualifiers\\\]\r\n$gdb_prompt $" { + xfail "$test (PR compile/18202)" + } +} gdb_test "print struct_object.selffield == &struct_object" " = 1" gdb_test_no_output "compile code struct_object.charfield = 1" @@ -261,7 +266,7 @@ gdb_test "print 'compile.c'::globalshadow" " = 77000" \ # Test GOT vs. resolving jit function pointers. -gdb_test_no_output "compile -raw -- int func(){return 21;} _gdb_expr(){int (*funcp)()=func; if (funcp()!=21) abort();}" \ +gdb_test_no_output "compile -raw -- int func(){return 21;} void _gdb_expr(){ void abort (void); int (*funcp)()=func; if (funcp()!=21) abort(); }" \ "pointer to jit function" #