From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26792 invoked by alias); 7 Aug 2002 23:53:26 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 26674 invoked from network); 7 Aug 2002 23:53:24 -0000 Received: from unknown (HELO jackfruit.Stanford.EDU) (171.64.38.136) by sources.redhat.com with SMTP; 7 Aug 2002 23:53:24 -0000 Received: (from carlton@localhost) by jackfruit.Stanford.EDU (8.11.6/8.11.6) id g77NrOx20521; Wed, 7 Aug 2002 16:53:24 -0700 From: david carlton MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15697.45810.578860.108712@jackfruit.Stanford.EDU> Date: Wed, 07 Aug 2002 16:53:00 -0000 To: gdb-patches@sources.redhat.com Subject: dwarf2_build_psymtabs should check that .debug_line exists Cc: carlton@math.stanford.edu X-SW-Source: 2002-08/txt/msg00172.txt.bz2 I was reading through dwarf2read.c when I noticed that dwarf2_build_psymtabs() doesn't check to see if the file that you're debugging has a .debug_line section before initializing dwarf_line_buffer. This is potentially unfortunate: dwarf2_build_psymtabs() is called when dwarf2_has_info() returns 1, but dwarf2_has_info() only checks to see if the file that you're debugging has .debug_info and .debug_abbrev sections. It is, of course, quite rare for a file to have .debug_info and .debug_abbrev sections but not to have a .debug_line section; so, obviously this isn't a serious problem. And, even if you produce such a file (using objcopy -R .debug_line, say), it's still pretty hard to cause GDB to signal an error, but with some effort I did manage to do so. (I can submit a PR with details, if anybody wants.) Given that dwarf2_build_psymtabs() is careful to make sure all the other .debug_XXX sections exist, it should certainly also check to make sure that .debug_line exists. By the way, I checked to see where the contents of the .debug_line section are used; as far as I can tell, it's only used in dwarf2read.c(dwarf_decode_line_header), and that function does have a check in it to make sure that dwarf_line_buffer is non-NULL. So this fix is probably better than the other obvious fix, namely to have dwarf2_has_info() ensure that the file has a .debug_line section. Here's a patch; no new regressions. 2002-08-07 David Carlton * dwarf2read.c (dwarf2_build_psymtabs): Check that dwarf_line_offset is nonzero before creating dwarf_line_buffer. Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.64 diff -u -p -r1.64 dwarf2read.c --- dwarf2read.c 31 Jul 2002 22:35:30 -0000 1.64 +++ dwarf2read.c 7 Aug 2002 22:55:49 -0000 @@ -1009,9 +1009,13 @@ dwarf2_build_psymtabs (struct objfile *o dwarf_abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_offset, dwarf_abbrev_size); - dwarf_line_buffer = dwarf2_read_section (objfile, - dwarf_line_offset, - dwarf_line_size); + + if (dwarf_line_offset) + dwarf_line_buffer = dwarf2_read_section (objfile, + dwarf_line_offset, + dwarf_line_size); + else + dwarf_line_buffer = NULL; if (dwarf_str_offset) dwarf_str_buffer = dwarf2_read_section (objfile, David Carlton carlton@math.stanford.edu