From patchwork Thu Jan 17 01:20:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 213117 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 9289A2C007E for ; Thu, 17 Jan 2013 12:20:47 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1358990448; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: From:To:Subject:Date:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=QCNrIpk gWd9RCIVG++nESZuIGOI=; b=oHULq4y8eTzFc/NGWUXpf25H0g+q3iEkpOrTI8a NM44k1G20uTnE3tWvthvMhh3L9nLs2AuGOx4qI3C6FLK7jdt25jEUPzitQalG05H +BzsLmOg1r/OD1HtQEPA+qTsErM6jY/ee6mV7cY3edg/M8Yl8kMPrxWmzBlYY6J5 1HGs= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:X-Received:Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=u773lTRqMHhAUeY4raMnt1QoJxY/jb1X0g4ekefDI0kgdiWdhZA2hUTRoM0ZhN gG9gA8NRihZgy4wuXDJTAw4VwSH4BFUHOIqIsJuhC1kjvlfSnFKE+qpn10EIT8M4 wqm+MqzqkcaSIpI1A8S4XW7TFZQvBQ2sWBc+KJrktWXys=; Received: (qmail 6083 invoked by alias); 17 Jan 2013 01:20:44 -0000 Received: (qmail 6072 invoked by uid 22791); 17 Jan 2013 01:20:43 -0000 X-SWARE-Spam-Status: No, hits=-5.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_CP, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-da0-f54.google.com (HELO mail-da0-f54.google.com) (209.85.210.54) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Jan 2013 01:20:38 +0000 Received: by mail-da0-f54.google.com with SMTP id n2so830392dad.13 for ; Wed, 16 Jan 2013 17:20:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=KPVzuwlc2Quvzs4Fu7FuOYOmtgc084f+zvN8Xef0VAE=; b=HDNzlk0CsZrYSKfFuBxhBc931KZhkMgtjp5pmBt1gPMX7vbZHoGlMryEuAX0AMNYif /ulQqb+lPB3xm6WoVkvEGC5gJcglNlQZKtHqHJi2SUpFkOWlwclQi6bRa0BZJoQg0vrr +6u91/ZxkRmNkaj7NHpTSgXZ5S4gQU9BlOmRIZzMoF1DTP9/okF2GOnQuqEAusALeDYZ QNh8/tyFrMR85uSftFTJXb1qdKkD+3LRVpA0alsCQIpzd355QjOsn808fOLncwjpJOVk v7IxGrgTp8zOIJ0CQ2OGCd7JhQv5owsxNUoN0UDfivH9VVkQjv1KtknlL+EgusFXBGVF v0mg== X-Received: by 10.68.239.232 with SMTP id vv8mr8266877pbc.53.1358385637658; Wed, 16 Jan 2013 17:20:37 -0800 (PST) Received: from iant-glaptop.google.com ([172.26.48.136]) by mx.google.com with ESMTPS id a1sm74933pav.2.2013.01.16.17.20.35 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 16 Jan 2013 17:20:36 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org Subject: libbacktrace patch committed: Handle missing line number entry Date: Wed, 16 Jan 2013 17:20:30 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQnXEx8AkxS3lg7QoerzBmcZS1t5feswSp9sOmq1X9Ttlf81lodq9wQIy0mNmAtVUKjdcTgMgRFBKh2uNoM/bcDa3Ocuhcm3XA1FCx0+xdQ70QLaQUOYkWqRTP6lu2J9QqH0pDbaj/0p0oiIccPurchDv+0XJHjRGRqTETRlORSDpEuDjaOxeH3Ea4VK0urfT+7Wn4uZYfuJdet+7K8C8FhDoLy3yA== 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 It turns out that it is possible to construct debug info in which a compilation unit has a low_pc and a high_pc, and a line number table, but the line number table does not cover PC values from low_pc up to some value. For example, this will happen in an assembler file if you use a .cfi_startproc with no preceding .loc, and then provide some instructions, and then use a .loc later in the function before the .cfi_endproc. In this admittedly obscure case the backtrace library was returning an error "inconsistent DWARF line number info." Since the case can occur in real files, this is inappropriate. This patch fixes libbacktrace to return the main compilation file, if available, with no associated function or line number. I have not added a test case because I don't know how to create one without using assembler code. I did write a test case myself and verified that it fixed the problem on my system. Bootstrapped and ran libbacktrace testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian 2013-01-16 Ian Lance Taylor * dwarf.c (struct unit): Add filename and abs_filename fields. (build_address_map): Set new fields when reading unit. (dwarf_lookup_pc): If we don't find an entry in the line table, just return the main file name. Index: dwarf.c =================================================================== --- dwarf.c (revision 195256) +++ dwarf.c (working copy) @@ -283,8 +283,12 @@ struct unit int addrsize; /* Offset into line number information. */ off_t lineoff; + /* Primary source file. */ + const char *filename; /* Compilation command working directory. */ const char *comp_dir; + /* Absolute file name, only set if needed. */ + const char *abs_filename; /* The abbreviations for this unit. */ struct abbrevs abbrevs; @@ -1288,6 +1292,7 @@ build_address_map (struct backtrace_stat int have_ranges; uint64_t lineoff; int have_lineoff; + const char *filename; const char *comp_dir; if (info.reported_underflow) @@ -1346,6 +1351,7 @@ build_address_map (struct backtrace_stat have_ranges = 0; lineoff = 0; have_lineoff = 0; + filename = NULL; comp_dir = NULL; for (i = 0; i < abbrev->num_attrs; ++i) { @@ -1394,6 +1400,10 @@ build_address_map (struct backtrace_stat have_lineoff = 1; } break; + case DW_AT_name: + if (val.encoding == ATTR_VAL_STRING) + filename = val.u.string; + break; case DW_AT_comp_dir: if (val.encoding == ATTR_VAL_STRING) comp_dir = val.u.string; @@ -1421,7 +1431,9 @@ build_address_map (struct backtrace_stat u->version = version; u->is_dwarf64 = is_dwarf64; u->addrsize = addrsize; + u->filename = filename; u->comp_dir = comp_dir; + u->abs_filename = NULL; u->lineoff = lineoff; u->abbrevs = abbrevs; memset (&abbrevs, 0, sizeof abbrevs); @@ -2701,8 +2713,45 @@ dwarf_lookup_pc (struct backtrace_state sizeof (struct line), line_search); if (ln == NULL) { - error_callback (data, "inconsistent DWARF line number info", 0); - return 0; + /* The PC is between the low_pc and high_pc attributes of the + compilation unit, but no entry in the line table covers it. + This implies that the start of the compilation unit has no + line number information. */ + + if (entry->u->abs_filename == NULL) + { + const char *filename; + + filename = entry->u->filename; + if (filename != NULL + && !IS_ABSOLUTE_PATH (filename) + && entry->u->comp_dir != NULL) + { + size_t filename_len; + const char *dir; + size_t dir_len; + char *s; + + filename_len = strlen (filename); + dir = entry->u->comp_dir; + dir_len = strlen (dir); + s = (char *) backtrace_alloc (state, dir_len + filename_len + 2, + error_callback, data); + if (s == NULL) + { + *found = 0; + return 0; + } + memcpy (s, dir, dir_len); + /* FIXME: Should use backslash if DOS file system. */ + s[dir_len] = '/'; + memcpy (s + dir_len + 1, filename, filename_len + 1); + filename = s; + } + entry->u->abs_filename = filename; + } + + return callback (data, pc, entry->u->abs_filename, 0, NULL); } /* Search for function name within this unit. */