public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Doug Evans <xdje42@gmail.com>
To: "Maciej W. Rozycki" <macro@codesourcery.com>
Cc: Joel Brobecker <brobecker@adacore.com>,
	 <gdb-patches@sourceware.org>,  Rich Fuhler <rich@mips.com>,
	 Richard Sandiford <rdsandiford@googlemail.com>
Subject: Re: [PATCH v2 1/2] ISA bit treatment on the MIPS platform
Date: Mon, 17 Nov 2014 01:17:00 -0000	[thread overview]
Message-ID: <m3zjbqy6bm.fsf@sspiff.org> (raw)
In-Reply-To: <alpine.DEB.1.10.1409292313170.4971@tp.orcam.me.uk> (Maciej	W. Rozycki's message of "Mon, 6 Oct 2014 01:41:50 +0100")

"Maciej W. Rozycki" <macro@codesourcery.com> writes:
> [...]
> 2014-10-06  Maciej W. Rozycki  <macro@codesourcery.com>
>             Maciej W. Rozycki  <macro@mips.com>
>             Pedro Alves  <pedro@codesourcery.com>
>
> 	* gdbarch.sh (elf_make_msymbol_special): Change type to `F',
> 	remove `predefault' and `invalid_p' initializers.
> 	(make_symbol_special): New architecture method.
> 	(adjust_dwarf2_addr, adjust_dwarf2_line): Likewise.
> 	(objfile, symbol): New declarations.
> 	* arch-utils.h (default_elf_make_msymbol_special): Remove
> 	prototype.
> 	(default_make_symbol_special): New prototype.
> 	(default_adjust_dwarf2_addr): Likewise.
> 	(default_adjust_dwarf2_line): Likewise.
> 	* mips-tdep.h (mips_unmake_compact_addr): New prototype.
> 	* arch-utils.c (default_elf_make_msymbol_special): Remove
> 	function.
> 	(default_make_symbol_special): New function.
> 	(default_adjust_dwarf2_addr): Likewise.
> 	(default_adjust_dwarf2_line): Likewise.
> 	* dwarf2-frame.c (decode_frame_entry_1): Call
> 	`gdbarch_adjust_dwarf2_addr'.
> 	* dwarf2loc.c (dwarf2_find_location_expression): Likewise.
> 	* dwarf2read.c (create_addrmap_from_index): Likewise.
> 	(process_psymtab_comp_unit_reader): Likewise.
> 	(add_partial_symbol): Likewise.
> 	(add_partial_subprogram): Likewise.
> 	(process_full_comp_unit): Likewise.
> 	(read_file_scope): Likewise.
> 	(read_func_scope): Likewise.  Call `gdbarch_make_symbol_special'.
> 	(read_lexical_block_scope): Call `gdbarch_adjust_dwarf2_addr'.
> 	(read_call_site_scope): Likewise.
> 	(dwarf2_ranges_read): Likewise.
> 	(dwarf2_record_block_ranges): Likewise.
> 	(read_attribute_value): Likewise.
> 	(dwarf_decode_lines_1): Call `gdbarch_adjust_dwarf2_line'.
> 	(new_symbol_full): Call `gdbarch_adjust_dwarf2_addr'.
> 	* elfread.c (elf_symtab_read): Don't call
> 	`gdbarch_elf_make_msymbol_special' if unset.
> 	* mips-linux-tdep.c (micromips_linux_sigframe_validate): Strip
> 	the ISA bit from the PC.
> 	* mips-tdep.c (mips_unmake_compact_addr): New function.
> 	(mips_elf_make_msymbol_special): Set the ISA bit in the symbol's
> 	address appropriately.
> 	(mips_make_symbol_special): New function.
> 	(mips_pc_is_mips): Set the ISA bit before symbol lookup.
> 	(mips_pc_is_mips16): Likewise.
> 	(mips_pc_is_micromips): Likewise.
> 	(mips_pc_isa): Likewise.
> 	(mips_adjust_dwarf2_addr): New function.
> 	(mips_adjust_dwarf2_line): Likewise.
> 	(mips_read_pc, mips_unwind_pc): Keep the ISA bit.
> 	(mips_addr_bits_remove): Likewise.
> 	(mips_skip_trampoline_code): Likewise.
> 	(mips_write_pc): Don't set the ISA bit.
> 	(mips_eabi_push_dummy_call): Likewise.
> 	(mips_o64_push_dummy_call): Likewise.
> 	(mips_gdbarch_init): Install `mips_make_symbol_special',
> 	`mips_adjust_dwarf2_addr' and `mips_adjust_dwarf2_line' gdbarch
> 	handlers.
> 	* solib.c (gdb_bfd_lookup_symbol_from_symtab): Get
> 	target-specific symbol address adjustments.
> 	* gdbarch.h: Regenerate.
> 	* gdbarch.c: Regenerate.
>
> 2014-10-06  Maciej W. Rozycki  <macro@codesourcery.com>
>
> 	gdb/testsuite/
> 	* gdb.base/func-ptrs.c: New file.
> 	* gdb.base/func-ptrs.exp: New file.

Ummm, bleah.

Going forward dwarf2*.c are going to be measurably more of a pain
to maintain than they already are.
I notice a fair bit of mips code gets a lot simpler.
Such is life I guess.

Just a few comments.

>[...]
> Index: gdb-fsf-trunk-quilt/gdb/gdbarch.sh
> ===================================================================
> --- gdb-fsf-trunk-quilt.orig/gdb/gdbarch.sh	2014-10-03 13:52:46.000000000 +0100
> +++ gdb-fsf-trunk-quilt/gdb/gdbarch.sh	2014-10-03 14:50:26.000000000 +0100
> @@ -635,8 +635,11 @@ m:int:in_solib_return_trampoline:CORE_AD
>  # which don't suffer from that problem could just let this functionality
>  # untouched.
>  m:int:in_function_epilogue_p:CORE_ADDR addr:addr:0:generic_in_function_epilogue_p::0
> -f:void:elf_make_msymbol_special:asymbol *sym, struct minimal_symbol *msym:sym, msym::default_elf_make_msymbol_special::0
> +F:void:elf_make_msymbol_special:asymbol *sym, struct minimal_symbol *msym:sym, msym
>  f:void:coff_make_msymbol_special:int val, struct minimal_symbol *msym:val, msym::default_coff_make_msymbol_special::0
> +f:void:make_symbol_special:struct symbol *sym, struct objfile *objfile:sym, objfile::default_make_symbol_special::0
> +f:CORE_ADDR:adjust_dwarf2_addr:CORE_ADDR pc:pc::default_adjust_dwarf2_addr::0
> +f:CORE_ADDR:adjust_dwarf2_line:CORE_ADDR addr, int rel:addr, rel::default_adjust_dwarf2_line::0

I don't know where the best place to put this is, but the adjust_dwarf2
functions need a lot more documentation.  Why do they exist?
What problem do they solve?  Something along those lines.
References to existing documentation is fine, as long as they're sufficient.

I realize I can find that out with some manual labor, e.g., finding
which arches provide an implementation of these functions, and reading them,
but even when I get to mips-tdep.c I'm left wondering *why*
the mips port needs this (e.g., why can't the problem be solved
differently?).  I'm more familiar with arm/thumb, and of course
the first thing that comes to mind is that arm/thumb doesn't need this
(maybe it does, but we've gotten this far without it).  It would help
to educate the reader of this code as to why mips is different.
Maybe this patch is the best solution.  If so, and I'm going to assume that
it is, then let's get this documented in the code.
Even just a reference to existing docs is fine.
mips-tdep.c is a big file though - I don't want to have to read all
of it just to understand why adjust_dwarf2_line exists.

>  v:int:cannot_step_breakpoint:::0:0::0
>  v:int:have_nonsteppable_watchpoint:::0:0::0
>  F:int:address_class_type_flags:int byte_size, int dwarf2_addr_class:byte_size, dwarf2_addr_class
> @@ -1140,6 +1143,8 @@ struct target_ops;
>  struct obstack;
>  struct bp_target_info;
>  struct target_desc;
> +struct objfile;
> +struct symbol;
>  struct displaced_step_closure;
>  struct core_regset_section;
>  struct syscall;
>[...]
> Index: gdb-fsf-trunk-quilt/gdb/mips-tdep.c
> ===================================================================
> --- gdb-fsf-trunk-quilt.orig/gdb/mips-tdep.c	2014-10-03 13:52:46.000000000 +0100
> +++ gdb-fsf-trunk-quilt/gdb/mips-tdep.c	2014-10-06 00:11:55.028611249 +0100
>[...]
> @@ -391,6 +406,29 @@ msymbol_is_micromips (struct minimal_sym
>    return MSYMBOL_TARGET_FLAG_2 (msym);
>  }
>  
> +/* Set the ISA bit in the main symbol too, complementing the corresponding
> +   minimal symbol setting and reflecting the run-time value of the symbol.  */
> +
> +static void
> +mips_make_symbol_special (struct symbol *sym, struct objfile *objfile)
> +{
> +  if (SYMBOL_CLASS (sym) == LOC_BLOCK)
> +    {
> +      CORE_ADDR compact_block_start;
> +      struct bound_minimal_symbol msym;
> +
> +      compact_block_start = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) | 1;
> +      msym = lookup_minimal_symbol_by_pc (compact_block_start);
> +      if (msym.minsym && !msymbol_is_mips (msym.minsym))
> +	{
> +	  /* We are in symbol reading so it is OK to cast away constness.  */
> +	  struct block *block = (struct block *) SYMBOL_BLOCK_VALUE (sym);
> +
> +	  BLOCK_START (block) = compact_block_start;
> +	}
> +    }
> +}

This function would be easier to read if the assignment to block
was moved up and its value used in both invocations of BLOCK_START.

>[...]
> +/* Recalculate the line record requested so that the resulting PC has the
> +   ISA bit set correctly, used by DWARF-2 machinery.  */
> +
> +static CORE_ADDR
> +mips_adjust_dwarf2_line (CORE_ADDR addr, int rel)
> +{
> +  static CORE_ADDR adj_pc;
> +  static CORE_ADDR pc;
> +  CORE_ADDR isa_pc;
> +
> +  pc = rel ? pc + addr : addr;
> +  isa_pc = mips_adjust_dwarf2_addr (pc);
> +  addr = rel ? isa_pc - adj_pc : isa_pc;
> +  adj_pc = isa_pc;
> +  return addr;
> +}

If this function was a "method", we could remove the "static" vars,
but this is ok I guess.
There's magic going on here, carrying the value of pc,adj_pc
from one call to the next.  There's a rule here that this will
be called with rel == 0, before any calls with rel != 0.
It's kinda obvious now, but it would have helped this reader to see
it written down.

Ok with those changes.

  parent reply	other threads:[~2014-11-17  1:17 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-14 15:37 [RFD+PATCH] " Maciej W. Rozycki
2012-05-18 22:01 ` Maciej W. Rozycki
2012-06-11 18:21 ` Joel Brobecker
2012-06-12 14:05   ` Pedro Alves
2014-10-06  0:42   ` [PATCH v2 1/2] " Maciej W. Rozycki
2014-10-06  0:42     ` [PATCH v2 2/2] Correct invalid assumptions made by (mostly) DWARF-2 tests Maciej W. Rozycki
2014-11-16 11:09       ` Joel Brobecker
2014-11-16 18:32         ` Doug Evans
2014-11-16 19:49           ` Doug Evans
2014-11-16 20:05             ` Maciej W. Rozycki
2014-11-16 21:52               ` Doug Evans
2014-12-04  0:24                 ` Maciej W. Rozycki
2014-11-16 22:28       ` Doug Evans
2014-10-06 14:10     ` [PATCH v2 1/2] ISA bit treatment on the MIPS platform Joel Brobecker
2014-10-14 20:45       ` Maciej W. Rozycki
2014-10-20 17:10         ` [PING][PATCH " Maciej W. Rozycki
2014-11-03 16:13           ` [PING^2][PATCH " Maciej W. Rozycki
2014-11-16 19:23       ` [PATCH " Doug Evans
2014-10-06 15:43     ` Maciej W. Rozycki
2014-11-16 10:37     ` Joel Brobecker
2014-11-16 19:27       ` Doug Evans
2014-12-04 23:14       ` Maciej W. Rozycki
2014-12-12 14:00         ` Maciej W. Rozycki
2014-12-12 17:22           ` Doug Evans
2014-11-17  1:17     ` Doug Evans [this message]
2014-12-04 15:31       ` Maciej W. Rozycki
2014-12-12 16:38     ` [committed] MIPS: Define aliases for MSYMBOL_TARGET_FLAG macros Maciej W. Rozycki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3zjbqy6bm.fsf@sspiff.org \
    --to=xdje42@gmail.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=macro@codesourcery.com \
    --cc=rdsandiford@googlemail.com \
    --cc=rich@mips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).