mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-22 17:23:06 +00:00
libdrgn: add drgn_error_from_string_builder()
And use that instead of exposing drgn_error_create_nodup().
This commit is contained in:
parent
b0f10d3b58
commit
e21ed988fb
@ -10,6 +10,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "string_builder.h"
|
||||
|
||||
LIBDRGN_PUBLIC struct drgn_error drgn_enomem = {
|
||||
.code = DRGN_ERROR_NO_MEMORY,
|
||||
@ -26,8 +27,8 @@ struct drgn_error drgn_not_elf = {
|
||||
.message = "not an ELF file",
|
||||
};
|
||||
|
||||
struct drgn_error *drgn_error_create_nodup(enum drgn_error_code code,
|
||||
char *message)
|
||||
static struct drgn_error *drgn_error_create_nodup(enum drgn_error_code code,
|
||||
char *message)
|
||||
{
|
||||
struct drgn_error *err;
|
||||
|
||||
@ -102,6 +103,18 @@ LIBDRGN_PUBLIC struct drgn_error *drgn_error_format(enum drgn_error_code code,
|
||||
return drgn_error_create_nodup(code, message);
|
||||
}
|
||||
|
||||
struct drgn_error *drgn_error_from_string_builder(enum drgn_error_code code,
|
||||
struct string_builder *sb)
|
||||
{
|
||||
char *message;
|
||||
|
||||
if (!string_builder_finalize(sb, &message)) {
|
||||
free(sb->str);
|
||||
return &drgn_enomem;
|
||||
}
|
||||
return drgn_error_create_nodup(code, message);
|
||||
}
|
||||
|
||||
LIBDRGN_PUBLIC void drgn_error_fwrite(FILE *file, struct drgn_error *err)
|
||||
{
|
||||
if (err->code == DRGN_ERROR_OS) {
|
||||
|
@ -40,14 +40,15 @@ extern struct drgn_error drgn_stop;
|
||||
/** Not an ELF file. */
|
||||
extern struct drgn_error drgn_not_elf;
|
||||
|
||||
struct string_builder;
|
||||
|
||||
/**
|
||||
* Create a @ref drgn_error from a string that does not need to be duplicated.
|
||||
* Create a @ref drgn_error with a message from a @ref string_builder.
|
||||
*
|
||||
* If there is a failure to allocate memory for the error, @p message is freed
|
||||
* and @ref drgn_enomem is returned instead.
|
||||
* This finalizes the string builder.
|
||||
*/
|
||||
struct drgn_error *drgn_error_create_nodup(enum drgn_error_code code,
|
||||
char *message);
|
||||
struct drgn_error *drgn_error_from_string_builder(enum drgn_error_code code,
|
||||
struct string_builder *sb);
|
||||
|
||||
/** Create a @ref drgn_error from the libelf error indicator. */
|
||||
struct drgn_error *drgn_error_libelf(void)
|
||||
|
@ -1402,14 +1402,8 @@ static struct drgn_error *load_kernel_debug_info(struct drgn_program *prog)
|
||||
goto err;
|
||||
|
||||
if (missing_debug_info.len) {
|
||||
char *msg;
|
||||
|
||||
if (!string_builder_finalize(&missing_debug_info, &msg)) {
|
||||
err = &drgn_enomem;
|
||||
goto err;
|
||||
}
|
||||
return drgn_error_create_nodup(DRGN_ERROR_MISSING_DEBUG_INFO,
|
||||
msg);
|
||||
return drgn_error_from_string_builder(DRGN_ERROR_MISSING_DEBUG_INFO,
|
||||
&missing_debug_info);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user