X-Git-Url: https://git.saurik.com/apple/ld64.git/blobdiff_plain/55e3d2f687f4ed9653982dbda92c6a055b0a8350..eaf282aaf65b222563e6b3db98e12d720fb161bf:/src/ld/debugline.c?ds=inline diff --git a/src/ld/debugline.c b/src/ld/debugline.c index 971e616..c4e151d 100644 --- a/src/ld/debugline.c +++ b/src/ld/debugline.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005-2006 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2005-2009 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -152,6 +152,7 @@ line_file (struct line_reader_data *lnd, uint64_t n) size_t filelen, dirlen; uint64_t dir; char * result; + const char * dirpath; /* I'm not sure if this is actually an error. */ if (n == 0 @@ -168,9 +169,14 @@ line_file (struct line_reader_data *lnd, uint64_t n) else if (dir > lnd->numdir) return NULL; - dirlen = strlen ((const char *) lnd->dirnames[dir - 1]); + dirpath = (const char *)lnd->dirnames[dir - 1]; + dirlen = strlen (dirpath); + if ( dirpath[dirlen-1] == '/' ) + --dirlen; + if ( (dirpath[dirlen-1] == '.') && (dirpath[dirlen-2] == '/') ) + dirlen -= 2; result = malloc (dirlen + filelen + 2); - memcpy (result, lnd->dirnames[dir - 1], dirlen); + memcpy (result, dirpath, dirlen); result[dirlen] = '/'; memcpy (result + dirlen + 1, lnd->filenames[n - 1], filelen); result[dirlen + 1 + filelen] = '\0'; @@ -345,6 +351,8 @@ line_at_eof (struct line_reader_data * lnd) return lnd->cpos == lnd->end; } +static const bool verbose = false; + static bool next_state (struct line_reader_data *lnd) { @@ -373,28 +381,34 @@ next_state (struct line_reader_data *lnd) case DW_LNS_extended_op: { uint64_t sz = read_uleb128 (lnd); - const uint8_t * op = lnd->cpos; + const uint8_t * eop = lnd->cpos; - if ((uint64_t)(lnd->end - op) < sz || sz == 0) + if ((uint64_t)(lnd->end - eop) < sz || sz == 0) return false; lnd->cpos += sz; - switch (*op++) + switch (*eop++) { case DW_LNE_end_sequence: + if (verbose) fprintf(stderr, "DW_LNE_end_sequence\n"); lnd->cur.end_of_sequence = true; return true; case DW_LNE_set_address: - if (sz == 9) - lnd->cur.pc = read_64 (op); - else if (sz == 5) - lnd->cur.pc = read_32 (op); + if (sz == 9) { + lnd->cur.pc = read_64 (eop); + if (verbose) fprintf(stderr, "DW_LNE_set_address(0x%08llX)\n", lnd->cur.pc); + } + else if (sz == 5) { + lnd->cur.pc = read_32 (eop); + if (verbose) fprintf(stderr, "DW_LNE_set_address(0x%08llX)\n", lnd->cur.pc); + } else return false; break; case DW_LNE_define_file: { + if (verbose) fprintf(stderr, "DW_LNE_define_file\n"); const uint8_t * * filenames; filenames = realloc (lnd->filenames, @@ -402,9 +416,9 @@ next_state (struct line_reader_data *lnd) if (! filenames) return false; /* Check for zero-termination. */ - if (! memchr (op, 0, lnd->cpos - op)) + if (! memchr (eop, 0, lnd->cpos - eop)) return false; - filenames[lnd->numfile++] = op; + filenames[lnd->numfile++] = eop; lnd->filenames = filenames; /* There's other data here, like file sizes and modification @@ -414,40 +428,41 @@ next_state (struct line_reader_data *lnd) default: /* Don't understand it, so skip it. */ + if (verbose) fprintf(stderr, "DW_LNS_extended_op unknown\n"); break; } break; } case DW_LNS_copy: - //fprintf(stderr, "DW_LNS_copy\n"); + if (verbose) fprintf(stderr, "DW_LNS_copy\n"); return true; case DW_LNS_advance_pc: - //fprintf(stderr, "DW_LNS_advance_pc\n"); tmp = read_uleb128 (lnd); if (tmp == (uint64_t) -1) return false; lnd->cur.pc += tmp * lnd->minimum_instruction_length; + if (verbose) fprintf(stderr, "DW_LNS_advance_pc(0x%08llX)\n", lnd->cur.pc); break; case DW_LNS_advance_line: - //fprintf(stderr, "DW_LNS_advance_line\n"); lnd->cur.line += read_sleb128 (lnd); + if (verbose) fprintf(stderr, "DW_LNS_advance_line(%lld)\n", lnd->cur.line); break; case DW_LNS_set_file: - //fprintf(stderr, "DW_LNS_set_file\n"); + if (verbose) fprintf(stderr, "DW_LNS_set_file\n"); lnd->cur.file = read_uleb128 (lnd); break; case DW_LNS_set_column: - //fprintf(stderr, "DW_LNS_set_column\n"); + if (verbose) fprintf(stderr, "DW_LNS_set_column\n"); lnd->cur.col = read_uleb128 (lnd); break; case DW_LNS_const_add_pc: - //fprintf(stderr, "DW_LNS_const_add_pc\n"); + if (verbose) fprintf(stderr, "DW_LNS_const_add_pc\n"); lnd->cur.pc += ((255 - lnd->opcode_base) / lnd->line_range * lnd->minimum_instruction_length); break; case DW_LNS_fixed_advance_pc: - //fprintf(stderr, "DW_LNS_fixed_advance_pc\n"); + if (verbose) fprintf(stderr, "DW_LNS_fixed_advance_pc\n"); if (lnd->end - lnd->cpos < 2) return false; lnd->cur.pc += read_16 (lnd->cpos); @@ -456,6 +471,7 @@ next_state (struct line_reader_data *lnd) default: { /* Don't know what it is, so skip it. */ + if (verbose) fprintf(stderr, "unknown opcode\n"); int i; for (i = 0; i < lnd->standard_opcode_lengths[op - 1]; i++) skip_leb128 (lnd);