From patchwork Wed Mar 8 15:42:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66137 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66508384B833 for ; Wed, 8 Mar 2023 15:43:20 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy3-pub.mail.unifiedlayer.com (gproxy3-pub.mail.unifiedlayer.com [69.89.30.42]) by sourceware.org (Postfix) with ESMTPS id 4AB81385B51A for ; Wed, 8 Mar 2023 15:42:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AB81385B51A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway5.mail.pro1.eigbox.com (Postfix) with ESMTP id 6C2DA100563BE for ; Wed, 8 Mar 2023 15:42:48 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id ZvwGpegA9WuSqZvwGp8EuS; Wed, 08 Mar 2023 15:42:48 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=Vqrmv86n c=1 sm=1 tr=0 ts=6408acf8 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=k__wU0fu6RkA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=3OExdwvWXfJ5qSYBzYoA:9 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=q/2V9WTpps4QOZi0vT3qIm52XYOe0WYJ5vwm2QbkYGk=; b=lQYdJ/L8abYuGodRMgYnv2N+D7 FudsshNccnlDZHhqD0AHStmCRJAMS4EQ9v+rmNN/avWnNUpyXdkyFBM1/Vo+iTU/OKKXFjG+nVILv RxReOO39FwyOnYyOBlQbLk7NM; Received: from 75-166-130-93.hlrn.qwest.net ([75.166.130.93]:55612 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pZvwG-000Mk5-8k for gdb-patches@sourceware.org; Wed, 08 Mar 2023 08:42:48 -0700 From: Tom Tromey Date: Wed, 08 Mar 2023 08:42:47 -0700 Subject: [PATCH 3/5] Constify linetables MIME-Version: 1.0 Message-Id: <20230308-submit-constify-linetable-v1-3-ca4057478141@tromey.com> References: <20230308-submit-constify-linetable-v1-0-ca4057478141@tromey.com> In-Reply-To: <20230308-submit-constify-linetable-v1-0-ca4057478141@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.130.93 X-Source-L: No X-Exim-ID: 1pZvwG-000Mk5-8k X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-130-93.hlrn.qwest.net ([192.168.0.21]) [75.166.130.93]:55612 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3026.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Linetables no longer change after they are created. This patch applies const to them. Note there is one hack to cast away const in mdebugread.c. This code allocates a linetable using 'malloc', then later copies it to the obstack. While this could be cleaned up, I chose not to do so because I have no way of testing it. --- gdb/buildsym.c | 12 +++++++----- gdb/disasm.c | 2 +- gdb/jit.c | 8 +++++--- gdb/linespec.c | 6 +++--- gdb/mdebugread.c | 5 ++++- gdb/python/py-linetable.c | 11 +++++------ gdb/record-btrace.c | 4 ++-- gdb/symmisc.c | 6 +++--- gdb/symtab.c | 40 ++++++++++++++++++++-------------------- gdb/symtab.h | 8 ++++---- 10 files changed, 54 insertions(+), 48 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 33c51beed57..392b446943c 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -918,13 +918,15 @@ buildsym_compunit::end_compunit_symtab_with_blockvector size_t entry_array_size = n_entries * sizeof (struct linetable_entry); int linetablesize = sizeof (struct linetable) + entry_array_size; - symtab->set_linetable - (XOBNEWVAR (&m_objfile->objfile_obstack, struct linetable, - linetablesize)); + struct linetable *new_table + = XOBNEWVAR (&m_objfile->objfile_obstack, struct linetable, + linetablesize); - symtab->linetable ()->nitems = n_entries; - memcpy (symtab->linetable ()->item, + new_table->nitems = n_entries; + memcpy (new_table->item, subfile->line_vector_entries.data (), entry_array_size); + + symtab->set_linetable (new_table); } else symtab->set_linetable (nullptr); diff --git a/gdb/disasm.c b/gdb/disasm.c index 2acde04ffe9..71d3b97258d 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -573,7 +573,7 @@ do_mixed_source_and_assembly_deprecated { int newlines = 0; int nlines; - struct linetable_entry *le; + const struct linetable_entry *le; struct deprecated_dis_line_entry *mle; struct symtab_and_line sal; int i; diff --git a/gdb/jit.c b/gdb/jit.c index f9f2c92553c..b27df8a6e17 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -543,9 +543,11 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile) size_t size = ((stab->linetable->nitems - 1) * sizeof (struct linetable_entry) + sizeof (struct linetable)); - filetab->set_linetable ((struct linetable *) - obstack_alloc (&objfile->objfile_obstack, size)); - memcpy (filetab->linetable (), stab->linetable.get (), size); + struct linetable *new_table + = (struct linetable *) obstack_alloc (&objfile->objfile_obstack, + size); + memcpy (new_table, stab->linetable.get (), size); + filetab->set_linetable (new_table); } blockvector_size = (sizeof (struct blockvector) diff --git a/gdb/linespec.c b/gdb/linespec.c index 36f2ef46a7c..7d969f37fbf 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -403,7 +403,7 @@ static std::vector decode_digits_ordinary (struct linespec_state *self, linespec *ls, int line, - linetable_entry **best_entry); + const linetable_entry **best_entry); static std::vector decode_digits_list_mode (struct linespec_state *self, @@ -2079,7 +2079,7 @@ create_sals_line_offset (struct linespec_state *self, values = decode_digits_list_mode (self, ls, val); else { - struct linetable_entry *best_entry = NULL; + const linetable_entry *best_entry = NULL; int i, j; std::vector intermediate_results @@ -4026,7 +4026,7 @@ static std::vector decode_digits_ordinary (struct linespec_state *self, linespec *ls, int line, - struct linetable_entry **best_entry) + const linetable_entry **best_entry) { std::vector sals; for (const auto &elt : ls->file_symtabs) diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 85dceb54fe7..d2234f18a1f 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -4094,7 +4094,10 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile) psymtab_language = cust->primary_filetab ()->language (); - lines = cust->primary_filetab ()->linetable (); + /* This code allocates the line table on the heap and then later + copies it to the obstack. So, while casting away const here + is ugly, it's not incorrect. */ + lines = const_cast (cust->primary_filetab ()->linetable ()); /* Get a new lexical context. */ diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c index e42bcc2c792..6e89c43e65f 100644 --- a/gdb/python/py-linetable.c +++ b/gdb/python/py-linetable.c @@ -156,7 +156,7 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args) { struct symtab *symtab; gdb_py_longest py_line; - struct linetable_entry *best_entry = NULL; + const linetable_entry *best_entry = nullptr; std::vector pcs; LTPY_REQUIRE_VALID (self, symtab); @@ -201,7 +201,7 @@ ltpy_has_line (PyObject *self, PyObject *args) for (index = 0; index < symtab->linetable ()->nitems; index++) { - struct linetable_entry *item = &(symtab->linetable ()->item[index]); + const linetable_entry *item = &(symtab->linetable ()->item[index]); if (item->line == py_line) Py_RETURN_TRUE; } @@ -219,7 +219,6 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args) { struct symtab *symtab; Py_ssize_t index; - struct linetable_entry *item; LTPY_REQUIRE_VALID (self, symtab); @@ -236,7 +235,7 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args) for (index = 0; index < symtab->linetable ()->nitems; index++) { - item = &(symtab->linetable ()->item[index]); + const linetable_entry *item = &(symtab->linetable ()->item[index]); /* 0 is used to signify end of line table information. Do not include in the source set. */ @@ -395,7 +394,6 @@ ltpy_iternext (PyObject *self) ltpy_iterator_object *iter_obj = (ltpy_iterator_object *) self; struct symtab *symtab; PyObject *obj; - struct linetable_entry *item; LTPY_REQUIRE_VALID (iter_obj->source, symtab); @@ -405,7 +403,8 @@ ltpy_iternext (PyObject *self) return NULL; } - item = &(symtab->linetable ()->item[iter_obj->current_index]); + const linetable_entry *item + = &(symtab->linetable ()->item[iter_obj->current_index]); /* Skip over internal entries such as 0. 0 signifies the end of line table data and is not useful to the API user. */ diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 55fe25e84ae..5b6e33f78fe 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -705,8 +705,8 @@ static struct btrace_line_range btrace_find_line_range (CORE_ADDR pc) { struct btrace_line_range range; - struct linetable_entry *lines; - struct linetable *ltable; + const linetable_entry *lines; + const linetable *ltable; struct symtab *symtab; int nlines, i; diff --git a/gdb/symmisc.c b/gdb/symmisc.c index d1458784e5c..c24d26554d3 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -237,7 +237,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) struct objfile *objfile = symtab->compunit ()->objfile (); struct gdbarch *gdbarch = objfile->arch (); struct mdict_iterator miter; - struct linetable *l; + const struct linetable *l; struct symbol *sym; int depth; @@ -948,7 +948,7 @@ block_depth (const struct block *block) static int maintenance_print_one_line_table (struct symtab *symtab, void *data) { - struct linetable *linetable; + const struct linetable *linetable; struct objfile *objfile; objfile = symtab->compunit ()->objfile (); @@ -986,7 +986,7 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data) for (int i = 0; i < linetable->nitems; ++i) { - struct linetable_entry *item; + const linetable_entry *item; item = &linetable->item [i]; ui_out_emit_tuple tuple_emitter (uiout, nullptr); diff --git a/gdb/symtab.c b/gdb/symtab.c index df7d3b2a398..df7dc69fc07 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -78,7 +78,7 @@ static void rbreak_command (const char *, int); -static int find_line_common (struct linetable *, int, int *, int); +static int find_line_common (const linetable *, int, int *, int); static struct block_symbol lookup_symbol_aux (const char *name, @@ -2994,15 +2994,15 @@ struct symtab_and_line find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) { struct compunit_symtab *cust; - struct linetable *l; + const linetable *l; int len; - struct linetable_entry *item; + const linetable_entry *item; const struct blockvector *bv; struct bound_minimal_symbol msymbol; /* Info on best line seen so far, and where it starts, and its file. */ - struct linetable_entry *best = NULL; + const linetable_entry *best = NULL; CORE_ADDR best_end = 0; struct symtab *best_symtab = 0; @@ -3011,11 +3011,11 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) If we don't find a line whose range contains PC, we will use a line one less than this, with a range from the start of that file to the first line's pc. */ - struct linetable_entry *alt = NULL; + const linetable_entry *alt = NULL; /* Info on best line seen in this file. */ - struct linetable_entry *prev; + const linetable_entry *prev; /* If this pc is not from the current frame, it is the address of the end of a call instruction. @@ -3171,8 +3171,8 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) return comp_pc < lhs.raw_pc (); }; - struct linetable_entry *first = item; - struct linetable_entry *last = item + len; + const linetable_entry *first = item; + const linetable_entry *last = item + len; item = std::upper_bound (first, last, pc - objfile->text_section_offset (), pc_compare); @@ -3203,7 +3203,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) pretty cheap. */ if (!best->is_stmt) { - struct linetable_entry *tmp = best; + const linetable_entry *tmp = best; while (tmp > first && (tmp - 1)->raw_pc () == tmp->raw_pc () && (tmp - 1)->line != 0 && !tmp->is_stmt) --tmp; @@ -3311,7 +3311,7 @@ find_line_symtab (struct symtab *sym_tab, int line, so far seen. */ int best_index; - struct linetable *best_linetable; + const struct linetable *best_linetable; struct symtab *best_symtab; /* First try looking it up in the given symtab. */ @@ -3346,7 +3346,7 @@ find_line_symtab (struct symtab *sym_tab, int line, { for (symtab *s : cu->filetabs ()) { - struct linetable *l; + const struct linetable *l; int ind; if (FILENAME_CMP (sym_tab->filename, s->filename) != 0) @@ -3395,7 +3395,7 @@ find_line_symtab (struct symtab *sym_tab, int line, std::vector find_pcs_for_symtab_line (struct symtab *symtab, int line, - struct linetable_entry **best_item) + const linetable_entry **best_item) { int start = 0; std::vector result; @@ -3414,7 +3414,7 @@ find_pcs_for_symtab_line (struct symtab *symtab, int line, if (!was_exact) { - struct linetable_entry *item = &symtab->linetable ()->item[idx]; + const linetable_entry *item = &symtab->linetable ()->item[idx]; if (*best_item == NULL || (item->line < (*best_item)->line && item->is_stmt)) @@ -3438,7 +3438,7 @@ find_pcs_for_symtab_line (struct symtab *symtab, int line, bool find_line_pc (struct symtab *symtab, int line, CORE_ADDR *pc) { - struct linetable *l; + const struct linetable *l; int ind; *pc = 0; @@ -3503,7 +3503,7 @@ find_line_pc_range (struct symtab_and_line sal, CORE_ADDR *startptr, Set *EXACT_MATCH nonzero if the value returned is an exact match. */ static int -find_line_common (struct linetable *l, int lineno, +find_line_common (const linetable *l, int lineno, int *exact_match, int start) { int i; @@ -3526,7 +3526,7 @@ find_line_common (struct linetable *l, int lineno, len = l->nitems; for (i = start; i < len; i++) { - struct linetable_entry *item = &(l->item[i]); + const linetable_entry *item = &(l->item[i]); /* Ignore non-statements. */ if (!item->is_stmt) @@ -3640,7 +3640,7 @@ static CORE_ADDR skip_prologue_using_lineinfo (CORE_ADDR func_addr, struct symtab *symtab) { CORE_ADDR func_start, func_end; - struct linetable *l; + const struct linetable *l; int i; /* Give up if this symbol has no lineinfo table. */ @@ -3661,7 +3661,7 @@ skip_prologue_using_lineinfo (CORE_ADDR func_addr, struct symtab *symtab) address we are looking for. */ for (i = 0; i < l->nitems; i++) { - struct linetable_entry *item = &(l->item[i]); + const linetable_entry *item = &(l->item[i]); CORE_ADDR item_pc = item->pc (objfile); /* Don't use line numbers of zero, they mark special entries in @@ -3693,7 +3693,7 @@ skip_prologue_using_linetable (CORE_ADDR func_addr) if (prologue_sal.symtab != nullptr && prologue_sal.symtab->language () != language_asm) { - struct linetable *linetable = prologue_sal.symtab->linetable (); + const linetable *linetable = prologue_sal.symtab->linetable (); struct objfile *objfile = prologue_sal.symtab->compunit ()->objfile (); start_pc -= objfile->text_section_offset (); @@ -3946,7 +3946,7 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr) { struct objfile *objfile = prologue_sal.symtab->compunit ()->objfile (); - struct linetable *linetable = prologue_sal.symtab->linetable (); + const linetable *linetable = prologue_sal.symtab->linetable (); int idx = 0; /* Skip any earlier lines, and any end-of-sequence marker diff --git a/gdb/symtab.h b/gdb/symtab.h index 84d12617f31..654da14e9a8 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1635,12 +1635,12 @@ struct symtab m_compunit = compunit; } - struct linetable *linetable () const + const struct linetable *linetable () const { return m_linetable; } - void set_linetable (struct linetable *linetable) + void set_linetable (const struct linetable *linetable) { m_linetable = linetable; } @@ -1667,7 +1667,7 @@ struct symtab /* Table mapping core addresses to line numbers for this file. Can be NULL if none. Never shared between different symtabs. */ - struct linetable *m_linetable; + const struct linetable *m_linetable; /* Name of this source file, in a form appropriate to print to the user. @@ -2698,7 +2698,7 @@ void iterate_over_symtabs (const char *name, std::vector find_pcs_for_symtab_line - (struct symtab *symtab, int line, struct linetable_entry **best_entry); + (struct symtab *symtab, int line, const linetable_entry **best_entry); /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback is called once per matching symbol SYM. The callback should return