From patchwork Mon Aug 5 20:19:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Terekhov, Mikhail via Gdb-patches" X-Patchwork-Id: 33969 Received: (qmail 80268 invoked by alias); 5 Aug 2019 20:19:09 -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 80255 invoked by uid 89); 5 Aug 2019 20:19:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Spam-Relays-External:sk:mail-yw, HX-HELO:sk:mail-yw, H*RU:sk:mail-yw, H*r:sk:mail-yw X-HELO: mail-yw1-f74.google.com Received: from mail-yw1-f74.google.com (HELO mail-yw1-f74.google.com) (209.85.161.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Aug 2019 20:19:07 +0000 Received: by mail-yw1-f74.google.com with SMTP id h203so62042659ywb.9 for ; Mon, 05 Aug 2019 13:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=OruM7zeMoUBcu+ZrzRpZkdNZU1xfKVpmJo7QRadLN74=; b=RRiRXjGj2ynA/ghsmCXOW1JFXUau3A/A4WTk7Xa5DjN7x8QaUrPfmX1C+27IPxdoLv bOmn0GRdNVFih8iQRDwDc3y3eV+qfAmdKxpSVONFLFG0DmpzdLQCmy3MYWkzVDSXoXie Yqw+tBCBEXIarTyzxfrnaC3zjWELOHPaCwt/Ba6fOjKnyMpWddLRWA9PGL3foBWWGORr ovMixkzzrLM1oDKe1jMNFXkQB+BS6XVrc9SblPsJ7HvmXLi/sT8ZNv4wZzcnESeCUojD H5a4K5M7qSxJlLglwcwQmri5zTnNivduFyBf28yew7bMKaCVkSqGvyUNFIjbEd7Pus08 s+MA== Date: Mon, 5 Aug 2019 15:19:02 -0500 Message-Id: <20190805201902.15900-1-cbiesinger@google.com> Mime-Version: 1.0 Subject: [PATCH] Make info_symbol_command use lookup_minimal_symbol_by_pc X-Patchwork-Original-From: "Christian Biesinger via gdb-patches" From: "Terekhov, Mikhail via Gdb-patches" Reply-To: Christian Biesinger To: gdb-patches@sourceware.org Cc: Christian Biesinger Currently it reimplements that functionality. Tested with the following two tests, which seem to be the only non-Cell tests that use "info symbol": gdb.base/default.exp gdb.asm/asm-source.exp gdb/ChangeLog: 2019-08-05 Christian Biesinger * printcmd.c (info_symbol_command): Use lookup_minimal_symbol_by_pc instead of reimplementing that functionality. --- gdb/printcmd.c | 146 +++++++++++++++++++++++-------------------------- 1 file changed, 67 insertions(+), 79 deletions(-) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 0c368a6f6d..1d7483c62a 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1306,93 +1306,81 @@ set_command (const char *exp, int from_tty) static void info_symbol_command (const char *arg, int from_tty) { - struct minimal_symbol *msymbol; + bound_minimal_symbol msymbol; struct obj_section *osect; CORE_ADDR addr, sect_addr; - int matches = 0; unsigned int offset; if (!arg) error_no_arg (_("address")); addr = parse_and_eval_address (arg); - for (objfile *objfile : current_program_space->objfiles ()) - ALL_OBJFILE_OSECTIONS (objfile, osect) - { - /* Only process each object file once, even if there's a separate - debug file. */ - if (objfile->separate_debug_objfile_backlink) - continue; - - sect_addr = overlay_mapped_address (addr, osect); - - if (obj_section_addr (osect) <= sect_addr - && sect_addr < obj_section_endaddr (osect) - && (msymbol - = lookup_minimal_symbol_by_pc_section (sect_addr, - osect).minsym)) - { - const char *obj_name, *mapped, *sec_name, *msym_name; - const char *loc_string; - - matches = 1; - offset = sect_addr - MSYMBOL_VALUE_ADDRESS (objfile, msymbol); - mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped"); - sec_name = osect->the_bfd_section->name; - msym_name = MSYMBOL_PRINT_NAME (msymbol); - - /* Don't print the offset if it is zero. - We assume there's no need to handle i18n of "sym + offset". */ - std::string string_holder; - if (offset) - { - string_holder = string_printf ("%s + %u", msym_name, offset); - loc_string = string_holder.c_str (); - } - else - loc_string = msym_name; - - gdb_assert (osect->objfile && objfile_name (osect->objfile)); - obj_name = objfile_name (osect->objfile); - - if (MULTI_OBJFILE_P ()) - if (pc_in_unmapped_range (addr, osect)) - if (section_is_overlay (osect)) - printf_filtered (_("%s in load address range of " - "%s overlay section %s of %s\n"), - loc_string, mapped, sec_name, obj_name); - else - printf_filtered (_("%s in load address range of " - "section %s of %s\n"), - loc_string, sec_name, obj_name); - else - if (section_is_overlay (osect)) - printf_filtered (_("%s in %s overlay section %s of %s\n"), - loc_string, mapped, sec_name, obj_name); - else - printf_filtered (_("%s in section %s of %s\n"), - loc_string, sec_name, obj_name); - else - if (pc_in_unmapped_range (addr, osect)) - if (section_is_overlay (osect)) - printf_filtered (_("%s in load address range of %s overlay " - "section %s\n"), - loc_string, mapped, sec_name); - else - printf_filtered - (_("%s in load address range of section %s\n"), - loc_string, sec_name); - else - if (section_is_overlay (osect)) - printf_filtered (_("%s in %s overlay section %s\n"), - loc_string, mapped, sec_name); - else - printf_filtered (_("%s in section %s\n"), - loc_string, sec_name); - } - } - if (matches == 0) - printf_filtered (_("No symbol matches %s.\n"), arg); + msymbol = lookup_minimal_symbol_by_pc (addr); + if (msymbol.minsym == nullptr) + { + printf_filtered (_("No symbol matches %s.\n"), arg); + return; + } + osect = MSYMBOL_OBJ_SECTION (msymbol.objfile, msymbol.minsym); + + sect_addr = overlay_mapped_address (addr, osect); + + const char *obj_name, *mapped, *sec_name, *msym_name; + const char *loc_string; + + offset = sect_addr - MSYMBOL_VALUE_ADDRESS (msymbol.objfile, msymbol.minsym); + mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped"); + sec_name = osect->the_bfd_section->name; + msym_name = MSYMBOL_PRINT_NAME (msymbol.minsym); + + /* Don't print the offset if it is zero. + We assume there's no need to handle i18n of "sym + offset". */ + std::string string_holder; + if (offset) + { + string_holder = string_printf ("%s + %u", msym_name, offset); + loc_string = string_holder.c_str (); + } + else + loc_string = msym_name; + + gdb_assert (osect->objfile && objfile_name (osect->objfile)); + obj_name = objfile_name (osect->objfile); + + if (MULTI_OBJFILE_P ()) + if (pc_in_unmapped_range (addr, osect)) + if (section_is_overlay (osect)) + printf_filtered (_("%s in load address range of " + "%s overlay section %s of %s\n"), + loc_string, mapped, sec_name, obj_name); + else + printf_filtered (_("%s in load address range of " + "section %s of %s\n"), + loc_string, sec_name, obj_name); + else + if (section_is_overlay (osect)) + printf_filtered (_("%s in %s overlay section %s of %s\n"), + loc_string, mapped, sec_name, obj_name); + else + printf_filtered (_("%s in section %s of %s\n"), + loc_string, sec_name, obj_name); + else + if (pc_in_unmapped_range (addr, osect)) + if (section_is_overlay (osect)) + printf_filtered (_("%s in load address range of %s overlay " + "section %s\n"), + loc_string, mapped, sec_name); + else + printf_filtered + (_("%s in load address range of section %s\n"), + loc_string, sec_name); + else + if (section_is_overlay (osect)) + printf_filtered (_("%s in %s overlay section %s\n"), + loc_string, mapped, sec_name); + else + printf_filtered (_("%s in section %s\n"), + loc_string, sec_name); } static void