Fix formatting and apply clang-tidy fixes

This commit is contained in:
Les De Ridder 2020-07-10 18:17:38 +02:00
parent 43ba294701
commit d82430d33c
1 changed files with 92 additions and 88 deletions

View File

@ -19,7 +19,6 @@ HACK: Honestly, this whole thing is a hack:
#undef QUIT #undef QUIT
#include <libr/r_pdb.h> #include <libr/r_pdb.h>
#include <libr/r_core.h>
#undef QUIT #undef QUIT
#define QUIT maybe_quit () #define QUIT maybe_quit ()
@ -40,8 +39,7 @@ HACK: Honestly, this whole thing is a hack:
typedef void (*parse_stream_) (void *stream, R_STREAM_FILE *stream_file); typedef void (*parse_stream_) (void *stream, R_STREAM_FILE *stream_file);
typedef struct typedef struct {
{
int indx; int indx;
parse_stream_ parse_stream; parse_stream_ parse_stream;
void *stream; void *stream;
@ -51,9 +49,9 @@ typedef struct
//END radare2 imports //END radare2 imports
static std::unique_ptr<R_PDB> static std::unique_ptr<R_PDB>
get_r_pdb (std::string path) get_r_pdb (const std::string & path)
{ {
R_PDB pdb = { 0 }; R_PDB pdb = {nullptr};
if (std::ifstream (path).good ()) if (std::ifstream (path).good ())
{ {
if (init_pdb_parser (&pdb, path.c_str ())) if (init_pdb_parser (&pdb, path.c_str ()))
@ -71,14 +69,17 @@ get_r_pdb (std::string path)
auto fd = target->fileio_open (nullptr, auto fd = target->fileio_open (nullptr,
path.c_str () + sizeof ("target:") - 1, path.c_str () + sizeof ("target:") - 1,
FILEIO_O_RDONLY, /* mode */ 0, /* warn_if_slow */ true, &errno); FILEIO_O_RDONLY,
/* mode */ 0,
/* warn_if_slow */ true,
&errno);
if (fd == -1) if (fd == -1)
{ {
return nullptr; return nullptr;
} }
struct stat st; struct stat st{};
if (target->fileio_fstat (fd, &st, &errno) == -1) if (target->fileio_fstat (fd, &st, &errno) == -1)
{ {
return nullptr; return nullptr;
@ -136,12 +137,12 @@ get_pdb_path (struct objfile *objfile)
auto real_path = gdb_realpath (objfile->original_name); auto real_path = gdb_realpath (objfile->original_name);
auto pdb_path = std::regex_replace (std::string (real_path.get ()), auto pdb_path = std::regex_replace (std::string (real_path.get ()),
std::regex ("\\.[^.]*$"), ".pdb"); std::regex ("\\.[^.]*$"),
".pdb");
return pdb_path; return pdb_path;
} }
struct find_section_by_name_args struct find_section_by_name_args {
{
const char *name; const char *name;
asection **resultp; asection **resultp;
}; };
@ -149,7 +150,9 @@ struct find_section_by_name_args
static void static void
find_section_by_name_filter (bfd *abfd, asection *sect, void *obj) find_section_by_name_filter (bfd *abfd, asection *sect, void *obj)
{ {
struct find_section_by_name_args *args = (struct find_section_by_name_args *) obj; (void) abfd;
auto *args = (struct find_section_by_name_args *) obj;
if (strcmp (sect->name, args->name) == 0) if (strcmp (sect->name, args->name) == 0)
*args->resultp = sect; *args->resultp = sect;
@ -158,8 +161,8 @@ find_section_by_name_filter (bfd *abfd, asection *sect, void *obj)
static struct bfd_section * static struct bfd_section *
section_by_name (const char *name, struct objfile *objfile) section_by_name (const char *name, struct objfile *objfile)
{ {
asection *sect = NULL; asection *sect = nullptr;
struct find_section_by_name_args args; struct find_section_by_name_args args{};
args.name = name; args.name = name;
args.resultp = &sect; args.resultp = &sect;
bfd_map_over_sections (objfile->obfd, find_section_by_name_filter, &args); bfd_map_over_sections (objfile->obfd, find_section_by_name_filter, &args);
@ -176,13 +179,13 @@ read_pdb (struct objfile *objfile, minimal_symbol_reader &reader)
{ {
if (pdb->pdb_parse (pdb.get ())) if (pdb->pdb_parse (pdb.get ()))
{ {
SStreamParseFunc *omap = 0, *sctns = 0, *sctns_orig = 0, *gsym = 0, *tmp = 0; SStreamParseFunc *omap = nullptr, *sctns = nullptr, *sctns_orig = nullptr, *gsym = nullptr, *tmp;
SIMAGE_SECTION_HEADER *sctn_header = 0; SIMAGE_SECTION_HEADER *sctn_header;
SGDATAStream *gsym_data_stream = 0; SGDATAStream *gsym_data_stream;
SPEStream *pe_stream = 0; SPEStream *pe_stream = nullptr;
SGlobal *gdata = 0; SGlobal *gdata;
RListIter *it = 0; RListIter *it;
RList *l = 0; RList *l;
l = pdb->pdb_streams2; l = pdb->pdb_streams2;
it = r_list_iterator (l); it = r_list_iterator (l);
@ -213,7 +216,7 @@ read_pdb (struct objfile *objfile, minimal_symbol_reader &reader)
return; return;
} }
gsym_data_stream = (SGDATAStream *) gsym->stream; gsym_data_stream = (SGDATAStream *) gsym->stream;
if ((omap != 0) && (sctns_orig != 0)) if ((omap != nullptr) && (sctns_orig != nullptr))
{ {
pe_stream = (SPEStream *) sctns_orig->stream; pe_stream = (SPEStream *) sctns_orig->stream;
} }
@ -244,8 +247,9 @@ read_pdb (struct objfile *objfile, minimal_symbol_reader &reader)
auto section = sect ? sect->index : -1; auto section = sect ? sect->index : -1;
auto section_address = sect ? bfd_section_vma (sect) : 0; auto section_address = sect ? bfd_section_vma (sect) : 0;
auto address = section_address + gdata->offset; auto address = section_address + gdata->offset;
if (address == 0) continue; //we don't want to record unresolved symbols or something? if (address == 0)
auto type = mst_unknown; //FIXME continue; //we don't want to record unresolved symbols or something?
auto type = mst_text; //FIXME
reader.record_with_info (gdata->name.name, address, type, section); reader.record_with_info (gdata->name.name, address, type, section);
} }
} }