This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: dwarf2_build_psymtabs should check that .debug_line exists


david carlton <carlton@math.stanford.edu> writes:
> 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.

Yes, this all makes good sense.

Well, dwarf_decode_line_header stashes pointers into the
debug_line_buffer in the struct line_header it returns.  So
dwarf_decode_lines uses dwarf_line_buffer, too.

It looks to me like read_file_scope shouldn't call dwarf_decode_macros
either when line_header is zero.  Could you add that to your patch,
and re-post it?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]