alloc.c (backtrace_vector_finish): Add error_callback and data parameters.

* alloc.c (backtrace_vector_finish): Add error_callback and data
	parameters.  Call backtrace_vector_release.  Return address base.
	* mmap.c (backtrace_vector_finish): Add error_callback and data
	parameters.  Return address base.
	* dwarf.c (read_function_info): Get new address base from
	backtrace_vector_finish.
	* internal.h (backtrace_vector_finish): Update declaration.

From-SVN: r205716
This commit is contained in:
Ian Lance Taylor 2013-12-05 18:32:02 +00:00 committed by Ian Lance Taylor
parent e69dbe3721
commit bfd74f227d
5 changed files with 51 additions and 14 deletions

View File

@ -1,3 +1,13 @@
2013-12-05 Ian Lance Taylor <iant@google.com>
* alloc.c (backtrace_vector_finish): Add error_callback and data
parameters. Call backtrace_vector_release. Return address base.
* mmap.c (backtrace_vector_finish): Add error_callback and data
parameters. Return address base.
* dwarf.c (read_function_info): Get new address base from
backtrace_vector_finish.
* internal.h (backtrace_vector_finish): Update declaration.
2013-11-27 Ian Lance Taylor <iant@google.com> 2013-11-27 Ian Lance Taylor <iant@google.com>
* dwarf.c (find_address_ranges): New static function, broken out * dwarf.c (find_address_ranges): New static function, broken out

View File

@ -113,12 +113,24 @@ backtrace_vector_grow (struct backtrace_state *state ATTRIBUTE_UNUSED,
/* Finish the current allocation on VEC. */ /* Finish the current allocation on VEC. */
void void *
backtrace_vector_finish (struct backtrace_state *state ATTRIBUTE_UNUSED, backtrace_vector_finish (struct backtrace_state *state,
struct backtrace_vector *vec) struct backtrace_vector *vec,
backtrace_error_callback error_callback,
void *data)
{ {
vec->base = (char *) vec->base + vec->size; void *ret;
/* With this allocator we call realloc in backtrace_vector_grow,
which means we can't easily reuse the memory here. So just
release it. */
if (!backtrace_vector_release (state, vec, error_callback, data))
return NULL;
ret = vec->base;
vec->base = NULL;
vec->size = 0; vec->size = 0;
vec->alc = 0;
return ret;
} }
/* Release any extra space allocated for VEC. */ /* Release any extra space allocated for VEC. */

View File

@ -2535,19 +2535,23 @@ read_function_info (struct backtrace_state *state, struct dwarf_data *ddata,
if (pfvec->count == 0) if (pfvec->count == 0)
return; return;
addrs = (struct function_addrs *) pfvec->vec.base;
addrs_count = pfvec->count; addrs_count = pfvec->count;
if (fvec == NULL) if (fvec == NULL)
{ {
if (!backtrace_vector_release (state, &lvec.vec, error_callback, data)) if (!backtrace_vector_release (state, &lvec.vec, error_callback, data))
return; return;
addrs = (struct function_addrs *) pfvec->vec.base;
} }
else else
{ {
/* Finish this list of addresses, but leave the remaining space in /* Finish this list of addresses, but leave the remaining space in
the vector available for the next function unit. */ the vector available for the next function unit. */
backtrace_vector_finish (state, &fvec->vec); addrs = ((struct function_addrs *)
backtrace_vector_finish (state, &fvec->vec,
error_callback, data));
if (addrs == NULL)
return;
fvec->count = 0; fvec->count = 0;
} }

View File

@ -233,13 +233,17 @@ extern void *backtrace_vector_grow (struct backtrace_state *state, size_t size,
struct backtrace_vector *vec); struct backtrace_vector *vec);
/* Finish the current allocation on VEC. Prepare to start a new /* Finish the current allocation on VEC. Prepare to start a new
allocation. The finished allocation will never be freed. */ allocation. The finished allocation will never be freed. Returns
a pointer to the base of the finished entries, or NULL on
failure. */
extern void backtrace_vector_finish (struct backtrace_state *state, extern void* backtrace_vector_finish (struct backtrace_state *state,
struct backtrace_vector *vec); struct backtrace_vector *vec,
backtrace_error_callback error_callback,
void *data);
/* Release any extra space allocated for VEC. Returns 1 on success, 0 /* Release any extra space allocated for VEC. This may change
on failure. */ VEC->base. Returns 1 on success, 0 on failure. */
extern int backtrace_vector_release (struct backtrace_state *state, extern int backtrace_vector_release (struct backtrace_state *state,
struct backtrace_vector *vec, struct backtrace_vector *vec,

View File

@ -230,12 +230,19 @@ backtrace_vector_grow (struct backtrace_state *state,size_t size,
/* Finish the current allocation on VEC. */ /* Finish the current allocation on VEC. */
void void *
backtrace_vector_finish (struct backtrace_state *state ATTRIBUTE_UNUSED, backtrace_vector_finish (
struct backtrace_vector *vec) struct backtrace_state *state ATTRIBUTE_UNUSED,
struct backtrace_vector *vec,
backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED)
{ {
void *ret;
ret = vec->base;
vec->base = (char *) vec->base + vec->size; vec->base = (char *) vec->base + vec->size;
vec->size = 0; vec->size = 0;
return ret;
} }
/* Release any extra space allocated for VEC. */ /* Release any extra space allocated for VEC. */