ldmisc.h (einfo, minfo, info): Don't bother with PARAMS macro when no

prototype is being supplied.
(ldmalloc, ldrealloc): Size argument is now size_t.

ldmisc.c (finfo): New function, accepts FILE* argument.
(vfinfo, case 'v'): New format character; displays bfd_vma in hex without
leading zeros.
(vfinfo, cases 'R' and 'C'): Use finfo(%v) when displaying a bfd_vma value,
instead of fprintf(%x) which won't hold a long long value.
(concat, buystring): String lengths are size_t.
(ldmalloc, ldrealloc, xrealloc): Size argument is now size_t.
This commit is contained in:
Ken Raeburn 1993-07-08 20:27:13 +00:00
parent 5af8e9d6a1
commit 9b0da7f468

View file

@ -41,6 +41,9 @@ extern int errno;
extern int sys_nerr; extern int sys_nerr;
extern char *sys_errlist[]; extern char *sys_errlist[];
/* VARARGS*/
static void finfo ();
/* /*
%F error is fatal %F error is fatal
%P print progam name %P print progam name
@ -51,10 +54,32 @@ extern char *sys_errlist[];
%T symbol table entry %T symbol table entry
%X no object output, fail return %X no object output, fail return
%V hex bfd_vma %V hex bfd_vma
%v hex bfd_vma, no leading zeros
%C Clever filename:linenumber %C Clever filename:linenumber
%R info about a relent %R info about a relent
% %
*/ */
extern bfd *output_bfd;
static char *
demangle(string, remove_underscore)
char *string;
int remove_underscore;
{
char *res;
if (remove_underscore && output_bfd)
{
if (bfd_get_symbol_leading_char(output_bfd) == string[0])
string++;
}
/* Note that there's a memory leak here, we keep buying memory
for demangled names, and never free. But if you have so many
errors that you run out of VM with the error messages, then
there's something up */
res = cplus_demangle(string, DMGL_ANSI|DMGL_PARAMS);
return res ? res : string;
}
static void static void
vfinfo(fp, fmt, arg) vfinfo(fp, fmt, arg)
FILE *fp; FILE *fp;
@ -83,6 +108,19 @@ vfinfo(fp, fmt, arg)
fprintf_vma(fp, value); fprintf_vma(fp, value);
} }
break; break;
case 'v':
{
char buf[100];
char *p = buf;
bfd_vma value = va_arg (arg, bfd_vma);
sprintf_vma (p, value);
while (*p == '0')
p++;
if (!*p)
p--;
fputs (p, fp);
}
break;
case 'T': case 'T':
{ {
asymbol *symbol = va_arg(arg, asymbol *); asymbol *symbol = va_arg(arg, asymbol *);
@ -91,24 +129,16 @@ vfinfo(fp, fmt, arg)
asection *section = symbol->section; asection *section = symbol->section;
char *cplusname = char *cplusname = demangle(symbol->name, 1);
cplus_demangle(symbol->name, DMGL_ANSI|DMGL_PARAMS);
CONST char *section_name = section->name; CONST char *section_name = section->name;
if (section != &bfd_und_section) if (section != &bfd_und_section)
{ {
fprintf(fp,"%s (%s)", cplusname ? cplusname : fprintf(fp,"%s (%s)", cplusname, section_name);
symbol->name, section_name);
} }
else else
{ {
fprintf(fp,"%s", cplusname ? cplusname : symbol->name); fprintf(fp,"%s", cplusname);
} }
if (cplusname)
{
free(cplusname);
}
} }
else else
{ {
@ -173,12 +203,10 @@ vfinfo(fp, fmt, arg)
{ {
arelent *relent = va_arg(arg, arelent *); arelent *relent = va_arg(arg, arelent *);
fprintf(fp,"%s+0x%x (type %s)", finfo (fp, "%s+0x%v (type %s)",
(*(relent->sym_ptr_ptr))->name, (*(relent->sym_ptr_ptr))->name,
relent->addend, relent->addend,
relent->howto->name); relent->howto->name);
} }
break; break;
@ -209,28 +237,19 @@ vfinfo(fp, fmt, arg)
filename = abfd->filename; filename = abfd->filename;
if (functionname != (char *)NULL) if (functionname != (char *)NULL)
{ {
cplus_name = cplus_demangle(functionname, DMGL_ANSI|DMGL_PARAMS); /* There is no initial '_' to remove here. */
fprintf(fp,"%s:%u: (%s)", filename, linenumber, cplus_name = demangle(functionname, 0);
cplus_name? cplus_name: functionname); fprintf(fp,"%s:%u: (%s)", filename, linenumber, cplus_name);
if (cplus_name)
free(cplus_name);
} }
else if (linenumber != 0) else if (linenumber != 0)
fprintf(fp,"%s:%u", filename, linenumber); fprintf(fp,"%s:%u", filename, linenumber);
else else
fprintf(fp,"%s(%s+%0x)", filename, finfo (fp, "%s(%s+0x%v)", filename, section->name, offset);
section->name,
offset);
} }
else { else
fprintf(fp,"%s(%s+%0x)", abfd->filename, finfo (fp, "%s(%s+0x%v)", abfd->filename, section->name, offset);
section->name,
offset);
}
} }
break; break;
@ -301,14 +320,14 @@ unsigned int line;
whose contents concatenate those of S1, S2, S3. */ whose contents concatenate those of S1, S2, S3. */
char * char *
DEFUN(concat, (s1, s2, s3), concat (s1, s2, s3)
CONST char *s1 AND CONST char *s1;
CONST char *s2 AND CONST char *s2;
CONST char *s3) CONST char *s3;
{ {
bfd_size_type len1 = strlen (s1); size_t len1 = strlen (s1);
bfd_size_type len2 = strlen (s2); size_t len2 = strlen (s2);
bfd_size_type len3 = strlen (s3); size_t len3 = strlen (s3);
char *result = ldmalloc (len1 + len2 + len3 + 1); char *result = ldmalloc (len1 + len2 + len3 + 1);
if (len1 != 0) if (len1 != 0)
@ -324,8 +343,8 @@ DEFUN(concat, (s1, s2, s3),
PTR PTR
DEFUN(ldmalloc, (size), ldmalloc (size)
bfd_size_type size) size_t size;
{ {
PTR result = malloc ((int)size); PTR result = malloc ((int)size);
@ -336,17 +355,17 @@ bfd_size_type size)
} }
PTR PTR
DEFUN(xmalloc,(size), xmalloc (size)
int size) int size;
{ {
return ldmalloc(size); return ldmalloc(size);
} }
PTR PTR
DEFUN(ldrealloc, (ptr, size), ldrealloc (ptr, size)
PTR ptr AND PTR ptr;
bfd_size_type size) size_t size;
{ {
PTR result = realloc (ptr, (int)size); PTR result = realloc (ptr, (int)size);
@ -356,12 +375,20 @@ bfd_size_type size)
return result; return result;
} }
PTR
xrealloc (ptr, size)
char *DEFUN(buystring,(x), PTR ptr;
CONST char *CONST x) size_t size;
{ {
bfd_size_type l = strlen(x)+1; return ldrealloc(ptr, size);
}
char *
buystring (x)
CONST char *CONST x;
{
size_t l = strlen(x)+1;
char *r = ldmalloc(l); char *r = ldmalloc(l);
memcpy(r, x,l); memcpy(r, x,l);
return r; return r;
@ -382,7 +409,19 @@ va_dcl
} }
static void
finfo (va_alist)
va_dcl
{
char *fmt;
FILE *file;
va_list arg;
va_start (arg);
file = va_arg (arg, FILE *);
fmt = va_arg (arg, char *);
vfinfo (file, fmt, arg);
va_end (arg);
}
@ -391,18 +430,18 @@ va_dcl
*/ */
void void
DEFUN_VOID(print_space) print_space ()
{ {
fprintf(config.map_file, " "); fprintf(config.map_file, " ");
} }
void void
DEFUN_VOID(print_nl) print_nl ()
{ {
fprintf(config.map_file, "\n"); fprintf(config.map_file, "\n");
} }
void void
DEFUN(print_address,(value), print_address (value)
bfd_vma value) bfd_vma value;
{ {
fprintf_vma(config.map_file, value); fprintf_vma(config.map_file, value);
} }