summaryrefslogtreecommitdiffstats
path: root/main/common/symtbl.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/common/symtbl.c')
-rw-r--r--main/common/symtbl.c251
1 files changed, 132 insertions, 119 deletions
diff --git a/main/common/symtbl.c b/main/common/symtbl.c
index efc08c4..8fef69d 100644
--- a/main/common/symtbl.c
+++ b/main/common/symtbl.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
* Copyright (c) 2013 Alcatel-Lucent
- *
+ *
* Alcatel Lucent licenses this file to You under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. A copy of the License is contained the
@@ -46,101 +46,111 @@
int
SymFileFd(int verbose)
{
- TFILE *tfp;
- int tfd;
- char *symfile;
-
- /* Load symbol table file name. If SYMFILE is not a variable, default
- * to the string defined by SYMFILE.
- */
- symfile = getenv("SYMFILE");
- if (!symfile)
- symfile = SYMFILE;
-
- tfp = tfsstat(symfile);
- if (!tfp)
- return(TFSERR_NOFILE);
-
- tfd = tfsopen(symfile,TFS_RDONLY,0);
- if (tfd < 0) {
- if (verbose)
- printf("%s: %s\n",symfile,(char *)tfsctrl(TFS_ERRMSG,tfd,0));
- return(TFSERR_NOFILE);
- }
- return(tfd);
+ TFILE *tfp;
+ int tfd;
+ char *symfile;
+
+ /* Load symbol table file name. If SYMFILE is not a variable, default
+ * to the string defined by SYMFILE.
+ */
+ symfile = getenv("SYMFILE");
+ if(!symfile) {
+ symfile = SYMFILE;
+ }
+
+ tfp = tfsstat(symfile);
+ if(!tfp) {
+ return(TFSERR_NOFILE);
+ }
+
+ tfd = tfsopen(symfile,TFS_RDONLY,0);
+ if(tfd < 0) {
+ if(verbose) {
+ printf("%s: %s\n",symfile,(char *)tfsctrl(TFS_ERRMSG,tfd,0));
+ }
+ return(TFSERR_NOFILE);
+ }
+ return(tfd);
}
/* AddrToSym():
- * Assumes each line of symfile is formatted as...
- * synmame SP hex_address
- * and that the symbols are sorted from lowest to highest address.
- * Using the file specified by the incoming TFS file descriptor,
- * determine what symbol's address range covers the incoming address.
- * If found, store the name of the symbol as well as the offset between
- * the address of the symbol and the incoming address.
- * Note, if the incoming file descriptor is -1, then we open (and later
- * close) the file here.
+ * Assumes each line of symfile is formatted as...
+ * synmame SP hex_address
+ * and that the symbols are sorted from lowest to highest address.
+ * Using the file specified by the incoming TFS file descriptor,
+ * determine what symbol's address range covers the incoming address.
+ * If found, store the name of the symbol as well as the offset between
+ * the address of the symbol and the incoming address.
+ * Note, if the incoming file descriptor is -1, then we open (and later
+ * close) the file here.
*
- * Return 1 if a match is found, else 0.
+ * Return 1 if a match is found, else 0.
*/
int
AddrToSym(int tfdin,ulong addr,char *name,ulong *offset)
{
- int lno, tfd;
- char *space;
- ulong thisaddr, lastaddr;
- char thisline[84];
- char lastline[sizeof(thisline)];
-
- lno = 1;
- if (offset)
- *offset = 0;
- lastaddr = 0;
- if (tfdin == -1) {
- tfd = SymFileFd(0);
- if (tfd == TFSERR_NOFILE)
- return(0);
- }
- else
- tfd = tfdin;
- tfsseek(tfd,0,TFS_BEGIN);
- while(tfsgetline(tfd,thisline,sizeof(thisline)-1)) {
- space = strpbrk(thisline,"\t ");
- if (!space)
- continue;
- *space++ = 0;
- while(isspace(*space))
- space++;
-
- thisaddr = strtoul(space,0,0); /* Compute address from entry in */
- /* symfile. */
-
- if (thisaddr == addr) { /* Exact match, use this entry */
- strcpy(name,thisline); /* in symfile. */
- if (tfdin == -1)
- tfsclose(tfd,0);
- return(1);
- }
- else if (thisaddr > addr) { /* Address in symfile is greater */
- if (lno == 1) /* than incoming address... */
- break; /* If this is first line of symfile */
- strcpy(name,lastline); /* then return error. */
- if (offset)
- *offset = addr-lastaddr;/* Otherwise return the symfile */
- if (tfdin == -1)
- tfsclose(tfd,0);
- return(1); /* entry previous to this one. */
- }
- else { /* Address in symfile is less than */
- lastaddr = thisaddr; /* incoming address, so just keep */
- strcpy(lastline,thisline); /* a copy of this line and go to */
- lno++; /* the next. */
- }
- }
- if (tfdin == -1)
- tfsclose(tfd,0);
- sprintf(name,"0x%lx",addr);
- return(0);
+ int lno, tfd;
+ char *space;
+ ulong thisaddr, lastaddr;
+ char thisline[84];
+ char lastline[sizeof(thisline)];
+
+ lno = 1;
+ if(offset) {
+ *offset = 0;
+ }
+ lastaddr = 0;
+ if(tfdin == -1) {
+ tfd = SymFileFd(0);
+ if(tfd == TFSERR_NOFILE) {
+ return(0);
+ }
+ } else {
+ tfd = tfdin;
+ }
+ tfsseek(tfd,0,TFS_BEGIN);
+ while(tfsgetline(tfd,thisline,sizeof(thisline)-1)) {
+ space = strpbrk(thisline,"\t ");
+ if(!space) {
+ continue;
+ }
+ *space++ = 0;
+ while(isspace(*space)) {
+ space++;
+ }
+
+ thisaddr = strtoul(space,0,0); /* Compute address from entry in */
+ /* symfile. */
+
+ if(thisaddr == addr) { /* Exact match, use this entry */
+ strcpy(name,thisline); /* in symfile. */
+ if(tfdin == -1) {
+ tfsclose(tfd,0);
+ }
+ return(1);
+ } else if(thisaddr > addr) { /* Address in symfile is greater */
+ if(lno == 1) { /* than incoming address... */
+ break; /* If this is first line of symfile */
+ }
+ strcpy(name,lastline); /* then return error. */
+ if(offset) {
+ *offset = addr-lastaddr; /* Otherwise return the symfile */
+ }
+ if(tfdin == -1) {
+ tfsclose(tfd,0);
+ }
+ return(1); /* entry previous to this one. */
+ } else { /* Address in symfile is less than */
+ lastaddr = thisaddr; /* incoming address, so just keep */
+ strcpy(lastline,thisline); /* a copy of this line and go to */
+ lno++; /* the next. */
+ }
+ }
+ if(tfdin == -1) {
+ tfsclose(tfd,0);
+ }
+ sprintf(name,"0x%lx",addr);
+ return(0);
}
/* getsym():
@@ -160,8 +170,8 @@ AddrToSym(int tfdin,ulong addr,char *name,ulong *offset)
* spaces and/or tabs.
* For example, here are a few lines:
*
- * main 0x10400
- * func 0x10440
+ * main 0x10400
+ * func 0x10440
*
* With the above lines in SYMFILE, if %main were on the command line, it
* would be replaced with 0x10400.
@@ -169,32 +179,35 @@ AddrToSym(int tfdin,ulong addr,char *name,ulong *offset)
char *
getsym(char *symname,char *line,int sizeofline)
{
- int tfd;
- char *space;
-
- if ((tfd = SymFileFd(1)) < 0) {
- return((char *)0);
- }
-
- while(tfsgetline(tfd,line,sizeofline)) {
- char *eol;
- eol = strpbrk(line,"\r\n");
- if (eol)
- *eol = 0;
- space = strpbrk(line,"\t ");
- if (!space)
- continue;
- *space = 0;
- if (!strcmp(line,symname)) {
- tfsclose(tfd,0);
- space++;
- while((*space == ' ') || (*space == '\t'))
- space++;
- return(space);
- }
- }
- tfsclose(tfd,0);
- return((char *)0);
+ int tfd;
+ char *space;
+
+ if((tfd = SymFileFd(1)) < 0) {
+ return((char *)0);
+ }
+
+ while(tfsgetline(tfd,line,sizeofline)) {
+ char *eol;
+ eol = strpbrk(line,"\r\n");
+ if(eol) {
+ *eol = 0;
+ }
+ space = strpbrk(line,"\t ");
+ if(!space) {
+ continue;
+ }
+ *space = 0;
+ if(!strcmp(line,symname)) {
+ tfsclose(tfd,0);
+ space++;
+ while((*space == ' ') || (*space == '\t')) {
+ space++;
+ }
+ return(space);
+ }
+ }
+ tfsclose(tfd,0);
+ return((char *)0);
}
#else
@@ -202,14 +215,14 @@ getsym(char *symname,char *line,int sizeofline)
char *
getsym(char *symname,char *line,int sizeofline)
{
- return((char *)0);
+ return((char *)0);
}
int
AddrToSym(int tfd,ulong addr,char *name,ulong *offset)
{
- sprintf(name,"0x%lx",addr);
- return(0);
+ sprintf(name,"0x%lx",addr);
+ return(0);
}
#endif