From patchwork Tue Nov 22 15:27:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 127110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BE4921007D1 for ; Wed, 23 Nov 2011 02:28:16 +1100 (EST) Received: (qmail 3803 invoked by alias); 22 Nov 2011 15:28:08 -0000 Received: (qmail 3784 invoked by uid 22791); 22 Nov 2011 15:28:06 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-gx0-f201.google.com (HELO mail-gx0-f201.google.com) (209.85.161.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Nov 2011 15:27:41 +0000 Received: by ggnq2 with SMTP id q2so65830ggn.2 for ; Tue, 22 Nov 2011 07:27:40 -0800 (PST) Received: by 10.236.184.2 with SMTP id r2mr33255375yhm.0.1321975660963; Tue, 22 Nov 2011 07:27:40 -0800 (PST) Received: by 10.236.184.2 with SMTP id r2mr33255345yhm.0.1321975660855; Tue, 22 Nov 2011 07:27:40 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id d63si4776723yhe.2.2011.11.22.07.27.40 (version=TLSv1/SSLv3 cipher=AES128-SHA); Tue, 22 Nov 2011 07:27:40 -0800 (PST) Received: from wpaz9.hot.corp.google.com (wpaz9.hot.corp.google.com [172.24.198.73]) by wpzn4.hot.corp.google.com (Postfix) with ESMTPS id 5E1331E004D; Tue, 22 Nov 2011 07:27:40 -0800 (PST) Received: from topo.tor.corp.google.com (topo.tor.corp.google.com [172.29.41.2]) by wpaz9.hot.corp.google.com with ESMTP id pAMFRccG004405; Tue, 22 Nov 2011 07:27:39 -0800 Received: by topo.tor.corp.google.com (Postfix, from userid 54752) id 8504B1DA1C6; Tue, 22 Nov 2011 10:27:38 -0500 (EST) Date: Tue, 22 Nov 2011 10:27:38 -0500 From: Diego Novillo To: Jason Merrill , gcc-patches@gcc.gnu.org Cc: Dodji Seketeli Subject: Add line table and line map debugging routines Message-ID: <20111122152736.GA3798@google.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org I found these useful while debugging the trunk->pph merge that brought in the new macro location tracking features. OK for trunk? We are in stage 3, but these are debugging routines so I figured it should be safe. Tested on x86_64. Diego. * include/line-map.h (linemap_dump): Declare. (line_table_dump): Declare. * line-map.c (linemap_dump): New. (line_table_dump): New. diff --git a/svnclient/libcpp/include/line-map.h b/svnclient/libcpp/include/line-map.h index cfa6566..1facf03 100644 --- a/svnclient/libcpp/include/line-map.h +++ b/svnclient/libcpp/include/line-map.h @@ -710,4 +710,14 @@ void linemap_get_statistics (struct line_maps *, struct linemap_stats *); stream STREAM. SET is the line map set LOC comes from. */ void linemap_dump_location (struct line_maps *, source_location, FILE *); +/* Dump line map at index IX in line table SET to STREAM. If STREAM + is NULL, use stderr. IS_MACRO is true if the caller wants to + dump a macro map, false otherwise. */ +void linemap_dump (FILE *, struct line_maps *, unsigned, bool); + +/* Dump line table SET to STREAM. If STREAM is NULL, stderr is used. + NUM_ORDINARY specifies how many ordinary maps to dump. NUM_MACRO + specifies how many macro maps to dump. */ +void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int); + #endif /* !LIBCPP_LINE_MAP_H */ diff --git a/svnclient/libcpp/line-map.c b/svnclient/libcpp/line-map.c index 0c59106..fd35204 100644 --- a/svnclient/libcpp/line-map.c +++ b/svnclient/libcpp/line-map.c @@ -1152,6 +1152,57 @@ linemap_expand_location (struct line_maps *set, return xloc; } + +/* Dump line map at index IX in line table SET to STREAM. If STREAM + is NULL, use stderr. IS_MACRO is true if the caller wants to + dump a macro map, false otherwise. */ + +void +linemap_dump (FILE *stream, struct line_maps *set, unsigned ix, bool is_macro) +{ + const char *lc_reasons_v[LC_ENTER_MACRO + 1] + = { "LC_ENTER", "LC_LEAVE", "LC_RENAME", "LC_RENAME_VERBATIM", + "LC_ENTER_MACRO" }; + const char *reason; + struct line_map *map; + + if (stream == NULL) + stream = stderr; + + if (!is_macro) + map = LINEMAPS_ORDINARY_MAP_AT (set, ix); + else + map = LINEMAPS_MACRO_MAP_AT (set, ix); + + reason = (map->reason <= LC_ENTER_MACRO) ? lc_reasons_v[map->reason] : "???"; + + fprintf (stream, "Map #%u [%p] - LOC: %u - REASON: %s - SYSP: %s\n", + ix, (void *) map, map->start_location, reason, + (!is_macro && ORDINARY_MAP_IN_SYSTEM_HEADER_P (map)) ? "yes" : "no"); + if (!is_macro) + { + unsigned includer_ix; + struct line_map *includer_map; + + includer_ix = ORDINARY_MAP_INCLUDER_FILE_INDEX (map); + includer_map = includer_ix < LINEMAPS_ORDINARY_USED (set) + ? LINEMAPS_ORDINARY_MAP_AT (set, includer_ix) + : NULL; + + fprintf (stream, "File: %s:%d\n", ORDINARY_MAP_FILE_NAME (map), + ORDINARY_MAP_STARTING_LINE_NUMBER (map)); + fprintf (stream, "Included from: [%d] %s\n", includer_ix, + includer_map ? ORDINARY_MAP_FILE_NAME (includer_map) : "None"); + } + else + fprintf (stream, "Macro: %s (%u tokens)\n", + linemap_map_get_macro_name (map), + MACRO_MAP_NUM_MACRO_TOKENS (map)); + + fprintf (stream, "\n"); +} + + /* Dump debugging information about source location LOC into the file stream STREAM. SET is the line map set LOC comes from. */ @@ -1253,3 +1304,42 @@ linemap_get_statistics (struct line_maps *set, s->duplicated_macro_maps_locations_size = duplicated_macro_maps_locations_size; } + + +/* Dump line table SET to STREAM. If STREAM is NULL, stderr is used. + NUM_ORDINARY specifies how many ordinary maps to dump. NUM_MACRO + specifies how many macro maps to dump. */ + +void +line_table_dump (FILE *stream, struct line_maps *set, unsigned int num_ordinary, + unsigned int num_macro) +{ + unsigned int i; + + if (set == NULL) + return; + + if (stream == NULL) + stream = stderr; + + fprintf (stream, "# of ordinary maps: %d\n", LINEMAPS_ORDINARY_USED (set)); + fprintf (stream, "# of macro maps: %d\n", LINEMAPS_MACRO_USED (set)); + fprintf (stream, "Include stack depth: %d\n", set->depth); + fprintf (stream, "Highest location: %u\n", set->highest_location); + + if (num_ordinary) + { + fprintf (stream, "\nOrdinary line maps\n"); + for (i = 0; i < num_ordinary && i < LINEMAPS_ORDINARY_USED (set); i++) + linemap_dump (stream, set, i, false); + fprintf (stream, "\n"); + } + + if (num_macro) + { + fprintf (stream, "\nMacro line maps\n"); + for (i = 0; i < num_macro && i < LINEMAPS_MACRO_USED (set); i++) + linemap_dump (stream, set, i, true); + fprintf (stream, "\n"); + } +}