contrib/elf2dmp: Fix error reporting style in pdb.c
include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Tested-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 20240307-elf2dmp-v4-7-4f324ad4d99d@daynix.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
1b806c36bc
commit
b1250455c7
@ -596,7 +596,7 @@ int main(int argc, char *argv[])
|
|||||||
goto out_ps;
|
goto out_ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdb_init_from_file(PDB_NAME, &pdb)) {
|
if (!pdb_init_from_file(PDB_NAME, &pdb)) {
|
||||||
eprintf("Failed to initialize PDB reader\n");
|
eprintf("Failed to initialize PDB reader\n");
|
||||||
goto out_pdb_file;
|
goto out_pdb_file;
|
||||||
}
|
}
|
||||||
|
@ -158,30 +158,30 @@ static void *pdb_ds_read_file(struct pdb_reader* r, uint32_t file_number)
|
|||||||
return pdb_ds_read(r->ds.header, block_list, file_size[file_number]);
|
return pdb_ds_read(r->ds.header, block_list, file_size[file_number]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pdb_init_segments(struct pdb_reader *r)
|
static bool pdb_init_segments(struct pdb_reader *r)
|
||||||
{
|
{
|
||||||
unsigned stream_idx = r->segments;
|
unsigned stream_idx = r->segments;
|
||||||
|
|
||||||
r->segs = pdb_ds_read_file(r, stream_idx);
|
r->segs = pdb_ds_read_file(r, stream_idx);
|
||||||
if (!r->segs) {
|
if (!r->segs) {
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->segs_size = pdb_get_file_size(r, stream_idx);
|
r->segs_size = pdb_get_file_size(r, stream_idx);
|
||||||
if (!r->segs_size) {
|
if (!r->segs_size) {
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pdb_init_symbols(struct pdb_reader *r)
|
static bool pdb_init_symbols(struct pdb_reader *r)
|
||||||
{
|
{
|
||||||
PDB_SYMBOLS *symbols;
|
PDB_SYMBOLS *symbols;
|
||||||
|
|
||||||
symbols = pdb_ds_read_file(r, 3);
|
symbols = pdb_ds_read_file(r, 3);
|
||||||
if (!symbols) {
|
if (!symbols) {
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->symbols = symbols;
|
r->symbols = symbols;
|
||||||
@ -198,18 +198,18 @@ static int pdb_init_symbols(struct pdb_reader *r)
|
|||||||
goto out_symbols;
|
goto out_symbols;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return true;
|
||||||
|
|
||||||
out_symbols:
|
out_symbols:
|
||||||
g_free(symbols);
|
g_free(symbols);
|
||||||
|
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr)
|
static bool pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr)
|
||||||
{
|
{
|
||||||
if (hdr->block_size == 0) {
|
if (hdr->block_size == 0) {
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(r->file_used, 0, sizeof(r->file_used));
|
memset(r->file_used, 0, sizeof(r->file_used));
|
||||||
@ -218,22 +218,22 @@ static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr)
|
|||||||
hdr->toc_page * hdr->block_size), hdr->toc_size);
|
hdr->toc_page * hdr->block_size), hdr->toc_size);
|
||||||
|
|
||||||
if (!r->ds.toc) {
|
if (!r->ds.toc) {
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pdb_reader_init(struct pdb_reader *r, void *data)
|
static bool pdb_reader_init(struct pdb_reader *r, void *data)
|
||||||
{
|
{
|
||||||
const char pdb7[] = "Microsoft C/C++ MSF 7.00";
|
const char pdb7[] = "Microsoft C/C++ MSF 7.00";
|
||||||
|
|
||||||
if (memcmp(data, pdb7, sizeof(pdb7) - 1)) {
|
if (memcmp(data, pdb7, sizeof(pdb7) - 1)) {
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdb_reader_ds_init(r, data)) {
|
if (!pdb_reader_ds_init(r, data)) {
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->ds.root = pdb_ds_read_file(r, 1);
|
r->ds.root = pdb_ds_read_file(r, 1);
|
||||||
@ -241,15 +241,15 @@ static int pdb_reader_init(struct pdb_reader *r, void *data)
|
|||||||
goto out_ds;
|
goto out_ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdb_init_symbols(r)) {
|
if (!pdb_init_symbols(r)) {
|
||||||
goto out_root;
|
goto out_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdb_init_segments(r)) {
|
if (!pdb_init_segments(r)) {
|
||||||
goto out_sym;
|
goto out_sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return true;
|
||||||
|
|
||||||
out_sym:
|
out_sym:
|
||||||
pdb_exit_symbols(r);
|
pdb_exit_symbols(r);
|
||||||
@ -258,7 +258,7 @@ out_root:
|
|||||||
out_ds:
|
out_ds:
|
||||||
pdb_reader_ds_exit(r);
|
pdb_reader_ds_exit(r);
|
||||||
|
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pdb_reader_exit(struct pdb_reader *r)
|
static void pdb_reader_exit(struct pdb_reader *r)
|
||||||
@ -269,7 +269,7 @@ static void pdb_reader_exit(struct pdb_reader *r)
|
|||||||
pdb_reader_ds_exit(r);
|
pdb_reader_ds_exit(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pdb_init_from_file(const char *name, struct pdb_reader *reader)
|
bool pdb_init_from_file(const char *name, struct pdb_reader *reader)
|
||||||
{
|
{
|
||||||
GError *gerr = NULL;
|
GError *gerr = NULL;
|
||||||
void *map;
|
void *map;
|
||||||
@ -278,21 +278,21 @@ int pdb_init_from_file(const char *name, struct pdb_reader *reader)
|
|||||||
if (gerr) {
|
if (gerr) {
|
||||||
eprintf("Failed to map PDB file \'%s\'\n", name);
|
eprintf("Failed to map PDB file \'%s\'\n", name);
|
||||||
g_error_free(gerr);
|
g_error_free(gerr);
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader->file_size = g_mapped_file_get_length(reader->gmf);
|
reader->file_size = g_mapped_file_get_length(reader->gmf);
|
||||||
map = g_mapped_file_get_contents(reader->gmf);
|
map = g_mapped_file_get_contents(reader->gmf);
|
||||||
if (pdb_reader_init(reader, map)) {
|
if (!pdb_reader_init(reader, map)) {
|
||||||
goto out_unmap;
|
goto out_unmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return true;
|
||||||
|
|
||||||
out_unmap:
|
out_unmap:
|
||||||
g_mapped_file_unref(reader->gmf);
|
g_mapped_file_unref(reader->gmf);
|
||||||
|
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pdb_exit(struct pdb_reader *reader)
|
void pdb_exit(struct pdb_reader *reader)
|
||||||
|
@ -233,7 +233,7 @@ struct pdb_reader {
|
|||||||
size_t segs_size;
|
size_t segs_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
int pdb_init_from_file(const char *name, struct pdb_reader *reader);
|
bool pdb_init_from_file(const char *name, struct pdb_reader *reader);
|
||||||
void pdb_exit(struct pdb_reader *reader);
|
void pdb_exit(struct pdb_reader *reader);
|
||||||
uint64_t pdb_resolve(uint64_t img_base, struct pdb_reader *r, const char *name);
|
uint64_t pdb_resolve(uint64_t img_base, struct pdb_reader *r, const char *name);
|
||||||
uint64_t pdb_find_public_v3_symbol(struct pdb_reader *reader, const char *name);
|
uint64_t pdb_find_public_v3_symbol(struct pdb_reader *reader, const char *name);
|
||||||
|
Loading…
Reference in New Issue
Block a user