Re: [osol-discuss] C programming, invalid argc value

2010-10-06 Thread George Vasick

On 10/5/2010 11:04 AM, Jürgen Keil wrote:

I can reproduce the problem on my system running bash so I don't think
it is related the the shell:

(gdb) b main
Breakpoint 1 at 0x8050ccc: file g.c, line 4.
(gdb) r
Starting program: /home/gvasick/a.out

Breakpoint 1, main (argc=260904, argv=0xfef90018) at g.c:4


Which compiler, compiler version, gdb version did you use?


gcc 4.3.3, gdb 6.8 running on build 116


What compilation flags?


-g


What does the test program look like?


#include stdio.h

int main (int argc, char *argv[])
{
printf (hello world!\n);
printf (Welcome to C!\n);
printf (%i, %s\n, argc, argv [0]);
return 0;
}



Using Opensolaris b134, gcc 3.4.3, gdb 6.8, a simple
hello, world type test program, and compilation options
-g -O it works for me.

For me, the b main command sets a breakpoint
at offset 12 relative to the symbol main, after
main's function prologue.


I retested with gcc 3.4.3 and everything works fine.  Using the 4.3.3 
compiler, the breakpoint is being set right at the address of main 
before the prologue code is executed.  I will need to investigate why 
that is happening.



Thanks,
George
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-06 Thread Jürgen Keil
 I retested with gcc 3.4.3 and everything works fine.
 Using the 4.3.3 compiler, the breakpoint is being set right at the address of 
 main 
 before the prologue code is executed.  I will need to investigate why 
 that is happening.

Hmm...

On opensolaris b134, after pkg install gcc-43, and
compiling the test programm with the new installed
gcc 4.3.3 compiler (with -g or with -g -O) it still
works for me.

Which assembler is used by your gcc 4.3.3?
gcc 4.3.3 on opensolaris b134 uses /usr/bin/gas,
and that is gnu assembler version 2.19.
-- 
This message posted from opensolaris.org
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-05 Thread Brian Ruthven - Solaris Network Sustaining - Oracle UK



Scott Rotondo wrote:

On 10/ 4/10 10:45 AM, George Vasick wrote:

Hi Alan,

I can reproduce the problem on my system running bash so I don't think
it is related the the shell:

(gdb) b main
Breakpoint 1 at 0x8050ccc: file g.c, line 4.
(gdb) r
Starting program: /home/gvasick/a.out

Breakpoint 1, main (argc=260904, argv=0xfef90018) at g.c:4
4 {

I also notice that stepping one statement seems to resolve the problem:

(gdb) n
main (argc=1, argv=0x8047a88) at g.c:5
5 printf (hello world!\n);
(gdb) p argc
$1 = 1
(gdb) p *argv
$2 = 0x8047b60 /home/gvasick/a.out


Isn't that a well-known issue with x86 debuggers - needing to break at 
function+3 so that the frame pointer is set up before you try to 
examine arguments or local variables?




That sounds right. I believe the same is true on SPARC, where a 
breakpoint is better set at function+4 to allow for the save %sp + 
register window switch before examining any of the %i registers.


It looks like you may need function+4 for 64-bit executables on x86.
Prior to the setup of the frame/stack pointer at the top of main(), you 
are actually getting the args for _start() from the crt for the process 
(I think) although somebody may correct me on this :-)


Regards,
Brian


--
Brian Ruthven
Solaris Network RPE (Sustaining)
Oracle UK

___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-05 Thread Jürgen Keil
 I can reproduce the problem on my system running bash so I don't think 
 it is related the the shell:
 
 (gdb) b main
 Breakpoint 1 at 0x8050ccc: file g.c, line 4.
 (gdb) r
 Starting program: /home/gvasick/a.out
 
 Breakpoint 1, main (argc=260904, argv=0xfef90018) at g.c:4

Which compiler, compiler version, gdb version did you use?
What compilation flags?
What does the test program look like?

Using Opensolaris b134, gcc 3.4.3, gdb 6.8, a simple
hello, world type test program, and compilation options
-g -O it works for me.

For me, the b main command sets a breakpoint
at offset 12 relative to the symbol main, after
main's function prologue.
-- 
This message posted from opensolaris.org
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-05 Thread Scott Rotondo

On 10/ 5/10 11:04 AM, Jürgen Keil wrote:

I can reproduce the problem on my system running bash so I don't think
it is related the the shell:

(gdb) b main
Breakpoint 1 at 0x8050ccc: file g.c, line 4.
(gdb) r
Starting program: /home/gvasick/a.out

Breakpoint 1, main (argc=260904, argv=0xfef90018) at g.c:4


Which compiler, compiler version, gdb version did you use?
What compilation flags?
What does the test program look like?

Using Opensolaris b134, gcc 3.4.3, gdb 6.8, a simple
hello, world type test program, and compilation options
-g -O it works for me.

For me, the b main command sets a breakpoint
at offset 12 relative to the symbol main, after
main's function prologue.


And that makes all the difference. It's never going to work properly 
unless at least the first two instructions of the function prologue get 
executed in order to set the frame pointer in %ebp.


If the debugger automatically modifies your breakpoint request, you 
don't have to worry about this. If it literally sets the breakpoint 
where you tell it, you have to be aware of this little trick.


Scott

--
Scott Rotondo
Senior Principal Engineer, Solaris Core OS Engineering
President, Trusted Computing Group
Phone: +1 408 276 6987 (Internal x66987)
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-05 Thread John Martin

On 10/ 5/10 02:04 PM, Jürgen Keil wrote:


Which compiler, compiler version, gdb version did you use?
What compilation flags?
What does the test program look like?

Using Opensolaris b134, gcc 3.4.3, gdb 6.8, a simple
hello, world type test program, and compilation options
-g -O it works for me.


Per private email, this was on b111 and compiling the cfgadm
utility source.
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-04 Thread George Vasick

Hi Alan,

I can reproduce the problem on my system running bash so I don't think 
it is related the the shell:


(gdb) b main
Breakpoint 1 at 0x8050ccc: file g.c, line 4.
(gdb) r
Starting program: /home/gvasick/a.out

Breakpoint 1, main (argc=260904, argv=0xfef90018) at g.c:4
4   {

I also notice that stepping one statement seems to resolve the problem:

(gdb) n
main (argc=1, argv=0x8047a88) at g.c:5
5   printf (hello world!\n);
(gdb) p argc
$1 = 1
(gdb) p *argv
$2 = 0x8047b60 /home/gvasick/a.out

I get worse behavior with dbx:

(dbx) run
Running: a.out
(process id 3625)
stopped in main at line 4 in file g.c
4   {
(dbx) print argc
argc = -16795644
(dbx) print *argv
*argv = 0x3fb28 bad address 0x3fb28
(dbx) next
stopped in main at line 5 in file g.c
5   printf (hello world!\n);
(dbx) print argc
argc = 134511124
(dbx) print *argv
*argv = 0x1 bad address 0x1

although the program itself correctly prinst out argc and argv:

1, /home/gvasick/a.out


George


On 10/1/2010 2:06 AM, Alan Burlison wrote:

On 01/10/2010 03:17, Saadia Fatima wrote:


Invalid argc value is passed to main, when I run the program with no
cmmand line arguments

main(argc = 134551360, argv=0x8047b2a) // from gdb

How to fix this??


Which shell are you using?


___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-04 Thread Alan Burlison

On 04/10/2010 18:45, George Vasick wrote:


I can reproduce the problem on my system running bash so I don't think
it is related the the shell:


OK, was just wondering if it might be related to 
http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6974936


--
Alan Burlison
--
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-04 Thread Scott Rotondo

On 10/ 4/10 10:45 AM, George Vasick wrote:

Hi Alan,

I can reproduce the problem on my system running bash so I don't think
it is related the the shell:

(gdb) b main
Breakpoint 1 at 0x8050ccc: file g.c, line 4.
(gdb) r
Starting program: /home/gvasick/a.out

Breakpoint 1, main (argc=260904, argv=0xfef90018) at g.c:4
4 {

I also notice that stepping one statement seems to resolve the problem:

(gdb) n
main (argc=1, argv=0x8047a88) at g.c:5
5 printf (hello world!\n);
(gdb) p argc
$1 = 1
(gdb) p *argv
$2 = 0x8047b60 /home/gvasick/a.out


Isn't that a well-known issue with x86 debuggers - needing to break at 
function+3 so that the frame pointer is set up before you try to 
examine arguments or local variables?


Scott

--
Scott Rotondo
Senior Principal Engineer, Solaris Core OS Engineering
President, Trusted Computing Group
Phone: +1 408 276 6987 (Internal x66987)
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-01 Thread Alan Burlison

On 01/10/2010 03:17, Saadia Fatima wrote:


Invalid argc value is passed to main, when I run the program with no cmmand 
line arguments

main(argc = 134551360, argv=0x8047b2a) // from gdb

How to fix this??


Which shell are you using?

--
Alan Burlison
--
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-10-01 Thread Joerg Schilling
Richard L. Hamilton rlha...@smart.net wrote:

 Maybe something strange with gdb, or with the compiler?

A bug in gdb could be verified by checking with mdb or pstack.

Jörg

-- 
 EMail:jo...@schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
   j...@cs.tu-berlin.de(uni)  
   joerg.schill...@fokus.fraunhofer.de (work) Blog: 
http://schily.blogspot.com/
 URL:  http://cdrecord.berlios.de/private/ ftp://ftp.berlios.de/pub/schily
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


[osol-discuss] C programming, invalid argc value

2010-09-30 Thread Saadia Fatima
Hi,

Invalid argc value is passed to main, when I run the program with no cmmand 
line arguments

main(argc = 134551360, argv=0x8047b2a) // from gdb 

How to fix this??

-Thanks
SF
-- 
This message posted from opensolaris.org
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-09-30 Thread Richard L. Hamilton
Maybe something strange with gdb, or with the compiler?

By convention, there is always supposed to be at least one
argument, argv[0], which should be the same as the pathname
or the last level of the pathname being executed (login shells
typically get the last level of the pathname but prefixed with a
dash; that little trick lets them know to act like login shells rather
than like subshells).

So if that convention is observed, argc will be at least 1.

However, I tried truly passing zero arguments, using cc and dbx; it
worked reasonably:

$ cat aatest.c
#include unistd.h
#include stdio.h

int
main(int argc, char **argv)
{
char *empty[] = {NULL};
execve(/home/rlhamil/atest,empty,empty);
perror(execve() failed);
return 1;
}
$ cat atest.c
#include stdio.h
int
main(int argc, char **argv)
{
printf(%d\n,argc);
return 0;
}

When I ran aatest, 0 was printed (by atest).
 
That's as close to passing no arguments as one can get.  Attempting
to pass NULL rather than an array with one NULL element to
execve() for the arguments (maybe for the environment too) will
get a Bad Address error.

Even a situation that violates convention (but isn't strictly wrong) works.

So like I said, I think it's back to a problem with the tools you're using,
or something else you're doing wrong.
-- 
This message posted from opensolaris.org
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-09-30 Thread Edward Martinez
 Hi,
 
 Invalid argc value is passed to main, when I run the
 program with no cmmand line arguments
 
 main(argc = 134551360, argv=0x8047b2a) // from gdb 
 
 How to fix this??
 
 -Thanks
 SF
 not a C guru;-) but i think main needs to be converted from   string to an 
interger, something  like this

int main(int argc, char *argv[]);
-- 
This message posted from opensolaris.org
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org


Re: [osol-discuss] C programming, invalid argc value

2010-09-30 Thread Richard L. Hamilton
And for the curious, after adding a pause() following the printf() in
atest.c, so I could use ps to see what a process with no argv[0] looked like:

$ ps -o pid,fname -p 15789
  PID COMMAND
15789 atest
$ ps -o pid,comm -p 15789
  PID COMMAND
15789 
$ ps -o pid,args -p 15789
  PID COMMAND
15789 
$
-- 
This message posted from opensolaris.org
___
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org