Prefix line with "file:linenumber:" such that editors can easily jump to the source location
Unified · Split
| @@ -222,7 +222,7 @@ static void set_pages_executable(void *ptr, unsigned long length) · 221 unmodified lines | ||
| 222 | 222 | |
| 223 | 223 | /* print the position in the source file of PC value 'pc' by reading |
| 224 | 224 | the stabs debug information */ |
| 225 | −static uplong rt_printline(uplong wanted_pc) | |
| 225 | +static uplong rt_printline(uplong wanted_pc, const char *msg) | |
| 226 | 226 | { |
| 227 | 227 | Stab_Sym *sym, *sym_end; |
| 228 | 228 | char func_name[128], last_func_name[128]; |
| @@ -231,8 +231,6 @@ static uplong rt_printline(uplong wanted_pc) · 2 unmodified lines | ||
| 231 | 231 | int incl_index, len, last_line_num, i; |
| 232 | 232 | const char *str, *p; |
| 233 | 233 | |
| 234 | − fprintf(stderr, "0x%08lx:", (unsigned long)wanted_pc); | |
| 235 | − | |
| 236 | 234 | func_name[0] = '\0'; |
| 237 | 235 | func_addr = 0; |
| 238 | 236 | incl_index = 0; |
| @@ -327,20 +325,28 @@ static uplong rt_printline(uplong wanted_pc) · 88 unmodified lines | ||
| 327 | 325 | } |
| 328 | 326 | } |
| 329 | 327 | /* did not find any info: */ |
| 330 | − fprintf(stderr, " ???\n"); | |
| 328 | + fprintf(stderr, "%s %p ???\n", msg, (void*)wanted_pc); | |
| 329 | + fflush(stderr); | |
| 331 | 330 | return 0; |
| 332 | 331 | found: |
| 333 | − if (last_func_name[0] != '\0') { | |
| 332 | + i = incl_index; | |
| 333 | + if (i > 0) | |
| 334 | + fprintf(stderr, "%s:%d: ", incl_files[--i], last_line_num); | |
| 335 | + fprintf(stderr, "%s %p", msg, (void*)wanted_pc); | |
| 336 | + if (last_func_name[0] != '\0') | |
| 334 | 337 | fprintf(stderr, " %s()", last_func_name); |
| 335 | − } | |
| 336 | − if (incl_index > 0) { | |
| 337 | − fprintf(stderr, " (%s:%d", | |
| 338 | − incl_files[incl_index - 1], last_line_num); | |
| 339 | − for(i = incl_index - 2; i >= 0; i--) | |
| 340 | − fprintf(stderr, ", included from %s", incl_files[i]); | |
| 338 | + if (--i >= 0) { | |
| 339 | + fprintf(stderr, " (included from "); | |
| 340 | + for (;;) { | |
| 341 | + fprintf(stderr, "%s", incl_files[i]); | |
| 342 | + if (--i < 0) | |
| 343 | + break; | |
| 344 | + fprintf(stderr, ", "); | |
| 345 | + } | |
| 341 | 346 | fprintf(stderr, ")"); |
| 342 | 347 | } |
| 343 | 348 | fprintf(stderr, "\n"); |
| 349 | + fflush(stderr); | |
| 344 | 350 | return func_addr; |
| 345 | 351 | } |
| 346 | 352 | |
| @@ -359,11 +365,7 @@ static void rt_error(ucontext_t *uc, const char *fmt, ...) · 12 unmodified lines | ||
| 359 | 365 | for(i=0;i<num_callers;i++) { |
| 360 | 366 | if (rt_get_caller_pc(&pc, uc, i) < 0) |
| 361 | 367 | break; |
| 362 | − if (i == 0) | |
| 363 | − fprintf(stderr, "at "); | |
| 364 | − else | |
| 365 | − fprintf(stderr, "by "); | |
| 366 | − pc = rt_printline(pc); | |
| 368 | + pc = rt_printline(pc, i ? "by" : "at"); | |
| 367 | 369 | if (pc == (uplong)rt_prog_main && pc) |
| 368 | 370 | break; |
| 369 | 371 | } |