From patchwork Sat Aug 16 01:00:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 2406 Received: (qmail 2906 invoked by alias); 16 Aug 2014 01:00:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 2280 invoked by uid 89); 16 Aug 2014 01:00:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-oa0-f73.google.com Received: from mail-oa0-f73.google.com (HELO mail-oa0-f73.google.com) (209.85.219.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 16 Aug 2014 01:00:13 +0000 Received: by mail-oa0-f73.google.com with SMTP id g18so730103oah.0 for ; Fri, 15 Aug 2014 18:00:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type; bh=c9j9MVfuKsGLBs32YVvLk4iMi6ifXyEw9T9adlcqKB8=; b=Gjok4U210cBhBG355B2DcnAJ0cUCM6cHRESxVMVzAYIbdKsAtDoyFJRRpABwd/sDmK AD06lXl91si5fW1Ui4+mcuBdqbajcPAeTsG0X6D+P0jDNLER5n0wNs+rI/wkFCtp9msd W8xd/7rJEq4OIcCSBh5bDwI7dWLEHCHXljfyJ+LPorMYW88HENmiSBfjCHh1QdOAM6Uw 11K3f4U25WloWBgK5YwVA0ZcjWc7uJ44WvWxR3ZB8Uyiqx07Sw3ZLKUk5Mab1cnL7yXY x88d3fXgqKTKsVBzjpdS/450Gb/hFSNm6B7+rjms4zfBl9eyQ4iu4nQclmyE56hsO/BB 8JuA== X-Gm-Message-State: ALoCoQn3eh1BXhzee6lg6TNH1yc6YHA21GrUiXqSapzvVCWEbMqofKS9Et/pPi4xFe+Jt7b5GhSfzJqESb59PbFyzh/Vuw6SiopVSsAEx/xi3kty/Frg3vRVNZ37WC+mhkBeGIYJOFb0 X-Received: by 10.42.62.73 with SMTP id x9mr11954635ich.15.1408150810261; Fri, 15 Aug 2014 18:00:10 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id v20si814626yhe.2.2014.08.15.18.00.10 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Aug 2014 18:00:10 -0700 (PDT) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.44]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id D85B45A43E7 for ; Fri, 15 Aug 2014 18:00:09 -0700 (PDT) From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH 1/2] [PR symtab/17276]: Coalesce line number entries. Date: Fri, 15 Aug 2014 18:00:09 -0700 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. This is the first of two patches to fix 17276. The problem here is that clang can emit multiple line number entries for the same line, e.g., for for (i = 0; i < 100000; i++); // line #34 clang will emit four line number entries: The Directory Table: ../../../binutils-gdb/gdb/testsuite/gdb.base The File Name Table: Entry Dir Time Size Name 1 1 0 0 watchpoint-reuse-slot.c Line Number Statements: Extended opcode 2: set Address to 0x400600 Advance Line by 29 to 30 Copy Set column to 3 Set prologue_end to true Special opcode 160: advance Address by 11 to 0x40060b and Line by 1 to 31 Set column to 8 Special opcode 106: advance Address by 7 to 0x400612 and Line by 3 to 34 Extended opcode 4: set Discriminator to 4 Special opcode 103: advance Address by 7 to 0x400619 and Line by 0 to 34 Extended opcode 4: set Discriminator to 2 Special opcode 201: advance Address by 14 to 0x400627 and Line by 0 to 34 Set column to 27 Extended opcode 4: set Discriminator to 3 Special opcode 75: advance Address by 5 to 0x40062c and Line by 0 to 34 Set column to 3 Extended opcode 4: set Discriminator to 0 Advance PC by constant 17 to 0x40063d Special opcode 63: advance Address by 4 to 0x400641 and Line by 2 to 36 Advance PC by 2 to 0x400643 Extended opcode 1: End of Sequence This confuses gdb because a pc can be in the middle of the source line, and yet at the start of a line number entry. This patch is just cleanup, no functional changes. It wraps some operations in functions to abstract away the details. 2014-08-15 Doug Evans * buildsym.h (record_line_ftype): New typedef. (record_line): Use it. * dwarf2read.c (dwarf_record_line, dwarf_finish_line): New functions. (dwarf_decode_lines_1): Call them. diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 57467c7..8ce01b2 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -171,6 +171,10 @@ EXTERN int context_stack_size; EXTERN int within_function; +/* The type of the record_line function. */ +typedef void (record_line_ftype) (struct subfile *subfile, int line, + CORE_ADDR pc); + #define next_symbol_text(objfile) (*next_symbol_text_func)(objfile) @@ -236,7 +240,7 @@ extern struct context_stack *push_context (int desc, CORE_ADDR valu); extern struct context_stack *pop_context (void); -extern void record_line (struct subfile *subfile, int line, CORE_ADDR pc); +extern record_line_ftype record_line; extern void start_symtab (const char *name, const char *dirname, CORE_ADDR start_addr); diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 801f05d..2017821 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -17172,6 +17172,32 @@ noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) return; } +/* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS + in the line table of subfile SUBFILE. */ + +static void +dwarf_record_line (struct gdbarch *gdbarch, struct subfile *subfile, + unsigned int line, CORE_ADDR address, + record_line_ftype p_record_line) +{ + CORE_ADDR addr = gdbarch_addr_bits_remove (gdbarch, address); + + (*p_record_line) (current_subfile, line, addr); +} + +/* Subroutine of dwarf_decode_lines_1 to simplify it. + Mark the end of a set of line number records. + The arguments are the same as for dwarf_record_line. + If SUBFILE is NULL the request is ignored. */ + +static void +dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile, + CORE_ADDR address, record_line_ftype p_record_line) +{ + if (subfile != NULL) + dwarf_record_line (gdbarch, subfile, 0, address, p_record_line); +} + /* Subroutine of dwarf_decode_lines to simplify it. Process the line number information in LH. */ @@ -17205,7 +17231,6 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, unsigned int line = 1; int is_stmt = lh->default_is_stmt; int end_sequence = 0; - CORE_ADDR addr; unsigned char op_index = 0; if (!decode_for_pst_p && lh->num_file_names >= file) @@ -17257,14 +17282,13 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, { if (last_subfile != current_subfile) { - addr = gdbarch_addr_bits_remove (gdbarch, address); - if (last_subfile) - (*p_record_line) (last_subfile, 0, addr); + dwarf_finish_line (gdbarch, last_subfile, + address, p_record_line); last_subfile = current_subfile; } /* Append row to matrix using current values. */ - addr = gdbarch_addr_bits_remove (gdbarch, address); - (*p_record_line) (current_subfile, line, addr); + dwarf_record_line (gdbarch, current_subfile, + line, address, p_record_line); } } } @@ -17357,13 +17381,12 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, { if (last_subfile != current_subfile) { - addr = gdbarch_addr_bits_remove (gdbarch, address); - if (last_subfile) - (*p_record_line) (last_subfile, 0, addr); + dwarf_finish_line (gdbarch, last_subfile, + address, p_record_line); last_subfile = current_subfile; } - addr = gdbarch_addr_bits_remove (gdbarch, address); - (*p_record_line) (current_subfile, line, addr); + dwarf_record_line (gdbarch, current_subfile, + line, address, p_record_line); } } break; @@ -17459,8 +17482,8 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, lh->file_names[file - 1].included_p = 1; if (!decode_for_pst_p) { - addr = gdbarch_addr_bits_remove (gdbarch, address); - (*p_record_line) (current_subfile, 0, addr); + dwarf_finish_line (gdbarch, current_subfile, address, + p_record_line); } } }