From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Eiler, James A." Newsgroups: gmane.os.tru64.managers Subject: SUMMARY: oddity with debugger and sprintf( ) Date: Fri, 10 Sep 2004 16:06:14 -0400 Sender: tru64-unix-managers-owner@ornl.gov Message-ID: <5CE3000C0721A24F9575EA3F4F1B691C06AE1D0E@noaadc-mxu25.noa.alcoa.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: sea.gmane.org 1094846824 17382 80.91.224.253 (10 Sep 2004 20:07:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 10 Sep 2004 20:07:04 +0000 (UTC) Original-X-From: tru64-unix-managers-owner-gotm-tru64-unix-managers=m.gmane.org@sws1.ctd.ornl.gov Fri Sep 10 22:06:54 2004 Return-path: Original-Received: from sws1.ornl.gov ([160.91.1.101]) by deer.gmane.org with smtp (Exim 3.35 #1 (Debian)) id 1C5rfZ-0001eK-00 for ; Fri, 10 Sep 2004 22:06:54 +0200 Original-Received: (qmail 26686 invoked by uid 5); 10 Sep 2004 20:06:44 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 26671 invoked by uid 49501); 10 Sep 2004 20:06:43 -0000 Original-Received: from James.Eiler@alcoa.com by sws1 by uid 49491 with qmail-scanner-1.21 (clamdscan: 0.70-rc. iscan: v3.1/v5.600-1011/847/50540. spamassassin: 2.63. Clear:RC:0(160.91.4.110):SA:0(-4.9/5.0):. Processed in 1.044825 secs); 10 Sep 2004 20:06:43 -0000 Original-Received: from unknown (HELO emroute3.ornl.gov) (160.91.4.110) by 0 with SMTP; 10 Sep 2004 20:06:42 -0000 Original-Received: from emroute3.ornl.gov (localhost [127.0.0.1]) by emroute3.ornl.gov (PMDF V6.2-X27 #30899) with ESMTP id <0I3U004KQD6W9D@emroute3.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Fri, 10 Sep 2004 16:06:41 -0400 (EDT) Original-Received: from VIRUSCAN-DAEMON.emroute3.ornl.gov by emroute3.ornl.gov (PMDF V6.2-X27 #30899) id <0I3U00602D6ORX@emroute3.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Fri, 10 Sep 2004 16:06:25 -0400 (EDT) Original-Received: from NOAADC-MSW03.NOA.Alcoa.com (noaadc-msw03.noa.alcoa.com [147.154.9.220]) by emroute3.ornl.gov (PMDF V6.2-X27 #30899) with ESMTP id <0I3U005HCD6N55@emroute3.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Fri, 10 Sep 2004 16:06:24 -0400 (EDT) Original-Received: from NOAADC-MXI02.NOA.Alcoa.com (unverified [147.154.9.24]) by NOAADC-MSW03.NOA.Alcoa.com (Content Technologies SMTPRS 4.3.14) with ESMTP id for ; Fri, 10 Sep 2004 16:06:20 -0400 Original-Received: by noaadc-mxi02.noa.alcoa.com with Internet Mail Service (5.5.2657.72) id ; Fri, 10 Sep 2004 16:06:20 -0400 Content-return: allowed Original-To: tru64-unix-managers@ornl.gov X-Mailer: Internet Mail Service (5.5.2657.72) Xref: main.gmane.org gmane.os.tru64.managers:7548 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:7548 Original posting at the end... Thanks to James Sainsbury and Bob Harris for their replies. Both suggested line ordering as the root "problem" and James gave a very detailed response: It's probably not obvious but the compiler can and does rearrange code sequences. ie the code generated for source line `n+k' can precede that for line `n' cc -S and dis are useful here. The problem seems to be that you have set a breakpoint at line 12 and branched to line 14 (jumping over line 13 - which in source is empty). The sequence stop at 12 run next doesn't produce an exception. Looking at the .o file - stopping before line 13 and starting after line 13 (ie line 15) would probably explain the observed problem dis jaetest.o main: [jaetest.c: 5] 0x0: 27bb0001 ldah gp, 1(t12) [jaetest.c: 5] 0x4: 23bd80c0 lda gp, -32576(gp) [jaetest.c: 5] 0x8: 23defec0 lda sp, -320(sp) [jaetest.c: 5] 0xc: b75e0018 stq ra, 24(sp) [jaetest.c: 11] 0x10: 221e0028 lda a0, 40(sp) [jaetest.c: 11] 0x14: a63d8028 ldq a1, -32728(gp) [jaetest.c: 11] 0x18: 22310000 lda a1, 0(a1) [jaetest.c: 11] 0x1c: a77d8020 ldq t12, -32736(gp) [jaetest.c: 11] 0x20: 6b5b4000 jsr ra, (t12), strcpy [jaetest.c: 11] 0x24: 27ba0001 ldah gp, 1(ra) [jaetest.c: 11] 0x28: 23bd809c lda gp, -32612(gp) # Break point here [jaetest.c: 13] 0x2c: 47e03400 bis zero, 0x1, v0 [jaetest.c: 13] 0x30: b01e0020 stl v0, 32(sp) [jaetest.c: 16] 0x34: 203e0028 lda t0, 40(sp) [jaetest.c: 16] 0x38: 205e0028 lda t1, 40(sp) [jaetest.c: 16] 0x3c: 207e0028 lda t2, 40(sp) # Branched to here [jaetest.c: 15] 0x40: b43e0000 stq t0, 0(sp) [jaetest.c: 15] 0x44: b45e0008 stq t1, 8(sp) [jaetest.c: 15] 0x48: b47e0010 stq t2, 16(sp) [jaetest.c: 15] 0x4c: 221e0038 lda a0, 56(sp) [jaetest.c: 15] 0x50: a63d8018 ldq a1, -32744(gp) [jaetest.c: 15] 0x54: 22310000 lda a1, 0(a1) [jaetest.c: 15] 0x58: 225e0028 lda a2, 40(sp) [jaetest.c: 15] 0x5c: 227e0028 lda a3, 40(sp) [jaetest.c: 15] 0x60: 229e0028 lda a4, 40(sp) [jaetest.c: 15] 0x64: 22be0028 lda a5, 40(sp) [jaetest.c: 15] 0x68: a77d8010 ldq t12, -32752(gp) [jaetest.c: 15] 0x6c: 2ffe0000 ldq_u zero, 0(sp) [jaetest.c: 15] 0x70: 6b5b4000 jsr ra, (t12), sprintf [jaetest.c: 15] 0x74: 27ba0001 ldah gp, 1(ra) [jaetest.c: 15] 0x78: 23bd804c lda gp, -32692(gp) [jaetest.c: 18] 0x7c: 47ff0400 bis zero, zero, v0 [jaetest.c: 18] 0x80: a75e0018 ldq ra, 24(sp) [jaetest.c: 18] 0x84: 23de0140 lda sp, 320(sp) [jaetest.c: 18] 0x88: 6bfa8001 ret zero, (ra), 1 [jaetest.c: 18] 0x8c: 00000000 call_pal halt RGDS Original Posting: On Thu, 12 Aug 2004, Eiler, James A. wrote: > All, > > I've tried the following on several Alphas with different versions of T64 (4.0G, 5.1A, 5.1B) (and different versions of dbx and ladebug) and got the same result every time. > > My little C program is as follows: > > 1 #include > 2 #include > 3 > 4 main( ) > 5 { > 6 char sName [ 16 ]; > 7 char sString[ 256 ]; > 8 int iStatus; > 9 > 10 strcpy( sName, "bar" ); > 11 > 12 iStatus = 1; > 13 > 14 sprintf( sString, "%s %s %s %s %s %s %s", > 15 sName, sName, sName, sName, sName, sName, sName ); > 16 > 17 } > > > If I compile it and run it with the debugger (dbx or ladebug), set a breakpoint at line 12, then run it to the breakpoint, then goto line 14, then do a next, I get a segmentation violation: > > alpha1-mst> cc jaetest.c -g2 -o jaetest > alpha1-mst> dbx jaetest > dbx version 5.1 > Type 'help' for help. > > main: 10 strcpy( sName, "bar" ); > (dbx) b 12 > [2] stop at "jaetest.c":12 > (dbx) r > [2] stopped at [main:12 ,0x12000118c] iStatus = 1; > (dbx) goto 14 > (dbx) n > signal Segmentation fault at >*[strlen, 0x3ff800d27e0] ldq_u t0, 0(a0) > > However, if I just run it (from the command prompt), it runs just fine. > > And if I run in from the debugger and just "next" through it, it also works just fine. > > Lastly, if I change the sprintf( ) to have less than 5 "%s" conversion strings, it also works just fine! > > I stumbled across this quite by accident while trying to debug one of my programs, and this is the essence of what I was running into. > > Has anyone seen anything like this before? > > Thanks! > > Jim >