help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird behavior on program execution with gmake (socket + pthreads)


From: Axel
Subject: Re: Weird behavior on program execution with gmake (socket + pthreads)
Date: Mon, 13 Sep 2010 18:57:21 +0200

Le samedi 11 septembre 2010 à 22:01 +0000, Greg Chicares a écrit :
> 
> The makefile says:
> 
> .PHONY: run
> run: build
>       @cd $(DEBUGDIR); ./$(EXEC)
> 
> debugrun: build
>       @cd $(DEBUGDIR); gdb ./$(EXEC)
> 
> and it sounds like the first target works, the second fails, and it
> also fails if you run the first target's recipe on the command line:
> 
>   # substituting variables in "cd $(DEBUGDIR); ./$(EXEC)":
>   $cd build/debug; ./main

The debugrun recipe doesn't fail. It works as the run recipe
doesMakefile.
But if I run the debugrun recipe commands (cd build/debug/; gdb ./main)
on the command line it fails as the run recipe on the command line. I
don't know why yet but I only know this is the same issue I'm talking
about in my first email (accept() returns -1).

> To verify what command 'make' is issuing, run 'make -d run' or at
> least remove the '@' above. For the 'run' target, it should run this
> command in a '/bin/sh' subshell:
>   cd build/debug; ./main
> which, however, fails if you paste it into your interactive shell.

When I remove the @ I see the recipe I've written, nothing special. I
tried to run with the -d option of gmake and it's very verbose (over 9k
lines) ! In summary I see:
        0) gmake licence 
        1) build target Makefile (implicit rules .o .cc .C etc...), no need to
ramke target Makefile
        2) build target makesubdir (copy the dir tree of the project into
build/)
        3) build target main which implies all the .cpp/.hpp files, need to
remake tgarget main
        4) Then (copy/paste) :

Live child 0x086487f0 (main) PID 4029 
Reaping winning child 0x086487f0 PID 4029 
Live child 0x086487f0 (main) PID 4032 
Reaping winning child 0x086487f0 PID 4032 
Live child 0x086487f0 (main) PID 4033 
Reaping winning child 0x086487f0 PID 4033 
Removing child 0x086487f0 PID 4033 from chain.
    Successfully remade target file `main'.
   Finished prerequisites of target file `build'.
  Must remake target `build'.
  Successfully remade target file `build'.
 Finished prerequisites of target file `run'.
Must remake target `run'.
Putting child 0x0864bc20 (run) PID 4034 on the chain.
Live child 0x0864bc20 (run) PID 4034 
Live child 0x0864bc20 (run) PID 4034 
<-- program outpit is here -->
Reaping winning child 0x0864bc20 PID 4034 
Removing child 0x0864bc20 PID 4034 from chain.

The program main's pid was 4035 and its theard's was 4036. I don't know
if gmake makes a fork or something like this, could it be something
relevant to the issue?
I can show you the output of my program when all is fine and when it's
wrong (if it can help to compare).

> 
> Could the cause be something like an uninitialized pointer in 'main'?
> 

It's very hard to tell since my program has over 1500 lines in 54 files.
With valgrind .... hum ... I've just found out the issue ! I've check
all the warnings (like "points to uninitialised byte"). Finally I've
found a "Syscall param socketcall.accept(addr) points to unaddressable
byte(s)" which leads me to this link:
http://www.mail-archive.com/address@hidden/msg00342.html where they advice me 
to set the 2nd argument variable before using the accept() syscall function.

I've only added:
        memset(&addr, 0, sizeof(struct sockaddr_in));
which makes my program work on the command line: Great news ! Thank you
for your advice ! ;)

I'm alwys interested to understand why was it working with gmake but not
in bash ? Was there a side effect which allocate some memory around the
program virtual one or something like this ? Is it gmake specific or
linux specific ?

Axel ANGEL.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]