mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 01:33: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 <string.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "string_builder.h"
|
||||||
|
|
||||||
LIBDRGN_PUBLIC struct drgn_error drgn_enomem = {
|
LIBDRGN_PUBLIC struct drgn_error drgn_enomem = {
|
||||||
.code = DRGN_ERROR_NO_MEMORY,
|
.code = DRGN_ERROR_NO_MEMORY,
|
||||||
@ -26,8 +27,8 @@ struct drgn_error drgn_not_elf = {
|
|||||||
.message = "not an ELF file",
|
.message = "not an ELF file",
|
||||||
};
|
};
|
||||||
|
|
||||||
struct drgn_error *drgn_error_create_nodup(enum drgn_error_code code,
|
static struct drgn_error *drgn_error_create_nodup(enum drgn_error_code code,
|
||||||
char *message)
|
char *message)
|
||||||
{
|
{
|
||||||
struct drgn_error *err;
|
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);
|
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)
|
LIBDRGN_PUBLIC void drgn_error_fwrite(FILE *file, struct drgn_error *err)
|
||||||
{
|
{
|
||||||
if (err->code == DRGN_ERROR_OS) {
|
if (err->code == DRGN_ERROR_OS) {
|
||||||
|
@ -40,14 +40,15 @@ extern struct drgn_error drgn_stop;
|
|||||||
/** Not an ELF file. */
|
/** Not an ELF file. */
|
||||||
extern struct drgn_error drgn_not_elf;
|
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
|
* This finalizes the string builder.
|
||||||
* and @ref drgn_enomem is returned instead.
|
|
||||||
*/
|
*/
|
||||||
struct drgn_error *drgn_error_create_nodup(enum drgn_error_code code,
|
struct drgn_error *drgn_error_from_string_builder(enum drgn_error_code code,
|
||||||
char *message);
|
struct string_builder *sb);
|
||||||
|
|
||||||
/** Create a @ref drgn_error from the libelf error indicator. */
|
/** Create a @ref drgn_error from the libelf error indicator. */
|
||||||
struct drgn_error *drgn_error_libelf(void)
|
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;
|
goto err;
|
||||||
|
|
||||||
if (missing_debug_info.len) {
|
if (missing_debug_info.len) {
|
||||||
char *msg;
|
return drgn_error_from_string_builder(DRGN_ERROR_MISSING_DEBUG_INFO,
|
||||||
|
&missing_debug_info);
|
||||||
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 NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user