Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [commit/powerpc] crash trying to allocate memory in inferior
Date: Mon, 24 Oct 2011 17:09:00 -0000	[thread overview]
Message-ID: <1319475191-2379-1-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <201102071924.p17JONol029741@d06av02.portsmouth.uk.ibm.com>

Our testsuite noticed a crash when trying to call a function which
requires GDB to allocate memory in the inferior. Typically, this
happens when one of the parameters is a string.  For instance, our
testcase tries:

    (gdb) call debug.trace (me, "You")
    [1]    32737 segmentation fault /path/to/gdb

What happens is that GDB sees the string, and thus tries to allocate
memory for it in the inferior:

> /* Allocate NBYTES of space in the inferior using the inferior's
>    malloc and return a value that is a pointer to the allocated
>    space.  */
>
> struct value *
> value_allocate_space_in_inferior (int len)
> {
>   struct objfile *objf;
>   struct value *val = find_function_in_inferior ("malloc", &objf);

And find_function_in_inferior first searches the symtab in case
we have debug info.  But, in our case (bareboard powerpc), we don't,
so it gets "malloc"'s address from the minimal symbols, and builds
a value whose type is a TYPE_CODE_PTR, not a TYPE_CODE_FUNC.

As a result, when we later try to make the call to malloc, we end up
inside the powerpc tdep code that has:

> do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
[...]
>   if (func_type
>       && TYPE_CALLING_CONVENTION (func_type) == DW_CC_GDB_IBM_OpenCL)

The problem is that func_type is not a TYPE_CODE_FUNC, and thus
the type-specific kind is not TYPE_SPECIFIC_FUNC, and so we do
TYPE_CALLING_CONVENTION is an invalid access.

Interestingly, the other call to TYPE_CALLING_CONVENTION is correctly
preceded by a check of the type's TYPE_CODE (making sure that it is
TYPE_CODE_FUNC).

gdb/ChangeLog:

        * ppc-sysv-tdep.c (do_ppc_sysv_return_value): Do not check
        FUNC_TYPE's calling convention if FUNC_TYPE is not a function.

tested on powerpc-elf. Checked in.

---
 gdb/ChangeLog       |    5 +++++
 gdb/ppc-sysv-tdep.c |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 30cf144..f5cdd45 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2011-10-24  Joel Brobecker  <brobecker@adacore.com>
+
+	* ppc-sysv-tdep.c (do_ppc_sysv_return_value): Do not check
+	FUNC_TYPE's calling convention if FUNC_TYPE is not a function.
+
 2011-10-24  Pedro Alves  <pedro@codesourcery.com>
 
 	* linux-nat.c (linux_handle_extended_wait): When handling a clone
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index e431363..bda4544 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -692,6 +692,7 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
   int opencl_abi = 0;
 
   if (func_type
+      && TYPE_CODE (func_type) == TYPE_CODE_FUNC
       && TYPE_CALLING_CONVENTION (func_type) == DW_CC_GDB_IBM_OpenCL)
     opencl_abi = 1;
 
-- 
1.7.1


  parent reply	other threads:[~2011-10-24 16:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-02 17:48 [rfc] Implement support for IBM XL C for OpenCL vector ABI Ulrich Weigand
2011-02-04 16:47 ` Tom Tromey
2011-02-07 19:25   ` Ulrich Weigand
2011-02-07 20:05     ` Tom Tromey
2011-02-08 13:30       ` Ulrich Weigand
2011-02-14 12:59         ` Luis Machado
2011-02-14 12:07           ` Luis Machado
2011-02-14 13:41           ` Yao Qi
2011-10-24 17:09     ` Joel Brobecker [this message]
2011-10-26 17:31       ` [commit/powerpc] crash trying to allocate memory in inferior Ulrich Weigand
2011-10-26 18:16         ` Joel Brobecker
2011-02-13 15:38 ` [rfc] Implement support for IBM XL C for OpenCL vector ABI Mark Kettenis
2011-02-14 13:47   ` Ulrich Weigand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1319475191-2379-1-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox