[gdb/testsuite] Don't use default form in Dwarf::_guess_form
authorTom de Vries <tdevries@suse.de>
Fri, 23 Oct 2020 16:49:48 +0000 (18:49 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 23 Oct 2020 16:49:48 +0000 (18:49 +0200)
commit7d72802bfc3fc52fe0f35854694941c9534e0bcb
tree2acdb665d7d85b2b6a168d142548afb7528f0600
parent9476b583cb3e72e57355f5a6bfcd5ba69e71ea31
[gdb/testsuite] Don't use default form in Dwarf::_guess_form

The only possible form for a DW_AT_low_pc attribute is DW_FORM_addr.

When specifying in dwarf assembly a low_pc attribute without explicit form:
...
  {low_pc {main_label - 4}}
...
the resulting attribute uses DW_FORM_string, which is misinterpreted by gdb
when reading it as:
...
        cu->base_address = attr->as_address ();
...

Stop using DW_FORM_string as default form.  Instead, use a default form based
on the attribute name, if possible and unambiguous.  Otherwise, error out.

F.i.:
- for DW_AT_low_pc we use DW_FORM_addr.
- For DW_AT_high_pc, we don't specify a default form because it could be
  either address or constant class.
- For DW_AT_name, we use DW_FORM_string.  While we could encode with
  DW_FORM_strp instead, DW_FORM_string is always ok.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-10-23  Tom de Vries  <tdevries@suse.de>

* lib/dwarf.exp (Dwarf::_guess_form): Return "" by default instead of
DW_FORM_string.
(Dwarf::_default_form): New proc.
(Dwarf::_handle_DW_TAG): Use _default_form.  Error out if no form was
guessed.
gdb/testsuite/ChangeLog
gdb/testsuite/lib/dwarf.exp