This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA] Assuming malloc exists in callfwmall.exp
- To: fnasser at cygnus dot com, msnyder at cygnus dot com
- Subject: Re: [RFA] Assuming malloc exists in callfwmall.exp
- From: Michael Elizabeth Chastain <chastain at cygnus dot com>
- Date: Wed, 14 Feb 2001 13:40:59 -0800
- Cc: gdb-patches at sources dot redhat dot com, keiths at cygnus dot com
> But how is it possible that GDB needs malloc() when the target does not
> have it?
(gdb) print strlen("foo")
GDB needs some mechanism to grab scratch memory in the target.
malloc() is the only mechanism that it has.
Michael
/* gdb/valops.c */
/* Allocate NBYTES of space in the inferior using the inferior's malloc
and return a value that is a pointer to the allocated space. */
value_ptr
value_allocate_space_in_inferior (int len)
{
value_ptr blocklen;
register value_ptr val = find_function_in_inferior ("malloc");
blocklen = value_from_longest (builtin_type_int, (LONGEST) len);
val = call_function_by_hand (val, 1, &blocklen);
if (value_logical_not (val))
{
if (!target_has_execution)
error ("No memory available to program now: you need to start the target first");
else
error ("No memory available to program: call to malloc failed");
}
return val;
}