From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 289B538346A9 for ; Thu, 28 Apr 2022 16:00:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 289B538346A9 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 23SFxuZM031366 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Apr 2022 12:00:00 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 23SFxuZM031366 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 02D491E01D; Thu, 28 Apr 2022 11:59:55 -0400 (EDT) Message-ID: Date: Thu, 28 Apr 2022 11:59:55 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH v3 3/7] gdb/dwarf: pass compilation directory to line header Content-Language: en-US To: Tom Tromey , Simon Marchi via Gdb-patches References: <20220428033542.1636284-1-simon.marchi@polymtl.ca> <20220428033542.1636284-4-simon.marchi@polymtl.ca> <874k2dmcny.fsf@tromey.com> From: Simon Marchi In-Reply-To: <874k2dmcny.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 28 Apr 2022 15:59:56 +0000 X-Spam-Status: No, score=-3032.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Thu, 28 Apr 2022 16:00:03 -0000 On 2022-04-28 11:48, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi via Gdb-patches writes: > > Simon> + /* COMP_DIR is the value of the DW_AT_comp_dir attribute of the compilation > Simon> + unit in the context of which we are reading this line header, or nullptr > Simon> + if not applicable. */ > Simon> + line_header (const char *comp_dir) > Simon> + : m_comp_dir (comp_dir != nullptr ? comp_dir : "") > Simon> + {} > > I think a single-argument constructor should be 'explicit'. Fixed. I should also initialize the bitfield field offset_in_dwz, fixed that too. > > Simon> + /* Compilation directory of the compilation unit in the context of which this > Simon> + line header is read. */ > Simon> + std::string m_comp_dir; > > Is there a need to copy the value here? > I didn't check in this case, but often in the DWARF reader, a string > will come directly from some mapped section, and in that case there > aren't lifetime issues -- and so it's fine to just store the pointer. I thought there might be lifetime issues. read_file_scope owns a file_and_directory object, which contains a possibly computed comp dir. That object's lifetime is read_file_scope, but the line_header created there (by calling handle_DW_AT_stmt_list) lives on, it is stored in dwarf2_cu::line_header. However, I see that we call fnd.intern_comp_dir prior to that, so the returned string should actually be one with objfile lifetime, it should be fine. I'll change it to a const char*, we'll see if it causes any test to fail (I build with ASan, so it should point out any use-after-free). Thanks, Simon