Re: [RFA] Assuming malloc exists in callfwmall.exp

Michael Elizabeth Chastain
2001-02-14T13:41:00Z

> 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;
}