plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

stabs.c (982B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <mach.h>
      4 #include "stabs.h"
      5 
      6 /*
      7 http://sources.redhat.com/gdb/onlinedocs/stabs.html
      8 */
      9 
     10 int
     11 stabsym(Stab *stabs, int i, StabSym *sym)
     12 {
     13 	uchar *p;
     14 	ulong x;
     15 
     16 	if(stabs == nil){
     17 		werrstr("no stabs");
     18 		return -1;
     19 	}
     20 	if(stabs->e2==0 || stabs->e4==0){
     21 		werrstr("no data extractors");
     22 		return -1;
     23 	}
     24 
     25 	if(i >= stabs->stabsize/12){
     26 		werrstr("stabs index out of range");
     27 		return -1;
     28 	}
     29 
     30 	p = stabs->stabbase+i*12;
     31 	x = stabs->e4(p);
     32 	if(x == 0)
     33 		sym->name = nil;
     34 	else if(x < stabs->strsize)
     35 		sym->name = stabs->strbase+x;
     36 	else{
     37 		werrstr("bad stabs string index");
     38 		return -1;
     39 	}
     40 
     41 	/*
     42 	 * In theory, if name ends with a backslash,
     43 	 * it continues into the next entry.  We could
     44 	 * rewrite these in place and then zero the next
     45 	 * few entries, but let's wait until we run across
     46 	 * some system that generates these.
     47 	 */
     48 	sym->type = p[4];
     49 	sym->other = p[5];
     50 	sym->desc = stabs->e2(p+6);
     51 	sym->value = stabs->e4(p+8);
     52 	return 0;
     53 }