aboutsummaryrefslogtreecommitdiff
path: root/src/libmach/stabs.c
blob: d34bb864362fd93f2d20bc5eaeec2c843fa438c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <u.h>
#include <libc.h>
#include <mach.h>
#include "stabs.h"

/*
http://sources.redhat.com/gdb/onlinedocs/stabs.html
*/

int
stabsym(Stab *stabs, int i, StabSym *sym)
{
	uchar *p;
	ulong x;

	if(stabs == nil){
		werrstr("no stabs");
		return -1;
	}
	if(stabs->e2==nil || stabs->e4==nil){
		werrstr("no data extractors");
		return -1;
	}

	if(i >= stabs->stabsize/12){
		werrstr("stabs index out of range");
		return -1;
	}

	p = stabs->stabbase+i*12;
	x = stabs->e4(p);
	if(x == 0)
		sym->name = nil;
	else if(x < stabs->strsize)
		sym->name = stabs->strbase+x;
	else{
		werrstr("bad stabs string index");
		return -1;
	}

	/*
	 * In theory, if name ends with a backslash,
	 * it continues into the next entry.  We could
	 * rewrite these in place and then zero the next
	 * few entries, but let's wait until we run across
	 * some system that generates these.
	 */
	sym->type = p[4];
	sym->other = p[5];
	sym->desc = stabs->e2(p+6);
	sym->value = stabs->e4(p+8);
	return 0;
}