From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 14FAE3858C41 for ; Tue, 16 Jan 2024 19:13:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14FAE3858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14FAE3858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705432415; cv=none; b=rVuf867WWPa7vXAhC8jjKx5lwZ77p/S5cHR04F7u5gOLTmCf3LBUkvPcjFTItBSeAAgOMHSS70SxiOIXKsiXE0D6RSr45ondjtreSd+IBZWVcOMLc/uL2Ay//t4DBpql73Ixwpmm+yHckj+iaW21kA5nINlhYDf8/DFRJfXnpxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705432415; c=relaxed/simple; bh=4qDch1tqoO+NAKr3m8zsDMpcFjx6PnsLdNVmbNrGXQI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SLnfxQ0pYVBOSkFPNnNVQAfGSbJ+ZQa7g2aH6JCT/Gp0Fj8iMr195uNwDJiiCUiCrEMQGClYGU8EswaVWXX+Lkd6HcBVWE2Y/sf6JYbl+Vbf6ij7dAzgdMnJEZn5r10AtP+x2gum18HRtm+D3xLQpGKdSTdnbnBuDTcAYQjYV/c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2cd46e7ae8fso113326531fa.1 for ; Tue, 16 Jan 2024 11:13:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705432408; x=1706037208; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=a6Gw7o2AK07C1Qy3nzCe7NGkZL2t8RsvvP5NMP3qXsI=; b=EIJcbrVs+4kaQG9qXIOvIlRrnCKqYLFv6VYo1157O0pfz/Xj7FxWiT7OV+NxtIDD9Q T5votqat6V6jMkz53QqVHW9o5ijB6UpYfvyJcPAM5T+aADUcabFE/5ZfiL96N8nZGp12 efe/x4VNZRuKNWqIaS8CNFcBkbYZX1pzC5BcmxXV8Ih1GKXv50x+a19w2/JtPey2/jYP ZgZ8HD1FnoEPtqUjqKjDRyhQ/f3oWfoQx5UWSS465jDSn0SHdd+R47dNg/N/SN1vywlE 7AkW6i4G1WRwpsxDh4rMXLMrdeaZOXCBRYyzkQVxBwuTzzn9U4GO4qN0hKHvoSJb2VFm IDDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705432408; x=1706037208; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=a6Gw7o2AK07C1Qy3nzCe7NGkZL2t8RsvvP5NMP3qXsI=; b=klY7DHK7sF9HeV6qg1OFtWHwNylpp0QOjlm4TYvtvM+bWFMn07SdVJ6CmLRX4PQIUO 9scowO9H0LybTOatIaWpqVVU9lm7iFktFO2FAbUVZLrqWKoa2Y3jBHp1lLOXxQff9hYP CM0XVmKd1XJJy0de+TnykeQU5qOciQ7tmBhlHpJwbiUelr5NHvHQ/7898/WFli7pRbna 2bkFd8A9BcISa6sH2xCDuH8WveqMqEiSlfL1QevWEC5xFvvKBG9sjhVEbB9xdA+bJI72 oshb50fbWOayotHuagdgHIPNlX/7gAHoM1O+cs0VyNb3SRaj2qRaesTZiEqr2bS3fK/K iwRg== X-Gm-Message-State: AOJu0YwX48mgIUdKn99K8xfD+N28uSl7dG+6rlJ2zmrR7RQtUdtKn2ZT oz9TXn4mydXiZBGTLrsbvkrJ6ipWzUw= X-Google-Smtp-Source: AGHT+IEF+nt5xrQnZmkdWVA+hEehhhgkn7s8wdjwA+u5V33bXw9JhXKggQI9yL1HVCCDAxX1xMLXog== X-Received: by 2002:a2e:8893:0:b0:2cc:6ab1:e6a4 with SMTP id k19-20020a2e8893000000b002cc6ab1e6a4mr1341126lji.71.1705432407279; Tue, 16 Jan 2024 11:13:27 -0800 (PST) Received: from localhost.localdomain ([2001:2044:7c:4b00:37f8:fc67:7f51:113d]) by smtp.gmail.com with ESMTPSA id u1-20020a2eb801000000b002cdc84fdef9sm630413ljo.89.2024.01.16.11.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 11:13:26 -0800 (PST) From: Simon Farre To: gdb-patches@sourceware.org Cc: Simon Farre Subject: [PATCH 1/5] [dap & linetable]: Add column to linetable entry Date: Tue, 16 Jan 2024 20:13:01 +0100 Message-ID: <20240116191305.126345-1-simon.farre.cx@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is the first patch in a series meant to introduce the functionality required to serve the breakpointLocations request in the DAP protocol. It's useful for end users for other reasons, beyond that though. For instance with this data exposed to the end user (via Python, see later patches), a user can implement "step to next breakpoint location on line" on their own, which maybe will be more easily accepted than previous attempts of implementing a "next expression" command that ended up in limbo for various reasons. Such behavior would also provide the functionality required to serve DAP step/next requests with a stepping granularity of "statement". Non-DWARF debug info will just store the value 0 as the column. I specifically made the column field 29 bits, as this means linetable_entry will not increase in size, which seemingly is/was an issue, reading the comment above `linetable_entry`'s definition, though this comment is 25 years old so it may not be relevant anymore. 29 bits can represent about 500 million (29 bits=~500 million). This comment is 25 years old, so it might not be relevant any longer, but I figured making it 29 bits makes it impossible to argue against storing it (since the size doesn't change). No changes has been made to sorting of the entries etc. They work just like before, just that now entries store a "column" field. --- gdb/buildsym-legacy.c | 4 ++-- gdb/buildsym-legacy.h | 2 +- gdb/buildsym.c | 3 ++- gdb/buildsym.h | 4 ++-- gdb/coffread.c | 4 ++-- gdb/dbxread.c | 6 +++--- gdb/dwarf2/read.c | 24 +++++++++++++++++++----- gdb/mdebugread.c | 2 +- gdb/symtab.h | 9 +++++++-- 9 files changed, 39 insertions(+), 19 deletions(-) diff --git a/gdb/buildsym-legacy.c b/gdb/buildsym-legacy.c index 84bc96e843b..f267896a3b6 100644 --- a/gdb/buildsym-legacy.c +++ b/gdb/buildsym-legacy.c @@ -205,12 +205,12 @@ finish_block (struct symbol *symbol, struct pending_block *old_blocks, } void -record_line (struct subfile *subfile, int line, unrelocated_addr pc) +record_line (struct subfile *subfile, int line, uint col, unrelocated_addr pc) { gdb_assert (buildsym_compunit != nullptr); /* Assume every line entry is a statement start, that is a good place to put a breakpoint for that line number. */ - buildsym_compunit->record_line (subfile, line, pc, LEF_IS_STMT); + buildsym_compunit->record_line (subfile, line, col, pc, LEF_IS_STMT); } /* Start a new compunit_symtab for a new source file in OBJFILE. Called, for diff --git a/gdb/buildsym-legacy.h b/gdb/buildsym-legacy.h index 1fb545831b8..45eacb15d30 100644 --- a/gdb/buildsym-legacy.h +++ b/gdb/buildsym-legacy.h @@ -76,7 +76,7 @@ extern struct context_stack *push_context (int desc, CORE_ADDR valu); extern struct context_stack pop_context (); -extern void record_line (struct subfile *subfile, int line, +extern void record_line (struct subfile *subfile, int line, uint col, unrelocated_addr pc); extern struct compunit_symtab *start_compunit_symtab (struct objfile *objfile, diff --git a/gdb/buildsym.c b/gdb/buildsym.c index a963219a0d2..75229d6ccda 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -623,7 +623,7 @@ buildsym_compunit::pop_subfile () line vector for SUBFILE. */ void -buildsym_compunit::record_line (struct subfile *subfile, int line, +buildsym_compunit::record_line (struct subfile *subfile, int line, uint col, unrelocated_addr pc, linetable_entry_flags flags) { m_have_line_numbers = true; @@ -664,6 +664,7 @@ buildsym_compunit::record_line (struct subfile *subfile, int line, subfile->line_vector_entries.emplace_back (); linetable_entry &e = subfile->line_vector_entries.back (); e.line = line; + e.col = col; e.is_stmt = (flags & LEF_IS_STMT) != 0; e.set_unrelocated_pc (pc); e.prologue_end = (flags & LEF_PROLOGUE_END) != 0; diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 79ece794559..a7f9c45b936 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -243,8 +243,8 @@ struct buildsym_compunit const char *pop_subfile (); - void record_line (struct subfile *subfile, int line, unrelocated_addr pc, - linetable_entry_flags flags); + void record_line (struct subfile *subfile, int line, uint col, + unrelocated_addr pc, linetable_entry_flags flags); struct compunit_symtab *get_compunit_symtab () { diff --git a/gdb/coffread.c b/gdb/coffread.c index 30a38035c52..77f9c11146b 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1097,7 +1097,7 @@ coff_symtab_read (minimal_symbol_reader &reader, other statement-line-number. */ if (fcn_last_line == 1) record_line - (get_current_subfile (), fcn_first_line, + (get_current_subfile (), fcn_first_line, 0, unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, fcn_first_line_addr))); else @@ -1430,7 +1430,7 @@ enter_linenos (file_ptr file_offset, int first_line, { CORE_ADDR addr = lptr.l_addr.l_paddr; record_line (get_current_subfile (), - first_line + L_LNNO32 (&lptr), + first_line + L_LNNO32 (&lptr), 0, unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr))); } diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 1734e8062fb..12a3d877ff9 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -2478,7 +2478,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, CORE_ADDR addr = last_function_start + valu; record_line - (get_current_subfile (), 0, + (get_current_subfile (), 0, 0, unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr) - objfile->text_section_offset ())); } @@ -2688,14 +2688,14 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name, last_function_start : valu; record_line - (get_current_subfile (), desc, + (get_current_subfile (), desc, 0, unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, addr) - objfile->text_section_offset ())); sline_found_in_function = 1; } else record_line - (get_current_subfile (), desc, + (get_current_subfile (), desc, 0, unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, valu) - objfile->text_section_offset ())); break; diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a50248c4d56..a4f62e6c59e 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18114,6 +18114,10 @@ class lnp_state_machine advance_line (line_delta); } + void set_column (unsigned int column) noexcept { + m_col = column; + } + /* Handle DW_LNS_set_file. */ void handle_set_file (file_name_index file); @@ -18185,6 +18189,8 @@ class lnp_state_machine file_name_index m_file = 1; unsigned int m_line = 1; + unsigned int m_col = 1; + /* These are initialized in the constructor. */ unrelocated_addr m_address; @@ -18215,6 +18221,8 @@ class lnp_state_machine consecutive entries for the same line. This can happen, for example, when discriminators are present. PR 17276. */ unsigned int m_last_line = 0; + unsigned int m_last_col = 0; + bool m_line_has_non_zero_discriminator = false; }; @@ -18318,6 +18326,7 @@ lnp_state_machine::handle_const_add_pc () static int dwarf_record_line_p (struct dwarf2_cu *cu, unsigned int line, unsigned int last_line, + uint col, uint last_col, int line_has_non_zero_discriminator, struct subfile *last_subfile) { @@ -18325,6 +18334,8 @@ dwarf_record_line_p (struct dwarf2_cu *cu, return 1; if (line != last_line) return 1; + else if(line == last_line && col != last_col) + return 1; /* Same line for the same file that we've seen already. As a last check, for pr 17276, only record the line if the line has never had a non-zero discriminator. */ @@ -18338,7 +18349,7 @@ dwarf_record_line_p (struct dwarf2_cu *cu, static void dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile, - unsigned int line, unrelocated_addr address, + unsigned int line, uint col, unrelocated_addr address, linetable_entry_flags flags, struct dwarf2_cu *cu) { @@ -18355,7 +18366,7 @@ dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile, } if (cu != nullptr) - cu->get_builder ()->record_line (subfile, line, addr, flags); + cu->get_builder ()->record_line (subfile, line, col, addr, flags); } /* Subroutine of dwarf_decode_lines_1 to simplify it. @@ -18378,7 +18389,7 @@ dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile, paddress (gdbarch, (CORE_ADDR) address)); } - dwarf_record_line_1 (gdbarch, subfile, 0, address, LEF_IS_STMT, cu); + dwarf_record_line_1 (gdbarch, subfile, 0, 0, address, LEF_IS_STMT, cu); } void @@ -18444,17 +18455,19 @@ lnp_state_machine::record_line (bool end_sequence) lte_flags |= LEF_IS_STMT; if (dwarf_record_line_p (m_cu, m_line, m_last_line, + m_col, m_last_col, m_line_has_non_zero_discriminator, m_last_subfile)) { buildsym_compunit *builder = m_cu->get_builder (); dwarf_record_line_1 (m_gdbarch, builder->get_current_subfile (), - m_line, m_address, lte_flags, + m_line, m_col, m_address, lte_flags, m_currently_recording_lines ? m_cu : nullptr); } m_last_subfile = m_cu->get_builder ()->get_current_subfile (); m_last_line = m_line; + m_last_col = m_col; } } @@ -18670,7 +18683,8 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu, } break; case DW_LNS_set_column: - (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); + state_machine.set_column ( + read_unsigned_leb128 (abfd, line_ptr, &bytes_read)); line_ptr += bytes_read; break; case DW_LNS_negate_stmt: diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 73df0ed8165..b5cbe4548a7 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -4008,7 +4008,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile) { /* Handle encoded stab line number. */ record_line - (get_current_subfile (), sh.index, + (get_current_subfile (), sh.index, 0, unrelocated_addr (gdbarch_addr_bits_remove (gdbarch, valu))); } diff --git a/gdb/symtab.h b/gdb/symtab.h index eecd999b7e6..38d08fe8599 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1616,14 +1616,19 @@ struct linetable_entry return m_pc < other.m_pc; } - /* Two entries are equal if they have the same line and PC. The + /* Two entries are equal if they have the same line, PC and col. The other members are ignored. */ bool operator== (const linetable_entry &other) const - { return line == other.line && m_pc == other.m_pc; } + { return line == other.line && m_pc == other.m_pc && col == other.col; } /* The line number for this entry. */ int line; + /* The column number for entry. Assume a maximum of circa 500M columns, + a similar assumption is made for line after all. Keeps an identical + size for linetable_entry (16 bytes). */ + unsigned int col : 29; + /* True if this PC is a good location to place a breakpoint for LINE. */ bool is_stmt : 1; -- 2.43.0