public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-call-frame-cfa: protect dwarf expression evaluation against memory leaks
@ 2009-08-11 17:39 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2009-08-11 17:39 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-call-frame-cfa has been updated
       via  c09f5506acfca898b69b99e6d849d8ed22bff9a8 (commit)
       via  8b4e2c4f9bfd463e24cc8c0927fb197447f7e0b1 (commit)
      from  2029b500425a67fe148d5a7cfe6d03011c0a939d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit c09f5506acfca898b69b99e6d849d8ed22bff9a8
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Aug 11 11:36:39 2009 -0600

    protect dwarf expression evaluation against memory leaks
    
    	* dwarf2loc.c (dwarf2_evaluate_loc_desc): Make a cleanup.
    	(dwarf2_loc_desc_needs_frame): Likewise.
    	* dwarf2expr.h (make_cleanup_free_dwarf_expr_context): Declare.
    	* dwarf2expr.c (free_dwarf_expr_context_cleanup): New function.
    	(make_cleanup_free_dwarf_expr_context): Likewise.
    	* dwarf2-frame.c (execute_stack_op): Make a cleanup.

commit 8b4e2c4f9bfd463e24cc8c0927fb197447f7e0b1
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Aug 11 11:30:12 2009 -0600

    gdb
    	* frame.h (frame_unwinder_is): Rename from frame_base_is.
    	* frame.c (frame_unwinder_is): Rename from frame_base_is.
    	Rewrite.
    	* dwarf2-frame.c (dwarf2_frame_cfa): Use frame_unwinder_is and
    	get_frame_base.
    gdb/testsuite
    	* gdb.dwarf2/callframecfa.exp: New file.
    	* gdb.dwarf2/callframecfa.S: New file.

-----------------------------------------------------------------------

Summary of changes:
 gdb/dwarf2-frame.c                        |    9 +-
 gdb/dwarf2expr.c                          |   16 ++
 gdb/dwarf2expr.h                          |    2 +
 gdb/dwarf2loc.c                           |   10 +-
 gdb/frame.c                               |    6 +-
 gdb/frame.h                               |    5 +-
 gdb/testsuite/gdb.dwarf2/callframecfa.S   |  309 +++++++++++++++++++++++++++++
 gdb/testsuite/gdb.dwarf2/callframecfa.exp |   55 +++++
 8 files changed, 401 insertions(+), 11 deletions(-)
 create mode 100644 gdb/testsuite/gdb.dwarf2/callframecfa.S
 create mode 100644 gdb/testsuite/gdb.dwarf2/callframecfa.exp

First 500 lines of diff:
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index ea69300..6cfaa96 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -354,8 +354,11 @@ execute_stack_op (gdb_byte *exp, ULONGEST len, int addr_size,
 {
   struct dwarf_expr_context *ctx;
   CORE_ADDR result;
+  struct cleanup *old_chain;
 
   ctx = new_dwarf_expr_context ();
+  old_chain = make_cleanup_free_dwarf_expr_context (ctx);
+
   ctx->gdbarch = get_frame_arch (this_frame);
   ctx->addr_size = addr_size;
   ctx->baton = this_frame;
@@ -372,7 +375,7 @@ execute_stack_op (gdb_byte *exp, ULONGEST len, int addr_size,
   if (ctx->in_reg)
     result = read_reg (this_frame, result);
 
-  free_dwarf_expr_context (ctx);
+  do_cleanups (old_chain);
 
   return result;
 }
@@ -1254,9 +1257,9 @@ dwarf2_frame_base_sniffer (struct frame_info *this_frame)
 CORE_ADDR
 dwarf2_frame_cfa (struct frame_info *this_frame)
 {
-  if (! frame_base_is (this_frame, &dwarf2_frame_base))
+  if (! frame_unwinder_is (this_frame, &dwarf2_frame_unwind))
     error (_("can't compute CFA for this frame"));
-  return get_frame_base_address (this_frame);
+  return get_frame_base (this_frame);
 }
 \f
 const struct objfile_data *dwarf2_frame_objfile_data;
diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
index 8a962a4..6401e72 100644
--- a/gdb/dwarf2expr.c
+++ b/gdb/dwarf2expr.c
@@ -61,6 +61,22 @@ free_dwarf_expr_context (struct dwarf_expr_context *ctx)
   xfree (ctx);
 }
 
+/* Helper for make_cleanup_free_dwarf_expr_context.  */
+
+static void
+free_dwarf_expr_context_cleanup (void *arg)
+{
+  free_dwarf_expr_context (arg);
+}
+
+/* Return a cleanup that calls free_dwarf_expr_context.  */
+
+struct cleanup *
+make_cleanup_free_dwarf_expr_context (struct dwarf_expr_context *ctx)
+{
+  return make_cleanup (free_dwarf_expr_context_cleanup, ctx);
+}
+
 /* Expand the memory allocated to CTX's stack to contain at least
    NEED more elements than are currently used.  */
 
diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
index 97edf6c..6b3a068 100644
--- a/gdb/dwarf2expr.h
+++ b/gdb/dwarf2expr.h
@@ -134,6 +134,8 @@ struct dwarf_expr_piece
 
 struct dwarf_expr_context *new_dwarf_expr_context (void);
 void free_dwarf_expr_context (struct dwarf_expr_context *ctx);
+struct cleanup *
+    make_cleanup_free_dwarf_expr_context (struct dwarf_expr_context *ctx);
 
 void dwarf_expr_push (struct dwarf_expr_context *ctx, CORE_ADDR value);
 void dwarf_expr_pop (struct dwarf_expr_context *ctx);
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 930ba18..6930093 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -223,6 +223,7 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
   struct value *retval;
   struct dwarf_expr_baton baton;
   struct dwarf_expr_context *ctx;
+  struct cleanup *old_chain;
 
   if (size == 0)
     {
@@ -236,6 +237,8 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
   baton.objfile = dwarf2_per_cu_objfile (per_cu);
 
   ctx = new_dwarf_expr_context ();
+  old_chain = make_cleanup_free_dwarf_expr_context (ctx);
+
   ctx->gdbarch = get_objfile_arch (baton.objfile);
   ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
   ctx->baton = &baton;
@@ -291,7 +294,7 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
 
   set_value_initialized (retval, ctx->initialized);
 
-  free_dwarf_expr_context (ctx);
+  do_cleanups (old_chain);
 
   return retval;
 }
@@ -364,10 +367,13 @@ dwarf2_loc_desc_needs_frame (gdb_byte *data, unsigned short size,
   struct needs_frame_baton baton;
   struct dwarf_expr_context *ctx;
   int in_reg;
+  struct cleanup *old_chain;
 
   baton.needs_frame = 0;
 
   ctx = new_dwarf_expr_context ();
+  old_chain = make_cleanup_free_dwarf_expr_context (ctx);
+
   ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (per_cu));
   ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
   ctx->baton = &baton;
@@ -392,7 +398,7 @@ dwarf2_loc_desc_needs_frame (gdb_byte *data, unsigned short size,
           in_reg = 1;
     }
 
-  free_dwarf_expr_context (ctx);
+  do_cleanups (old_chain);
 
   return baton.needs_frame || in_reg;
 }
diff --git a/gdb/frame.c b/gdb/frame.c
index afa6e2a..2b5a5b6 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1847,11 +1847,9 @@ get_frame_args_address (struct frame_info *fi)
    otherwise.  */
 
 int
-frame_base_is (struct frame_info *fi, const struct frame_base *base)
+frame_unwinder_is (struct frame_info *fi, const struct frame_unwind *unwinder)
 {
-  if (fi->base == NULL)
-    fi->base = frame_base_find_by_frame (fi);
-  return fi->base == base;
+  return fi->unwind == unwinder;
 }
 
 /* Level of the selected frame: 0 for innermost, 1 for its caller, ...
diff --git a/gdb/frame.h b/gdb/frame.h
index 09bf628..611c6d3 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -696,9 +696,10 @@ extern struct frame_info *deprecated_safe_get_selected_frame (void);
 
 extern struct frame_info *create_new_frame (CORE_ADDR base, CORE_ADDR pc);
 
-/* Return true if the frame base for frame FI is BASE; false
+/* Return true if the frame unwinder for frame FI is UNWINDER; false
    otherwise.  */
 
-extern int frame_base_is (struct frame_info *fi, const struct frame_base *base);
+extern int frame_unwinder_is (struct frame_info *fi,
+			      const struct frame_unwind *unwinder);
 
 #endif /* !defined (FRAME_H)  */
diff --git a/gdb/testsuite/gdb.dwarf2/callframecfa.S b/gdb/testsuite/gdb.dwarf2/callframecfa.S
new file mode 100644
index 0000000..6d0421a
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/callframecfa.S
@@ -0,0 +1,309 @@
+/*
+   Copyright 2009 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* This was compiled from a trivial program just to test the
+   DW_OP_call_frame_cfa operator:
+
+    int func (int arg) {
+      return arg + 23;
+    }
+
+    int main(int argc, char *argv[]) {
+      func (77);
+    }
+*/
+
+	.file	"q.c"
+	.section	.debug_abbrev,"",@progbits
+.Ldebug_abbrev0:
+	.section	.debug_info,"",@progbits
+.Ldebug_info0:
+	.section	.debug_line,"",@progbits
+.Ldebug_line0:
+	.text
+.Ltext0:
+.globl func
+	.type	func, @function
+func:
+.LFB0:
+	.file 1 "q.c"
+	.loc 1 2 0
+	.cfi_startproc
+	pushl	%ebp
+	.cfi_def_cfa_offset 8
+	movl	%esp, %ebp
+	.cfi_offset 5, -8
+	.cfi_def_cfa_register 5
+	.loc 1 3 0
+	movl	8(%ebp), %eax
+	addl	$23, %eax
+	.loc 1 4 0
+	popl	%ebp
+	.cfi_restore 5
+	.cfi_def_cfa 4, 4
+	ret
+	.cfi_endproc
+.LFE0:
+	.size	func, .-func
+.globl _start
+	.type	_start, @function
+_start:
+.LFB1:
+	.loc 1 6 0
+	.cfi_startproc
+	pushl	%ebp
+	.cfi_def_cfa_offset 8
+	movl	%esp, %ebp
+	.cfi_offset 5, -8
+	.cfi_def_cfa_register 5
+	subl	$4, %esp
+	.loc 1 7 0
+	movl	$77, (%esp)
+	call	func
+	.loc 1 8 0
+	leave
+	.cfi_restore 5
+	.cfi_def_cfa 4, 4
+	ret
+	.cfi_endproc
+.LFE1:
+	.size	_start, .-_start
+.Letext0:
+	.section	.debug_info
+	.long	0x9e
+	.value	0x3
+	.long	.Ldebug_abbrev0
+	.byte	0x4
+	.uleb128 0x1
+	.long	.LASF5
+	.byte	0x1
+	.string	"q.c"
+	.long	.LASF6
+	.long	.Ltext0
+	.long	.Letext0
+	.long	.Ldebug_line0
+	.uleb128 0x2
+	.byte	0x1
+	.long	.LASF0
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.long	0x4f
+	.long	.LFB0
+	.long	.LFE0
+	.byte	0x1
+	.byte	0x9c
+	.long	0x4f
+	.uleb128 0x3
+	.string	"arg"
+	.byte	0x1
+	.byte	0x1
+	.long	0x4f
+	.byte	0x2
+	.byte	0x91
+	.sleb128 0
+	.byte	0x0
+	.uleb128 0x4
+	.byte	0x4
+	.byte	0x5
+	.string	"int"
+	.uleb128 0x2
+	.byte	0x1
+	.long	.LASF1
+	.byte	0x1
+	.byte	0x6
+	.byte	0x1
+	.long	0x4f
+	.long	.LFB1
+	.long	.LFE1
+	.byte	0x1
+	.byte	0x9c
+	.long	0x8e
+	.uleb128 0x5
+	.long	.LASF2
+	.byte	0x1
+	.byte	0x6
+	.long	0x4f
+	.byte	0x2
+	.byte	0x91
+	.sleb128 0
+	.uleb128 0x5
+	.long	.LASF3
+	.byte	0x1
+	.byte	0x6
+	.long	0x8e
+	.byte	0x2
+	.byte	0x91
+	.sleb128 4
+	.byte	0x0
+	.uleb128 0x6
+	.byte	0x4
+	.long	0x94
+	.uleb128 0x6
+	.byte	0x4
+	.long	0x9a
+	.uleb128 0x7
+	.byte	0x1
+	.byte	0x6
+	.long	.LASF4
+	.byte	0x0
+	.section	.debug_abbrev
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0x1
+	.uleb128 0x25
+	.uleb128 0xe
+	.uleb128 0x13
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x8
+	.uleb128 0x1b
+	.uleb128 0xe
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x12
+	.uleb128 0x1
+	.uleb128 0x10
+	.uleb128 0x6
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x2
+	.uleb128 0x2e
+	.byte	0x1
+	.uleb128 0x3f
+	.uleb128 0xc
+	.uleb128 0x3
+	.uleb128 0xe
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x27
+	.uleb128 0xc
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x12
+	.uleb128 0x1
+	.uleb128 0x40
+	.uleb128 0xa
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x3
+	.uleb128 0x5
+	.byte	0x0
+	.uleb128 0x3
+	.uleb128 0x8
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0xa
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x4
+	.uleb128 0x24
+	.byte	0x0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x8
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x5
+	.uleb128 0x5
+	.byte	0x0
+	.uleb128 0x3
+	.uleb128 0xe
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0xa
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x6
+	.uleb128 0xf
+	.byte	0x0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0x0
+	.byte	0x0
+	.uleb128 0x7
+	.uleb128 0x24
+	.byte	0x0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0xe
+	.byte	0x0
+	.byte	0x0
+	.byte	0x0
+	.section	.debug_pubnames,"",@progbits
+	.long	0x20
+	.value	0x2
+	.long	.Ldebug_info0
+	.long	0xa2
+	.long	0x25
+	.string	"func"
+	.long	0x56
+	.string	"main"
+	.long	0x0
+	.section	.debug_aranges,"",@progbits
+	.long	0x1c
+	.value	0x2
+	.long	.Ldebug_info0
+	.byte	0x4
+	.byte	0x0
+	.value	0x0
+	.value	0x0
+	.long	.Ltext0
+	.long	.Letext0-.Ltext0
+	.long	0x0
+	.long	0x0
+	.section	.debug_str,"MS",@progbits,1
+.LASF5:
+	.string	"GNU C 4.5.0 20090810 (experimental) [trunk revision 150633]"
+.LASF2:
+	.string	"argc"
+.LASF6:
+	.string	"/tmp"
+.LASF0:
+	.string	"func"
+.LASF3:
+	.string	"argv"
+.LASF1:
+	.string	"main"
+.LASF4:
+	.string	"char"
+	.ident	"GCC: (GNU) 4.5.0 20090810 (experimental) [trunk revision 150633]"
+	.section	.note.GNU-stack,"",@progbits
diff --git a/gdb/testsuite/gdb.dwarf2/callframecfa.exp b/gdb/testsuite/gdb.dwarf2/callframecfa.exp
new file mode 100644
index 0000000..00d67fc
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/callframecfa.exp
@@ -0,0 +1,55 @@
+# Copyright 2009 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-08-11 17:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-11 17:39 [SCM] archer-tromey-call-frame-cfa: protect dwarf expression evaluation against memory leaks tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).