A debugging problem (long)

Gautam Makani makani at marque.mu.edu
Wed Feb 22 14:44:00 AEST 1989


I was'nt too sure whether this was a UNIX or a C problem hence the
cross-posting.
I have a piece of code to read in line entries from an object file
and filter out some information. I get an EMT (core dump) and cannot
figure out why.

The problem happens when I access a particular part of a struct, *but*
 i) I can print out the constituent data in that area. 
 ii) Using "sdb" (UNIX debugger), I can access (look at) the variable.
 iii) Further, what puzzles me is that this happens the *second* time through a 
      loop.I know that seems stupid ...

 I would appreciate it if someone tells me what's going on. 
 The struct I'm looking at is
struct lineno
{
	union
	{
		long	l_symndx ;
		long	l_paddr ;
	}		l_addr ;
	unsigned short	l_lnno ;	
} ;
#define LINENO struct lineno

The problem comes when I access l_symndx as
       tmplptr->l_addr.l_symndx in any form (in an assignment, printf etc)
Further on this machine,(3b15) sizeof(int) = sizeof(long) (if that helps)

Code segement follows:
----------------------
    for (i = 0, lindex = 0; i <= nlentries ;i++ )
    {
       tmplptr = (LINENO *)lineptr;
       tmp = (char * ) tmplptr;
       printf("tmplptr.l_lnno = %lx\n", (long )tmplptr[0].l_lnno);
       for (ret = 0; ret < 6; ret ++)
       {
         printf("%x ", (char )*tmp);
         tmp++;
       }
       printf("\n");
       printf("symndx = %lx\n",tmplptr->l_addr.l_symndx );
       lineptr = (char *)((long) lineptr + LINESZ);
     }
Program run follows: 
--------------------
c$ tline tline
tmplptr.l_lnno = 0
0 0 0 b7 0 0
symndx = b7
tmplptr.l_lnno = 1
80 80 1	1d 0 1
EMT trap - core	dumped

Sdb session follows:
---------------------
c$ sdb tline
0x8080030b in line:88:	      printf("symndx = %lx\n",tmplptr->l_addr.l_symndx );
*b
line:88	b
*R tline
tmplptr.l_lnno = 0
0 0 0 b7 0 0
Breakpoint at
line:88:	printf("symndx = %lx\n",tmplptr->l_addr.l_symndx );
*c
symndx = b7
tmplptr.l_lnno = 1
80 80 1	1d 0 1
Breakpoint at
line:88:	printf("symndx = %lx\n",tmplptr->l_addr.l_symndx );
*tmplptr->l_addr.l_symndx/lx
0x8080011d
*s
EMT (7)	(sig 7)
0x8080030b in line:88:	      printf("symndx = %lx\n",tmplptr->l_addr.l_symndx );
*q
-------------
I realize this is utilizing precious bandwidth. Please reply by e-mail
and thanks in advance.

----------------------------------------------------------------------
Makani Gautam
Department of MSCS           email : makani at marque.mu.edu 
Marquette University               { uwvax!uwmcsd1 | uunet }!marque!makani
----------------------------------------------------------------------



More information about the Comp.lang.c mailing list