[powerpc] crash trying to allocate memory in inferior
authorJoel Brobecker <brobecker@gnat.com>
Mon, 24 Oct 2011 16:51:36 +0000 (16:51 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Mon, 24 Oct 2011 16:51:36 +0000 (16:51 +0000)
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.

gdb/ChangeLog
gdb/ppc-sysv-tdep.c

index 30cf1449ca6a4e30ff6fca786fb544bd46316f43..f5cdd454e8f0e0c66382d584fd70c01928aa63d8 100644 (file)
@@ -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
index e4313633c8d0cba2d91293aff45aa63e1e74c175..bda45446ac840cdd022b2e23e3cfe7b8a4a2333f 100644 (file)
@@ -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;
 
This page took 0.033227 seconds and 4 git commands to generate.