Thread: Can any body unfold this sentences related to GDB.

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    147

    Can any body unfold this sentences related to GDB.

    The following are the senteces from one of GDB book .

    the red lines need to be concentrated

    " If you ask to debug a child process and a vfork is followed by an exec, gdb executes the new target up to the first breakpoint in the new target. If you have a breakpoint set on main in your original program, the breakpoint will also be set on the child process’s main.

    When a child process is spawned by vfork, you cannot debug the child or parent until an exec call completes.

    If you issue a run command to gdb after an exec call executes, the new target restarts. To restart the parent process, use the file command with the parent executable name as its argument. "

    in first para what he says is that in a program if we call fork() next there is exec call then the new child process will run/execute till it find the break point.
    is this understading correct.

    in second para he says we cannot debug untill exec call completes , i.e exec any way runs on the same PCB so does that mean all break points go and we cannot debug there ?

    in third para if we issue the run command after exec , i did not understand here.
    any way once we start gdb like gdb a.out next command to execute the program under gdb is run , so why or how can we issue run command after exec

    i know it might be very trivial for some guys here but for me a bit confusing.
    Help me in understanding this lines.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    To make some sense here, I think we need an example (this code is simplified - it would be several more lines if we wanted to have a working piece of code):
    Code:
    // program called starter
    int main()
    {
       vfork();
       exec("myprog");
    }
    The first sentence says that if you run "starter", when you get to vfork myprog will start, and only when you reach a breakpoint in myprog, will gdb stop.

    In the second sentence, it says that you can not debug the code between the beginning of vfork() and the end of exec().

    The third sentence says that if you are debugging inside myprog, you can not restart the starter application with "run", because essentially, gdb decides that what you are really debugging is "myprog", so the "run" command will restart myprog (which may or may not be what you actually wanted to do).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    147
    Thanks matsp for your insight

    Still i get some confustion in second para

    lets take your example


    Code:
    // program called starter
    int main()
    {
    line no 1:   vfork();
    line no 2:  exec("myprog");
    line no 3:  printf("Hello First GDB Testing \n");
    
    line no 4: return 0;
    }
    "In the second sentence, it says that you can not debug the code between the beginning of vfork() and the end of exec(). "

    Is this mean that we cannot step in between vfork and exec directly after vfork it goes to line no 3 .

    Is my understanding correct.

    Another sentence is in GDB which bothers me like below

    "If we call the fucntions interactively we cannot catch the execptions inside that function through catch command"

    What we mean here calling the function interactively is it like calling with function pointer / dynamic binding / late binding .

    Please give your thoughts

    Thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. buffered vs unbuffered question
    By Overworked_PhD in forum Linux Programming
    Replies: 6
    Last Post: 07-04-2008, 04:57 PM
  2. Contiguous Array version of Linked List
    By ampersand11 in forum C Programming
    Replies: 19
    Last Post: 10-07-2007, 03:05 AM
  3. Dynamically allocating memory...
    By Junior89 in forum C++ Programming
    Replies: 28
    Last Post: 05-08-2007, 10:17 PM
  4. Too much output in GDB
    By MacNilly in forum Tech Board
    Replies: 0
    Last Post: 09-13-2006, 12:45 PM
  5. does gdb lie?
    By dinjas in forum C Programming
    Replies: 8
    Last Post: 03-10-2005, 05:17 PM