From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13158 invoked by alias); 30 Jun 2011 18:47:25 -0000 Received: (qmail 13148 invoked by uid 22791); 30 Jun 2011 18:47:24 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,TW_YM,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 30 Jun 2011 18:47:06 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5UIl52q017030 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 30 Jun 2011 14:47:05 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p5UIl5oD027530; Thu, 30 Jun 2011 14:47:05 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p5UIl4UD017514; Thu, 30 Jun 2011 14:47:04 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Subject: FYI: more cleanup fixes Date: Thu, 30 Jun 2011 18:47:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-06/txt/msg00496.txt.bz2 I am checking this in on the trunk. I've updated the GCC plugin a little and it caught a few more obviously incorrect uses of cleanups. Built and regtested by the buildbot. There are still a number of failures where the fix was not as obvious: ../../archer/gdb/remote-mips.c: In function =E2=80=98mips_initialize=E2=80= =99: ../../archer/gdb/remote-mips.c:1419:7: error: cleanup stack is not empty at= return [-fpermissive] ../../archer/gdb/remote-mips.c: In function =E2=80=98mips_exit_debug=E2=80= =99: ../../archer/gdb/remote-mips.c:1400:1: error: cleanup stack is not empty at= return [-fpermissive] ../../archer/gdb/remote-mips.c: In function =E2=80=98common_open=E2=80=99: ../../archer/gdb/remote-mips.c:1659:1: error: cleanup stack is not empty at= return [-fpermissive] ../../archer/gdb/linux-nat.c: In function =E2=80=98linux_nat_info_proc_cmd= =E2=80=99: ../../archer/gdb/linux-nat.c:4887:1: error: cleanup stack is not empty at r= eturn [-fpermissive] ../../archer/gdb/linux-nat.c: In function =E2=80=98linux_child_pid_to_exec_= file=E2=80=99: ../../archer/gdb/linux-nat.c:4197:1: error: cleanup stack is not empty at r= eturn [-fpermissive] ../../archer/gdb/linux-nat.c: In function =E2=80=98linux_nat_make_corefile_= notes=E2=80=99: ../../archer/gdb/linux-nat.c:4601:3: error: cleanup stack is not empty at r= eturn [-fpermissive] The linux_child_pid_to_exec_file one is interesting -- nearly all of the existing pid_to_exec_file methods return malloc'd memory, despite the spec in target.h. Perhaps we should change the spec, I think only the Windows variant would need a minor tweak. ../../archer/gdb/breakpoint.c: In function =E2=80=98breakpoint_re_set_defau= lt=E2=80=99: ../../archer/gdb/breakpoint.c:11448:1: error: cleanup stack is not empty at= return [-fpermissive] ../../archer/gdb/ada-lang.c: In function =E2=80=98ada_make_symbol_completio= n_list=E2=80=99: ../../archer/gdb/ada-lang.c:5649:5: error: cleanup stack is not empty at re= turn [-fpermissive] ../../archer/gdb/record.c: In function =E2=80=98record_wait_1=E2=80=99: ../../archer/gdb/record.c:1466:1: error: cleanup stack is not empty at retu= rn [-fpermissive] This one seem particularly bad -- lots of return paths without running cleanups. Tom 2011-06-30 Tom Tromey * symfile-mem.c (symbol_file_add_from_memory): Call do_cleanups. * solib-svr4.c (open_symbol_file_object): Call do_cleanups on all return paths. Defer final do_cleanups until last return. * arm-tdep.c (arm_exidx_new_objfile): Make null cleanup after early return. diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 433ce21..1a75af1 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -2211,7 +2211,7 @@ arm_obj_section_from_vma (struct objfile *objfile, bf= d_vma vma) static void arm_exidx_new_objfile (struct objfile *objfile) { - struct cleanup *cleanups =3D make_cleanup (null_cleanup, NULL); + struct cleanup *cleanups; struct arm_exidx_data *data; asection *exidx, *extab; bfd_vma exidx_vma =3D 0, extab_vma =3D 0; @@ -2222,6 +2222,7 @@ arm_exidx_new_objfile (struct objfile *objfile) /* If we've already touched this file, do nothing. */ if (!objfile || objfile_data (objfile, arm_exidx_data_key) !=3D NULL) return; + cleanups =3D make_cleanup (null_cleanup, NULL); =20 /* Read contents of exception table and index. */ exidx =3D bfd_get_section_by_name (objfile->obfd, ".ARM.exidx"); diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index f668f83..d92a83c 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1021,17 +1021,26 @@ open_symbol_file_object (void *from_ttyp) =20 if (symfile_objfile) if (!query (_("Attempt to reload symbols from process? "))) - return 0; + { + do_cleanups (cleanups); + return 0; + } =20 /* Always locate the debug struct, in case it has moved. */ info->debug_base =3D 0; if (locate_base (info) =3D=3D 0) - return 0; /* failed somehow... */ + { + do_cleanups (cleanups); + return 0; /* failed somehow... */ + } =20 /* First link map member should be the executable. */ lm =3D solib_svr4_r_map (info); if (lm =3D=3D 0) - return 0; /* failed somehow... */ + { + do_cleanups (cleanups); + return 0; /* failed somehow... */ + } =20 /* Read address of name from target memory to GDB. */ read_memory (lm + lmo->l_name_offset, l_name_buf, l_name_size); @@ -1039,11 +1048,11 @@ open_symbol_file_object (void *from_ttyp) /* Convert the address to host format. */ l_name =3D extract_typed_address (l_name_buf, ptr_type); =20 - /* Free l_name_buf. */ - do_cleanups (cleanups); - if (l_name =3D=3D 0) - return 0; /* No filename. */ + { + do_cleanups (cleanups); + return 0; /* No filename. */ + } =20 /* Now fetch the filename from target memory. */ target_read_string (l_name, &filename, SO_NAME_MAX_PATH_SIZE - 1, &errco= de); @@ -1053,12 +1062,14 @@ open_symbol_file_object (void *from_ttyp) { warning (_("failed to read exec filename from attached file: %s"), safe_strerror (errcode)); + do_cleanups (cleanups); return 0; } =20 /* Have a pathname: read the symbol file. */ symbol_file_add_main (filename, from_tty); =20 + do_cleanups (cleanups); return 1; } =20 diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c index 6da5a1c..bef28c7 100644 --- a/gdb/symfile-mem.c +++ b/gdb/symfile-mem.c @@ -72,6 +72,7 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR= addr, char *name, bfd_vma loadbase; struct section_addr_info *sai; unsigned int i; + struct cleanup *cleanup; =20 if (bfd_get_flavour (templ) !=3D bfd_target_elf_flavour) error (_("add-symbol-file-from-memory not supported for this target")); @@ -97,7 +98,7 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR= addr, char *name, } =20 sai =3D alloc_section_addr_info (bfd_count_sections (nbfd)); - make_cleanup (xfree, sai); + cleanup =3D make_cleanup (xfree, sai); i =3D 0; for (sec =3D nbfd->sections; sec !=3D NULL; sec =3D sec->next) if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) !=3D 0) @@ -114,6 +115,7 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_AD= DR addr, char *name, /* This might change our ideas about frames already looked at. */ reinit_frame_cache (); =20 + do_cleanups (cleanup); return objf; } =20