Fix more trailing spaces in dwarf and comments

This commit is contained in:
pancake 2016-05-31 23:37:17 +02:00
parent ae52bb5ded
commit 88b71663c0
3 changed files with 25 additions and 20 deletions

View file

@ -1,10 +1,9 @@
/* radare - LGPL - Copyright 2009-2015 - nibble, pancake */
/* radare - LGPL - Copyright 2009-2016 - nibble, pancake */
#include <r_types.h>
#include <r_bin.h>
R_API int r_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line) {
#define GETLINE() cp->dbginfo->get_line (bin->cur, addr, file, len, line)
RBinFile *binfile = r_bin_cur (bin);
RBinObject *o = r_bin_cur_object (bin);
RBinPlugin *cp = r_bin_file_cur_plugin (binfile);
@ -12,19 +11,21 @@ R_API int r_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line)
if (cp && cp->dbginfo) {
if (o && addr >= baddr && addr < baddr + bin->cur->o->size) {
if (cp->dbginfo->get_line) {
return GETLINE ();
return cp->dbginfo->get_line (
bin->cur, addr, file, len, line);
}
}
}
return false;
}
R_API char *r_bin_addr2text(RBin *bin, ut64 addr) {
R_API char *r_bin_addr2text(RBin *bin, ut64 addr, bool origin) {
char file[4096];
int line;
char *out = NULL, *out2;
char *out = NULL, *out2 = NULL;
char *file_nopath;
file[0] = 0;
if (r_bin_addr2line (bin, addr, file, sizeof (file), &line)) {
if (bin->srcdir && *bin->srcdir) {
char *nf = r_str_newf ("%s/%s", bin->srcdir, file);
@ -32,16 +33,18 @@ R_API char *r_bin_addr2text(RBin *bin, ut64 addr) {
free (nf);
}
out = r_file_slurp_line (file, line, 0);
if (!out)
return 0;
if (!out) return 0;
out2 = malloc ((strlen (file) + 64 + strlen (out)) * sizeof (char));
file_nopath = strrchr (file, '/');
snprintf (out2, strlen (file) + 63 + strlen (out), "%s:%d %s",
file_nopath? file_nopath + 1: file, line, out);
if (origin) {
snprintf (out2, strlen (file) + 63 + strlen (out), "%s:%d%s%s",
file_nopath? file_nopath + 1: file, line, *out? " ": "", out);
} else {
snprintf (out2, 64, "%s", out);
}
free (out);
return out2;
}
return 0;
return out2;
}
R_API char *r_bin_addr2fileline(RBin *bin, ut64 addr) {

View file

@ -67,7 +67,7 @@ typedef struct r_disam_options_t {
int cyclespace;
int cmtfold;
int show_indent;
int show_dwarf;
bool show_dwarf;
int show_size;
int show_trace;
int show_family;
@ -2124,7 +2124,7 @@ static void ds_print_dwarf(RDisasmState *ds) {
if (len < 30) {
len = 30 - len;
}
ds->sl = r_bin_addr2text (ds->core->bin, ds->at);
ds->sl = r_bin_addr2text (ds->core->bin, ds->at, true);
if (ds->sl) {
if ((!ds->osl || (ds->osl && strcmp (ds->sl, ds->osl)))) {
char *chopstr, *line = strdup (ds->sl);
@ -2623,7 +2623,7 @@ static void ds_print_comments_right(RDisasmState *ds) {
free (locase);
}
if (ds->show_comments) {
if (desc) {
if (desc && *desc) {
ds_align_comment (ds);
if (ds->show_color) {
r_cons_strcat (ds->color_comment);
@ -2632,15 +2632,17 @@ static void ds_print_comments_right(RDisasmState *ds) {
r_cons_strcat (desc);
}
if (ds->show_comment_right && ds->comment) {
if (!desc) {
ds_align_comment (ds);
char *comment = r_str_chop (ds->comment);
if (*comment) {
if (!desc) {
ds_align_comment (ds);
}
if (ds->show_color) {
r_cons_strcat (ds->color_comment);
}
r_cons_strcat (" ; ");
r_cons_printf (" ; %s", comment);
}
//r_cons_strcat_justify (comment, strlen (ds->refline) + 5, ';');
r_cons_strcat (ds->comment);
// r_cons_strcat_justify (comment, strlen (ds->refline) + 5, ';');
if (ds->show_color) {
ds_print_color_reset (ds);
}

View file

@ -555,7 +555,7 @@ R_API void r_bin_force_plugin (RBin *bin, const char *pname);
/* dbginfo.c */
R_API int r_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line);
R_API char *r_bin_addr2text(RBin *bin, ut64 addr);
R_API char *r_bin_addr2text(RBin *bin, ut64 addr, bool origin);
R_API char *r_bin_addr2fileline(RBin *bin, ut64 addr);
/* bin_write.c */
R_API bool r_bin_wr_addlib(RBin *bin, const char *lib);