| 9120e874 Andy McCall |
1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include "dbg_info.h" |
| 10 |
|
| 11 |
#include <stdio.h> |
| 12 |
#include <stdlib.h> |
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
|
| 16 |
static int g_fails = 0; |
| 17 |
|
| 18 |
static void |
| 19 |
check(int cond, const char *msg) |
| 20 |
{ |
| 21 |
printf("%s: %s\n", cond ? "ok " : "FAIL", msg); |
| 22 |
if (!cond) { |
| 23 |
g_fails++; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
static const char *k_dbg = |
| 31 |
"version\tmajor=2,minor=0\n" |
| 32 |
"info\tcsym=0,file=2,lib=0,line=3,mod=1,scope=1,seg=1,span=2,sym=2,type=0\n" |
| 33 |
"file\tid=0,name=\"main.s\",size=200,mtime=0x00000000,mod=0\n" |
| 34 |
"file\tid=1,name=\"util.s\",size=100,mtime=0x00000000,mod=0\n" |
| 35 |
"seg\tid=0,name=\"CODE\",start=0x000801,size=0x0040,addrsize=absolute,type=ro\n" |
| 36 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 37 |
"span\tid=1,seg=0,start=16,size=16,type=0\n" |
| 38 |
"line\tid=0,file=0,line=10,span=0\n" |
| 39 |
"line\tid=1,file=0,line=11,span=1\n" |
| 40 |
"line\tid=2,file=1,line=42,span=1\n" |
| 41 |
"sym\tid=0,name=\"_main\",addrsize=absolute,size=3,scope=0,def=0,val=0x000801,type=lab\n" |
| 42 |
"sym\tid=1,name=\"_helper\",addrsize=absolute,size=3,scope=0,def=0,val=0x000811,type=lab\n" |
| 43 |
"mod\tid=0,name=\"main.o\",file=0\n"; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
static const char *k_dbg_equ_v1 = |
| 49 |
"version\tmajor=2,minor=0\n" |
| 50 |
"file\tid=0,name=\"equ.s\",size=10,mtime=0x00000000,mod=0\n" |
| 51 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro,oname=\"e.prg\"\n" |
| 52 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 53 |
"line\tid=0,file=0,line=1,span=0\n" |
| 54 |
"sym\tid=0,name=\"SCORE\",addrsize=absolute,size=2,scope=0,def=0,val=0x001234,type=equ\n" |
| 55 |
"sym\tid=1,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 56 |
"mod\tid=0,name=\"equ.o\",file=0\n"; |
| 57 |
|
| 58 |
static const char *k_dbg_equ_v2 = |
| 59 |
"version\tmajor=2,minor=0\n" |
| 60 |
"file\tid=0,name=\"equ.s\",size=10,mtime=0x00000000,mod=0\n" |
| 61 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro,oname=\"e.prg\"\n" |
| 62 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 63 |
"line\tid=0,file=0,line=1,span=0\n" |
| 64 |
"sym\tid=0,name=\"SCORE\",addrsize=absolute,size=2,scope=0,def=0,val=0x00BEEF,type=equ\n" |
| 65 |
"sym\tid=1,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000007,type=equ\n" |
| 66 |
"mod\tid=0,name=\"equ.o\",file=0\n"; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
#define WRITE_TEMP_SLOTS 8 |
| 74 |
static char * |
| 75 |
write_temp(const char *contents, const char *leaf) |
| 76 |
{ |
| 77 |
static char slots[WRITE_TEMP_SLOTS][512]; |
| 78 |
static int next_slot = 0; |
| 79 |
char *path = slots[next_slot]; |
| 80 |
next_slot = (next_slot + 1) % WRITE_TEMP_SLOTS; |
| 81 |
const char *dir = getenv("TMPDIR"); |
| 82 |
if (!dir || !*dir) { |
| 83 |
dir = getenv("TEMP"); |
| 84 |
} |
| 85 |
if (!dir || !*dir) { |
| 86 |
dir = "."; |
| 87 |
} |
| 88 |
snprintf(path, 512, "%s/%s", dir, leaf); |
| 89 |
|
| 90 |
FILE *f = fopen(path, "wb"); |
| 91 |
if (!f) { |
| 92 |
printf("FAIL: cannot write %s\n", path); |
| 93 |
g_fails++; |
| 94 |
return NULL; |
| 95 |
} |
| 96 |
fwrite(contents, 1, strlen(contents), f); |
| 97 |
fclose(f); |
| 98 |
return path; |
| 99 |
} |
| 100 |
|
| 101 |
static char * |
| 102 |
write_temp_dbg(void) |
| 103 |
{ |
| 104 |
return write_temp(k_dbg, "x16_dbg_info_test.dbg"); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
static const char *k_dbg_banked = |
| 111 |
"version\tmajor=2,minor=0\n" |
| 112 |
"file\tid=0,name=\"a_bank5.s\",size=100,mtime=0x00000000,mod=0\n" |
| 113 |
"file\tid=1,name=\"b_bank6.s\",size=100,mtime=0x00000000,mod=0\n" |
| 114 |
"seg\tid=0,name=\"BANKA\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 115 |
"seg\tid=1,name=\"BANKB\",start=0x00a000,size=0x0020,addrsize=absolute,type=ro\n" |
| 116 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 117 |
"span\tid=1,seg=1,start=0,size=32,type=0\n" |
| 118 |
"line\tid=0,file=0,line=7,span=0\n" |
| 119 |
"line\tid=1,file=1,line=99,span=1\n" |
| 120 |
"mod\tid=0,name=\"banked.o\",file=0\n"; |
| 121 |
|
| 122 |
static char * |
| 123 |
write_temp_banked_dbg(void) |
| 124 |
{ |
| 125 |
return write_temp(k_dbg_banked, "x16_dbg_info_banked.dbg"); |
| 126 |
} |
| 127 |
|
| 128 |
int |
| 129 |
main(void) |
| 130 |
{ |
| 131 |
|
| 132 |
|
| 133 |
check(!dbg_info_is_loaded(), "reports not loaded before any load"); |
| 134 |
{ |
| 135 |
const char *file = NULL; |
| 136 |
int line = 0; |
| 137 |
check(!dbg_info_addr_to_source(0x0801, &file, &line), |
| 138 |
"address lookup declines when nothing is loaded"); |
| 139 |
dbg_addr_t addr = 0; |
| 140 |
check(!dbg_info_label_to_addr("_main", &addr), |
| 141 |
"label lookup declines when nothing is loaded"); |
| 142 |
} |
| 143 |
|
| 144 |
check(dbg_info_load("this/does/not/exist.dbg") != 0, |
| 145 |
"load of a missing file reports failure"); |
| 146 |
|
| 147 |
char *path = write_temp_dbg(); |
| 148 |
if (!path) { |
| 149 |
return 1; |
| 150 |
} |
| 151 |
check(dbg_info_load(path) == 0, "loads a well-formed .dbg"); |
| 152 |
check(dbg_info_is_loaded(), "reports loaded afterwards"); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
{ |
| 157 |
const char *file = NULL; |
| 158 |
int line = 0; |
| 159 |
check(dbg_info_addr_to_source(0x0801, &file, &line), "maps a span-start address"); |
| 160 |
check(file && strstr(file, "main.s") != NULL, " ...to the right file"); |
| 161 |
check(line == 10, " ...to the right line"); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
{ |
| 167 |
const char *file = NULL; |
| 168 |
int line = 0; |
| 169 |
check(dbg_info_addr_to_source_nearest(0x0805, &file, &line), |
| 170 |
"maps an address inside a span to the enclosing line"); |
| 171 |
check(line == 10, " ...to the line that opened the span"); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
{ |
| 176 |
const char *file = NULL; |
| 177 |
int line = 0; |
| 178 |
check(!dbg_info_addr_to_source(0xC000, &file, &line), |
| 179 |
"declines an address outside every segment"); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
{ |
| 184 |
dbg_addr_t addr = 0; |
| 185 |
check(dbg_info_source_to_addr("main.s", 10, &addr), "maps file/line back to an address"); |
| 186 |
check(addr == 0x0801, " ...to the span start"); |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
{ |
| 191 |
dbg_addr_t addr = 0; |
| 192 |
check(dbg_info_label_to_addr("_main", &addr) && addr == 0x0801, "finds a label by name"); |
| 193 |
check(dbg_info_label_to_addr("_MAIN", &addr) && addr == 0x0801, |
| 194 |
"label lookup is case-insensitive"); |
| 195 |
check(!dbg_info_label_to_addr("_nosuch", &addr), "declines an unknown label"); |
| 196 |
|
| 197 |
const char *name = NULL; |
| 198 |
check(dbg_info_addr_to_label(0x0811, &name) && name && strcmp(name, "_helper") == 0, |
| 199 |
"finds a label by address"); |
| 200 |
check(dbg_info_symbol_count() == 2, "enumerates both labels"); |
| 201 |
|
| 202 |
|
| 203 |
dbg_addr_t prev = 0; |
| 204 |
int sorted = 1; |
| 205 |
for (int i = 0; i < dbg_info_symbol_count(); i++) { |
| 206 |
const char *n = NULL; |
| 207 |
dbg_addr_t a = 0; |
| 208 |
if (!dbg_info_symbol_at(i, &n, &a) || (i && a < prev)) { |
| 209 |
sorted = 0; |
| 210 |
} |
| 211 |
prev = a; |
| 212 |
} |
| 213 |
check(sorted, "enumeration is sorted by address"); |
| 214 |
|
| 215 |
const char *n = NULL; |
| 216 |
dbg_addr_t a = 0; |
| 217 |
check(!dbg_info_symbol_at(dbg_info_symbol_count(), &n, &a), |
| 218 |
"declines an out-of-range index"); |
| 219 |
check(!dbg_info_symbol_at(-1, &n, &a), "declines a negative index"); |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
check(dbg_info_file_count() == 2, "enumerates both source files"); |
| 225 |
|
| 226 |
|
| 227 |
check(dbg_info_is_span_start(0x0801), "recognises a span start"); |
| 228 |
check(!dbg_info_is_span_start(0x0805), "does not claim a mid-span address"); |
| 229 |
|
| 230 |
|
| 231 |
dbg_info_unload_range(0x0801, 0x0840); |
| 232 |
{ |
| 233 |
const char *file = NULL; |
| 234 |
int line = 0; |
| 235 |
check(!dbg_info_addr_to_source(0x0801, &file, &line), |
| 236 |
"unload_range drops mappings in the range"); |
| 237 |
} |
| 238 |
|
| 239 |
dbg_info_free(); |
| 240 |
check(!dbg_info_is_loaded(), "reports not loaded after free"); |
| 241 |
|
| 242 |
dbg_info_free(); |
| 243 |
check(1, "double free is harmless"); |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
check(dbg_info_load(path) == 0, "reloads after free"); |
| 248 |
check(dbg_info_load("this/does/not/exist.dbg") != 0, "second load of a missing file fails"); |
| 249 |
{ |
| 250 |
const char *file = NULL; |
| 251 |
int line = 0; |
| 252 |
check(dbg_info_addr_to_source(0x0801, &file, &line), |
| 253 |
"a failed load leaves the existing mapping intact"); |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
{ |
| 260 |
const int files_before = dbg_info_file_count(); |
| 261 |
dbg_info_unload_range(0x0801, 0x0840); |
| 262 |
check(dbg_info_load(path) == 0, "reloads the same module"); |
| 263 |
const char *file = NULL; |
| 264 |
int line = 0; |
| 265 |
check(dbg_info_addr_to_source(0x0801, &file, &line), |
| 266 |
"the reloaded module still resolves"); |
| 267 |
check(line == 10, " ...to the original line"); |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
check(dbg_info_file_count() == files_before, |
| 275 |
" ...without accumulating a second copy of its files"); |
| 276 |
} |
| 277 |
|
| 278 |
const int files_before_swaps = dbg_info_file_count(); |
| 279 |
for (int i = 0; i < 5; i++) { |
| 280 |
dbg_info_unload_range(0x0801, 0x0840); |
| 281 |
dbg_info_load(path); |
| 282 |
} |
| 283 |
{ |
| 284 |
const char *file = NULL; |
| 285 |
int line = 0; |
| 286 |
check(dbg_info_addr_to_source(0x0801, &file, &line) && line == 10, |
| 287 |
"still resolves after repeated module swaps"); |
| 288 |
check(dbg_info_file_count() == files_before_swaps, |
| 289 |
"and does not grow a little on every swap"); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
{ |
| 295 |
char huge[4096]; |
| 296 |
memset(huge, 'a', sizeof(huge) - 1); |
| 297 |
huge[sizeof(huge) - 1] = '\0'; |
| 298 |
dbg_addr_t lo = 0, hi = 0; |
| 299 |
check(!dbg_info_peek_file_range(huge, &lo, &hi), |
| 300 |
"declines an over-long path instead of overflowing"); |
| 301 |
} |
| 302 |
|
| 303 |
dbg_info_free(); |
| 304 |
remove(path); |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
{ |
| 314 |
char *bpath = write_temp_banked_dbg(); |
| 315 |
if (!bpath) { |
| 316 |
return 1; |
| 317 |
} |
| 318 |
check(dbg_info_load(bpath) == 0, "loads a banked .dbg"); |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
const char *fu = NULL; |
| 325 |
int lu = 0; |
| 326 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 5, &fu, &lu) == DBG_BANK_UNKNOWN, |
| 327 |
"flags a match against an unknown-bank segment as a guess"); |
| 328 |
check(dbg_info_addr_to_source_banked(0xA000, 5, &fu, &lu), |
| 329 |
"still reports the mapping for an unknown-bank segment"); |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
dbg_info_note_bank_load(0xA000, 0x10, 5); |
| 334 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 5, &fu, &lu) == DBG_BANK_RESOLVED, |
| 335 |
"reports the newly learned segment as resolved"); |
| 336 |
check(dbg_info_addr_to_source_banked_ex(0xA018, 5, &fu, &lu) == DBG_BANK_UNKNOWN, |
| 337 |
"keeps a still-unknown segment flagged as a guess"); |
| 338 |
|
| 339 |
dbg_info_note_bank_load(0xA000, 0x20, 6); |
| 340 |
|
| 341 |
const char *f5 = NULL, *f6 = NULL; |
| 342 |
int l5 = 0, l6 = 0; |
| 343 |
bool ok5 = dbg_info_addr_to_source_banked(0xA000, 5, &f5, &l5); |
| 344 |
bool ok6 = dbg_info_addr_to_source_banked(0xA000, 6, &f6, &l6); |
| 345 |
check(ok5 && ok6, "resolves the banked address in both banks"); |
| 346 |
check(ok5 && ok6 && f5 && f6 && strcmp(f5, f6) != 0, |
| 347 |
"tells the two banks apart"); |
| 348 |
|
| 349 |
|
| 350 |
dbg_info_unload_range(0xA000, 0xBFFF); |
| 351 |
check(dbg_info_load(bpath) == 0, "reloads the banked module"); |
| 352 |
dbg_info_note_bank_load(0xA000, 0x10, 5); |
| 353 |
dbg_info_note_bank_load(0xA000, 0x20, 6); |
| 354 |
|
| 355 |
f5 = f6 = NULL; |
| 356 |
ok5 = dbg_info_addr_to_source_banked(0xA000, 5, &f5, &l5); |
| 357 |
ok6 = dbg_info_addr_to_source_banked(0xA000, 6, &f6, &l6); |
| 358 |
check(ok5 && ok6 && f5 && f6 && strcmp(f5, f6) != 0, |
| 359 |
"still tells the banks apart after a module swap"); |
| 360 |
|
| 361 |
|
| 362 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 5, &f5, &l5) == DBG_BANK_RESOLVED, |
| 363 |
"reports a known bank as resolved"); |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 9, &f5, &l5) == DBG_BANK_UNKNOWN, |
| 368 |
"reports an unlearned bank as unknown rather than guessing"); |
| 369 |
|
| 370 |
|
| 371 |
check(dbg_info_addr_to_source_banked_ex(0x5000, 5, &f5, &l5) == DBG_BANK_NO_MATCH, |
| 372 |
"reports an unmapped address as no match"); |
| 373 |
|
| 374 |
dbg_info_free(); |
| 375 |
remove(bpath); |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
{ |
| 382 |
static const char *k_dbg_far = |
| 383 |
"version\tmajor=2,minor=0\n" |
| 384 |
"file\tid=0,name=\"far.s\",size=10,mtime=0x00000000,mod=0\n" |
| 385 |
"seg\tid=0,name=\"FAR\",start=0x018000,size=0x0010,addrsize=far,type=ro\n" |
| 386 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 387 |
"line\tid=0,file=0,line=5,span=0\n" |
| 388 |
"sym\tid=0,name=\"_far\",addrsize=far,size=3,scope=0,def=0,val=0x018000,type=lab\n"; |
| 389 |
char *fpath = write_temp(k_dbg_far, "x16_dbg_info_far.dbg"); |
| 390 |
if (!fpath) { |
| 391 |
return 1; |
| 392 |
} |
| 393 |
check(dbg_info_load(fpath) == 0, "loads a .dbg with addresses above $FFFF"); |
| 394 |
const char *file = NULL; |
| 395 |
int line = 0; |
| 396 |
check(dbg_info_addr_to_source(0x018000, &file, &line) && line == 5, |
| 397 |
"maps a bank-1 address to source"); |
| 398 |
dbg_addr_t addr = 0; |
| 399 |
check(dbg_info_label_to_addr("_far", &addr) && addr == 0x018000, |
| 400 |
"keeps the full 24-bit value of a far label"); |
| 401 |
check(dbg_info_is_span_start(0x018000), "recognises a far span start"); |
| 402 |
dbg_info_free(); |
| 403 |
remove(fpath); |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
{ |
| 412 |
char *big = malloc(70000); |
| 413 |
if (!big) { |
| 414 |
printf("FAIL: out of memory building the long-record case\n"); |
| 415 |
return 1; |
| 416 |
} |
| 417 |
int n = sprintf(big, |
| 418 |
"version\tmajor=2,minor=0\n" |
| 419 |
"file\tid=0,name=\"long.s\",size=10,mtime=0x00000000,mod=0\n" |
| 420 |
"seg\tid=0,name=\"CODE\",start=0x000801,size=0x0010,addrsize=absolute,type=ro\n" |
| 421 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 422 |
"line\tid=0,file=0,line=1,span=0\n" |
| 423 |
"sym\tid=0,name=\"_busy\",addrsize=absolute,ref="); |
| 424 |
for (int i = 0; i < 8000; i++) { |
| 425 |
n += sprintf(big + n, "%d+", i); |
| 426 |
} |
| 427 |
n += sprintf(big + n, "99,size=3,scope=0,def=0,val=0x000801,type=lab\n"); |
| 428 |
|
| 429 |
char *lpath = write_temp(big, "x16_dbg_info_long.dbg"); |
| 430 |
free(big); |
| 431 |
if (!lpath) { |
| 432 |
return 1; |
| 433 |
} |
| 434 |
check(dbg_info_load(lpath) == 0, "loads a .dbg with a very long record"); |
| 435 |
dbg_addr_t addr = 0; |
| 436 |
check(dbg_info_label_to_addr("_busy", &addr) && addr == 0x0801, |
| 437 |
"reads fields that follow a multi-kilobyte reference list"); |
| 438 |
dbg_info_free(); |
| 439 |
remove(lpath); |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
{ |
| 452 |
dbg_info_free(); |
| 453 |
char *bpath = write_temp_banked_dbg(); |
| 454 |
if (!bpath) { |
| 455 |
check(false, "could not write the banked fixture"); |
| 456 |
} else { |
| 457 |
check(dbg_info_load(bpath) == 0, "reloads the banked fixture"); |
| 458 |
|
| 459 |
dbg_info_note_bank_load(0xA000, 0x20, 6); |
| 460 |
|
| 461 |
const char *fb = NULL; |
| 462 |
int lb = 0; |
| 463 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 6, &fb, &lb) |
| 464 |
== DBG_BANK_RESOLVED, |
| 465 |
"a confirmed bank is not demoted by a narrower unknown one"); |
| 466 |
check(fb && strstr(fb, "b_bank6") != NULL, |
| 467 |
" ...and answers with the segment that matched"); |
| 468 |
check(lb == 99, " ...and with its line"); |
| 469 |
|
| 470 |
dbg_info_free(); |
| 471 |
remove(bpath); |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
{ |
| 480 |
dbg_info_free(); |
| 481 |
char *p1 = write_temp(k_dbg_equ_v1, "x16_dbg_info_equ.dbg"); |
| 482 |
if (!p1) { |
| 483 |
check(false, "could not write the equate fixture"); |
| 484 |
} else { |
| 485 |
check(dbg_info_load(p1) == 0, "loads a module with equates"); |
| 486 |
dbg_addr_t v = 0; |
| 487 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 488 |
"reads an equate's value"); |
| 489 |
|
| 490 |
|
| 491 |
char *p2 = write_temp(k_dbg_equ_v2, "x16_dbg_info_equ.dbg"); |
| 492 |
if (p2) { |
| 493 |
dbg_info_unload_range(0xA000, 0xA00F); |
| 494 |
check(dbg_info_load(p2) == 0, "reloads it after a rebuild"); |
| 495 |
v = 0; |
| 496 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0xBEEF, |
| 497 |
"and the new value replaces the old one"); |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
const char *bf = NULL; |
| 505 |
int bl = 0; |
| 506 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 7, &bf, &bl) |
| 507 |
== DBG_BANK_RESOLVED, |
| 508 |
"and a reloaded bank equate reseeds the segment's bank"); |
| 509 |
} |
| 510 |
remove(p1); |
| 511 |
dbg_info_free(); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
{ |
| 520 |
dbg_info_free(); |
| 521 |
char *pa = write_temp(k_dbg_equ_v1, "x16_dbg_info_modA.dbg"); |
| 522 |
if (!pa) { |
| 523 |
check(false, "could not write module A"); |
| 524 |
} else { |
| 525 |
check(dbg_info_load(pa) == 0, "loads module A"); |
| 526 |
|
| 527 |
char *pb = write_temp(k_dbg_equ_v2, "x16_dbg_info_modB.dbg"); |
| 528 |
if (pb) { |
| 529 |
check(dbg_info_load(pb) == 0, "loads module B alongside it"); |
| 530 |
dbg_addr_t v = 0; |
| 531 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 532 |
"and B's SCORE does not overwrite A's"); |
| 533 |
remove(pb); |
| 534 |
} |
| 535 |
remove(pa); |
| 536 |
dbg_info_free(); |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
{ |
| 544 |
dbg_info_free(); |
| 545 |
static const char *k_dbg_line_first = |
| 546 |
"version\tmajor=2,minor=0\n" |
| 547 |
"line\tid=0,file=0,line=7,span=0\n" |
| 548 |
"file\tid=0,name=\"late.s\",size=10,mtime=0x00000000,mod=0\n" |
| 549 |
"seg\tid=0,name=\"CODE\",start=0x000801,size=0x0010,addrsize=absolute,type=ro\n" |
| 550 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 551 |
"mod\tid=0,name=\"late.o\",file=0\n"; |
| 552 |
char *lp = write_temp(k_dbg_line_first, "x16_dbg_info_linefirst.dbg"); |
| 553 |
if (!lp) { |
| 554 |
check(false, "could not write the record-order fixture"); |
| 555 |
} else { |
| 556 |
check(dbg_info_load(lp) == 0, "loads a .dbg with line before file"); |
| 557 |
const char *f = NULL; |
| 558 |
int n = 0; |
| 559 |
check(dbg_info_addr_to_source(0x0801, &f, &n) && n == 7, |
| 560 |
"and the line still resolves to its file"); |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
dbg_info_unload_range(0x0801, 0x0810); |
| 566 |
check(dbg_info_load(lp) == 0, "reloads it"); |
| 567 |
f = NULL; |
| 568 |
n = 0; |
| 569 |
check(dbg_info_addr_to_source(0x0801, &f, &n) && n == 7, |
| 570 |
"and it still resolves after the IDs have moved on"); |
| 571 |
remove(lp); |
| 572 |
dbg_info_free(); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
{ |
| 582 |
dbg_info_free(); |
| 583 |
static const char *k_dbg_two_banks = |
| 584 |
"version\tmajor=2,minor=0\n" |
| 585 |
"file\tid=0,name=\"two.s\",size=10,mtime=0x00000000,mod=0\n" |
| 586 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 587 |
"seg\tid=1,name=\"CODE2\",start=0x00a020,size=0x0010,addrsize=absolute,type=ro\n" |
| 588 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 589 |
"span\tid=1,seg=1,start=0,size=16,type=0\n" |
| 590 |
"line\tid=0,file=0,line=1,span=0\n" |
| 591 |
"line\tid=1,file=0,line=2,span=1\n" |
| 592 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 593 |
"sym\tid=1,name=\"RAM_BANK_CODE2\",addrsize=absolute,size=1,scope=0,def=0,val=0x000007,type=equ\n" |
| 594 |
"mod\tid=0,name=\"two.o\",file=0\n"; |
| 595 |
char *tp = write_temp(k_dbg_two_banks, "x16_dbg_info_twobanks.dbg"); |
| 596 |
if (!tp) { |
| 597 |
check(false, "could not write the prefix-collision fixture"); |
| 598 |
} else { |
| 599 |
check(dbg_info_load(tp) == 0, "loads two segments with related names"); |
| 600 |
const char *f = NULL; |
| 601 |
int l = 0; |
| 602 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l) |
| 603 |
== DBG_BANK_RESOLVED, |
| 604 |
"CODE takes the bank named for it"); |
| 605 |
f = NULL; |
| 606 |
l = 0; |
| 607 |
check(dbg_info_addr_to_source_banked_ex(0xA020, 7, &f, &l) |
| 608 |
== DBG_BANK_RESOLVED, |
| 609 |
"and CODE2 is not claimed by CODE's equate"); |
| 610 |
remove(tp); |
| 611 |
dbg_info_free(); |
| 612 |
} |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
{ |
| 621 |
dbg_info_free(); |
| 622 |
static const char *k_dbg_ambig = |
| 623 |
"version\tmajor=2,minor=0\n" |
| 624 |
"file\tid=0,name=\"amb.s\",size=10,mtime=0x00000000,mod=0\n" |
| 625 |
"seg\tid=0,name=\"STORETILE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 626 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 627 |
"line\tid=0,file=0,line=1,span=0\n" |
| 628 |
"sym\tid=0,name=\"RAM_BANK_STORE_TILEMAP\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 629 |
"sym\tid=1,name=\"RAM_BANK_STORE_TILESET\",addrsize=absolute,size=1,scope=0,def=0,val=0x000007,type=equ\n" |
| 630 |
"mod\tid=0,name=\"amb.o\",file=0\n"; |
| 631 |
char *ap = write_temp(k_dbg_ambig, "x16_dbg_info_ambig.dbg"); |
| 632 |
if (!ap) { |
| 633 |
check(false, "could not write the ambiguity fixture"); |
| 634 |
} else { |
| 635 |
check(dbg_info_load(ap) == 0, "loads an ambiguously named segment"); |
| 636 |
const char *f = NULL; |
| 637 |
int l = 0; |
| 638 |
|
| 639 |
dbg_bank_result_t m3 = dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l); |
| 640 |
f = NULL; |
| 641 |
l = 0; |
| 642 |
dbg_bank_result_t m7 = dbg_info_addr_to_source_banked_ex(0xA000, 7, &f, &l); |
| 643 |
check(m3 != DBG_BANK_RESOLVED && m7 != DBG_BANK_RESOLVED, |
| 644 |
"and picks neither bank when two equates match equally well"); |
| 645 |
remove(ap); |
| 646 |
dbg_info_free(); |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
{ |
| 656 |
dbg_info_free(); |
| 657 |
static const char *k_bank_a = |
| 658 |
"version\tmajor=2,minor=0\n" |
| 659 |
"file\tid=0,name=\"ova.s\",size=10,mtime=0x00000000,mod=0\n" |
| 660 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 661 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 662 |
"line\tid=0,file=0,line=1,span=0\n" |
| 663 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 664 |
"mod\tid=0,name=\"ova.o\",file=0\n"; |
| 665 |
static const char *k_bank_b = |
| 666 |
"version\tmajor=2,minor=0\n" |
| 667 |
"file\tid=0,name=\"ovb.s\",size=10,mtime=0x00000000,mod=0\n" |
| 668 |
"seg\tid=0,name=\"CODE\",start=0x00a020,size=0x0010,addrsize=absolute,type=ro\n" |
| 669 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 670 |
"line\tid=0,file=0,line=1,span=0\n" |
| 671 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000007,type=equ\n" |
| 672 |
"mod\tid=0,name=\"ovb.o\",file=0\n"; |
| 673 |
char *ba = write_temp(k_bank_a, "x16_dbg_info_bankA.dbg"); |
| 674 |
if (!ba) { |
| 675 |
check(false, "could not write bank module A"); |
| 676 |
} else { |
| 677 |
check(dbg_info_load(ba) == 0, "loads overlay A"); |
| 678 |
char *bb = write_temp(k_bank_b, "x16_dbg_info_bankB.dbg"); |
| 679 |
if (bb) { |
| 680 |
check(dbg_info_load(bb) == 0, "loads overlay B, same equate name"); |
| 681 |
const char *f = NULL; |
| 682 |
int l = 0; |
| 683 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l) |
| 684 |
== DBG_BANK_RESOLVED, |
| 685 |
"A's CODE keeps the bank A declared"); |
| 686 |
f = NULL; |
| 687 |
l = 0; |
| 688 |
check(dbg_info_addr_to_source_banked_ex(0xA020, 7, &f, &l) |
| 689 |
== DBG_BANK_RESOLVED, |
| 690 |
"and B's CODE keeps the bank B declared"); |
| 691 |
remove(bb); |
| 692 |
} |
| 693 |
remove(ba); |
| 694 |
dbg_info_free(); |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
{ |
| 702 |
dbg_info_free(); |
| 703 |
char *fa = write_temp(k_dbg_equ_v1, "x16_dbg_info_fileA.dbg"); |
| 704 |
if (!fa) { |
| 705 |
check(false, "could not write file module A"); |
| 706 |
} else { |
| 707 |
check(dbg_info_load(fa) == 0, "loads a module declaring equ.s"); |
| 708 |
int after_a = dbg_info_file_count(); |
| 709 |
char *fb = write_temp(k_dbg_equ_v2, "x16_dbg_info_fileB.dbg"); |
| 710 |
if (fb) { |
| 711 |
check(dbg_info_load(fb) == 0, "loads another declaring its own equ.s"); |
| 712 |
check(dbg_info_file_count() == after_a + 1, |
| 713 |
"and the two same-named files stay separate records"); |
| 714 |
remove(fb); |
| 715 |
} |
| 716 |
remove(fa); |
| 717 |
dbg_info_free(); |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
{ |
| 726 |
dbg_info_free(); |
| 727 |
static const char *k_donor_v1 = |
| 728 |
"version\tmajor=2,minor=0\n" |
| 729 |
"file\tid=0,name=\"donor.s\",size=10,mtime=0x00000000,mod=0\n" |
| 730 |
"seg\tid=0,name=\"DONOR\",start=0x000800,size=0x0010,addrsize=absolute,type=ro\n" |
| 731 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 732 |
"line\tid=0,file=0,line=1,span=0\n" |
| 733 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 734 |
"mod\tid=0,name=\"donor.o\",file=0\n"; |
| 735 |
static const char *k_donor_v2 = |
| 736 |
"version\tmajor=2,minor=0\n" |
| 737 |
"file\tid=0,name=\"donor.s\",size=10,mtime=0x00000000,mod=0\n" |
| 738 |
"seg\tid=0,name=\"DONOR\",start=0x000800,size=0x0010,addrsize=absolute,type=ro\n" |
| 739 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 740 |
"line\tid=0,file=0,line=1,span=0\n" |
| 741 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000007,type=equ\n" |
| 742 |
"mod\tid=0,name=\"donor.o\",file=0\n"; |
| 743 |
|
| 744 |
static const char *k_consumer = |
| 745 |
"version\tmajor=2,minor=0\n" |
| 746 |
"file\tid=0,name=\"consumer.s\",size=10,mtime=0x00000000,mod=0\n" |
| 747 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 748 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 749 |
"line\tid=0,file=0,line=1,span=0\n" |
| 750 |
"mod\tid=0,name=\"consumer.o\",file=0\n"; |
| 751 |
char *dp = write_temp(k_donor_v1, "x16_dbg_info_donor.dbg"); |
| 752 |
if (!dp) { |
| 753 |
check(false, "could not write the donor fixture"); |
| 754 |
} else { |
| 755 |
check(dbg_info_load(dp) == 0, "loads the donor module"); |
| 756 |
char *cp = write_temp(k_consumer, "x16_dbg_info_consumer.dbg"); |
| 757 |
if (cp) { |
| 758 |
check(dbg_info_load(cp) == 0, "loads a consumer with no equate of its own"); |
| 759 |
const char *f = NULL; |
| 760 |
int l = 0; |
| 761 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l) |
| 762 |
== DBG_BANK_RESOLVED, |
| 763 |
"which borrows the donor's bank"); |
| 764 |
|
| 765 |
|
| 766 |
char *dp2 = write_temp(k_donor_v2, "x16_dbg_info_donor.dbg"); |
| 767 |
if (dp2) { |
| 768 |
dbg_info_unload_range(0x0800, 0x080F); |
| 769 |
check(dbg_info_load(dp2) == 0, "reloads the donor with a new bank"); |
| 770 |
f = NULL; |
| 771 |
l = 0; |
| 772 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 7, &f, &l) |
| 773 |
== DBG_BANK_RESOLVED, |
| 774 |
"and the borrowed bank follows it"); |
| 775 |
f = NULL; |
| 776 |
l = 0; |
| 777 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l) |
| 778 |
!= DBG_BANK_RESOLVED, |
| 779 |
"rather than answering to the bank nobody declares"); |
| 780 |
} |
| 781 |
remove(cp); |
| 782 |
} |
| 783 |
remove(dp); |
| 784 |
dbg_info_free(); |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
{ |
| 791 |
dbg_info_free(); |
| 792 |
char *op = write_temp(k_dbg_equ_v1, "x16_dbg_info_obs.dbg"); |
| 793 |
if (!op) { |
| 794 |
check(false, "could not write the observation fixture"); |
| 795 |
} else { |
| 796 |
check(dbg_info_load(op) == 0, "loads a module whose equate says bank 3"); |
| 797 |
|
| 798 |
dbg_info_note_bank_load(0xA000, 0x10, 9); |
| 799 |
const char *f = NULL; |
| 800 |
int l = 0; |
| 801 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 9, &f, &l) |
| 802 |
== DBG_BANK_RESOLVED, |
| 803 |
"and a runtime observation overrides it"); |
| 804 |
|
| 805 |
|
| 806 |
char *o2 = write_temp(k_dbg_equ_v1, "x16_dbg_info_obs2.dbg"); |
| 807 |
if (o2) { |
| 808 |
check(dbg_info_load(o2) == 0, "loads another module afterwards"); |
| 809 |
f = NULL; |
| 810 |
l = 0; |
| 811 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 9, &f, &l) |
| 812 |
== DBG_BANK_RESOLVED, |
| 813 |
"and re-deriving equate banks leaves the observation alone"); |
| 814 |
remove(o2); |
| 815 |
} |
| 816 |
remove(op); |
| 817 |
dbg_info_free(); |
| 818 |
} |
| 819 |
} |
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
{ |
| 826 |
dbg_info_free(); |
| 827 |
static const char *k_rank_main = |
| 828 |
"version\tmajor=2,minor=0\n" |
| 829 |
"file\tid=0,name=\"rmain.s\",size=10,mtime=0x00000000,mod=0\n" |
| 830 |
"seg\tid=0,name=\"OTHER\",start=0x000900,size=0x0010,addrsize=absolute,type=ro\n" |
| 831 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 832 |
"line\tid=0,file=0,line=1,span=0\n" |
| 833 |
"sym\tid=0,name=\"RAM_BANK_CODE2\",addrsize=absolute,size=1,scope=0,def=0,val=0x000009,type=equ\n" |
| 834 |
"mod\tid=0,name=\"rmain.o\",file=0\n"; |
| 835 |
static const char *k_rank_ovl = |
| 836 |
"version\tmajor=2,minor=0\n" |
| 837 |
"file\tid=0,name=\"rovl.s\",size=10,mtime=0x00000000,mod=0\n" |
| 838 |
"seg\tid=0,name=\"CODE2\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 839 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 840 |
"line\tid=0,file=0,line=1,span=0\n" |
| 841 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000002,type=equ\n" |
| 842 |
"mod\tid=0,name=\"rovl.o\",file=0\n"; |
| 843 |
char *rm = write_temp(k_rank_main, "x16_dbg_info_rankmain.dbg"); |
| 844 |
if (!rm) { |
| 845 |
check(false, "could not write the ranking fixture"); |
| 846 |
} else { |
| 847 |
check(dbg_info_load(rm) == 0, "loads a module declaring RAM_BANK_CODE2"); |
| 848 |
char *ro = write_temp(k_rank_ovl, "x16_dbg_info_rankovl.dbg"); |
| 849 |
if (ro) { |
| 850 |
|
| 851 |
|
| 852 |
check(dbg_info_load(ro) == 0, "loads an overlay whose own equate only resembles it"); |
| 853 |
const char *f = NULL; |
| 854 |
int l = 0; |
| 855 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 9, &f, &l) |
| 856 |
== DBG_BANK_RESOLVED, |
| 857 |
"an exact match elsewhere beats a resemblance at home"); |
| 858 |
f = NULL; |
| 859 |
l = 0; |
| 860 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 2, &f, &l) |
| 861 |
!= DBG_BANK_RESOLVED, |
| 862 |
"and the resemblance does not also answer"); |
| 863 |
remove(ro); |
| 864 |
} |
| 865 |
remove(rm); |
| 866 |
dbg_info_free(); |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
{ |
| 874 |
dbg_info_free(); |
| 875 |
static const char *k_self_contradict = |
| 876 |
"version\tmajor=2,minor=0\n" |
| 877 |
"file\tid=0,name=\"sc.s\",size=10,mtime=0x00000000,mod=0\n" |
| 878 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 879 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 880 |
"line\tid=0,file=0,line=1,span=0\n" |
| 881 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 882 |
"sym\tid=1,name=\"CODE_BANK\",addrsize=absolute,size=1,scope=0,def=0,val=0x000007,type=equ\n" |
| 883 |
"mod\tid=0,name=\"sc.o\",file=0\n"; |
| 884 |
char *sp = write_temp(k_self_contradict, "x16_dbg_info_selfcon.dbg"); |
| 885 |
if (!sp) { |
| 886 |
check(false, "could not write the self-contradiction fixture"); |
| 887 |
} else { |
| 888 |
check(dbg_info_load(sp) == 0, "loads a module naming one segment twice"); |
| 889 |
const char *f = NULL; |
| 890 |
int l = 0; |
| 891 |
dbg_bank_result_t r3 = dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l); |
| 892 |
f = NULL; |
| 893 |
l = 0; |
| 894 |
dbg_bank_result_t r7 = dbg_info_addr_to_source_banked_ex(0xA000, 7, &f, &l); |
| 895 |
check(r3 != DBG_BANK_RESOLVED && r7 != DBG_BANK_RESOLVED, |
| 896 |
"and two exact matches that disagree resolve to neither"); |
| 897 |
remove(sp); |
| 898 |
dbg_info_free(); |
| 899 |
} |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
{ |
| 904 |
dbg_info_free(); |
| 905 |
static const char *k_short_prefix = |
| 906 |
"version\tmajor=2,minor=0\n" |
| 907 |
"file\tid=0,name=\"sp.s\",size=10,mtime=0x00000000,mod=0\n" |
| 908 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 909 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 910 |
"line\tid=0,file=0,line=1,span=0\n" |
| 911 |
"sym\tid=0,name=\"RAM_BANK_COD\",addrsize=absolute,size=1,scope=0,def=0,val=0x000005,type=equ\n" |
| 912 |
"mod\tid=0,name=\"sp.o\",file=0\n"; |
| 913 |
char *pp = write_temp(k_short_prefix, "x16_dbg_info_shortpfx.dbg"); |
| 914 |
if (!pp) { |
| 915 |
check(false, "could not write the short-prefix fixture"); |
| 916 |
} else { |
| 917 |
check(dbg_info_load(pp) == 0, "loads a segment with a near-miss equate"); |
| 918 |
const char *f = NULL; |
| 919 |
int l = 0; |
| 920 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 5, &f, &l) |
| 921 |
!= DBG_BANK_RESOLVED, |
| 922 |
"and a three-character overlap does not claim it"); |
| 923 |
remove(pp); |
| 924 |
dbg_info_free(); |
| 925 |
} |
| 926 |
} |
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
{ |
| 932 |
dbg_info_free(); |
| 933 |
static const char *k_gone_v1 = |
| 934 |
"version\tmajor=2,minor=0\n" |
| 935 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=2,type=0\n" |
| 936 |
"file\tid=0,name=\"gone.s\",size=10,mtime=0x00000000,mod=0\n" |
| 937 |
"seg\tid=0,name=\"GONE\",start=0x000800,size=0x0010,addrsize=absolute,type=ro\n" |
| 938 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 939 |
"line\tid=0,file=0,line=1,span=0\n" |
| 940 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 941 |
"sym\tid=1,name=\"SCORE\",addrsize=absolute,size=2,scope=0,def=0,val=0x001234,type=equ\n" |
| 942 |
"mod\tid=0,name=\"gone.o\",file=0\n"; |
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
static const char *k_gone_v2 = |
| 947 |
"version\tmajor=2,minor=0\n" |
| 948 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=1,type=0\n" |
| 949 |
"file\tid=0,name=\"gone.s\",size=10,mtime=0x00000000,mod=0\n" |
| 950 |
"seg\tid=0,name=\"GONE\",start=0x000800,size=0x0010,addrsize=absolute,type=ro\n" |
| 951 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 952 |
"line\tid=0,file=0,line=1,span=0\n" |
| 953 |
"sym\tid=0,name=\"_gone_entry\",addrsize=absolute,size=3,scope=0,def=0,val=0x000800,type=lab\n" |
| 954 |
"mod\tid=0,name=\"gone.o\",file=0\n"; |
| 955 |
static const char *k_borrower = |
| 956 |
"version\tmajor=2,minor=0\n" |
| 957 |
"file\tid=0,name=\"borrow.s\",size=10,mtime=0x00000000,mod=0\n" |
| 958 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 959 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 960 |
"line\tid=0,file=0,line=1,span=0\n" |
| 961 |
"mod\tid=0,name=\"borrow.o\",file=0\n"; |
| 962 |
char *gp = write_temp(k_gone_v1, "x16_dbg_info_gone.dbg"); |
| 963 |
if (!gp) { |
| 964 |
check(false, "could not write the removed-equate fixture"); |
| 965 |
} else { |
| 966 |
check(dbg_info_load(gp) == 0, "loads a module with two equates"); |
| 967 |
char *bp = write_temp(k_borrower, "x16_dbg_info_borrow.dbg"); |
| 968 |
if (bp) { |
| 969 |
check(dbg_info_load(bp) == 0, "loads a borrower with none of its own"); |
| 970 |
const char *f = NULL; |
| 971 |
int l = 0; |
| 972 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l) |
| 973 |
== DBG_BANK_RESOLVED, |
| 974 |
"which borrows the declared bank"); |
| 975 |
|
| 976 |
char *gp2 = write_temp(k_gone_v2, "x16_dbg_info_gone.dbg"); |
| 977 |
if (gp2) { |
| 978 |
dbg_info_unload_range(0x0800, 0x080F); |
| 979 |
check(dbg_info_load(gp2) == 0, "reloads it with the equates removed"); |
| 980 |
dbg_addr_t v = 0; |
| 981 |
check(!dbg_info_equate_to_value("SCORE", &v), |
| 982 |
"and the dropped equate stops resolving"); |
| 983 |
f = NULL; |
| 984 |
l = 0; |
| 985 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l) |
| 986 |
!= DBG_BANK_RESOLVED, |
| 987 |
"and the borrowed bank is not still claimed"); |
| 988 |
} |
| 989 |
remove(bp); |
| 990 |
} |
| 991 |
remove(gp); |
| 992 |
dbg_info_free(); |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
{ |
| 1000 |
dbg_info_free(); |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
char longseg[256], longequ[256]; |
| 1006 |
memset(longseg, 'A', 130); |
| 1007 |
memcpy(longseg + 130, "LEFT", 5); |
| 1008 |
memset(longequ, 'A', 127); |
| 1009 |
longequ[127] = '\0'; |
| 1010 |
char buf[2048]; |
| 1011 |
snprintf(buf, sizeof buf, |
| 1012 |
"version\tmajor=2,minor=0\n" |
| 1013 |
"file\tid=0,name=\"lng.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1014 |
"seg\tid=0,name=\"%s\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1015 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1016 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1017 |
"sym\tid=0,name=\"RAM_BANK_%s\",addrsize=absolute,size=1,scope=0,def=0,val=0x000004,type=equ\n" |
| 1018 |
"mod\tid=0,name=\"lng.o\",file=0\n", |
| 1019 |
longseg, longequ); |
| 1020 |
char *lp = write_temp(buf, "x16_dbg_info_long_names.dbg"); |
| 1021 |
if (!lp) { |
| 1022 |
check(false, "could not write the long-name fixture"); |
| 1023 |
} else { |
| 1024 |
check(dbg_info_load(lp) == 0, "loads a module with over-long names"); |
| 1025 |
const char *f = NULL; |
| 1026 |
int l = 0; |
| 1027 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 4, &f, &l) |
| 1028 |
!= DBG_BANK_RESOLVED, |
| 1029 |
"and two names that differ past the cutoff do not match"); |
| 1030 |
remove(lp); |
| 1031 |
dbg_info_free(); |
| 1032 |
} |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
{ |
| 1039 |
dbg_info_free(); |
| 1040 |
|
| 1041 |
static const char *k_ft_own = |
| 1042 |
"version\tmajor=2,minor=0\n" |
| 1043 |
"file\tid=0,name=\"ftown.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1044 |
"seg\tid=0,name=\"CODE2\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1045 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1046 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1047 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000002,type=equ\n" |
| 1048 |
"mod\tid=0,name=\"ftown.o\",file=0\n"; |
| 1049 |
|
| 1050 |
static const char *k_ft_x = |
| 1051 |
"version\tmajor=2,minor=0\n" |
| 1052 |
"file\tid=0,name=\"ftx.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1053 |
"seg\tid=0,name=\"XONE\",start=0x000900,size=0x0010,addrsize=absolute,type=ro\n" |
| 1054 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1055 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1056 |
"sym\tid=0,name=\"RAM_BANK_CODE2\",addrsize=absolute,size=1,scope=0,def=0,val=0x000005,type=equ\n" |
| 1057 |
"mod\tid=0,name=\"ftx.o\",file=0\n"; |
| 1058 |
static const char *k_ft_y = |
| 1059 |
"version\tmajor=2,minor=0\n" |
| 1060 |
"file\tid=0,name=\"fty.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1061 |
"seg\tid=0,name=\"YONE\",start=0x000920,size=0x0010,addrsize=absolute,type=ro\n" |
| 1062 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1063 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1064 |
"sym\tid=0,name=\"RAM_BANK_CODE2\",addrsize=absolute,size=1,scope=0,def=0,val=0x000006,type=equ\n" |
| 1065 |
"mod\tid=0,name=\"fty.o\",file=0\n"; |
| 1066 |
char px[512], py[512], po2[512]; |
| 1067 |
char *t = write_temp(k_ft_x, "x16_dbg_info_ftx.dbg"); |
| 1068 |
bool wrote = (t != NULL); |
| 1069 |
if (wrote) snprintf(px, sizeof px, "%s", t); |
| 1070 |
t = wrote ? write_temp(k_ft_y, "x16_dbg_info_fty.dbg") : NULL; |
| 1071 |
wrote = wrote && (t != NULL); |
| 1072 |
if (wrote) snprintf(py, sizeof py, "%s", t); |
| 1073 |
t = wrote ? write_temp(k_ft_own, "x16_dbg_info_ftown.dbg") : NULL; |
| 1074 |
wrote = wrote && (t != NULL); |
| 1075 |
if (wrote) snprintf(po2, sizeof po2, "%s", t); |
| 1076 |
if (!wrote) { |
| 1077 |
check(false, "could not write the fall-through fixtures"); |
| 1078 |
} else { |
| 1079 |
check(dbg_info_load(px) == 0 && dbg_info_load(py) == 0 && |
| 1080 |
dbg_info_load(po2) == 0, |
| 1081 |
"loads two disagreeing exact namers and one that resembles"); |
| 1082 |
const char *f = NULL; |
| 1083 |
int l = 0; |
| 1084 |
dbg_bank_result_t r5 = dbg_info_addr_to_source_banked_ex(0xA000, 5, &f, &l); |
| 1085 |
f = NULL; l = 0; |
| 1086 |
dbg_bank_result_t r6 = dbg_info_addr_to_source_banked_ex(0xA000, 6, &f, &l); |
| 1087 |
f = NULL; l = 0; |
| 1088 |
dbg_bank_result_t r2 = dbg_info_addr_to_source_banked_ex(0xA000, 2, &f, &l); |
| 1089 |
check(r5 != DBG_BANK_RESOLVED && r6 != DBG_BANK_RESOLVED, |
| 1090 |
"the contradicting exact matches resolve to neither"); |
| 1091 |
check(r2 != DBG_BANK_RESOLVED, |
| 1092 |
"and the weaker resemblance is not used to break the tie"); |
| 1093 |
remove(px); |
| 1094 |
remove(py); |
| 1095 |
remove(po2); |
| 1096 |
dbg_info_free(); |
| 1097 |
} |
| 1098 |
} |
| 1099 |
|
| 1100 |
|
| 1101 |
{ |
| 1102 |
dbg_info_free(); |
| 1103 |
static const char *k_pp_other = |
| 1104 |
"version\tmajor=2,minor=0\n" |
| 1105 |
"file\tid=0,name=\"ppo.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1106 |
"seg\tid=0,name=\"PPOTHER\",start=0x000940,size=0x0010,addrsize=absolute,type=ro\n" |
| 1107 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1108 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1109 |
"sym\tid=0,name=\"RAM_BANK_STORETILEMAP\",addrsize=absolute,size=1,scope=0,def=0,val=0x000005,type=equ\n" |
| 1110 |
"mod\tid=0,name=\"ppo.o\",file=0\n"; |
| 1111 |
static const char *k_pp_own = |
| 1112 |
"version\tmajor=2,minor=0\n" |
| 1113 |
"file\tid=0,name=\"ppw.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1114 |
"seg\tid=0,name=\"STORETILE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1115 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1116 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1117 |
"sym\tid=0,name=\"RAM_BANK_STORETILESET\",addrsize=absolute,size=1,scope=0,def=0,val=0x000006,type=equ\n" |
| 1118 |
"mod\tid=0,name=\"ppw.o\",file=0\n"; |
| 1119 |
char ppa[512], ppb[512]; |
| 1120 |
char *t2 = write_temp(k_pp_other, "x16_dbg_info_ppo.dbg"); |
| 1121 |
bool wrote2 = (t2 != NULL); |
| 1122 |
if (wrote2) snprintf(ppa, sizeof ppa, "%s", t2); |
| 1123 |
t2 = wrote2 ? write_temp(k_pp_own, "x16_dbg_info_ppw.dbg") : NULL; |
| 1124 |
wrote2 = wrote2 && (t2 != NULL); |
| 1125 |
if (wrote2) snprintf(ppb, sizeof ppb, "%s", t2); |
| 1126 |
if (!wrote2) { |
| 1127 |
check(false, "could not write the prefix-ownership fixtures"); |
| 1128 |
} else { |
| 1129 |
check(dbg_info_load(ppa) == 0 && dbg_info_load(ppb) == 0, |
| 1130 |
"loads two modules that both merely resemble the segment"); |
| 1131 |
const char *f = NULL; |
| 1132 |
int l = 0; |
| 1133 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 6, &f, &l) |
| 1134 |
== DBG_BANK_RESOLVED, |
| 1135 |
"and the segment's own module wins among resemblances"); |
| 1136 |
remove(ppa); |
| 1137 |
remove(ppb); |
| 1138 |
dbg_info_free(); |
| 1139 |
} |
| 1140 |
} |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
{ |
| 1148 |
dbg_info_free(); |
| 1149 |
static const char *k_tx_good = |
| 1150 |
"version\tmajor=2,minor=0\n" |
| 1151 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=2,type=0\n" |
| 1152 |
"file\tid=0,name=\"tx.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1153 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1154 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1155 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1156 |
"sym\tid=0,name=\"SCORE\",addrsize=absolute,size=2,scope=0,def=0,val=0x001234,type=equ\n" |
| 1157 |
"sym\tid=1,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 1158 |
"mod\tid=0,name=\"tx.o\",file=0\n"; |
| 1159 |
char txp[512]; |
| 1160 |
char *t3 = write_temp(k_tx_good, "x16_dbg_info_tx.dbg"); |
| 1161 |
if (!t3) { |
| 1162 |
check(false, "could not write the transactional fixture"); |
| 1163 |
} else { |
| 1164 |
snprintf(txp, sizeof txp, "%s", t3); |
| 1165 |
check(dbg_info_load(txp) == 0, "loads a module with equates"); |
| 1166 |
dbg_addr_t v = 0; |
| 1167 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 1168 |
"and reads one back"); |
| 1169 |
|
| 1170 |
|
| 1171 |
if (write_temp("", "x16_dbg_info_tx.dbg")) { |
| 1172 |
check(dbg_info_load(txp) != 0, |
| 1173 |
"an empty rebuild is reported as a failed load"); |
| 1174 |
v = 0; |
| 1175 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 1176 |
"an empty rebuild does not delete what still works"); |
| 1177 |
const char *f = NULL; |
| 1178 |
int l = 0; |
| 1179 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l) |
| 1180 |
== DBG_BANK_RESOLVED, |
| 1181 |
"and the bank it seeded survives too"); |
| 1182 |
} |
| 1183 |
|
| 1184 |
|
| 1185 |
if (write_temp("nonsense\nmore nonsense\n", "x16_dbg_info_tx.dbg")) { |
| 1186 |
check(dbg_info_load(txp) != 0, |
| 1187 |
"an unparseable rebuild is reported as a failed load"); |
| 1188 |
v = 0; |
| 1189 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 1190 |
"nor does an unparseable one"); |
| 1191 |
} |
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
static const char *k_tx_partial = |
| 1196 |
"version\tmajor=2,minor=0\n" |
| 1197 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=2,type=0\n" |
| 1198 |
"file\tid=0,name=\"tx.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1199 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1200 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1201 |
"line\tid=0,file=0,line=1,span=0\n"; |
| 1202 |
if (write_temp(k_tx_partial, "x16_dbg_info_tx.dbg")) { |
| 1203 |
check(dbg_info_load(txp) != 0, |
| 1204 |
"a write cut off before the symbols is a failed load"); |
| 1205 |
v = 0; |
| 1206 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 1207 |
"and a write cut off before the symbols keeps them too"); |
| 1208 |
} |
| 1209 |
remove(txp); |
| 1210 |
dbg_info_free(); |
| 1211 |
} |
| 1212 |
} |
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
{ |
| 1223 |
dbg_info_free(); |
| 1224 |
char huge[400]; |
| 1225 |
memset(huge, 'B', 300); |
| 1226 |
huge[300] = '\0'; |
| 1227 |
char buf2[2048]; |
| 1228 |
snprintf(buf2, sizeof buf2, |
| 1229 |
"version\tmajor=2,minor=0\n" |
| 1230 |
"file\tid=0,name=\"ov.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1231 |
"seg\tid=0,name=\"%s\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1232 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1233 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1234 |
"sym\tid=0,name=\"RAM_BANK_%s\",addrsize=absolute,size=1,scope=0,def=0,val=0x000008,type=equ\n" |
| 1235 |
"mod\tid=0,name=\"ov.o\",file=0\n", |
| 1236 |
huge, huge); |
| 1237 |
char *hp = write_temp(buf2, "x16_dbg_info_hugeequ.dbg"); |
| 1238 |
if (!hp) { |
| 1239 |
check(false, "could not write the long-equate fixture"); |
| 1240 |
} else { |
| 1241 |
char hpath[512]; |
| 1242 |
snprintf(hpath, sizeof hpath, "%s", hp); |
| 1243 |
check(dbg_info_load(hpath) == 0, "loads a module with an oversized equate name"); |
| 1244 |
const char *f = NULL; |
| 1245 |
int l = 0; |
| 1246 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 8, &f, &l) |
| 1247 |
!= DBG_BANK_RESOLVED, |
| 1248 |
"and an oversized equate name is handled without incident"); |
| 1249 |
remove(hpath); |
| 1250 |
dbg_info_free(); |
| 1251 |
} |
| 1252 |
} |
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
{ |
| 1258 |
dbg_info_free(); |
| 1259 |
static const char *k_cnt_full = |
| 1260 |
"version\tmajor=2,minor=0\n" |
| 1261 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=3,type=0\n" |
| 1262 |
"file\tid=0,name=\"cnt.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1263 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1264 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1265 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1266 |
"sym\tid=0,name=\"_cnt_entry\",addrsize=absolute,size=3,scope=0,def=0,val=0x00a000,type=lab\n" |
| 1267 |
"sym\tid=1,name=\"SCORE\",addrsize=absolute,size=2,scope=0,def=0,val=0x001234,type=equ\n" |
| 1268 |
"sym\tid=2,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 1269 |
"mod\tid=0,name=\"cnt.o\",file=0\n"; |
| 1270 |
|
| 1271 |
static const char *k_cnt_cut = |
| 1272 |
"version\tmajor=2,minor=0\n" |
| 1273 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=3,type=0\n" |
| 1274 |
"file\tid=0,name=\"cnt.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1275 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1276 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1277 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1278 |
"sym\tid=0,name=\"_cnt_entry\",addrsize=absolute,size=3,scope=0,def=0,val=0x00a000,type=lab\n"; |
| 1279 |
|
| 1280 |
|
| 1281 |
static const char *k_cnt_slim = |
| 1282 |
"version\tmajor=2,minor=0\n" |
| 1283 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=1,type=0\n" |
| 1284 |
"file\tid=0,name=\"cnt.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1285 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1286 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1287 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1288 |
"sym\tid=0,name=\"_cnt_entry\",addrsize=absolute,size=3,scope=0,def=0,val=0x00a000,type=lab\n" |
| 1289 |
"mod\tid=0,name=\"cnt.o\",file=0\n"; |
| 1290 |
char cpath[512]; |
| 1291 |
char *c1 = write_temp(k_cnt_full, "x16_dbg_info_cnt.dbg"); |
| 1292 |
if (!c1) { |
| 1293 |
check(false, "could not write the record-count fixture"); |
| 1294 |
} else { |
| 1295 |
snprintf(cpath, sizeof cpath, "%s", c1); |
| 1296 |
check(dbg_info_load(cpath) == 0, "loads a module that declares three symbols"); |
| 1297 |
dbg_addr_t v = 0; |
| 1298 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 1299 |
"and reads a constant from it"); |
| 1300 |
|
| 1301 |
if (write_temp(k_cnt_cut, "x16_dbg_info_cnt.dbg")) { |
| 1302 |
check(dbg_info_load(cpath) != 0, |
| 1303 |
"a file that promised three and gave one is a failed load"); |
| 1304 |
v = 0; |
| 1305 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 1306 |
"a file that promised three and gave one keeps them"); |
| 1307 |
} |
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
static const char *k_cnt_mid = |
| 1315 |
"version\tmajor=2,minor=0\n" |
| 1316 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=3,type=0\n" |
| 1317 |
"file\tid=0,name=\"cnt.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1318 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1319 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1320 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1321 |
"sym\tid=0,name=\"_cnt_entry\",addrsize=absolute,size=3,scope=0,def=0,val=0x00a000,type=lab\n" |
| 1322 |
"sym\tid=1,name=\"SCORE\",addrsize=absolute,size=2,scope=0,def=0,val=0x001234,type=equ\n"; |
| 1323 |
if (write_temp(k_cnt_full, "x16_dbg_info_cnt.dbg")) { |
| 1324 |
dbg_info_load(cpath); |
| 1325 |
} |
| 1326 |
if (write_temp(k_cnt_mid, "x16_dbg_info_cnt.dbg")) { |
| 1327 |
check(dbg_info_load(cpath) != 0, |
| 1328 |
"a cut inside the symbol block is a failed load too"); |
| 1329 |
v = 0; |
| 1330 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 1331 |
"and the bank equate that follows the cut survives"); |
| 1332 |
const char *bf = NULL; |
| 1333 |
int bl = 0; |
| 1334 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &bf, &bl) |
| 1335 |
== DBG_BANK_RESOLVED, |
| 1336 |
"so the bank it seeded is still known"); |
| 1337 |
} |
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
static const char *k_cnt_torn = |
| 1342 |
"version\tmajor=2,minor=0\n" |
| 1343 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=2,type=0\n" |
| 1344 |
"file\tid=0,name=\"cnt.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1345 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1346 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1347 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1348 |
"sym\tid=0,name=\"_cnt_entry\",addrsize=absolute,size=3,scope=0,def=0,val=0x00a000,type=lab\n" |
| 1349 |
"sym\tid=1,name=\"SCO\n"; |
| 1350 |
if (write_temp(k_cnt_full, "x16_dbg_info_cnt.dbg")) { |
| 1351 |
dbg_info_load(cpath); |
| 1352 |
} |
| 1353 |
if (write_temp(k_cnt_torn, "x16_dbg_info_cnt.dbg")) { |
| 1354 |
dbg_info_load(cpath); |
| 1355 |
v = 0; |
| 1356 |
check(dbg_info_equate_to_value("SCORE", &v) && v == 0x1234, |
| 1357 |
"and a torn final symbol does not count towards the promise"); |
| 1358 |
} |
| 1359 |
|
| 1360 |
|
| 1361 |
if (write_temp(k_cnt_full, "x16_dbg_info_cnt.dbg")) { |
| 1362 |
dbg_info_load(cpath); |
| 1363 |
} |
| 1364 |
if (write_temp(k_cnt_slim, "x16_dbg_info_cnt.dbg")) { |
| 1365 |
dbg_info_load(cpath); |
| 1366 |
v = 0; |
| 1367 |
check(!dbg_info_equate_to_value("SCORE", &v), |
| 1368 |
"but one that promised one and gave one drops them"); |
| 1369 |
} |
| 1370 |
remove(cpath); |
| 1371 |
dbg_info_free(); |
| 1372 |
} |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
{ |
| 1379 |
dbg_info_free(); |
| 1380 |
static const char *k_cross = |
| 1381 |
"version\tmajor=2,minor=0\n" |
| 1382 |
"file\tid=0,name=\"cr.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1383 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1384 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1385 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1386 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 1387 |
"sym\tid=1,name=\"RAM_BANK_CODE\",addrsize=absolute,size=2,scope=0,def=0,val=0x001234,type=equ\n" |
| 1388 |
"mod\tid=0,name=\"cr.o\",file=0\n"; |
| 1389 |
char *xp = write_temp(k_cross, "x16_dbg_info_cross.dbg"); |
| 1390 |
if (!xp) { |
| 1391 |
check(false, "could not write the cross-table fixture"); |
| 1392 |
} else { |
| 1393 |
char xpath[512]; |
| 1394 |
snprintf(xpath, sizeof xpath, "%s", xp); |
| 1395 |
check(dbg_info_load(xpath) == 0, "loads a name defined twice across tables"); |
| 1396 |
dbg_addr_t v = 0; |
| 1397 |
check(dbg_info_equate_to_value("RAM_BANK_CODE", &v) && v == 0x1234, |
| 1398 |
"the later definition answers name lookups"); |
| 1399 |
const char *f = NULL; |
| 1400 |
int l = 0; |
| 1401 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &f, &l) |
| 1402 |
!= DBG_BANK_RESOLVED, |
| 1403 |
"and the superseded one no longer seeds a bank"); |
| 1404 |
remove(xpath); |
| 1405 |
dbg_info_free(); |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
dbg_info_free(); |
| 1411 |
static const char *k_cross_rev = |
| 1412 |
"version\tmajor=2,minor=0\n" |
| 1413 |
"file\tid=0,name=\"cr2.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1414 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1415 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1416 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1417 |
"sym\tid=0,name=\"RAM_BANK_CODE\",addrsize=absolute,size=2,scope=0,def=0,val=0x001234,type=equ\n" |
| 1418 |
"sym\tid=1,name=\"RAM_BANK_CODE\",addrsize=absolute,size=1,scope=0,def=0,val=0x000003,type=equ\n" |
| 1419 |
"mod\tid=0,name=\"cr2.o\",file=0\n"; |
| 1420 |
char *yp = write_temp(k_cross_rev, "x16_dbg_info_cross2.dbg"); |
| 1421 |
if (!yp) { |
| 1422 |
check(false, "could not write the reverse cross-table fixture"); |
| 1423 |
} else { |
| 1424 |
char ypath[512]; |
| 1425 |
snprintf(ypath, sizeof ypath, "%s", yp); |
| 1426 |
check(dbg_info_load(ypath) == 0, "loads the same collision reversed"); |
| 1427 |
dbg_addr_t v2 = 0; |
| 1428 |
check(!dbg_info_equate_to_value("RAM_BANK_CODE", &v2), |
| 1429 |
"the superseded constant no longer answers name lookups"); |
| 1430 |
const char *f2 = NULL; |
| 1431 |
int l2 = 0; |
| 1432 |
check(dbg_info_addr_to_source_banked_ex(0xA000, 3, &f2, &l2) |
| 1433 |
== DBG_BANK_RESOLVED, |
| 1434 |
"and the later definition seeds the bank"); |
| 1435 |
remove(ypath); |
| 1436 |
dbg_info_free(); |
| 1437 |
} |
| 1438 |
} |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
{ |
| 1444 |
dbg_info_free(); |
| 1445 |
static const char *k_ni_full = |
| 1446 |
"version\tmajor=2,minor=0\n" |
| 1447 |
"file\tid=0,name=\"ni.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1448 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1449 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1450 |
"line\tid=0,file=0,line=1,span=0\n" |
| 1451 |
"sym\tid=0,name=\"NILIMIT\",addrsize=absolute,size=2,scope=0,def=0,val=0x004321,type=equ\n" |
| 1452 |
"mod\tid=0,name=\"ni.o\",file=0\n"; |
| 1453 |
static const char *k_ni_cut = |
| 1454 |
"version\tmajor=2,minor=0\n" |
| 1455 |
"file\tid=0,name=\"ni.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1456 |
"seg\tid=0,name=\"CODE\",start=0x00a000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1457 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1458 |
"line\tid=0,file=0,line=1,span=0\n"; |
| 1459 |
char nipath[512]; |
| 1460 |
char *n1 = write_temp(k_ni_full, "x16_dbg_info_noinfo.dbg"); |
| 1461 |
if (!n1) { |
| 1462 |
check(false, "could not write the info-less fixture"); |
| 1463 |
} else { |
| 1464 |
snprintf(nipath, sizeof nipath, "%s", n1); |
| 1465 |
check(dbg_info_load(nipath) == 0, "loads a .dbg with no info record"); |
| 1466 |
dbg_addr_t v = 0; |
| 1467 |
check(dbg_info_equate_to_value("NILIMIT", &v) && v == 0x4321, |
| 1468 |
"and reads a constant from it"); |
| 1469 |
if (write_temp(k_ni_cut, "x16_dbg_info_noinfo.dbg")) { |
| 1470 |
dbg_info_load(nipath); |
| 1471 |
v = 0; |
| 1472 |
check(dbg_info_equate_to_value("NILIMIT", &v) && v == 0x4321, |
| 1473 |
"a short read it cannot detect still keeps the constant"); |
| 1474 |
} |
| 1475 |
remove(nipath); |
| 1476 |
dbg_info_free(); |
| 1477 |
} |
| 1478 |
} |
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
{ |
| 1489 |
dbg_info_free(); |
| 1490 |
static const char *k_dbg_imp = |
| 1491 |
"version\tmajor=2,minor=0\n" |
| 1492 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=3,type=0\n" |
| 1493 |
"file\tid=0,name=\"imp.s\",size=10,mtime=0x00000000,mod=0\n" |
| 1494 |
"seg\tid=0,name=\"CODE\",start=0x000801,size=0x0010,addrsize=absolute,type=ro\n" |
| 1495 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1496 |
"line\tid=0,file=0,line=3,span=0\n" |
| 1497 |
"sym\tid=0,name=\"_start\",addrsize=absolute,size=3,scope=0,def=0,val=0x000801,type=lab\n" |
| 1498 |
"sym\tid=1,name=\"_puts\",addrsize=absolute,scope=0,def=0,ref=7,type=imp,exp=4\n" |
| 1499 |
"sym\tid=2,name=\"EOF\",addrsize=long,scope=5,def=9,val=0xFFFFFFFF,type=equ\n" |
| 1500 |
"mod\tid=0,name=\"imp.o\",file=0\n"; |
| 1501 |
char *ip = write_temp(k_dbg_imp, "x16_dbg_info_imp.dbg"); |
| 1502 |
if (!ip) { |
| 1503 |
check(false, "could not write the import fixture"); |
| 1504 |
} else { |
| 1505 |
check(dbg_info_load(ip) == 0, |
| 1506 |
"merges a .dbg whose declared symbol count includes imports " |
| 1507 |
"and out-of-range constants"); |
| 1508 |
const char *f = NULL; |
| 1509 |
int n = 0; |
| 1510 |
check(dbg_info_addr_to_source(0x0801, &f, &n) && n == 3, |
| 1511 |
" ...and its mappings are usable"); |
| 1512 |
dbg_addr_t a = 0; |
| 1513 |
check(dbg_info_label_to_addr("_start", &a) && a == 0x0801, |
| 1514 |
" ...and its labels survived"); |
| 1515 |
check(!dbg_info_equate_to_value("EOF", &a), |
| 1516 |
" ...while the out-of-range constant is counted, not kept"); |
| 1517 |
remove(ip); |
| 1518 |
dbg_info_free(); |
| 1519 |
} |
| 1520 |
} |
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
{ |
| 1538 |
dbg_info_free(); |
| 1539 |
static const char *k_dbg_cc65 = |
| 1540 |
"version\tmajor=2,minor=0\n" |
| 1541 |
"info\tcsym=0,file=7,lib=0,line=16,mod=1,scope=1,seg=1,span=16,sym=2,type=0\n" |
| 1542 |
"file\tid=0,name=\"x16hello.c\",size=200,mtime=0x00000000,mod=0\n" |
| 1543 |
"file\tid=1,name=\"x16hello.s\",size=900,mtime=0x00000000,mod=0\n" |
| 1544 |
"file\tid=2,name=\"x16util.s\",size=100,mtime=0x00000000,mod=0\n" |
| 1545 |
"file\tid=3,name=\"x16mixed.c\",size=100,mtime=0x00000000,mod=0\n" |
| 1546 |
"file\tid=4,name=\"x16mixed.s\",size=100,mtime=0x00000000,mod=0\n" |
| 1547 |
"file\tid=5,name=\"x16gen.c\",size=100,mtime=0x00000000,mod=0\n" |
| 1548 |
"file\tid=6,name=\"x16gen.c.81128.0.s\",size=900,mtime=0x00000000,mod=0\n" |
| 1549 |
"seg\tid=0,name=\"CODE\",start=0x000801,size=0x0040,addrsize=absolute,type=ro\n" |
| 1550 |
"span\tid=0,seg=0,start=0,size=12,type=0\n" |
| 1551 |
"span\tid=1,seg=0,start=0,size=3,type=0\n" |
| 1552 |
"span\tid=2,seg=0,start=3,size=2,type=0\n" |
| 1553 |
"span\tid=3,seg=0,start=5,size=3,type=0\n" |
| 1554 |
"span\tid=4,seg=0,start=8,size=4,type=0\n" |
| 1555 |
"span\tid=5,seg=0,start=12,size=8,type=0\n" |
| 1556 |
"span\tid=6,seg=0,start=12,size=4,type=0\n" |
| 1557 |
"span\tid=7,seg=0,start=16,size=4,type=0\n" |
| 1558 |
"span\tid=8,seg=0,start=20,size=4,type=0\n" |
| 1559 |
"span\tid=9,seg=0,start=20,size=4,type=0\n" |
| 1560 |
"span\tid=10,seg=0,start=24,size=6,type=0\n" |
| 1561 |
"span\tid=11,seg=0,start=24,size=2,type=0\n" |
| 1562 |
"span\tid=12,seg=0,start=30,size=6,type=0\n" |
| 1563 |
"span\tid=13,seg=0,start=30,size=3,type=0\n" |
| 1564 |
"span\tid=14,seg=0,start=36,size=6,type=0\n" |
| 1565 |
"span\tid=15,seg=0,start=36,size=3,type=0\n" |
| 1566 |
"line\tid=0,file=0,line=5,type=1,span=0\n" |
| 1567 |
"line\tid=1,file=1,line=100,span=1\n" |
| 1568 |
"line\tid=2,file=1,line=101,span=2\n" |
| 1569 |
"line\tid=3,file=1,line=102,span=3\n" |
| 1570 |
"line\tid=4,file=1,line=103,span=4\n" |
| 1571 |
"line\tid=5,file=0,line=6,type=1,span=5\n" |
| 1572 |
"line\tid=6,file=1,line=104,span=6\n" |
| 1573 |
"line\tid=7,file=1,line=105,span=7\n" |
| 1574 |
"line\tid=8,file=0,line=5,type=1,span=8\n" |
| 1575 |
"line\tid=9,file=1,line=106,span=9\n" |
| 1576 |
"line\tid=10,file=2,line=10,type=2,count=1,span=10\n" |
| 1577 |
"line\tid=11,file=2,line=20,span=11\n" |
| 1578 |
"line\tid=12,file=3,line=7,type=1,span=12\n" |
| 1579 |
"line\tid=13,file=4,line=200,span=13\n" |
| 1580 |
"line\tid=14,file=5,line=9,type=1,span=14\n" |
| 1581 |
"line\tid=15,file=6,line=300,span=15\n" |
| 1582 |
"sym\tid=0,name=\"_main\",addrsize=absolute,size=3,scope=0,def=0,val=0x000801,type=lab\n" |
| 1583 |
"sym\tid=1,name=\"_printf\",addrsize=absolute,scope=0,def=0,ref=9,type=imp,exp=6\n" |
| 1584 |
"mod\tid=0,name=\"x16hello.o\",file=0\n"; |
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
char *mixed_asm = write_temp("; hand-written\n", "x16mixed.s"); |
| 1589 |
char *cpath = write_temp(k_dbg_cc65, "x16_dbg_info_cc65.dbg"); |
| 1590 |
if (!cpath) { |
| 1591 |
check(false, "could not write the cc65 fixture"); |
| 1592 |
} else { |
| 1593 |
check(dbg_info_load(cpath) == 0, "loads a cc65 C .dbg"); |
| 1594 |
|
| 1595 |
const char *f = NULL; |
| 1596 |
int n = 0; |
| 1597 |
|
| 1598 |
|
| 1599 |
check(dbg_info_addr_to_source_nearest(0x0801, &f, &n), |
| 1600 |
"maps the first address of a C statement"); |
| 1601 |
check(f && strstr(f, "x16hello.c") != NULL, " ...to the C source"); |
| 1602 |
check(n == 5, " ...to the C line"); |
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
f = NULL; n = 0; |
| 1609 |
check(dbg_info_addr_to_source_nearest(0x0804, &f, &n) |
| 1610 |
&& f && strstr(f, "x16hello.c") != NULL && n == 5, |
| 1611 |
"an interior instruction boundary still reports the C line"); |
| 1612 |
|
| 1613 |
|
| 1614 |
f = NULL; n = 0; |
| 1615 |
check(dbg_info_addr_to_source_nearest(0x0807, &f, &n) |
| 1616 |
&& f && strstr(f, "x16hello.c") != NULL && n == 5, |
| 1617 |
"an address inside an instruction reports the C line"); |
| 1618 |
|
| 1619 |
|
| 1620 |
f = NULL; n = 0; |
| 1621 |
check(dbg_info_addr_to_source_nearest(0x080C, &f, &n) |
| 1622 |
&& f && strstr(f, "x16hello.c") != NULL && n == 5, |
| 1623 |
"the last byte of a C statement is still that statement"); |
| 1624 |
|
| 1625 |
|
| 1626 |
f = NULL; n = 0; |
| 1627 |
check(dbg_info_addr_to_source_nearest(0x080D, &f, &n) |
| 1628 |
&& f && strstr(f, "x16hello.c") != NULL && n == 6, |
| 1629 |
"the next C statement is reported at its own address"); |
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
f = NULL; n = 0; |
| 1634 |
check(dbg_info_addr_to_source(0x0804, &f, &n) |
| 1635 |
&& f && strstr(f, "x16hello.c") != NULL && n == 5, |
| 1636 |
"the exact-address lookup also prefers the C line"); |
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
f = NULL; n = 0; |
| 1641 |
check(dbg_info_addr_to_source_nearest(0x0815, &f, &n) |
| 1642 |
&& f && strstr(f, "x16hello.c") != NULL && n == 5, |
| 1643 |
"a C line wins a same-size tie with the generated assembly"); |
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
f = NULL; n = 0; |
| 1648 |
check(dbg_info_addr_to_source_nearest(0x0819, &f, &n) |
| 1649 |
&& f && strstr(f, "x16util.s") != NULL && n == 10, |
| 1650 |
"a macro record outranks the assembly line inside it"); |
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
{ |
| 1655 |
dbg_addr_t a = 0; |
| 1656 |
check(dbg_info_source_to_addr("x16hello.c", 5, &a) && a == 0x0801, |
| 1657 |
"a C line breakpoint resolves to the lowest of its spans"); |
| 1658 |
a = 0; |
| 1659 |
check(dbg_info_source_to_addr("x16hello.c", 6, &a) && a == 0x080D, |
| 1660 |
"and each statement resolves to its own start"); |
| 1661 |
} |
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
check(dbg_info_is_span_start(0x0804), "keeps an assembly span start as an anchor"); |
| 1667 |
check(dbg_info_is_span_start(0x0809), "keeps the later ones too"); |
| 1668 |
check(!dbg_info_is_span_start(0x0807), "and still rejects a mid-span address"); |
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
{ |
| 1675 |
int fc = dbg_info_file_count(); |
| 1676 |
bool has_c = false, has_gen = false, has_util = false; |
| 1677 |
bool has_mixed_c = false, has_mixed_s = false; |
| 1678 |
bool has_gen_c = false, has_gen_tmp = false; |
| 1679 |
for (int i = 0; i < fc; i++) { |
| 1680 |
const char *nm = NULL; |
| 1681 |
if (!dbg_info_file_at(i, &nm) || !nm) |
| 1682 |
continue; |
| 1683 |
if (!strcmp(nm, "x16hello.c")) has_c = true; |
| 1684 |
if (!strcmp(nm, "x16hello.s")) has_gen = true; |
| 1685 |
if (!strcmp(nm, "x16util.s")) has_util = true; |
| 1686 |
if (!strcmp(nm, "x16mixed.c")) has_mixed_c = true; |
| 1687 |
if (!strcmp(nm, "x16mixed.s")) has_mixed_s = true; |
| 1688 |
if (!strcmp(nm, "x16gen.c")) has_gen_c = true; |
| 1689 |
if (!strcmp(nm, "x16gen.c.81128.0.s")) has_gen_tmp = true; |
| 1690 |
} |
| 1691 |
check(fc == 5, "the picker drops only the generated intermediates"); |
| 1692 |
check(has_c, " ...keeps the C source"); |
| 1693 |
check(!has_gen, " ...hides the .s cc65 generated and deleted"); |
| 1694 |
check(has_util, " ...keeps a .s with no C source behind it"); |
| 1695 |
check(has_mixed_c && has_mixed_s, |
| 1696 |
" ...keeps a hand-written .s that is on disk"); |
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
check(has_gen_c, " ...keeps the C source of a one-step build"); |
| 1702 |
check(!has_gen_tmp, " ...hides cl65's temporary intermediate"); |
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
const char *nm = NULL; |
| 1707 |
check(dbg_info_file_at(fc - 1, &nm) && nm, "the last visible index resolves"); |
| 1708 |
check(!dbg_info_file_at(fc, &nm), "and one past the end does not"); |
| 1709 |
} |
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
dbg_info_unload_range(0x0801, 0x0840); |
| 1714 |
check(dbg_info_file_count() == 7, |
| 1715 |
"unloading the C module puts every file back on offer"); |
| 1716 |
|
| 1717 |
remove(cpath); |
| 1718 |
if (mixed_asm) |
| 1719 |
remove(mixed_asm); |
| 1720 |
dbg_info_free(); |
| 1721 |
} |
| 1722 |
} |
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
{ |
| 1730 |
dbg_info_free(); |
| 1731 |
char *apath = write_temp(k_dbg, "x16_dbg_info_asmonly.dbg"); |
| 1732 |
if (!apath) { |
| 1733 |
check(false, "could not write the assembly-only fixture"); |
| 1734 |
} else { |
| 1735 |
check(dbg_info_load(apath) == 0, "reloads the assembly-only fixture"); |
| 1736 |
check(dbg_info_file_count() == 2, |
| 1737 |
"an assembly-only .dbg still offers every file it names"); |
| 1738 |
const char *f = NULL; |
| 1739 |
int n = 0; |
| 1740 |
check(dbg_info_addr_to_source_nearest(0x0805, &f, &n) && n == 10, |
| 1741 |
"and still resolves by innermost span"); |
| 1742 |
remove(apath); |
| 1743 |
dbg_info_free(); |
| 1744 |
} |
| 1745 |
} |
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
{ |
| 1756 |
dbg_info_free(); |
| 1757 |
|
| 1758 |
|
| 1759 |
static const char *k_dbg_asm_two = |
| 1760 |
"version\tmajor=2,minor=0\n" |
| 1761 |
"file\tid=0,name=\"two.s\",size=100,mtime=0x00000000,mod=0\n" |
| 1762 |
"seg\tid=0,name=\"CODE\",start=0x000801,size=0x0020,addrsize=absolute,type=ro\n" |
| 1763 |
"span\tid=0,seg=0,start=0,size=8,type=0\n" |
| 1764 |
"span\tid=1,seg=0,start=3,size=17,type=0\n" |
| 1765 |
"line\tid=0,file=0,line=10,span=0\n" |
| 1766 |
"line\tid=1,file=0,line=11,span=1\n" |
| 1767 |
"mod\tid=0,name=\"two.o\",file=0\n"; |
| 1768 |
|
| 1769 |
|
| 1770 |
static const char *k_dbg_c_cut = |
| 1771 |
"version\tmajor=2,minor=0\n" |
| 1772 |
"info\tcsym=0,file=1,lib=0,line=1,mod=1,scope=1,seg=1,span=1,sym=2,type=0\n" |
| 1773 |
"file\tid=0,name=\"cut.c\",size=100,mtime=0x00000000,mod=0\n" |
| 1774 |
"seg\tid=0,name=\"OTHER\",start=0x002000,size=0x0010,addrsize=absolute,type=ro\n" |
| 1775 |
"span\tid=0,seg=0,start=0,size=16,type=0\n" |
| 1776 |
"line\tid=0,file=0,line=3,type=1,span=0\n" |
| 1777 |
"sym\tid=0,name=\"_cut\",addrsize=absolute,size=3,scope=0,def=0,val=0x002000,type=lab\n"; |
| 1778 |
|
| 1779 |
char *apath = write_temp(k_dbg_asm_two, "x16_dbg_info_two.dbg"); |
| 1780 |
char *cpath = write_temp(k_dbg_c_cut, "x16_dbg_info_cut.dbg"); |
| 1781 |
if (!apath || !cpath) { |
| 1782 |
check(false, "could not write the refused-load fixtures"); |
| 1783 |
} else { |
| 1784 |
check(dbg_info_load(apath) == 0, "loads an assembly module"); |
| 1785 |
const char *f = NULL; |
| 1786 |
int before = 0, after = 0; |
| 1787 |
check(dbg_info_addr_to_source_nearest(0x0806, &f, &before), |
| 1788 |
" ...and resolves an address inside two overlapping spans"); |
| 1789 |
|
| 1790 |
check(dbg_info_load(cpath) != 0, "refuses a half-written C .dbg"); |
| 1791 |
|
| 1792 |
f = NULL; |
| 1793 |
check(dbg_info_addr_to_source_nearest(0x0806, &f, &after), |
| 1794 |
"the assembly module still resolves afterwards"); |
| 1795 |
check(before == after, |
| 1796 |
" ...to the same line: a refused load does not change how " |
| 1797 |
"another module is read"); |
| 1798 |
check(dbg_info_file_count() == 2, |
| 1799 |
" ...and hides nothing on a refused load's say-so"); |
| 1800 |
|
| 1801 |
remove(apath); |
| 1802 |
remove(cpath); |
| 1803 |
dbg_info_free(); |
| 1804 |
} |
| 1805 |
} |
| 1806 |
|
| 1807 |
printf("\n%s (%d failure%s)\n", g_fails ? "FAILED" : "PASSED", g_fails, |
| 1808 |
g_fails == 1 ? "" : "s"); |
| 1809 |
return g_fails ? 1 : 0; |
| 1810 |
} |