Fix formatting and apply clang-tidy fixes
This commit is contained in:
parent
43ba294701
commit
d82430d33c
180
gdb/pdb.c
180
gdb/pdb.c
|
@ -19,7 +19,6 @@ HACK: Honestly, this whole thing is a hack:
|
|||
#undef QUIT
|
||||
|
||||
#include <libr/r_pdb.h>
|
||||
#include <libr/r_core.h>
|
||||
|
||||
#undef QUIT
|
||||
#define QUIT maybe_quit ()
|
||||
|
@ -38,22 +37,21 @@ HACK: Honestly, this whole thing is a hack:
|
|||
//BEGIN radare2 imports
|
||||
#include "pdb_types.h"
|
||||
|
||||
typedef void (*parse_stream_)(void *stream, R_STREAM_FILE *stream_file);
|
||||
typedef void (*parse_stream_) (void *stream, R_STREAM_FILE *stream_file);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int indx;
|
||||
parse_stream_ parse_stream;
|
||||
void *stream;
|
||||
EStream type;
|
||||
free_func free;
|
||||
} SStreamParseFunc;
|
||||
typedef struct {
|
||||
int indx;
|
||||
parse_stream_ parse_stream;
|
||||
void *stream;
|
||||
EStream type;
|
||||
free_func free;
|
||||
} SStreamParseFunc;
|
||||
//END radare2 imports
|
||||
|
||||
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 (init_pdb_parser (&pdb, path.c_str ()))
|
||||
|
@ -63,58 +61,61 @@ get_r_pdb (std::string path)
|
|||
{
|
||||
auto target = find_target_at (process_stratum);
|
||||
|
||||
void* buffer;
|
||||
void *buffer;
|
||||
size_t length;
|
||||
|
||||
{ //begin read PDB into buffer
|
||||
int errno;
|
||||
{ //begin read PDB into buffer
|
||||
int errno;
|
||||
|
||||
auto fd = target->fileio_open (nullptr,
|
||||
path.c_str () + sizeof ("target:") - 1,
|
||||
FILEIO_O_RDONLY, /* mode */ 0, /* warn_if_slow */ true, &errno);
|
||||
auto fd = target->fileio_open (nullptr,
|
||||
path.c_str () + sizeof ("target:") - 1,
|
||||
FILEIO_O_RDONLY,
|
||||
/* mode */ 0,
|
||||
/* warn_if_slow */ true,
|
||||
&errno);
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
if (fd == -1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
if (target->fileio_fstat (fd, &st, &errno) == -1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
struct stat st{};
|
||||
if (target->fileio_fstat (fd, &st, &errno) == -1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
length = st.st_size;
|
||||
buffer = xmalloc (length);
|
||||
length = st.st_size;
|
||||
buffer = xmalloc (length);
|
||||
|
||||
file_ptr pos = 0, bytes;
|
||||
while (length > pos)
|
||||
{
|
||||
bytes = target->fileio_pread (fd,
|
||||
(gdb_byte *) buffer + pos,
|
||||
length - pos,
|
||||
pos,
|
||||
&errno);
|
||||
if (bytes == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (bytes == -1)
|
||||
{
|
||||
xfree (buffer);
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos += bytes;
|
||||
}
|
||||
}
|
||||
assert (pos == length);
|
||||
file_ptr pos = 0, bytes;
|
||||
while (length > pos)
|
||||
{
|
||||
bytes = target->fileio_pread (fd,
|
||||
(gdb_byte *) buffer + pos,
|
||||
length - pos,
|
||||
pos,
|
||||
&errno);
|
||||
if (bytes == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (bytes == -1)
|
||||
{
|
||||
xfree (buffer);
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos += bytes;
|
||||
}
|
||||
}
|
||||
assert (pos == length);
|
||||
|
||||
target->fileio_close (fd, &errno);
|
||||
} //end read PDB into buffer
|
||||
target->fileio_close (fd, &errno);
|
||||
} //end read PDB into buffer
|
||||
|
||||
auto r_buffer = r_buf_new_with_bytes ((const ut8*) buffer, length);
|
||||
auto r_buffer = r_buf_new_with_bytes ((const ut8 *) buffer, length);
|
||||
if (init_pdb_parser_with_buf (&pdb, r_buffer))
|
||||
{
|
||||
xfree (buffer);
|
||||
|
@ -136,12 +137,12 @@ get_pdb_path (struct objfile *objfile)
|
|||
|
||||
auto real_path = gdb_realpath (objfile->original_name);
|
||||
auto pdb_path = std::regex_replace (std::string (real_path.get ()),
|
||||
std::regex ("\\.[^.]*$"), ".pdb");
|
||||
std::regex ("\\.[^.]*$"),
|
||||
".pdb");
|
||||
return pdb_path;
|
||||
}
|
||||
|
||||
struct find_section_by_name_args
|
||||
{
|
||||
struct find_section_by_name_args {
|
||||
const char *name;
|
||||
asection **resultp;
|
||||
};
|
||||
|
@ -149,17 +150,19 @@ struct find_section_by_name_args
|
|||
static void
|
||||
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)
|
||||
*args->resultp = sect;
|
||||
}
|
||||
|
||||
static struct bfd_section*
|
||||
section_by_name (const char* name, struct objfile *objfile)
|
||||
static struct bfd_section *
|
||||
section_by_name (const char *name, struct objfile *objfile)
|
||||
{
|
||||
asection *sect = NULL;
|
||||
struct find_section_by_name_args args;
|
||||
asection *sect = nullptr;
|
||||
struct find_section_by_name_args args{};
|
||||
args.name = name;
|
||||
args.resultp = §
|
||||
bfd_map_over_sections (objfile->obfd, find_section_by_name_filter, &args);
|
||||
|
@ -167,7 +170,7 @@ section_by_name (const char* name, struct objfile *objfile)
|
|||
}
|
||||
|
||||
void
|
||||
read_pdb (struct objfile *objfile, minimal_symbol_reader &reader)
|
||||
read_pdb (struct objfile *objfile, minimal_symbol_reader & reader)
|
||||
{
|
||||
auto pdb_path = get_pdb_path (objfile);
|
||||
|
||||
|
@ -176,13 +179,13 @@ read_pdb (struct objfile *objfile, minimal_symbol_reader &reader)
|
|||
{
|
||||
if (pdb->pdb_parse (pdb.get ()))
|
||||
{
|
||||
SStreamParseFunc *omap = 0, *sctns = 0, *sctns_orig = 0, *gsym = 0, *tmp = 0;
|
||||
SIMAGE_SECTION_HEADER *sctn_header = 0;
|
||||
SGDATAStream *gsym_data_stream = 0;
|
||||
SPEStream *pe_stream = 0;
|
||||
SGlobal *gdata = 0;
|
||||
RListIter *it = 0;
|
||||
RList *l = 0;
|
||||
SStreamParseFunc *omap = nullptr, *sctns = nullptr, *sctns_orig = nullptr, *gsym = nullptr, *tmp;
|
||||
SIMAGE_SECTION_HEADER *sctn_header;
|
||||
SGDATAStream *gsym_data_stream;
|
||||
SPEStream *pe_stream = nullptr;
|
||||
SGlobal *gdata;
|
||||
RListIter *it;
|
||||
RList *l;
|
||||
|
||||
l = pdb->pdb_streams2;
|
||||
it = r_list_iterator (l);
|
||||
|
@ -191,20 +194,20 @@ read_pdb (struct objfile *objfile, minimal_symbol_reader &reader)
|
|||
tmp = (SStreamParseFunc *) r_list_iter_get (it);
|
||||
switch (tmp->type)
|
||||
{
|
||||
case ePDB_STREAM_SECT__HDR_ORIG:
|
||||
sctns_orig = tmp;
|
||||
case ePDB_STREAM_SECT__HDR_ORIG:
|
||||
sctns_orig = tmp;
|
||||
break;
|
||||
case ePDB_STREAM_SECT_HDR:
|
||||
sctns = tmp;
|
||||
case ePDB_STREAM_SECT_HDR:
|
||||
sctns = tmp;
|
||||
break;
|
||||
case ePDB_STREAM_OMAP_FROM_SRC:
|
||||
omap = tmp;
|
||||
case ePDB_STREAM_OMAP_FROM_SRC:
|
||||
omap = tmp;
|
||||
break;
|
||||
case ePDB_STREAM_GSYM:
|
||||
gsym = tmp;
|
||||
break;
|
||||
default:
|
||||
case ePDB_STREAM_GSYM:
|
||||
gsym = tmp;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!gsym)
|
||||
|
@ -213,7 +216,7 @@ read_pdb (struct objfile *objfile, minimal_symbol_reader &reader)
|
|||
return;
|
||||
}
|
||||
gsym_data_stream = (SGDATAStream *) gsym->stream;
|
||||
if ((omap != 0) && (sctns_orig != 0))
|
||||
if ((omap != nullptr) && (sctns_orig != nullptr))
|
||||
{
|
||||
pe_stream = (SPEStream *) sctns_orig->stream;
|
||||
}
|
||||
|
@ -226,7 +229,7 @@ read_pdb (struct objfile *objfile, minimal_symbol_reader &reader)
|
|||
return;
|
||||
}
|
||||
|
||||
printf_filtered (_("Reading symbols from %s...\n"), pdb_path.c_str());
|
||||
printf_filtered (_("Reading symbols from %s...\n"), pdb_path.c_str ());
|
||||
|
||||
//TODO: Use this. For now, we allocate the symtab so we don't print we found no symbols.
|
||||
auto psymtab = allocate_psymtab (objfile->original_name, objfile);
|
||||
|
@ -239,14 +242,15 @@ read_pdb (struct objfile *objfile, minimal_symbol_reader &reader)
|
|||
sctn_header = (SIMAGE_SECTION_HEADER*) r_list_get_n (pe_stream->sections_hdrs, (gdata->segment - 1));
|
||||
if (sctn_header)
|
||||
{
|
||||
asection *sect = section_by_name(sctn_header->name, objfile);
|
||||
asection *sect = section_by_name (sctn_header->name, objfile);
|
||||
|
||||
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;
|
||||
if (address == 0) continue; //we don't want to record unresolved symbols or something?
|
||||
auto type = mst_unknown; //FIXME
|
||||
reader.record_with_info(gdata->name.name, address, type, section);
|
||||
if (address == 0)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue