| 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 |
#include "pass1.h" |
| 32 |
|
| 33 |
#ifdef DWARF |
| 34 |
|
| 35 |
#include <sys/param.h> |
| 36 |
#include <unistd.h> |
| 37 |
|
| 38 |
#include "dwarf.h" |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#define DVERSION 3 |
| 44 |
#define DLABEL ".LD%d" |
| 45 |
|
| 46 |
#define DW64 (SZPOINT(VOID)/SZCHAR == 8) |
| 47 |
|
| 48 |
static int dwseg = -1; |
| 49 |
enum { DINFO, DABBREV, DSTR }; |
| 50 |
static char *segn[] = { ".debug_info", ".debug_abbrev", ".debug_str" }; |
| 51 |
|
| 52 |
static int debug_info_sz, debug_info_sz_lbl; |
| 53 |
static int debug_abbrev_beg_lbl; |
| 54 |
|
| 55 |
static int dwcfl, dwbtext, dwetext; |
| 56 |
|
| 57 |
static char *dwname; |
| 58 |
|
| 59 |
static int |
| 60 |
dwlab(void) |
| 61 |
{ |
| 62 |
static int dwlbl; |
| 63 |
return dwlbl++; |
| 64 |
} |
| 65 |
|
| 66 |
static void |
| 67 |
dwarfseg(int seg) |
| 68 |
{ |
| 69 |
if (seg == dwseg) |
| 70 |
return; |
| 71 |
|
| 72 |
printf("\t.section\t%s,\"\",@progbits\n", segn[seg]); |
| 73 |
lastloc = NOSEG; |
| 74 |
dwseg = seg; |
| 75 |
} |
| 76 |
|
| 77 |
static void |
| 78 |
dwslab(int seg, int lbl) |
| 79 |
{ |
| 80 |
dwarfseg(seg); |
| 81 |
printf(PRTPREF DLABEL ":\n", lbl); |
| 82 |
} |
| 83 |
|
| 84 |
static void |
| 85 |
p1b(int v) |
| 86 |
{ |
| 87 |
printf(PRTPREF "%s 0x%x\n", astypnames[CHAR], v); |
| 88 |
} |
| 89 |
|
| 90 |
static void |
| 91 |
p2w(int v) |
| 92 |
{ |
| 93 |
printf(PRTPREF "%s 0x%x\n", astypnames[SHORT], v); |
| 94 |
} |
| 95 |
|
| 96 |
static int |
| 97 |
leb128(int d) |
| 98 |
{ |
| 99 |
if (d > 127) |
| 100 |
cerror("FIXME: leb128 > 127"); |
| 101 |
p1b(d); |
| 102 |
return 1; |
| 103 |
} |
| 104 |
|
| 105 |
static void |
| 106 |
al128(int d) |
| 107 |
{ |
| 108 |
dwarfseg(DABBREV); |
| 109 |
leb128(d); |
| 110 |
} |
| 111 |
|
| 112 |
static void |
| 113 |
apair(int d, int e) |
| 114 |
{ |
| 115 |
dwarfseg(DABBREV); |
| 116 |
leb128(d); |
| 117 |
leb128(e); |
| 118 |
} |
| 119 |
|
| 120 |
static void |
| 121 |
strng(char *s) |
| 122 |
{ |
| 123 |
printf(PRTPREF "\t.ascii \"%s\\0\"\n", s); |
| 124 |
} |
| 125 |
|
| 126 |
static void |
| 127 |
istring(char *str) |
| 128 |
{ |
| 129 |
dwarfseg(DINFO); |
| 130 |
strng(str); |
| 131 |
debug_info_sz += (strlen(str) + 1); |
| 132 |
} |
| 133 |
|
| 134 |
static void |
| 135 |
dwslabstr(int lbl, char *s) |
| 136 |
{ |
| 137 |
dwslab(DSTR, lbl); |
| 138 |
strng(s); |
| 139 |
} |
| 140 |
|
| 141 |
static void |
| 142 |
ilbl(int l) |
| 143 |
{ |
| 144 |
dwarfseg(DINFO); |
| 145 |
printf(PRTPREF "%s " DLABEL "\n", astypnames[LONG], l); |
| 146 |
debug_info_sz += (DW64 * 4 + 4); |
| 147 |
} |
| 148 |
|
| 149 |
static void |
| 150 |
il128(int d) |
| 151 |
{ |
| 152 |
dwarfseg(DINFO); |
| 153 |
debug_info_sz += leb128(d); |
| 154 |
} |
| 155 |
|
| 156 |
static void |
| 157 |
p412l(int lbl) |
| 158 |
{ |
| 159 |
if (DW64) |
| 160 |
printf(PRTPREF "%s 0xffffff00\n", astypnames[INT]); |
| 161 |
printf(PRTPREF "%s " DLABEL "\n", astypnames[LONG], lbl); |
| 162 |
} |
| 163 |
|
| 164 |
static void |
| 165 |
info1b(int v) |
| 166 |
{ |
| 167 |
dwarfseg(DINFO); |
| 168 |
p1b(v); |
| 169 |
debug_info_sz++; |
| 170 |
} |
| 171 |
|
| 172 |
static void |
| 173 |
info2w(int v) |
| 174 |
{ |
| 175 |
dwarfseg(DINFO); |
| 176 |
p2w(v); |
| 177 |
debug_info_sz += 2; |
| 178 |
} |
| 179 |
|
| 180 |
static void |
| 181 |
info412l(int lbl) |
| 182 |
{ |
| 183 |
dwarfseg(DINFO); |
| 184 |
p412l(lbl); |
| 185 |
debug_info_sz += (DW64 * 8 + 4); |
| 186 |
} |
| 187 |
|
| 188 |
void |
| 189 |
dwarf_init(char *iname) |
| 190 |
{ |
| 191 |
char buf[MAXPATHLEN]; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
dwname = iname; |
| 198 |
debug_info_sz_lbl = dwlab(); |
| 199 |
debug_abbrev_beg_lbl = dwlab(); |
| 200 |
|
| 201 |
|
| 202 |
info412l(debug_info_sz_lbl); debug_info_sz = 0; |
| 203 |
info2w(DVERSION); |
| 204 |
info412l(debug_abbrev_beg_lbl); |
| 205 |
info1b(SZPOINT(VOID)/SZCHAR); |
| 206 |
|
| 207 |
|
| 208 |
dwslab(DABBREV, debug_abbrev_beg_lbl); |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
al128(1); |
| 213 |
al128(DW_TAG_compile_unit); |
| 214 |
al128(DW_CHILDREN_yes); |
| 215 |
|
| 216 |
apair(DW_AT_name, DW_FORM_strp); |
| 217 |
apair(DW_AT_producer, DW_FORM_string); |
| 218 |
apair(DW_AT_comp_dir, DW_FORM_string); |
| 219 |
apair(DW_AT_language, DW_FORM_data1); |
| 220 |
apair(DW_AT_low_pc, DW_FORM_addr); |
| 221 |
apair(DW_AT_high_pc, DW_FORM_addr); |
| 222 |
apair(0, 0); |
| 223 |
|
| 224 |
|
| 225 |
il128(1); |
| 226 |
ilbl(dwcfl = dwlab()); |
| 227 |
istring(PACKAGE_STRING); |
| 228 |
istring(getcwd(buf, MAXPATHLEN)); |
| 229 |
il128(DW_LANG_C99); |
| 230 |
ilbl(dwbtext = dwlab()); |
| 231 |
ilbl(dwetext = dwlab()); |
| 232 |
|
| 233 |
locctr(PROG, NULL); |
| 234 |
printf(PRTPREF DLABEL ":\n", dwbtext); |
| 235 |
} |
| 236 |
|
| 237 |
void |
| 238 |
dwarf_file(char *fn) |
| 239 |
{ |
| 240 |
|
| 241 |
if (dwcfl) { |
| 242 |
dwslabstr(dwcfl, fn); |
| 243 |
dwcfl = 0; |
| 244 |
} |
| 245 |
|
| 246 |
} |
| 247 |
|
| 248 |
void |
| 249 |
dwarf_end() |
| 250 |
{ |
| 251 |
locctr(PROG, NULL); |
| 252 |
printf(PRTPREF DLABEL ":\n", dwetext); |
| 253 |
if (dwcfl) |
| 254 |
dwslabstr(dwcfl, dwname ? dwname : "<unknown>"); |
| 255 |
printf(PRTPREF "\t.set " DLABEL ",%d\n", |
| 256 |
debug_info_sz_lbl, debug_info_sz); |
| 257 |
} |
| 258 |
|
| 259 |
#endif |