From patchwork Sun Feb 9 11:48:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 37782 Received: (qmail 10553 invoked by alias); 9 Feb 2020 11:48:55 -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 10466 invoked by uid 89); 9 Feb 2020 11:48:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=brought, pst X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Feb 2020 11:48:38 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B562FAAC7; Sun, 9 Feb 2020 11:48:17 +0000 (UTC) Subject: Re: [PATCH][gdb] Mention CU offset for if verbose To: Simon Marchi , Christian Biesinger Cc: gdb-patches References: <20200207113429.GA6532@delia> <7a8ea599-5254-46be-95b3-fa2af134656d@simark.ca> From: Tom de Vries Message-ID: <99e7c8e5-8662-5b66-9d05-6ec3581b08bd@suse.de> Date: Sun, 9 Feb 2020 12:48:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <7a8ea599-5254-46be-95b3-fa2af134656d@simark.ca> X-IsSubscribed: yes On 08-02-2020 16:48, Simon Marchi wrote: > On 2020-02-08 4:16 a.m., Tom de Vries wrote: >> On 07-02-2020 15:45, Christian Biesinger wrote: >>> On Fri, Feb 7, 2020 at 6:34 AM Tom de Vries wrote: >>> >>> >>>> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c >>>> index dafe01d94a..28ade424fd 100644 >>>> --- a/gdb/dwarf2read.c >>>> +++ b/gdb/dwarf2read.c >>>> @@ -8020,6 +8020,20 @@ create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name) >>>> struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile; >>>> dwarf2_psymtab *pst; >>>> >>>> + const char *artificial = ""; >>> >>> This may not matter but I'd use static const char artificial[] = "..." >>> >> >> Done. >> >>>> + if (strcmp (name, artificial) == 0) >>>> + { >>>> + sect_offset cu_offset = per_cu->sect_off; >>>> + const char *cu_offset_str = sect_offset_str (cu_offset); >>>> + const char *sep = "@"; >>>> + char *new_name = (char *) xmalloc (strlen (artificial) + strlen (sep) >>>> + + strlen (cu_offset_str) + 1); >>>> + strcpy (new_name, artificial); >>>> + strcat (new_name, sep); >>>> + strcat (new_name, cu_offset_str); >>> >>> Use concat() instead of malloc/strcpy/strcat? >>> >> >> Done. >> >> Updated patch re-tested and attached. > > Should the string allocated with concat be freed? Indeed. I've done that now by using gdb::unique_xmalloc_ptr. [ FWIW, there's some code in create_type_unit_group that does something similar, but there we use std::string and string_printf. ] Also, I realized that the code was too deep in the call stack, and I've brought it one level up, to process_psymtab_comp_unit_reader, to make sure it doesn't trigger for f.i. create_type_unit_group. Thanks, - Tom [gdb] Mention CU offset for if verbose Say we're debugging a test-case with CUs with name "", meaning not originating from a single file compilation, and use the verbose setting: ... $ gdb -iex "set verbose on" -batch cc1 Reading symbols from cc1... Reading in symbols for ... \ and /tmp/trunk/gcc/attribs.c... \ ... and /tmp/trunk/gcc/tree-ssa-reassoc.c... \ done. ... From the "/tmp/trunk/gcc/attribs.c" message, it's clear which CU is loaded. But that's not the case for the "" message. The message uses the filename field of struct partial_symtab, which is documented like this: ... /* Name of the source file which this partial_symtab defines, or if the psymtab is anonymous then a descriptive name for debugging purposes, or "". It must not be NULL. */ ... So, fix this by setting the filename field to a more descriptive name than "", by appending the CU offset. This way, we print instead: ... $ gdb -iex "set verbose on" -batch cc1 Reading symbols from cc1... Reading in symbols for @0x41146d9 \ and /tmp/trunk/gcc/attribs.c... \ ... \ and /tmp/trunk/gcc/tree-ssa-reassoc.c... \ done. ... Build and reg-tested on x86_64-linux. gdb/ChangeLog: 2020-02-07 Tom de Vries * dwarf2read.c (process_psymtab_comp_unit_reader): Append CU offset to filename if it matches "". --- gdb/dwarf2read.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index dafe01d94a..bd53dcc711 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -8059,9 +8059,17 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, prepare_one_comp_unit (cu, comp_unit_die, pretend_language); /* Allocate a new partial symbol table structure. */ + gdb::unique_xmalloc_ptr debug_filename; + static const char artificial[] = ""; filename = dwarf2_string_attr (comp_unit_die, DW_AT_name, cu); if (filename == NULL) filename = ""; + else if (strcmp (filename, artificial) == 0) + { + debug_filename.reset (concat (artificial, "@", + sect_offset_str (per_cu->sect_off), NULL)); + filename = debug_filename.get (); + } pst = create_partial_symtab (per_cu, filename);