Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Wu Zhou <woodzltc@cn.ibm.com>
To: gdb@sources.redhat.com
Subject: Re: Program terminated with SIGSEGV when trying to print an array element
Date: Tue, 07 Jun 2005 09:03:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.63.0506071624520.28024@plinuxt18.cn.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.63.0506071550050.28024@plinuxt18.cn.ibm.com>

On Tue, 7 Jun 2005, Wu Zhou wrote:

> (gdb) p a(1)
> 
> Program terminated with signal SIGSEGV, Segmentation fault.
> The program no longer exists.
> The program being debugged stopped while in a function called from GDB.
> When the function (at 0xbf8b9b50) is done executing, GDB will silently
> stop (instead of continuing to evaluate the expression containing
> the function call).

I am doing some debugging on this.  It seems that GDB take a(1) as a 
function.  But in fact that function doesn't exist at all.

The related code is in function evaluate_subexp_standard (in eval.c).  The
opcode of "a(1)" is OP_F77_UNDETERMINED_ARGLIST at the parse time, and its
real type need to be determined at run time: 

    case OP_F77_UNDETERMINED_ARGLIST:

      /* Remember that in F77, functions, substring ops and 
         array subscript operations cannot be disambiguated 
         at parse time.  We have made all array subscript operations, 
         substring operations as well as function calls  come here 
         and we now have to discover what the heck this thing actually was.  
         If it is a function, we process just as if we got an OP_FUNCALL. */

      nargs = longest_to_int (exp->elts[pc + 1].longconst);
      (*pos) += 2;

      /* First determine the type code we are dealing with.  */
      arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
      type = check_typedef (value_type (arg1));
      code = TYPE_CODE (type);

      switch (code)
	{
	case TYPE_CODE_ARRAY:
	  goto multi_f77_subscript;

	case TYPE_CODE_STRING:
	  goto op_f77_substr;

	case TYPE_CODE_PTR:
	case TYPE_CODE_FUNC:
	  /* It's a function call. */
	  /* Allocate arg vector, including space for the function to be
	     called in argvec[0] and a terminating NULL */
	  argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 2));
	  argvec[0] = arg1;
	  tem = 1;
	  for (; tem <= nargs; tem++)
	    argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);

As far as I can see, the problem lies in that GDB take TYPE_CODE_PTR as
a function call as well.  But in the above failing testcase, "a" is a 
pointer to array type (Fortran treat formal parameter as pointer). Its 
code is TYPE_CODE_PTR indeed, but it is not a function call.  

So maybe we need to change the code logic above.  My thought is when the
code match TYPE_CODE_PTR, we first get its target_type.  If it is 
TYPE_CODE_ARRAY, we can goto multi_f77_subscript. If not, we can go on 
with the orignial path.  But I have one question on the original code: 
in which circumstance should a function's code return TYPE_CODE_PTR,
isn't the code of a function always return TYPE_CODE_FUNC? 

Any thought on this?  Any suggestions and comments are highly appreciated! 

Cheers
- Wu Zhou


  reply	other threads:[~2005-06-07  9:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-07  8:14 Wu Zhou
2005-06-07  9:03 ` Wu Zhou [this message]
2005-06-07 13:14   ` Daniel Jacobowitz
2005-06-08  6:57     ` Wu Zhou
2005-06-08 13:07       ` Daniel Jacobowitz
2005-06-09  2:47         ` Wu Zhou

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=Pine.LNX.4.63.0506071624520.28024@plinuxt18.cn.ibm.com \
    --to=woodzltc@cn.ibm.com \
    --cc=gdb@sources.redhat.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