From patchwork Tue Sep 29 21:35:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 8881 Received: (qmail 50070 invoked by alias); 29 Sep 2015 21:35: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 50056 invoked by uid 89); 29 Sep 2015 21:35:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-pd0-f202.google.com Received: from mail-pd0-f202.google.com (HELO mail-pd0-f202.google.com) (209.85.192.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 29 Sep 2015 21:35:06 +0000 Received: by pdbou10 with SMTP id ou10so1585244pdb.0 for ; Tue, 29 Sep 2015 14:35:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:date:subject:from:to :content-type:content-transfer-encoding; bh=Y9GavJmxB4wuTQVOlQb6QDVIdaQBK2DsY1k8Pb558Lo=; b=C/BNsMUVQpWjiysnF8qDLjRPAA4Fp0hU07yLenCP06ofjIE0u87PHSpZ2xk+zXulPQ 2JvWU8LadWwBvcf1ENBh1HRLNMOC4SVqy0PhZ5inTK/RoA8av4Souo/AVgZF7qhQTq5s 1nOtAFdqSGXUo40LgytU88ZZM2m1IfAFW8nmlMVpgeusGmam58YW0Udd144RHebHGVXa 5Qi5ynn1qMS+KaeHCT6XwFrA6Wmf/tQftu/oKjsIW8TDy19wvlNzync38DuzXHKRmiIH faG3qCPDhEF9mvWunvWesmGIYrEILLEFUzVA271QgBufLxranl/jaeLDLjxCNmYAU13U 1yBQ== X-Gm-Message-State: ALoCoQkkSZlE1Sd6HFCb4XEG3HxLLD183x1/Jyt4ErNXbDqu7DID86CtymfegshkxDk8X9h4yE/fZVny638KmMgJmoOGvqUhC9c9H/6+O1gJfgPb1JOMOBMHuWYxD9Ky3BRaKUXnbS/7bkE8ovU92HmuUTsoKTsfozvfgvNW0V6SqKun+Eq7a74= MIME-Version: 1.0 X-Received: by 10.66.160.135 with SMTP id xk7mr226328pab.28.1443562504705; Tue, 29 Sep 2015 14:35:04 -0700 (PDT) Message-ID: <047d7b6d85324e1d010520e99691@google.com> Date: Tue, 29 Sep 2015 21:35:04 +0000 Subject: [PATCH] Print address map in output of "mt print psymbols" From: Doug Evans To: gdb-patches@sourceware.org X-IsSubscribed: yes Hi. While trying to track down a gdb crash due to the addrmap gdb produces for .gdb_index I found this helpful. 2015-09-29 Doug Evans * psymtab.c (struct dump_psymtab_addrmap_data): Define. (dump_psymtab_addrmap_1, dump_psymtab_addrmap): New functions. (maintenance_print_psymbols): Treat filename arg as a regexp. Print address map. maintenance_print_psymbols (char *args, int from_tty) { @@ -1923,12 +1995,30 @@ print-psymbols takes an output file name and optional symbol file name")); perror_with_name (filename); make_cleanup_ui_file_delete (outfile); - ALL_PSYMTABS (objfile, ps) + ALL_OBJFILES (objfile) + { + fprintf_filtered (outfile, "\nPartial symtabs for objfile %s\n", + objfile_name (objfile)); + + ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps) { QUIT; if (symname == NULL || filename_cmp (symname, ps->filename) == 0) - dump_psymtab (objfile, ps, outfile); + { + dump_psymtab (objfile, ps, outfile); + dump_psymtab_addrmap (objfile, ps, outfile); + } } + + /* If we're printing all symbols dump the full addrmap. */ + + if (symname == NULL) + { + fprintf_filtered (outfile, "\n"); + dump_psymtab_addrmap (objfile, NULL, outfile); + } + } + do_cleanups (cleanups); } diff --git a/gdb/psymtab.c b/gdb/psymtab.c index d565c67..96f6ce2 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1884,6 +1884,78 @@ make_cleanup_discard_psymtabs (struct objfile *objfile) +/* We need to pass a couple of items to the addrmap_foreach function, + so use a struct. */ + +struct dump_psymtab_addrmap_data +{ + struct objfile *objfile; + struct partial_symtab *psymtab; + struct ui_file *outfile; + + /* Non-zero if the previously printed addrmap entry was for PSYMTAB. + If so, we want to print the next one as well (since the next addrmap + entry defines the end of the range). */ + int previous_matched; +}; + +/* Helper function for dump_psymtab_addrmap to print an addrmap entry. */ + +static int +dump_psymtab_addrmap_1 (void *datap, CORE_ADDR start_addr, void *obj) +{ + struct dump_psymtab_addrmap_data *data = datap; + struct gdbarch *gdbarch = get_objfile_arch (data->objfile); + struct partial_symtab *addrmap_psymtab = obj; + const char *psymtab_address_or_end = NULL; + + QUIT; + + if (data->psymtab == NULL + || data->psymtab == addrmap_psymtab) + psymtab_address_or_end = host_address_to_string (addrmap_psymtab); + else if (data->previous_matched) + psymtab_address_or_end = ""; + + if (data->psymtab == NULL + || data->psymtab == addrmap_psymtab + || data->previous_matched) + { + fprintf_filtered (data->outfile, " %s%s %s\n", + data->psymtab != NULL ? " " : "", + paddress (gdbarch, start_addr), + psymtab_address_or_end); + } + + data->previous_matched = (data->psymtab == NULL + || data->psymtab == addrmap_psymtab); + + return 0; +} + +/* Helper function for maintenance_print_psymbols to print the addrmap + of PSYMTAB. If PSYMTAB is NULL print the entire addrmap. */ + +static void +dump_psymtab_addrmap (struct objfile *objfile, struct partial_symtab *psymtab, + struct ui_file *outfile) +{ + struct dump_psymtab_addrmap_data addrmap_dump_data; + + if (psymtab == NULL + || psymtab->psymtabs_addrmap_supported) + { + addrmap_dump_data.objfile = objfile; + addrmap_dump_data.psymtab = psymtab; + addrmap_dump_data.outfile = outfile; + addrmap_dump_data.previous_matched = 0; + fprintf_filtered (outfile, "%sAddress map:\n", + psymtab == NULL ? "" : " "); + addrmap_foreach (objfile->psymtabs_addrmap, dump_psymtab_addrmap_1, + &addrmap_dump_data); + } +} + static void